public function pjActionIndex()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         if (isset($_POST['working_time'])) {
             $pjWorkingTimeModel = pjWorkingTimeModel::factory();
             $arr = $pjWorkingTimeModel->find($_POST['location_id'])->getData();
             $data = array();
             $data['location_id'] = $_POST['location_id'];
             $types = array('p_' => 'pickup', 'd_' => 'delivery');
             $weekDays = pjUtil::getWeekdays();
             foreach ($types as $prefix => $type) {
                 foreach ($weekDays as $day) {
                     if (!isset($_POST[$prefix . $day . '_dayoff'])) {
                         $data[$prefix . $day . '_from'] = $_POST[$prefix . $day . '_hour_from'] . ":" . $_POST[$prefix . $day . '_minute_from'];
                         $data[$prefix . $day . '_to'] = $_POST[$prefix . $day . '_hour_to'] . ":" . $_POST[$prefix . $day . '_minute_to'];
                     }
                 }
             }
             if (count($arr) > 0) {
                 $pjWorkingTimeModel->reset()->setAttributes(array('location_id' => $_POST['location_id']))->erase();
             }
             $pjWorkingTimeModel->reset()->setAttributes($data)->insert();
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminTime&action=pjActionIndex&id=" . $_POST['location_id'] . "&err=AT01");
         }
         if (isset($_POST['custom_time'])) {
             $date = pjUtil::formatDate($_POST['date'], $this->option_arr['o_date_format']);
             $pjDateModel = pjDateModel::factory();
             $pjDateModel->where('type', $_POST['type'])->where('date', $date)->eraseAll();
             $data = array();
             $data['location_id'] = $_POST['location_id'];
             $data['start_time'] = join(":", array($_POST['start_hour'], $_POST['start_minute']));
             $data['end_time'] = join(":", array($_POST['end_hour'], $_POST['end_minute']));
             $data['date'] = $date;
             $data['type'] = $_POST['type'];
             $data['is_dayoff'] = $_POST['is_dayoff'];
             $pjDateModel->reset()->setAttributes($data)->insert();
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminTime&action=pjActionIndex&id=" . $_POST['location_id'] . "&err=AT02&tab_id=tabs-2");
         }
         $arr = pjLocationModel::factory()->find($_GET['id'])->getData();
         if (count($arr) === 0) {
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminLocations&action=pjActionIndex&err=AL08");
         }
         $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang($arr['id'], 'pjLocation');
         $this->set('arr', $arr);
         $this->set('wt_arr', pjWorkingTimeModel::factory()->find($_GET['id'])->getData());
         $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
         $this->appendJs('additional-methods.js', PJ_THIRD_PARTY_PATH . 'validate/');
         $this->appendJs('jquery.datagrid.js', PJ_FRAMEWORK_LIBS_PATH . 'pj/js/');
         $this->appendJs('pjAdminTime.js');
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionCloneUser()
 {
     $this->setAjax(true);
     if ($this->isXHR()) {
         if (isset($_POST['record']) && count($_POST['record']) > 0) {
             $MultiLangModel = new pjMultiLangModel();
             $data = pjUserModel::factory()->whereIn('id', $_POST['record'])->findAll()->getData();
             foreach ($data as $item) {
                 $item_id = $item['id'];
                 unset($item['id']);
                 unset($item['email']);
                 $id = pjUserModel::factory($item)->insert()->getInsertId();
                 if ($id !== false && (int) $id > 0) {
                     $_data = pjMultiLangModel::factory()->getMultiLang($item_id, 'pjUser');
                     $MultiLangModel->saveMultiLang($_data, $id, 'pjUser');
                 }
             }
         }
     }
     exit;
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin() || $this->isEditor()) {
         if (isset($_POST['extra_update'])) {
             pjExtraModel::factory()->where('id', $_POST['id'])->limit(1)->modifyAll($_POST);
             if (isset($_POST['i18n'])) {
                 pjMultiLangModel::factory()->updateMultiLang($_POST['i18n'], $_POST['id'], 'pjExtra', 'data');
             }
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminExtras&action=pjActionIndex&err=AE01");
         } else {
             $arr = pjExtraModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminExtras&action=pjActionIndex&err=AE08");
             }
             $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang($arr['id'], 'pjExtra');
             $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('pjAdminExtras.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionClean()
 {
     $this->checkLogin();
     if (!$this->isAdmin()) {
         $this->set('status', 2);
         return;
     }
     if (isset($_POST['clean_step'])) {
         if ($_POST['clean_step'] == 1) {
             $pjMultiLangModel = pjMultiLangModel::factory();
             $arr = pjMultiLangModel::factory()->select('t1.id')->join('pjField', 't2.id=t1.foreign_id', 'left')->where('t1.model', 'pjField')->where('t2.id IS NULL')->findAll()->getDataPair(null, 'id');
             if (!empty($arr)) {
                 $pjMultiLangModel->reset()->whereIn('id', $arr)->eraseAll();
                 $this->pjActionUpdateFieldsIndex();
             }
         }
         if ($_POST['clean_step'] == 2) {
             if (isset($_POST['field_id']) && !empty($_POST['field_id'])) {
                 pjFieldModel::factory()->whereIn('id', $_POST['field_id'])->eraseAll();
                 pjMultiLangModel::factory()->where('model', 'pjField')->whereIn('foreign_id', $_POST['field_id'])->eraseAll();
                 $this->pjActionUpdateFieldsIndex();
             }
         }
         pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjLocale&action=pjActionClean");
     }
     # Step 1
     $step1_arr = pjMultiLangModel::factory()->select('t1.id')->join('pjField', 't2.id=t1.foreign_id', 'left')->where('t1.model', 'pjField')->where('t2.id IS NULL')->findAll()->getDataPair(null, 'id');
     $this->set('step1_arr', $step1_arr);
     # Step 2
     $keys = $start = $data = array();
     pjToolkit::readDir($data, PJ_APP_PATH);
     foreach ($data as $file) {
         $ext = pjToolkit::getFileExtension($file);
         if ($ext !== 'php') {
             continue;
         }
         $string = file_get_contents($file);
         if ($string !== FALSE) {
             preg_match_all('/__\\(\\s*\'(\\w+)\'\\s*(?:,\\s*(true|false))?\\)/i', $string, $matches);
             if (!empty($matches[1])) {
                 foreach ($matches[1] as $k => $m) {
                     if (!empty($matches[2][$k]) && strtolower($matches[2][$k]) == 'true') {
                         $start[] = $m;
                     } else {
                         $keys[] = $m;
                     }
                 }
             }
         }
     }
     $keys = array_unique($keys);
     $keys = array_values($keys);
     $start = array_unique($start);
     $start = array_values($start);
     if (!empty($keys) || !empty($start)) {
         $field_arr = pjFieldModel::factory()->whereNotIn('t1.key', $keys)->whereNotIn("SUBSTRING_INDEX(t1.key, '_ARRAY_', 1)", $start)->orderBy("FIELD(t1.type, 'backend', 'frontend', 'arrays'), t1.key ASC", false)->findAll()->getData();
         $this->set('field_arr', $field_arr);
     }
     $this->appendJs('pjLocale.js', $this->getConst('PLUGIN_JS_PATH'));
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin() || $this->isEditor()) {
         $post_max_size = pjUtil::getPostMaxSize();
         if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > $post_max_size) {
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminProducts&action=pjActionIndex&err=AP06");
         }
         if (isset($_POST['product_update'])) {
             $pjProductModel = pjProductModel::factory();
             $err = 'AP01';
             $arr = $pjProductModel->find($_POST['id'])->getData();
             if (empty($arr)) {
                 pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminProducts&action=pjActionIndex&err=AP08");
             }
             $data = array();
             if (isset($_FILES['image'])) {
                 if ($_FILES['image']['error'] == 0) {
                     if (getimagesize($_FILES['image']["tmp_name"]) != false) {
                         if (!empty($arr['image'])) {
                             @unlink(PJ_INSTALL_PATH . $arr['image']);
                         }
                         $Image = new pjImage();
                         if ($Image->getErrorCode() !== 200) {
                             $Image->setAllowedTypes(array('image/png', 'image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg'));
                             if ($Image->load($_FILES['image'])) {
                                 $resp = $Image->isConvertPossible();
                                 if ($resp['status'] === true) {
                                     $hash = md5(uniqid(rand(), true));
                                     $image_path = PJ_UPLOAD_PATH . 'products/' . $_POST['id'] . '_' . $hash . '.' . $Image->getExtension();
                                     $Image->loadImage($_FILES['image']["tmp_name"]);
                                     $Image->setFillColor($this->imageFillColor)->resize(116, 87);
                                     $Image->saveImage($image_path);
                                     $data['image'] = $image_path;
                                 }
                             }
                         }
                     } else {
                         $err = 'AP10';
                     }
                 } else {
                     if ($_FILES['image']['error'] != 4) {
                         $err = 'AP10';
                     }
                 }
             }
             if (isset($_POST['is_featured'])) {
                 $data['is_featured'] = 1;
                 unset($_POST['is_featured']);
             } else {
                 $data['is_featured'] = 0;
             }
             $pjProductModel->reset()->where('id', $_POST['id'])->limit(1)->modifyAll(array_merge($_POST, $data));
             if (isset($_POST['i18n'])) {
                 pjMultiLangModel::factory()->updateMultiLang($_POST['i18n'], $_POST['id'], 'pjProduct', 'data');
                 $pjMultiLangModel = pjMultiLangModel::factory();
                 $pjProductPriceModel = pjProductPriceModel::factory();
                 if ($_POST['set_different_sizes'] == 'T') {
                     if (isset($_POST['index_arr']) && $_POST['index_arr'] != '') {
                         $index_arr = explode("|", $_POST['index_arr']);
                         foreach ($index_arr as $k => $v) {
                             if (strpos($v, 'fd') !== false) {
                                 $p_data = array();
                                 $p_data['product_id'] = $_POST['id'];
                                 $p_data['price'] = $_POST['product_price'][$v];
                                 $price_id = $pjProductPriceModel->reset()->setAttributes($p_data)->insert()->getInsertId();
                                 if ($price_id !== false && (int) $price_id > 0) {
                                     foreach ($_POST['i18n'] as $locale => $locale_arr) {
                                         foreach ($locale_arr as $field => $content) {
                                             if (is_array($content)) {
                                                 $insert_id = $pjMultiLangModel->reset()->setAttributes(array('foreign_id' => $price_id, 'model' => 'pjProductPrice', 'locale' => $locale, 'field' => $field, 'content' => $content[$v], 'source' => 'data'))->insert()->getInsertId();
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 $p_data = array();
                                 $p_data['price'] = $_POST['product_price'][$v];
                                 $pjProductPriceModel->reset()->where('id', $v)->limit(1)->modifyAll($p_data);
                                 foreach ($_POST['i18n'] as $locale => $locale_arr) {
                                     foreach ($locale_arr as $field => $content) {
                                         if (is_array($content)) {
                                             $sql = sprintf("INSERT INTO `%1\$s` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)\n\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (NULL, :foreign_id, :model, :locale, :field, :update_content, :source)\n\t\t\t\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE `content` = :update_content, `source` = :source;", $pjMultiLangModel->getTable());
                                             $foreign_id = $v;
                                             $model = 'pjProductPrice';
                                             $source = 'data';
                                             $update_content = $content[$v];
                                             $modelObj = $pjMultiLangModel->reset()->prepare($sql)->exec(compact('foreign_id', 'model', 'locale', 'field', 'update_content', 'source'));
                                             if ($modelObj->getAffectedRows() > 0 || $modelObj->getInsertId() > 0) {
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (isset($_POST['remove_arr']) && $_POST['remove_arr'] != '') {
                         $remove_arr = explode("|", $_POST['remove_arr']);
                         $pjMultiLangModel->reset()->where('model', 'pjProductPrice')->whereIn('foreign_id', $remove_arr)->eraseAll();
                         $pjProductPriceModel->reset()->whereIn('id', $remove_arr)->eraseAll();
                     }
                     $pjProductModel->reset()->where('id', $_POST['id'])->limit(1)->modifyAll(array('price' => ':NULL'));
                 } else {
                     $id_arr = $pjProductPriceModel->where('product_id', $_POST['id'])->findAll()->getDataPair("id", "id");
                     $pjMultiLangModel->reset()->where('model', 'pjProductPrice')->whereIn('foreign_id', $id_arr);
                     $pjProductPriceModel->reset()->where('product_id', $_POST['id'])->eraseAll();
                 }
             }
             $pjProductCategoryModel = pjProductCategoryModel::factory();
             $pjProductCategoryModel->where('product_id', $_POST['id'])->eraseAll();
             if (isset($_POST['category_id']) && is_array($_POST['category_id']) && count($_POST['category_id']) > 0) {
                 $pjProductCategoryModel->reset()->begin();
                 foreach ($_POST['category_id'] as $category_id) {
                     $pjProductCategoryModel->reset()->set('product_id', $_POST['id'])->set('category_id', $category_id)->insert();
                 }
                 $pjProductCategoryModel->commit();
             }
             $pjProductExtraModel = pjProductExtraModel::factory();
             $pjProductExtraModel->where('product_id', $_POST['id'])->eraseAll();
             if (isset($_POST['extra_id']) && is_array($_POST['extra_id']) && count($_POST['extra_id']) > 0) {
                 $pjProductExtraModel->reset()->begin();
                 foreach ($_POST['extra_id'] as $extra_id) {
                     $pjProductExtraModel->reset()->set('product_id', $_POST['id'])->set('extra_id', $extra_id)->insert();
                 }
                 $pjProductExtraModel->commit();
             }
             if ($err == 'AP01') {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminProducts&action=pjActionIndex&err=AP01");
             } else {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminProducts&action=pjActionUpdate&id=" . $_POST['id'] . "&err=AP10");
             }
         } else {
             $pjMultiLangModel = pjMultiLangModel::factory();
             $arr = pjProductModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminProducts&action=pjActionIndex&err=AP08");
             }
             $arr['i18n'] = $pjMultiLangModel->getMultiLang($arr['id'], 'pjProduct');
             $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->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='" . $this->getLocaleId() . "'", '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='" . $this->getLocaleId() . "'", 'left outer')->orderBy('name ASC')->findAll()->getData());
             $this->set('category_id_arr', pjProductCategoryModel::factory()->where("product_id", $_GET['id'])->findAll()->getDataPair("category_id", "category_id"));
             $this->set('extra_id_arr', pjProductExtraModel::factory()->where("product_id", $_GET['id'])->findAll()->getDataPair("extra_id", "extra_id"));
             if ($arr['set_different_sizes'] == 'T') {
                 $size_arr = pjProductPriceModel::factory()->where('product_id', $_GET['id'])->findAll()->getData();
                 foreach ($size_arr as $k => $v) {
                     $size_arr[$k]['i18n'] = pjMultiLangModel::factory()->getMultiLang($v['id'], 'pjProductPrice');
                 }
                 $this->set('size_arr', $size_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('jquery.multiselect.min.js', PJ_THIRD_PARTY_PATH . 'multiselect/');
             $this->appendCss('jquery.multiselect.css', PJ_THIRD_PARTY_PATH . 'multiselect/');
             $this->appendJs('pjAdminProducts.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin() || $this->isEditor()) {
         if (isset($_POST['location_update'])) {
             $data = array();
             if (empty($_POST['lat']) && empty($_POST['lng'])) {
                 $data = pjAppController::getCoords($_POST['i18n'][$this->getLocaleId()]['address']);
             }
             pjLocationModel::factory()->where('id', $_POST['id'])->limit(1)->modifyAll(array_merge($_POST, $data));
             if (isset($_POST['i18n'])) {
                 pjMultiLangModel::factory()->updateMultiLang($_POST['i18n'], $_POST['id'], 'pjLocation', 'data');
             }
             $pjLocationCoordModel = pjLocationCoordModel::factory();
             $pjLocationCoordModel->where('location_id', $_POST['id'])->eraseAll();
             if (isset($_POST['data'])) {
                 foreach ($_POST['data'] as $type => $coords) {
                     foreach ($coords as $hash => $d) {
                         $pjLocationCoordModel->reset()->setAttributes(array('location_id' => $_POST['id'], 'type' => $type, 'hash' => md5($hash), 'data' => $d))->insert();
                     }
                 }
             }
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminLocations&action=pjActionUpdate&id=" . $_POST['id'] . "&err=AL01");
         } else {
             $arr = pjLocationModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminLocations&action=pjActionIndex&err=AL08");
             }
             $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang($arr['id'], 'pjLocation');
             $this->set('arr', $arr);
             $this->set('coord_arr', pjLocationCoordModel::factory()->where('location_id', $_GET['id'])->findAll()->getData());
             $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('js?sensor=false&libraries=drawing', 'https://maps.googleapis.com/maps/api/', TRUE);
             $this->appendJs('pjAdminLocations.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isCountryReady()) {
         if (isset($_POST['country_update'])) {
             pjCountryModel::factory()->where('id', $_POST['id'])->limit(1)->modifyAll($_POST);
             if (isset($_POST['i18n'])) {
                 pjMultiLangModel::factory()->updateMultiLang($_POST['i18n'], $_POST['id'], 'pjCountry');
             }
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjCountry&action=pjActionIndex&err=PCY01");
         } else {
             $arr = pjCountryModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjCountry&action=pjActionIndex&err=PCY08");
             }
             $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang($arr['id'], 'pjCountry');
             $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'];
                 //Hack for jquery $.extend, to prevent (re)order of numeric keys in object
             }
             $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('pjCountry.js', $this->getConst('PLUGIN_JS_PATH'));
             $this->appendJs('index.php?controller=pjAdmin&action=pjActionMessages', PJ_INSTALL_URL, true);
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionReminderEmail()
 {
     $this->setAjax(true);
     if ($this->isXHR() && $this->isLoged()) {
         if (isset($_POST['send_email']) && isset($_POST['to']) && !empty($_POST['to']) && !empty($_POST['from']) && !empty($_POST['subject']) && !empty($_POST['message']) && !empty($_POST['id'])) {
             $Email = new pjEmail();
             $Email->setContentType('text/html');
             if ($this->option_arr['o_send_email'] == 'smtp') {
                 $Email->setTransport('smtp')->setSmtpHost($this->option_arr['o_smtp_host'])->setSmtpPort($this->option_arr['o_smtp_port'])->setSmtpUser($this->option_arr['o_smtp_user'])->setSmtpPass($this->option_arr['o_smtp_pass']);
             }
             $r = $Email->setTo($_POST['to'])->setFrom($_POST['from'])->setSubject($_POST['subject'])->send(pjUtil::textToHtml($_POST['message']));
             if (isset($r) && $r) {
                 pjAppController::jsonResponse(array('status' => 'OK', 'code' => 200, 'text' => __('lblEmailSent', true, false)));
             }
             pjAppController::jsonResponse(array('status' => 'ERR', 'code' => 100, 'text' => __('lblFailedToSend', true, false)));
         }
         if (isset($_GET['id']) && (int) $_GET['id'] > 0) {
             $pjOrderModel = pjOrderModel::factory();
             $arr = $pjOrderModel->join('pjClient', "t2.id=t1.client_id", 'left outer')->select('t1.*, t2.c_title, t2.c_email, t2.c_name, t2.c_phone, t2.c_company, t2.c_address_1, t2.c_address_2, t2.c_country, t2.c_state, t2.c_city, t2.c_zip, t2.c_notes')->find($_GET['id'])->getData();
             if (!empty($arr)) {
                 pjAppController::addOrderDetails($arr, $this->getLocaleId());
                 $tokens = pjAppController::getTokens($this->option_arr, $arr, PJ_SALT, $this->getLocaleId());
                 $pjMultiLangModel = pjMultiLangModel::factory();
                 $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $this->getLocaleId())->where('t1.field', 'o_email_confirmation_message')->limit(0, 1)->findAll()->getData();
                 $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $this->getLocaleId())->where('t1.field', 'o_email_confirmation_subject')->limit(0, 1)->findAll()->getData();
                 if (count($lang_message) === 1 && count($lang_subject) === 1) {
                     if ($arr['type'] == 'delivery') {
                         $message = str_replace(array('[Delivery]', '[/Delivery]'), array('', ''), $lang_message[0]['content']);
                     } else {
                         $message = preg_replace('/\\[Delivery\\].*\\[\\/Delivery\\]/s', '', $lang_message[0]['content']);
                     }
                     $subject_client = str_replace($tokens['search'], $tokens['replace'], $lang_subject[0]['content']);
                     $message_client = str_replace($tokens['search'], $tokens['replace'], $message);
                     $from = !empty($this->option_arr['o_sender_email']) ? $this->option_arr['o_sender_email'] : $this->getAdminEmail();
                     $this->set('arr', array('id' => $_GET['id'], 'client_email' => $arr['c_email'], 'from' => $from, 'message' => $message_client, 'subject' => $subject_client));
                 }
             } else {
                 exit;
             }
         } else {
             exit;
         }
     }
 }
 public function pjActionConfirmSend($option_arr, $data, $salt, $opt)
 {
     $Email = new pjEmail();
     if ($option_arr['o_send_email'] == 'smtp') {
         $Email->setTransport('smtp')->setSmtpHost($option_arr['o_smtp_host'])->setSmtpPort($option_arr['o_smtp_port'])->setSmtpUser($option_arr['o_smtp_user'])->setSmtpPass($option_arr['o_smtp_pass']);
     }
     $Email->setContentType('text/html');
     $pjMultiLangModel = pjMultiLangModel::factory();
     $admin_email = $this->getAdminEmail();
     $admin_phone = $this->getAdminPhone();
     $from_email = $admin_email;
     if (!empty($option_arr['o_sender_email'])) {
         $from_email = $option_arr['o_sender_email'];
     }
     $locale_id = isset($booking_arr['locale_id']) && (int) $booking_arr['locale_id'] > 0 ? (int) $booking_arr['locale_id'] : $this->getLocaleId();
     if ($opt == 'account' || $opt == 'forgot') {
         $tokens = pjAppController::getClientTokens($option_arr, $data, PJ_SALT, $this->getLocaleId());
         $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_' . $opt . '_message')->limit(0, 1)->findAll()->getData();
         $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_' . $opt . '_subject')->limit(0, 1)->findAll()->getData();
         if (count($lang_message) === 1 && count($lang_subject) === 1) {
             $message = str_replace($tokens['search'], $tokens['replace'], $lang_message[0]['content']);
             $Email->setTo($data['c_email'])->setFrom($from_email)->setSubject($lang_subject[0]['content'])->send(pjUtil::textToHtml($message));
         }
     } else {
         $tokens = pjAppController::getTokens($option_arr, $data, PJ_SALT, $this->getLocaleId());
         if ($option_arr['o_email_confirmation'] == 1 && $opt == 'confirm') {
             $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_confirmation_message')->limit(0, 1)->findAll()->getData();
             $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_confirmation_subject')->limit(0, 1)->findAll()->getData();
             if (count($lang_message) === 1 && count($lang_subject) === 1) {
                 if ($data['type'] == 'delivery') {
                     $message = str_replace(array('[Delivery]', '[/Delivery]'), array('', ''), $lang_message[0]['content']);
                 } else {
                     $message = preg_replace('/\\[Delivery\\].*\\[\\/Delivery\\]/s', '', $lang_message[0]['content']);
                 }
                 $message = str_replace($tokens['search'], $tokens['replace'], $message);
                 $Email->setTo($data['c_email'])->setFrom($from_email)->setSubject($lang_subject[0]['content'])->send(pjUtil::textToHtml($message));
             }
         }
         if ($option_arr['o_admin_email_confirmation'] == 1 && $opt == 'confirm') {
             $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_email_confirmation_message')->limit(0, 1)->findAll()->getData();
             $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_email_confirmation_subject')->limit(0, 1)->findAll()->getData();
             if (count($lang_message) === 1 && count($lang_subject) === 1) {
                 if ($data['type'] == 'delivery') {
                     $message = str_replace(array('[Delivery]', '[/Delivery]'), array('', ''), $lang_message[0]['content']);
                 } else {
                     $message = preg_replace('/\\[Delivery\\].*\\[\\/Delivery\\]/s', '', $lang_message[0]['content']);
                 }
                 $message = str_replace($tokens['search'], $tokens['replace'], $message);
                 $Email->setTo($admin_email)->setFrom($from_email)->setSubject($lang_subject[0]['content'])->send(pjUtil::textToHtml($message));
             }
             if (!empty($admin_phone)) {
                 $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_sms_confirmation_message')->limit(0, 1)->findAll()->getData();
                 if (count($lang_message) === 1) {
                     $message = str_replace($tokens['search'], $tokens['replace'], $lang_message[0]['content']);
                     $params = array('text' => $message, 'key' => md5($option_arr['private_key'] . PJ_SALT));
                     $params['number'] = $admin_phone;
                     $this->requestAction(array('controller' => 'pjSms', 'action' => 'pjActionSend', 'params' => $params), array('return'));
                 }
             }
         }
         if ($option_arr['o_email_payment'] == 1 && $opt == 'payment') {
             $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_payment_message')->limit(0, 1)->findAll()->getData();
             $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_payment_subject')->limit(0, 1)->findAll()->getData();
             if (count($lang_message) === 1 && count($lang_subject) === 1) {
                 if ($data['type'] == 'delivery') {
                     $message = str_replace(array('[Delivery]', '[/Delivery]'), array('', ''), $lang_message[0]['content']);
                 } else {
                     $message = preg_replace('/\\[Delivery\\].*\\[\\/Delivery\\]/s', '', $lang_message[0]['content']);
                 }
                 $message = str_replace($tokens['search'], $tokens['replace'], $message);
                 $Email->setTo($data['c_email'])->setFrom($from_email)->setSubject($lang_subject[0]['content'])->send(pjUtil::textToHtml($message));
             }
         }
         if ($option_arr['o_admin_email_payment'] == 1 && $opt == 'payment') {
             $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_email_payment_message')->limit(0, 1)->findAll()->getData();
             $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_email_payment_subject')->limit(0, 1)->findAll()->getData();
             if (count($lang_message) === 1 && count($lang_subject) === 1) {
                 if ($data['type'] == 'delivery') {
                     $message = str_replace(array('[Delivery]', '[/Delivery]'), array('', ''), $lang_message[0]['content']);
                 } else {
                     $message = preg_replace('/\\[Delivery\\].*\\[\\/Delivery\\]/s', '', $lang_message[0]['content']);
                 }
                 $message = str_replace($tokens['search'], $tokens['replace'], $message);
                 $Email->setTo($admin_email)->setFrom($from_email)->setSubject($lang_subject[0]['content'])->send(pjUtil::textToHtml($message));
             }
             if (!empty($admin_phone)) {
                 $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_sms_payment_message')->limit(0, 1)->findAll()->getData();
                 if (count($lang_message) === 1) {
                     $message = str_replace($tokens['search'], $tokens['replace'], $lang_message[0]['content']);
                     $params = array('text' => $message, 'key' => md5($option_arr['private_key'] . PJ_SALT));
                     $params['number'] = $admin_phone;
                     $this->requestAction(array('controller' => 'pjSms', 'action' => 'pjActionSend', 'params' => $params), array('return'));
                 }
             }
         }
         if ($option_arr['o_email_cancel'] == 1 && $opt == 'cancel') {
             $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_cancel_message')->limit(0, 1)->findAll()->getData();
             $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_email_cancel_subject')->limit(0, 1)->findAll()->getData();
             if (count($lang_message) === 1 && count($lang_subject) === 1) {
                 if ($data['type'] == 'delivery') {
                     $message = str_replace(array('[Delivery]', '[/Delivery]'), array('', ''), $lang_message[0]['content']);
                 } else {
                     $message = preg_replace('/\\[Delivery\\].*\\[\\/Delivery\\]/s', '', $lang_message[0]['content']);
                 }
                 $message = str_replace($tokens['search'], $tokens['replace'], $message);
                 $Email->setTo($data['c_email'])->setFrom($from_email)->setSubject($lang_subject[0]['content'])->send(pjUtil::textToHtml($message));
             }
         }
         if ($option_arr['o_admin_email_cancel'] == 1 && $opt == 'cancel') {
             $lang_message = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_email_cancel_message')->limit(0, 1)->findAll()->getData();
             $lang_subject = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $locale_id)->where('t1.field', 'o_admin_email_cancel_subject')->limit(0, 1)->findAll()->getData();
             if (count($lang_message) === 1 && count($lang_subject) === 1) {
                 if ($data['type'] == 'delivery') {
                     $message = str_replace(array('[Delivery]', '[/Delivery]'), array('', ''), $lang_message[0]['content']);
                 } else {
                     $message = preg_replace('/\\[Delivery\\].*\\[\\/Delivery\\]/s', '', $lang_message[0]['content']);
                 }
                 $message = str_replace($tokens['search'], $tokens['replace'], $message);
                 $Email->setTo($admin_email)->setFrom($from_email)->setSubject($lang_subject[0]['content'])->send(pjUtil::textToHtml($message));
             }
         }
     }
 }
 public function pjActionTerm()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         $arr = pjOptionModel::factory()->where('t1.foreign_id', $this->getForeignId())->orderBy('t1.order ASC')->findAll()->getData();
         $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang(1, 'pjOption');
         $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.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('pjAdminOptions.js');
     }
 }
 public static function setFields($locale)
 {
     $fields = pjMultiLangModel::factory()->select('t1.content, t2.key')->join('pjField', "t2.id=t1.foreign_id", 'inner')->where('t1.locale', $locale)->where('t1.model', 'pjField')->where('t1.field', 'title')->findAll()->getDataPair('key', 'content');
     $registry = pjRegistry::getInstance();
     $tmp = array();
     if ($registry->is('fields')) {
         $tmp = $registry->get('fields');
     }
     $arrays = array();
     foreach ($fields as $key => $value) {
         if (strpos($key, '_ARRAY_') !== false) {
             list($prefix, $suffix) = explode("_ARRAY_", $key);
             if (!isset($arrays[$prefix])) {
                 $arrays[$prefix] = array();
             }
             $arrays[$prefix][$suffix] = $value;
         }
     }
     require PJ_CONFIG_PATH . 'settings.inc.php';
     $fields = array_merge($tmp, $fields, $settings, $arrays);
     $registry->set('fields', $fields);
 }