Example #1
0
 public function addClient($_data)
 {
     $photoname = str_replace(" ", "_", $_data['name_en'] . '-AGN') . '.jpg';
     $upload = new Zend_File_Transfer();
     $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $photoname, 'overwrite' => true), 'photo');
     $receive = $upload->receive();
     if ($receive) {
         $_data['photo'] = $photoname;
     } else {
         $_data['photo'] = !empty($_data['id']) ? $_data['id'] : "";
     }
     try {
         $db = new Application_Model_DbTable_DbGlobal();
         $client_code = $db->getNewClientId();
         $_arr = array('title' => $_data['title'], 'customer_code' => $client_code, 'first_name' => $_data['name_kh'], 'last_name' => $_data['name_en'], 'sex' => $_data['sex'], 'dob' => $_data['dob_client'], 'pob' => $_data['country'], 'occupation' => $_data['occupation'], 'nationality' => $_data['nationality'], 'company_name' => $_data['company_name'], 'customer_type' => $_data['customer_type'], 'photo' => $_data['photo'], 'note' => $_data['desc'], 'passport_name' => $_data['passport'], 'pass_issuedate' => $_data['pissue_date'], 'pass_expireddate' => $_data['pexpired_date'], 'card_name' => $_data['card_code'], 'card_issuedate' => $_data['cissue_date'], 'card_expireddate' => $_data['cexpired_date'], 'ftb' => $_data['ftb'], 'ftb_issuedate' => $_data['fissue_date'], 'ftb_expireddate' => $_data['fexpired_date'], 'phone' => $_data['phone'], 'email' => $_data['email'], 'fax' => $_data['fax'], 'group_num' => $_data['group_num'], 'house_num' => $_data['address'], 'street' => $_data['street'], 'commune' => $_data['commune'], 'district' => $_data["district"], 'province_id' => $_data['province'], 'balance' => $_data['balance'], 'address1' => $_data['address1'], 'address2' => $_data['address2'], 'i_city' => $_data['i_city'], 'i_zipcode' => $_data['i_zipcode'], 'i_state' => $_data['state'], 'country' => $_data['countries'], 'i_phone' => $_data['i_phone'], 'status' => $_data['status'], 'date' => date("Y-m-d"));
         if (!empty($_data['id'])) {
             $where = 'id = ' . $_data['id'];
             $this->update($_arr, $where);
             return $_data['id'];
         } else {
             return $this->insert($_arr);
         }
     } catch (Exception $e) {
         Application_Model_DbTable_DbUserLog::writeMessageError($e->getMessage());
     }
 }
Example #2
0
 public function updatCat($data, $id)
 {
     $session = new Zend_Session_Namespace('auth');
     $GetUserId = $session->user_id;
     $user_type = $session->level;
     $db = $this->getAdapter();
     $db->beginTransaction();
     try {
         $image = str_replace(" ", "_", $data["name_en"]) . '.png';
         $upload = new Zend_File_Transfer();
         $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/icon/' . $image, 'overwrite' => true), 'icon');
         $receive = $upload->receive();
         if ($receive) {
             $data['icon'] = $image;
         } elseif ($receive == "") {
             $dbs = $this->getAdapter();
             $sql = "SELECT icon FROM {$this->_name} WHERE pro_id =" . $id;
             $old_photo = $db->fetchRow($sql);
             foreach ($old_photo as $old_photos) {
                 $data['icon'] = $old_photos;
             }
         }
         $arr = array('cat_id' => $data["cat_id"], 'pro_name_en' => $data["name_en"], 'pro_name_km' => $data["name_km"], 'pro_code' => $data["id_code"], 'cu_id' => $data["currency"], 'price_out' => $data["price"], 'description' => $data["description"], 'status' => $data["status"], 'date' => date("y-m-d"), 'icon' => $data["icon"], 'user_id' => $GetUserId);
         $where = $this->getAdapter()->quoteInto('pro_id=?', $id);
         $this->update($arr, $where);
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         echo $e->getMessage();
         exit;
     }
 }
Example #3
0
 public function updat($data, $id)
 {
     $session = new Zend_Session_Namespace('auth');
     $GetUserId = $session->user_id;
     $user_type = $session->level;
     $db = $this->getAdapter();
     $db->beginTransaction();
     try {
         $image = str_replace(" ", "_", $data["name_en"]) . '.jpg';
         $upload = new Zend_File_Transfer();
         $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/icon/' . $image, 'overwrite' => true), 'icon');
         $receive = $upload->receive();
         if ($receive) {
             $data['icon'] = $image;
         } elseif ($receive == "") {
             $dbs = $this->getAdapter();
             $sql = "SELECT icon FROM {$this->_name} WHERE Location_id =" . $id;
             $old_photo = $db->fetchRow($sql);
             foreach ($old_photo as $old_photos) {
                 $data['icon'] = $old_photos;
             }
         }
         $arr = array('location_code' => $data["location_code"], 'name_kh' => $data["name_en"], 'name_en' => $data["name_km"], 'user_id' => 1, 'status' => $data["status"], 'contact' => $data["contact"], 'phone' => $data["tel"], 'fax' => $data["fax"], 'email' => $data["email"], 'company' => $data["company"], 'last_mod_date' => new Zend_Date(), 'address' => $data["address"], 'description' => $data["description"], 'user_id' => $GetUserId);
         $where = $this->getAdapter()->quoteInto('location_id=?', $id);
         $this->update($arr, $where);
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         echo $e->getMessage();
         exit;
     }
 }
 private function saveImagesToFilesystem($savePath)
 {
     if (!file_exists($savePath)) {
         mkdir($savePath);
     }
     $upload = new Zend_File_Transfer();
     $upload->setDestination($savePath);
     $upload->receive();
     $this->resizeImagesAndCreateThumbnails($savePath, $upload->getFileInfo());
 }
Example #5
0
 public function updateProvince($_data, $id)
 {
     $photoname = str_replace(" ", "_", $_data['kh_province']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $photoname, 'overwrite' => true), 'photo');
     $receive = $upload->receive();
     if ($receive) {
         $_data['photo'] = $photoname;
     } else {
         $_data['photo'] = $_data['old_photo'];
     }
     $_arr = array('province_name' => $_data['kh_province'], 'photo' => $_data['photo'], 'note' => $_data['note'], 'date' => date("Y-d-m"), 'status' => $_data['status'], 'user_id' => $this->getUserId());
     $where = $this->getAdapter()->quoteInto("id=?", $id);
     $this->update($_arr, $where);
 }
