PageRenderTime 73ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/contact/list.php

https://github.com/asterix14/dolibarr
PHP | 423 lines | 332 code | 46 blank | 45 comment | 74 complexity | b09d24049739d3d59c1af4d2d5b0814f MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  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 2 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/contact/list.php
  22. * \ingroup societe
  23. * \brief Page to list all contacts
  24. */
  25. require("../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  27. $langs->load("companies");
  28. $langs->load("suppliers");
  29. // Security check
  30. $contactid = isset($_GET["id"])?$_GET["id"]:'';
  31. if ($user->societe_id) $socid=$user->societe_id;
  32. $result = restrictedArea($user, 'contact', $contactid,'');
  33. $search_nom=GETPOST("search_nom");
  34. $search_prenom=GETPOST("search_prenom");
  35. $search_societe=GETPOST("search_societe");
  36. $search_poste=GETPOST("search_poste");
  37. $search_phone=GETPOST("search_phone");
  38. $search_phoneper=GETPOST("search_phoneper");
  39. $search_phonepro=GETPOST("search_phonepro");
  40. $search_phonemob=GETPOST("search_phonemob");
  41. $search_fax=GETPOST("search_fax");
  42. $search_email=GETPOST("search_email");
  43. $search_priv=GETPOST("search_priv");
  44. $type=GETPOST("type");
  45. $view=GETPOST("view");
  46. $sall=GETPOST("contactname");
  47. $sortfield = GETPOST("sortfield");
  48. $sortorder = GETPOST("sortorder");
  49. $page = GETPOST("page");
  50. if (! $sortorder) $sortorder="ASC";
  51. if (! $sortfield) $sortfield="p.name";
  52. if ($page < 0) { $page = 0 ; }
  53. $limit = $conf->liste_limit;
  54. $offset = $limit * $page ;
  55. $langs->load("companies");
  56. $titre=$langs->trans("ListOfContacts");
  57. if ($type == "c")
  58. {
  59. $titre=$langs->trans("ListOfContacts").' ('.$langs->trans("ThirdPartyCustomers").')';
  60. $urlfiche="fiche.php";
  61. }
  62. if ($type == "p")
  63. {
  64. $titre=$langs->trans("ListOfContacts").' ('.$langs->trans("ThirdPartyProspects").')';
  65. $urlfiche="prospect/fiche.php";
  66. }
  67. if ($type == "f") {
  68. $titre=$langs->trans("ListOfContacts").' ('.$langs->trans("ThirdPartySuppliers").')';
  69. $urlfiche="fiche.php";
  70. }
  71. if ($type == "o") {
  72. $titre=$langs->trans("ListOfContacts").' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
  73. $urlfiche="";
  74. }
  75. if ($view == 'phone') { $text=" (Vue Telephones)"; }
  76. if ($view == 'mail') { $text=" (Vue EMail)"; }
  77. if ($view == 'recent') { $text=" (Recents)"; }
  78. $titre = $titre." $text";
  79. if ($_POST["button_removefilter"])
  80. {
  81. $search_nom="";
  82. $search_prenom="";
  83. $search_societe="";
  84. $search_poste="";
  85. $search_phone="";
  86. $search_phoneper="";
  87. $search_phonepro="";
  88. $search_phonemob="";
  89. $search_fax="";
  90. $search_email="";
  91. $search_priv="";
  92. $sall="";
  93. }
  94. if ($search_priv < 0) $search_priv='';
  95. /*
  96. * View
  97. */
  98. llxHeader('',$langs->trans("ContactsAddresses"),'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
  99. $form=new Form($db);
  100. $sql = "SELECT s.rowid as socid, s.nom,";
  101. $sql.= " p.rowid as cidp, p.name, p.firstname, p.poste, p.email,";
  102. $sql.= " p.phone, p.phone_mobile, p.fax, p.fk_pays, p.priv,";
  103. $sql.= " p.tms,";
  104. $sql.= " cp.code as pays_code";
  105. $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  106. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as cp ON cp.rowid = p.fk_pays";
  107. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  108. if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  109. $sql.= " WHERE p.entity = ".$conf->entity;
  110. if (!$user->rights->societe->client->voir && !$socid) //restriction
  111. {
  112. $sql .= " AND (sc.fk_user = " .$user->id." OR p.fk_soc IS NULL)";
  113. }
  114. if ($_GET["userid"]) // propre au commercial
  115. {
  116. $sql .= " AND p.fk_user_creat=".$_GET["userid"];
  117. }
  118. // Filter to exclude not owned private contacts
  119. if ($search_priv != '0' && $search_priv != '1')
  120. {
  121. $sql .= " AND (p.priv='0' OR (p.priv='1' AND p.fk_user_creat=".$user->id."))";
  122. }
  123. else
  124. {
  125. if ($search_priv == '0') $sql .= " AND p.priv='0'";
  126. if ($search_priv == '1') $sql .= " AND (p.priv='1' AND p.fk_user_creat=".$user->id.")";
  127. }
  128. if ($search_nom) // filtre sur le nom
  129. {
  130. $sql .= " AND p.name like '%".$db->escape($search_nom)."%'";
  131. }
  132. if ($search_prenom) // filtre sur le prenom
  133. {
  134. $sql .= " AND p.firstname like '%".$db->escape($search_prenom)."%'";
  135. }
  136. if ($search_societe) // filtre sur la societe
  137. {
  138. $sql .= " AND s.nom like '%".$db->escape($search_societe)."%'";
  139. }
  140. if (strlen($search_poste)) // filtre sur la societe
  141. {
  142. $sql .= " AND p.poste like '%".$db->escape($search_poste)."%'";
  143. }
  144. if (strlen($search_phone))
  145. {
  146. $sql .= " AND (p.phone like '%".$db->escape($search_phone)."%' OR p.phone_perso like '%".$db->escape($search_phone)."%' OR p.phone_mobile like '%".$db->escape($search_phone)."%')";
  147. }
  148. if (strlen($search_phoneper))
  149. {
  150. $sql .= " AND p.phone like '%".$db->escape($search_phoneper)."%'";
  151. }
  152. if (strlen($search_phonepro))
  153. {
  154. $sql .= " AND p.phone_perso like '%".$db->escape($search_phonepro)."%'";
  155. }
  156. if (strlen($search_phonemob))
  157. {
  158. $sql .= " AND p.phone_mobile like '%".$db->escape($search_phonemob)."%'";
  159. }
  160. if (strlen($search_fax))
  161. {
  162. $sql .= " AND p.fax like '%".$db->escape($search_fax)."%'";
  163. }
  164. if (strlen($search_email)) // filtre sur l'email
  165. {
  166. $sql .= " AND p.email like '%".$db->escape($search_email)."%'";
  167. }
  168. if ($type == "o") // filtre sur type
  169. {
  170. $sql .= " AND p.fk_soc IS NULL";
  171. }
  172. if ($type == "f") // filtre sur type
  173. {
  174. $sql .= " AND fournisseur = 1";
  175. }
  176. if ($type == "c") // filtre sur type
  177. {
  178. $sql .= " AND client IN (1, 3)";
  179. }
  180. if ($type == "p") // filtre sur type
  181. {
  182. $sql .= " AND client IN (2, 3)";
  183. }
  184. if ($sall)
  185. {
  186. $sql .= " AND (p.name like '%".$db->escape($sall)."%' OR p.firstname like '%".$db->escape($sall)."%' OR p.email like '%".$db->escape($sall)."%') ";
  187. }
  188. if ($socid)
  189. {
  190. $sql .= " AND s.rowid = ".$socid;
  191. }
  192. // Count total nb of records
  193. $nbtotalofrecords = 0;
  194. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  195. {
  196. $result = $db->query($sql);
  197. $nbtotalofrecords = $db->num_rows($result);
  198. }
  199. // Add order and limit
  200. if($view == "recent")
  201. {
  202. $sql.= " ORDER BY p.datec DESC ";
  203. $sql.= " ".$db->plimit($conf->liste_limit+1, $offset);
  204. }
  205. else
  206. {
  207. $sql.= " ORDER BY $sortfield $sortorder ";
  208. $sql.= " ".$db->plimit($conf->liste_limit+1, $offset);
  209. }
  210. //print $sql;
  211. dol_syslog("contact/list.php sql=".$sql);
  212. $result = $db->query($sql);
  213. if ($result)
  214. {
  215. $contactstatic=new Contact($db);
  216. $begin=$_GET["begin"];
  217. $param ='&begin='.urlencode($begin).'&view='.urlencode($view).'&userid='.urlencode($_GET["userid"]).'&contactname='.urlencode($sall);
  218. $param.='&type='.urlencode($type).'&view='.urlencode($view).'&search_nom='.urlencode($search_nom).'&search_prenom='.urlencode($search_prenom).'&search_societe='.urlencode($search_societe).'&search_email='.urlencode($search_email);
  219. if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".urlencode($search_priv);
  220. $num = $db->num_rows($result);
  221. $i = 0;
  222. print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
  223. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  224. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  225. print '<input type="hidden" name="view" value="'.$view.'">';
  226. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  227. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  228. if ($sall)
  229. {
  230. print $langs->trans("Filter")." (".$langs->trans("Lastname").", ".$langs->trans("Firstname")." ".$langs->trans("or")." ".$langs->trans("EMail")."): ".$sall;
  231. }
  232. print '<table class="liste" width="100%">';
  233. // Ligne des titres
  234. print '<tr class="liste_titre">';
  235. print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"p.name", $begin, $param, '', $sortfield,$sortorder);
  236. print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"p.firstname", $begin, $param, '', $sortfield,$sortorder);
  237. print_liste_field_titre($langs->trans("PostOrFunction"),$_SERVER["PHP_SELF"],"p.poste", $begin, $param, '', $sortfield,$sortorder);
  238. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom", $begin, $param, '', $sortfield,$sortorder);
  239. if ($view == 'phone')
  240. {
  241. print_liste_field_titre($langs->trans("Phone"),$_SERVER["PHP_SELF"],"p.phone", $begin, $param, '', $sortfield,$sortorder);
  242. print_liste_field_titre($langs->trans("Mobile"),$_SERVER["PHP_SELF"],"p.phone_mob", $begin, $param, '', $sortfield,$sortorder);
  243. print_liste_field_titre($langs->trans("Fax"),$_SERVER["PHP_SELF"],"p.fax", $begin, $param, '', $sortfield,$sortorder);
  244. }
  245. else
  246. {
  247. print_liste_field_titre($langs->trans("Phone"),$_SERVER["PHP_SELF"],"p.phone", $begin, $param, '', $sortfield,$sortorder);
  248. print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"p.email", $begin, $param, '', $sortfield,$sortorder);
  249. }
  250. print_liste_field_titre($langs->trans("DateModificationShort"),$_SERVER["PHP_SELF"],"p.tms", $begin, $param, 'align="center"', $sortfield,$sortorder);
  251. print_liste_field_titre($langs->trans("ContactVisibility"),$_SERVER["PHP_SELF"],"p.priv", $begin, $param, 'align="center"', $sortfield,$sortorder);
  252. print '<td class="liste_titre">&nbsp;</td>';
  253. print "</tr>\n";
  254. // Ligne des champs de filtres
  255. print '<tr class="liste_titre">';
  256. print '<td class="liste_titre">';
  257. print '<input class="flat" type="text" name="search_nom" size="9" value="'.$search_nom.'">';
  258. print '</td>';
  259. print '<td class="liste_titre">';
  260. print '<input class="flat" type="text" name="search_prenom" size="9" value="'.$search_prenom.'">';
  261. print '</td>';
  262. print '<td class="liste_titre">';
  263. print '<input class="flat" type="text" name="search_poste" size="9" value="'.$search_poste.'">';
  264. print '</td>';
  265. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  266. {
  267. print '<td class="liste_titre">';
  268. print '<input class="flat" type="text" name="search_societe" size="9" value="'.$search_societe.'">';
  269. print '</td>';
  270. }
  271. if ($view == 'phone')
  272. {
  273. print '<td class="liste_titre">';
  274. print '<input class="flat" type="text" name="search_phonepro" size="9" value="'.$search_phonepro.'">';
  275. print '</td>';
  276. print '<td class="liste_titre">';
  277. print '<input class="flat" type="text" name="search_phonemob" size="9" value="'.$search_phonemob.'">';
  278. print '</td>';
  279. print '<td class="liste_titre">';
  280. print '<input class="flat" type="text" name="search_fax" size="9" value="'.$search_fax.'">';
  281. print '</td>';
  282. }
  283. else
  284. {
  285. print '<td class="liste_titre">';
  286. print '<input class="flat" type="text" name="search_phone" size="9" value="'.$search_phone.'">';
  287. print '</td>';
  288. print '<td class="liste_titre">';
  289. print '<input class="flat" type="text" name="search_email" size="9" value="'.$search_email.'">';
  290. print '</td>';
  291. }
  292. print '<td class="liste_titre">&nbsp;</td>';
  293. print '<td class="liste_titre" align="center">';
  294. $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
  295. print $form->selectarray('search_priv',$selectarray,$search_priv,1);
  296. print '</td>';
  297. print '<td class="liste_titre" align="right">';
  298. print '<input type="image" value="button_search" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  299. print '&nbsp; ';
  300. print '<input type="image" value="button_removefilter" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  301. print '</td>';
  302. print '</tr>';
  303. $var=True;
  304. while ($i < min($num,$limit))
  305. {
  306. $obj = $db->fetch_object($result);
  307. $var=!$var;
  308. print "<tr $bc[$var]>";
  309. // Name
  310. print '<td valign="middle">';
  311. $contactstatic->name=$obj->name;
  312. $contactstatic->firstname='';
  313. $contactstatic->id=$obj->cidp;
  314. print $contactstatic->getNomUrl(1,'',20);
  315. print '</td>';
  316. // Firstname
  317. print '<td>'.dol_trunc($obj->firstname,20).'</td>';
  318. // Function
  319. print '<td>'.dol_trunc($obj->poste,20).'</td>';
  320. // Company
  321. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  322. {
  323. print '<td>';
  324. if ($obj->socid)
  325. {
  326. print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">';
  327. print img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->nom,20).'</a>';
  328. }
  329. else
  330. {
  331. print '&nbsp;';
  332. }
  333. print '</td>';
  334. }
  335. if ($view == 'phone')
  336. {
  337. // Phone
  338. print '<td>'.dol_print_phone($obj->phone,$obj->pays_code,$obj->cidp,$obj->socid,'AC_TEL').'</td>';
  339. // Phone mobile
  340. print '<td>'.dol_print_phone($obj->phone_mobile,$obj->pays_code,$obj->cidp,$obj->socid,'AC_TEL').'</td>';
  341. // Fax
  342. print '<td>'.dol_print_phone($obj->fax,$obj->pays_code,$obj->cidp,$obj->socid,'AC_TEL').'</td>';
  343. }
  344. else
  345. {
  346. // Phone
  347. print '<td>'.dol_print_phone($obj->phone,$obj->pays_code,$obj->cidp,$obj->socid,'AC_TEL').'</td>';
  348. // EMail
  349. print '<td>'.dol_print_email($obj->email,$obj->cidp,$obj->socid,'AC_EMAIL',18).'</td>';
  350. }
  351. // Date
  352. print '<td align="center">'.dol_print_date($db->jdate($obj->tms),"day").'</td>';
  353. // Private/Public
  354. print '<td align="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
  355. // Links Add action and Export vcard
  356. print '<td align="right">';
  357. print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;backtopage=1&amp;contactid='.$obj->cidp.'&amp;socid='.$obj->socid.'">'.img_object($langs->trans("AddAction"),"action").'</a>';
  358. print ' &nbsp; ';
  359. print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$obj->cidp.'">';
  360. print img_picto($langs->trans("VCard"),'vcard.png').' ';
  361. print '</a></td>';
  362. print "</tr>\n";
  363. $i++;
  364. }
  365. print "</table>";
  366. print '</form>';
  367. if ($num > $limit) print_barre_liste('', $page, $_SERVER["PHP_SELF"], '&amp;begin='.$begin.'&amp;view='.$view.'&amp;userid='.$_GET["userid"], $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
  368. $db->free($result);
  369. }
  370. else
  371. {
  372. dol_print_error($db);
  373. }
  374. print '<br>';
  375. $db->close();
  376. llxFooter();
  377. ?>