Subversion Repositories SmartDukaan

Rev

Rev 16910 | Details | Compare with Previous | 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)) {
16916 anikendra 68
				$this->loadModel('Appaclrevision');
69
				$historydata = $data;
70
				$historydata['modifier'] = $this->Auth->User('id');
71
				$historydata['timestamp'] = date('Y-m-d H:i:s',time());
72
				$this->Appaclrevision->create();
73
				$this->Appaclrevision->save($historydata);
16910 anikendra 74
				$this->Session->setFlash(__('The user has been activated.'));				
75
			} else {
76
				$this->Session->setFlash(__('The user could not be activated. Please, try again.'));
77
			}
78
		}		
79
		return $this->redirect($this->referer());
80
	}
81
 
82
/**
83
 * edit method
84
 *
85
 * @throws NotFoundException
86
 * @param string $id
87
 * @return void
88
 */
89
	public function admin_edit($id = null) {
90
		if (!$this->Appacl->exists($id)) {
91
			throw new NotFoundException(__('Invalid appacl'));
92
		}
93
		if ($this->request->is(array('post', 'put'))) {
94
			if ($this->Appacl->save($this->request->data)) {
95
				$this->Session->setFlash(__('The appacl has been saved.'));
96
				return $this->redirect(array('action' => 'index'));
97
			} else {
98
				$this->Session->setFlash(__('The appacl could not be saved. Please, try again.'));
99
			}
100
		} else {
101
			$options = array('conditions' => array('Appacl.' . $this->Appacl->primaryKey => $id));
102
			$this->request->data = $this->Appacl->find('first', $options);
103
		}
104
		$users = $this->Appacl->User->find('list');
105
		$this->set(compact('users'));
106
	}
107
 
108
/**
109
 * delete method
110
 *
111
 * @throws NotFoundException
112
 * @param string $id
113
 * @return void
114
 */
115
	public function admin_delete($id = null) {
116
		$this->Appacl->id = $id;
117
		if (!$this->Appacl->exists()) {
118
			throw new NotFoundException(__('Invalid appacl'));
119
		}
120
		$this->request->onlyAllow('post', 'delete');
121
		if ($this->Appacl->delete()) {
122
			$this->Session->setFlash(__('The appacl has been deleted.'));
123
		} else {
124
			$this->Session->setFlash(__('The appacl could not be deleted. Please, try again.'));
125
		}
126
		return $this->redirect(array('action' => 'index'));
127
	}
128
}