Subversion Repositories SmartDukaan

Rev

Rev 15403 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15403 manish.sha 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
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('redirectto');
21
	}
22
 
23
/**
24
 * index method
25
 *
26
 * @return void
27
 */
28
	public function index() {
15655 anikendra 29
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 30
		$this->Store->recursive = 0;
31
		$this->set('stores', $this->Paginator->paginate());		
32
	}
33
 
34
/**
35
 * view method
36
 *
37
 * @throws NotFoundException
38
 * @param string $id
39
 * @return void
40
 */
41
	public function view($id = null) {
15655 anikendra 42
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 43
		if (!$this->Store->exists($id)) {
44
			throw new NotFoundException(__('Invalid store'));
45
		}
46
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
47
		$this->set('store', $this->Store->find('first', $options));
48
	}
49
 
50
	public function redirectto(){
51
		$this->layout = 'innerpages';
52
		$userId = $this->request->query('user_id');
53
		if(isset($userId) && !empty($userId)){
54
			$this->loadModel('User');
55
			$dbuser = $this->User->findById($userId);
56
			$this->Auth->login($dbuser['User']);
57
		}
58
		$storeId = $this->request->query('store_id');
59
		$cachekey = 'store-'.$storeId;
60
		// $store = Cache::read($cachekey,'month');
61
		if(empty($store)) {
62
			$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeId)));
63
			Cache::write($cachekey,$store,'month');			
64
		}
65
		$prefix = "SHA".$storeId;
66
		$tag = $prefix.time();
67
		if($storeId == 2){				
68
			$url = "http://dl.flipkart.com/dl/";
69
		} elseif($storeId == 3) {
70
			$url = "http://m.snapdeal.com/products/mobiles?utm_source=aff_prog&utm_campaign=afts&offer_id=17";			
71
		} elseif($storeId == 1){
72
			$url = "http://www.amazon.in/gp/goldbox";
73
		}
74
		if( strpos($url, '?') === false ) {
75
			$firstChar = '?';
76
		} else {
77
			$firstChar = '&';
78
		}
79
		$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
80
		if(!empty($store['Store']['sub_tag_param'])){
81
			$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
82
		}
83
		$extras = array('store'=>$store['Store']['name']);
84
		$data = array('user_id'=>$userId,'store_product_id'=>0,'price'=>0,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));
85
		$this->loadModel('Click');
86
		$this->Click->create();
87
		if ($this->Click->save($data)) {
88
			$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);
89
		} else {
90
			$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));
91
		}
92
		$this->set(compact('store','url'));
93
	}
94
 
95
/**
96
 * add method
97
 *
98
 * @return void
99
 */
100
	public function add() {
15655 anikendra 101
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 102
		if ($this->request->is('post')) {
103
			$this->Store->create();
104
			if ($this->Store->save($this->request->data)) {
105
				$this->Session->setFlash(__('The store has been saved.'));
106
				return $this->redirect(array('action' => 'index'));
107
			} else {
108
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
109
			}
110
		}
111
		$affiliates = $this->Store->Affiliate->find('list');
112
		$this->set(compact('affiliates'));
113
	}
114
 
115
/**
116
 * edit method
117
 *
118
 * @throws NotFoundException
119
 * @param string $id
120
 * @return void
121
 */
122
	public function edit($id = null) {
15655 anikendra 123
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 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) {
15655 anikendra 150
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 151
		$this->Store->id = $id;
152
		if (!$this->Store->exists()) {
153
			throw new NotFoundException(__('Invalid store'));
154
		}
155
		$this->request->onlyAllow('post', 'delete');
156
		if ($this->Store->delete()) {
157
			$this->Session->setFlash(__('The store has been deleted.'));
158
		} else {
159
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
160
		}
161
		return $this->redirect(array('action' => 'index'));
162
	}
163
 
164
/**
165
 * admin_index method
166
 *
167
 * @return void
168
 */
169
	public function admin_index() {
15655 anikendra 170
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 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) {
15655 anikendra 183
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 184
		if (!$this->Store->exists($id)) {
185
			throw new NotFoundException(__('Invalid store'));
186
		}
187
		$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
188
		$this->set('store', $this->Store->find('first', $options));
189
	}
190
 
191
/**
192
 * admin_add method
193
 *
194
 * @return void
195
 */
196
	public function admin_add() {
15655 anikendra 197
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 198
		if ($this->request->is('post')) {
199
			$this->Store->create();
200
			if ($this->Store->save($this->request->data)) {
201
				$this->Session->setFlash(__('The store has been saved.'));
202
				return $this->redirect(array('action' => 'index'));
203
			} else {
204
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
205
			}
206
		}
207
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
208
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
209
		$this->set(compact('statuses','cashback_statuses'));
210
	}
211
 
212
/**
213
 * admin_edit method
214
 *
215
 * @throws NotFoundException
216
 * @param string $id
217
 * @return void
218
 */
219
	public function admin_edit($id = null) {
15655 anikendra 220
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 221
		if (!$this->Store->exists($id)) {
222
			throw new NotFoundException(__('Invalid store'));
223
		}
224
		if ($this->request->is(array('post', 'put'))) {
225
			if ($this->Store->save($this->request->data)) {
226
				$this->Session->setFlash(__('The store has been saved.'));
227
				return $this->redirect(array('action' => 'index'));
228
			} else {
229
				$this->Session->setFlash(__('The store could not be saved. Please, try again.'));
230
			}
231
		} else {
232
			$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));
233
			$this->request->data = $this->Store->find('first', $options);
234
		}
235
		$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');
236
		$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');
237
		$this->set(compact('statuses','cashback_statuses'));
238
	}
239
 
240
/**
241
 * admin_delete method
242
 *
243
 * @throws NotFoundException
244
 * @param string $id
245
 * @return void
246
 */
247
	public function admin_delete($id = null) {
15655 anikendra 248
		throw new NotFoundException(__('Unauthorized access'));
15403 manish.sha 249
		$this->Store->id = $id;
250
		if (!$this->Store->exists()) {
251
			throw new NotFoundException(__('Invalid store'));
252
		}
253
		$this->request->onlyAllow('post', 'delete');
254
		if ($this->Store->delete()) {
255
			$this->Session->setFlash(__('The store has been deleted.'));
256
		} else {
257
			$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));
258
		}
259
		return $this->redirect(array('action' => 'index'));
15655 anikendra 260
	}
261
}