Subversion Repositories SmartDukaan

Rev

Rev 14661 | Rev 17091 | 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'];
13595 anikendra 59
				$this->log(print_r($pushdata,1));
60
				$this->UserUrl->create();
61
				if ($this->UserUrl->saveAll($pushdata['pushdata'])) {
62
					$result = array('success' => true,'message'=>__('The url has been saved.'));
63
				} else {
64
					$result = array('success' => false,'message'=>__('The url could not be saved. Please, try again.'));
65
				}
14934 anikendra 66
				if(isset($pushdata['pushdata'][0]['httpstatus']) && !empty($pushdata['pushdata'][0]['httpstatus'])) {
67
					$this->loadModel('SaholicLog');
68
					$this->SaholicLog->create();
69
					$this->SaholicLog->saveAll($pushdata['pushdata']);
70
				}
13595 anikendra 71
				$this->response->type('json');
72
				$this->layout = 'ajax';
73
				$this->set(array(
74
				    'result' => $result,
75
				    // 'callback' => $callback,
76
				    '_serialize' => array('result')
77
				));
78
				$this->render('/Elements/json');
79
			}			
13591 anikendra 80
		}		
13532 anikendra 81
	}
82
 
83
/**
84
 * edit method
85
 *
86
 * @throws NotFoundException
87
 * @param string $id
88
 * @return void
89
 */
90
	public function edit($id = null) {
13591 anikendra 91
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 92
		if (!$this->UserUrl->exists($id)) {
93
			throw new NotFoundException(__('Invalid user url'));
94
		}
95
		if ($this->request->is(array('post', 'put'))) {
96
			if ($this->UserUrl->save($this->request->data)) {
97
				$this->Session->setFlash(__('The user url has been saved.'));
98
				return $this->redirect(array('action' => 'index'));
99
			} else {
100
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
101
			}
102
		} else {
103
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
104
			$this->request->data = $this->UserUrl->find('first', $options);
105
		}
106
		$users = $this->UserUrl->User->find('list');
107
		$this->set(compact('users'));
108
	}
109
 
110
/**
111
 * delete method
112
 *
113
 * @throws NotFoundException
114
 * @param string $id
115
 * @return void
116
 */
117
	public function delete($id = null) {
13591 anikendra 118
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 119
		$this->UserUrl->id = $id;
120
		if (!$this->UserUrl->exists()) {
121
			throw new NotFoundException(__('Invalid user url'));
122
		}
123
		$this->request->onlyAllow('post', 'delete');
124
		if ($this->UserUrl->delete()) {
125
			$this->Session->setFlash(__('The user url has been deleted.'));
126
		} else {
127
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
128
		}
129
		return $this->redirect(array('action' => 'index'));
130
	}
131
 
132
/**
133
 * admin_index method
134
 *
135
 * @return void
136
 */
137
	public function admin_index() {
138
		$this->UserUrl->recursive = 0;
14434 anikendra 139
		$q = $this->request->query('q');
140
		if(isset($q) && !empty($q)){
14654 anikendra 141
			$this->Paginator->settings = array('conditions' => array('UserUrl.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
142
 			$this->set(compact('q'));
143
		} else {
144
			$this->Paginator->settings = array('order' => array('id'=>'desc'));
145
 		}
13532 anikendra 146
		$this->set('userUrls', $this->Paginator->paginate());
147
	}
148
 
149
/**
150
 * admin_view method
151
 *
152
 * @throws NotFoundException
153
 * @param string $id
154
 * @return void
155
 */
156
	public function admin_view($id = null) {
157
		if (!$this->UserUrl->exists($id)) {
158
			throw new NotFoundException(__('Invalid user url'));
159
		}
160
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
161
		$this->set('userUrl', $this->UserUrl->find('first', $options));
162
	}
163
 
14401 anikendra 164
	public function admin_by($userId = null) {
165
		$options = array('conditions' => array('UserUrl.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
166
		$this->Paginator->settings = $options;
167
		$userUrls = $this->Paginator->paginate();		
168
		$this->set(compact('userUrls'));
169
	}
13532 anikendra 170
/**
171
 * admin_add method
172
 *
173
 * @return void
174
 */
175
	public function admin_add() {
176
		if ($this->request->is('post')) {
177
			$this->UserUrl->create();
178
			if ($this->UserUrl->save($this->request->data)) {
179
				$this->Session->setFlash(__('The user url has been saved.'));
180
				return $this->redirect(array('action' => 'index'));
181
			} else {
182
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
183
			}
184
		}
185
		$users = $this->UserUrl->User->find('list');
186
		$this->set(compact('users'));
187
	}
188
 
189
/**
190
 * admin_edit method
191
 *
192
 * @throws NotFoundException
193
 * @param string $id
194
 * @return void
195
 */
196
	public function admin_edit($id = null) {
197
		if (!$this->UserUrl->exists($id)) {
198
			throw new NotFoundException(__('Invalid user url'));
199
		}
200
		if ($this->request->is(array('post', 'put'))) {
201
			if ($this->UserUrl->save($this->request->data)) {
202
				$this->Session->setFlash(__('The user url has been saved.'));
203
				return $this->redirect(array('action' => 'index'));
204
			} else {
205
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
206
			}
207
		} else {
208
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
209
			$this->request->data = $this->UserUrl->find('first', $options);
210
		}
211
		$users = $this->UserUrl->User->find('list');
212
		$this->set(compact('users'));
213
	}
214
 
215
/**
216
 * admin_delete method
217
 *
218
 * @throws NotFoundException
219
 * @param string $id
220
 * @return void
221
 */
222
	public function admin_delete($id = null) {
223
		$this->UserUrl->id = $id;
224
		if (!$this->UserUrl->exists()) {
225
			throw new NotFoundException(__('Invalid user url'));
226
		}
227
		$this->request->onlyAllow('post', 'delete');
228
		if ($this->UserUrl->delete()) {
229
			$this->Session->setFlash(__('The user url has been deleted.'));
230
		} else {
231
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
232
		}
233
		return $this->redirect(array('action' => 'index'));
234
	}}