| 14509 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Campaigns Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Campaign $Campaign
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class CampaignsController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator','RequestHandler');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* index method
|
|
|
20 |
*
|
|
|
21 |
* @return void
|
|
|
22 |
*/
|
|
|
23 |
public function index() {
|
| 15227 |
anikendra |
24 |
$this->checkAcl();
|
| 14509 |
anikendra |
25 |
$country = 'IN';
|
|
|
26 |
foreach (getallheaders() as $name => $value) {
|
|
|
27 |
if($name == "Cf-Ipcountry"){
|
|
|
28 |
//error_log("[XFWDF] [country]- $value");
|
|
|
29 |
//if($value != 'XX')
|
|
|
30 |
// $country = $value;
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
$this->Campaign->recursive = 0;
|
|
|
34 |
$options = array('conditions'=>array('status'=>'active','OR' => array(array('target_countries LIKE'=>'%'.$country.'%'),array('target_countries' => null))),'order'=>array('clicks'=>'asc'));
|
|
|
35 |
$cachekey = "campaign-$country";
|
|
|
36 |
$response = Cache::read($cachekey,'hour');
|
|
|
37 |
if(empty($response)) {
|
|
|
38 |
$response = $this->Campaign->find('first',$options);
|
|
|
39 |
Cache::write($cachekey,$response,'hour');
|
|
|
40 |
}
|
|
|
41 |
if ($this->request->is('requested')) {
|
|
|
42 |
return $response;
|
|
|
43 |
} else {
|
|
|
44 |
$this->set('campaign', $response);
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* view method
|
|
|
50 |
*
|
|
|
51 |
* @throws NotFoundException
|
|
|
52 |
* @param string $id
|
|
|
53 |
* @return void
|
|
|
54 |
*/
|
|
|
55 |
public function view($id = null) {
|
|
|
56 |
$this->layout= 'ajax';
|
|
|
57 |
if (!$this->Campaign->exists($id)) {
|
|
|
58 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
59 |
}
|
|
|
60 |
$options = array('conditions' => array('Campaign.id'=> $id));
|
|
|
61 |
$campaign = $this->Campaign->find('first', $options);
|
|
|
62 |
$campaign['Campaign']['clicks'] = $campaign['Campaign']['clicks'] + 1;
|
|
|
63 |
$this->Campaign->save($campaign);
|
|
|
64 |
$url = $campaign['Campaign']['url'];
|
|
|
65 |
$url = str_replace('INSERTPUBLISHERID','hotbhojpuri',$url);
|
|
|
66 |
$url = str_replace('INSERTS2STRACKING',$campaign['Campaign']['id'],$url);
|
|
|
67 |
$this->set('url',$url);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* add method
|
|
|
72 |
*
|
|
|
73 |
* @return void
|
|
|
74 |
*/
|
|
|
75 |
public function add() {
|
| 15227 |
anikendra |
76 |
$this->checkAcl();
|
| 14509 |
anikendra |
77 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
78 |
if ($this->request->is('post')) {
|
|
|
79 |
$this->Campaign->create();
|
|
|
80 |
if ($this->Campaign->save($this->request->data)) {
|
|
|
81 |
$this->Session->setFlash(__('The campaign has been saved.'));
|
|
|
82 |
return $this->redirect(array('action' => 'index'));
|
|
|
83 |
} else {
|
|
|
84 |
$this->Session->setFlash(__('The campaign could not be saved. Please, try again.'));
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* edit method
|
|
|
91 |
*
|
|
|
92 |
* @throws NotFoundException
|
|
|
93 |
* @param string $id
|
|
|
94 |
* @return void
|
|
|
95 |
*/
|
|
|
96 |
public function edit($id = null) {
|
|
|
97 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
98 |
if (!$this->Campaign->exists($id)) {
|
|
|
99 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
100 |
}
|
|
|
101 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
102 |
if ($this->Campaign->save($this->request->data)) {
|
|
|
103 |
$this->Session->setFlash(__('The campaign has been saved.'));
|
|
|
104 |
return $this->redirect(array('action' => 'index'));
|
|
|
105 |
} else {
|
|
|
106 |
$this->Session->setFlash(__('The campaign could not be saved. Please, try again.'));
|
|
|
107 |
}
|
|
|
108 |
} else {
|
|
|
109 |
$options = array('conditions' => array('Campaign.' . $this->Campaign->primaryKey => $id));
|
|
|
110 |
$this->request->data = $this->Campaign->find('first', $options);
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* delete method
|
|
|
116 |
*
|
|
|
117 |
* @throws NotFoundException
|
|
|
118 |
* @param string $id
|
|
|
119 |
* @return void
|
|
|
120 |
*/
|
|
|
121 |
public function delete($id = null) {
|
|
|
122 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
123 |
$this->Campaign->id = $id;
|
|
|
124 |
if (!$this->Campaign->exists()) {
|
|
|
125 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
126 |
}
|
|
|
127 |
$this->request->onlyAllow('post', 'delete');
|
|
|
128 |
if ($this->Campaign->delete()) {
|
|
|
129 |
$this->Session->setFlash(__('The campaign has been deleted.'));
|
|
|
130 |
} else {
|
|
|
131 |
$this->Session->setFlash(__('The campaign could not be deleted. Please, try again.'));
|
|
|
132 |
}
|
|
|
133 |
return $this->redirect(array('action' => 'index'));
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
/**
|
|
|
137 |
* admin_index method
|
|
|
138 |
*
|
|
|
139 |
* @return void
|
|
|
140 |
*/
|
|
|
141 |
public function admin_index() {
|
|
|
142 |
$this->Campaign->recursive = 0;
|
|
|
143 |
$this->set('campaigns', $this->Paginator->paginate());
|
| 14547 |
anikendra |
144 |
$this->loadModel('Store');
|
|
|
145 |
$this->set('stores',$this->Store->find('list'));
|
| 14509 |
anikendra |
146 |
}
|
|
|
147 |
|
|
|
148 |
/**
|
|
|
149 |
* admin_view method
|
|
|
150 |
*
|
|
|
151 |
* @throws NotFoundException
|
|
|
152 |
* @param string $id
|
|
|
153 |
* @return void
|
|
|
154 |
*/
|
|
|
155 |
public function admin_view($id = null) {
|
|
|
156 |
if (!$this->Campaign->exists($id)) {
|
|
|
157 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
158 |
}
|
|
|
159 |
$options = array('conditions' => array('Campaign.' . $this->Campaign->primaryKey => $id));
|
|
|
160 |
$this->set('campaign', $this->Campaign->find('first', $options));
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
* admin_add method
|
|
|
165 |
*
|
|
|
166 |
* @return void
|
|
|
167 |
*/
|
|
|
168 |
public function admin_add() {
|
|
|
169 |
if ($this->request->is('post')) {
|
|
|
170 |
$this->log(print_r($this->request->data,1));
|
|
|
171 |
$this->Campaign->create();
|
|
|
172 |
if ($this->Campaign->save($this->request->data)) {
|
|
|
173 |
$this->Session->setFlash(__('The campaign has been saved.'));
|
|
|
174 |
return $this->redirect(array('action' => 'index'));
|
|
|
175 |
} else {
|
|
|
176 |
$this->Session->setFlash(__('The campaign could not be saved. Please, try again.'));
|
|
|
177 |
}
|
|
|
178 |
}
|
| 14547 |
anikendra |
179 |
$this->loadModel('Store');
|
|
|
180 |
$this->set('stores',$this->Store->find('list'));
|
| 14509 |
anikendra |
181 |
}
|
|
|
182 |
|
|
|
183 |
/**
|
|
|
184 |
* admin_edit method
|
|
|
185 |
*
|
|
|
186 |
* @throws NotFoundException
|
|
|
187 |
* @param string $id
|
|
|
188 |
* @return void
|
|
|
189 |
*/
|
|
|
190 |
public function admin_edit($id = null) {
|
|
|
191 |
if (!$this->Campaign->exists($id)) {
|
|
|
192 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
193 |
}
|
|
|
194 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
195 |
if ($this->Campaign->save($this->request->data)) {
|
|
|
196 |
$this->Session->setFlash(__('The campaign has been saved.'));
|
|
|
197 |
return $this->redirect(array('action' => 'index'));
|
|
|
198 |
} else {
|
|
|
199 |
$this->Session->setFlash(__('The campaign could not be saved. Please, try again.'));
|
|
|
200 |
}
|
|
|
201 |
} else {
|
|
|
202 |
$options = array('conditions' => array('Campaign.' . $this->Campaign->primaryKey => $id));
|
|
|
203 |
$this->request->data = $this->Campaign->find('first', $options);
|
|
|
204 |
}
|
| 14547 |
anikendra |
205 |
$this->loadModel('Store');
|
|
|
206 |
$this->set('stores',$this->Store->find('list'));
|
| 14509 |
anikendra |
207 |
}
|
|
|
208 |
|
|
|
209 |
/**
|
|
|
210 |
* admin_delete method
|
|
|
211 |
*
|
|
|
212 |
* @throws NotFoundException
|
|
|
213 |
* @param string $id
|
|
|
214 |
* @return void
|
|
|
215 |
*/
|
|
|
216 |
public function admin_delete($id = null) {
|
|
|
217 |
$this->Campaign->id = $id;
|
|
|
218 |
if (!$this->Campaign->exists()) {
|
|
|
219 |
throw new NotFoundException(__('Invalid campaign'));
|
|
|
220 |
}
|
|
|
221 |
$this->request->onlyAllow('post', 'delete');
|
|
|
222 |
if ($this->Campaign->delete()) {
|
|
|
223 |
$this->Session->setFlash(__('The campaign has been deleted.'));
|
|
|
224 |
} else {
|
|
|
225 |
$this->Session->setFlash(__('The campaign could not be deleted. Please, try again.'));
|
|
|
226 |
}
|
|
|
227 |
return $this->redirect(array('action' => 'index'));
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
if (!function_exists('getallheaders'))
|
|
|
232 |
{
|
|
|
233 |
function getallheaders()
|
|
|
234 |
{
|
|
|
235 |
$headers = '';
|
|
|
236 |
foreach ($_SERVER as $name => $value)
|
|
|
237 |
{
|
|
|
238 |
if (substr($name, 0, 5) == 'HTTP_')
|
|
|
239 |
{
|
|
|
240 |
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
|
|
241 |
}
|
|
|
242 |
}
|
|
|
243 |
return $headers;
|
|
|
244 |
}
|
|
|
245 |
}
|