entreprise.php 11.8 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
 * 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/entreprise.inc.php");
require_once($topdir. "include/entities/ville.inc.php");
Feu's avatar
Feu committed
30
require_once($topdir. "include/entities/asso.inc.php");
Ayolo's avatar
Ayolo committed
31 32 33

$site = new site ();

34
$site->allow_only_logged_users("services");
Ayolo's avatar
Ayolo committed
35 36 37 38


$assos=$site->user->get_assos(ROLEASSO_MEMBREBUREAU);
if ( !count($assos) && !$site->user->is_in_group("gestion_ae") )
39
  $site->error_forbidden("services");
Ayolo's avatar
Ayolo committed
40 41 42 43 44

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

if (isset($_REQUEST["id_ent"]))
45
  $entreprise->load_by_id($_REQUEST["id_ent"]);
Ayolo's avatar
Ayolo committed
46 47 48

if ( $entreprise->is_valid() )
{
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 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 111 112 113 114 115 116 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
  $ville->load_by_id($entreprise->id_ville);

  if ( $_REQUEST["action"] == "addcontact" )
  {
    $contact = new contact_entreprise($site->db,$site->dbrw);

    if ( $_REQUEST["nom"] )
      $contact->add ( $entreprise->id, $_REQUEST["nom"], $_REQUEST["telephone"], $_REQUEST["service"], $_REQUEST["email"], $_REQUEST["fax"] );
  }
  elseif ( $_REQUEST["action"] == "addcomment" )
  {
    if ( $_REQUEST["commentaire"] )
    {
      $contact = new contact_entreprise($site->db);
      $commentaire = new commentaire_entreprise($site->db,$site->dbrw);

      if ( $_REQUEST["id_contact"] )
        $contact->load_by_id($_REQUEST["id_contact"]);

      if ( ($contact->id < 1) || ($entreprise->id != $contact->id_ent) )
        $contact->id = NULL;

      $commentaire->add ( $site->user->id, $entreprise->id, $contact->id, $_REQUEST["commentaire"] );
    }
  }
  elseif ( $_REQUEST["action"] == "joinent" )
  {
    if ($_REQUEST["id_ent_doublon"])
      $entreprise->join($_REQUEST["id_ent_doublon"]);

  }
  elseif ( $_REQUEST["action"] == "addtosecteur" )
  {
    if ($_REQUEST["id_secteur"])
      $entreprise->add_secteur($_REQUEST["id_secteur"]);

  }
  elseif ( $_REQUEST["page"] == "edit" )
  {
    $site->start_page("services",$entreprise->nom);


    $frm = new form("addent","entreprise.php?id_ent=".$entreprise->id,false,"POST","Editer");
    $frm->add_hidden("action","save");
    $frm->add_text_field("nom","Nom",$entreprise->nom,true);
    $frm->add_text_field("rue","Rue",$entreprise->rue);
    $frm->add_entity_smartselect ("id_ville","Ville", $ville);
    $frm->add_text_field("email","Adresse email",$entreprise->email);
    $frm->add_text_field("telephone","Téléphone",$entreprise->telephone);
    $frm->add_text_field("fax","Numéro de fax",$entreprise->fax);
    $frm->add_text_field("siteweb","Site web",$entreprise->siteweb);
    $frm->add_submit("valid","Enregistrer");

    $site->add_contents($frm);
    $site->end_page();
    exit();
  }
  elseif( $_REQUEST["action"] == "save" )
  {
    if ( $_REQUEST["nom"] != "" )
    {
      $entreprise->save($_REQUEST["nom"],$_REQUEST["rue"],$_REQUEST["id_ville"],
        $_REQUEST["telephone"],$_REQUEST["email"],$_REQUEST["fax"], $_REQUEST["siteweb"]);
      $ville->load_by_id($entreprise->id_ville);
    }
  }

  if ( $_REQUEST["action"] == "viewcomment" )
  {
    $commentaire = new commentaire_entreprise($site->db);
    $utl = new utilisateur($site->db);
    $commentaire->load_by_id($_REQUEST["id_com_ent"]);
    $utl->load_by_id($commentaire->id_utilisateur);

    $title = "Commentaire de ".$utl->prenom." ".$utl->nom;
    if ( $commentaire->id_contact )
    {
      $contact = new contact_entreprise($site->db);
      $contact->load_by_id($commentaire->id_contact);
      $title .= " (interlocuteur: ".$contact->nom.")";
    }
    $cmt = new wikicontents($title,$commentaire->commentaire);

  }

  $site->start_page("services",$entreprise->nom);

  if ( $cmt )
    $site->add_contents($cmt);
  $l = strtolower(substr($entreprise->nom,0,1));

  $cts = new contents("<a href=\"entreprise.php\">Entreprises</a> / <a href=\"entreprise.php?letter=$l\">$l</a> / ".$entreprise->get_html_link());

  $tbl = new table("Informations");
  if ( $site->user->is_in_group("gestion_ae") )
    $tbl->set_toolbox(new toolbox(array("entreprise.php?page=edit&id_ent=".$entreprise->id=>"Editer")));
  $tbl->add_row(array("Rue",$entreprise->rue));
  $tbl->add_row(array("Ville",$ville->get_html_link()));
  $tbl->add_row(array("Telephone",$entreprise->telephone));
  $tbl->add_row(array("Fax",$entreprise->fax));
  $tbl->add_row(array("Adresse email",$entreprise->email));
  $tbl->add_row(array("Site web","<a href=\"".$entreprise->siteweb."\">".$entreprise->siteweb."</a>"));
  $cts->add($tbl,true);

  $cts->add_paragraph("Voir aussi : <a href=\"entreprise.php\">Autres entreprises</a>");

  $frm = new form("addtosecteur","entreprise.php?id_ent=".$entreprise->id,false,"POST","Ajouter à un secteur d'activité");
  $frm->add_hidden("action","addtosecteur");
  $frm->add_entity_smartselect ("id_secteur","Secteur", new secteur($site->db) );
  $frm->add_submit("valid","Ajouter");
  $cts->add($frm,true);

  $frm = new form("joinent","entreprise.php?id_ent=".$entreprise->id,false,"POST","Fusionner avec un doublon");
  $frm->add_hidden("action","joinent");
  $frm->add_entity_smartselect ("id_ent_doublon","Entreprise", new entreprise($site->db) );
  $frm->add_submit("valid","Fusionner");
  $cts->add($frm,true);

  $req = new requete($site->db,
    "SELECT `id_contact`, `nom_contact`, `service_contact`, `telephone_contact`, `email_contact`, `fax_contact` " .
    "FROM `contact_entreprise` WHERE `id_ent`='".$entreprise->id."' ORDER BY `nom_contact`");
  if ( $req->lines > 0 )
  {
    $tbl = new sqltable(
      "listcontacts",
      "Contacts au sein de l'entreprise", $req, "entreprise.php?id_ent=".$entreprise->id,
      "id_contact",
      array("nom_contact"=>"Contact","service_contact"=>"Service","service_contact"=>"Telephone","email_contact"=>"Adresse email","fax_contact"=>"Fax"),
      array(), array(), array()
      );
    $cts->add($tbl,true);
  }

  $req = new requete($site->db,
    "SELECT `commentaire_entreprise`.`id_com_ent`, `commentaire_entreprise`.`date_com_ent`, " .
    "CONCAT(`utilisateurs`.`prenom_utl`,' ',`utilisateurs`.`nom_utl`) as `nom_utilisateur`, " .
    "`contact_entreprise`.`nom_contact` " .
    "FROM `commentaire_entreprise` " .
    "INNER JOIN `utilisateurs` ON `utilisateurs`.`id_utilisateur`=`commentaire_entreprise`.`id_utilisateur` " .
    "LEFT JOIN `contact_entreprise` ON `contact_entreprise`.`id_contact`=`commentaire_entreprise`.`id_contact` " .
    "WHERE `commentaire_entreprise`.`id_ent`='".$entreprise->id."' ORDER BY `nom_contact`");
  if ( $req->lines > 0 )
  {
    $tbl = new sqltable(
      "listcomment",
      "Commentaires", $req, "entreprise.php?id_ent=".$entreprise->id,
      "id_com_ent",
      array("nom_utilisateur"=>"Déposé par","date_com_ent"=>"Date","nom_contact"=>"Interlocuteur"),
      array("viewcomment"=>"Voir commentaire"), array(), array()
      );
    $cts->add($tbl,true);
  }






  $req->go_first();
  $contacts=array(0=>"(Aucun)");
  while ( $row = $req->get_row() )
    $contacts[$row['id_contact']] = $row['nom_contact'];


  $frm = new form("addcomment","entreprise.php?id_ent=".$entreprise->id,false,"POST","Ajouter un commentaire");
  $frm->add_hidden("action","addcomment");
  $frm->add_select_field("id_contact","Interlocuteur",$contacts);
  $frm->add_text_area("commentaire","Commentaire","",40,6,true);
  $frm->add_submit("valid","Ajouter");
  $cts->add($frm,true);

  $frm = new form("addcontact","entreprise.php?id_ent=".$entreprise->id,false,"POST","Ajouter contact");
  $frm->add_hidden("action","addcontact");
  $frm->add_text_field("nom","Nom","",true);
  $frm->add_text_field("service","Service","");
  $frm->add_text_field("email","Adresse email","");
  $frm->add_text_field("telephone","Téléphone","");
  $frm->add_text_field("fax","Numéro de fax","");
  $frm->add_submit("valid","Ajouter");
  $cts->add($frm,true);



  $site->add_contents($cts);
  $site->end_page();
  exit();
Ayolo's avatar
Ayolo committed
236 237 238 239
}

