asso.php 14.2 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
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") )
{
	$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;

    if ( $GLOBALS["is_using_ssl"] )
Feu's avatar
Feu 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
Feu's avatar
Feu committed
61
		  $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
62 63 64 65 66 67 68 69
	}
}
else if ( isset($_REQUEST["id_asso"]) )
{
	$asso_parent = new asso($site->db);
	$asso->load_by_id($_REQUEST["id_asso"]);
	if ( $asso->id < 1 )
	{
70
		$site->error_not_found();
Ayolo's avatar
Ayolo committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
		exit();
	}
	
	// Correction du vocabulaire
  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";
  }
    
	if ( $site->user->is_in_group("gestion_ae") || $asso->is_member_role( $site->user->id, ROLEASSO_VICEPRESIDENT ) )
	{
	
    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 103 104 105 106 107
      else
      {
			  if ( $site->user->is_in_group("gestion_ae") )
				{
          $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']));
Feu's avatar
Feu committed
116 117 118
          
          
        $asso->set_tags($_REQUEST['tags']);
Ayolo's avatar
Ayolo committed
119 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    {
      if ( is_uploaded_file($_FILES['logofile']['tmp_name']) )
      {
        $src = $_FILES['logofile']['tmp_name'];
    
        $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";
    
        exec("/usr/share/php5/exec/convert $src -thumbnail 80x80 $dest_small");
        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"));
        exec(escapeshellcmd("/usr/share/php5/exec/convert $src -background white $dest_full"));
      }
      else
        $ErreurLogo = "Erreur lors de l'upload";
    
      $_REQUEST['page'] = "edit";
    }

	}
	
	if ( ($_REQUEST['page'] == "edit" ) && ($site->user->is_in_group("gestion_ae") || $asso->is_member_role($site->user->id, ROLEASSO_VICEPRESIDENT)))
	{
    $site->start_page("presentation",$asso->nom);
    $cts = new contents($asso->get_html_path());
    $cts->add(new tabshead($asso->get_tabs($site->user),"info"));	
    
    $frm = new form("editasso","asso.php?id_asso=".$asso->id,true,"POST","Edition");
    $frm->add_hidden("action","applyedit");
  
    if ( $Error )
      $frm->error($Error);
    if ( $site->user->is_in_group("gestion_ae") ) 
    {
			$frm->add_text_field("nom","Nom de l'association",$asso->nom,true);
      $frm->add_entity_select("asso_parent", "Association parent", $site->db, "asso",$asso->id_parent,true);
    }
BenC's avatar
BenC committed
160 161 162 163 164 165
    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
Ayolo committed
166 167 168 169
		$frm->add_text_area("adresse","Adresse postale",$asso->adresse_postale);
    
    $frm->add_text_field("email","Email",$asso->email);
    $frm->add_text_field("siteweb","Site web",$asso->siteweb);
Feu's avatar
Feu committed
170
    $frm->add_text_field("tags","Tags (séparateur: virgule)",$asso->get_tags());
Ayolo's avatar
Ayolo committed
171
    
Feu's avatar
Feu committed
172 173
    $frm->add_checkbox("distinct_benevole","Activer la mailing liste bénévoles",$asso->distinct_benevole);

Ayolo's avatar
Ayolo committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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);
  
    $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);
    
    $site->add_contents($cts);
    $site->end_page();
    exit();
	}
Feu's avatar
fix  
Feu committed
200
  $site->add_css("css/doku.css");
Ayolo's avatar
Ayolo committed
201 202 203
	$site->start_page("presentation",$asso->nom);

	$cts = new contents($asso->get_html_path());
BenC's avatar
BenC committed
204
	if ( $site->user->is_in_group("moderateur_site") || $asso->is_member_role( $site->user->id, ROLEASSO_MEMBREBUREAU ) || $site->user->is_in_group("root") )
205
	  $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")));
Ayolo's avatar
Ayolo committed
206 207 208
	
	$cts->add(new tabshead($asso->get_tabs($site->user),"info"));	

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

  if ( $_REQUEST["action"] == "selfenroll" && !is_null($asso->id_parent) )
  {
    $site->allow_only_logged_users("presentation");
    
    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
    {
      $asso->add_actual_member ( $site->user->id, time(), ROLEASSO_MEMBRE, "" );		
      $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);
    }
  }


Feu's avatar
Feu committed
228
	/*$img = "/var/img/logos/".$asso->nom_unix.".small.png";
Ayolo's avatar
Ayolo committed
229
	if ( file_exists("/var/www/ae/www/ae2".$img) )
Feu's avatar
Feu committed
230
		$cts->add(new image($asso->nom, $img, "newsimg"));*/
