mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
Moved under "trunk" to be able to track releases under "tags"
SVN:trunk[55]
This commit is contained in:
80
application/utils.inc.php
Normal file
80
application/utils.inc.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
define('CONFIGFILE', '../config.txt');
|
||||
|
||||
class utils
|
||||
{
|
||||
private static $m_aConfig = null;
|
||||
|
||||
public static function ReadParam($sName, $defaultValue = "")
|
||||
{
|
||||
return isset($_REQUEST[$sName]) ? $_REQUEST[$sName] : $defaultValue;
|
||||
}
|
||||
|
||||
public static function ReadPostedParam($sName, $defaultValue = "")
|
||||
{
|
||||
return isset($_POST[$sName]) ? $_POST[$sName] : $defaultValue;
|
||||
}
|
||||
|
||||
public static function GetNewTransactionId()
|
||||
{
|
||||
// TO DO implement the real mechanism here
|
||||
return sprintf("%08x", rand(0,2000000000));
|
||||
}
|
||||
|
||||
public static function IsTransactionValid($sId)
|
||||
{
|
||||
// TO DO implement the real mechanism here
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function ReadFromFile($sFileName)
|
||||
{
|
||||
if (!file_exists($sFileName)) return false;
|
||||
return file_get_contents($sFileName);
|
||||
}
|
||||
|
||||
public static function ReadConfig()
|
||||
{
|
||||
self::$m_aConfig = array();
|
||||
|
||||
$sConfigContents = self::ReadFromFile(CONFIGFILE);
|
||||
if (!$sConfigContents) throw new Exception("Could not load file ".CONFIGFILE);
|
||||
|
||||
foreach (explode("\n", $sConfigContents) as $sLine)
|
||||
{
|
||||
$sLine = trim($sLine);
|
||||
if (($iPos = strpos($sLine, '#')) !== false)
|
||||
{
|
||||
// strip out the end of the line right after the #
|
||||
$sLine = substr($sLine, 0, $iPos);
|
||||
}
|
||||
|
||||
$aMatches = array();
|
||||
if (preg_match("@(\\S+.*)=\s*(\S+.*)@", $sLine, $aMatches))
|
||||
{
|
||||
$sParamName = trim($aMatches[1]);
|
||||
$sParamValue = trim($aMatches[2]);
|
||||
self::$m_aConfig[$sParamName] = $sParamValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetConfig($sParamName, $defaultValue = "")
|
||||
{
|
||||
if (is_null(self::$m_aConfig))
|
||||
{
|
||||
self::ReadConfig();
|
||||
}
|
||||
|
||||
if (array_key_exists($sParamName, self::$m_aConfig))
|
||||
{
|
||||
return self::$m_aConfig[$sParamName];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user