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(); }
public function itemAction($id = null) { if (empty($id)) { return AddAlertMessage('danger', 'Организации не существует.', '/'); } $CanSubmit = CanSubmit_CheckTokenForPreventDoubleSubmit(); $ActiveTab = "uslugi"; /*if (($CanSubmit == true) && (filter_input(INPUT_POST, 'AddCommentBtn') !== NULL)) { $ActiveTab = "comments"; $MsgUserName = POSTStrAsSQLStr('MsgUserName'); $MsgText = POSTStrAsSQLStr('MsgText'); unset($_POST['AddCommentBtn']); unset($_POST['MsgUserName']); unset($_POST['MsgText']); if (!empty($MsgUserName) && !empty($MsgText)) { if (isset($_SESSION['auth'])) { $vUserID = $_SESSION['auth']['id']; $vUnknownUserGUID = "null"; } else { $vUserID = "null"; $vUnknownUserGUID = "'".(string)GetUnknownUserGUID()."'"; } $sql = "insert into CatalogComments(CatalogItemID, UserID, UnknownUserGUID, CreateDate, UserName, Text) ". "values($id, $vUserID, $vUnknownUserGUID, '".GetLocalDateTimeAsSQLStr()."', '$MsgUserName', '$MsgText');"; $this->db->exec($sql); } }*/ if ($CanSubmit == true && filter_input(INPUT_POST, 'AddRaitingBtn') !== NULL) { $ActiveTab = "raiting"; $Rating1 = POSTStrAsSQLStr('uslovjEdt'); $Rating2 = POSTStrAsSQLStr('personalEdt'); $Rating3 = POSTStrAsSQLStr('uvagaEdt'); unset($_POST['AddRaitingBtn']); unset($_POST['uslovjEdt']); unset($_POST['personalEdt']); unset($_POST['uvagaEdt']); if (isset($_SESSION['auth'])) { $vUserIDForIns = $_SESSION['auth']['id']; $vUnknownUserGUIDForIns = "null"; $vUserID = "=" . $_SESSION['auth']['id']; $vUnknownUserGUID = "is null"; } else { $vUserIDForIns = "null"; $vUnknownUserGUIDForIns = "'" . (string) GetUnknownUserGUID() . "'"; $vUserID = "is null"; $vUnknownUserGUID = "='" . (string) GetUnknownUserGUID() . "'"; } $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;"; $this->db->exec($sql); } $sql = "select CI.ID, CI.id_pod_cat, CI.name, L.ShortName as LocalityName, CONCAT_WS(', ', L.Name, CI.adress) as FullAddress, CI.adress, CI.foto, CI.kont_tell, " . "CI.site_url, CP.name as SubCategoryName, CI.MetaKeywords, (CI.Rating1+CI.Rating2+CI.Rating3)/3 as TotalRating, " . "CI.Rating1, CI.Rating2, CI.Rating3, CI.CountRatings, CI.uslugi, CI.MapX, CI.MapY, L.RegionName, L.LocalityName as OriginalLocalityName " . "from Catalog_item as CI " . "left outer join view_LocalitiesWithRegion as L on ((CI.LocalityID = L.ID) and (CI.RegionID = L.RegionID)) " . "left outer join Catalog_pod as CP on (CI.id_pod_cat = CP.ID) " . "where CI.ID = {$id} " . "and CI.IsDeleted = 0"; $item = $this->db->query($sql)->fetch(); $sql = "select PI.foto, CONCAT_WS(' ', PI.famil, PI.name, PI.othestvo) as Name, PP.Name as JobTitleName, PI.tell_kont, PI.rabot_graf " . "from Personal_item as PI " . "left outer join Personal_pod as PP on (PI.id_pod_cat = PP.ID) " . "where (PI.CatalogItemID = {$id}) " . "and (PI.IsDeleted = 0) " . "order by PI.famil, PI.name, PI.othestvo;"; $personal = $this->db->query($sql)->fetchAll(); $sql = "select Photo " . "from Catalog_item_images " . "where (CatalogItemID = {$id}) " . "order by ID;"; $photos = $this->db->query($sql)->fetchAll(); $sql = "select CreateDate, UserID, UserName, Text " . "from CatalogComments " . "where (CatalogItemID = {$id}) " . "and (IsDeleted = 0) " . "order by CreateDate desc;"; $comments = $this->db->query($sql)->fetchAll(); if (isset($_SESSION['auth'])) { $vUserID = "=" . $_SESSION['auth']['id']; $vUnknownUserGUID = "is null"; } else { $vUserID = "is null"; $vUnknownUserGUID = "='" . (string) GetUnknownUserGUID() . "'"; } $sql = "select ID " . "from CatalogRatings " . "where (CatalogItemID = {$id}) " . "and (UserID {$vUserID}) " . "and (UnknownUserGUID {$vUnknownUserGUID}) " . "limit 1;"; $rec = $this->db->query($sql)->fetch(); $RaitingID = $rec['ID']; $this->view->setVars(array('id' => $id, 'item' => $item, 'personal' => $personal, 'photos' => $photos, 'comments' => $comments, 'ActiveTab' => $ActiveTab, 'RaitingID' => $RaitingID)); $this->view->breadcrumbs = array(array('url' => '/catalog/', 'title' => 'Каталог организаций'), array('url' => '/catalog/p-' . $item['id_pod_cat'], 'title' => $item['SubCategoryName']), array('url' => '/catalog/i-' . $id, 'title' => $item['name'])); $this->view->meta = array('meta_title' => 'Организация: ' . $item['name'], 'meta_description' => 'Организация: ' . $item['name'], 'meta_keywords' => $item['MetaKeywords']); SetTokenForPreventDoubleSubmit(); $this->view->generate(); }