public function pjActionCreate()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         if (isset($_POST['voucher_create'])) {
             $data = array();
             $data['code_for'] = $_POST['voucher_type'];
             $data['product_id'] = $_POST['product_id'];
             $data['category_id'] = $_POST['category_id'];
             $data['code'] = $_POST['code'];
             $data['discount'] = $_POST['discount'];
             $data['type'] = $_POST['type'];
             $data['user_id'] = $_POST['user_id'];
             $data['valid'] = $_POST['valid'];
             switch ($_POST['valid']) {
                 case 'fixed':
                     $data['date_from'] = pjUtil::formatDate($_POST['f_date'], $this->option_arr['o_date_format']);
                     $data['date_to'] = $data['date_from'];
                     $data['time_from'] = $_POST['f_hour_from'] . ":" . $_POST['f_minute_from'] . ":00";
                     $data['time_to'] = $_POST['f_hour_to'] . ":" . $_POST['f_minute_to'] . ":00";
                     break;
                 case 'period':
                     $data['date_from'] = pjUtil::formatDate($_POST['p_date_from'], $this->option_arr['o_date_format']);
                     $data['date_to'] = pjUtil::formatDate($_POST['p_date_to'], $this->option_arr['o_date_format']);
                     $data['time_from'] = $_POST['p_hour_from'] . ":" . $_POST['p_minute_from'] . ":00";
                     $data['time_to'] = $_POST['p_hour_to'] . ":" . $_POST['p_minute_to'] . ":00";
                     break;
                 case 'recurring':
                     $data['every'] = $_POST['r_every'];
                     $data['time_from'] = $_POST['r_hour_from'] . ":" . $_POST['r_minute_from'] . ":00";
                     $data['time_to'] = $_POST['r_hour_to'] . ":" . $_POST['r_minute_to'] . ":00";
                     break;
             }
             $id = pjVoucherModel::factory($data)->insert()->getInsertId();
             if ($id !== false && (int) $id > 0) {
                 $err = 'AV03';
             } else {
                 $err = 'AV04';
             }
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminVouchers&action=pjActionIndex&err={$err}");
         } else {
             $pjCategoryModel = pjCategoryModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjCategory' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select('t1.id, t2.content as name')->where('t1.user_id', $_SESSION['admin_user']['id'])->findAll()->getData();
             $this->set('cat_arr', $pjCategoryModel);
             $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('additional-methods.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('pjAdminVouchers.js');
             $this->appendJs('pjAdminVouchersFunction.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionGetLocale()
 {
     $this->setAjax(true);
     if ($this->isXHR()) {
         if (isset($_GET['locale']) && (int) $_GET['locale'] > 0) {
             pjAppController::setFields($_GET['locale']);
             $this->set('category_arr', pjCategoryModel::factory()->select('t1.*, t2.content AS name')->join('pjMultiLang', "t2.model='pjCategory' AND t2.foreign_id=t1.id AND t2.field='name' AND t2.locale='" . pjObject::escapeString($_GET['locale']) . "'", 'left outer')->where('t1.status', 'T')->orderBy('`order` ASC')->findAll()->getData());
             $this->set('extra_arr', pjExtraModel::factory()->select('t1.*, t2.content AS name')->join('pjMultiLang', "t2.model='pjExtra' AND t2.foreign_id=t1.id AND t2.field='name' AND t2.locale='" . pjObject::escapeString($_GET['locale']) . "'", 'left outer')->orderBy('name ASC')->findAll()->getData());
         }
     }
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin() || $this->isEditor()) {
         if (isset($_POST['category_update'])) {
             pjCategoryModel::factory()->where('id', $_POST['id'])->limit(1)->modifyAll($_POST);
             if (isset($_POST['i18n'])) {
                 pjMultiLangModel::factory()->updateMultiLang($_POST['i18n'], $_POST['id'], 'pjCategory', 'data');
             }
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminCategories&action=pjActionIndex&err=ACT01");
         } else {
             $arr = pjCategoryModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminCategories&action=pjActionIndex&err=ACT08");
             }
             $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang($arr['id'], 'pjCategory');
             $this->set('arr', $arr);
             $locale_arr = pjLocaleModel::factory()->select('t1.*, t2.file')->join('pjLocaleLanguage', 't2.iso=t1.language_iso', 'left')->where('t2.file IS NOT NULL')->orderBy('t1.sort ASC')->findAll()->getData();
             $lp_arr = array();
             foreach ($locale_arr as $item) {
                 $lp_arr[$item['id'] . "_"] = $item['file'];
             }
             $this->set('lp_arr', $locale_arr);
             $this->set('locale_str', pjAppController::jsonEncode($lp_arr));
             $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('jquery.multilang.js', PJ_FRAMEWORK_LIBS_PATH . 'pj/js/');
             $this->appendJs('jquery.tipsy.js', PJ_THIRD_PARTY_PATH . 'tipsy/');
             $this->appendCss('jquery.tipsy.css', PJ_THIRD_PARTY_PATH . 'tipsy/');
             $this->appendJs('pjAdminCategories.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 private function getCategories($get)
 {
     $user_id = '';
     //check front layout order data set or not.
     if (isset($_SESSION['order_data'])) {
         $user_id = $_SESSION['order_data']['o_user_id'];
     } else {
         $user_id = $_SESSION['admin_user']['id'];
     }
     $category_arr = '';
     //Get categories from DB.
     $category_arr = pjCategoryModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjCategory' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select("t1.*, t2.content as name")->where('t1.status', 'T')->where('t1.location_id', $_SESSION['order_data']['o_location_id'])->where('t1.user_id', $user_id)->orderBy("`order` ASC")->findAll()->getData();
     $open_id = null;
     $product_arr = array();
     if (isset($get['category_id'])) {
         $open_id = $get['category_id'];
         $this->_set('open_id', $open_id);
     } elseif (!empty($lc)) {
         $open_id = $category_arr[0]['id'];
         $this->_set('open_id', $open_id);
     } else {
         if (!$this->_is('open_id')) {
             foreach ($category_arr as $k => $v) {
                 if ($k == 0) {
                     $open_id = $v['id'];
                 }
             }
         } else {
             $open_id = $this->_get('open_id');
         }
     }
     if ($open_id != null) {
         $pjExtraModel = pjExtraModel::factory();
         $pjProductExtraTable = pjProductExtraModel::factory()->getTable();
         $pjProductPriceModel = pjProductPriceModel::factory();
         $product_arr = pjProductModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjProduct' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->join('pjMultiLang', "t3.foreign_id = t1.id AND t3.model = 'pjProduct' AND t3.locale = '" . $this->getLocaleId() . "' AND t3.field = 'description'", 'left')->select("t1.*, t2.content AS name, t3.content AS description")->where("(t1.id IN (SELECT TPC.product_id FROM `" . pjProductCategoryModel::factory()->getTable() . "` AS TPC WHERE TPC.category_id='{$open_id}'))")->orderBy("t1.is_featured DESC, t2.content ASC")->findAll()->getData();
         foreach ($product_arr as $k => $product) {
             $product['price_arr'] = array();
             $product['extra_arr'] = array();
             $product['extra_arr'] = $pjExtraModel->reset()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjExtra' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->where("(t1.id IN (SELECT TPE.extra_id FROM `" . $pjProductExtraTable . "` AS TPE WHERE TPE.product_id='" . $product['id'] . "'))")->select("t1.*, t2.content AS name")->orderBy("name ASC")->findAll()->getData();
             if ($product['set_different_sizes'] == 'T') {
                 $product['price_arr'] = $pjProductPriceModel->reset()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjProductPrice' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'price_name'", 'left')->where('t1.product_id', $product['id'])->select("t1.*, t2.content AS price_name")->findAll()->getData();
             }
             $product_arr[$k] = $product;
         }
     }
     return compact('category_arr', 'product_arr', 'open_id', 'mlocation_arr', 'lc');
 }