Subversion Repositories SmartDukaan

Rev

Rev 15380 | Rev 16397 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Stores Controller
5
 *
6
 * @property Store $Store
7
 * @property PaginatorComponent $Paginator
8
 */
9
class StoresController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
14455 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('redirectto');
21
	}
22
 
13532 anikendra 23
/**
24
 * index method
25
 *
26
 * @return void
27
 */
28
	public function index() {
29
		$this->Store->recursive = 0;
14455 anikendra 30
		$this->set('stores', $this->Paginator->paginate());		
13532 anikendra 31
	}
32
 
33
/**
34
 * view method
35
 *
36
 * @throws NotFoundException
37
 * @param string $id
38
 * @return void
39
 */
40
	public function view($id = null) {
41
		if (!$this->Store->exists($id)) {
42
			throw new NotFoundException(__('Invalid store'));
43
		}
44
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
45
		$this->set('store', $this->Store->find('first', $options));
46
	}
47
 
14455 anikendra 48
	public function redirectto(){
49
		$this->layout = 'innerpages';
50
		$userId = $this->request->query('user_id');
51
		if(isset($userId) && !empty($userId)){
52
			$this->loadModel('User');
53
			$dbuser = $this->User->findById($userId);
54
			$this->Auth->login($dbuser['User']);
55
		}
56
		$storeId = $this->request->query('store_id');
57
		$cachekey = 'store-'.$storeId;
15085 anikendra 58
		// $store = Cache::read($cachekey,'month');
14455 anikendra 59
		if(empty($store)) {
14786 anikendra 60
			$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeId)));
14455 anikendra 61
			Cache::write($cachekey,$store,'month');			
62
		}
63
		$prefix = "SHA".$storeId;
64
		$tag = $prefix.time();
65
		if($storeId == 2){				
14654 anikendra 66
			$url = "http://dl.flipkart.com/dl/";
14455 anikendra 67
		} elseif($storeId == 3) {
14838 anikendra 68
			$url = "http://m.snapdeal.com/products/mobiles?utm_source=aff_prog&utm_campaign=afts&offer_id=17";			
14455 anikendra 69
		} elseif($storeId == 1){
14786 anikendra 70
			$url = "http://www.amazon.in/gp/goldbox";
15248 anikendra 71
		} elseif($storeId == 4) {
15380 anikendra 72
			// $this->checkToken();			
15925 anikendra 73
		} elseif($storeId==5){
74
			$url = "http://clk.omgt5.com/?PID=10314&r=$url";
14455 anikendra 75
		}
76
		if( strpos($url, '?') === false ) {
77
			$firstChar = '?';
78
		} else {
79
			$firstChar = '&';
80
		}
81
		$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
82
		if(!empty($store['Store']['sub_tag_param'])){
83
			$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
84
		}
85
		$extras = array('store'=>$store['Store']['name']);
86
		$data = array('user_id'=>$userId,'store_product_id'=>0,'price'=>0,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
87
		$this->loadModel('Click');
88
		$this->Click->create();
89
		if ($this->Click->save($data)) {
90
			$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
91
		} else {
92
			$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
93
		}
94
		$this->set(compact('store','url'));
95
	}
96
 
13532 anikendra 97
/**
98
 * add method
99
 *
100
 * @return void
101
 */
102
	public function add() {
103
		if ($this->request->is('post')) {
104
			$this->Store->create();
105
			if ($this->Store->save($this->request->data)) {
106
				$this->Session->setFlash(__('The store has been saved.'));
107
				return $this->redirect(array('action' => 'index'));
108
			} else {
109
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
110
			}
111
		}
112
		$affiliates = $this->Store->Affiliate->find('list');
113
		$this->set(compact('affiliates'));
114
	}
115
 
116
/**
117
 * edit method
118
 *
119
 * @throws NotFoundException
120
 * @param string $id
121
 * @return void
122
 */
123
	public function edit($id = null) {
124
		if (!$this->Store->exists($id)) {
125
			throw new NotFoundException(__('Invalid store'));
126
		}
127
		if ($this->request->is(array('post', 'put'))) {
128
			if ($this->Store->save($this->request->data)) {
129
				$this->Session->setFlash(__('The store has been saved.'));
130
				return $this->redirect(array('action' => 'index'));
131
			} else {
132
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
133
			}
134
		} else {
135
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
136
			$this->request->data = $this->Store->find('first', $options);
137
		}
138
		$affiliates = $this->Store->Affiliate->find('list');
139
		$this->set(compact('affiliates'));
140
	}
141
 
142
/**
143
 * delete method
144
 *
145
 * @throws NotFoundException
146
 * @param string $id
147
 * @return void
148
 */
149
	public function delete($id = null) {
150
		$this->Store->id = $id;
151
		if (!$this->Store->exists()) {
152
			throw new NotFoundException(__('Invalid store'));
153
		}
154
		$this->request->onlyAllow('post', 'delete');
155
		if ($this->Store->delete()) {
156
			$this->Session->setFlash(__('The store has been deleted.'));
157
		} else {
158
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
159
		}
160
		return $this->redirect(array('action' => 'index'));
161
	}
162
 
163
/**
164
 * admin_index method
165
 *
166
 * @return void
167
 */
168
	public function admin_index() {
169
		$this->Store->recursive = 0;
170
		$this->set('stores', $this->Paginator->paginate());
171
	}
172
 
173
/**
174
 * admin_view method
175
 *
176
 * @throws NotFoundException
177
 * @param string $id
178
 * @return void
179
 */
180
	public function admin_view($id = null) {
181
		if (!$this->Store->exists($id)) {
182
			throw new NotFoundException(__('Invalid store'));
183
		}
184
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
185
		$this->set('store', $this->Store->find('first', $options));
186
	}
187
 
188
/**
189
 * admin_add method
190
 *
191
 * @return void
192
 */
193
	public function admin_add() {
194
		if ($this->request->is('post')) {
195
			$this->Store->create();
196
			if ($this->Store->save($this->request->data)) {
197
				$this->Session->setFlash(__('The store has been saved.'));
198
				return $this->redirect(array('action' => 'index'));
199
			} else {
200
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
201
			}
202
		}
203
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 204
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
205
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 206
	}
207
 
208
/**
209
 * admin_edit method
210
 *
211
 * @throws NotFoundException
212
 * @param string $id
213
 * @return void
214
 */
215
	public function admin_edit($id = null) {
216
		if (!$this->Store->exists($id)) {
217
			throw new NotFoundException(__('Invalid store'));
218
		}
219
		if ($this->request->is(array('post', 'put'))) {
220
			if ($this->Store->save($this->request->data)) {
221
				$this->Session->setFlash(__('The store has been saved.'));
222
				return $this->redirect(array('action' => 'index'));
223
			} else {
224
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
225
			}
226
		} else {
227
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
228
			$this->request->data = $this->Store->find('first', $options);
229
		}
230
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 231
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
232
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 233
	}
234
 
235
/**
236
 * admin_delete method
237
 *
238
 * @throws NotFoundException
239
 * @param string $id
240
 * @return void
241
 */
242
	public function admin_delete($id = null) {
243
		$this->Store->id = $id;
244
		if (!$this->Store->exists()) {
245
			throw new NotFoundException(__('Invalid store'));
246
		}
247
		$this->request->onlyAllow('post', 'delete');
248
		if ($this->Store->delete()) {
249
			$this->Session->setFlash(__('The store has been deleted.'));
250
		} else {
251
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
252
		}
253
		return $this->redirect(array('action' => 'index'));
254
	}}