AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

685 lines
16 KiB

7 years ago
<?php
7 years ago
/**
* AVE.cms
*
* @package AVE.cms
* @subpackage admin
* @filesource
*/
7 years ago
7 years ago
/**
* Если был referer, то перенапрявляем на него
*
6 years ago
* @return mixed|null|string $link
7 years ago
*/
function get_referer_admin_link()
7 years ago
{
7 years ago
static $link = null;
6 years ago
$ok = false;
7 years ago
if ($link === null)
7 years ago
{
7 years ago
if (isset($_SERVER['HTTP_REFERER']))
{
$link = parse_url($_SERVER['HTTP_REFERER']);
7 years ago
6 years ago
$ok = (trim($link['host']) == $_SERVER['HTTP_HOST'])
? true
: false;
$ok = (trim($link['path']) != '/admin/admin.php')
? true
: false;
7 years ago
}
6 years ago
$link = ($ok === true
? $_SERVER['HTTP_REFERER']
: '/admin/index.php');
7 years ago
}
7 years ago
return $link;
}
7 years ago
7 years ago
/**
* Получаем кол-во записей в журналах событий
*
6 years ago
* @return void массив из кол-ва записей
7 years ago
*/
function getLogRecords()
{
6 years ago
global $AVE_Template;
7 years ago
7 years ago
$logs = array();
$logdata = array();
$log404 = array();
$logsql = array();
7 years ago
7 years ago
$_404dir = BASE_DIR . '/tmp/logs/404.php';
$_logdir = BASE_DIR . '/tmp/logs/log.php';
$_sqldir = BASE_DIR . '/tmp/logs/sql.php';
7 years ago
7 years ago
if (file_exists($_logdir))
6 years ago
@eval(' ?>' . file_get_contents($_logdir) . '<?'.'php ');
7 years ago
7 years ago
$logs['logs'] = count($logdata);
7 years ago
7 years ago
if (file_exists($_404dir))
6 years ago
@eval(' ?>' . file_get_contents($_404dir) . '<?'.'php ');
7 years ago
7 years ago
$logs['404'] = count($log404);
7 years ago
7 years ago
if (file_exists($_sqldir))
6 years ago
@eval(' ?>' . file_get_contents($_sqldir) . '<?'.'php ');
7 years ago
7 years ago
$logs['sql'] = count($logsql);
7 years ago
7 years ago
unset($logdata);
unset($log404);
unset($logsql);
7 years ago
7 years ago
// Передаем данные в шаблон для вывода
$AVE_Template->assign('logs', $logs);
7 years ago
}
7 years ago
7 years ago
7 years ago
/**
* Список пользователей за последние $onlinetime секунд
*
* @param int $onlinetime количество секунд
6 years ago
*
* @return void массив из пользователей отсортированный по последней активности
7 years ago
*/
7 years ago
function get_online_users($onlinetime = USERS_TIME_SHOW)
7 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
7 years ago
6 years ago
$time = (time() - intval($onlinetime));
7 years ago
6 years ago
$sql = @$AVE_DB->Query("SELECT * FROM " . PREFIX . "_users WHERE last_visit > " . $time . " ORDER BY last_visit DESC");
7 years ago
6 years ago
$online_users = array();
7 years ago
7 years ago
while ($row = $sql->FetchRow())
{
$row->user_name = get_username_by_id($row->Id);
$row->user_group_name = get_usergroup_by_id($row->user_group);
array_push($online_users,$row);
}
7 years ago
7 years ago
$AVE_Template->assign('online_users', $online_users);
7 years ago
}
7 years ago
7 years ago
/**
* Форматированный вывод размера
*
* @param int $file_size размер
* @return string нормированный размер с единицой измерения
*/
function format_size($file_size)
7 years ago
{
7 years ago
if ($file_size >= 1073741824)
$file_size = round($file_size / 1073741824 * 100) / 100 . ' Gb';
elseif ($file_size >= 1048576)
$file_size = round($file_size / 1048576 * 100) / 100 . ' Mb';
elseif ($file_size >= 1024)
$file_size = round($file_size / 1024 * 100) / 100 . ' Kb';
else
$file_size = $file_size . ' b';
return $file_size;
7 years ago
}
6 years ago
7 years ago
/**
* Извлечение из БД статистики по основным компонентам системы
*
*/
function get_ave_info()
7 years ago
{
7 years ago
global $AVE_DB, $AVE_Template;
$cnts = array();
$cnts['templates'] = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_templates")->GetCell();
7 years ago
$cnts['request'] = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_request")->GetCell();
$cnts['rubrics'] = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_rubrics")->GetCell();
7 years ago
$sql = $AVE_DB->Query("
SELECT
`ModuleStatus`,
COUNT(`ModuleStatus`) AS cntStatus
7 years ago
FROM
" . PREFIX . "_module
7 years ago
GROUP BY `ModuleStatus`
");
7 years ago
7 years ago
while ($row = $sql->FetchRow())
$cnts['modules_' . $row->ModuleStatus] = $row->cntStatus;
$sql = $AVE_DB->Query("
SELECT
status,
COUNT(status) AS cntStatus
7 years ago
FROM
" . PREFIX . "_users
7 years ago
GROUP BY status
");
7 years ago
7 years ago
while ($row = $sql->FetchRow())
$cnts['users_' . $row->status] = $row->cntStatus;
$AVE_Template->assign('cnts', $cnts);
7 years ago
}
7 years ago
function countDocuments($rubric_id = null)
{
global $AVE_DB;
if (is_numeric($rubric_id) && $rubric_id > 0)
$count = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_documents WHERE rubric_id = '".$rubric_id."'")->GetCell();
else
$count = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_documents")->GetCell();
echo $count;
}
7 years ago
/**
* Размер дириктории
*
* @param string $directory наименование директории
* @return int
*/
function get_dir_size($directory)
7 years ago
{
6 years ago
if (! is_dir($directory))
return -1;
7 years ago
7 years ago
$size = 0;
7 years ago
7 years ago
if ($DIR = opendir($directory))
7 years ago
{
7 years ago
while (($dirfile = readdir($DIR)) !== false)
7 years ago
{
7 years ago
if (@is_link($directory . '/' . $dirfile) || $dirfile == '.' || $dirfile == '..')
continue;
7 years ago
if (@is_file($directory . '/' . $dirfile))
7 years ago
{
7 years ago
$size += filesize($directory . '/' . $dirfile);
7 years ago
}
7 years ago
elseif (@is_dir($directory . '/' . $dirfile))
7 years ago
{
7 years ago
$dirSize = get_dir_size($directory . '/' . $dirfile);
7 years ago
7 years ago
if ($dirSize >= 0)
$size += $dirSize;
else
return -1;
7 years ago
}
}
7 years ago
7 years ago
closedir($DIR);
7 years ago
}
7 years ago
return $size;
7 years ago
}
7 years ago
7 years ago
/**
* Размер базы данных
*
* @return int
*/
function get_mysql_size()
7 years ago
{
7 years ago
global $AVE_DB;
$mysql_size = 0;
7 years ago
7 years ago
$sql = $AVE_DB->Query("SHOW TABLE STATUS LIKE '" . PREFIX . "_%'");
7 years ago
7 years ago
while ($row = $sql->FetchAssocArray())
$mysql_size += $row['Data_length'] + $row['Index_length'];
return format_size($mysql_size);
7 years ago
}
7 years ago
function get_ave_tags($srcfile)
7 years ago
{
7 years ago
if (@include_once($srcfile))
7 years ago
{
7 years ago
reset ($vorlage);
$vl = array();
while (list($key, $value) = each($vorlage))
{
$tag = new stdClass;
$tag->cp_tag = $key;
$tag->cp_desc = $value;
array_push($vl, $tag);
unset($tag);
}
return $vl;
7 years ago
}
7 years ago
return null;
7 years ago
}
7 years ago
function get_all_templates()
{
global $AVE_DB;
static $templates = null;
if ($templates == null)
{
$templates = array();
$sql = $AVE_DB->Query("
SELECT
Id,
template_title
FROM " . PREFIX . "_templates
");
while ($row = $sql->FetchRow())
{
array_push($templates, $row);
}
}
7 years ago
7 years ago
return $templates;
}
7 years ago
7 years ago
function getInstaledModules()
7 years ago
{
7 years ago
global $AVE_DB, $AVE_Template, $AVE_Module;
7 years ago
7 years ago
$modules = $AVE_Module->_modules;
7 years ago
7 years ago
$modules_instaled = array();
foreach ($modules AS $module)
7 years ago
{
7 years ago
if ($module['ModuleAdminEdit'] == 1 && $module['ModuleStatus'])
7 years ago
$modules_instaled[] = array(
'ModuleName' => $module['ModuleName'],
'ModuleSysName' => $module['ModuleSysName']
);
7 years ago
}
7 years ago
unset ($modules);
$AVE_Template->assign('modules', $modules_instaled);
7 years ago
}
7 years ago
function get_mime_type($file)
7 years ago
{
7 years ago
$file_extension = strtolower(mb_substr(strrchr($file, '.'), 1));
switch ($file_extension)
7 years ago
{
7 years ago
case 'psd': $ctype = 'image/x-photoshop'; break;
case 'rar': $ctype = 'application/x-rar-compressed'; break;
case 'zip': $ctype = 'application/x-zip-compressed'; break;
case 'pdf': $ctype = 'application/pdf'; break;
case 'bz2': $ctype = 'application/bzip2'; break;
case 'doc':
case 'dot':
case 'wiz':
case 'wzs': $ctype = 'application/msword'; break;
case 'eps': $ctype = 'application/postscript'; break;
case 'pot':
case 'ppa':
case 'pps':
case 'ppt':
case 'pwz': $ctype = 'application/vnd.ms-powerpoint'; break;
case 'rtf': $ctype = 'application/rtf'; break;
case 'rnx': $ctype = 'application/vnd.rn-realmedia'; break;
case 'hlp': $ctype = 'hlp'; break;
case 'gtar': $ctype = 'application/x-gtar'; break;
case 'gzip':
case 'tgz': $ctype = 'application/x-gzip'; break;
case 'lnx': $ctype = 'application/x-latex'; break;
case 'exe': $ctype = 'application/x-msdownload'; break;
case 'swf': $ctype = 'application/x-shockwafe-flash'; break;
case 'xml': $ctype = 'application/xml'; break;
case 'midi': $ctype = 'audio/midi'; break;
case 'mp3':
case 'mp2':
case 'mpga': $ctype = 'audio/mpeg'; break;
case 'wav': $ctype = 'audio/wav'; break;
case 'bmp': $ctype = 'audio/wav'; break;
case 'gif': $ctype = 'image/gif'; break;
case 'jpeg':
case 'jpg':
case 'jpe': $ctype = 'image/jpeg'; break;
case 'png': $ctype = 'image/png'; break;
case 'tif':
case 'tiff': $ctype = 'image/tiff'; break;
case 'ico': $ctype = 'image/x-icon'; break;
case 'csv': $ctype = 'text/comma-separated-values'; break;
case 'css': $ctype = 'text/css'; break;
case 'htm':
case 'html':
case 'shtml': $ctype = 'text/html'; break;
case 'txt':
case 'klp':
case 'tex':
case 'php':
case 'asp':
case 'aspx':
case 'php3':
case 'php4':
case 'php5':
case 'sql': $ctype = 'text/plain'; break;
case 'xml': $ctype = 'text/xml'; break;
case 'xhtm': $ctype = 'text/xhtml'; break;
case 'wml': $ctype = 'text/wml'; break;
case 'mpeg':
case 'mpg':
case 'mpe':
case 'mlv':
case 'mpa':
case 'wma':
case 'wmv': $ctype = 'video/mpeg'; break;
case 'avi': $ctype = 'video/x-msvideo'; break;
case 'mov': $ctype = 'video/quicktime'; break;
case 'xls': $ctype = 'application/vnd.ms-excel'; break;
case 'ai': $ctype = 'application/postscript'; break;
case 'rm': $ctype = 'application/vnd.rn-realmedia'; break;
case 'gz': $ctype = 'application/x-gzip'; break;
case 'js': $ctype = 'application/x-javascript'; break;
case 'pl':
case 'cc': $ctype = 'text/plain'; break;
case 'qt': $ctype = 'video/quicktime'; break;
default : $ctype='application/force-download';
7 years ago
}
7 years ago
return $ctype;
}
7 years ago
7 years ago
function file_download($filename, $retbytes = true)
7 years ago
{
6 years ago
$chunksize = 1 * (1024 * 1024);
7 years ago
$buffer = '';
$cnt = 0;
7 years ago
7 years ago
$handle = fopen($filename, 'rb');
7 years ago
7 years ago
if ($handle === false)
return false;
7 years ago
6 years ago
while (! feof($handle))
7 years ago
{
$buffer = fread($handle, $chunksize);
7 years ago
7 years ago
echo $buffer;
7 years ago
7 years ago
flush();
7 years ago
if ($retbytes)
$cnt += strlen($buffer);
7 years ago
}
7 years ago
7 years ago
$status = fclose($handle);
7 years ago
6 years ago
if ($retbytes && $status)
return $cnt;
7 years ago
7 years ago
return $status;
7 years ago
}
7 years ago
function is_php_code($check_code)
{
$check_code = stripslashes($check_code);
$check_code = str_replace(' ', '', $check_code);
$check_code = strtolower($check_code);
if (strpos($check_code, '<?php') !== false ||
strpos($check_code, '<?') !== false ||
strpos($check_code, '<? ') !== false ||
strpos($check_code, '<?=') !== false ||
strpos($check_code, '<script language="php">') !== false ||
strpos($check_code, 'language="php"') !== false ||
strpos($check_code, "language='php'") !== false ||
strpos($check_code, 'language=php') !== false)
{
return true;
}
7 years ago
7 years ago
return false;
}
7 years ago
7 years ago
function check_permission_acp($perm)
7 years ago
{
7 years ago
if (! check_permission($perm))
{
if (! defined('NOPERM'))
define('NOPERM', 1);
return false;
}
7 years ago
return true;
}
7 years ago
//Проверка на наличие модуля Контакты и новых писем
6 years ago
function ContactsModuleCheck()
{
7 years ago
global $AVE_DB, $AVE_Template;
7 years ago
7 years ago
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module WHERE ModuleFunction = 'contact' and ModuleStatus = '1'");
6 years ago
$enable = $sql->NumRows();
if ($enable != "0" || $enable != "")
{
7 years ago
$contacts = "1";
$sql_num = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_modul_contact_info WHERE Aw_Zeit = '0'");
6 years ago
$num_posts = $sql_num->NumRows();
}
else
{
7 years ago
$contacts = "0";
}
$AVE_Template->assign('num_posts', $num_posts);
$AVE_Template->assign('contacts', $contacts);
7 years ago
}
7 years ago
//Проверка на наличие модуля Логин
6 years ago
function LoginModuleCheck()
{
7 years ago
global $AVE_DB, $AVE_Template;
6 years ago
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_module WHERE ModuleFunction = 'mod_login' and ModuleStatus = '1'");
$enable = $sql->NumRows();
if ($enable != '0' || $enable != '')
$login_menu = '1';
else
$login_menu = '0';
7 years ago
$AVE_Template->assign('login_menu', $login_menu);
}
7 years ago
6 years ago
/**
* Выводим на главную список последних 15 документов
*/
7 years ago
function DisplayMainDocuments()
{
global $AVE_DB, $AVE_Template;
7 years ago
7 years ago
$doc_start = array();
7 years ago
7 years ago
$sql = $AVE_DB->Query("
SELECT
doc.*,
rub.rubric_admin_teaser_template
FROM " . PREFIX . "_documents doc
LEFT JOIN " . PREFIX . "_rubrics AS rub ON rub.Id = doc.rubric_id
WHERE 1 = 1
AND rub.rubric_docs_active = '1'
ORDER BY doc.document_published DESC LIMIT 0,10");
6 years ago
while($row = $sql->FetchRow()) {
7 years ago
$row->rubric_title = showrubricName($row->rubric_id);
$row->document_title = stripslashes(htmlspecialchars_decode(pretty_chars($row->document_title)));
$row->document_breadcrum_title = stripslashes(htmlspecialchars_decode(pretty_chars($row->document_breadcrum_title)));
$row->document_author = get_username_by_id($row->document_author_id); // Получаем имя пользователя (Автора)
$row->cantEdit = 0;
6 years ago
$row->canDelete = 0;
$row->canEndDel = 0;
7 years ago
$row->canOpenClose = 0;
7 years ago
$row->rubric_admin_teaser_template = @eval2var(' ?>'.($row->rubric_admin_teaser_template > ''
? @showrequestelement($row, $row->rubric_admin_teaser_template)
6 years ago
: '') . '<?'.'php ');
7 years ago
// разрешаем редактирование и удаление
// если автор имеет право изменять свои документы в рубрике
// или пользователю разрешено изменять все документы в рубрике
6 years ago
if (($row->document_author_id == @$_SESSION['user_id']
7 years ago
&& isset($_SESSION[$row->rubric_id . '_editown']) && @$_SESSION[$row->rubric_id . '_editown'] == 1)
6 years ago
|| (isset($_SESSION[$row->rubric_id . '_editall']) && $_SESSION[$row->rubric_id . '_editall'] == 1))
7 years ago
{
$row->cantEdit = 1;
$row->canDelete = 1;
}
// запрещаем редактирование главной страницы и страницу ошибки 404 если требуется одобрение Администратора
6 years ago
if (($row->Id == 1 || $row->Id == PAGE_NOT_FOUND_ID)
7 years ago
&& isset($_SESSION[$row->rubric_id . '_newnow']) && @$_SESSION[$row->rubric_id . '_newnow'] != 1)
{
$row->cantEdit = 0;
}
// разрешаем автору блокировать и разблокировать свои документы если не требуется одобрение Администратора
if ($row->document_author_id == @$_SESSION['user_id']
&& isset($_SESSION[$row->rubric_id . '_newnow']) && @$_SESSION[$row->rubric_id . '_newnow'] == 1)
{
$row->canOpenClose = 1;
}
// разрешаем всё, если пользователь принадлежит группе Администраторов или имеет все права на рубрику
if (UGROUP == 1 || @$_SESSION[$row->rubric_id . '_alles'] == 1)
{
$row->cantEdit = 1;
$row->canDelete = 1;
$row->canEndDel = 1;
$row->canOpenClose = 1;
}
// Запрещаем удаление Главной страницы и страницы с 404 ошибкой
if ($row->Id == 1 || $row->Id == PAGE_NOT_FOUND_ID)
{
$row->canDelete = 0;
$row->canEndDel = 0;
}
array_push($doc_start, $row);
}
$AVE_Template->assign('doc_start', $doc_start);
}
7 years ago
6 years ago
/**
* @param $id
*
* @return mixed
*/
7 years ago
function showrubricName($id)
{
7 years ago
global $AVE_DB;
7 years ago
6 years ago
$sql = $AVE_DB->Query("SELECT rubric_title FROM " . PREFIX . "_rubrics WHERE Id = '$id'");
$row = $sql->FetchRow();
7 years ago
return $row->rubric_title;
}
7 years ago
6 years ago
/**
* @param $id
*
* @return mixed
*/
7 years ago
function showuserName($id)
{
7 years ago
global $AVE_DB;
7 years ago
6 years ago
$sql = $AVE_DB->Query("SELECT user_name FROM " . PREFIX . "_users WHERE Id = '$id'");
$row = $sql->FetchRow();
7 years ago
return $row->user_name;
}
7 years ago
6 years ago
/**
*
*/
7 years ago
function cacheShow()
{
global $AVE_Template;
7 years ago
7 years ago
$showCache = format_size(get_dir_size($AVE_Template->cache_dir_root));
6 years ago
7 years ago
echo json_encode(array($showCache, 'accept'));
}
7 years ago
7 years ago
6 years ago
/**
* @param $id
*
* @return mixed
*/
7 years ago
function templateName($id)
{
7 years ago
global $AVE_DB;
7 years ago
7 years ago
$sql = $AVE_DB->Query("
6 years ago
SELECT
*
FROM
" . PREFIX . "_templates
WHERE
Id = '$id'
");
$row = $sql->FetchRow();
7 years ago
return $row->template_title;
}
6 years ago
/**
* @param $id
*
* @return mixed
*/
7 years ago
function groupName($id)
{
7 years ago
global $AVE_DB;
7 years ago
$sql = $AVE_DB->Query("
6 years ago
SELECT
*
FROM
" . PREFIX . "_user_groups
WHERE
user_group = '$id'
");
$row = $sql->FetchRow();
7 years ago
7 years ago
return $row->user_group_name;
}
7 years ago
?>