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@capnetworks.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. $langs->load("companies");
  27. $sortfield=GETPOST('sortfield', 'alpha');
  28. $sortorder=GETPOST('sortorder', 'alpha');
  29. $page=GETPOST('page', 'int');
  30. if (! $sortorder) $sortorder="ASC";
  31. if (! $sortfield) $sortfield="p.name";
  32. if ($page < 0) { $page = 0; }
  33. $limit = $conf->liste_limit;
  34. $offset = $limit * $page ;
  35. $type=GETPOST('type', 'alpha');
  36. $search_lastname=GETPOST('search_nom')?GETPOST('search_nom'):GETPOST('search_lastname'); // For backward compatibility
  37. $search_firstname=GETPOST('search_firstname')?GETPOST('search_firstname'):GETPOST('search_firstname'); // For backward compatibility
  38. $search_company=GETPOST('search_societe')?GETPOST('search_societe'):GETPOST('search_company'); // For backward compatibility
  39. $contactname=GETPOST('contactname');
  40. $begin=GETPOST('begin','alpha');
  41. // Security check
  42. $socid = GETPOST('socid','int');
  43. if ($user->societe_id) $socid=$user->societe_id;
  44. $result = restrictedArea($user, 'societe',$socid,'');
  45. /*
  46. * View
  47. */
  48. llxHeader('','Contacts');
  49. if ($type == "c" || $type == "p")
  50. {
  51. $label = $langs->trans("Customers");
  52. $urlfiche="fiche.php";
  53. }
  54. if ($type == "f")
  55. {
  56. $label = $langs->trans("Suppliers");
  57. $urlfiche="fiche.php";
  58. }
  59. /*
  60. * Mode liste
  61. *
  62. */
  63. $sql = "SELECT s.rowid, s.nom, 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('societe', 1).")";
  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 '<table class="liste" width="100%">';
  108. print '<tr class="liste_titre">';
  109. print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"p.name", $begin, $param,"",$sortfield,$sortorder);
  110. print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"p.firstname", $begin, $param,"",$sortfield,$sortorder);
  111. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom", $begin, $param,"",$sortfield,$sortorder);
  112. print '<td class="liste_titre">'.$langs->trans("Email").'</td>';
  113. print '<td class="liste_titre">'.$langs->trans("Phone").'</td>';
  114. print "</tr>\n";
  115. print '<form action="'.$_SERVER["PHP_SELF"].'?type='.$_GET["type"].'" method="GET">';
  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. print '</form>';
  124. $var=True;
  125. $i = 0;
  126. while ($i < min($num,$limit))
  127. {
  128. $obj = $db->fetch_object($resql);
  129. $var=!$var;
  130. print "<tr ".$bc[$var].">";
  131. print '<td><a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"),"contact");
  132. print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
  133. print "<td>$obj->firstname</TD>";
  134. print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
  135. print "<a href=\"".$urlfiche."?socid=".$obj->rowid."\">$obj->nom</a></td>\n";
  136. print '<td>'.dol_print_phone($obj->email,$obj->cidp,$obj->rowid,'AC_EMAIL').'</td>';
  137. print '<td>'.dol_print_phone($obj->phone,$obj->country_code,$obj->cidp,$obj->rowid,'AC_TEL').'&nbsp;</td>';
  138. print "</tr>\n";
  139. $i++;
  140. }
  141. print "</table></p>";
  142. $db->free($resql);
  143. }
  144. else
  145. {
  146. dol_print_error($db);
  147. }
  148. llxFooter();
  149. $db->close();