<?php

/* get country names */
$hms = array();
$hms[] = array(".",".");
$hms[] = array(":",":");
$hms[] = array(" ","' ' (space)");
$hms[] = array("","'' (none)");

$sdfmt = array(
    array("dmy", "dd mm yy"),
    array("dmY", "dd mm yyyy"),
    array("mdy", "mm dd yy"),
    array("mdY", "mm dd yyyy"),
    array("ymd", "yy mm dd"),
    array("Ymd", "yyyy mm dd")
);

$ldfmt = array(
	array("%A %d %B %Y", "dddd d mmmm yyyy"),
    array("%d %b %y", "dd mmm yy"),
    array("%d %b %Y", "dd mmm yyyy"),
    array("%d %B %Y", "dd mmmm yyyy")
);

$dmys = array(
	array("/","/"),
    array(".","."),
    array("-","-"),
    array("","'' (none)")
); 

$gen = array(
    array("male", "male"),
    array("female", "female"),
);

$prov = array(
	array("Drente","Drente"),
	array("Flevoland","Flevoland"),
	array("Friesland","Friesland"),
	array("Gelderland","Gelderland"),
	array("Groningen","Groningen"),
	array("Limburg","Limburg"),
	array("Noord-Brabant","Noord-Brabant"),
	array("Noord-Holland","Noord-Holland"),
	array("Overijssel","Overijssel"),
	array("Utrecht","Utrecht"),
	array("Zeeland","Zeeland"),
	array("Zuid-Holland","Zuid-Holland"),
);
 
/* put this in db? */
$cur = array(
	array("aud","Australian Dollar (AUD)"), //australian dollar
	array("brl","Brazilian Real (BRL)"), //brazilian real
	array("cad","Canadian Dollar (CAD)"), //canadian dollar
	array("chf","Swiss Frank (CHF)"), //swiss frank
	array("czk","Zech Crown (CZK)"), //zech crown
	array("dkk","Danish Crown (DKK)"), //danish crown
	array("eur","Euro (EUR)"), //euro
	array("gbp","Great Britain Pound (GBP)"), //great britain pound
	array("isk","Iceland Crown (ISK)"), //iceland crown
	array("nok","Norsk Crown (NOK)"), //norsk crown
	array("nzd","New Zeland Dollar (NZD)"), //new zeland dollar
	array("sek","Swedish Crown (SEK)"), //swedish crown
	array("usd","US Dollar (USD)"), //us dollar
	array("jpy","Japanese Yen (JPY)"), //japanese yen
	array("zar","South African Rand (ZAR)")  //south african -> rand :p
	);

/* styles */
$themenames = array();
if ($dir = @opendir(ROOTPATH . "/modules/general/templates/". $appconf['theme']. "/css/")) {
    while (($file = readdir($dir)) !== false) {
        if(strpos($file, ".css")>0) {
	    $themenames[] = array("name" => substr($file, 0, strpos($file, ".")), "value" => $file);
    	}
    }
    closedir($dir);
    sort($themenames);
}

// modules
$smodules = array();
foreach($_SESSION["MGW"]->modules as $smodule){
    if(in_array($smodule['modulename'], array('general',
					      'admin',
					      'admin2'))) continue;
    if(queryRights2_bool('root_modules_'.$smodule['modulename'].'_accessmodule'))
	$smodules[] = array($smodule["modulename"],Lang::getLanguageString($smodule["modulename"]));
}

/* Countries */
$sql = "SELECT code,name FROM mgw_countries ORDER BY name";
$ADODB_FETCH_MODE=ADODB_FETCH_NUM;
if(($country = $conn->GetAll($sql))===false) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
$ADODB_FETCH_MODE=ADODB_FETCH_ASSOC;
array_unshift($country, array("",Lang::getLanguageString("chosecountrytext")));

/* get languages */
$sql = "SELECT langcode, description FROM mgw_languages";
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if(($lang = $conn->GetAll($sql))===false) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
array_unshift($lang, array("login", Lang::getLanguageString("login_select")));

/* locales */
// FIX KIP KFISH
//$sql = "SELECT locale,locale FROM locales ORDER BY language";
//if(($loc = $conn->GetAll($sql))===false) die(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
$loc=array();

