<?PHP

/* ====================
Seditio - Website engine
Copyright Neocrome
http://www.neocrome.net
[BEGIN_SED]
File=system/functions.admin.php
Version=101
Updated=2006-mar-15
Type=Core
Author=Neocrome
Description=Functions
[END_SED]
==================== */

if (!defined('SED_CODE') || !defined('SED_ADMIN')) { die('Wrong URL.'); }

/* ======== Defaulting the admin variables ========= */

unset($adminmain, $adminhelp, $admin_icon, $plugin_body, $plugin_title, $plugin_help);
$adminpath = array();
$cfgmap = sed_loadconfigmap();

/* ------------------ */

function sed_auth_getvalue($mask)
	{
	$mn['0'] = 0;
	$mn['R'] = 1;
	$mn['W'] = 2;
	$mn['1'] = 4;
	$mn['2'] = 8;
	$mn['3'] = 16;
	$mn['4'] = 32;
	$mn['5'] = 64;
	$mn['A'] = 128;

	$masks = str_split($mask);

	foreach($mn as $k => $v)
		{
		if (in_array($k, $masks))
			{ $res += $mn[$k]; }
		}
	return($res);
	}

/* ------------------ */

function sed_auth_reorder()
	{
	global $db_auth;

	$sql = sed_sql_query("ALTER TABLE $db_auth ORDER BY auth_code ASC, auth_option ASC, auth_groupid ASC, auth_code ASC");
	return(TRUE);
	}

/* ------------------ */

function sed_build_admrights($rn)
	{
	$res = ($rn & 1) ? 'R' : '';
	$res .= (($rn & 2)==2) ? 'W' : '';
	$res .= (($rn & 4)==4) ? '1' : '';
	$res .= (($rn & 8)==8) ? '2' : '';
	$res .= (($rn & 16)==16) ? '3' : '';
	$res .= (($rn & 32)==32) ? '4' : '';
	$res .= (($rn & 64)==64) ? '5' : '';
	$res .= (($rn & 128)==128) ? 'A' : '';
	return($res);
	}

/* ------------------ */

function sed_build_adminsection($adminpath)
	{
	global $cfg, $L;

	$result = array();
	$result[] = "<a href=\"admin.php\">".$L['Adminpanel']."</a>";
	foreach($adminpath as $i => $k)
		{ $result[] = "<a href=\"".$k[0]."\">".$k[1]."</a>"; }
		$result = implode(" ".$cfg['separator']." ", $result);

	return($result);
	}

/* ------------------ */

function sed_forum_deletesection($id)
	{
	global $db_forum_topics, $db_forum_posts, $db_forum_sections, $db_auth;

	$sql = sed_sql_query("DELETE FROM $db_forum_posts WHERE fp_sectionid='$id'");
	$num = sed_sql_affectedrows();
	$sql = sed_sql_query("DELETE FROM $db_forum_topics WHERE ft_sectionid='$id'");
	$num = $num + sed_sql_affectedrows();
	$sql = sed_sql_query("DELETE FROM $db_forum_sections WHERE fs_id='$id'");
	$num = $num + sed_sql_affectedrows();
	$sql = sed_sql_query("DELETE FROM $db_auth WHERE auth_code='forums' AND auth_option='$id'");
	$num = $num + sed_sql_affectedrows();
	return($num);
	}

/* ------------------ */

function sed_forum_resync($id)
	{
	global $db_forum_topics, $db_forum_posts, $db_forum_sections;

	$sql = sed_sql_query("SELECT COUNT(*) FROM $db_forum_topics WHERE ft_sectionid='$id'");
	$num = sed_sql_result($sql,0,"COUNT(*)");
	$sql = sed_sql_query("UPDATE $db_forum_sections SET fs_topiccount='$num' WHERE fs_id='$id'");
	$sql = sed_sql_query("SELECT COUNT(*) FROM $db_forum_posts WHERE fp_sectionid='$id'");
	$num = sed_sql_result($sql, 0, "COUNT(*)");
	$sql = sed_sql_query("UPDATE $db_forum_sections SET fs_postcount='$num' WHERE fs_id='$id'");
	return;
	}

/* ------------------ */

function sed_forum_resyncall()
	{
	global $db_forum_sections;

	$sql = sed_sql_query("SELECT fs_id FROM $db_forum_sections");
	while ($row = sed_sql_fetcharray($sql))
		{ sed_forum_resync($row['fs_id']); }
	return;
	}

/* ------------------ */

function sed_linkif($url, $text, $cond)
	{
	if ($cond)
		{ $res = "<a href=\"".$url."\">".$text."</a>"; }
	else
		{ $res = $text; }

	return($res);
	}

