asso.inc.php 21.6 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3 4 5
<?php

/** @file Gestion des associations et clubs
 *
 */
6

Ayolo's avatar
Ayolo committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/* Copyright 2005-2007
 * - Julien Etelain <julien CHEZ pmad POINT 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.
 */
28 29 30 31 32 33 34 35 36 37 38 39 40 41

define("ROLEASSO_PRESIDENT",10);
define("ROLEASSO_VICEPRESIDENT",9);
define("ROLEASSO_TRESORIER",7);
define("ROLEASSO_RESPCOM",5);
define("ROLEASSO_SECRETAIRE",4);
define("ROLEASSO_RESPINFO",3);
define("ROLEASSO_MEMBREBUREAU",2);
define("ROLEASSO_MEMBREACTIF",1);
define("ROLEASSO_MEMBRE",0);


$GLOBALS['ROLEASSO'] = array
(
BenC's avatar
BenC committed
42 43 44 45
  ROLEASSO_PRESIDENT=>"Responsable/président",
  ROLEASSO_VICEPRESIDENT=>"Vice-responsable/Vice-président",
  ROLEASSO_TRESORIER=>"Trésorier",
  ROLEASSO_RESPCOM=>"Responsable communication",
Ayolo's avatar
Ayolo committed
46 47
  ROLEASSO_SECRETAIRE=>"Secrétaire",
  ROLEASSO_RESPINFO=>"Responsable informatique",
BenC's avatar
BenC committed
48
  ROLEASSO_MEMBREBUREAU=>"Membre du bureau/de l'équipe",
49 50
  ROLEASSO_MEMBREACTIF=>"Benevole, membre actif",
  ROLEASSO_MEMBRE=>"Membre, adepte ou curieux"
51 52
);

Ayolo's avatar
Ayolo committed
53
$GLOBALS['ROLEASSO100'] = array
54
 (
BenC's avatar
BenC committed
55 56 57 58
  (ROLEASSO_PRESIDENT+100)=>"Président",
  (ROLEASSO_VICEPRESIDENT+100)=>"Vice-président",
  (ROLEASSO_TRESORIER+100)=>"Trésorier",
  (ROLEASSO_RESPCOM+100)=>"Responsable communication",
Ayolo's avatar
Ayolo committed
59 60
  (ROLEASSO_SECRETAIRE+100)=>"Secrétaire",
  (ROLEASSO_RESPINFO+100)=>"Responsable informatique",
BenC's avatar
BenC committed
61
  (ROLEASSO_MEMBREBUREAU+100)=>"Membre du bureau/de l'équipe",
62 63
  (ROLEASSO_MEMBREACTIF+100)=>"Benevole, membre actif",
  (ROLEASSO_MEMBRE+100)=>"Membre, adepte ou curieux",
BenC's avatar
BenC committed
64 65 66 67
  ROLEASSO_PRESIDENT=>"Responsable",
  ROLEASSO_VICEPRESIDENT=>"Vice-responsable",
  ROLEASSO_TRESORIER=>"Trésorier",
  ROLEASSO_RESPCOM=>"Responsable communication",
Ayolo's avatar
Ayolo committed
68 69
  ROLEASSO_SECRETAIRE=>"Secrétaire",
  ROLEASSO_RESPINFO=>"Responsable informatique",
BenC's avatar
BenC committed
70
  ROLEASSO_MEMBREBUREAU=>"Membre du bureau/de l'équipe",
71 72
  ROLEASSO_MEMBREACTIF=>"Benevole, membre actif",
  ROLEASSO_MEMBRE=>"Membre, adepte ou curieux"
73
);
Ayolo's avatar
Ayolo committed
74 75 76 77

