user.php 31.3 KB
Newer Older
ayolo's avatar
bleh  
ayolo committed
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
<?php
/* Copyright 2009
 *
 * Ce fichier est adapté du site de l'association des étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License a
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
$topdir = "./";
require_once($topdir. "include/site.inc.php");
require_once($topdir . "include/cts/sqltable.inc.php");
require_once($topdir . "include/entities/club.inc.php");
require_once($topdir . "include/cts/user.inc.php");
require_once($topdir . "include/entities/cartebds.inc.php");
require_once($topdir . "include/entities/cotisation.inc.php");

$site = new site ();
$site->add_css("css/userfullinfo.css");

ayolo's avatar
bleh  
ayolo committed
33
$site->allow_only_logged_users("profil");
ayolo's avatar
bleh  
ayolo committed
34 35 36

if ( isset($_REQUEST['id_utilisateur']) )
{
ayolo's avatar
bleh  
ayolo committed
37
  $user = new utilisateur($site->db);
ayolo's avatar
bleh  
ayolo committed
38 39 40
  $user->load_by_id($_REQUEST["id_utilisateur"]);

  if ( !$user->is_valid() )
ayolo's avatar
bleh  
ayolo committed
41
    $site->error_not_found("profil");
ayolo's avatar
bleh  
ayolo committed
42 43 44 45 46 47 48

  // Peut éditer une fiche:
  // - l'utilisateur en question
  // - les admins (gestion_bds)
  // - les membres du matmatonch qui ont un rôlesupérieur ou à égal à membre actif
  $can_edit = ( $user->id==$site->user->id || $site->user->is_in_group("gestion_bds") );

ayolo's avatar
bleh  
ayolo committed
49
  // Pour accdéder aux fiches profil faut être cotisant, ou être utbm
ayolo's avatar
bleh  
ayolo committed
50 51
  // ou vouloir consulter sa propre fiche
  if ( $user->id != $site->user->id && !$site->user->utbm && !$site->user->bds )
ayolo's avatar
bleh  
ayolo committed
52
    $site->error_forbidden("profil","group",10001);
ayolo's avatar
bleh  
ayolo committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
}
else
{
  $user = &$site->user;
  $can_edit = true;
}
$ville = new ville($site->db);
$pays = new pays($site->db);

$ville_parents = new ville($site->db);
$pays_parents = new pays($site->db);

// Reinitialisation d'un compte
if ( $_REQUEST['action'] == "reinit" && $site->user->is_in_group("gestion_bds") )
{
ayolo's avatar
bleh  
ayolo committed
68
  $user->load_all_extra();
ayolo's avatar
bleh  
ayolo committed
69 70 71 72 73 74
  if ( $GLOBALS["svalid_call"] && ( !empty($user->email_utbm) || !empty($user->email) ) )
  {
    if ( $user->email_utbm )
      $email = $user->email_utbm;
    else
      $email = $user->email;
ayolo's avatar
bleh  
ayolo committed
75
    $pass = $user->genere_pass(10);
ayolo's avatar
bleh  
ayolo committed
76 77 78 79 80 81 82 83 84 85 86
    $user->invalidate();
    $user->change_password($pass);
    $user->send_autopassword_email($email,$pass);
    $Notice = "Compte re-initialisé";
  }
}
// Suppresion d'une participation dans un club
elseif ( $_REQUEST["action"] == "delete" && $can_edit && isset($_REQUEST["id_membership"]))
{
  $_REQUEST["view"]="clubs";
  list($id_asso,$date_debut) = explode(",",$_REQUEST["id_membership"]);
ayolo's avatar
bleh  
ayolo committed
87
  $club = new club($site->db);
ayolo's avatar
bleh  
ayolo committed
88 89 90 91 92 93 94 95 96
  $club->load_by_id($id_club);
  $club->remove_member($user->id, strtotime($date_debut));
}
// Passage en ancien membre dans un club dans laquelle l'utilisateur
// est actuellement membre
elseif ( $_REQUEST["action"] == "stop" && $can_edit && isset($_REQUEST["id_membership"]))
{
  $_REQUEST["view"]="clubs";
  list($id_club,$date_debut) = explode(",",$_REQUEST["id_membership"]);
ayolo's avatar
bleh  
ayolo committed
97
  $club = new club($site->db);
ayolo's avatar
bleh  
ayolo committed
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
  $club->load_by_id($id_club);
  $club->make_former_member($user->id, time());
}
// Sauvgarde des information personelle
elseif ( $_REQUEST["action"] == "saveinfos" && $can_edit )
{
  $user->nom = $_REQUEST['nom'];
  $user->prenom = $_REQUEST['prenom'];
  if($site->user->is_in_group("gestion_bds"))
    $user->sexe = $_REQUEST['sexe'];
  $user->date_naissance = $_REQUEST['date_naissance'];
  $user->addresse = $_REQUEST['addresse'];
  if ( $_REQUEST['id_ville'] )
  {
    $ville->load_by_id($_REQUEST['id_ville']);
    $user->id_ville = $ville->id;
    $user->id_pays = $ville->id_pays;
  }
  else
  {
    $user->id_ville = null;
    $user->id_pays = $_REQUEST['id_pays'];
  }
  $user->tel_maison = telephone_userinput($_REQUEST['tel_maison']);
  $user->tel_portable = telephone_userinput($_REQUEST['tel_portable']);
  $user->date_maj = time();

  if ( $user->etudiant || $user->ancien_etudiant )
  {
    $user->adresse_parents = $_REQUEST['adresse_parents'];
    $user->tel_parents = telephone_userinput($_REQUEST['tel_parents']);
    $user->nom_ecole_etudiant = $_REQUEST['nom_ecole'];

    if ( $_REQUEST['id_ville_parents'] )
    {
      $ville_parents->load_by_id($_REQUEST['id_ville_parents']);
      $user->id_ville_parents = $ville_parents->id;
      $user->id_pays_parents = $ville_parents->id_pays;
    }
    else
    {
      $user->id_ville_parents = null;
      $user->id_pays_parents = $_REQUEST['id_pays_parents'];
    }
  }
  if ( $user->utbm )
  {
    $user->semestre = $_REQUEST['semestre'];
    $user->role = $_REQUEST['role'];
    $user->departement = $_REQUEST['departement'];
    $user->filiere = $_REQUEST['filiere'];

    if ( $_REQUEST['date_diplome'] < time()
      && $_REQUEST['date_diplome'] != 0
      && $_REQUEST['date_diplome'] != "" )
      $user->date_diplome_utbm = $_REQUEST['date_diplome'];
    else
      $user->date_diplome_utbm = NULL;
  }
  if ($user->saveinfos())
  {
    header("Location: ".$topdir."user.php?id_utilisateur=".$user->id);
    exit();
  }
}
// Changement de mot de passe
elseif ( $_REQUEST["action"] == "changepassword" && $can_edit )
{
  if ( $_REQUEST["bds_password"] && ($_REQUEST["bds_password"] == $_REQUEST["bds_password2"]) )
    $user->change_password($_REQUEST["bds_password"]);
  else
    $_REQUEST["page"] = "edit";
}
// Definition des groupe
elseif ( $_REQUEST["action"] == "setgroups" &&
         (($site->user->is_in_group("gestion_bds") && $site->user->id != $user->id )
         ||$site->user->is_in_group("root")) )
{
  $req = new requete($site->db,
                     "SELECT `groupe`.`id_groupe`, `groupe`.`nom_groupe`, `utl_groupe`.`id_utilisateur` ".
                     "FROM `groupe` " .
                     "LEFT JOIN `utl_groupe` ON (`groupe`.`id_groupe`=`utl_groupe`.`id_groupe` " .
                     " AND `utl_groupe`.`id_utilisateur`='".$user->id."' ) " .
                     "ORDER BY `groupe`.`nom_groupe`");

  while ( $row=$req->get_row())
  {
    $new=$_REQUEST["groups"][$row["id_groupe"]]==true;
    $old=$row["id_utilisateur"]!="";
    if ( $new != $old )
    {
      if ( $new )
      {
        if ( $row["id_groupe"] != 1 || $site->user->is_in_group("root") )
          $user->add_to_group($row["id_groupe"]);
      }
      else
      {
        if ( $row["id_groupe"] != 1 || $site->user->is_in_group("root") )
          $user->remove_from_group($row["id_groupe"]);
      }
    }
  }
}
// Definition des flag
elseif ( $_REQUEST["action"] == "setattributes" &&
         (($site->user->is_in_group("gestion_bds") && $site->user->id != $user->id )
         ||$site->user->is_in_group("root")) )
{
  if ( isset($_REQUEST["etudiant"]) || isset($_REQUEST["ancien_etudiant"]) )
    $user->became_etudiant (
        is_null($user->nom_ecole_etudiant)?"":$user->nom_ecole_etudiant,
        isset($_REQUEST["ancien_etudiant"]),
        true );
}
// Ajout de l'utilisateur comme membre d'une activité ou association
// Vu que cette opération est faite sans contrôle, le seul rôle possible est ROLECLUB_MEMBRE
elseif ( $_REQUEST["action"]=="addme" )
{
ayolo's avatar
bleh  
ayolo committed
217
  $club = new club($site->db);
ayolo's avatar
bleh  
ayolo committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
  $club->load_by_id($_REQUEST["id_club"]);

  if ( $club->id > 0 && $club->id_parent )
  {
    if ( ($_REQUEST["date_debut"] <= time()) && ($_REQUEST["date_debut"] > 0) )
      $club->add_actual_member ( $user->id, $_REQUEST["date_debut"], ROLECLUB_MEMBRE, $_REQUEST["role_desc"] );
    else
      $ErreurAddMe = "Donn&eacute;es invalides";
  }
  else
    $ErreurAddMe = "Non autoris&eacute; sur cette association.";

}
// Ajout de l'utilisateur comme ancien membre d'une activité ou association
elseif ( $_REQUEST["action"]=="addmeformer" )
{
ayolo's avatar
bleh  
ayolo committed
234
  $club = new club($site->db);
ayolo's avatar
bleh  
ayolo committed
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
  $club->load_by_id($_REQUEST["id_club"]);

  if ( $club->id > 0 )
  {
    if ($club->id_parent < 1 && $_REQUEST["role"] < 2)
      $ErreurAddMeFormer = "Non autoris&eacute; sur cette association.";

    elseif ( isset($GLOBALS['ROLECLUB'][$_REQUEST["role"]]) &&
              ($_REQUEST["former_date_debut"] < $_REQUEST["former_date_fin"]) &&
              ($_REQUEST["former_date_fin"] < time()) && ($_REQUEST["former_date_debut"] > 0) )
      $club->add_former_member ( $user->id, $_REQUEST["former_date_debut"],
                                  $_REQUEST["former_date_fin"], $_REQUEST["role"], $_REQUEST["role_desc"] );
    else
      $ErreurAddMeFormer = "Données invalides";
  }
}
// Changemement d'adresse e-mail principale
elseif ( $_REQUEST["action"] == "changeemail" && $can_edit  )
{
  if ( !CheckEmail($_POST["email"], 3) )
  {
    $ErreurMail="Adresse email invalide.";
    $_REQUEST["page"] = "edit";
    $_REQUEST["open"]="email";
  }
  else
  {
    $user->set_email($_POST["email"], $site->user->is_in_group("gestion_bds"));

    if ( $site->user->is_in_group("gestion_bds") )
      $Notice = "Adresse e-mail principale modifiée";
    else
    {
ayolo's avatar
bleh  
ayolo committed
268
      $site->start_page("profil",$user->prenom." ".$user->nom);
ayolo's avatar
bleh  
ayolo committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
      $cts = new contents ($user->prenom . " " . $user->nom );

      $cts->add_paragraph("Votre adresse e-mail principale a été modifiée");

      $cts->add_paragraph("Vous allez recevoir un e-mail de vérification à l'adresse ".$_POST["email"].". Vous devrez cliquer sur le lien se trouvant dans cet e-mail piur pouvoir utiliser de nouveau le site.");

      $cts->add_paragraph("Pour plus d'informations, ou si vous ne recevez pas l'email, consultez la documentation : <a href=\"article.php?name=docs:profil\">Documentation : Profil personnel : Questions et problèmes fréquents</a>");

      $site->add_contents($cts);
      $site->end_page();
      exit();
    }
  }
}
// Definition ou changement d'adresse e-mail utbm
elseif ( $_REQUEST["action"] == "changeemailutbm" && $can_edit  )
{
  if ( !CheckEmail($_POST["email_utbm"], 1) && !CheckEmail($_POST["email_utbm"], 2) )
  {
    $ErreurMailUtbm="Adresse email invalide : prenom.nom@utbm.fr ou prenom.nom@assidu-utbm.fr";
    $_REQUEST["page"] = "edit";
    $_REQUEST["open"]="email";
  }
  else
  {
    if ( !$user->utbm )
    {
      $user->became_utbm($_POST["email_utbm"], $site->user->is_in_group("gestion_bds"));
      $lex = "définie";
    }
    else
    {
      $user->set_email_utbm($_POST["email_utbm"], $site->user->is_in_group("gestion_bds"));
      $lex = "modifiée";
    }

    if ( $site->user->is_in_group("gestion_bds") )
      $Notice = "Adresse e-mail utbm $lex";
    else
    {
ayolo's avatar
bleh  
ayolo committed
309
      $site->start_page("profil",$user->prenom." ".$user->nom);
ayolo's avatar
bleh  
ayolo committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
      $cts = new contents ($user->prenom . " " . $user->nom );

      $cts->add_paragraph("Votre adresse e-mail utbm a été $lex");

      $cts->add_paragraph("Vous allez recevoir un e-mail de vérification à l'adresse ".$_POST["email"].". Vous devrez cliquer sur le lien se trouvant dans cet e-mail piur pouvoir utiliser de nouveau le site.");

      $cts->add_paragraph("Pour plus d'informations, ou si vous ne recevez pas l'email, consultez la documentation : <a href=\"article.php?name=docs:profil\">Documentation : Profil personnel : Questions et problèmes fréquents</a>");

      $site->add_contents($cts);
      $site->end_page();
      exit();
    }
  }
}
elseif ( $_REQUEST["action"] == "reprint" && $site->user->is_in_group("gestion_bds") )
{
ayolo's avatar
bleh  
ayolo committed
326
  $carte = new cartebds($site->db);
ayolo's avatar
bleh  
ayolo committed
327 328 329 330 331
  $carte->load_by_utilisateur($user->id);
  $carte->set_state(CETAT_ATTENTE);
}
elseif ( $_REQUEST["action"] == "retrait" && $site->user->is_in_group("gestion_bds") )
{
ayolo's avatar
bleh  
ayolo committed
332
  $carte = new cartebds($site->db);
ayolo's avatar
bleh  
ayolo committed
333 334 335 336 337
  $carte->load_by_utilisateur($user->id);
  $carte->set_state(CETAT_CIRCULATION);
}
elseif ( $_REQUEST["action"] == "cadeau" && $site->user->is_in_group("gestion_bds") )
{
ayolo's avatar
bleh  
ayolo committed
338 339
  $carte = new cartebds($site->db);
  $cotiz = new cotisation($site->db);
ayolo's avatar
bleh  
ayolo committed
340 341 342 343 344
  $carte->load_by_utilisateur($user->id);
  $cotiz->load_by_id($carte->id_cotisation);
  $cotiz->mark_cadeau();
}

ayolo's avatar
user  
ayolo committed
345
if ( $_REQUEST["action"] == "setphoto" && $can_edit && is_dir("/var/www/bds/www/var/img") )
ayolo's avatar
bleh  
ayolo committed
346
{
ayolo's avatar
bleh  
ayolo committed
347
  $dest_idt = "/var/www/bds/www/var/img/profil/".$user->id.".jpg";
ayolo's avatar
bleh  
ayolo committed
348 349 350 351 352 353
  if ( is_uploaded_file($_FILES['idtfile']['tmp_name'])  )
  {
    $src = $_FILES['idtfile']['tmp_name'];
    if ( !file_exists($dest_idt) ||  // S'il n'y a pas de photo
         ($site->user->is_in_group("gestion_bds"))) // ou gestion_bds
    {
ayolo's avatar
bleh  
ayolo committed
354
      exec("/usr/share/php5/exec/convert $src -thumbnail 200x200 $dest_idt");
ayolo's avatar
bleh  
ayolo committed
355 356 357 358 359 360 361 362
    }
  }
}

$tabs = $user->get_tabs($site->user);

if ( $_REQUEST["page"] == "edit" && $can_edit )
{
ayolo's avatar
bleh  
ayolo committed
363
  $site->start_page("profil",$user->prenom." ".$user->nom);
ayolo's avatar
bleh  
ayolo committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381

  $user->load_all_extra();

  $ville->load_by_id($user->id_ville);
  $pays->load_by_id($user->id_pays);

  $cts = new contents($user->prenom." ".$user->nom);

  // Legacy support
  if ( isset($_REQUEST["open"]) && ( $_REQUEST["open"]=="email" || $_REQUEST["open"]=="emailutbm") )
    $_REQUEST["see"] = "email";

  $cts->add(new tabshead($tabs,$_REQUEST["view"]));

  $cts->add(new tabshead(array(
    array("","user.php?page=edit&id_utilisateur=".$user->id,"Information personnelles"),
    array("email","user.php?see=email&page=edit&id_utilisateur=".$user->id,"Adresses E-Mail"),
    array("passwd","user.php?see=passwd&page=edit&id_utilisateur=".$user->id,"Mot de passe"),
ayolo's avatar
user  
ayolo committed
382
    array("photo","user.php?see=photo&page=edit&id_utilisateur=".$user->id,"Photo")
ayolo's avatar
bleh  
ayolo committed
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
    ),
    isset($_REQUEST["see"])?$_REQUEST["see"]:"","","subtab"));

  if ( !isset($_REQUEST["see"]) || empty($_REQUEST["see"]) )
  {
    $frm = new form("infoperso","user.php?id_utilisateur=".$user->id,true,"POST","Informations personelles");
    $frm->add_hidden("action","saveinfos");
    if ( $ErreurMAJ )
      $frm->error($ErreurMAJ);
    if ( $site->user->is_in_group("gestion_bds") )
     {
      $frm->add_text_field("nom","Nom",$user->nom,true,false,false,true);
      $frm->add_text_field("prenom","Prenom",$user->prenom,true,false,false,true);
    }
    else
    {
      $frm->add_text_field("nom","Nom",$user->nom,true,false,false,false);
      $frm->add_text_field("prenom","Prenom",$user->prenom,true,false,false,false);
      $frm->add_hidden("nom", $user->nom);
      $frm->add_hidden("prenom", $user->prenom);
    }

ayolo's avatar
bleh  
ayolo committed
405
    $frm->add_select_field("sexe","Sexe",array(1=>"Homme",2=>"Femme"),$user->sexe,false,false,$site->user->is_in_group("gestion_bds"));
ayolo's avatar
bleh  
ayolo committed
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
    $frm->add_date_field("date_naissance","Date de naissance",$user->date_naissance);

    if ( $user->utbm )
    {
      $frm->add_select_field("role","Role",$GLOBALS["utbm_roles"],$user->role);
      $frm->add_select_field("departement","Departement",$GLOBALS["utbm_departements"],$user->departement);
      $frm->add_text_field("semestre","Semestre",$user->semestre);
    }

    $subfrm1 = new form("infocontact",null,null,null,"Adresse et téléphone");

    $subfrm1->add_text_field("addresse","Adresse",$user->addresse);

    $subfrm1->add_entity_smartselect ("id_pays","ou pays", $pays,true);
    $subfrm1->add_entity_smartselect ("id_ville","Ville", $ville,true,false,array('id_pays'=>'id_pays_id'),true);

    $subfrm1->add_text_field("tel_maison","Telephone (fixe)",$user->tel_maison);
    $subfrm1->add_text_field("tel_portable","Telephone (portable)",$user->tel_portable);
    $frm->add ( $subfrm1, false, false, false, false, false, true, false );

    if ( $user->etudiant || $user->ancien_etudiant )
    {
      $ville_parents->load_by_id($user->id_ville_parents);
      $pays_parents->load_by_id($user->id_pays_parents);

      $subfrm2 = new form("infoextra",null,null,null,"Informations suppl&eacute;mentaires");
      $subfrm2->add_text_field("nom_ecole","Ecole",$user->nom_ecole_etudiant);
      $frm->add ( $subfrm2, false, false, false, false, false, true, false );

      $subfrm3 = new form("infoparents",null,null,null,"Informations sur les parents");
      $subfrm3->add_text_field("adresse_parents","Adresse parents",$user->adresse_parents);

      $subfrm3->add_entity_smartselect ("id_pays_parents","ou pays parents", $pays_parents,true);
      $subfrm3->add_entity_smartselect ("id_ville_parents","Ville parents", $ville_parents,true,false,array('id_pays'=>'id_pays_parents_id'),true);

      $subfrm3->add_text_field("tel_parents","T&eacute;l&eacute;phone parents",$user->tel_parents);
      $frm->add ( $subfrm3, false, false, false, false, false, true, false );
    }

    if ( $user->utbm )
    {
      $subfrm4 = new form("infoutbm",null,null,null,"Informations UTBM");
      $subfrm4->add_text_field("filiere","Filiere",$user->filiere);
      $subfrm4->add_date_field("date_diplome","Date d'obtention du diplome",($user->date_diplome_utbm!=NULL)?$user->date_diplome_utbm:null);
      $frm->add ( $subfrm4, false, false, false, false, false, true, false );
    }

    $frm->add_submit("save","Enregistrer");
    $cts->add($frm,true);

    $cts->add_paragraph("** Ces informations ne seront pas rendues publiques, elles pourrons être utilisées pour pouvoir vous contacter si l'association recherche des bénévoles particuliers.");
    $cts->add_paragraph("&nbsp;");

    $cts->add(new itemlist("Modification des autres informations",false,array(
    "<a href=\"user.php?see=email&amp;page=edit&amp;id_utilisateur=".$user->id."\">Adresses e-mail (personelle et utbm)</a>",
    "<a href=\"user.php?see=passwd&amp;page=edit&amp;id_utilisateur=".$user->id."\">Mot de passe</a>",
ayolo's avatar
user  
ayolo committed
462
    "<a href=\"user.php?see=photo&amp;page=edit&amp;id_utilisateur=".$user->id."\">Photo d'identité</a>"
ayolo's avatar
bleh  
ayolo committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    )),true);

  }
  elseif ( $_REQUEST["see"] == "email" )
  {

    $frm = new form("changeemail","user.php?id_utilisateur=".$user->id,true,"POST","Adresse email principale");
    if ( $ErreurMail )
      $frm->error($ErreurMail);
    $frm->add_hidden("action","changeemail");
    $frm->add_info("<b>Attention:</b> Votre compte sera d&eacute;sactiv&eacute; et votre session sera ferm&eacute;e jusqu'&agrave; validation du lien qui vous sera envoye par email &agrave; l'adresse que vous pr&eacute;ciserez !");

    $frm->add_text_field("email","Adresse email",$user->email,true);
    $frm->add_submit("save","Enregistrer");
    $cts->add($frm,true);

    $cts->add_paragraph("<b>Remarque:</b> Votre adresse e-mail principale est utilisée pour les mailing listes. Si vous changer votre adresse, les mailing listes seront mises à jours au bout de 60 minutes environs.");
    $cts->add_paragraph("<b>Attention:</b> Pour envoyer des messages sur les mailing listes vous devez le faire depuis votre adresse e-mail principale.");

    $frm = new form("changeemailutbm","user.php?id_utilisateur=".$user->id,true,"POST","Adresse email UTBM ou ASSIDU");
    if ( $ErreurMailUtbm )
      $frm->error($ErreurMailUtbm);
    $frm->add_hidden("action","changeemailutbm");
    $frm->add_info("<b>Attention:</b> Votre compte sera d&eacute;sactiv&eacute; et votre session sera ferm&eacute;e jusqu'&agrave; validation du lien qui vous sera envoye par email &agrave; l'adresse que vous pr&eacute;ciserez !");
    $frm->add_text_field("email_utbm","Adresse email",$user->email_utbm?$user->email_utbm:"prenom.nom@utbm.fr",true);

    $frm->add_submit("save","Enregistrer");
    $cts->add($frm,true);

  }
  elseif ( $_REQUEST["see"] == "passwd" )
  {

    $frm = new form("changepassword","user.php?id_utilisateur=".$user->id,true,"POST","Changer de mot de passe");
    $frm->add_hidden("action","changepassword");
    $frm->add_password_field("bds_password","Mot de passe","",true);
    $frm->add_password_field("bds_password2","Repetez le mot de passe","",true);
    $frm->add_submit("save","Enregistrer");
    $cts->add($frm,true);

  }
ayolo's avatar
user  
ayolo committed
504
  elseif ( $_REQUEST["see"] == "photo" )
ayolo's avatar
bleh  
ayolo committed
505 506
  {

ayolo's avatar
user  
ayolo committed
507 508
    $frm = new form("setphoto","user.php?id_utilisateur=".$user->id,true,"POST","Changer ma photo d'identit&eacute;");
    $frm->add_hidden("action","setphoto");
ayolo's avatar
bleh  
ayolo committed
509
    if ( file_exists( $topdir."var/img/profil/".$user->id.".jpg") )
ayolo's avatar
bleh  
ayolo committed
510
    {
ayolo's avatar
bleh  
ayolo committed
511
      $frm->add_info("<img src=\"".$topdir."var/img/profil/".$user->id.".jpg?".filemtime($topdir."var/img/profil/".$user->id.".jpg")."\" alt=\"\" width=\"100\" /><br/>");
ayolo's avatar
bleh  
ayolo committed
512 513 514 515 516 517 518 519

      if ($site->user->is_in_group("gestion_bds"))
      {
        $frm->add_file_field ( "idtfile", "Fichier" );
        $frm->add_checkbox("delete_idt","Supprimer la photo d'identit&eacute;");
      }
    }
    else
ayolo's avatar
bleh  
ayolo committed
520
      $frm->add_file_field ( "idtfile", "Fichier" );
ayolo's avatar
bleh  
ayolo committed
521 522 523 524 525 526 527 528 529

    $frm->add_submit("save","Enregistrer");
    $cts->add($frm,true);
  }
  $site->add_contents($cts);
  $site->end_page();
  exit();
}

ayolo's avatar
bleh  
ayolo committed
530
$site->start_page("profil", $user->prenom . " " . $user->nom );
ayolo's avatar
bleh  
ayolo committed
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680

$cts = new contents ($user->prenom . " " . $user->nom );

$cts->add(new tabshead($tabs,$_REQUEST["view"]));

if ( $_REQUEST["view"]=="clubs" )
{

  /* Clubs en cours */
  $req = new requete($site->db,
    "SELECT `club`.`id_club`, `club`.`nom_club`, " .
    "IF(`club`.`id_club_parent` IS NULL,`club_membre`.`role`+100,`club_membre`.`role`) AS `role`, ".
    "`club_membre`.`date_debut`, `club_membre`.`desc_role`, " .
    "CONCAT(`club`.`id_club`,',',`club_membre`.`date_debut`) as `id_membership` " .
    "FROM `club_membre` " .
    "INNER JOIN `club` ON `club`.`id_club`=`club_membre`.`id_club` " .
    "WHERE `club_membre`.`id_utilisateur`='".$user->id."' " .
    "AND `club_membre`.`date_fin` is NULL " .
    "ORDER BY `club`.`nom_club`");
  if ( $req->lines > 0 )
  {
    $tbl = new sqltable(
      "listclub",
      "Clubs actuels", $req, "user.php?id_utilisateur=".$user->id,
      "id_membership",
      array("nom_club"=>"Club","role"=>"Role","desc_role"=>"","date_debut"=>"Depuis"),
      $can_edit?array("delete"=>"Supprimer","stop"=>"Arreter à la date de ce jour"):array(),
      array(), array("role"=>$GLOBALS['ROLECLUB100'])
      );
    $cts->add($tbl,true);
  }

  if ( $can_edit )
  {
    $frm = new form("addme","user.php?view=clubs&id_utilisateur=".$user->id,false,"POST","S'inscire aux nouvelles d'une activité");
    if ( $ErreurAddMe )
      $frm->error($ErreurAddMe);
    $frm->add_hidden("action","addme");
    $frm->add_info("<b>Attention</b> : Si vous &ecirc;tes le responsable, merci de vous adresser à l'équipe informatique.");
    $frm->add_info("En tant que membre vous serez inscrit à la mailing liste du club, vous receverez donc par e-mail toutes les informations sur l'activité.");
    $frm->add_entity_select ( "id_club", "Club", $site->db, "club");
    $frm->add_date_field("date_debut","Depuis le",time(),true);
    $frm->add_submit("valid","Ajouter");
    $cts->add($frm,true);
  }

  /* Anciennes assos */
  $req = new requete($site->db,
    "SELECT `club`.`id_club`, `club`.`nom_club`, " .
    "IF(`club`.`id_club_parent` IS NULL,`club_membre`.`role`+100,`club_membre`.`role`) AS `role`, ".
    "`club_membre`.`date_debut`, `club_membre`.`desc_role`, `club_membre`.`date_fin`, " .
    "CONCAT(`club`.`id_club`,',',`club_membre`.`date_debut`) as `id_membership` " .
    "FROM `club_membre` " .
    "INNER JOIN `club` ON `club`.`id_club`=`club_membre`.`id_club` " .
    "WHERE `club_membre`.`id_utilisateur`='".$user->id."' " .
    "AND `club_membre`.`date_fin` is NOT NULL " .
    "ORDER BY `club`.`nom_club`,`club_membre`.`date_debut`");
  if ( $req->lines > 0 )
  {
    $tbl = new sqltable(
      "listclubformer",
      "Anciennes participation aux clubs", $req, "user.php?id_utilisateur=".$user->id,
      "id_membership",
      array("nom_club"=>"Club","role"=>"Role","desc_role"=>"","date_debut"=>"Date de début","date_fin"=>"Date de fin"),
      $can_edit?array("delete"=>"Supprimer"):array(), array(), array("role"=>$GLOBALS['ROLECLUB100'] )
      );
    $cts->add($tbl,true);
  }

  unset($GLOBALS['ROLECLUB'][ROLECLUB_MEMBRE]);
  unset($GLOBALS['ROLECLUB'][ROLECLUB_MEMBREACTIF]);

  if ( $can_edit )
  {
    $frm = new form("addmeformer","user.php?view=assos&id_utilisateur=".$user->id,false,"POST","Ajouter une ancienne participation");
    $frm->add_hidden("action","addmeformer");
    if ( $ErreurAddMeFormer )
      $frm->error($ErreurAddMeFormer);
    $frm->add_entity_select ( "id_club", "Club", $site->db, "club");
    $frm->add_text_field("role_desc","Role (champ libre)","");
    $frm->add_select_field("role","Role",$GLOBALS['ROLECLUB']);
    $frm->add_date_field("former_date_debut","Date de d&eacute;but",-1,true);
    $frm->add_date_field("former_date_fin","Date de fin",-1,true);
    $frm->add_submit("valid","Ajouter");
    $cts->add($frm,true);
  }
}