/* ------------------ */

function sed_loadcharsets()
	{
	$result = array();
	$result[] = array('ISO-10646-UTF-1', 'ISO-10646-UTF-1 / Universal Transfer Format');
	$result[] = array('UTF-8','UTF-8 / Standard Unicode');
	$result[] = array('ISO-8859-1', 'ISO-8859-1 / Western Europe');
	$result[] = array('ISO-8859-2', 'ISO-8859-2 / Middle Europe');
	$result[] = array('ISO-8859-3', 'ISO-8859-3 / Maltese');
	$result[] = array('ISO-8859-4', 'ISO-8859-4 / Baltic');
	$result[] = array('ISO-8859-5', 'ISO-8859-5 / Cyrillic');
	$result[] = array('ISO-8859-6', 'ISO-8859-6 / Arabic');
	$result[] = array('ISO-8859-7', 'ISO-8859-7 / Greek');
	$result[] = array('ISO-8859-8', 'ISO-8859-8 / Hebrew');
	$result[] = array('ISO-8859-9', 'ISO-8859-9 / Turkish');
	$result[] = array('ISO-2022-KR', 'ISO-2022-KR / Korean');
	$result[] = array('ISO-2022-JP', 'ISO-2022-JP / Japanese');
	$result[] = array('windows-1250', 'windows-1250 / Central European');
	$result[] = array('windows-1251', 'windows-1251 / Russian');
	$result[] = array('windows-1252', 'windows-1252 / Western Europe');
	$result[] = array('windows-1254', 'windows-1254 / Turkish');
	$result[] = array('EUC-JP', 'EUC-JP / Japanese');
	$result[] = array('GB2312', 'GB2312 / Chinese simplified');
	$result[] = array('BIG5', 'BIG5 / Chinese traditional');
	$result[] = array('tis-620', 'Tis-620 / Thai');
	return($result);
	}

/* ------------------ */

