asso.php 13.4 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 24 25 26 27 28 29 30
<?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
 * 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.
 */
/** 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 59 60 61 62 63 64 65 66 67 68 69
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"] )
		  $asso->add_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],$_REQUEST['login_email'],$_REQUEST['passwd_email']);
    else
		  $asso->add_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb']);
	}
}
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
		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";
      }
      else
      {
			  if ( $site->user->is_in_group("gestion_ae") )
				{
          $asso_parent->load_by_id($_REQUEST['asso_parent']);

          if ( $GLOBALS["is_using_ssl"] )
            $asso->update_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],$_REQUEST['login_email'],$_REQUEST['passwd_email']);
          else
            $asso->update_asso($_REQUEST['nom'],$_REQUEST['nom_unix'],$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb']);
        }
        elseif ( $GLOBALS["is_using_ssl"] )
          $asso->update_asso($asso->nom,$asso->nom_unix,$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb'],$_REQUEST['login_email'],$_REQUEST['passwd_email']);
        else
          $asso->update_asso($asso->nom,$asso->nom_unix,$asso_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb']);
Feu's avatar
Feu committed
111 112 113
          
          
        $asso->set_tags($_REQUEST['tags']);
Ayolo's avatar
Ayolo committed
114 115 116
        
      }
    }
Ayolo's avatar
Ayolo committed
117
    else if ( is_dir("/var/www/ae/www/ae2/var/img") && $_REQUEST['action'] == "setlogo"  )
Ayolo's avatar
Ayolo committed
118 119 120 121 122 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
    {
      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
155 156 157 158 159 160
    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
161 162 163 164
		$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
165
    $frm->add_text_field("tags","Tags (séparateur: virgule)",$asso->get_tags());
Ayolo's avatar
Ayolo committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
    
    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
193
  $site->add_css("css/doku.css");
Ayolo's avatar
Ayolo committed
194 195 196
	$site->start_page("presentation",$asso->nom);

	$cts = new contents($asso->get_html_path());
BenC's avatar
BenC committed
197
	if ( $site->user->is_in_group("moderateur_site") || $asso->is_member_role( $site->user->id, ROLEASSO_MEMBREBUREAU ) || $site->user->is_in_group("root") )
198
	  $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
199 200 201
	
	$cts->add(new tabshead($asso->get_tabs($site->user),"info"));	

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220

  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
221
	/*$img = "/var/img/logos/".$asso->nom_unix.".small.png";
Ayolo's avatar
Ayolo committed
222
	if ( file_exists("/var/www/ae/www/ae2".$img) )
Feu's avatar
Feu committed
223
		$cts->add(new image($asso->nom, $img, "newsimg"));*/
Ayolo's avatar
Ayolo committed
224 225

	$page = new page($site->db);
226
	$page->load_by_pagename("activites:".$asso->nom_unix);
Ayolo's avatar
Ayolo committed
227 228 229 230 231 232 233
	if ( $page->id > 0 ) 
	{
		$cts->add_title(2,"Pr&eacute;sentation");
		$cts->add($page->get_contents());
		
	}
	elseif ( $site->user->is_in_group("moderateur_site") )
234
		$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
235 236 237 238 239 240 241 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

	$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
300 301
	$links[] = "<b>Historique</b> : <a href=\"asso/history.php?id_asso=".$asso->id."\">Voir résumé</a>";
		
Ayolo's avatar
Ayolo committed
302 303 304 305
	if ( count($links) > 0)
		$cts->add(new itemlist("",false,$links),true);
		
	$cts->puts("<div class=\"clearboth\"></div>");
Feu's avatar
Feu committed
306

307
  if ( $asso->is_mailing_allowed() && !is_null($asso->id_parent) && (!$site->user->is_valid() || !$asso->is_member($site->user->id)) )
308
  {
Feu's avatar
Feu committed
309 310 311
    $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>");
312 313
  }
  
Feu's avatar
Feu committed
314 315
  $cts->add(new taglist($asso),true);

Ayolo's avatar
Ayolo committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
	$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" ));

if ( $site->user->is_in_group("gestion_ae") )
{
  $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);
  
  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();
?>