public function test_ensure_ascii() { $this->assertEquals(ensure_ascii("et oui \n é non\n"), "et oui \n e non\n"); $this->assertEquals(ensure_ascii("et oui \r é non\r"), "et oui \r e non\r"); $this->assertEquals(ensure_ascii("et oui \r\n é non\r\n"), "et oui \r\n e non\r\n"); $this->assertEquals(ensure_ascii("et oui é non"), "et oui e non"); $utf8_str = file_get_contents(dirname(__FILE__) . "/../tools/utf8_str.txt"); $ascii_str = file_get_contents(dirname(__FILE__) . "/../tools/ascii_str.txt"); $this->assertEquals(ensure_ascii($utf8_str), $ascii_str); $iso_str = file_get_contents(dirname(__FILE__) . "/../tools/iso-8859-1_str.txt"); $this->assertEquals(ensure_ascii($iso_str), $ascii_str); }
/** fonction retournant une chaine encodée pour le download d'un CSV * * @param string $texte_csv * @return string La chaine encodée */ function echo_csv_encoded($texte_csv) { // D'après http://www.oxeron.com/2008/09/15/probleme-daccent-dans-un-export-csv-en-php //$retour=$texte_csv; //$retour=chr(255).chr(254).mb_convert_encoding($texte_csv, 'UTF-16LE', 'UTF-8'); $choix_encodage_csv = getPref($_SESSION['login'], "choix_encodage_csv", ""); if (!in_array($choix_encodage_csv, array("", "ascii", "utf-8", "windows-1252"))) { $choix_encodage_csv = "ascii"; } if ($choix_encodage_csv == "") { if ($_SESSION['statut'] == 'administrateur') { $retour = $texte_csv; } else { //$retour=mb_convert_encoding($texte_csv, 'ASCII', 'utf-8'); //$retour=remplace_accents($texte_csv,'csv'); // Les autres utilisateurs preferont sans doute ca: $retour = mb_convert_encoding($texte_csv, "windows-1252", 'utf-8'); } } else { if ($choix_encodage_csv == "ascii") { //echo "=======================================<br />\n"; //echo $texte_csv; $retour = ensure_ascii($texte_csv); //echo "=======================================<br />\n"; //echo $retour; //echo "=======================================<br />\n"; } else { $retour = mb_convert_encoding($texte_csv, $choix_encodage_csv, 'utf-8'); } } return $retour; }
if((getSettingAOui('sso_cas_table'))&&(isset($_POST['login_sso']))) { $enregistrer_sso_corresp="y"; if($_POST['login_sso']!="") { $sql="SELECT login_gepi FROM sso_table_correspondance WHERE login_sso='".$_POST['login_sso']."' AND login_gepi!='$user_login';"; $res_sso=mysqli_query($GLOBALS["mysqli"], $sql); if(mysqli_num_rows($res_sso)>0) { $lig_sso=mysqli_fetch_object($res_sso); $sql="SELECT * FROM utilisateurs WHERE login='******';"; $test_user=mysqli_query($GLOBALS["mysqli"], $sql); if(mysqli_num_rows($test_user)>0) { $lig_user=mysqli_fetch_object($test_user); $msg.="ANOMALIE : La correspondance SSO proposée ".$_POST['login_sso']." est déjà attribuée "; if($lig_user->statut=="eleve") { $msg.=" à l'élève <a href='edit_eleve.php?filtrage=afficher&critere_recherche=".preg_replace("/[^A-Za-z]/","%",ensure_ascii($lig_user->nom))."' target='_blank'>".$lig_sso->login_gepi."</a>"; } elseif($lig_user->statut=="responsable") { $msg.=" au responsable <a href='edit_responsable.php?filtrage=afficher&critere_recherche_login="******"' target='_blank'>".$lig_sso->login_gepi."</a>"; } else { $msg.=" au personnel <a href='modify_user.php?user_login="******"' target='_blank'>".$lig_sso->login_gepi."</a>"; } $msg.="<br />Vous devriez faire le ménage pour ne conserver qu'une seule association.<br />"; $enregistrer_sso_corresp="n"; } else { $sql="DELETE FROM sso_table_correspondance WHERE login_gepi='".$lig_sso->login_gepi."';"; $menage=mysqli_query($GLOBALS["mysqli"], $sql); $msg.="Suppression d'une scorie :<br />La correspondance SSO proposée ".$_POST['login_sso']." était associée au login ".$lig_sso->login_gepi." qui n'existe plus dans la table 'utilisateurs'.<br />"; }