cat.inc.php 20 KB
Newer Older
Ayolo's avatar
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
<?php
/* Copyright 2004-2006
 * - Julien Etelain < julien at pmad dot net >
 *
 * 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.
 */
require_once($topdir."include/entities/basedb.inc.php");
24
require_once($topdir."include/entities/asso.inc.php");
Ayolo's avatar
Ayolo committed
25
26
27
28
29
30
31
32
33

define("CATPH_MODE_NORMAL",0);
define("CATPH_MODE_META_ASSO",1);

$GLOBALS['catph_modes'] =
  array(
    CATPH_MODE_NORMAL=>"Catégorie normale",
    CATPH_MODE_META_ASSO=>"Catégorie sommaire association"
  );
34

35
36
37
38
39
/**
 * Catégorie du SAS
 * @ingroup sas
 * @author Julien Etelain
 */
Ayolo's avatar
Ayolo committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class catphoto extends basedb
{

  var $id_catph_parent;/*id_catph_parent*/
  var $id_photo;/*id_photo*/
  var $nom;/*nom_catph*/
  var $date_debut;/*date_debut_catph*/
  var $date_fin;/*date_fin_catph*/
  /*modere_catph*/

  var $meta_id_asso;
  var $meta_mode;

  var $meta_cat;
54

Ayolo's avatar
Ayolo committed
55
56
57
58
59
60
61
62
63
64
65
  var $id_lieu;

  /** Charge une catégorie par son ID
   * @param $id ID de l'association
   */
  function load_by_id ( $id )
  {
    $req = new requete($this->db, "SELECT * FROM `sas_cat_photos`
        WHERE `id_catph` = '" . mysql_real_escape_string($id) . "'
        LIMIT 1");
    if ( $req->lines == 1 )
Ayolo's avatar
debug    
Ayolo committed
66
67
68
69
    {
      $this->_load($req->get_row());
      return true;
    }
70
71

    $this->id = null;
Ayolo's avatar
debug    
Ayolo committed
72
    return false;
Ayolo's avatar
Ayolo committed
73
74
75
76
77
78
79
80
81
  }

  function load_by_asso_summary($id_asso)
  {
    $req = new requete($this->db, "SELECT * FROM `sas_cat_photos` " .
        "WHERE `meta_id_asso_catph` = '" . mysql_real_escape_string($id_asso) . "' " .
        "AND `meta_mode_catph`='".CATPH_MODE_META_ASSO."' " .
        "LIMIT 1");
    if ( $req->lines == 1 )
Ayolo's avatar
debug    
Ayolo committed
82
83
84
85
    {
      $this->_load($req->get_row());
      return true;
    }
86
87

    $this->id = null;
Ayolo's avatar
debug    
Ayolo committed
88
    return false;
Ayolo's avatar
Ayolo committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  }


  function load_by_name ( $id_parent, $name )
  {
    if ( $id_parent )
      $req = new requete($this->db, "SELECT * FROM `sas_cat_photos`
          WHERE `id_catph_parent` = '" . mysql_real_escape_string($id_parent) . "'
          AND `nom_catph` = '" . mysql_real_escape_string($name) . "'
          LIMIT 1");
    else
      $req = new requete($this->db, "SELECT * FROM `sas_cat_photos`
          WHERE `id_catph_parent` IS NULL
          AND `nom_catph` = '" . mysql_real_escape_string($name) . "'
          LIMIT 1");

    if ( $req->lines == 1 )
Ayolo's avatar
debug    
Ayolo committed
106
107
108
109
    {
      $this->_load($req->get_row());
      return true;
    }
110
111

    $this->id = null;
Ayolo's avatar
debug    
Ayolo committed
112
    return false;
Ayolo's avatar
Ayolo committed
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
  }

  function load_by_path ( $path )
  {
    $tokens = explode("/",$path);

    if ( $tokens[0] == "" ) unset($tokens[0]);

    $this->id_catph_parent = null;

    foreach ( $tokens as $name )
    {
      if(  $name != "" )
      {
        $this->load_by_name($this->id_catph_parent,$name);
        if ( !$this->is_valid() ) return false;
      }
    }

    return true;
  }

  function _load($row)
  {
    $this->id = $row['id_catph'];
    $this->id_catph_parent = $row['id_catph_parent'];
    $this->id_photo = $row['id_photo'];
    $this->nom = $row['nom_catph'];
141

Ayolo's avatar
Ayolo committed
142
143
144
145
146
147
148
149
150
151
    if ( is_null($row['date_debut_catph']) )
    {
      $this->date_debut = null;
      $this->date_fin = null;
    }
    else
    {
      $this->date_debut = strtotime($row['date_debut_catph']);
      $this->date_fin = strtotime($row['date_fin_catph']);
    }
152

Ayolo's avatar
Ayolo committed
153
154
155
156
157
158
159
160
161
    $this->modere = $row['modere_catph'];

    $this->id_utilisateur = $row['id_utilisateur'];
    $this->id_groupe = $row['id_groupe'];
    $this->id_groupe_admin = $row['id_groupe_admin'];
    $this->droits_acces = $row['droits_acces_catph'];

    $this->meta_id_asso = $row['meta_id_asso_catph'];
    $this->meta_mode = $row['meta_mode_catph'];
162

Ayolo's avatar
Ayolo committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    $this->id_lieu = $row['id_lieu'];
  }

  function get_photos ( $id_cat, $user, $grps, $select="*", $limit="")
  {
    if ( isset($this->meta_cat) && $this->meta_cat->meta_id_asso != $this->meta_id_asso )
      $filter = " AND (`meta_id_asso_ph`='".$this->meta_cat->meta_id_asso."' ".
                       "OR `id_asso_photographe`='".$this->meta_cat->meta_id_asso."')";
    else
      $filter = "";

    if ( $this->is_admin( $user ) )
      return new requete($this->db,"SELECT $select " .
        "FROM sas_photos " .
        "WHERE " .
        "id_catph='".$id_cat."'$filter ".
Feu's avatar
Feu committed
179
        "ORDER BY type_media_ph DESC, date_prise_vue " .
Ayolo's avatar
Ayolo committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
        "$limit");
    else
      return new requete($this->db,"SELECT $select " .
        "FROM sas_photos " .
        "LEFT JOIN sas_personnes_photos ON " .
          "(sas_personnes_photos.id_photo=sas_photos.id_photo " .
          "AND sas_personnes_photos.id_utilisateur='".$user->id."' " .
          "AND sas_personnes_photos.modere_phutl='1') " .
        "LEFT JOIN `asso_membre` ON ".
          "(`asso_membre`.`id_asso` = `sas_photos`.`meta_id_asso_ph` ".
          "AND `asso_membre`.`id_utilisateur` = '" . $user->id."' ".
          "AND `asso_membre`.`date_fin` is NULL AND `asso_membre`.`role` >= '".ROLEASSO_MEMBREBUREAU."') ".
        "WHERE " .
        "id_catph='".$id_cat."'$filter AND " .
        "((((droits_acces_ph & 0x1) OR " .
        "((droits_acces_ph & 0x10) AND id_groupe IN ($grps))) " .
Feu's avatar
fix    
Feu committed
196
          "AND droits_acquis='1' AND modere_ph='1' ) OR " .
Ayolo's avatar
Ayolo committed
197
198
199
        "(id_groupe_admin IN ($grps)) OR " .
        "((droits_acces_ph & 0x100) AND sas_photos.id_utilisateur='".$user->id."') OR " .
        "((droits_acces_ph & 0x100) AND sas_personnes_photos.id_utilisateur IS NOT NULL) ) " .
Feu's avatar
Feu committed
200
        "ORDER BY type_media_ph DESC, date_prise_vue " .
Ayolo's avatar
Ayolo committed
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        "$limit");

  }

  function get_categories ( $id_cat, $user, $grps, $select="*")
  {
    if ( $this->is_admin( $user ) )
      return new requete($this->db,"SELECT $select " .
        "FROM sas_cat_photos " .
        "WHERE " .
        "id_catph_parent='$id_cat' " .
        "ORDER BY `date_debut_catph` DESC,`nom_catph`");
    else
      return new requete($this->db,"SELECT $select " .
        "FROM sas_cat_photos " .
        "WHERE " .
        "id_catph_parent='$id_cat' AND " .
        "((droits_acces_catph & 0x1) OR " .
        "((droits_acces_catph & 0x10) AND id_groupe IN ($grps)) OR " .
        "(id_groupe_admin IN ($grps)) OR " .
        "((droits_acces_catph & 0x100) AND id_utilisateur='".$user->id."')) " .
        "ORDER BY `date_debut_catph` DESC,`nom_catph`");
  }
224

Ayolo's avatar
Ayolo committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  /**
   * Retourne toutes les sous-catégories que l'utilisateur peut voir.
   * Retourne un tableau ou chaque entrée est un tableau associatif contenant :
   * - id_catph
   * - nom_catph
   * - id_photo
   * - id_catph_parent
   * - nom_catph_parent
   * - date_debut_catph
   * - id_utilisateur
   * - id_groupe
   * - id_groupe_admin
   * - droits_acces_catph
   * - meta_mode_catph
   * - meta_id_asso
240
   * Attention: Si id_catph_parent != $this->id, alors il s'agit d'une méta sous-catégorie
Ayolo's avatar
Ayolo committed
241
242
243
244
245
   */
  function get_all_categories ( &$user )
  {
    $cats = array();
    $grps = $user->get_groups_csv();
246

Ayolo's avatar
Ayolo committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    if ( $this->is_admin( $user ) )
      $query = "SELECT id_catph, nom_catph, id_photo, id_catph_parent, NULL AS nom_catph_parent, date_debut_catph, id_utilisateur, id_groupe, id_groupe_admin, droits_acces_catph, meta_mode_catph, meta_id_asso_catph   " .
        "FROM sas_cat_photos " .
        "WHERE " .
        "id_catph_parent='".$this->id."' ";
    else
      $query = "SELECT id_catph, nom_catph, id_photo, id_catph_parent, NULL AS nom_catph_parent, date_debut_catph, id_utilisateur, id_groupe, id_groupe_admin, droits_acces_catph, meta_mode_catph, meta_id_asso_catph " .
        "FROM sas_cat_photos " .
        "WHERE " .
        "id_catph_parent='".$this->id."' AND " .
        "((droits_acces_catph & 0x1) OR " .
        "((droits_acces_catph & 0x10) AND id_groupe IN ($grps)) OR " .
        "(id_groupe_admin IN ($grps)) OR " .
        "((droits_acces_catph & 0x100) AND id_utilisateur='".$user->id."')) ";
261

Ayolo's avatar
Ayolo committed
262
263
264
265
266
267
268
269
270
271
272
273
    if ( $this->meta_mode == CATPH_MODE_META_ASSO )
    {
      $query .= "UNION ".
        "SELECT DISTINCT(sas_cat_photos.id_catph) AS `id_catph`, ".
        "sas_cat_photos.nom_catph, ".
        "NULL AS id_photo, ".
        "sas_cat_photos.id_catph_parent, ".
        "parent.nom_catph AS nom_catph_parent, ".
        "sas_cat_photos.date_debut_catph,".
        "NULL AS id_utilisateur, ".
        "NULL AS id_groupe, ".
        "NULL AS id_groupe_admin, ".
274
275
276
        "NULL AS droits_acces_catph, " .
        "NULL AS meta_mode_catph, " .
        "NULL AS meta_id_asso_catph " .
Ayolo's avatar
Ayolo committed
277
278
279
280
281
282
283
        "FROM `sas_photos` ".
        "INNER JOIN sas_cat_photos ON ( sas_photos.id_catph = sas_cat_photos.id_catph ) " .
        "LEFT JOIN sas_cat_photos as parent ON ( parent.id_catph = sas_cat_photos.id_catph_parent ) ".
        "WHERE ".
          "(sas_photos.meta_id_asso_ph='".$this->meta_id_asso."' ".
          "OR sas_photos.id_asso_photographe='".$this->meta_id_asso."') " .
        "AND sas_cat_photos.id_catph!='".$this->id."' ".
284
285
        "AND sas_cat_photos.id_catph_parent!='".$this->id."' ".
        "AND parent.id_catph_parent!='".$this->id."' ".
Ayolo's avatar
Ayolo committed
286
287
288
289
290
291
292
293
294
295
296
297
        "AND (sas_cat_photos.meta_id_asso_catph!='".$this->meta_id_asso."' OR sas_cat_photos.meta_id_asso_catph IS NULL)";

      $query .= "UNION ".
        "SELECT sas_cat_photos.id_catph, ".
        "sas_cat_photos.nom_catph, ".
        "sas_cat_photos.id_photo, ".
        "sas_cat_photos.id_catph_parent, ".
        "parent.nom_catph AS nom_catph_parent, ".
        "sas_cat_photos.date_debut_catph,".
        "NULL AS id_utilisateur, ".
        "NULL AS id_groupe, ".
        "NULL AS id_groupe_admin, ".
298
299
300
        "NULL AS droits_acces_catph, " .
        "NULL AS meta_mode_catph, " .
        "NULL AS meta_id_asso_catph " .
Ayolo's avatar
Ayolo committed
301
302
303
304
        "FROM sas_cat_photos ".
        "LEFT JOIN sas_cat_photos as parent ON ( parent.id_catph = sas_cat_photos.id_catph_parent ) ".
        "WHERE sas_cat_photos.meta_id_asso_catph='".$this->meta_id_asso."' ".
        "AND sas_cat_photos.id_catph!='".$this->id."' ".
305
306
        "AND sas_cat_photos.id_catph_parent!='".$this->id."' ".
        "AND parent.id_catph_parent!='".$this->id."' ".
Ayolo's avatar
Ayolo committed
307
        "AND sas_cat_photos.meta_mode_catph!='".CATPH_MODE_META_ASSO."'";
308
    }
Ayolo's avatar
Ayolo committed
309
310

    $query .= "ORDER BY  `date_debut_catph` DESC,`nom_catph`";
311

Ayolo's avatar
Ayolo committed
312
    $cats = array();
313

Ayolo's avatar
Ayolo committed
314
    $req = new requete($this->db,$query);
315

Ayolo's avatar
Ayolo committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
    while ( $row = $req->get_row() )
    {
      if ( is_null($row['id_photo']) || $row['id_photo'] <= 0 )
      {
        if ( $row['id_catph_parent'] != $this->id_catph_parent )
          $req2 = new requete($this->db,
            "SELECT id_photo FROM `sas_photos` ".
            "WHERE meta_id_asso_ph='".$this->meta_id_asso."' " .
            "AND id_catph='".$row['id_catph']."' " .
            "AND droits_acquis =1 " .
            "AND (droits_acces_ph & 1) = 1 " .
            "ORDER BY date_prise_vue");
        else
          $req2 = new requete($this->db,
            "SELECT id_photo FROM `sas_photos` ".
            "AND id_catph='".$row['id_catph']."' " .
            "AND droits_acquis =1 " .
            "AND (droits_acces_ph & 1) = 1 " .
            "ORDER BY date_prise_vue");
335

Ayolo's avatar
Ayolo committed
336
337
338
        if ( $req2->lines > 0 )
          list($row['id_photo']) = $req2->get_row();
      }
339

Ayolo's avatar
Ayolo committed
340
341
      $cats[] = $row;
    }
342

Ayolo's avatar
Ayolo committed
343
344
    return $cats;
  }
345
346


Ayolo's avatar
Ayolo committed
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387

  function get_recent_photos_categories ($user, $grps )
  {
      // pas tres beau, mais ca marche...
      return new requete($this->db, "SELECT ( SELECT sas_photos.id_photo ".
        "FROM sas_photos " .
        "LEFT JOIN sas_personnes_photos ON " .
          "(sas_personnes_photos.id_photo=sas_photos.id_photo " .
          "AND sas_personnes_photos.id_utilisateur='".$user->id."' " .
          "AND sas_personnes_photos.modere_phutl='1') " .
        "LEFT JOIN `asso_membre` ON ".
          "(`asso_membre`.`id_asso` = `sas_photos`.`meta_id_asso_ph` ".
          "AND `asso_membre`.`id_utilisateur` = '" . $user->id."' ".
          "AND `asso_membre`.`date_fin` is NULL AND `asso_membre`.`role` >= '".ROLEASSO_MEMBREBUREAU."') ".
        "WHERE " .
        " sas_photos.id_catph = sas_cat_photos.id_catph 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='".$user->id."') OR " .
        "((droits_acces_ph & 0x100) AND sas_personnes_photos.id_utilisateur IS NOT NULL) ) ".
        "ORDER BY sas_photos.id_photo DESC LIMIT 1 ), ".
        "sas_cat_photos.* " .
        "FROM sas_cat_photos WHERE" .
        "((droits_acces_catph & 0x1) OR " .
        "((droits_acces_catph & 0x10) AND sas_cat_photos.id_groupe IN ($grps)) OR " .
        "(sas_cat_photos.id_groupe_admin IN ($grps)) OR " .
        "((droits_acces_catph & 0x100) AND sas_cat_photos.id_utilisateur='".$user->id."')) " .
        "ORDER BY 1 DESC " .
        "LIMIT 4");

  }



  function add_catphoto ( $id_catph_parent, $nom, $debut, $fin, $meta_id_asso=NULL, $meta_mode=CATPH_MODE_NORMAL, $id_lieu=NULL )
  {
    $this->nom = $nom;
    $this->id_catph_parent = $id_catph_parent;
    $this->id_photo = null;
388

Ayolo's avatar
Ayolo committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
    $this->date_debut = $debut;
    $this->date_fin = $fin;
    $this->modere=0;
    $this->meta_id_asso=$meta_id_asso;
    $this->meta_mode=$meta_mode;

    $this->id_lieu=$id_lieu;


    $sql = new insert ($this->dbrw,
      "sas_cat_photos",
      array(
        "id_catph_parent"=>$this->id_catph_parent,
        "id_photo"=>$this->id_photo,
        "nom_catph"=>$this->nom,
        "date_debut_catph"=>is_null($this->date_debut)?null:date("Y-m-d H:i:s",$this->date_debut),
        "date_fin_catph"=>is_null($this->date_debut)?null:date("Y-m-d H:i:s",$this->date_fin),
        "modere_catph"=>$this->modere,
        "id_utilisateur"=>$this->id_utilisateur,
        "id_groupe"=>$this->id_groupe,
        "id_groupe_admin"=>$this->id_groupe_admin,
        "droits_acces_catph"=>$this->droits_acces,

        "meta_id_asso_catph"=>$this->meta_id_asso,
        "meta_mode_catph"=>$this->meta_mode,
414

Ayolo's avatar
Ayolo committed
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
462
463
464
465
466
467
        "id_lieu"=>$this->id_lieu
        )
      );

    if ( $sql )
      $this->id = $sql->get_id();
    else
      $this->id = null;
  }

  function set_photo ( $id_photo )
  {
    $this->id_photo = $id_photo;

    $sql = new update ($this->dbrw,
      "sas_cat_photos",
      array(
        "id_photo"=>$this->id_photo
        ),
      array("id_catph"=>$this->id )
      );


  }

  function update_catphoto ( &$user, $id_catph_parent, $nom, $debut, $fin, $meta_id_asso=NULL, $meta_mode=CATPH_MODE_NORMAL, $id_lieu=NULL )
  {
    $this->nom = $nom;
    $this->id_catph_parent = $id_catph_parent;
    $this->date_debut = $debut;
    $this->date_fin = $fin;
    if ( !$this->is_admin( $user ) )
      $this->modere=0;
    $this->meta_id_asso=$meta_id_asso;
    $this->meta_mode=$meta_mode;

    $this->id_lieu=$id_lieu;

    $sql = new update ($this->dbrw,
      "sas_cat_photos",
      array(
        "id_catph_parent"=>$this->id_catph_parent,
        "id_photo"=>$this->id_photo,
        "nom_catph"=>$this->nom,
        "date_debut_catph"=>is_null($this->date_debut)?null:date("Y-m-d H:i:s",$this->date_debut),
        "date_fin_catph"=>is_null($this->date_debut)?null:date("Y-m-d H:i:s",$this->date_fin),
        "modere_catph"=>$this->modere,
        "id_groupe"=>$this->id_groupe,
        "id_groupe_admin"=>$this->id_groupe_admin,
        "droits_acces_catph"=>$this->droits_acces,

        "meta_id_asso_catph"=>$this->meta_id_asso,
        "meta_mode_catph"=>$this->meta_mode,
468

Ayolo's avatar
Ayolo committed
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
        "id_lieu"=>$this->id_lieu

        ),
        array("id_catph"=>$this->id)
      );


  }

  /**
   * Définit si la catégorie est modérée ou pas
   * @param $modere Modérée(=true) ou non (=false)
   */
  function set_modere($modere=true)
  {
    $this->modere = $modere;
    $sql = new update($this->dbrw,"sas_cat_photos",array("modere_catph"=>$this->modere),array("id_catph"=>$this->id) );
  }


  function set_meta ( &$meta_cat)
  {
    $this->meta_cat = &$meta_cat;
  }

  function remove_cat()
  {
    $req = new requete($this->db,
        "SELECT * FROM sas_photos " .
        "WHERE id_catph='".$this->id."'");

    $ph = new photo($this->db,$this->dbrw);
    while ( $row = $req->get_row() )
    {
      $ph->_load($row);
      $ph->remove_photo();
    }


    $req = new requete($this->db,
        "SELECT * FROM sas_cat_photos " .
        "WHERE id_catph_parent='".$this->id."'");
    $cat = new catphoto($this->db,$this->dbrw);
    while ( $row = $req->get_row() )
    {
      $cat->_load($row);
      $cat->remove_cat();
    }

    $sql = new delete($this->dbrw,"sas_cat_photos",array("id_catph"=>$this->id) );
    $this->id=null;
520
    $site->log('suppression catégorie sas', 'potentiel boulet a supprimé :'.$nom, 'sas', $site->user);
Ayolo's avatar
Ayolo committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
  }

  /**
   * Détermine si l'utilisateur est administrateur de l'élèment
   * @param $user Instance de utilisateur
   */
  function is_admin ( &$user )
  {
    if ( $user->is_in_group("sas_admin")) return true;
    return parent::is_admin($user);
  }

  function move_to ( $id_catph_parent )
  {
    $this->id_catph_parent = $id_catph_parent;
536

Ayolo's avatar
Ayolo committed
537
538
539
540
541
542
    $sql = new update ($this->dbrw,
      "sas_cat_photos",
      array("id_catph_parent"=>$this->id_catph_parent),
      array("id_catph"=>$this->id ));
  }

Feu's avatar
Feu committed
543
544
545
546
  function get_semestre ()
  {
    if ( is_null($this->date_debut) )
      return null;
547

Feu's avatar
Feu committed
548
549
    $y = date("Y",$this->date_debut);
    $m = date("m",$this->date_debut);
550

Feu's avatar
Feu committed
551
    if ( $m >= 2 && $m < 9)
Ayolo's avatar
debug    
Ayolo committed
552
      return "Printemps ".$y;
Feu's avatar
Feu committed
553
    else if ( $m >= 9 )
Ayolo's avatar
debug    
Ayolo committed
554
      return "Automne ".$y;
Feu's avatar
Feu committed
555
    else
Ayolo's avatar
debug    
Ayolo committed
556
      return "Automne ".($y-1);
Feu's avatar
Feu committed
557
  }
558

Feu's avatar
Feu committed
559
560
561
562
  function get_short_semestre ()
  {
    if ( is_null($this->date_debut) )
      return null;
563

Feu's avatar
Feu committed
564
565
    $y = date("Y",$this->date_debut);
    $m = date("m",$this->date_debut);
566

Feu's avatar
Feu committed
567
    if ( $m >= 2 && $m < 9)
Ayolo's avatar
debug    
Ayolo committed
568
      return "P".$y;
Feu's avatar
Feu committed
569
    else if ( $m >= 9 )
Ayolo's avatar
debug    
Ayolo committed
570
      return "A".$y;
Feu's avatar
Feu committed
571
    else
Ayolo's avatar
debug    
Ayolo committed
572
      return "A".($y-1);
Feu's avatar
Feu committed
573
  }
574

575
576
577
578
579
580
581
582
583
584
  function is_right (&$user, $required)
  {
    $result = parent::is_right($user, $required);

    // Le test a réussi vraisemblablement parce que le mec est seulement dans
    // le bureau de l'asso. Dans ce cas restreindre l'accès aux vrais gradés.
    if ($meta_id_asso != NULL && $required == DROIT_ECRITURE)
      if ($result && !$user->is_in_group("sas_admin") && $user->is_in_group_id($this->id_groupe_admin))
        if (!$user->is_asso_role($meta_id_asso, ROLEASSO_PRESIDENT) && !$user->is_asso_role($meta_id_asso, ROLEASSO_RESPCOM))
          return false;
585

586
587
    return $result;
  }
588

Feu's avatar
Feu committed
589
  function get_photos_search ( $user, $filter, $joins="", $select="*", $limit="", $order="type_media_ph DESC, date_prise_vue")
Feu's avatar
Feu committed
590
  {
591

Feu's avatar
Feu committed
592
593
594
595
596
597
    if ( $this->is_admin( $user ) )
      return new requete($this->db,"SELECT $select " .
        "FROM sas_photos " .
        "$joins ".
        "WHERE " .
        "($filter) ".
Feu's avatar
Feu committed
598
        "ORDER BY $order " .
Ayolo's avatar
bleh    
Ayolo committed
599
        "$limit");
600

Feu's avatar
Feu committed
601
    $grps = $user->get_groups_csv();
602

Feu's avatar
Feu committed
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
    return new requete($this->db,"SELECT $select " .
        "FROM sas_photos " .
        "$joins ".
        "LEFT JOIN sas_personnes_photos AS p1 ON " .
          "(p1.id_photo=sas_photos.id_photo " .
          "AND p1.id_utilisateur='".$user->id."' " .
          "AND p1.modere_phutl='1') " .
        "LEFT JOIN `asso_membre` ON ".
          "(`asso_membre`.`id_asso` = `sas_photos`.`meta_id_asso_ph` ".
          "AND `asso_membre`.`id_utilisateur` = '" . $user->id."' ".
          "AND `asso_membre`.`date_fin` is NULL AND `asso_membre`.`role` >= '".ROLEASSO_MEMBREBUREAU."') ".
        "WHERE " .
        "($filter) AND " .
        "((((droits_acces_ph & 0x1) OR " .
        "((droits_acces_ph & 0x10) AND id_groupe IN ($grps))) " .
          "AND droits_acquis='1' AND modere_ph='1' ) OR " .
        "(id_groupe_admin IN ($grps)) OR " .
        "((droits_acces_ph & 0x100) AND sas_photos.id_utilisateur='".$user->id."') OR " .
        "((droits_acces_ph & 0x100) AND p1.id_utilisateur IS NOT NULL) ) " .
Feu's avatar
Feu committed
622
        "ORDER BY $order " .
Feu's avatar
Feu committed
623
624
625
        "$limit");

  }
626

Ayolo's avatar
Ayolo committed
627
628
629
630
}



Ayolo's avatar
debug    
Ayolo committed
631
?>