* */ /** * 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(); } /** * 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; } /** * 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'] = ""; } } } /** * 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))); $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,3}$",$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) { // show a var with personnal formating // It allow you to add formating action for showing the var return stripslashes($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 == "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 = ""._ADMIN." "; $step3 = _SHIPPER_LIST_SHORT; $step4 = ""; } if($page == "models") { $step2 = ""._ADMIN." "; $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 == "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 = ""._ADMIN." "; $step3 = ""._MODELS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "model_add") { $step2 = ""._ADMIN." "; $step3 = ""._MODELS_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "types") { $step2 = ""._ADMIN." "; $step3 = _DOCTYPES_LIST_SHORT; $step4 = ""; } if($page == "types_up") { $step2 = ""._ADMIN." "; $step3 = ""._DOCTYPES_LIST_SHORT.""; $step4 = _MODIFICATION; } if($page == "types_add") { $step2 = ""._ADMIN." "; $step3 = ""._DOCTYPES_LIST_SHORT.""; $step4 = _ADDITION; } if($page == "courrier") { $step2 = _VALIDATION; $step3 = ""; $step4 = ""; } if($page == "stats") { $step2 = _STATS; $step3 = ""; $step4 = ""; } if($page == "mail_process") { $step2 = _PROCESS_SHORT; $step3 = ""; $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") { return $ar_date[2]."/".$ar_date[1]."/".$ar_date[0]; } else { return $ar_date[2]."/".$ar_date[1]."/".$ar_date[0]." ".$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'] = ""; } } } } } /** * 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") { return _JANUARY; } elseif($num_month == "02") { return _FEBRUARY; } elseif($num_month == "03") { return _MARCH; } elseif($num_month == "04") { return _APRIL; } elseif($num_month == "05") { return _MAY; } elseif($num_month == "06") { return _JUNE; } elseif($num_month == "07") { return _JULY; } elseif($num_month == "08") { return _AUGUST; } elseif($num_month == "09") { return _SEPTEMBER; } elseif($num_month == "10") { return _OCTOBER; } elseif($num_month == "11") { return _NOVEMBER; } elseif($num_month == "12") { return _DECEMBER; } } /** * 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; } } ?>