contact.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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@inodbox.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 <https://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->socid > 0) {
  32. $action = '';
  33. $socid = $user->socid;
  34. }
  35. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  36. $sortfield = GETPOST('sortfield', 'aZ09comma');
  37. $sortorder = GETPOST('sortorder', 'aZ09comma');
  38. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  39. if (empty($page) || $page == -1) {
  40. $page = 0;
  41. } // If $page is not defined, or '' or -1
  42. $offset = $limit * $page;
  43. $pageprev = $page - 1;
  44. $pagenext = $page + 1;
  45. if (!$sortorder) {
  46. $sortorder = "ASC";
  47. }
  48. if (!$sortfield) {
  49. $sortfield = "p.name";
  50. }
  51. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  52. /*
  53. * Mode liste
  54. */
  55. $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";
  56. if (empty($user->rights->societe->client->voir) && !$socid) {
  57. $sql .= ", sc.fk_soc, sc.fk_user ";
  58. }
  59. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
  60. if (empty($user->rights->societe->client->voir) && !$socid) {
  61. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  62. }
  63. $sql .= " WHERE s.fk_stcomm = st.id";
  64. $sql .= " AND s.fournisseur = 1";
  65. $sql .= " AND s.rowid = p.fk_soc";
  66. $sql .= " AND s.entity IN (".getEntity('societe').")";
  67. if (empty($user->rights->societe->client->voir) && !$socid) {
  68. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  69. }
  70. if (dol_strlen($stcomm)) {
  71. $sql .= " AND s.fk_stcomm=$stcomm";
  72. }
  73. if (dol_strlen($begin)) {
  74. $sql .= " AND p.name LIKE '$begin%'";
  75. }
  76. if ($contactname) {
  77. $sql .= " AND p.name LIKE '%".strtolower($contactname)."%'";
  78. $sortfield = "p.name";
  79. $sortorder = "ASC";
  80. }
  81. if ($socid) {
  82. $sql .= " AND s.rowid = ".((int) $socid);
  83. }
  84. $sql .= " ORDER BY $sortfield $sortorder ";
  85. $sql .= $db->plimit($limit, $offset);
  86. $result = $db->query($sql);
  87. if ($result) {
  88. $num = $db->num_rows($result);
  89. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  90. print_barre_liste($title." (".$langs->trans("Suppliers").")", $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
  91. print '<table class="liste centpercent">';
  92. print '<tr class="liste_titre">';
  93. print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, "", "", $sortfield, $sortorder);
  94. print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, "", "", $sortfield, $sortorder);
  95. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, "", "", $sortfield, $sortorder);
  96. print_liste_field_titre("Email");
  97. print_liste_field_titre("Phone");
  98. print "</tr>\n";
  99. $i = 0;
  100. while ($i < min($num, $limit)) {
  101. $obj = $db->fetch_object($result);
  102. print '<tr class="oddeven">';
  103. print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'">'.img_object($langs->trans("ShowContact"), "contact").' '.$obj->lastname.'</a></td>';
  104. print '<td>'.$obj->firstname.'</td>';
  105. print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
  106. print '<td>'.$obj->email.'</td>';
  107. print '<td>'.$obj->phone.'</td>';
  108. print "</tr>\n";
  109. $i++;
  110. }
  111. print "</table>";
  112. $db->free($result);
  113. } else {
  114. dol_print_error($db);
  115. }
  116. // End of page
  117. llxFooter();
  118. $db->close();