Subversion Repositories SmartDukaan

Rev

Rev 17096 | Rev 17113 | 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
 * UserUrls Controller
5
 *
6
 * @property UserUrl $UserUrl
7
 * @property PaginatorComponent $Paginator
8
 */
9
class UserUrlsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13591 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('add');
21
	}
13532 anikendra 22
/**
23
 * index method
24
 *
25
 * @return void
26
 */
27
	public function index() {
13591 anikendra 28
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 29
		$this->UserUrl->recursive = 0;
30
		$this->set('userUrls', $this->Paginator->paginate());
31
	}
32
 
33
/**
34
 * view method
35
 *
36
 * @throws NotFoundException
37
 * @param string $id
38
 * @return void
39
 */
40
	public function view($id = null) {
13591 anikendra 41
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 42
		if (!$this->UserUrl->exists($id)) {
43
			throw new NotFoundException(__('Invalid user url'));
44
		}
45
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
46
		$this->set('userUrl', $this->UserUrl->find('first', $options));
47
	}
48
 
49
/**
50
 * add method
51
 *
52
 * @return void
53
 */
54
	public function add() {
55
		if ($this->request->is('post')) {
13595 anikendra 56
			if(isset($this->request->data['pushdata']) && !empty($this->request->data['pushdata'])) {
57
				$pushdata = json_decode($this->request->data['pushdata'],1);	
14661 anikendra 58
				$pushdata['pushdata'][0]['ip'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
17096 anikendra 59
				$this->log(print_r($pushdata['pushdata'][0],1),'nodejs');
17091 anikendra 60
				/*
13595 anikendra 61
				$this->UserUrl->create();
62
				if ($this->UserUrl->saveAll($pushdata['pushdata'])) {
63
					$result = array('success' => true,'message'=>__('The url has been saved.'));
64
				} else {
65
					$result = array('success' => false,'message'=>__('The url could not be saved. Please, try again.'));
66
				}
17101 anikendra 67
				*/
14934 anikendra 68
				if(isset($pushdata['pushdata'][0]['httpstatus']) && !empty($pushdata['pushdata'][0]['httpstatus'])) {
69
					$this->loadModel('SaholicLog');
70
					$this->SaholicLog->create();
71
					$this->SaholicLog->saveAll($pushdata['pushdata']);
17101 anikendra 72
				}				
17091 anikendra 73
				//Nodejs api call
17101 anikendra 74
				$url = Configure::read('nodeurl') . '/addBrowsingHistory/?pushed_by=php';
75
				$this->make_request($url,json_encode($pushdata));
17091 anikendra 76
				$result = array('success' => true,'message'=>__('The url has been saved.'));
13595 anikendra 77
				$this->response->type('json');
78
				$this->layout = 'ajax';
79
				$this->set(array(
80
				    'result' => $result,
81
				    // 'callback' => $callback,
82
				    '_serialize' => array('result')
83
				));
84
				$this->render('/Elements/json');
85
			}			
13591 anikendra 86
		}		
13532 anikendra 87
	}
88
 
89
/**
90
 * edit method
91
 *
92
 * @throws NotFoundException
93
 * @param string $id
94
 * @return void
95
 */
96
	public function edit($id = null) {
13591 anikendra 97
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 98
		if (!$this->UserUrl->exists($id)) {
99
			throw new NotFoundException(__('Invalid user url'));
100
		}
101
		if ($this->request->is(array('post', 'put'))) {
102
			if ($this->UserUrl->save($this->request->data)) {
103
				$this->Session->setFlash(__('The user url has been saved.'));
104
				return $this->redirect(array('action' => 'index'));
105
			} else {
106
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
107
			}
108
		} else {
109
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
110
			$this->request->data = $this->UserUrl->find('first', $options);
111
		}
112
		$users = $this->UserUrl->User->find('list');
113
		$this->set(compact('users'));
114
	}
115
 
116
/**
117
 * delete method
118
 *
119
 * @throws NotFoundException
120
 * @param string $id
121
 * @return void
122
 */
123
	public function delete($id = null) {
13591 anikendra 124
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 125
		$this->UserUrl->id = $id;
126
		if (!$this->UserUrl->exists()) {
127
			throw new NotFoundException(__('Invalid user url'));
128
		}
129
		$this->request->onlyAllow('post', 'delete');
130
		if ($this->UserUrl->delete()) {
131
			$this->Session->setFlash(__('The user url has been deleted.'));
132
		} else {
133
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
134
		}
135
		return $this->redirect(array('action' => 'index'));
136
	}
137
 
138
/**
139
 * admin_index method
140
 *
141
 * @return void
142
 */
143
	public function admin_index() {
17101 anikendra 144
		/*
13532 anikendra 145
		$this->UserUrl->recursive = 0;
14434 anikendra 146
		$q = $this->request->query('q');
147
		if(isset($q) && !empty($q)){
14654 anikendra 148
			$this->Paginator->settings = array('conditions' => array('UserUrl.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
149
 			$this->set(compact('q'));
150
		} else {
151
			$this->Paginator->settings = array('order' => array('id'=>'desc'));
152
 		}
13532 anikendra 153
		$this->set('userUrls', $this->Paginator->paginate());
17101 anikendra 154
		*/
155
		$page = $this->request->query('page');
156
		if(!isset($page)){
157
			$page = 1;
158
		}		
159
		$url = Configure::read('nodeurl') . '/getBrowsingHistory/?posted_by=php';
160
		$url = $this->UserUrl->getNodeUrl($url,$page);
161
		$userUrls = $this->make_request($url,null);
162
		$this->set(compact('userUrls', 'page'));
13532 anikendra 163
	}
164
 
165
/**
166
 * admin_view method
167
 *
168
 * @throws NotFoundException
169
 * @param string $id
170
 * @return void
171
 */
172
	public function admin_view($id = null) {
173
		if (!$this->UserUrl->exists($id)) {
174
			throw new NotFoundException(__('Invalid user url'));
175
		}
176
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
177
		$this->set('userUrl', $this->UserUrl->find('first', $options));
178
	}
179
 
14401 anikendra 180
	public function admin_by($userId = null) {
17101 anikendra 181
		/*$options = array('conditions' => array('UserUrl.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
14401 anikendra 182
		$this->Paginator->settings = $options;
183
		$userUrls = $this->Paginator->paginate();		
17101 anikendra 184
		$this->set(compact('userUrls'));*/
185
		$page = $this->request->query('page');
186
		if(!isset($page)){
187
			$page = 1;
188
		}	
189
		$url = Configure::read('nodeurl') . '/getBrowsingHistoryByUserId/?posted_by=php&user_id='.$userId;
190
		$url = $this->UserUrl->getNodeUrl($url,$page);
191
		$userUrls = $this->make_request($url,null);
192
		$userInfoApiUrl = Configure::read('nodeurl') . '/getUserById/?user_id='.$userId;
193
		$user = $this->make_request($userInfoApiUrl,null);
194
		$this->set(compact('userUrls', 'page','user','userId'));
14401 anikendra 195
	}
13532 anikendra 196
/**
197
 * admin_add method
198
 *
199
 * @return void
200
 */
201
	public function admin_add() {
202
		if ($this->request->is('post')) {
203
			$this->UserUrl->create();
204
			if ($this->UserUrl->save($this->request->data)) {
205
				$this->Session->setFlash(__('The user url has been saved.'));
206
				return $this->redirect(array('action' => 'index'));
207
			} else {
208
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
209
			}
210
		}
211
		$users = $this->UserUrl->User->find('list');
212
		$this->set(compact('users'));
213
	}
214
 
215
/**
216
 * admin_edit method
217
 *
218
 * @throws NotFoundException
219
 * @param string $id
220
 * @return void
221
 */
222
	public function admin_edit($id = null) {
223
		if (!$this->UserUrl->exists($id)) {
224
			throw new NotFoundException(__('Invalid user url'));
225
		}
226
		if ($this->request->is(array('post', 'put'))) {
227
			if ($this->UserUrl->save($this->request->data)) {
228
				$this->Session->setFlash(__('The user url has been saved.'));
229
				return $this->redirect(array('action' => 'index'));
230
			} else {
231
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
232
			}
233
		} else {
234
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
235
			$this->request->data = $this->UserUrl->find('first', $options);
236
		}
237
		$users = $this->UserUrl->User->find('list');
238
		$this->set(compact('users'));
239
	}
240
 
241
/**
242
 * admin_delete method
243
 *
244
 * @throws NotFoundException
245
 * @param string $id
246
 * @return void
247
 */
248
	public function admin_delete($id = null) {
249
		$this->UserUrl->id = $id;
250
		if (!$this->UserUrl->exists()) {
251
			throw new NotFoundException(__('Invalid user url'));
252
		}
253
		$this->request->onlyAllow('post', 'delete');
254
		if ($this->UserUrl->delete()) {
255
			$this->Session->setFlash(__('The user url has been deleted.'));
256
		} else {
257
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
258
		}
259
		return $this->redirect(array('action' => 'index'));
260
	}}