Description : History : - 25/3/9 inital version */ /* Create index */ function index($string) { return preg_replace("/[^0-9A-Za-z]/", "_", $string); //return rawurlencode(str_replace(".", "_", $string)); } /* Display menu structure */ function displaymenu($db, $uid, $menu) { global $levelgap, $levelunit; if (!$menu) return; if (!$uid) $uid = -1; /* Start menu list */ echo "\n
\n\n"; } /* Valid login */ function validlogin($db, $validsession, $sid, $login, $password) { global $debug; /* Check session */ if ($sid) { $uid = checksession ($db, $sid, $validsession); debugger (($debug > 1), "checksession returns $uid"); if ($uid < 0) { setcookie("session", $sid, time() - $validsessioni, "/"); /* "/", $_SERVER['HTTP_HOST']); */ if ($login) { $uid = checkuser($db, $login, $password); debugger (($debug > 1), "checkuser returns $uid"); if ($uid >= 0) $sid = addsession($db, $uid, $validsession); } } /* Check login */ } elseif ($login) { $uid = checkuser($db, $login, $password); debugger (($debug > 1), "checkuser returns $uid"); if ($uid >= 0) $sid = addsession($db, $uid, $validsession); /* No login */ } else $uid = -1; /* Set cookie */ if ($uid >= 0) setcookie("session", $sid, time() + $validsession, "/"); /* "/", $_SERVER['HTTP_HOST']); */ return $uid; } /* Remove login */ function removelogin($db, $validsession, $sid) { /* Remove session */ $uid = removesession($db, $sid); /* Remove cookie */ setcookie("session", $sid, time() - $validsession, "/"); /* "/", $_SERVER['HTTP_HOST']); */ /* UID */ return $uid; } /* Find MIME type */ function findmimetype($ext) { switch ($ext) { case "": $ctype = "directory"; break; case "css": $ctype = "text/css"; break; case "doc": $ctype = "application/msword"; break; case "exe": $ctype = "application/octet-stream"; break; case "gif": $ctype = "image/gif"; break; case "html": $ctype = ""; break; case "ico": $ctype = "image/icone"; break; case "jpg": $ctype = "image/jpg"; break; case "pdf": $ctype = "application/pdf"; break; case "php": $ctype = ""; break; case "png": $ctype = "image/png"; break; case "ppt": $ctype = "application/vnd.ms-powerpoint"; break; case "xls": $ctype = "application/vnd.ms-excel"; break; case "zip": $ctype = "application/zip"; break; case "png": $ctype = "image/png"; break; default: $ctype = "application/force-download"; } return $ctype; } /* List documents */ function listdocuments($dirname, $path, $desc) { /* Chek directory type */ if (!is_dir($dirname)) return; /* Open idrectory */ if (!($dh = opendir($dirname))) return; /* Create table */ echo "\n\n\n\n\n"; /* Read all documents to sort them */ $alldocs = array(); while ($doc = readdir($dh)) if (($doc != ".") && ($doc != "..")) $alldocs[] = $doc; sort($alldocs, SORT_STRING); /* One line per document */ foreach ($alldocs as $doc) { $docname = realpath("$dirname/$doc"); setlocale(LC_TIME, 'fr_FR'); $date = strftime ("%e %B %Y %H:%M:%S", fileatime($docname)); $rem = filesize($docname); $sizeunity = array("To", "Go", "Mo", "ko", "octets"); do { $rem = round(($size = $rem) / 1024); $unity = array_pop($sizeunity); } while ($rem > 0); $desciption = $desc[index($doc)]; echo "\n"; } /* Close directory */ closedir($dh); /* Close table */ echo "\n
DocumentDateTailleDescription
$doc$date$size $unity$desciption
\n"; } /* HTML entity protection */ function htmlprotect($string) { return str_replace (array ('&', '<', '>'), array ('&', '<', '>'), $string); } /* Quote protection */ function quoteprotect($string) { return str_replace (array ('"', "'"), array ('"', '''), $string); } /* URL protection */ function urlprotect($string) { if (empty($string)) return "/"; if (($string[0] == "?") || (preg_match("/^[a-z]+:\/\//", strtolower($string)))) return $string; return implode("/", array_map("rawurlencode", explode("/", $string))); } /* List all files */ function listallfiles ($dir, $rp, $allfiles = array()) { $dh = opendir("$rp/$dir"); while ($file = readdir($dh)) { if (preg_match('/^\.+$/', $file)) continue; $allfiles[] = preg_replace("/^\//", "", "$dir/$file"); if (is_dir("$rp/$dir/$file")) $allfiles = listallfiles ("$dir/$file", "$rp", $allfiles); } return $allfiles; } /* Log action */ function logger ($logfile, $login, $msg) { if (empty($logfile)) return; if ($fd = @fopen($logfile, "a")) { //setlocale(LC_TIME, 'fr_FR'); $date = strftime ("%Y/%m/%d %H:%M:%S", time()); fwrite ($fd, $date . " (" . $login . "): " . $msg . "\n"); fclose ($fd); } } /* Log debug */ function debugger ($cond, $msg) { global $debugfile; if (!$cond) return; if (empty($debugfile)) return; if ($fd = @fopen($debugfile, "a")) { //setlocale(LC_TIME, 'fr_FR'); $date = strftime ("%Y/%m/%d %H:%M:%S", time()); fwrite ($fd, "$date: $msg\n"); fclose ($fd); } }