Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16910 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Appacls Controller
5
 *
6
 * @property Appacl $Appacl
7
 * @property PaginatorComponent $Paginator
8
 */
9
class AppaclsController 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 admin_index() {
24
		$this->Appacl->recursive = 0;
25
		$this->set('appacls', $this->Paginator->paginate());
26
	}
27
 
28
/**
29
 * view method
30
 *
31
 * @throws NotFoundException
32
 * @param string $id
33
 * @return void
34
 */
35
	public function admin_view($id = null) {
36
		if (!$this->Appacl->exists($id)) {
37
			throw new NotFoundException(__('Invalid appacl'));
38
		}
39
		$options = array('conditions' => array('Appacl.' . $this->Appacl->primaryKey => $id));
40
		$this->set('appacl', $this->Appacl->find('first', $options));
41
	}
42
 
43
/**
44
 * add method
45
 *
46
 * @return void
47
 */
48
	public function admin_add() {
49
		if ($this->request->is('post')) {
50
			$this->Appacl->create();
51
			if ($this->Appacl->save($this->request->data)) {
52
				$this->Session->setFlash(__('The appacl has been saved.'));
53
				return $this->redirect(array('action' => 'index'));
54
			} else {
55
				$this->Session->setFlash(__('The appacl could not be saved. Please, try again.'));
56
			}
57
		}
58
		$users = $this->Appacl->User->find('list');
59
		$this->set(compact('users'));
60
	}
61
 
62
	public function admin_activate($id) {
63
		$data = array('user_id'=>$id,'access'=>1);
64
		$count = $this->Appacl->find('count',array('conditions'=> $data));
65
		if($count==0){
66
			$this->Appacl->create();
67
			if ($this->Appacl->save($data)) {
68
				$this->Session->setFlash(__('The user has been activated.'));				
69
			} else {
70
				$this->Session->setFlash(__('The user could not be activated. Please, try again.'));
71
			}
72
		}		
73
		return $this->redirect($this->referer());
74
	}
75
 
76
/**
77
 * edit method
78
 *
79
 * @throws NotFoundException
80
 * @param string $id
81
 * @return void
82
 */
83
	public function admin_edit($id = null) {
84
		if (!$this->Appacl->exists($id)) {
85
			throw new NotFoundException(__('Invalid appacl'));
86
		}
87
		if ($this->request->is(array('post', 'put'))) {
88
			if ($this->Appacl->save($this->request->data)) {
89
				$this->Session->setFlash(__('The appacl has been saved.'));
90
				return $this->redirect(array('action' => 'index'));
91
			} else {
92
				$this->Session->setFlash(__('The appacl could not be saved. Please, try again.'));
93
			}
94
		} else {
95
			$options = array('conditions' => array('Appacl.' . $this->Appacl->primaryKey => $id));
96
			$this->request->data = $this->Appacl->find('first', $options);
97
		}
98
		$users = $this->Appacl->User->find('list');
99
		$this->set(compact('users'));
100
	}
101
 
102
/**
103
 * delete method
104
 *
105
 * @throws NotFoundException
106
 * @param string $id
107
 * @return void
108
 */
109
	public function admin_delete($id = null) {
110
		$this->Appacl->id = $id;
111
		if (!$this->Appacl->exists()) {
112
			throw new NotFoundException(__('Invalid appacl'));
113
		}
114
		$this->request->onlyAllow('post', 'delete');
115
		if ($this->Appacl->delete()) {
116
			$this->Session->setFlash(__('The appacl has been deleted.'));
117
		} else {
118
			$this->Session->setFlash(__('The appacl could not be deleted. Please, try again.'));
119
		}
120
		return $this->redirect(array('action' => 'index'));
121
	}
122
}