Index: trunk/globals.php
===================================================================
diff -u -r3534 -r3983
--- trunk/globals.php	(.../globals.php)	(revision 3534)
+++ trunk/globals.php	(.../globals.php)	(revision 3983)
@@ -3,7 +3,7 @@
 if (!function_exists('parse_portal_ini')) {
 	function parse_portal_ini($file, $parse_section = false) {
 
-			if (!file_exists($file)) return;
+			if (!file_exists($file)) return false;
 
 	    if(file_exists($file) && !is_readable($file))
 	        die('Could Not Open Ini File');
@@ -56,16 +56,14 @@
 	}
 }
 
-$vars = parse_portal_ini(FULL_PATH.'/config.php');
+	$vars = parse_portal_ini(FULL_PATH.'/config.php');
+	if ($vars) {
+		foreach ($vars as $config_key => $config_value) {
+			$GLOBALS['g_'.$config_key] = $config_value;
+		}
+		unset($config_key, $config_value);
+	}
 
-while($key = key($vars))
-{
-  $key = "g_".$key;
-  global $$key;
-  $$key = current($vars); //variable variables
-  next($vars);
-}
-
 /*list the tables which contain item data */
 $ItemTables = array();
 
@@ -529,67 +527,31 @@
     return $ret;
 }
 */
-function ExtractDatePart($part,$datestamp)
+function ExtractDatePart($part, $datestamp)
 {
-    switch($part)
-    {
-        case "month":
-            if($datestamp<=0)
-            {
-                $ret = "";
-            }
-            else
-              $ret = adodb_date("m",$datestamp);
-        break;
-        case "day":
-            if($datestamp<=0)
-            {
-                $ret = "";
-            }
-            else
-                $ret = adodb_date("d", $datestamp);
-        break;
-        case "year":
-            if($datestamp<=0)
-            {
-                $ret = "";
-            }
-            else
-                $ret = adodb_date("Y", $datestamp);
-        break;
-        case "time_24hr":
-            if($datestamp<=0)
-            {
-                $ret = "";
-            }
-            else
-                $ret = adodb_date("H:i", $datestamp);
-        break;
-        case "time_12hr":
-            if($datestamp<=0)
-            {
-                $ret = "";
-            }
-            else
-                $ret = adodb_date("g:i a",$datestamp);
-       		break;
-       	default:
-       		$ret = adodb_date($part, $datestamp);
-       		break;
-     }
-    return $ret;
+	if ($datestamp <= 0) return '';
+		
+	$formats = Array(	'month' => 'm', 'day' => 'd', 'year' => 'Y',
+						'time_24hr' => 'H:i', 'time_12hr' => 'g:i a', 'time' => GetTimeFormat(), 'date' => GetDateFormat() );
+	
+	$format = isset($formats[$part]) ? $formats[$part] : $part;
+	return adodb_date($format, $datestamp);
 }
 
-function GetLocalTime($TimeStamp,$TargetZone=NULL)
+function GetLocalTime($TimeStamp, $TargetZone = null)
 {
-    if($TargetZone==NULL)
-        $TargetZone = $objConfig->Get("Config_Site_Time");
-    $server = $objConfig->Get("Config_Server_Time");
-    if($TargetZone!=$server)
-    {
-      $offset = ($server - $TargetZone) * -1;
-      $TimeStamp = $TimeStamp + (3600 * $offset);
+	global $objConfig;
+	
+    if ($TargetZone == null) {
+		$TargetZone = $objConfig->Get('Config_Site_Time');
     }
+    
+    $server = $objConfig->Get('Config_Server_Time');
+    if ($TargetZone != $server) {
+    	$offset = ($server - $TargetZone) * -1;
+    	$TimeStamp = $TimeStamp + (3600 * $offset);
+    }
+    
     return $TimeStamp;
 }
 
@@ -901,15 +863,15 @@
 {
     global $objSession, $objLanguageCache, $objLanguages;
 
-    if($LangId==0)
-        $LangId = $objSession->Get("Language");
-
-	if($LangId==0)
-      $LangId = $objLanguages->GetPrimary();
-
-    $translation = $objLanguageCache->GetTranslation($phrase,$LangId);
-
-    return $translation;
+    if ($LangId == 0) {
+        $LangId = $objSession->Get('Language');
+    }
+    
+	if ($LangId == 0) {
+		$LangId = $objLanguages->GetPrimary();
+	}
+    
+    return $objLanguageCache->GetTranslation($phrase,$LangId);
 }
 
 function admin_language($phrase,$lang=0,$LinkMissing=FALSE)
@@ -1199,41 +1161,36 @@
 	unset($objTagList);
 }
 
-function GetDateFormat($LangId=0)
-{
-  global $objLanguages;
+	function GetDateFormat($LangId = 0, $is_input = false)
+	{
+		global $objLanguages;
+	
+		if (!$LangId) {
+			$LangId = $objLanguages->GetPrimary();
+		}
+		
+		$l = $objLanguages->GetItem($LangId);
+		$fmt = is_object($l) ? $l->Get(($is_input ? 'Input' : '').'DateFormat') : 'm-d-Y';
+	
+		if (getArrayValue($GLOBALS, 'FrontEnd')) {
+			return $fmt;
+		}
+		return preg_replace('/y+/i','Y', $fmt);
+	}
 
-  if(!$LangId)
-    $LangId= $objLanguages->GetPrimary();
-  $l = $objLanguages->GetItem($LangId);
-  if(is_object($l))
-  {
-  	$fmt = $l->Get("DateFormat");
-  }
-  else
-    $fmt = "m-d-Y";
+	function GetTimeFormat($LangId = 0, $is_input = false)
+	{
+		global $objLanguages;
 
-	if(isset($GLOBALS['FrontEnd'])&&$GLOBALS['FrontEnd'])
+		if (!$LangId) {
+			$LangId = $objLanguages->GetPrimary();
+		}
+		$l = $objLanguages->GetItem($LangId);
+		
+		$fmt = is_object($l) ? $l->Get(($is_input ? 'Input' : '').'TimeFormat') : 'H:i:s';
 		return $fmt;
-	return preg_replace('/y+/i','Y',$fmt);
-}
+	}
 
