Subversion Repositories SmartDukaan

Rev

Rev 17091 | Rev 17101 | 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
				}
14934 anikendra 67
				if(isset($pushdata['pushdata'][0]['httpstatus']) && !empty($pushdata['pushdata'][0]['httpstatus'])) {
68
					$this->loadModel('SaholicLog');
69
					$this->SaholicLog->create();
70
					$this->SaholicLog->saveAll($pushdata['pushdata']);
71
				}
17091 anikendra 72
				*/
73
				//Nodejs api call
74
				$url = "45.33.50.227:3001/addBrowsingHistory";
17096 anikendra 75
				$this->make_request($url,$pushdata['pushdata'][0]);
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() {
144
		$this->UserUrl->recursive = 0;
14434 anikendra 145
		$q = $this->request->query('q');
146
		if(isset($q) && !empty($q)){
14654 anikendra 147
			$this->Paginator->settings = array('conditions' => array('UserUrl.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
148
 			$this->set(compact('q'));
149
		} else {
150
			$this->Paginator->settings = array('order' => array('id'=>'desc'));
151
 		}
13532 anikendra 152
		$this->set('userUrls', $this->Paginator->paginate());
153
	}
154
 
155
/**
156
 * admin_view method
157
 *
158
 * @throws NotFoundException
159
 * @param string $id
160
 * @return void
161
 */
162
	public function admin_view($id = null) {
163
		if (!$this->UserUrl->exists($id)) {
164
			throw new NotFoundException(__('Invalid user url'));
165
		}
166
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
167
		$this->set('userUrl', $this->UserUrl->find('first', $options));
168
	}
169
 
14401 anikendra 170
	public function admin_by($userId = null) {
171
		$options = array('conditions' => array('UserUrl.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
172
		$this->Paginator->settings = $options;
173
		$userUrls = $this->Paginator->paginate();		
174
		$this->set(compact('userUrls'));
175
	}
13532 anikendra 176
/**
177
 * admin_add method
178
 *
179
 * @return void
180
 */
181
	public function admin_add() {
182
		if ($this->request->is('post')) {
183
			$this->UserUrl->create();
184
			if ($this->UserUrl->save($this->request->data)) {
185
				$this->Session->setFlash(__('The user url has been saved.'));
186
				return $this->redirect(array('action' => 'index'));
187
			} else {
188
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
189
			}
190
		}
191
		$users = $this->UserUrl->User->find('list');
192
		$this->set(compact('users'));
193
	}
194
 
195
/**
196
 * admin_edit method
197
 *
198
 * @throws NotFoundException
199
 * @param string $id
200
 * @return void
201
 */
202
	public function admin_edit($id = null) {
203
		if (!$this->UserUrl->exists($id)) {
204
			throw new NotFoundException(__('Invalid user url'));
205
		}
206
		if ($this->request->is(array('post', 'put'))) {
207
			if ($this->UserUrl->save($this->request->data)) {
208
				$this->Session->setFlash(__('The user url has been saved.'));
209
				return $this->redirect(array('action' => 'index'));
210
			} else {
211
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
212
			}
213
		} else {
214
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
215
			$this->request->data = $this->UserUrl->find('first', $options);
216
		}
217
		$users = $this->UserUrl->User->find('list');
218
		$this->set(compact('users'));
219
	}
220
 
221
/**
222
 * admin_delete method
223
 *
224
 * @throws NotFoundException
225
 * @param string $id
226
 * @return void
227
 */
228
	public function admin_delete($id = null) {
229
		$this->UserUrl->id = $id;
230
		if (!$this->UserUrl->exists()) {
231
			throw new NotFoundException(__('Invalid user url'));
232
		}
233
		$this->request->onlyAllow('post', 'delete');
234
		if ($this->UserUrl->delete()) {
235
			$this->Session->setFlash(__('The user url has been deleted.'));
236
		} else {
237
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
238
		}
239
		return $this->redirect(array('action' => 'index'));
240
	}}