Viewing file: module.php (12.56 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<? class Publications { var $UserMode = false; var $UserAsynchMode = true; var $AdminMode = true; var $AdminAsynchMode = true; var $SearchMode = false; var $PanelMode = true; var $PublicationsTable; var $GroupsTable; var $SGroupsTable; var $Directory; var $FilesDirectory; var $ClassName = 'Publications'; function Publications() { $this->FilesDirectory = "data/publications/"; $this->Directory = dirname(__FILE__); $this->PublicationsTable = new AMTable2('AMCMS_publications'); $this->PublicationsTable->AddIndexField('publication_id'); $this->PublicationsTable->Module($this->ClassName); $this->PublicationsTable->AddPositionField("publication_position"); $this->GroupsTable = new AMTable2('AMCMS_publications_groups'); $this->GroupsTable->AddIndexField('group_id'); $this->GroupsTable->Module($this->ClassName); $this->GroupsTable->AddPositionField("group_position"); $this->SGroupsTable = new AMTable2('AMCMS_publications_subgroups'); $this->SGroupsTable->AddIndexField('sgroup_id'); $this->SGroupsTable->Module($this->ClassName); $this->SGroupsTable->AddPositionField("sgroup_position"); } function User() { global $language, $ULANG; } function Menu() { global $ALANG; return array( array('title' => "Додати документ", 'link' => '?mod='.__CLASS__.'&document&add'), array('title' => "Список документів", 'link' => '?mod='.__CLASS__.'&document&list'), array('title' => "Додати групу", 'link' => '?mod='.__CLASS__.'&groups&add'), array('title' => "Список груп", 'link' => '?mod='.__CLASS__.'&groups&list'), array('title' => "Додати розділ", 'link' => '?mod='.__CLASS__.'&sgroups&add'), array('title' => "Список розділів", 'link' => '?mod='.__CLASS__.'&sgroups&list'), ); } function UserAsynch() { $group_id = $_REQUEST['group_id']; $rows = $this->SGroupsTable->GetRows("sgroup_id DESC","group_id = '{$_REQUEST['group_id']}'"); $html .= "<option value=\"0\">НЕ КЛАСИФІКОВАНО</option>"; for($i = 0; $i < count($rows); $i++) $html .= "<option value=\"{$rows[$i]['sgroup_id']}\">{$rows[$i]['sgroup_name_ukr']}</option>"; echo $html; } function Admin() { global $ALANG, $alang, $_LANG_ID; $smarty = GetAdminSmarty($this->ClassName); if (isset($_GET['groups']) && isset($_GET['add'])) { if (isset($_POST['add'])) { $id = $this->GroupsTable->Insert($_POST); header("Location: ?mod=".__CLASS__."&groups&list"); } $smarty->assign('oper', 'add'); $result['Title'] = "Додавання групи"; $result['Content'] = $smarty->fetch('group.tpl'); return $result; } if (isset($_GET['sgroups']) && isset($_GET['add'])) { if (isset($_POST['add'])) { $id = $this->SGroupsTable->Insert($_POST); header("Location: ?mod=".__CLASS__."&sgroups&list"); } $smarty->assign('oper', 'add'); $smarty->assign('groups', $this->GroupsTable->GetRows()); $result['Title'] = "Додавання розділу"; $result['Content'] = $smarty->fetch('sgroup.tpl'); return $result; } if (isset($_GET['groups']) && isset($_GET['list'])) { $fields = array("group_name_".GetParam("DefaultLanguage")); $captions = array("Назва групи"); $order = "group_position DESC"; $links = array("checkbox", "delete", "edit"); $multiple = array("delete"); $params = array("sortable" => "yes", "id" => "Publications"); $html = $this->GroupsTable->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); $result['Title'] = "Список груп"; $result['Content'] = $html; return $result; } if (isset($_GET['sgroups']) && isset($_GET['list'])) { $fields = array("sgroup_name_".GetParam("DefaultLanguage")); $captions = array("Назва розділу"); $conditions = array("group_id = '{$_REQUEST['group_id']}'"); $order = "sgroup_position DESC"; $links = array("checkbox", "delete", "edit"); $multiple = array("delete"); $params = array("sortable" => "yes", "id" => "Publications"); $html = $this->SGroupsTable->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); $result['Title'] = "Список розділів"; $smarty->assign('groups', $this->GroupsTable->GetRows()); $result['Content'] = $smarty->fetch("group-select.tpl").$html; return $result; } if (isset($_GET['edit']) && isset($_GET['group_id'])) { $id = $_GET['group_id']; $row = $this->GroupsTable->GetRowById($id); if (isset($_POST['edit'])) { $this->GroupsTable->Update($_POST, $id); header("Location: ?mod=".$this->ClassName."&groups&list"); } foreach($row as $key => $value) $smarty->assign($key, $value); $smarty->assign('oper', 'edit'); $result['Title'] = "Редагування групи"; $result['Content'] = $smarty->fetch('group.tpl'); return $result; } if (isset($_GET['edit']) && isset($_GET['sgroup_id'])) { $id = $_GET['sgroup_id']; $row = $this->SGroupsTable->GetRowById($id); if (isset($_POST['edit'])) { $this->SGroupsTable->Update($_POST, $id); header("Location: ?mod=".$this->ClassName."&sgroups&list&group_id={$_POST['group_id']}"); } foreach($row as $key => $value) $smarty->assign($key, $value); $smarty->assign('oper', 'edit'); $smarty->assign('groups', $this->GroupsTable->GetRows()); $result['Title'] = "Редагування розділу"; $result['Content'] = $smarty->fetch('sgroup.tpl'); return $result; } if (isset($_GET['document']) && isset($_GET['list'])) { if (isset($_REQUEST['sgroup_id']) && $sgroup_id != 0) { $sgroup = $this->SGroupsTable->GetRowById($_REQUEST['sgroup_id']); $_REQUEST['group_id'] = $sgroup['group_id']; } $groups = $this->GroupsTable->GetRows("group_position DESC"); //foreach($groups as $group) { $fields = array("publication_name_".GetParam("DefaultLanguage")); $captions = array("Назва публікації"); $conditions = array("group_id = '{$_REQUEST['group_id']}' AND sgroup_id = '{$_REQUEST['sgroup_id']}'"); $order = "publication_position DESC"; $links = array("checkbox", "delete", "edit"); $multiple = array("delete"); $params = array("sortable" => "yes", "id" => "group".$group['group_id']); $html .= "<div class=\"page-subtitle\">".$group['group_name_'.GetParam("DefaultLanguage")]."</div>"; $html .= $this->PublicationsTable->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); } $result['pagename'] = "Список документів"; $result['Title'] = "Список документів"; $smarty->assign('groups', $this->GroupsTable->GetRows()); $smarty->assign('sgroups', $this->SGroupsTable->GetRows("sgroup_id DESC","group_id = '{$_REQUEST['group_id']}'")); $result['Content'] = $smarty->fetch("group-select.tpl").$smarty->fetch("sgroup-select.tpl").$html; return $result; } if (isset($_GET['document'])&& isset($_GET['add'])) { if (isset($_POST['add'])) { $id = $this->PublicationsTable->Insert($_POST); if (strlen($_FILES['publication_filename']['name']) > 0) { $name = $_FILES['publication_filename']['name']; if (!is_file($this->FilesDirectory."{$name}")) { move_uploaded_file($_FILES['publication_filename']['tmp_name'], $this->FilesDirectory."{$name}"); $row['publication_filename'] = $name; $this->PublicationsTable->Update($row, $id); } } header("Location: ?mod=".__CLASS__."&document&list"); die; } foreach($_POST as $key => $value) $smarty->assign($key, $value); $groups = $this->GroupsTable->GetRows("group_position DESC"); $sgroups = $this->SGroupsTable->GetRows("sgroup_id DESC", "group_id = '{$row['group_id']}'"); $smarty->assign('sgroups', $sgroups); $smarty->assign('groups', $groups); $smarty->assign('oper', 'add'); $result['Title'] = $ALANG['PublicationsAdd']; $result['Content'] = $smarty->fetch('publication.tpl'); return $result; } if (isset($_GET['edit']) && isset($_GET['publication_id'])) { if (isset($_POST['edit'])) { $error = $this->PublicationsTable->Update($_POST, $_GET['publication_id']); $id = $_GET['publication_id']; if (strlen($_FILES['publication_filename']['name']) > 0) { $name = $_FILES['publication_filename']['name']; if (!is_file($this->FilesDirectory."{$name}")) { move_uploaded_file($_FILES['publication_filename']['tmp_name'], $this->FilesDirectory."{$name}"); $row['publication_filename'] = $name; $this->PublicationsTable->Update($row, $id); } } $row = $this->PublicationsTable->GetRowById($_GET['publication_id']); header("Location: ?mod=".__CLASS__."&document&list&group_id={$_POST['group_id']}&sgroup_id={$_REQUEST['sgroup_id']}"); die; } $row = $this->PublicationsTable->GetRowById($_GET['publication_id']); foreach($row as $key => $value) $smarty->assign($key, $value); $groups = $this->GroupsTable->GetRows("group_position DESC"); $sgroups = $this->SGroupsTable->GetRows("sgroup_id DESC", "group_id = '{$row['group_id']}'"); $smarty->assign('sgroups', $sgroups); $smarty->assign('groups', $groups); $smarty->assign($key, $value); $smarty->assign('oper', 'edit'); $result['Title'] = $ALANG['PublicationsEdit']; $result['Content'] = $smarty->fetch('publication.tpl'); return $result; } } static function GetDocuments($group, $title = false) { global $ulang; $PublicationsTable = new AMTable2('AMCMS_publications'); $PublicationsTable->AddIndexField('publication_id'); $PublicationsTable->Module(__CLASS__); $PublicationsTable->AddPositionField("publication_position"); $GroupsTable = new AMTable2('AMCMS_publications_groups'); $GroupsTable->AddIndexField('group_id'); $GroupsTable->Module(__CLASS__); $GroupsTable->AddPositionField("group_position"); $SGroupsTable = new AMTable2('AMCMS_publications_subgroups'); $SGroupsTable->AddIndexField('sgroup_id'); $SGroupsTable->Module(__CLASS__); $SGroupsTable->AddPositionField("sgroup_position"); $gr = $GroupsTable->GetRowById($group); $html = ""; if ($title) { $html = "<h2>".$gr["group_name_{$ulang}"]."</h2>"; } $chapters = $SGroupsTable->GetRows("sgroup_position DESC", "group_id = '{$group}'"); $chapters [] = array("sgroup_id" => 0, "sgroup_name_ukr" => "Інше", "sgroup_name_eng" => "Other"); for($k = 0; $k < count($chapters); $k++) { $sgroup_id = $chapters[$k]['sgroup_id']; $rows = $PublicationsTable->GetRows("publication_position DESC", "group_id = '{$group}' AND sgroup_id = '{$sgroup_id}'"); if (count($rows) == 0) continue; $sgroup = $chapters[$k]; if (count($chapters) > 1) $html .= "<h2>".$sgroup["sgroup_name_{$ulang}"]."</h2>"; $html .= "<ul class=\"publications\">"; foreach($rows as $pub) { $ext = getExtension($pub['publication_filename']); $html .= '<li class="'.$ext.'"><a href="/data/publications/'.$pub["publication_filename"].'" target="_blank">'.$pub["publication_name_{$ulang}"].'</a></li>'; } $html .= "</ul>"; } return $html; } function Panel() { global $ULANG, $ulang; $groups = $this->GroupsTable->GetRows(); $smarty = GetUserSmarty($this->ClassName); foreach($groups as $group) { $Publications = $this->PublicationsTable->GetRows("publication_position DESC", "group_id = '{$group['group_id']}'"); $html = ""; foreach($Publications as $row) { $id = $row['publication_id']; $link = $row['publication_link_'.$ulang]; $filename = ""; if (file_exists("data/links/{$id}_{$ulang}.jpeg")) $filename = "/data/links/{$id}_{$ulang}.jpeg"; if (file_exists("data/links/{$id}_{$ulang}.gif")) $filename = "/data/links/{$id}_{$ulang}.gif"; if ($filename != "") $html .= "<div class=\"publication\"><a href=\"{$link}\" target=\"{$row['publication_target']}\"><img src=\"{$filename}\" title=\"{$row['publication_title_'.$ulang]}\"/></a></div>"; } $result['publication'.$group['group_id']] = array('Title' => $group['group_name_'.$ulang]." ", 'Module' => $this->ClassName, 'Content' => $html); } return $result; } function AdminAsynch() { $this->GroupsTable->Run($_POST); $this->PublicationsTable->Run($_POST); } }
$Modules ['Publications'] = new Publications(); ?>
|