contact.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/contact.php
  22. * \ingroup commercial
  23. * \brief Liste des contacts
  24. */
  25. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. // Load translation files required by the page
  28. $langs->load("companies");
  29. $sortfield = GETPOST('sortfield', 'aZ09comma');
  30. $sortorder = GETPOST('sortorder', 'aZ09comma');
  31. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  32. if (!$sortorder) {
  33. $sortorder = "ASC";
  34. }
  35. if (!$sortfield) {
  36. $sortfield = "p.name";
  37. }
  38. if ($page < 0) {
  39. $page = 0;
  40. }
  41. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  42. $offset = $limit * $page;
  43. $type = GETPOST('type', 'alpha');
  44. $search_lastname = GETPOST('search_nom') ?GETPOST('search_nom') : GETPOST('search_lastname'); // For backward compatibility
  45. $search_firstname = GETPOST('search_firstname') ?GETPOST('search_firstname') : GETPOST('search_firstname'); // For backward compatibility
  46. $search_company = GETPOST('search_societe') ?GETPOST('search_societe') : GETPOST('search_company'); // For backward compatibility
  47. $contactname = GETPOST('contactname');
  48. $begin = GETPOST('begin', 'alpha');
  49. // Security check
  50. $socid = GETPOST('socid', 'int');
  51. if ($user->socid) {
  52. $action = '';
  53. $socid = $user->socid;
  54. }
  55. $result = restrictedArea($user, 'societe', $socid, '');
  56. /*
  57. * View
  58. */
  59. llxHeader('', $langs->trans("Contacts"));
  60. if ($type == "c" || $type == "p") {
  61. $label = $langs->trans("Customers");
  62. $urlfiche = "card.php";
  63. }
  64. if ($type == "f") {
  65. $label = $langs->trans("Suppliers");
  66. $urlfiche = "card.php";
  67. }
  68. /*
  69. * List mode
  70. */
  71. $sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm";
  72. $sql .= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
  73. $sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
  74. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  75. $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  76. }
  77. $sql .= " ".MAIN_DB_PREFIX."socpeople as p";
  78. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  79. $sql .= " WHERE s.fk_stcomm = st.id";
  80. $sql .= " AND p.entity IN (".getEntity('contact').")";
  81. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  82. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  83. }
  84. if ($type == "c") {
  85. $sql .= " AND s.client IN (1, 3)";
  86. }
  87. if ($type == "p") {
  88. $sql .= " AND s.client IN (2, 3)";
  89. }
  90. if ($type == "f") {
  91. $sql .= " AND s.fournisseur = 1";
  92. }
  93. if ($socid) {
  94. $sql .= " AND s.rowid = ".((int) $socid);
  95. }
  96. if (!empty($search_lastname)) {
  97. $sql .= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
  98. }
  99. if (!empty($search_firstname)) {
  100. $sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
  101. }
  102. if (!empty($search_company)) {
  103. $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
  104. }
  105. if (!empty($contactname)) { // acces a partir du module de recherche
  106. $sql .= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
  107. $sortfield = "p.name";
  108. $sortorder = "ASC";
  109. }
  110. $sql .= $db->order($sortfield, $sortorder);
  111. $sql .= $db->plimit($limit + 1, $offset);
  112. $resql = $db->query($sql);
  113. if ($resql) {
  114. $num = $db->num_rows($resql);
  115. $param = "&type=".$type;
  116. $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  117. print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
  118. print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
  119. print '<table class="liste centpercent">';
  120. print '<tr class="liste_titre">';
  121. print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, $param, "", $sortfield, $sortorder);
  122. print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
  123. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
  124. print_liste_field_titre("Email");
  125. print_liste_field_titre("Phone");
  126. print "</tr>\n";
  127. print '<tr class="liste_titre">';
  128. print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
  129. print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
  130. print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
  131. print '<td class="liste_titre">&nbsp;</td>';
  132. print '<td class="liste_titre right"><input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>';
  133. print "</tr>\n";
  134. $i = 0;
  135. while ($i < min($num, $limit)) {
  136. $obj = $db->fetch_object($resql);
  137. print '<tr class="oddeven">';
  138. print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
  139. print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
  140. print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
  141. print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a>&nbsp;';
  142. print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
  143. print '<td>'.dol_print_phone($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
  144. print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').'&nbsp;</td>';
  145. print "</tr>\n";
  146. $i++;
  147. }
  148. print "</table>";
  149. print '</form>';
  150. $db->free($resql);
  151. } else {
  152. dol_print_error($db);
  153. }
  154. // End of page
  155. llxFooter();
  156. $db->close();