index.php 27.3 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
4
5
<?php

/* Copyright 2007
 *
 * - Sebastien WATTIEZ < webast2 at gmail dot com >
Ayolo's avatar
Ayolo committed
6
 * - Simon Lopez < simon DOT lopez AT ayolo DOT org >
7
 * - Pierre Mauduit <pierre POINT mauduit CHEZ utbm POINT fr>
Ayolo's avatar
Ayolo committed
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
 *
 * Ce fichier fait partie 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 as
 * 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 = "../";

include($topdir. "include/site.inc.php");
require_once($topdir. "include/cts/sqltable.inc.php");
require_once($topdir. "include/entities/asso.inc.php");
require_once($topdir. "include/cts/user.inc.php");
Ayolo's avatar
Ayolo committed
34
require_once($topdir. "sas2/include/photo.inc.php");
Ayolo's avatar
blurp    
Ayolo committed
35
36
37
require_once($topdir. "include/cts/gallery.inc.php");
require_once($topdir. "include/cts/special.inc.php");
require_once($topdir. "include/globals.inc.php");
Ayolo's avatar
Ayolo committed
38
39
40
require_once($topdir. "include/entities/ville.inc.php");
require_once($topdir. "include/entities/pays.inc.php");
require_once($topdir. "include/graph.inc.php");
Ayolo's avatar
Ayolo committed
41
42
require_once($topdir. "include/cts/imgcarto.inc.php");
require_once($topdir. "include/pgsqlae.inc.php");
43
44
require_once("include/entities/commentaire.inc.php");
require_once("include/cts/commentaire.inc.php");
Ayolo's avatar
Ayolo committed
45
46

$site = new site();
47
$cmt = new commentaire($site->db, $site->dbrw);
Ayolo's avatar
Ayolo committed
48
49

$site->add_css("css/userfullinfo.css");
vazlin's avatar
vazlin committed
50
$site->add_css("css/trombicomment.css");
Ayolo's avatar
Ayolo committed
51
52

if (!$site->user->id)
53
  $site->error_forbidden();
54

Ayolo's avatar
Ayolo committed
55

vazlin's avatar
vazlin committed
56
57
$is_user_moderator = ( $site->user->is_in_group("gestion_ae") || $site->user->is_asso_role ( 27, 1 ) );

Ayolo's avatar
Ayolo committed
58
59
60
61
if (isset($_REQUEST['id_utilisateur']))
{
  $user = new utilisateur($site->db,$site->dbrw);
  $user->load_by_id($_REQUEST["id_utilisateur"]);
62

Ayolo's avatar
Ayolo committed
63
64
  if (!$user->is_valid())
    $site->error_not_found("matmatronch");
65

Ayolo's avatar
bleh    
Ayolo committed
66
67
  $user->load_all_extra();

vazlin's avatar
debug    
vazlin committed
68
  $is_user_page = ($user->id==$site->user->id);
69

vazlin's avatar
vazlin committed
70
  $can_edit = ($user->id==$site->user->id || $is_user_moderator);
71

Ayolo's avatar
Ayolo committed
72
73
  if ($user->id != $site->user->id && !$site->user->utbm && !$site->user->ae)
    $site->error_forbidden("matmatronch","group",10001);
74

75
  if ( (($user->publique == 0) || ($user->publique == 1 && !$site->user->cotisant)) && !$can_edit )
Ayolo's avatar
blurp    
Ayolo committed
76
    $site->error_forbidden("matmatronch","private");
77
78

  if ($user->promo_utbm != $site->user->promo_utbm)
Ayolo's avatar
blurp    
Ayolo committed
79
    $user = &$site->user;
Ayolo's avatar
bleh    
Ayolo committed
80

Ayolo's avatar
bleh    
Ayolo committed
81
  if ($site->user->is_in_group("gestion_ae"))
Ayolo's avatar
blurp    
Ayolo committed
82
    $can_edit = true;
Ayolo's avatar
Ayolo committed
83
84
85
86
}
else
{
  $user = &$site->user;
vazlin's avatar
vazlin committed
87
  $is_user_page = true;
Ayolo's avatar
Ayolo committed
88
89
90
  $can_edit = true;
}

91

vazlin's avatar
vazlin committed
92
if ( $_REQUEST["page"]  == "edit" )
93
94
95
96
97
98
{
  if ( isset($_REQUEST["id_commentaire"]) )
  {
    $cmt->load_by_id($_REQUEST["id_commentaire"]);
    if ( $cmt->id < 1 )
    {
99
      $site->error_not_found();
100
101
      exit();
    }
102

vazlin's avatar
vazlin committed
103
104
105
    if ( $is_user_moderator || $cmt->id_commentateur == $site->user->id )
    {
      $site->start_page ("services", "Edition d'un commentaire");
106
      $cts = new contents("Edition d'un commentaire");
vazlin's avatar
vazlin committed
107
108
109
110
111
112
113
114
115
116

      $frm = new form("editcomment", "index.php?id_utilisateur=".$cmt->id_commente."#c".$cmt->id, false, "POST", "Edition d'un commentaire");
      $frm->add_hidden("action","edit");
      $frm->add_hidden("id_commentaire",$cmt->id);
      $frm->add_hidden("id_utilisateur",$cmt->id_commente);
      $frm->add_info("<b>ATTENTION</b>Votre commentaire peut &ecirc;tre mod&eacute;r&eacute;");
      $frm->add_dokuwiki_toolbar('commentaire');
      $frm->add_text_area ("commentaire","Commentaire",$cmt->commentaire);
      $frm->add_submit("valid","Enregistrer");

117
118
119
120
      $cts->add ($frm);
      $cts->add_paragraph ("<a href=\"index.php?id_utilisateur=".$cmt->id_commente."#c".$cmt->id."\">Annuler</a>");
      $cts->add (new wikihelp());
      $site->add_contents($cts);
vazlin's avatar
vazlin committed
121
122
123
      $site->end_page ();
      exit();
    }
124
125
  }
}
126
127
128
129
130
131
132
elseif ( $_REQUEST["page"]  == "del" )
{
  if ( isset($_REQUEST["id_commentaire"]) )
  {
    $cmt->load_by_id($_REQUEST["id_commentaire"]);
    if ( $cmt->id < 1 )
    {
133
      $site->error_not_found();
134
135
      exit();
    }
136

137
138
139
    if ( $cmt->id_commentateur == $site->user->id )
    {
      $site->start_page ("services", "Suppression d'un commentaire");
140
141
      $cts = new contents("Supprimer d'un commentaire");
      $cts->add_paragraph("Supprimer le commentaire ?");
142
143
144
145
146
147
148

      $frm = new form("delcomment", "index.php?id_utilisateur=".$cmt->id_commente."#comments", false, "POST", "Suppression d'un commentaire");
      $frm->add_hidden("action","delete");
      $frm->add_hidden("id_commentaire",$cmt->id);
      $frm->add_hidden("id_utilisateur",$cmt->id_commente);
      $frm->add_submit("valid","Supprimer");

149
150
151
      $cts->add($frm);
      $cts->add_paragraph("<a href=\"index.php?id_utilisateur=".$cmt->id_commente."#c".$cmt->id."\">Annuler</a>");
      $site->add_contents ($cts);
152
153
154
155
156
157

      $site->end_page ();
      exit();
    }
  }
}
158
159


vazlin's avatar
vazlin committed
160
if ( ($_REQUEST["action"] == "create") && (!$is_user_page) )
161
{
vazlin's avatar
vazlin committed
162
163
164
165
  if ( isset($_REQUEST["commentaire"]) )
  {
    $cmt->create($user->id, $site->user->id, $_REQUEST["commentaire"]);
  }
166
}
vazlin's avatar
vazlin committed
167
elseif ( ($_REQUEST["action"] == "edit") && (!$is_user_page || $is_user_moderator) )
168
{
vazlin's avatar
vazlin committed
169
170
171
  if ( isset($_REQUEST["id_commentaire"]) && isset($_REQUEST["commentaire"]) )
  {
    $cmt->load_by_id($_REQUEST["id_commentaire"]);
172

vazlin's avatar
vazlin committed
173
174
175
176
    if ( $site->user->id == $cmt->id_commentateur || $is_user_moderator)
      $cmt->update($_REQUEST["commentaire"]);
  }
}
177
178
179
180
181
elseif ( ($_REQUEST["action"] == "delete") && (!$is_user_page) )
{
  if ( isset($_REQUEST["id_commentaire"]) )
  {
    $cmt->load_by_id($_REQUEST["id_commentaire"]);
182

183
184
185
186
    if ( $site->user->id == $cmt->id_commentateur )
      $cmt->delete();
  }
}
vazlin's avatar
vazlin committed
187
188
189
190
191
192
elseif ( ($_REQUEST["action"] == "moderate") && ($is_user_moderator) )
{
  if ( isset($_REQUEST["id_commentaire"]) )
  {
    $cmt->load_by_id($_REQUEST["id_commentaire"]);
    $cmt->set_modere($site->user->id);
vazlin's avatar
vazlin committed
193
  }
194
195
196
197
198
199
200
201
202
203
204
205
206
207
}


$site->start_page ("none", "Trombi Promo ".sprintf("%02d",$site->user->promo_utbm));

$tabs = array(array("","trombi/index.php", "Informations"),
              //array("board","trombi/index.php?view=board", "Messages"),
              array("listing","trombi/index.php?view=listing", "La promo"),
              array("stats","trombi/index.php?view=stats", "Des chiffres")
             );
$cts = new contents("Trombinoscope, Promo ".sprintf("%02d",$site->user->promo_utbm));
$cts->add(new tabshead($tabs,$_REQUEST["view"]));


Ayolo's avatar
Ayolo committed
208
209
210
211
212
213
214
215
216
217
218
219
if(isset($_REQUEST["stats"]))
{
  if($_REQUEST["stats"]=="sexe")
  {
    $req = new requete($site->db,
                       "SELECT `utilisateurs`.`sexe_utl`, COUNT(`utilisateurs`.`sexe_utl`) ".
                       "FROM `utl_etu_utbm` ".
                       "LEFT JOIN `utilisateurs` USING (`id_utilisateur`) ".
                       "WHERE `promo_utbm`='" . $site->user->promo_utbm . "' ".
                       "GROUP BY `utilisateurs`.`sexe_utl`");
    $cam=new camembert(600,400,array(),2,0,0,0,0,0,0,10,150);
    while(list($sexe,$nb)=$req->get_row())
Ayolo's avatar
Ayolo committed
220
    {
Ayolo's avatar
Ayolo committed
221
222
      if($sexe==1)
        $cam->data($nb, "Homme");
Ayolo's avatar
Ayolo committed
223
      elseif($sexe=="2")
Ayolo's avatar
Ayolo committed
224
225
226
227
228
        $cam->data($nb, "Femme");
    }
    $cam->png_render();
    exit();
  }
Ayolo's avatar
Ayolo committed
229
  elseif($_REQUEST["stats"]=="departements")
Ayolo's avatar
Ayolo committed
230
  {
Ayolo's avatar
Ayolo committed
231
    $cam=new camembert(600,400,array(),2,0,0,0,0,0,0,10,150);
Ayolo's avatar
Ayolo committed
232
    $req = new requete($site->db,
Ayolo's avatar
bleh    
Ayolo committed
233
                       "SELECT `departement_utbm` , COUNT( `departement_utbm` ) ".
Ayolo's avatar
Ayolo committed
234
                       "FROM `utl_etu_utbm` ".
Ayolo's avatar
Ayolo committed
235
                       "WHERE `promo_utbm` = '" . $site->user->promo_utbm . "'".
Ayolo's avatar
bleh    
Ayolo committed
236
                       "GROUP BY `departement_utbm`");
Ayolo's avatar
Ayolo committed
237
238
239
240
241
    while(list($branche,$nb)=$req->get_row())
      $cam->data($nb, $branche);
    $cam->png_render();
    exit();
  }
Ayolo's avatar
Ayolo committed
242
  elseif($_REQUEST["stats"]=="naissances")
Ayolo's avatar
Ayolo committed
243
244
245
246
247
248
249
250
251
252
253
254
  {
    $req = new requete($site->db,
                       "SELECT substring(`utilisateurs`.`date_naissance_utl`,1,7) AS date, ".
                       "COUNT(substring(`utilisateurs`.`date_naissance_utl`,1,7)) as num ".
                       "FROM `utilisateurs` ".
                       "INNER JOIN `utl_etu_utbm` USING(`id_utilisateur`) ".
                       "WHERE `utl_etu_utbm`.`promo_utbm`='" . $site->user->promo_utbm . "' ".
                       "AND `utilisateurs`.`date_naissance_utl` IS NOT NULL ".
                       "AND `utilisateurs`.`date_naissance_utl` != '1970-01-01' ".
                       "AND `utilisateurs`.`date_naissance_utl` != '0000-00-00' ".
                       "GROUP BY substring(`utilisateurs`.`date_naissance_utl`,1,7) ".
                       "ORDER BY substring(`utilisateurs`.`date_naissance_utl`,1,7) ASC");
Ayolo's avatar
Ayolo committed
255
256
257
258
    $coords = array();
    $xtics = array();
    $i = 0;
    $step = (int) ($req->lines / 5);
Ayolo's avatar
Ayolo committed
259
    while(list($date,$nb)=$req->get_row())
Ayolo's avatar
Ayolo committed
260
261
262
263
    {
      if (($i % $step) == 0)
        $xtics[$i]=$date;
      $coords[] = array('x' => $i,'y' => $nb);
Ayolo's avatar
Ayolo committed
264
      $i++;
Ayolo's avatar
Ayolo committed
265
    }
Ayolo's avatar
Ayolo committed
266
    $graph = new graphic("", "Date de naissance des membres",$coords,false,$xtics);
Ayolo's avatar
Ayolo committed
267
268
    $graph->png_render();
    $graph->destroy_graph();
Ayolo's avatar
Ayolo committed
269
270
    exit();
  }
Ayolo's avatar
Ayolo committed
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  elseif($_REQUEST["stats"]=="france")
  {
    $img = new imgcarto(800, 10);
    $img->addcolor('pblue_dark', 51, 102, 153);
    $img->addcolor('pblue', 222, 235, 245);

    $nbpaliers = 5;

    $img->addcolor('l0', 255, 255, 255);
    $img->addcolor('l1', 255, 220, 0);
    $img->addcolor('l2', 255, 198, 0);
    $img->addcolor('l3', 255, 176, 0);
    $img->addcolor('l4', 255, 154, 0);
    $img->addcolor('l5', 255, 143, 0);
    $img->addcolor('l6', 255, 121, 0);
    $img->addcolor('l7', 255, 114, 0);
    $img->addcolor('l8', 255, 101, 0);
    $img->addcolor('l9', 255, 68, 0);
    $img->addcolor('l10', 255, 0, 0);
Ayolo's avatar
Ayolo committed
290
    $img->addcolor('lsux', 255, 255, 0);
Ayolo's avatar
Ayolo committed
291
292
293

    $pgconn = new pgsqlae();

294
295
296
    $statscotis = new requete($site->db, "SELECT
                                          COUNT(`utl_etu`.`id_utilisateur`) AS num
                                          , substring(cpostal_ville,1,2) AS cpostal
Ayolo's avatar
Ayolo committed
297
298
299
300
301
                                          FROM `utl_etu`
                                          INNER JOIN `loc_ville` ON `loc_ville`.`id_ville` = `utl_etu`.`id_ville`
                                          INNER JOIN `utl_etu_utbm` ON `utl_etu_utbm`.`id_utilisateur` = `utl_etu`.`id_utilisateur`
                                          WHERE `utl_etu`.`id_ville` IS NOT NULL AND `utl_etu_utbm`.`promo_utbm`='" . $site->user->promo_utbm . "'
                                          GROUP BY substring(cpostal_ville,1,2)");
Ayolo's avatar
Ayolo committed
302
    $max=0;
Ayolo's avatar
Ayolo committed
303
304
305
    while ($rs = $statscotis->get_row())
    {
      $statsdep[$rs['cpostal']] = $rs['num'];
Ayolo's avatar
Ayolo committed
306
307
      if($max<$rs['num'])
        $max=$rs['num'];
Ayolo's avatar
Ayolo committed
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
    }
    $pgreq = new pgrequete($pgconn, "SELECT code_dept, nom_dept, asText(simplify(the_geom, 2000)) AS points FROM deptfr");
    $rs = $pgreq->get_all_rows();
    $numdept = 0;
    $dept=array();
    foreach($rs as $result)
    {
      $astext = $result['points'];
      $matched = array();
      preg_match_all("/\(([^)]*)\)/", $astext, $matched);
      $i = 0;
      foreach ($matched[1] as $polygon)
      {
        $polygon = str_replace("(", "", $polygon);
        $points = explode(",", $polygon);
        foreach ($points as $point)
        {
          $coord = explode(" ", $point);
          $dept[$numdept]['plgs'][$i][] = $coord[0];
          $dept[$numdept]['plgs'][$i][] = $coord[1];
        }
        $i++;
      }
      $dept[$numdept]['name'] = $result['nom_dept'];
      $dept[$numdept]['iddept'] = $result['code_dept'];

      $numdept++;
    }
    foreach($dept as $departement)
    {
      foreach($departement['plgs'] as $plg)
      {
        if ($statsdep[$departement['iddept']] == 0)
          $img->addpolygon($plg, 'l0', true,
                           array('id' =>$departement['gid'],
Ayolo's avatar
Ayolo committed
343
                                 'url' => "".
Ayolo's avatar
Ayolo committed
344
                                 $departement['iddept']. ")"));
Ayolo's avatar
Ayolo committed
345
346
        else
        {
Ayolo's avatar
Ayolo committed
347
          $color=(int)(($statsdep[$departement['iddept']]*10)/$max);
Ayolo's avatar
Ayolo committed
348
349
350
          if($color==0)
            $color="sux";
          $img->addpolygon($plg, 'l' . $color, true,
Ayolo's avatar
Ayolo committed
351
                           array('id' =>$departement['gid'],
Ayolo's avatar
Ayolo committed
352
                                 'url' => "".
Ayolo's avatar
Ayolo committed
353
354
                                 $departement['iddept']. ")"));
        }
Ayolo's avatar
Ayolo committed
355
356
357
358
359
360
        $img->addpolygon($plg, 'black', false);
      }
    }

    $img->draw();
    $wm_img = new img_watermark ($img->imgres);
Ayolo's avatar
Ayolo committed
361
    $wm_img->output();
Ayolo's avatar
Ayolo committed
362
363
    exit();
  }
Ayolo's avatar
Ayolo committed
364
365
}

Ayolo's avatar
blurp    
Ayolo committed
366

Ayolo's avatar
blurp    
Ayolo committed
367
if($_REQUEST["view"] == "listing")
Ayolo's avatar
Ayolo committed
368
{
Ayolo's avatar
blurp    
Ayolo committed
369
  $site->add_css("css/mmt.css");
Ayolo's avatar
blurp    
Ayolo committed
370
371
372
373
374
375
376
  $npp=18;
  $page = intval($_REQUEST["page"]);

  if ( $page)
    $st=$page*$npp;
  else
    $st=0;
377
  /*
Ayolo's avatar
blurp    
Ayolo committed
378
379
380
381
382
383
384
385
386
  $reqnb = new requete($site->db,
                       "SELECT COUNT(`utilisateurs`.`id_utilisateur`) "
                       ."FROM `utl_etu_utbm` "
                       ."LEFT JOIN `utilisateurs` USING (`id_utilisateur`) "
                       ."LEFT JOIN `utl_etu` USING (`id_utilisateur`) "
                       ."WHERE `promo_utbm`='" . $site->user->promo_utbm . "' "
                       ."AND `publique_utl`='1'");
  list($nb) = $reqnb->get_row();

387
388
389
  */

  $reqnb = new requete($site->db,
390
                       "SELECT
391
392
393
                               `utilisateurs`.`nom_utl`
                        FROM
                               `utl_etu_utbm`
394
395
                        LEFT JOIN
                               `utilisateurs`
396
                        USING (`id_utilisateur`)
397
398
                        LEFT JOIN
                               `utl_etu`
399
                        USING (`id_utilisateur`)
400
                        WHERE
401
                               `promo_utbm`='" . $site->user->promo_utbm . "'
402
                        AND
403
                               `publique_utl`>='".($site->user->cotisant ? '1' : '2')."'
404
405
406
407
408
409
410
411
                        ORDER BY
                               `nom_utl`
                        ASC");

  $nb = $reqnb->lines;

  $noms = array();

412
  while ($res = $reqnb->get_row())
413
414
415
416
417
418
    {
      $noms[] = $res['nom_utl'];
    }



Ayolo's avatar
blurp    
Ayolo committed
419
  $req = new requete($site->db,
Ayolo's avatar
Ayolo committed
420
                     "SELECT `utilisateurs`.*, `utl_etu`.*, `utl_etu_utbm`.*, "
Ayolo's avatar
Ayolo committed
421
                    ."`utilisateurs`.`id_ville` AS `id_ville`, `utl_etu`.`id_ville` AS `ville_parents`, "
Ayolo's avatar
Ayolo committed
422
                    ."`utilisateurs`.`id_pays` AS `id_pays`, `utl_etu`.`id_pays` AS `pays_parents` "
Ayolo's avatar
Ayolo committed
423
424
425
426
                    ."FROM `utl_etu_utbm` "
                    ."LEFT JOIN `utilisateurs` USING (`id_utilisateur`) "
                    ."LEFT JOIN `utl_etu` USING (`id_utilisateur`) "
                    ."WHERE `promo_utbm`='" . $site->user->promo_utbm . "' "
427
                    ."AND `publique_utl`>='".($site->user->cotisant ? '1' : '2')."' "
Ayolo's avatar
Ayolo committed
428
429
                    ."ORDER BY `nom_utl`, `prenom_utl` ASC "
                    ."LIMIT ".$st." , ".$npp."");
Ayolo's avatar
blurp    
Ayolo committed
430
431
432
433
  if ($req->lines == 0)
    $tbl = new error("Aucun resultat","");
  else
  {
Ayolo's avatar
blurp    
Ayolo committed
434
435
436
437
438
    $gal = new gallery();
    $tmpuser = new utilisateur($site->db);
    while ( $row = $req->get_row() )
    {
      $tmpuser->_load_all($row);
Ayolo's avatar
Ayolo committed
439
      $gal->add_item(new userinfov2($tmpuser, "small", false, "trombi/index.php"));
Ayolo's avatar
blurp    
Ayolo committed
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
    }
    $cts->add($gal);
    if ( $nb > $npp )
    {
      $tabs = array();
      $i=0;
      while ( $i < $nb )
      {
        $n = $i/$npp;
        $url = "";
        $ar = array_merge($_GET,$_POST);
        $ar["page"] = $n;
        foreach ( $ar as $key => $value )
        {
          if( $key != "magicform" && $value && $key != "mmtsubmit" )
          {
            if ( $url )
              $url .= "&";
            else
              $url = "trombi/index.php?";
            if ( !is_array($value) )
              $url .= $key."=".rawurlencode($value);
          }
        }
464

Ayolo's avatar
bleh    
Ayolo committed
465
466
467
468
469
  $firstnamepage = substr($noms[$i], 0, 3);
  if (($i + $npp - 1) < count($noms))
    $lastnamepage  = substr($noms[$i + $npp - 1], 0,3);
  else
    $lastnamepage  = substr($noms[count($noms) - 1], 0,3);
470
471

        /* $tabs[]=array($n,$url,$n+1 ); */
Ayolo's avatar
bleh    
Ayolo committed
472
  $tabs[] = array($n, $url, $firstnamepage . " - " . $lastnamepage);
473

Ayolo's avatar
blurp    
Ayolo committed
474
475
476
477
        $i+=$npp;
      }
      $cts->add(new tabshead($tabs, $page, "_bottom"));
    }
Ayolo's avatar
blurp    
Ayolo committed
478
  }
Ayolo's avatar
Ayolo committed
479
}
Ayolo's avatar
Ayolo committed
480
481
elseif($_REQUEST["view"]=="stats")
{
Ayolo's avatar
fixes    
Ayolo committed
482
  $cts->add_paragraph("Des stats, des stats, oui mais des panzani ! (&copy;Ayolo)");
Ayolo's avatar
Ayolo committed
483
484
485
  $site->add_contents($cts);
  $cts = new contents("Répartition Homme/Femme dans la promo");
  $cts->add_paragraph("<center><img src=\"index.php?stats=sexe\" alt=\"répartition Homme/Femme\" /></center>\n");
Ayolo's avatar
Ayolo committed
486
  $site->add_contents($cts);
Ayolo's avatar
Ayolo committed
487
488
  $cts = new contents("Carte de la natalité");
  $cts->add_paragraph("<center><img src=\"index.php?stats=naissances\" alt=\"graph des naissances\" /></center>\n");
Ayolo's avatar
Ayolo committed
489
  $site->add_contents($cts);
Ayolo's avatar
Ayolo committed
490
491
  $cts = new contents("Répartition par départements");
  $cts->add_paragraph("<center><img src=\"index.php?stats=departements\" alt=\"répartition par départements\" /></center>\n");
Ayolo's avatar
Ayolo committed
492
493
494
  $site->add_contents($cts);
  $cts = new contents("Carte de france de la promo");
  $cts->add_paragraph("<center><img src=\"index.php?stats=france\" alt=\"carte de france de la promo\" /></center>\n");
Ayolo's avatar
Ayolo committed
495
}
Ayolo's avatar
Ayolo committed
496
497
else
{
vazlin's avatar
debug    
vazlin committed
498
  $cts->add_paragraph("<a name=\"trombicard\"></a>");
Ayolo's avatar
blurp    
Ayolo committed
499
  $cts->add_title(2, "Informations personnelles");
Ayolo's avatar
Ayolo committed
500
  $info = new userinfov2($user,"full",$site->user->is_in_group("gestion_ae"), "trombi/index.php");
Ayolo's avatar
blurp    
Ayolo committed
501
  $cts->add($info);
502

vazlin's avatar
vazlin committed
503
  /* renvoie plus bas */
vazlin's avatar
debug    
vazlin committed
504
  $cts->add_paragraph("<a href=\"#comments\">Voir les commentaires</a>");
Ayolo's avatar
addons    
Ayolo committed
505
506

  /* photos */
Ayolo's avatar
addons    
Ayolo committed
507
  $grps = $site->user->get_groups_csv();
Ayolo's avatar
fixes    
Ayolo committed
508
  $req = new requete($site->db,"SELECT sas_photos.* " .
Ayolo's avatar
addons    
Ayolo committed
509
510
511
512
513
                               "FROM sas_personnes_photos AS `p2` " .
                               "INNER JOIN sas_photos ON p2.id_photo=sas_photos.id_photo " .
                               "INNER JOIN sas_cat_photos ON sas_cat_photos.id_catph=sas_photos.id_catph " .
                               "LEFT JOIN sas_personnes_photos AS `p1` ON " .
                               "(p1.id_photo=sas_photos.id_photo " .
Ayolo's avatar
fixes    
Ayolo committed
514
                               "AND p1.id_utilisateur='". $site->user->id."' " .//$site->user->id
Ayolo's avatar
addons    
Ayolo committed
515
516
517
518
519
520
521
522
523
                               "AND p1.modere_phutl='1') " .
                               "WHERE " .
                               "p2.id_utilisateur='". $user->id."' AND " .
                               "((((droits_acces_ph & 0x1) OR " .
                               "((droits_acces_ph & 0x10) AND sas_photos.id_groupe IN ($grps))) " .
                               "AND droits_acquis='1') OR " .
                               "(sas_photos.id_groupe_admin IN ($grps)) OR " .
                               "((droits_acces_ph & 0x100) AND sas_photos.id_utilisateur='". $site->user->id."') OR " .
                               "((droits_acces_ph & 0x100) AND p1.id_utilisateur IS NOT NULL) ) " .
Ayolo's avatar
Ayolo committed
524
525
                               "ORDER BY RAND() ".
                               "LIMIT 5"
Ayolo's avatar
addons    
Ayolo committed
526
                     );
Ayolo's avatar
Ayolo committed
527
  if($req->lines>0)
Ayolo's avatar
addons    
Ayolo committed
528
  {
Ayolo's avatar
Ayolo committed
529
    $site->add_css("css/sas.css");
Ayolo's avatar
addons    
Ayolo committed
530
531
    $site->add_contents($cts);
    $cts = new contents("Photos");
Ayolo's avatar
Ayolo committed
532
    $gal = new gallery("Photos aléatoires","photos");
Ayolo's avatar
Ayolo committed
533
534
535
536
537
538
539
    while ( $row = $req->get_row())
    {
      $img = $topdir."sas2/images.php?/".$row['id_photo'].".vignette.jpg";
      $gal->add_item("<a href=\"".$topdir."sas2/?id_photo=".$row['id_photo']."\"><img src=\"$img\" alt=\"Photo\"></a>");
    }
    $cts->add($gal,true);
    $cts->add_paragraph("<a href=\"".$topdir."user/photos.php?id_utilisateur=".$user->id."\">Toutes les photos</a>.");
Ayolo's avatar
addons    
Ayolo committed
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
  }

  /* genealogie */
  $genea=false;
  $req = new requete($site->db,
                "SELECT `utilisateurs`.`id_utilisateur` AS `id_utilisateur2`, " .
                "IF(utl_etu_utbm.surnom_utbm!='' AND utl_etu_utbm.surnom_utbm IS NOT NULL,utl_etu_utbm.surnom_utbm, CONCAT(`utilisateurs`.`prenom_utl`,' ',`utilisateurs`.`nom_utl`)) as `nom_utilisateur2` " .
                "FROM `parrains` " .
                "INNER JOIN `utilisateurs` ON `utilisateurs`.`id_utilisateur`=`parrains`.`id_utilisateur` " .
                "LEFT JOIN `utl_etu_utbm` ON `utl_etu_utbm`.`id_utilisateur`=`utilisateurs`.`id_utilisateur` ".
                "WHERE `parrains`.`id_utilisateur_fillot`='".$user->id."'");
  if ( $req->lines > 0 )
  {
    $site->add_contents($cts);
    $cts = new contents("Généalogie");
Ayolo's avatar
Ayolo committed
555
    $cts->add_paragraph("<a href=\"".$topdir."family.php?id_utilisateur=".$user->id."\">Arbre généalogique parrains/fillots</a>.");
Ayolo's avatar
addons    
Ayolo committed
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
    $genea=true;
    $tbl = new sqltable("listasso",
                        "Parrain(s)/Marraine(s)", $req, "user.php?view=parrain&mode=parrain&id_utilisateur=".$user->id,
                        "id_utilisateur2",
                        array("nom_utilisateur2"=>"Parrain/Marraine"),
                        array("delete"=>"Enlever"), array(), array( )
                      );
    $cts->add($tbl,true);
  }
  $req = new requete($site->db,
                "SELECT `utilisateurs`.`id_utilisateur` AS `id_utilisateur2`, " .
                "IF(utl_etu_utbm.surnom_utbm!='' AND utl_etu_utbm.surnom_utbm IS NOT NULL,utl_etu_utbm.surnom_utbm, CONCAT(`utilisateurs`.`prenom_utl`,' ',`utilisateurs`.`nom_utl`)) as `nom_utilisateur2` " .
                "FROM `parrains` " .
                "INNER JOIN `utilisateurs` ON `utilisateurs`.`id_utilisateur`=`parrains`.`id_utilisateur_fillot` " .
                "LEFT JOIN `utl_etu_utbm` ON `utl_etu_utbm`.`id_utilisateur`=`utilisateurs`.`id_utilisateur` ".
                "WHERE `parrains`.`id_utilisateur`='".$user->id."'");
  if ( $req->lines > 0 )
  {
    if(!$genea)
    {
      $site->add_contents($cts);
      $cts = new contents("Généalogie");
Ayolo's avatar
Ayolo committed
578
      $cts->add_paragraph("<a href=\"".$topdir."family.php?id_utilisateur=".$user->id."\">Arbre généalogique parrains/fillots</a>.");
Ayolo's avatar
addons    
Ayolo committed
579
580
581
582
583
584
585
586
587
588
    }
    $tbl = new sqltable("listasso",
                      "Fillot(s)/Fillote(s)", $req, "user.php?view=parrain&mode=fillot&id_utilisateur=".$user->id,
                      "id_utilisateur2",
                      array("nom_utilisateur2"=>"Fillot/Fillote"),
                      array("delete"=>"Enlever"), array(), array( )
                    );
    $cts->add($tbl,true);
  }

Ayolo's avatar
Ayolo committed
589
  $asso=false;
Ayolo's avatar
Ayolo committed
590
591
592
593
594
595
596
597
598
599
600
601
602
  /* Associations en cours */
  $req = new requete($site->db,
                     "SELECT `asso`.`id_asso`, `asso`.`nom_asso`, " .
                     "IF(`asso`.`id_asso_parent` IS NULL,`asso_membre`.`role`+100,`asso_membre`.`role`) AS `role`, ".
                     "`asso_membre`.`date_debut`, `asso_membre`.`desc_role`, " .
                     "CONCAT(`asso`.`id_asso`,',',`asso_membre`.`date_debut`) as `id_membership` " .
                     "FROM `asso_membre` " .
                     "INNER JOIN `asso` ON `asso`.`id_asso`=`asso_membre`.`id_asso` " .
                     "WHERE `asso_membre`.`id_utilisateur`='".$user->id."' " .
                     "AND `asso_membre`.`date_fin` is NULL " .
                     "ORDER BY `asso`.`nom_asso`");
  if ( $req->lines > 0 )
  {
Ayolo's avatar
Ayolo committed
603
604
605
    $site->add_contents($cts);
    $cts = new contents("Associations");
    $asso=true;
Ayolo's avatar
Ayolo committed
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
    $tbl = new sqltable("listasso",
                        "Associations et clubs actuels",
                        $req,
                        "user.php?id_utilisateur=".$user->id,
                        "id_membership",
                          array("nom_asso"=>"Association","role"=>"Role","desc_role"=>"","date_debut"=>"Depuis"),
                          $can_edit?array("delete"=>"Supprimer","stop"=>"Arreter à la date de ce jour"):array(),
                          array(),
                          array("role"=>$GLOBALS['ROLEASSO100'])
                        );
    $cts->add($tbl,true);
  }
  /* Anciennes assos */
  $req = new requete($site->db,
                     "SELECT `asso`.`id_asso`, `asso`.`nom_asso`, " .
                     "IF(`asso`.`id_asso_parent` IS NULL,`asso_membre`.`role`+100,`asso_membre`.`role`) AS `role`, ".
                     "`asso_membre`.`date_debut`, `asso_membre`.`desc_role`, `asso_membre`.`date_fin`, " .
                     "CONCAT(`asso`.`id_asso`,',',`asso_membre`.`date_debut`) as `id_membership` " .
                     "FROM `asso_membre` " .
                     "INNER JOIN `asso` ON `asso`.`id_asso`=`asso_membre`.`id_asso` " .
                     "WHERE `asso_membre`.`id_utilisateur`='".$user->id."' " .
                     "AND `asso_membre`.`date_fin` is NOT NULL " .
                     "ORDER BY `asso`.`nom_asso`,`asso_membre`.`date_debut`");
  if ( $req->lines > 0 )
  {
Ayolo's avatar
Ayolo committed
631
632
633
634
635
    if(!$asso)
    {
      $site->add_contents($cts);
      $cts = new contents("Associations");
    }
Ayolo's avatar
Ayolo committed
636
637
638
639
640
641
642
643
    $tbl = new sqltable("listassoformer",
                        "Associations et clubs (anciennes participations)", $req, "user.php?id_utilisateur=".$user->id,
                        "id_membership",
                        array("nom_asso"=>"Association","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['ROLEASSO100'] )
                       );
    $cts->add($tbl,true);
  }
644

645
646
647
  /* Commentaires */
  $site->add_contents($cts);
  $cts = new contents("Commentaires");
vazlin's avatar
debug    
vazlin committed
648
  $cts->add_paragraph("<a name=\"comments\"></a><a href=\"#trombicard\">Remonter aux informations personnelles</a>");
649

650
  $req = new requete($site->db,
vazlin's avatar
vazlin committed
651
652
653
654
           "SELECT `trombi_commentaire`.*, `utilisateurs`.*
             FROM `trombi_commentaire`
             LEFT JOIN `utilisateurs`
               ON `trombi_commentaire`.`id_commentateur` = `utilisateurs`.`id_utilisateur`
655
             WHERE `id_commente` = '" .
vazlin's avatar
vazlin committed
656
657
            mysql_real_escape_string($user->id) . "'
             ORDER BY date_commentaire ASC"
658
         );
vazlin's avatar
vazlin committed
659

660
  $cmt_exists = false;
vazlin's avatar
vazlin committed
661
  $are_comments = false;
vazlin's avatar
vazlin committed
662
  $all_cmt_moderated = true;
vazlin's avatar
vazlin committed
663
  $commentaires = array();
vazlin's avatar
debug    
vazlin committed
664
  while ( $row = $req->get_row() )
vazlin's avatar
vazlin committed
665
666
  {
    $commentaires[$row["id_commentaire"]] = $row;
667

vazlin's avatar
vazlin committed
668
    if ( $row["id_commentateur"] == $site->user->id )
vazlin's avatar
test    
vazlin committed
669
    {
vazlin's avatar
vazlin committed
670
      $cmt_exists = true;
vazlin's avatar
test    
vazlin committed
671
672
      $cmt_is_moderated = $row["modere_commentaire"];
    }
673

vazlin's avatar
vazlin committed
674
    if ( !$row["modere_commentaire"] )
675
      $all_cmt_moderated = false;
vazlin's avatar
vazlin committed
676
  }
677

vazlin's avatar
vazlin committed
678
  $are_comments = ( count($commentaires) > 0 );
679

vazlin's avatar
vazlin committed
680
  if ( !$are_comments )
681
  {
vazlin's avatar
vazlin committed
682
683
    $cts->add_paragraph( ($is_user_page ? "Vous n'avez" : "Cet utilisateur n'a") . " encore aucun commentaire.");
  }
684
685
  else
  {
vazlin's avatar
vazlin committed
686
687
    if ($all_cmt_moderated )
      $cts->add_paragraph( ($is_user_page ? "Vous avez" : "Cet utilisateur a") . " des commentaires, mais ils ont tous été modérés.");
688

689
690
    if ( !$is_user_page )
    {
691

692
693
      if ( $cmt_exists )
      {
vazlin's avatar
vazlin committed
694
695
696
        if ( !$cmt_is_moderated )
          $cts->add_paragraph("<a href=\"#mycomment\">Aller à mon commentaire</a>");
        else
vazlin's avatar
vazlin committed
697
          $cts->add_paragraph("<strong>Attention :</strong> Votre commentaire a été modéré. Peut-être contenait-il un contenu offensant.<br />Contactez un responsable de vore promo pour toute réclamation.");
698
699
      }
    }
700

vazlin's avatar
vazlin committed
701
    foreach ( $commentaires as $row )
702
    {
vazlin's avatar
vazlin committed
703
      $cts->add(new comment_contents(&$row, $site->user->id, $is_user_moderator));
704
    }
705

706
  }
707

708
  if ( !$is_user_page && !$cmt_exists )
709
  {
vazlin's avatar
debug    
vazlin committed
710
    $frm = new form("createcomment", "index.php#mycomment", false, "POST", "Ajouter mon commentaire");
711
    $frm->add_hidden("action","create");
vazlin's avatar
debug    
vazlin committed
712
    $frm->add_hidden("id_utilisateur",$user->id);
713
    $frm->add_info("<b>ATTENTION</b>Votre commentaire peut &ecirc;tre mod&eacute;r&eacute;");
vazlin's avatar
vazlin committed
714
715
    $frm->add_dokuwiki_toolbar('commentaire');
    $frm->add_text_area ("commentaire","Commentaire");
716
    $frm->add_submit("valid","Enregistrer");
717

718
719
720
    $cts->add($frm);
    $cts->add(new wikihelp());
  }
Ayolo's avatar
Ayolo committed
721
}
722

723

Ayolo's avatar
Ayolo committed
724
725
$site->add_contents($cts);

Ayolo's avatar
blurp    
Ayolo committed
726

Ayolo's avatar
Ayolo committed
727
728
729
$site->end_page ();

?>