<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

include_once('auth.php');
include_once( dirname(__FILE__) . "/../include/class.MenuBlocks.php" );

// detect which menu items should be disabled

$id = db_query("select * from admin");
$admin = db_fetch_array($id);

$loUser = new SQLString($PHP_AUTH_USER);
$id = safe_query2( "SELECT * FROM kunden WHERE kunde = ?", $loUser);
$kunde = db_fetch_array($id);

$loRes = new SQLString($kunde["anbieter"]);
$id = safe_query2( "SELECT * FROM anbieter WHERE anbieter = ?", $loRes );
$reseller = db_fetch_array($id);

$items_enabled['general']['statistik'] = ($kunde['statistik'] && $admin['statistik']);

$id = safe_query2( "SELECT domain FROM domains WHERE frontpage=1 and kunde=?", $loUser);
$items_enabled['general']['frontpage'] = ($admin['frontpage'] && db_num_rows($id) > 0);

// The $noemail flag means if any email/pop3 are allowed to user or already created by user
$noemail = false;
if (($admin["email"] == 0) || ($kunde["maxemail"] == 0)) {
	$id = safe_query2( "SELECT COUNT(kunde) AS email FROM email WHERE kunde = ?", $loUser);
	$werte = db_fetch_array($id);
	if ($werte["email"] == 0) {
		$id = safe_query2( "SELECT COUNT(kunde) AS pop3 FROM pop3 WHERE kunde = ?", $loUser);
		$werte = db_fetch_array($id);
		if ($werte["pop3"] == 0)	{
			$noemail = true;
		}
	}	
}

// If no email/pop3 are created/allowed to create, then there no sense in 
// email/pop3/autoresponder menus (nothing to operate with)
$items_enabled['email']['pop3'] = !$noemail;
$items_enabled['email']['email'] = !$noemail;

$items_enabled['email']['autoresponder'] = !$noemail 
	&& ($admin["autoresponder"] && $kunde['maxautoresponder'] != 0);

// mailing lists do not require any email/pop3 to be functioning -> do not use $noemail
$items_enabled['email']['maillist'] = ($admin["majordomo"] && $kunde['maxmaillist'] != 0);

$nodb = false;
if (($admin["mysql"] == 0) || ($kunde["maxmysql"] == 0)){
	$id = safe_query2( "SELECT kunde FROM mysql_datenbanken WHERE kunde = ?", $loUser);
	if (db_num_rows($id) < 1){
		$nodb = true;
	}
}

$items_enabled['db']['mysql'] = !$nodb;
$items_enabled['db']['phpmyadmin'] = !$nodb && $admin['phpmyadmin'];
$phpmyadmin_path = $admin['phpmyadminpfad'];

$items_enabled['tools']['webftp']  	= ($kunde['webftp'] == 1);
$items_enabled['tools']['webmail'] 	= ($kunde['webmail'] == 1);
$items_enabled['tools']['cgicheck'] 	= ($kunde['perl'] == 1 || $kunde['perl'] == 2);
$items_enabled['tools']['atdomains'] = ($kunde['maxatdomains'] != 0);
$items_enabled['tools']['pwschutz'] 	= ($kunde['pwschutz'] == 1);
$items_enabled['tools']['ftpusers'] 	= ($kunde['maxftp'] != 0);
$items_enabled['tools']['errordocs'] = ($kunde['fehlerseiten'] == 1);
$items_enabled['tools']['cron']      = ($kunde['maxcronjobs'] != 0);
$items_enabled['tools']['idn']       = 0;

if(isset($GLOBALS["backup_off"])) $items_enabled['tools']['backup'] = !$GLOBALS["backup_off"];
else $items_enabled['tools']['backup'] = 1;

$items_enabled['general']['changepw'] = $items_enabled['general']['select_language'] = ($PHP_AUTH_USER != ($user_prefix . '0'));

/*
 * $items_enabled[], $phpmyadmin_path => page 
 */

// start menu generation

