public function suaSanPhamAction() { $id = $this->params('id'); $id_kho = $this->AuthService()->getIdKho(); $return = array('id' => $id); $san_pham_table = $this->getServiceLocator()->get('Application\\Model\\SanPhamTable'); // kiểm tra sản phẩm tồn tại $san_pham = $san_pham_table->getSanPhamByArrayConditionAndArrayColumn(array('id_san_pham' => $id, 'id_kho' => $id_kho, 'state' => 1), array()); if (!$san_pham) { $this->flashMessenger()->addErrorMessage('Sản phẩm không tồn tại'); return $this->redirect()->toRoute('hang_hoa'); } // get giá xuất $kenh_phan_phoi_table = $this->getServiceLocator()->get('Application\\Model\\KenhPhanPhoiTable'); $gia_xuat = $kenh_phan_phoi_table->getIdKenhPhanPhoiAndGiaXuatByIdKhoAndIdSanPham(array('id_kho' => $id_kho, 'id_san_pham' => $id)); $return['gia_xuat'] = $gia_xuat; $return['hinh_anh'] = $san_pham[0]['hinh_anh']; //tạo form $form = $this->getServiceLocator()->get('Application\\Form\\SuaSanPhamForm'); $form->setData($san_pham[0]); $form->setData($gia_xuat); $return['form'] = $form; $request = $this->getRequest(); if ($request->isPost()) { $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setData($post); if ($form->isValid()) { $san_pham_moi = new SanPham(); $user_id = $this->AuthService()->getUserId(); $data = array_merge($san_pham[0], $post); $san_pham_moi->exchangeArray($data); // nếu sửa mã vạch if ($san_pham[0]['ma_vach'] != $post['ma_vach'] and $post['ma_vach']) { // nếu nhập mã vạch thì phải kiểm tra có tồn tại chưa $san_pham_ton_tai = $san_pham_table->getSanPhamByArrayConditionAndArrayColumn(array('id_kho' => $id_kho, 'ma_vach' => $post['ma_vach']), array('id_san_pham')); if ($san_pham_ton_tai) { $form->get('ma_vach')->setMessages(array('Mã vạch này đã được sử dụng')); $return['form'] = $form; return $return; } $san_pham_moi->setIdBarcode(6); } else { $san_pham_moi->setMaVach($san_pham[0]['ma_vach']); } // nếu sửa mã sản phẩm if ($san_pham[0]['ma_san_pham'] != $post['ma_san_pham'] and $post['ma_san_pham']) { // nếu nhập mã sản phẩm thì phải kiểm tra có tồn tại chưa $san_pham_ton_tai = $san_pham_table->getSanPhamByArrayConditionAndArrayColumn(array('id_kho' => $id_kho, 'ma_san_pham' => $post['ma_san_pham']), array('id_san_pham')); if ($san_pham_ton_tai) { $form->get('ma_san_pham')->setMessages(array('Mã sản phẩm này đã được sử dụng')); $return['form'] = $form; return $return; } } else { $san_pham_moi->setMaSanPham($san_pham[0]['ma_san_pham']); } // nếu sửa hình ảnh if ($post['hinh_anh'] and $post['hinh_anh']['error'] == 0) { $image = $post['hinh_anh']; // lưu hình mới $path = "./public/img/orther/product/" . $id_kho . "/"; $pathSave = "/img/orther/product/" . $id_kho . "/"; if (!file_exists($path)) { mkdir($path, 0700, true); } $uniqueToken = md5(uniqid(mt_rand(), true)); $newName = $this->CheckPathExist()->checkPathExist($path, $uniqueToken, $image['name']); $filter = new \Zend\Filter\File\Rename($path . $newName); $filter->filter($image); $pathSave .= $newName; $san_pham_moi->setHinhAnh($pathSave); // nếu hình khác default thì xóa if (trim($san_pham[0]['hinh_anh']) != '/img/default/product/default.png') { $path = './public' . $san_pham[0]['hinh_anh']; array_map("unlink", glob($path)); } } else { $san_pham_moi->setHinhAnh($san_pham[0]['hinh_anh']); } $san_pham_moi->setUserId($user_id); $san_pham_table->saveSanPham($san_pham_moi); // xóa giá xuất củ $gia_xuat_table = $this->getServiceLocator()->get('Application\\Model\\GiaXuatTable'); $gia_xuat_table->deleteGiaXuat(array('id_san_pham' => $id)); // lưu giá foreach ($gia_xuat as $key => $value) { $array = explode('id_kenh_pha_phoi_', $key); $id_kenh_phan_phoi = $array[1]; $gia_xuat_moi = new GiaXuat(); $gia_xuat_moi->setIdSanPham($id); $gia_xuat_moi->setIdKenhPhanPhoi($id_kenh_phan_phoi); $gia_xuat_moi->setGiaXuat($post[$key]); $gia_xuat_table->saveGiaXuat($gia_xuat_moi); } $this->flashMessenger()->addSuccessMessage('Chúc mừng, cập nhật sản phẩm thành công!'); return $this->redirect()->toRoute('hang_hoa'); } else { $return['form'] = $form; return $return; } } else { return $return; } }
public function suaThongTinNhaCungCapAction() { $id = $this->params('id'); $id_kho = $this->AuthService()->getIdKho(); $nha_cung_cap_table = $this->getServiceLocator()->get('Application\\Model\\NhaCungCapTable'); $nha_cung_cap = $nha_cung_cap_table->getNhaCungCapByArrayConditionAndArrayColumn(array('id_nha_cung_cap' => $id, 'id_kho' => $id_kho, 'state' => 1), array()); if (!$nha_cung_cap) { $this->flashMessenger()->addErrorMessage('Nhà cung cấp không tồn tại'); return $this->redirect()->toRoute('doi_tac', array('action' => 'nha-cung-cap')); } $form = $this->getServiceLocator()->get('Application\\Form\\SuaThongTinNhaCungCapForm'); $form->setData($nha_cung_cap[0]); $return = array('id' => $id, 'form' => $form, 'hinh_anh' => $nha_cung_cap[0]['hinh_anh']); $request = $this->getRequest(); if ($request->isPost()) { $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setData($post); if ($form->isValid()) { $data = array_merge($nha_cung_cap[0], $post); $nha_cung_cap_moi = new NhaCungCap(); $nha_cung_cap_moi->exchangeArray($data); // xử lý hình ảnh $image = $post['hinh_anh']; if ($image and $image['error'] == 0) { $path = "./public/img/orther/nhacungcap/" . $id_kho . "/"; $pathSave = "/img/orther/nhacungcap/" . $id_kho . "/"; if (!file_exists($path)) { mkdir($path, 0700, true); } $uniqueToken = md5(uniqid(mt_rand(), true)); $newName = $this->CheckPathExist()->checkPathExist($path, $uniqueToken, $image['name']); $filter = new \Zend\Filter\File\Rename($path . $newName); $filter->filter($image); $pathSave .= $newName; $nha_cung_cap_moi->setHinhAnh($pathSave); // nếu hình khác default thì xóa if (trim($nha_cung_cap[0]['hinh_anh']) != '/img/default/nhacungcap/default.png') { $path = './public' . $nha_cung_cap[0]['hinh_anh']; array_map("unlink", glob($path)); } } else { $nha_cung_cap_moi->setHinhAnh($nha_cung_cap[0]['hinh_anh']); } $nha_cung_cap_moi->setNgayDangKy($nha_cung_cap[0]['ngay_dang_ky']); $nha_cung_cap_table->saveNhaCungCap($nha_cung_cap_moi); $this->flashMessenger()->addSuccessMessage('Chúc mừng, sửa thông tin nhà cung cấp thành công!'); return $this->redirect()->toRoute('doi_tac', array('action' => 'nha-cung-cap')); } else { $return['form'] = $form; return $return; } } else { return $return; } }
public function addAction() { $logged = $this->getConnection(); $form = new ImageForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $image = new Image(); $form->setInputFilter($image->getInputFilter()); $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setData($post); if ($form->isValid()) { $data = $form->getData(); //On créer la procédure pour renomer l'image $filter = new \Zend\Filter\File\Rename(array("source" => getcwd() . '/public/img/BanqueImage/' . $data['lien']['name'], "target" => getcwd() . '/public/img/BanqueImage', "randomize" => true)); $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setDestination(getcwd() . '/public/img/BanqueImage/'); if ($adapter->receive($data['lien']['name'])) { //On renomme l'image pour éiter les doublons $imageName = basename($filter->filter(getcwd() . '/public/img/BanqueImage/' . $data['lien']['name'])); $saveImage = array('idMembre' => $logged, 'lien' => $imageName); $image->exchangeArray($saveImage); $this->getImageTable()->saveImage($image); } // Redirect to list of images return $this->redirect()->toRoute('image', array('action' => 'membre', 'id' => $logged)); } } return array('form' => $form); }
public function editAction() { $this->accessRights(17); //Accept Parent Module, Return Main Menu Lists with Active Menu Indicator $this->childModuleAccessRights(17, 'edit'); //Accept Child Module ID & it's Actions: add, edit, view, disable //$msgs means message, it will show if data had been changed. $msgs = ''; //get the id from parameter $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('media_profile', array('action' => 'add', 'access_rights' => $this->getSubModuleAccessRights(17))); } try { $media_profile = $this->getMediaProfileTable()->getMediaProfile($this->serviceLocator(), $id); $media_profile_education = $this->getMediaProfileTable()->getMediaProfileEducation($this->serviceLocator(), $id); $media_profile_career = $this->getMediaProfileTable()->getMediaProfileCareer($this->serviceLocator(), $id); } catch (\Exception $ex) { return $this->redirect()->toRoute('media_profile', array('action' => 'index', 'access_rights' => $this->getSubModuleAccessRights(17))); } //instantiate the Media Profile's Form //populate the data $form_media_profile = new MediaProfileForm($this->serviceLocator()); $form_media_profile->get('relation_id')->setAttribute('options', $this->optionRelations()); $form_media_profile->get('additional_position_id[]')->setAttribute('options', $this->optionPositions()); $form_media_profile->get('additional_beat_id[]')->setAttribute('options', $this->optionBeats()); $form_media_profile->get('additional_section_id[]')->setAttribute('options', $this->optionSections()); $form_media_profile->get('additional_radio_station_id[]')->setAttribute('options', $this->optionRadioStations()); $form_media_profile->get('additional_tv_channel_id[]')->setAttribute('options', $this->optionTVChannels()); $form_media_profile->get('additional_source_id[]')->setAttribute('options', $this->optionSources()); $form_media_profile->get('submit')->setAttribute('value', 'Save'); $form_media_profile->setData($media_profile); //remove inputfilter for select element due to conflict $formInputFilter = $form_media_profile->getInputFilter(); $formInputFilter->remove('year[]'); $formInputFilter->remove('educ_course[]'); $formInputFilter->remove('educ_school[]'); $formInputFilter->remove('additional_year[]'); $formInputFilter->remove('additional_educ_course[]'); $formInputFilter->remove('additional_educ_school[]'); //remove inputfilter for select element due to conflict //CAREER $formInputFilter = $form_media_profile->getInputFilter(); $formInputFilter->remove('from[]'); $formInputFilter->remove('to[]'); $formInputFilter->remove('position_id[]'); $formInputFilter->remove('beat_id[]'); $formInputFilter->remove('section_id[]'); $formInputFilter->remove('source_id[]'); $formInputFilter->remove('circulation[]'); $formInputFilter->remove('other_affiliation[]'); $formInputFilter->remove('additional_from[]'); $formInputFilter->remove('additional_to[]'); $formInputFilter->remove('additional_position_id[]'); $formInputFilter->remove('additional_beat_id[]'); $formInputFilter->remove('additional_section_id[]'); $formInputFilter->remove('additional_source_id[]'); $formInputFilter->remove('additional_circulation[]'); $formInputFilter->remove('additional_other_affiliation[]'); //check if the data request is post //update the data $request = $this->getRequest(); if ($request->isPost()) { //prepare audit trail parameters $from = (array) $media_profile; $to = $this->getRequest()->getPost()->toArray(); $diff = array_diff_assoc($to, $from); unset($diff['submit'], $diff['media_profles_id'], $diff['media_profile_careers_id'], $diff['media_profile_educations_id'], $diff['year'], $diff['educ_course'], $diff['educ_school'], $diff['additional_year'], $diff['additional_educ_course'], $diff['additional_educ_school'], $diff['from'], $diff['to'], $diff['media_profile_type'], $diff['position_id'], $diff['beat_id'], $diff['section_id'], $diff['circulation'], $diff['source_id'], $diff['other_affiliation'], $diff['additional_from'], $diff['additional_to'], $diff['additional_media_profile_type'], $diff['additional_position_id'], $diff['additional_beat_id'], $diff['additional_section_id'], $diff['additional_circulation'], $diff['additional_source_id'], $diff['additional_other_affiliation']); $changes = $this->prepare_modified_data($from, $to, $diff); //end audit trail parameters $media_profile = new MediaProfile(); $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form_media_profile->setData($post); //uploading file $request = new Request(); //request to get the file $files = $request->getFiles(); //get the details of uploading file if ($files['photo']['name']) { $filter = new \Zend\Filter\File\Rename(array("target" => "./public/img/" . $files['photo']['name'], "overwrite" => true)); $filter->filter($files['photo']); //resize image $imagine = $this->getImagineService(); $size = new \Imagine\Image\Box(150, 150); $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET; $image = $imagine->open('./public/img/' . $files['photo']['name']); $image->thumbnail($size, $mode)->save('./public/img/' . $files['photo']['name']); //resize image $imagine = $this->getImagineService(); $image = $imagine->open('./public/img/' . $files['photo']['name']); $image->resize(new Box(150, 150))->save('./public/img/' . $files['photo']['name']); } $media_profile->exchangeArray($post); if (isset($_POST['year']) || isset($_POST['educ_course']) || isset($_POST['educ_school']) || isset($_POST['additional_year']) || isset($_POST['additional_educ_course']) || !empty($to) || isset($_POST['additional_educ_school'])) { $this->getMediaProfileTable()->saveProfileEducation($this->serviceLocator()); } if (isset($_POST['from']) || isset($_POST['to']) || isset($_POST['media_profile_type']) || isset($_POST['position_id']) || isset($_POST['beat_id']) || isset($_POST['section_id']) || isset($_POST['source_id']) || isset($_POST['circulation']) || isset($_POST['other_affiliation']) || isset($_POST['additional_from']) || isset($_POST['additional_to']) || isset($_POST['additional_media_profile_type']) || isset($_POST['additional_position_id']) || isset($_POST['additional_beat_id']) || isset($_POST['additional_section_id']) || isset($_POST['additional_source_id']) || isset($_POST['additional_circulation']) || isset($_POST['additional_other_affiliation'])) { $this->getMediaProfileTable()->saveProfileCareer($this->serviceLocator()); } $this->getMediaProfileTable()->saveMediaProfile($media_profile); $this->save_to_audit_trail($to['first_name'] . ' ' . $to['last_name'], $changes['pre'], $changes['post'], 'edit', 17); //flash message $this->flashMessenger()->addMessage(['content' => $request->getPost('first_name') . ' ' . $request->getPost('last_name') . ' Media profile updated!', 'type' => 'success']); return $this->redirect()->toRoute('media_profile'); } //return the form after saving new article type. return new ViewModel(array('form_media_profile' => $form_media_profile, 'media_profile_id' => $id, 'access_rights' => $this->getSubModuleAccessRights(17), 'media_profile_education' => $media_profile_education, 'media_profile_career' => $media_profile_career, 'positions' => $this->getMediaProfileTable()->fetchPositions($this->serviceLocator()), 'beats' => $this->getMediaProfileTable()->fetchbeats($this->serviceLocator()), 'sections' => $this->getMediaProfileTable()->fetchSections($this->serviceLocator()), 'sources' => $this->getMediaProfileTable()->fetchSources($this->serviceLocator()), 'radio_stations' => $this->getMediaProfileTable()->fetchRadioStations($this->serviceLocator()), 'tv_channels' => $this->getMediaProfileTable()->fetchTVChannels($this->serviceLocator()))); }
public function saveAttachment($files, $filename) { $file = pathinfo($files['attachments']['name']); // $filename = md5(uniqid(time(), true)) . '.' . $file['extension']; $filter = new \Zend\Filter\File\Rename(array("target" => getcwd() . "/public/news_attachments/" . $filename, "overwrite" => true)); $filter->filter($files['attachments']); }
public function suaTaiKhoanAction() { $id = $this->params('id'); $user_table = $this->getServiceLocator()->get('Permission\\Model\\UserTable'); $user = $user_table->getUserByArrayConditionAndArrayColumn(array('user_id' => $id, 'state' => 1), array()); if (!$user) { $this->flashMessenger()->addErrorMessage('Tài khoản không tồn tại'); return $this->redirect()->toRoute('tai_khoan'); } $form = $this->getServiceLocator()->get('Application\\Form\\SuaTaiKhoanForm'); $form->setData($user[0]); $return = array('form' => $form, 'id' => $id, 'hinh_anh' => $user[0]['hinh_anh']); $request = $this->getRequest(); if ($request->isPost()) { $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setData($post); if ($form->isValid()) { $user_exist = $user_table->getUserByArrayConditionAndArrayColumn(array('username' => $post['username']), array('user_id')); if (!$user_exist or $user_exist and $user_exist[0]['user_id'] == $id) { $user_moi = new User(); $user_moi->exchangeArray($post); $user_moi->setUserId($id); // xử lý hình ảnh $image = $post['hinh_anh']; if ($image and $image['error'] == 0) { $id_kho = $this->AuthService()->getIdKho(); $path = "./public/img/orther/user/"; $pathSave = "/img/orther/user/"; if (!file_exists($path)) { mkdir($path, 0700, true); } $uniqueToken = md5(uniqid(mt_rand(), true)); $newName = $this->CheckPathExist()->checkPathExist($path, $uniqueToken, $image['name']); $filter = new \Zend\Filter\File\Rename($path . $newName); $filter->filter($image); $pathSave .= $newName; $user_moi->setHinhAnh($pathSave); if ($user[0]['hinh_anh'] != '/img/default/user/default.png') { $path = './public' . $user[0]['hinh_anh']; array_map("unlink", glob($path)); } } $user_moi->setState(1); if ($post['password']) { $password = md5($post['password']); $user_moi->setPassword($password); } else { $user_moi->setPassword($user[0]['password']); } $user_table->saveUser($user_moi); $this->flashMessenger()->addSuccessMessage('Chúc mừng, cập nhật tài khoản thành công!'); return $this->redirect()->toRoute('tai_khoan'); } else { // ngược lại username đã tồn tại $form->get('username')->setMessages(array('Tên đăng nhập này đã tồn tại!')); $return['form'] = $form; return $return; } } else { $return['form'] = $form; return $return; } } else { return $return; } }
public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('portal/articles'); } if (!($articles = $this->getArticlesTable()->getArticle($id))) { $this->flashMessenger()->addErrorMessage('No article found..!!'); return $this->redirect()->toRoute('portal/articles'); } $form = $this->getForm(array_keys($this->getArticlesTable()->getArticleTags($id))); $form->bind($articles); $request = $this->getRequest(); if ($request->isPost()) { $filePath = $request->getPost('oldFile'); // Adding already exist validation on runtime excluding the current record $articles->getInputFilter()->get('title')->getValidatorChain()->attach(new \Zend\Validator\Db\NoRecordExists(array('table' => 'articles', 'field' => 'title', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'), 'exclude' => array('field' => 'articleId', 'value' => $id)))); $form->setInputFilter($articles->getInputFilter()); $tags = $request->getPost('tags'); $form->setData($request->getPost()); if ($form->isValid()) { /* image upload code starts here */ $file = $request->getFiles(); $fileAdapter = new \Zend\File\Transfer\Adapter\Http(); $imageValidator = new IsImage(); if ($imageValidator->isValid($file['file_url']['tmp_name'])) { $fileParts = explode('.', $file['file_url']['name']); $filter = new \Zend\Filter\File\Rename(array("target" => $this->folderPath . "/images/articles/article." . $fileParts[1], "randomize" => true)); try { @unlink($this->folderPath . $filePath); $filePath = str_replace($this->folderPath, '', $filter->filter($file['file_url'])['tmp_name']); } catch (\Exception $e) { return new ViewModel(array('form' => $form, 'file_errors' => array($e->getMessage()))); } } else { return new ViewModel(array('form' => $form, 'file_errors' => $imageValidator->getMessages())); } /* image upload code ends here */ $loggedInUser = $this->getAdminsTable()->getAdmin($this->getServiceLocator()->get('AuthService')->getIdentity()); $this->getArticlesTable()->saveArticles($form->getData(), $tags, $filePath, '', $loggedInUser->adminId); $this->flashMessenger()->addSuccessMessage('Article updated successfully..!!'); // Redirect to listing pages return $this->redirect()->toRoute('portal/articles'); } } return new ViewModel(array('form' => $form, 'article' => $articles)); }