public function get($bid, $name = null)
 {
     $_action = 'show';
     $_viewtype = 'book/show';
     $_viewdata = array('env' => $this->_env, 'action' => $_action, 'book_id' => $bid);
     $book = Book::find($bid);
     if (!$book) {
         // On vérifie si le livre existe en bdd, sinon erreur
         $_viewtype = 'error/nobook';
     } else {
         if (!$name) {
             // s'il n'y a pas de parametre name, on redirect avec le name
             $urlname = $book->urlname;
             return Redirect::to('book/' . $bid . '/' . $urlname . '/');
         } else {
             $db_urlname = $book->urlname;
             if ($db_urlname !== $name) {
                 // si le name en parametre n'est pas le meme qu'en base,
                 // on redirect avec le name de la bdd
                 return Redirect::to('book/' . $bid . '/' . $db_urlname . '/');
             } else {
                 // enfin OKLM
                 $_viewdata['author'] = Traveler::where('id', '=', $book->traveler_id)->first();
                 $_viewdata['book'] = $book;
                 $_viewdata['chapters'] = Chapter::where('book_id', '=', $bid)->get();
             }
         }
     }
     return View::make($_viewtype, $_viewdata);
 }
 public function get($bid, $name = null, $chid = 1)
 {
     $_action = 'show';
     $_viewtype = 'chapter/show';
     $_viewdata = array('env' => $this->_env, 'action' => $_action, 'book_id' => $bid, 'chapter_id' => $chid);
     if (!Book::find($bid)) {
         // On vérifie si le livre existe en bdd, sinon erreur
         $_viewtype = 'error/nobook';
     } else {
         if (!isset($name)) {
             // s'il n'y a pas de parametre name, on redirect avec le name
             $book = Book::find($bid);
             $urlname = $book->urlname;
             return Redirect::to('book/' . $bid . '/' . $urlname . '/chapter/' . $chid);
         } else {
             if (!Chapter::find($chid)) {
                 $_viewtype = 'error/nochapter';
             } else {
                 // on récupère l'urlname pour comparer à celui en parametre
                 $book = Book::find($bid);
                 $db_urlname = $book->urlname;
                 if ($db_urlname !== $name) {
                     // si le name en parametre n'est pas le meme qu'en base,
                     // on redirect avec le name de la bdd
                     return Redirect::to('book/' . $bid . '/' . $db_urlname . '/chapter/' . $chid);
                 } else {
                     $author = Traveler::where('id', '=', $book->traveler_id)->first();
                     $chapters = Chapter::where('book_id', '=', $bid)->get();
                     $_viewdata['book'] = $book;
                     $_viewdata['author'] = $author;
                     $_viewdata['chapters'] = $chapters;
                     if ($chapter = Chapter::where('book_id', '=', $bid)->where('id', '=', $chid)->first()) {
                         // chapitre spécifié existe
                         $elements = Element::where('chapter_id', '=', $chid)->orderBy('order', 'ASC')->get();
                         //var_dump(Request::ajax());
                         $_viewtype = Request::ajax() == true ? 'chapter/show-ajax' : 'chapter/show';
                         $_viewdata['chapter'] = $chapter;
                         $_viewdata['elements'] = $elements;
                     } else {
                         // chapitre spécifié n'existe pas
                         $_viewtype = 'error/nochapter';
                     }
                     // on retourne le livre
                     //Redirect::to('book/'.$bid.'/'.$db_urlname);
                 }
             }
         }
     }
     return View::make($_viewtype, $_viewdata);
 }
 public function signUp()
 {
     $_action = 'signup';
     $_viewtype = 'traveler/signin';
     $_viewdata = array('env' => $this->_env, 'action' => $_action);
     if (Auth::check()) {
         return Redirect::to('me/');
     } else {
         if (Request::isMethod('post')) {
             // pas connecté
             if (Request::isMethod('post')) {
                 $email = Input::get('email');
                 $username = Input::get('username');
                 $password = Input::get('password');
                 $dbuser = Traveler::where('email', '=', $email)->first();
                 if ($dbuser) {
                     // user existant
                     $_viewdata['error'] = array('code' => "emailused");
                 } else {
                     if (!Traveler::where('email', '=', $email)->first()) {
                         // ok create
                         $user = new Traveler();
                         $user->email = $email;
                         $user->username = $username;
                         $user->password = sha1($password);
                         $user->save();
                         Auth::login($user);
                         return Redirect::to('me/');
                     }
                 }
             }
             if (Request::isMethod('get') || Request::isMethod('post')) {
                 return View::make($_viewtype, $_viewdata);
             }
         }
     }
 }