public function pjActionIndex() { $this->checkLogin(); if ($this->isAdmin() || $this->isEditor()) { $user_id = $_SESSION['admin_user']['id']; $pjOrderModel = pjOrderModel::factory(); $cnt_delivery_orders = $pjOrderModel->where('user_id', $user_id)->where("type", "delivery")->where("DATE(t1.d_dt) = CURDATE()")->findCount()->getData(); $amount_delivery_orders = $pjOrderModel->reset()->select("SUM(total) AS amount")->where("type", "delivery")->where('user_id', $user_id)->where("DATE(t1.d_dt) = CURDATE()")->findAll()->getData(); $cnt_pickup_orders = $pjOrderModel->reset()->where('user_id', $user_id)->where("type", "pickup")->where("DATE(t1.p_dt) = CURDATE()")->findCount()->getData(); $amount_pickup_orders = $pjOrderModel->reset()->select("SUM(total) AS amount")->where('user_id', $user_id)->where("type", "pickup")->where("DATE(t1.p_dt) = CURDATE()")->findAll()->getData(); $cnt_orders = $pjOrderModel->reset()->where('user_id', $user_id)->findCount()->getData(); $amount_orders = $pjOrderModel->reset()->select("SUM(total) AS amount")->where('user_id', $user_id)->findAll()->getData(); $this->set('cnt_delivery_orders', $cnt_delivery_orders); $this->set('amount_delivery_orders', !empty($amount_delivery_orders) ? $amount_delivery_orders[0]['amount'] : 0); $this->set('cnt_pickup_orders', $cnt_pickup_orders); $this->set('amount_pickup_orders', !empty($amount_pickup_orders) ? $amount_pickup_orders[0]['amount'] : 0); $this->set('cnt_orders', $cnt_orders); $this->set('amount_orders', !empty($amount_orders) ? $amount_orders[0]['amount'] : 0); $latest_delivery = $pjOrderModel->reset()->join('pjClient', "t2.id=t1.client_id", 'left outer')->join('pjMultiLang', "t3.model='pjLocation' AND t3.foreign_id=t1.location_id AND t3.field='name' AND t3.locale='" . $this->getLocaleId() . "'", 'left outer')->select('t1.*, t2.c_name as client_name, t3.content as location')->where("type", "delivery")->where('t1.user_id', $user_id)->orderBy("d_dt DESC")->limit(6)->findAll()->getData(); $latest_pickup = $pjOrderModel->reset()->join('pjClient', "t2.id=t1.client_id", 'left outer')->join('pjMultiLang', "t3.model='pjLocation' AND t3.foreign_id=t1.location_id AND t3.field='name' AND t3.locale='" . $this->getLocaleId() . "'", 'left outer')->select('t1.*, t2.c_name as client_name, t3.content as location')->where('t1.user_id', $user_id)->where("type", "pickup")->orderBy("p_dt DESC")->limit(6)->findAll()->getData(); $this->set('latest_delivery', $latest_delivery); $this->set('latest_pickup', $latest_pickup); $location_arr = pjWorkingTimeModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.location_id AND t2.model = 'pjLocation' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select('t1.*, t2.content as location_title')->findAll()->getData(); $week_day = strtolower(date("l")); $current_time = date('H:i:s'); foreach ($location_arr as $k => $v) { if ($v['p_' . $week_day . '_from'] <= $current_time && $current_time <= $v['p_' . $week_day . '_to']) { $v['pickup'] = __('lblOpened', true); } else { $v['pickup'] = __('lblClosed', true); } if ($v['d_' . $week_day . '_from'] <= $current_time && $current_time <= $v['d_' . $week_day . '_to']) { $v['delivery'] = __('lblOpened', true); } else { $v['delivery'] = __('lblClosed', true); } $location_arr[$k] = $v; } $this->set('location_arr', $location_arr); } 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 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 pjActionGetClient() { $this->setAjax(true); if ($this->isXHR()) { $pjClientModel = pjClientModel::factory()->where('user_id', $_SESSION['admin_user']['id']); if (isset($_GET['q']) && !empty($_GET['q'])) { $q = pjObject::escapeString($_GET['q']); $pjClientModel->where('t1.c_email LIKE', "%{$q}%"); $pjClientModel->orWhere('t1.c_name LIKE', "%{$q}%"); } if (isset($_GET['status']) && !empty($_GET['status']) && in_array($_GET['status'], array('T', 'F'))) { $pjClientModel->where('t1.status', $_GET['status']); } $column = 'c_name'; $direction = 'ASC'; if (isset($_GET['direction']) && isset($_GET['column']) && in_array(strtoupper($_GET['direction']), array('ASC', 'DESC'))) { $column = $_GET['column']; $direction = strtoupper($_GET['direction']); } $total = $pjClientModel->findCount()->getData(); $rowCount = isset($_GET['rowCount']) && (int) $_GET['rowCount'] > 0 ? (int) $_GET['rowCount'] : 10; $pages = ceil($total / $rowCount); $page = isset($_GET['page']) && (int) $_GET['page'] > 0 ? intval($_GET['page']) : 1; $offset = ((int) $page - 1) * $rowCount; if ($page > $pages) { $page = $pages; } $data = array(); $data = $pjClientModel->select("t1.id, t1.c_email, t1.c_name, t1.status, (SELECT COUNT(TO.client_id) FROM `" . pjOrderModel::factory()->getTable() . "` AS `TO` WHERE `TO`.client_id=t1.id) AS cnt_orders")->orderBy("{$column} {$direction}")->limit($rowCount, $offset)->findAll()->getData(); pjAppController::jsonResponse(compact('data', 'total', 'pages', 'page', 'rowCount', 'column', 'direction')); } exit; }