asso.php 14.6 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3 4 5 6 7 8
<?php
/* Copyright 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
Ayolo's avatar
Ayolo committed
9
 * modify it under the terms of the GNU General Public License a
Ayolo's avatar
Ayolo committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * 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.
 */
/** Affiche les informations publiques sur une association.
 * @see asso/asso.php
 */

$topdir = "./";
include($topdir. "include/site.inc.php");

require_once($topdir. "include/cts/sqltable.inc.php");
Feu's avatar
Feu committed
31 32
require_once($topdir. "include/cts/taglist.inc.php");

Ayolo's avatar
Ayolo committed
33 34 35 36 37 38 39 40
require_once($topdir. "include/entities/asso.inc.php");
require_once($topdir. "include/entities/page.inc.php");

$site = new site ();
$asso = new asso($site->db,$site->dbrw);

if ( ($_REQUEST['action'] == "addasso") && $site->user->is_in_group("gestion_ae") )
{
Ayolo's avatar
bleh  
Ayolo committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  $asso_parent = new asso($site->db);

  if ( !$_REQUEST['nom']  || !$_REQUEST['nom_unix'] )
  {
    $Error = "Un ou plusieurs champs sont incomplets.";
  }
  else
  {
    if ( $_REQUEST['asso_parent'] )
    {
      $asso_parent->load_by_id($_REQUEST['asso_parent']);
      if ( $asso_parent->id < 1 )
        $asso_parent->id = null;
    }
    else
      $asso_parent->id = null;
Ayolo's avatar
Ayolo committed
57 58

    if ( $GLOBALS["is_using_ssl"] )
Ayolo's avatar
bleh  
Ayolo committed
59
      $asso->add_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],$_REQUEST['login_email'],$_REQUEST['passwd_email'],isset($_REQUEST['distinct_benevole']));
Ayolo's avatar
Ayolo committed
60
    else
Ayolo's avatar
bleh  
Ayolo committed
61 62
      $asso->add_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],null,null,isset($_REQUEST['distinct_benevole']));
  }
Ayolo's avatar
Ayolo committed
63 64 65
}
else if ( isset($_REQUEST["id_asso"]) )
{
Ayolo's avatar
bleh  
Ayolo committed
66 67 68 69 70 71 72 73 74
  $asso_parent = new asso($site->db);
  $asso->load_by_id($_REQUEST["id_asso"]);
  if ( $asso->id < 1 )
  {
    $site->error_not_found();
    exit();
  }

  // Correction du vocabulaire
Ayolo's avatar
Ayolo committed
75 76 77 78 79 80 81 82 83 84
  if ( !is_null($asso->id_parent) )
  {
    $GLOBALS['ROLEASSO'][ROLEASSO_PRESIDENT] = "Responsable";
    $GLOBALS['ROLEASSO'][ROLEASSO_VICEPRESIDENT] = "Vice-responsable";
  }
  else
  {
    $GLOBALS['ROLEASSO'][ROLEASSO_PRESIDENT] = "Président";
    $GLOBALS['ROLEASSO'][ROLEASSO_VICEPRESIDENT] = "Vice-président";
  }
85

Ayolo's avatar
bleh  
Ayolo committed
86 87
  if ( $site->user->is_in_group("gestion_ae") || $asso->is_member_role( $site->user->id, ROLEASSO_VICEPRESIDENT ) )
  {
88

Ayolo's avatar
Ayolo committed
89 90 91 92 93 94 95
    if ( $_REQUEST['action'] == "applyedit" )
    {
      if ( $site->user->is_in_group("gestion_ae") && ( !$_REQUEST['nom']  || !$_REQUEST['nom_unix'] ) )
      {
        $Error = "Un ou plusieurs champs sont incomplets.";
        $_REQUEST['page'] = "edit";
      }
BenC's avatar
BenC committed
96
      elseif ( !preg_match("#^([a-z0-9][a-z0-9\.]+[a-z0-9])$#i",strtolower($_REQUEST['nom_unix'])) )
BenC's avatar
BenC committed
97
      {
BenC's avatar
BenC committed
98
        $Error = "Le nom Unix ne doit comporter que des caractères alpha-numériques et des points (jamais à la fin), et doit faire au moins trois caractères";
BenC's avatar
BenC committed
99 100
        $_REQUEST['page'] = "edit";
      }
Ayolo's avatar
Ayolo committed
101 102
      else
      {
Ayolo's avatar
bleh  
Ayolo committed
103 104
        if ( $site->user->is_in_group("gestion_ae") )
        {
Ayolo's avatar
Ayolo committed
105 106 107
          $asso_parent->load_by_id($_REQUEST['asso_parent']);

          if ( $GLOBALS["is_using_ssl"] )
Feu's avatar
Feu committed
108
            $asso->update_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],$_REQUEST['login_email'],$_REQUEST['passwd_email'],isset($_REQUEST['distinct_benevole']));
Ayolo's avatar
Ayolo committed
109
          else
Feu's avatar
Feu committed
110
            $asso->update_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],null,null,isset($_REQUEST['distinct_benevole']));
Ayolo's avatar
Ayolo committed
111 112
        }
        elseif ( $GLOBALS["is_using_ssl"] )
