teol

Controller of a profile updating page

Sep 28th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.08 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author: TeoL <[email protected]>
  4.  * @version: 1.0
  5.  */
  6.  
  7. if(defined('INDEX')){
  8.     if(!empty($_SESSION['id'])){
  9.         if(isset($_POST) && !empty($_POST)){
  10.             $erreurs = array();
  11.             $tableau_sexes = array(1, 2); //1 Homme, 2 Femme
  12.             //$tableau_extensions = array("jpg", "png", "gif");
  13.             $tableau_mimes = array("image/jpeg", "image/png", "image/gif");
  14.             $tableau_exif = array("IMAGETYPE_GIF", "IMAGETYPE_PNG", "IMAGETYPE_JPEG", 1, 2, 3);
  15.             $maxwidth = '150'; //Largeur max
  16.             $maxheight = '150'; //Hauteur max
  17.             $dernier_id_jeux = lastGameId();
  18.  
  19.             if(empty($_POST['password_actuel']) && !empty($_POST['password_new'])){
  20.                 $erreurs[] = "Vous n'avez pas renseigné votre mot de passe actuel.";
  21.             }
  22.             if(isset($_POST['game_1'])){
  23.                 if(!ctype_digit($_POST['game_1'])){
  24.                     $erreurs[] = "DU HURENSÖHN :@"; //Modification dynamique de la page (FireBug)
  25.                 }
  26.                 if($_POST['game_1'] < 0 OR $_POST['game_1'] > $dernier_id_jeux){
  27.                     $erreurs[] = "DU HURENSÖHN :@"; //Modification dynamique de la page (FireBug)
  28.                 }
  29.             }
  30.             if(isset($_POST['game_2'])){
  31.                 if(!ctype_digit($_POST['game_2'])){
  32.                     $erreurs[] = "DU HURENSÖHN :@"; //Modification dynamique de la page (FireBug)
  33.                 }
  34.                 if($_POST['game_2'] < 0 OR $_POST['game_2'] > $dernier_id_jeux){
  35.                     $erreurs[] = "DU HURENSÖHN :@"; //Modification dynamique de la page (FireBug)
  36.                 }
  37.             }
  38.             if(isset($_POST['game_3'])){
  39.                 if(!ctype_digit($_POST['game_3'])){
  40.                     $erreurs[] = "DU HURENSÖHN :@"; //Modification dynamique de la page (FireBug)
  41.                 }
  42.                 if($_POST['game_3'] < 0 OR $_POST['game_3'] > $dernier_id_jeux){
  43.                     $erreurs[] = "DU HURENSÖHN :@"; //Modification dynamique de la page (FireBug)
  44.                 }
  45.             }
  46.             if(!empty($_POST['password_actuel']) && !empty($_POST['password_new'])){
  47.                 if(!checkPassword($_SESSION['pseudo'], $pwd)){
  48.                     $erreurs[] = "Le mot de passe actuel que vous avez entré est erroné.";
  49.                 }
  50.             }
  51.             if(strlen($_FILES['avatar']['tmp_name']) > 0){
  52.                 if($_FILES['avatar']['error'] > 0){
  53.                     $erreurs[] = "Erreur upload avatar : ".$_FILES['avatar']['error']."";
  54.                 }
  55.                 if(!in_array($_FILES['avatar']['type'], $tableau_mimes) OR !in_array(exif_imagetype($_FILES['avatar']['tmp_name']), $tableau_exif)){
  56.                     $erreurs[] = "Seules les images PNG, JPEG et GIF de maximum 150*150px sont autorisées.";
  57.                 }
  58.                 //On récupere la taille de l'image (avatar)
  59.                 $image_size = getimagesize($_FILES['avatar']['tmp_name']);
  60.                 //Puis on regarde si c'est pas trop grand
  61.                 if($image_size[0] > $maxwidth OR $image_size[1] > $maxheight){
  62.                     $erreurs[] = "Votre avatar est trop grand, il doit être au maximum de 150*150px.";
  63.                 }
  64.             }
  65.             if(!in_array($_POST['sexe'], $tableau_sexes)){
  66.                 $erreurs[] = "DU HURENSÖHN :@"; //Modification dynamique de la page (FireBug)
  67.             }
  68.             if(!empty($_POST['mail'])){
  69.                 if(!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $_POST['mail'])){
  70.                     $erreurs[] = "Vous n'avez pas entré une adresse e-mail valide.";
  71.                 }
  72.             }
  73.             if(!empty($_POST['password_new'])){
  74.                 if(!empty($_POST['password_conf'])){
  75.                     if($_POST['password_new'] != $_POST['password_conf']){
  76.                         $erreurs[] = "Les deux mots de passe ne correspondent pas.";
  77.                     }
  78.                 }
  79.                 else{
  80.                     $erreurs[] = "Vous n'avez pas entré la confirmation du nouveau mot de passe.";
  81.                 }
  82.             }
  83.             if(!empty($_POST['steamid'])){
  84.                 //On vérifie la syntaxe du SteamID
  85.                 if(!preg_match("#^STEAM_0:[0-1]:[0-9]{1,8}$#", $_POST['steamid'])){
  86.                     $erreurs[] = "La syntaxe du SteamID n'est pas bonne. ( STEAM_X:Y:Z )";
  87.                 }
  88.             }
  89.             if(!empty($_POST['eslid'])){
  90.                 //On vérifie la syntaxe de l'esl ID
  91.                 if(!preg_match("#^[0-9]{1,15}$#", $_POST['eslid'])){
  92.                     $erreurs[] = "La syntaxe de l'ESL ID n'est pas bonne. ( ex: 3465536 )";
  93.                 }
  94.             }
  95.             if(!empty($_POST['titre'])){
  96.                 if(strlen($_POST['titre']) > 50){
  97.                     $erreurs[] = "Votre titre ne doit pas ocntenir plus de 50 caractères.";
  98.                 }
  99.             }
  100.             if(!empty($_POST['description'])){
  101.                 if(strlen($_POST['description']) > 250){
  102.                     $erreurs[] = "Votre résumé ne doit pas contenir plus de 250 caractères.";
  103.                 }
  104.             }
  105.  
  106.             //S'il n'y a pas d'erreurs, on continue
  107.             if(empty($erreurs)){
  108.                 $pwd = hash_pwd($_POST['password_actuel'], $_SESSION['pseudo']);
  109.                 //On voit si le membre veut la newsletter
  110.                 if(isset($_POST['newsletter'])){
  111.                     $newsletter = 1;
  112.                 }
  113.                 else{
  114.                     $newsletter = 0;
  115.                 }
  116.                 //ON UPDATE, ENFIN ! ( mais c'est loin d'être fini :( )
  117.                 if(!empty($_POST['password_new'])){
  118.                     $pwd = hash_pwd($_POST['password_new'], $_SESSION['pseudo']);
  119.                     updatePwd($pwd, $_SESSION['id']); //Updated :)
  120.                 }
  121.                 if(!empty($_POST['mail'])){
  122.                     updateMail($_POST['mail'], $_SESSION['id']); //Updated :)
  123.                 }
  124.                 if(!empty($_POST['steamid'])){
  125.                     $steamid = $_POST['steamid'];
  126.                     //On découpe le SteamID
  127.                     sscanf(strtoupper($steamid), 'STEAM_%d:%d:%d', $X, $Y, $Z);
  128.                     //Puis on calcule le SteamID_64
  129.                     $constanteCommunityid = 7656119;
  130.                     $communityid = $Z * 2;
  131.                     $communityid = $communityid + 7960265728;
  132.                     $communityid = $communityid + $Y;
  133.                     $steamid64 = $constanteCommunityid.$communityid;
  134.  
  135.                     updateSteam($steamid, $steamid64, $_SESSION['id']); //Updated :)
  136.                 }
  137.                 if(!empty($_POST['eslid'])){
  138.                     updateEsl($_POST['eslid'], $_SESSION['id']); //Updated :)
  139.                 }
  140.                 if(!empty($_POST['titre'])){
  141.                     updateTitle($_POST['titre'], $_SESSION['id']); //Updated :)
  142.                 }
  143.                 if(!empty($_POST['description'])){
  144.                     $_POST['description'] = htmlentities($_POST['description']);
  145.                     //NL2BR, normal :)
  146.                     $_POST['description'] = nl2br($_POST['description']);
  147.  
  148.                     updateDescription($_POST['description'], $_SESSION['id']); //Updated :)
  149.                 }
  150.                 if(strlen($_FILES['avatar']['tmp_name']) > 0){
  151.                     //On upload l'avatar
  152.                     $image_extension = strtolower(  substr(  strrchr($_FILES['avatar']['name'], '.')  ,1)  );
  153.                     $avatar_name = ''.$_SESSION['pseudo'].'-'.uniqid().'.'.$image_extension.''; //Donne un truc du style teol-454xbx568.jpg
  154.                     $img_location = "img/avatars/".$avatar_name; //Endroit de l'upload
  155.                     //Si l'upload se passe bien
  156.                     if(move_uploaded_file($_FILES['avatar']['tmp_name'], $img_location)){
  157.                         //On update
  158.                         updateAvatar($img_location, $_SESSION['id']); //Updated :)
  159.                     }
  160.                     else{
  161.                         $erreurs[] = "Une erreur s'est produite durant l'upload de votre avatar. Veuillez réessayer.";
  162.                     }
  163.                 }
  164.                 //Puis enfin, on update le sexe et la newsletter, qui sont censé être présents
  165.                 updateGender($_POST['sexe'], $_SESSION['id']); //Updated :)
  166.                 updateNewsletter($newsletter, $_SESSION['id']); //Updated :)
  167.                 updateGame3($_POST['game_3'], $_SESSION['id']); //Updated :)
  168.                 updateGame2($_POST['game_2'], $_SESSION['id']); //Updated :)
  169.                 updateGame1($_POST['game_1'], $_SESSION['id']); //Updated :)
  170.             }
  171.         }
  172.  
  173.         $jeux = gameList();
  174.         $info = getProfileinfo($_SESSION['id']);
  175.         $info['description'] = stripslashes($info['description']);
  176.         //On transforme les <br /> en \n
  177.         $info['description'] = str_replace("<br />", "\n", $info['description']);
  178.         include "views/updateprofile.php";
  179.     }
  180.     else{
  181.         include "views/erreur_non_connecte.php";
  182.     }
  183. }
  184. ?>
  185.  
Advertisement
Add Comment
Please, Sign In to add comment