phpDocumentor PHPShopCore
[ class tree: PHPShopCore ] [ all elements ]

Source for file gbook.core.php

Documentation is available at gbook.core.php

  1. <?php
  2. /**
  3.  * Обработчик гостевой книги
  4.  * @author PHPShop Software
  5.  * @version 1.0
  6.  * @package PHPShopCore
  7.  */
  8. class PHPShopGbook extends PHPShopCore {
  9.     
  10.     /**
  11.      * Конструктор
  12.      */
  13.     function PHPShopGbook({
  14.         
  15.         // Имя Бд
  16.         $this->objBase=$GLOBALS['SysValue']['base']['table_name7'];
  17.         
  18.         // Путь для навигации
  19.         $this->objPath="/gbook/gbook_";
  20.         
  21.         // Отладка
  22.         $this->debug=false;
  23.         
  24.         // Список экшенов
  25.         $this->action=array("post"=>"send_gb","nav"=>"index","nav"=>"ID","get"=>"add_forma");
  26.         parent::PHPShopCore();
  27.     }
  28.     
  29.     /**
  30.      * Экшен по умолчанию, вывод отзывов
  31.      */
  32.     function index({
  33.  
  34.         // Мета
  35.         $this->title="Отзывы - ".$this->PHPShopSystem->getValue("name");
  36.         
  37.         // Выборка данных
  38.         $this->dataArray=parent::getListInfoItem(array('*'),array('enabled'=>"='1'"),array('order'=>'id DESC'));
  39.         
  40.         // 404
  41.         if(!isset($this->dataArray)) return $this->setError404();
  42.         
  43.         if(is_array($this->dataArray))
  44.             foreach($this->dataArray as $row{
  45.                 
  46.                 // Ссылка на автора
  47.                 if(!empty($row['mail']))  $d_mail="<a href=\"mailto:$row[mail]\"><b>$row[name]</b></a>";
  48.                 else  $d_mail="<b>$row[name]</b>";
  49.                 
  50.                 // Определяем переменые
  51.                 $this->set('gbookData',PHPShopDate::dataV($row['date']));
  52.                 $this->set('gbookName',$row['name']);
  53.                 $this->set('gbookTema',$row['title']);
  54.                 $this->set('gbookMail',$d_mail);
  55.                 $this->set('gbookOtsiv',$row['question']);
  56.                 $this->set('gbookOtvet',$row['answer']);
  57.                 $this->set('gbookId',$row['id']);
  58.                 
  59.                 // Подключаем шаблон
  60.                 $this->addToTemplate($this->getValue('templates.main_gbook_forma'));
  61.             }
  62.         
  63.         // Пагинатор
  64.         $this->setPaginator();
  65.         
  66.         
  67.         // Подключаем шаблон
  68.         $this->parseTemplate($this->getValue('templates.gbook_page_list'));
  69.         
  70.         // Ссылка на новый отзыв
  71.         $this->add($this->attachLink());
  72.     }
  73.     
  74.     /**
  75.      * Экшен выборки подробной информации при наличии переменной навигации ID
  76.      * @return string 
  77.      */
  78.     function ID({
  79.         
  80.         // Безопасность
  81.         if(!PHPShopSecurity::true_num($this->PHPShopNav->getId())) return $this->setError404();
  82.         
  83.         // Выборка данных
  84.         $row=parent::getFullInfoItem(array('*'),array('id'=>'='.$this->PHPShopNav->getId()));
  85.         
  86.         // 404
  87.         if(!isset($row)) return $this->setError404();
  88.         
  89.         // Ссылка на автора
  90.         if(!empty($row['mail']))  $d_mail="<a href=\"mailto:$row[mail]\"><b>$row[name]</b></a>";
  91.         else  $d_mail="<b>$row[name]</b>";
  92.         
  93.         
  94.         // Определяем переменые
  95.         $this->set('gbookData',PHPShopDate::dataV($row['date']));
  96.         $this->set('gbookName',$row['name']);
  97.         $this->set('gbookTema',$row['title']);
  98.         $this->set('gbookMail',$d_mail);
  99.         $this->set('gbookOtsiv',$row['question']);
  100.         $this->set('gbookOtvet',$row['answer']);
  101.         $this->set('gbookId',$row['id']);
  102.         
  103.         // Подключаем шаблон
  104.         $this->addToTemplate($this->getValue('templates.main_gbook_forma'));
  105.         
  106.         // Мета
  107.         $this->title=$row['title']." - ".$this->PHPShopSystem->getValue("name");
  108.         $this->description=strip_tags($row['question']);
  109.         $this->lastmodified=$row['date'];
  110.         
  111.         
  112.         // Подключаем шаблон
  113.         $this->parseTemplate($this->getValue('templates.gbook_page_list'));
  114.     }
  115.     
  116.     /**
  117.      * Ссылка на новый отзыв
  118.      * @return string 
  119.      */
  120.     function attachLink({
  121.         return '<div align="center" style="padding:20"><a href="/gbook/?add_forma=true">
  122.         <img src="images/shop/icon_9.gif" alt="" width="50" height="46" border="0"><br><u>Оставить отзыв</u></a></div>';
  123.     }
  124.     
  125.     /**
  126.      * Новый отзыв
  127.      */
  128.     function add_forma({
  129.         $this->parseTemplate($this->getValue('templates.gbook_forma_question'));
  130.     }
  131.     
  132.     /**
  133.      * Экшен записи отзыва при получении $_POST[send_gb]
  134.      */
  135.     function send_gb({
  136.         if(!empty($_SESSION['text']and $_POST['key']==$_SESSION['text']{
  137.             $this->write();
  138.             header("Location: ../gbook/?write=ok");
  139.         }else {
  140.             $this->set('Error',"Ошибка ключа, повторите попытку ввода ключа");
  141.             $this->parseTemplate($this->getValue('templates.gbook_forma_question'));
  142.         }
  143.     }
  144.     
  145.     /**
  146.      * Запись отзыва в базу
  147.      */
  148.     function write({
  149.         
  150.         // Подключаем библиотеку отправки почты
  151.         PHPShopObj::loadClass("mail");
  152.         
  153.         if(isset($_POST['send_gb'])) {
  154.             if(!preg_match("/@/",$_POST['mail_new']))//проверка почты
  155.             {
  156.                 $_POST['mail_new']="";
  157.             }
  158.             if(PHPShopSecurity::true_param($_POST['name_new'],$_POST['otsiv_new'],$_POST['tema_new'])){
  159.                 $name_new=PHPShopSecurity::TotalClean($_POST['name_new'],2);
  160.                 $question_new=PHPShopSecurity::TotalClean($_POST['otsiv_new'],2);
  161.                 $title_new=PHPShopSecurity::TotalClean($_POST['tema_new'],2);
  162.                 $mail_new=addslashes($_POST['mail_new']);
  163.                 $date date("U");
  164.                 $ip=$_SERVER['REMOTE_ADDR'];
  165.                 
  166.                 // Запись в базу
  167.                 $this->PHPShopOrm->insert(array('date'=>$date,'name'=>$name_new,'mail'=>$mail_new,'title'=>$title_new,'question'=>$question_new),
  168.                         $prefix='');
  169.                 
  170.                 $zag=$this->PHPShopSystem->getValue('name')." - Уведомление о добалении отзыва / ".$date;
  171.                 $message="
  172. Доброго времени!
  173. ---------------
  174.  
  175. С сайта ".$this->PHPShopSystem->getValue('name')." пришло уведомление о добалении отзыва
  176. в гостевую книгу.
  177.  
  178. Данные о пользователе:
  179. ----------------------
  180.  
  181. Имя:                ".$name_new."
  182. E-mail:             ".$mail_new."
  183. Тема сообщения:     ".$title_new."
  184. Сообщение:          ".$question_new."
  185. Дата:               ".PHPShopDate::dataV($date)."
  186. IP:                 ".$ip."
  187.  
  188. ---------------
  189.  
  190. С уважением,
  191. http://".$_SERVER['SERVER_NAME'];
  192.                 
  193.                 $PHPShopMail new PHPShopMail($this->PHPShopSystem->getValue('admin_mail'),$mail_new,$zag,$message);
  194.                 
  195.                 
  196.             }
  197.         }
  198.     }
  199.     
  200. }
  201. ?>

Documentation generated on Thu, 17 Feb 2011 15:58:34 +0300 by phpDocumentor 1.4.3