[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/contrat/ -> contact.php (source)

   1  <?php
   2  /* Copyright (C) 2005 Patrick Rouillon     <patrick@rouillon.net>
   3   * Copyright (C) 2005 Destailleur Laurent  <eldy@users.sourceforge.net>
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License
  16   * along with this program; if not, write to the Free Software
  17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18   *
  19   * $Id: contact.php,v 1.9 2005/12/03 17:55:50 eldy Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/contrat/contact.php,v $
  21   */
  22  
  23  /**
  24          \file       htdocs/contrat/contact.php
  25          \ingroup    contrat
  26          \brief      Onglet de gestion des contacts des contrats
  27          \version    $Revision: 1.9 $
  28  */
  29  
  30  require  ("./pre.inc.php");
  31  require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php");
  32  require_once (DOL_DOCUMENT_ROOT."/contact.class.php");
  33  
  34  
  35  $langs->load("contracts");
  36  // $langs->load("orders");
  37  $langs->load("companies");
  38  
  39  $user->getrights('contrat');
  40  
  41  if (!$user->rights->contrat->lire)
  42      accessforbidden();
  43  
  44  
  45  // les methodes locales
  46  /**
  47    *    \brief      Retourne la liste déroulante des sociétés
  48    *    \param      selected        Societe présélectionnée
  49    *    \param      htmlname        Nom champ formulaire
  50    */
  51  function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'newcompany')
  52  {
  53          // On recherche les societes
  54      $sql = "SELECT s.idp, s.nom FROM";
  55      $sql .= " ".MAIN_DB_PREFIX."societe as s";
  56      if ($filter) $sql .= " WHERE $filter";
  57      $sql .= " ORDER BY nom ASC";
  58  
  59      $resql = $contrat->db->query($sql);
  60      if ($resql)
  61      {
  62          $javaScript = "window.location='./contact.php?id=".$contrat->id."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
  63          print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
  64          $num = $contrat->db->num_rows($resql);
  65          $i = 0;
  66          if ($num)
  67          {
  68              while ($i < $num)
  69              {
  70                  $obj = $contrat->db->fetch_object($resql);
  71                  if ($i == 0)
  72                      $firstCompany = $obj->idp;
  73                  if ($selected > 0 && $selected == $obj->idp)
  74                  {
  75                      print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
  76                      $firstCompany = $obj->idp;
  77                  } else
  78                  {
  79                      print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
  80                  }
  81                  $i ++;
  82              }
  83          }
  84          print "</select>\n";
  85          return $firstCompany;
  86      } else
  87      {
  88          dolibarr_print_error($contrat->db);
  89      }
  90  }
  91  
  92  /**
  93   * 
  94   */
  95  function select_type_contact($contrat, $defValue, $htmlname = 'type', $source)
  96  {
  97      $lesTypes = $contrat->liste_type_contact($source);
  98      print '<select class="flat" name="'.$htmlname.'">';
  99      foreach($lesTypes as $key=>$value)
 100      {
 101          print '<option value="'.$key.'">'.$value.'</option>';
 102      }
 103      print "</select>\n";
 104  }
 105  
 106  
 107  // Sécurité accés client
 108  if ($user->societe_id > 0)
 109  {
 110      $action = '';
 111      $socidp = $user->societe_id;
 112  }
 113  
 114  /*
 115   * Ajout d'un nouveau contact
 116   */
 117  
 118  if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer)
 119  {
 120      $result = 0;
 121      $contrat = new Contrat($db);
 122      $result = $contrat->fetch($_GET["id"]);
 123  
 124      if ($result > 0 && $_POST["id"] > 0)
 125      {
 126            $result = $contrat->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
 127      }
 128      
 129      if ($result >= 0)
 130      {
 131          Header("Location: contact.php?id=".$contrat->id);
 132          exit;
 133      } else
 134      {
 135          $mesg = '<div class="error">'.$contrat->error.'</div>';
 136      }
 137  }
 138  // modification d'un contact. On enregistre le type
 139  if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
 140  {
 141      $contrat = new Contrat($db);
 142      if ($contrat->fetch($_GET["id"]))
 143      {
 144          $contact = $contrat->detail_contact($_POST["elrowid"]);
 145          $type = $_POST["type"];
 146          $statut = $contact->statut;
 147  
 148          $result = $contrat->update_contact($_POST["elrowid"], $statut, $type);
 149          if ($result >= 0)
 150          {
 151              $db->commit();
 152          } else
 153          {
 154              dolibarr_print_error($db, "result=$result");
 155              $db->rollback();
 156          }
 157      } else
 158      {
 159          dolibarr_print_error($db);
 160      }
 161  }
 162  
 163  // bascule du statut d'un contact
 164  if ($_GET["action"] == 'swapstatut' && $user->rights->contrat->creer)
 165  {
 166      $contrat = new Contrat($db);
 167      if ($contrat->fetch($_GET["id"]))
 168      {
 169          $contact = $contrat->detail_contact($_GET["ligne"]);
 170          $id_type_contact = $contact->fk_c_type_contact;
 171          $statut = ($contact->statut == 4) ? 5 : 4;
 172  
 173          $result = $contrat->update_contact($_GET["ligne"], $statut, $id_type_contact);
 174          if ($result >= 0)
 175          {
 176              $db->commit();
 177          } else
 178          {
 179              dolibarr_print_error($db, "result=$result");
 180              $db->rollback();
 181          }
 182      } else
 183      {
 184          dolibarr_print_error($db);
 185      }
 186  }
 187  
 188  // Efface un contact
 189  if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer)
 190  {
 191      $contrat = new Contrat($db);
 192      $contrat->fetch($_GET["id"]);
 193      $result = $contrat->delete_contact($_GET["lineid"]);
 194  
 195      if ($result >= 0)
 196      {
 197          Header("Location: contact.php?id=".$contrat->id);
 198          exit;
 199      }
 200  }
 201  
 202  
 203  
 204  llxHeader('', $langs->trans("ContractCard"), "Contrat");
 205  
 206  $html = new Form($db);
 207  
 208  /* *************************************************************************** */
 209  /*                                                                             */
 210  /* Mode vue et edition                                                         */
 211  /*                                                                             */
 212  /* *************************************************************************** */
 213  $id = $_GET["id"];
 214  if ($id > 0)
 215  {
 216      $contrat = New Contrat($db);
 217      if ($contrat->fetch($id) > 0)
 218      {
 219          if ($mesg)
 220              print $mesg;
 221  
 222          $h = 0;
 223          $head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$contrat->id;
 224          $head[$h][1] = $langs->trans("ContractCard");
 225          $h ++;
 226  
 227          $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id;
 228          $head[$h][1] = $langs->trans("ContractContacts");
 229          $hselected = $h;
 230          $h ++;
 231  
 232          $head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$contrat->id;
 233          $head[$h][1] = $langs->trans("Info");
 234          $h ++;
 235  
 236          dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id);
 237  
 238          /*
 239           *   Contrat
 240           */
 241          print '<table class="border" width="100%">';
 242  
 243          // Reference du contrat
 244          print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
 245          print $contrat->ref;
 246          print "</td></tr>";
 247  
 248          // Customer
 249          print "<tr><td>".$langs->trans("Customer")."</td>";
 250          print '<td colspan="3">';
 251          print '<b><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$contrat->societe->id.'">'.$contrat->societe->nom.'</a></b></td></tr>';
 252  
 253          print "</table>";
 254  
 255  
 256          print '</div>';
 257  
 258  
 259          /*
 260           * Lignes de contacts
 261           */
 262          echo '<br><table class="noborder" width="100%">';
 263  
 264          /*
 265           * Ajouter une ligne de contact
 266           * Non affiché en mode modification de ligne
 267           */
 268          if ($_GET["action"] != 'editline' && $user->rights->contrat->creer)
 269          {
 270              print '<tr class="liste_titre">';
 271              print '<td>'.$langs->trans("Source").'</td>';
 272              print '<td>'.$langs->trans("Company").'</td>';
 273              print '<td>'.$langs->trans("Contacts").'</td>';
 274              print '<td>'.$langs->trans("ContactType").'</td>';
 275              print '<td colspan="3">&nbsp;</td>';
 276              print "</tr>\n";
 277  
 278              $var = false;
 279  
 280              print '<form action="contact.php?id='.$id.'" method="post">';
 281              print '<input type="hidden" name="action" value="addcontact">';
 282              print '<input type="hidden" name="source" value="internal">';
 283              print '<input type="hidden" name="id" value="'.$id.'">';
 284  
 285              // Ligne ajout pour contact interne
 286              print "<tr $bc[$var]>";
 287              
 288              print '<td>';
 289              print $langs->trans("Internal");
 290              print '</td>';            
 291              
 292              print '<td colspan="1">';
 293              print $conf->global->MAIN_INFO_SOCIETE_NOM;
 294              print '</td>';
 295  
 296              print '<td colspan="1">';
 297              $html->select_users($user->id,'contactid');
 298              print '</td>';
 299              print '<td>';
 300              select_type_contact($contrat, '', 'type','internal');
 301              print '</td>';
 302              print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
 303              print '</tr>';
 304  
 305              print '</form>';
 306  
 307              print '<form action="contact.php?id='.$id.'" method="post">';
 308              print '<input type="hidden" name="action" value="addcontact">';
 309              print '<input type="hidden" name="source" value="external">';
 310              print '<input type="hidden" name="id" value="'.$id.'">';
 311  
 312              // Ligne ajout pour contact externe
 313              $var=!$var;
 314              print "<tr $bc[$var]>";
 315              
 316              print '<td>';
 317              print $langs->trans("External");
 318              print '</td>';            
 319              
 320              print '<td colspan="1">';
 321              $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$contrat->societe->id;
 322              $selectedCompany = select_societes_for_newconcat($contrat, $selectedCompany, $htmlname = 'newcompany');
 323              print '</td>';
 324  
 325              print '<td colspan="1">';
 326              $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
 327              print '</td>';
 328              print '<td>';
 329              select_type_contact($contrat, '', 'type','external');
 330              print '</td>';
 331              print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
 332              print '</tr>';
 333              
 334              print "</form>";
 335  
 336          }
 337  
 338          print '<tr><td colspan="6">&nbsp;</td></tr>';
 339          
 340          // Liste des contacts liés
 341          print '<tr class="liste_titre">';
 342          print '<td>'.$langs->trans("Source").'</td>';
 343          print '<td>'.$langs->trans("Company").'</td>';
 344          print '<td>'.$langs->trans("Contacts").'</td>';
 345          print '<td>'.$langs->trans("ContactType").'</td>';
 346          print '<td align="center">'.$langs->trans("Status").'</td>';
 347          print '<td colspan="2">&nbsp;</td>';
 348          print "</tr>\n";
 349  
 350          $societe = new Societe($db);
 351          $var = true;
 352  
 353          foreach(array('internal','external') as $source)
 354          {
 355              $tab = $contrat->liste_contact(-1,$source);
 356              $num=sizeof($tab);
 357  
 358              $i = 0;
 359              while ($i < $num)
 360              {
 361                  $var = !$var;
 362  
 363                  print '<tr '.$bc[$var].' valign="top">';
 364  
 365                  // Source
 366                  print '<td align="left">';
 367                  if ($tab[$i]['source']=='internal') print $langs->trans("Internal");
 368                  if ($tab[$i]['source']=='external') print $langs->trans("External");
 369                  print '</td>';
 370                  
 371                  // Societe
 372                  print '<td align="left">';
 373                  if ($tab[$i]['socid'] > 0)
 374                  {
 375                      print '<a href="'.DOL_URL_ROOT.'/soc.php?idp='.$tab[$i]['socid'].'">';
 376                      print img_object($langs->trans("ShowCompany"),"company").' '.$societe->get_nom($tab[$i]['socid']);
 377                      print '</a>';
 378                  }
 379                  if ($tab[$i]['socid'] < 0)
 380                  {
 381                      print $conf->global->MAIN_INFO_SOCIETE_NOM;
 382                  }
 383                  if (! $tab[$i]['socid'])
 384                  {
 385                      print '&nbsp;';   
 386                  }
 387                  print '</td>';
 388  
 389                  // Contact
 390                  print '<td>';
 391                  if ($tab[$i]['source']=='internal')
 392                  {
 393                      print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$tab[$i]['id'].'">';
 394                      print img_object($langs->trans("ShowUser"),"user").' '.$tab[$i]['nom'].'</a>';
 395                  }
 396                  if ($tab[$i]['source']=='external')
 397                  {
 398                      print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$tab[$i]['id'].'">';
 399                      print img_object($langs->trans("ShowContact"),"contact").' '.$tab[$i]['nom'].'</a>';
 400                  }
 401                  print '</td>';
 402  
 403                  // Type de contact
 404                  print '<td>'.$tab[$i]['libelle'].'</td>';
 405  
 406                  // Statut
 407                  print '<td align="center">';
 408                  // Activation desativation du contact
 409                  if ($contrat->statut >= 0)
 410                      print '<a href="'.DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
 411                  print img_statut($tab[$i]['status']);
 412                  if ($contrat->statut >= 0)
 413                      print '</a>';
 414                  print '</td>';
 415  
 416                  // Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé)
 417                  print '<td align="center" nowrap>';
 418                  if ($contrat->statut == 0 && $user->rights->contrat->creer)
 419                  {
 420                      print '&nbsp;';
 421                      print '<a href="contact.php?id='.$contrat->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
 422                      print img_delete();
 423                      print '</a>';
 424                  }
 425                  print '</td>';
 426  
 427                  print "</tr>\n";
 428  
 429                  $i ++;
 430              }
 431              $db->free($result);
 432          }
 433          print "</table>";
 434  
 435  
 436      }
 437      else
 438      {
 439          // Contrat non trouvé
 440          print "Contrat inexistant ou accés refusé";
 441      }
 442  }
 443  
 444  $db->close();
 445  
 446  llxFooter('$Date: 2005/12/03 17:55:50 $');
 447  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics