//------------------------------------------------------------
function isEmpty($my_value)
//------------------------------------------------------------
{
if ( $my_value === null || $my_value === "" )
{
return true;
}
return false;
}
//------------------------------------------------------------
function loadCurrentLanguage()
//------------------------------------------------------------
{
if (isset($_SESSION["CurrentLanguage"]))
{
$currentLanguage = $_SESSION["CurrentLanguage"];
}
else
{
$currentLanguage = LANGUAGE_FALLBACK;
}
return $currentLanguage;
}
//------------------------------------------------------------
function saveCurrentLanguage( $langtosave )
//------------------------------------------------------------
{
$_SESSION["CurrentLanguage"] = $langtosave;
}
//------------------------------------------------------------
function getCurrentLanguage( $paramLang )
//------------------------------------------------------------
{
global $db;
$currentLanguage = loadCurrentLanguage();
if( $paramLang != "" )
{
$sqlStr = "SELECT id FROM languages WHERE show_translation = 1 AND iso_code = \"".$paramLang."\"";
$retcode = $db->select($sqlStr);
if( $retcode > 0 )
{
$currentLanguage = $paramLang;
saveCurrentLanguage($paramLang);
}
}
return $currentLanguage;
}
//------------------------------------------------------------
function loadUserdataFromSession()
//------------------------------------------------------------
{
global $currentuserdata;
if (isset($_SESSION["CUD_login"])) {
$currentuserdata["login"] = $_SESSION["CUD_login"];
} else {
$currentuserdata["login"] = null;
}
if (isset($_SESSION["CUD_username"])) {
$currentuserdata["username"] = $_SESSION["CUD_username"];
} else {
$currentuserdata["username"] = null;
}
if (isset($_SESSION["CUD_fullname"])) {
$currentuserdata["fullname"] = $_SESSION["CUD_fullname"];
} else {
$currentuserdata["fullname"] = null;
}
if (isset($_SESSION["CUD_id"]))
{
$currentuserdata["id"] = $_SESSION["CUD_id"];
}
else
{
$currentuserdata["id"] = null;
}
if (isset($_SESSION["CUD_right_group_id"]))
{
$currentuserdata["right_group_id"] = $_SESSION["CUD_right_group_id"];
}
else
{
$currentuserdata["right_group_id"] = PUBLIC_RIGHT_ID;
}
if (isset($_SESSION["CUD_disclaimer_accepted"]))
{
$currentuserdata["disclaimer_accepted"] = $_SESSION["CUD_disclaimer_accepted"];
}
else
{
$currentuserdata["disclaimer_accepted"] = PUBLIC_RIGHT_ID;
}
if (isset($_SESSION["CUD_partner_id"]))
{
$currentuserdata["partner_id"] = $_SESSION["CUD_partner_id"];
}
else
{
$currentuserdata["partner_id"] = PUBLIC_RIGHT_ID;
}
// CG TEST
//$currentuserdata["id"] = 1;
}
//------------------------------------------------------------
function saveUserdataToSession()
//------------------------------------------------------------
{
global $currentuserdata;
$_SESSION["CUD_login"] = $currentuserdata["login"];
$_SESSION["CUD_username"] = $currentuserdata["username"];
$_SESSION["CUD_fullname"] = $currentuserdata["fullname"];
$_SESSION["CUD_id"] = $currentuserdata["id"];
$_SESSION["CUD_right_group_id"] = $currentuserdata["right_group_id"];
$_SESSION["CUD_partner_id"] = $currentuserdata["partner_id"];
$_SESSION["CUD_disclaimer_accepted"] = $currentuserdata["disclaimer_accepted"];
}
//------------------------------------------------------------
function getParamValue( $paramname )
//------------------------------------------------------------
{
$dummy = "";
if (isset($_POST[$paramname]))
{
$dummy = $_POST[$paramname];
}
if (isset($_GET[$paramname]))
{
$dummy = $_GET[$paramname];
}
return $dummy;
}
//------------------------------------------------------------
function uniqueId()
//------------------------------------------------------------
{
$lastuniqueid = 0;
if (isset($_SESSION["lastuniqueid"]))
$lastuniqueid = $_SESSION["lastuniqueid"];
if( $lastuniqueid >= 10000 )
$lastuniqueid = 0;
else
$lastuniqueid++;
$_SESSION["lastuniqueid"] = $lastuniqueid;
$uid = date("YmdhisU") . $lastuniqueid;
return $uid;
}
//------------------------------------------------------------
function printMessage( $action , $successfull )
//------------------------------------------------------------
{
if( $successfull <= 0)
{
echo "
The action \"" . $action . "\" Failed.
";
}
else
{
echo "
The action \"" . $action . "\" was Successfull.
";
}
}
//------------------------------------------------------------
function printError( $errortext )
//------------------------------------------------------------
{
echo "
" . $errortext . "
";
}
//------------------------------------------------------------
function printWarning( $errortext )
//------------------------------------------------------------
{
echo "
" . $errortext . "
";
}
//------------------------------------------------------------
function dprint( $prefix, $values, $dieornot = false )
//------------------------------------------------------------
{
echo "
";
echo "";
if( $prefix != "" )
echo $prefix . ":";
echo $values;
echo "";
echo "
";
if( $dieornot === true )
die();
}
//------------------------------------------------------------
function createRandomPassword()
//------------------------------------------------------------
{
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
//------------------------------------------------------------
function isValidEmail($email)
//------------------------------------------------------------
{
$retval = false;
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
$retval = true;
}
return $retval;
}
//------------------------------------------------------------
function isValidUsername($username)
//------------------------------------------------------------
{
$retval = false;
if (eregi("^[_.@a-zA-Z0-9]+$", $username)) {
$retval = true;
}
return $retval;
}
//------------------------------------------------------------
function getButtonHTML( $text, $link, $target = null, $onclick = null)
//------------------------------------------------------------
{
$clickstring = "";
$targetstring = "";
$line = "";
if( $target != null )
$targetstring = " target=\"" . $target . "\" ";
if( $onclick != null )
$clickstring = " onclick=\"" . $onclick . "\" ";
$line .= "";
return $line;
}
//------------------------------------------------------------
function getBacklink( $pagename )
//------------------------------------------------------------
{
$backlink = "index.php?page=" . $pagename;
$page = getParamValue("p");
if( $page != "" )
$backlink .= "&p=" . $page;
return $backlink;
}
//------------------------------------------------------------
function getFooterHTML( )
//------------------------------------------------------------
{
return;
global $db,$currentuserdata;
$line = "";
$sqlStr = "SELECT name,page,syspage FROM sys_navi WHERE active = 1 AND topbottom = 1 ORDER BY position ASC";
$retcode = $db->select($sqlStr);
//dprint("sql",$sqlStr,false);
if( $retcode > 0 )
{
for( $i = 0 ; $i < count($db->result);$i++)
{
if( $i > 0 )
$line .= " | ";
if( $db->result[$i]["syspage"] == "1" )
$line .= "result[$i]["page"] . "\">";
else
$line .= "result[$i]["page"] . "\">";
//$line .= "result[$i]["page"] . "\">";
$line .= $db->result[$i]["name"];
$line .= "";
}
}
return $line;
}
//------------------------------------------------------------
function htmlEncode($str)
//------------------------------------------------------------
{
$str = str_replace("\n","
",$str);
$str = str_replace("\r","",$str);
return $str;
}
//------------------------------------------------------------
function htmlDecode($str)
//------------------------------------------------------------
{
$str = str_replace("
","\n",$str);
$str = str_replace("
","\n",$str);
return $str;
}
//------------------------------------------------------------
function getLanguages( )
//------------------------------------------------------------
{
global $db;
$sqlStr="SELECT l.iso_code,l.english_name FROM languages l WHERE is_translatable=1 ORDER BY english_name ASC";
$retcode = $db->select($sqlStr);
if( $retcode > 0 )
{
$res_languages = $db->getResult();
}
else
{
$res_languages = array();
}
return $res_languages;
}
//------------------------------------------------------------
function getCategories( )
//------------------------------------------------------------
{
global $db;
$sqlStr="SELECT c.id,c.category,c.description FROM categories c ORDER BY id ASC";
$retcode = $db->select($sqlStr);
if( $retcode > 0 )
{
$res_cat = $db->getResult();
}
else
{
$res_cat = array();
}
return $res_cat;
}
//------------------------------------------------------------
function getSiteLanguageSelectBox($htmlName, $selectedValue = null, $htmlStyle = null, $onchange = null, $htmlId = null)
//------------------------------------------------------------
{
global $db;
$strSQL = "SELECT iso_code, english_name AS name "
. "FROM languages "
. "WHERE `show_translation` = 1 "
. "ORDER BY `name` ASC;";
$retcode = $db->select($strSQL);
if ($retcode > 0) {
$selectbox = new Selectbox($db->getResult(), "iso_code", "name");
$selectbox->selectedValue = $selectedValue;
$selectbox->htmlName = $htmlName;
$selectbox->htmlId = $htmlId;
$selectbox->htmlStyle = $htmlStyle;
$selectbox->onChange = $onchange;
return $selectbox->getHtmlCode();
}
return false;
}
//------------------------------------------------------------
function createThumbnail($imagePath, $thumbnailPath, $max_width = 100, $max_height = 100)
//------------------------------------------------------------
{
$info = pathinfo($imagePath);
$img = null;
if ( strtolower($info['extension']) == 'jpg' )
{
$img = imagecreatefromjpeg( $imagePath );
}
if ( strtolower($info['extension']) == 'png' )
{
$img = imagecreatefrompng($imagePath);
}
if ( strtolower($info['extension']) == 'gif' )
{
$img = imagecreatefromgif($imagePath);
}
if ($img != null)
{
$width = imagesx( $img );
$height = imagesy( $img );
$ratio_orig = $width/$height;
if ($max_width/$max_height > $ratio_orig)
{
$max_width = $max_height*$ratio_orig;
}
else
{
$max_height = $max_width/$ratio_orig;
}
// create a new temporary image
$tmp_img = imagecreatetruecolor( $max_width, $max_height );
// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $max_width, $max_height, $width, $height );
// save thumbnail into a file
imagejpeg( $tmp_img, $thumbnailPath );
return true;
}
return false;
}
?>