Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13745 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Feedbacks Controller
5
 *
6
 * @property Feedback $Feedback
7
 * @property PaginatorComponent $Paginator
8
 */
14484 anikendra 9
App::uses('CakeEmail', 'Network/Email');
10
 
13745 anikendra 11
class FeedbacksController extends AppController {
12
 
13
/**
14
 * Components
15
 *
16
 * @var array
17
 */
18
	public $components = array('Paginator');
19
 
20
	public function beforeFilter() {
21
		parent::beforeFilter();
22
		$this->Auth->allow('add');
23
	}
24
 
25
/**
26
 * index method
27
 *
28
 * @return void
29
 */
30
	public function index() {
31
		$this->Feedback->recursive = 0;
32
		$this->set('feedbacks', $this->Paginator->paginate());
33
	}
34
 
35
/**
36
 * view method
37
 *
38
 * @throws NotFoundException
39
 * @param string $id
40
 * @return void
41
 */
42
	public function view($id = null) {
43
		if (!$this->Feedback->exists($id)) {
44
			throw new NotFoundException(__('Invalid feedback'));
45
		}
46
		$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));
47
		$this->set('feedback', $this->Feedback->find('first', $options));
48
	}
49
 
50
/**
51
 * add method
52
 *
53
 * @return void
54
 */
55
	public function add() {
56
		$this->log(print_r($this->request->data,1),'feedbacks');
57
		if ($this->request->is('post')) {
58
			$this->Feedback->create();
59
			if ($this->Feedback->save($this->request->data)) {
14484 anikendra 60
				$emailConf = Configure::read('emails');
61
				$Email = new CakeEmail();
62
				$Email->from($emailConf['from']);
63
				$Email->to($emailConf['from']);
64
				$Email->cc($emailConf['cc']);
65
				$Email->subject('New Contact Us message');
66
				$message = "<ul style='list-style:none;'><li style='padding:10px 0;'>User Id : ".$this->request->data['Feedback']['user_id']."<li>";
67
				$message .= "<li>Email : ".$this->request->data['Feedback']['email']."<li>";
68
				$message .= "<li>Subject : ".$this->request->data['Feedback']['subject']."<li>";
69
				$message .= "<li>Message : ".$this->request->data['Feedback']['message']."<li></ul>";
70
				$Email->send($message);
13745 anikendra 71
				$result = array('success'=>true,'message'=>__('The feedback has been saved.'));
72
			} else {
73
				$result = array('success'=>false,'message'=>__('The feedback could not be saved. Please, try again.'));
74
			}
75
			$this->response->type('json');
76
			$this->layout = 'ajax';
77
			$this->set(array(
78
			    'result' => $result,
79
			    '_serialize' => array('result')
80
			));
81
			$this->render('/Elements/json');		
82
		}
83
	}
84
 
85
/**
86
 * edit method
87
 *
88
 * @throws NotFoundException
89
 * @param string $id
90
 * @return void
91
 */
92
	public function edit($id = null) {
93
		if (!$this->Feedback->exists($id)) {
94
			throw new NotFoundException(__('Invalid feedback'));
95
		}
96
		if ($this->request->is(array('post', 'put'))) {
97
			if ($this->Feedback->save($this->request->data)) {
98
				$this->Session->setFlash(__('The feedback has been saved.'));
99
				return $this->redirect(array('action' => 'index'));
100
			} else {
101
				$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));
102
			}
103
		} else {
104
			$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));
105
			$this->request->data = $this->Feedback->find('first', $options);
106
		}
107
		$users = $this->Feedback->User->find('list');
108
		$this->set(compact('users'));
109
	}
110
 
111
/**
112
 * delete method
113
 *
114
 * @throws NotFoundException
115
 * @param string $id
116
 * @return void
117
 */
118
	public function delete($id = null) {
119
		$this->Feedback->id = $id;
120
		if (!$this->Feedback->exists()) {
121
			throw new NotFoundException(__('Invalid feedback'));
122
		}
123
		$this->request->onlyAllow('post', 'delete');
124
		if ($this->Feedback->delete()) {
125
			$this->Session->setFlash(__('The feedback has been deleted.'));
126
		} else {
127
			$this->Session->setFlash(__('The feedback could not be deleted. Please, try again.'));
128
		}
129
		return $this->redirect(array('action' => 'index'));
130
	}
131
 
132
/**
133
 * admin_index method
134
 *
135
 * @return void
136
 */
137
	public function admin_index() {
138
		$this->Feedback->recursive = 0;
139
		$this->set('feedbacks', $this->Paginator->paginate());
140
	}
141
 
142
/**
143
 * admin_view method
144
 *
145
 * @throws NotFoundException
146
 * @param string $id
147
 * @return void
148
 */
149
	public function admin_view($id = null) {
150
		if (!$this->Feedback->exists($id)) {
151
			throw new NotFoundException(__('Invalid feedback'));
152
		}
153
		$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));
154
		$this->set('feedback', $this->Feedback->find('first', $options));
155
	}
156
 
157
/**
158
 * admin_add method
159
 *
160
 * @return void
161
 */
162
	public function admin_add() {
163
		if ($this->request->is('post')) {
164
			$this->Feedback->create();
165
			if ($this->Feedback->save($this->request->data)) {
166
				$this->Session->setFlash(__('The feedback has been saved.'));
167
				return $this->redirect(array('action' => 'index'));
168
			} else {
169
				$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));
170
			}
171
		}
172
		$users = $this->Feedback->User->find('list');
173
		$this->set(compact('users'));
174
	}
175
 
176
/**
177
 * admin_edit method
178
 *
179
 * @throws NotFoundException
180
 * @param string $id
181
 * @return void
182
 */
183
	public function admin_edit($id = null) {
184
		if (!$this->Feedback->exists($id)) {
185
			throw new NotFoundException(__('Invalid feedback'));
186
		}
187
		if ($this->request->is(array('post', 'put'))) {
188
			if ($this->Feedback->save($this->request->data)) {
189
				$this->Session->setFlash(__('The feedback has been saved.'));
190
				return $this->redirect(array('action' => 'index'));
191
			} else {
192
				$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));
193
			}
194
		} else {
195
			$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));
196
			$this->request->data = $this->Feedback->find('first', $options);
197
		}
198
		$users = $this->Feedback->User->find('list');
199
		$this->set(compact('users'));
200
	}
201
 
202
/**
203
 * admin_delete method
204
 *
205
 * @throws NotFoundException
206
 * @param string $id
207
 * @return void
208
 */
209
	public function admin_delete($id = null) {
210
		$this->Feedback->id = $id;
211
		if (!$this->Feedback->exists()) {
212
			throw new NotFoundException(__('Invalid feedback'));
213
		}
214
		$this->request->onlyAllow('post', 'delete');
215
		if ($this->Feedback->delete()) {
216
			$this->Session->setFlash(__('The feedback has been deleted.'));
217
		} else {
218
			$this->Session->setFlash(__('The feedback could not be deleted. Please, try again.'));
219
		}
220
		return $this->redirect(array('action' => 'index'));
221
	}}