site.inc.php 49.4 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
4
5
6
<?php
/** @file
 *
 * @brief Fonctions générales du site.
 *
 */
Ayolo's avatar
bleh    
Ayolo committed
7
/* Copyright 2004,2005,2006,2007,2008
Ayolo's avatar
Ayolo committed
8
9
10
11
12
 * - Alexandre Belloni <alexandre POINT belloni CHEZ utbm POINT fr>
 * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
 * - Maxime Petazzoni <maxime POINT petazzoni CHEZ bulix POINT org>
 * - Pierre Mauduit <pierre POINT mauduit CHEZ utbm POINT fr>
 * - Julien Etelain <julien CHEZ pmad POINT net>
BenC's avatar
BenC committed
13
14
 * - Benjamin Collet <bcollet CHEZ oxynux POINT org>
 * - Sarah Amsellem <sarah POINT amsellem CHEZ gmail POINT com>
Ayolo's avatar
bleh    
Ayolo committed
15
 * - Simon Lopez < simon dot lopez at ayolo dot org >
Ayolo's avatar
Ayolo committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 *
 * Ce fichier fait partie du site de l'Association des 0tudiants 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.
 */
35

Feu's avatar
Feu committed
36
37
if ( !isset($GLOBALS['nosession']) )
  session_start();
Ayolo's avatar
Ayolo committed
38

BenC's avatar
fix    
BenC committed
39
if ( $_SERVER["REMOTE_ADDR"] == "127.0.1.1" )
BenC's avatar
kwain    
BenC committed
40
41
  $GLOBALS["is_using_ssl"] = true;

Ayolo's avatar
Ayolo committed
42
43
44
45
46
47
require_once($topdir . "include/interface.inc.php");
require_once($topdir . "include/globals.inc.php");
require_once($topdir . "include/cts/calendar.inc.php");
require_once($topdir . "include/entities/sondage.inc.php");
require_once($topdir . "include/entities/campagne.inc.php");
require_once($topdir . "include/entities/cotisation.inc.php");
gliss's avatar
gliss committed
48
require_once($topdir . "jobetu/include/jobuser_etu.inc.php");
Ayolo's avatar
Ayolo committed
49
50
51
52

/** La classe principale du site */
class site extends interfaceweb
{
Ayolo's avatar
bleh    
Ayolo committed
53

Ayolo's avatar
Ayolo committed
54
  /** Constructeur de la classe */
Ayolo's avatar
bleh    
Ayolo committed
55
  function site ($siteae=true)
Ayolo's avatar
Ayolo committed
56
  {
Feu's avatar
Feu committed
57
    global $timing;
Feu's avatar
Feu committed
58
    $timing["includes"] = microtime(true)+$timing["all"];
Feu's avatar
Feu committed
59
    $timing["site::site"] -= microtime(true);
Ayolo's avatar
bleh    
Ayolo committed
60
61
62

    $this->siteae=$siteae;

Ayolo's avatar
Ayolo committed
63
    $dbro = new mysqlae ();
64

Feu's avatar
debug    
Feu committed
65
    if (!$dbro->dbh)
Ayolo's avatar
Ayolo committed
66
67
68
      $this->fatal("no db");

    $dbrw = new mysqlae ("rw");
Feu's avatar
debug    
Feu committed
69
    if (!$dbrw->dbh)
70
      $this->fatal("no dbrw");
Ayolo's avatar
Ayolo committed
71

72
    $this->interfaceweb($dbro, $dbrw);
Ayolo's avatar
Ayolo committed
73

BenC's avatar
Kwain    
BenC committed
74
75
    if($_COOKIE['AE2_SESS_ID'])
      $this->load_session($_COOKIE['AE2_SESS_ID']);
Ayolo's avatar
Ayolo committed
76

77
78
    if ( $this->get_param("closed",false) && !$this->user->is_in_group("root") )
      $this->fatal("closed");
Ayolo's avatar
Ayolo committed
79

Feu's avatar
Feu committed
80
    $timing["site::site"] += microtime(true);
Ayolo's avatar
Ayolo committed
81
82
83
84

    /*
     * LEs css du site ae restent sur le site ae
     */
Ayolo's avatar
bleh    
Ayolo committed
85
/*    if ( $siteae )
Ayolo's avatar
Ayolo committed
86
    {
Ayolo's avatar
bleh    
Ayolo committed
87
88
      $this->add_css("themes/congres08/css/site.css");
    }*/
89
90

  }
Feu's avatar
Feu committed
91

Feu's avatar
test    
Feu committed
92
93
  private function unset_session (  )
  {
BenC's avatar
Kwain    
BenC committed
94
    if ( isset($_COOKIE['AE2_SESS_ID']) )
Feu's avatar
test    
Feu committed
95
96
    {
      $domain = ($_SERVER['HTTP_HOST'] != 'localhost' && $_SERVER['HTTP_HOST'] != '127.0.0.1') ? $_SERVER['HTTP_HOST'] : false;
BenC's avatar
debug    
BenC committed
97

BenC's avatar
Kwain    
BenC committed
98
99
      setcookie ("AE2_SESS_ID", "", time() - 3600, "/", $domain);
      unset($_COOKIE['AE2_SESS_ID']);
Feu's avatar
test    
Feu committed
100
    }
101

Feu's avatar
test    
Feu committed
102
    if ( !isset($_SESSION["visite"]) )
103
104
      unset($_SESSION['visite']);

Feu's avatar
test    
Feu committed
105
106
107
108
109
    if ( isset($_SESSION['session_redirect']) )
      unset($_SESSION['session_redirect']);
  }


Feu's avatar
Feu committed
110
111
112
113
  /**
   * Charge une session en fonction de son identidiant.
   * @param $sid Identifiant de la session
   */
Feu's avatar
test    
Feu committed
114
  function load_session ( $sid )
Ayolo's avatar
Ayolo committed
115
  {
Feu's avatar
test    
Feu committed
116

117
    $req = new requete($this->db,
Feu's avatar
test    
Feu committed
118
119
120
121
122
123
      "SELECT `utilisateurs`.*, `expire_sess`, `derniere_visite`  ".
      "FROM `site_sessions` ".
      "INNER JOIN `utilisateurs` USING(`id_utilisateur`) ".
      "WHERE `id_session` = '".mysql_escape_string($sid)."'");

    if ($req->lines < 1 )
124
    {
Feu's avatar
test    
Feu committed
125
126
127
      $this->unset_session();
      return;
    }
128

Feu's avatar
test    
Feu committed
129
    $row = $req->get_row();
130

Feu's avatar
test    
Feu committed
131
132
133
134
135
    if ( $row["hash_utl"] != "valid")
    {
      new delete($this->dbrw,"site_sessions",array("id_session" => $sid));
      $this->unset_session();
      return;
136
    }
137

Feu's avatar
Feu committed
138
    $expire = $row['expire_sess'];
Feu's avatar
test    
Feu committed
139

140
    // On n'est pas à une minute près
Feu's avatar
test    
Feu committed
141
142
    $d = date("Y-m-d H:i:")."00";

Feu's avatar
Feu committed
143
    if ( !is_null($expire) )
Ayolo's avatar
Ayolo committed
144
    {
Feu's avatar
test    
Feu committed
145
      $expire = strtotime($expire)-time();
146

Feu's avatar
test    
Feu committed
147
      if ( $expire < 0 ) // Session expirée, fait le ménage
Ayolo's avatar
Ayolo committed
148
      {
Feu's avatar
test    
Feu committed
149
150
        new delete($this->dbrw,"site_sessions",array("id_session" => $sid));
        $this->unset_session();
Ayolo's avatar
Ayolo committed
151
152
        return;
      }
153

Feu's avatar
test    
Feu committed
154
155
156
157
158
      if ( $d != $row['derniere_visite'] )
        new update($this->dbrw, "site_sessions",
            array(
              "derniere_visite" => $d,
              "expire_sess" => date("Y-m-d H:i:s",time()+(16*60))),
159
              array("id_session" => $sid));
Feu's avatar
test    
Feu committed
160
161
162
163
164
    }
    else if ( $d != $row['derniere_visite'] )
    {
      new update($this->dbrw, "site_sessions",
          array("derniere_visite" => $d),
165
          array("id_session" => $sid));
166
    }
167

Feu's avatar
test    
Feu committed
168
    $this->user->_load($row);
169

Feu's avatar
test    
Feu committed
170
    if ( !isset($_SESSION["visite"]) )
171
    {
Feu's avatar
test    
Feu committed
172
173
      $this->user->visite();
      $_SESSION["visite"]=time();
174
    }
175

Feu's avatar
test    
Feu committed
176
177
    if ( !isset($_SESSION["usersession"]) ) // restore le usersession
      $_SESSION["usersession"] = $this->user->get_param("usersession",null);
178

Ayolo's avatar
Ayolo committed
179
180
  }

Feu's avatar
Feu committed
181
  /**
182
   * Connecte l'utilisateur chargé dans le champ user ($this->user) pour
Feu's avatar
Feu committed
183
184
185
186
   * 15 minutes, ou permanente, en créant une sessions et en envoyant un cookie.
   * @param $forever Precise si la session doit être permanente
   * @return l'identifiant de la session
   */
Ayolo's avatar
Ayolo committed
187
188
189
190
191
192
  function connect_user ($forever=true)
  {
    if ( $forever )
      $expire = null;
    else
      $expire = date("Y-m-d H:i:s",time()+(15*60)); // Session expire dans 15 minutes
193

Ayolo's avatar
Ayolo committed
194
195
196
197
198
199
200
201
202
203
204
    $sid = md5(rand(0,32000) . $_SERVER['REMOTE_ADDR'] . rand(0,32000));

    $req = new insert($this->dbrw, "site_sessions",
            array(
              "id_session"      => $sid,
              "id_utilisateur"    => $this->user->id,
              "date_debut_sess"  => date("Y-m-d H:i:s"),
              "derniere_visite"  => date("Y-m-d H:i:s"),
              "expire_sess" => $expire
              ));
    $domain = ($_SERVER['HTTP_HOST'] != 'localhost' && $_SERVER['HTTP_HOST'] != '127.0.0.1') ? $_SERVER['HTTP_HOST'] : false;
BenC's avatar
debug    
BenC committed
205

BenC's avatar
Kwain    
BenC committed
206
    setcookie ("AE2_SESS_ID", $sid, time() + 31536000, "/", $domain);
Ayolo's avatar
Ayolo committed
207
208
209
210
211

    $this->user->visite();

    return $sid;
  }
212

Feu's avatar
Feu committed
213
214
215
216
217
218
219
220
  /**
   * Crée un identifiant unique pour connecter ultérieurement un utilisateur.
   * Utile pour envoyer un lien par e-mail avec authentification automatique.
   * Le "token" est en fait un identifiant de session, il expire au bout de 60 jours.
   * @param $id_utilisateur Id de l'utilisateur pour qui le "token" doit être généré
   * @return le "token" (identifiant de session)
   * @see load_token
   */
Feu's avatar
wip    
Feu committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
  function create_token_for_user ( $id_utilisateur )
  {
    $sid = "T".$id_utilisateur."$".md5(rand(0,32000) . "TOKEN" . $id_utilisateur . rand(0,32000));

    $req = new insert($this->dbrw, "site_sessions",
            array(
              "id_session"      => $sid,
              "id_utilisateur"    => $id_utilisateur,
              "date_debut_sess"  => date("Y-m-d H:i:s"),
              "derniere_visite"  => date("Y-m-d H:i:s"),
              "expire_sess" => date("Y-m-d H:i:s",time()+(24*60*60*60))
              ));

    return $sid;
  }
236

Feu's avatar
Feu committed
237
238
239
240
241
242
243
244
245
246
247
248
  /**
   * Ouvre une session pour l'utilisateur associé à un token donné.
   * La session est ouverte par le biai de connect_user(). Le token n'est plus
   * valable après l'appel à cette fonction.
   * @param $token le "token"
   * @return null en cas d'echec, ou l'identifiant de la session ouverte
   * @see connect_user
   * @see create_token_for_user
   */
  function load_token ( $token )
  {
    $this->user->id=null;
249
    $this->load_session($token);
Feu's avatar
Feu committed
250
251
252
253
254
255
256
257
258
    if ( $this->user->is_valid() )
    {
      new delete($this->dbrw, "site_sessions", array("id_session"=>$token) );
      return $this->connect_user();
    }
    return null;
  }