Ayolo's avatar
Ayolo committed
231 232

	$page = new page($site->db);
233
	$page->load_by_pagename("activites:".$asso->nom_unix);
Ayolo's avatar
Ayolo committed
234 235 236 237 238 239 240
	if ( $page->id > 0 ) 
	{
		$cts->add_title(2,"Pr&eacute;sentation");
		$cts->add($page->get_contents());
		
	}
	elseif ( $site->user->is_in_group("moderateur_site") )
241
		$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
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

	$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 )
	{
    require_once($topdir."include/cts/gallery.inc.php");

    $site->add_css("css/asso.css");
		
		$vocable = "Activités";
		if ( $asso->id == 1 )
		  $vocable = "Pôles";
		
    $gal = new gallery($vocable,"clubsgal");
    while ( $row = $req->get_row() )
    {
  		$img = "/var/img/logos/".$row['nom_unix_asso'].".small.png";

      if ( !file_exists("/var/www/ae/www/ae2".$img) )
      {
        $gal->add_item(
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">&nbsp;<img src=\"images/icons/128/asso.png\" alt=\"\" class=\"nope\" />&nbsp;</a>", 
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">".$row['nom_asso']."</a>" );
      }
      else
        $gal->add_item(
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">&nbsp;<img src=\"$img\" alt=\"\" />&nbsp;</a>", 
          "<a href=\"asso.php?id_asso=".$row['id_asso']."\">".$row['nom_asso']."</a>" );
    }
    $cts->add($gal,true);
		
	}
		
  $links = array();
  
  if ( $asso->email )
		$links[] = "<b>Contact</b> : <a href=\"mailto:".$asso->email."\">".$asso->email."</a>";
		
  if ( $asso->siteweb )
		$links[] = "<b>Site web</b> : <a href=\"".$asso->siteweb."\">".$asso->siteweb."</a>";
		
  if ( is_null($asso->id_parent) )
    $extracond .= "`asso_membre`.`role` > '".ROLEASSO_MEMBREACTIF."' ";
  else
    $extracond .= "`asso_membre`.`role` > '".ROLEASSO_TRESORIER."' ";
    
  $req = new requete($site->db,
		"SELECT COUNT(*) " .
		"FROM `asso_membre` " .
		"WHERE `asso_membre`.`date_fin` IS NULL " .
		"AND `asso_membre`.`id_asso`='".$asso->id."' " .
		"AND ".$extracond);

  list($respcnt) = $req->get_row();
  
  if ( $respcnt > 0 )
  {
    if ( is_null($asso->id_parent) )
		  $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>";
	}	
		
Feu's avatar
Feu committed
307 308
	$links[] = "<b>Historique</b> : <a href=\"asso/history.php?id_asso=".$asso->id."\">Voir résumé</a>";
		
Ayolo's avatar
Ayolo committed
309 310 311 312
	if ( count($links) > 0)
		$cts->add(new itemlist("",false,$links),true);
		
	$cts->puts("<div class=\"clearboth\"></div>");
Feu's avatar
Feu committed
313

314
  if ( $asso->is_mailing_allowed() && !is_null($asso->id_parent) && (!$site->user->is_valid() || !$asso->is_member($site->user->id)) )
315
  {
Feu's avatar
Feu committed
316 317 318
    $cts->add_title(2,"Inscrivez vous pour en savoir plus");  
  
    $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>");
319 320
  }
  
Feu's avatar
Feu committed
321 322
  $cts->add(new taglist($asso),true);

Ayolo's avatar
Ayolo committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
	$site->add_contents($cts);
	$site->end_page();
	exit();
}

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

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

$req = new requete($site->db,
		"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` ");

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

BenC's avatar
BenC committed
342
if ( $site->user->is_in_group("root") )
Ayolo's avatar
Ayolo committed
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
{
  $frm = new form("newasso","asso.php",true,"POST","Ajouter une association");
  
  if ( isset($Error) && $Error )
    $frm->error($Error);
  
  $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);
	$frm->add_entity_select("asso_parent", "Association parent", $site->db, "asso",0,true);
  $frm->add_text_area("adresse","Adresse postale");
  
  $frm->add_text_field("email","Email",$asso->email);
  $frm->add_text_field("siteweb","Site web",$asso->siteweb);
  
Feu's avatar
Feu committed
358 359 360
  $frm->add_checkbox("distinct_benevole","Activer la mailing liste bénévoles",$asso->distinct_benevole);
  
  
Ayolo's avatar
Ayolo committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  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");
  
  $site->add_contents($frm);
}



$site->end_page();
?>