Example #6
0
 public function updatePhoto($_data)
 {
     $photo_name = str_replace(" ", "_", $_data['title']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $a = $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/slider/' . $photo_name, 'overwrite' => true));
     $recieve = $upload->receive();
     if ($recieve) {
         $img = $photo_name;
     } else {
         $img = $_data['old_photo'];
     }
     $_arr = array('title' => $_data['title'], 'status' => $_data['status'], 'description' => $_data['note'], 'photo_name' => $img, 'user_id' => $this->getUserId());
     $where = $this->getAdapter()->quoteInto("id=?", $_data['id']);
     $this->update($_arr, $where);
 }
Example #7
0
 function updateSeason($_data)
 {
     $photo = str_replace(" ", "", $_data['season_title']);
     $photo = str_replace("%", "", $_data['season_title']);
     $photo_name = str_replace("", "_", $photo) . '.jpg';
     $upload = new Zend_File_Transfer();
     $a = $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $photo_name, 'overwrite' => true));
     $recieve = $upload->receive();
     if ($recieve) {
         $img = $photo_name;
     } else {
         $img = $_data['oldphoto'];
     }
     $_arr = array('season_title' => $_data['season_title'], 'start_date' => $_data['start_date'], 'end_date' => $_data['end_date'], 'value' => $_data['value'], 'season_type' => $_data['season_type'], 'status' => $_data['status'], 'date' => date("Y-m-d"), 'user_id' => $this->getUserId(), 'photo_name' => $img, 'note' => $_data['note']);
     $where = $this->getAdapter()->quoteInto("id=?", $_data['id']);
     $this->update($_arr, $where);
 }
 /**
  * Sube el archivo a temporal
  * @return string
  */
 public function upload($extenciones = array('kml', 'kmz'))
 {
     $correcto = true;
     $upload = new Zend_File_Transfer();
     $upload->addValidator('Extension', false, $extenciones);
     $upload->addValidator('FilesSize', false, array('min' => '0.001kB', 'max' => '64MB'));
     $file = $upload->getFileInfo();
     foreach ($file as $field_name => $file_data) {
         if (!$upload->isUploaded($field_name)) {
             $correcto = false;
             $retorno = array("correcto" => false, "mensaje" => "No se subio ningún archivo o estaba vacío");
         }
         if (!$upload->isValid($field_name)) {
             $texto = "</br>";
             $mensajes = $upload->getMessages();
             foreach ($mensajes as $key => $txt) {
                 $texto .= $txt . "</br>";
             }
             $correcto = false;
             $retorno = array("correcto" => false, "mensaje" => "<b>El archivo es inv&aacute;lido</b>." . $texto);
         }
         $this->_setFileConfig($file_data["name"]);
         $this->_mime = $file_data["type"];
         $this->_hash = $this->_ci->string_core->rand_string(20);
         $this->_target = $this->_dir_temp . $this->_hash . "." . $this->_file_ext;
         $upload->addFilter('Rename', array('target' => $this->_target, 'overwrite' => true));
     }
     if ($correcto) {
         fb($upload->receive());
         $retorno = $this->_saveToCache();
     }
     return $retorno;
 }
 /**
  * Metodo para renderizar o formulario de cadastro/alteracao dos parametros do contribuinte.
  *
  * Retorna para a view a instancia do formulario Contribuinte_Form_ParametrosContribuinte
  */
 public function contribuinteAction()
 {
     $oForm = new Contribuinte_Form_ParametrosContribuinte();
     $oParametroContribuinte = $this->buscaParametroContribuinte($this->view->contribuinte->getIdUsuarioContribuinte());
     $aDados = $this->getRequest()->getPost();
     if ($this->getRequest()->isPost() && $oForm->isValid($aDados)) {
         try {
             $oDoctrine = Zend_Registry::get('em');
             $oDoctrine->getConnection()->beginTransaction();
             $oParametroContribuinte->setAvisofimEmissaoNota($aDados["avisofim_emissao_nota"]);
             $oParametroContribuinte->setCofins(DBSeller_Helper_Number_Format::toDataBase($aDados["cofins"]));
             $oParametroContribuinte->setCsll(DBSeller_Helper_Number_Format::toDataBase($aDados["csll"]));
             $oParametroContribuinte->setIdContribuinte($this->view->contribuinte->getIdUsuarioContribuinte());
             $oParametroContribuinte->setInss(DBSeller_Helper_Number_Format::toDataBase($aDados["inss"]));
             $oParametroContribuinte->setIr(DBSeller_Helper_Number_Format::toDataBase($aDados["ir"]));
             $oParametroContribuinte->setMaxDeducao(DBSeller_Helper_Number_Format::toDataBase($aDados["max_deducao"]));
             $oParametroContribuinte->setPis(DBSeller_Helper_Number_Format::toDataBase($aDados["pis"]));
             $oParametroContribuinte->setValorIssFixo(DBSeller_Helper_Number_Format::toDataBase($aDados["valor_iss_fixo"]));
             $oParametroContribuinte->salvar();
             $oDoctrine->getConnection()->commit();
             $this->view->messages[] = array('success' => 'Parâmetros modificados com sucesso.');
             $oArquivoUpload = new Zend_File_Transfer();
             $oArquivoUpload->receive();
             $iInscricaoMunicipal = $this->view->contribuinte->getInscricaoMunicipal();
             Administrativo_Model_Empresa::setLogoByIm($iInscricaoMunicipal, $oArquivoUpload->getFileInfo());
         } catch (Exception $oErro) {
             $oDoctrine->getConnection()->rollback();
             $this->view->messages[] = array('error' => $oErro->getMessage());
         }
     }
     $oDados->im = $this->view->contribuinte->getInscricaoMunicipal();
     $oDados->nome_contribuinte = $this->view->contribuinte->getNome();
     $oDados->avisofim_emissao_nota = $oParametroContribuinte->getAvisofimEmissaoNota();
     $oDados->cofins = $oParametroContribuinte->getCofins();
     $oDados->csll = $oParametroContribuinte->getCsll();
     $oDados->inss = $oParametroContribuinte->getInss();
     $oDados->ir = $oParametroContribuinte->getIr();
     $oDados->max_deducao = $oParametroContribuinte->getMaxDeducao();
     $oDados->pis = $oParametroContribuinte->getPis();
     $oDados->valor_iss_fixo = $oParametroContribuinte->getValorIssFixo();
     $oForm->preenche($oDados);
     $this->view->sLogoPrestador = Administrativo_Model_Empresa::getLogoByIm($oDados->im);
     $this->view->form = $oForm;
 }