  /**
259
   * Crée une session pour  l'utilisateur chargé dans le champ user ($this->user)
Feu's avatar
Feu committed
260
261
262
263
   * pour 15 minutes, ou permanente.
   * @param $forever Precise si la session doit être permanente
   * @return l'identifiant de la session
   */
Ayolo's avatar
Ayolo committed
264
265
266
267
268
269
  function create_session ($forever=true)
  {
    if ( $forever )
      $expire = null;
    else
      $expire = date("Y-m-d H:i:s",time()+(15*60)); // Session expire dans 15 minutes
270

Ayolo's avatar
Ayolo committed
271
272
273
    $sid = md5(rand(0,32000) . $_SERVER['REMOTE_ADDR'] . rand(0,32000));

    $req = new insert($this->dbrw, "site_sessions",
274
275
276
277
278
279
                      array("id_session"      => $sid,
                            "id_utilisateur"  => $this->user->id,
                            "date_debut_sess" => date("Y-m-d H:i:s"),
                            "derniere_visite" => date("Y-m-d H:i:s"),
                            "expire_sess"     => $expire
                           ));
Ayolo's avatar
Ayolo committed
280
281
282
283

    return $sid;
  }

Ayolo's avatar
bleh    
Ayolo committed
284
285
286
287
  function get_connection_contents()
  {
  }

Feu's avatar
Feu committed
288
289
290
291
292
293
294
295
296
297
  /**
   * Demarre la page à rendre en spécifiant quelques informations clefs.
   * Aucune donnée ne sera envoyé au client avant l'appel de end_page.
   * Gènère la liste des boites en fonction de la section.
   * @param $section Nom de la section
   * @param $title Titre de la page
   * @param $compact Cache le logo et la boite informations (utile pour augmenter la taille de contenu visisble sans scroll)
   */
  function start_page ( $section, $title,$compact=false )
  {
Feu's avatar
Feu committed
298
    global $topdir,$timing;
299

Feu's avatar
Feu committed
300
301
    if ( isset($_REQUEST["fetch"]) )
      return;
302

Feu's avatar
Feu committed
303
    $timing["site::start_page"] -= microtime(true);
Feu's avatar
Feu committed
304
    parent::start_page($section,$title,$compact);
Ayolo's avatar
bleh    
Ayolo committed
305
    $this->add_box("calendrier",new calendar($this->db));
306

Feu's avatar
Feu committed
307
308
    if ( $section == "accueil" )
    {
slopez's avatar
slopez committed
309
310
311
312
313
314
315
      require_once($topdir . "include/cts/box_slide_show.inc.php");
      $slides = new box_slideshow('L\'info en boucle');
      $slides->add_slide($this->get_weekly_photo_contents());
      $slides->add_slide($this->get_planning_contents());
      $slides->add_slide($this->get_planning_permanences_contents());
      if ($this->user->is_valid())
        $slides->add_slide($this->get_forum_box());
Ayolo's avatar
bleh    
Ayolo committed
316
317
      if(!$slides->is_empty())
         $this->add_box("info_en_boucle",$slides);
Feu's avatar
Feu committed
318
319
      //Nb: alerts est *trés* long à calculer, il ne sera donc que dans accueil
      $this->add_box("alerts",$this->get_alerts());
320

Feu's avatar
Feu committed
321
322
      $this->add_box("anniv", $this->get_anniv_contents());
      $this->add_box("planning", $this->get_planning_contents());
323

Feu's avatar
Feu committed
324
325
      if ($this->user->is_valid())
      {
Sarah's avatar
Sarah committed
326
        $this->add_box("sondage",$this->get_sondage());
Ayolo's avatar
test    
Ayolo committed
327
        $this->set_side_boxes("right",
Ayolo's avatar
bleh    
Ayolo committed
328
329
330
                              array("alerts",
                                    "calendrier",
                                    "info_en_boucle",
Ayolo's avatar
bleh    
Ayolo committed
331
332
                                    "anniv",
                                    "stream",
Ayolo's avatar
bleh    
Ayolo committed
333
                                    "sondage"
Ayolo's avatar
bleh    
Ayolo committed
334
335
                              ),
                              "accueil_c_right");
336
      }
Feu's avatar
Feu committed
337
338
      else
        $this->set_side_boxes("right",
Ayolo's avatar
bleh    
Ayolo committed
339
340
                              array("calendrier",
                                    "info_en_boucle",
Ayolo's avatar
bleh    
Ayolo committed
341
342
343
                                    "stream"
                              ),
                              "accueil_nc_right");
344

Feu's avatar
Feu committed
345
346
347
    }
    elseif ( $section == "pg" )
    {
Ayolo's avatar
bleh    
Ayolo committed
348
      //$this->set_side_boxes("left",array("connexion"),"pg_left");
Feu's avatar
Feu committed
349
350
    }
    elseif ( $section == "matmatronch" )
Ayolo's avatar
bleh    
Ayolo committed
351
352
      require_once($topdir . "include/cts/newsflow.inc.php");
    elseif($section!='e-boutic' && $section!='sas')
Feu's avatar
Feu committed
353
354
355
356
    {
      $this->set_side_boxes("left",array());
      $this->set_side_boxes("right",array());
    }
Feu's avatar
Feu committed
357
    $timing["site::start_page"] += microtime(true);
358

Feu's avatar
Feu committed
359
360
361
362
363
364
  }

