* @author Loic Vinet */ /** * Class docserver : contains all the various functions of this application * * @author Claire Figueras * @license GPL * @package Maarch LetterBox 2.3 * @version 2.3 */ class functions { /** * * @access private * @var string */ private $f_page; /** * To calculate the page generation page * * @access private * @var integer */ private $start_page; // to calculate the page generation page //private $insert_page; // state of the insert page /** * Obtains the micro time to calculate the page generation page * */ private function getmicrotime() { // obtains the micro time to calculate the page generation page list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } /** * Start the loading page calculation * */ public function start_page_stat() { // start the loading page calculation $this->start_page = $this->getmicrotime(); } /** * Cut a string with maximum char to displayed * * @param string $string string value * int $max char allowed to show */ public function cut_string($string, $max) { if (strlen($string) >= $max) { $string = substr($string, 0, $max); $espace = strrpos($string, " "); $string = substr($string, 0, $espace)."..."; return $string; } else { return $string; } } /** * Cut a string with maximum char to displayed * * @param string $string string value * int $max char allowed to show */ public function string_notes($string, $max) { if(strlen($string) >= $max) { $cpt_concat=1; $string_array = array(); $total_cpt = strlen($string)/$max; $final_string = ""; for($cpt_str=0;$cpt_str<$total_cpt;$cpt_str++) { $string_tmp = ""; if($cpt_concat == 1) { $string_tmp = substr($string, 0, $max); } else { $deb = $max * $cpt_concat; $string_tmp = substr($string, $deb, $max); } $string_array[$cpt_concat] = $string_tmp; $final_string .= "\n".$string_tmp; $cpt_concat++; } return $final_string; } else { return $string; } } /** * Stop the loading page calculation and show it into the page * */ public function show_page_stat() { // Stop the loading page calculation and show it into the page $end_page = $this->getmicrotime(); $page_total = round($end_page - $this->start_page,3); if($page_total > 1) { $page_secondes = _SECONDS; } else { $page_secondes = _SECOND; } echo _PAGE_GENERATED_IN." ".$page_total." ".$page_secondes; } function getEaster ($iYear = null) { if (is_null ($iYear)) { $iYear = (int)date ('Y'); } $iN = $iYear - 1900; $iA = $iN%19; $iB = floor (((7*$iA)+1)/19); $iC = ((11*$iA)-$iB+4)%29; $iD = floor ($iN/4); $iE = ($iN-$iC+$iD+31)%7; $iResult = 25-$iC-$iE; if ($iResult > 0) { $iEaster = strtotime ($iYear.'/04/'.$iResult); } else { $iEaster = strtotime ($iYear.'/03/'.(31+$iResult)); } return $iEaster; } /** * * * */ function getNextOpenDay ($iDate, $iDays) { $aBankHolidays = array ( '1_1', '1_5', '8_5', '14_7', '15_8', '1_11', '11_11', '25_12' ); if (function_exists ('easter_date')) { $iEaster = easter_date ((int)date('Y'), $iDate); } else { $iEaster = getEaster ((int)date('Y'), $iDate); } $aBankHolidays[] = date ('j_n',$iEaster); $aBankHolidays[] = date ('j_n', $iEaster + (86400*39)); $aBankHolidays[] = date ('j_n', $iEaster + (86400*49)); //print_r ($aBankHolidays); $iEnd = $iDays * 86400; $i = $iDate; while ($i < $iEnd) { $i = strtotime('+1 day', $i); if (in_array (date ('w', $iDate+$i),array (0,6) ) || in_array (date ('j_n', $iDate+$i), $aBankHolidays)) { $iEnd = strtotime ('+1 day', $iEnd); $iDays ++; } } return $iDays; } /** * Configure the actual position of the visitor with all query strings to go to the right page after the logging action * * @param string $index "index.php?" by default */ public function configPosition($index ="index.php?") { // Configure the actual position of the visitor with all query strings // to go to the right page after the logging action $querystring = $_SERVER['QUERY_STRING']; $tab_query = explode("&",$querystring); $querystring = ""; for($i=0;$i "css" && substr($tab_query[$i],0,3) <> "CSS") { $querystring .= $tab_query[$i]."&"; } } $querystring = substr($querystring,0,strlen($querystring)-1); $_SESSION['position'] = $index.$querystring; } /** * Add en error to the errors log * * @param string $msg message to add * @param string $var lang dependant message */ public function add_error($msg,$var) { // Add en error to the errors log $msg = trim($msg); if(!empty($msg)) { $_SESSION['error'] .= $msg." ".$var."
"; if(strlen(str_replace(array("
","
"),"",$_SESSION['error'])) < 6) { $_SESSION['error'] = ""; } } } /** * Show list letter or not if we have acces to one user * * @param string $link link to use * @param string $letter what letter to find * @param string $type user or service? */ public function exist_user_letter($link,$letter,$type) { $db = new dbquery(); $db -> connect(); //extract string for available services $user_access = ''; $current_basket_services = $_SESSION['current_basket']['redirect_services']; $current_basket_services = str_replace("'","",$current_basket_services); $brute_access = explode(",",$current_basket_services); if (count($brute_access) <> 0) { for($t=0; $tquery("SELECT count('user_id') as total from ".$_SESSION['tablename']['users']." where LASTNAME LIKE '".$letter."%' AND DEPARTMENT IN (".$user_access.") AND ENABLED = 'Y' "); //$db->show(); $result = $db->fetch_object(); if ($result->total > 0) //echo $result->total; { return "".$letter.""; } else { return $letter; } } else { $db->query("SELECT count('user_id') as total from ".$_SESSION['tablename']['users']." where DEPARTMENT LIKE '".$letter."%' AND DEPARTMENT IN (".$user_access.")"); //$db->show(); $result = $db->fetch_object(); //echo $result->total; if ($result->total > 0) { return "".$letter.""; } else { return $letter; } } } else { return $letter; } } public function exist_user_letter_for_index($link,$letter,$type) { $db = new dbquery(); $db -> connect(); //extract string for available services $user_access = ''; if (count($_SESSION['user']['services']) <> 0) { for($t=0; $tquery("SELECT count('user_id') as total from ".$_SESSION['tablename']['users']." where LASTNAME LIKE '".$letter."%' AND DEPARTMENT IN (".$user_access.")"); //$db->show(); $result = $db->fetch_object(); //echo $result->total; if ($result->total > 0) { return "".$letter.""; } else { return $letter; } } else { $db->query("SELECT count('user_id') as total from ".$_SESSION['tablename']['users']." where DEPARTMENT LIKE '".$letter."%' AND DEPARTMENT IN (".$user_access.")"); //$db->show(); $result = $db->fetch_object(); //echo $result->total; if ($result->total > 0) { return "".$letter.""; } else { return $letter; } } } else { return $letter; } } /** * Clean the var with multiple possibility * * @param string $what variable to wash * @param string $mask mask, "no" by default * @param string $msg_error error message, empty by default * @param string $empty "yes" by default * @param integer $min_limit empty by default * @param integer $max_limit empty by default * @return string clean variable or empty string */ public function wash($what, $mask = "no", $msg_error = "", $empty = "yes", $min_limit = "", $max_limit = "") { // Clean the var with multiple possibility //$w_var = addslashes(trim(strip_tags($what))); $w_var = trim(strip_tags($what)); $test_empty = "ok"; if($empty == "yes") { // We use strlen instead of the php's empty function because for a var containing 0 return by a form (in string format) // the empty function return that the var is empty but it contains à 0 if(strlen($w_var) == 0) { $test_empty = "no"; } else { $test_empty = "ok"; } } if($test_empty == "no") { $this->add_error($msg_error, _IS_EMPTY); return ""; } else { if($msg_error <> '') { if($min_limit <> "") { if(strlen($w_var) < $min_limit) { if($min_limit > 1) { $this->add_error($msg_error, _MUST_MAKE_AT_LEAST." ".$min_limit." "._CHARACTERS); } else { $this->add_error($msg_error, _MUST_MAKE_AT_LEAST." ".$min_limit." "._CHARACTER); } return ""; } } } if($max_limit <> "") { if(strlen($w_var) > $max_limit) { if($min_limit > 1) { $this->add_error($msg_error, MUST_BE_LESS_THAN." ".$max_limit." "._CHARACTERS); } else { $this->add_error($msg_error, MUST_BE_LESS_THAN." ".$max_limit." "._CHARACTER); } return ""; } } switch ($mask) { case "no": return $w_var; case "num": if (ereg("^[0-9]+$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } case "letter": if (ereg("^[a-zA-Z]+$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } case "alphanum": if (ereg("^[a-zA-Z0-9]+$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } case "nick": if (ereg("^[_a-zA-Z0-9.-]+$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } case "mail": if (ereg("^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } case "url": if (ereg("^[www.]+[_a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } case "file": if (ereg("^[_a-zA-Z0-9.-? /&é]+$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } case "name": if (ereg("^[_a-zA-Z0-9.-? \'/&éea]+$",$w_var)) { return $w_var; } else { $this->add_error($msg_error, _WRONG_FORMAT); return ""; } } } } /** * Show a var with personnal formating. It allow you to add formating action for showing the var * * @param string $what variable to show * @return string variable without slashes */ public function show($what,$limit=0) { if($limit <= 0) //No limit : strip slashes return stripslashes($what); else //Specified limit : add space and dash for each word which overflows the limit + 1 return stripslashes(utf8_encode(preg_replace('/([\S]{'.($limit).'})([\S]{1})/','$1- -$2',utf8_decode($what) )) ); } /** * Indicate where in site the visitor where situated * */ public function where_am_i() { // Indicate where in site the visitor where situated if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = ""; } $step1 = "".$_SESSION['config']['applicationname'].""; $step2 = ""; $step3 = ""; $step4 = ""; if($page == "") { $step2 = ""._WELCOME.""; $step3 = ""; $step4 = ""; } if($page == "help") { $step2 = ""._HELP.""; $step3 = ""; $step4 = ""; } if($page == "maarch_advance") { $step2 = ""._HELP.""; $step3 = _MAARCH_INTEGRATION; $step4 = ""; } if($page == "guide1") { $step2 = ""._HELP.""; $step3 = _QUICK_GUIDE.' : '._SUMMARY; $step4 = ""; } if($page == "guidelogin") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."1"; } if($page == "guide2") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."2.1"; } if($page == "guide3") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."2.2"; } if($page == "guide4") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."2.3"; } if($page == "guide5") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."3"; } if($page == "guide6") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."4"; } if($page == "guide7") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."4"; } if($page == "guide8") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."5.1"; } if($page == "guide9") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."5.2"; } if($page == "guide10") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."5.3"; } if($page == "guide11") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."6"; } if($page == "guide12") { $step2 = ""._HELP.""; $step3 = ""._QUICK_GUIDE.""; $step4 = _CHAPTER_SHORT."6"; } if($page == "search_adv") { $step2 = ""._SEARCH_ADV_SHORT.""; $step3 = ""; $step4 = ""; } if($page == "details") { $step2 =_DETAILS; $step3 = ""; $step4 = ""; } if($page == "modify_user") { $step2 = _USER_MODIFICATION; $step3 = ""; $step4 = ""; } if($page == "dir") { $step2 = _BROWSE_BY_FOLDER; $step3 = ""; $step4 = ""; } if($page == "folders") { $step2 = _MY_FOLDERS; $step3 = ""; $step4 = ""; } if($page == "search_adv_result") { $step2 = ""._SEARCH_ADV_SHORT.""; $step3 = _SEARCH_ADV_SHORT; $step4 = ""; } if($page == "search") { $step2 = ""._QUICKSEARCH.""; $step3 = _SEARCH_ADV_SHORT; $step4 = ""; } if($page == "admin") { $step2 = _ADMIN; $step3 = ""; $step4 = ""; } if($page == "hist") { $step2 = ""._ADMIN." "; $step3 = _VIEW_HISTORY; $step4 = ""; } if($page == "files") { $step2 = ""._INDEXING.""; $step3 = ""; $step4 = ""; } if($page == "users") { $step2 = ""._ADMIN." "; $step3 = _USERS_LIST_SHORT; $step4 = ""; } if($page == "emet") { $step2 = ""._PARAM." "; $step3 = _SHIPPER_LIST_SHORT; $step4 = ""; } if($page == "models") { $step2 = ""._PARAM." "; $step3 = _MODELS_LIST_SHORT; $step4 = ""; } if($page == "groups") { $step2 = ""._ADMIN." "; $step3 = _GROUPS_LIST_SHORT; $step4 = ""; } if($page == "liste") { $step2 = ""._ADMIN." "; $step3 = _DEPARTMENTS_LIST_SHORT; $step4 = ""; } if($page == "basket") { $step2 = ""._ADMIN." "; $step3 = _BASKETS_LIST; $step4 = ""; } if($page == "basket_add") { $step2 = ""._ADMIN." "; $step3 = ""._BASKETS_LIST." "; $step4 = _ADDITION; } if($page == "basket_up") { $step2 = ""._ADMIN." "; $step3 = ""._BASKETS_LIST." "; $step4 = _MODIFICATION; } if($page == "coll") { $step2 = ""._ADMIN." "; $step3 = _COLL_LIST; $step4 = ""; } if($page == "coll_up") { $step2 = ""._ADMIN." "; $step3 = ""._COLL_LIST." "; $step4 = _COLL_MODIFICATION; } if($page == "emet_add") { $step2 = ""._ADMIN." "; $step3 = "Liste émetteurs "; $step4 = _ADDITION; } if($page == "emet_up") { $step2 = ""._ADMIN." "; $step3 = "Liste émetteurs "; $step4 = _MODIFICATION; } if($page == "group_add") { $step2 = ""._ADMIN." "; $step3 = ""._GROUPS_LIST_SHORT.""; $step4 = _ADDITION; } if($page == "users_add") { $step2 = ""._ADMIN." "; $step3 = ""._USERS_LIST_SHORT." "; $step4 = _ADDITION; } if($page == "group_up") { $step2 = ""._ADMIN." "; $step3 = ""._GROUPS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "users_up") { $step2 = ""._ADMIN." "; $step3 = ""._USERS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "service_up") { $step2 = ""._ADMIN." "; $step3 = ""._DEPARTMENTS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "service_add") { $step2 = ""._ADMIN." "; $step3 = ""._DEPARTMENTS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "model_up") { $step2 = ""._PARAM." "; $step3 = ""._MODELS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "model_add") { $step2 = ""._ADMIN." "; $step3 = ""._MODELS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "types") { $step2 = ""._PARAM." "; $step3 = _DOCTYPES_LIST_SHORT; $step4 = ""; } if($page == "types_up") { $step2 = ""._PARAM." "; $step3 = ""._DOCTYPES_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "types_add") { $step2 = ""._ADMIN." "; $step3 = ""._DOCTYPES_LIST_SHORT.""; $step4 = _ADDITION; } if($page == "ldap_param") { $step2 = ""._ADMIN." "; $step3 = _CONFIG_LDAP; $step4 = ""; } if($page == "courrier") { $step2 = _VALIDATION; $step3 = ""; $step4 = ""; } if($page == "stats") { $step2 = _STATS; $step3 = ""; $step4 = ""; } if($page == "mail_process") { $step2 = _PROCESS_SHORT; $step3 = ""; $step4 = ""; } if($page == "sender") { $step2 = ""._PARAM." "; $step3 = _SENDER_LIST_SHORT; $step4 = ""; } if(empty($step2)) { echo $step1." > "; } else { if(empty($step3)) { echo $step1." > ".$step2; } else { if(empty($step4)) { echo $step1." > ".$step2." > ".$step3; } else { echo $step1." > ".$step2." > ".$step3." > ".$step4; } } } } /** * Clean the page var and look if she exists or not before including her * */ public function insert_page() { // clean the page var and look if she exists or not before including her if(isset($_GET['page'])) { $this->f_page = $this->wash($_GET['page'],"file","","yes"); } else { $this->f_page = "step1"; } if(file_exists($this->f_page.".php")) { require($this->f_page.".php"); } else { require($_SESSION["config"]["defaultPage"].".php"); } } /** * For the debug, show completly an array * * @param array $arr */ public function show_array($arr) { // For the debug, show completly an array echo "
"; echo "
";
		print_r($arr);
		echo "
"; echo "
"; } /** * Format a datetime to a dd/mm/yyyy format (date) * * @param datetime $date a date * @return datetime the formatted date */ public function format_date($date) { // Format a datetime to a dd/mm/yyyy format if(strpos($date," ")) { $date_ex = explode(" ",$date); $the_date = explode("-",$date_ex[0]); $last_date = $the_date[2]."/".$the_date[1]."/".$the_date[0]; } else { $the_date = explode("-",$date); $last_date = $the_date[2]."/".$the_date[1]."/".$the_date[0]; } return $last_date; } /** * Format a datetime to a dd/mm/yyyy hh:ii:ss format (timestamp) * * @param datetime $date a date * @return datetime the formatted date */ public function dateformat($date) { // Format a datetime to a dd/mm/yyyy hh:ii:ss format $ar_test = explode(" ",$date); $date = $ar_test[0]; $time = $ar_test[1]; $ar_date = explode("-",$date); if(substr($ar_test[1],0,2) == "00") { if(ereg( "^[1-2][0-9][0-9][0-9]$",$ar_date[0])) { return $ar_date[2]."/".$ar_date[1]."/".$ar_date[0]; } else { return $date; } } else { if(ereg( "^[1-2][0-9][0-9][0-9]$",$ar_date[0])) { return $ar_date[2]."/".$ar_date[1]."/".$ar_date[0]." ".$time; } else { return $date." ".$time; } } } /** * Write an error in pre formating format with header and footer * * @param string $title the title * @param string $message the message */ public function echo_error($title,$message) { // Write an error in pre formating format with header and footer ?> ".$title.""; ?>

 

 

 

 

 

 

12) { $_SESSION['error'] .= _BAD_MONTH_FORMAT.".
"; $_SESSION['monthstart'] = ""; } if($day > 31) { $_SESSION['error'] .= _BAD_DAY_FORMAT.".
"; $_SESSION['daystart'] = ""; } else { if($month == "2" || $month == "02") { if($day > 29) { $_SESSION['error'] .= _BAD_FEBRUARY.".
"; $_SESSION['daystart'] = ""; } } else { if($month == 2 || $month == 4 || $month == 6 || $month == 9 || $month == 11) { if($day > 30) { $_SESSION['error'] .= _BAD_DAY_FORMAT."t.
"; $_SESSION['daystart'] = ""; } } } } } /** * Add days in a date * * $current_date datetime -date to convert * $n_day int -nomber of days to add at the curent_date * * return a new timestamp * @author Loic Vinet */ public function add_days_in_date($current_date,$n_day) { $date = new DateTime($current_date); $date->modify("+".$n_day." day"); return $date->format("Y-m-d"); } /** * White a var with a label if the var is not empty * * @param string $what the variable * @param string $$label the label */ public function writeifnotempty($what,$label) { // White a var with a label if the var is not empty if(!empty($what)) { echo "".$label." : ".$what."
"; } } /** * Extract the user info from database and put the result in an array * * @param integer $id user identifier */ public function infouser($id) { // Extract the user info from database and put the result in an array $conn = new dbquery(); $conn->connect(); $conn->query("select * from ".$_SESSION['tablename']['users']." where User_Id = '".$id."'"); if($conn->nb_result() == 0) { return array("UserId" => "", "FirstName" => "", "LastName" => "", "Phone" => "", "Mail" => "", "department" => "", ); } else { $ligne = $conn->fetch_object(); return array("UserId" => $ligne->USER_ID, "FirstName" => $ligne->FIRSTNAME, "LastName" => $ligne->LASTNAME, "Phone" => $ligne->PHONE, "Mail" => $ligne->MAIL, "department" => $ligne->DEPARTMENT, ); } } /** * Inverse a date (fr ->en and en->fr) * * @param date $date1 date to inverse */ public function inverse_date($date1) { $tab = array(); $tab = explode("-", $date1); $date2= ""; $date2 = $tab[2]."-".$tab[1]."-".$tab[0]; return $date2; } /** * Update the parameters table * * @param string $key1 first key * @param string $key2 second key * @param string $key3 third key */ public function update_parameter($key1,$key2,$key3) { $req="SELECT value FROM ".$_SESSION['tablename']['param']." WHERE key1='".$key1."' AND key2='".$key2."' AND key3='".$key3."'"; $conn = new dbquery(); $conn->connect(); $conn->query($req); if($conn->nb_result() < 1 ) { return ""; } else { $res = $conn->fetch_object(); $val=$res->value; $val=$val+1; $req="UPDATE ".$_SESSION['tablename']['param']." SET value='".$val."' WHERE key1='".$key1."' AND key2='".$key2."' AND key3='".$key3."'"; $conn->query($req); return $val; } } /** * Return the month name * * @param string $num_month month in digits */ public function get_month_name($num_month) { if($num_month == "01" || $num_month == 1) { return _JANUARY; } elseif($num_month == "02" || $num_month == 2) { return _FEBRUARY; } elseif($num_month == "03" || $num_month == 3) { return _MARCH; } elseif($num_month == "04" || $num_month == 4) { return _APRIL; } elseif($num_month == "05" || $num_month == 5) { return _MAY; } elseif($num_month == "06" || $num_month == 6) { return _JUNE; } elseif($num_month == "07" || $num_month == 7) { return _JULY; } elseif($num_month == "08" || $num_month == 8) { return _AUGUST; } elseif($num_month == "09"|| $num_month == 9) { return _SEPTEMBER; } elseif($num_month == "10" || $num_month == 10) { return _OCTOBER; } elseif($num_month == "11" || $num_month == 11) { return _NOVEMBER; } elseif($num_month == "12" || $num_month == 12) { return _DECEMBER; } else { return _UNDEFINED; } } /** * Is the current user allowed to the given basket * * @param string $basket_id the identifier of a basket */ public function user_has_basket($basket_id) { for($i=0; $i $_SESSION['config']['cookietime']) { $time = $_SESSION['config']['cookietime']; } else { $time = ini_get('session.cache_expire'); } return $time; } public function get_nb_days_in_month($month, $year) { if($month == '01' || $month == 1 || $month == '03' || $month == 3 || $month == '05' || $month == 5 || $month == '07' || $month == 7 || $month == '08' || $month == 8 || $month == '10' || $month == 10 || $month == '12' || $month == 12) { return 31; } elseif($month == '02' || $month == 2) { if($this->is_leap_year($year)) { return 29; } else { return 28; } } elseif($month == '04' || $month == 4 || $month == '06' || $month == 6 || $month == '09' || $month == 9 || $month == '11' || $month == 11) { return 30; } } public function is_leap_year($year) { $year_int = (int) $year; if($year_int % 4 == 0 && $year_int % 100 > 0) { return true; } else { if($year_int % 400 == 0) { return true; } else { return false; } } } /** * Checks if a directory is empty * * @param $dir string The directory to check * @return bool True if empty, False otherwise */ function isDirEmpty($dir) { $dir = opendir($dir); $isEmpty = true; while(($entry = readdir($dir)) !== false) { if($entry !== '.' && $entry !== '..') { $isEmpty = false; break; } } closedir($dir); return $isEmpty; } /* * Convert an integer in array bytes (0,1) */ public function dec_to_bytes($value=0,$int_max=null) { $array_bytes = array(); if( !isset($value) || !is_numeric($value) || $value < 0 ) return array(); if( $int_max == null ) $int_max = log($value,2); if( $value > ( pow(2,$int_max) -1 ) ) $value = (pow(2,$int_max) -1); for( $i=0; $i < $int_max ; $i++ ) { if( $value & pow(2,$i) ) $array_bytes[pow(2,$i)] = 1; else $array_bytes[pow(2,$i)] = 0; } return $array_bytes; } /* * Convert an array bytes (0,1) in an integer */ public function bytes_to_dec( $array_bytes=array() ) { $value = 0; foreach($array_bytes as $k_ab => $d_ab) { if($d_ab == 1) $value += $k_ab; } return $value; } /* * Return the date in Ymd format or null for invalid date */ function valid_date($day,$month,$year) { if ( !checkdate($month,$day,$year) ) { return null; } else { return date("Ymd" , mktime(0,0,0,$month,$day,$year) ); } return date("Ymd"); } /** * Convert an object to an array * @param $object object to convert */ public function object2array($object) { $return = NULL; if(is_array($object)) { foreach($object as $key => $value) { $return[$key] = $this->object2array($value); } } else { if(is_object($object)) { $var = get_object_vars($object); if($var) { foreach($var as $key => $value) { $return[$key] = ($key && !$value) ? NULL : $this->object2array($value); } } else return $object; } else return $object; } return $return; } } ?>