Feu's avatar
Feu committed
113
          $asso->update_asso($asso->nom,$asso->nom_unix,$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],$_REQUEST['login_email'],$_REQUEST['passwd_email'],isset($_REQUEST['distinct_benevole']));
Ayolo's avatar
Ayolo committed
114
        else
Feu's avatar
Feu committed
115
          $asso->update_asso($asso->nom,$asso->nom_unix,$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],null,null,isset($_REQUEST['distinct_benevole']));
116 117


Feu's avatar
Feu committed
118
        $asso->set_tags($_REQUEST['tags']);
119

Ayolo's avatar
Ayolo committed
120 121
      }
    }
Ayolo's avatar
Ayolo committed
122
    else if ( is_dir("/var/www/ae/www/ae2/var/img") && $_REQUEST['action'] == "setlogo"  )
Ayolo's avatar
Ayolo committed
123 124 125 126
    {
      if ( is_uploaded_file($_FILES['logofile']['tmp_name']) )
      {
        $src = $_FILES['logofile']['tmp_name'];
127
        $output = array ();
128

Ayolo's avatar
Ayolo committed
129 130 131
        $dest_small ="/var/www/ae/www/ae2/var/img/logos/".$asso->nom_unix.".small.png";
        $dest_icon = "/var/www/ae/www/ae2/var/img/logos/".$asso->nom_unix.".icon.png";
        $dest_full = "/var/www/ae/www/ae2/var/img/logos/".$asso->nom_unix.".jpg";
132

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
        exec(escapeshellcmd("/usr/share/php5/exec/convert $src -thumbnail 80x80 $dest_small"), $output);
        foreach ($output as $line) {
          echo $line;
        }
        echo '\n';
        unset($output);
        exec(escapeshellcmd("/usr/share/php5/exec/convert $src -thumbnail 48x48 -bordercolor white  -border 24 -background white -gravity center -crop 48x48+0+0 +repage $dest_icon"), $output);
        foreach ($output as $line) {
          echo $line;
        }
        echo '\n';
        unset($output);
        exec(escapeshellcmd("/usr/share/php5/exec/convert $src -background white $dest_full"), $output);
        foreach ($output as $line) {
          echo $line;
        }
        echo '\n';
        unset($output);
Ayolo's avatar
Ayolo committed
151 152 153
      }
      else
        $ErreurLogo = "Erreur lors de l'upload";
154

Ayolo's avatar
Ayolo committed
155 156 157
      $_REQUEST['page'] = "edit";
    }

Ayolo's avatar
bleh  
Ayolo committed
158
  }
159

