2006-04-26 12:28:53 +00:00
|
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
AlternC - Web Hosting System
|
2012-08-23 18:46:47 +00:00
|
|
|
|
Copyright (C) 2000-2012 by the AlternC Development Team.
|
|
|
|
|
https://alternc.org/
|
2006-04-26 12:28:53 +00:00
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
LICENSE
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License (GPL)
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
Purpose of file: Miscellaneous functions globally used
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* seed the random number generator : */
|
|
|
|
|
list($usec, $sec) = explode(' ', microtime());
|
|
|
|
|
mt_srand((float) $sec + ((float) $usec * 100000));
|
|
|
|
|
|
|
|
|
|
/* Format a field value for input or textarea : */
|
|
|
|
|
function fl($str) { return str_replace("<","<",str_replace("\"",""",$str)); }
|
|
|
|
|
|
2012-08-23 18:46:47 +00:00
|
|
|
|
/* Used by class/m_log.php for usort */
|
2012-08-21 18:25:56 +00:00
|
|
|
|
function compare_logname($a, $b) {
|
|
|
|
|
return strcmp($a['name'],$b['name']);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-26 12:28:53 +00:00
|
|
|
|
/*
|
|
|
|
|
Check if a domain can be hosted on this server :
|
|
|
|
|
Return a negative value in case of an error,
|
|
|
|
|
or a string for the index in $tld
|
|
|
|
|
*/
|
|
|
|
|
function checkhostallow($domain,$dns) {
|
|
|
|
|
global $L_NS1,$L_NS2,$db;
|
|
|
|
|
$sizefound=0;
|
|
|
|
|
$found="";
|
|
|
|
|
$db->query("SELECT tld,mode FROM tld;");
|
|
|
|
|
while ($db->next_record()) {
|
|
|
|
|
list($key,$val)=$db->Record;
|
|
|
|
|
if (substr($domain,-1-strlen($key))==".".$key) {
|
|
|
|
|
if ($sizefound<strlen($key)) {
|
|
|
|
|
$sizefound=strlen($key);
|
|
|
|
|
$found=$key;
|
|
|
|
|
$fmode=$val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$found || $fmode==0) // TLD not allowed at all
|
|
|
|
|
return -1;
|
|
|
|
|
if (($fmode!=4) && (!is_array($dns))) // NO dns found in the whois, and domain MUST exists
|
|
|
|
|
return -2;
|
|
|
|
|
if ($fmode>2) // OK, in the case 3 4 5
|
|
|
|
|
return $found;
|
|
|
|
|
$n1=false; $n2=false;
|
|
|
|
|
for ($i=0;$i<count($dns);$i++) {
|
|
|
|
|
if ($dns[$i]==$L_NS1) $n1=true;
|
|
|
|
|
if ($dns[$i]==$L_NS2) $n2=true;
|
|
|
|
|
}
|
|
|
|
|
if ($fmode==1 && $n1) // OK
|
|
|
|
|
return $found;
|
|
|
|
|
if ($fmode==2 && $n1 && $n2) // OK
|
|
|
|
|
return $found;
|
|
|
|
|
return -3; // DNS incorrect in the whois
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check that a domain can be hosted in that server,
|
|
|
|
|
without DNS managment.
|
|
|
|
|
*/
|
|
|
|
|
function checkhostallow_nodns($domain) {
|
|
|
|
|
global $db;
|
|
|
|
|
$sizefound=0;
|
|
|
|
|
$found="";
|
|
|
|
|
$db->query("SELECT tld,mode FROM tld;");
|
|
|
|
|
while ($db->next_record()) {
|
|
|
|
|
list($key,$val)=$db->Record;
|
|
|
|
|
if (substr($domain,-1-strlen($key))==".".$key) {
|
|
|
|
|
if ($sizefound<strlen($key)) {
|
|
|
|
|
$sizefound=strlen($key);
|
|
|
|
|
$found=$key;
|
|
|
|
|
$fmode=$val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If we found a correct tld, let's find how many . before ;)
|
|
|
|
|
if (!$found || $fmode==0) // TLD not allowed at all
|
|
|
|
|
return 1;
|
|
|
|
|
if (count(explode(".",substr($domain,0,-$sizefound)))>2) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check that $url is a correct url (http:// or https:// or ftp://) */
|
|
|
|
|
function checkurl($url) {
|
|
|
|
|
// TODO : add a path/file check
|
|
|
|
|
if (substr($url,0,7)!="http://" && substr($url,0,8)!="https://" && substr($url,0,6)!="ftp://") return false;
|
|
|
|
|
if (substr($url,0,7)=="http://" ) $fq=substr($url,7);
|
|
|
|
|
if (substr($url,0,8)=="https://") $fq=substr($url,8);
|
|
|
|
|
if (substr($url,0,6)=="ftp://" ) $fq=substr($url,6);
|
|
|
|
|
$f=explode("/",$fq);
|
|
|
|
|
if (!is_array($f)) $f=array($f);
|
|
|
|
|
$t=checkfqdn($f[0]);
|
|
|
|
|
if ($t) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-16 17:11:06 +00:00
|
|
|
|
/* Check that TXT domain is correct */
|
|
|
|
|
function checksubtxt($txt) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/* Check that CNAME domain is correct */
|
|
|
|
|
function checkcname($cname) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-26 12:28:53 +00:00
|
|
|
|
/* Check that $ip is a correct 4 Dotted ip */
|
|
|
|
|
function checkip($ip) {
|
|
|
|
|
// return true or false whether the ip is correctly formatted
|
2010-11-16 17:11:06 +00:00
|
|
|
|
return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
|
2006-04-26 12:28:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-14 16:54:27 +00:00
|
|
|
|
/* Check that $ip is a correct ipv6 ip */
|
|
|
|
|
function checkipv6($ip) {
|
|
|
|
|
// return true or false whether the ip is correctly formatted
|
2010-11-16 17:11:06 +00:00
|
|
|
|
return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
|
2010-11-14 16:54:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 18:46:47 +00:00
|
|
|
|
/* Check a login mail, cf http://www.bortzmeyer.org/arreter-d-interdire-des-adresses-legales.html */
|
|
|
|
|
/* FIXME: check who is using that function and delete it when unused */
|
2006-04-26 12:28:53 +00:00
|
|
|
|
function checkloginmail($mail) {
|
2012-08-23 18:46:47 +00:00
|
|
|
|
return true;
|
2006-04-26 12:28:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 18:46:47 +00:00
|
|
|
|
/* Check an email address, use filter_var with emails, which works great ;) */
|
|
|
|
|
/* FIXME: check who is using that function and delete it when unused */
|
2006-04-26 12:28:53 +00:00
|
|
|
|
function checkmail($mail) {
|
2012-08-23 18:46:47 +00:00
|
|
|
|
if (filter_var($mail,FILTER_VALIDATE_EMAIL)) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
return 1;
|
2006-04-26 12:28:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check that a domain name is fqdn compliant */
|
|
|
|
|
function checkfqdn($fqdn) {
|
2006-04-26 18:28:31 +00:00
|
|
|
|
// (RFC 1035 http://www.ietf.org/rfc/rfc1035.txt)
|
2006-04-26 12:28:53 +00:00
|
|
|
|
// Retourne 0 si tout va bien, sinon, retourne un code erreur...
|
|
|
|
|
// 1. Nom de domaine complet trop long.
|
|
|
|
|
// 2. L'un des membres est trop long.
|
2007-08-27 07:19:10 +00:00
|
|
|
|
// 3. Caractere interdit dans l'un des membres.
|
|
|
|
|
// 4. Le fqdn ne fait qu'un seul membre (il n'est donc pas fq...)
|
2006-04-26 12:28:53 +00:00
|
|
|
|
if (strlen($fqdn)>255)
|
|
|
|
|
return 1;
|
|
|
|
|
$members=explode(".", $fqdn);
|
2007-08-27 07:19:10 +00:00
|
|
|
|
if (count($members)>1) $ret=0; else $ret=4;
|
|
|
|
|
reset($members);
|
|
|
|
|
while (list ($key, $val) = each ($members)) {
|
|
|
|
|
if (strlen($val)>63)
|
|
|
|
|
return 2;
|
2009-04-02 18:33:20 +00:00
|
|
|
|
|
|
|
|
|
// Note: a.foo.net is a valid domain
|
2009-09-08 05:29:38 +00:00
|
|
|
|
// Note: RFC1035 tells us that a domain should not start by a digit, but every registrar allows such a domain to be created ... too bad.
|
2011-06-17 10:32:21 +00:00
|
|
|
|
if (!preg_match("#^[a-z0-9]([a-z0-9-]*[a-z0-9])?$#i",$val)) {
|
2009-04-02 18:33:20 +00:00
|
|
|
|
return 3;
|
2006-04-26 12:28:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-27 07:19:10 +00:00
|
|
|
|
return $ret;
|
2006-04-26 12:28:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkuserpath($path) {
|
|
|
|
|
/*
|
|
|
|
|
return 0 if the path is not in the user's space
|
|
|
|
|
return 1 if this is a directory
|
|
|
|
|
return 2 if this is a regular file
|
|
|
|
|
*/
|
|
|
|
|
global $mem;
|
|
|
|
|
$user=$mem->user["login"];
|
|
|
|
|
$usar=substr($user,0,1);
|
|
|
|
|
if (substr($path,0,1)=="/")
|
|
|
|
|
$path="/".$path;
|
2006-11-27 18:21:17 +00:00
|
|
|
|
|
2012-08-21 17:04:24 +00:00
|
|
|
|
$rpath = realpath(ALTERNC_HTML."/$usar/$user$path");
|
|
|
|
|
$userpath = getuserpath();
|
2006-11-27 18:21:17 +00:00
|
|
|
|
if(strpos($rpath,$userpath) === 0){
|
2012-08-21 17:04:24 +00:00
|
|
|
|
if (is_dir(ALTERNC_HTML."/$usar/$user$path")) {
|
2006-11-27 18:21:17 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2012-08-21 17:04:24 +00:00
|
|
|
|
if (is_file(ALTERNC_HTML."/$usar/$user$path")) {
|
2006-11-27 18:21:17 +00:00
|
|
|
|
return 2;
|
|
|
|
|
}
|
2006-04-26 12:28:53 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 19:59:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* get the home of the user
|
|
|
|
|
*
|
|
|
|
|
* @args string $user the username, if null will use the global $mem. no
|
|
|
|
|
* security checks performed on path
|
|
|
|
|
* @returns string the actual absolute path
|
|
|
|
|
* @see $L_ALTERNC_LOC
|
|
|
|
|
*/
|
|
|
|
|
function getuserpath($user = null) {
|
|
|
|
|
global $L_ALTERNC_LOC;
|
|
|
|
|
if (is_null($user)) {
|
|
|
|
|
global $mem;
|
|
|
|
|
$user = $mem->user['login'];
|
|
|
|
|
}
|
2012-08-21 17:04:24 +00:00
|
|
|
|
return ALTERNC_HTML."/".substr($user,0,1)."/".$user;
|
2007-05-30 19:59:15 +00:00
|
|
|
|
}
|
2006-04-26 12:28:53 +00:00
|
|
|
|
|
2010-04-29 08:31:15 +00:00
|
|
|
|
/* ECHOes checked="checked" only if the parameter is true
|
|
|
|
|
* useful for checkboxes and radio buttons
|
|
|
|
|
*/
|
2006-04-26 12:28:53 +00:00
|
|
|
|
function cbox($test) {
|
|
|
|
|
if ($test) echo (" checked=\"checked\"");
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-29 08:31:15 +00:00
|
|
|
|
|
|
|
|
|
/* ECHOes selected="selected" only if the parameter is true
|
|
|
|
|
* useful for checkboxes and radio buttons
|
|
|
|
|
*/
|
|
|
|
|
function selected($bool) {
|
|
|
|
|
if ($bool) {
|
|
|
|
|
echo " selected=\"selected\"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-26 12:28:53 +00:00
|
|
|
|
function ecif($test,$tr,$fa="") {
|
|
|
|
|
if ($test)
|
|
|
|
|
echo $tr;
|
|
|
|
|
else
|
|
|
|
|
echo $fa;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function __($str) {
|
|
|
|
|
echo _($str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ife($test,$tr,$fa="") {
|
|
|
|
|
if ($test)
|
|
|
|
|
return $tr;
|
|
|
|
|
else
|
|
|
|
|
return $fa;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function format_size($size) {
|
|
|
|
|
// Retourne une taille formatt<74>e en Octets, Kilo-octets, M<>ga-octets ou Giga-Octets, avec 2 d<>cimales.
|
|
|
|
|
if ("-" == $size) {
|
|
|
|
|
return $size;
|
|
|
|
|
}
|
|
|
|
|
$size=(float)$size;
|
|
|
|
|
if ($size<1024) {
|
|
|
|
|
$r=$size;
|
|
|
|
|
if ($size!=1) {
|
|
|
|
|
$r.=" "._("Bytes");
|
|
|
|
|
} else {
|
|
|
|
|
$r.=" "._("Byte");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$size=$size/1024;
|
|
|
|
|
if ($size<1024) {
|
|
|
|
|
$r=round($size,2)." "._("Kb");
|
|
|
|
|
} else {
|
|
|
|
|
$size=$size/1024;
|
|
|
|
|
if ($size<1024) {
|
|
|
|
|
$r=round($size,2)." "._("Mb");
|
|
|
|
|
} else {
|
|
|
|
|
$size=$size/1024;
|
|
|
|
|
if ($size<1024) {
|
|
|
|
|
$r=round($size,2)." "._("Gb");
|
|
|
|
|
} else {
|
|
|
|
|
$r=round($size/1024,2)." "._("Tb");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getlinkhelp($hid) {
|
|
|
|
|
return "(<a href=\"javascript:help($hid);\">?</a>)";
|
|
|
|
|
}
|
|
|
|
|
function linkhelp($hid) {
|
|
|
|
|
echo getlinkhelp($hid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function format_date($format,$date) {
|
|
|
|
|
$d=substr($date,8,2);
|
|
|
|
|
$m=substr($date,5,2);
|
|
|
|
|
$y=substr($date,0,4);
|
|
|
|
|
$h=substr($date,11,2);
|
|
|
|
|
$i=substr($date,14,2);
|
|
|
|
|
if ($h>12) {
|
|
|
|
|
$hh=$h-12;
|
|
|
|
|
$am="pm";
|
|
|
|
|
} else {
|
|
|
|
|
$hh=$h;
|
|
|
|
|
$am="am";
|
|
|
|
|
}
|
|
|
|
|
return sprintf(_($format),$d,$m,$y,$h,$i,$hh,$am);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Strip slashes if needed : */
|
|
|
|
|
function ssla($str) {
|
|
|
|
|
if (get_magic_quotes_gpc()) {
|
|
|
|
|
return stripslashes($str);
|
|
|
|
|
} else {
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------- */
|
|
|
|
|
/** Hashe un mot de passe en clair en MD5 avec un salt al<EFBFBD>atoire
|
|
|
|
|
* @param string $pass Mot de passe <EFBFBD> crypter (max 32 caract<EFBFBD>res)
|
|
|
|
|
* @return string Retourne le mot de passe crypt<EFBFBD>
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function _md5cr($pass,$salt="") {
|
|
|
|
|
if (!$salt) {
|
|
|
|
|
$chars="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
|
for ($i=0;$i<12;$i++) {
|
|
|
|
|
$salt.=substr($chars,(mt_rand(0,strlen($chars))),1);
|
|
|
|
|
}
|
|
|
|
|
$salt="$1$".$salt;
|
|
|
|
|
}
|
|
|
|
|
return crypt($pass,$salt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** split mysql database name between username and custom database name
|
|
|
|
|
* @param string $dbname database name
|
|
|
|
|
* @return array returns username as first element, custom name as second
|
|
|
|
|
*/
|
|
|
|
|
function split_mysql_database_name($dbname) {
|
|
|
|
|
$db_exploded_name = explode("_",$dbname);
|
|
|
|
|
return array($db_exploded_name[0],
|
|
|
|
|
implode("_", array_slice($db_exploded_name, 1)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------- */
|
|
|
|
|
/** Echappe les caract<EFBFBD>res pouvant perturber un flux XML standard :
|
|
|
|
|
* @param string $string Chaine de caract<EFBFBD>re <EFBFBD> encoder en valeur xml.
|
|
|
|
|
* @return string Retourne la cha<EFBFBD>ne modifi<EFBFBD>e si besoin.
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function xml_entities($string) {
|
|
|
|
|
return str_replace("<","<",str_replace(">",">",str_replace("&","&",$string)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------- */
|
|
|
|
|
/** Converti un nombre de mois en une chaine plus lisible
|
|
|
|
|
* @param number $months Nombre de mois
|
|
|
|
|
* @return string Cha<EFBFBD>ne repr<EFBFBD>sentant le nombre de mois
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function pretty_months($months) {
|
|
|
|
|
if( $months % 12 == 0 && $months > 11) {
|
|
|
|
|
$years = $months / 12;
|
|
|
|
|
return "$years " . ($years > 1 ? _("years") : _("year"));
|
|
|
|
|
} else {
|
|
|
|
|
return "$months " . ($months > 1 ? _("months") : _("month"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------- */
|
|
|
|
|
/** Fabrique un drop-down pour les dur<EFBFBD>es de comptes
|
|
|
|
|
* @name string $name Nom pour le composasnt
|
|
|
|
|
* @selected number Option selection<EFBFBD>e du composant
|
|
|
|
|
* @return string Code html pour le drop-down
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function duration_list($name, $selected=0) {
|
2010-04-29 10:27:09 +00:00
|
|
|
|
$res = "<select name=\"$name\" id=\"$name\" class=\"inl\">";
|
2006-04-26 12:28:53 +00:00
|
|
|
|
|
|
|
|
|
foreach(array(0, 1, 2, 3, 4, 6, 12, 24) as $dur) {
|
|
|
|
|
$res .= "<option value=\"$dur\"";
|
|
|
|
|
if($selected == $dur) {
|
|
|
|
|
$res .= ' selected';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res .= '>';
|
|
|
|
|
|
|
|
|
|
if($dur == 0) {
|
|
|
|
|
$res .= _('Not managed');
|
|
|
|
|
} else {
|
|
|
|
|
$res .= pretty_months($dur);
|
|
|
|
|
}
|
|
|
|
|
$res .= '</option>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res .= '</select>';
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-04 16:16:13 +00:00
|
|
|
|
/* select_values($arr,$cur) echo des <option> du tableau $values ou de la table sql $values
|
|
|
|
|
selectionne $current par defaut. Par defaut prends les champs 0 comme id et 1 comme
|
|
|
|
|
donnees pour la table. sinon utilise $info[0] et $info[1].
|
|
|
|
|
*/
|
|
|
|
|
function eoption($values,$cur,$info="") {
|
|
|
|
|
if (is_array($values)) {
|
|
|
|
|
foreach ($values as $k=>$v) {
|
|
|
|
|
echo "<option value=\"$k\"";
|
|
|
|
|
if ($k==$cur) echo " selected=\"selected\"";
|
|
|
|
|
echo ">".$v."</option>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-28 19:28:36 +00:00
|
|
|
|
|
|
|
|
|
/* Echo the HTMLSpecialChars version of a value.
|
|
|
|
|
* Must be called when pre-filling fields values in forms such as :
|
|
|
|
|
* <input type="text" name="toto" value="<?php ehe($toto); ?>" />
|
|
|
|
|
* Use the charset of the current language for transcription
|
|
|
|
|
*/
|
|
|
|
|
function ehe($str) {
|
|
|
|
|
global $charset;
|
|
|
|
|
echo htmlspecialchars($str,ENT_COMPAT,$charset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Get the Fields of the posted form from $_REQUEST or POST or GET
|
|
|
|
|
* and check their type
|
|
|
|
|
*/
|
|
|
|
|
function getFields($fields, $requestOnly = false) {
|
|
|
|
|
$vars = array();
|
2012-08-25 15:34:28 +00:00
|
|
|
|
$methodType = array ("get", "post", "request", "files", "server");
|
2010-04-28 19:28:36 +00:00
|
|
|
|
|
|
|
|
|
foreach ($fields AS $name => $options) {
|
2012-08-25 15:34:28 +00:00
|
|
|
|
if (in_array(strtolower($options[0]), $methodType) === false)
|
|
|
|
|
die ("Unrecognized method type used for field " . $name . " : " . $options[0]);
|
2010-04-28 19:28:36 +00:00
|
|
|
|
|
|
|
|
|
if ($requestOnly === true)
|
|
|
|
|
$method = "_REQUEST";
|
|
|
|
|
else
|
|
|
|
|
$method = "_" . strtoupper($options[0]);
|
|
|
|
|
|
|
|
|
|
switch ($options[1]) {
|
|
|
|
|
case "integer":
|
|
|
|
|
$vars[$name] = (isset($GLOBALS[$method][$name]) && is_numeric($GLOBALS[$method][$name]) ? intval($GLOBALS[$method][$name]) : $options[2]);
|
|
|
|
|
break;
|
|
|
|
|
case "float":
|
|
|
|
|
$vars[$name] = (isset($GLOBALS[$method][$name]) && is_numeric($GLOBALS[$method][$name]) ? floatval($GLOBALS[$method][$name]) : $options[2]);
|
|
|
|
|
break;
|
|
|
|
|
case "string":
|
|
|
|
|
$vars[$name] = (isset($GLOBALS[$method][$name]) ? trim($GLOBALS[$method][$name]) : $options[2]);
|
|
|
|
|
break;
|
|
|
|
|
case "array":
|
|
|
|
|
$vars[$name] = (isset($GLOBALS[$method][$name]) && is_array($GLOBALS[$method][$name]) ? $GLOBALS[$method][$name] : $options[2]);
|
|
|
|
|
break;
|
|
|
|
|
case "boolean":
|
|
|
|
|
$vars[$name] = (isset($GLOBALS[$method][$name]) ? $GLOBALS[$method][$name] : $options[2]);
|
|
|
|
|
break;
|
|
|
|
|
case "file":
|
|
|
|
|
$vars[$name] = (isset($GLOBALS[$method][$name]) ? $GLOBALS[$method][$name] : $options[2]);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
die ("Illegal method type used for field " . $name . " : " . $options[1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 21:05:11 +00:00
|
|
|
|
// Insert into $GLOBALS.
|
2010-04-28 19:28:36 +00:00
|
|
|
|
foreach ($vars AS $var => $value)
|
|
|
|
|
$GLOBALS[$var] = $value;
|
|
|
|
|
|
|
|
|
|
return $vars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function printVar($array) {
|
|
|
|
|
echo "<pre style=\"border: 1px solid black; text-align: left; font-size: 9px\">\n";
|
|
|
|
|
print_r($array);
|
|
|
|
|
echo "</pre>\n";
|
|
|
|
|
}
|
2012-04-06 10:10:36 +00:00
|
|
|
|
function list_properties_order($a, $b) {
|
|
|
|
|
if ( $a['label'] == $b['label']) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return ($a['label']<$b['label'])?-1:1;
|
|
|
|
|
} // end private function list_properties_order
|
2010-04-28 19:28:36 +00:00
|
|
|
|
|
2006-07-21 21:59:16 +00:00
|
|
|
|
|
2012-08-23 18:46:47 +00:00
|
|
|
|
/** Show a pager as
|
|
|
|
|
Previous page 0 1 2 ... 16 17 18 19 20 ... 35 36 37 Next page
|
|
|
|
|
Arguments are as follow :
|
|
|
|
|
$offset = the current offset from 0
|
|
|
|
|
$count = The number of elements shown per page
|
|
|
|
|
$total = The total number of elements
|
|
|
|
|
$url = The url to show for each page. %%offset%% will be replace by the proper offset
|
|
|
|
|
$before & $after are HTML code to show before and after the pager **only if the pager is to be shown**
|
|
|
|
|
*/
|
|
|
|
|
function pager($offset,$count,$total,$url,$before="",$after="") {
|
|
|
|
|
$offset=intval($offset);
|
|
|
|
|
$count=intval($count);
|
|
|
|
|
$total=intval($total);
|
|
|
|
|
if ($offset<=0) $offset="0";
|
|
|
|
|
if ($count<=1) $count="1";
|
|
|
|
|
if ($total<=0) $total="0";
|
|
|
|
|
if ($total<$offset) $offset=max(0,$total-$count);
|
|
|
|
|
|
|
|
|
|
if ($total<=$count) { // When there is less element than 1 complete page, just don't do anything :-D
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
echo $before;
|
|
|
|
|
// Shall-we show previous page link ?
|
|
|
|
|
if ($offset) {
|
|
|
|
|
$o=max($offset-$count,0);
|
|
|
|
|
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-p)\" title=\"(Alt-p)\" accesskey=\"p\">"._("Previous Page")."</a> ";
|
|
|
|
|
} else {
|
|
|
|
|
echo _("Previous Page")." ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($total>(2*$count)) { // On n'affiche le pager central (0 1 2 ...) s'il y a au moins 2 pages.
|
|
|
|
|
echo " - ";
|
|
|
|
|
if (($total<($count*10)) && ($total>$count)) { // moins de 10 pages :
|
|
|
|
|
for($i=0;$i<$total/$count;$i++) {
|
|
|
|
|
$o=$i*$count;
|
|
|
|
|
if ($offset==$o) {
|
|
|
|
|
echo $i." ";
|
|
|
|
|
} else {
|
|
|
|
|
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else { // Plus de 10 pages, on affiche 0 1 2 , 2 avant et 2 apr<70>s la page courante, et les 3 dernieres
|
|
|
|
|
for($i=0;$i<=2;$i++) {
|
|
|
|
|
$o=$i*$count;
|
|
|
|
|
if ($offset==$o) {
|
|
|
|
|
echo $i." ";
|
|
|
|
|
} else {
|
|
|
|
|
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($offset>=$count && $offset<($total-2*$count)) { // On est entre les milieux ...
|
|
|
|
|
// On affiche 2 avant jusque 2 apr<70>s l'offset courant mais sans d<>border sur les indices affich<63>s autour
|
|
|
|
|
$start=max(3,intval($offset/$count)-2);
|
|
|
|
|
$end=min(intval($offset/$count)+3,intval($total/$count)-3);
|
|
|
|
|
if ($start!=3) echo " ... ";
|
|
|
|
|
for($i=$start;$i<$end;$i++) {
|
|
|
|
|
$o=$i*$count;
|
|
|
|
|
if ($offset==$o) {
|
|
|
|
|
echo $i." ";
|
|
|
|
|
} else {
|
|
|
|
|
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($end!=intval($total/$count)-3) echo " ... ";
|
|
|
|
|
} else {
|
|
|
|
|
echo " ... ";
|
|
|
|
|
}
|
|
|
|
|
for($i=intval($total/$count)-3;$i<$total/$count;$i++) {
|
|
|
|
|
$o=$i*$count;
|
|
|
|
|
if ($offset==$o) {
|
|
|
|
|
echo $i." ";
|
|
|
|
|
} else {
|
|
|
|
|
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
echo " - ";
|
|
|
|
|
} // More than 10 pages?
|
|
|
|
|
}
|
|
|
|
|
// Shall-we show the next page link ?
|
|
|
|
|
if ($offset+$count<$total) {
|
|
|
|
|
$o=$offset+$count;
|
|
|
|
|
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-s)\" title=\"(Alt-s)\" accesskey=\"s\">"._("Next Page")."</a> ";
|
|
|
|
|
} else {
|
|
|
|
|
echo _("Next Page")." ";
|
|
|
|
|
}
|
|
|
|
|
echo $after;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-24 10:31:57 +00:00
|
|
|
|
function create_pass($length = 8){
|
|
|
|
|
|
|
|
|
|
$chars = "1234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
|
$i = 0;
|
|
|
|
|
$password = "";
|
|
|
|
|
while ($i <= $length) {
|
|
|
|
|
$password .= @$chars{mt_rand(0,strlen($chars))};
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
return $password;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 18:46:47 +00:00
|
|
|
|
|
|
|
|
|
|
2006-04-26 12:28:53 +00:00
|
|
|
|
?>
|