Example #1
0
 public function callAction()
 {
     $data = array_intersect_key($_POST, array_flip(array('phone', 'fio', 'formid')));
     // Validate data
     $validator = new Validator($data);
     $validator->rule('empty', 'formid')->message('Некорректный идентификатор формы');
     $validator->rule('required', 'phone')->message('Поле не заполнено');
     $validator->rule('phone', 'phone')->message('Некорректный номер телефона');
     if ($validator->validate()) {
         if (empty($data['fio'])) {
             $data['fio'] = 'Личный номер';
         }
         unset($data['formid']);
         // Send to subscribers
         $mailers = MSCore::db()->getCol('SELECT mail FROM `' . PRFX . 'mailer` WHERE type = ' . self::TARGET_CALL . ' OR type = 0');
         $data['date'] = date('Y-m-d H:i:s');
         MSCore::db()->insert(PRFX . 'order_call', $data);
         if (is_array($mailers) && !empty($mailers)) {
             // Send email
             $sendMail = new SendMail();
             $sendMail->init();
             $sendMail->setSubject('Обратный звонок на ' . DOMAIN);
             $sendMail->setFrom('noreply@' . DOMAIN, 'Первая кровельная');
             // Prepare body
             $message = template('email/call', array('data' => $data));
             $sendMail->setMessage($message);
             foreach ($mailers as $_email) {
                 $sendMail->setTo($_email);
                 $sendMail->send();
             }
             unset($sendMail);
         }
         $content = template('ajax/success/call');
         $this->addData(array('content' => $content));
     } else {
         $errors = $validator->errors();
         foreach ($errors as $_name => $_error) {
             if (is_array($_error)) {
                 $errors[$_name] = reset($_error);
             }
         }
         $this->errorAction(1001, 'Некорректно заполненные поля', array('errors' => $errors));
     }
 }
Example #2
0
 * Отправитель писем, работает по CRON
 *
 * @author      Pereskokov Yurii
 * @copyright   2016 Pereskokov Yurii
 * @license     Mediasite LLC
 * @link        http://www.mediasite.ru/
 */
