Subversion Repositories SmartDukaan

Rev

Rev 15194 | Rev 15227 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15194 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Acls Controller
5
 *
6
 * @property Acl $Acl
7
 * @property PaginatorComponent $Paginator
8
 */
9
class AclsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
/**
19
 * index method
20
 *
21
 * @return void
22
 */
23
	public function index() {
24
		$this->Acl->recursive = 0;
25
		$this->set('acls', $this->Paginator->paginate());
15222 anikendra 26
	}	
15194 anikendra 27
 
28
/**
29
 * view method
30
 *
31
 * @throws NotFoundException
32
 * @param string $id
33
 * @return void
34
 */
35
	public function view($id = null) {
36
		if (!$this->Acl->exists($id)) {
37
			throw new NotFoundException(__('Invalid acl'));
38
		}
39
		$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
40
		$this->set('acl', $this->Acl->find('first', $options));
41
	}
42
 
43
/**
44
 * add method
45
 *
46
 * @return void
47
 */
48
	public function add() {
49
		if ($this->request->is('post')) {
50
			$this->Acl->create();
51
			if ($this->Acl->save($this->request->data)) {
52
				$this->Session->setFlash(__('The acl has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
56
			}
57
		}
58
		Cache::delete('acls');
59
		$groups = $this->Acl->Group->find('list');
60
		$this->set(compact('groups'));
61
	}
62
 
63
/**
64
 * edit method
65
 *
66
 * @throws NotFoundException
67
 * @param string $id
68
 * @return void
69
 */
70
	public function edit($id = null) {
71
		if (!$this->Acl->exists($id)) {
72
			throw new NotFoundException(__('Invalid acl'));
73
		}
74
		if ($this->request->is(array('post', 'put'))) {
75
			if ($this->Acl->save($this->request->data)) {
76
				$this->Session->setFlash(__('The acl has been saved.'));
77
				return $this->redirect(array('action' => 'index'));
78
			} else {
79
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
80
			}
81
		} else {
82
			$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
83
			$this->request->data = $this->Acl->find('first', $options);
84
		}
85
		$groups = $this->Acl->Group->find('list');
86
		$this->set(compact('groups'));
87
	}
88
 
89
/**
90
 * delete method
91
 *
92
 * @throws NotFoundException
93
 * @param string $id
94
 * @return void
95
 */
96
	public function delete($id = null) {
97
		$this->Acl->id = $id;
98
		if (!$this->Acl->exists()) {
99
			throw new NotFoundException(__('Invalid acl'));
100
		}
101
		$this->request->onlyAllow('post', 'delete');
102
		if ($this->Acl->delete()) {
103
			$this->Session->setFlash(__('The acl has been deleted.'));
104
		} else {
105
			$this->Session->setFlash(__('The acl could not be deleted. Please, try again.'));
106
		}
107
		return $this->redirect(array('action' => 'index'));
108
	}
109
 
110
/**
111
 * admin_index method
112
 *
113
 * @return void
114
 */
115
	public function admin_index() {
116
		$this->Acl->recursive = 0;
117
		$this->set('permissions', $this->Paginator->paginate());
118
	}
119
 
15222 anikendra 120
	public function admin_group($id) {
121
		$this->Acl->recursive = 0;
122
		$options = array('conditions'=>array('group_id'=>$id));
123
		$this->Paginator->settings = $options;
124
		$this->set('permissions', $this->Paginator->paginate());
125
		$this->render('admin_index');
126
	}
127
 
15194 anikendra 128
/**
129
 * admin_view method
130
 *
131
 * @throws NotFoundException
132
 * @param string $id
133
 * @return void
134
 */
135
	public function admin_view($id = null) {
136
		if (!$this->Acl->exists($id)) {
137
			throw new NotFoundException(__('Invalid acl'));
138
		}
139
		$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
140
		$this->set('acl', $this->Acl->find('first', $options));
141
	}
142
 
143
/**
144
 * admin_add method
145
 *
146
 * @return void
147
 */
148
	public function admin_add() {
149
		if ($this->request->is('post')) {
150
			$this->Acl->create();
151
			if ($this->Acl->save($this->request->data)) {
152
				$this->Session->setFlash(__('The acl has been saved.'));
153
				Cache::delete('acls','month');
154
				return $this->redirect(array('action' => 'index'));
155
			} else {
156
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
157
			}
158
		}		
159
		$groups = $this->Acl->Group->find('list');
160
		$this->set(compact('groups'));
161
	}
162
 
163
/**
164
 * admin_edit method
165
 *
166
 * @throws NotFoundException
167
 * @param string $id
168
 * @return void
169
 */
170
	public function admin_edit($id = null) {
171
		if (!$this->Acl->exists($id)) {
172
			throw new NotFoundException(__('Invalid acl'));
173
		}
174
		if ($this->request->is(array('post', 'put'))) {
175
			if ($this->Acl->save($this->request->data)) {
176
				$this->Session->setFlash(__('The acl has been saved.'));
177
				Cache::delete('acls','month');
178
				return $this->redirect(array('action' => 'index'));
179
			} else {
180
				$this->Session->setFlash(__('The acl could not be saved. Please, try again.'));
181
			}
182
		} else {
183
			$options = array('conditions' => array('Acl.' . $this->Acl->primaryKey => $id));
184
			$this->request->data = $this->Acl->find('first', $options);
185
		}		
186
		$groups = $this->Acl->Group->find('list');
187
		$this->set(compact('groups'));
188
	}
189
 
190
/**
191
 * admin_delete method
192
 *
193
 * @throws NotFoundException
194
 * @param string $id
195
 * @return void
196
 */
197
	public function admin_delete($id = null) {
198
		$this->Acl->id = $id;
199
		if (!$this->Acl->exists()) {
200
			throw new NotFoundException(__('Invalid acl'));
201
		}
202
		$this->request->onlyAllow('post', 'delete');
203
		if ($this->Acl->delete()) {
204
			$this->Session->setFlash(__('The acl has been deleted.'));
205
		} else {
206
			$this->Session->setFlash(__('The acl could not be deleted. Please, try again.'));
207
		}
208
		return $this->redirect(array('action' => 'index'));
209
	}}