$c_general = array(
	$gui->make_menu_item('overview', 
		ltext('m_overview'), 
		$gui->make_menu_target_int("allgemein_start.php")
	),
	$gui->make_menu_item('changepw', 
		ltext('ma_changepw'), 
		$gui->make_menu_target_int("allgemein_pwaendern.php", "alpw_desc1", "alpw_desc2"),
		$items_enabled['general']['changepw']
	),
	$gui->make_menu_item('select_language', 
		ltext('ma_selectlanguage'), 
		$gui->make_menu_target_int("allgemein_sprache.php", "alsp_title1", "alsp_descr1"),
		$items_enabled['general']['select_language']
	),
	$gui->make_menu_item('traffic', 
		ltext('ma_traffic'), 
		$gui->make_menu_target_int("allgemein_transfer.php")
	), 
	$gui->make_menu_item('statistics', 
		ltext('ma_stats'), 
		$gui->make_menu_target_int("allgemein_webalizer.php"),
		$items_enabled['general']['statistik']
	),
	$gui->make_menu_item('setting', 
		ltext('m_settings'), 
		$gui->make_menu_target_int('settings.php')
	),
	$gui->make_menu_item('servermessages', 
		ltext('ma_servermessages'), 
		$gui->make_menu_target_int("allgemein_servermeldungen.php")
	),
	$gui->make_menu_item('frontpage', 
		ltext('ma_frontpage'), 
		$gui->make_menu_target_int("allgemein_frontpage.php", "alfr_desc1", "alfr_desc3"),
		$items_enabled['general']['frontpage']
	)
);

$c_email = array(
	$gui->make_menu_item('overview', 
		ltext('m_overview'),
		$gui->make_menu_target_int("email_start.php")
	),
	$gui->make_menu_item('pop3',
		ltext('me_pop3'),
		$gui->make_menu_target_int("email_pop3.php", "empo_desc1", ""),
		$items_enabled['email']['pop3']
	),
	$gui->make_menu_item('email',
		ltext('me_email'),
    	$gui->make_menu_target_int("email_email.php", "emem_desc1", "emem_desc2"),
		$items_enabled['email']['email']
	),
	$gui->make_menu_item('autoresponder',
       	ltext("me_autoresponder"),
		$gui->make_menu_target_int("email_autoresponder.php", "emau_desc1", "emau_desc2"),
		$items_enabled['email']['autoresponder']
	),
	$gui->make_menu_item('maillist',
		ltext('m_maillist'),
    	$gui->make_menu_target_int('maillist.php'), 
		$items_enabled['email']['maillist']
	)
);

$c_db = array(
	$gui->make_menu_item('overview',
		ltext("m_overview"),
		$gui->make_menu_target_int("db_start.php")
	),
	$gui->make_menu_item('mysql',
		ltext("md_mysql"),
		$gui->make_menu_target_int("db_mysql.php"),
		$items_enabled['db']['mysql']
	),
	$gui->make_menu_item('phpmyadmin',
		ltext('md_phpmyadmin'),
		$gui->make_menu_target_ext($phpmyadmin_path),
		$items_enabled['db']['phpmyadmin']
	)
);

$c_tools = array(
	$gui->make_menu_item('overview',
		ltext("m_overview"),
		$gui->make_menu_target_int("tools_start.php")
	),
	$gui->make_menu_item('webftp',
		ltext("mt_webftp"),
		$gui->make_menu_target_ext("/ftplogin/"),
		$items_enabled['tools']['webftp']
	),
	$gui->make_menu_item('webmail',
		ltext("mt_webmail"),
		$gui->make_menu_target_ext("/poplogin/"),
		$items_enabled['tools']['webmail']
	),
	$gui->make_menu_item('cgicheck',
		ltext("mt_cgicheck"),
		$gui->make_menu_target_int("tools_cgicheck.php"),
		$items_enabled['tools']['cgicheck']
	),
	$gui->make_menu_item('domains',
		ltext("mt_domains"),
		$gui->make_menu_target_int("tools_domains.php")
	),
	$gui->make_menu_item('pwschutz',
		ltext("mt_auth"),
		$gui->make_menu_target_int("tools_pwschutz.php", "topw_desc1", "topw_desc2"),
		$items_enabled['tools']['pwschutz']
	),
	$gui->make_menu_item('ftpusers',
    	ltext("mt_ftpusers"),
	    $gui->make_menu_target_int("tools_ftp.php", "toft_title", "toft_desc1"),
	    $items_enabled['tools']['ftpusers']
	),
	$gui->make_menu_item('errordocs',
     	ltext("mt_errorfiles"),
   		$gui->make_menu_target_int("tools_fehlerseiten.php", "tofe_title", "tofe_desc1"),
		$items_enabled['tools']['errordocs'] 
	),
	$gui->make_menu_item('atdomains',
		ltext("mt_atdomains"),
		$gui->make_menu_target_int("atdomains.php"),
		$items_enabled['tools']['atdomains']
	),
	$gui->make_menu_item('backup',
		ltext('m_backup'),
		$gui->make_menu_target_int("tools_backup.php", "toba_desc1", ""),
		$items_enabled['tools']['backup']
	),
	$gui->make_menu_item('restore',
		ltext("m_restore"),
		$gui->make_menu_target_int("tools_restore.php", "tore_desc1", ""),
		$items_enabled['tools']['backup']
	),
	$gui->make_menu_item('cron',
		ltext("m_cron"),
    	$gui->make_menu_target_int("tools_cron.php", "cron_desc_title", "cron_desc1"),
		$items_enabled['tools']['cron']
	),
	$gui->make_menu_item('idn',
		ltext("m_idn"),
    	$gui->make_menu_target_int("idn.php"),
		$items_enabled['tools']['idn']
	)
);

