Viewing file: module.php (11.46 KB) -rwxrwxrwx Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
class Announcements
{
var $UserMode = true;
var $AdminMode = true;
var $SearchMode = true;
var $PanelMode = true;
var $AdminAsynchMode = true;
var $Table;
var $Directory;
var $ClassName = 'Announcements';
var $Photomanager;
function Announcements()
{
$this->Directory = dirname(__FILE__);
$this->Table = new AMTable2('AMCMS_announcements');
$this->Table->Module($this->ClassName);
$this->Table->AddIndexField('announcement_id');
$this->Table->AddPositionField("announcement_position");
$params['main'] = GetParam("AnnouncementsMainPhotoSize");
$params['text']['small'] = GetParam("AnnouncementsSmallPhotoSize");
$params['text']['big'] = GetParam("AnnouncementsBigPhotoSize");
$this->Photomanager = new AMPhotomanager($params);
}
function User()
{
global $ulang, $ULANG;
if (isset($_GET['list']))
{
$year = 0;
if ($_GET['list'] >= GetParam("StartYear") && $_GET['list'] <= GetCurrentYear())
$year = $_GET['list'];
if ($year != 0)
{
$date1 = $year."-01-01";
$date2 = ($year+1)."-01-01";
$rows = $this->Table->GetRows("announcement_position DESC", array("announcement_type = '2'", "announcement_date >= '$date1'", "announcement_date < '$date2'"));
}
else
$rows = $this->Table->GetRows("announcement_position DESC", array("announcement_type = '1'"));
$smarty = GetUserSmarty($this->ClassName);
$smarty->assign('rows', $rows);
$smarty->assign('Photomanager', $this->Photomanager);
$smarty->assign('mod', $this->ClassName);
$result['Content'] = $smarty->fetch("user-year-form.tpl").
$smarty->fetch("user-row.tpl");
$modName = GetParam('Module'.$this->ClassName, $ulang);
$modArchiveName = GetParam("Module{$this->ClassName}Archive", $ulang);
$navigator = new AMNavigator();
if ($year == 0)
$navigator->AddLink($modName, "/announcement");
else
{
$year = DateExplode($row['announcement_date']);
$navigator->AddLink($modArchiveName, "/announcements/archive/".$year[0]);
}
$result['GlobalParams']['Navigator'] = $navigator->Fetch();
$result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage();
$result['Module'] = $this->ClassName;
$result['Print'] = true;
$result['Title'] = ($year == 0) ? $modName : $modArchiveName;
return $result;
}
if (isset($_GET['announcement_id']))
{
$row = $this->Table->GetRowById($_GET['announcement_id']);
if ($row == null) return;
$modName = GetParam('Module'.$this->ClassName, $ulang);
$modArchiveName = GetParam("Module{$this->ClassName}Archive", $ulang);
$smarty = GetUserSmarty($this->ClassName);
$smarty->assign('row', $row);
$smarty->assign('Photomanager', $this->Photomanager);
$smarty->assign('mod', $this->ClassName);
$navigator = new AMNavigator();
if ($row['announcement_type'] == '1')
$navigator->AddLink($modName, "/announcements");
else
{
$year = DateExplode($row['announcement_date']);
$navigator->AddLink($modArchiveName, "/announcements/archive/".$year[0]);
}
$navigator->AddLink($row['announcement_title_'.$ulang], "/announcements/{$row['announcement_id']}");
$result['Title'] = $row['announcement_title_'.$ulang];
$result['Content'] = $smarty->fetch("user-page.tpl");
$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['AnnouncementMenuAdd'], 'link' => '?mod='.$this->ClassName.'&add'),
array('title' => $ALANG['AnnouncementMenuList'], 'link' => '?mod='.$this->ClassName.'&list'),
array('title' => $ALANG['AnnouncementMenuArchive'], 'link' => '?mod='.$this->ClassName.'&archive'),
);
}
function Admin()
{
global $ALANG, $alang;
$smarty = GetAdminSmarty($this->ClassName);
if (isset($_GET['list']))
{
$fields = array("announcement_date", "announcement_title_".GetParam("DefaultLanguage"));
$captions = array($ALANG['Announcements_announcement_date'], $ALANG['Announcements_announcement_title']);
$conditions = "announcement_type = '1'";
$order = "announcement_position DESC";
$links = array("checkbox", "delete", "edit", "toarhive");
$multiple = array("delete", "toarhive");
$params = array("sortable" => "yes", "id" => "announcement");
$html = $this->Table->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params);
$result['Title'] = $ALANG['AnnouncementList'];
$result['Content'] = $html;
return $result;
}
if (isset($_GET['archive']))
{
$year = $_GET['year'];
if ($year < 2000)
$year = GetCurrentYear();
if (isset($_POST['year']))
$year = $_POST['year'];
$smarty = GetAdminSmarty($this->ClassName);
$smarty->assign("year", $year);
$date1 = "{$year}-01-01";
$date2 = ($year + 1)."-01-01";
$fields = array("announcement_date", "announcement_title_".GetParam("DefaultLanguage"));
$captions = array($ALANG['Announcements_announcement_date'], $ALANG['Announcements_announcement_title']);
$conditions = array("announcement_type = '2'", "announcement_date >= '{$date1}'", "announcement_date < '{$date2}'");
$order = "announcement_position DESC";
$multiple = array("delete", "fromarhive");
$links = array("checkbox", "delete", "edit", "fromarhive");
$params = array("sortable" => "yes", "id" => "announcement");
$html = $this->Table->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params);
$result['Title'] = $ALANG['AnnouncementArchive'];
$result['Content'] = $smarty->fetch("year.tpl").$html;
return $result;
}
if (isset($_GET['add']))
{
if (isset($_POST['add']))
{
$_POST['announcement_date_of_creation'] = GetCurrentDateAndTime();
$_POST['announcement_date_of_edition'] = GetCurrentDateAndTime();
$_POST['announcement_date'] = DateConvert($_POST['announcement_date_year'], $_POST['announcement_date_month'], $_POST['announcement_date_day'], $_POST['announcement_date_hours'], $_POST['announcement_date_minutes']);
$id = $this->Table->Insert($_POST);
$this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id));
header("Location: ?mod=".$this->ClassName."&list");
}
foreach($_POST as $key => $value)
$smarty->assign($key, $value);
$smarty->assign('oper', 'add');
$smarty->assign('announcement_date', GetCurrentDateAndTime());
$smarty->assign('announcement_show_title', 'Y');
$smarty->assign('announcement_show_read_more_link', 'Y');
$smarty->assign('announcement_show_date', 0);
$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['AnnouncementAdd'];
$result['Content'] = $smarty->fetch('announcement.tpl');
return $result;
}
if (isset($_GET['edit']) && isset($_GET['announcement_id']))
{
$id = $_GET['announcement_id'];
if (isset($_POST['edit']))
{
$_POST['announcement_date_of_edition'] = GetCurrentDateAndTime();
$_POST['announcement_date'] = DateConvert($_POST['announcement_date_year'], $_POST['announcement_date_month'], $_POST['announcement_date_day'], $_POST['announcement_date_hours'], $_POST['announcement_date_minutes']);
$this->Table->Update($_POST, $id);
$this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id));
$row = $this->Table->GetRowById($_GET['announcement_id']);
if ($row['announcement_type'] == 1)
header("Location: ?mod=".$this->ClassName."&list");
else
header("Location: ?mod=".$this->ClassName."&archive&year=".$_POST['announcement_date_year']);
}
$smarty = GetAdminSmarty($this->ClassName);
$row = $this->Table->GetRowById($_GET['announcement_id']);
foreach($row as $key => $value)
$smarty->assign($key, $value);
$smarty->assign('oper', 'edit');
$photo_admin_table = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id));
$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['AnnouncementEdit'];
$result['Content'] = $smarty->fetch('announcement.tpl');
return $result;
}
}
function Panel()
{
global $ULANG, $ulang;
$rows = $this->Table->GetRows("announcement_position DESC", array("announcement_type = '1'"));
$smarty = GetUserSmarty($this->ClassName);
$smarty->assign('rows', $rows);
$smarty->assign('Photomanager', $this->Photomanager);
$smarty->assign('mod', $this->ClassName);
$result[$this->ClassName] = array( 'Title' => GetParam("Module".$this->ClassName."Panel", $ulang),
'Content' => $smarty->fetch("user-row.tpl"),
'Module' => $this->ClassName,
'Link' => array("Address" => "/announcements",
"Title" => $ULANG['AnnouncementsArchiveLinkTitle'],
"Class" => "archive"));
return $result;
}
function Search($words)
{
global $ulang, $ULANG;
$fields = array("announcement_title_".$ulang, "announcement_short_text_".$ulang, "announcement_description_".$ulang, "announcement_text_".$ulang, "announcement_keywords_".$ulang);
$rows = SearchOnSite($words, array('announcement_title_'.$ulang, "announcement_date_of_creation"), 'announcement_id', $fields, 'AMCMS_announcements');
$searchRows = array();
if ($rows)
foreach($rows as $key => $value)
{
$row['Module'] = $this->ClassName;
$row['Date'] = $value['announcement_date_of_creation'];
$row['Title'] = $value['announcement_title_'.$ulang];
$row['Link'] = "/announcements/{$value['announcement_id']}";
$row['Relev'] = $value['relev'];
$row['NewWindowLink'] = $link;
$searchRows [] = $row;
}
return $searchRows;
}
function AdminAsynch()
{
global $alang, $ALANG;
if (isset($_POST['oper']) && ($_POST['oper'] == 'toarchive'))
{
$id = $_POST['id'];
$row['announcement_date_of_archiving'] = GetCurrentDateAndTime();
$row['announcement_type'] = 2;
$this->Table->Update($row, $id);
$res["status"] = "ok";
$res["code"] = $id;
echo json_encode($res);
die;
}
if (isset($_POST['oper']) && ($_POST['oper'] == 'fromarchive'))
{
$id = $_POST['id'];
$row['announcement_date_of_archiving'] = "";
$row['announcement_type'] = 1;
$this->Table->Update($row, $_POST['id']);
$res["status"] = "ok";
$res["code"] = $id;
echo json_encode($res);
die;
}
$this->Table->Run($_POST);
}
}
$Modules ['Announcements'] = new Announcements();
?>
|