Example #10
0
 function updateMenuCombo($data)
 {
     $db = $this->getAdapter();
     $photo_name = str_replace(" ", "_", $data['combo_code']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $db->beginTransaction();
     $a = $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/image/' . $photo_name, 'overwrite' => true));
     $receive = $upload->receive();
     if ($receive) {
         $img = $photo_name;
     } else {
         $img = "";
     }
     $arr = array('bar_code' => $data['combo_code'], 'desc' => $data['description'], 'lang1' => $data['lang_1'], 'lang2' => $data['lang_2'], 'price' => $data['price'], 'display_by' => $data['show_description'], 'category_id' => $data['menu_group'], 'img_name' => $img, 'root_menuid' => $data['root_menu'], 'print_code' => $data['printer_code'], 'root_menu_name' => $data['combo'], 'printto_print' => $data['combo1'], 'showscreen' => $data['combo2'], 'is_discound' => $data['combo3'], 'time' => $data['combo4']);
     print_r($arr);
     exit;
     $where = " id = " . $data['id'];
     $this->update($arr, $where);
 }
Example #11
0
 public function addCreditOfficer($_data)
 {
     $photoname = str_replace(" ", "_", $_data['first_name']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $photoname, 'overwrite' => true), 'photo');
     $receive = $upload->receive();
     //echo $receive; exit();
     if ($receive) {
         $_data['photo'] = $photoname;
     } else {
         $_data['photo'] = "";
     }
     unset($_data['MAX_FILE_SIZE']);
     $_arr = array('co_code' => $_data['co_id'], 'co_khname' => $_data['name_kh'], 'co_firstname' => $_data['first_name'], 'co_lastname' => '', 'displayby' => $_data['display'], 'position_id' => $_data['position'], 'sex' => $_data['co_sex'], 'national_id' => $_data['national_id'], 'address' => $_data['address'], 'pob' => $_data['pob'], 'degree' => $_data['degree'], 'tel' => $_data['tel'], 'email' => $_data['email'], 'create_date' => Zend_Date::now(), 'status' => $_data['status'], 'user_id' => $this->getUserId(), 'basic_salary' => $_data['basic_salary'], 'start_date' => $_data['start_date'], 'end_date' => $_data['end_date'], 'contract_no' => $_data['contract_no'], 'note' => $_data['note'], 'shift' => $_data['shift'], 'workingtime' => $_data['workingtime'], 'annual_lives' => $_data['annual_lives'], 'photo' => $_data['photo'], 'department_id' => $_data['department_id'], 'figer_print_id' => $_data['figer_print_id']);
     if (!empty($_data['id'])) {
         $where = 'co_id = ' . $_data['id'];
         return $this->update($_arr, $where);
     } else {
         return $this->insert($_arr);
     }
 }
Example #12
0
 function updateSlideshow($_data)
 {
     if (@$_data['is_showcaption'] == "" or @$_data['is_showcaption'] == null) {
         $is_showcaption = 0;
     } else {
         $is_showcaption = 1;
     }
     $img = str_replace(" ", "_", $_data['title']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $a = $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $img, 'overwrite' => true));
     $recieve = $upload->receive();
     if ($recieve) {
         $imgs = $img;
     } else {
         $imgs = $_data['old_photo'];
     }
     $_arr = array('title' => $_data['title'], 'caption' => $_data['caption'], 'ordering' => $_data['ordering'], 'img' => $imgs, 'status' => $_data['status'], 'is_showcaption' => $is_showcaption, 'user_id' => $this->getUserId());
     $where = $this->getAdapter()->quoteInto("id=?", $_data['id']);
     $this->update($_arr, $where);
     //insert data
 }
Example #13
0
 function updateTableGroup($data)
 {
     $db = $this->getAdapter();
     $photo_name = str_replace(" ", "_", $data['group_code']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/image/' . $photo_name, 'overwrite' => true), 'photo');
     $recieve = $upload->receive();
     if ($recieve) {
         $data['photo'] = $photo_name;
     } else {
         $sql = "SELECT img_name FROM rs_table_group where id=" . $data["id"];
         $row = $db->fetchRow($sql);
         foreach ($row as $rs) {
             $data['photo'] = $rs;
         }
     }
     unset($data['MAX_FILE_SIZE']);
     $arr = array('code' => $data['group_code'], 'description' => $data['description'], 'lang1' => $data['lang_1'], 'lang2' => $data['lang_2'], 'img_name' => $data['photo'], 'display_by' => $data['show_description'], 'compid' => $data['apply_to_company'], 'note' => $data['note'], 'background_color' => $data['backgroun_color'], 'font_color' => $data['font_color'], 'font_size' => $data['font_size'], 'status' => $data['active']);
     $where = " id = " . $data['id'];
     $this->update($arr, $where);
 }
 public function uploadAction()
 {
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return;
     }
     $name = $this->_getParam('name', false);
     $upload = new Zend_File_Transfer();
     $upload->addValidator('Count', false, 1);
     if (!$upload->isValid()) {
         return;
     }
     $upload->receive();
     $file = $upload->getFileName();
     $fp = fopen($file, "r");
     if (!$fp) {
         return;
     }
     $mime = $upload->getMimeType();
     if (!$name) {
         // get short name
         $name = $upload->getFileName(null, false);
     }
     $this->_storage->storeItem($name, $fp, array(Zend_Cloud_StorageService_Adapter_S3::METADATA => array("type" => $mime)));
     try {
         $this->_storage->storeMetadata($name, array("type" => $mime));
     } catch (Zend_Cloud_OperationNotAvailableException $e) {
         // ignore it
     }
     return $this->_helper->redirector('index');
 }
Example #15
0
 public function direct($exts = array('xml', 'csv', 'txt'))
 {
     $front = Zend_Controller_Front::getInstance();
     $front->registerPlugin(new \Tid_Zend_Controller_Plugin_UploadMax());
     // Frontend HACK
     if ($this->getRequest()->getParam('iframeHack', false)) {
         $h = Zend_Controller_Action_HelperBroker::getStaticHelper('Output');
         $h->direct('json')->setContentType('text/html');
     }
     // Preprocess mime types
     $mimes = array();
     foreach ($exts as $ext) {
         if (!isset($this->_mimeTypes[$ext])) {
             throw new \Application\Exceptions\InvalidArgumentException("Unsupported extension {$ext}");
         }
         if (!in_array($this->_mimeTypes[$ext], $mimes)) {
             $mimes[] = $this->_mimeTypes[$ext];
         }
     }
     // Upload file
     $upload = new Zend_File_Transfer();
     $mimes['headerCheck'] = true;
     $upload->addValidator('Count', true, array('min' => 1, 'max' => 1))->addValidator('Extension', true, $exts)->addValidator('MimeType', true, $mimes)->addValidator('Size', true, array('max' => '20MB'));
     // Validate file
     if (!$upload->isValid()) {
         throw new \Application\Exceptions\ValidateException('Invalid file', array('validationErrors' => $upload->getMessages(), 'entity' => 'file', 'code' => ValidationCodes::FILE_UPLOAD_ERR));
     }
     if (!$upload->receive()) {
         throw new \Application\Exceptions\InvalidArgumentException('Could not receive file', ValidationCodes::FILE_UPLOAD_ERR);
     }
     return $upload;
 }
