<?php
//******************************************************************//
// |     MAP - Mumb1e Admin Plugin   |   http://www.mumb1e.de/    | //    
// |              ___      ___   _________   _________            | //
// |             |   \    /   | |   ___   | |   ___   |           | //
// |             |    \__/    | |  |   |  | |  |   |  |           | //
// |             |  |\    /|  | |  |___|  | |  |___|  |           | //
// |             |  | \__/ |  | |   ___   | |   ______|           | //
// |             |  |      |  | |  |   |  | |  |                  | //
// |             |__|      |__| |__|   |__| |__|                  | //
// |                                                              | //
// | --- VERSION ---                                              | //
// | Build: 419                                                   | //
// | Version: V2.3.1                                              | //
// | Date: 2010-05-30                                             | //
// | --- COPYRIGTH ---                                            | //
// | Build by P.M. and M.H. | Accept the Copyrigths!              | //
// | © by Michael Koch 'aka' P.M. <princemichi@web.de>            | //
// | --- LICENSE ---                                              | //
// | MAP - Mumb1e Admin Plugin is a dual-licensed software        | //
// | MAP is released for private end-users under GPLv3            | //
// |   >>  (visit at: http://www.gnu.org/licenses/gpl-3.0.html)   | //
// | MAP is released for commercial use under a commerial license | //
// |   >>  (visit at: http://www.mumb1e.de/index.php/en/license)  | //
// | --- ATTENTION ---                                            | //
// | Changing, editing or spreading of this sourcecode in other   | //
// | scripts, or on other websites only with permission by PM!    | //
//******************************************************************//
//************************************************************************************************//
// Start des Ausgabeinhalts
//************************************************************************************************//

//Berechtigungen fÃ¼r gerade angemeldeten User definieren, wenn Coockies noch nicht vorhanden sind! Damit Main_Navi richtig dargestellt wird.
if (!isset($_COOKIE['MAP_user_id'])&& !isset($_COOKIE['MAP_user_pwd'])) {
    $qry = mysql_query("SELECT * FROM `".$database_prefix."map_user` WHERE user_id = '".$MUID."' LIMIT 1");
    $get = mysql_fetch_array($qry);
    if ($get[perm_s_server_user] == "1") {
        $perm_s_server_user = "TRUE";
        } else {
            $perm_s_server_user = "FALSE";
    }
    if ($get[perm_s_map_user] == "1") {
        $perm_s_map_user = "TRUE";
        } else {
            $perm_s_map_user = "FALSE";
    }
    if ($get[perm_s_most_active] == "1") {
        $perm_s_most_active = "TRUE";
        } else {
            $perm_s_most_active = "FALSE";
    }
    if ($get[perm_s_accounts] == "1") {
        $perm_s_accounts = "TRUE";
        } else {
            $perm_s_accounts = "FALSE";
    }
    if ($get[perm_s_servers] == "1") {
        $perm_s_servers = "TRUE";
        } else {
            $perm_s_servers = "FALSE";
    }
    if ($get[perm_s_settings] == "1") {
        $perm_s_settings = "TRUE";
        } else {
            $perm_s_settings = "FALSE";
    }
    if ($get[perm_c_server_user] == "1") {
        $perm_c_server_user = "TRUE";
        } else {
            $perm_c_server_user = "FALSE";
    }
    if ($get[perm_c_map_user] == "1") {
        $perm_c_map_user = "TRUE";
        } else {
            $perm_c_map_user = "FALSE";
    }
    if ($get[perm_c_servers] == "1") {
        $perm_c_servers = "TRUE";
        } else {
            $perm_c_servers = "FALSE";
    }
    //Hole Berechtigungen fürs Logging
    $qry_log_set = mysql_query("SELECT * FROM `".$database_prefix."map_settings` WHERE id = '27' LIMIT 1");
    $get_log_set = mysql_fetch_array($qry_log_set);
    $qry_log_usr = mysql_query("SELECT * FROM `".$database_prefix."map_user` WHERE user_id = '".$MUID."' LIMIT 1");
    $get_log_usr = mysql_fetch_array($qry_log_usr);
    if (($get_log_set[2] == "1" AND $get_log_usr[server_id] == "0") OR ($get_log_set[2] == "2" AND $get_log_usr[server_id] == "0") OR ($get_log_set[2] == "2" AND $get_log_usr[server_id] != "0")) {
        $perm_s_logging = "TRUE";
        } else {
            $perm_s_logging = "FALSE";
    }
    // Hole Channelviewer Berechtigungen
    if ($get[server_id] == "0") {
    	$perm_e_channelviewer = "TRUE";
    	$perm_s_channelviewer = "TRUE";
    	} elseif ($get[server_id] != "0") {    		
		    $qry_view_perm = mysql_query("SELECT * FROM `".$database_prefix."map_channelviewer` WHERE server_id = '".$get[server_id]."'");
		    $get_view_perm = mysql_fetch_array($qry_view_perm);
		    //Definiere Berechtigungen zum Editieren
			if ($get_view_perm[permission] == "1") {
		        $perm_e_channelviewer_pre = "1";
		        } elseif ($get_view_perm[permission] == "2"){
		            $perm_e_channelviewer_pre = "2";
		    }
		    if ($perm_e_channelviewer_pre == "1" & $get[server_id] != "0") {
		    	$perm_e_channelviewer = "TRUE";   	
		    	} elseif ($perm_e_channelviewer_pre == "2" & $get[server_id] != "0") {
		    		$perm_e_channelviewer = "FALSE";   	
		    }    
		    //Definiere Berechtigungen zum Anzeigen
			if ($get_view_perm[show_permission] == "1") {
		        $perm_s_channelviewer_pre = "1";
		        } elseif ($get_view_perm[show_permission] == "2") {
		            $perm_s_channelviewer_pre = "2";
		    }
		    if ($perm_s_channelviewer_pre == "1" & $get[server_id] != "0") {
		    	$perm_s_channelviewer = "TRUE";   	
		    	} elseif ($perm_s_channelviewer_pre == "2" & $get[server_id] != "0") {
		    		$perm_s_channelviewer = "FALSE";   	
		    }
    } 
}