function sed_loadconfigmap()
	{
$result = array();
$result[] = array ('main', '01', 'maintitle', 1, 'Title of your site', '');
$result[] = array ('main', '02', 'subtitle', 1, 'Subtitle', '');
$result[] = array ('main', '03', 'mainurl', 1, 'http://www.yourdomain.com', '');
$result[] = array ('main', '04', 'adminemail', 1, 'admin@mysite.com', '');
$result[] = array ('main', '05', 'hostip', 1, '999.999.999.999', '');
$result[] = array ('main', '06', 'cache', 3, '1', '');
$result[] = array ('main', '06', 'gzip', 3, '1', '');
$result[] = array ('main', '07', 'devmode', 3, '0', '');
$result[] = array ('main', '10', 'cookiedomain', 1, '', '');
$result[] = array ('main', '10', 'cookiepath', 1, '', '');
$result[] = array ('main', '10', 'cookielifetime', 2, '5184000', array(1800,3600,7200,14400,28800,43200,86400,172800, 259200,604800,1296000,2592000,5184000));
$result[] = array ('main', '12', 'disablehitstats', 3, '0', '');
$result[] = array ('main', '20', 'shieldenabled', 3, '0', '');
$result[] = array ('main', '20', 'shieldtadjust', 2, '100', array(10,25,50,75,100,125,150,200,300,400,600,800));
$result[] = array ('main', '20', 'shieldzhammer', 2, '25', array(5,10,15,20,25,30,40,50,100));
$result[] = array ('time', '11', 'dateformat', 1, 'Y-m-d H:i', '');
$result[] = array ('time', '11', 'formatmonthday', 1, 'm-d', '');
$result[] = array ('time', '11', 'formatyearmonthday', 1, 'Y-m-d', '');
$result[] = array ('time', '11', 'formatmonthdayhourmin', 1, 'm-d H:i', '');
$result[] = array ('time', '11', 'servertimezone', 1, '0', '');
$result[] = array ('time', '12', 'defaulttimezone', 1, '0', '');
$result[] = array ('time', '14', 'timedout', 2, '1200', array(30,60,120,300,600,900,1200,1800,2400,3600));
$result[] = array ('skin', '02', 'forcedefaultskin', 3, '0', '');
$result[] = array ('skin', '04', 'doctypeid', 4, '4', '');
$result[] = array ('skin', '06', 'charset', 4, 'ISO-8859-1', '');
$result[] = array ('skin', '08', 'metakeywords', 1, '', '');
$result[] = array ('skin', '08', 'separator', 1, '/', '');
$result[] = array ('skin', '10', 'newwindows', 3, '1', '');
$result[] = array ('skin', '15', 'disablesysinfos', 3, '1', '');
$result[] = array ('skin', '15', 'keepcrbottom', 3, '1', '');
$result[] = array ('skin', '15', 'showsqlstats', 3, '0', '');
$result[] = array ('lang', '10', 'forcedefaultlang', 3, '0',  '');
$result[] = array ('menus', '10', 'topline', 0, '', '');
$result[] = array ('menus', '10', 'banner', 0, '', '');
$result[] = array ('menus', '10', 'motd', 0, '', '');
$result[] = array ('menus', '10', 'bottomline', 0, '', '');
$result[] = array ('menus', '15', 'menu1', 0, '<ul>\n<li><a href="index.php">Home</a></li>\n<li><a href="forums.php">Forums</a></li>\n<li><a href="list.php?c=articles">Articles</a></li>\n<li><a href="plug.php?e=search">Search</a></li>\n</ul>', '');
$result[] = array ('menus', '15', 'menu2', 0, '',  '');
$result[] = array ('menus', '15', 'menu3', 0, '', '');
$result[] = array ('menus', '15', 'menu4', 0, '', '');
$result[] = array ('menus', '15', 'menu5', 0, '', '');
$result[] = array ('menus', '15', 'menu6', 0, '', '');
$result[] = array ('menus', '15', 'menu7', 0, '', '');
$result[] = array ('menus', '15', 'menu8', 0, '', '');
$result[] = array ('menus', '15', 'menu9', 0, '', '');
$result[] = array ('menus', '20', 'freetext1', 0, '', '');
$result[] = array ('menus', '20', 'freetext2', 0, '', '');
$result[] = array ('menus', '20', 'freetext3', 0, '', '');
$result[] = array ('menus', '20', 'freetext4', 0, '', '');
$result[] = array ('menus', '20', 'freetext5', 0, '', '');
$result[] = array ('menus', '20', 'freetext6', 0, '', '');
$result[] = array ('menus', '20', 'freetext7', 0, '', '');
$result[] = array ('menus', '20', 'freetext8', 0, '', '');
$result[] = array ('menus', '20', 'freetext9', 0, '', '');
$result[] = array ('comments', '01', 'disable_comments', 3, '0', '');
$result[] = array ('comments', '10', 'countcomments', 3, '1', '');
$result[] = array ('comments', '20', 'parsebbcodecom', 3, '1', '');
$result[] = array ('comments', '20', 'parsesmiliescom', 3, '1', '');
$result[] = array ('forums', '01', 'disable_forums', 3, '0', '');
$result[] = array ('forums', '10', 'hideprivateforums', 3, '0', '');
$result[] = array ('forums', '10', 'hottopictrigger', 2, '20', array(5,10,15,20,25,30,35,40,50));
$result[] = array ('forums', '10', 'maxtopicsperpage', 2, '30', array(5,10,15,20,25,30,35,40,45,50,60,70,80,90));
$result[] = array ('forums', '12', 'antibumpforums', 3, '0', '');
$result[] = array ('forums', '20', 'parsebbcodeforums', 3, '1', '');
$result[] = array ('forums', '20', 'parsesmiliesforums', 3, '1', '');
$result[] = array ('page', '01', 'disable_page', 3, '0', '');
$result[] = array ('page', '02', 'allowphp_pages', 3, '0', '');
$result[] = array ('page', '05', 'maxrowsperpage', 2, '15', array(5,10,15,20,25,30,35,40,45,50,60,70,80,90));
$result[] = array ('page', '20', 'parsebbcodepages', 3, '1', '');
$result[] = array ('page', '20', 'parsesmiliespages', 3, '0', '');
$result[] = array ('pfs', '01', 'disable_pfs', 3, '0', '');
$result[] = array ('pfs', '02', 'pfsuserfolder', 3, '0', '');
$result[] = array ('pfs', '10', 'th_amode', 2, 'GD2', array('Disabled','GD1','GD2'));
$result[] = array ('pfs', '10', 'th_x', 2, '112', '');
$result[] = array ('pfs', '10', 'th_y', 2, '84', '');
$result[] = array ('pfs', '10', 'th_border', 2, '4', '');
$result[] = array ('pfs', '10', 'th_keepratio', 3, '1', '');
$result[] = array ('pfs', '10', 'th_jpeg_quality', 2, '85', array(0,5,10,20,30,40,50,60,70,75,80,85,90,95,100));
$result[] = array ('pfs', '10', 'th_colorbg', 2, '000000', '');
$result[] = array ('pfs', '10', 'th_colortext', 2, 'FFFFFF', '');
$result[] = array ('pfs', '10', 'th_textsize', 2, '1', array(0,1,2,3,4,5));
$result[] = array ('plug', '01', 'disable_plug', 3, '0', '');
$result[] = array ('pm', '01', 'disable_pm', 3, '0', '');
$result[] = array ('pm', '10', 'pm_maxsize', 2, '10000', array(200,500,1000,2000, 5000,10000,15000,20000,30000,50000,65000));
$result[] = array ('pm', '10', 'pm_allownotifications', 3, '1', '');
$result[] = array ('pm', '12', 'keepoldpms', 3, '0', '');
$result[] = array ('polls', '01', 'disable_polls', 3, '0', '');
$result[] = array ('ratings', '01', 'disable_ratings', 3, '0', '');
$result[] = array ('users', '01', 'disablereg', 3, '0', '');
$result[] = array ('users', '03', 'disablewhosonline', 3, '0', '');
$result[] = array ('users', '05', 'maxusersperpage', 2, '50', array(5,10,15,20,25,30,35,40,45,50,75,100,150,200));
$result[] = array ('users', '07', 'regrequireadmin', 3, '0',  '');
$result[] = array ('users', '10', 'regnoactivation', 3, '0', '');
$result[] = array ('users', '10', 'useremailchange', 3, '0', '');
$result[] = array ('users', '10', 'usertextimg', 3, '0', '');
$result[] = array ('users', '11', 'parsebbcodeusertext', 3, '1', '');
$result[] = array ('users', '11', 'parsesmiliesusertext', 3, '0', '');
$result[] = array ('users', '12', 'av_maxsize', 2, '8000', '');
$result[] = array ('users', '12', 'av_maxx', 2, '64', '');
$result[] = array ('users', '12', 'av_maxy', 2, '64', '');
$result[] = array ('users', '12', 'usertextmax', 2, '300', '');
$result[] = array ('users', '13', 'sig_maxsize', 2, '32000', '');
$result[] = array ('users', '13', 'sig_maxx', 2, '550', '');
$result[] = array ('users', '13', 'sig_maxy', 2, '100', '');
$result[] = array ('users', '14', 'ph_maxsize', 2, '32000', '');
$result[] = array ('users', '14', 'ph_maxx', 2, '128', '');
$result[] = array ('users', '14', 'ph_maxy', 2, '128', '');
$result[] = array ('users', '20', 'extra1title', 1, 'Real name', '');
$result[] = array ('users', '20', 'extra2title', 1, 'Title', '');
$result[] = array ('users', '20', 'extra3title', 1, '', '');
$result[] = array ('users', '20', 'extra4title', 1, '', '');
$result[] = array ('users', '20', 'extra5title', 1, '', '');
$result[] = array ('users', '20', 'extra6title', 1, '', '');
$result[] = array ('users', '20', 'extra7title', 1, '', '');
$result[] = array ('users', '20', 'extra8title', 1, '', '');
$result[] = array ('users', '20', 'extra9title', 1, '', '');
$result[] = array ('users', '20', 'extra1tsetting', 2, '255', array(0,1,8,16,32,64,128,255));
$result[] = array ('users', '20', 'extra2tsetting', 2, '255', array(0,1,8,16,32,64,128,255));
$result[] = array ('users', '20', 'extra3tsetting', 2, '255', array(0,1,8,16,32,64,128,255));
$result[] = array ('users', '20', 'extra4tsetting', 2, '255', array(0,1,8,16,32,64,128,255));
$result[] = array ('users', '20', 'extra5tsetting', 2, '255', array(0,1,8,16,32,64,128,255));
$result[] = array ('users', '20', 'extra6tsetting', 1, '', '');
$result[] = array ('users', '20', 'extra7tsetting', 1, '', '');
$result[] = array ('users', '20', 'extra8tsetting', 1, '', '');
$result[] = array ('users', '20', 'extra9tsetting', 1, '', '');
$result[] = array ('users', '20', 'extra1uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra2uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra3uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra4uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra5uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra6uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra7uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra8uchange', 3, '0', '');
$result[] = array ('users', '20', 'extra9uchange', 3, '0', '');

	return($result);
	}

/* ------------------ */

function sed_loaddoctypes()
	{
	$result = array();
	$result[] = array(0,'HTML 4.01');
	$result[] = array(1,'HTML 4.01 Transitional');
	$result[] = array(2,'HTML 4.01 Frameset');
	$result[] = array(3,'XHTML 1.0 Strict');
	$result[] = array(4,'XHTML 1.0 Transitional');
	$result[] = array(5,'XHTML 1.0 Frameset');
	$result[] = array(6,'XHTML 1.1');
	$result[] = array(7,'XHTML 2');
	return($result);
	}

?>