Esempio n. 1
0
 /**
  * функция отсылает строку запроса к БД
  * получает и отправляет на обработку результат запроса
  * возвращает одну строку результата в виде массива данных
  *
  * @param (string) $strQuery - строка запроса к БД
  *
  * @return array массив данных
  */
 static function dbSingleQuery($strQuery)
 {
     self::dbQuery($strQuery);
     $row = self::dbGetRow();
     if (!empty(self::$tIdForce)) {
         if (defined('CONF_ENABLE_CHPU') && defined('CONF_ENABLE_TRANSLITERATION_CHPU') && CONF_ENABLE_CHPU && CONF_ENABLE_TRANSLITERATION_CHPU) {
             chpu::chpuTranslit($row);
         } elseif (!empty($row)) {
             $row['tId'] =& $row['id'];
         }
         // сбрасываем флаг свойства self::$tIdForce
         self::$tIdForce = false;
     }
     /**
      * Проверяем значение идентификатора записи tId (ЧПУ с транслитерацией)
      * Должно совпадать со значением хранимым в глобале $_GET['tId']
      * Иначе в URL запрошен некорректный адрес страницы - выдаем страницу ошибки HTTP/1.0 404 Not Found
      */
     if (!empty($_GET['tId']) && !empty($row['tId']) && $row['tId'] != $_GET['tId']) {
         messages::error404();
     }
     return $row;
 }
 /**
  * private функция рассылки почтовых сообщений
  *
  * @param string $typeAnnounce - тип объявления (должно соответствовать имени таблицы БД)
  * @param array $arrAnnounceData - массив данных объявления
  * @param bool $screenMessageOn [default = true] - завершение работы скрипта, выводом информационного сообщения
  *
  * @return bool
  */
 private function sendEmails(&$typeAnnounce, &$arrAnnounceData, $screenMessageOn = true)
 {
     if (isset($_SESSION['referer'])) {
         unset($_SESSION['referer']);
     }
     $user_type = !empty($_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type']) ? 'ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&' : '';
     switch ($arrAnnounceData['token']) {
         case 'new':
             /**
              * отправляем письмо пользователю
              */
             $mailer = new mailer();
             // дата удаления неактивированного объявления
             $deldate = date(terms::dateFormatFromSmarty(CONF_DATE_FORMAT, CONF_TIME_FORMAT), strtotime(terms::calcDateTimeOfTerm(constant('CONF_' . strtoupper($typeAnnounce) . '_ACTIVATE_THERM'))));
             $mailer->setAddReplace(array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title'], '%CODE%' => $arrAnnounceData['unikey'], '%DELDATE%' => $deldate, '%ACTIVATE_PAGE%' => CONF_SCRIPT_URL . 'index.php?' . $user_type . 'do=' . $typeAnnounce . '&action=activate', '%ACTIVATE_LINK%' => CONF_SCRIPT_URL . 'index.php?' . $user_type . 'do=' . $typeAnnounce . '&action=activate&code=' . $arrAnnounceData['unikey']));
             $result = $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, $arrAnnounceData['email'], $arrAnnounceData['email'], MAIL_SUBJ_ACTIVATE_ANNOUNCE . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'announce.user.activate.txt');
             unset($mailer);
             // уничтожаем объект
             if (!$result && !empty($screenMessageOn)) {
                 messages::printDie(ERROR_SEND_EMAIL);
             } elseif (!empty($screenMessageOn)) {
                 messages::messageChangeSaved(ANNOUNCE_ADD_ACTIVATE_TITLE, ANNOUNCE_ADD_ACTIVATE_MESSAGE, CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=' . $typeAnnounce . '&action=activate', 5000);
             } else {
                 return $result;
             }
         case 'moderate':
             // массив для замены в шаблоне
             $arrAddReplace = array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title']);
             /**
              * отправляем письмо администратору
              */
             $mailer = new mailer();
             // передаем массив для замены в шаблоне
             $mailer->setAddReplace($arrAddReplace + array('%ADMIN_PANEL_LINK%' => CONF_SCRIPT_URL . CONF_ADMIN_FILE . '?m=announces&s=' . $typeAnnounce . 's&action=moderate'));
             $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, CONF_MAIL_ADMIN_EMAIL, false, MAIL_SUBJ_NEW_ANNOUNCE . $arrAnnounceData['title'], empty($arrAnnounceData['comments']) ? 'adm.moderate.announce.txt' : 'adm.edited.announce.txt');
             unset($mailer);
             // уничтожаем объект
             /**
              * отправляем письмо пользователю
              */
             $mailer = new mailer();
             // передаем массив для замены в шаблоне
             $mailer->setAddReplace($arrAddReplace);
             $result = $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, $arrAnnounceData['email'], $arrAnnounceData['email'], MAIL_SUBJ_MODERATE_ANNOUNCE . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'announce.user.moderate.txt');
             unset($mailer);
             // уничтожаем объект
             if (!$result && !empty($screenMessageOn)) {
                 messages::printDie(ERROR_SEND_EMAIL);
             } elseif (!empty($screenMessageOn)) {
                 $link = !empty($arrAnnounceData['id_user']) ? CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=user.announces&action=' . $typeAnnounce . '&token=' . $arrAnnounceData['token'] : CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'];
                 messages::messageChangeSaved(ANNOUNCE_ADD_MODERATION_TITLE, ANNOUNCE_ADD_MODERATION_MESSAGE, chpu::createChpuUrl($link), 5000);
             } else {
                 return $result;
             }
         case 'correction':
             /**
              * отправляем письмо пользователю
              */
             $mailer = new mailer();
             // дата удаления не исправленного объявления
             $deldate = date(terms::dateFormatFromSmarty(CONF_DATE_FORMAT, CONF_TIME_FORMAT), strtotime(terms::calcDateTimeOfTerm(constant('CONF_' . strtoupper($typeAnnounce) . '_CORRECTION_THERM'))));
             $mailer->setAddReplace(array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title'], '%DELDATE%' => $deldate, '%USER_PANEL_LINK%' => chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=user.announces&action=' . $typeAnnounce . '&token=' . $arrAnnounceData['token']), '%COMMENTS%' => CONF_MAIL_FORMAT_HTML ? nl2br($arrAnnounceData['comments']) : $arrAnnounceData['comments']));
             $result = $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, $arrAnnounceData['email'], $arrAnnounceData['email'], MAIL_SUBJ_NEW_ANNOUNCE_CORRECTION . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'announce.user.correction.txt');
             unset($mailer);
             // уничтожаем объект
             if (!$result && !empty($screenMessageOn)) {
                 messages::printDie(ERROR_SEND_EMAIL);
             } else {
                 return $result;
             }
         case 'payment':
             /**
              * отправляем письмо пользователю
              */
             $mailer = new mailer();
             // дата удаления неоплаченого объявления
             $deldate = date(terms::dateFormatFromSmarty(CONF_DATE_FORMAT, CONF_TIME_FORMAT), strtotime(terms::calcDateTimeOfTerm(constant('CONF_' . strtoupper($typeAnnounce) . '_PAYMENT_THERM'))));
             $mailer->setAddReplace(array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title'], '%CODE%' => $arrAnnounceData['unikey'], '%DELDATE%' => $deldate, '%PAYMENT_LINK%' => CONF_SCRIPT_URL . 'index.php?' . $user_type . 'do=' . $typeAnnounce . '&action=payment&id=' . $arrAnnounceData['id']));
             $result = $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, $arrAnnounceData['email'], $arrAnnounceData['email'], MAIL_SUBJ_NEW_ANNOUNCE_PAYMENT . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'announce.user.payment.txt');
             unset($mailer);
             // уничтожаем объект
             if (!$result && !empty($screenMessageOn)) {
                 messages::printDie(ERROR_SEND_EMAIL);
             } elseif (!empty($screenMessageOn)) {
                 $_SESSION['payment'] = array('service' => 'add_' . $typeAnnounce, 'announce_type' => $typeAnnounce, 'id' => $arrAnnounceData['id'], 'tId' => $arrAnnounceData['tId'], 'announce_title' => $arrAnnounceData['title']);
                 messages::messageChangeSaved(ANNOUNCE_ADD_PAYMENT_TITLE, ANNOUNCE_ADD_PAYMENT_MESSAGE, chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=payments'), 5000);
             } else {
                 return $result;
             }
         case 'active':
             // транслитерация ЧПУ
             chpu::chpuTranslit($arrAnnounceData);
             if (CONF_ANNOUNCE_ADD_SUCCESS_ADMIN_INFORM) {
                 $mailer = new mailer();
                 // массив для замены в шаблоне
                 $mailer->setAddReplace(array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title'], '%ANNOUNCE_LINK%' => chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=' . $typeAnnounce . '&action=view&id=' . $arrAnnounceData['tId']), '%ADMIN_PANEL_LINK%' => CONF_SCRIPT_URL . CONF_ADMIN_FILE . '?m=announces&s=' . $typeAnnounce . 's'));
                 // отправляем письмо администратору
                 $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, CONF_MAIL_ADMIN_EMAIL, false, MAIL_SUBJ_NEW_ANNOUNCE . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'adm.add.announce.txt');
                 unset($mailer);
                 // уничтожаем объект
             }
             if (CONF_ANNOUNCE_ADD_SUCCESS_USER_INFORM) {
                 $mailer = new mailer();
                 $mailer->setAddReplace(array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title'], '%ANNOUNCE_LINK%' => chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=' . $typeAnnounce . '&action=view&id=' . $arrAnnounceData['tId']), '%USER_PANEL_LINK%' => chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?do=user.announces&action=' . $typeAnnounce . '&token=' . $arrAnnounceData['token'])));
                 // отправляем письмо пользователю
                 $result = $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, $arrAnnounceData['email'], $arrAnnounceData['email'], MAIL_SUBJ_NEW_ANNOUNCE . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'announce.user.added.txt');
                 unset($mailer);
                 // уничтожаем объект
                 if (!$result && !empty($screenMessageOn)) {
                     messages::printDie(ERROR_SEND_EMAIL);
                 }
             }
             if (!empty($screenMessageOn)) {
                 messages::messageChangeSaved(ANNOUNCE_ADD_SUCCESS_TITLE, ANNOUNCE_ADD_SUCCESS_MESSAGE, chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=' . $typeAnnounce . '&action=view&id=' . $arrAnnounceData['tId']), 5000);
             } else {
                 return true;
             }
         case 'deleted':
         case 'archived':
             /**
              * отправляем письмо пользователю
              */
             $mailer = new mailer();
             $mailer->setAddReplace(array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title'], '%COMMENTS%' => $arrAnnounceData['comments']));
             $result = $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, $arrAnnounceData['email'], $arrAnnounceData['email'], MAIL_SUBJ_NEW_ANNOUNCE_DELETED . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'announce.user.deleted.txt');
             unset($mailer);
             // уничтожаем объект
             if (!$result && !empty($screenMessageOn)) {
                 messages::printDie(ERROR_SEND_EMAIL);
             } else {
                 return $result;
             }
         case 'vip':
         case 'hot':
             /**
              * отправляем письмо пользователю
              */
             $mailer = new mailer();
             $mailer->setAddReplace(array('%ANNOUNCE_TYPE%' => constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)), '%ANNOUNCE_TITLE%' => $arrAnnounceData['title'], '%STATUS%' => strtoupper($arrAnnounceData['token'])));
             $result = $mailer->sendEmail(CONF_MAIL_ADMIN_EMAIL, CONF_SITE_NAME, false, $arrAnnounceData['email'], $arrAnnounceData['email'], MAIL_SUBJ_NEW_ANNOUNCE_DELETED . constant('MAIL_ANNOUNCE_TYPE_' . strtoupper($typeAnnounce)) . ' - ' . $arrAnnounceData['title'], 'announce.user.' . $arrAnnounceData['token'] . '.reset.txt');
             unset($mailer);
             // уничтожаем объект
             if (!$result && !empty($screenMessageOn)) {
                 messages::printDie(ERROR_SEND_EMAIL);
             } else {
                 return $result;
             }
         default:
             return false;
     }
 }