Subversion Repositories SmartDukaan

Rev

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