Exemplo n.º 1
0
 function check($name, $method)
 {
     $data = array();
     if (!isset($_REQUEST[$this->data_var][$name])) {
         $post = get('post', array(), 's');
         if (empty($post[$this->data_var])) {
             return '{#unknown_error#}';
         }
         $data = $post[$this->data_var];
     } else {
         $data = $_REQUEST[$this->data_var];
     }
     if ($method[0] == '=') {
         $_name = substr($method, 1);
         if ($data[$name] !== $data[$_name]) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'email') {
         if (!CheckMailAddress($data[$name])) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'phone') {
         if (!CheckPhone($data[$name])) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'zip') {
         if (!$this->CheckNumber($data[$name], 6)) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'bik') {
         if (!$this->CheckNumber($data[$name], 9)) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'ks') {
         if (!$this->CheckNumber($data[$name], 20)) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'inn') {
         if (!$this->CheckNumber($data[$name], 10)) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'kpp') {
         if (!$this->CheckNumber($data[$name], 9)) {
             return isset($this->elements[$name]['onerror']) ? $this->elements[$name]['onerror'] : '{#unknown_error#}';
         }
     } elseif ($method == 'captcha') {
         $keystring = $_SESSION['captcha_keystring'];
         unset($_SESSION['captcha_keystring']);
         if ($data[$name] && (empty($keystring) || $data[$name] !== $keystring)) {
             return '{#captcha_error#}';
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Функция отправляет заявку на выбранные объекты
  *
  */
 function sendOrder()
 {
     global $settings;
     require_once 'smstraff.php';
     require_once "phpmailer/class.phpmailer.php";
     $error = "";
     $order = $_REQUEST['fld']['order'];
     $keystring = $_SESSION['captcha_keystring'];
     unset($_SESSION['captcha_keystring']);
     if (empty($keystring) || $order['captcha'] !== $keystring) {
         $error = 'Не правельно введен проверочный код.';
     }
     if (empty($order['name']) || empty($order['email']) || empty($order['phone'])) {
         $error = 'Не заполнены обязательные поля.';
     }
     if (!empty($order['email']) && !CheckMailAddress($order['email'])) {
         $error = 'Не корректно введен E-mail адрес.';
     }
     if ($error) {
         $data = array('error_form' => iconv('windows-1251', 'utf-8', $error));
         header('Content-Type: application/json; charset=utf-8');
         echo json_encode($data);
         exit;
     }
     $ids = array();
     // Проверяем уже сохраненные в куках объекты
     if (isset($_COOKIE['obj_favorite'])) {
         $obj_favorite = unserialize($_COOKIE['obj_favorite']);
         if (count($obj_favorite)) {
             $ids = array_merge($ids, $obj_favorite);
         }
     }
     $ids = array_unique($ids);
     $count_sms = isset($_COOKIE['count_sms']) ? $_COOKIE['count_sms'] : 0;
     $query = "SELECT o.*, oa.address\n\t\tFROM rnt_objects AS o\n\t\tLEFT JOIN obj_address AS oa ON oa.id=o.address_id\n\t\tWHERE o.id IN ('" . implode("','", $ids) . "')";
     $list = sql_getRows($query);
     //Готовим отправку уведомлений
     //Разложим все объекты по пользователям
     foreach ($list as $key => $value) {
         //Узнаем какие типы уведомлений выбраны пользователем
         $user_notify = sql_getRows("SELECT method FROM notify_user_settings WHERE type='view_order' AND user_id=" . $value['client_id']);
         if (!empty($user_notify)) {
             foreach ($user_notify as $k => $v) {
                 $value['notify_' . $v] = $v;
             }
         }
         //Если пользователя нет, то установим все возможное
         if (!$value['client_id']) {
             $value['notify_email'] = 'email';
             $value['notify_sms'] = 'sms';
         }
         $c_objects[$value['client_id']][] = $value;
         $e_objects[$value['email']][] = $value;
     }
     $sent_mobiles = array();
     // массив мобильных телефонов на которые уже отправили смс
     foreach ($c_objects as $key => $object) {
         foreach ($object as $k => $value) {
             //проверяем, хочет ли пользователь получать смс
             //и не закончился ли лимит отправок
             if ($value['notify_sms'] == 'sms' && $count_sms <= 20) {
                 $sms_text = "";
                 //проверим поле сотовый телефон,  и что на него еще не отсылали смс
                 if ($value['mobile_phone'] && !in_array($value['mobile_phone'], $sent_mobiles)) {
                     $locmankvartir = $this->Translit(" locmankvartir.ru");
                     $sms_text = substr($this->Translit(iconv('utf-8', 'windows-1251', $order['name'])), 0, 12) . ", ";
                     $sms_text .= substr($this->Translit(iconv('utf-8', 'windows-1251', $order['phone'])), 0, 12) . ", ";
                     $remain = 160 - (int) strlen($sms_text) - (int) strlen($locmankvartir);
                     $sms_text .= substr($this->Translit($value['address']), 0, $remain) . ",";
                     $sms_text .= $locmankvartir;
                     $sent_mobiles[] = $value['mobile_phone'];
                     //Сама отправка
                     $mobile_phone = substr($value['mobile_phone'], 0, 1) == "8" ? "+7" . substr($value['mobile_phone'], 1, 10) : $value['mobile_phone'];
                     $response = Sms::send($value['mobile_phone'], $sms_text);
                     $count_sms++;
                 }
             }
         }
     }
     //Запишем количество отправленных смс
     setcookie('count_sms', $count_sms, time() + 604800, '/');
     //Отправляем уведомления на email
     $page =& Registry::get('TPage');
     $page->tpl->config_load($page->content['domain'] . '__' . lang() . '.conf', 'searchobject');
     $count_objects = $page->tpl->get_config_vars('searchobject_count_objects_in_email');
     // Подготовка письма
     $mail =& new PHPMailer();
     $mail->From = $mail->Sender = $page->tpl->get_config_vars('admin_email');
     $mail->Mailer = 'mail';
     $tableHead = "<tr>\n\t\t<td>Адрес</td>\n\t\t<td>Квартира</td>\n\t\t<td>Цена</td>\n\t\t<td>Кол-во комнат</td>\n\t\t<td>Этаж/этажность</td>\n\t\t<td>Тип здания</td>\n\t\t<td>Площадь</td>\n\t\t<td>Балкон</td>\n\t\t<td>Контактные данные</td>\n\t\t</tr>";
     foreach ($e_objects as $key => $object) {
         if ($key) {
             $i = $j = 0;
             $tableBody = "";
             foreach ($object as $k => $value) {
                 if ($value['notify_email'] == 'email' && $value['email']) {
                     if ($i == 0) {
                         $j++;
                         $mail->Subject = 'Заявка на просмотр объектов от ' . iconv('utf-8', 'windows-1251', $order['name']) . ' часть ' . $j . ' из ' . (int) ceil(count($object) / $count_objects);
                         $body = '';
                         $body .= 'ФИО: ' . iconv('utf-8', 'windows-1251', $order['name']) . '<br>';
                         $body .= 'E-mail: ' . nl2br($order['email']) . '<br>';
                         $body .= 'Телефон: ' . nl2br(iconv('utf-8', 'windows-1251', $order['phone'])) . '<br>';
                         $body .= 'Дополнительно: ' . nl2br(iconv('utf-8', 'windows-1251', $order['other'])) . '<br>';
                         $body .= '<hr>';
                     }
                     // Здесь полная информация об объектах
                     $tableBody .= "<tr width='5000'>\n\t\t\t\t\t\t<td>" . $value['address'] . "</td>\n\t\t\t\t\t\t<td>" . $settings['market'][$value['market']] . "</td>\n\t\t\t\t\t\t<td>" . $value['price_rub'] . "</td>\n\t\t\t\t\t\t<td>" . $value['room'] . "</td>\n\t\t\t\t\t\t<td>" . $value['storey'] . "/" . $value['storeys_number'] . "</td>\n\t\t\t\t\t\t<td>" . sql_getValue('SELECT name FROM obj_housetypes WHERE id=' . $value['house_type']) . "</td>\n\t\t\t\t\t\t<td>" . $value['total_area'] . "/" . $value['living_area'] . "/" . $value['kitchen_area'] . "</td>\n\t\t\t\t\t\t<td>" . sql_getValue('SELECT name FROM obj_balcony WHERE id=' . $value['balcony']) . "</td>\n\t\t\t\t\t\t<td>" . $value['contact_phone'] . "</td>\n\t\t\t\t\t\t</tr>";
                     $i++;
                     if ($i == $count_objects) {
                         $body .= "<table cellpadding='5' cellspacing='5' border='2'>" . $tableHead . $tableBody . "</table>";
                         $mail->Body = $body;
                         $mail->ClearAddresses();
                         $mail->AddAddress($key);
                         $mail->IsHTML(true);
                         $mail->Send();
                         $i = 0;
                     }
                 }
             }
             if ($i != $count_objects) {
                 $body .= "<table cellpadding='5' cellspacing='5' border='2'>" . $tableHead . $tableBody . "</table>";
                 $mail->Body = $body;
                 $mail->ClearAddresses();
                 $mail->AddAddress($key);
                 $mail->IsHTML(true);
                 $mail->Send();
             }
         }
     }
     $data = array('msg_form' => iconv('windows-1251', 'utf-8', "Ваша заявка была отправлена на доступные электронные ящики и мобильные телефоны."));
     header('Content-Type: application/json; charset=utf-8');
     echo json_encode($data);
     exit;
 }
Exemplo n.º 3
0
 function show_cart()
 {
     $auth_obj =& Registry::get('TUserAuth');
     session_start();
     $post = isset($_POST['fld']) ? $_POST['fld'] : array();
     session_write_close();
     $page =& Registry::get('TPage');
     $user_id = $auth_obj->getCurrentUserId();
     if (!$user_id) {
         session_start();
         $_SESSION['smsm']['login_registration_redirect'] = $page->content['href'];
         session_write_close();
         redirect("/registruser/");
     }
     if ($user_id && !empty($post)) {
         //получаем все строковые константы
         $sql = "SELECT name, strings.* FROM strings WHERE module='" . $this->name . "'";
         $str = sql_getRows($sql, true);
         //обновляем карточку данного пользователя
         if (empty($post['login'])) {
             $error['email'] = $str['error_login_empty']['value'];
         } else {
             $prf = $auth_obj->getUserProfile($auth_obj->getId($post['login']));
             if (isset($prf['auth']) && $prf['auth'] == 1 && $prf['id'] != $user_id) {
                 $error['login'] = $str['error_login']['value'];
             }
             //пользователь существует
             if (!CheckMailAddress($post['login'])) {
                 $error['login'] = $str['error_login_incorrect']['value'];
             }
             // Некорректный email
         }
         $req_fields = array('fio', 'login');
         foreach ($req_fields as $key => $val) {
             if (empty($post[$val])) {
                 $error[$val] = $str['error_' . $val]['value'];
             }
         }
         if ($post['password1'] != $post['password2']) {
             $error['global'][] = $str['error_passwords']['value'];
         }
         if ($post['login'] != $post['login2']) {
             $error['global'][] = $str['error_emails']['value'];
         }
         if (empty($error)) {
             if ($post['password1']) {
                 $post['password'] = md5($post['password1']);
             }
             unset($post['login2']);
             unset($post['password1']);
             unset($post['password2']);
             unset($post['password0']);
             $str = "";
             foreach ($post as $k => $v) {
                 $str .= ", `" . $k . "`='" . e($v) . "' ";
             }
             $sql = "UPDATE auth_users SET " . substr($str, 1) . " WHERE id=" . $user_id;
             sql_query($sql);
             $auth_obj->setLoginCookie();
             $auth_obj->setUserData($user_id);
         } else {
             $profile = $post;
         }
     }
     if (!isset($profile)) {
         $profile = $auth_obj->getCurrentUserData();
     }
     $ret['form'] = true;
     $ret['fld'] = isset($profile) ? $profile : array();
     $ret['error'] = isset($error) ? $error : array();
     $ret['dirs'] = get('dirs', $_SERVER['REDIRECT_URL'], 'pg');
     return $ret;
 }