  /**
   * Gènère la boite "Attention".
   * @param renvoie un stdcontents, ou null (si vide)
   */
Ayolo's avatar
Ayolo committed
365
366
367
368
  function get_alerts()
  {
    global $topdir;

369
    if ( !$this->user->is_valid() ) return null;
Feu's avatar
Feu committed
370
    if ( $this->user->type=="srv" ) return null;
Ayolo's avatar
Ayolo committed
371
372
    $elements = array();

Ayolo's avatar
Ayolo committed
373
    if(date("m-d",$this->user->date_naissance) == date("m-d"))
Ayolo's avatar
Ayolo committed
374
      $elements[] = "<b>Joyeux anniversaire de la part de toute l'ae :)</b><br><small>Si ce n'est pas ton anniversaire nous t'invitons à mettre ton profil à jour : <a href='".$topdir."user.php?page=edit'><b>ici</b></a></small>";
Ayolo's avatar
Ayolo committed
375

Ayolo's avatar
Ayolo committed
376
377
378
    $carte = new carteae($this->db);
    $carte->load_by_utilisateur($this->user->id);

Feu's avatar
Feu committed
379
380
    $today = date("Y-m-d");

Ayolo's avatar
Ayolo committed
381
    $cpg = new campagne($this->db,$this->dbrw);
Feu's avatar
Feu committed
382
    $req = new requete($this->db, "SELECT `id_campagne` FROM `cpg_campagne` WHERE `date_fin_campagne`>='$today' ORDER BY date_debut_campagne DESC");
Ayolo's avatar
blop    
Ayolo committed
383
    while(list($id)=$req->get_row())
Ayolo's avatar
Ayolo committed
384
385
      if($cpg->load_by_id($id) && $this->user->is_in_group_id($cpg->group) && !$cpg->a_repondu($this->user->id))
        $elements[] = "<a href=\"".$topdir."campagne.php?id_campagne=".$cpg->id."\"><b>Campagne en cours : ".$cpg->nom."</b>.</a>";
Ayolo's avatar
Ayolo committed
386
387
388
389
390
391

    if ( $carte->is_valid() )
    {
      if ( $carte->etat_vie_carte == CETAT_ATTENTE &&
        !file_exists("/var/www/ae/www/ae2/var/img/matmatronch/" . $this->user->id .".identity.jpg") )
      {
BenC's avatar
BenC committed
392
        $elements[] = "<a href=\"".$topdir."user.php?page=edit&open=photo#setphotos\"><b>Vous devez ajouter une photo</b> pour que votre carte AE soit imprimée.</a>";
Ayolo's avatar
Ayolo committed
393
      }
394
      elseif ($carte->etat_vie_carte == CETAT_AU_BUREAU_AE )
Ayolo's avatar
Ayolo committed
395
396
397
      {
        $lieu = "Belfort";
        $this->user->load_all_extra();
BenC's avatar
BenC committed
398
        if ( $this->user->departement == "tc" || $this->user->departement == "mc" )
BenC's avatar
BenC committed
399
          $lieu = "Sevenans";
BenC's avatar
BenC committed
400
401
        elseif ( $this->user->departement == "edim" )
          $lieu = "Montbéliard";
Ayolo's avatar
Ayolo committed
402

403
        $elements[] = "<b>Votre carte AE est prête</b>. Elle vous attends au bureau de l'AE de $lieu.";
Ayolo's avatar
Ayolo committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
      }
    }

    if( $this->user->is_in_group("moderateur_site") )
    {
      $req = new requete($this->db,"SELECT COUNT(*) FROM `nvl_nouvelles`  WHERE `modere_nvl`='0' ");
      list($nbnews) = $req->get_row();

      $req = new requete($this->db,"SELECT COUNT(*) FROM `d_file`  WHERE `modere_file`='0' ");
      list($nbfichiers) = $req->get_row();
      $req = new requete($this->db,"SELECT COUNT(*) FROM `d_folder`  WHERE `modere_folder`='0' ");
      list($nbdossiers) = $req->get_row();
      $nbfichiers+=$nbdossiers;

418
419
420
421
422
423
      $req = new requete($this->db,"SELECT COUNT(*) FROM `planet_flux`  WHERE `modere`='0' ");
      list($nbflux) = $req->get_row();
      $req = new requete($this->db,"SELECT COUNT(*) FROM `planet_tags`  WHERE `modere`='0' ");
      list($nbtags) = $req->get_row();
      $nbflux+=$nbtags;

Ayolo's avatar
Ayolo committed
424
425
426
427
428
      if ( $nbnews > 0 )
        $elements[] = "<a href=\"".$topdir."ae/moderenews.php\"><b>$nbnews nouvelle(s)</b> à modérer</b></a>";

      if ( $nbfichiers > 0 )
        $elements[] = "<a href=\"".$topdir."ae/moderedrive.php\"><b>$nbfichiers fichier(s) et dossier(s)</b> à modérer</a>";
429
430
431

      if ( $nbflux > 0 )
        $elements[] = "<a href=\"".$topdir."planet/index.php?view=modere\"><b>$nbflux flux</b> à modérer</b></a>";
Ayolo's avatar
Ayolo committed
432
    }
433

Ayolo's avatar
Ayolo committed
434
435
436
437
438
439
440
    if ( $this->user->is_in_group("gestion_salles") )
    {
      $req = new requete($this->db,"SELECT COUNT(*) ".
        "FROM sl_reservation " .
        "INNER JOIN sl_salle ON sl_salle.id_salle=sl_reservation.id_salle " .
        "WHERE ((sl_reservation.date_accord_res IS NULL) OR " .
        "(sl_salle.convention_salle=1 AND sl_reservation.convention_salres=0)) " .
Feu's avatar
Feu committed
441
        "AND sl_reservation.date_debut_salres >= '$today'");
Ayolo's avatar
Ayolo committed
442
443
444
      list($count) = $req->get_row();

      if ( $count > 0 )
BenC's avatar
kwain    
BenC committed
445
446
447
448
449
        $elements[] = "<a href=\"".$topdir."ae/modereres.php\"><b>$count reservation(s) de salles</b> à modérer</a>";

      $req = new requete($this->db,"SELECT COUNT(*) ".
        "FROM sl_reservation " .
        "INNER JOIN sl_salle ON sl_salle.id_salle=sl_reservation.id_salle " .
BenC's avatar
BenC committed
450
        "WHERE sl_reservation.date_accord_res IS NOT NULL " .
BenC's avatar
BenC committed
451
        "AND sl_reservation.date_debut_salres >= '$today' " .
BenC's avatar
kwain    
BenC committed
452
453
454
455
        "AND DATEDIFF(sl_reservation.date_debut_salres,'".$today."') <= 10");
      list($count) = $req->get_row();

      if ( $count > 0 )
456
        $elements[] = "<a href=\"".$topdir."ae/modereres.php\"><b>$count reservation(s) de salles</b> dans les 10 prochaines jours</a>";
BenC's avatar
kwain    
BenC committed
457

Ayolo's avatar
Ayolo committed
458
    }
459
    else if( $this->user->is_in_group("bdf-bureau") )
Sarah's avatar
Sarah committed
460
    {
Ayolo's avatar
Ayolo committed
461
      $req = new requete($this->db,"SELECT COUNT(*) ".
Sarah's avatar
Sarah committed
462
463
        "FROM sl_reservation " .
        "INNER JOIN sl_salle ON sl_salle.id_salle=sl_reservation.id_salle " .
BenC's avatar
kwain    
BenC committed
464
        "WHERE sl_reservation.date_debut_salres >= '$today' " .
BenC's avatar
BenC committed
465
        "AND (sl_salle.id_salle='5' OR sl_salle.id_salle='28')");
Sarah's avatar
Sarah committed
466
467
468
      list($count) = $req->get_row();

      if ( $count > 0 )
BenC's avatar
BenC committed
469
      $elements[] = "<a href=\"".$topdir."ae/modereres.php\"><b>$count reservation(s) du foyer et de la Kfet</b></a>";
Sarah's avatar
Sarah committed
470
    }
471

Ayolo's avatar
Ayolo committed
472
473
474
475
476
477
478
    if ( $this->user->is_in_group("gestion_emprunts") )
    {
      $req = new requete($this->db,"SELECT COUNT(*) " .
        "FROM inv_emprunt WHERE etat_emprunt=0 ");
      list($count) = $req->get_row();

      if ( $count > 0 )
BenC's avatar
typo    
BenC committed
479
        $elements[] = "<a href=\"".$topdir."ae/modereemp.php\"><b>$count emprunt(s) de matériel</b> à modérer</a>";
BenC's avatar
kwain    
BenC committed
480
481
482
483
484
485

      $req = new requete($this->db,"SELECT COUNT(*) " .
        "FROM inv_emprunt WHERE date_debut_emp >= NOW()");
      list($count) = $req->get_row();

      if ( $count > 0 )
BenC's avatar
typo    
BenC committed
486
        $elements[] = "<a href=\"".$topdir."ae/modereemp.php?view=togo\"><b>$count emprunt(s) de matériel</b> à venir</a>";
Ayolo's avatar
Ayolo committed
487
488
489
490
491
492
493
494
495
496
497
    }

    $req = new requete($this->db, "SELECT COUNT(*) " .
      "FROM `cpt_vendu` " .
      "INNER JOIN `cpt_debitfacture` ON `cpt_debitfacture`.`id_facture` =`cpt_vendu`.`id_facture` " .
      "WHERE `id_utilisateur_client`='".$this->user->id."' AND a_retirer_vente='1'");

    list($nb) = $req->get_row();

    if ( $nb > 0 )
      $elements[] = "<a href=\"".$topdir."comptoir/encours.php\">Vous avez des commandes à venir retirer</a>";
498

Ayolo's avatar
Ayolo committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
    $sql = new requete($this->db,"SELECT `vt_election`.id_election, `vt_election`.nom_elec " .
        "FROM `vt_election` " .
        "LEFT JOIN vt_a_vote ON (`vt_a_vote`.`id_election`=`vt_election`.`id_election` AND vt_a_vote.id_utilisateur='".$this->user->id."')  " .
        "WHERE `date_debut`<= NOW() " .
        "AND `date_fin` >= NOW() " .
        "AND `id_groupe` IN (".$this->user->get_groups_csv().") " .
        "AND vt_a_vote.id_utilisateur IS NULL");

    if ( $sql->lines != 0 )
    {
      while ( list($id,$nom) = $sql->get_row() )
      {
        $elements[] = "<a href=\"".$topdir."elections.php?id_election=$id\"><b>Votez pour les élections : $nom</b></a>";
      }
    }

    if (  is_null($this->user->date_maj) )
Feu's avatar
test    
Feu committed
516
        $elements[] = "<b>Vous n'avez pas r&eacute;cemment mis &agrave; jour votre fiche Matmatronch</b> : <a href=\"".$topdir."majprofil.php\">La mettre &agrave; jour</a>";
Ayolo's avatar
Ayolo committed
517
    elseif ( (time() - $this->user->date_maj) > (6*30*24*60*60) )
Feu's avatar
test    
Feu committed
518
        $elements[] = "<b>Vous n'avez pas mis &agrave; jour votre fiche Matmatronch depuis ".round((time() - $this->user->date_maj)/(24*60*60))." jours !</b> : <a href=\"".$topdir."majprofil.php\">La mettre &agrave; jour</a>";
Ayolo's avatar
Ayolo committed
519

520
    if( $this->user->is_in_group("sas_admin") && (!$this->get_param("closed.sas",false) && is_dir("/var/www/ae/accounts/sas")) )
Ayolo's avatar
Ayolo committed
521
522
523
524
525
526
527
528
529
    {
      $req = new requete($this->db, "SELECT COUNT(*) FROM `sas_cat_photos` WHERE `modere_catph`='0' ");
      list($ncat) = $req->get_row();
      $req = new requete($this->db, "SELECT COUNT(*) FROM `sas_photos` WHERE `modere_ph`='0'");
      list($nphoto) = $req->get_row();
      if ( $ncat > 0 || $nphoto > 0 )
      {
        $msg = "";
        if ( $ncat > 0 )
530
          $msg .= $ncat." catégorie(s)";
Ayolo's avatar
Ayolo committed
531
532
533
534
535
536
537
        if ( $ncat > 0 && $nphoto > 0 )
          $msg .= " et ";
        if ($nphoto > 0 )
          $msg .= $nphoto." photo(s)";
        $elements[] = "<a href=\"".$topdir."sas2/modere.php\">$msg &agrave; moderer dans le SAS</a>";
      }
    }
BenC's avatar
BenC committed
538

539
    if( !$this->get_param("closed.sas",false) && is_dir("/var/www/ae/accounts/sas"))
BenC's avatar
BenC committed
540
    {
541
      $req = new requete($this->db, "SELECT COUNT(*) FROM `sas_personnes_photos` WHERE `id_utilisateur`='".$this->user->id."' AND `vu_phutl`='0' AND `modere_phutl`='1'");
BenC's avatar
BenC committed
542
543
544
545
      list($nphoto) = $req->get_row();
      if ( $nphoto > 0 )
        $elements[] = "<a href=\"".$topdir."user/photos.php?see=new\"><b>".$nphoto." nouvelle(s) photo(s)</b> dans le SAS</a>";
    }
546

Ayolo's avatar
bleh    
Ayolo committed
547
548
549
550
551
    $req = new requete($this->db, "SELECT COUNT(*) FROM `d_file_lock` WHERE `id_utilisateur`='".$this->user->id."'");
    list($nblocks)=$req->get_row();
    if($nblocks>0)
       $elements[] = "<a href=\"".$topdir."user/d.php\"><b>".$nblocks." fichiers(s) emprunté(s)</b></a>";

Ayolo's avatar
Ayolo committed
552
553
554
555
556
557
558
559
    $cotiz = new cotisation($this->db);
    $cotiz->load_lastest_by_user ( $this->user->id );

    if ( ($cotiz->is_valid()) && ($cotiz->date_fin_cotis < time()) && (time()-$cotiz->date_fin_cotis < (30*24*60*60)) )
    {
      $elements[] = "<a href=\"".$topdir."e-boutic/?cat=23\"><b>Votre cotisation &agrave; l'AE est expir&eacute;e !</b> Renouvelez l&agrave; en ligne avec E-boutic.</a>";
    }

560
    if ( !$this->user->droit_image && !$this->get_param("closed.sas",false) && is_dir("/var/www/ae/accounts/sas") )
561
562
563
564
565
566
567
    {
      $sql = new requete($this->db,
        "SELECT COUNT(*) " .
        "FROM sas_personnes_photos " .
        "INNER JOIN sas_photos ON (sas_photos.id_photo=sas_personnes_photos.id_photo) " .
        "WHERE sas_personnes_photos.id_utilisateur=".$this->user->id." " .
        "AND sas_personnes_photos.accord_phutl='0' " .
568
        "AND sas_personnes_photos.modere_phutl='1' " .
569
570
571
572
        "AND (droits_acces_ph & 0x100)");
      list($count) = $sql->get_row();

      if ( $count > 0 )
573
        $elements[] ="<a href=\"".$topdir."sas2/droitimage.php?page=process\"><b>$count photo(s)</b> nécessitent votre accord</a>";
574

575
576
    }

pedrov's avatar
pedrov committed
577
    /* alertes covoiturage */
578
579
    $nbsteps = $this->user->covoiturage_steps_moderation();

pedrov's avatar
pedrov committed
580
    if ($nbsteps == 1)
Ayolo's avatar
fix    
Ayolo committed
581
582
583
    {
      $elements[] = "<a href=\"".$topdir."covoiturage/\">$nbsteps étape de covoiturage à modérer<b></a>";
    }
pedrov's avatar
pedrov committed
584
585
586
    else if ($nbsteps > 1)
      $elements[] = "<a href=\"".$topdir."covoiturage/\">$nbsteps étapes de covoiturage à modérer<b></a>";

587
    $assoces = $this->user->get_assos(ROLEASSO_PRESIDENT);
588

589
    if (count($assoces) > 0)
Ayolo's avatar
fix    
Ayolo committed
590
591
    {
      require_once($topdir. "include/entities/asso.inc.php");
592

593
      if ( !$this->get_param("backup_server",true) )
Ayolo's avatar
Ayolo committed
594
      {
595
        foreach ($assoces as $key => $assoce)
Ayolo's avatar
Ayolo committed
596
        {
597
598
599
600
601
            $asso = new asso($this->db);
            $asso->load_by_id($key);
            $pm = $asso->get_pending_unmod_mail();
            if ($pm == 1)
            {
slopez's avatar
fix ml    
slopez committed
602
                $elements[] = "<a href=\"https://ae.utbm.fr/mailman/admindb/".$asso->nom_unix.".membres\"><b>$pm e-mail en attente de modération sur la liste de diffusion de ". $asso->nom_unix . "</b></a>";
603
604
605
            }
            else if ($pm > 1)
            {
slopez's avatar
fix ml    
slopez committed
606
                $elements[] = "<a href=\"https://ae.utbm.fr/mailman/admindb/".$asso->nom_unix.".membres\"><b>$pm e-mails en attente de modération sur la liste de diffusion de ". $asso->nom_unix . "</b></a>";
607
            }
Ayolo's avatar
Ayolo committed
608
609
        }
      }
Ayolo's avatar
fix    
Ayolo committed
610
    }
pedrov's avatar
pedrov committed
611

Ayolo's avatar
Ayolo committed
612
    if ( count($elements) == 0 ) return null;
613

Feu's avatar
Feu committed
614
    $cts = new contents("Attention");
Ayolo's avatar
Ayolo committed
615
616
617
618
619
620
621
622
623
624

    if ( count($elements) == 1 )
      $cts->add_paragraph("Nous attirons votre attention sur l'&eacute;l&eacute;ment suivant:");
    else
      $cts->add_paragraph("Nous attirons votre attention sur les &eacute;l&eacute;ments suivants:");

    $cts->add(new itemlist(false,false,$elements));
    return $cts;
  }

Feu's avatar
Feu committed
625
626
627
628
  /**
   * Gènère la boite sondage.
   * @param renvoie un stdcontents, ou null (si vide)
   */
Ayolo's avatar
Ayolo committed
629
630
631
632
633
634
635
  function get_sondage()
  {
    $sdn = new sondage($this->db,$this->dbrw);

    $sdn->load_lastest();
    if ( !$sdn->is_valid() )
      return NULL;
636

Feu's avatar
Feu committed
637
    if ( $this->user->type=="srv" ) return null;
638

Ayolo's avatar
Ayolo committed
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
    require_once($topdir."include/cts/react.inc.php");

    $react = new reactonforum ( $this->db, $this->user, $sdn->question, array("id_sondage"=>$sdn->id), null, false );

    if ( $sdn->a_repondu($this->user->id) )
    {
      $cts = new contents("Sondage");

      $cts->add_paragraph("<b>".$sdn->question."</b>");

      $cts->puts("<p>");

      $res = $sdn->get_results();

      foreach ( $res as $re )
      {
        $cumul+=$re[1];
mbriand's avatar
mbriand committed
656
657
658
659
660

        if ($sdn->total > 0)
            $pc = $re[1]*100/$sdn->total;
        else
            $pc = 0;
Ayolo's avatar
Ayolo committed
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683

        $cts->puts($re[0]."<br/>");

        $wpx = floor($pc);
        if ( $wpx != 0 )
          $cts->puts("<div class=\"activebar\" style=\"width: ".$wpx."px\"></div>");
        if ( $wpx != 100 )
          $cts->puts("<div class=\"inactivebar\" style=\"width: ".(100-$wpx)."px\"></div>");

        $cts->puts("<div class=\"percentbar\">".round($pc,1)."%</div>");
        $cts->puts("<div class=\"clearboth\"></div>\n");

      }

      if ( $cumul < $sdn->total )
      {
        $pc = ( $sdn->total-$cumul)*100/$sdn->total;
        $cts->puts("<br/>Blanc ou nul : ".round($pc,1)."%");
      }

      $cts->puts("</p>");

      $cts->add_paragraph("(".$sdn->total." réponses)","nbvotes");
684

Ayolo's avatar
Ayolo committed
685
      $cts->add($react);
686

Ayolo's avatar
Ayolo committed
687
      $cts->add_paragraph("<a href=\"sondage.php\">Archives</a>","nbvotes");
688

Ayolo's avatar
Ayolo committed
689
690
691
692
693
694
      return $cts;
    }

    $cts = new contents("Sondage");
    $cts->add_paragraph("<b>".$sdn->question."</b>");

695

Ayolo's avatar
Ayolo committed
696
697
698
    $frm = new form("sondage","sondage.php");
    $frm->add_hidden("id_sondage",$sdn->id);

699
700
    $reps = $sdn->get_reponses();
    foreach( $reps as $num => $rep )
Ayolo's avatar
Ayolo committed
701
702
703
704
705
706
      $resp_[$num] = "$rep<br/>";

    $frm->add_radiobox_field ( "numrep", "", $resp_ );

    $frm->add_submit("answord","Repondre");
    $cts->add($frm);
707

Ayolo's avatar
Ayolo committed
708
709
710
    $cts->add($react);

    $cts->add_paragraph("<a href=\"sondage.php\">Archives</a>","nbvotes");
711

Ayolo's avatar
Ayolo committed
712
713
714
715
716
717
718
    return $cts;
  }

