contact.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2006 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/fourn/contact.php
  21. * \ingroup fournisseur
  22. * \brief Liste des contacts fournisseurs
  23. */
  24. require '../main.inc.php';
  25. $langs->load("companies");
  26. /*
  27. * View
  28. */
  29. llxHeader();
  30. // Security check
  31. if ($user->societe_id > 0)
  32. {
  33. $action = '';
  34. $socid = $user->societe_id;
  35. }
  36. $sortfield = GETPOST("sortfield",'alpha');
  37. $sortorder = GETPOST("sortorder",'alpha');
  38. $page = GETPOST("page",'int');
  39. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  40. $offset = $conf->liste_limit * $page;
  41. $pageprev = $page - 1;
  42. $pagenext = $page + 1;
  43. if (! $sortorder) $sortorder="ASC";
  44. if (! $sortfield) $sortfield="p.name";
  45. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  46. /*
  47. * Mode liste
  48. */
  49. $sql = "SELECT s.rowid as socid, s.nom as name, st.libelle as stcomm, p.rowid as cidp, p.lastname, p.firstname, p.email, p.phone";
  50. if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
  51. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
  52. if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  53. $sql.= " WHERE s.fk_stcomm = st.id";
  54. $sql.= " AND s.fournisseur = 1";
  55. $sql.= " AND s.rowid = p.fk_soc";
  56. $sql.= " AND s.entity IN (".getEntity('societe').")";
  57. if (! $user->rights->societe->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  58. if (dol_strlen($stcomm)) {
  59. $sql .= " AND s.fk_stcomm=$stcomm";
  60. }
  61. if (dol_strlen($begin)) {
  62. $sql .= " AND p.name LIKE '$begin%'";
  63. }
  64. if ($contactname) {
  65. $sql .= " AND p.name LIKE '%".strtolower($contactname)."%'";
  66. $sortfield = "p.name";
  67. $sortorder = "ASC";
  68. }
  69. if ($socid) {
  70. $sql .= " AND s.rowid = ".$socid;
  71. }
  72. $sql .= " ORDER BY $sortfield $sortorder ";
  73. $sql .= $db->plimit($limit, $offset);
  74. $result = $db->query($sql);
  75. if ($result)
  76. {
  77. $num = $db->num_rows($result);
  78. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  79. print_barre_liste($title." (".$langs->trans("Suppliers").")",$page, $_SERVER["PHP_SELF"], "",$sortfield,$sortorder,"",$num);
  80. print '<table class="liste" width="100%">';
  81. print '<tr class="liste_titre">';
  82. print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"p.name", $begin, "", "", $sortfield,$sortorder);
  83. print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"p.firstname", $begin, "", "", $sortfield,$sortorder);
  84. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom", $begin, "", "", $sortfield,$sortorder);
  85. print_liste_field_titre($langs->trans("Email"));
  86. print_liste_field_titre($langs->trans("Phone"));
  87. print "</tr>\n";
  88. $var=True;
  89. $i = 0;
  90. while ($i < min($num,$limit))
  91. {
  92. $obj = $db->fetch_object($result);
  93. print '<tr class="oddeven">';
  94. print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'">'.img_object($langs->trans("ShowContact"),"contact").' '.$obj->lastname.'</a></td>';
  95. print '<td>'.$obj->firstname.'</td>';
  96. print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
  97. print '<td>'.$obj->email.'</td>';
  98. print '<td>'.$obj->phone.'</td>';
  99. print "</tr>\n";
  100. $i++;
  101. }
  102. print "</table>";
  103. $db->free($result);
  104. }
  105. else
  106. {
  107. dol_print_error($db);
  108. }
  109. llxFooter();
  110. $db->close();