PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 191 lines | 126 code | 33 blank | 32 comment | 29 complexity | 33277275b415e13aee0c513592a73283 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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_prenom')?GETPOST('search_prenom'):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. // Security check
  41. $socid = GETPOST('socid','int');
  42. if ($user->societe_id) $socid=$user->societe_id;
  43. $result = restrictedArea($user, 'societe',$socid,'');
  44. /*
  45. * View
  46. */
  47. llxHeader('','Contacts');
  48. if ($type == "c")
  49. {
  50. $label = $langs->trans("Customers");
  51. $urlfiche="fiche.php";
  52. }
  53. if ($type == "p")
  54. {
  55. $label = $langs->trans("Prospects");
  56. $urlfiche="prospect/fiche.php";
  57. }
  58. if ($type == "f")
  59. {
  60. $label = $langs->trans("Suppliers");
  61. $urlfiche="fiche.php";
  62. }
  63. /*
  64. * Mode liste
  65. *
  66. */
  67. $sql = "SELECT s.rowid, s.nom, st.libelle as stcomm";
  68. $sql.= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
  69. $sql.= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
  70. if (! $user->rights->societe->client->voir && ! $socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  71. $sql.= " ".MAIN_DB_PREFIX."socpeople as p";
  72. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  73. $sql.= " WHERE s.fk_stcomm = st.id";
  74. $sql.= " AND p.entity IN (".getEntity('societe', 1).")";
  75. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  76. if ($type == "c") $sql.= " AND s.client IN (1, 3)";
  77. if ($type == "p") $sql.= " AND s.client IN (2, 3)";
  78. if ($type == "f") $sql.= " AND s.fournisseur = 1";
  79. if ($socid) $sql.= " AND s.rowid = ".$socid;
  80. if (dol_strlen($stcomm))
  81. {
  82. $sql.= " AND s.fk_stcomm=$stcomm";
  83. }
  84. // FIXME $begin not exist
  85. if (dol_strlen($begin)) // filtre sur la premiere lettre du nom
  86. {
  87. $sql.= " AND upper(p.name) LIKE '".$begin."%'";
  88. }
  89. if (! empty($search_lastname))
  90. {
  91. $sql.= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
  92. }
  93. if (! empty($search_firstname))
  94. {
  95. $sql.= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
  96. }
  97. if (! empty($search_company))
  98. {
  99. $sql.= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
  100. }
  101. if (! empty($contactname)) // acces a partir du module de recherche
  102. {
  103. $sql.= " AND (p.name LIKE '%".$db->escape(strtolower($contactname))."%' OR lower(p.firstname) LIKE '%".$db->escape(strtolower($contactname))."%') ";
  104. $sortfield = "p.name";
  105. $sortorder = "ASC";
  106. }
  107. $sql.= $db->order($sortfield,$sortorder);
  108. $sql.= $db->plimit($limit+1, $offset);
  109. $resql = $db->query($sql);
  110. if ($resql)
  111. {
  112. $num = $db->num_rows($resql);
  113. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  114. print_barre_liste($title.($label?" (".$label.")":""),$page, $_SERVER["PHP_SELF"], "&amp;type=$type",$sortfield,$sortorder,"",$num);
  115. print '<table class="liste" width="100%">';
  116. print '<tr class="liste_titre">';
  117. print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"p.name", $begin,"&amp;type=$type","",$sortfield,$sortorder);
  118. print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"p.firstname", $begin,"&amp;type=$type","",$sortfield,$sortorder);
  119. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom", $begin,"&amp;type=$type","",$sortfield,$sortorder);
  120. print '<td class="liste_titre">'.$langs->trans("Email").'</td>';
  121. print '<td class="liste_titre">'.$langs->trans("Phone").'</td>';
  122. print "</tr>\n";
  123. print '<form action="'.$_SERVER["PHP_SELF"].'?type='.$_GET["type"].'" method="GET">';
  124. print '<tr class="liste_titre">';
  125. print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
  126. print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
  127. print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
  128. print '<td class="liste_titre">&nbsp;</td>';
  129. print '<td class="liste_titre" align="right"><input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>';
  130. print "</tr>\n";
  131. print '</form>';
  132. $var=True;
  133. $i = 0;
  134. while ($i < min($num,$limit))
  135. {
  136. $obj = $db->fetch_object($resql);
  137. $var=!$var;
  138. print "<tr $bc[$var]>";
  139. print '<td><a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"),"contact");
  140. print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
  141. print "<td>$obj->firstname</TD>";
  142. print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
  143. print "<a href=\"".$urlfiche."?socid=".$obj->rowid."\">$obj->nom</a></td>\n";
  144. print '<td>'.dol_print_phone($obj->email,$obj->cidp,$obj->rowid,'AC_EMAIL').'</td>';
  145. print '<td>'.dol_print_phone($obj->phone,$obj->country_code,$obj->cidp,$obj->rowid,'AC_TEL').'&nbsp;</td>';
  146. print "</tr>\n";
  147. $i++;
  148. }
  149. print "</table></p>";
  150. $db->free($resql);
  151. }
  152. else
  153. {
  154. dol_print_error($db);
  155. }
  156. llxFooter();
  157. $db->close();
  158. ?>