contact.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. require '../main.inc.php';
  26. // Load translation files required by the page
  27. $langs->load("companies");
  28. $sortfield = GETPOST('sortfield', 'aZ09comma');
  29. $sortorder = GETPOST('sortorder', 'aZ09comma');
  30. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  31. if (!$sortorder) {
  32. $sortorder = "ASC";
  33. }
  34. if (!$sortfield) {
  35. $sortfield = "p.name";
  36. }
  37. if ($page < 0) {
  38. $page = 0;
  39. }
  40. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  41. $offset = $limit * $page;
  42. $type = GETPOST('type', 'alpha');
  43. $search_lastname = GETPOST('search_nom') ?GETPOST('search_nom') : GETPOST('search_lastname'); // For backward compatibility
  44. $search_firstname = GETPOST('search_firstname') ?GETPOST('search_firstname') : GETPOST('search_firstname'); // For backward compatibility
  45. $search_company = GETPOST('search_societe') ?GETPOST('search_societe') : GETPOST('search_company'); // For backward compatibility
  46. $contactname = GETPOST('contactname');
  47. $begin = GETPOST('begin', 'alpha');
  48. // Security check
  49. $socid = GETPOST('socid', 'int');
  50. if ($user->socid) {
  51. $action = '';
  52. $socid = $user->socid;
  53. }
  54. $result = restrictedArea($user, 'societe', $socid, '');
  55. /*
  56. * View
  57. */
  58. llxHeader('', $langs->trans("Contacts"));
  59. if ($type == "c" || $type == "p") {
  60. $label = $langs->trans("Customers");
  61. $urlfiche = "card.php";
  62. }
  63. if ($type == "f") {
  64. $label = $langs->trans("Suppliers");
  65. $urlfiche = "card.php";
  66. }
  67. /*
  68. * List mode
  69. */
  70. $sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm";
  71. $sql .= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
  72. $sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
  73. if (empty($user->rights->societe->client->voir) && !$socid) {
  74. $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  75. }
  76. $sql .= " ".MAIN_DB_PREFIX."socpeople as p";
  77. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  78. $sql .= " WHERE s.fk_stcomm = st.id";
  79. $sql .= " AND p.entity IN (".getEntity('contact').")";
  80. if (empty($user->rights->societe->client->voir) && !$socid) {
  81. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  82. }
  83. if ($type == "c") {
  84. $sql .= " AND s.client IN (1, 3)";
  85. }
  86. if ($type == "p") {
  87. $sql .= " AND s.client IN (2, 3)";
  88. }
  89. if ($type == "f") {
  90. $sql .= " AND s.fournisseur = 1";
  91. }
  92. if ($socid) {
  93. $sql .= " AND s.rowid = ".((int) $socid);
  94. }
  95. if (!empty($search_lastname)) {
  96. $sql .= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
  97. }
  98. if (!empty($search_firstname)) {
  99. $sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
  100. }
  101. if (!empty($search_company)) {
  102. $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
  103. }
  104. if (!empty($contactname)) { // acces a partir du module de recherche
  105. $sql .= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
  106. $sortfield = "p.name";
  107. $sortorder = "ASC";
  108. }
  109. $sql .= $db->order($sortfield, $sortorder);
  110. $sql .= $db->plimit($limit + 1, $offset);
  111. $resql = $db->query($sql);
  112. if ($resql) {
  113. $num = $db->num_rows($resql);
  114. $param = "&type=".$type;
  115. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  116. print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
  117. print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
  118. print '<table class="liste centpercent">';
  119. print '<tr class="liste_titre">';
  120. print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, $param, "", $sortfield, $sortorder);
  121. print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
  122. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
  123. print_liste_field_titre("Email");
  124. print_liste_field_titre("Phone");
  125. print "</tr>\n";
  126. print '<tr class="liste_titre">';
  127. print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
  128. print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
  129. print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
  130. print '<td class="liste_titre">&nbsp;</td>';
  131. 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>';
  132. print "</tr>\n";
  133. $i = 0;
  134. while ($i < min($num, $limit)) {
  135. $obj = $db->fetch_object($resql);
  136. print '<tr class="oddeven">';
  137. print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
  138. print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
  139. print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
  140. print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a>&nbsp;';
  141. print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
  142. print '<td>'.dol_print_phone($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
  143. print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').'&nbsp;</td>';
  144. print "</tr>\n";
  145. $i++;
  146. }
  147. print "</table>";
  148. print '</form>';
  149. $db->free($resql);
  150. } else {
  151. dol_print_error($db);
  152. }
  153. // End of page
  154. llxFooter();
  155. $db->close();