  /** Génre la boite qui affiche les anniversaires */
  function get_anniv_contents ()
  {
    global $topdir;
719

Feu's avatar
Feu committed
720
    require_once($topdir."include/cts/cached.inc.php");
721

Feu's avatar
Feu committed
722
    $cache = new cachedcontents("anniv");
723

Feu's avatar
Feu committed
724
725
    if ( $cache->is_cached_since(strtotime(date("Y-m-d")." 00:00:00")) )
      return $cache->get_cache();
726

Ayolo's avatar
Ayolo committed
727
728
    $cts = new contents("Anniversaire");

Feu's avatar
Feu committed
729
730
    $annee = date("Y");

Feu's avatar
Feu committed
731
732
733
734
    $req = new requete ($this->db, "SELECT `utilisateurs`.`id_utilisateur`,`utilisateurs`.`nom_utl`,".
    "`utilisateurs`.`prenom_utl`,`utl_etu_utbm`.`surnom_utbm`,`utilisateurs`.`date_naissance_utl` ".
    "FROM `utilisateurs` ".
    "INNER JOIN `utl_etu_utbm` ON `utilisateurs`.`id_utilisateur` = `utl_etu_utbm`.`id_utilisateur` ".
Feu's avatar
Feu committed
735
    "WHERE `utilisateurs`.`date_naissance_utl` LIKE '%-" . date("m-d") . "' ".
Feu's avatar
Feu committed
736
    "AND (`utilisateurs`.`ancien_etudiant_utl` = '0' OR `utilisateurs`.`ae_utl` = '1') ".
Ayolo's avatar
bleh    
Ayolo committed
737
    "AND (`utl_etu_utbm`.`role_utbm` LIKE 'etu' OR `utl_etu_utbm`.`role_utbm` LIKE 'anc') ".
Ayolo's avatar
bleh    
Ayolo committed
738
    "AND `utilisateurs`.`hash_utl` LIKE 'valid' ".
739
    "ORDER BY `utilisateurs`.`date_naissance_utl` DESC");
Ayolo's avatar
Ayolo committed
740
741
742

    if ($req->lines > 0)
    {
Feu's avatar
Feu committed
743
      $cts->add_paragraph($this->get_param('box.Anniversaire'));
Ayolo's avatar
Ayolo committed
744
745
746
747
748
749

      $old_age = 0;
      $count   = 0;

      while ($res = $req->get_row())
      {
Feu's avatar
Feu committed
750
751

        $age=$annee-substr($res['date_naissance_utl'],0,4);
Ayolo's avatar
Ayolo committed
752
753
754
755
        if (!$count || ($old_age != $age))
        {
          if ( $count )
            $cts->puts("</ul>\n");
756

Ayolo's avatar
Ayolo committed
757
758
759
760
761
762
763
764
765
766
767
          $cts->puts("<h2 class=\"epure\">" . $age . " ans</h2>\n");
          $cts->puts("<ul>\n");
          $old_age = $age;
        }

        if (empty($res['surnom_utbm']))
          $nom = $res['prenom_utl'] . " " . $res['nom_utl'];
        else
          $nom = $res['surnom_utbm'];

        $ref = "anniv". $res['id_utilisateur'];
768

Ayolo's avatar
Ayolo committed
769
770
771
772
773
774
775
776
        $count++;
        $cts->puts ("<li><a id=\"$ref\" onmouseover=\"show_tooltip('$ref','$topdir','utilisateur','".$res['id_utilisateur']."');\" onmouseout=\"hide_tooltip('$ref');\" href=\"". $topdir ."user.php?id_utilisateur=". $res['id_utilisateur'] .
         "\">" . $nom . "</a></li>\n");
      }
      $cts->puts("</ul>\n");
    }
    else
    {
Feu's avatar
Feu committed
777
      $cts->add_paragraph("L'AE est triste de vous annoncer qu'il n'y a pas d'anniversaire aujourd'hui.\n");
Ayolo's avatar
Ayolo committed
778
    }
779

Feu's avatar
Feu committed
780
    return $cache->set_contents($cts);
Ayolo's avatar
Ayolo committed
781
782
783
784
785
786
787
788
  }

