Rev 18638 | Rev 18870 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Feedbacks Controller** @property Feedback $Feedback* @property PaginatorComponent $Paginator*/App::uses('CakeEmail', 'Network/Email');class FeedbacksController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function beforeFilter() {parent::beforeFilter();$this->Auth->allow('add','crm_mail');}/*** index method** @return void*/public function index() {$this->Feedback->recursive = 0;$this->set('feedbacks', $this->Paginator->paginate());}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {if (!$this->Feedback->exists($id)) {throw new NotFoundException(__('Invalid feedback'));}$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));$this->set('feedback', $this->Feedback->find('first', $options));}/*** add method** @return void*/public function add() {$this->log(print_r($this->request->data,1),'feedbacks');if ($this->request->is('post')) {$this->Feedback->create();if ($this->Feedback->save($this->request->data)) {$this->loadModel('User');$this->User->recursive = -1;$user = $this->User->findById($this->request->data['user_id']);$emailConf = Configure::read('emails');$Email = new CakeEmail('smtp');$Email->from($emailConf['from']);$Email->to($emailConf['to']);$Email->cc($emailConf['cc']);$Email->subject('New Contact Us message');$message = "User Id : ".$this->request->data['user_id']."\n\n";$message .= "Email : ".$this->request->data['email']."\n\n";$message .= "Mobile : ".$user['User']['mobile_number']."\n\n";$message .= "Mobile Verified : ".($user['User']['mobile_verified']==1)?'Yes':'No'."\n\n";$message .= "Subject : ".$this->request->data['subject']."\n\n";$message .= "Message : ".$this->request->data['message']."\n\n";$Email->send($message);$result = array('success'=>true,'message'=>__('The feedback has been saved.'));} else {$result = array('success'=>false,'message'=>__('The feedback could not be saved. Please, try again.'));}$this->response->type('json');$this->layout = 'ajax';$this->set(array('result' => $result,'_serialize' => array('result')));$this->render('/Elements/json');}}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {if (!$this->Feedback->exists($id)) {throw new NotFoundException(__('Invalid feedback'));}if ($this->request->is(array('post', 'put'))) {if ($this->Feedback->save($this->request->data)) {$this->Session->setFlash(__('The feedback has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));$this->request->data = $this->Feedback->find('first', $options);}$users = $this->Feedback->User->find('list');$this->set(compact('users'));}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {$this->Feedback->id = $id;if (!$this->Feedback->exists()) {throw new NotFoundException(__('Invalid feedback'));}$this->request->onlyAllow('post', 'delete');if ($this->Feedback->delete()) {$this->Session->setFlash(__('The feedback has been deleted.'));} else {$this->Session->setFlash(__('The feedback could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {$this->Feedback->recursive = 0;$this->set('feedbacks', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->Feedback->exists($id)) {throw new NotFoundException(__('Invalid feedback'));}$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));$this->set('feedback', $this->Feedback->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {if ($this->request->is('post')) {$this->Feedback->create();if ($this->Feedback->save($this->request->data)) {$this->Session->setFlash(__('The feedback has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));}}$users = $this->Feedback->User->find('list');$this->set(compact('users'));}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {if (!$this->Feedback->exists($id)) {throw new NotFoundException(__('Invalid feedback'));}if ($this->request->is(array('post', 'put'))) {if ($this->Feedback->save($this->request->data)) {$this->Session->setFlash(__('The feedback has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The feedback could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Feedback.' . $this->Feedback->primaryKey => $id));$this->request->data = $this->Feedback->find('first', $options);}$users = $this->Feedback->User->find('list');$this->set(compact('users'));}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->Feedback->id = $id;if (!$this->Feedback->exists()) {throw new NotFoundException(__('Invalid feedback'));}$this->request->onlyAllow('post', 'delete');if ($this->Feedback->delete()) {$this->Session->setFlash(__('The feedback has been deleted.'));} else {$this->Session->setFlash(__('The feedback could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}public function crm_mail(){$this->log(print_r($this->request->data,1),'feedbacks');$this->loadModel('User');$this->User->recursive = -1;$user = $this->User->findById($this->request->data['user_id']);$emailConf = Configure::read('emailsCrm');$Email = new CakeEmail('smtp');$Email->from($emailConf['from']);$Email->to($emailConf['to']);$Email->cc($emailConf['cc']);$Email->subject($this->request->data['subject']);$message = "User Id : ".$this->request->data['user_id']."\n\n";$message .= "Email : ".$user['User']['email']."\n\n";$message .= "Mobile : ".$user['User']['mobile_number']."\n\n";$message .= "Subject : ".$this->request->data['subject']."\n\n";$message .= "Message : ".$this->request->data['message']."\n\n";$Email->send($message);}}