contact.php 6.5 KB

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