Example #16
0
 function updateMenuItem($data)
 {
     $db = $this->getAdapter();
     $photo_name = str_replace(" ", "_", $data['item_code']) . '.jpg';
     $upload = new Zend_File_Transfer();
     try {
         $a = $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/image/' . $photo_name, 'overwrite' => true));
         $recieve = $upload->receive();
         if ($recieve) {
             $img = $photo_name;
         } else {
             $img = "";
         }
         $arr = array('bar_code' => $data['item_code'], 'desc' => $data['description'], 'lang1' => $data['lang_1'], 'lang2' => $data['lang_2'], 'price' => $data['demo3'], 'add_charge' => $data['demo4'], 'display_by' => $data['show_description'], 'category_id' => $data['menu_group'], 'img_name' => $img, 'root_menuid' => $data['root_menu'], 'print_code' => $data['print_code'], 'printto_print' => $data['print_to'], 'is_service' => $data['is_service'], 'background_color' => $data['backgroun_color'], 'font_color' => $data['font_color'], 'font_size' => $data['font_size'], 'status' => $data['active'], 'note' => $data['note'], 'showscreen' => $data['show_screen'], 'is_root' => $data['is_root'], 'time' => $data['time'], 'is_discound' => $data['discount'], 'is_reqty' => $data['require_qty']);
         //print_r($arr);exit();
         $where = " id = " . $data['id'];
         $this->update($arr, $where);
     } catch (Exception $e) {
         echo $e->getMessage();
         exit;
     }
 }
Example #17
0
 function getupdatePartner($data)
 {
     $db = $this->getAdapter();
     $photoname = str_replace(" ", "_", $data['partner_name']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $photoname, 'overwrite' => true), 'photo');
     $receive = $upload->receive();
     if ($receive != "") {
         $data['photo'] = $photoname;
     } elseif ($receive == "") {
         $dbs = $this->getAdapter();
         $sql = "SELECT photo FROM cms_partner WHERE id =" . $data["id"];
         $old_photo = $db->fetchRow($sql);
         foreach ($old_photo as $old_photos) {
             $data['photo'] = $old_photos;
         }
     }
     $arr = array('partner_name' => $data['partner_name'], 'nation_id' => $data['cade_number'], 'account_no' => $data['account_number'], 'nation_id' => $data['cade_number'], 'house_no' => $data['home_number'], 'group_no' => $data['group_number'], 'street' => $data['street_number'], 'commune' => $data['commune'], 'district' => $data['district'], 'province' => $data['province_name'], 'tel' => $data['fax_number'], 'mobile' => $data['sele_phone'], 'note' => $data['note'], 'photo' => $data['photo'], 'cash_riel' => $data['money_riel'], 'cash_dollar' => $data['money_usa'], 'cash_bath' => $data['money_bath'], 'date' => $data['date'], 'village' => $data['village'], 'is_cashoperation' => $data['tran_type'], 'status' => $data['status']);
     $where = "id=" . $data['id'];
     //print_r($where);exit();
     $this->update($arr, $where);
 }
Example #18
0
 function updateTable($data)
 {
     $photo_name = str_replace(" ", "_", $data['table_code']) . '.jpg';
     $upload = new Zend_File_Transfer();
     $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/image/' . $photo_name, 'overwrite' => true));
     $receive = $upload->receive();
     if ($receive) {
         $data['photo'] = $photo_name;
     } else {
         $db = $this->getAdapter();
         $sql = "SELECT img_name FROM {$this->_name} WHERE id=" . $data['id'];
         $row = $db->fetchRow($sql);
         foreach ($row as $rs) {
             $data['photo'] = $rs;
         }
     }
     $arr = array('code' => $data['table_code'], 'description' => $data['description'], 'lang1' => $data['lang_1'], 'lang2' => $data['lang_2'], 'img_name' => $data['photo'], 'tbl_groupid' => $data['group_code'], 'display_by' => $data['show_description'], 'max_sit' => $data['max_seat'], 'price' => $data['price'], 'compid' => $data['apply_to_company'], 'active' => $data['active'], 'time_charge_id' => $data['time_ck'], 'is_discound' => $data['dicount_ck'], 'tbl_type' => $data['type_of_table'], 'add_date' => date("Y-m-d"), 'est_time' => $data['est_time'], 'backgroud_color' => $data['backgroun_color'], 'font_color' => $data['font_color'], 'font_size' => $data['font_size'], 'note' => $data['note']);
     $where = " id = " . $data['id'];
     $this->update($arr, $where);
     //     	Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery());
     //     	Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams());
     //     	$db->getProfiler()->setEnabled(false);
 }
Example #19
0
 public function updatecustomer($_data)
 {
     //update customer
     $photoname = str_replace(" ", "_", $_data['name_en'] . '-AGNF') . '.jpg';
     $upload = new Zend_File_Transfer();
     $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $photoname, 'overwrite' => true), 'photo');
     $receive = $upload->receive();
     if ($receive) {
         $_data['photo'] = $photoname;
     } else {
         $_data['photo'] = $_data['old_photo'];
     }
     try {
         // 			$db = new Application_Model_DbTable_DbGlobal();
         // 			$client_code = $db->getNewClientId();
         $_arr = array('title' => $_data['title'], 'first_name' => $_data['name_kh'], 'last_name' => $_data['name_en'], 'sex' => $_data['sex'], 'dob' => $_data['dob_client'], 'photo' => $_data['photo'], 'occupation' => $_data['occupation'], 'pob' => $_data['country'], 'company_name' => $_data['company_name'], 'nationality' => $_data['national_id'], 'phone' => $_data['phone'], 'email' => $_data['email'], 'group_num' => $_data['group_num'], 'house_num' => $_data['home'], 'street' => $_data['street'], 'commune' => $_data['commune'], 'district' => $_data["district"], 'province_id' => $_data['province'], 'address1' => $_data['address1'], 'address2' => $_data['address2'], 'i_city' => $_data['city'], 'i_zipcode' => $_data['i_zipcode'], 'i_state' => $_data['state'], 'country' => $_data['country'], 'i_phone' => $_data['i_phone'], 'fax' => $_data['fax'], 'date' => date("Y-m-d"));
         $session_user = new Zend_Session_Namespace('customer');
         $user_id = $session_user->customer_id;
         $where = 'id = ' . $user_id;
         $this->update($_arr, $where);
     } catch (Exception $e) {
         Application_Model_DbTable_DbUserLog::writeMessageError($e->getMessage());
     }
 }
Example #20
0
 /**
  * 上传用户文件的action 
  */
 public function uploadUserDocAction()
 {
     $this->_helper->layout->disableLayout();
     $doctype = $this->request->getParam('doctype');
     $this->view->doctype = $doctype;
     $result = 0;
     if ($this->request->isPost()) {
         $upload = new Zend_File_Transfer();
         $upload->addValidator('Size', false, 10240000);
         //10M
         $utilService = $this->_container->get('util');
         $fileService = $this->_container->get('file');
         $filename = $utilService->getFilename($upload->getFileName());
         $extension = $fileService->getExtensionByFilename($filename);
         $destination = $utilService->getTmpDirectory() . DIRECTORY_SEPARATOR . uniqid();
         $upload->addFilter('Rename', $destination);
         if ($upload->isValid()) {
             if ($upload->receive()) {
                 $userModel = $this->getModel('user');
                 $mimetype = $upload->getMimeType();
                 if ($fileService->isAcceptedDocument($mimetype, $extension)) {
                     $user = $userModel->getUserById($this->me->getId());
                     if ($user) {
                         $doc = null;
                         if ($doctype == \Angel_Model_User::FILETYPE_IDENTITY_FRONT || $doctype == \Angel_Model_User::FILETYPE_IDENTITY_BACK) {
                             $doc = $userModel->addUserDoc($user, $doctype, $destination, $filename, $mimetype);
                         }
                         if ($doc) {
                             $result = 1;
                             $this->view->filename = $doc->filename;
                             $this->view->path = $this->view->url(array('doctype' => $doctype, 'user_id' => $user->id, 'doc_id' => $doc->id), 'user-doc');
                         }
                     }
                 } else {
                     // 上传的文件格式不接受
                     $result = 2;
                 }
             }
         }
     }
     $this->view->result = $result;
 }
