club.php 11.2 KB
Newer Older
ayolo's avatar
bleh  
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 31 32 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 70 71 72 73 74 75 76 77 78 79 80 81
<?php
/* Copyright 2009
 *
 * Ce fichier est adapté 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 a
 * 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.
 */

$topdir = "./";
include($topdir. "include/site.inc.php");
require_once($topdir. "include/cts/sqltable.inc.php");
require_once($topdir. "include/entities/club.inc.php");
require_once($topdir. "include/entities/page.inc.php");

$site = new site ();
$club = new club($site->db);

if ( $_REQUEST['action'] == "addclub" && $site->user->is_in_group("gestion_bds") )
{
  $club_parent = new club($site->db);

  if ( !$_REQUEST['nom']  || !$_REQUEST['nom_unix'] )
    $Error = "Un ou plusieurs champs sont incomplets.";
  else
  {
    if ( $_REQUEST['club_parent'] )
    {
      $club_parent->load_by_id($_REQUEST['club_parent']);
      if ( $club_parent->id < 1 )
        $club_parent->id = null;
    }
    else
      $club_parent->id = null;
    $club->add_club($_REQUEST['nom'],$_REQUEST['nom_unix'],$club_parent->id,$_REQUEST["adresse"],$_REQUEST['email'],$_REQUEST['siteweb']);
  }
}
else if ( isset($_REQUEST["id_club"]) )
{
  $club_parent = new club($site->db);
  $club->load_by_id($_REQUEST["id_club"]);
  if ( $club->id < 1 )
  {
    $site->error_not_found();
    exit();
  }

  if ( !is_null($club->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_bds") || $club->is_member_role( $site->user->id, ROLEASSO_VICEPRESIDENT ) )
  {

    if ( $_REQUEST['action'] == "applyedit" )
    {
      if ( $site->user->is_in_group("gestion_bds") && ( !$_REQUEST['nom']  || !$_REQUEST['nom_unix'] ) )
      {
        $Error = "Un ou plusieurs champs sont incomplets.";
        $_REQUEST['page'] = "edit";
      }
ayolo's avatar
bleh  
ayolo committed
82
      elseif ( !preg_match("#^([a-z0-9](([a-z0-9\.]+[a-z0-9])|([a-z0-9]+)))$#i",strtolower($_REQUEST['nom_unix'])) )
ayolo's avatar
bleh  
ayolo committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96
      {
        $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";
        $_REQUEST['page'] = "edit";
      }
      else
      {
        if ( $site->user->is_in_group("gestion_bds") )
        {
          $club_parent->load_by_id($_REQUEST['club_parent']);
          $club->update_club($_REQUEST['nom'],$_REQUEST['nom_unix'],$club_parent->id,$_REQUEST['email']);
        }
        $club->update_club($club->nom,$club->nom_unix,$club_parent->id,$_REQUEST['email']);
      }
    }
ayolo's avatar
bleh  
ayolo committed
97
    else if ( is_dir("/var/www/bds/www/var/img/logos") && $_REQUEST['action'] == "setlogo"  )
ayolo's avatar
bleh  
ayolo committed
98 99 100 101 102
    {
      if ( is_uploaded_file($_FILES['logofile']['tmp_name']) )
      {
        $src = $_FILES['logofile']['tmp_name'];

ayolo's avatar
bleh  
ayolo committed
103
        $dest_small ="/var/www/bds/www/var/img/logos/".$club->nom_unix.".png";
ayolo's avatar
bleh  
ayolo committed
104

ayolo's avatar
bleh  
ayolo committed
105
        exec("/usr/share/php5/exec/convert $src -thumbnail 128x128 $dest_small");
ayolo's avatar
bleh  
ayolo committed
106 107 108 109 110 111 112 113 114 115
      }
      else
        $ErreurLogo = "Erreur lors de l'upload";

      $_REQUEST['page'] = "edit";
    }

  }
  if ( ($_REQUEST['page'] == "edit" ) && ($site->user->is_in_group("gestion_bds") || $club->is_member_role($site->user->id, ROLEASSO_VICEPRESIDENT)))
  {
ayolo's avatar
bleh  
ayolo committed
116
    $site->start_page("clubs",$club->nom);
ayolo's avatar
bleh  
ayolo committed
117 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
    $cts = new contents($club->get_html_path());
    $cts->add(new tabshead($club->get_tabs($site->user),"info"));

    $frm = new form("editclub","club.php?id_club=".$club->id,true,"POST","Edition");
    $frm->add_hidden("action","applyedit");

    if ( $Error )
      $frm->error($Error);
    if ( $site->user->is_in_group("gestion_bds") )
    {
      $frm->add_text_field("nom","Nom du club",$club->nom,true);
      $frm->add_entity_select("club_parent", "Club parent", $site->db, "club",$club->id_parent,true);
    }
    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)",$club->nom_unix,true);
    }
    $frm->add_text_field("email","Email",$club->email);
    $frm->add_submit("applyedit","Enregistrer");
    $cts->add($frm,true);

    $frm = new form("setlogo","club.php?id_club=".$club->id,true,"POST","Logo");
    $frm->add_hidden("action","setlogo");
    if ( $ErreurLogo )
      $frm->error($ErreurLogo);
ayolo's avatar
bleh  
ayolo committed
143 144
    if ( file_exists($topdir."var/img/logos/".$club->nom_unix.".png") )
      $frm->add_info("<img src=\"".$topdir."var/img/logos/".$club->nom_unix.".png\" />");
ayolo's avatar
bleh  
ayolo committed
145 146 147 148 149 150 151 152 153 154
    $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();
  }
  $site->add_css("css/doku.css");
ayolo's avatar
bleh  
ayolo committed
155
  $site->start_page("clubs",$club->nom);
ayolo's avatar
bleh  
ayolo committed
156 157

  $cts = new contents($club->get_html_path());
ayolo's avatar
bleh  
ayolo committed
158
  if ( $site->user->is_in_group("wiki_admin") || $club->is_member_role( $site->user->id, ROLEASSO_MEMBREBUREAU ) || $site->user->is_in_group("root") )
ayolo's avatar
bleh  
ayolo committed
159 160 161 162 163
    $cts->set_toolbox(new toolbox(array("article.php?page=edit&name=activites:".$club->nom_unix=>"Editer Présentation","club.php?page=edit&id_club=".$club->id=>"Editer")));

  $cts->add(new tabshead($club->get_tabs($site->user),"info"));


ayolo's avatar
bleh  
ayolo committed
164
  if ( $_REQUEST["action"] == "selfenroll" && $site->user->is_valid() && !is_null($club->id_parent) && $club->id_parent!=1 )
ayolo's avatar
bleh  
ayolo committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  {
    $site->allow_only_logged_users("presentation");

    if ( $club->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 ".$club->nom);
    }
    else
    {
      $club->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 ".$club->nom);
    }
  }


ayolo's avatar
bleh  
ayolo committed
182 183
  if ( file_exists($topdir."var/img/logos/".$club->nom_unix.".png") )
    $cts->add(new image($club->nom, $topdir."var/img/logos/".$club->nom_unix.".png", "newsimg"));
ayolo's avatar
bleh  
ayolo committed
184 185 186 187 188 189 190 191 192

  $page = new page($site->db);
  $page->load_by_pagename("activites:".$club->nom_unix);
  if ( $page->id > 0 )
  {
    $cts->add_title(2,"Pr&eacute;sentation");
    $cts->add($page->get_contents());

  }
ayolo's avatar
bleh  
ayolo committed
193
  elseif ( $site->user->is_in_group("wiki_admin") )
ayolo's avatar
bleh  
ayolo committed
194
    $cts->add_paragraph("<a href=\"article.php?page=new&amp;name=activites:".$club->nom_unix."\">Creer l'article de pr&eacute;sentation</a>");
ayolo's avatar
bleh  
ayolo committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

  $req = new requete($site->db,
    "SELECT `id_club`, `nom_club`, `nom_unix_club` " .
    "FROM `club` WHERE `id_club_parent`='".$club->id."' " .
    "ORDER BY `nom_club`");
  if ( $req->lines > 0 )
  {
    require_once($topdir."include/cts/gallery.inc.php");

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

    $vocable = "Activités";
    if ( $club->id == 1 )
      $vocable = "Pôles";

    $gal = new gallery($vocable,"clubsgal");
    while ( $row = $req->get_row() )
    {
ayolo's avatar
bleh  
ayolo committed
213
      $img = $topdir."/var/img/logos/".$row['nom_unix_club'].".png";
ayolo's avatar
bleh  
ayolo committed
214

ayolo's avatar
bleh  
ayolo committed
215
      if ( !file_exists($img) )
ayolo's avatar
bleh  
ayolo committed
216 217
      {
        $gal->add_item(
ayolo's avatar
bleh  
ayolo committed
218
          "<a href=\"club.php?id_club=".$row['id_club']."\"><img src=\"images/icons/128/club.png\" alt=\"\" class=\"nope\" />&nbsp;</a>",
ayolo's avatar
bleh  
ayolo committed
219 220 221 222
          "<a href=\"club.php?id_club=".$row['id_club']."\">".$row['nom_club']."</a>" );
      }
      else
        $gal->add_item(
ayolo's avatar
bleh  
ayolo committed
223
          "<a href=\"club.php?id_club=".$row['id_club']."\"><img src=\"$img\" alt=\"".$row['nom_club']."\" />&nbsp;</a>",
ayolo's avatar
bleh  
ayolo committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
          "<a href=\"club.php?id_club=".$row['id_club']."\">".$row['nom_club']."</a>" );
    }
    $cts->add($gal,true);

  }

  $links = array();

  if ( $club->email )
    $links[] = "<b>Contact</b> : <a href=\"mailto:".$club->email."\">".$club->email."</a>";

  if ( $club->siteweb )
    $links[] = "<b>Site web</b> : <a href=\"".$club->siteweb."\">".$club->siteweb."</a>";

  if ( is_null($club->id_parent) )
    $extracond .= "`club_membre`.`role` > '".ROLEASSO_MEMBREACTIF."' ";
  else
    $extracond .= "`club_membre`.`role` > '".ROLEASSO_TRESORIER."' ";

  $req = new requete($site->db,
    "SELECT COUNT(*) " .
    "FROM `club_membre` " .
    "WHERE `club_membre`.`date_fin` IS NULL " .
    "AND `club_membre`.`id_club`='".$club->id."' " .
    "AND ".$extracond);

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

  if ( $respcnt > 0 )
  {
    if ( is_null($club->id_parent) )
      $links[] = "<b>Bureau</b> : <a href=\"club/membres.php?id_club=".$club->id."\">Voir les membres du bureau</a>";
ayolo's avatar
bleh  
ayolo committed
256
    elseif($club->id_parent!=1)
ayolo's avatar
bleh  
ayolo committed
257 258 259 260 261 262 263 264
      $links[] = "<b>Responsable</b> : <a href=\"club/membres.php?id_club=".$club->id."\">Voir le(s) responsable(s)</a>";
  }

  if ( count($links) > 0)
    $cts->add(new itemlist("",false,$links),true);

  $cts->puts("<div class=\"clearboth\"></div>");

ayolo's avatar
bleh  
ayolo committed
265
  if ( (!is_null($club->id_parent) && $club->id_parent!=1) && ($site->user->is_valid() && !$club->is_member($site->user->id)) )
ayolo's avatar
bleh  
ayolo committed
266 267 268 269 270 271 272 273 274 275 276 277 278
  {
    $cts->add_title(2,"Inscrivez vous pour en savoir plus");

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

  $site->add_contents($cts);
  $site->end_page();
  exit();
}

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

ayolo's avatar
bleh  
ayolo committed
279
$site->start_page("clubs","Clubs");
ayolo's avatar
bleh  
ayolo committed
280 281 282

$req = new requete($site->db,
    "SELECT " .
ayolo's avatar
bleh  
ayolo committed
283 284
    "`club1`.id_club, `club1`.nom_club, " .
    "IF(`club1`.`id_club_parent`=1,NULL,`club1`.`id_club_parent`) as `id_club_parent` " .
ayolo's avatar
bleh  
ayolo committed
285
    "FROM `club` AS `club1` " .
ayolo's avatar
bleh  
ayolo committed
286
    "LEFT JOIN `club` AS `club2` ON `club1`.`id_club_parent`=`club2`.`id_club` " .
ayolo's avatar
bleh  
ayolo committed
287 288
    "WHERE `club1`.`id_club`!=1 ".
    "ORDER BY `club2`.`id_club`,`club1`.`nom_club` ");
ayolo's avatar
bleh  
ayolo committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312

$site->add_contents(new treects ( "Clubs", $req, 0, "id_club", "id_club_parent", "nom_club" ));

if ( $site->user->is_in_group("root") )
{
  $frm = new form("newclub","club.php",true,"POST","Ajouter une clubciation");

  if ( isset($Error) && $Error )
    $frm->error($Error);

  $frm->add_hidden("action","addclub");
  $frm->add_text_field("nom","Nom du club","",true);
  $frm->add_text_field("nom_unix","Nom 'unix' (lettres et chiffres sans espaces)","",true);
  $frm->add_entity_select("club_parent", "Club parent", $site->db, "club",0,true);
  $frm->add_text_field("email","Email",$club->email);
  $frm->add_submit("addclub","Ajouter");

  $site->add_contents($frm);
}



$site->end_page();
?>