//////////////// SETTINGS
define('ROOT_DIR', dirname(dirname(__FILE__)));
//define('ROOT_SITE' , dirname($_SERVER['PHP_SELF']));
define('ROOT_SITE' , 'http://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', dirname(dirname(__FILE__)))).'/');
define("UPLOAD_DIR", "uploads");
//////////////// session directory
define('SESSION_DIR', ROOT_DIR.'/temp/sessions');
//session_save_path(SESSION_DIR);
//////////////// Cache Dir
define("CASHE_DIR", ROOT_DIR."/temp/cache/");
//////////////// Template Dir
define("THEME_DIR", ROOT_DIR."/templates/");
//////////////// database setting;
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'homshealth_dba');
define('DB_PASSWORD', 'asd@123@QWE');
define('DB_DATABASE', 'homshealth_new');
//define('DB_DATABASE', 'sajjel_golden');
define('DB_TYPE', 'mysql');
define('DB_CHARSET', 'utf8');
//////////////// Error Reporting
define('DEVELOPMENT_ENVIRONMENT', true);
///////////////////////////////////////////////////////////////////////////
define('SECRETKEY','132458412345670897654');
///////////////////////////////////////////////////////////////////////////
define('DS', DIRECTORY_SEPARATOR);
///////////////////////////////////////////////////////////////////////////
$today=date("Y-m-d");
?>
//////////////////////////////////////////////////////////////////////////////////
function setErrorReporting(){
if(DEVELOPMENT_ENVIRONMENT === false){
error_reporting(0);
ini_set('display_errors','false');
}
else{
//error_reporting(E_ALL);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors','On');
ini_set('log_errors', 'On');
ini_set('error_log', ROOT_DIR.'/temp/logs/error.log');
}
}
//////////////////////////////////////////////////////////////////////////////////
function callHook(){
global $url;
if($url){
$urlArray = array();
$urlArray = explode('/',$url);
$controller = $urlArray[0];
array_shift($urlArray);
$action = $urlArray[0];
array_shift($urlArray);
$queryString = $urlArray[0];
}
}
//////////////////////////////////////////////////////////////////////////////////
function loadsettings(){
$query = 'SELECT * FROM tblsettings';
$result = mysql_query ($query);
while ($data = @mysql_fetch_array ($result)){
$setting = $data['setting'];
$value = $data['value'];
$CONFIG['' . $setting] = '' . $value;
}
return $CONFIG;
}
//////////////////////////////////////////////////////////////////////////////////
function savesettings($conf=array()){
if(is_array($conf)){
foreach ($conf as $key=>$value){
$result = mysql_query ('' . 'UPDATE tblsettings SET value=\'' . $value . '\' WHERE setting=\''.$key.'\'');
}
}
}
//////////////////////////////////////////////////////////////////////////////////
function format_as_currency ($amount){
$amount += 9.99999999999999954748112e-07;
$amount = round ($amount, 2);
$amount = sprintf ('%01.2f', $amount);
return $amount;
}
//////////////////////////////////////////////////////////////////////////////////
function OptionSelected($a,$b){
if($a==$b){
return " selected";
}
}
//////////////////////////
function check_me($a,$b){
if($a==$b){
return " selected";
}
}
//////////////////////////
function OptionChecked($a,$b){
if($a==$b){
return " checked";
}
}
//////////////////////////
function dropOptions($Arr,$selected){
if(is_array($Arr)){
$xx="";
foreach($Arr as $key=>$value){
$xx.= '';
}
return $xx;
}
}
//////////////////////////
function dropCheckBoxes($Arr,$selectedArr=null){
foreach($Arr as $key=>$value){
echo ''.$value.'
';
}
}
//////////////////////////////////////////////////////////////
function counter(){
$query=@mysql_query("update tblsettings set value=value+1 where setting='counter'");
}
//////////////////////////////////////////////////////////////
function GetRandomChar() {
// This function generates our random chars
// Seed with microseconds since last "whole" second
mt_srand((double)microtime()*1000000);
// Create a random number between 1 and 3
//$IMGVER_RandVal = mt_rand(1,3);
//$IMGVER_RandVal = mt_rand(1,2);
$IMGVER_RandVal = 1;
// If the random number was 1, we generate a lowercase
// character, if it was 2, we generate a number and if
// it was 3, we generate an uppercase character.
switch ($IMGVER_RandVal) {
case 1:
// 48 to 57 are the ASCII codes for the
// numbers from 0 to 9.
$IMGVER_RandVal = mt_rand(48, 57);
break;
case 2:
// 97 to 122 are the ASCII codes for lower-
// case characters from a to z.
$IMGVER_RandVal = mt_rand(97, 122);
break;
//case 3:
// 65 to 70 are the ASCII codes for upper-
// case characters from a to z.
// $IMGVER_RandVal = mt_rand(65, 90);
// break;
}
// Now we return the character, generated from the ASCII code
return chr($IMGVER_RandVal);
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
function showAdsById($id=0){
$QUERY=MYSQL_QUERY("select * from tbladvertising where id='$id' ");
$SHOW=MYSQL_FETCH_ARRAY($QUERY);
if($SHOW['adsKind']=="flash"){
$htmlVal='';
}
if($SHOW['adsKind']=="image"){
$htmlVal.='
';
}
if($SHOW['adsKind']=="code"){
$htmlVal=$SHOW[HtmlCode ];
}
return $htmlVal;
}
//////////////////////////////////////////////////////////////////////////////////
function getCatByid( $tbl,$cid){
$Q1=MYSQL_QUERY("select * from $tbl where id = '$cid' ") ;
$USR = MYSQL_FETCH_ARRAY($Q1);
$USR[name]=$USR['name'.$_SESSION['language']];
$USR[description]=$USR['description'.$_SESSION['language']];
return $USR;
}
//////////////////////////////////////////////////////////////////////////////////
function forceUTF8($text){
/**
* Function forceUTF8
*
* This function leaves UTF8 characters alone, while converting almost all non-UTF8 to UTF8.
*
* It may fail to convert characters to unicode if they fall into one of these scenarios:
*
* 1) when any of these characters: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß
* are followed by any of these: ("group B")
* ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶•¸¹º»¼½¾¿
* For example: %ABREPRESENT%C9%BB. «REPRESENTÉ»
* The "«" (%AB) character will be converted, but the "É" followed by "»" (%C9%BB)
* is also a valid unicode character, and will be left unchanged.
*
* 2) when any of these: àáâãäåæçèéêëìíîï are followed by TWO chars from group B,
* 3) when any of these: ðñòó are followed by THREE chars from group B.
*
* @name forceUTF8
* @param string $text Any string.
* @return string The same string, UTF8 encoded
*
*/
if(is_array($text))
{
foreach($text as $k => $v)
{
$text[$k] = forceUTF8($v);
}
return $text;
}
$max = strlen($text);
$buf = "";
for($i = 0; $i < $max; $i++){
$c1 = $text{$i};
if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already
$c2 = $i+1 >= $max? "\x00" : $text{$i+1};
$c3 = $i+2 >= $max? "\x00" : $text{$i+2};
$c4 = $i+3 >= $max? "\x00" : $text{$i+3};
if($c1 >= "\xc0" & $c1 <= "\xdf"){ //looks like 2 bytes UTF8
if($c2 >= "\x80" && $c2 <= "\xbf"){ //yeah, almost sure it's UTF8 already
$buf .= $c1 . $c2;
$i++;
} else { //not valid UTF8. Convert it.
$cc1 = (chr(ord($c1) / 64) | "\xc0");
$cc2 = ($c1 & "\x3f") | "\x80";
$buf .= $cc1 . $cc2;
}
} elseif($c1 >= "\xe0" & $c1 <= "\xef"){ //looks like 3 bytes UTF8
if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf"){ //yeah, almost sure it's UTF8 already
$buf .= $c1 . $c2 . $c3;
$i = $i + 2;
} else { //not valid UTF8. Convert it.
$cc1 = (chr(ord($c1) / 64) | "\xc0");
$cc2 = ($c1 & "\x3f") | "\x80";
$buf .= $cc1 . $cc2;
}
} elseif($c1 >= "\xf0" & $c1 <= "\xf7"){ //looks like 4 bytes UTF8
if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf"){ //yeah, almost sure it's UTF8 already
$buf .= $c1 . $c2 . $c3;
$i = $i + 2;
} else { //not valid UTF8. Convert it.
$cc1 = (chr(ord($c1) / 64) | "\xc0");
$cc2 = ($c1 & "\x3f") | "\x80";
$buf .= $cc1 . $cc2;
}
} else { //doesn't look like UTF8, but should be converted
$cc1 = (chr(ord($c1) / 64) | "\xc0");
$cc2 = (($c1 & "\x3f") | "\x80");
$buf .= $cc1 . $cc2;
}
} elseif(($c1 & "\xc0") == "\x80"){ // needs conversion
$cc1 = (chr(ord($c1) / 64) | "\xc0");
$cc2 = (($c1 & "\x3f") | "\x80");
$buf .= $cc1 . $cc2;
} else { // it doesn't need convesion
$buf .= $c1;
}
}
return $buf;
}
//////////////////////////////////////////////////////////////////////////////////
function forceLatin1($text) {
if(is_array($text)) {
foreach($text as $k => $v) {
$text[$k] = forceLatin1($v);
}
return $text;
}
return utf8_decode(forceUTF8($text));
}
//////////////////////////////////////////////////////////////////////////////////
function fixUTF8($text){
if(is_array($text)) {
foreach($text as $k => $v) {
$text[$k] = fixUTF8($v);
}
return $text;
}
$last = "";
while($last <> $text){
$last = $text;
$text = forceUTF8(utf8_decode(forceUTF8($text)));
}
return $text;
}
//////////////////////////////////////////////////////////////////////////////////
function is_valid_email($email) {
$result = TRUE;
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
$result = FALSE;
}
return $result;
}
//////////////////////////////////////////////////////////////////////////////////
function formatDate($date,$type="Ar"){
if($type == "Ar"){
$monthsArr = array (
'01' => 'كانون الثاني',
'02' => 'شباط',
'03' => 'آذار',
'04' => 'نيسان',
'05' => 'أيار',
'06' => 'حزيران',
'07' => 'تموز',
'08' => 'آب',
'09' => 'ايلول',
'10' => 'تشرين الاول',
'11' => 'تشرين الثاني',
'12' => 'كانون الأول'
);
}else{
$monthsArr = array (
'01' => 'JAN',
'02' => 'FEB',
'03' => 'MAR',
'04' => 'APR',
'05' => 'MAY',
'06' => 'JUN',
'07' => 'JUL',
'08' => 'AUG',
'09' => 'SEP',
'10' => 'OCT',
'11' => 'NOV',
'12' => 'DEC'
);
}
$dd=explode("-",$date);
return $dd[2]." ".$monthsArr[$dd[1]]." ".$dd[0];
}
//////////////////////////////////////////////////////////////////////////////////
function rmdir_r($dirname) {
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
else
rmdir_r($dirname.'/'.$file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
//////////////////////////////////////////////////////////////////////////////////
function loadController(){
//fetch the passed request
$request = $_SERVER['QUERY_STRING'];
//parse the page request and other GET variables
$parsed = explode('/' , $request);
//the page is the first element
$page = array_shift($parsed);
//$page =$this->sanitize->clean($page);
$page=strlen($page)>1 ? $page : INDEX;
//the rest of the array are get statements, parse them out.
$getVars = array();
foreach ($parsed as $variable=>$value)
{
//split GET vars along '=' symbol to separate variable, values
//list($variable , $value) = split('=' , $argument);
//$getVars[$variable] = urldecode($value);
//$value =$this->sanitize->clean($value);
$getVars[] = urldecode($value);
}
//print_r($parsed);
//print_r($getVars);
//compute the path to the file
$target = ROOT_DIR . '/controllers/' . $page . '.php';
}
//////////////////////////////////////////////////////////////////////////////////
function getAllCats($id=0) {
////////// ابدأ التعديل من هنا //////////
$name_t = "tblpages"; // اسم جدول الاقسام
$id_f = "id"; // id اسم الحقل الذي يحوي رقم القسم
$name_f = "nameAr"; // اسم الحقل الذي يحوي اسم القسم
$parent_f = "subid"; // parent اسم الحقل الذي يحوي رقم القسم الاساسي
////////// الانتهاء من التعديل //////////
static $cates = array();
static $tnum = 0;
$tnum++;
$result = mysql_query("SELECT $id_f,$name_f FROM $name_t WHERE (id<>1 and id<>2 and id<>3) and $parent_f=$id ORDER BY $name_f");
while($row = mysql_fetch_assoc($result))
{
$cates[$row[$id_f]] = str_repeat("|_",$tnum-1)."|___ ".$row[$name_f];
getAllCats($row[$id_f]);
}
$tnum = $tnum-1;
return $cates;
}
//////////////////////////////////////////////////////////////////////////////////
function getCatPath($catid=0) {
//$options="";
$query = "SELECT * FROM tblpages WHERE id='$catid'";
if (!$result = MYSQL_QUERY($query) ) die('query failed: '.mysql_error());
$row = MYSQL_FETCH_ASSOC($result);
if($row){
$options = getCatPath($row[subid]) . ' >> ' .$row['nameAr'];
}
return $options;
}
//////////////////////////////////////////////////////////////////////////////////
?>