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()); } }
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; } }
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; } }
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); }
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); }
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); }
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); }
/** * 上传用户文件的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; }
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); }
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 }
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); } }
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; } }
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); }
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); }
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()); } }
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"; } }
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)); } }
public function processpictureAction() { // disable rendering of the view and layout so that we can just echo the AJAX output $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $formvalues = $this->_getAllParams(); //debugMessage($this->_getAllParams()); $user = new UserAccount(); $user->populate(decode($this->_getParam('id'))); // only upload a file if the attachment field is specified $upload = new Zend_File_Transfer(); // set the file size in bytes $upload->setOptions(array('useByteString' => false)); // Limit the extensions to the specified file extensions $upload->addValidator('Extension', false, $config->uploads->photoallowedformats); $upload->addValidator('Size', false, $config->uploads->photomaximumfilesize); // base path for profile pictures $destination_path = BASE_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . "users" . DIRECTORY_SEPARATOR . "user_"; // determine if user has destination avatar folder. Else user is editing there picture if (!is_dir($destination_path . $user->getID())) { // no folder exits. Create the folder mkdir($destination_path . $user->getID(), 0777); } // set the destination path for the image $profilefolder = $user->getID(); $destination_path = $destination_path . $profilefolder . DIRECTORY_SEPARATOR . "avatar"; if (!is_dir($destination_path)) { mkdir($destination_path, 0777); } // create archive folder for each user $archivefolder = $destination_path . DIRECTORY_SEPARATOR . "archive"; if (!is_dir($archivefolder)) { mkdir($archivefolder, 0777); } $oldfilename = $user->getProfilePhoto(); //debugMessage($destination_path); $upload->setDestination($destination_path); // the profile image info before upload $file = $upload->getFileInfo('profileimage'); $uploadedext = findExtension($file['profileimage']['name']); $currenttime = time(); $currenttime_file = $currenttime . '.' . $uploadedext; $thefilename = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime_file; $thelargefilename = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime_file; $updateablefile = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime; $updateablelarge = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime; //debugMessage($thefilename); // rename the base image file $upload->addFilter('Rename', array('target' => $thefilename, 'overwrite' => true)); // exit(); // process the file upload if ($upload->receive()) { // debugMessage('Completed'); $file = $upload->getFileInfo('profileimage'); // debugMessage($file); $basefile = $thefilename; // convert png to jpg if (in_array(strtolower($uploadedext), array('png', 'PNG', 'gif', 'GIF'))) { ak_img_convert_to_jpg($thefilename, $updateablefile . '.jpg', $uploadedext); unlink($thefilename); } $basefile = $updateablefile . '.jpg'; // new profilenames $newlargefilename = "large_" . $currenttime_file; // generate and save thumbnails for sizes 250, 125 and 50 pixels resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime . '.jpg', 400); resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . 'medium_' . $currenttime . '.jpg', 165); // unlink($thefilename); unlink($destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime . '.jpg'); // exit(); // update the user with the new profile images try { $user->setProfilePhoto($currenttime . '.jpg'); $user->save(); // check if user already has profile picture and archive it $ftimestamp = current(explode('.', $user->getProfilePhoto())); $allfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*.*'); $currentfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*' . $ftimestamp . '*.*'); // debugMessage($currentfiles); $deletearray = array(); foreach ($allfiles as $value) { if (!in_array($value, $currentfiles)) { $deletearray[] = $value; } } // debugMessage($deletearray); if (count($deletearray) > 0) { foreach ($deletearray as $afile) { $afile_filename = basename($afile); rename($afile, $archivefolder . DIRECTORY_SEPARATOR . $afile_filename); } } $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate("global_update_success")); $this->_helper->redirector->gotoUrl($this->view->baseUrl("profile/picture/id/" . encode($user->getID()) . '/crop/1')); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); $session->setVar(FORM_VALUES, $this->_getAllParams()); $this->_helper->redirector->gotoUrl($this->view->baseUrl('profile/picture/id/' . encode($user->getID()))); } } else { // debugMessage($upload->getMessages()); $uploaderrors = $upload->getMessages(); $customerrors = array(); if (!isArrayKeyAnEmptyString('fileUploadErrorNoFile', $uploaderrors)) { $customerrors['fileUploadErrorNoFile'] = "Please browse for image on computer"; } if (!isArrayKeyAnEmptyString('fileExtensionFalse', $uploaderrors)) { $custom_exterr = sprintf($this->_translate->translate('global_invalid_ext_error'), $config->uploads->photoallowedformats); $customerrors['fileExtensionFalse'] = $custom_exterr; } if (!isArrayKeyAnEmptyString('fileUploadErrorIniSize', $uploaderrors)) { $custom_exterr = sprintf($this->_translate->translate('global_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0)); $customerrors['fileUploadErrorIniSize'] = $custom_exterr; } if (!isArrayKeyAnEmptyString('fileSizeTooBig', $uploaderrors)) { $custom_exterr = sprintf($this->_translate->translate('global_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0)); $customerrors['fileSizeTooBig'] = $custom_exterr; } $session->setVar(ERROR_MESSAGE, 'The following errors occured <ul><li>' . implode('</li><li>', $customerrors) . '</li></ul>'); $session->setVar(FORM_VALUES, $this->_getAllParams()); $this->_helper->redirector->gotoUrl($this->view->baseUrl('profile/picture/id/' . encode($user->getID()))); } // exit(); }
/** * Upload a new file for this user if one is present in the form data, or if * not, check if one has been uploaded previously. If there's one known * about, return its name. Uses session to persist an uploaded file's * details between form submission attempts, in the case the overall form * doesn't validate. * * @todo Move somewhere else. * * @return array Array indicating boolean true for success plus and an * associative array with uploaded file information (or empty array if no * file), or boolean false for failure and an array of error messages. */ private function _uploadPersistentCompanyApplicationFile() { // For storing original filename intact $session = new Zend_Session_Namespace('homelet_connect_referencing'); $tempFile = "{$this->_params->connect->tempPrivatePath}companyApp_{$this->_agentSchemeNumber}_{$this->_agentId}"; // Is a new file being sent? $upload = new Zend_File_Transfer('http'); if ($upload->isUploaded()) { $upload->getValidator('Upload')->setMessages(array(Zend_Validate_File_Upload::INI_SIZE => 'The uploaded file size exceeds system maximum (' . ini_get('upload_max_filesize') . ')', Zend_Validate_File_Upload::FORM_SIZE => 'The uploaded file size exceeds the HTML form maximum', Zend_Validate_File_Upload::PARTIAL => 'The uploaded file was only partially uploaded', Zend_Validate_File_Upload::NO_FILE => 'No file was uploaded', Zend_Validate_File_Upload::NO_TMP_DIR => 'Missing a temporary folder', Zend_Validate_File_Upload::CANT_WRITE => 'Failed to write file to disk', Zend_Validate_File_Upload::EXTENSION => 'File upload stopped by extension', Zend_Validate_File_Upload::UNKNOWN => 'Unknown upload error')); $upload->addValidator('Count', true, 1); $upload->addValidator('Size', false, $this->_params->connect->companyapps->fileUpload->maxSize->file); $upload->getValidator('Size')->setMessages(array(Zend_Validate_File_Size::TOO_SMALL => 'File \'%value%\' below minimum size', Zend_Validate_File_Size::TOO_BIG => 'File \'%value%\' above maximum size')); $upload->addValidator('MimeType', false, $this->_params->connect->companyapps->fileUpload->mimeTypes); $upload->getValidator('MimeType')->setMessages(array(Zend_Validate_File_MimeType::FALSE_TYPE => 'File \'%value%\' of incorrect MIME type')); $upload->addValidator('Extension', true, $this->_params->connect->companyapps->fileUpload->extensions); $upload->getValidator('Extension')->setMessages(array(Zend_Validate_File_Extension::FALSE_EXTENSION => 'File \'%value%\' of incorrect extension')); if ($upload->isValid()) { // First delete any old file that may have been previously // uploaded $this->_deleteCompanyApplicationFile(); // Upload new one $session->companyAppFile->originalFilename = $upload->getFileName(null, false); $upload->addFilter('Rename', $tempFile); if ($upload->receive()) { $session->companyAppFile->uploadedFile = $tempFile; } else { unset($session->companyAppFile); } } else { // Send back validation messages return array(false, $upload->getMessages()); } } // Is there one stored, perhaps already? If yes, return original // filename $returnVal = array(); if (isset($session->companyAppFile->originalFilename)) { $returnVal = array('originalName' => $session->companyAppFile->originalFilename, 'pathToFile' => $tempFile); } return array(true, $returnVal); }
public function addClient($_data){ $photoname = str_replace(" ", "_", $_data['name_en']) . '.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']=""; } try{ $client_code = $this->getClientCode($_data['branch_id']); $_arr=array( 'is_group' => $_data['is_group'], //'parent_id' =>$parent, 'branch_id' => $_data['branch_id'], 'parent_id' =>($_data['group_id']!=-1)?$_data['group_id']:"", 'group_code' => ($_data['is_group']==1)?$_data['group_code']:"", 'client_number'=> $client_code,//$_data['client_no'], 'name_kh' => $_data['name_kh'], 'name_en' => $_data['name_en'], 'join_with' => $_data['join_with'], 'join_nation_id'=> $_data['join_nation_id'], 'relate_with' => $_data['relate_with'], 'join_tel' => $_data['relate_tel'], 'sex' => $_data['sex'], 'dob' =>$_data['dob_client'], 'sit_status' => $_data['situ_status'], 'pro_id' => $_data['province'], 'dis_id' => $_data['district'], 'com_id' => $_data['commune'], 'village_id' => $_data['village'], 'street' => $_data['street'], 'house' => $_data['house'], 'photo_name' =>$_data['photo'], 'job' =>$_data['job'], 'nation_id'=>$_data['national_id'], 'phone' => $_data['phone'], 'spouse_name' => $_data['spouse'], 'spouse_nationid'=>$_data['spouse_nationid'], 'guarantor_with'=>$_data['guarantor_with'], 'guarantor_tel'=>$_data['guarantor_tel'], 'create_date' => date("Y-m-d"), 'remark' => $_data['desc'], 'status' => $_data['status'], 'client_d_type' => $_data['client_d_type'], 'join_d_type' => $_data['join_d_type'], 'guarantor_d_type' => $_data['guarantor_d_type'], 'guarantor_address' => $_data['guarantor_address'], 'user_id' => $this->getUserId(), 'dob_guarantor' => $_data['dob_guarantor'], 'dob_join_acc' => $_data['dob_join_acc'], ); if(!empty($_data['id'])){ $where = 'client_id = '.$_data['id']; $this->update($_arr, $where); return $_data['id']; }else{ //echo $this->insert($_arr);exit(); return $this->insert($_arr); } }catch(Exception $e){ Application_Model_DbTable_DbUserLog::writeMessageError($e->getMessage()); } }
/** * 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á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; }
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 pro_id =" . $id; $old_photo = $db->fetchRow($sql); foreach ($old_photo as $old_photos) { $data['icon'] = $old_photos; } } // $pro_exist = $this->getProductExist($id); // if(!empty($pro_exist)){ // $p_qtyohand = $pro_exist["p_qty_onhand"]; // $p_qtyavailable = $pro_exist["p_qty_available"]; // $pl_qtyohand = $pro_exist["pl_qty_onhand"]; // $pl_qtyavailable = $pro_exist["pl_qty_available"]; // } $arr = array('cate_id' => $data["cat_id"], 'name_en' => $data["name_en"], 'name_kh' => $data["name_km"], 'item_code' => $data["pro_code"], 'cu_id' => $data["currency"], 'unit_sale_price' => $data["unit_price"], 'price_per_qty' => $data["qty_price"], 'brand_id' => $data["brand"], 'measure_id' => $data["measure"], 'label' => $data["label"], 'stock_type' => $data["stock_type"], 'item_size' => $data["pro_size"], 'qty_perunit' => $data["qty_per_unit"], 'description' => $data["description"], 'status' => $data["status"], 'last_mod_date' => date("y-m-d"), 'icon' => $data["icon"], 'last_usermod' => $GetUserId); $where = $db->quoteInto("pro_id=?", $id); $this->update($arr, $where); $arr_l = array('unit_sale_price' => $data["unit_price"], 'price_per_qty' => $data["qty_price"], 'last_mod_date' => date("y-m-d"), 'last_usermod' => $GetUserId); $this->_name = "tb_prolocation"; $where = array("pro_id=?" => $id, "location_id=?" => 1); $db->getProfiler()->setEnabled(true); $this->update($arr_l, $where); Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQuery()); Zend_Debug::dump($db->getProfiler()->getLastQueryProfile()->getQueryParams()); $db->getProfiler()->setEnabled(false); $data_history = array('transaction_type' => 1, 'pro_id' => $id, 'date' => new Zend_Date(), 'location_id' => 1, 'qty_edit' => "0 -> " . $data["qty"], 'qty_before' => 0, 'qty_after' => $data["qty"], 'user_mod' => $GetUserId); $db->insert("tb_move_history", $data_history); // exit(); $db->commit(); } catch (Exception $e) { $db->rollBack(); echo $e->getMessage(); exit; } }
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'); }
function regAction() { if ($this->_request->isPost('reg-form')) { Zend_Loader::loadClass('Zend_Filter_StripTags'); Zend_Loader::loadClass('Zend_File_Transfer'); Zend_Loader::loadClass('Zend_Date'); Zend_Loader::loadClass('Zend_Mail'); Zend_Loader::loadClass('Zend_Validate_EmailAddress'); Zend_Loader::loadClass('Zend_Validate_StringLength'); Zend_Loader::loadClass('Zend_Validate_Alnum'); $filter = new Zend_Filter_StripTags(); $email = trim($filter->filter($this->_request->getPost('reg-email'))); $username = trim($filter->filter($this->_request->getPost('reg-name'))); $password = trim($filter->filter($this->_request->getPost('reg-pswd'))); $password_confirm = trim($filter->filter($this->_request->getPost('reg-pswd-verification'))); $real_name = trim($filter->filter($this->_request->getPost('reg-real-name'))); $file_name = ''; $warnings = new Zend_Session_Namespace(); $warnings->username = $username; $warnings->email = $email; $warnings->real_name = $real_name; $warnings->error = ''; $error_msg = ''; $mail_val = new Zend_Validate_EmailAddress(); $name_lenght_val = new Zend_Validate_StringLength(6, 12); $name_an_val = new Zend_Validate_Alnum(); $pass_lenght_val = new Zend_Validate_StringLength(6, 16); $real_name_lenght_val = new Zend_Validate_StringLength(0, 60); if ($email == '') { $error_msg .= '<p>Enter your email.</p>'; } else { if (!$mail_val->isValid($email)) { foreach ($mail_val->getMessages() as $message) { $error_msg .= '<p>' . $message . '</p>'; } } else { $data = new Users(); $query = 'email = "' . $email . '"'; $data_row = $data->fetchRow($query); if ($data_row['email'] != '') { $error_msg .= '<p>User with such an email is already registered.</p>'; } } } if ($username == '') { $error_msg .= '<p>Enter your username.</p>'; } else { if (!$name_lenght_val->isValid($username) || !$name_an_val->isValid($username)) { foreach ($name_lenght_val->getMessages() as $message) { $error_msg .= '<p>' . $message . '</p>'; } foreach ($name_an_val->getMessages() as $message) { $error_msg .= '<p>' . $message . '</p>'; } } else { $data = new Users(); $query = 'login = "******"'; $data_row = $data->fetchRow($query); if ($data_row['login'] != '') { $error_msg .= '<p>User with such an username is already registered.</p>'; } } } if ($password == '' || !$pass_lenght_val->isValid($password)) { $error_msg .= '<p>Enter password (must consist 6 to 16 characters).</p>'; } else { if ($password_confirm == '') { $error_msg .= '<p>Empty verification password.</p>'; } else { if ($password != $password_confirm) { $error_msg .= '<p>The entered passwords do not match.</p>'; } else { $salt = substr(sha1(microtime(true) . rand(1, 99999)), 0, 3); $password = sha1($password . $salt); } } } if ($real_name != '') { if (!$real_name_lenght_val->isValid($real_name)) { foreach ($real_name_lenght_val->getMessages() as $message) { $error_msg .= '<p>' . $message . '</p>'; } } } $upload = new Zend_File_Transfer(); if ($upload->isUploaded()) { $upload->setDestination('public/upload/avatars/'); $upload->addValidator('IsImage', false); $upload->addValidator('Size', false, 1024 * 1024); if (!$upload->isValid()) { foreach ($upload->getMessages() as $message) { $error_msg .= '<p>' . $message . '</p>'; } } else { $upload_info = $upload->getFileName(); $file_ext = mb_substr($upload_info, strrpos($upload_info, '.') + 1); $file_name = $username . '.' . $file_ext; $upload->addFilter('Rename', array('target' => 'public/upload/avatars/' . $file_name, 'overwrite' => true)); } } if ($error_msg != '') { $warnings->error = $error_msg; $warnings->status = ''; $this->_redirect('/register/'); return; } else { $date = new Zend_Date(); $current_date = $date->toString('YYYY-MM-dd'); $upload->receive(); $data = array('login' => $username, 'email' => $email, 'password' => $password, 'salt' => $salt, 'real_name' => $real_name, 'reg_date' => $current_date, 'avatar' => $file_name, 'last_login' => '-'); $user = new Users(); $user->insert($data); $warnings->error = '<p>Registration complete.</p><p>Now check your E-Mail to activate your profile.</p>'; $warnings->username = ''; $warnings->email = ''; $warnings->real_name = ''; $warnings->status = ' reg_ok'; $mail = new Zend_Mail(); $hash = sha1($email . $salt); $url = $this->getRequest()->getServer('HTTP_HOST'); $mail->setBodyHtml('<p>To activate your profile follow the link below:</p> <p>Link: <a href="http://' . $url . '/register/activate/' . $hash . '">http://' . $url . '/register/activate/' . $hash . '</a></p> <p>Thanks for your registration.</p> '); $mail->setFrom('*****@*****.**', 'Administrator'); $mail->addTo($email, $username); $mail->setSubject('Test activation link'); $mail->send(); $this->_redirect('/register/'); return; } } }
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; }
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 photoUploadAction() { if ($this->request->isPost()) { // POST METHOD $result = 0; $upload = new Zend_File_Transfer(); $upload->addValidator('Size', false, 5120000); //5M $uid = uniqid(); $destination = $this->getTmpFile($uid); $upload->addFilter('Rename', $destination); if ($upload->isValid()) { if ($upload->receive()) { $result = $uid; } } echo $result; exit; } else { // GET METHOD $this->view->title = "上传图片"; } }