list.php 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646
  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. // Load Dolibarr environment
  35. require '../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array("companies", "suppliers", "categories"));
  42. $socialnetworks = getArrayOfSocialNetworks();
  43. // Get parameters
  44. $action = GETPOST('action', 'aZ09');
  45. $massaction = GETPOST('massaction', 'alpha');
  46. $show_files = GETPOST('show_files', 'int');
  47. $confirm = GETPOST('confirm', 'alpha');
  48. $toselect = GETPOST('toselect', 'array');
  49. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contactlist';
  50. $mode = GETPOST('mode', 'alpha');
  51. // Security check
  52. $id = GETPOST('id', 'int');
  53. $contactid = GETPOST('id', 'int');
  54. $ref = ''; // There is no ref for contacts
  55. if ($user->socid) {
  56. $socid = $user->socid;
  57. }
  58. $result = restrictedArea($user, 'contact', $contactid, '');
  59. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  60. $search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
  61. $search_phone = GETPOST("search_phone", 'alpha');
  62. $search_id = GETPOST("search_id", "int");
  63. $search_firstlast_only = GETPOST("search_firstlast_only", 'alpha');
  64. $search_lastname = GETPOST("search_lastname", 'alpha');
  65. $search_firstname = GETPOST("search_firstname", 'alpha');
  66. $search_societe = GETPOST("search_societe", 'alpha');
  67. $search_societe_alias = GETPOST("search_societe_alias", 'alpha');
  68. $search_poste = GETPOST("search_poste", 'alpha');
  69. $search_phone_perso = GETPOST("search_phone_perso", 'alpha');
  70. $search_phone_pro = GETPOST("search_phone_pro", 'alpha');
  71. $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha');
  72. $search_fax = GETPOST("search_fax", 'alpha');
  73. $search_email = GETPOST("search_email", 'alpha');
  74. if (isModEnabled('mailing')) {
  75. $search_no_email = GETPOSTISSET("search_no_email") ? GETPOST("search_no_email", 'int') : -1;
  76. } else {
  77. $search_no_email = -1;
  78. }
  79. if (isModEnabled('socialnetworks')) {
  80. foreach ($socialnetworks as $key => $value) {
  81. if ($value['active']) {
  82. $search_[$key] = GETPOST("search_".$key, 'alpha');
  83. }
  84. }
  85. }
  86. $search_priv = GETPOST("search_priv", 'alpha');
  87. $search_categ = GETPOST("search_categ", 'int');
  88. $search_categ_thirdparty = GETPOST("search_categ_thirdparty", 'int');
  89. $search_categ_supplier = GETPOST("search_categ_supplier", 'int');
  90. $search_status = GETPOST("search_status", 'int');
  91. $search_type = GETPOST('search_type', 'alpha');
  92. $search_address = GETPOST('search_address', 'alpha');
  93. $search_zip = GETPOST('search_zip', 'alpha');
  94. $search_town = GETPOST('search_town', 'alpha');
  95. $search_import_key = GETPOST("search_import_key", 'alpha');
  96. $search_country = GETPOST("search_country", 'intcomma');
  97. $search_roles = GETPOST("search_roles", 'array');
  98. $search_level = GETPOST("search_level", 'array');
  99. $search_stcomm = GETPOST('search_stcomm', 'int');
  100. if ($search_status === '') {
  101. $search_status = 1; // always display active customer first
  102. }
  103. if ($search_no_email === '') {
  104. $search_no_email = -1;
  105. }
  106. $optioncss = GETPOST('optioncss', 'alpha');
  107. $type = GETPOST("type", 'aZ');
  108. $view = GETPOST("view", 'alpha');
  109. $userid = GETPOST('userid', 'int');
  110. $begin = GETPOST('begin');
  111. // Load variable for pagination
  112. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  113. $sortfield = GETPOST('sortfield', 'aZ09comma');
  114. $sortorder = GETPOST('sortorder', 'aZ09comma');
  115. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  116. if (!$sortorder) {
  117. $sortorder = "ASC";
  118. }
  119. if (!$sortfield) {
  120. $sortfield = "p.lastname";
  121. }
  122. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  123. // If $page is not defined, or '' or -1 or if we click on clear filters
  124. $page = 0;
  125. }
  126. $offset = $limit * $page;
  127. $pageprev = $page - 1;
  128. $pagenext = $page + 1;
  129. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  130. if ($type == "p") {
  131. if (empty($contextpage) || $contextpage == 'contactlist') {
  132. $contextpage = 'contactprospectlist';
  133. }
  134. $title .= ' ('.$langs->trans("ThirdPartyProspects").')';
  135. $urlfiche = "card.php";
  136. }
  137. if ($type == "c") {
  138. if (empty($contextpage) || $contextpage == 'contactlist') {
  139. $contextpage = 'contactcustomerlist';
  140. }
  141. $title .= ' ('.$langs->trans("ThirdPartyCustomers").')';
  142. $urlfiche = "card.php";
  143. } elseif ($type == "f") {
  144. if (empty($contextpage) || $contextpage == 'contactlist') {
  145. $contextpage = 'contactsupplierlist';
  146. }
  147. $title .= ' ('.$langs->trans("ThirdPartySuppliers").')';
  148. $urlfiche = "card.php";
  149. } elseif ($type == "o") {
  150. if (empty($contextpage) || $contextpage == 'contactlist') {
  151. $contextpage = 'contactotherlist';
  152. }
  153. $title .= ' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
  154. $urlfiche = "";
  155. }
  156. // Initialize technical object
  157. $object = new Contact($db);
  158. $extrafields = new ExtraFields($db);
  159. $hookmanager->initHooks(array($contextpage));
  160. // fetch optionals attributes and labels
  161. $extrafields->fetch_name_optionals_label($object->table_element);
  162. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  163. // List of fields to search into when doing a "search in all"
  164. $fieldstosearchall = array();
  165. foreach ($object->fields as $key => $val) {
  166. // don't allow search in private notes for external users when doing "search in all"
  167. if (!empty($user->socid) && $key == "note_private") {
  168. continue;
  169. }
  170. if (empty($val['searchall'])) {
  171. continue;
  172. }
  173. $fieldstosearchall['p.'.$key] = $val['label'];
  174. }
  175. // Add none object fields for "search in all"
  176. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  177. $fieldstosearchall['s.nom'] = "ThirdParty";
  178. $fieldstosearchall['s.name_alias'] = "AliasNames";
  179. }
  180. $parameters = array('fieldstosearchall'=>$fieldstosearchall);
  181. $reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  182. if ($reshook > 0) {
  183. $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
  184. } elseif ($reshook == 0) {
  185. $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
  186. }
  187. // Definition of array of fields for columns
  188. $arrayfields = array();
  189. foreach ($object->fields as $key => $val) {
  190. // If $val['visible']==0, then we never show the field
  191. if (!empty($val['visible'])) {
  192. $visible = (int) dol_eval($val['visible'], 1);
  193. $arrayfields['p.'.$key] = array(
  194. 'label'=>$val['label'],
  195. 'checked'=>(($visible < 0) ? 0 : 1),
  196. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  197. 'position'=>$val['position'],
  198. 'help'=> isset($val['help']) ? $val['help'] : ''
  199. );
  200. }
  201. }
  202. // Add none object fields to fields for list
  203. $arrayfields['country.code_iso'] = array('label'=>"Country", 'position'=>66, 'checked'=>0);
  204. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  205. $arrayfields['s.nom'] = array('label'=>"ThirdParty", 'position'=>113, 'checked'=> 1);
  206. $arrayfields['s.name_alias'] = array('label'=>"AliasNameShort", 'position'=>114, 'checked'=> 1);
  207. }
  208. $arrayfields['unsubscribed'] = array(
  209. 'label'=>'No_Email',
  210. 'checked'=>0,
  211. 'enabled'=>(isModEnabled('mailing')),
  212. 'position'=>111);
  213. if (isModEnabled('socialnetworks')) {
  214. foreach ($socialnetworks as $key => $value) {
  215. if ($value['active']) {
  216. $arrayfields['p.'.$key] = array(
  217. 'label' => $value['label'],
  218. 'checked' => 0,
  219. 'position' => 300
  220. );
  221. }
  222. }
  223. }
  224. // Extra fields
  225. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  226. $object->fields = dol_sort_array($object->fields, 'position');
  227. //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
  228. $arrayfields = dol_sort_array($arrayfields, 'position');
  229. if (($id > 0 || !empty($ref)) && $action != 'add') {
  230. $result = $object->fetch($id, $ref);
  231. if ($result < 0) {
  232. dol_print_error($db);
  233. }
  234. }
  235. $permissiontoread = $user->hasRight('societe', 'lire');
  236. $permissiontodelete = $user->hasRight('societe', 'supprimer');
  237. $permissiontoadd = $user->hasRight('societe', 'creer');
  238. if (!$permissiontoread) accessforbidden();
  239. /*
  240. * Actions
  241. */
  242. if (GETPOST('cancel', 'alpha')) {
  243. $action = 'list';
  244. $massaction = '';
  245. }
  246. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  247. $massaction = '';
  248. }
  249. $parameters = array();
  250. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  251. if ($reshook < 0) {
  252. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  253. }
  254. if (empty($reshook)) {
  255. // Selection of new fields
  256. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  257. // Purge search criteria
  258. 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
  259. $search_all = "";
  260. $search_id = '';
  261. $search_firstlast_only = "";
  262. $search_lastname = "";
  263. $search_firstname = "";
  264. $search_societe = "";
  265. $search_societe_alias = "";
  266. $search_town = "";
  267. $search_address = "";
  268. $search_zip = "";
  269. $search_country = "";
  270. $search_poste = "";
  271. $search_phone = "";
  272. $search_phone_perso = "";
  273. $search_phone_pro = "";
  274. $search_phone_mobile = "";
  275. $search_fax = "";
  276. $search_email = "";
  277. $search_no_email = -1;
  278. if (isModEnabled('socialnetworks')) {
  279. foreach ($socialnetworks as $key => $value) {
  280. if ($value['active']) {
  281. $search_[$key] = "";
  282. }
  283. }
  284. }
  285. $search_priv = "";
  286. $search_stcomm = '';
  287. $search_level = '';
  288. $search_status = -1;
  289. $search_categ = '';
  290. $search_categ_thirdparty = '';
  291. $search_categ_supplier = '';
  292. $search_import_key = '';
  293. $toselect = array();
  294. $search_array_options = array();
  295. $search_roles = array();
  296. }
  297. // Mass actions
  298. $objectclass = 'Contact';
  299. $objectlabel = 'Contact';
  300. $uploaddir = $conf->societe->dir_output;
  301. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  302. if ($action == 'setstcomm') {
  303. $object = new Contact($db);
  304. $result = $object->fetch(GETPOST('stcommcontactid'));
  305. $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
  306. $result = $object->update($object->id, $user);
  307. if ($result < 0) {
  308. setEventMessages($object->error, $object->errors, 'errors');
  309. }
  310. $action = '';
  311. }
  312. }
  313. if ($search_priv < 0) {
  314. $search_priv = '';
  315. }
  316. /*
  317. * View
  318. */
  319. $form = new Form($db);
  320. $formother = new FormOther($db);
  321. $formcompany = new FormCompany($db);
  322. $contactstatic = new Contact($db);
  323. $now = dol_now();
  324. $title = $langs->trans("Contacts")." - ".$langs->trans("List");
  325. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
  326. $morejs = array();
  327. $morecss = array();
  328. if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
  329. $contactstatic->loadCacheOfProspStatus();
  330. }
  331. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  332. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  333. // Select every potentiels, and note each potentiels which fit in search parameters
  334. $tab_level = array();
  335. $sql = "SELECT code, label, sortorder";
  336. $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectcontactlevel";
  337. $sql .= " WHERE active > 0";
  338. $sql .= " ORDER BY sortorder";
  339. $resql = $db->query($sql);
  340. if ($resql) {
  341. while ($obj = $db->fetch_object($resql)) {
  342. // Compute level text
  343. $level = $langs->trans($obj->code);
  344. if ($level == $obj->code) {
  345. $level = $langs->trans($obj->label);
  346. }
  347. $tab_level[$obj->code] = $level;
  348. }
  349. } else {
  350. dol_print_error($db);
  351. }
  352. // Build and execute select
  353. // --------------------------------------------------------------------
  354. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias as alias,";
  355. $sql .= " p.rowid, p.lastname as lastname, p.statut, p.firstname, p.address, p.zip, p.town, p.poste, p.email,";
  356. $sql .= " p.socialnetworks, p.photo,";
  357. $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,";
  358. $sql .= " p.import_key, p.fk_stcommcontact as stcomm_id, p.fk_prospectlevel,";
  359. $sql .= " st.libelle as stcomm, st.picto as stcomm_picto,";
  360. $sql .= " co.label as country, co.code as country_code";
  361. // Add fields from extrafields
  362. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  363. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  364. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  365. }
  366. }
  367. if (isModEnabled('mailing')) {
  368. $sql .= ", (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) as unsubscribed";
  369. }
  370. // Add fields from hooks
  371. $parameters = array();
  372. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  373. $sql .= $hookmanager->resPrint;
  374. $sql = preg_replace('/,\s*$/', '', $sql);
  375. $sqlfields = $sql; // $sql fields to remove for count total
  376. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  377. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  378. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
  379. }
  380. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays";
  381. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  382. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_stcommcontact as st ON st.id = p.fk_stcommcontact";
  383. if (empty($user->rights->societe->client->voir) && !$socid) {
  384. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  385. }
  386. // Add fields from hooks - ListFrom
  387. $parameters = array();
  388. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  389. $sql .= $hookmanager->resPrint;
  390. $sql .= ' WHERE p.entity IN ('.getEntity('contact').')';
  391. if (empty($user->rights->societe->client->voir) && !$socid) { //restriction
  392. $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR p.fk_soc IS NULL)";
  393. }
  394. if (!empty($userid)) { // propre au commercial
  395. $sql .= " AND p.fk_user_creat=".((int) $userid);
  396. }
  397. if ($search_level) {
  398. $sql .= natural_search("p.fk_prospectlevel", join(',', $search_level), 3);
  399. }
  400. if ($search_stcomm != '' && $search_stcomm != -2) {
  401. $sql .= natural_search("p.fk_stcommcontact", $search_stcomm, 2);
  402. }
  403. // Filter to exclude not owned private contacts
  404. if ($search_priv != '0' && $search_priv != '1') {
  405. $sql .= " AND (p.priv='0' OR (p.priv='1' AND p.fk_user_creat=".((int) $user->id)."))";
  406. } else {
  407. if ($search_priv == '0') {
  408. $sql .= " AND p.priv='0'";
  409. }
  410. if ($search_priv == '1') {
  411. $sql .= " AND (p.priv='1' AND p.fk_user_creat=".((int) $user->id).")";
  412. }
  413. }
  414. // Search Contact Categories
  415. $searchCategoryContactList = $search_categ ? array($search_categ) : array();
  416. $searchCategoryContactOperator = 0;
  417. // Search for tag/category ($searchCategoryContactList is an array of ID)
  418. if (!empty($searchCategoryContactList)) {
  419. $searchCategoryContactSqlList = array();
  420. $listofcategoryid = '';
  421. foreach ($searchCategoryContactList as $searchCategoryContact) {
  422. if (intval($searchCategoryContact) == -2) {
  423. $searchCategoryContactSqlList[] = "NOT EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople)";
  424. } elseif (intval($searchCategoryContact) > 0) {
  425. if ($searchCategoryContactOperator == 0) {
  426. $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople AND ck.fk_categorie = ".((int) $searchCategoryContact).")";
  427. } else {
  428. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryContact);
  429. }
  430. }
  431. }
  432. if ($listofcategoryid) {
  433. $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  434. }
  435. if ($searchCategoryContactOperator == 1) {
  436. if (!empty($searchCategoryContactSqlList)) {
  437. $sql .= " AND (".implode(' OR ', $searchCategoryContactSqlList).")";
  438. }
  439. } else {
  440. if (!empty($searchCategoryContactSqlList)) {
  441. $sql .= " AND (".implode(' AND ', $searchCategoryContactSqlList).")";
  442. }
  443. }
  444. }
  445. // Search Customer Categories
  446. $searchCategoryCustomerList = $search_categ_thirdparty ? array($search_categ_thirdparty) : array();
  447. $searchCategoryCustomerOperator = 0;
  448. // Search for tag/category ($searchCategoryCustomerList is an array of ID)
  449. if (!empty($searchCategoryCustomerList)) {
  450. $searchCategoryCustomerSqlList = array();
  451. $listofcategoryid = '';
  452. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  453. if (intval($searchCategoryCustomer) == -2) {
  454. $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
  455. } elseif (intval($searchCategoryCustomer) > 0) {
  456. if ($searchCategoryCustomerOperator == 0) {
  457. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategoryCustomer).")";
  458. } else {
  459. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
  460. }
  461. }
  462. }
  463. if ($listofcategoryid) {
  464. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  465. }
  466. if ($searchCategoryCustomerOperator == 1) {
  467. if (!empty($searchCategoryCustomerSqlList)) {
  468. $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
  469. }
  470. } else {
  471. if (!empty($searchCategoryCustomerSqlList)) {
  472. $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
  473. }
  474. }
  475. }
  476. // Search Supplier Categories
  477. $searchCategorySupplierList = $search_categ_supplier ? array($search_categ_supplier) : array();
  478. $searchCategorySupplierOperator = 0;
  479. // Search for tag/category ($searchCategorySupplierList is an array of ID)
  480. if (!empty($searchCategorySupplierList)) {
  481. $searchCategorySupplierSqlList = array();
  482. $listofcategoryid = '';
  483. foreach ($searchCategorySupplierList as $searchCategorySupplier) {
  484. if (intval($searchCategorySupplier) == -2) {
  485. $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
  486. } elseif (intval($searchCategorySupplier) > 0) {
  487. if ($searchCategorySupplierOperator == 0) {
  488. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategorySupplier).")";
  489. } else {
  490. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
  491. }
  492. }
  493. }
  494. if ($listofcategoryid) {
  495. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  496. }
  497. if ($searchCategorySupplierOperator == 1) {
  498. if (!empty($searchCategorySupplierSqlList)) {
  499. $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
  500. }
  501. } else {
  502. if (!empty($searchCategorySupplierSqlList)) {
  503. $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
  504. }
  505. }
  506. }
  507. if ($search_all) {
  508. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  509. }
  510. if (strlen($search_phone)) {
  511. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_phone);
  512. }
  513. if (strlen($search_cti)) {
  514. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_cti);
  515. }
  516. if (strlen($search_firstlast_only)) {
  517. $sql .= natural_search(array('p.lastname', 'p.firstname'), $search_firstlast_only);
  518. }
  519. if ($search_id > 0) {
  520. $sql .= natural_search('p.rowid', $search_id, 1);
  521. }
  522. if ($search_lastname) {
  523. $sql .= natural_search('p.lastname', $search_lastname);
  524. }
  525. if ($search_firstname) {
  526. $sql .= natural_search('p.firstname', $search_firstname);
  527. }
  528. if (empty($arrayfields['s.name_alias']['checked']) && $search_societe) {
  529. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_societe);
  530. } else {
  531. if ($search_societe) {
  532. $sql .= natural_search('s.nom', $search_societe);
  533. }
  534. if ($search_societe_alias) {
  535. $sql .= natural_search('s.name_alias', $search_societe_alias);
  536. }
  537. }
  538. if ($search_country) {
  539. $sql .= " AND p.fk_pays IN (".$db->sanitize($search_country).')';
  540. }
  541. if (strlen($search_poste)) {
  542. $sql .= natural_search('p.poste', $search_poste);
  543. }
  544. if (strlen($search_phone_perso)) {
  545. $sql .= natural_search('p.phone_perso', $search_phone_perso);
  546. }
  547. if (strlen($search_phone_pro)) {
  548. $sql .= natural_search('p.phone', $search_phone_pro);
  549. }
  550. if (strlen($search_phone_mobile)) {
  551. $sql .= natural_search('p.phone_mobile', $search_phone_mobile);
  552. }
  553. if (strlen($search_fax)) {
  554. $sql .= natural_search('p.fax', $search_fax);
  555. }
  556. if (isModEnabled('socialnetworks')) {
  557. foreach ($socialnetworks as $key => $value) {
  558. if ($value['active'] && strlen($search_[$key])) {
  559. $searchkeyinjsonformat = preg_replace('/"$/', '', preg_replace('/^"/', '', json_encode($search_[$key])));
  560. if (in_array($db->type, array('mysql', 'mysqli'))) {
  561. $sql .= " AND p.socialnetworks REGEXP '\"".$db->escape($db->escapeforlike($key))."\":\"[^\"]*".$db->escape($db->escapeforlike($searchkeyinjsonformat))."'";
  562. } elseif ($db->type == 'pgsql') {
  563. $sql .= " AND p.socialnetworks ~ '\"".$db->escape($db->escapeforlike($key))."\":\"[^\"]*".$db->escape($db->escapeforlike($searchkeyinjsonformat))."'";
  564. } else {
  565. // Works with all database but not reliable because search only for social network code starting with earched value
  566. $sql .= " AND p.socialnetworks LIKE '%\"".$db->escape($db->escapeforlike($key))."\":\"".$db->escape($db->escapeforlike($searchkeyinjsonformat))."%'";
  567. }
  568. }
  569. }
  570. }
  571. //print $sql;
  572. if (strlen($search_email)) {
  573. $sql .= natural_search('p.email', $search_email);
  574. }
  575. if (strlen($search_address)) {
  576. $sql .= natural_search("p.address", $search_address);
  577. }
  578. if (strlen($search_zip)) {
  579. $sql .= natural_search("p.zip", $search_zip);
  580. }
  581. if (strlen($search_town)) {
  582. $sql .= natural_search("p.town", $search_town);
  583. }
  584. if (count($search_roles) > 0) {
  585. $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))."))";
  586. }
  587. if ($search_no_email != -1 && $search_no_email > 0) {
  588. $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) > 0";
  589. }
  590. if ($search_no_email != -1 && $search_no_email == 0) {
  591. $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0 AND p.email IS NOT NULL AND p.email <> ''";
  592. }
  593. if ($search_status != '' && $search_status >= 0) {
  594. $sql .= " AND p.statut = ".((int) $search_status);
  595. }
  596. if ($search_import_key) {
  597. $sql .= natural_search("p.import_key", $search_import_key);
  598. }
  599. if ($type == "o") { // filter on type
  600. $sql .= " AND p.fk_soc IS NULL";
  601. } elseif ($type == "f") { // filter on type
  602. $sql .= " AND s.fournisseur = 1";
  603. } elseif ($type == "c") { // filter on type
  604. $sql .= " AND s.client IN (1, 3)";
  605. } elseif ($type == "p") { // filter on type
  606. $sql .= " AND s.client IN (2, 3)";
  607. }
  608. if (!empty($socid)) {
  609. $sql .= " AND s.rowid = ".((int) $socid);
  610. }
  611. // Add where from extra fields
  612. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  613. // Add where from hooks
  614. $parameters = array();
  615. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  616. $sql .= $hookmanager->resPrint;
  617. //print $sql;
  618. // Count total nb of records
  619. $nbtotalofrecords = '';
  620. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  621. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  622. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  623. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  624. $resql = $db->query($sqlforcount);
  625. if ($resql) {
  626. $objforcount = $db->fetch_object($resql);
  627. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  628. } else {
  629. dol_print_error($db);
  630. }
  631. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  632. $page = 0;
  633. $offset = 0;
  634. }
  635. $db->free($resql);
  636. }
  637. // Complete request and execute it with limit
  638. if ($view == "recent") {
  639. $sql .= $db->order("p.datec", "DESC");
  640. } else {
  641. $sql .= $db->order($sortfield, $sortorder);
  642. }
  643. if ($limit) {
  644. $sql .= $db->plimit($limit + 1, $offset);
  645. }
  646. $resql = $db->query($sql);
  647. if (!$resql) {
  648. dol_print_error($db);
  649. exit;
  650. }
  651. $num = $db->num_rows($resql);
  652. // Direct jump if only one record found
  653. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($search_all != '' || $search_cti != '') && !$page) {
  654. $obj = $db->fetch_object($resql);
  655. $id = $obj->rowid;
  656. header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
  657. exit;
  658. }
  659. // Output page
  660. // --------------------------------------------------------------------
  661. // Page Header
  662. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  663. $arrayofselected = is_array($toselect) ? $toselect : array();
  664. $param = '';
  665. if (!empty($mode)) {
  666. $param .= '&mode='.urlencode($mode);
  667. }
  668. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  669. $param .= '&contextpage='.urlencode($contextpage);
  670. }
  671. if ($limit > 0 && $limit != $conf->liste_limit) {
  672. $param .= '&limit='.((int) $limit);
  673. }
  674. $param .= '&begin='.urlencode($begin).'&userid='.urlencode($userid).'&contactname='.urlencode($search_all);
  675. $param .= '&type='.urlencode($type).'&view='.urlencode($view);
  676. if (!empty($search_categ) && $search_categ != '-1') {
  677. $param .= '&search_categ='.urlencode($search_categ);
  678. }
  679. if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') {
  680. $param .= '&search_categ_thirdparty='.urlencode($search_categ_thirdparty);
  681. }
  682. if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') {
  683. $param .= '&search_categ_supplier='.urlencode($search_categ_supplier);
  684. }
  685. if ($search_all != '') {
  686. $param .= '&search_all='.urlencode($search_all);
  687. }
  688. if ($search_id > 0) {
  689. $param .= "&search_id=".urlencode($search_id);
  690. }
  691. if ($search_lastname != '') {
  692. $param .= '&search_lastname='.urlencode($search_lastname);
  693. }
  694. if ($search_firstname != '') {
  695. $param .= '&search_firstname='.urlencode($search_firstname);
  696. }
  697. if ($search_societe != '') {
  698. $param .= '&search_societe='.urlencode($search_societe);
  699. }
  700. if ($search_societe_alias != '') {
  701. $param .= '&search_societe_alias='.urlencode($search_societe_alias);
  702. }
  703. if ($search_address != '') {
  704. $param .= '&search_address='.urlencode($search_address);
  705. }
  706. if ($search_zip != '') {
  707. $param .= '&search_zip='.urlencode($search_zip);
  708. }
  709. if ($search_town != '') {
  710. $param .= '&search_town='.urlencode($search_town);
  711. }
  712. if ($search_country != '') {
  713. $param .= "&search_country=".urlencode($search_country);
  714. }
  715. if ($search_poste != '') {
  716. $param .= '&search_poste='.urlencode($search_poste);
  717. }
  718. if ($search_phone_pro != '') {
  719. $param .= '&search_phone_pro='.urlencode($search_phone_pro);
  720. }
  721. if ($search_phone_perso != '') {
  722. $param .= '&search_phone_perso='.urlencode($search_phone_perso);
  723. }
  724. if ($search_phone_mobile != '') {
  725. $param .= '&search_phone_mobile='.urlencode($search_phone_mobile);
  726. }
  727. if ($search_fax != '') {
  728. $param .= '&search_fax='.urlencode($search_fax);
  729. }
  730. if ($search_email != '') {
  731. $param .= '&search_email='.urlencode($search_email);
  732. }
  733. if ($search_no_email != '') {
  734. $param .= '&search_no_email='.urlencode($search_no_email);
  735. }
  736. if ($search_status != '') {
  737. $param .= '&search_status='.urlencode($search_status);
  738. }
  739. if ($search_priv == '0' || $search_priv == '1') {
  740. $param .= "&search_priv=".urlencode($search_priv);
  741. }
  742. if ($search_stcomm != '') {
  743. $param .= '&search_stcomm='.urlencode($search_stcomm);
  744. }
  745. if (is_array($search_level) && count($search_level)) {
  746. foreach ($search_level as $slevel) {
  747. $param .= '&search_level[]='.urlencode($slevel);
  748. }
  749. }
  750. if ($search_import_key != '') {
  751. $param .= '&search_import_key='.urlencode($search_import_key);
  752. }
  753. if ($optioncss != '') {
  754. $param .= '&optioncss='.urlencode($optioncss);
  755. }
  756. if (count($search_roles) > 0) {
  757. $param .= implode('&search_roles[]=', $search_roles);
  758. }
  759. // Add $param from extra fields
  760. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  761. // List of mass actions available
  762. $arrayofmassactions = array(
  763. 'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  764. // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  765. );
  766. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  767. if (!empty($permissiontodelete)) {
  768. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  769. }
  770. if (isModEnabled('category') && $user->hasRight('societe', 'creer')) {
  771. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  772. }
  773. if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
  774. $arrayofmassactions = array();
  775. }
  776. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  777. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  778. if ($optioncss != '') {
  779. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  780. }
  781. print '<input type="hidden" name="token" value="'.newToken().'">';
  782. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  783. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  784. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  785. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  786. //print '<input type="hidden" name="page" value="'.$page.'">';
  787. print '<input type="hidden" name="type" value="'.$type.'">';
  788. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  789. print '<input type="hidden" name="page_y" value="">';
  790. print '<input type="hidden" name="mode" value="'.$mode.'">';
  791. $newcardbutton = '';
  792. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  793. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  794. $newcardbutton .= dolGetButtonTitleSeparator();
  795. $newcardbutton .= dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create', '', $permissiontoadd);
  796. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'address', 0, $newcardbutton, '', $limit, 0, 0, 1);
  797. $topicmail = "Information";
  798. $modelmail = "contact";
  799. $objecttmp = new Contact($db);
  800. $trackid = 'ctc'.$object->id;
  801. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  802. if ($search_all) {
  803. $setupstring = '';
  804. foreach ($fieldstosearchall as $key => $val) {
  805. $fieldstosearchall[$key] = $langs->trans($val);
  806. $setupstring .= $key."=".$val.";";
  807. }
  808. print '<!-- Search done like if CONTACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  809. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  810. }
  811. if ($search_firstlast_only) {
  812. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_firstlast_only).$langs->trans("Lastname").", ".$langs->trans("Firstname").'</div>';
  813. }
  814. $moreforfilter = '';
  815. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  816. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  817. $moreforfilter .= '<div class="divsearchfield">';
  818. $tmptitle = $langs->trans('ContactCategoriesShort');
  819. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  820. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CONTACT, $search_categ, 'search_categ', 1, $tmptitle);
  821. $moreforfilter .= '</div>';
  822. if (empty($type) || $type == 'c' || $type == 'p') {
  823. $moreforfilter .= '<div class="divsearchfield">';
  824. $tmptitle = '';
  825. if ($type == 'c') {
  826. $tmptitle .= $langs->trans('CustomersCategoriesShort');
  827. } elseif ($type == 'p') {
  828. $tmptitle .= $langs->trans('ProspectsCategoriesShort');
  829. } else {
  830. $tmptitle .= $langs->trans('CustomersProspectsCategoriesShort');
  831. }
  832. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  833. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CUSTOMER, $search_categ_thirdparty, 'search_categ_thirdparty', 1, $tmptitle);
  834. $moreforfilter .= '</div>';
  835. }
  836. if (isModEnabled("fournisseur") && (empty($type) || $type == 'f')) {
  837. $moreforfilter .= '<div class="divsearchfield">';
  838. $tmptitle = $langs->trans('SuppliersCategoriesShort');
  839. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  840. $moreforfilter .= $formother->select_categories(Categorie::TYPE_SUPPLIER, $search_categ_supplier, 'search_categ_supplier', 1, $tmptitle);
  841. $moreforfilter .= '</div>';
  842. }
  843. }
  844. $moreforfilter .= '<div class="divsearchfield">';
  845. $moreforfilter .= $langs->trans('Roles').': ';
  846. $moreforfilter .= $formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
  847. $moreforfilter .= '</div>';
  848. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  849. print $moreforfilter;
  850. $parameters = array('type'=>$type);
  851. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  852. print $hookmanager->resPrint;
  853. print '</div>';
  854. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  855. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  856. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  857. print '<div class="div-table-responsive">';
  858. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  859. // Fields title search
  860. // --------------------------------------------------------------------
  861. print '<tr class="liste_titre_filter">';
  862. // Action column
  863. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  864. print '<td class="liste_titre center maxwidthsearch">';
  865. $searchpicto = $form->showFilterButtons('left');
  866. print $searchpicto;
  867. print '</td>';
  868. }
  869. if (!empty($arrayfields['p.rowid']['checked'])) {
  870. print '<td class="liste_titre">';
  871. print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
  872. print '</td>';
  873. }
  874. if (!empty($arrayfields['p.lastname']['checked'])) {
  875. print '<td class="liste_titre">';
  876. print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
  877. print '</td>';
  878. }
  879. if (!empty($arrayfields['p.firstname']['checked'])) {
  880. print '<td class="liste_titre">';
  881. print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
  882. print '</td>';
  883. }
  884. if (!empty($arrayfields['p.poste']['checked'])) {
  885. print '<td class="liste_titre">';
  886. print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
  887. print '</td>';
  888. }
  889. if (!empty($arrayfields['p.address']['checked'])) {
  890. print '<td class="liste_titre">';
  891. print '<input class="flat" type="text" name="search_address" size="6" value="'.dol_escape_htmltag($search_address).'">';
  892. print '</td>';
  893. }
  894. if (!empty($arrayfields['p.zip']['checked'])) {
  895. print '<td class="liste_titre">';
  896. print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
  897. print '</td>';
  898. }
  899. if (!empty($arrayfields['p.town']['checked'])) {
  900. print '<td class="liste_titre">';
  901. print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
  902. print '</td>';
  903. }
  904. /*
  905. // State
  906. if (!empty($arrayfields['state.nom']['checked']))
  907. {
  908. print '<td class="liste_titre">';
  909. print '<input class="flat searchstring" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  910. print '</td>';
  911. }
  912. // Region
  913. if (!empty($arrayfields['region.nom']['checked']))
  914. {
  915. print '<td class="liste_titre">';
  916. print '<input class="flat searchstring" size="4" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
  917. print '</td>';
  918. }
  919. */
  920. // Country
  921. if (!empty($arrayfields['country.code_iso']['checked'])) {
  922. print '<td class="liste_titre center">';
  923. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  924. print '</td>';
  925. }
  926. if (!empty($arrayfields['p.phone']['checked'])) {
  927. print '<td class="liste_titre">';
  928. print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
  929. print '</td>';
  930. }
  931. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  932. print '<td class="liste_titre">';
  933. print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
  934. print '</td>';
  935. }
  936. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  937. print '<td class="liste_titre">';
  938. print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
  939. print '</td>';
  940. }
  941. if (!empty($arrayfields['p.fax']['checked'])) {
  942. print '<td class="liste_titre">';
  943. print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
  944. print '</td>';
  945. }
  946. if (!empty($arrayfields['p.email']['checked'])) {
  947. print '<td class="liste_titre">';
  948. print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
  949. print '</td>';
  950. }
  951. if (!empty($arrayfields['unsubscribed']['checked'])) {
  952. print '<td class="liste_titre center">';
  953. print $form->selectarray('search_no_email', array('-1'=>'', '0'=>$langs->trans('No'), '1'=>$langs->trans('Yes')), $search_no_email);
  954. print '</td>';
  955. }
  956. if (isModEnabled('socialnetworks')) {
  957. foreach ($socialnetworks as $key => $value) {
  958. if ($value['active']) {
  959. if (!empty($arrayfields['p.'.$key]['checked'])) {
  960. print '<td class="liste_titre">';
  961. print '<input class="flat" type="text" name="search_'.$key.'" size="6" value="'.dol_escape_htmltag($search_[$key]).'">';
  962. print '</td>';
  963. }
  964. }
  965. }
  966. }
  967. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  968. print '<td class="liste_titre">';
  969. print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  970. print '</td>';
  971. }
  972. // Alias of ThirdParty
  973. if (!empty($arrayfields['s.name_alias']['checked'])) {
  974. print '<td class="liste_titre" align="left">';
  975. print '<input class="flat maxwidth100" type="text" name="search_societe_alias" value="'.dol_escape_htmltag($search_societe_alias).'">';
  976. print '</td>';
  977. }
  978. if (!empty($arrayfields['p.priv']['checked'])) {
  979. print '<td class="liste_titre center">';
  980. $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
  981. print $form->selectarray('search_priv', $selectarray, $search_priv, 1);
  982. print '</td>';
  983. }
  984. // Prospect level
  985. if (!empty($arrayfields['p.fk_prospectlevel']['checked'])) {
  986. print '<td class="liste_titre center">';
  987. print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
  988. print '</td>';
  989. }
  990. // Prospect status
  991. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  992. print '<td class="liste_titre maxwidthonsmartphone center">';
  993. $arraystcomm = array();
  994. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  995. $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
  996. }
  997. print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', 'nowrap ');
  998. print '</td>';
  999. }
  1000. // Extra fields
  1001. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1002. // Fields from hook
  1003. $parameters = array('arrayfields'=>$arrayfields);
  1004. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1005. print $hookmanager->resPrint;
  1006. // Date creation
  1007. if (!empty($arrayfields['p.datec']['checked'])) {
  1008. print '<td class="liste_titre">';
  1009. print '</td>';
  1010. }
  1011. // Date modification
  1012. if (!empty($arrayfields['p.tms']['checked'])) {
  1013. print '<td class="liste_titre">';
  1014. print '</td>';
  1015. }
  1016. // Status
  1017. if (!empty($arrayfields['p.statut']['checked'])) {
  1018. print '<td class="liste_titre center parentonrightofpage">';
  1019. print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $search_status, 0, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
  1020. print '</td>';
  1021. }
  1022. if (!empty($arrayfields['p.import_key']['checked'])) {
  1023. print '<td class="liste_titre center">';
  1024. print '<input class="flat searchstring" type="text" name="search_import_key" size="3" value="'.dol_escape_htmltag($search_import_key).'">';
  1025. print '</td>';
  1026. }
  1027. // Action column
  1028. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1029. print '<td class="liste_titre center maxwidthsearch">';
  1030. $searchpicto = $form->showFilterButtons();
  1031. print $searchpicto;
  1032. print '</td>';
  1033. }
  1034. print '</tr>'."\n";
  1035. $totalarray = array();
  1036. $totalarray['nbfield'] = 0;
  1037. // Fields title label
  1038. // --------------------------------------------------------------------
  1039. print '<tr class="liste_titre">';
  1040. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1041. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1042. $totalarray['nbfield']++;
  1043. }
  1044. if (!empty($arrayfields['p.rowid']['checked'])) {
  1045. print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
  1046. $totalarray['nbfield']++;
  1047. }
  1048. if (!empty($arrayfields['p.lastname']['checked'])) {
  1049. print_liste_field_titre($arrayfields['p.lastname']['label'], $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, '', $sortfield, $sortorder);
  1050. $totalarray['nbfield']++;
  1051. }
  1052. if (!empty($arrayfields['p.firstname']['checked'])) {
  1053. print_liste_field_titre($arrayfields['p.firstname']['label'], $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, '', $sortfield, $sortorder);
  1054. $totalarray['nbfield']++;
  1055. }
  1056. if (!empty($arrayfields['p.poste']['checked'])) {
  1057. print_liste_field_titre($arrayfields['p.poste']['label'], $_SERVER["PHP_SELF"], "p.poste", $begin, $param, '', $sortfield, $sortorder);
  1058. $totalarray['nbfield']++;
  1059. }
  1060. if (!empty($arrayfields['p.address']['checked'])) {
  1061. print_liste_field_titre($arrayfields['p.address']['label'], $_SERVER["PHP_SELF"], "p.address", $begin, $param, '', $sortfield, $sortorder);
  1062. $totalarray['nbfield']++;
  1063. }
  1064. if (!empty($arrayfields['p.zip']['checked'])) {
  1065. print_liste_field_titre($arrayfields['p.zip']['label'], $_SERVER["PHP_SELF"], "p.zip", $begin, $param, '', $sortfield, $sortorder);
  1066. $totalarray['nbfield']++;
  1067. }
  1068. if (!empty($arrayfields['p.town']['checked'])) {
  1069. print_liste_field_titre($arrayfields['p.town']['label'], $_SERVER["PHP_SELF"], "p.town", $begin, $param, '', $sortfield, $sortorder);
  1070. $totalarray['nbfield']++;
  1071. }
  1072. //if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  1073. //if (!empty($arrayfields['region.nom']['checked'])) print_liste_field_titre($arrayfields['region.nom']['label'],$_SERVER["PHP_SELF"],"region.nom","",$param,'',$sortfield,$sortorder);
  1074. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1075. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "co.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1076. $totalarray['nbfield']++;
  1077. }
  1078. if (!empty($arrayfields['p.phone']['checked'])) {
  1079. print_liste_field_titre($arrayfields['p.phone']['label'], $_SERVER["PHP_SELF"], "p.phone", $begin, $param, '', $sortfield, $sortorder);
  1080. $totalarray['nbfield']++;
  1081. }
  1082. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  1083. print_liste_field_titre($arrayfields['p.phone_perso']['label'], $_SERVER["PHP_SELF"], "p.phone_perso", $begin, $param, '', $sortfield, $sortorder);
  1084. $totalarray['nbfield']++;
  1085. }
  1086. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  1087. print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder);
  1088. $totalarray['nbfield']++;
  1089. }
  1090. if (!empty($arrayfields['p.fax']['checked'])) {
  1091. print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder);
  1092. $totalarray['nbfield']++;
  1093. }
  1094. if (!empty($arrayfields['p.email']['checked'])) {
  1095. print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder);
  1096. $totalarray['nbfield']++;
  1097. }
  1098. if (!empty($arrayfields['unsubscribed']['checked'])) {
  1099. print_liste_field_titre($arrayfields['unsubscribed']['label'], $_SERVER["PHP_SELF"], "unsubscribed", $begin, $param, '', $sortfield, $sortorder, 'center ');
  1100. $totalarray['nbfield']++;
  1101. }
  1102. if (isModEnabled('socialnetworks')) {
  1103. foreach ($socialnetworks as $key => $value) {
  1104. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  1105. print_liste_field_titre($arrayfields['p.'.$key]['label'], $_SERVER["PHP_SELF"], "p.".$key, $begin, $param, '', $sortfield, $sortorder);
  1106. $totalarray['nbfield']++;
  1107. }
  1108. }
  1109. }
  1110. if (!empty($arrayfields['p.fk_soc']['checked'])) {
  1111. print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER["PHP_SELF"], "p.fk_soc", $begin, $param, '', $sortfield, $sortorder);
  1112. $totalarray['nbfield']++;
  1113. }
  1114. if (!empty($arrayfields['s.nom']['checked'])) {
  1115. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $begin, $param, '', $sortfield, $sortorder);
  1116. $totalarray['nbfield']++;
  1117. }
  1118. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1119. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", $begin, $param, '', $sortfield, $sortorder);
  1120. $totalarray['nbfield']++;
  1121. }
  1122. if (!empty($arrayfields['p.priv']['checked'])) {
  1123. print_liste_field_titre($arrayfields['p.priv']['label'], $_SERVER["PHP_SELF"], "p.priv", $begin, $param, '', $sortfield, $sortorder, 'center ');
  1124. $totalarray['nbfield']++;
  1125. }
  1126. if (!empty($arrayfields['p.fk_prospectlevel']['checked'])) {
  1127. print_liste_field_titre($arrayfields['p.fk_prospectlevel']['label'], $_SERVER["PHP_SELF"], "p.fk_prospectlevel", "", $param, '', $sortfield, $sortorder, 'center ');
  1128. $totalarray['nbfield']++;
  1129. }
  1130. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  1131. print_liste_field_titre($arrayfields['p.fk_stcommcontact']['label'], $_SERVER["PHP_SELF"], "p.fk_stcommcontact", "", $param, '', $sortfield, $sortorder, 'center ');
  1132. $totalarray['nbfield']++;
  1133. }
  1134. // Extra fields
  1135. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1136. // Hook fields
  1137. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  1138. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1139. print $hookmanager->resPrint;
  1140. if (!empty($arrayfields['p.datec']['checked'])) {
  1141. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1142. $totalarray['nbfield']++;
  1143. }
  1144. if (!empty($arrayfields['p.tms']['checked'])) {
  1145. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1146. $totalarray['nbfield']++;
  1147. }
  1148. if (!empty($arrayfields['p.statut']['checked'])) {
  1149. print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1150. $totalarray['nbfield']++;
  1151. }
  1152. if (!empty($arrayfields['p.import_key']['checked'])) {
  1153. print_liste_field_titre($arrayfields['p.import_key']['label'], $_SERVER["PHP_SELF"], "p.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  1154. $totalarray['nbfield']++;
  1155. }
  1156. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  1157. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1158. $totalarray['nbfield']++;
  1159. }
  1160. print "</tr>\n";
  1161. // Loop on record
  1162. // --------------------------------------------------------------------
  1163. $i = 0;
  1164. $savnbfield = $totalarray['nbfield'];
  1165. $totalarray = array();
  1166. $totalarray['nbfield'] = 0;
  1167. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1168. while ($i < $imaxinloop) {
  1169. $obj = $db->fetch_object($resql);
  1170. if (empty($obj)) {
  1171. break; // Should not happen
  1172. }
  1173. $arraysocialnetworks = (array) json_decode($obj->socialnetworks, true);
  1174. $contactstatic->lastname = $obj->lastname;
  1175. $contactstatic->firstname = '';
  1176. $contactstatic->id = $obj->rowid;
  1177. $contactstatic->statut = $obj->statut;
  1178. $contactstatic->poste = $obj->poste;
  1179. $contactstatic->email = $obj->email;
  1180. $contactstatic->phone_pro = $obj->phone_pro;
  1181. $contactstatic->phone_perso = $obj->phone_perso;
  1182. $contactstatic->phone_mobile = $obj->phone_mobile;
  1183. $contactstatic->address = $obj->address;
  1184. $contactstatic->zip = $obj->zip;
  1185. $contactstatic->town = $obj->town;
  1186. $contactstatic->socialnetworks = $arraysocialnetworks;
  1187. $contactstatic->country = $obj->country;
  1188. $contactstatic->country_code = $obj->country_code;
  1189. $contactstatic->photo = $obj->photo;
  1190. $contactstatic->import_key = $obj->import_key;
  1191. $contactstatic->photo = $obj->photo;
  1192. $contactstatic->fk_prospectlevel = $obj->fk_prospectlevel;
  1193. if ($mode == 'kanban') {
  1194. if ($i == 0) {
  1195. print '<tr><td colspan="'.$savnbfield.'">';
  1196. print '<div class="box-flex-container kanban">';
  1197. }
  1198. // Output Kanban
  1199. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1200. $selected = 0;
  1201. if (in_array($object->id, $arrayofselected)) {
  1202. $selected = 1;
  1203. }
  1204. }
  1205. if ($obj->socid > 0) {
  1206. $contactstatic->fetch_thirdparty($obj->socid);
  1207. }
  1208. print $contactstatic->getKanbanView('', array('selected' => in_array($contactstatic->id, $arrayofselected)));
  1209. if ($i == ($imaxinloop - 1)) {
  1210. print '</div>';
  1211. print '</td></tr>';
  1212. }
  1213. } else {
  1214. // Show here line of result
  1215. $j = 0;
  1216. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  1217. // Action column
  1218. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1219. print '<td class="nowrap center">';
  1220. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1221. $selected = 0;
  1222. if (in_array($obj->rowid, $arrayofselected)) {
  1223. $selected = 1;
  1224. }
  1225. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1226. }
  1227. print '</td>';
  1228. if (!$i) {
  1229. $totalarray['nbfield']++;
  1230. }
  1231. }
  1232. // ID
  1233. if (!empty($arrayfields['p.rowid']['checked'])) {
  1234. print '<td class="tdoverflowmax50">';
  1235. print dol_escape_htmltag($obj->rowid);
  1236. print "</td>\n";
  1237. if (!$i) {
  1238. $totalarray['nbfield']++;
  1239. }
  1240. }
  1241. // (Last) Name
  1242. if (!empty($arrayfields['p.lastname']['checked'])) {
  1243. print '<td class="middle tdoverflowmax150">';
  1244. print $contactstatic->getNomUrl(1);
  1245. print '</td>';
  1246. if (!$i) {
  1247. $totalarray['nbfield']++;
  1248. }
  1249. }
  1250. // Firstname
  1251. if (!empty($arrayfields['p.firstname']['checked'])) {
  1252. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
  1253. if (!$i) {
  1254. $totalarray['nbfield']++;
  1255. }
  1256. }
  1257. // Job position
  1258. if (!empty($arrayfields['p.poste']['checked'])) {
  1259. print '<td class="tdoverflowmax100">'.dol_escape_htmltag($obj->poste).'</td>';
  1260. if (!$i) {
  1261. $totalarray['nbfield']++;
  1262. }
  1263. }
  1264. // Address
  1265. if (!empty($arrayfields['p.address']['checked'])) {
  1266. print '<td>'.dol_escape_htmltag($obj->address).'</td>';
  1267. if (!$i) {
  1268. $totalarray['nbfield']++;
  1269. }
  1270. }
  1271. // Zip
  1272. if (!empty($arrayfields['p.zip']['checked'])) {
  1273. print '<td>'.dol_escape_htmltag($obj->zip).'</td>';
  1274. if (!$i) {
  1275. $totalarray['nbfield']++;
  1276. }
  1277. }
  1278. // Town
  1279. if (!empty($arrayfields['p.town']['checked'])) {
  1280. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">'.dol_escape_htmltag($obj->town).'</td>';
  1281. if (!$i) {
  1282. $totalarray['nbfield']++;
  1283. }
  1284. }
  1285. /*
  1286. // State
  1287. if (!empty($arrayfields['state.nom']['checked']))
  1288. {
  1289. print "<td>".$obj->state_name."</td>\n";
  1290. if (! $i) $totalarray['nbfield']++;
  1291. }
  1292. // Region
  1293. if (!empty($arrayfields['region.nom']['checked']))
  1294. {
  1295. print "<td>".$obj->region_name."</td>\n";
  1296. if (! $i) $totalarray['nbfield']++;
  1297. }*/
  1298. // Country
  1299. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1300. print '<td class="center">';
  1301. $tmparray = getCountry($obj->fk_pays, 'all');
  1302. print dol_escape_htmltag($tmparray['label']);
  1303. print '</td>';
  1304. if (!$i) {
  1305. $totalarray['nbfield']++;
  1306. }
  1307. }
  1308. // Phone pro
  1309. if (!empty($arrayfields['p.phone']['checked'])) {
  1310. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1311. if (!$i) {
  1312. $totalarray['nbfield']++;
  1313. }
  1314. }
  1315. // Phone perso
  1316. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  1317. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1318. if (!$i) {
  1319. $totalarray['nbfield']++;
  1320. }
  1321. }
  1322. // Phone mobile
  1323. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  1324. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'mobile').'</td>';
  1325. if (!$i) {
  1326. $totalarray['nbfield']++;
  1327. }
  1328. }
  1329. // Fax
  1330. if (!empty($arrayfields['p.fax']['checked'])) {
  1331. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'fax').'</td>';
  1332. if (!$i) {
  1333. $totalarray['nbfield']++;
  1334. }
  1335. }
  1336. // EMail
  1337. if (!empty($arrayfields['p.email']['checked'])) {
  1338. print '<td class="nowraponall tdoverflowmax300">'.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).'</td>';
  1339. if (!$i) {
  1340. $totalarray['nbfield']++;
  1341. }
  1342. }
  1343. // No EMail Subscription
  1344. if (!empty($arrayfields['unsubscribed']['checked'])) {
  1345. print '<td class="center">';
  1346. if (empty($obj->email)) {
  1347. //print '<span class="opacitymedium">'.$langs->trans("NoEmail").'</span>';
  1348. } else {
  1349. print yn(($obj->unsubscribed > 0) ? 1 : 0);
  1350. }
  1351. print '</td>';
  1352. if (!$i) {
  1353. $totalarray['nbfield']++;
  1354. }
  1355. }
  1356. // Social Networks
  1357. if (isModEnabled('socialnetworks')) {
  1358. foreach ($socialnetworks as $key => $value) {
  1359. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  1360. print '<td class="tdoverflowmax100">'.(empty($arraysocialnetworks[$key]) ? '' : dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks)).'</td>';
  1361. if (!$i) {
  1362. $totalarray['nbfield']++;
  1363. }
  1364. }
  1365. }
  1366. }
  1367. // Company / Third Party
  1368. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  1369. print '<td class="tdoverflowmax200">';
  1370. if ($obj->socid) {
  1371. $objsoc = new Societe($db);
  1372. $objsoc->fetch($obj->socid);
  1373. print $objsoc->getNomUrl(1, '', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1374. } else {
  1375. print '&nbsp;';
  1376. }
  1377. print '</td>';
  1378. if (!$i) {
  1379. $totalarray['nbfield']++;
  1380. }
  1381. }
  1382. // Alias name
  1383. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1384. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->alias).'">';
  1385. print dol_escape_htmltag($obj->alias);
  1386. print '</td>';
  1387. if (!$i) {
  1388. $totalarray['nbfield']++;
  1389. }
  1390. }
  1391. // Private/Public
  1392. if (!empty($arrayfields['p.priv']['checked'])) {
  1393. print '<td class="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
  1394. if (!$i) {
  1395. $totalarray['nbfield']++;
  1396. }
  1397. }
  1398. // Prospect Level
  1399. if (!empty($arrayfields['p.fk_prospectlevel']['checked'])) {
  1400. print '<td class="center">';
  1401. print $contactstatic->getLibProspLevel();
  1402. print "</td>";
  1403. if (!$i) {
  1404. $totalarray['nbfield']++;
  1405. }
  1406. }
  1407. // Prospect status
  1408. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  1409. print '<td class="center nowrap"><div class="nowrap">';
  1410. print '<div class="inline-block">'.$contactstatic->libProspCommStatut($obj->stcomm_id, 2, $contactstatic->cacheprospectstatus[$obj->stcomm_id]['label'], $obj->stcomm_picto);
  1411. print '</div> - <div class="inline-block">';
  1412. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  1413. $titlealt = 'default';
  1414. if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
  1415. $titlealt = $val['label'];
  1416. }
  1417. if ($obj->stcomm_id != $val['id']) {
  1418. 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>';
  1419. }
  1420. }
  1421. print '</div></div></td>';
  1422. if (!$i) {
  1423. $totalarray['nbfield']++;
  1424. }
  1425. }
  1426. // Extra fields
  1427. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1428. // Fields from hook
  1429. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1430. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1431. print $hookmanager->resPrint;
  1432. // Date creation
  1433. if (!empty($arrayfields['p.datec']['checked'])) {
  1434. print '<td class="center nowraponall">';
  1435. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1436. print '</td>';
  1437. if (!$i) {
  1438. $totalarray['nbfield']++;
  1439. }
  1440. }
  1441. // Date modification
  1442. if (!empty($arrayfields['p.tms']['checked'])) {
  1443. print '<td class="center nowraponall">';
  1444. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1445. print '</td>';
  1446. if (!$i) {
  1447. $totalarray['nbfield']++;
  1448. }
  1449. }
  1450. // Status
  1451. if (!empty($arrayfields['p.statut']['checked'])) {
  1452. print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
  1453. if (!$i) {
  1454. $totalarray['nbfield']++;
  1455. }
  1456. }
  1457. // Import key
  1458. if (!empty($arrayfields['p.import_key']['checked'])) {
  1459. print '<td class="tdoverflowmax100">';
  1460. print dol_escape_htmltag($obj->import_key);
  1461. print "</td>\n";
  1462. if (!$i) {
  1463. $totalarray['nbfield']++;
  1464. }
  1465. }
  1466. // Action column
  1467. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1468. print '<td class="nowrap center">';
  1469. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1470. $selected = 0;
  1471. if (in_array($obj->rowid, $arrayofselected)) {
  1472. $selected = 1;
  1473. }
  1474. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1475. }
  1476. print '</td>';
  1477. if (!$i) {
  1478. $totalarray['nbfield']++;
  1479. }
  1480. }
  1481. print '</tr>'."\n";
  1482. }
  1483. $i++;
  1484. }
  1485. // Show total line
  1486. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1487. // If no record found
  1488. if ($num == 0) {
  1489. $colspan = 1;
  1490. foreach ($arrayfields as $key => $val) {
  1491. if (!empty($val['checked'])) {
  1492. $colspan++;
  1493. }
  1494. }
  1495. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1496. }
  1497. $db->free($resql);
  1498. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1499. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1500. print $hookmanager->resPrint;
  1501. print '</table>'."\n";
  1502. print '</div>'."\n";
  1503. print '</form>'."\n";
  1504. // End of page
  1505. llxFooter();
  1506. $db->close();