Guest User

Untitled

a guest
Aug 13th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2. App::uses('AppController', 'Controller');
  3. /**
  4.  * Comments Controller
  5.  *
  6.  * @property Comment $Comment
  7.  */
  8. class CommentsController extends AppController {
  9.  
  10. /**
  11. * Ajout de commentaire.
  12. **/
  13.   public function add($guestbook_id = null){
  14.     if(!$guestbook_id && !$this->request->is('post'))
  15.       throw new NotFoundException('Aucun message ne correspond à cet ID');
  16.     if($this->request->is('post')){
  17.       $last = $this->Comment->find('first',array(
  18.         'conditions'=>array('guestbook_id' => $guestbook_id),
  19.         'order' => 'created desc',
  20.         'recursive' => -1
  21.       ));
  22.       if($last['Comment']['clientip'] == $_SERVER['REMOTE_ADDR']){
  23.         $this->Session->setFlash("Vous ne pouvez pas poster 2 commentaires à la suite, veuillez attendre que quelqu'un post un commentaire","notif",array('type'=>'error'));
  24.         $this->redirect($this->referer());
  25.       } else {
  26.         $d = $this->request->data;
  27.         $d['Comment']['clientip'] = $_SERVER['REMOTE_ADDR'];
  28.         if($this->Comment->save($d,true,array('name','email','content','clientip','guestbook_id'))){
  29.           $this->Session->setFlash("Votre commentaire à bien été envoyé","notif");
  30.           $this->redirect($this->referer());
  31.         } else {
  32.           $this->Session->setFlash("Votre commentaire n'a pas pu être enregistré, veuillez réessayé","notif",array('type'=>'error'));
  33.           $this->redirect($this->referer());
  34.         }
  35.       }  
  36.     } else {
  37.       $d['guestbook_id'] = $guestbook_id;
  38.       $this->set($d);
  39.     }
  40.   }
Advertisement
Add Comment
Please, Sign In to add comment