elseif ( ($_REQUEST["view"]=="groups") &&
         (($site->user->is_in_group("gestion_bds") && $site->user->id != $user->id )
         ||$site->user->is_in_group("root")) )
{
  $user->load_all_extra();
  /* groupes */
  $frm = new form("setattributes","user.php?view=groups&id_utilisateur=".$user->id,false,"POST","Attribus");
  $frm->add_hidden("action","setattributes");
  $frm->add_checkbox("bds","bds",$user->bds,true);
  $frm->add_checkbox("utbm","utbm",$user->utbm, !$user->email_utbm);
  $frm->add_checkbox("etudiant","etudiant",$user->etudiant);
  $frm->add_checkbox("ancien_etudiant","ancien_etudiant",$user->ancien_etudiant);

  $frm->add_submit("save","Enregistrer");
  $cts->add($frm,true);


  $req = new requete($site->db,
                     "SELECT `groupe`.`id_groupe`, `groupe`.`nom_groupe`, `utl_groupe`.`id_utilisateur` ".
                     "FROM `groupe` " .
                     "LEFT JOIN `utl_groupe` ON (`groupe`.`id_groupe`=`utl_groupe`.`id_groupe`" .
                     " AND `utl_groupe`.`id_utilisateur`='".$user->id."' ) " .
                     "ORDER BY `groupe`.`nom_groupe`");

  $frm = new form("setgroups","user.php?view=groups&id_utilisateur=".$user->id,true,"POST","Groupes");
  $frm->add_hidden("action","setgroups");
  $grp = new group($site->db);

  while ( $row=$req->get_row())
  {
    $grp->_load($row);
    if ( $row["id_groupe"] == 1 && !$site->user->is_in_group("root") )
      $frm->add_checkbox("groups|".$row["id_groupe"],$grp->get_html_link(),$row["id_utilisateur"]!="",true);
    else
      $frm->add_checkbox("groups|".$row["id_groupe"],$grp->get_html_link(),$row["id_utilisateur"]!="");
  }

  $frm->add_submit("save","Enregistrer");
  $cts->add($frm,true);
}