Example #21
0
 public function importSeasons()
 {
     $option = JRequest::getCmd('option');
     $controller = JRequest::getCmd('controller');
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $path = JPATH_ROOT . "/tmp";
     $upload = new Zend_File_Transfer();
     $upload->setDestination($path);
     $upload->addValidator('Extension', false, array("csv"));
     $errors = array();
     $file = "products_seasons";
     $info = $upload->getFileInfo($file);
     if ($upload->isUploaded($file)) {
         if (!$upload->isValid($file)) {
             foreach ($upload->getMessages() as $k => $v) {
                 $errors[$k] = true;
             }
         }
     }
     if ($upload->receive()) {
         $mProduct = new EcwidgatewayModelProducts();
         $mProduct->processSeasonsCsv($path . "/" . $info[$file]["name"]);
         $msg = "Данные импортированы";
     } else {
         $errorMessages = array("Ошибка при загрузке файла");
         foreach ($errors as $k => $v) {
             if (isset($errors[Zend_Validate_File_Extension::FALSE_EXTENSION])) {
                 $errorMessages[] = JText::_("Недопустимое расширение файла");
             }
         }
         $msg = implode("<p>", $errorMessages);
     }
     $link = 'index.php?option=' . $option . '&controller=' . $controller;
     $this->setRedirect($link, $msg);
 }
Example #22
0
 public function uploadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $options = $this->getRequest()->getParam('options');
         if ($options && !is_array($options)) {
             $options = unserialize($options);
         }
         /**
          * @var Zend_File_Transfer_Adapter_Http 
          */
         $uploads = new Zend_File_Transfer('Http', false, array('detectInfos' => false));
         if ($options['extension'] == ZendT_Type_Blob::FILTER_EXECUTABLE) {
             $options['extension'] = array('text/php', 'text/x-php', 'text/asp', 'text/x-asp');
         }
         if ($options['maxSize'] || $options['minSize']) {
             $uploads->addValidator('FilesSize', false, array('max' => $options['maxSize'], 'min' => $options['minSize']));
         }
         if (is_array($options['validators'])) {
             array_merge($options['extension'], $options['validators']);
         }
         //$uploads->addValidator('ExcludeMimeType', false, $options['extension']);
         $uploads->receive();
         if ($uploads->hasErrors()) {
             $message = $uploads->getMessages();
             throw new ZendT_Exception_Information(current($message));
         } else {
         }
         $infoFiles = $uploads->getFileInfo();
         @($content = file_get_contents($infoFiles['file']['tmp_name']));
         if ($content === false) {
             throw new ZendT_Exception_Error('Não foi possível armazenar o arquivo informado!');
         }
         $_file = new ZendT_File($infoFiles['file']['name'], $content, $infoFiles['file']['type']);
         @unlink($infoFiles['file']['tmp_name']);
         $infoFile = $_file->toArrayJson();
         $infoFile['size'] = $infoFiles['file']['size'];
         $json->setResult($infoFile);
     } catch (Exception $Ex) {
         $json->setException($Ex);
     }
     echo $json->render();
 }
 function addproductsAction()
 {
     $muser = new Admin_Model_Page();
     $paginator = Zend_Paginator::factory($muser->option_page());
     $paginator->setItemCountPerPage(10);
     $paginator->setPageRange(10);
     $currentPage = $this->_request->getParam('page', 1);
     $paginator->setCurrentPageNumber($currentPage);
     $this->view->books = $paginator;
     $system = new Admin_Model_Category();
     $menu = $system->option_menu();
     $this->view->bookss = $menu;
     $district = $system->option_dictrict();
     $this->view->bokk = $district;
     if ($this->_request->isPost()) {
         $this->view->purifier = Zend_Registry::get('purifier');
         $conf = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($conf);
         $menu_id = $purifier->purify($this->_request->getParam('parent_id'));
         $title = $purifier->purify($this->_request->getParam('title'));
         $dis = $purifier->purify($this->_request->getParam('dis'));
         $key = $purifier->purify($this->_request->getParam('key'));
         $description = $purifier->purify($this->_request->getParam('description'));
         $home = $purifier->purify($this->_request->getParam('home'));
         $upload = new Zend_File_Transfer();
         // $images=$upload->addValidator('IsImage', false, array('application/gif'));
         $images = $upload->addValidator('Extension', false, 'jpg,png,gif');
         // if($images==true){ thongbao('Không đúng định dạng hình ảnh');   return;}
         $images = $upload->getFilename();
         $images = basename($images);
         $url = khongdau($title);
         $random_digit = rand(00, 99999);
         $img = $url . "-" . $random_digit . $images;
         $filterRename = new Zend_Filter_File_Rename(array('target' => 'Upload/' . $img, 'overwrite' => false));
         $upload->addFilter($filterRename);
         $upload->receive();
         $position = $purifier->purify($this->_request->getParam('position'));
         $active = $purifier->purify($this->_request->getParam('active'));
         $content = $purifier->purify($this->_request->getParam('content'));
         $price = $purifier->purify($this->_request->getParam('price'));
         $state = $purifier->purify($this->_request->getParam('state'));
         $sales = $purifier->purify($this->_request->getParam('sales'));
         $code = $purifier->purify($this->_request->getParam('code'));
         $members = $purifier->purify($this->_request->getParam('members'));
         $dictrict_id = $purifier->purify($this->_request->getParam('dictrict_id'));
         $type = $purifier->purify($this->_request->getParam('type'));
         $category_id = $purifier->purify($this->_request->getParam('category_id'));
         $add = new Admin_Model_Products();
         $add->insert_products($title, $description, $img, $content, $menu_id, $price, $state, $sales, $dis, $key, $position, $active, $home, $code, $members, $dictrict_id, $type, $category_id);
     }
     $this->view->idmenu = $this->_request->getParam('idmenu');
 }
 public function applyAction()
 {
     $this->view->pageTitle = 'Careers';
     if ($this->getRequest()->isPost()) {
         // Handle the cv file and form data
         $filters = array('name' => 'StringTrim', 'tel' => 'StringTrim', 'email' => 'StringTrim', 'enquiry' => 'StringTrim');
         $validators = array('name' => array('NotEmpty', 'messages' => 'Please enter your name'), 'tel' => array('NotEmpty', 'messages' => 'Please enter your telephone number'), 'email' => array('NotEmpty', 'messages' => 'Please enter your email address'), 'enquiry' => array('NotEmpty', 'messages' => 'Please tell us why this position interests you'));
         $input = new Zend_Filter_Input($filters, $validators, $_POST);
         if ($input->isValid()) {
             $upload = new Zend_File_Transfer();
             // Make sure the file is actually a document
             $upload->clearValidators();
             $upload->setOptions(array('ignoreNoFile' => true));
             //$upload->addValidator('MimeType', false, array('application/msword', 'application/pdf', 'application/rtf', 'text/plain'));
             if ($upload->isValid()) {
                 $params = Zend_Registry::get('params');
                 $uploadPath = $params->cms->fileUploadPath;
                 $upload->setDestination($uploadPath);
                 $upload->receive();
                 $fileInfo = $upload->getFileInfo();
                 $emailer = new Application_Core_Mail();
                 $emailer->setTo($params->email->careers, 'HomeLet');
                 $emailer->setFrom($input->email, $input->name);
                 $emailer->setSubject('HomeLet - Job Application (' . $input->position . ')');
                 $bodyHtml = 'Position : ' . $input->position . '<br />';
                 $bodyHtml .= 'Name : ' . $input->name . '<br />';
                 $bodyHtml .= 'Email : ' . $input->email . '<br />';
                 $bodyHtml .= 'Tel : ' . $input->tel . '<br />';
                 $bodyHtml .= 'Enquiry : <pre>' . $input->enquiry . '</pre><br />';
                 if ($fileInfo['cv_file']['type'] !== null) {
                     $emailer->addAttachment($fileInfo['cv_file']['destination'] . '/' . $fileInfo['cv_file']['name'], $fileInfo['cv_file']['name']);
                 }
                 $emailer->setBodyHtml($bodyHtml);
                 if ($emailer->send()) {
                     $this->_helper->redirector('thanks', 'careers');
                 } else {
                 }
             } else {
                 // Invalid file type
                 $this->view->errors = array('cv_file' => 'Invalid file type');
                 $this->view->name = $input->name;
                 $this->view->tel = $input->tel;
                 $this->view->email = $input->email;
                 $this->view->enquiry = $input->enquiry;
             }
         } else {
             // Invalid form data
             $this->view->errors = $input->getMessages();
             $this->view->name = $input->name;
             $this->view->tel = $input->tel;
             $this->view->email = $input->email;
             $this->view->enquiry = $input->enquiry;
         }
     }
     $careerUrl = $this->getRequest()->getParam('careerID');
     $careerID = substr($careerUrl, 0, strpos($careerUrl, '-'));
     $careers = new Datasource_Cms_Careers();
     $career = $careers->getById($careerID);
     $this->view->title = $career['title'];
     $this->view->id = $career['id'];
 }