class asso extends stdentity
{

BenC's avatar
BenC committed
78
  /* table asso */
79
  var $id_parent;
BenC's avatar
BenC committed
80
  var $nom;
Ayolo's avatar
Ayolo committed
81
  var $nom_unix;
BenC's avatar
BenC committed
82
  var $adresse_postale;
83

BenC's avatar
BenC committed
84 85
  var $email;
  var $siteweb;
86

BenC's avatar
BenC committed
87
  var $login_email;
88
  var $passwd_email;
BenC's avatar
BenC committed
89 90 91 92 93 94 95
  /*
   *  L'objectif est de conserver les mots de passe des boites
   * mails des clubs (er pourquoi pas d'y acceder en imap).
   * Cependant conserver en clair les mots de passe dans la bdd
   * ça craint, faudrait une méthode de pseudo cryptage, pour
   * que le stockage ne se fasse pas en clair...
   */
96

97 98
  public $distinct_benevole=false;

Ayolo's avatar
Ayolo committed
99

BenC's avatar
BenC committed
100 101 102 103 104 105 106
  /** Charge une association par son ID
   * @param $id ID de l'association
   */
  function load_by_id ( $id )
  {
    $req = new requete($this->db, "SELECT * FROM `asso`
        WHERE `id_asso` = '" . mysql_real_escape_string($id) . "'
107
        LIMIT 1");
BenC's avatar
BenC committed
108 109 110 111 112
    if ( $req->lines == 1 )
    {
      $this->_load($req->get_row());
      return true;
    }
113 114

    $this->id = null;
BenC's avatar
BenC committed
115
    return false;
116 117
  }

BenC's avatar
BenC committed
118 119 120 121 122 123 124
  /** Charge une association par son nom unix
   * @param $name Nom unix de l'association
   */
  function load_by_unix_name ( $name )
  {
    $req = new requete($this->db, "SELECT * FROM `asso`
        WHERE `nom_unix_asso` = '" . mysql_real_escape_string($name) . "'
125
        LIMIT 1");
BenC's avatar
BenC committed
126 127 128 129 130
    if ( $req->lines == 1 )
    {
      $this->_load($req->get_row());
      return true;
    }
131 132

    $this->id = null;
BenC's avatar
BenC committed
133
    return false;
134 135
  }

BenC's avatar
BenC committed
136 137 138
  function _load ( $row )
  {
    $this->id = $row['id_asso'];
139
    $this->id_parent = $row['id_asso_parent'];
BenC's avatar
BenC committed
140 141 142
    $this->nom = $row['nom_asso'];
    $this->nom_unix = $row['nom_unix_asso'];
    $this->adresse_postale = $row['adresse_postale'];
143 144

    $this->email = $row['email_asso'];
BenC's avatar
BenC committed
145 146
    $this->siteweb = $row['siteweb_asso'];
    $this->login_email = $row['login_email'];
147
    $this->passwd_email = $row['passwd_email'];
148 149

    $this->distinct_benevole = $row['distinct_benevole_asso'];
BenC's avatar
BenC committed
150
  }
151

BenC's avatar
BenC committed
152 153 154 155 156
  /** Crée une nouvelle association
   * @param $nom      Nom  de l'association
   * @param $nom_unix    Nom UNIX de l'association
   * @param $id_parent  ID de l'association parent, false si non applicable
   */
Feu's avatar
Feu committed
157
  function add_asso ( $nom, $nom_unix, $id_parent = null, $adresse_postale="", $email="", $siteweb="", $login_email="", $passwd_email="", $distinct_benevole=false  )
BenC's avatar
BenC committed
158 159
  {
    if ( is_null($this->dbrw) ) return; // "Read Only" mode
160

BenC's avatar
BenC committed
161 162 163 164
    $this->nom = $nom;
    $this->nom_unix = $nom_unix;
    $this->id_parent = $id_parent;
    $this->adresse_postale = $adresse_postale;
165

BenC's avatar
BenC committed
166 167 168 169
    $this->email = $email;
    $this->siteweb = $siteweb;
    $this->login_email = $login_email;
    $this->passwd_email = $passwd_email;
170

BenC's avatar
BenC committed
171 172 173 174 175 176 177
    $sql = new insert ($this->dbrw,
      "asso",
      array(
        "id_asso_parent" => $this->id_parent,
        "nom_asso" => $this->nom,
        "nom_unix_asso" => $this->nom_unix,
        "adresse_postale"=>$this->adresse_postale,
178

BenC's avatar
BenC committed
179 180 181
        "email_asso"=>$this->email,
        "siteweb_asso"=>$this->siteweb,
        "login_email"=>$this->login_email,
Feu's avatar
Feu committed
182
        "passwd_email"=>$this->passwd_email,
183

Feu's avatar
Feu committed
184
        "distinct_benevole_asso" => $this->distinct_benevole
185

BenC's avatar
BenC committed
186 187
        )
      );
188

BenC's avatar
BenC committed
189 190 191 192
    if ( $sql )
      $this->id = $sql->get_id();
    else
      $this->id = null;
193

BenC's avatar
BenC committed
194 195 196
    if ( $this->nom_unix && $this->is_mailing_allowed() )
    {
      if ( !is_null($this->id_parent) )
197 198
        $this->_ml_create($this->dbrw,$this->nom_unix.".membres",$this->email);

199
      if ( $this->distinct_benevole )
200 201 202
        $this->_ml_create($this->dbrw,$nom_unix.".benevoles",$this->email);

      $this->_ml_create($this->dbrw,$this->nom_unix.".bureau",$this->email);
BenC's avatar
BenC committed
203 204
    }
  }
205

BenC's avatar
BenC committed
206 207 208 209 210
  /** Modifie l'association
   * @param $nom      Nom  de l'association
   * @param $nom_unix    Nom UNIX de l'association
   * @param $id_parent  ID de l'association parent, false si non applicable
   */
Feu's avatar
Feu committed
211
  function update_asso ( $nom, $nom_unix, $id_parent = null, $adresse_postale="", $email=null, $siteweb=null, $login_email=null, $passwd_email=null, $distinct_benevole=false )
212
  {
BenC's avatar
BenC committed
213
    if ( is_null($this->dbrw) ) return; // "Read Only" mode
214

BenC's avatar
BenC committed
215
    $old_allow = $this->is_mailing_allowed();
216
    $old_id_parent = $this->id_parent;
BenC's avatar
BenC committed
217
    $this->id_parent = $id_parent;
218

BenC's avatar
BenC committed
219 220
    if ( $this->is_mailing_allowed() )
    {
221
      if ( !$old_allow || ($nom_unix && !$this->nom_unix) )
BenC's avatar
BenC committed
222 223 224
      {
        if ( $nom_unix )
        {
Feu's avatar
Feu committed
225
          if ( !is_null($id_parent) )
226 227
            $this->_ml_create($this->dbrw,$nom_unix.".membres",$this->email);

Feu's avatar
Feu committed
228
          if ( $distinct_benevole )
229 230
            $this->_ml_create($this->dbrw,$nom_unix.".benevoles",$this->email);

BenC's avatar
BenC committed
231 232
          $this->_ml_create($this->dbrw,$nom_unix.".bureau",$this->email);
        }
233
      }
BenC's avatar
BenC committed
234 235
      elseif ( $this->nom_unix )
      {
236
        if ( is_null($old_id_parent) && !is_null($id_parent) )
BenC's avatar
BenC committed
237
          $this->_ml_create($this->dbrw,$this->nom_unix.".membres",$this->email);
238

Feu's avatar
Feu committed
239
        if ( $distinct_benevole && !$this->distinct_benevole )
240
          $this->_ml_create($this->dbrw,$this->nom_unix.".benevoles",$this->email);
BenC's avatar
BenC committed
241 242
      }
    }
243

BenC's avatar
BenC committed
244 245 246
    $this->nom = $nom;
    $this->nom_unix = $nom_unix;
    $this->adresse_postale = $adresse_postale;
247

BenC's avatar
BenC committed
248 249
    if ( !is_null($email) )
      $this->email = $email;
250

BenC's avatar
BenC committed
251 252
    if ( !is_null($siteweb) )
      $this->siteweb = $siteweb;
253

BenC's avatar
BenC committed
254 255
    if ( !is_null($login_email) )
      $this->login_email = $login_email;
256

BenC's avatar
BenC committed
257 258
    if ( !is_null($passwd_email) )
      $this->passwd_email = $passwd_email;
Ayolo's avatar
Ayolo committed
259

Feu's avatar
Feu committed
260 261
    $this->distinct_benevole = $distinct_benevole;

BenC's avatar
BenC committed
262 263 264 265 266 267 268 269 270 271
    $sql = new update ($this->dbrw,
      "asso",
      array(
        "id_asso_parent" => $this->id_parent,
        "nom_asso" => $this->nom,
        "nom_unix_asso" => $this->nom_unix,
        "adresse_postale"=>$this->adresse_postale,
        "email_asso"=>$this->email,
        "siteweb_asso"=>$this->siteweb,
        "login_email"=>$this->login_email,
Feu's avatar
Feu committed
272 273
        "passwd_email"=>$this->passwd_email,
        "distinct_benevole_asso" => $this->distinct_benevole
BenC's avatar
BenC committed
274 275
        ),
      array ( "id_asso" => $this->id )
276

BenC's avatar
BenC committed
277
      );
278

Feu's avatar
Feu committed
279

Ayolo's avatar
Ayolo committed
280

BenC's avatar
BenC committed
281
  }
282 283


BenC's avatar
BenC committed
284
  /* table asso_membre */
285

BenC's avatar
BenC committed
286 287 288 289
  /** Ajoute un membre actuel à l'association
   * Si l'utilisateur est déjà membre, passe sa participation
   *  précédente comme ancienne
   * @param $id_utl    ID de l'utilisateur
290 291 292
   * @param $date_debut  Date de début (timestamp unix)
   * @param $role      Role
   * @param $description  Description du role (vice président, vpi ...)
BenC's avatar
BenC committed
293 294 295 296
  */
  function add_actual_member ( $id_utl, $date_debut, $role, $description )
  {
    if ( is_null($this->dbrw) ) return; // "Read Only" mode
297

BenC's avatar
BenC committed
298
    if ( !$date_debut )
299
      $date_debut = time();
300

BenC's avatar
BenC committed
301
    $prevrole = $this->member_role($id_utl);
302

BenC's avatar
BenC committed
303 304 305 306 307 308 309 310 311
    if ( is_null($prevrole) )
      $this->_ml_all_subscribe_user($id_utl,$role);
    elseif ( $role == $prevrole )
      return;
    else
    {
      $this->make_former_member($id_utl,$date_debut,true);
      $this->_ml_all_delta_user($id_utl,$prevrole,$role);
    }
312 313

    // Boulet-proof
BenC's avatar
BenC committed
314 315 316 317
    // Enlève toute participation qui est après la date de debut
    new requete($this->dbrw,"DELETE FROM asso_membre ".
      "WHERE date_debut >= '".strftime("%Y-%m-%d", $date_debut)."' ".
      "AND id_utilisateur='".mysql_real_escape_string($id_utl)."' ".
318 319
      "AND id_asso='".mysql_real_escape_string($this->id)."'");

BenC's avatar
BenC committed
320 321 322 323 324 325 326 327 328
    $sql = new insert ($this->dbrw,
      "asso_membre",
      array(
        "id_asso" => $this->id,
        "id_utilisateur" => $id_utl,
        "date_debut" => strftime("%Y-%m-%d", $date_debut),
        "role" => $role,
        "desc_role" => $description
        )
329
      );
BenC's avatar
BenC committed
330
  }
331

BenC's avatar
BenC committed
332 333 334 335
  /** Ajoute un ancien membre de l'association
   * @param $id_utl    ID de l'utilisateur
   * @param $date_debut  Date de début (timestamp unix)
   * @param $date_fin    Date de fin (timestamp unix)
336
   * @param $role      Role
BenC's avatar
BenC committed
337
   * @param $description  Description du role (vice président, vpi ...)
338
   */
BenC's avatar
BenC committed
339 340 341 342
  function add_former_member ( $id_utl, $date_debut, $date_fin, $role, $description )
  {
    if ( is_null($this->dbrw) )
      return; // "Read Only" mode
Feu's avatar
Feu committed
343

BenC's avatar
BenC committed
344 345
    if ( is_null($date_fin))
      return;
Ayolo's avatar
Ayolo committed
346

Feu's avatar
Feu committed
347
    if ( $date_fin <= $date_debut ) // Boulet proof
Feu's avatar
Feu committed
348 349
      return;

350
    // Boulet-proof
BenC's avatar
BenC committed
351 352 353 354 355
    // Enlève toute participation qui est après la date de debut et avant la date de fin
    new requete($this->dbrw,"DELETE FROM asso_membre ".
      "WHERE date_debut >= '".strftime("%Y-%m-%d", $date_debut)."' ".
      "AND date_debut < '".strftime("%Y-%m-%d", $date_fin)."' ".
      "AND id_utilisateur='".mysql_real_escape_string($id_utl)."' ".
356
      "AND id_asso='".mysql_real_escape_string($this->id)."'");
Ayolo's avatar
Ayolo committed
357

BenC's avatar
BenC committed
358 359 360 361 362 363 364 365 366 367
    $sql = new insert ($this->dbrw,
      "asso_membre",
      array(
        "id_asso" => $this->id,
        "id_utilisateur" => $id_utl,
        "date_debut" => strftime("%Y-%m-%d", $date_debut),
        "date_fin" => strftime("%Y-%m-%d", $date_fin),
        "role" => $role,
        "desc_role" => $description
        )
368
      );
BenC's avatar
BenC committed
369
  }
370

BenC's avatar
BenC committed
371 372
  /** Passe un membre actuel de l'association comme ancien
   * @param $id_utl  ID de l'utilisateur
373
   * @param $date_fin  Date de fin (timestamp unix)
BenC's avatar
BenC committed
374 375 376 377
   */
  function make_former_member ( $id_utl, $date_fin, $ignore_ml=false )
  {
    if ( is_null($this->dbrw) ) return; // "Read Only" mode
378

BenC's avatar
BenC committed
379 380
    if ( !$date_fin )
      $date_fin = time();
381

BenC's avatar
BenC committed
382 383
    if ( !$ignore_ml )
      $this->_ml_all_unsubscribe_user($id_utl);
384

BenC's avatar
BenC committed
385
    // Boulet-proof
386
    // Verifie que l'action ne gènère par une durée nulle ou négative
BenC's avatar
BenC committed
387 388 389 390 391 392 393 394
    $req = new requete($this->db,"SELECT date_debut FROM asso_membre ".
      "WHERE date_fin IS NULL ".
      "AND id_utilisateur='".mysql_real_escape_string($id_utl)."' ".
      "AND id_asso='".mysql_real_escape_string($this->id)."'");
    if ( $req->lines == 1 )
    {
      list($date_debut) = $req->get_row();
      $date_debut = strtotime($date_debut);
395 396

      if ( $date_debut >= $date_fin ) // un debut après la fin ?
397 398
      {
        // On oublie la "précédente" participation
BenC's avatar
BenC committed
399 400
        new delete ($this->dbrw,
          "asso_membre",
401 402
          array(
            "id_asso" => $this->id,
BenC's avatar
BenC committed
403 404 405
            "id_utilisateur" => $id_utl,
            "date_fin" => NULL
            )
406
          );
407 408
        return;
      }
BenC's avatar
BenC committed
409
    }
410

BenC's avatar
BenC committed
411 412 413 414 415
    $sql = new update ($this->dbrw,
      "asso_membre",
      array(
        "date_fin" => strftime("%Y-%m-%d", $date_fin)
        ),
416 417
      array(
        "id_asso" => $this->id,
BenC's avatar
BenC committed
418 419 420
        "id_utilisateur" => $id_utl,
        "date_fin" => NULL
        )
421 422
      );

BenC's avatar
BenC committed
423
  }
424

BenC's avatar
BenC committed
425 426 427 428 429 430
  /** Determine si un utilisteur est actuellemnt membre de l'association
   * @param $id_utl  ID de l'utilisateur
   * @return true si vrai, false sinon
   */
  function is_member ( $id_utl )
  {
Ayolo's avatar
Ayolo committed
431 432
    if ( is_null($id_utl) )
      return false;
433

BenC's avatar
BenC committed
434 435 436 437 438
    $req = new requete($this->db, "SELECT * FROM `asso_membre`
          WHERE `id_asso` = '" . mysql_real_escape_string($this->id) . "'
          AND `id_utilisateur` = '" . mysql_real_escape_string($id_utl) . "'
          AND `date_fin` is NULL
          LIMIT 1");
439 440

    return ($req->lines == 1);
BenC's avatar
BenC committed
441
  }
442

BenC's avatar
BenC committed
443 444 445 446 447 448 449
  /** Determine si un utilisteur est actuellemnt membre de l'association et occupe un poste spécial
   * @param $id_utl  ID de l'utilisateur
   * @param $role  Role minimum à occuper
   * @return true si vrai, false sinon
   */
  function is_member_role ( $id_utl, $role )
  {
Ayolo's avatar
Ayolo committed
450 451
    if ( is_null($id_utl) )
      return false;
452

BenC's avatar
BenC committed
453 454 455 456 457
    $req = new requete($this->db, "SELECT * FROM `asso_membre`
        WHERE `id_asso` = '" . mysql_real_escape_string($this->id) . "'
        AND `id_utilisateur` = '" . mysql_real_escape_string($id_utl) . "'
        AND `date_fin` is NULL AND `role` >= '".mysql_real_escape_string($role)."'
        LIMIT 1");
458 459 460 461

    return ($req->lines == 1);
  }

BenC's avatar
BenC committed
462 463
  function member_role ( $id_utl )
  {
Feu's avatar
Feu committed
464
    if ( is_null($id_utl) )
465
      return NULL;
466

BenC's avatar
BenC committed
467 468 469 470 471
    $req = new requete($this->db, "SELECT role FROM `asso_membre`
        WHERE `id_asso` = '" . mysql_real_escape_string($this->id) . "'
        AND `id_utilisateur` = '" . mysql_real_escape_string($id_utl) . "'
        AND `date_fin` is NULL
        LIMIT 1");
472

BenC's avatar
BenC committed
473 474
    if ( $req->lines != 1 )
      return NULL;
475

BenC's avatar
BenC committed
476
    list($role) = $req->get_row();
477 478 479 480 481

    return $role;
  }


BenC's avatar
BenC committed
482 483 484 485 486 487 488
  /** Enlève une 'participation' d'un membre de l'association actuelle
   * @param $id_utl    ID de l'utilisateur
   * @param $date_debut  Date de debut de la 'participation' (timestamp unix)
   */
  function remove_member ( $id_utl, $date_debut )
  {
    if ( is_null($this->dbrw) ) return; // "Read Only" mode
489

BenC's avatar
BenC committed
490
    $prevrole = $this->member_role($id_utl);
491

BenC's avatar
BenC committed
492 493
    $sql = new delete ($this->dbrw,
      "asso_membre",
494 495
      array(
        "id_asso" => $this->id,
BenC's avatar
BenC committed
496 497 498
        "id_utilisateur" => $id_utl,
        "date_debut" => strftime("%Y-%m-%d", $date_debut)
        )
499 500 501
      );

    $newrole = $this->member_role($id_utl);
BenC's avatar
BenC committed
502 503
    if ( is_null($newrole) && !is_null($prevrole) )
      $this->_ml_all_unsubscribe_user($id_utl,$prevrole);
504
    elseif ( $newrole != $prevrole && !is_null($prevrole) && !is_null($newrole) )
BenC's avatar
BenC committed
505 506
      $this->_ml_all_delta_user($id_utl,$prevrole,$newrole);
  }
507 508 509



BenC's avatar
BenC committed
510 511 512
  function get_tabs($user)
  {
    $tabs = array(array("info","asso.php?id_asso=".$this->id, "Informations"));
513

BenC's avatar
BenC committed
514 515 516 517 518 519 520
    if ( $user->is_in_group("gestion_ae")|| $this->is_member_role($user->id,ROLEASSO_MEMBREBUREAU) )
    {
      $tabs[] = array("tools","asso/index.php?id_asso=".$this->id,"Outils");
      $tabs[] = array("inv","asso/inventaire.php?id_asso=".$this->id,"Inventaire");
      $tabs[] = array("res","asso/reservations.php?id_asso=".$this->id,"Reservations");
      $tabs[] = array("mebs","asso/membres.php?id_asso=".$this->id,"Membres");
      $tabs[] = array("slds","asso/ventes.php?id_asso=".$this->id,"Ventes");
BenC's avatar
BenC committed
521
      $tabs[] = array("cpg","asso/campagne.php?id_asso=".$this->id,"Campagne");
BenC's avatar
BenC committed
522 523 524 525 526 527
    }
    else
    {
      $tabs[] = array("mebs","asso/membres.php?id_asso=".$this->id,"Membres");
    }
    $tabs[] = array("files","d.php?id_asso=".$this->id,"Fichiers");
528 529


Ayolo's avatar
Ayolo committed
530 531
    $req = new requete($this->db, "SELECT id_catph FROM `sas_cat_photos` " .
        "WHERE `meta_id_asso_catph` = '" . mysql_real_escape_string($this->id) . "' " .
532 533
        "AND `meta_mode_catph`='1' LIMIT 1");

Ayolo's avatar
Ayolo committed
534 535 536
    if ( $req->lines == 1 )
    {
      $enr = $req->get_row();
BenC's avatar
BenC committed
537 538
      $tabs[] = array("photos","sas2/?id_catph=".$enr["id_catph"],"Photos");
    }
539

540
    $req = new requete($this->db, "SELECT CONCAT(asso_parent.nom_unix_asso,':',asso.nom_unix_asso) AS path
541 542 543
                                   FROM asso
                                   LEFT JOIN asso AS asso_parent ON asso.id_asso_parent=asso_parent.id_asso
                                   WHERE asso.id_asso='".$this->id."'
BenC's avatar
BenC committed
544 545
                                   AND CONCAT(asso_parent.nom_unix_asso,':',asso.nom_unix_asso) IS NOT NULL
                                   AND asso.id_asso_parent <> '1'");
BenC's avatar
BenC committed
546 547 548 549 550 551 552 553
    if ( $req->lines == 1 )
    {
      list($path) = $req->get_row();
      $tabs[] = array("wiki2","wiki2/?name=".$path,"Wiki");
    }

    return $tabs;
  }
554

BenC's avatar
BenC committed
555 556 557 558
  function get_membres_group_id()
  {
   return $this->id+30000;
  }
559

BenC's avatar
BenC committed
560 561 562 563
  function get_bureau_group_id()
  {
   return $this->id+20000;
  }
564 565


Ayolo's avatar
Ayolo committed
566 567 568 569 570 571 572 573 574 575 576 577 578
  function get_html_path()
  {
    global $wwwtopdir;
    $path = $this->get_html_link();
    $parent = new asso($this->db);
    $parent->load_by_id($this->id_parent);
    while ( $parent->is_valid() )
    {
      $path = $parent->get_html_link()." / ".$path;
      $parent->load_by_id($parent->id_parent);
    }
    return $path;
  }
579

580 581
  function prefer_list()
  {
582 583 584
    return true;
  }

Feu's avatar
Feu committed
585 586
  function _ml_all_subscribe_user ( $id_utl, $role=null )
  {
Feu's avatar
Feu committed
587 588
    if ( !$this->is_mailing_allowed() )
      return;
589

Feu's avatar
Feu committed
590 591
    $user = new utilisateur($this->db);
    $user->load_by_id($id_utl);
592

Feu's avatar
Feu committed
593 594
    if ( !$user->is_valid() )
      return;
595

Feu's avatar
wip  
Feu committed
596 597
    if ( !$this->nom_unix )
      return;
598

Feu's avatar
Feu committed
599 600
    if ( is_null($role) )
      $role = $this->member_role($user->id);
601

Feu's avatar
Feu committed
602
    if ( !is_null($this->id_parent) )
Feu's avatar
fix ml  
Feu committed
603
      $this->_ml_subscribe($this->dbrw,$this->nom_unix.".membres",$user->email);
604

605 606
    if ( $this->distinct_benevole && $role >= ROLEASSO_MEMBREACTIF )
      $this->_ml_subscribe($this->dbrw,$this->nom_unix.".benevoles",$user->email);
607

Feu's avatar
Feu committed
608
    if ( $role > ROLEASSO_MEMBREACTIF )
Feu's avatar
fix ml  
Feu committed
609
      $this->_ml_subscribe($this->dbrw,$this->nom_unix.".bureau",$user->email);
Feu's avatar
Feu committed
610
  }
611

Feu's avatar
Feu committed
612 613
  function _ml_all_unsubscribe_user ( $id_utl, $role=null )
  {
Feu's avatar
Feu committed
614
    if ( !$this->is_mailing_allowed() )
615 616
      return;

Feu's avatar
Feu committed
617 618
    $user = new utilisateur($this->db);
    $user->load_by_id($id_utl);
619

Feu's avatar
Feu committed
620 621
    if ( !$user->is_valid() )
      return;
622

Feu's avatar
wip  
Feu committed
623
    if ( !$this->nom_unix )
624 625
      return;

Feu's avatar
Feu committed
626 627
    if ( is_null($role) )
      $role = $this->member_role($user->id);
628

Feu's avatar
Feu committed
629
    if ( !is_null($this->id_parent) )
Feu's avatar
fix ml  
Feu committed
630
      $this->_ml_unsubscribe($this->dbrw,$this->nom_unix.".membres",$user->email);
631

632 633
    if ( $this->distinct_benevole && $role >= ROLEASSO_MEMBREACTIF )
      $this->_ml_unsubscribe($this->dbrw,$this->nom_unix.".benevoles",$user->email);
634

Feu's avatar
Feu committed
635
    if ( $role > ROLEASSO_MEMBREACTIF )
Feu's avatar
fix ml  
Feu committed
636
      $this->_ml_unsubscribe($this->dbrw,$this->nom_unix.".bureau",$user->email);
Feu's avatar
Feu committed
637
  }
638

639 640
  function _ml_all_delta_user ( $id_utl, $oldrole, $newrole )
  {
641
    if ( !$this->is_mailing_allowed() )
642 643
      return;

644 645
    $user = new utilisateur($this->db);
    $user->load_by_id($id_utl);
646

647 648 649
    if ( !$user->is_valid() )
      return;

Feu's avatar
wip  
Feu committed
650 651 652
    if ( !$this->nom_unix )
      return;

653 654 655 656 657 658 659 660 661
    if ( $this->distinct_benevole )
    {
      if ( $oldrole >= ROLEASSO_MEMBREACTIF && $newrole < ROLEASSO_MEMBREACTIF )
        $this->_ml_unsubscribe($this->dbrw,$this->nom_unix.".benevoles",$user->email);
      elseif ( $oldrole < ROLEASSO_MEMBREACTIF && $newrole >= ROLEASSO_MEMBREACTIF )
        $this->_ml_subscribe($this->dbrw,$this->nom_unix.".benevoles",$user->email);
    }


662
    if ( $oldrole > ROLEASSO_MEMBREACTIF && $newrole <= ROLEASSO_MEMBREACTIF )
Feu's avatar
fix ml  
Feu committed
663
      $this->_ml_unsubscribe($this->dbrw,$this->nom_unix.".bureau",$user->email);
664
    elseif ( $oldrole <= ROLEASSO_MEMBREACTIF && $newrole > ROLEASSO_MEMBREACTIF )
Feu's avatar
fix ml  
Feu committed
665
      $this->_ml_subscribe($this->dbrw,$this->nom_unix.".bureau",$user->email);
666

667
  }
668

Feu's avatar
test ml  
Feu committed
669
  static function _ml_subscribe ( $db, $ml, $email )
Feu's avatar
Feu committed
670
  {
Feu's avatar
test ml  
Feu committed
671 672
    if ( !$email )
      return;
Feu's avatar
Feu committed
673
    //echo "SUBSCRIBE $ml $email<br/>";
BenC's avatar
BenC committed
674
    new insert($db,"ml_todo",array("action_todo"=>"SUBSCRIBE","ml_todo"=>strtolower($ml),"email_todo"=>$email));
Feu's avatar
Feu committed
675
  }
676

Feu's avatar
test ml  
Feu committed
677
  static function _ml_unsubscribe ( $db, $ml, $email )
Feu's avatar
Feu committed
678
  {
Feu's avatar
test ml  
Feu committed
679 680
    if ( !$email )
      return;
Feu's avatar
Feu committed
681
    //echo "UNSUBSCRIBE $ml $email<br/>";
BenC's avatar
BenC committed
682
    new insert($db,"ml_todo",array("action_todo"=>"UNSUBSCRIBE","ml_todo"=>strtolower($ml),"email_todo"=>$email));
Feu's avatar
Feu committed
683
  }
684

Feu's avatar
test ml  
Feu committed
685
  static function _ml_create ( $db, $ml, $owner="" )
Feu's avatar
Feu committed
686
  {
Feu's avatar
test ml  
Feu committed
687 688
    if ( empty($owner) )
      $owner = "ae@utbm.fr";
Feu's avatar
Feu committed
689
    //echo "CREATE $ml $owner<br/>";
BenC's avatar
BenC committed
690
    new insert($db,"ml_todo",array("action_todo"=>"CREATE","ml_todo"=>strtolower($ml),"email_todo"=>$owner));
Feu's avatar
Feu committed
691
  }
692

Feu's avatar
test ml  
Feu committed
693
  static function _ml_rename ( $db, $old, $new )
Feu's avatar
Feu committed
694 695
  {
    //TODO: rename mailing $old to $new
Feu's avatar
test ml  
Feu committed
696 697
    //echo "MOVE $old TO $new<br/>";
    //>>> MAIL ADMIN
Feu's avatar
Feu committed
698
  }
699

Feu's avatar
test ml  
Feu committed
700
  static function _ml_remove ( $db, $ml )
Feu's avatar
Feu committed
701 702
  {
    //TODO: destroy $ml
Feu's avatar
test ml  
Feu committed
703 704
    //echo "DESTROY $ml<br/>";
    //>>> MAIL ADMIN
705 706 707
  }


Feu's avatar
Feu committed
708 709 710 711
  function is_mailing_allowed()
  {
    if ( $this->id == 1 )
     return true;
712

Feu's avatar
Feu committed
713
    if ( !is_null($this->id_parent) && $this->id_parent != 3 )
Feu's avatar
Feu committed
714
     return true;
715

Feu's avatar
Feu committed
716 717
    return false;
  }
718 719 720

  function get_pending_unmod_mail()
  {
BenC's avatar
BenC committed
721
    if (strlen($this->nom_unix) <= 0)
Ayolo's avatar
bleh  
Ayolo committed
722
      return 0;
723 724

/*    $pendings = file_get_contents("http://barty.me.aeinfo.net/list_heldmsgs.php");
725 726 727
    $pendings = explode("\n", $pendings);

    foreach ($pendings as $asso_pending)
BenC's avatar
BenC committed
728
    {
Ayolo's avatar
bleh  
Ayolo committed
729 730 731 732
      $asso_pending = explode(":", $asso_pending);

      if ($asso_pending[0] == ($this->nom_unix . ".membres"))
        return $asso_pending[1];
733
    }*/
734 735
    return 0;
  }
Ayolo's avatar
Ayolo committed
736
}
737 738 739



BenC's avatar
BenC committed
740
?>