if( $_REQUEST["action"] == "addent"/* && $site->user->is_in_group("gestion_ae")*/)
{
240 241 242 243 244
  if ( $_REQUEST["nom"] != "" )
  {
    $entreprise->add($_REQUEST["nom"],$_REQUEST["rue"],$_REQUEST["id_ville"],$_REQUEST["telephone"],
      $_REQUEST["email"],$_REQUEST["fax"], $_REQUEST["siteweb"]);
  }
Ayolo's avatar
Ayolo committed
245 246 247
}


248
$site->start_page("services","Entreprises");
Ayolo's avatar
Ayolo committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

$cts = new contents("Entreprises");

if ( isset($_REQUEST["id_secteur"]) )
{
  $id_secteur = intval($_REQUEST["id_secteur"]);
  $letter = null;
}
else
{
  $id_secteur = null;
  $letter = strtolower($_REQUEST["letter"]);
  if ( !$letter ) $letter = "a";
}


$req = new requete($site->db,
266 267
  "SELECT * " .
  "FROM `secteur` ORDER BY `nom_secteur`");
Ayolo's avatar
Ayolo committed
268 269 270 271

$tabsentries = array();

while ( $row = $req->get_row() )
272
  $tabsentries[] = array($row["id_secteur"],"entreprise.php?id_secteur=".$row["id_secteur"], $row["nom_secteur"] );
