public function edit($id_user)
 {
     if ($this->request->isPost()) {
         $data = $this->request->data('user');
         $pass = $this->request->data('password');
         if ($pass != '') {
             $data['User']['password'] = md5($pass);
         }
         if ($this->User->save($data)) {
             $this->Session->setFlash(GlobalVar::get_html_success('Update profile successful'));
         } else {
             $this->Session->setFlash(GlobalVar::get_html_error('Update profile failed'));
         }
     }
     if ($user = $this->User->find('first', array('conditions' => array('id_user' => $id_user)))) {
         $this->set('Profile', $user);
     } else {
         $this->redirect(ROOT_URL . 'book/index');
     }
 }
 public function add()
 {
     $this->set('title_for_layout', 'Add Book');
     if ($this->request->isPost()) {
         if ($this->Author->find('first', array('conditions' => array('id_author' => $this->request->data['id_author'])))) {
             if (!$this->Book->find('first', array('conditions' => array('id_book' => $this->request->data['id_book'])))) {
                 if (isset($this->params['form']['image']['name']) && !empty($this->params['form']['image']['name'])) {
                     $new_name = $this->params['form']['image']['name'];
                     $uploader = new ImageUploader(IMAGE_UPLOAD_PATH_BOOK, $this->params['form']['image'], $this->request->data('id_user'), $this->img_check_pattern);
                     $upload_result = $uploader->upload();
                     if (!$upload_result) {
                         $upload_image_err = $uploader->get_error_message();
                         $msg = "You can not upload images。";
                         $this->set('errors_image', $upload_image_err);
                     } else {
                         $img = $this->request->data('id_user') . '.' . $this->img_check_pattern['ext'];
                         $this->User->save(array('id_user' => $this->request->data('id_user'), 'avatar' => $img));
                     }
                     if ($this->Wrote->save(array('id_author' => $this->request->data('id_author'), 'id_book' => $this->request->data('id_book')))) {
                         $remain = $this->request->data('price') * (100 - $this->request->data('remain')) / 100;
                         if (!$this->request->data('adult')) {
                             $adult = 0;
                         } else {
                             $adult = $this->request->data('adult');
                         }
                         if (!$this->request->data('ebook')) {
                             $adult = 0;
                         } else {
                             $adult = $this->request->data('ebook');
                         }
                         if ($this->request->data('book')) {
                             $adult = 1;
                         } else {
                             $adult = $this->request->data('book');
                         }
                         if ($this->Book->save(array('id_book' => $this->request->data('id_book'), 'name' => $this->request->data('name'), 'description' => $this->request->data('description'), 'descriptionpro' => $this->request->data('descriptionpro'), 'description404' => $this->request->data('description404'), 'sale' => $this->request->data('remain'), 'price' => $this->request->data('price'), 'remain' => $remain, 'adult' => $this->request->data('adult'), 'ebook' => $this->request->data('ebook'), 'book' => $this->request->data('book')))) {
                             $this->Session->setFlash(GlobalVar::get_html_success("Add Book succeed"));
                             $this->redirect(ADMIN_ROOT_URL . 'adminbook/index');
                             exit;
                         } else {
                             $this->Session->setFlash(GlobalVar::get_html_error("This author's id  not existed "));
                             exit;
                         }
                     } else {
                         $this->Session->setFlash(GlobalVar::get_html_error("This author's id  not existed "));
                         exit;
                     }
                 }
             }
         } else {
             $this->Session->setFlash(GlobalVar::get_html_error("This author's id  not existed "));
             exit;
         }
     }
 }