public function indexAction($id = null)
 {
     if (empty($id)) {
         return AddAlertMessage('danger', 'Статьи не существует.', '/');
     }
     $vUserID = GetUserID();
     $UnknownUserGUID = GetUnknownUserGUID();
     $IsNotifyRecipientActive = false;
     if ($vUserID != 0) {
         $vAddWhere = "((UserID = {$vUserID}) or (UnknownUserGUID = '{$UnknownUserGUID}'))";
         $UnknownUserGUIDForViewed = "";
         $IsNotifyRecipientActive = Emails_IsNotifyRecipientActive(1, $id, $_SESSION['auth']['email']);
     } else {
         $vAddWhere = "(UnknownUserGUID = '{$UnknownUserGUID}')";
         $UnknownUserGUIDForViewed = $UnknownUserGUID;
     }
     // Регистрация просмотра статьи пользователем
     $sql = "insert into ArticleViewed(ArticleID, UnknownUserGUID, UserID, LastView) " . "values({$id}, '{$UnknownUserGUIDForViewed}', {$vUserID}, '" . GetLocalDateTimeAsSQLStr() . "') " . "on duplicate key update " . "LastView = '" . GetLocalDateTimeAsSQLStr() . "';";
     $this->db->exec($sql);
     $article = new Articles($this->context, 'ID = "' . $id . '"');
     if (!isset($article->ID) || $article->ID == null) {
         return AddAlertMessage('danger', 'Статьи не существует.', '/');
     }
     if ($article->IsActive != '1' && !Tools::getValue('preview')) {
         return AddAlertMessage('danger', 'Статья в черновике.', '/');
     }
     $article->PhotoL = URL . DIR_DBIMAGES . 'articles/' . $id . '/l_1.' . $article->MainImageExt;
     $sql = "select Name from ArticleCategories where ID = " . (int) $article->CategoryID;
     $category = GetMainConnection()->query($sql)->fetch();
     $vArticleLike = $this->db->query("select ID from ArticleLikes where (ArticleID = {$id}) and {$vAddWhere} limit 1;")->fetch();
     $vAlreadyLiked = !empty($vArticleLike['ID']);
     $sql = "select CommentDate, UserID, UserName, Comment " . "from ArticleComments " . "where (ArticleID = {$id}) " . "and (IsDeleted = 0) " . "order by CommentDate desc;";
     $ArticleComments = $this->db->query($sql)->fetchAll();
     if (!isset($article->AuthorID) || $article->AuthorID == null) {
         $ArticleAuthor['Name'] = '';
         $ArticleAuthor['ShortDescription'] = '';
         $ArticleAuthor['Photo'] = '';
     } else {
         $sql = 'SELECT Name, ShortDescription, Photo FROM Authors WHERE ID=' . (int) $article->AuthorID;
         $ArticleAuthor = $this->db->query($sql)->fetch();
     }
     $this->view->setVars(array('id' => $id, 'article' => $article, 'similar' => $article->getSimilar($id), 'discused' => $article->getMostDiscussed(), 'alreadyLiked' => $vAlreadyLiked, 'ArticleAuthor' => $ArticleAuthor, 'ArticleDocuments' => $article->getArticleDocuments($id), 'ArticleComments' => $ArticleComments, 'ArticleCategory' => $category['Name'], 'IsNotifyRecipientActive' => $IsNotifyRecipientActive));
     $this->view->breadcrumbs = array(array('url' => '/category', 'title' => 'Все статьи'), array('url' => '/articles/c-' . $article->CategoryID, 'title' => $category['Name']), array('url' => '/articles/c-' . $article->CategoryID . '/a-' . $article->ID, 'title' => $article->Name));
     $this->view->meta = array('meta_title' => $article->Name, 'meta_description' => $article->ShortDescription, 'meta_keywords' => $article->MetaKeywords);
     SetTokenForPreventDoubleSubmit();
     $this->view->generate();
 }
        } else {
            $UserName = $_SESSION['auth']['firstname'];
        }
        unset($_POST['ajax_AddCommentBtn']);
        unset($_POST['UserNameEdt']);
        unset($_POST['CommentEdt']);
        if (isset($_SESSION['auth'])) {
            $vUserID = $_SESSION['auth']['id'];
            $vUnknownUserGUID = "";
        } else {
            $vUserID = "0";
            $vUnknownUserGUID = (string) GetUnknownUserGUID();
        }
        $sql = "select ID " . "from CatalogComments " . "where (CatalogItemID = {$id}) " . "and (UnknownUserGUID = '{$vUnknownUserGUID}') " . "and (UserID = {$vUserID}) " . "and (Text = '{$Comment}');";
        $rec = GetMainConnection()->query($sql)->fetch();
        if (empty($rec['ID'])) {
            $sql = "insert into CatalogComments(CatalogItemID, UserID, UnknownUserGUID, CreateDate, UserName, Text) " . "values({$id}, {$vUserID}, '{$vUnknownUserGUID}', '" . GetLocalDateTimeAsSQLStr() . "', '{$UserName}', '{$Comment}');";
            GetMainConnection()->exec($sql);
        } else {
            $ErrorText = 'Такой отзыв уже существует.';
        }
    }
    // Формат ответа: 1 позиция текст ошибки, 2 позиция кол-во комментов, 3-html для перезаполнения таблицы комментов
    if (empty($ErrorText)) {
        $sql = "select CreateDate, UserID, UserName, Text " . "from CatalogComments " . "where (CatalogItemID = {$id}) " . "and (IsDeleted = 0) " . "order by CreateDate desc;";
        $Comments = GetMainConnection()->query($sql)->fetchAll();
        echo '||' . count($Comments) . '||' . GetCatalogCommentsHTML($Comments);
    } else {
        echo $ErrorText . '||||';
    }
}
 public function contactusAction()
 {
     $email = Tools::getValue('email');
     $name = Tools::getValue('name');
     $subject = Tools::getValue('subject');
     $question = Tools::getValue('question');
     if (empty($name)) {
         $name = $email;
     }
     if (Tools::isPost()) {
         if (isset($_SESSION['auth'])) {
             $vUserID = $_SESSION['auth']['id'];
             $vUnknownUserGUID = "null";
         } else {
             $vUserID = "null";
             $vUnknownUserGUID = "'" . (string) GetUnknownUserGUID() . "'";
         }
         $RecordID = DBInsertRecord($this->db, "ContactUs");
         $sql = "update ContactUs " . "set StateID = 1, " . "UserID = {$vUserID}, " . "UnknownUserGUID = {$vUnknownUserGUID}, " . "CreateDate = '" . GetLocalDateTimeAsSQLStr() . "', " . "UserName = '******', " . "UserEmail = '{$email}', " . "MessageSubject = '{$subject}', " . "MessageText = '{$question}' " . "where (ID = {$RecordID});";
         $this->db->exec($sql);
         $content = array('title' => $subject, 'template' => 'contactus', 'data' => array('[year]' => date("Y", time()), '[name]' => $name, '[email]' => $email, '[question]' => $question, '[ticketlink]' => URL . "admincp/index.php?mod=ContactUsItem&id=" . $RecordID));
         //$vSendResult = Mailer::send('*****@*****.**', $content, $subject, null, $email);
         $vSendResult = SendEmailSMTP($email, $name, '*****@*****.**', $content, null, SMTP_CC);
         if ($vSendResult !== true) {
             return AddAlertMessage('danger', 'Ошибка при отправке письма!', '/');
         } else {
             return AddAlertMessage('success', 'Ваше сообщение было отправлено!', '/');
         }
     }
     $this->view->breadcrumbs = array(array('url' => '/auth/contactus', 'title' => 'Свяжитесь с нами'));
     $this->view->meta = array('meta_title' => 'Свяжитесь с нами', 'meta_description' => 'Свяжитесь с нами', 'meta_keywords' => '');
     $this->view->generate();
 }
             $mail->AddAddress($t);
         }
     } else {
         $mail->AddAddress($to);
     }*/
 $mail->AddAddress($rec['ToEmail'], $rec['ToName']);
 // Set email format to HTML
 $mail->isHTML(true);
 $mail->Subject = $rec['Subject'];
 // add content
 if (empty($rec['UseTemplate'])) {
     $vBody = base64_decode($rec['Body']);
 } else {
     if (empty($rec['Body'])) {
         $vTemplateParamsArray = array();
     } else {
         $vTemplateParamsArray = unserialize(base64_decode($rec['Body']));
     }
     $vBody = strtr(file_get_contents(URL . 'public/mails/' . $rec['UseTemplate'] . '.html'), $vTemplateParamsArray);
 }
 $mail->MsgHTML($vBody);
 /*
     // add attachments
     if ($attach != null) {
         foreach ($attach as $a) {
             $mail->AddAttachment($a['path'], $a['name']);
         }
     }*/
 //$answer = (!$mail->send()) ? $mail->ErrorInfo : true;
 SetTaskActivity($vTaskName, true);
 if ($mail->send()) {
Exemplo n.º 5
0
function Emails_AddNotify($ADocumentType, $ADocumentID, $ASubject, $ABody, $AOwnerEmail)
{
    $sql = "insert into Emails_Notify(RecordGUID, DocumentType, DocumentID, CreateDate, Subject, Body, OwnerEmail) " . "values(UUID(), {$ADocumentType}, {$ADocumentID}, '" . GetLocalDateTimeAsSQLStr() . "', '" . mb_strimwidth(ClearSQLStr($ASubject), 0, 252, '...') . "', '" . base64_encode($ABody) . "', lower('{$AOwnerEmail}'));";
    GetMainConnection()->exec($sql);
    CURL_SpeedUp_SendEmail();
}
 $IsNotifyRecipientActive = POSTBoolAsSQLStr('IsNotifyRecipientActiveEdt');
 unset($_POST['ajax_AddCommentBtn']);
 unset($_POST['UserNameEdt']);
 unset($_POST['IsRecipientEdt']);
 unset($_POST['CommentEdt']);
 if (isset($_SESSION['auth'])) {
     $vUserID = $_SESSION['auth']['id'];
     $vUnknownUserGUID = "";
 } else {
     $vUserID = "0";
     $vUnknownUserGUID = (string) GetUnknownUserGUID();
 }
 $sql = "select ID " . "from ArticleComments " . "where (ArticleID = {$id}) " . "and (UnknownUserGUID = '{$vUnknownUserGUID}') " . "and (UserID = {$vUserID}) " . "and (Comment = '{$Comment}');";
 $rec = GetMainConnection()->query($sql)->fetch();
 if (empty($rec['ID'])) {
     $sql = "insert into ArticleComments(ArticleID, UnknownUserGUID, UserID, UserName, CommentDate, Comment) " . "values({$id}, '{$vUnknownUserGUID}', {$vUserID}, '{$UserName}', '" . GetLocalDateTimeAsSQLStr() . "', '{$Comment}');";
     GetMainConnection()->exec($sql);
     /*$sql = "insert into CatalogRatings(CatalogItemID, UserID, UnknownUserGUID, Rating1, Rating2, Rating3) ".
       "select * from (select $id as C1, $vUserIDForIns as C2, $vUnknownUserGUIDForIns as C3, $Rating1 as C4, $Rating2 as C5, $Rating3 as C6) AS tmp ".
       "where not exists ( ".
          "select ID ".
          "from CatalogRatings ".
          "where (CatalogItemID = $id) ".
          "and (UserID $vUserID) ".
          "and (UnknownUserGUID $vUnknownUserGUID) ".
       ") limit 1;";*/
     if (POSTBoolAsSQLStr('PriorNotifyStateEdt') != $IsNotifyRecipientActive) {
         if ($IsNotifyRecipientActive == '1') {
             Emails_AddNotifyRecipient(1, $id, $OwnerEmail);
         } else {
             Emails_DeleteNotifyRecipient(1, $id, $OwnerEmail);