require_once dirname(__FILE__) . '/../console.php';
// Достать письма
$query = new MSTable('{mails}');
$query->setFields(['*']);
$mails = $query->getItems();
// Отправить письма
foreach ($mails as $mailItem) {
    $mail = new SendMail();
    $mail->init();
    $mail->setEncoding("utf8");
    $mail->setEncType("base64");
    $mail->setSubject($mailItem['subject']);
    $mail->setMessage($mailItem['text']);
    $mail->setFrom($mailItem['from'], "apstroy");
    $mail->setFiles([$mailItem['files']]);
    $emails = MSCore::db()->getCol('SELECT `mail` FROM `' . PRFX . 'mailer`');
    foreach ($emails as $email) {
        $mail->setTo($email);
        $mail->send();
    }
}
// Удалить письма и файлы
foreach ($mails as $mailItem) {
    MSCore::db()->execute("DELETE FROM `" . PRFX . 'mails' . "` WHERE `id` = " . $mailItem['id']);
Example #3
0
 public function orderAction()
 {
     if (isset($_POST)) {
         $data = [];
         try {
             if (!isset($_POST['name'])) {
                 throw new Exception('name');
             }
             $data['name'] = htmlspecialchars($_POST['name']);
             if (!isset($_POST['phone'])) {
                 throw new Exception('phone');
             }
             $data['phone'] = htmlspecialchars($_POST['phone']);
             if (!isset($_POST['comment'])) {
                 throw new Exception('comment');
             }
             $data['comment'] = htmlspecialchars($_POST['comment']);
             if (!isset($_POST['path'])) {
                 throw new Exception('path');
             }
             $data['path'] = htmlspecialchars($_POST['path']);
             if (!isset($_POST['address'])) {
                 throw new Exception('honeyPot');
             }
             $honeyPot = htmlspecialchars($_POST['address']);
             $data['honeyPot'] = $honeyPot;
             // Проверка на бота
             if ($honeyPot != '') {
                 $this->errorAction(1001, 'Custom system error', ['honeyPot' => 'honeyPot']);
             }
             // Валидация
             $v = new Validator(['name' => $data['name'], 'phone' => $data['phone'], 'comment' => $data['comment']]);
             $v->rule('required', 'comment')->message('comment!');
             $v->rule('required', 'name')->message('name!');
             $v->rule('regex', 'name', '/^([a-zа-я\\s\\-]+)$/iu')->message('name!!');
             $v->rule('required', 'phone')->message('phone!');
             $v->rule('phone', 'phone')->message('phone!!');
             if ($v->validate()) {
                 if (!empty($data['path'])) {
                     $query = new MSTable('{www}');
                     $query->setFields(['title_page']);
                     $query->setFilter('path_id = ' . $data['path']);
                     $data['path'] = $query->getItem();
                     $data['path'] = $data['path']['title_page'];
                 }
                 // Проверяем есть ли файл в наличии
                 $type = 'modal';
                 if (isset($_SESSION['uploaded'][$type]['directory'])) {
                     $path = $_SESSION['uploaded'][$type]['directory'];
                     unset($_SESSION['uploaded'][$type]['directory']);
                 }
                 $title = "Заявка с сайта " . DOMAIN;
                 $msg = template('email/order', $data);
                 if (isset($path)) {
                     $files = str_replace('\\', '/', $path);
                     $from = "noreply@" . DOMAIN;
                     // Помещаем в базу
                     MSCore::db()->insert(PRFX . 'mails', ['subject' => $title, 'files' => $files, 'text' => $msg, 'from' => $from]);
                     $msg = template('email/order', $data + ['files' => $files]);
                 } else {
                     $mail = new SendMail();
                     $mail->init();
                     $mail->setEncoding("utf8");
                     $mail->setEncType("base64");
                     $mail->setSubject($title);
                     $mail->setMessage($msg);
                     $mail->setFrom("noreply@" . DOMAIN, "apstroy");
                     $emails = MSCore::db()->getCol('SELECT `mail` FROM `' . PRFX . 'mailer`');
                     foreach ($emails as $email) {
                         $mail->setTo($email);
                         $mail->send();
                     }
                 }
                 $sql = "\n                        INSERT INTO mp_list(`title`,`text`)\n                        VALUES('" . $title . "','" . $msg . "');\n                    ";
                 MSCore::db()->execute($sql);
                 $this->addData(['succes' => 'Ok']);
                 $this->successAction();
             } else {
                 $errors = $v->errors();
                 foreach ($errors as $_name => $_error) {
                     if (is_array($_error)) {
                         $errors[$_name] = reset($_error);
                     }
                 }
                 $this->errorAction(1001, 'Custom system error', ['data' => $data, 'error' => $errors]);
             }
         } catch (Exception $exception) {
             $error = $exception->getMessage();
             $this->errorAction(1001, 'Custom system error', ['error' => $error, 'postArgument' => 'noPostArgument']);
         }
     }
 }
Example #4
0
 public function callAction()
 {
     if (isset($_POST)) {
         $data = [];
         try {
             if (!isset($_POST['name'])) {
                 throw new Exception('name');
             }
             $data['name'] = htmlspecialchars($_POST['name']);
             if (!isset($_POST['phone'])) {
                 throw new Exception('phone');
             }
             $data['phone'] = htmlspecialchars($_POST['phone']);
             if (!isset($_POST['email'])) {
                 throw new Exception('email');
             }
             $data['email'] = htmlspecialchars($_POST['email']);
             if (!isset($_POST['comment'])) {
                 throw new Exception('comment');
             }
             $data['comment'] = htmlspecialchars($_POST['comment']);
             if (!isset($_POST['address'])) {
                 throw new Exception('honeyPot');
             }
             $honeyPot = htmlspecialchars($_POST['address']);
             $data['honeyPot'] = $honeyPot;
             // Проверка на бота
             if ($honeyPot != '') {
                 $this->errorAction(1001, 'Custom system error', ['honeyPot' => 'honeyPot']);
             }
             // Валидация
             $v = new Validator(['name' => $data['name'], 'phone' => $data['phone'], 'email' => $data['email'], 'comment' => $data['comment']]);
             $v->rule('required', 'comment')->message('comment!');
             $v->rule('required', 'name')->message('name!');
             $v->rule('regex', 'name', '/^([a-zа-я\\s\\-]+)$/iu')->message('name!!');
             $v->rule('required', 'phone')->message('phone!');
             $v->rule('phone', 'phone')->message('phone!!');
             $v->rule('required', 'email')->message('email!');
             $v->rule('email', 'email')->message('email!!');
             if ($v->validate()) {
                 $msg = template('email/call', $data);
                 $title = "Вопрос с сайта " . DOMAIN;
                 $mail = new SendMail();
                 $mail->init();
                 $mail->setEncoding("utf8");
                 $mail->setEncType("base64");
                 $mail->setSubject($title);
                 $mail->setMessage($msg);
                 $mail->setFrom("noreply@" . DOMAIN, "eko");
                 $emails = MSCore::db()->getCol('SELECT `mail` FROM `' . PRFX . 'mailer`');
                 foreach ($emails as $email) {
                     $mail->setTo($email);
                     $mail->send();
                 }
                 $sql = "\n                        INSERT INTO mp_list(`title`,`text`)\n                        VALUES('" . $title . "','" . $msg . "');\n                    ";
                 MSCore::db()->execute($sql);
                 $this->addData(['succes' => 'Ok']);
                 $this->successAction();
             } else {
                 $errors = $v->errors();
                 foreach ($errors as $_name => $_error) {
                     if (is_array($_error)) {
                         $errors[$_name] = reset($_error);
                     }
                 }
                 $this->errorAction(1001, 'Custom system error', ['data' => $data, 'error' => $errors]);
             }
         } catch (Exception $exception) {
             $error = $exception->getMessage();
             $this->errorAction(1001, 'Custom system error', ['error' => $error, 'postArgument' => 'noPostArgument']);
         }
     }
 }