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; } } }
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 edit($id = null) { $this->set('title_for_layout', ' Edit Author'); $success_message = ''; if ($this->request->isPost()) { if (isset($this->data['cancel'])) { $this->redirect(ADMIN_ROOT_URL . 'adminauthor/index'); return; } if (isset($this->data['editauthor'])) { 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_AUTHOR, $this->params['form']['image'], $id, $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 = $id . '.' . $this->img_check_pattern['ext']; $this->Author->save(array('id_author' => $id, 'img' => $img)); } } $this->Author->save(array('id_author' => $id, 'name' => $this->request->data('name'), 'biography' => $this->request->data('biography'))); $success_message = 'Update succeed。'; $this->Session->setFlash(GlobalVar::get_html_success($success_message)); } } $authorupdate = $this->Author->find('first', array('conditions' => array('id_author' => $id))); $this->set('Author', $authorupdate); }
public function add() { $this->set('title_for_layout', ' Add User'); $success_message = ''; if ($this->request->isPost()) { if (isset($this->data['cancel'])) { $this->redirect(ADMIN_ROOT_URL . 'adminusers/index'); return; } if (isset($this->data['adduser'])) { 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_USER, $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->User->save(array('id_user' => $this->request->data('id_user'), 'username' => $this->request->data('username'), 'password' => sha1($this->request->data('password')), 'birth' => $this->request->data('birth'), 'mail' => $this->request->data('mail'), 'sex' => $this->request->data('gender'), 'mail' => $this->request->data('mail'), 'facebook' => $this->request->data('facebook'), 'balance' => $this->request->data('balance'), 'created' => $this->request->data('created'), 'nearest' => $this->request->data('nearest')))) { $success_message = 'Add succeed。'; $this->Session->setFlash(GlobalVar::get_html_success($success_message)); } else { $success_message = 'Add failed。'; $this->Session->setFlash(GlobalVar::get_html_success($success_message)); } } } }