+function isvalid_email_redirection($email)
+{
+ return isvalid_email($email) &&
+ !preg_match("/@(polytechnique\.(org|edu)|melix\.(org|net)|m4x\.org)$/", $email);
+}
+
+/** genere une chaine aleatoire de 22 caracteres ou moins
+ * @param $len longueur souhaitée, 22 par défaut
+ * @return la chaine aleatoire qui contient les caractères [A-Za-z0-9+/]
+ */
+function rand_token($len = 22)
+{
+ $len = max(2, $len);
+ $len = min(50, $len);
+ $fp = fopen('/dev/urandom', 'r');
+ // $len * 2 is certainly an overkill,
+ // but HEY, reading 40 bytes from /dev/urandom is not that slow !
+ $token = fread($fp, $len * 2);
+ fclose($fp);
+ $token = base64_encode($token);
+ $token = preg_replace("![Il10O+/]!", "", $token);
+ $token = substr($token,0,$len);
+ return $token;
+}
+
+/** genere une chaine aleatoire convenable pour une url
+ * @param $len longueur souhaitée, 22 par défaut
+ * @return la chaine aleatoire
+ */
+function rand_url_id($len = 22)
+{
+ return rand_token($len);
+}
+
+
+/** genere une chaine aleatoire convenable pour un mot de passe
+ * @return la chaine aleatoire
+ */
+function rand_pass()
+{
+ return rand_token(8);
+}
+
+/** Remove accent from a string and replace them by the nearest letter
+ */
+global $lc_convert, $uc_convert;
+$lc_convert = array('é' => 'e', 'è' => 'e', 'ë' => 'e', 'ê' => 'e',
+ 'á' => 'a', 'à' => 'a', 'ä' => 'a', 'â' => 'a', 'å' => 'a', 'ã' => 'a',
+ 'ï' => 'i', 'î' => 'i', 'ì' => 'i', 'í' => 'i',
+ 'ô' => 'o', 'ö' => 'o', 'ò' => 'o', 'ó' => 'o', 'õ' => 'o', 'ø' => 'o',
+ 'ú' => 'u', 'ù' => 'u', 'û' => 'u', 'ü' => 'u',
+ 'ç' => 'c', 'ñ' => 'n');
+$uc_convert = array('É' => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E',
+ 'Á' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', 'Å' => 'A', 'Ã' => 'A',
+ 'Ï' => 'I', 'Î' => 'I', 'Ì' => 'I', 'Í' => 'I',
+ 'Ô' => 'O', 'Ö' => 'O', 'Ò' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O',
+ 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ü' => 'U',
+ 'Ç' => 'C', 'Ñ' => 'N');
+
+function replace_accent($string)
+{
+ global $lc_convert, $uc_convert;
+ $string = strtr($string, $lc_convert);
+ return strtr($string, $uc_convert);
+}
+
+/** creates a username from a first and last name
+ *
+ * @param $prenom the firstname
+ * @param $nom the last name
+ *
+ * return STRING the corresponding username
+ */
+function make_username($prenom,$nom)
+{
+ /* on traite le prenom */
+ $prenomUS=replace_accent(trim($prenom));
+ $prenomUS=stripslashes($prenomUS);
+
+ /* on traite le nom */
+ $nomUS=replace_accent(trim($nom));
+ $nomUS=stripslashes($nomUS);
+
+ // calcul du login
+ $username = strtolower($prenomUS.".".$nomUS);
+ $username = str_replace(" ","-",$username);
+ $username = str_replace("'","",$username);
+ return $username;