  /** Fonction qui génére le contents du dernier planning de l'AE */
  function get_planning_contents ()
  {
    global $topdir;
    if ( !file_exists($topdir."var/img/com/planning.jpg"))
      return null;
789

Ayolo's avatar
Ayolo committed
790
791
792
793
794
795
796
797
    $planning_valid = filemtime($topdir."var/img/com/planning.jpg") + (7 * 24 * 60 * 60);
    if ( time() <= $planning_valid )
    {
      $cts = new contents("Planning");
      $cts->puts("<center><a href=\"".$topdir."article.php?name=planning\"><img src=\"".$topdir."var/img/com/planning-small.jpg?".$planning_valid."\" alt=\"Planning\" /></a></center>");
      return $cts;
    }
  }
798

Feu's avatar
Feu committed
799
800
801
802
  /**
   * Gènère la boite contenant la photo de la semaine.
   * @param renvoie un stdcontents
   */
Ayolo's avatar
Ayolo committed
803
804
805
806
807
808
809
810
  function get_weekly_photo_contents ()
  {
    global $topdir;
    if ( !file_exists($topdir."var/img/com/weekly_photo.jpg"))
      return null;
    $weekly_photo_valid = filemtime($topdir."var/img/com/weekly_photo.jpg") + (7 * 24 * 60 * 60);
    if ( time() <= $weekly_photo_valid )
    {
Ayolo's avatar
bleh    
Ayolo committed
811
812
813
814
815
      $cts = new contents("Photo de la semaine");
      $cts->puts("<center><a href=\"".$topdir."article.php?name=weekly_photo\"><img src=\"".$topdir."var/img/com/weekly_photo-small.jpg?".$weekly_photo_valid."\" style=\"margin-bottom:0.5em;\" alt=\"Photo de la semaine\" /></a><br/>");
      $cts->puts($this->get_param('box.Weekly_photo'));
      $cts->puts("</center>");
      return $cts;
Ayolo's avatar
Ayolo committed
816
    }
Ayolo's avatar
bleh    
Ayolo committed
817
    return null;
Ayolo's avatar
Ayolo committed
818
819
  }

Feu's avatar
Feu committed
820
  /**
Ayolo's avatar
bleh    
Ayolo committed
821
   * Vérifie la vie des comptoirs :).
Ayolo's avatar
Ayolo committed
822
   */
Ayolo's avatar
bleh    
Ayolo committed
823
824