//Setze CV Auth
if ($mklock == "TRUE") {
	mysql_query("UPDATE `".$database_prefix."map_settings` SET value_2 = '0' WHERE id = '4'");
	echo "Auth successfully!";
	} elseif ($mklock == "Authed") {
		mysql_query("UPDATE `".$database_prefix."map_settings` SET value_2 = '1' WHERE id = '4'");
		echo "Auth undo successfully!";
}

// Main Navigation
if ($MUID !='0') {
    // Main Menu Standart Links
    $i = '0';
    $main_link[$i] = "<img src=\"../inc/tpl/".$tpldir."/images/home.png\" alt=\"\" border=\"0\"><a href=\"../start/index.php\" target=\"_self\" class=\"main_navi\">"._menu_link_home."</a>";
    $i++;
    if ($perm_s_servers == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/server_user.png\" alt=\"\" border=\"0\"><a href=\"../server/index.php?default\" target=\"_self\" class=\"main_navi\">"._menu_link_servers."</a>");
        $i++;
    }
    if ($perm_s_channelviewer == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/channelviewer/menue.png\" alt=\"\" border=\"0\"><a href=\"../view/index.php?default\" target=\"_self\" class=\"main_navi\">"._menu_link_view."</a>");
        $i++;
    }
    if ($perm_s_server_user == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/userlist.png\" alt=\"\" border=\"0\"><a href=\"../user/index.php?default\" target=\"_self\" class=\"main_navi\">"._menu_link_server_users."</a>");
        $i++;
    }
    if ($perm_s_map_user == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/map_user.png\" alt=\"\" border=\"0\"><a href=\"../user/index.php?section=show_map_users\" target=\"_self\" class=\"main_navi\">"._menu_link_map_users."</a>");
        $i++;
    }
    if ($perm_s_most_active == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/activity.png\" alt=\"\" border=\"0\"><a href=\"../user/index.php?section=show_most_activ_users\" target=\"_self\" class=\"main_navi\">"._menu_link_activity."</a>");
        $i++;
    }
    if ($perm_c_server_user == "TRUE" OR $perm_c_map_user == "TRUE" OR $perm_c_servers == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/create_user.png\" alt=\"\" border=\"0\"><a href=\"../server/index.php?section=create\" target=\"_self\" class=\"main_navi\">"._menu_link_create."</a>");
        $i++;
    }
    if ($perm_s_accounts == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/requested_account.png\" alt=\"\" border=\"0\"><a href=\"../request/index.php?section=show_requested_accounts\" target=\"_self\" class=\"main_navi\">"._menu_link_requested_accounts."</a>");
        $i++;
    }
    $qry_logging_on = mysql_query("SELECT * FROM `".$database_prefix."map_settings` WHERE id = '23'");
    $get_logging_on = mysql_fetch_array($qry_logging_on);
    if ($perm_s_logging == "TRUE" && $get_logging_on[2] == "1") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/logging.png\" alt=\"\" border=\"0\"><a href=\"../log/index.php?default\" target=\"_self\" class=\"main_navi\">"._menu_link_log."</a>");
        $i++;
    }
    if ($perm_s_settings == "TRUE") {
        array_splice($main_link, $i, 0, "<img src=\"../inc/tpl/".$tpldir."/images/settings.png\" alt=\"\" border=\"0\"><a href=\"../settings/index.php?default\" target=\"_self\" class=\"main_navi\">"._menu_link_settings."</a>");
        $i++;
    }
    $main_link[$i] = "<img src=\"../inc/tpl/".$tpldir."/images/logout.png\" alt=\"\" border=\"0\"><a href=\"../start?do=logout\" target=\"_self\" class=\"main_navi\">"._menu_link_logout."</a>";
    
    $i = '0';
    while ($main_link[$i]) {
        $main_menu_link .= show("menu/menu_link", array("link" => $main_link[$i]));
        $i++;
    }
 
    $main_navi = show("menu/main_navi", array("menu_link" => $main_menu_link,
                                              "overview" => _menu_link_overview,                                                                                                                                                                                      
                                              ));
    } else {
        $main_navi = "";
}

