Subversion Repositories SmartDukaan

Rev

Rev 15925 | Rev 16679 | 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";
16397 anikendra 75
		} elseif($storeId==6){
76
			$url = "http://clk.omgt5.com/?PID=11365&r=$url";
14455 anikendra 77
		}
78
		if( strpos($url, '?') === false ) {
79
			$firstChar = '?';
80
		} else {
81
			$firstChar = '&';
82
		}
83
		$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
84
		if(!empty($store['Store']['sub_tag_param'])){
85
			$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
86
		}
87
		$extras = array('store'=>$store['Store']['name']);
88
		$data = array('user_id'=>$userId,'store_product_id'=>0,'price'=>0,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
89
		$this->loadModel('Click');
90
		$this->Click->create();
91
		if ($this->Click->save($data)) {
92
			$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
93
		} else {
94
			$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
95
		}
96
		$this->set(compact('store','url'));
97
	}
98
 
13532 anikendra 99
/**
100
 * add method
101
 *
102
 * @return void
103
 */
104
	public function add() {
105
		if ($this->request->is('post')) {
106
			$this->Store->create();
107
			if ($this->Store->save($this->request->data)) {
108
				$this->Session->setFlash(__('The store has been saved.'));
109
				return $this->redirect(array('action' => 'index'));
110
			} else {
111
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
112
			}
113
		}
114
		$affiliates = $this->Store->Affiliate->find('list');
115
		$this->set(compact('affiliates'));
116
	}
117
 
118
/**
119
 * edit method
120
 *
121
 * @throws NotFoundException
122
 * @param string $id
123
 * @return void
124
 */
125
	public function edit($id = null) {
126
		if (!$this->Store->exists($id)) {
127
			throw new NotFoundException(__('Invalid store'));
128
		}
129
		if ($this->request->is(array('post', 'put'))) {
130
			if ($this->Store->save($this->request->data)) {
131
				$this->Session->setFlash(__('The store has been saved.'));
132
				return $this->redirect(array('action' => 'index'));
133
			} else {
134
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
135
			}
136
		} else {
137
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
138
			$this->request->data = $this->Store->find('first', $options);
139
		}
140
		$affiliates = $this->Store->Affiliate->find('list');
141
		$this->set(compact('affiliates'));
142
	}
143
 
144
/**
145
 * delete method
146
 *
147
 * @throws NotFoundException
148
 * @param string $id
149
 * @return void
150
 */
151
	public function delete($id = null) {
152
		$this->Store->id = $id;
153
		if (!$this->Store->exists()) {
154
			throw new NotFoundException(__('Invalid store'));
155
		}
156
		$this->request->onlyAllow('post', 'delete');
157
		if ($this->Store->delete()) {
158
			$this->Session->setFlash(__('The store has been deleted.'));
159
		} else {
160
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
161
		}
162
		return $this->redirect(array('action' => 'index'));
163
	}
164
 
165
/**
166
 * admin_index method
167
 *
168
 * @return void
169
 */
170
	public function admin_index() {
171
		$this->Store->recursive = 0;
172
		$this->set('stores', $this->Paginator->paginate());
173
	}
174
 
175
/**
176
 * admin_view method
177
 *
178
 * @throws NotFoundException
179
 * @param string $id
180
 * @return void
181
 */
182
	public function admin_view($id = null) {
183
		if (!$this->Store->exists($id)) {
184
			throw new NotFoundException(__('Invalid store'));
185
		}
186
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
187
		$this->set('store', $this->Store->find('first', $options));
188
	}
189
 
190
/**
191
 * admin_add method
192
 *
193
 * @return void
194
 */
195
	public function admin_add() {
196
		if ($this->request->is('post')) {
197
			$this->Store->create();
198
			if ($this->Store->save($this->request->data)) {
199
				$this->Session->setFlash(__('The store has been saved.'));
200
				return $this->redirect(array('action' => 'index'));
201
			} else {
202
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
203
			}
204
		}
205
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 206
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
207
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 208
	}
209
 
210
/**
211
 * admin_edit method
212
 *
213
 * @throws NotFoundException
214
 * @param string $id
215
 * @return void
216
 */
217
	public function admin_edit($id = null) {
218
		if (!$this->Store->exists($id)) {
219
			throw new NotFoundException(__('Invalid store'));
220
		}
221
		if ($this->request->is(array('post', 'put'))) {
222
			if ($this->Store->save($this->request->data)) {
223
				$this->Session->setFlash(__('The store has been saved.'));
224
				return $this->redirect(array('action' => 'index'));
225
			} else {
226
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
227
			}
228
		} else {
229
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
230
			$this->request->data = $this->Store->find('first', $options);
231
		}
232
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
13558 anikendra 233
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
234
		$this->set(compact('statuses','cashback_statuses'));
13532 anikendra 235
	}
236
 
237
/**
238
 * admin_delete method
239
 *
240
 * @throws NotFoundException
241
 * @param string $id
242
 * @return void
243
 */
244
	public function admin_delete($id = null) {
245
		$this->Store->id = $id;
246
		if (!$this->Store->exists()) {
247
			throw new NotFoundException(__('Invalid store'));
248
		}
249
		$this->request->onlyAllow('post', 'delete');
250
		if ($this->Store->delete()) {
251
			$this->Session->setFlash(__('The store has been deleted.'));
252
		} else {
253
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
254
		}
255
		return $this->redirect(array('action' => 'index'));
256
	}}