Ayolo's avatar
bleh  
Ayolo committed
160 161
  if ( ($_REQUEST['page'] == "edit" ) && ($site->user->is_in_group("gestion_ae") || $asso->is_member_role($site->user->id, ROLEASSO_VICEPRESIDENT)))
  {
Ayolo's avatar
Ayolo committed
162 163
    $site->start_page("presentation",$asso->nom);
    $cts = new contents($asso->get_html_path());
164 165
    $cts->add(new tabshead($asso->get_tabs($site->user),"info"));

Ayolo's avatar
Ayolo committed
166 167
    $frm = new form("editasso","asso.php?id_asso=".$asso->id,true,"POST","Edition");
    $frm->add_hidden("action","applyedit");
168

Ayolo's avatar
Ayolo committed
169 170
    if ( $Error )
      $frm->error($Error);
171
    if ( $site->user->is_in_group("gestion_ae") )
Ayolo's avatar
Ayolo committed
172
    {
Ayolo's avatar
bleh  
Ayolo committed
173
      $frm->add_text_field("nom","Nom de l'association",$asso->nom,true);
Ayolo's avatar
Ayolo committed
174 175
      $frm->add_entity_select("asso_parent", "Association parent", $site->db, "asso",$asso->id_parent,true);
    }
BenC's avatar
BenC committed
176 177 178 179 180 181
    if ( $site->user->is_in_group("root") )
    {
      $frm->add_info("Le nom Unix est une donnée sensible utilisé pour le fonctionements de plusieurs services comme les mailing-lists, à ne modifier que si vous savez ce que vous faites !");
      $frm->add_text_field("nom_unix","Nom 'unix' (lettres et chiffres sans espaces)",$asso->nom_unix,true);
    }

Ayolo's avatar
bleh  
Ayolo committed
182
    $frm->add_text_area("adresse","Adresse postale",$asso->adresse_postale);
183

Ayolo's avatar
Ayolo committed
184 185
    $frm->add_text_field("email","Email",$asso->email);
    $frm->add_text_field("siteweb","Site web",$asso->siteweb);
Feu's avatar
Feu committed
186
    $frm->add_text_field("tags","Tags (séparateur: virgule)",$asso->get_tags());
187

Feu's avatar
Feu committed
188 189
    $frm->add_checkbox("distinct_benevole","Activer la mailing liste bénévoles",$asso->distinct_benevole);

Ayolo's avatar
Ayolo committed
190 191 192 193 194 195 196 197 198 199
    if ( $GLOBALS["is_using_ssl"] )
    {
      $frm->add_text_field("login_email","Login mail utbm",$asso->login_email);
      $frm->add_password_field("passwd_email","Mot de passe",$asso->passwd_email);
    }
    else
      $frm->add_info("Pour pouvoir définir la boite email utbm et son mot de passe, passez en connexion sécurisée (HTTPS).");

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

Ayolo's avatar
Ayolo committed
201 202 203 204 205 206 207 208 209 210
    $frm = new form("setlogo","asso.php?id_asso=".$asso->id,true,"POST","Logo");
    $frm->add_hidden("action","setlogo");
    if ( $ErreurLogo )
      $frm->error($ErreurLogo);
    if ( file_exists($topdir."var/img/logos/".$asso->nom_unix.".small.png") )
      $frm->add_info("<img src=\"".$topdir."var/img/logos/".$asso->nom_unix.".small.png\" />");
    $frm->add_info("Le logo doit être de grande taille, avec un fond transparent et au format PNG");
    $frm->add_file_field("logofile","Fichier PNG");
    $frm->add_submit("valid","Enregistrer");
    $cts->add($frm,true);
211

Ayolo's avatar
Ayolo committed
212 213 214
    $site->add_contents($cts);
    $site->end_page();
    exit();
Ayolo's avatar
bleh  
Ayolo committed
215
  }
Feu's avatar
fix  
Feu committed
216
  $site->add_css("css/doku.css");
Ayolo's avatar
bleh  
Ayolo committed
217
  $site->start_page("presentation",$asso->nom);
Ayolo's avatar
Ayolo committed
218

Ayolo's avatar
bleh  
Ayolo committed
219 220 221
  $cts = new contents($asso->get_html_path());
  if ( $site->user->is_in_group("moderateur_site") || $asso->is_member_role( $site->user->id, ROLEASSO_MEMBREBUREAU ) || $site->user->is_in_group("root") )
    $cts->set_toolbox(new toolbox(array("article.php?page=edit&name=activites:".$asso->nom_unix=>"Editer Présentation","asso.php?page=edit&id_asso=".$asso->id=>"Editer")));
222

Ayolo's avatar
bleh  
Ayolo committed
223
  $cts->add(new tabshead($asso->get_tabs($site->user),"info"));
Ayolo's avatar
Ayolo committed
224

225 226 227 228

  if ( $_REQUEST["action"] == "selfenroll" && !is_null($asso->id_parent) )
  {
    $site->allow_only_logged_users("presentation");
229

230 231 232 233 234 235 236
    if ( $asso->is_member($site->user->id) )
    {
      $cts->add_title(2,"Inscription enregistrée");
      $cts->add_paragraph("Votre inscription était déjà enregistré, vous receverez déjà par e-mail les nouvelles de ".$asso->nom);
    }
    else
    {
237
      $asso->add_actual_member ( $site->user->id, time(), ROLEASSO_MEMBRE, "" );
238 239 240 241 242 243
      $cts->add_title(2,"Inscription enregistrée");
      $cts->add_paragraph("Votre inscription a été enregistré, vous receverez désormais par e-mail les nouvelles de ".$asso->nom);
    }
  }