//Check ob das "../install/-Verzeichnis gelöscht wurde!
if (file_exists('../install/') AND $development != "1") {
    echo "<div align=\"center\"><div class='commerial'>"._info_install_dirctory_exists."</div></div>";
}
            
//Prüfe ob System auf Linux läuft
$qry = mysql_query("SELECT * FROM `".$database_prefix."map_settings` WHERE id = '20'");
$get = mysql_fetch_array($qry);
if ($get[value_2] == "linux") {
    //Check ob die CHMOD -Rechte für "../inc/_mysql.php" stimmen
    $savepath = substr(decoct(fileperms('../inc/_mysql.php')), 2);
    if ((octdec($savepath) & 0667) >= 0667 AND $development == "0") {
        echo "<div align=\"center\"><div class='commerial'>"._info_inc_mysqlphp_chmod_wrong."</div></div>";
    }
}

// Login Box
if ($MUID =='0') { 
    $login = show("menu/login", array("login" => _menu_login_overview,
                                      "login_do" => _menu_login_do,
                                      "login_field_1" => _menu_login_field_1,
                                      "login_field_2" => _menu_login_field_2
                                      ));
    } else {
        $login = "";
}

//Damit es im Forintend anständig aussieht checke ob request und passwort an sind. ansonsten gebe jeweils einzeln aus.
$qry = mysql_query("SELECT * FROM `".$database_prefix."map_settings` WHERE id = '16'");
$get_request_account = mysql_fetch_array($qry);
//Gebe beide Links im Frontend aus, wenn EIN, ansonsten Einzelausgabe
if ($MUID == '0' && $get_request_account[2] == '1' && $perm_s_req_access_default == "TRUE" && $perm_s_forgot_area == "TRUE") {
	$request_forgot .= show("menu/request_forgot", array("request_link" => _menu_request_link,
											     		 "forgot_link" => _menu_forgot_link,
												 		 ));
	} else {
	// Einzelausgabe: Request User Account - Link
	if ($MUID == '0' && $get_request_account[2] == '1' && $perm_s_req_access_default == "TRUE") { 
	    $request_forgot .= show("menu/request", array("request_link" => _menu_request_link));
	    } else {
	        $request_forgot .= "";
	}
	
	// Einzelausgabe: Passwort vergessen Funktionen - Link
	if ($MUID == '0' && $perm_s_forgot_area == "TRUE") { 
	    $request_forgot .= show("menu/forgot", array("forgot_link" => _menu_forgot_link));
	    } else {
	        $request_forgot .= "";
	}
}

// Content - Head
if ($content_headers[head_on] == TRUE) {
	// Lädt HTML-Datei
	if ($content_headers[head_type] == "default") {
		$content_head = show("content/head", array("head" => $content_headers[head_value],
			                                     ));
	}
}

// Content - Navi
if ($content_headers[navi_on] == TRUE) {
	// Lädt HTML-Datei
	if ($content_headers[navi_type] == "default") {
		$content_navi = show("content/navi_default", array("back" => "<a href=\"".$_SERVER['HTTP_REFERER']."\" target=\"_self\"><img src=\"../inc/tpl/".$tpldir."/images/back.png\" alt=\"\" title=\""._layout_navi_default_back."\" border=\"0\"></a>",
	                                                       "cancel" => "",
		                                                   ));
	}
}
                                      
//Berechnet die Parse Zeit des Scripts und gibt in Footer aus.
$php_parse_time_finish = time()+(double)microtime();
$php_parse_time = round($php_parse_time_finish-$php_parse_time_start,5);

// Footer
// Lädt HTML-Datei
$footer = show("footer/footer", array("copyrigth" => $copyrigth,
                                      "logged" => $logged,
                                      "akt_date" => $aktdate_detail,
                                      "version_num" => $version_num,
									  "parse_time" => $php_parse_time,
                                      "version_date" => $version_date
                                      ));

// Header
// Lädt HTML-Datei
$header = show("header/header", array());

// Anzeige des gesammten Templates
if ($comuse == FALSE AND $authed[f1] == TRUE) {
    echo show("/index", array("seitentitel" => $seitentitel,
                              "map_version" => $version_num,
                              "map_date" => $version_date,
                              "header" => $header,
                              "main_navi" => $main_navi,
                              "login" => $login,
                              "request_forgot" => $request_forgot,
    					      "content_head" => $content_head,
    						  "content_navi" => $content_navi,
                              "info" => $info,
                              "index" => $index,
                              "footer" => $footer
                              ));
    } elseif ($comuse == TRUE AND $authed[f1] == FALSE) {
        echo $tpl_output_comuse;
}
//************************************************************************************************//
// Ende des Ausgabeinhalts
//************************************************************************************************//
?>