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 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 pjActionForgot()
 {
     $this->setLayout('pjActionAdminLogin');
     if (isset($_POST['forgot_user'])) {
         if (!isset($_POST['forgot_email']) || !pjValidation::pjActionNotEmpty($_POST['forgot_email']) || !pjValidation::pjActionEmail($_POST['forgot_email'])) {
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdmin&action=pjActionForgot&err=AA10");
         }
         $pjUserModel = pjUserModel::factory();
         $user = $pjUserModel->where('t1.email', $_POST['forgot_email'])->limit(1)->findAll()->getData();
         if (count($user) != 1) {
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdmin&action=pjActionForgot&err=AA10");
         } else {
             $user = $user[0];
             $Email = new pjEmail();
             $Email->setTo($user['email'])->setFrom($user['email'])->setSubject(__('emailForgotSubject', true));
             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']);
             }
             $body = str_replace(array('{Name}', '{Password}'), array($user['name'], $user['password']), __('emailForgotBody', true));
             if ($Email->send($body)) {
                 $err = "AA11";
             } else {
                 $err = "AA12";
             }
             pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdmin&action=pjActionForgot&err={$err}");
         }
     } else {
         $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
         $this->appendJs('pjAdmin.js');
     }
 }