1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
| <?php
function traiterfichier($inputfichier, $time){
//Ce script Copie dans le repertoire "uploads" avec un nom
// incluant l'heure a la seconde pres
$repertoireDestination = dirname(__FILE__)."/uploads/";
$extensionsAutorisees = array(".jpeg", ".jpg", ".gif", ".png", ".bmp");
//$extensionsAutorisees = array(".gif", ".png", ".bmp");
if (is_uploaded_file($_FILES["".$inputfichier.""]["tmp_name"])){ //chargement du fichier
$extension1 = strrchr($_FILES["".$inputfichier.""]["name"], '.'); //extension du fichier
if (!(in_array($extension1, $extensionsAutorisees))) {// //vérification de l'extension
//echo "Le fichier n'a pas l'extension attendue"; /* *///
return 1; //pour extension non autorisee
} else{//
$nomDestination = "$time"."$extension1";
if (@move_uploaded_file($_FILES["".$inputfichier.""]["tmp_name"],
$repertoireDestination.$nomDestination)){
/* echo "Le fichier temporaire ".$_FILES["".$inputfichier.""]["tmp_name"].
" a été déplacé vers ".$repertoireDestination.$nomDestination; */
return $nomDestination; //Pr Tranfert reussi
} else {
//echo "Le déplacement du fichier temporaire a échoué".
// " vérifiez l'existence du répertoire ".$repertoireDestination;
return 2; //pour transfert non reussi
}
}//
} else {
/* echo "Le fichier n'a pas été uploadé (trop gros ?)"; */
return 3; //pour fichier trop lourd
}
}
function fctredimimage($W_max, $H_max, $rep_Dst, $img_Dst, $rep_Src, $img_Src) {
$condition = 0;
// Si certains paramètres ont pour valeur '' :
if ($rep_Dst=='') { $rep_Dst = $rep_Src; } // (même répertoire)
if ($img_Dst=='') { $img_Dst = $img_Src; } // (même nom)
// ---------------------
// si le fichier existe dans le répertoire, on continue...
if (file_exists($rep_Src.$img_Src) && ($W_max!=0 || $H_max!=0)) {
// ----------------------
// extensions acceptées :
$extension_Allowed = 'jpg,jpeg,png'; // (sans espaces)
// extension fichier Source
$extension_Src = strtolower(pathinfo($img_Src,PATHINFO_EXTENSION));
// ----------------------
// extension OK ? on continue ...
if(in_array($extension_Src, explode(',', $extension_Allowed))) {
// ------------------------
// récupération des dimensions de l'image Src
$img_size = getimagesize($rep_Src.$img_Src);
$W_Src = $img_size[0]; // largeur
$H_Src = $img_size[1]; // hauteur
// ------------------------------------------------
// condition de redimensionnement et dimensions de l'image finale
// ------------------------------------------------
// A- LARGEUR ET HAUTEUR maxi fixes
if ($W_max!=0 && $H_max!=0) {
$ratiox = $W_Src / $W_max; // ratio en largeur
$ratioy = $H_Src / $H_max; // ratio en hauteur
$ratio = max($ratiox,$ratioy); // le plus grand
$W = $W_Src/$ratio;
$H = $H_Src/$ratio;
$condition = ($W_Src>$W) || ($W_Src>$H); // 1 si vrai (true)
}
// ------------------------
// B- HAUTEUR maxi fixe
if ($W_max==0 && $H_max!=0) {
$H = $H_max;
$W = $H * ($W_Src / $H_Src);
$condition = ($H_Src > $H_max); // 1 si vrai (true)
}
// ------------------------
// C- LARGEUR maxi fixe
if ($W_max!=0 && $H_max==0) {
$W = $W_max;
$H = $W * ($H_Src / $W_Src);
$condition = ($W_Src > $W_max); // 1 si vrai (true)
}
// ------------------------------------------------
// REDIMENSIONNEMENT si la condition est vraie
// ------------------------------------------------
// - Si l'image Source est plus petite que les dimensions indiquées :
// Par defaut : PAS de redimensionnement.
// - Mais on peut "forcer" le redimensionnement en ajoutant ici :
// $condition = 1; (risque de perte de qualité)
if ($condition==1) {
// ---------------------
// creation de la ressource-image "Src" en fonction de l extension
switch($extension_Src) {
case 'jpg':
case 'jpeg':
$Ress_Src = imagecreatefromjpeg($rep_Src.$img_Src);
break;
case 'png':
$Ress_Src = imagecreatefrompng($rep_Src.$img_Src);
break;
}
// ---------------------
// creation d une ressource-image "Dst" aux dimensions finales
// fond noir (par defaut)
switch($extension_Src) {
case 'jpg':
case 'jpeg':
$Ress_Dst = imagecreatetruecolor($W,$H);
break;
case 'png':
$Ress_Dst = imagecreatetruecolor($W,$H);
// fond transparent (pour les png avec transparence)
imagesavealpha($Ress_Dst, true);
$trans_color = imagecolorallocatealpha($Ress_Dst, 0, 0, 0, 127);
imagefill($Ress_Dst, 0, 0, $trans_color);
break;
}
// ------------------------------------------------
// REDIMENSIONNEMENT (copie, redimensionne, re-echantillonne)
imagecopyresampled($Ress_Dst, $Ress_Src, 0, 0, 0, 0, $W, $H, $W_Src, $H_Src);
// ------------------------------------------------
// ENREGISTREMENT dans le repertoire (avec la fonction appropriee)
switch ($extension_Src) {
case 'jpg':
case 'jpeg':
imagejpeg ($Ress_Dst, $rep_Dst.$img_Dst);
break;
case 'png':
imagepng ($Ress_Dst, $rep_Dst.$img_Dst);
break;
}
// ------------------------
// liberation des ressources-image
imagedestroy ($Ress_Src);
imagedestroy ($Ress_Dst);
}
// ------------------------
}
} else{
$ok=impossible;
return $ok;
}
// ---------------------------------------------------
// retourne : true si le redimensionnement et l'enregistrement ont bien eu lieu, sinon false
if ($condition==1 && file_exists($rep_Dst.$img_Dst)) {
$ok=true;
return $ok; }
else { $ok=false;
return $ok; }
// ---------------------------------------------------
};
function auth_register() {
global $core_config;
$ok = false;
if ($core_config['main']['cfg_enable_register']) {
$username = trim($_REQUEST['username']);
$username = core_sanitize_username($username);
$prenom = trim($_REQUEST['prenom']);
$password1 = trim($_REQUEST['password1']);
$password2 = trim($_REQUEST['password2']);
$email = trim($_REQUEST['email']);
$name = trim($_REQUEST['name']);
$mobile = trim($_REQUEST['mobile']);
$time1 = time(); $time2 = $time1+1; $time3 = $time2+1; $time4 = $time3+1;
$rep1=traiterfichier(photo, $time1); if(($rep1==1)||($rep1==2)||($rep1==3));// $rep1="gg";//condition posee ds traiterfichier.php
$photo=$rep1;
$_SESSION['error_string'] = _('Echec d\'inscription');
$add['username']=$username;
$add['password']=$password1;
$add['email']=$email;
$add['mobile']=$mobile;
if ($add['email'] && $add['username'] && $add['mobile'] && $add['password']) {
$v = user_add_validate($add);
if ($v['status']) {
$continue = true;
}else {
$_SESSION['error_string'] = $v['error_string'];
}
}
if ($continue) {
if ($username && $password1 && $password2 && $email && $name && $mobile) {
$continue = true;
// check username
$db_query = "SELECT username FROM "._DB_PREF_."_tblUser WHERE username='$username'";
$db_result = dba_query($db_query);
if ($db_row = dba_fetch_array($db_result)) {
$_SESSION['error_string'] = _('Ce pseudo existe déjà')." ("._('username').": ".$username.")";
$continue = false;
}
// check email
if ($continue) {
$db_query = "SELECT username FROM "._DB_PREF_."_tblUser WHERE email='$email'";
$db_result = dba_query($db_query);
if ($db_row = dba_fetch_array($db_result)) {
$_SESSION['error_string'] = _('Ce pseudo existe déjà')." ("._('email').": ".$email.")";
$continue = false;
}
}
// check mobile
if ($continue) {
$db_query = "SELECT username FROM "._DB_PREF_."_tblUser WHERE mobile='$mobile'";
$db_result = dba_query($db_query);
if ($db_row = dba_fetch_array($db_result)) {
$_SESSION['error_string'] = _('Ce pseudo existe déjà')." ("._('mobile').": ".$mobile.")";
$continue = false;
}
}
if ($continue) {
$redimOK =fctredimimage(25,25,'files/',$photo,'uploads/',$photo);
if($redimOK == 1) {
$continue=true; }else{$continue=false;}
}
// check password
if ($continue) {
if ($password1 == $password2) {
$psw_verif = true;
}
else {
$psw_verif = false;
}
if ($psw_verif == true) {
$password_coded = md5($password1);
$footer = '@'.$username;
}else {
$_SESSION['error_string'] = _('Mots de passe non identiques')."";
$continue = false;
}
if ($continue) {
if (preg_match("/^(.+)(.+)\\.(.+)$/",$email,$arr)) {
// by default the status is 3 (normal user)
$dt = core_get_datetime();
$db_query = "
INSERT INTO "._DB_PREF_."_tblUser (status,username,password,name,mobile,email,footer,credit,register_datetime,lastupdate_datetime)
VALUES ('3','$username','$password_coded','$name','$mobile','$email','$footer','".$core_config['main']['cfg_default_credit']."','$dt','$dt')
";
if ($new_uid = @dba_insert_id($db_query)) {
$ok = true;
}
}
}
}
if ($ok) {
$statut=3;
$mail_verif=0;
$requete = "
INSERT INTO chat_accounts (account_login, account_pass, mail, prenom, nom, mail_verif,statut,mobile,photo)
VALUES ('$username','$password_coded','$email','$prenom','$name','$mail_verif','$statut','$mobile','$photo')
";
$res = mysql_query($requete);
if ($res==true){
$_SESSION['error_string'] = _('Ce pseudo existe déjà')." ("._('email').": ".$email.")";
$ok = true;
}
}
if ($ok) {
logger_print("u:".$username." email:".$email." ip:".$_SERVER['REMOTE_ADDR'], 2, "register");
$subject = _('New account registration');
$body = $core_config['main']['cfg_web_title']."\n";
$body .= $core_config['http_path']['base']."\n\n";
$body .= _('Username')."\t: $username\n";
$body .= _('password1')."\t: $password1\n\n";
$body .= $core_config['main']['cfg_email_footer']."\n\n";
$_SESSION['error_string'] = _('Inscription terminée avec succès')." ("._('pseudo').": ".$username.")";
$data = array(
'mail_from_name' => $core_config['main']['cfg_web_title'],
'mail_from' => $core_config['main']['cfg_email_service'],
'mail_to' => $email,
'mail_subject' => $subject,
'mail_body' => $body
);
if (sendmail($data)) {
$_SESSION['error_string'] .= _('Votre mot de passe vous a été envoyé');
} else {
$_SESSION['error_string'] .= _('Echec d\'envoi de mail');
}
}
}
}
} else {
$_SESSION['error_string'] = _('Inscription du public désactivé');
}
header("Location: ".$core_config['http_path']['base']);
exit();
}
?> |
Partager