Example #25
0
 public function updateUser($arr, $user_id)
 {
     try {
         $db = $this->getAdapter();
         $db->beginTransaction();
         $photoname = str_replace(" ", "_", $arr['username']) . '.jpg';
         $upload = new Zend_File_Transfer();
         $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/' . $photoname, 'overwrite' => true), 'photo');
         $receive = $upload->receive();
         if ($receive != "") {
             $arr['photo'] = $photoname;
         } elseif ($receive == "") {
             $dbs = $this->getAdapter();
             $sql = "SELECT photo FROM `tb_user` WHERE `user_id` =" . $user_id;
             $old_photo = $db->fetchRow($sql);
             foreach ($old_photo as $old_photos) {
                 $arr['photo'] = $old_photos;
             }
         }
         unset($arr['MAX_FILE_SIZE']);
         $db->getProfiler()->setEnabled(true);
         $data = array("name" => $arr["fullname"], "user_name" => $arr["username"], "user_code" => $arr["id_code"], "email" => $arr["email"], "photo" => $arr["photo"], "user_type" => $arr["user_type"], "status" => 1, "date" => date("Y-m-d H:i:s"));
         $this->_name = "tb_user";
         $where = $this->getAdapter()->quoteInto('user_id=?', $user_id);
         $this->update($data, $where);
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         $e->getMessage();
         echo "Connect Fail";
     }
 }
Example #26
0
 /**
  * @param string $adapter
  * @param bool $direction
  * @param array $options
  */
 public function __construct($adapter = "\\Pimcore\\File\\Transfer\\Adapter\\Http", $direction = false, $options = array())
 {
     parent::__construct($adapter, $direction, $options);
 }
 function postingAction()
 {
     $captcha = new Zend_Captcha_Image();
     $vi = new Zend_View();
     $base = $vi->baseurl();
     $muser = new Admin_Model_Page();
     $paginator = Zend_Paginator::factory($muser->option_page());
     $paginator->setItemCountPerPage(10);
     $paginator->setPageRange(10);
     $currentPage = $this->_request->getParam('page', 1);
     $paginator->setCurrentPageNumber($currentPage);
     $this->view->books = $paginator;
     $system = new Admin_Model_Category();
     $menu = $system->option_menu();
     $this->view->bookss = $menu;
     $district = $system->option_dictrict();
     $this->view->bokk = $district;
     if (!$this->_request->isPost()) {
         $captcha->setTimeout('300')->setWordLen('4')->setHeight('60')->setWidth('320')->setImgDir(APPLICATION_PATH . '/../public_html/captcha/images/')->setImgUrl($base . '/captcha/images/')->setFont(APPLICATION_PATH . '/../public_html/font/AHGBold.ttf')->setFontSize(24);
         $captcha->generate();
         $this->view->captcha = $captcha->render($this->view);
         $this->view->captchaID = $captcha->getId();
         // Dua chuoi Captcha vao session
         $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captcha->getId());
         $captchaSession->word = $captcha->getWord();
     } else {
         $captchaID = $this->_request->captcha_id;
         $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captchaID);
         $captchaIterator = $captchaSession->getIterator();
         $captchaWord = $captchaIterator['word'];
         if ($this->_request->captcha == $captchaWord) {
             $this->view->purifier = Zend_Registry::get('purifier');
             $conf = HTMLPurifier_Config::createDefault();
             $purifier = new HTMLPurifier($conf);
             $content = $purifier->purify($this->_request->getParam('content'));
             $menu_id = $purifier->purify($this->_request->getParam('parent_id'));
             $title = $purifier->purify($this->_request->getParam('title'));
             $dis = $purifier->purify($this->_request->getParam('dis'));
             $key = $purifier->purify($this->_request->getParam('key'));
             $description = $purifier->purify($this->_request->getParam('description'));
             // $home = $purifier->purify($this->_request->getParam('home'));
             $upload = new Zend_File_Transfer();
             $images = $upload->addValidator('Extension', false, 'jpg,png,gif');
             //print_r($images, FALSE) ;
             $images = $upload->getFilename();
             $images = basename($images);
             $url = khongdau($title);
             $random_digit = rand(00, 99999);
             if (basename($images)) {
                 $img = $url . "-" . $random_digit . $images;
                 $filterRename = new Zend_Filter_File_Rename(array('target' => 'Upload/' . $img, 'overwrite' => false));
                 $upload->addFilter($filterRename);
                 if (!$upload->receive()) {
                     thongbao("Vui lòng nhập đúng định dạng hình ảnh");
                     trang_truoc();
                     return;
                 }
                 $upload->receive();
             } else {
                 $img == "no-img.png";
             }
             // $position = $purifier->purify($this->_request->getParam('position'));
             //  $active = $purifier->purify($this->_request->getParam('active'));
             $price = $purifier->purify($this->_request->getParam('price'));
             $state = $purifier->purify($this->_request->getParam('state'));
             $sales = $purifier->purify($this->_request->getParam('sales'));
             $made_in = $purifier->purify($this->_request->getParam('made_in'));
             //$members = $purifier->purify($this->_request->getParam('members'));
             $session = new Zend_Session_Namespace('identity');
             $members = $session->username;
             $dictrict_id = $purifier->purify($this->_request->getParam('dictrict_id'));
             //  $type = $purifier->purify($this->_request->getParam('type'));
             $add = new Admin_Model_Products();
             $add->insert_products($title, $description, $img, $content, $menu_id, $price, $state, $sales, $dis, $key, "", 1, 2, $made_in, $members, $dictrict_id, 1);
             thongbao("Chúc mừng {$members}, bạn đã đăng tin thành công");
             chuyen_trang($base . "/thanh-vien.html");
         } else {
             thongbao('Ban nhap sai chuoi Captcha');
             trang_truoc();
         }
         $this->_helper->viewRenderer->setNoRender();
         $mask = APPLICATION_PATH . "/../public_html/captcha/images/*.png";
         array_map("unlink", glob($mask));
     }
 }
