list.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  9. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/contact/list.php
  26. * \ingroup societe
  27. * \brief Page to list all contacts
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. $langs->loadLangs(array("companies", "suppliers"));
  33. $action=GETPOST('action','alpha');
  34. $massaction=GETPOST('massaction','alpha');
  35. $show_files=GETPOST('show_files','int');
  36. $confirm=GETPOST('confirm','alpha');
  37. $toselect = GETPOST('toselect', 'array');
  38. // Security check
  39. $id = GETPOST('id','int');
  40. $contactid = GETPOST('id','int');
  41. $ref = ''; // There is no ref for contacts
  42. if ($user->societe_id) $socid=$user->societe_id;
  43. $result = restrictedArea($user, 'contact', $contactid,'');
  44. $sall=GETPOST('sall', 'alphanohtml');
  45. $search_firstlast_only=GETPOST("search_firstlast_only");
  46. $search_lastname=GETPOST("search_lastname");
  47. $search_firstname=GETPOST("search_firstname");
  48. $search_societe=GETPOST("search_societe");
  49. $search_poste=GETPOST("search_poste");
  50. $search_phone=GETPOST("search_phone");
  51. $search_phone_perso=GETPOST("search_phone_perso");
  52. $search_phone_pro=GETPOST("search_phone_pro");
  53. $search_phone_mobile=GETPOST("search_phone_mobile");
  54. $search_fax=GETPOST("search_fax");
  55. $search_email=GETPOST("search_email");
  56. $search_skype=GETPOST("search_skype");
  57. $search_priv=GETPOST("search_priv");
  58. $search_categ=GETPOST("search_categ",'int');
  59. $search_categ_thirdparty=GETPOST("search_categ_thirdparty",'int');
  60. $search_categ_supplier=GETPOST("search_categ_supplier",'int');
  61. $search_status=GETPOST("search_status",'int');
  62. $search_type=GETPOST('search_type','alpha');
  63. if ($search_status=='') $search_status=1; // always display activ customer first
  64. $optioncss = GETPOST('optioncss','alpha');
  65. $type=GETPOST("type");
  66. $view=GETPOST("view");
  67. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  68. $sortfield = GETPOST('sortfield', 'alpha');
  69. $sortorder = GETPOST('sortorder', 'alpha');
  70. $page = GETPOST('page', 'int');
  71. $userid=GETPOST('userid','int');
  72. $begin=GETPOST('begin');
  73. if (! $sortorder) $sortorder="ASC";
  74. if (! $sortfield) $sortfield="p.lastname";
  75. if (empty($page) || $page < 0) { $page = 0; }
  76. $offset = $limit * $page;
  77. $langs->load("companies");
  78. $contextpage='contactlist';
  79. $titre = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  80. if ($type == "p")
  81. {
  82. $contextpage='contactprospectlist';
  83. $titre.=' ('.$langs->trans("ThirdPartyProspects").')';
  84. $urlfiche="card.php";
  85. }
  86. if ($type == "c")
  87. {
  88. $contextpage='contactcustomerlist';
  89. $titre.=' ('.$langs->trans("ThirdPartyCustomers").')';
  90. $urlfiche="card.php";
  91. }
  92. else if ($type == "f")
  93. {
  94. $contextpage='contactsupplierlist';
  95. $titre.=' ('.$langs->trans("ThirdPartySuppliers").')';
  96. $urlfiche="card.php";
  97. }
  98. else if ($type == "o")
  99. {
  100. $contextpage='contactotherlist';
  101. $titre.=' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
  102. $urlfiche="";
  103. }
  104. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  105. $hookmanager->initHooks(array($contextpage));
  106. $extrafields = new ExtraFields($db);
  107. // fetch optionals attributes and labels
  108. $extralabels = $extrafields->fetch_name_optionals_label('contact');
  109. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  110. // List of fields to search into when doing a "search in all"
  111. $fieldstosearchall = array(
  112. 'p.lastname'=>'Lastname',
  113. 'p.firstname'=>'Firstname',
  114. 'p.email'=>'EMail',
  115. 's.nom'=>"ThirdParty",
  116. );
  117. // Definition of fields for list
  118. $arrayfields=array(
  119. 'p.lastname'=>array('label'=>$langs->trans("Lastname"), 'checked'=>1),
  120. 'p.firstname'=>array('label'=>$langs->trans("Firstname"), 'checked'=>1),
  121. 'p.poste'=>array('label'=>$langs->trans("PostOrFunction"), 'checked'=>1),
  122. 'p.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),
  123. 'p.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),
  124. 'p.phone'=>array('label'=>$langs->trans("Phone"), 'checked'=>1),
  125. 'p.phone_perso'=>array('label'=>$langs->trans("PhonePerso"), 'checked'=>0),
  126. 'p.phone_mobile'=>array('label'=>$langs->trans("PhoneMobile"), 'checked'=>1),
  127. 'p.fax'=>array('label'=>$langs->trans("Fax"), 'checked'=>1),
  128. 'p.email'=>array('label'=>$langs->trans("EMail"), 'checked'=>1),
  129. 'p.skype'=>array('label'=>$langs->trans("Skype"), 'checked'=>1, 'enabled'=>(! empty($conf->skype->enabled))),
  130. 'p.thirdparty'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'enabled'=>empty($conf->global->SOCIETE_DISABLE_CONTACTS)),
  131. 'p.priv'=>array('label'=>$langs->trans("ContactVisibility"), 'checked'=>1, 'position'=>200),
  132. 'p.datec'=>array('label'=>$langs->trans("DateCreationShort"), 'checked'=>0, 'position'=>500),
  133. 'p.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  134. 'p.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  135. );
  136. // Extra fields
  137. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  138. {
  139. foreach($extrafields->attribute_label as $key => $val)
  140. {
  141. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  142. }
  143. }
  144. $object=new Contact($db);
  145. if (($id > 0 || ! empty($ref)) && $action != 'add')
  146. {
  147. $result=$object->fetch($id,$ref);
  148. if ($result < 0) dol_print_error($db);
  149. }
  150. /*
  151. * Actions
  152. */
  153. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  154. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  155. $parameters=array();
  156. $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  157. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  158. if (empty($reshook))
  159. {
  160. // Selection of new fields
  161. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  162. // Did we click on purge search criteria ?
  163. if (GETPOST('button_removefilter_x') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter')) // All tests are required to be compatible with all browsers
  164. {
  165. $sall="";
  166. $search_firstlast_only="";
  167. $search_lastname="";
  168. $search_firstname="";
  169. $search_societe="";
  170. $search_poste="";
  171. $search_phone="";
  172. $search_phone_perso="";
  173. $search_phone_pro="";
  174. $search_phone_mobile="";
  175. $search_fax="";
  176. $search_email="";
  177. $search_skype="";
  178. $search_priv="";
  179. $search_status=-1;
  180. $search_categ='';
  181. $search_categ_thirdparty='';
  182. $search_categ_supplier='';
  183. $toselect='';
  184. $search_array_options=array();
  185. }
  186. // Mass actions
  187. $objectclass='Contact';
  188. $objectlabel='Contact';
  189. $permtoread = $user->rights->societe->lire;
  190. $permtodelete = $user->rights->societe->supprimer;
  191. $uploaddir = $conf->societe->dir_output;
  192. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  193. }
  194. if ($search_priv < 0) $search_priv='';
  195. /*
  196. * View
  197. */
  198. $form=new Form($db);
  199. $formother=new FormOther($db);
  200. $contactstatic=new Contact($db);
  201. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  202. $sql = "SELECT s.rowid as socid, s.nom as name,";
  203. $sql.= " p.rowid, p.lastname as lastname, p.statut, p.firstname, p.zip, p.town, p.poste, p.email, p.skype,";
  204. $sql.= " p.phone as phone_pro, p.phone_mobile, p.phone_perso, p.fax, p.fk_pays, p.priv, p.datec as date_creation, p.tms as date_update,";
  205. $sql.= " co.code as country_code";
  206. // Add fields from extrafields
  207. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  208. // Add fields from hooks
  209. $parameters=array();
  210. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  211. $sql.=$hookmanager->resPrint;
  212. $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  213. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (p.rowid = ef.fk_object)";
  214. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays";
  215. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  216. if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cc ON p.rowid = cc.fk_socpeople"; // We need this table joined to the select in order to filter by categ
  217. if (! empty($search_categ_thirdparty)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; // We need this table joined to the select in order to filter by categ
  218. if (! empty($search_categ_supplier)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs2 ON s.rowid = cs2.fk_soc"; // We need this table joined to the select in order to filter by categ
  219. if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  220. $sql.= ' WHERE p.entity IN ('.getEntity('societe', 1).')';
  221. if (!$user->rights->societe->client->voir && !$socid) //restriction
  222. {
  223. $sql .= " AND (sc.fk_user = " .$user->id." OR p.fk_soc IS NULL)";
  224. }
  225. if (! empty($userid)) // propre au commercial
  226. {
  227. $sql .= " AND p.fk_user_creat=".$db->escape($userid);
  228. }
  229. // Filter to exclude not owned private contacts
  230. if ($search_priv != '0' && $search_priv != '1')
  231. {
  232. $sql .= " AND (p.priv='0' OR (p.priv='1' AND p.fk_user_creat=".$user->id."))";
  233. }
  234. else
  235. {
  236. if ($search_priv == '0') $sql .= " AND p.priv='0'";
  237. if ($search_priv == '1') $sql .= " AND (p.priv='1' AND p.fk_user_creat=".$user->id.")";
  238. }
  239. if ($search_categ > 0) $sql.= " AND cc.fk_categorie = ".$db->escape($search_categ);
  240. if ($search_categ == -2) $sql.= " AND cc.fk_categorie IS NULL";
  241. if ($search_categ_thirdparty > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ_thirdparty);
  242. if ($search_categ_thirdparty == -2) $sql.= " AND cs.fk_categorie IS NULL";
  243. if ($search_categ_supplier > 0) $sql.= " AND cs2.fk_categorie = ".$db->escape($search_categ_supplier);
  244. if ($search_categ_supplier == -2) $sql.= " AND cs2.fk_categorie IS NULL";
  245. if ($search_firstlast_only) {
  246. $sql .= natural_search(array('p.lastname','p.firstname'), $search_firstlast_only);
  247. }
  248. if ($search_lastname) { // filter on lastname
  249. $sql .= natural_search('p.lastname', $search_lastname);
  250. }
  251. if ($search_firstname) { // filter on firstname
  252. $sql .= natural_search('p.firstname', $search_firstname);
  253. }
  254. if ($search_societe) { // filtre sur la societe
  255. $sql .= natural_search('s.nom', $search_societe);
  256. }
  257. if (strlen($search_poste)) { // filtre sur la societe
  258. $sql .= natural_search('p.poste', $search_poste);
  259. }
  260. if (strlen($search_phone))
  261. {
  262. $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)."%')";
  263. }
  264. if (strlen($search_phone_perso))
  265. {
  266. $sql .= " AND p.phone_perso LIKE '%".$db->escape($search_phone_perso)."%'";
  267. }
  268. if (strlen($search_phone_pro))
  269. {
  270. $sql .= " AND p.phone LIKE '%".$db->escape($search_phone_pro)."%'";
  271. }
  272. if (strlen($search_phone_mobile))
  273. {
  274. $sql .= " AND p.phone_mobile LIKE '%".$db->escape($search_phone_mobile)."%'";
  275. }
  276. if (strlen($search_fax))
  277. {
  278. $sql .= " AND p.fax LIKE '%".$db->escape($search_fax)."%'";
  279. }
  280. if (strlen($search_email)) // filtre sur l'email
  281. {
  282. $sql .= " AND p.email LIKE '%".$db->escape($search_email)."%'";
  283. }
  284. if (strlen($search_skype)) // filtre sur skype
  285. {
  286. $sql .= " AND p.skype LIKE '%".$db->escape($search_skype)."%'";
  287. }
  288. if ($search_status != '' && $search_status >= 0) $sql .= " AND p.statut = ".$db->escape($search_status);
  289. if ($type == "o") // filtre sur type
  290. {
  291. $sql .= " AND p.fk_soc IS NULL";
  292. }
  293. else if ($type == "f") // filtre sur type
  294. {
  295. $sql .= " AND s.fournisseur = 1";
  296. }
  297. else if ($type == "c") // filtre sur type
  298. {
  299. $sql .= " AND s.client IN (1, 3)";
  300. }
  301. else if ($type == "p") // filtre sur type
  302. {
  303. $sql .= " AND s.client IN (2, 3)";
  304. }
  305. if ($sall)
  306. {
  307. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  308. }
  309. if (! empty($socid))
  310. {
  311. $sql .= " AND s.rowid = ".$socid;
  312. }
  313. // Add where from extra fields
  314. foreach ($search_array_options as $key => $val)
  315. {
  316. $crit=$val;
  317. $tmpkey=preg_replace('/search_options_/','',$key);
  318. $typ=$extrafields->attribute_type[$tmpkey];
  319. $mode=0;
  320. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  321. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  322. {
  323. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  324. }
  325. }
  326. // Add where from hooks
  327. $parameters=array();
  328. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  329. $sql.=$hookmanager->resPrint;
  330. // Add order
  331. if ($view == "recent")
  332. {
  333. $sql.= $db->order("p.datec","DESC");
  334. }
  335. else
  336. {
  337. $sql.= $db->order($sortfield,$sortorder);
  338. }
  339. // Count total nb of records
  340. $nbtotalofrecords = '';
  341. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  342. {
  343. $result = $db->query($sql);
  344. $nbtotalofrecords = $db->num_rows($result);
  345. }
  346. $sql.= $db->plimit($limit+1, $offset);
  347. $result = $db->query($sql);
  348. if (! $result)
  349. {
  350. dol_print_error($db);
  351. exit;
  352. }
  353. $num = $db->num_rows($result);
  354. $arrayofselected=is_array($toselect)?$toselect:array();
  355. if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
  356. {
  357. $obj = $db->fetch_object($resql);
  358. $id = $obj->rowid;
  359. header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
  360. exit;
  361. }
  362. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
  363. llxHeader('',$title,$help_url);
  364. $param='';
  365. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  366. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  367. $param.='&begin='.urlencode($begin).'&view='.urlencode($view).'&userid='.urlencode($userid).'&contactname='.urlencode($sall);
  368. $param.='&type='.urlencode($type).'&view='.urlencode($view);
  369. if (!empty($search_categ)) $param.='&search_categ='.urlencode($search_categ);
  370. if (!empty($search_categ_thirdparty)) $param.='&search_categ_thirdparty='.urlencode($search_categ_thirdparty);
  371. if (!empty($search_categ_supplier)) $param.='&search_categ_supplier='.urlencode($search_categ_supplier);
  372. if ($sall != '') $param.='&amp;sall='.urlencode($sall);
  373. if ($search_lastname != '') $param.='&amp;search_lastname='.urlencode($search_lastname);
  374. if ($search_firstname != '') $param.='&amp;search_firstname='.urlencode($search_firstname);
  375. if ($search_societe != '') $param.='&amp;search_societe='.urlencode($search_societe);
  376. if ($search_zip != '') $param.='&amp;search_zip='.urlencode($search_zip);
  377. if ($search_town != '') $param.='&amp;search_town='.urlencode($search_town);
  378. if ($search_job != '') $param.='&amp;search_job='.urlencode($search_job);
  379. if ($search_phone_pro != '') $param.='&amp;search_phone_pro='.urlencode($search_phone_pro);
  380. if ($search_phone_perso != '') $param.='&amp;search_phone_perso='.urlencode($search_phone_perso);
  381. if ($search_phone_mobile != '') $param.='&amp;search_phone_mobile='.urlencode($search_phone_mobile);
  382. if ($search_fax != '') $param.='&amp;search_fax='.urlencode($search_fax);
  383. if ($search_email != '') $param.='&amp;search_email='.urlencode($search_email);
  384. if ($search_status != '') $param.='&amp;search_status='.urlencode($search_status);
  385. if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".urlencode($search_priv);
  386. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  387. // Add $param from extra fields
  388. foreach ($search_array_options as $key => $val)
  389. {
  390. $crit=$val;
  391. $tmpkey=preg_replace('/search_options_/','',$key);
  392. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  393. }
  394. // List of mass actions available
  395. $arrayofmassactions = array(
  396. // 'presend'=>$langs->trans("SendByMail"),
  397. // 'builddoc'=>$langs->trans("PDFMerge"),
  398. );
  399. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  400. if ($user->rights->societe->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
  401. if ($massaction == 'presend') $arrayofmassactions=array();
  402. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  403. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  404. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  405. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  406. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  407. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  408. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  409. print '<input type="hidden" name="page" value="'.$page.'">';
  410. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  411. print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies.png', 0, '', '', $limit);
  412. if ($sall)
  413. {
  414. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  415. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  416. }
  417. if ($search_firstlast_only)
  418. {
  419. print $langs->trans("FilterOnInto", $search_firstlast_only) . $langs->trans("Lastname").", ".$langs->trans("Firstname");
  420. }
  421. $moreforfilter='';
  422. if (! empty($conf->categorie->enabled))
  423. {
  424. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  425. $moreforfilter.='<div class="divsearchfield">';
  426. $moreforfilter.=$langs->trans('Categories'). ': ';
  427. $moreforfilter.=$formother->select_categories(Categorie::TYPE_CONTACT,$search_categ,'search_categ',1);
  428. $moreforfilter.='</div>';
  429. if (empty($type) || $type == 'c' || $type == 'p')
  430. {
  431. $moreforfilter.='<div class="divsearchfield">';
  432. if ($type == 'c') $moreforfilter.=$langs->trans('CustomersCategoriesShort'). ': ';
  433. else if ($type == 'p') $moreforfilter.=$langs->trans('ProspectsCategoriesShort'). ': ';
  434. else $moreforfilter.=$langs->trans('CustomersProspectsCategoriesShort'). ': ';
  435. $moreforfilter.=$formother->select_categories(Categorie::TYPE_CUSTOMER,$search_categ_thirdparty,'search_categ_thirdparty',1);
  436. $moreforfilter.='</div>';
  437. }
  438. if (empty($type) || $type == 'f')
  439. {
  440. $moreforfilter.='<div class="divsearchfield">';
  441. $moreforfilter.=$langs->trans('SuppliersCategoriesShort'). ': ';
  442. $moreforfilter.=$formother->select_categories(Categorie::TYPE_SUPPLIER,$search_categ_supplier,'search_categ_supplier',1);
  443. $moreforfilter.='</div>';
  444. }
  445. }
  446. if ($moreforfilter)
  447. {
  448. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  449. print $moreforfilter;
  450. $parameters=array('type'=>$type);
  451. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  452. print $hookmanager->resPrint;
  453. print '</div>';
  454. }
  455. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  456. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  457. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  458. print '<div class="div-table-responsive">';
  459. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  460. // Lines for filter fields
  461. print '<tr class="liste_titre_filter">';
  462. if (! empty($arrayfields['p.lastname']['checked']))
  463. {
  464. print '<td class="liste_titre">';
  465. print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
  466. print '</td>';
  467. }
  468. if (! empty($arrayfields['p.firstname']['checked']))
  469. {
  470. print '<td class="liste_titre">';
  471. print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
  472. print '</td>';
  473. }
  474. if (! empty($arrayfields['p.poste']['checked']))
  475. {
  476. print '<td class="liste_titre">';
  477. print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
  478. print '</td>';
  479. }
  480. if (! empty($arrayfields['p.zip']['checked']))
  481. {
  482. print '<td class="liste_titre">';
  483. print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
  484. print '</td>';
  485. }
  486. if (! empty($arrayfields['p.town']['checked']))
  487. {
  488. print '<td class="liste_titre">';
  489. print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
  490. print '</td>';
  491. }
  492. if (! empty($arrayfields['p.phone']['checked']))
  493. {
  494. print '<td class="liste_titre">';
  495. print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
  496. print '</td>';
  497. }
  498. if (! empty($arrayfields['p.phone_perso']['checked']))
  499. {
  500. print '<td class="liste_titre">';
  501. print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
  502. print '</td>';
  503. }
  504. if (! empty($arrayfields['p.phone_mobile']['checked']))
  505. {
  506. print '<td class="liste_titre">';
  507. print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
  508. print '</td>';
  509. }
  510. if (! empty($arrayfields['p.fax']['checked']))
  511. {
  512. print '<td class="liste_titre">';
  513. print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
  514. print '</td>';
  515. }
  516. if (! empty($arrayfields['p.email']['checked']))
  517. {
  518. print '<td class="liste_titre">';
  519. print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
  520. print '</td>';
  521. }
  522. if (! empty($arrayfields['p.skype']['checked']))
  523. {
  524. print '<td class="liste_titre">';
  525. print '<input class="flat" type="text" name="search_skype" size="6" value="'.dol_escape_htmltag($search_skype).'">';
  526. print '</td>';
  527. }
  528. if (! empty($arrayfields['p.thirdparty']['checked']))
  529. {
  530. print '<td class="liste_titre">';
  531. print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  532. print '</td>';
  533. }
  534. if (! empty($arrayfields['p.priv']['checked']))
  535. {
  536. print '<td class="liste_titre" align="center">';
  537. $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
  538. print $form->selectarray('search_priv',$selectarray,$search_priv,1);
  539. print '</td>';
  540. }
  541. // Extra fields
  542. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  543. {
  544. foreach($extrafields->attribute_label as $key => $val)
  545. {
  546. if (! empty($arrayfields["ef.".$key]['checked']))
  547. {
  548. $align=$extrafields->getAlignFlag($key);
  549. $typeofextrafield=$extrafields->attribute_type[$key];
  550. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  551. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
  552. {
  553. $crit=$val;
  554. $tmpkey=preg_replace('/search_options_/','',$key);
  555. $searchclass='';
  556. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  557. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  558. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  559. }
  560. print '</td>';
  561. }
  562. }
  563. }
  564. // Fields from hook
  565. $parameters=array('arrayfields'=>$arrayfields);
  566. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  567. print $hookmanager->resPrint;
  568. // Date creation
  569. if (! empty($arrayfields['p.datec']['checked']))
  570. {
  571. print '<td class="liste_titre">';
  572. print '</td>';
  573. }
  574. // Date modification
  575. if (! empty($arrayfields['p.tms']['checked']))
  576. {
  577. print '<td class="liste_titre">';
  578. print '</td>';
  579. }
  580. // Status
  581. if (! empty($arrayfields['p.statut']['checked']))
  582. {
  583. print '<td class="liste_titre" align="center">';
  584. print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),$search_status);
  585. print '</td>';
  586. }
  587. // Action column
  588. print '<td class="liste_titre" align="right">';
  589. $searchpicto=$form->showFilterButtons();
  590. print $searchpicto;
  591. print '</td>';
  592. print '</tr>';
  593. // Ligne des titres
  594. print '<tr class="liste_titre">';
  595. if (! empty($arrayfields['p.lastname']['checked'])) print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"p.lastname", $begin, $param, '', $sortfield,$sortorder);
  596. if (! empty($arrayfields['p.firstname']['checked'])) print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"p.firstname", $begin, $param, '', $sortfield,$sortorder);
  597. if (! empty($arrayfields['p.zip']['checked'])) print_liste_field_titre($langs->trans("Zip"),$_SERVER["PHP_SELF"],"p.zip", $begin, $param, '', $sortfield,$sortorder);
  598. if (! empty($arrayfields['p.town']['checked'])) print_liste_field_titre($langs->trans("Town"),$_SERVER["PHP_SELF"],"p.town", $begin, $param, '', $sortfield,$sortorder);
  599. if (! empty($arrayfields['p.poste']['checked'])) print_liste_field_titre($langs->trans("PostOrFunction"),$_SERVER["PHP_SELF"],"p.poste", $begin, $param, '', $sortfield,$sortorder);
  600. if (! empty($arrayfields['p.phone']['checked'])) print_liste_field_titre($langs->trans("Phone"),$_SERVER["PHP_SELF"],"p.phone", $begin, $param, '', $sortfield,$sortorder);
  601. if (! empty($arrayfields['p.phone_perso']['checked'])) print_liste_field_titre($langs->trans("PhonePerso"),$_SERVER["PHP_SELF"],"p.phone_perso", $begin, $param, '', $sortfield,$sortorder);
  602. if (! empty($arrayfields['p.phone_mobile']['checked'])) print_liste_field_titre($langs->trans("PhoneMobile"),$_SERVER["PHP_SELF"],"p.phone_mobile", $begin, $param, '', $sortfield,$sortorder);
  603. if (! empty($arrayfields['p.fax']['checked'])) print_liste_field_titre($langs->trans("Fax"),$_SERVER["PHP_SELF"],"p.fax", $begin, $param, '', $sortfield,$sortorder);
  604. if (! empty($arrayfields['p.email']['checked'])) print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"p.email", $begin, $param, '', $sortfield,$sortorder);
  605. if (! empty($arrayfields['p.skype']['checked'])) print_liste_field_titre($langs->trans("Skype"),$_SERVER["PHP_SELF"],"p.skype", $begin, $param, '', $sortfield,$sortorder);
  606. if (! empty($arrayfields['p.thirdparty']['checked'])) print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom", $begin, $param, '', $sortfield,$sortorder);
  607. if (! empty($arrayfields['p.priv']['checked'])) print_liste_field_titre($langs->trans("ContactVisibility"),$_SERVER["PHP_SELF"],"p.priv", $begin, $param, 'align="center"', $sortfield,$sortorder);
  608. // Extra fields
  609. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  610. {
  611. foreach($extrafields->attribute_label as $key => $val)
  612. {
  613. if (! empty($arrayfields["ef.".$key]['checked']))
  614. {
  615. $align=$extrafields->getAlignFlag($key);
  616. $sortonfield = "ef.".$key;
  617. if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
  618. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  619. }
  620. }
  621. }
  622. // Hook fields
  623. $parameters=array('arrayfields'=>$arrayfields);
  624. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  625. print $hookmanager->resPrint;
  626. if (! empty($arrayfields['p.datec']['checked'])) print_liste_field_titre($langs->trans("DateCreationShort"),$_SERVER["PHP_SELF"],"p.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  627. if (! empty($arrayfields['p.tms']['checked'])) print_liste_field_titre($langs->trans("DateModificationShort"),$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  628. if (! empty($arrayfields['p.statut']['checked'])) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$param,'align="center"',$sortfield,$sortorder);
  629. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  630. print "</tr>\n";
  631. $i = 0;
  632. while ($i < min($num,$limit))
  633. {
  634. $obj = $db->fetch_object($result);
  635. print '<tr class="oddeven">';
  636. $contactstatic->lastname=$obj->lastname;
  637. $contactstatic->firstname='';
  638. $contactstatic->id=$obj->rowid;
  639. $contactstatic->statut=$obj->statut;
  640. $contactstatic->poste=$obj->poste;
  641. $contactstatic->email=$obj->email;
  642. $contactstatic->phone_pro=$obj->phone_pro;
  643. $contactstatic->phone_perso=$obj->phone_perso;
  644. $contactstatic->phone_mobile=$obj->phone_mobile;
  645. $contactstatic->zip=$obj->zip;
  646. $contactstatic->town=$obj->town;
  647. // Name
  648. if (! empty($arrayfields['p.lastname']['checked']))
  649. {
  650. print '<td valign="middle">';
  651. print $contactstatic->getNomUrl(1,'',0);
  652. print '</td>';
  653. }
  654. // Firstname
  655. if (! empty($arrayfields['p.firstname']['checked']))
  656. {
  657. print '<td>'.$obj->firstname.'</td>';
  658. }
  659. // Zip
  660. if (! empty($arrayfields['p.zip']['checked']))
  661. {
  662. print '<td>'.$obj->zip.'</td>';
  663. }
  664. // Town
  665. if (! empty($arrayfields['p.town']['checked']))
  666. {
  667. print '<td>'.$obj->town.'</td>';
  668. }
  669. // Function
  670. if (! empty($arrayfields['p.poste']['checked']))
  671. {
  672. print '<td>'.dol_trunc($obj->poste,20).'</td>';
  673. }
  674. // Phone
  675. if (! empty($arrayfields['p.phone']['checked']))
  676. {
  677. print '<td>'.dol_print_phone($obj->phone_pro,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
  678. }
  679. // Phone perso
  680. if (! empty($arrayfields['p.phone_perso']['checked']))
  681. {
  682. print '<td>'.dol_print_phone($obj->phone_perso,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
  683. }
  684. // Phone mobile
  685. if (! empty($arrayfields['p.phone_mobile']['checked']))
  686. {
  687. print '<td>'.dol_print_phone($obj->phone_mobile,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
  688. }
  689. // Fax
  690. if (! empty($arrayfields['p.fax']['checked']))
  691. {
  692. print '<td>'.dol_print_phone($obj->fax,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
  693. }
  694. // EMail
  695. if (! empty($arrayfields['p.email']['checked']))
  696. {
  697. print '<td>'.dol_print_email($obj->email,$obj->rowid,$obj->socid,'AC_EMAIL',18).'</td>';
  698. }
  699. // Skype
  700. if (! empty($arrayfields['p.skype']['checked']))
  701. {
  702. if (! empty($conf->skype->enabled)) { print '<td>'.dol_print_skype($obj->skype,$obj->rowid,$obj->socid,'AC_SKYPE',18).'</td>'; }
  703. }
  704. // Company
  705. if (! empty($arrayfields['p.thirdparty']['checked']))
  706. {
  707. print '<td>';
  708. if ($obj->socid)
  709. {
  710. $objsoc = new Societe($db);
  711. $objsoc->fetch($obj->socid);
  712. print $objsoc->getNomUrl(1);
  713. }
  714. else
  715. print '&nbsp;';
  716. print '</td>';
  717. }
  718. // Private/Public
  719. if (! empty($arrayfields['p.priv']['checked']))
  720. {
  721. print '<td align="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
  722. }
  723. // Extra fields
  724. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  725. {
  726. foreach($extrafields->attribute_label as $key => $val)
  727. {
  728. if (! empty($arrayfields["ef.".$key]['checked']))
  729. {
  730. print '<td';
  731. $align=$extrafields->getAlignFlag($key);
  732. if ($align) print ' align="'.$align.'"';
  733. print '>';
  734. $tmpkey='options_'.$key;
  735. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  736. print '</td>';
  737. }
  738. }
  739. }
  740. // Fields from hook
  741. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  742. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  743. print $hookmanager->resPrint;
  744. // Date creation
  745. if (! empty($arrayfields['p.datec']['checked']))
  746. {
  747. print '<td align="center">';
  748. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  749. print '</td>';
  750. }
  751. // Date modification
  752. if (! empty($arrayfields['p.tms']['checked']))
  753. {
  754. print '<td align="center">';
  755. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  756. print '</td>';
  757. }
  758. // Status
  759. if (! empty($arrayfields['p.statut']['checked']))
  760. {
  761. print '<td align="center">'.$contactstatic->getLibStatut(3).'</td>';
  762. }
  763. // Action column
  764. print '<td class="nowrap" align="center">';
  765. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  766. {
  767. $selected=0;
  768. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  769. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  770. }
  771. print '</td>';
  772. if (! $i) $totalarray['nbfield']++;
  773. print "</tr>\n";
  774. $i++;
  775. }
  776. $db->free($result);
  777. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  778. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  779. print $hookmanager->resPrint;
  780. print "</table>";
  781. print "</div>";
  782. //if ($num > $limit || $page) print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies.png', 0, '', '', $limit, 1);
  783. print '</form>';
  784. llxFooter();
  785. $db->close();