list.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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@inodbox.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@open-dsi.fr>
  9. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  10. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  11. * Copyright (C) 2018 Juanjo Menent <jmenent@2byte.es>
  12. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  13. * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
  14. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/contact/list.php
  31. * \ingroup societe
  32. * \brief Page to list all contacts
  33. */
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("companies", "suppliers", "categories"));
  41. $socialnetworks = getArrayOfSocialNetworks();
  42. $action = GETPOST('action', 'aZ09');
  43. $massaction = GETPOST('massaction', 'alpha');
  44. $show_files = GETPOST('show_files', 'int');
  45. $confirm = GETPOST('confirm', 'alpha');
  46. $toselect = GETPOST('toselect', 'array');
  47. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contactlist';
  48. // Security check
  49. $id = GETPOST('id', 'int');
  50. $contactid = GETPOST('id', 'int');
  51. $ref = ''; // There is no ref for contacts
  52. if ($user->socid) {
  53. $socid = $user->socid;
  54. }
  55. $result = restrictedArea($user, 'contact', $contactid, '');
  56. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  57. $search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
  58. $search_phone = GETPOST("search_phone", 'alpha');
  59. $search_id = GETPOST("search_id", "int");
  60. $search_firstlast_only = GETPOST("search_firstlast_only", 'alpha');
  61. $search_lastname = GETPOST("search_lastname", 'alpha');
  62. $search_firstname = GETPOST("search_firstname", 'alpha');
  63. $search_societe = GETPOST("search_societe", 'alpha');
  64. $search_poste = GETPOST("search_poste", 'alpha');
  65. $search_phone_perso = GETPOST("search_phone_perso", 'alpha');
  66. $search_phone_pro = GETPOST("search_phone_pro", 'alpha');
  67. $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha');
  68. $search_fax = GETPOST("search_fax", 'alpha');
  69. $search_email = GETPOST("search_email", 'alpha');
  70. $search_no_email = GETPOST("search_no_email", 'int');
  71. if (!empty($conf->socialnetworks->enabled)) {
  72. foreach ($socialnetworks as $key => $value) {
  73. if ($value['active']) {
  74. $search_[$key] = GETPOST("search_".$key, 'alpha');
  75. }
  76. }
  77. }
  78. $search_priv = GETPOST("search_priv", 'alpha');
  79. $search_categ = GETPOST("search_categ", 'int');
  80. $search_categ_thirdparty = GETPOST("search_categ_thirdparty", 'int');
  81. $search_categ_supplier = GETPOST("search_categ_supplier", 'int');
  82. $search_status = GETPOST("search_status", 'int');
  83. $search_type = GETPOST('search_type', 'alpha');
  84. $search_address = GETPOST('search_address', 'alpha');
  85. $search_zip = GETPOST('search_zip', 'alpha');
  86. $search_town = GETPOST('search_town', 'alpha');
  87. $search_import_key = GETPOST("search_import_key", "alpha");
  88. $search_country = GETPOST("search_country", 'intcomma');
  89. $search_roles = GETPOST("search_roles", 'array');
  90. $search_level = GETPOST("search_level", "array");
  91. $search_stcomm = GETPOST('search_stcomm', 'int');
  92. if ($search_status == '') {
  93. $search_status = 1; // always display active customer first
  94. }
  95. $optioncss = GETPOST('optioncss', 'alpha');
  96. $type = GETPOST("type", 'aZ');
  97. $view = GETPOST("view", 'alpha');
  98. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  99. $sortfield = GETPOST('sortfield', 'aZ09comma');
  100. $sortorder = GETPOST('sortorder', 'aZ09comma');
  101. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  102. $userid = GETPOST('userid', 'int');
  103. $begin = GETPOST('begin');
  104. if (!$sortorder) {
  105. $sortorder = "ASC";
  106. }
  107. if (!$sortfield) {
  108. $sortfield = "p.lastname";
  109. }
  110. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  111. $page = 0;
  112. }
  113. $offset = $limit * $page;
  114. $titre = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  115. if ($type == "p") {
  116. if (empty($contextpage) || $contextpage == 'contactlist') {
  117. $contextpage = 'contactprospectlist';
  118. }
  119. $titre .= ' ('.$langs->trans("ThirdPartyProspects").')';
  120. $urlfiche = "card.php";
  121. }
  122. if ($type == "c") {
  123. if (empty($contextpage) || $contextpage == 'contactlist') {
  124. $contextpage = 'contactcustomerlist';
  125. }
  126. $titre .= ' ('.$langs->trans("ThirdPartyCustomers").')';
  127. $urlfiche = "card.php";
  128. } elseif ($type == "f") {
  129. if (empty($contextpage) || $contextpage == 'contactlist') {
  130. $contextpage = 'contactsupplierlist';
  131. }
  132. $titre .= ' ('.$langs->trans("ThirdPartySuppliers").')';
  133. $urlfiche = "card.php";
  134. } elseif ($type == "o") {
  135. if (empty($contextpage) || $contextpage == 'contactlist') {
  136. $contextpage = 'contactotherlist';
  137. }
  138. $titre .= ' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
  139. $urlfiche = "";
  140. }
  141. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  142. $object = new Contact($db);
  143. $hookmanager->initHooks(array('contactlist'));
  144. $extrafields = new ExtraFields($db);
  145. // fetch optionals attributes and labels
  146. $extrafields->fetch_name_optionals_label($object->table_element);
  147. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  148. // List of fields to search into when doing a "search in all"
  149. $fieldstosearchall = array();
  150. foreach ($object->fields as $key => $val) {
  151. // don't allow search in private notes for external users when doing "search in all"
  152. if (!empty($user->socid) && $key == "note_private") {
  153. continue;
  154. }
  155. if (empty($val['searchall'])) {
  156. continue;
  157. }
  158. $fieldstosearchall['p.'.$key] = $val['label'];
  159. }
  160. // Add none object fields for "search in all"
  161. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  162. $fieldstosearchall['s.nom'] = "ThirdParty";
  163. }
  164. // Definition of fields for list
  165. $arrayfields = array();
  166. foreach ($object->fields as $key => $val) {
  167. // If $val['visible']==0, then we never show the field
  168. if (empty($val['visible'])) {
  169. continue;
  170. }
  171. $arrayfields['p.'.$key] = array(
  172. 'label'=>$val['label'],
  173. 'checked'=>(($val['visible'] < 0) ? 0 : 1),
  174. 'enabled'=>($val['enabled'] && ($val['visible'] != 3)),
  175. 'position'=>$val['position']);
  176. }
  177. // Add none object fields to fields for list
  178. $arrayfields['country.code_iso'] = array('label'=>"Country", 'position'=>22, 'checked'=>0);
  179. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  180. $arrayfields['s.nom'] = array('label'=>"ThirdParty", 'position'=>25, 'checked'=>1);
  181. }
  182. if (!empty($conf->socialnetworks->enabled)) {
  183. foreach ($socialnetworks as $key => $value) {
  184. if ($value['active']) {
  185. $arrayfields['p.'.$key] = array(
  186. 'label' => $value['label'],
  187. 'checked' => 0,
  188. 'position' => 300
  189. );
  190. }
  191. }
  192. }
  193. // Extra fields
  194. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  195. $object->fields = dol_sort_array($object->fields, 'position');
  196. $arrayfields = dol_sort_array($arrayfields, 'position');
  197. if (($id > 0 || !empty($ref)) && $action != 'add') {
  198. $result = $object->fetch($id, $ref);
  199. if ($result < 0) {
  200. dol_print_error($db);
  201. }
  202. }
  203. /*
  204. * Actions
  205. */
  206. if (GETPOST('cancel', 'alpha')) {
  207. $action = 'list'; $massaction = '';
  208. }
  209. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  210. $massaction = '';
  211. }
  212. $parameters = array();
  213. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  214. if ($reshook < 0) {
  215. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  216. }
  217. if (empty($reshook)) {
  218. // Selection of new fields
  219. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  220. // Did we click on purge search criteria ?
  221. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  222. $sall = "";
  223. $search_id = '';
  224. $search_firstlast_only = "";
  225. $search_lastname = "";
  226. $search_firstname = "";
  227. $search_societe = "";
  228. $search_town = "";
  229. $search_address = "";
  230. $search_zip = "";
  231. $search_country = "";
  232. $search_poste = "";
  233. $search_phone = "";
  234. $search_phone_perso = "";
  235. $search_phone_pro = "";
  236. $search_phone_mobile = "";
  237. $search_fax = "";
  238. $search_email = "";
  239. $search_no_email = -1;
  240. if (!empty($conf->socialnetworks->enabled)) {
  241. foreach ($socialnetworks as $key => $value) {
  242. if ($value['active']) {
  243. $search_[$key] = "";
  244. }
  245. }
  246. }
  247. $search_priv = "";
  248. $search_stcomm = '';
  249. $search_level = '';
  250. $search_status = -1;
  251. $search_categ = '';
  252. $search_categ_thirdparty = '';
  253. $search_categ_supplier = '';
  254. $search_import_key = '';
  255. $toselect = array();
  256. $search_array_options = array();
  257. $search_roles = array();
  258. }
  259. // Mass actions
  260. $objectclass = 'Contact';
  261. $objectlabel = 'Contact';
  262. $permissiontoread = $user->rights->societe->lire;
  263. $permissiontodelete = $user->rights->societe->supprimer;
  264. $permissiontoadd = $user->rights->societe->creer;
  265. $uploaddir = $conf->societe->dir_output;
  266. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  267. if ($action == 'setstcomm') {
  268. $object = new Contact($db);
  269. $result = $object->fetch(GETPOST('stcommcontactid'));
  270. $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
  271. $result = $object->update($object->id, $user);
  272. if ($result < 0) {
  273. setEventMessages($object->error, $object->errors, 'errors');
  274. }
  275. $action = '';
  276. }
  277. }
  278. if ($search_priv < 0) {
  279. $search_priv = '';
  280. }
  281. /*
  282. * View
  283. */
  284. $form = new Form($db);
  285. $formother = new FormOther($db);
  286. $formcompany = new FormCompany($db);
  287. $contactstatic = new Contact($db);
  288. if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
  289. $contactstatic->loadCacheOfProspStatus();
  290. }
  291. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  292. // Select every potentiels, and note each potentiels which fit in search parameters
  293. $tab_level = array();
  294. $sql = "SELECT code, label, sortorder";
  295. $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectcontactlevel";
  296. $sql .= " WHERE active > 0";
  297. $sql .= " ORDER BY sortorder";
  298. $resql = $db->query($sql);
  299. if ($resql) {
  300. while ($obj = $db->fetch_object($resql)) {
  301. // Compute level text
  302. $level = $langs->trans($obj->code);
  303. if ($level == $obj->code) {
  304. $level = $langs->trans($obj->label);
  305. }
  306. $tab_level[$obj->code] = $level;
  307. }
  308. } else {
  309. dol_print_error($db);
  310. }
  311. $sql = "SELECT s.rowid as socid, s.nom as name,";
  312. $sql .= " p.rowid, p.lastname as lastname, p.statut, p.firstname, p.address, p.zip, p.town, p.poste, p.email, p.no_email,";
  313. $sql .= " p.socialnetworks, p.photo,";
  314. $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,";
  315. $sql .= " st.libelle as stcomm, st.picto as stcomm_picto, p.fk_stcommcontact as stcomm_id, p.fk_prospectcontactlevel,";
  316. $sql .= " co.label as country, co.code as country_code";
  317. // Add fields from extrafields
  318. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  319. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  320. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  321. }
  322. }
  323. // Add fields from hooks
  324. $parameters = array();
  325. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  326. $sql .= $hookmanager->resPrint;
  327. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  328. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  329. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
  330. }
  331. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays";
  332. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  333. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_stcommcontact as st ON st.id = p.fk_stcommcontact";
  334. if (!empty($search_categ) && $search_categ != '-1') {
  335. $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
  336. }
  337. if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') {
  338. $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
  339. }
  340. if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') {
  341. $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
  342. }
  343. if (!$user->rights->societe->client->voir && !$socid) {
  344. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  345. }
  346. $sql .= ' WHERE p.entity IN ('.getEntity('socpeople').')';
  347. if (!$user->rights->societe->client->voir && !$socid) { //restriction
  348. $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR p.fk_soc IS NULL)";
  349. }
  350. if (!empty($userid)) { // propre au commercial
  351. $sql .= " AND p.fk_user_creat=".((int) $userid);
  352. }
  353. if ($search_level) {
  354. $sql .= natural_search("p.fk_prospectcontactlevel", join(',', $search_level), 3);
  355. }
  356. if ($search_stcomm != '' && $search_stcomm != -2) {
  357. $sql .= natural_search("p.fk_stcommcontact", $search_stcomm, 2);
  358. }
  359. // Filter to exclude not owned private contacts
  360. if ($search_priv != '0' && $search_priv != '1') {
  361. $sql .= " AND (p.priv='0' OR (p.priv='1' AND p.fk_user_creat=".((int) $user->id)."))";
  362. } else {
  363. if ($search_priv == '0') {
  364. $sql .= " AND p.priv='0'";
  365. }
  366. if ($search_priv == '1') {
  367. $sql .= " AND (p.priv='1' AND p.fk_user_creat=".((int) $user->id).")";
  368. }
  369. }
  370. if ($search_categ > 0) {
  371. $sql .= " AND cc.fk_categorie = ".((int) $search_categ);
  372. }
  373. if ($search_categ == -2) {
  374. $sql .= " AND cc.fk_categorie IS NULL";
  375. }
  376. if ($search_categ_thirdparty > 0) {
  377. $sql .= " AND cs.fk_categorie = ".((int) $search_categ_thirdparty);
  378. }
  379. if ($search_categ_thirdparty == -2) {
  380. $sql .= " AND cs.fk_categorie IS NULL";
  381. }
  382. if ($search_categ_supplier > 0) {
  383. $sql .= " AND cs2.fk_categorie = ".((int) $search_categ_supplier);
  384. }
  385. if ($search_categ_supplier == -2) {
  386. $sql .= " AND cs2.fk_categorie IS NULL";
  387. }
  388. if ($sall) {
  389. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  390. }
  391. if (strlen($search_phone)) {
  392. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_phone);
  393. }
  394. if (strlen($search_cti)) {
  395. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_cti);
  396. }
  397. if (strlen($search_firstlast_only)) {
  398. $sql .= natural_search(array('p.lastname', 'p.firstname'), $search_firstlast_only);
  399. }
  400. if ($search_id > 0) {
  401. $sql .= natural_search('p.rowid', $search_id, 1);
  402. }
  403. if ($search_lastname) {
  404. $sql .= natural_search('p.lastname', $search_lastname);
  405. }
  406. if ($search_firstname) {
  407. $sql .= natural_search('p.firstname', $search_firstname);
  408. }
  409. if ($search_societe) {
  410. $sql .= natural_search(empty($conf->global->SOCIETE_DISABLE_CONTACTS) ? 's.nom' : 'p.fk_soc', $search_societe);
  411. }
  412. if ($search_country) {
  413. $sql .= " AND p.fk_pays IN (".$db->sanitize($search_country).')';
  414. }
  415. if (strlen($search_poste)) {
  416. $sql .= natural_search('p.poste', $search_poste);
  417. }
  418. if (strlen($search_phone_perso)) {
  419. $sql .= natural_search('p.phone_perso', $search_phone_perso);
  420. }
  421. if (strlen($search_phone_pro)) {
  422. $sql .= natural_search('p.phone', $search_phone_pro);
  423. }
  424. if (strlen($search_phone_mobile)) {
  425. $sql .= natural_search('p.phone_mobile', $search_phone_mobile);
  426. }
  427. if (strlen($search_fax)) {
  428. $sql .= natural_search('p.fax', $search_fax);
  429. }
  430. if (!empty($conf->socialnetworks->enabled)) {
  431. foreach ($socialnetworks as $key => $value) {
  432. if ($value['active'] && strlen($search_[$key])) {
  433. $sql .= " AND p.socialnetworks LIKE '%\"".$key."\":\"".$search_[$key]."%'";
  434. }
  435. }
  436. }
  437. if (strlen($search_email)) {
  438. $sql .= natural_search('p.email', $search_email);
  439. }
  440. if (strlen($search_address)) {
  441. $sql .= natural_search("p.address", $search_address);
  442. }
  443. if (strlen($search_zip)) {
  444. $sql .= natural_search("p.zip", $search_zip);
  445. }
  446. if (strlen($search_town)) {
  447. $sql .= natural_search("p.town", $search_town);
  448. }
  449. if (count($search_roles) > 0) {
  450. $sql .= " AND p.rowid IN (SELECT sc.fk_socpeople FROM ".MAIN_DB_PREFIX."societe_contacts as sc WHERE sc.fk_c_type_contact IN (".$db->sanitize(implode(',', $search_roles))."))";
  451. }
  452. if ($search_no_email != '' && $search_no_email >= 0) {
  453. $sql .= " AND p.no_email = ".((int) $search_no_email);
  454. }
  455. if ($search_status != '' && $search_status >= 0) {
  456. $sql .= " AND p.statut = ".((int) $search_status);
  457. }
  458. if ($search_import_key) {
  459. $sql .= natural_search("p.import_key", $search_import_key);
  460. }
  461. if ($type == "o") { // filtre sur type
  462. $sql .= " AND p.fk_soc IS NULL";
  463. } elseif ($type == "f") { // filtre sur type
  464. $sql .= " AND s.fournisseur = 1";
  465. } elseif ($type == "c") { // filtre sur type
  466. $sql .= " AND s.client IN (1, 3)";
  467. } elseif ($type == "p") { // filtre sur type
  468. $sql .= " AND s.client IN (2, 3)";
  469. }
  470. if (!empty($socid)) {
  471. $sql .= " AND s.rowid = ".((int) $socid);
  472. }
  473. // Add where from extra fields
  474. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  475. // Add where from hooks
  476. $parameters = array();
  477. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  478. $sql .= $hookmanager->resPrint;
  479. // Add order
  480. if ($view == "recent") {
  481. $sql .= $db->order("p.datec", "DESC");
  482. } else {
  483. $sql .= $db->order($sortfield, $sortorder);
  484. }
  485. // Count total nb of records
  486. $nbtotalofrecords = '';
  487. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  488. $resql = $db->query($sql);
  489. $nbtotalofrecords = $db->num_rows($resql);
  490. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  491. $page = 0;
  492. $offset = 0;
  493. }
  494. }
  495. $sql .= $db->plimit($limit + 1, $offset);
  496. $resql = $db->query($sql);
  497. if (!$resql) {
  498. dol_print_error($db);
  499. exit;
  500. }
  501. $num = $db->num_rows($resql);
  502. $arrayofselected = is_array($toselect) ? $toselect : array();
  503. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($sall != '' || $search_cti != '')) {
  504. $obj = $db->fetch_object($resql);
  505. $id = $obj->rowid;
  506. header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
  507. exit;
  508. }
  509. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
  510. llxHeader('', $title, $help_url);
  511. $param = '';
  512. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  513. $param .= '&amp;contextpage='.$contextpage;
  514. }
  515. if ($limit > 0 && $limit != $conf->liste_limit) {
  516. $param .= '&amp;limit='.$limit;
  517. }
  518. $param .= '&amp;begin='.urlencode($begin).'&amp;userid='.urlencode($userid).'&amp;contactname='.urlencode($sall);
  519. $param .= '&amp;type='.urlencode($type).'&amp;view='.urlencode($view);
  520. if (!empty($search_categ)) {
  521. $param .= '&amp;search_categ='.urlencode($search_categ);
  522. }
  523. if (!empty($search_categ_thirdparty)) {
  524. $param .= '&amp;search_categ_thirdparty='.urlencode($search_categ_thirdparty);
  525. }
  526. if (!empty($search_categ_supplier)) {
  527. $param .= '&amp;search_categ_supplier='.urlencode($search_categ_supplier);
  528. }
  529. if ($sall != '') {
  530. $param .= '&amp;sall='.urlencode($sall);
  531. }
  532. if ($search_id > 0) {
  533. $param .= "&amp;search_id=".urlencode($search_id);
  534. }
  535. if ($search_lastname != '') {
  536. $param .= '&amp;search_lastname='.urlencode($search_lastname);
  537. }
  538. if ($search_firstname != '') {
  539. $param .= '&amp;search_firstname='.urlencode($search_firstname);
  540. }
  541. if ($search_societe != '') {
  542. $param .= '&amp;search_societe='.urlencode($search_societe);
  543. }
  544. if ($search_address != '') {
  545. $param .= '&amp;search_address='.urlencode($search_address);
  546. }
  547. if ($search_zip != '') {
  548. $param .= '&amp;search_zip='.urlencode($search_zip);
  549. }
  550. if ($search_town != '') {
  551. $param .= '&amp;search_town='.urlencode($search_town);
  552. }
  553. if ($search_country != '') {
  554. $param .= "&search_country=".urlencode($search_country);
  555. }
  556. if ($search_poste != '') {
  557. $param .= '&amp;search_poste='.urlencode($search_poste);
  558. }
  559. if ($search_phone_pro != '') {
  560. $param .= '&amp;search_phone_pro='.urlencode($search_phone_pro);
  561. }
  562. if ($search_phone_perso != '') {
  563. $param .= '&amp;search_phone_perso='.urlencode($search_phone_perso);
  564. }
  565. if ($search_phone_mobile != '') {
  566. $param .= '&amp;search_phone_mobile='.urlencode($search_phone_mobile);
  567. }
  568. if ($search_fax != '') {
  569. $param .= '&amp;search_fax='.urlencode($search_fax);
  570. }
  571. if ($search_email != '') {
  572. $param .= '&amp;search_email='.urlencode($search_email);
  573. }
  574. if ($search_no_email != '') {
  575. $param .= '&amp;search_no_email='.urlencode($search_no_email);
  576. }
  577. if ($search_status != '') {
  578. $param .= '&amp;search_status='.urlencode($search_status);
  579. }
  580. if ($search_priv == '0' || $search_priv == '1') {
  581. $param .= "&amp;search_priv=".urlencode($search_priv);
  582. }
  583. if ($search_stcomm != '') {
  584. $param .= '&search_stcomm='.urlencode($search_stcomm);
  585. }
  586. if (is_array($search_level) && count($search_level)) {
  587. foreach ($search_level as $slevel) {
  588. $param .= '&search_level[]='.urlencode($slevel);
  589. }
  590. }
  591. if ($search_import_key != '') {
  592. $param .= '&amp;search_import_key='.urlencode($search_import_key);
  593. }
  594. if ($optioncss != '') {
  595. $param .= '&amp;optioncss='.urlencode($optioncss);
  596. }
  597. if (count($search_roles) > 0) {
  598. $param .= implode('&search_roles[]=', $search_roles);
  599. }
  600. // Add $param from extra fields
  601. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  602. // List of mass actions available
  603. $arrayofmassactions = array(
  604. // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  605. // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  606. );
  607. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  608. if ($user->rights->societe->supprimer) {
  609. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  610. }
  611. if ($user->rights->societe->creer) {
  612. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  613. }
  614. if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
  615. $arrayofmassactions = array();
  616. }
  617. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  618. $newcardbutton = dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create', '', $user->rights->societe->contact->creer);
  619. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  620. if ($optioncss != '') {
  621. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  622. }
  623. print '<input type="hidden" name="token" value="'.newToken().'">';
  624. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  625. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  626. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  627. //print '<input type="hidden" name="page" value="'.$page.'">';
  628. print '<input type="hidden" name="type" value="'.$type.'">';
  629. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  630. print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'address', 0, $newcardbutton, '', $limit, 0, 0, 1);
  631. $topicmail = "Information";
  632. $modelmail = "contact";
  633. $objecttmp = new Contact($db);
  634. $trackid = 'ctc'.$object->id;
  635. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  636. if ($sall) {
  637. foreach ($fieldstosearchall as $key => $val) {
  638. $fieldstosearchall[$key] = $langs->trans($val);
  639. }
  640. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  641. }
  642. if ($search_firstlast_only) {
  643. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_firstlast_only).$langs->trans("Lastname").", ".$langs->trans("Firstname").'</div>';
  644. }
  645. $moreforfilter = '';
  646. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  647. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  648. $moreforfilter .= '<div class="divsearchfield">';
  649. $tmptitle = $langs->trans('ContactCategoriesShort');
  650. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  651. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CONTACT, $search_categ, 'search_categ', 1, $tmptitle);
  652. $moreforfilter .= '</div>';
  653. if (empty($type) || $type == 'c' || $type == 'p') {
  654. $moreforfilter .= '<div class="divsearchfield">';
  655. $tmptitle = '';
  656. if ($type == 'c') {
  657. $tmptitle .= $langs->trans('CustomersCategoriesShort');
  658. } elseif ($type == 'p') {
  659. $tmptitle .= $langs->trans('ProspectsCategoriesShort');
  660. } else {
  661. $tmptitle .= $langs->trans('CustomersProspectsCategoriesShort');
  662. }
  663. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  664. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CUSTOMER, $search_categ_thirdparty, 'search_categ_thirdparty', 1, $tmptitle);
  665. $moreforfilter .= '</div>';
  666. }
  667. if (!empty($conf->fournisseur->enabled) && (empty($type) || $type == 'f')) {
  668. $moreforfilter .= '<div class="divsearchfield">';
  669. $tmptitle = $langs->trans('SuppliersCategoriesShort');
  670. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  671. $moreforfilter .= $formother->select_categories(Categorie::TYPE_SUPPLIER, $search_categ_supplier, 'search_categ_supplier', 1, $tmptitle);
  672. $moreforfilter .= '</div>';
  673. }
  674. }
  675. $moreforfilter .= '<div class="divsearchfield">';
  676. $moreforfilter .= $langs->trans('Roles').': ';
  677. $moreforfilter .= $formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
  678. $moreforfilter .= '</div>';
  679. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  680. print $moreforfilter;
  681. $parameters = array('type'=>$type);
  682. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  683. print $hookmanager->resPrint;
  684. print '</div>';
  685. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  686. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  687. if ($massactionbutton) {
  688. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  689. }
  690. print '<div class="div-table-responsive">';
  691. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  692. // Lines for filter fields
  693. print '<tr class="liste_titre_filter">';
  694. if (!empty($arrayfields['p.rowid']['checked'])) {
  695. print '<td class="liste_titre">';
  696. print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
  697. print '</td>';
  698. }
  699. if (!empty($arrayfields['p.lastname']['checked'])) {
  700. print '<td class="liste_titre">';
  701. print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
  702. print '</td>';
  703. }
  704. if (!empty($arrayfields['p.firstname']['checked'])) {
  705. print '<td class="liste_titre">';
  706. print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
  707. print '</td>';
  708. }
  709. if (!empty($arrayfields['p.poste']['checked'])) {
  710. print '<td class="liste_titre">';
  711. print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
  712. print '</td>';
  713. }
  714. if (!empty($arrayfields['p.address']['checked'])) {
  715. print '<td class="liste_titre">';
  716. print '<input class="flat" type="text" name="search_address" size="6" value="'.dol_escape_htmltag($search_address).'">';
  717. print '</td>';
  718. }
  719. if (!empty($arrayfields['p.zip']['checked'])) {
  720. print '<td class="liste_titre">';
  721. print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
  722. print '</td>';
  723. }
  724. if (!empty($arrayfields['p.town']['checked'])) {
  725. print '<td class="liste_titre">';
  726. print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
  727. print '</td>';
  728. }
  729. // State
  730. /*if (! empty($arrayfields['state.nom']['checked']))
  731. {
  732. print '<td class="liste_titre">';
  733. print '<input class="flat searchstring" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  734. print '</td>';
  735. }
  736. // Region
  737. if (! empty($arrayfields['region.nom']['checked']))
  738. {
  739. print '<td class="liste_titre">';
  740. print '<input class="flat searchstring" size="4" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
  741. print '</td>';
  742. }*/
  743. // Country
  744. if (!empty($arrayfields['country.code_iso']['checked'])) {
  745. print '<td class="liste_titre center">';
  746. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  747. print '</td>';
  748. }
  749. if (!empty($arrayfields['p.phone']['checked'])) {
  750. print '<td class="liste_titre">';
  751. print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
  752. print '</td>';
  753. }
  754. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  755. print '<td class="liste_titre">';
  756. print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
  757. print '</td>';
  758. }
  759. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  760. print '<td class="liste_titre">';
  761. print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
  762. print '</td>';
  763. }
  764. if (!empty($arrayfields['p.fax']['checked'])) {
  765. print '<td class="liste_titre">';
  766. print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
  767. print '</td>';
  768. }
  769. if (!empty($arrayfields['p.email']['checked'])) {
  770. print '<td class="liste_titre">';
  771. print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
  772. print '</td>';
  773. }
  774. if (!empty($arrayfields['p.no_email']['checked'])) {
  775. print '<td class="liste_titre center">';
  776. print $form->selectarray('search_no_email', array('-1'=>'', '0'=>$langs->trans('No'), '1'=>$langs->trans('Yes')), $search_no_email);
  777. print '</td>';
  778. }
  779. if (!empty($conf->socialnetworks->enabled)) {
  780. foreach ($socialnetworks as $key => $value) {
  781. if ($value['active']) {
  782. if (!empty($arrayfields['p.'.$key]['checked'])) {
  783. print '<td class="liste_titre">';
  784. print '<input class="flat" type="text" name="search_'.$key.'" size="6" value="'.dol_escape_htmltag($search_[$key]).'">';
  785. print '</td>';
  786. }
  787. }
  788. }
  789. }
  790. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  791. print '<td class="liste_titre">';
  792. print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  793. print '</td>';
  794. }
  795. if (!empty($arrayfields['p.priv']['checked'])) {
  796. print '<td class="liste_titre center">';
  797. $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
  798. print $form->selectarray('search_priv', $selectarray, $search_priv, 1);
  799. print '</td>';
  800. }
  801. // Prospect level
  802. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  803. print '<td class="liste_titre center">';
  804. print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
  805. print '</td>';
  806. }
  807. // Prospect status
  808. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  809. print '<td class="liste_titre maxwidthonsmartphone center">';
  810. $arraystcomm = array();
  811. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  812. $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
  813. }
  814. print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', 'nowrap ');
  815. print '</td>';
  816. }
  817. // Extra fields
  818. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  819. // Fields from hook
  820. $parameters = array('arrayfields'=>$arrayfields);
  821. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  822. print $hookmanager->resPrint;
  823. // Date creation
  824. if (!empty($arrayfields['p.datec']['checked'])) {
  825. print '<td class="liste_titre">';
  826. print '</td>';
  827. }
  828. // Date modification
  829. if (!empty($arrayfields['p.tms']['checked'])) {
  830. print '<td class="liste_titre">';
  831. print '</td>';
  832. }
  833. // Status
  834. if (!empty($arrayfields['p.statut']['checked'])) {
  835. print '<td class="liste_titre center">';
  836. print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $search_status);
  837. print '</td>';
  838. }
  839. if (!empty($arrayfields['p.import_key']['checked'])) {
  840. print '<td class="liste_titre center">';
  841. print '<input class="flat searchstring" type="text" name="search_import_key" size="3" value="'.dol_escape_htmltag($search_import_key).'">';
  842. print '</td>';
  843. }
  844. // Action column
  845. print '<td class="liste_titre maxwidthsearch">';
  846. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  847. print $searchpicto;
  848. print '</td>';
  849. print '</tr>';
  850. // Ligne des titres
  851. print '<tr class="liste_titre">';
  852. if (!empty($arrayfields['p.rowid']['checked'])) {
  853. print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
  854. }
  855. if (!empty($arrayfields['p.lastname']['checked'])) {
  856. print_liste_field_titre($arrayfields['p.lastname']['label'], $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, '', $sortfield, $sortorder);
  857. }
  858. if (!empty($arrayfields['p.firstname']['checked'])) {
  859. print_liste_field_titre($arrayfields['p.firstname']['label'], $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, '', $sortfield, $sortorder);
  860. }
  861. if (!empty($arrayfields['p.poste']['checked'])) {
  862. print_liste_field_titre($arrayfields['p.poste']['label'], $_SERVER["PHP_SELF"], "p.poste", $begin, $param, '', $sortfield, $sortorder);
  863. }
  864. if (!empty($arrayfields['p.address']['checked'])) {
  865. print_liste_field_titre($arrayfields['p.address']['label'], $_SERVER["PHP_SELF"], "p.address", $begin, $param, '', $sortfield, $sortorder);
  866. }
  867. if (!empty($arrayfields['p.zip']['checked'])) {
  868. print_liste_field_titre($arrayfields['p.zip']['label'], $_SERVER["PHP_SELF"], "p.zip", $begin, $param, '', $sortfield, $sortorder);
  869. }
  870. if (!empty($arrayfields['p.town']['checked'])) {
  871. print_liste_field_titre($arrayfields['p.town']['label'], $_SERVER["PHP_SELF"], "p.town", $begin, $param, '', $sortfield, $sortorder);
  872. }
  873. //if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  874. //if (! empty($arrayfields['region.nom']['checked'])) print_liste_field_titre($arrayfields['region.nom']['label'],$_SERVER["PHP_SELF"],"region.nom","",$param,'',$sortfield,$sortorder);
  875. if (!empty($arrayfields['country.code_iso']['checked'])) {
  876. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "co.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  877. }
  878. if (!empty($arrayfields['p.phone']['checked'])) {
  879. print_liste_field_titre($arrayfields['p.phone']['label'], $_SERVER["PHP_SELF"], "p.phone", $begin, $param, '', $sortfield, $sortorder);
  880. }
  881. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  882. print_liste_field_titre($arrayfields['p.phone_perso']['label'], $_SERVER["PHP_SELF"], "p.phone_perso", $begin, $param, '', $sortfield, $sortorder);
  883. }
  884. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  885. print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder);
  886. }
  887. if (!empty($arrayfields['p.fax']['checked'])) {
  888. print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder);
  889. }
  890. if (!empty($arrayfields['p.email']['checked'])) {
  891. print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder);
  892. }
  893. if (!empty($arrayfields['p.no_email']['checked'])) {
  894. print_liste_field_titre($arrayfields['p.no_email']['label'], $_SERVER["PHP_SELF"], "p.no_email", $begin, $param, '', $sortfield, $sortorder, 'center ');
  895. }
  896. if (!empty($conf->socialnetworks->enabled)) {
  897. foreach ($socialnetworks as $key => $value) {
  898. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  899. print_liste_field_titre($arrayfields['p.'.$key]['label'], $_SERVER["PHP_SELF"], "p.".$key, $begin, $param, '', $sortfield, $sortorder);
  900. }
  901. }
  902. }
  903. if (!empty($arrayfields['p.fk_soc']['checked'])) {
  904. print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER["PHP_SELF"], "p.fk_soc", $begin, $param, '', $sortfield, $sortorder);
  905. }
  906. if (!empty($arrayfields['s.nom']['checked'])) {
  907. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $begin, $param, '', $sortfield, $sortorder);
  908. }
  909. if (!empty($arrayfields['p.priv']['checked'])) {
  910. print_liste_field_titre($arrayfields['p.priv']['label'], $_SERVER["PHP_SELF"], "p.priv", $begin, $param, '', $sortfield, $sortorder, 'center ');
  911. }
  912. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  913. print_liste_field_titre($arrayfields['p.fk_prospectcontactlevel']['label'], $_SERVER["PHP_SELF"], "p.fk_prospectcontactlevel", "", $param, '', $sortfield, $sortorder, 'center ');
  914. }
  915. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  916. print_liste_field_titre($arrayfields['p.fk_stcommcontact']['label'], $_SERVER["PHP_SELF"], "p.fk_stcommcontact", "", $param, '', $sortfield, $sortorder, 'center ');
  917. }
  918. // Extra fields
  919. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  920. // Hook fields
  921. $parameters = array(
  922. 'arrayfields'=>$arrayfields,
  923. 'param'=>$param,
  924. 'sortfield'=>$sortfield,
  925. 'sortorder'=>$sortorder,
  926. );
  927. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  928. print $hookmanager->resPrint;
  929. if (!empty($arrayfields['p.datec']['checked'])) {
  930. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  931. }
  932. if (!empty($arrayfields['p.tms']['checked'])) {
  933. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  934. }
  935. if (!empty($arrayfields['p.statut']['checked'])) {
  936. print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", "", $param, '', $sortfield, $sortorder, 'center ');
  937. }
  938. if (!empty($arrayfields['p.import_key']['checked'])) {
  939. print_liste_field_titre($arrayfields['p.import_key']['label'], $_SERVER["PHP_SELF"], "p.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  940. }
  941. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  942. print "</tr>\n";
  943. $i = 0;
  944. $totalarray = array();
  945. while ($i < min($num, $limit)) {
  946. $obj = $db->fetch_object($resql);
  947. $arraysocialnetworks = (array) json_decode($obj->socialnetworks, true);
  948. $contactstatic->lastname = $obj->lastname;
  949. $contactstatic->firstname = '';
  950. $contactstatic->id = $obj->rowid;
  951. $contactstatic->statut = $obj->statut;
  952. $contactstatic->poste = $obj->poste;
  953. $contactstatic->email = $obj->email;
  954. $contactstatic->phone_pro = $obj->phone_pro;
  955. $contactstatic->phone_perso = $obj->phone_perso;
  956. $contactstatic->phone_mobile = $obj->phone_mobile;
  957. $contactstatic->address = $obj->address;
  958. $contactstatic->zip = $obj->zip;
  959. $contactstatic->town = $obj->town;
  960. $contactstatic->socialnetworks = $arraysocialnetworks;
  961. $contactstatic->country = $obj->country;
  962. $contactstatic->country_code = $obj->country_code;
  963. $contactstatic->photo = $obj->photo;
  964. $contactstatic->fk_prospectlevel = $obj->fk_prospectcontactlevel;
  965. print '<tr class="oddeven">';
  966. // ID
  967. if (!empty($arrayfields['p.rowid']['checked'])) {
  968. print '<td class="tdoverflowmax50">';
  969. print $obj->rowid;
  970. print "</td>\n";
  971. if (!$i) {
  972. $totalarray['nbfield']++;
  973. }
  974. }
  975. // Name
  976. if (!empty($arrayfields['p.lastname']['checked'])) {
  977. print '<td class="middle tdoverflowmax200">';
  978. print $contactstatic->getNomUrl(1);
  979. print '</td>';
  980. if (!$i) {
  981. $totalarray['nbfield']++;
  982. }
  983. }
  984. // Firstname
  985. if (!empty($arrayfields['p.firstname']['checked'])) {
  986. print '<td class="tdoverflowmax200">'.$obj->firstname.'</td>';
  987. if (!$i) {
  988. $totalarray['nbfield']++;
  989. }
  990. }
  991. // Job position
  992. if (!empty($arrayfields['p.poste']['checked'])) {
  993. print '<td class="tdoverflowmax100">'.$obj->poste.'</td>';
  994. if (!$i) {
  995. $totalarray['nbfield']++;
  996. }
  997. }
  998. // Address
  999. if (!empty($arrayfields['p.address']['checked'])) {
  1000. print '<td>'.$obj->address.'</td>';
  1001. if (!$i) {
  1002. $totalarray['nbfield']++;
  1003. }
  1004. }
  1005. // Zip
  1006. if (!empty($arrayfields['p.zip']['checked'])) {
  1007. print '<td>'.$obj->zip.'</td>';
  1008. if (!$i) {
  1009. $totalarray['nbfield']++;
  1010. }
  1011. }
  1012. // Town
  1013. if (!empty($arrayfields['p.town']['checked'])) {
  1014. print '<td>'.$obj->town.'</td>';
  1015. if (!$i) {
  1016. $totalarray['nbfield']++;
  1017. }
  1018. }
  1019. // State
  1020. /*if (! empty($arrayfields['state.nom']['checked']))
  1021. {
  1022. print "<td>".$obj->state_name."</td>\n";
  1023. if (! $i) $totalarray['nbfield']++;
  1024. }
  1025. // Region
  1026. if (! empty($arrayfields['region.nom']['checked']))
  1027. {
  1028. print "<td>".$obj->region_name."</td>\n";
  1029. if (! $i) $totalarray['nbfield']++;
  1030. }*/
  1031. // Country
  1032. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1033. print '<td class="center">';
  1034. $tmparray = getCountry($obj->fk_pays, 'all');
  1035. print $tmparray['label'];
  1036. print '</td>';
  1037. if (!$i) {
  1038. $totalarray['nbfield']++;
  1039. }
  1040. }
  1041. // Phone
  1042. if (!empty($arrayfields['p.phone']['checked'])) {
  1043. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1044. if (!$i) {
  1045. $totalarray['nbfield']++;
  1046. }
  1047. }
  1048. // Phone perso
  1049. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  1050. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1051. if (!$i) {
  1052. $totalarray['nbfield']++;
  1053. }
  1054. }
  1055. // Phone mobile
  1056. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  1057. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'mobile').'</td>';
  1058. if (!$i) {
  1059. $totalarray['nbfield']++;
  1060. }
  1061. }
  1062. // Fax
  1063. if (!empty($arrayfields['p.fax']['checked'])) {
  1064. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'fax').'</td>';
  1065. if (!$i) {
  1066. $totalarray['nbfield']++;
  1067. }
  1068. }
  1069. // EMail
  1070. if (!empty($arrayfields['p.email']['checked'])) {
  1071. print '<td class="nowraponall tdmaxoverflow300">'.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).'</td>';
  1072. if (!$i) {
  1073. $totalarray['nbfield']++;
  1074. }
  1075. }
  1076. // No EMail
  1077. if (!empty($arrayfields['p.no_email']['checked'])) {
  1078. print '<td class="center">'.yn($obj->no_email).'</td>';
  1079. if (!$i) {
  1080. $totalarray['nbfield']++;
  1081. }
  1082. }
  1083. if (!empty($conf->socialnetworks->enabled)) {
  1084. foreach ($socialnetworks as $key => $value) {
  1085. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  1086. print '<td>'.dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks).'</td>';
  1087. if (!$i) {
  1088. $totalarray['nbfield']++;
  1089. }
  1090. }
  1091. }
  1092. }
  1093. // Company
  1094. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  1095. print '<td class="tdoverflowmax200">';
  1096. if ($obj->socid) {
  1097. $objsoc = new Societe($db);
  1098. $objsoc->fetch($obj->socid);
  1099. print $objsoc->getNomUrl(1);
  1100. } else {
  1101. print '&nbsp;';
  1102. }
  1103. print '</td>';
  1104. if (!$i) {
  1105. $totalarray['nbfield']++;
  1106. }
  1107. }
  1108. // Private/Public
  1109. if (!empty($arrayfields['p.priv']['checked'])) {
  1110. print '<td class="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
  1111. if (!$i) {
  1112. $totalarray['nbfield']++;
  1113. }
  1114. }
  1115. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  1116. // Prospect level
  1117. print '<td class="center">';
  1118. print $contactstatic->getLibProspLevel();
  1119. print "</td>";
  1120. if (!$i) {
  1121. $totalarray['nbfield']++;
  1122. }
  1123. }
  1124. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  1125. // Prospect status
  1126. print '<td class="center nowrap"><div class="nowrap">';
  1127. print '<div class="inline-block">'.$contactstatic->libProspCommStatut($obj->stcomm_id, 2, $contactstatic->cacheprospectstatus[$obj->stcomm_id]['label'], $obj->stcomm_picto);
  1128. print '</div> - <div class="inline-block">';
  1129. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  1130. $titlealt = 'default';
  1131. if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
  1132. $titlealt = $val['label'];
  1133. }
  1134. if ($obj->stcomm_id != $val['id']) {
  1135. print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?stcommcontactid='.$obj->rowid.'&stcomm='.urlencode($val['code']).'&action=setstcomm&token='.newToken().$param.($page ? '&page='.urlencode($page) : '').'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
  1136. }
  1137. }
  1138. print '</div></div></td>';
  1139. if (!$i) {
  1140. $totalarray['nbfield']++;
  1141. }
  1142. }
  1143. // Extra fields
  1144. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1145. // Fields from hook
  1146. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1147. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1148. print $hookmanager->resPrint;
  1149. // Date creation
  1150. if (!empty($arrayfields['p.datec']['checked'])) {
  1151. print '<td class="center">';
  1152. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1153. print '</td>';
  1154. if (!$i) {
  1155. $totalarray['nbfield']++;
  1156. }
  1157. }
  1158. // Date modification
  1159. if (!empty($arrayfields['p.tms']['checked'])) {
  1160. print '<td class="center">';
  1161. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1162. print '</td>';
  1163. if (!$i) {
  1164. $totalarray['nbfield']++;
  1165. }
  1166. }
  1167. // Status
  1168. if (!empty($arrayfields['p.statut']['checked'])) {
  1169. print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
  1170. if (!$i) {
  1171. $totalarray['nbfield']++;
  1172. }
  1173. }
  1174. if (!empty($arrayfields['p.import_key']['checked'])) {
  1175. print '<td class="tdoverflowmax100">';
  1176. print $obj->import_key;
  1177. print "</td>\n";
  1178. if (!$i) {
  1179. $totalarray['nbfield']++;
  1180. }
  1181. }
  1182. // Action column
  1183. print '<td class="nowrap center">';
  1184. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1185. $selected = 0;
  1186. if (in_array($obj->rowid, $arrayofselected)) {
  1187. $selected = 1;
  1188. }
  1189. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1190. }
  1191. print '</td>';
  1192. if (!$i) {
  1193. $totalarray['nbfield']++;
  1194. }
  1195. print "</tr>\n";
  1196. $i++;
  1197. }
  1198. $db->free($resql);
  1199. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1200. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1201. print $hookmanager->resPrint;
  1202. print "</table>";
  1203. print "</div>";
  1204. //if ($num > $limit || $page) print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies.png', 0, '', '', $limit, 1);
  1205. print '</form>';
  1206. llxFooter();
  1207. $db->close();