Example #28
0
 public function uploadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $db = new Fotos();
     $album_id = $this->_request->getPost('album_id');
     $db->setAlbumId($album_id);
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination(APPLICATION_PATH . '/../data/temp');
     $upload = new Zend_File_Transfer();
     $files = $upload->getFileInfo();
     if (!file_exists(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id)) {
         mkdir(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id, 0777, true);
     }
     foreach ($files as $file => $info) {
         if ($upload->isUploaded($file)) {
             $extension = substr($info['name'], strrpos($info['name'], '.') + 1);
             $filename = 'photo_' . time() . '.' . $extension;
             $adapter->addFilter('Rename', array('target' => APPLICATION_PATH . '/../data/temp/' . $filename, 'overwrite' => true));
             $adapter->receive($info['name']);
             if (!$adapter->receive()) {
                 $messages = $adapter->getMessages();
                 echo implode("\n", $messages);
                 exit;
             }
             //setFileName::Url
             $db->setUrl($filename);
             //setCapa::false (0)
             $db->setCapa(0);
             $imanee = new Imanee\Imanee(APPLICATION_PATH . '/../data/temp/' . $filename);
             //resized
             $imanee->resize(870, 653)->write(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id . DS . 'r_' . $filename, 80);
             //full
             //$imanee->resize(1024, 768)
             //        ->write(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id . DS . 'f_' . $filename, 80);
             //thumbnail
             $imanee->thumbnail(200, 200, true)->write(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id . DS . 't_' . $filename, 60);
             unlink(APPLICATION_PATH . '/../data/temp/' . $filename);
             $data = array('url' => $db->getUrl(), 'album_id' => $db->getAlbumId(), 'capa' => $db->getCapa());
             $foto_id = $db->saveFoto($data);
             $data['foto_id'] = $foto_id;
             echo json_encode($data);
         }
     }
 }
 public function updateProduct($post)
 {
     try {
         //use try on 21-11-13
         $db = $this->getAdapter();
         $db->beginTransaction();
         $db_global = new Application_Model_DbTable_DbGlobal();
         $session_user = new Zend_Session_Namespace('auth');
         $userName = $session_user->user_name;
         $GetUserId = $session_user->user_id;
         $GetUserLever = $session_user->level;
         $user_location = $session_user->location_id;
         $photoname = str_replace(" ", "_", $post['txt_name']) . '.jpg';
         $upload = new Zend_File_Transfer();
         $upload->addFilter('Rename', array('target' => PUBLIC_PATH . '/images/fi-upload/' . $photoname, 'overwrite' => true), 'photo');
         $receive = $upload->receive();
         if ($receive) {
             $post['photo'] = $photoname;
         }
         unset($post['MAX_FILE_SIZE']);
         $data = array('item_name' => $post['txt_name'], 'item_code' => $post['txt_code'], 'item_code' => $post['product_size'], 'photo' => $post['photo'], 'brand_id' => $post['branch_id'], 'cate_id' => $post['category'], 'stock_type' => $post['stock_type'], 'measure_id' => $post['measure_unit'], 'qty_perunit' => $post['qty_perunit'], 'label' => $post['label_perunit'], 'is_avaliable' => $post['status'], 'unit_sale_price' => $post['unit_sale_price'], 'price_per_qty' => $post['unit_sale_price'] / $post['qty_perunit'], 'remark' => $post['remark'], 'last_usermod' => $GetUserId, 'last_mod_date' => new Zend_Date());
         $id = $post['id'];
         $itemid = $db_global->updateRecord($data, $id, "pro_id", "tb_product");
         //for update product by user level
         if ($GetUserLever == 1 or $GetUserLever == 2) {
             $_model = new Application_Model_DbTable_DbGlobal();
             $identitys = explode(',', $post['identity']);
             $qtyonhand = 0;
             foreach ($identitys as $i) {
                 $qtyonhand = $qtyonhand + $post['qty_' . $i];
                 if (empty($post['item_price' . $i])) {
                     $post['item_price' . $i] = 0;
                 }
                 $_rs = $_model->QtyProLocation($id, $post['location_id_' . $i]);
                 if ($_rs !== "") {
                     if ($_rs['qty'] !== $post['qty_' . $i]) {
                         $_arr = array('qty' => $post['qty_' . $i], 'qty_warn' => $post['qty_warnning' . $i], 'unit_sale_price' => $post['item_price' . $i], 'price_per_qty' => $post['item_price' . $i] / $post['qty_perunit'], 'last_usermod' => $this->getUserId(), 'last_mod_date' => new Zend_Date());
                         $db_global->updateRecord($_arr, $_rs['ProLocationID'], "ProLocationID", "tb_prolocation");
                         //code here
                         $_arr_history = array('transaction_type' => 1, 'pro_id' => $id, 'date' => new Zend_Date(), 'location_id' => $post['location_id_' . $i], 'qty_edit' => $_rs['qty'] . " -> " . $post['qty_' . $i], 'qty_before' => $_rs['qty'], 'qty_after' => $post['qty_' . $i], 'user_mod' => $this->getUserId());
                         $db->insert("tb_move_history", $_arr_history);
                     }
                 } else {
                     $dataproduct = array('pro_id' => $id, 'LocationId' => $post['location_id_' . $i], 'qty' => $post['qty' . $i], 'qty_warn' => $post['qty_warnning' . $i], 'unit_sale_price' => $post['item_price' . $i], 'price_per_qty' => $post['item_price' . $i] / $post['qty_perunit'], 'last_usermod' => $this->getUserId(), 'last_mod_date' => new Zend_Date());
                     //add qty to product location
                     $db->insert("tb_prolocation", $dataproduct);
                     //add history
                     $data_history = array('transaction_type' => 1, 'pro_id' => $id, 'date' => new Zend_Date(), 'location_id' => $post['location_id_' . $i], 'qty_before' => 0, 'qty_edit' => "0 -> " . $post['qty' . $i], 'qty_after' => $post['qty' . $i], 'user_mod' => $this->getUserId());
                     $db->insert("tb_move_history", $data_history);
                     unset($dataproduct);
                     unset($data_history);
                 }
             }
             $_rs = $db_global->getQtyFromProductById($id);
             if (!empty($_rs)) {
                 $_qty_deffer = $qtyonhand - $_rs['qty_onhand'];
                 $_qtydata = array('qty_onhand' => $qtyonhand, 'qty_available' => $_rs['qty_available'] + $_qty_deffer);
                 $where = $db->quoteInto("pro_id=?", $id);
                 $this->update($_qtydata, $where);
             }
         } else {
             $identitys = explode(',', $post['identity']);
             $qty_onhand = 0;
             foreach ($identitys as $i) {
                 $qty = $post['qty_' . $i];
                 //not yet
                 if (empty($post['item_price' . $i])) {
                     $post['item_price' . $i] = 0;
                 }
                 $rows_exist = $db_global->porductLocationExist($id, $post["location_id_" . $i]);
                 $_arr = array('qty' => $post['qty_' . $i], 'qty_warn' => $post['qty_warnning' . $i], 'unit_sale_price' => $post['item_price' . $i], 'price_per_qty' => $post['item_price' . $i] / $post['qty_perunit'], 'last_usermod' => $this->getUserId(), 'last_mod_date' => new Zend_Date());
             }
             if ($rows_exist !== "") {
                 $db_global->updateRecord($_arr, $rows_exist["ProLocationID"], "ProLocationID", "tb_prolocation");
                 unset($arr);
                 if ($rows_exist["qty"] !== $qty) {
                     $data_history = array('transaction_type' => 1, 'pro_id' => $id, 'date' => new Zend_Date(), 'location_id' => $user_location, 'Remark' => $post['remark'], 'qty_edit' => $rows_exist["qty"] . " -> " . $qty, 'qty_before' => $rows_exist["qty"], 'qty_after' => $qty, 'user_mod' => $GetUserId);
                     $db->insert("tb_move_history", $data_history);
                     unset($data_history);
                     $_qty_deffer = $qty - $rows_exist["qty"];
                     $_rs = $db_global->getQtyFromProductById($id);
                     if (!empty($_rs)) {
                         $_qtydata = array('qty_onhand' => $_rs['qty_onhand'] + $_qty_deffer, 'qty_available' => $_rs['qty_available'] + $_qty_deffer);
                         $where = $db->quoteInto("pro_id=?", $id);
                         $this->update($_qtydata, $where);
                     }
                 }
             }
         }
         $db->commit();
         return true;
     } catch (Exception $e) {
         $db->rollBack();
         Application_Form_FrmMessage::messageError("UPDATE_FAIL", $e->getMessage());
     }
 }
 public function saveAction()
 {
     $request = $this->getRequest();
     $id = $this->getParam('id');
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $user_id = $auth->getIdentity()->id;
     }
     $form = $this->getSaveProductForm($id);
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $data = $this->getRequest()->getParams();
             $upload = new Zend_File_Transfer();
             $files = $upload->getFileInfo();
             $isValid = true;
             foreach ($files as $field => $file) {
                 if (!strlen($file["name"])) {
                     continue;
                 }
                 $extension = pathinfo($file['name'], PATHINFO_EXTENSION);
                 $filename = pathinfo($file['name'], PATHINFO_FILENAME);
                 if (!file_exists(UPLOADS_IMAGES)) {
                     mkdir(UPLOADS_IMAGES, 0774, true);
                 }
                 if (!file_exists(UPLOADS_DATA)) {
                     mkdir(UPLOADS_DATA, 0774, true);
                 }
                 // upload instructions for image
                 if ($field == 'image') {
                     $upload->addFilter('Rename', array('target' => UPLOADS_IMAGES . '/' . $filename . "_" . $user_id . "_" . time() . "." . $extension, 'overwrite' => TRUE), $field)->addValidator('Extension', false, array('jpg', 'jpeg', 'png'), $field);
                     $data['image'] = $filename . "_" . $user_id . "_" . time() . "." . $extension;
                 }
                 // upload instructions for file
                 if ($field == 'file') {
                     $upload->addFilter('Rename', array('target' => UPLOADS_DATA . '/' . $filename . "_" . $user_id . "_" . time() . "." . $extension, 'overwrite' => TRUE), $field)->addValidator('Extension', false, array('doc', 'docx', 'txt', 'pdf'), $field);
                     $data['file'] = $filename . "_" . $user_id . "_" . time() . "." . $extension;
                 }
                 if ($upload->isValid($field)) {
                     if (!$upload->receive($field)) {
                         $isValid = false;
                         foreach ($upload->getMessages() as $key => $val) {
                             $this->_helper->getHelper('FlashMessenger')->addMessage($val, 'error');
                         }
                     }
                 } else {
                     $isValid = false;
                     $this->_helper->getHelper('FlashMessenger')->addMessage($file['name'] . " is not valid {$field}", 'error');
                     //return $this->_helper->redirector('save');
                 }
             }
             if ($upload->hasErrors()) {
                 $errors = $upload->getMessages();
                 foreach ($errors as $error) {
                     $this->_helper->getHelper('FlashMessenger')->addMessage("{$error}", 'error');
                 }
                 return $this->_helper->redirector('save');
             }
             if ($isValid) {
                 $product = new Application_Model_Product();
                 $productMapper = new Application_Model_ProductMapper();
                 if ($id) {
                     $product = $productMapper->getProductById($id);
                 }
                 if (isset($data['file']) && $product->file && $product->file != $data['file'] || !isset($data['file']) && $product->file) {
                     $productMapper->delete_file($product->file);
                 }
                 if (isset($data['image']) && $product->image && $product->image != $data['image'] || !isset($data['image']) && $product->image) {
                     $productMapper->delete_image($product->image);
                 }
                 $product = new Application_Model_Product($data);
                 $productMapper->save($product);
                 return $this->_helper->redirector('dashboard', 'users');
             }
         }
     }
     $this->view->headScript()->appendFile(JS_DIR . '/' . self::DELETE_FIELD . '.js');
     $this->view->form = $form;
 }