| 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();
|
| 18638 |
manas |
22 |
$this->Auth->allow('add','crm_mail');
|
| 13745 |
anikendra |
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)) {
|
| 14533 |
anikendra |
60 |
$this->loadModel('User');
|
|
|
61 |
$this->User->recursive = -1;
|
| 14654 |
anikendra |
62 |
$user = $this->User->findById($this->request->data['user_id']);
|
| 14484 |
anikendra |
63 |
$emailConf = Configure::read('emails');
|
| 14490 |
anikendra |
64 |
$Email = new CakeEmail('smtp');
|
| 14484 |
anikendra |
65 |
$Email->from($emailConf['from']);
|
| 14490 |
anikendra |
66 |
$Email->to($emailConf['to']);
|
| 14484 |
anikendra |
67 |
$Email->cc($emailConf['cc']);
|
|
|
68 |
$Email->subject('New Contact Us message');
|
| 14490 |
anikendra |
69 |
$message = "User Id : ".$this->request->data['user_id']."\n\n";
|
|
|
70 |
$message .= "Email : ".$this->request->data['email']."\n\n";
|
| 14533 |
anikendra |
71 |
$message .= "Mobile : ".$user['User']['mobile_number']."\n\n";
|
|
|
72 |
$message .= "Mobile Verified : ".($user['User']['mobile_verified']==1)?'Yes':'No'."\n\n";
|
| 14490 |
anikendra |
73 |
$message .= "Subject : ".$this->request->data['subject']."\n\n";
|
|
|
74 |
$message .= "Message : ".$this->request->data['message']."\n\n";
|
| 14484 |
anikendra |
75 |
$Email->send($message);
|
| 13745 |
anikendra |
76 |
$result = array('success'=>true,'message'=>__('The feedback has been saved.'));
|
|
|
77 |
} else {
|
|
|
78 |
$result = array('success'=>false,'message'=>__('The feedback could not be saved. Please, try again.'));
|
|
|
79 |
}
|
|
|
80 |
$this->response->type('json');
|
|
|
81 |
$this->layout = 'ajax';
|
|
|
82 |
$this->set(array(
|
|
|
83 |
'result' => $result,
|
|
|
84 |
'_serialize' => array('result')
|
|
|
85 |
));
|
|
|
86 |
$this->render('/Elements/json');
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* edit method
|
|
|
92 |
*
|
|
|
93 |
* @throws NotFoundException
|
|
|
94 |
* @param string $id
|
|
|
95 |
* @return void
|
|
|
96 |
*/
|
|
|
97 |
public function edit($id = null) {
|
|
|
98 |
if (!$this->Feedback->exists($id)) {
|
|
|
99 |
throw new NotFoundException(__('Invalid feedback'));
|
|
|
100 |
}
|
|
|
101 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
102 |
if ($this->Feedback->save($this->request->data)) {
|
|
|
103 |
$this->Session->setFlash(__('The feedback has been saved.'));
|
|
|
104 |
return $this->redirect(array('action' => 'index'));
|
|
|
105 |
} else {
|
|
|
106 |
$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));
|
|
|
107 |
}
|
|
|
108 |
} else {
|
|
|
109 |
$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));
|
|
|
110 |
$this->request->data = $this->Feedback->find('first', $options);
|
|
|
111 |
}
|
|
|
112 |
$users = $this->Feedback->User->find('list');
|
|
|
113 |
$this->set(compact('users'));
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* delete method
|
|
|
118 |
*
|
|
|
119 |
* @throws NotFoundException
|
|
|
120 |
* @param string $id
|
|
|
121 |
* @return void
|
|
|
122 |
*/
|
|
|
123 |
public function delete($id = null) {
|
|
|
124 |
$this->Feedback->id = $id;
|
|
|
125 |
if (!$this->Feedback->exists()) {
|
|
|
126 |
throw new NotFoundException(__('Invalid feedback'));
|
|
|
127 |
}
|
|
|
128 |
$this->request->onlyAllow('post', 'delete');
|
|
|
129 |
if ($this->Feedback->delete()) {
|
|
|
130 |
$this->Session->setFlash(__('The feedback has been deleted.'));
|
|
|
131 |
} else {
|
|
|
132 |
$this->Session->setFlash(__('The feedback could not be deleted. Please, try again.'));
|
|
|
133 |
}
|
|
|
134 |
return $this->redirect(array('action' => 'index'));
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* admin_index method
|
|
|
139 |
*
|
|
|
140 |
* @return void
|
|
|
141 |
*/
|
|
|
142 |
public function admin_index() {
|
|
|
143 |
$this->Feedback->recursive = 0;
|
|
|
144 |
$this->set('feedbacks', $this->Paginator->paginate());
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
/**
|
|
|
148 |
* admin_view method
|
|
|
149 |
*
|
|
|
150 |
* @throws NotFoundException
|
|
|
151 |
* @param string $id
|
|
|
152 |
* @return void
|
|
|
153 |
*/
|
|
|
154 |
public function admin_view($id = null) {
|
|
|
155 |
if (!$this->Feedback->exists($id)) {
|
|
|
156 |
throw new NotFoundException(__('Invalid feedback'));
|
|
|
157 |
}
|
|
|
158 |
$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));
|
|
|
159 |
$this->set('feedback', $this->Feedback->find('first', $options));
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
/**
|
|
|
163 |
* admin_add method
|
|
|
164 |
*
|
|
|
165 |
* @return void
|
|
|
166 |
*/
|
|
|
167 |
public function admin_add() {
|
|
|
168 |
if ($this->request->is('post')) {
|
|
|
169 |
$this->Feedback->create();
|
|
|
170 |
if ($this->Feedback->save($this->request->data)) {
|
|
|
171 |
$this->Session->setFlash(__('The feedback has been saved.'));
|
|
|
172 |
return $this->redirect(array('action' => 'index'));
|
|
|
173 |
} else {
|
|
|
174 |
$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
$users = $this->Feedback->User->find('list');
|
|
|
178 |
$this->set(compact('users'));
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
/**
|
|
|
182 |
* admin_edit method
|
|
|
183 |
*
|
|
|
184 |
* @throws NotFoundException
|
|
|
185 |
* @param string $id
|
|
|
186 |
* @return void
|
|
|
187 |
*/
|
|
|
188 |
public function admin_edit($id = null) {
|
|
|
189 |
if (!$this->Feedback->exists($id)) {
|
|
|
190 |
throw new NotFoundException(__('Invalid feedback'));
|
|
|
191 |
}
|
|
|
192 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
193 |
if ($this->Feedback->save($this->request->data)) {
|
|
|
194 |
$this->Session->setFlash(__('The feedback has been saved.'));
|
|
|
195 |
return $this->redirect(array('action' => 'index'));
|
|
|
196 |
} else {
|
|
|
197 |
$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));
|
|
|
198 |
}
|
|
|
199 |
} else {
|
|
|
200 |
$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));
|
|
|
201 |
$this->request->data = $this->Feedback->find('first', $options);
|
|
|
202 |
}
|
|
|
203 |
$users = $this->Feedback->User->find('list');
|
|
|
204 |
$this->set(compact('users'));
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
/**
|
|
|
208 |
* admin_delete method
|
|
|
209 |
*
|
|
|
210 |
* @throws NotFoundException
|
|
|
211 |
* @param string $id
|
|
|
212 |
* @return void
|
|
|
213 |
*/
|
|
|
214 |
public function admin_delete($id = null) {
|
|
|
215 |
$this->Feedback->id = $id;
|
|
|
216 |
if (!$this->Feedback->exists()) {
|
|
|
217 |
throw new NotFoundException(__('Invalid feedback'));
|
|
|
218 |
}
|
|
|
219 |
$this->request->onlyAllow('post', 'delete');
|
|
|
220 |
if ($this->Feedback->delete()) {
|
|
|
221 |
$this->Session->setFlash(__('The feedback has been deleted.'));
|
|
|
222 |
} else {
|
|
|
223 |
$this->Session->setFlash(__('The feedback could not be deleted. Please, try again.'));
|
|
|
224 |
}
|
|
|
225 |
return $this->redirect(array('action' => 'index'));
|
| 18638 |
manas |
226 |
}
|
|
|
227 |
|
|
|
228 |
public function crm_mail(){
|
| 20394 |
amit.gupta |
229 |
//$this->log(print_r($this->request->data,1),'feedbacks');
|
| 18638 |
manas |
230 |
$this->loadModel('User');
|
|
|
231 |
$this->User->recursive = -1;
|
|
|
232 |
$user = $this->User->findById($this->request->data['user_id']);
|
|
|
233 |
$emailConf = Configure::read('emailsCrm');
|
|
|
234 |
$Email = new CakeEmail('smtp');
|
|
|
235 |
$Email->from($emailConf['from']);
|
|
|
236 |
$Email->to($emailConf['to']);
|
|
|
237 |
$Email->cc($emailConf['cc']);
|
| 18641 |
manas |
238 |
$Email->subject($this->request->data['subject']);
|
| 18638 |
manas |
239 |
$message = "User Id : ".$this->request->data['user_id']."\n\n";
|
|
|
240 |
$message .= "Email : ".$user['User']['email']."\n\n";
|
|
|
241 |
$message .= "Mobile : ".$user['User']['mobile_number']."\n\n";
|
|
|
242 |
$message .= "Subject : ".$this->request->data['subject']."\n\n";
|
|
|
243 |
$message .= "Message : ".$this->request->data['message']."\n\n";
|
|
|
244 |
$Email->send($message);
|
| 18870 |
manas |
245 |
$result = array('success'=>true,'message'=>__('The feedback has been saved.'));
|
|
|
246 |
$this->response->type('json');
|
|
|
247 |
$this->layout = 'ajax';
|
|
|
248 |
$this->set(array(
|
|
|
249 |
'result' => $result,
|
|
|
250 |
'_serialize' => array('result')
|
|
|
251 |
));
|
|
|
252 |
$this->render('/Elements/json');
|
| 18638 |
manas |
253 |
}
|
|
|
254 |
}
|