-function GetTimeFormat($LangId=0)
-{
-  global $objLanguages;
-
-  if(!$LangId)
-    $LangId= $objLanguages->GetPrimary();
-  $l = $objLanguages->GetItem($LangId);
-  if(is_object($l))
-  {
-  	$fmt = $l->Get("TimeFormat");
-  }
-  else
-    $fmt = "H:i:s";
-  return $fmt;
-}
-
 /**
  * Gets one of currently selected language options
  *
@@ -1252,18 +1209,32 @@
 	return is_object($l)?$l->Get($optionName):false;
 }
 
-function LangDate($TimeStamp=NULL,$LangId=0)
+/**
+ * Returns formatted timestamp
+ *
+ * @param int $TimeStamp
+ * @param int $LangId
+ * @param bool $is_input use input date format instead of display date format
+ * @return string
+ */
+function LangDate($TimeStamp = null, $LangId = 0, $is_input = false)
 {
-  $fmt = GetDateFormat($LangId);
-  $ret = adodb_date($fmt,$TimeStamp);
-  return $ret;
+  $fmt = GetDateFormat($LangId, $is_input);
+  return adodb_date($fmt, $TimeStamp);
 }
 
-function LangTime($TimeStamp=NULL,$LangId=0)
+/**
+ * Returns formatted timestamp
+ *
+ * @param int $TimeStamp
+ * @param int $LangId
+ * @param bool $is_input use input time format instead of display time format
+ * @return string
+ */
+function LangTime($TimeStamp = null, $LangId = 0, $is_input = false)
 {
-  $fmt = GetTimeFormat($LangId);
-  $ret = adodb_date($fmt,$TimeStamp);
-  return $ret;
+  $fmt = GetTimeFormat($LangId, $is_input);
+  return adodb_date($fmt, $TimeStamp);
 }
 
 function LangNumber($Num,$DecPlaces=NULL,$LangId=0)
@@ -1611,23 +1582,25 @@
 	static $import_scripts = Array();
 	if( count($import_scripts) == 0 )
 	{
-		$sql = 'SELECT * FROM '.GetTablePrefix().'ImportScripts ORDER BY is_id';
-		$db =&GetADODBConnection();
+		
+		$sql = 'SELECT imp.* , m.LoadOrder
+				FROM '.TABLE_PREFIX.'ImportScripts imp
+				LEFT JOIN '.TABLE_PREFIX.'Modules m ON m.Name = imp.is_Module
+				ORDER BY m.LoadOrder';
+		
+		$db =& GetADODBConnection();
 		$rs = $db->Execute($sql);
-		if( $rs && $rs->RecordCount() > 0 )
-		{
-			while(!$rs->EOF)
-			{
+		if ($rs && $rs->RecordCount() > 0) {
+			while (!$rs->EOF) {
 				$rec =& $rs->fields;
-				$import_scripts[] = Array(	'label' => $rec['is_label'], 'url' => $rec['is_script'],
+				$import_scripts[ $rec['is_id'] ] = Array(	'label' => $rec['is_label'], 'url' => $rec['is_script'],
 											'enabled' => $rec['is_enabled'], 'field_prefix' => $rec['is_field_prefix'],
 											'id' => $rec['is_string_id'], 'required_fields' => $rec['is_requred_fields'],
 											'module' => strtolower($rec['is_Module']) );
 				$rs->MoveNext();
 			}
 		}
-		else
-		{
+		else {
 			$import_scripts = Array();
 		}
 	}
@@ -1710,9 +1683,11 @@
 		return Array();
 	}
 	
-  	foreach($main as $vl_key => $vl_value) {
-    	if(!$vl_value) $main[$vl_key] = '0'; // unset($main[$vl_key]);
-  	}
+	if ($main) {
+		foreach($main as $vl_key => $vl_value) {
+    		if(!$vl_value) $main[$vl_key] = '0'; // unset($main[$vl_key]);
+  		}
+	}
     
 	$ret = Array();
 	foreach($var_list as $src_name => $dst_name) {
@@ -1745,9 +1720,8 @@
  */
 function IsDebugMode($check_debugger = true)
 {
-	$debug_mode = defined('DEBUG_MODE') && DEBUG_MODE;
-	if($check_debugger) $debug_mode = $debug_mode && isset($GLOBALS['debugger']);
-	return $debug_mode;
+	$application =& kApplication::Instance();
+	return $application->isDebugMode($check_debugger);
 }
 
 /**
@@ -1757,7 +1731,8 @@
  */
 function IsAdmin()
 {
-	return defined('ADMIN') && constant('ADMIN') == 1 ? 1 : 0;
+	$application =& kApplication::Instance();
+	return $application->IsAdmin();
 }
 
 /**
@@ -2060,5 +2035,15 @@
 		}
 		return $GLOBALS[$var_name];
 	}
+	
+	/**
+	 * Returns true in case of AM/PM time
+	 *
+	 * @return bool
+	 */
+	function is12HourMode()
+	{
+		return preg_match('/(a|A)/', GetTimeFormat() );
+	}
 
 ?>