Ayolo's avatar
bleh  
Ayolo committed
244 245 246
  /*$img = "/var/img/logos/".$asso->nom_unix.".small.png";
  if ( file_exists("/var/www/ae/www/ae2".$img) )
    $cts->add(new image($asso->nom, $img, "newsimg"));*/
Ayolo's avatar
Ayolo committed
247

Ayolo's avatar
bleh  
Ayolo committed
248 249 250 251 252 253
  $page = new page($site->db);
  $page->load_by_pagename("activites:".$asso->nom_unix);
  if ( $page->id > 0 )
  {
    $cts->add_title(2,"Pr&eacute;sentation");
    $cts->add($page->get_contents());
254

Ayolo's avatar
bleh  
Ayolo committed
255 256 257
  }
  elseif ( $site->user->is_in_group("moderateur_site") )
    $cts->add_paragraph("<a href=\"article.php?page=edit&amp;name=activites:".$asso->nom_unix."\">Creer l'article de pr&eacute;sentation</a>");
Ayolo's avatar
Ayolo committed
258

Ayolo's avatar
bleh  
Ayolo committed
259 260 261 262 263 264
  $req = new requete($site->db,
    "SELECT `id_asso`, `nom_asso`, `nom_unix_asso` " .
    "FROM `asso` WHERE `id_asso_parent`='".$asso->id."' " .
    "ORDER BY `nom_asso`");
  if ( $req->lines > 0 )
  {
Ayolo's avatar
Ayolo committed
265 266 267
    require_once($topdir."include/cts/gallery.inc.php");

    $site->add_css("css/asso.css");
268

Ayolo's avatar
bleh  
Ayolo committed
269 270 271
    $vocable = "Activités";
    if ( $asso->id == 1 )
      $vocable = "Pôles";
272

Ayolo's avatar
Ayolo committed
273 274 275
    $gal = new gallery($vocable,"clubsgal");
    while ( $row = $req->get_row() )
    {
Ayolo's avatar
bleh  
Ayolo committed
276
      $img = "/var/img/logos/".$row['nom_unix_asso'].".small.png";
Ayolo's avatar
Ayolo committed
277 278 279 280

      if ( !file_exists("/var/www/ae/www/ae2".$img) )
      {
        $gal->add_item(
281
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">&nbsp;<img src=\"images/icons/128/asso.png\" alt=\"\" class=\"nope\" />&nbsp;</a>",
Ayolo's avatar
Ayolo committed
282 283 284 285
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">".$row['nom_asso']."</a>" );
      }
      else
        $gal->add_item(
286
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">&nbsp;<img src=\"$img\" alt=\"\" />&nbsp;</a>",
Ayolo's avatar
Ayolo committed
287 288 289
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">".$row['nom_asso']."</a>" );
    }
    $cts->add($gal,true);
290

Ayolo's avatar
bleh  
Ayolo committed
291
  }
292

Ayolo's avatar
Ayolo committed
293
  $links = array();
294

Ayolo's avatar
Ayolo committed
295
  if ( $asso->email )
Ayolo's avatar
bleh  
Ayolo committed
296
    $links[] = "<b>Contact</b> : <a href=\"mailto:".$asso->email."\">".$asso->email."</a>";
297

Ayolo's avatar
Ayolo committed
298
  if ( $asso->siteweb )
Ayolo's avatar
bleh  
Ayolo committed
299
    $links[] = "<b>Site web</b> : <a href=\"".$asso->siteweb."\">".$asso->siteweb."</a>";
300

Ayolo's avatar
Ayolo committed
301 302 303 304
  if ( is_null($asso->id_parent) )
    $extracond .= "`asso_membre`.`role` > '".ROLEASSO_MEMBREACTIF."' ";
  else
    $extracond .= "`asso_membre`.`role` > '".ROLEASSO_TRESORIER."' ";
305

Ayolo's avatar
Ayolo committed
306
  $req = new requete($site->db,
Ayolo's avatar
bleh  
Ayolo committed
307 308 309 310 311
    "SELECT COUNT(*) " .
    "FROM `asso_membre` " .
    "WHERE `asso_membre`.`date_fin` IS NULL " .
    "AND `asso_membre`.`id_asso`='".$asso->id."' " .
    "AND ".$extracond);
Ayolo's avatar
Ayolo committed
312 313

  list($respcnt) = $req->get_row();
314

