Viewing file: module.php (21.44 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<? class News { var $UserMode = true; var $AdminMode = true; var $SearchMode = true; var $PanelMode = true; var $Table; var $Directory; var $CountOfNews; var $ClassName = 'News'; var $AdminAsynchMode = true; var $Photomanager; function News() { $this->Directory = dirname(__FILE__); $this->Table = new AMTable2('AMCMS_news'); $this->Table->AddIndexField('news_id'); $this->Table->AddPositionField("news_position"); $this->Table->Module($this->ClassName); $this->CountOfNews = GetParam('NewsCount'); $params['main'] = "160x500"; $params['text']['small'] = GetParam("NewsSmallPhotoSize"); $params['text']['big'] = GetParam("NewsBigPhotoSize"); $this->Photomanager = new AMPhotomanager($params); } function User() { global $ULANG, $ulang; if (isset($_GET['edit']) && isset($_GET['news_id'])) { if (($_SESSION['user']['user_access']['admin'] != 'Y') and ($_SESSION['user']['user_access']['news'] != 'Y')) return; global $ALANG, $alang; $smarty = GetUserSmarty($this->ClassName); if (isset($_POST['edit'])) { $_POST['news_date_of_edition'] = GetCurrentDateAndTime(); $_POST['news_date'] = DateConvert($_POST['news_date_year'], $_POST['news_date_month'], $_POST['news_date_day'], $_POST['news_date_hours'], $_POST['news_date_minutes']); $id = $_GET['news_id']; $error = $this->Table->Update($_POST, $id); $this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id)); $index = 1; header("Location: /news/p{$id}"); die; } $id = $_GET['news_id']; $row = $this->Table->GetRowById($id); foreach($row as $key => $value) $smarty->assign($key, $value); $smarty->assign($key, $value); $smarty->assign('oper', 'edit'); $photo_admin_table1 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'main'); $photo_admin_table2 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'photos'); $smarty->assign('photo_admin_table1', $photo_admin_table1); $smarty->assign('photo_admin_table2', $photo_admin_table2);
$result['Title'] = $ULANG['AMCMS_news']['NewsEditing']; $result['Content'] = $smarty->fetch('news.tpl'); $navigator = new AMNavigator(); $navigator->AddLink(GetParam("Module{$this->ClassName}", $ulang), "/news"); $navigator->AddLink($row['news_title_'.$ulang], "/news/p{$row['news_id']}"); $navigator->AddLink($ULANG['AMCMS_news']['NewsEditing'], "#"); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } if (isset($_GET['delete']) && isset($_GET['news_id'])) { if (($_SESSION['user']['user_access']['admin'] != 'Y') and ($_SESSION['user']['user_access']['news'] != 'Y')) return; global $ALANG, $alang; $smarty = GetUserSmarty($this->ClassName); if (isset($_POST['delete'])) { $this->Table->Delete($_GET['news_id']); header("Location: /news/"); die; } $id = $_GET['news_id']; $row = $this->Table->GetRowById($id); foreach($row as $key => $value) $smarty->assign($key, $value); $smarty->assign($key, $value); $smarty->assign('oper', 'delete'); $result['Title'] = $ULANG['AMCMS_news']['DeletingNews']; $result['Content'] = $smarty->fetch('news-delete.tpl'); $navigator = new AMNavigator(); $navigator->AddLink(GetParam("Module{$this->ClassName}", $ulang), "/news"); $navigator->AddLink($row['news_title_'.$ulang], "/news/p{$row['news_id']}"); $navigator->AddLink($ULANG['AMCMS_news']['DeletingNews'], "#"); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } if (isset($_GET['add'])) { if (($_SESSION['user']['user_access']['admin'] != 'Y') and ($_SESSION['user']['user_access']['news'] != 'Y')) return; global $ALANG, $alang; $smarty = GetUserSmarty($this->ClassName); if (isset($_POST['add'])) { $_POST['news_date_of_creation'] = GetCurrentDateAndTime(); $_POST['news_date_of_edition'] = GetCurrentDateAndTime(); $_POST['news_date'] = DateConvert($_POST['news_date_year'], $_POST['news_date_month'], $_POST['news_date_day'], $_POST['news_date_hours'], $_POST['news_date_minutes']); $id = $this->Table->Insert($_POST); $this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id)); header("Location: /news/p{$id}"); die; } foreach($_POST as $key => $value) $smarty->assign($key, $value); $smarty->assign('oper', 'add'); $smarty->assign('news_date', GetCurrentDateAndTime()); $smarty->assign('news_show_title', 'Y'); $smarty->assign('news_show_read_more_link', 'Y'); $smarty->assign('news_show_date', 'Y');
$photo_admin_table1 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'main'); $photo_admin_table2 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'photos'); $smarty->assign('photo_admin_table1', $photo_admin_table1); $smarty->assign('photo_admin_table2', $photo_admin_table2); $result['Title'] = $ULANG['AMCMS_news']['NewsAdding']; $result['Content'] = $smarty->fetch('news.tpl'); $navigator = new AMNavigator(); $navigator->AddLink(GetParam("Module{$this->ClassName}", $ulang), "/news"); $navigator->AddLink($ULANG['AMCMS_news']['NewsAdding'], "/news/add"); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } if (isset($_GET['comments'])) { $sql = "SELECT COUNT(*) as count FROM AMCMS_comments, AMCMS_users WHERE (comment_module = 'News') AND (comment_chapter = 'news') AND (comment_user_id = user_id) AND (comment_status = '1') ORDER BY comment_date DESC"; $row = mysql_fetch_assoc(mysql_query($sql)); $count = $row['count']; $page_navigator = new AMPageNavigator($count, $_GET['pageNum'], 20); $limit = $page_navigator->GetLimitStatement(); $sql = "SELECT AMCMS_news.news_id, AMCMS_news.news_title_ukr, AMCMS_news.news_title_rus, AMCMS_news.news_date, AMCMS_comments.*, AMCMS_users.* FROM AMCMS_news, AMCMS_comments, AMCMS_users WHERE (comment_module = 'News') AND (comment_chapter = 'news') AND (comment_user_id = user_id) AND (comment_status = '1') AND comment_page = news_id ORDER BY comment_date DESC {$limit}"; $rows = array(); $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { $rows [] = $row; } $smarty = GetUserSmarty($this->ClassName); $smarty->assign("rows", $rows); $smarty->assign("count", $count); $smarty->assign("pnav", $page_navigator->GetNavigator()); $result['Title'] = $ULANG['AMCMS_photochapter']['AlbumComments']; $smarty->assign('Photomanager', $this->Photomanager); $result['Content'] = $smarty->fetch("news-comments.tpl"); $navigator = new AMNavigator(); $navigator->AddLink(GetParam("Module{$this->ClassName}", $ulang), "/news"); $navigator->AddLink($ULANG['AMCMS_photochapter']['AlbumComments'], ""); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; return; $where = ""; $html = ""; // $year = GetCurrentYear(); if (isset($_GET['year']) && ($_GET['year'] >= 2000) && ($_GET['year'] <= 2050)) $year = $_GET['year']; if (isset($_GET['month']) && ($_GET['month'] >= 1) && ($_GET['month'] <= 12)) $month = $_GET['month']; if (isset($_GET['day']) && ($_GET['day'] >= 1) && ($_GET['day'] <= 31)) $day = $_GET['day']; if (!empty($year) and empty($month) and empty($day)) { $date1 = "{$year}-01-01"; $year2 = $year + 1; $date2 = "{$year2}-01-01"; $where = "(news_date >= '$date1') AND (news_date < '$date2')"; } if (!empty($year) and !empty($month) and empty($day)) { $date1 = "{$year}-{$month}-01"; $month2 = $month + 1; $year2 = $year; if ($month2 > 12) { $month2 = 1; $year2++; } $date2 = "{$year2}-{$month2}-01"; $where = "(news_date >= '$date1') AND (news_date < '$date2')"; } if (!empty($year) and !empty($month) and !empty($day)) { $date1 = "{$year}-{$month}-{$day} 00:00:00"; $date2 = "{$year}-{$month}-{$day} 23:59:59"; $where = "(news_date >= '$date1') AND (news_date <= '$date2')"; } if (empty($year) and empty($month) and empty($day)) { //$prewweek = date('Y-m-d', strtotime("-5 week")); //$now = date('Y-m-d'); //$where = "(news_date between '{$prewweek} 00:00:00' and '{$now} 23:59:59')"; $where = "true"; } // $rows = $this->Table->GetRows("news_date DESC", $where); if (isset($_GET['text'])) { $text = $_GET['text']; $where = "(news_title_{$ulang} LIKE '%$text%') OR (news_text_{$ulang} LIKE '%$text%')"; unset($now); } $count = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) as count FROM AMCMS_news WHERE $where ORDER BY news_date DESC")); $count = $count['count']; $page_navigator = new AMPageNavigator($count, $_GET['pageNum'], 10); $limit = $page_navigator->GetLimitStatement(); $where .= " AND (c.comment_module = 'News' AND c.comment_page = n.news_id)"; $sql = "SELECT n.news_id, n.news_title_ukr, n.news_title_rus, n.news_show_title FROM AMCMS_news as n, AMCMS_comments as c WHERE $where ORDER BY news_date DESC $limit"; $res = mysql_query($sql); $rows = array(); while ($row = mysql_fetch_assoc($res)) { $rows[] = $row; } $smarty = GetUserSmarty($this->ClassName); $smarty->assign("pnav", $page_navigator->GetNavigator()); $smarty->assign('year', $year); $smarty->assign('month', $month); $smarty->assign('day', $day); $smarty->assign('rows', $rows); if (empty($now)) $smarty->assign('count', $count); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $title = GetParam("Module{$this->ClassName}", $ulang); $result['Title'] = $title; $result['Content'] = $html.$smarty->fetch("news-comments.tpl"); $navigator = new AMNavigator(); $navigator->AddLink($title, "/news"); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result;
} if (isset($_GET['news'])) { $where = ""; $html = ""; $search = false; // $year = GetCurrentYear(); if (isset($_GET['year']) && ($_GET['year'] >= 2000) && ($_GET['year'] <= 2050)) $year = $_GET['year']; if (isset($_GET['month']) && ($_GET['month'] >= 1) && ($_GET['month'] <= 12)) $month = $_GET['month']; if (isset($_GET['day']) && ($_GET['day'] >= 1) && ($_GET['day'] <= 31)) $day = $_GET['day']; if (!empty($year) and empty($month) and empty($day)) { $date1 = "{$year}-01-01"; $year2 = $year + 1; $date2 = "{$year2}-01-01"; $where = "(news_date >= '$date1') AND (news_date < '$date2')"; } if (!empty($year) and !empty($month) and empty($day)) { $date1 = "{$year}-{$month}-01"; $month2 = $month + 1; $year2 = $year; if ($month2 > 12) { $month2 = 1; $year2++; } $date2 = "{$year2}-{$month2}-01"; $where = "(news_date >= '$date1') AND (news_date < '$date2')"; } if (!empty($year) and !empty($month) and !empty($day)) { $date1 = "{$year}-{$month}-{$day} 00:00:00"; $date2 = "{$year}-{$month}-{$day} 23:59:59"; $where = "(news_date >= '$date1') AND (news_date <= '$date2')"; } if (empty($year) and empty($month) and empty($day)) { //$prewweek = date('Y-m-d', strtotime("-5 week")); //$now = date('Y-m-d'); //$where = "(news_date between '{$prewweek} 00:00:00' and '{$now} 23:59:59')"; $where = "true"; } // $rows = $this->Table->GetRows("news_date DESC", $where); if (isset($_GET['text'])) { $text = $_GET['text']; $where = "(news_title_{$ulang} LIKE '%$text%') OR (news_text_{$ulang} LIKE '%$text%')"; $search = true; } $count = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) as count FROM AMCMS_news WHERE $where ORDER BY news_date DESC")); $count = $count['count']; $page_navigator = new AMPageNavigator($count, $_GET['pageNum'], 10); $limit = $page_navigator->GetLimitStatement();
$sql = "SELECT * FROM AMCMS_news WHERE $where ORDER BY news_date DESC $limit"; $res = mysql_query($sql); $rows = array(); while ($row = mysql_fetch_assoc($res)) { $rows[] = $row; } $smarty = GetUserSmarty($this->ClassName); $smarty->assign("pnav", $page_navigator->GetNavigator()); $smarty->assign('year', $year); $smarty->assign('month', $month); $smarty->assign('day', $day); $smarty->assign('rows', $rows); $smarty->assign('search', $search); //if (!$search) $smarty->assign('count', $count); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $title = GetParam("Module{$this->ClassName}", $ulang); $result['Title'] = $title; $result['Content'] = $html.$smarty->fetch("user-row.tpl"); $navigator = new AMNavigator(); $navigator->AddLink($title, "/news"); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } if (isset($_GET['news_id'])) { $row = $this->Table->GetRowById($_GET['news_id']); if ($row == null) return; $result['Title'] = $row['news_title_'.$ulang]; $smarty = GetUserSmarty($this->ClassName); $smarty->assign("comments", Comments::GetComments($this->ClassName, "news", $row['news_id'], $nav)); $smarty->assign("count", Comments::GetCommentsCount($this->ClassName, "news", $row['news_id'])); $smarty->assign("navigator", $nav); $smarty->assign('row', $row); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $result['Content'] = ReplaceImages($smarty->fetch("user-page.tpl")); $navigator = new AMNavigator(); $date = DateExplode($row['news_date']); $link = "/news/"; $title = GetParam("Module{$this->ClassName}", $ulang);
$navigator->AddLink($title, $link); $navigator->AddLink($row['news_title_'.$ulang], "#"); $photo = $this->Photomanager->GetMainPhoto($this->ClassName, "news_id={$row['news_id']}"); $result['GlobalParams']['MainImage'] = "/".$photo['photo_filename']; $result['GlobalParams']['Description'] = str_replace('\n',' ',strip_tags($row['news_short_text_'.$ulang])); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } } function Menu() { global $ALANG; return array( array('title' => $ALANG['NewsMenuAdd'], 'link' => '?mod='.$this->ClassName.'&add'), array('title' => $ALANG['NewsMenuList'], 'link' => '?mod='.$this->ClassName.'&list'), ); } function Admin() { global $ALANG, $alang; $smarty = GetAdminSmarty($this->ClassName); if (isset($_GET['list'])) { $smarty = GetAdminSmarty($this->ClassName); $year = GetCurrentYear(); $month = (int)GetCurrentMonth(); if (isset($_GET['month'])) $month = $_GET['month']; if (isset($_GET['year'])) $year = $_GET['year']; if (isset($_POST['month'])) $month = $_POST['month']; if (isset($_POST['year'])) $year = $_POST['year']; if (isset($_POST['news_date_month'])) $month = $_POST['news_date_month']; if (isset($_POST['news_date_year'])) $year = $_POST['news_date_year']; $smarty->assign("year", $year); $smarty->assign("month", $month); $selectorHtml = $smarty->fetch("month.tpl"); $date1 = "{$year}-{$month}-01"; $month2 = $month + 1; $year2 = $year; if ($month2 > 12) { $month2 = 1; $year2++; } $date2 = "{$year2}-{$month2}-01"; $fields = array("news_date", "news_title_".GetParam("DefaultLanguage")); $captions = array($ALANG['News_news_date'], $ALANG['News_news_title']); $conditions = array("(news_date >= '{$date1}')", "(news_date < '{$date2}')"); $order = "news_date DESC"; $links = array("checkbox", "delete", "edit"); $multiple = array("delete"); $params = array("id" => "news"); $html = $this->Table->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); $result['Title'] = $ALANG['NewsList']; $result['Content'] = $selectorHtml.$html; return $result; } if (isset($_GET['add'])) { if (isset($_POST['add'])) { $_POST['news_date_of_creation'] = GetCurrentDateAndTime(); $_POST['news_date_of_edition'] = GetCurrentDateAndTime(); $_POST['news_date'] = DateConvert($_POST['news_date_year'], $_POST['news_date_month'], $_POST['news_date_day'], $_POST['news_date_hours'], $_POST['news_date_minutes']); $id = $this->Table->Insert($_POST); $this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id)); header("Location: ?mod=".$this->ClassName."&list&month=".$_POST['news_date_month']."&year=".$_POST['news_date_year']); die; } foreach($_POST as $key => $value) $smarty->assign($key, $value); $smarty->assign('oper', 'add'); $smarty->assign('news_date', GetCurrentDateAndTime()); $smarty->assign('news_show_title', 'Y'); $smarty->assign('news_show_read_more_link', 'Y'); $smarty->assign('news_show_date', 'Y');
$photo_admin_table1 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'main'); $photo_admin_table2 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'photos'); $smarty->assign('photo_admin_table1', $photo_admin_table1); $smarty->assign('photo_admin_table2', $photo_admin_table2); $result['Title'] = $ALANG['NewsAdd']; $result['Content'] = $smarty->fetch('news.tpl'); return $result; } if (isset($_GET['edit']) && isset($_GET['news_id'])) { if (isset($_POST['edit'])) { $_POST['news_date_of_edition'] = GetCurrentDateAndTime(); $_POST['news_date'] = DateConvert($_POST['news_date_year'], $_POST['news_date_month'], $_POST['news_date_day'], $_POST['news_date_hours'], $_POST['news_date_minutes']); $id = $_GET['news_id']; $error = $this->Table->Update($_POST, $id); $this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id)); $index = 1; header("Location: ?mod=".$this->ClassName."&list&month=".$_POST['news_date_month']."&year=".$_POST['news_date_year']); die; } $id = $_GET['news_id']; $row = $this->Table->GetRowById($id); foreach($row as $key => $value) $smarty->assign($key, $value); $smarty->assign($key, $value); $smarty->assign('oper', 'edit'); $photo_admin_table1 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'main'); $photo_admin_table2 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'photos'); $smarty->assign('photo_admin_table1', $photo_admin_table1); $smarty->assign('photo_admin_table2', $photo_admin_table2); $result['Title'] = $ALANG['NewsEdit']; $result['Content'] = $smarty->fetch('news.tpl'); return $result; } } function Panel() { global $ULANG, $ulang; $rows = $this->Table->GetRows("news_date DESC", "", "0,4"); $smarty = GetUserSmarty($this->ClassName); $smarty->assign('rows', $rows); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $result['News'] = array( 'Title' => ($ulang == "ukr" ? "Останні новини" : "Latest News"), 'Content' => "<div class=\"News Panel\">".$smarty->fetch("user-panel.tpl")."</div>", 'Module' => $this->ClassName, 'Link' => array("Address" => "/news", "Title" => $ULANG['NewsArchiveLinkTitle'], "Class" => "archive")); return $result; } function Search($words) { global $ulang, $ULANG; $fields = array("news_title_".$ulang, "news_short_text_".$ulang, "news_description_".$ulang, "news_text_".$ulang, "news_keywords_".$ulang); $rows = SearchOnSite($words, array('news_title_'.$ulang, "news_date_of_creation"), 'news_id', $fields, 'AMCMS_news'); $searchRows = array(); if ($rows) foreach($rows as $key => $value) { $row['Module'] = $this->ClassName; $row['Date'] = $value['news_date_of_creation']; $row['Title'] = $value['news_title_'.$ulang]; $row['Link'] = "/news/p{$value['news_id']}"; $row['Relev'] = $value['relev']; $row['NewWindowLink'] = $row['Link']; $searchRows [] = $row; } return $searchRows; } function AdminAsynch() { global $alang, $ALANG; $this->Table->Run($_POST); } } $Modules ["News"] = new News(); ?>
|