else
{
  $user->load_all_extra();

  $info = new userinfo($user,"full",$site->user->is_in_group("gestion_bds"));

  if ( $can_edit )
    $info->set_toolbox(new toolbox(array("user.php?id_utilisateur=".$user->id."&page=edit"=>"Modifier")));

  $cts->add($info);

  if ( $site->user->id == $user->id && !$user->bds )
  {
    $cts->add_title(2, "Cotisation BDS");
    $cts->add_paragraph("<img src=\"" . $topdir . "images/cartebds/mini_non_bds.png\">" .
                        "<b><font color=\"red\">&nbsp;&nbsp;Attention, aucune cotisation " .
                        "au BDS trouv&eacute;e !</font></b>");
  }

  if ( $can_edit && $user->bds )
  {
ayolo's avatar
user  
ayolo committed
681
    $cts2 = new contents("Cotisation BDS");
ayolo's avatar
bleh  
ayolo committed
682

slopez's avatar
bleh  
slopez committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
    $limit=$user->get_certificat();
    $req = new requete($site->db, "SELECT `date_fin_cotis` FROM `cotisations`
                                      WHERE `id_utilisateur`='".$user->id."'
                                      AND `date_fin_cotis` >= '" . date("Y-m-d") . "'
                                      ORDER BY `date_fin_cotis` DESC LIMIT 1");

    if($site->user->is_in_group("gestion_bds")
       && file_exists("/var/www/bds/www/var/img/profil/" . $user->id .".jpg")
       && $limit 
       && $req->lines == 1)
    {
      $req2 = new requete($site->db,
                "SELECT `id_carte` ".
                "FROM `cartes` ".
                "INNER JOIN `cotisations` USING(`id_cotisation`) ".
                "WHERE `cotisations`.`id_utilisateur`='".$user->id."' ".
slopez's avatar
bleh  
slopez committed
699
                "AND `cartes`.`etat_vie_carte`<".CETAT_IMPRIMEE."");
slopez's avatar
bleh  
slopez committed
700 701
      if($req2->lines==1)
      {
slopez's avatar
bleh  
slopez committed
702
        list($id)=$req2->get_row();
slopez's avatar
bleh  
slopez committed
703
        $cts2->add_paragraph('<a href="'.$topdir.'admin/cartes.php?action=pdf&ids='.$user->id.'">Imprimer la carte</a>');
slopez's avatar
bleh  
slopez committed
704 705 706
      }
    }

ayolo's avatar
bleh  
ayolo committed
707
    if ( !file_exists("/var/www/bds/www/var/img/profil/" . $user->id .".jpg"))
ayolo's avatar
user  
ayolo committed
708
      $cts2->add_paragraph("<img src=\"".$topdir."images/actions/delete.png\"><b>ATTENTION</b>: " .
ayolo's avatar
bleh  
ayolo committed
709
                          "<a href=\"user.php?page=edit&amp;id_utilisateur=".$user->id.
ayolo's avatar
bleh  
ayolo committed
710
                          "&amp;see=photo\">Photo d'identit&eacute; non pr&eacute;sente !</a>");
ayolo's avatar
bleh  
ayolo committed
711
    if(!$limit)
slopez's avatar
bleh  
slopez committed
712
    {
ayolo's avatar
user  
ayolo committed
713
      $cts2->add_paragraph("<img src=\"".$topdir."images/actions/delete.png\"><b>ATTENTION</b>: " .
ayolo's avatar
bleh  
ayolo committed
714
                          "Vous n'avez pas de certificat médical à jour, vous n'avez donc pas le droit de ".
ayolo's avatar
bleh  
ayolo committed
715
                          "pratiquer de sport. Merci de ramener un certificat au bureau du BDS !");
slopez's avatar
bleh  
slopez committed
716
      if($site->user->is_in_group("gestion_bds"))
slopez's avatar
bleh  
slopez committed
717
        $cts2->add_paragraph("<a href='".$topdir."admin/certificats.php?action=newcertif&id_utilisateur=".$user->id."'>Enregistrer un certficat</a>");
slopez's avatar
bleh  
slopez committed
718
    }
ayolo's avatar
bleh  
ayolo committed
719
    else
slopez's avatar
bleh  
slopez committed
720
      $cts2->add_paragraph("Certificat médical valide jusqu'au ".date('d/m/Y',strtotime($limit)));
ayolo's avatar
bleh  
ayolo committed
721 722

    if ($req->lines > 1)
ayolo's avatar
user  
ayolo committed
723 724 725 726
    {
      $cts2->add_paragraph("ATTENTION: Plusieurs cotisations en cours.");
      $cts->add($cts2,true,true,'cotisationinfos','cotisationinfos');
    }
slopez's avatar
bleh  
slopez committed
727
    elseif ($req->lines == 0)
ayolo's avatar
user  
ayolo committed
728 729 730 731
    {
      $cts2->add_paragraph("ATTENTION: Cotisation non enregistr&eacute;e ou etat non &agrave; jour.");
      $cts->add($cts2,true,true,'cotisationinfos','cotisationinfos');
    }
ayolo's avatar
bleh  
ayolo committed
732 733 734 735 736 737
    else
    {
      $res = $req->get_row();

      $year = explode("-", $res['date_fin_cotis']);
      $year = $year[0];
ayolo's avatar
user  
ayolo committed
738
      $cts2->add_paragraph("<img src=\"" . $topdir . "images/cartebds/mini_bds.png\">&nbsp;&nbsp;" .
ayolo's avatar
bleh  
ayolo committed
739 740
                          "Cotisant(e) BDS jusqu'au " .
                          HumanReadableDate($res['date_fin_cotis'], null, false) . " $year !");
ayolo's avatar
user  
ayolo committed
741
     $cts->add($cts2,true,true,'cotisationinfos','cotisationinfos');
ayolo's avatar
bleh  
ayolo committed
742 743
      if ( $can_edit )
      {
ayolo's avatar
bleh  
ayolo committed
744 745 746 747
        $req = new requete($site->db,
               "SELECT `id_carte` ".
               ", `etat_vie_carte` ".
               ", `a_pris_cadeau` ".
ayolo's avatar
bleh  
ayolo committed
748
               "FROM `cartes` ".
ayolo's avatar
bleh  
ayolo committed
749 750
               "INNER JOIN `cotisations` USING(`id_cotisation`) ".
               "WHERE `cotisations`.`id_utilisateur`='".$user->id."' ".
ayolo's avatar
bleh  
ayolo committed
751
               "AND `cartes`.`etat_vie_carte`<".CETAT_EXPIRE."");
ayolo's avatar
bleh  
ayolo committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774

        $item = $req->get_row();

        $tab = array("reprint"=>"Re-imprimer carte");
        if($item['etat_vie_carte']==CETAT_AU_BUREAU_BDS)
        {
          $ret = array("retrait" => "Retrait carte");
          $tab += $ret;
        }
        if($item['a_pris_cadeau']==0)
        {
          $cad = array("cadeau" => "Retrait cadeau");
          $tab += $cad;
        }

        $tbl = new sqltable(
          "listasso",
          "Ma carte BDS", array($item), "user.php?id_utilisateur=".$user->id,
          "id_carte",
          array("id_carte"=>"N°","etat_vie_carte"=>"Etat"),
          $site->user->is_in_group("gestion_bds")?$tab:array(),
          array(), array("etat_vie_carte"=>$EtatsCarteBDS )
          );
ayolo's avatar
user  
ayolo committed
775
        $cts->add($tbl,true,true,'cartestatus','cartestatus');
ayolo's avatar
bleh  
ayolo committed
776 777 778 779 780 781 782 783 784 785
      }
    }
  }

  if ( $can_edit )
  {
    $cts->add(new itemlist("Modification du profil",false,array(
    "<a href=\"user.php?page=edit&amp;id_utilisateur=".$user->id."\">Informations personelles</a>",
    "<a href=\"user.php?see=email&amp;page=edit&amp;id_utilisateur=".$user->id."\">Adresses e-mail (personelle et utbm)</a>",
    "<a href=\"user.php?see=passwd&amp;page=edit&amp;id_utilisateur=".$user->id."\">Mot de passe</a>",
ayolo's avatar
user  
ayolo committed
786
    "<a href=\"user.php?see=photo&amp;page=edit&amp;id_utilisateur=".$user->id."\">Photo d'identité</a>"
ayolo's avatar
bleh  
ayolo committed
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
    )),true);
  }

  if ( $site->user->is_in_group("gestion_bds") )
  {
    $frm = new form("pass_reinit", "user.php?id_utilisateur=".$user->id, true, "POST", "R&eacute;initialiser le mot de passe");
    $frm->allow_only_one_usage();
    $frm->add_hidden("action","reinit");
    $frm->add_submit("valid","R&eacute;initialiser !");
    $cts->add($frm,true);
  }
}

/* c'est tout */
$site->add_contents($cts);

$site->end_page();

?>