/* settings array */
$settings["general"] = array(
	"personaldata" => array(
    	"firstname" => array(
    		"method" => "text"
        ),
        "lastname" => array(
    		"method" => "text"
        ),
        "birthday" => array(
    		"method" => "date",
		"name" => "birthday",
		"start" => "-80",
		"end" => "+0"
        ),
        "sex" => array(
        	"method" => "select",
		"choices" => array(
            	  array("name" => "","value"=>$gen)),
		"name" => "sex",
		"translate" => true
        ),
        "privstreet" => array(
    		"method" => "text"
        ),
        "privcode" => array(
    		"method" => "text",
            "name" => "privcode"
        ),
        "privcity" => array(
    		"method" => "text"
	    ),
        "privregio" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => "","value"=>$prov)),
            "name" => "privregio",
            "translate" => false
	    ),
        "privcountry" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => " ","value"=>$country)),
                "type" => "str",
            "name" => "privcountry",
            "translate" => false // whether the option names in the value array are to be translated first
        ),
        "privmobil" => array(
    		"method" => "text",
            "name" => "privmobil"
        ),
        "privtel" => array(
    		"method" => "text",
        ),
        "privemail" => array(
    		"method" => "text"
        ),
        "privhobby" => array(
    		"method" => "text",
            "name" => "privhobby"
        ),
        "mobil" => array(
    		"method" => "text",
            "name" => "mobile"
        ),
        "telephone" => array(
    		"method" => "text",
            "name" => "telephone"
        ),
        "email" => array(
    		"method" => "text"
        ),
        "pw1" => array(
    		"method" => "password",
            "name" => "password"
        ),
        "pw2" => array(
    		"method" => "password",
            "name" => "passwordagain"
        ),
        "lang" => array(
    		"method" => "select",
            "choices" => array(
            	array("name" => "", "value" => $lang)),
            "name" => "language",
            "translate" => false,
		    "description" => "which language to use (language id)",
            "type" => "str",
		    "default" => "en"
        ),
        "title" => "edituser",
        "usersettings" => true
    ),
	"appearance" => array(
        "css_skin_theme" => array(
        	"method" => "radio",
            "choices" => $themenames,
            "name" => "skinassign",
		    "description" => "which CSS file to use / actual theme file",
            "type" => "str",
			"selections" => 1,
		    "default" => "Morelogs_Silver.css"
        ),
        "iconmode" => array(
        	"method" => "radio",
            "choices" => array(
            	array("name" => "on", "value" => "1"),
                array("name" => "off", "value" => "0")),
            "name" => "iconmode",
		    "description" => "true if links should be icons, false if links should be text",
            "type" => "int",
			"selections" => 1,
		    "default" => "0"
        ),
        "show_navi_images" => array(
        	"method" => "radio",
            "choices" => array(
            	array("name" => "advanced_drop-down_menu_with_icons_and_zoom", "value" => "1"),
            	array("name" => "advanced_drop-down_menu_with_icons_without_zoom", "value" => "3"),
                array("name" => "advanced_drop-down_menu_without_icon", "value" => "0"),
                array("name" => "basic_drop-down_menu", "value" => "2"),
				array("name" => "static_menu", "value" => "4")),
            "name" => "show_navi_images_lang",
		    "description" => "Display mode for the menu",
            "type" => "int",
			"selections" => 1,
		    "default" => "3"
        ),
        "iconid" => array(
        	"method" => "radio",
            "choices" => array(
            	array("name" => "DansIcons", "value" => "0"),
                array("name" => "WeikiIcy", "value" => "1")),
            "name" => "iconstyle",
		    "description" => "Icon Style (for different icon types)",
            "type" => "int",
		    "default" => "0"
        ),
		"def_module" => array(
	      "method" => "select",
	      "choices" => array(array("name" => "", "value" => $smodules)),
	      "name" => "defmodule",
		  "description" => "default module to show",
          "type" => "str",
		  "default" => "overview"
	      ),
        "title" => "appearance"
	),
	"datetimepref" => array(
    	"set_timefmt" => array(
        	"method" => "radio",
            "choices" => array(
            	array("name" => "12h", "value" => "12h"),
                array("name" => "24h", "value" => "24h")),
            "name" => "timeformat",
			"description" => "12h or 24h time format",
            "type" => "str",
			"default" => "24h",
        ),
        "set_hourminsep" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => "", "value" => $hms)),
            "translate" => false,
            "name" => "hourminseptxt",
			"description" => "seperator in time displays between hour and minute",
            "type" => "str",
			"default" => ":",
        ),	
        "set_datefmt" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => "","value"=>$sdfmt)),
            "name" => "datefmttxt",
            "translate" => false,
			"description" => "dateformat (settings notation)",
            "type" => "str",
			"default" => "dmY",
        ),
        "set_longdatefmt" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => "","value"=>$ldfmt)),
            "name" => "datefmttxt",
            "translate" => false,
	    "hide" => true
        ),
        "set_dmysep" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => "","value"=>$dmys)),
            "name" => "dmyseptxt",
            "translate" => false,
			"description" => "day-month-year seperator",
            "type" => "str",
			"default" => "/",
        ),
        "locale" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => "","value"=>$loc)),
            "translate" => false,
            "hide" => true
        ),
        "currency" => array(
        	"method" => "select",
            "choices" => array(
            	array("name" => "","value"=>$cur)),
            "name" => "currencytxt",
            "translate" => false,
			"description" => "user currency",
            "type" => "str",
			"default" => "eur",
        ),
        "title" => "edit_datetime"
    ),
    "notification" => array(
        "notify_js" => array(
            "method" => "checkbox",
            "name" => "notify_js",
            "type" => "int",
		    "description" => "enable js notification",
			"selections" => 1,
		    "default" => "0"
        ),
        "notify_html" => array(
            "method" => "checkbox",
            "name" => "notify_html",
            "type" => "int",
		    "description" => "enable html notification",
			"selections" => 1,
		    "default" => "1",
		    "spacer"=>15
        ),
        "notify_mim_iframe" => array(
            "method" => "checkbox",
            "name" => "notify_mim_iframe",
	    	"note" => "notify_note1",
            "type" => "int",
			"description" => "enable iframe for MIM",
			"selections" => 1,
		    "default" => "1"
        ),
        "notify_mim_refresh" => array(
            "method" => "text",
            "name" => "notify_mim_refresh",
	    	"note" => "notify_note2",
            "type" => "int",
			"description" => "MIM refresh interval",
			"selections" => 1,
		    "default" => "60"
        ),
        "notify_mim_alert" => array(
            "method" => "checkbox",
            "name" => "notify_mim_alert",
            "type" => "int",
			"description" => "enable alert for MIM",
			"selections" => 1,
		    "default" => "0"
        ),
        "title" => "notification_settings"
    ),
    "gennotification" => array(
        "notify_mail_from" => array(
            "method" => "text",
            "name" => "notify_mail_from",
            "type" => "str",
			"description" => "mail notification sender mail",
			"selections" => 1,
		    "default" => "noreply@mgw.invalid"
        ),
	"admin" => true,
        "title" => "notification_settings"
    ),
    "logging" => array(
        "enable_logging" => array(
            "method" => "checkbox",
            "name" => "log_on",
            "note" => "disabled by default (still testing)",
            "type" => "int",
		    "description" => "global enable logging",
			"selections" => 1,
		    "default" => "0"
        ),
        "admin" => true,
        "title" => "log_settings"
    )
);

if (is_array($settings["general"])) foreach ($settings["general"] as $my_module_settings) {
  if (is_array($my_module_settings)) foreach ($my_module_settings as $key=>$key2) {
    if (!isset($_SESSION["MGW"]->settings[$key]) and isset($key2["default"])) {
	  $_SESSION["MGW"]->settings[$key] = $key2["default"];
	}
  }
}

/* logging settings per module */
$first = true;
foreach($_SESSION["MGW"]->modules as $m) {
    if ($m["module_type"]!=MODULE_TYPE_CORE) {
        $settings["general"]["logging"]["log_".$m["modulename"]] = array(
            "method" => "checkbox",
            "choices" => array(
             	array("name" => "Fatal","value"=>16),
                array("name" => "Error","value"=>8),
                array("name" => "Warning","value"=>4), 
                array("name" => "Notice","value"=>2),
                array("name" => "Info","value"=>1)
            ),
            "name" => $m["modulename"],
            "layout" => "h", // v (vertical is default)
            "translate" => false,
			"type" => "int",
		    "description" => $m["modulename"]." module logging level",
			"selections" => 1,
			"dimensions" => 1,
		    "default" => array("16","8","4")
			
        );
    }
}

?>