  function get_comptoir()
Ayolo's avatar
Ayolo committed
825
826
827
828
829
830
831
  {
    global $topdir;
    // 1- On ferme les sessions expirés
    $req = new requete ($this->dbrw,
           "UPDATE `cpt_tracking` SET `closed_time`='".date("Y-m-d H:i:s")."'
            WHERE `activity_time` <= '".date("Y-m-d H:i:s",time()-intval(ini_get("session.gc_maxlifetime")))."'
            AND `closed_time` IS NULL");
832

Ayolo's avatar
bleh    
Ayolo committed
833

Ayolo's avatar
Ayolo committed
834
835
836
837
838
839
840
    // 2- On récupère les infos sur les bars ouverts
    $req = new requete ($this->dbrw,
           "SELECT MAX(activity_time),id_comptoir
            FROM `cpt_tracking`
            WHERE `activity_time` > '".date("Y-m-d H:i:s",time()-intval(ini_get("session.gc_maxlifetime")))."'
            AND `closed_time` IS NULL
            GROUP BY id_comptoir");
841

Ayolo's avatar
Ayolo committed
842
843
    while ( list($act,$id) = $req->get_row() )
      $activity[$id]=strtotime($act);
844
845

    // 3- On récupère les infos sur tous les bars
Ayolo's avatar
Ayolo committed
846
847
    $req = new requete ($this->dbrw,
           "SELECT id_comptoir, nom_cpt
848
            FROM cpt_comptoir
Ayolo's avatar
bleh    
Ayolo committed
849
850
851
852
            WHERE type_cpt='0'
            AND id_comptoir != '4'
            AND id_comptoir != '8'
            AND id_comptoir != '13'
Ayolo's avatar
Ayolo committed
853
            ORDER BY nom_cpt");
Ayolo's avatar
bleh    
Ayolo committed
854
855
    $list='';
    $i=0;
Ayolo's avatar
Ayolo committed
856
857
    while ( list($id,$nom) = $req->get_row() )
    {
Ayolo's avatar
bleh    
Ayolo committed
858
      $i++;
Ayolo's avatar
Ayolo committed
859
860
      $led = "green";
      $descled = "ouvert";
861

Ayolo's avatar
Ayolo committed
862
863
864
865
866
867
868
869
870
871
      if ( !isset($activity[$id]) )
      {
        $led = "red";
        $descled = "fermé (ou pas d'activité depuis plus de ".(intval(ini_get("session.gc_maxlifetime"))/60)." minutes)";
      }
      elseif ( time()-$activity[$id] > 600 )
      {
        $led = "yellow";
        $descled = "ouvert (mais pas d'activité depuis plus de 10 minutes)";
      }
Ayolo's avatar
bleh    
Ayolo committed
872
      $list.="<a href=\"".$topdir."comptoir/activity.php?id_comptoir=$id\"><img src=\"".$topdir."images/leds/".$led."led.png\" class=\"icon\" alt=\"".htmlentities($descled,ENT_NOQUOTES,"UTF-8")."\" title=\"".htmlentities($descled,ENT_NOQUOTES,"UTF-8")."\" /> $nom</a>";
Ayolo's avatar
bleh    
Ayolo committed
873
874
      if($i<$req->lines)
        $list.='<br />';
Ayolo's avatar
Ayolo committed
875
    }
Ayolo's avatar
bleh    
Ayolo committed
876

Ayolo's avatar
bleh    
Ayolo committed
877
    return '<div id="head_comptoirs">'.$list.'</div>';
Ayolo's avatar
Ayolo committed
878
  }
879

Feu's avatar
Feu committed
880
881
882
883
  /**
   * Gènère la boite d'information sur le forum
   * @param renvoie un stdcontents
   */
Feu's avatar
test    
Feu committed
884
  function get_forum_box ()
885
  {
pedrov's avatar
bogus ?    
pedrov committed
886
    global $wwwtopdir, $topdir;
Feu's avatar
test    
Feu committed
887
    require_once($topdir . "include/entities/forum.inc.php");
Feu's avatar
fixes    
Feu committed
888
    $forum = new forum($this->db);
Feu's avatar
test    
Feu committed
889
890
    $forum->load_by_id(1);

Feu's avatar
test    
Feu committed
891
    $cts = new contents("Forum");
892

Feu's avatar
Feu committed
893
894
    $query = "SELECT frm_sujet.titre_sujet, ".
        "frm_sujet.id_sujet, " .
Feu's avatar
test    
Feu committed
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
        "frm_message.date_message, " .
        "frm_message.id_message, " .
        "dernier_auteur.alias_utl AS `nom_utilisateur_dernier_auteur`, " .
        "dernier_auteur.id_utilisateur AS `id_utilisateur_dernier`, " .
        "premier_auteur.alias_utl AS `nom_utilisateur_premier_auteur`, " .
        "premier_auteur.id_utilisateur AS `id_utilisateur_premier`, " .
        "1 AS `nonlu`, " .
        "titre_forum AS `soustitre_sujet` " .
        "FROM frm_sujet " .
        "INNER JOIN frm_forum USING(id_forum) ".
        "LEFT JOIN frm_message ON ( frm_message.id_message = frm_sujet.id_message_dernier ) " .
        "LEFT JOIN utilisateurs AS `dernier_auteur` ON ( dernier_auteur.id_utilisateur=frm_message.id_utilisateur ) " .
        "LEFT JOIN utilisateurs AS `premier_auteur` ON ( premier_auteur.id_utilisateur=frm_sujet.id_utilisateur ) ".
        "LEFT JOIN frm_sujet_utilisateur ".
          "ON ( frm_sujet_utilisateur.id_sujet=frm_sujet.id_sujet ".
Feu's avatar
fixes    
Feu committed
910
          "AND frm_sujet_utilisateur.id_utilisateur='".$this->user->id."' ) ".
Feu's avatar
test    
Feu committed
911
        "WHERE ";
912

Feu's avatar
fixes    
Feu committed
913
    if( is_null($this->user->tout_lu_avant))
Feu's avatar
test    
Feu committed
914
      $query .= "(frm_sujet_utilisateur.id_message_dernier_lu<frm_sujet.id_message_dernier ".
915
                "OR frm_sujet_utilisateur.id_message_dernier_lu IS NULL) ";
Feu's avatar
test    
Feu committed
916
917
918
    else
      $query .= "((frm_sujet_utilisateur.id_message_dernier_lu<frm_sujet.id_message_dernier ".
                "OR frm_sujet_utilisateur.id_message_dernier_lu IS NULL) ".
919
920
                "AND frm_message.date_message > '".date("Y-m-d H:i:s",$this->user->tout_lu_avant)."') ";

Feu's avatar
fixes    
Feu committed
921
    if ( !$forum->is_admin( $this->user ) )
Feu's avatar
test    
Feu committed
922
    {
Feu's avatar
fixes    
Feu committed
923
      $grps = $this->user->get_groups_csv();
Feu's avatar
test    
Feu committed
924
925
926
      $query .= "AND ((droits_acces_forum & 0x1) OR " .
        "((droits_acces_forum & 0x10) AND id_groupe IN ($grps)) OR " .
        "(id_groupe_admin IN ($grps)) OR " .
Feu's avatar
fixes    
Feu committed
927
        "((droits_acces_forum & 0x100) AND frm_forum.id_utilisateur='".$this->user->id."')) ";
Feu's avatar
test    
Feu committed
928
    }
929

Feu's avatar
wip    
Feu committed
930
931
    $query_fav = $query."AND frm_sujet_utilisateur.etoile_sujet='1' ";
    $query_fav .= "ORDER BY frm_message.date_message DESC ";
Feu's avatar
wip    
Feu committed
932
    $query_fav .= "LIMIT 4 ";
933

Feu's avatar
wip    
Feu committed
934
    $query .= "AND ( frm_sujet_utilisateur.etoile_sujet IS NULL OR frm_sujet_utilisateur.etoile_sujet!='1' ) ";
Feu's avatar
test    
Feu committed
935
    $query .= "ORDER BY frm_message.date_message DESC ";
Feu's avatar
wip    
Feu committed
936
    $query .= "LIMIT 4 ";
937

Feu's avatar
wip    
Feu committed
938
    $req = new requete($this->db,$query_fav);
939

Feu's avatar
wip    
Feu committed
940
941
942
943
944
945
946
947
948
949
950
    if ( $req->lines > 0 )
    {
      $cts->add_title(2,"<a href=\"".$wwwtopdir."forum2/search.php?page=unread\">Favoris non lus</a>");
      $list = new itemlist();
      while ( $row = $req->get_row() )
      {
        $list->add("<a href=\"".$wwwtopdir."forum2/?id_sujet=".$row['id_sujet']."&amp;spage=firstunread#firstunread\"\">".
        htmlentities($row['titre_sujet'], ENT_NOQUOTES, "UTF-8").
        "</a>");
      }
      $cts->add($list);
Feu's avatar
wip    
Feu committed
951
      if ( $req->lines == 4 )
Feu's avatar
wip    
Feu committed
952
953
        $cts->add_paragraph("<a href=\"".$wwwtopdir."forum2/search.php?page=unread\">suite...</a>");
    }
Ayolo's avatar
bleh    
Ayolo committed
954
955

    $i=$req->lines;
956

Feu's avatar
fixes    
Feu committed
957
    $req = new requete($this->db,$query);
958

Feu's avatar
test    
Feu committed
959
960
    if ( $req->lines > 0 )
    {
Feu's avatar
wip    
Feu committed
961
      $cts->add_title(2,"<a href=\"".$wwwtopdir."forum2/search.php?page=unread\">Derniers messages non lus</a>");
Feu's avatar
test    
Feu committed
962
963
964
965
966
967
968
      $list = new itemlist();
      while ( $row = $req->get_row() )
      {
        $list->add("<a href=\"".$wwwtopdir."forum2/?id_sujet=".$row['id_sujet']."&amp;spage=firstunread#firstunread\"\">".
        htmlentities($row['titre_sujet'], ENT_NOQUOTES, "UTF-8").
        "</a>");
      }
Feu's avatar
wip    
Feu committed
969
      $cts->add($list);
Feu's avatar
wip    
Feu committed
970
      if ( $req->lines == 4 )
Feu's avatar
wip    
Feu committed
971
        $cts->add_paragraph("<a href=\"".$wwwtopdir."forum2/search.php?page=unread\">suite...</a>");
Feu's avatar
test    
Feu committed
972
    }
Ayolo's avatar
bleh    
Ayolo committed
973
974
    elseif($i==0)//ni favoris ni pas favoris
      return null;
975

Feu's avatar
test    
Feu committed
976
    return $cts;
Feu's avatar
test    
Feu committed
977
  }
978

979
980
981
982
  /**
   * Génère la boite des permanences à venir
   * @param renvoie un stdcontents
   */
983
  function get_planning_permanences_contents()
984
  {
BenC's avatar
BenC committed
985
    $cts = new contents("Prochaines permanences");
986
987
988

    $cts->add_paragraph("<a href=\"".$wwwtopdir."planning\">Les plannings de permanences</a>");

989
990
    $req = new requete($this->db,"SET lc_time_names='fr_FR'");

BenC's avatar
BenC committed
991
    //TODO : Faire en sorte qu'il affiche tout seul les différents plannings et plus avoir à hardcoder l'id_planning
992
    $sublist = new itemlist("Bureau AE - Belfort");
993

BenC's avatar
Kwain    
BenC committed
994
    $req = new requete($this->db,"SELECT DAYNAME(start_gap) AS day, HOUR(start_gap) AS hour,
BenC's avatar
kwain    
BenC committed
995
                                  IF(DAYOFWEEK(start_gap)<DAYOFWEEK(CURDATE()),true,false) as next
BenC's avatar
BenC committed
996
997
998
999
1000
1001
1002
1003
1004
                                  FROM pl_gap
                                  INNER JOIN pl_gap_user USING(id_gap)
                                  WHERE  id_planning='164' AND (((DAYOFWEEK(start_gap)>DAYOFWEEK(CURDATE())
                                    OR (DAYOFWEEK(start_gap)=DAYOFWEEK(CURDATE()) AND HOUR(start_gap)>=HOUR(CURTIME())))
                                    AND ((WEEKOFYEAR(CURDATE())-WEEKOFYEAR(start_gap))%2)=0)
                                    OR (DAYOFWEEK(start_gap)<DAYOFWEEK(CURDATE())
                                    AND (((WEEKOFYEAR(CURDATE())+1)-WEEKOFYEAR(start_gap))%2)=0))
                                  GROUP BY id_gap
                                  ORDER BY IF(DAYOFWEEK(start_gap)<DAYOFWEEK(CURDATE()),1,0), DAYOFWEEK(start_gap), HOUR(start_gap) LIMIT 3");
1005
1006
1007
1008
1009
1010
1011

    if($req->lines < 1)
    {
      $sublist->add("Aucune permanence à venir pour cette semaine");
    }
    else
    {
BenC's avatar
Kwain    
BenC committed
1012
      while(list($day,$hour,$next) = $req->get_row() )
BenC's avatar
kwain    
BenC committed
1013
      {
BenC's avatar
Kwain    
BenC committed
1014
        if($next)
BenC's avatar
BenC committed
1015
          $sublist->add(ucfirst($day) . " prochain à " . $hour . "h");
BenC's avatar
Kwain    
BenC committed
1016
1017
        else
          $sublist->add(ucfirst($day) . " à " . $hour . "h");
BenC's avatar
kwain    
BenC committed
1018
      }
1019
    }
1020

BenC's avatar
BenC committed
1021
    $cts->add($sublist, true, true, "bureau_ae_belfort", "boxlist", true, true);
1022

1023
1024
        $sublist = new itemlist("Bureau AE - Sevenans");

BenC's avatar
kwain    
BenC committed
1025
    $req = new requete($this->db,"SELECT DAYNAME(start_gap) AS day, HOUR(start_gap) AS hour,
BenC's avatar
kwain    
BenC committed
1026
                                  IF(DAYOFWEEK(start_gap)<DAYOFWEEK(CURDATE()),true,false) as next
BenC's avatar
BenC committed
1027
1028
1029
1030
1031
1032
1033
1034
1035
                                  FROM pl_gap
                                  INNER JOIN pl_gap_user USING(id_gap)
                                  WHERE  id_planning='166' AND (((DAYOFWEEK(start_gap)>DAYOFWEEK(CURDATE())
                                    OR (DAYOFWEEK(start_gap)=DAYOFWEEK(CURDATE()) AND HOUR(start_gap)>=HOUR(CURTIME())))
                                    AND ((WEEKOFYEAR(CURDATE())-WEEKOFYEAR(start_gap))%2)=0)
                                    OR (DAYOFWEEK(start_gap)<DAYOFWEEK(CURDATE())
                                    AND (((WEEKOFYEAR(CURDATE())+1)-WEEKOFYEAR(start_gap))%2)=0))
                                  GROUP BY id_gap
                                  ORDER BY IF(DAYOFWEEK(start_gap)<DAYOFWEEK(CURDATE()),1,0), DAYOFWEEK(start_gap), HOUR(start_gap) LIMIT 3");
1036

1037
1038
1039
1040
1041
1042
    if($req->lines < 1)
    {
      $sublist->add("Aucune permanence à venir pour cette semaine");
    }
    else
    {
BenC's avatar
Kwain    
BenC committed
1043
      while(list($day,$hour,$next) = $req->get_row() )
BenC's avatar
kwain    
BenC committed
1044
1045
      {
        if($next)
BenC's avatar
BenC committed
1046
          $sublist->add(ucfirst($day) . " prochain à " . $hour . "h");
BenC's avatar
kwain    
BenC committed
1047