Subversion Repositories SmartDukaan

Rev

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