public function pjActionCreate()
 {
     $this->setLayout('pjAdminSignUpLayout');
     if (isset($_POST['user_singup'])) {
         $data = array();
         $data['is_active'] = 'T';
         $data['ip'] = $_SERVER['REMOTE_ADDR'];
         $id = pjUserModel::factory(array_merge($_POST, $data))->insert()->getInsertId();
         if ($id !== false && (int) $id > 0) {
             $err = 'AU03';
         } else {
             $err = 'AU04';
         }
         //Let's check when or not coming from clover.
         if (empty($_SESSION['cloverData'])) {
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdmin&action=pjActionLogin");
         } else {
             $_SESSION['user_id'] = $id;
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminSignUp&action=pjActionMain&case=signup");
         }
     } else {
         $this->set('role_arr', pjRoleModel::factory()->orderBy('t1.id ASC')->findAll()->getData());
         $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
         $this->appendJs('pjAdminUsers.js');
     }
 }
Пример #2
0
 public function pjActionConfig()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         $pjLogConfigModel = pjLogConfigModel::factory();
         if (isset($_POST['update_config'])) {
             $pjLogConfigModel->eraseAll();
             if (isset($_POST['filename']) && count($_POST['filename']) > 0) {
                 $pjLogConfigModel->begin();
                 foreach ($_POST['filename'] as $filename) {
                     $pjLogConfigModel->reset()->set('filename', $filename)->insert();
                 }
                 $pjLogConfigModel->commit();
             }
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjLog&action=pjActionConfig&err=PLG01");
         }
         $data = array();
         pjUtil::readDir($data, 'app/controllers/');
         pjUtil::readDir($data, 'app/plugins/');
         $this->set('data', $data);
         $this->set('config_arr', $pjLogConfigModel->findAll()->getDataPair('id', 'filename'));
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         if (isset($_POST['options_update'])) {
             $OptionModel = new pjOptionModel();
             foreach ($_POST as $key => $value) {
                 if (preg_match('/value-(string|text|int|float|enum|bool|color)-(.*)/', $key) === 1) {
                     list(, $type, $k) = explode("-", $key);
                     if (!empty($k)) {
                         $OptionModel->reset()->where('foreign_id', $this->getForeignId())->where('`key`', $k)->limit(1)->modifyAll(array('value' => $value));
                     }
                 }
             }
             if (isset($_POST['i18n'])) {
                 pjMultiLangModel::factory()->updateMultiLang($_POST['i18n'], 1, 'pjOption', 'data');
             }
             if (isset($_POST['next_action'])) {
                 switch ($_POST['next_action']) {
                     case 'pjActionIndex':
                         $err = 'AO01';
                         break;
                     case 'pjActionOrders':
                         $err = 'AO02';
                         break;
                     case 'pjActionClientDetails':
                         if ($_POST['tab_id'] == 'tabs-1') {
                             $err = 'AO03&tab_id=' . $_POST['tab_id'];
                         } else {
                             $err = 'AO06&tab_id=' . $_POST['tab_id'];
                         }
                         break;
                     case 'pjActionNotification':
                         if ($_POST['tab_id'] == 'tabs-3') {
                             $err = 'AO07&tab_id=' . $_POST['tab_id'];
                         } else {
                             $err = 'AO04&tab_id=' . $_POST['tab_id'];
                         }
                         break;
                     case 'pjActionTerm':
                         $err = 'AO05';
                         break;
                 }
             }
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminOptions&action=" . @$_POST['next_action'] . "&err={$err}");
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionIndex()
 {
     $user_id = base64_decode($_GET['restaurants']);
     $name = urldecode($_GET['name']);
     if (is_numeric($user_id) == TRUE) {
         //Get all location from location table.
         $pjLocationModel = pjLocationModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjLocation' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'")->where('t1.user_id', $user_id)->select("t1.*, t2.content as name")->findAll()->getData();
         $this->set('location', $pjLocationModel);
         $this->set('user', $user_id);
         $this->set('name', $name);
         $this->appendJs('pjFrontIndex.js');
     } else {
         pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdmin&action=pjActionLogin");
     }
 }
Пример #5
0
 public function pjActionIndex()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         if (isset($_POST['sms_post'])) {
             $pjOptionModel = pjOptionModel::factory();
             if (0 != $pjOptionModel->where('foreign_id', $this->getForeignId())->where('`key`', 'plugin_sms_api_key')->findCount()->getData()) {
                 $pjOptionModel->limit(1)->modifyAll(array('value' => $_POST['plugin_sms_api_key']));
             } else {
                 $pjOptionModel->setAttributes(array('foreign_id' => $this->getForeignId(), 'key' => 'plugin_sms_api_key', 'tab_id' => '99', 'value' => $_POST['plugin_sms_api_key'], 'type' => 'string', 'is_visible' => 0))->insert();
             }
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjSms&action=pjActionIndex&err=PSS02");
         }
         $this->appendJs('jquery.datagrid.js', PJ_FRAMEWORK_LIBS_PATH . 'pj/js/');
         $this->appendJs('pjSms.js', $this->getConst('PLUGIN_JS_PATH'));
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionPrice()
 {
     $this->checkLogin();
     if ($this->isAdmin() || $this->isEditor()) {
         if (isset($_POST['price_update'])) {
             $pjPriceModel = pjPriceModel::factory();
             $pjPriceModel->where('location_id', $_POST['location_id'])->eraseAll();
             if (isset($_POST['price']) && count($_POST['price']) > 0) {
                 foreach ($_POST['price'] as $k => $price) {
                     if ((double) $_POST['total_from'][$k] >= 0 && (double) $_POST['total_to'][$k] > 0 && (double) $_POST['total_from'][$k] <= (double) $_POST['total_to'][$k]) {
                         $pjPriceModel->reset()->setAttributes(array('location_id' => $_POST['location_id'], 'total_from' => $_POST['total_from'][$k], 'total_to' => $_POST['total_to'][$k], 'price' => $_POST['price'][$k]))->insert();
                     }
                 }
             }
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminLocations&action=pjActionPrice&id=" . $_POST['location_id'] . "&err=AL09");
         } else {
             $this->set('arr', pjPriceModel::factory()->where('location_id', $_GET['id'])->orderBy("t1.total_from ASC, t1.total_to ASC")->findAll()->getData());
             $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('pjAdminLocations.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         if (isset($_POST['voucher_update'])) {
             $data = array();
             $data['code'] = $_POST['code'];
             $data['discount'] = $_POST['discount'];
             $data['type'] = $_POST['type'];
             $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";
                     $data['every'] = array('NULL');
                     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";
                     $data['every'] = array('NULL');
                     break;
                 case 'recurring':
                     $data['date_from'] = array('NULL');
                     $data['date_to'] = array('NULL');
                     $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;
             }
             pjVoucherModel::factory()->where('id', $_POST['id'])->limit(1)->modifyAll($data);
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminVouchers&action=pjActionIndex&err=AV01");
         } else {
             $arr = pjVoucherModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminVouchers&action=pjActionIndex&err=AV08");
             }
             $this->set('arr', $arr);
             $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');
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionLicense()
 {
     $arr = pjOptionModel::factory()->where('t1.foreign_id', $this->getForeignId())->where('t1.key', 'private_key')->limit(1)->findAll()->getData();
     $hash = NULL;
     if (count($arr) === 1) {
         $hash = $arr[0]['value'];
     }
     pjUtil::redirect(base64_decode("aHR0cDovL3N1cHBvcnQuc3RpdmFzb2Z0LmNvbS9jaGVja2xpY2Vuc2Uv") . $hash);
 }
 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 pjActionPrintOrder()
 {
     $this->checkLogin();
     if ($this->isAdmin() || $this->isEditor()) {
         $this->setLayout('pjActionPrint');
         $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)) {
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminOrders&action=pjActionIndex&err=AR08");
         }
         $hash = sha1($arr['id'] . $arr['created'] . PJ_SALT);
         if ($hash != $_GET['hash']) {
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminOrders&action=pjActionIndex&err=AR08");
         }
         pjAppController::addOrderDetails($arr, $this->getLocaleId());
         $pjMultiLangModel = pjMultiLangModel::factory();
         $lang_template = $pjMultiLangModel->reset()->select('t1.*')->where('t1.model', 'pjOption')->where('t1.locale', $this->getLocaleId())->where('t1.field', 'o_print_order')->limit(0, 1)->findAll()->getData();
         $template = '';
         if (count($lang_template) === 1) {
             $template = $lang_template[0]['content'];
         }
         $template_arr = '';
         $data = pjAppController::getTokens($this->option_arr, $arr, PJ_SALT, $this->getLocaleId());
         $template_arr = str_replace($data['search'], $data['replace'], $template);
         $this->set('template_arr', $template_arr);
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionCancel()
 {
     $this->setLayout('pjActionCancel');
     $pjOrderModel = pjOrderModel::factory();
     if (isset($_POST['order_cancel'])) {
         $order_arr = $pjOrderModel->reset()->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($_POST['id'])->getData();
         if (count($order_arr) > 0) {
             $sql = "UPDATE `" . $pjOrderModel->getTable() . "` SET status = 'cancelled' WHERE SHA1(CONCAT(`id`, `created`, '" . PJ_SALT . "')) = '" . $_POST['hash'] . "'";
             $pjOrderModel->reset()->execute($sql);
             pjAppController::addOrderDetails($order_arr, $this->getLocaleId());
             pjFront::pjActionConfirmSend($this->option_arr, $order_arr, PJ_SALT, 'cancel');
             pjUtil::redirect($_SERVER['PHP_SELF'] . '?controller=pjFront&action=pjActionCancel&err=200');
         }
     } else {
         if (isset($_GET['hash']) && isset($_GET['id'])) {
             $arr = $pjOrderModel->reset()->join('pjClient', "t2.id=t1.client_id", 'left outer')->join('pjMultiLang', "t3.model='pjCountry' AND t3.foreign_id=t1.d_country_id AND t3.field='name' AND t3.locale='" . $this->getLocaleId() . "'", 'left outer')->join('pjMultiLang', "t4.model='pjCountry' AND t4.foreign_id=t1.location_id AND t4.field='name' AND t4.locale='" . $this->getLocaleId() . "'", 'left outer')->join('pjClient', "t2.id=t1.client_id", 'left outer')->select('t1.*, t3.content as d_country, t4.content as location, 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 (count($arr) == 0) {
                 $this->set('status', 2);
             } else {
                 if ($arr['status'] == 'cancelled') {
                     $this->set('status', 4);
                 } else {
                     $hash = sha1($arr['id'] . $arr['created'] . PJ_SALT);
                     if ($_GET['hash'] != $hash) {
                         $this->set('status', 3);
                     } else {
                         pjAppController::addOrderDetails($arr, $this->getLocaleId());
                         $this->set('arr', $arr);
                     }
                 }
             }
         } elseif (!isset($_GET['err'])) {
             $this->set('status', 1);
         }
     }
 }
 public function pjActionProfile()
 {
     $this->checkLogin();
     if (!$this->isAdmin()) {
         if (isset($_POST['profile_update'])) {
             $pjUserModel = pjUserModel::factory();
             $arr = $pjUserModel->find($this->getUserId())->getData();
             $data = array();
             $data['role_id'] = $arr['role_id'];
             $data['status'] = $arr['status'];
             $post = array_merge($_POST, $data);
             if (!$pjUserModel->validates($post)) {
                 pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdmin&action=pjActionProfile&err=AA14");
             }
             $pjUserModel->set('id', $this->getUserId())->modify($post);
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdmin&action=pjActionProfile&err=AA13");
         } else {
             $this->set('arr', pjUserModel::factory()->find($this->getUserId())->getData());
             $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('pjAdmin.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
Пример #13
0
<?php

ini_set('session.gc_maxlifetime', 300);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);
if (!headers_sent()) {
    session_name('FoodDelivery');
    @session_start();
}
if (in_array($_SERVER['SERVER_ADDR'], array('127.0.0.1', '::1'))) {
    ini_set("display_errors", "On");
    error_reporting(E_ALL | E_STRICT);
} else {
    error_reporting(0);
}
header("Content-type: text/html; charset=utf-8");
if (!defined("ROOT_PATH")) {
    define("ROOT_PATH", dirname(__FILE__) . '/');
}
require ROOT_PATH . 'app/config/options.inc.php';
require_once PJ_FRAMEWORK_PATH . 'pjAutoloader.class.php';
pjAutoloader::register();
if (!isset($_GET['controller']) || empty($_GET['controller'])) {
    header("HTTP/1.1 301 Moved Permanently");
    pjUtil::redirect(PJ_INSTALL_URL . basename($_SERVER['PHP_SELF']) . "?controller=pjAdmin&action=pjActionIndex");
}
if (isset($_GET['controller'])) {
    $pjObserver = pjObserver::factory();
    $pjObserver->init();
}
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         if (isset($_POST['client_update'])) {
             pjClientModel::factory()->where('id', $_POST['id'])->limit(1)->modifyAll($_POST);
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminClients&action=pjActionIndex&err=AC01");
         } else {
             $arr = pjClientModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminClients&action=pjActionIndex&err=AC08");
             }
             $this->set('arr', $arr);
             $this->set('role_arr', pjRoleModel::factory()->orderBy('t1.id ASC')->findAll()->getData());
             $country_arr = pjCountryModel::factory()->select('t1.id, t2.content AS country_title')->join('pjMultiLang', "t2.model='pjCountry' AND t2.foreign_id=t1.id AND t2.field='name' AND t2.locale='" . $this->getLocaleId() . "'", 'left outer')->orderBy('`country_title` ASC')->findAll()->getData();
             $this->set('country_arr', $country_arr);
             $this->appendJs('chosen.jquery.js', PJ_THIRD_PARTY_PATH . 'harvest/chosen/');
             $this->appendCss('chosen.css', PJ_THIRD_PARTY_PATH . 'harvest/chosen/');
             $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('pjAdminClients.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 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->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 pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         if (isset($_POST['merchant_update'])) {
             pjMerchantModel::factory()->where('merchant_id', $_POST['id'])->limit(1)->modifyAll($_POST);
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminMerchant&action=pjActionIndex&err=AU01");
         } else {
             $arr = pjMerchantModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminMerchant&action=pjActionIndex&err=AU08");
             }
             $this->set('arr', $arr);
             $this->set('role_arr', pjRoleModel::factory()->orderBy('t1.id ASC')->findAll()->getData());
             $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('pjAdminMerchant.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin()) {
         $arr = pjDateModel::factory()->find($_GET['id'])->getData();
         if (count($arr) === 0) {
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminTime&action=pjActionIndex&err=AT09&tab_id=tabs-2");
         }
         $this->set('arr', $arr);
         $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
         $this->appendJs('pjAdminTime.js');
     } else {
         $this->set('status', 2);
     }
 }
 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 pjActionIndex()
 {
     $this->checkLogin();
     if (!$this->isAdmin()) {
         $this->set('status', 2);
         return;
     }
     if (isset($_POST['backup'])) {
         $backup_folder = PJ_WEB_PATH . 'backup/';
         if (!is_dir($backup_folder)) {
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjBackup&action=pjActionIndex&err=PBU05");
         }
         if (!is_writable($backup_folder)) {
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjBackup&action=pjActionIndex&err=PBU06");
         }
         @set_time_limit(600);
         //10 min
         $err = 'PBU04';
         if (isset($_POST['db'])) {
             $app_models = array();
             pjToolkit::readDir($app_models, PJ_MODELS_PATH);
             $plugin_models = array();
             pjToolkit::readDir($plugin_models, PJ_PLUGINS_PATH);
             $sql = array();
             $this->pjActionLoop($sql, $app_models);
             $this->pjActionLoop($sql, $plugin_models, true);
             $content = join("", $sql);
             if (!($handle = fopen(PJ_WEB_PATH . 'backup/database-backup-' . time() . '.sql', 'wb'))) {
             } else {
                 if (fwrite($handle, $content) === FALSE) {
                 } else {
                     fclose($handle);
                     $err = 'PBU02';
                 }
             }
         }
         if (isset($_POST['files'])) {
             $files = array();
             pjToolkit::readDir($files, PJ_UPLOAD_PATH);
             $zipName = 'files-backup-' . time() . '.zip';
             $zip = new pjZipStream();
             $zip->setZipFile(PJ_WEB_PATH . 'backup/' . $zipName);
             foreach ($files as $file) {
                 $handle = @fopen($file, "rb");
                 if ($handle) {
                     $buffer = "";
                     while (!feof($handle)) {
                         $buffer .= fgets($handle, 4096);
                     }
                     $zip->addFile($buffer, $file);
                     fclose($handle);
                 }
             }
             $zip->finalize();
             $err = 'PBU02';
         }
         if (!isset($_POST['db']) && !isset($_POST['files'])) {
             $err = 'PBU03';
         }
         pjUtil::redirect(sprintf("%sindex.php?controller=pjBackup&action=pjActionIndex&err=%s", PJ_INSTALL_URL, $err));
     }
     $this->appendJs('jquery.datagrid.js', PJ_FRAMEWORK_LIBS_PATH . 'pj/js/');
     $this->appendJs('pjBackup.js', $this->getConst('PLUGIN_JS_PATH'));
 }