Ayolo's avatar
Ayolo committed
273 274 275 276 277 278

$cts->add(new tabshead($tabsentries,$id_secteur,"_lg"));

if ( !is_null($id_secteur) )
{
  $req = new requete($site->db,
279 280
    "SELECT `id_ent`, `nom_entreprise`, `telephone_entreprise`, `email_entreprise`, `siteweb_entreprise` " .
    "FROM `entreprise_secteur` INNER JOIN `entreprise` USING(`id_ent`) WHERE `id_secteur`='".mysql_real_escape_string($id_secteur)."' ORDER BY `nom_entreprise`");
Ayolo's avatar
Ayolo committed
281 282
  if ( $req->lines > 0 )
  {
283 284 285 286 287 288 289 290
    $tbl = new sqltable(
      "listent",
      "Liste", $req, "entreprise.php",
      "id_ent",
      array("nom_entreprise"=>"Nom","telephone_entreprise"=>"Telephone","email_entreprise"=>"Adresse email","siteweb_entreprise"=>"Site web"),
      array("view"=>"Voir fiche, commentaires..."), array(), array()
      );
    $cts->add($tbl);
Ayolo's avatar
Ayolo committed
291 292 293 294 295 296
  }
}

$cts->add_paragraph("&nbsp;");

$req = new requete($site->db,
297 298
  "SELECT DISTINCT(SUBSTRING(`nom_entreprise`,1,1)) AS `letter` " .
  "FROM `entreprise` ORDER BY `letter`");
Ayolo's avatar
Ayolo committed
299 300 301 302 303

$tabsentries = array();

while ( $row = $req->get_row() )
{
304
  $tabsentries[] = array(strtolower($row[0]),"entreprise.php?letter=".$row[0], strtoupper($row[0]));
Ayolo's avatar
Ayolo committed
305 306 307 308 309 310 311 312 313
}

$tabsentries[] = array("%","entreprise.php?letter=%", "Tout");

$cts->add(new tabshead($tabsentries,$letter,"_lg"));

if ( !is_null($letter) )
{
  $req = new requete($site->db,
314 315
    "SELECT `id_ent`, `nom_entreprise`, `telephone_entreprise`, `email_entreprise`, `siteweb_entreprise` " .
    "FROM `entreprise` WHERE `nom_entreprise` LIKE '$letter%' ORDER BY `nom_entreprise`");
Ayolo's avatar
Ayolo committed
316 317
  if ( $req->lines > 0 )
  {
318 319 320 321 322 323 324 325
    $tbl = new sqltable(
      "listent",
      "Liste", $req, "entreprise.php",
      "id_ent",
      array("nom_entreprise"=>"Nom","telephone_entreprise"=>"Telephone","email_entreprise"=>"Adresse email","siteweb_entreprise"=>"Site web"),
      array("view"=>"Voir fiche, commentaires..."), array(), array()
      );
    $cts->add($tbl);
Ayolo's avatar
Ayolo committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
  }
}


$frm = new form("addent","entreprise.php",false,"POST","Ajouter entreprise");
$frm->add_hidden("action","addent");
$frm->add_text_field("nom","Nom","",true);
$frm->add_text_field("rue","Rue","");
$frm->add_entity_smartselect ("id_ville","Ville", $ville);
$frm->add_text_field("email","Adresse email","");
$frm->add_text_field("telephone","Téléphone","");
$frm->add_text_field("fax","Numéro de fax","");
$frm->add_text_field("siteweb","Site web","");
$frm->add_submit("valid","Ajouter");
$cts->add($frm,true);


$site->add_contents($cts);
$site->end_page();
?>