module_unicalendar/unicalendar/class.unicalendar.php

186 lines
5.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Класс работы с календарями событий - модуля Unicalendar
*
* @autor Repellent
* @package AVE.cms
* @subpackage module_unicalendar
* @filesource
*/
class Unicalendar
{
/**
* ФУНКЦИИ ПУБЛИЧНОЙ ЧАСТИ
*/
/**
* Вывод календаря событий
* @param string $tpl_dir - путь к папке с шаблонами модуля
* @param int $id - идентификатор календаря
*/
function unicalendarShow($tpl_dir, $id)
{
global $AVE_DB, $AVE_Template;
$sql = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_unicalendar
WHERE id = '" . $id . "'
");
$unicalendars = array();
while ($row = $sql->FetchAssocArray())
{
array_push($unicalendars, $row);
}
foreach ( $unicalendars as $k=>$v )
{
$uevents = $v['uca_events'];
$urubric_id = $v['uca_rubric_id'];
$udoc_id = $v['uca_doc_id'];
}
// Если выбрали вывести все документы из заданной рубрики - документы с Id=1 и Id=2 - выводиться не будут!
if ($uevents !='' && $uevents == '1'){
$sql = $AVE_DB->Query("
SELECT Id, document_alias, document_title, document_published, document_meta_description
FROM " . PREFIX . "_documents
WHERE rubric_id = '" . $urubric_id . "' AND Id > 2
");
$results = array();
while ($row = $sql->FetchAssocArray())
{
array_push($results, $row);
}
}
// Если выбрали вывести выбранные документы из заданной рубрики
if ($uevents !='' && $uevents == '2'){
$sql = $AVE_DB->Query("
SELECT Id, document_alias, document_title, document_published, document_meta_description
FROM " . PREFIX . "_documents
WHERE rubric_id = '" . $urubric_id . "' AND Id > 2 AND $udoc_id
");
$results = array();
while ($row = $sql->FetchAssocArray())
{
array_push($results, $row);
}
}
$AVE_Template->assign('unicalendars', $unicalendars);
$AVE_Template->assign('results', $results);
$AVE_Template->display($tpl_dir . 'unicalendar.tpl');
}
/**
* ФУНКЦИИ АДМИНИСТРАТИВНОЙ ЧАСТИ
*/
/**
* Вывод списка календарей
*
* @param string $tpl_dir - путь к папке с шаблонами модуля
*/
function unicalendarList($tpl_dir)
{
global $AVE_DB, $AVE_Template;
$unicalendars = array();
$limit = 20;
$start = get_current_page() * $limit - $limit;
$sql = $AVE_DB->Query("
SELECT SQL_CALC_FOUND_ROWS
u.*,
COUNT(u.id) AS uca_count
FROM
" . PREFIX . "_module_unicalendar AS u
GROUP BY u.id
ORDER BY u.id ASC
LIMIT " . $start . "," . $limit . "
");
$sql_num = $AVE_DB->Query("SELECT FOUND_ROWS()");
$num = $sql_num->GetCell();
while($row = $sql->FetchAssocArray())
{
array_push($unicalendars, $row);
}
if ($num > $limit)
{
$page_nav = "<li><a href=\"index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=1&page={s}&amp;cp=" . SESSION . "\">{t}</a></li>";
$page_nav = get_pagination(ceil($num / $limit), 'page', $page_nav);
}
else
{
$page_nav = '';
}
$AVE_Template->assign('page_nav', $page_nav);
if (!empty($_REQUEST['alert']))
{
$AVE_Template->assign('alert', htmlspecialchars(stripslashes($_REQUEST['alert'])));
}
$AVE_Template->assign('unicalendars', $unicalendars);
$AVE_Template->assign('formaction', 'index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=new&sub=save&amp;cp=' . SESSION);
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_unicalendar_list.tpl'));
}
/**
* Создание календаря
*
*/
function unicalendarNew()
{
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save')
{
global $AVE_DB;
$cont = true;
$alert = '';
if (empty($_POST['uca_title']))
{
$alert = '&alert=empty_uca_title';
$cont = false;
}
if ($cont)
{
$AVE_DB->Query("
INSERT
INTO " . PREFIX . "_module_unicalendar
SET
id = '',
uca_title = '" . $_POST['uca_title'] . "',
uca_events = '" . $_POST['uca_events'] . "',
uca_rubric_id = '" . $_POST['uca_rubric_id'] . "',
uca_doc_id = '" . $_POST['uca_doc_id'] . "'
");
}
header('Location:index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=1'. $alert);
exit;
}
}
/**
* Удаление календаря
*
* @param int $unicalendar_id - идентификатор календаря
*/
function unicalendarDelete($unicalendar_id)
{
global $AVE_DB;
$AVE_DB->Query("DELETE FROM " . PREFIX . "_module_unicalendar WHERE id = '" . $unicalendar_id . "'");
header('Location:index.php?do=modules&action=modedit&mod=unicalendar&moduleaction=1&amp;cp=' . SESSION);
exit;
}
}
?>