Ayolo's avatar
Ayolo committed
315 316 317
  if ( $respcnt > 0 )
  {
    if ( is_null($asso->id_parent) )
Ayolo's avatar
bleh  
Ayolo committed
318 319 320 321
      $links[] = "<b>Bureau</b> : <a href=\"asso/membres.php?id_asso=".$asso->id."\">Voir les membres du bureau</a>";
    else
      $links[] = "<b>Responsable</b> : <a href=\"asso/membres.php?id_asso=".$asso->id."\">Voir le(s) responsable(s)</a>";
  }
322

Ayolo's avatar
bleh  
Ayolo committed
323
  $links[] = "<b>Historique</b> : <a href=\"asso/history.php?id_asso=".$asso->id."\">Voir résumé</a>";
324

Ayolo's avatar
bleh  
Ayolo committed
325 326
  if ( count($links) > 0)
    $cts->add(new itemlist("",false,$links),true);
327

Ayolo's avatar
bleh  
Ayolo committed
328
  $cts->puts("<div class=\"clearboth\"></div>");
Feu's avatar
Feu committed
329

330
  if ( $asso->is_mailing_allowed() && !is_null($asso->id_parent) && (!$site->user->is_valid() || !$asso->is_member($site->user->id)) )
331
  {
332 333
    $cts->add_title(2,"Inscrivez vous pour en savoir plus");

Feu's avatar
Feu committed
334
    $cts->add_paragraph("Inscrivez vous pour recevoir les nouvelles de ".$asso->nom." par e-mail et participer aux discussions, c'est simple et rapide : <a href=\"asso.php?id_asso=".$asso->id."&amp;action=selfenroll\">cliquez ici</a>");
335
  }
336

Feu's avatar
Feu committed
337 338
  $cts->add(new taglist($asso),true);

Ayolo's avatar
bleh  
Ayolo committed
339 340 341
  $site->add_contents($cts);
  $site->end_page();
  exit();
Ayolo's avatar
Ayolo committed
342 343 344 345 346 347 348
}

require_once($topdir. "include/cts/tree.inc.php");

$site->start_page("presentation","Associations");

$req = new requete($site->db,
Ayolo's avatar
bleh  
Ayolo committed
349 350 351 352 353 354
    "SELECT " .
    "`asso1`.*, " .
    "`asso2`.`id_asso` as `id_asso_parent` " .
    "FROM `asso` AS `asso1`" .
    "LEFT JOIN `asso` AS `asso2` ON `asso1`.`id_asso_parent`=`asso2`.`id_asso`" .
    "ORDER BY `asso2`.`id_asso`,`asso1`.`nom_asso` ");
Ayolo's avatar
Ayolo committed
355 356 357

$site->add_contents(new treects ( "Associations", $req, 0, "id_asso", "id_asso_parent", "nom_asso" ));

BenC's avatar
BenC committed
358
if ( $site->user->is_in_group("root") )
Ayolo's avatar
Ayolo committed
359 360
{
  $frm = new form("newasso","asso.php",true,"POST","Ajouter une association");
361

Ayolo's avatar
Ayolo committed
362 363
  if ( isset($Error) && $Error )
    $frm->error($Error);
364

Ayolo's avatar
Ayolo committed
365 366 367
  $frm->add_hidden("action","addasso");
  $frm->add_text_field("nom","Nom de l'association","",true);
  $frm->add_text_field("nom_unix","Nom 'unix' (lettres et chiffres sans espaces)","",true);
Ayolo's avatar
bleh  
Ayolo committed
368
  $frm->add_entity_select("asso_parent", "Association parent", $site->db, "asso",0,true);
Ayolo's avatar
Ayolo committed
369
  $frm->add_text_area("adresse","Adresse postale");
370

Ayolo's avatar
Ayolo committed
371 372
  $frm->add_text_field("email","Email",$asso->email);
  $frm->add_text_field("siteweb","Site web",$asso->siteweb);
373

Feu's avatar
Feu committed
374
  $frm->add_checkbox("distinct_benevole","Activer la mailing liste bénévoles",$asso->distinct_benevole);
375 376


Ayolo's avatar
Ayolo committed
377 378 379 380 381 382 383 384 385 386
  if ( $GLOBALS["is_using_ssl"] )
  {
    $frm->add_text_field("login_email","Login mail utbm",$asso->login_email);
    $frm->add_password_field("passwd_email","Mot de passe",$asso->passwd_email);
  }
  else
    $frm->add_info("Pour pouvoir définir la boite email utbm et son mot de passe, passez en connexion sécurisée (HTTPS).");


  $frm->add_submit("addasso","Ajouter");
387

Ayolo's avatar
Ayolo committed
388 389 390 391 392 393 394
  $site->add_contents($frm);
}



$site->end_page();
?>