// add custom help page
if ( ! preg_match ( "/^\\s*$/", $reseller["hilfecode"] ) ){
	$c_general[] = $gui->make_menu_item('help', ltext("m_help"),
			$gui->make_menu_target_int("confixx_hilfe.php"));
	$c_email[]   = $gui->make_menu_item('help', ltext("m_help"),
			$gui->make_menu_target_int("confixx_hilfe.php"));
	$c_db[]      = $gui->make_menu_item('help', ltext("m_help"),
			$gui->make_menu_target_int("confixx_hilfe.php"));
	$c_tools[]   = $gui->make_menu_item('help', ltext("m_help"),
			$gui->make_menu_target_int("confixx_hilfe.php"));
}

$additional = array();
$custom = new MenuBlocks ( 'user' );
for ( $custom->Start(); $items = $custom->NextElement(); )
{
	$submenus = array(
		$gui->make_menu_item ( 'overview',
		ltext("m_overview"),
		$gui->make_menu_target_int("custom_start.php?menublock_id=".$custom->GetID()) )
	);
	for ( $items->Start(); $items->NextElement(); )
	{
		$menuItem = $items->GetInFrame()?
			$gui->make_menu_target_int($items->GetHRef()):
			$gui->make_menu_target_ext($items->GetHRef());

		$submenus[] = $gui->make_menu_item ( 'submenu'.$items->GetID(),
																				 $items->GetLabel(),
																				 $menuItem 
																				 );
	}

	$additional[] = $gui->make_menu_block( 'custom'.$custom->GetID(), $custom->GetLabel(), 'overview',  $submenus );
}

$nav_tree = $gui->make_navigation_container( array_merge ( array(
	$gui->make_menu_block('general',   
		ltext('m_general'),	'overview',	$c_general, true),	//opened
	$gui->make_menu_block('email',     
		ltext('m_email'),   'overview', $c_email),
	$gui->make_menu_block('db',        
		ltext('m_db'),      'overview', $c_db),
	$gui->make_menu_block('tools',     
		ltext('m_tools'),   'overview', $c_tools)
	),
	$additional )
);

$menu = array($nav_tree);

$users = $PHP_AUTH_USER;
$shortcuts_items = false;
if($PHP_AUTH_USER == ($user_prefix . '0'))
{
	$id = db_query('SELECT login FROM admin');
	$res = db_fetch_array($id);
	$users .= ',' . $res['login'] . ',res0';
	$shortcuts_items = array(
			$gui->make_shortcut_item('link_domains', ltext('sh_domains'), $gui->make_menu_target_top('../../admin/resredirect.php?type=' . USERTYPE_RESELLER . '&reseller=res0')),
			$gui->make_shortcut_item('link_back_to_admin', ltext('sh_back_to_admin'), $gui->make_menu_target_top('retadmin.php')));
}

$menu[] = $gui->make_action_button('logout', ltext('m_logout'), $gui->make_menu_target_top('/logout.php?user=' . $users));

if($shortcuts_items)
{
	$menu[] = $gui->make_shortcuts_block($shortcuts_items); 
}

$page = $gui->make_left_menu($menu);

$op_block = 'general';
$op_item = 'overview';

if(array_key_exists('op_block', $_GET) && array_key_exists('op_item', $_GET))
{
	$op_block = $_GET['op_block'];
	$op_item = $_GET['op_item'];
}

$page->set_height(93);  // height="93%" - 7% for SWsoft-logo
$page->set_default($op_block, $op_item);			// active
$page->draw();
?>
