Subversion Repositories SmartDukaan

Rev

Rev 13532 | Rev 13633 | 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
 * Orders Controller
5
 *
6
 * @property Order $Order
7
 * @property PaginatorComponent $Paginator
8
 */
9
class OrdersController 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
	}
22
 
13532 anikendra 23
/**
24
 * index method
25
 *
26
 * @return void
27
 */
28
	public function index() {
13591 anikendra 29
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 30
		$this->Order->recursive = 0;
31
		$this->set('orders', $this->Paginator->paginate());
32
	}
33
 
34
/**
35
 * view method
36
 *
37
 * @throws NotFoundException
38
 * @param string $id
39
 * @return void
40
 */
41
	public function view($id = null) {
13591 anikendra 42
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 43
		if (!$this->Order->exists($id)) {
44
			throw new NotFoundException(__('Invalid order'));
45
		}
46
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
47
		$this->set('order', $this->Order->find('first', $options));
48
	}
49
 
50
/**
51
 * add method
52
 *
53
 * @return void
54
 */
55
	public function add() {
56
		if ($this->request->is('post')) {
57
			$this->Order->create();
58
			if ($this->Order->save($this->request->data)) {
13591 anikendra 59
				$result =array('success'=>true,'message'=>__('The order has been saved.'));
13532 anikendra 60
			} else {
13591 anikendra 61
				$result = array('success'=>false,'message'=>__('The order could not be saved. Please, try again.'));
13532 anikendra 62
			}
13591 anikendra 63
			$this->response->type('json');
64
			$this->layout = 'ajax';
65
			$this->set(array(
66
			    'result' => $result,
67
			    // 'callback' => $callback,
68
			    '_serialize' => array('result')
69
			));
70
			$this->render('/Elements/json');		
71
		}			
13532 anikendra 72
	}
73
 
74
/**
75
 * edit method
76
 *
77
 * @throws NotFoundException
78
 * @param string $id
79
 * @return void
80
 */
81
	public function edit($id = null) {
13591 anikendra 82
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 83
		if (!$this->Order->exists($id)) {
84
			throw new NotFoundException(__('Invalid order'));
85
		}
86
		if ($this->request->is(array('post', 'put'))) {
87
			if ($this->Order->save($this->request->data)) {
88
				$this->Session->setFlash(__('The order has been saved.'));
89
				return $this->redirect(array('action' => 'index'));
90
			} else {
91
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
92
			}
93
		} else {
94
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
95
			$this->request->data = $this->Order->find('first', $options);
96
		}
97
		$users = $this->Order->User->find('list');
98
		$stores = $this->Order->Store->find('list');
99
		$storeOrders = $this->Order->StoreOrder->find('list');
100
		$this->set(compact('users', 'stores', 'storeOrders'));
101
	}
102
 
103
/**
104
 * delete method
105
 *
106
 * @throws NotFoundException
107
 * @param string $id
108
 * @return void
109
 */
110
	public function delete($id = null) {
13591 anikendra 111
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 112
		$this->Order->id = $id;
113
		if (!$this->Order->exists()) {
114
			throw new NotFoundException(__('Invalid order'));
115
		}
116
		$this->request->onlyAllow('post', 'delete');
117
		if ($this->Order->delete()) {
118
			$this->Session->setFlash(__('The order has been deleted.'));
119
		} else {
120
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
121
		}
122
		return $this->redirect(array('action' => 'index'));
123
	}
124
 
125
/**
126
 * admin_index method
127
 *
128
 * @return void
129
 */
130
	public function admin_index() {
131
		$this->Order->recursive = 0;
132
		$this->set('orders', $this->Paginator->paginate());
133
	}
134
 
135
/**
136
 * admin_view method
137
 *
138
 * @throws NotFoundException
139
 * @param string $id
140
 * @return void
141
 */
142
	public function admin_view($id = null) {
143
		if (!$this->Order->exists($id)) {
144
			throw new NotFoundException(__('Invalid order'));
145
		}
146
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
147
		$this->set('order', $this->Order->find('first', $options));
148
	}
149
 
150
/**
151
 * admin_add method
152
 *
153
 * @return void
154
 */
155
	public function admin_add() {
156
		if ($this->request->is('post')) {
157
			$this->Order->create();
158
			if ($this->Order->save($this->request->data)) {
159
				$this->Session->setFlash(__('The order has been saved.'));
160
				return $this->redirect(array('action' => 'index'));
161
			} else {
162
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
163
			}
164
		}
165
		$users = $this->Order->User->find('list');
166
		$stores = $this->Order->Store->find('list');
167
		$storeOrders = $this->Order->StoreOrder->find('list');
168
		$this->set(compact('users', 'stores', 'storeOrders'));
169
	}
170
 
171
/**
172
 * admin_edit method
173
 *
174
 * @throws NotFoundException
175
 * @param string $id
176
 * @return void
177
 */
178
	public function admin_edit($id = null) {
179
		if (!$this->Order->exists($id)) {
180
			throw new NotFoundException(__('Invalid order'));
181
		}
182
		if ($this->request->is(array('post', 'put'))) {
183
			if ($this->Order->save($this->request->data)) {
184
				$this->Session->setFlash(__('The order has been saved.'));
185
				return $this->redirect(array('action' => 'index'));
186
			} else {
187
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
188
			}
189
		} else {
190
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
191
			$this->request->data = $this->Order->find('first', $options);
192
		}
193
		$users = $this->Order->User->find('list');
194
		$stores = $this->Order->Store->find('list');
195
		$storeOrders = $this->Order->StoreOrder->find('list');
196
		$this->set(compact('users', 'stores', 'storeOrders'));
197
	}
198
 
199
/**
200
 * admin_delete method
201
 *
202
 * @throws NotFoundException
203
 * @param string $id
204
 * @return void
205
 */
206
	public function admin_delete($id = null) {
207
		$this->Order->id = $id;
208
		if (!$this->Order->exists()) {
209
			throw new NotFoundException(__('Invalid order'));
210
		}
211
		$this->request->onlyAllow('post', 'delete');
212
		if ($this->Order->delete()) {
213
			$this->Session->setFlash(__('The order has been deleted.'));
214
		} else {
215
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
216
		}
217
		return $this->redirect(array('action' => 'index'));
218
	}}