list.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2016 Josep Lluis Amador <joseplluis@lliuretic.cat>
  9. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/societe/list.php
  26. * \ingroup societe
  27. * \brief Page to show list of third parties
  28. */
  29. require_once '../main.inc.php';
  30. include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  35. $langs->loadLangs(array("companies", "commercial", "customers", "suppliers", "bills", "compta", "commercial"));
  36. $action=GETPOST('action','alpha');
  37. $massaction=GETPOST('massaction','alpha');
  38. $show_files=GETPOST('show_files','int');
  39. $confirm=GETPOST('confirm','alpha');
  40. $toselect = GETPOST('toselect', 'array');
  41. // Security check
  42. $socid = GETPOST('socid','int');
  43. if ($user->societe_id) $socid=$user->societe_id;
  44. $result = restrictedArea($user,'societe',$socid,'');
  45. $search_all=trim(GETPOST('sall', 'alphanohtml'));
  46. $search_nom=trim(GETPOST("search_nom"));
  47. $search_nom_only=trim(GETPOST("search_nom_only"));
  48. $search_barcode=trim(GETPOST("sbarcode"));
  49. $search_customer_code=trim(GETPOST('search_customer_code'));
  50. $search_supplier_code=trim(GETPOST('search_supplier_code'));
  51. $search_account_customer_code=trim(GETPOST('search_account_customer_code'));
  52. $search_account_supplier_code=trim(GETPOST('search_account_supplier_code'));
  53. $search_town=trim(GETPOST("search_town"));
  54. $search_zip=trim(GETPOST("search_zip"));
  55. $search_state=trim(GETPOST("search_state"));
  56. $search_email=trim(GETPOST('search_email'));
  57. $search_phone=trim(GETPOST('search_phone'));
  58. $search_url=trim(GETPOST('search_url'));
  59. $search_idprof1=trim(GETPOST('search_idprof1'));
  60. $search_idprof2=trim(GETPOST('search_idprof2'));
  61. $search_idprof3=trim(GETPOST('search_idprof3'));
  62. $search_idprof4=trim(GETPOST('search_idprof4'));
  63. $search_idprof5=trim(GETPOST('search_idprof5'));
  64. $search_idprof6=trim(GETPOST('search_idprof6'));
  65. $search_sale=trim(GETPOST("search_sale",'int'));
  66. $search_categ=trim(GETPOST("search_categ",'int'));
  67. $search_country=GETPOST("search_country",'int');
  68. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  69. $search_status=GETPOST("search_status",'int');
  70. $search_type=GETPOST('search_type','alpha');
  71. $search_level_from = GETPOST("search_level_from","alpha");
  72. $search_level_to = GETPOST("search_level_to","alpha");
  73. $search_stcomm=GETPOST('search_stcomm','int');
  74. $type=GETPOST('type');
  75. $optioncss=GETPOST('optioncss','alpha');
  76. $mode=GETPOST("mode");
  77. $diroutputmassaction=$conf->societe->dir_output . '/temp/massgeneration/'.$user->id;
  78. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  79. $sortfield=GETPOST("sortfield",'alpha');
  80. $sortorder=GETPOST("sortorder",'alpha');
  81. $page=GETPOST("page",'int');
  82. if (! $sortorder) $sortorder="ASC";
  83. if (! $sortfield) $sortfield="s.nom";
  84. if (empty($page) || $page == -1) { $page = 0; }
  85. $offset = $limit * $page;
  86. $pageprev = $page - 1;
  87. $pagenext = $page + 1;
  88. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  89. $contextpage='thirdpartylist';
  90. /*if ($search_type == '1,3') { $contextpage='customerlist'; $type='c'; }
  91. if ($search_type == '2,3') { $contextpage='prospectlist'; $type='p'; }
  92. if ($search_type == '4') { $contextpage='supplierlist'; $type='f'; }
  93. */
  94. if ($type == 'c') { $contextpage='customerlist'; if ($search_type=='') $search_type='1,3'; }
  95. if ($type == 'p') { $contextpage='prospectlist'; if ($search_type=='') $search_type='2,3'; }
  96. if ($type == 'f') { $contextpage='supplierlist'; if ($search_type=='') $search_type='4'; }
  97. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  98. $hookmanager->initHooks(array($contextpage));
  99. $extrafields = new ExtraFields($db);
  100. // fetch optionals attributes and labels
  101. $extralabels = $extrafields->fetch_name_optionals_label('societe');
  102. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  103. // List of fields to search into when doing a "search in all"
  104. $fieldstosearchall = array(
  105. 's.nom'=>"ThirdPartyName",
  106. 's.name_alias'=>"AliasNameShort",
  107. 's.code_client'=>"CustomerCode",
  108. 's.code_fournisseur'=>"SupplierCode",
  109. 's.code_compta'=>"CustomerAccountancyCodeShort",
  110. 's.code_compta_fournisseur'=>"SupplierAccountancyCodeShort",
  111. 's.email'=>"EMail",
  112. 's.url'=>"URL",
  113. 's.tva_intra'=>"VATIntra",
  114. 's.siren'=>"ProfId1",
  115. 's.siret'=>"ProfId2",
  116. 's.ape'=>"ProfId3",
  117. );
  118. if (($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') $fieldstosearchall['s.idprof4']='ProfId4';
  119. if (($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') $fieldstosearchall['s.idprof5']='ProfId5';
  120. if (($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') $fieldstosearchall['s.idprof6']='ProfId6';
  121. if (!empty($conf->barcode->enabled)) $fieldstosearchall['s.barcode']='Gencod';
  122. // Define list of fields to show into list
  123. $checkedcustomercode=(in_array($contextpage, array('thirdpartylist', 'customerlist', 'prospectlist')) ? 1 : 0);
  124. $checkedsuppliercode=(in_array($contextpage, array('supplierlist')) ? 1 : 0);
  125. $checkedcustomeraccountcode=(in_array($contextpage, array('customerlist')) ? 1 : 0);
  126. $checkedsupplieraccountcode=(in_array($contextpage, array('supplierlist')) ? 1 : 0);
  127. $checkedtypetiers=1;
  128. $checkedprofid1=0;
  129. $checkedprofid2=0;
  130. $checkedprofid3=0;
  131. $checkedprofid4=0;
  132. $checkedprofid5=0;
  133. $checkedprofid6=0;
  134. //$checkedprofid4=((($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') ? 1 : 0);
  135. //$checkedprofid5=((($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') ? 1 : 0);
  136. //$checkedprofid6=((($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') ? 1 : 0);
  137. $checkprospectlevel=(in_array($contextpage, array('prospectlist')) ? 1 : 0);
  138. $checkstcomm=(in_array($contextpage, array('prospectlist')) ? 1 : 0);
  139. $arrayfields=array(
  140. 's.nom'=>array('label'=>"Company", 'checked'=>1),
  141. 's.barcode'=>array('label'=>"Gencod", 'checked'=>1, 'enabled'=>(! empty($conf->barcode->enabled))),
  142. 's.code_client'=>array('label'=>"CustomerCodeShort", 'checked'=>$checkedcustomercode),
  143. 's.code_fournisseur'=>array('label'=>"SupplierCodeShort", 'checked'=>$checkedsuppliercode, 'enabled'=>(! empty($conf->fournisseur->enabled))),
  144. 's.code_compta'=>array('label'=>"CustomerAccountancyCodeShort", 'checked'=>$checkedcustomeraccountcode),
  145. 's.code_compta_fournisseur'=>array('label'=>"SupplierAccountancyCodeShort", 'checked'=>$checkedsupplieraccountcode, 'enabled'=>(! empty($conf->fournisseur->enabled))),
  146. 's.town'=>array('label'=>"Town", 'checked'=>1),
  147. 's.zip'=>array('label'=>"Zip", 'checked'=>1),
  148. 'state.nom'=>array('label'=>"State", 'checked'=>0),
  149. 'country.code_iso'=>array('label'=>"Country", 'checked'=>0),
  150. 's.email'=>array('label'=>"Email", 'checked'=>0),
  151. 's.url'=>array('label'=>"Url", 'checked'=>0),
  152. 's.phone'=>array('label'=>"Phone", 'checked'=>1),
  153. 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers),
  154. 's.siren'=>array('label'=>"ProfId1Short", 'checked'=>$checkedprofid1),
  155. 's.siret'=>array('label'=>"ProfId2Short", 'checked'=>$checkedprofid2),
  156. 's.ape'=>array('label'=>"ProfId3Short", 'checked'=>$checkedprofid3),
  157. 's.idprof4'=>array('label'=>"ProfId4Short", 'checked'=>$checkedprofid4),
  158. 's.idprof5'=>array('label'=>"ProfId5Short", 'checked'=>$checkedprofid5),
  159. 's.idprof6'=>array('label'=>"ProfId6Short", 'checked'=>$checkedprofid6),
  160. 'customerorsupplier'=>array('label'=>'Nature', 'checked'=>1),
  161. 's.fk_prospectlevel'=>array('label'=>"ProspectLevelShort", 'checked'=>$checkprospectlevel),
  162. 's.fk_stcomm'=>array('label'=>"StatusProsp", 'checked'=>$checkstcomm),
  163. 's.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  164. 's.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  165. 's.status'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  166. );
  167. // Extra fields
  168. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  169. {
  170. foreach($extrafields->attribute_label as $key => $val)
  171. {
  172. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  173. }
  174. }
  175. $object = new Societe($db);
  176. /*
  177. * Actions
  178. */
  179. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  180. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  181. $parameters=array();
  182. $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  183. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  184. if (empty($reshook))
  185. {
  186. // Selection of new fields
  187. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  188. // Did we click on purge search criteria ?
  189. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
  190. {
  191. $search_nom='';
  192. $search_categ=0;
  193. $search_sale='';
  194. $search_barcode="";
  195. $search_customer_code='';
  196. $search_supplier_code='';
  197. $search_account_customer_code='';
  198. $search_account_supplier_code='';
  199. $search_town="";
  200. $search_zip="";
  201. $search_state="";
  202. $search_country='';
  203. $search_email='';
  204. $search_phone='';
  205. $search_url='';
  206. $search_idprof1='';
  207. $search_idprof2='';
  208. $search_idprof3='';
  209. $search_idprof4='';
  210. $search_idprof5='';
  211. $search_idprof6='';
  212. $search_type='';
  213. $search_type_thirdparty='';
  214. $search_status=-1;
  215. $search_stcomm='';
  216. $search_level_from='';
  217. $search_level_to='';
  218. $toselect='';
  219. $search_array_options=array();
  220. }
  221. // Mass actions
  222. $objectclass='Societe';
  223. $objectlabel='ThirdParty';
  224. $permtoread = $user->rights->societe->lire;
  225. $permtodelete = $user->rights->societe->supprimer;
  226. $uploaddir = $conf->societe->dir_output;
  227. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  228. if ($action == 'setstcomm')
  229. {
  230. $object = new Client($db);
  231. $result=$object->fetch(GETPOST('stcommsocid'));
  232. $object->stcomm_id=dol_getIdFromCode($db, GETPOST('stcomm','alpha'), 'c_stcomm');
  233. $result=$object->update($object->id, $user);
  234. if ($result < 0) setEventMessages($object->error,$object->errors,'errors');
  235. $action='';
  236. }
  237. }
  238. if ($search_status=='') $search_status=1; // always display active thirdparty first
  239. /*
  240. * View
  241. */
  242. /*
  243. REM: Rules on permissions to see thirdparties
  244. Internal or External user + No permission to see customers => See nothing
  245. Internal user socid=0 + Permission to see ALL customers => See all thirdparties
  246. Internal user socid=0 + No permission to see ALL customers => See only thirdparties linked to user that are sale representative
  247. External user socid=x + Permission to see ALL customers => Can see only himself
  248. External user socid=x + No permission to see ALL customers => Can see only himself
  249. */
  250. $form=new Form($db);
  251. $formother=new FormOther($db);
  252. $companystatic=new Societe($db);
  253. $formcompany=new FormCompany($db);
  254. $prospectstatic=new Client($db);
  255. $prospectstatic->client=2;
  256. $prospectstatic->loadCacheOfProspStatus();
  257. $title=$langs->trans("ListOfThirdParties");
  258. if ($type == 'c' && (empty($search_type) || ($search_type == '1,3'))) $title=$langs->trans("ListOfCustomers");
  259. if ($type == 'p' && (empty($search_type) || ($search_type == '2,3'))) $title=$langs->trans("ListOfProspects");
  260. if ($type == 'f' && (empty($search_type) || ($search_type == '4'))) $title=$langs->trans("ListOfSuppliers");
  261. // If both parameters are set, search for everything BETWEEN them
  262. if ($search_level_from != '' && $search_level_to != '')
  263. {
  264. // Ensure that these parameters are numbers
  265. $search_level_from = (int) $search_level_from;
  266. $search_level_to = (int) $search_level_to;
  267. // If from is greater than to, reverse orders
  268. if ($search_level_from > $search_level_to)
  269. {
  270. $tmp = $search_level_to;
  271. $search_level_to = $search_level_from;
  272. $search_level_from = $tmp;
  273. }
  274. // Generate the SQL request
  275. $sortwhere = '(sortorder BETWEEN '.$search_level_from.' AND '.$search_level_to.') AS is_in_range';
  276. }
  277. // If only "from" parameter is set, search for everything GREATER THAN it
  278. else if ($search_level_from != '')
  279. {
  280. // Ensure that this parameter is a number
  281. $search_level_from = (int) $search_level_from;
  282. // Generate the SQL request
  283. $sortwhere = '(sortorder >= '.$search_level_from.') AS is_in_range';
  284. }
  285. // If only "to" parameter is set, search for everything LOWER THAN it
  286. else if ($search_level_to != '')
  287. {
  288. // Ensure that this parameter is a number
  289. $search_level_to = (int) $search_level_to;
  290. // Generate the SQL request
  291. $sortwhere = '(sortorder <= '.$search_level_to.') AS is_in_range';
  292. }
  293. // If no parameters are set, dont search for anything
  294. else
  295. {
  296. $sortwhere = '0 as is_in_range';
  297. }
  298. // Select every potentiels, and note each potentiels which fit in search parameters
  299. dol_syslog('societe/list.php',LOG_DEBUG);
  300. $sql = "SELECT code, label, sortorder, ".$sortwhere;
  301. $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
  302. $sql.= " WHERE active > 0";
  303. $sql.= " ORDER BY sortorder";
  304. $resql = $db->query($sql);
  305. if ($resql)
  306. {
  307. $tab_level = array();
  308. $search_levels = array();
  309. while ($obj = $db->fetch_object($resql))
  310. {
  311. // Compute level text
  312. $level=$langs->trans($obj->code);
  313. if ($level == $obj->code) $level=$langs->trans($obj->label);
  314. // Put it in the array sorted by sortorder
  315. $tab_level[$obj->sortorder] = $level;
  316. // If this potentiel fit in parameters, add its code to the $search_levels array
  317. if ($obj->is_in_range == 1)
  318. {
  319. $search_levels[] = '"'.preg_replace('[^A-Za-z0-9_-]', '', $obj->code).'"';
  320. }
  321. }
  322. // Implode the $search_levels array so that it can be use in a "IN (...)" where clause.
  323. // If no paramters was set, $search_levels will be empty
  324. $search_levels = implode(',', $search_levels);
  325. }
  326. else dol_print_error($db);
  327. $sql = "SELECT s.rowid, s.nom as name, s.name_alias, s.barcode, s.town, s.zip, s.datec, s.code_client, s.code_fournisseur, ";
  328. $sql.= " st.libelle as stcomm, s.fk_stcomm as stcomm_id, s.fk_prospectlevel, s.prefix_comm, s.client, s.fournisseur, s.canvas, s.status as status,";
  329. $sql.= " s.email, s.phone, s.url, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4 as idprof4, s.fk_pays,";
  330. $sql.= " s.tms as date_update, s.datec as date_creation,";
  331. $sql.= " s.code_compta,s.code_compta_fournisseur,";
  332. $sql.= " typent.code as typent_code,";
  333. $sql.= " state.code_departement as state_code, state.nom as state_name";
  334. // We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
  335. if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user";
  336. // We'll need these fields in order to filter by categ
  337. if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_soc";
  338. // Add fields from extrafields
  339. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  340. // Add fields from hooks
  341. $parameters=array();
  342. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  343. $sql.=$hookmanager->resPrint;
  344. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  345. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as ef on (s.rowid = ef.fk_object)";
  346. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  347. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  348. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  349. // We'll need this table joined to the select in order to filter by categ
  350. if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_".($type=='f'?"fournisseur":"societe")." as cs ON s.rowid = cs.fk_soc"; // We'll need this table joined to the select in order to filter by categ
  351. $sql.= " ,".MAIN_DB_PREFIX."c_stcomm as st";
  352. // We'll need this table joined to the select in order to filter by sale
  353. if ($search_sale || (!$user->rights->societe->client->voir && !$socid)) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  354. $sql.= " WHERE s.fk_stcomm = st.id";
  355. $sql.= " AND s.entity IN (".getEntity('societe', 1).")";
  356. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  357. if ($socid) $sql.= " AND s.rowid = ".$socid;
  358. if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  359. if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
  360. if ($search_sale) $sql.= " AND sc.fk_user = ".$db->escape($search_sale);
  361. if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ);
  362. if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
  363. if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_all);
  364. if ($search_nom) $sql.= natural_search("s.nom",$search_nom);
  365. if ($search_nom_only) $sql.= natural_search("s.nom",$search_nom_only);
  366. if ($search_customer_code) $sql.= natural_search("s.code_client",$search_customer_code);
  367. if ($search_supplier_code) $sql.= natural_search("s.code_fournisseur",$search_supplier_code);
  368. if ($search_account_customer_code) $sql.= natural_search("s.code_compta",$search_account_customer_code);
  369. if ($search_account_supplier_code) $sql.= natural_search("s.code_compta_fournisseur",$search_account_supplier_code);
  370. if ($search_town) $sql.= natural_search("s.town",$search_town);
  371. if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
  372. if ($search_state) $sql.= natural_search("state.nom",$search_state);
  373. if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
  374. if ($search_email) $sql.= natural_search("s.email",$search_email);
  375. if ($search_phone) $sql.= natural_search("s.phone",$search_phone);
  376. if ($search_url) $sql.= natural_search("s.url",$search_url);
  377. if ($search_idprof1) $sql.= natural_search("s.siren",$search_idprof1);
  378. if ($search_idprof2) $sql.= natural_search("s.siret",$search_idprof2);
  379. if ($search_idprof3) $sql.= natural_search("s.ape",$search_idprof3);
  380. if ($search_idprof4) $sql.= natural_search("s.idprof4",$search_idprof4);
  381. if ($search_idprof5) $sql.= natural_search("s.idprof5",$search_idprof5);
  382. if ($search_idprof6) $sql.= natural_search("s.idprof6",$search_idprof6);
  383. // Filter on type of thirdparty
  384. if ($search_type > 0 && in_array($search_type,array('1,3','2,3'))) $sql .= " AND s.client IN (".$db->escape($search_type).")";
  385. if ($search_type > 0 && in_array($search_type,array('4'))) $sql .= " AND s.fournisseur = 1";
  386. if ($search_type == '0') $sql .= " AND s.client = 0 AND s.fournisseur = 0";
  387. if ($search_status!='' && $search_status >= 0) $sql .= " AND s.status = ".$db->escape($search_status);
  388. if (!empty($conf->barcode->enabled) && $search_barcode) $sql.= " AND s.barcode LIKE '%".$db->escape($search_barcode)."%'";
  389. if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
  390. if ($search_levels) $sql .= " AND s.fk_prospectlevel IN (".$search_levels.')';
  391. if ($search_stcomm != '' && $search_stcomm != -2) $sql.= natural_search("s.fk_stcomm",$search_stcomm,2);
  392. // Add where from extra fields
  393. foreach ($search_array_options as $key => $val)
  394. {
  395. $crit=$val;
  396. $tmpkey=preg_replace('/search_options_/','',$key);
  397. $typ=$extrafields->attribute_type[$tmpkey];
  398. $mode=0;
  399. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  400. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  401. {
  402. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  403. }
  404. }
  405. // Add where from hooks
  406. $parameters=array();
  407. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  408. $sql.=$hookmanager->resPrint;
  409. $sql.= $db->order($sortfield,$sortorder);
  410. // Count total nb of records
  411. $nbtotalofrecords = '';
  412. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  413. {
  414. $result = $db->query($sql);
  415. $nbtotalofrecords = $db->num_rows($result);
  416. }
  417. $sql.= $db->plimit($limit+1, $offset);
  418. $resql = $db->query($sql);
  419. if (! $resql)
  420. {
  421. dol_print_error($db);
  422. exit;
  423. }
  424. $num = $db->num_rows($resql);
  425. $arrayofselected=is_array($toselect)?$toselect:array();
  426. if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && $action != 'list')
  427. {
  428. $obj = $db->fetch_object($resql);
  429. $id = $obj->rowid;
  430. header("Location: ".DOL_URL_ROOT.'/societe/card.php?socid='.$id);
  431. exit;
  432. }
  433. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  434. llxHeader('',$langs->trans("ThirdParty"),$help_url);
  435. $param='';
  436. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  437. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  438. if ($search_all != '') $param = "&amp;sall=".urlencode($search_all);
  439. if ($sall != '') $param .= "&amp;sall=".urlencode($sall);
  440. if ($search_categ > 0) $param.='&amp;search_categ='.urlencode($search_categ);
  441. if ($search_sale > 0) $param.='&amp;search_sale='.urlencode($search_sale);
  442. if ($search_nom != '') $param.= "&amp;search_nom=".urlencode($search_nom);
  443. if ($search_town != '') $param.= "&amp;search_town=".urlencode($search_town);
  444. if ($search_zip != '') $param.= "&amp;search_zip=".urlencode($search_zip);
  445. if ($search_phone != '') $param.= "&amp;search_phone=".urlencode($search_phone);
  446. if ($search_email != '') $param.= "&amp;search_email=".urlencode($search_email);
  447. if ($search_url != '') $param.= "&amp;search_url=".urlencode($search_url);
  448. if ($search_state != '') $param.= "&amp;search_state=".urlencode($search_state);
  449. if ($search_country != '') $param.= "&amp;search_country=".urlencode($search_country);
  450. if ($search_customer_code != '') $param.= "&amp;search_customer_code=".urlencode($search_customer_code);
  451. if ($search_supplier_code != '') $param.= "&amp;search_supplier_code=".urlencode($search_supplier_code);
  452. if ($search_account_customer_code != '') $param.= "&amp;search_account_customer_code=".urlencode($search_account_customer_code);
  453. if ($search_account_supplier_code != '') $param.= "&amp;search_account_supplier_code=".urlencode($search_account_supplier_code);
  454. if ($search_barcode != '') $param.= "&amp;sbarcode=".urlencode($search_barcode);
  455. if ($search_idprof1 != '') $param.= '&amp;search_idprof1='.urlencode($search_idprof1);
  456. if ($search_idprof2 != '') $param.= '&amp;search_idprof2='.urlencode($search_idprof2);
  457. if ($search_idprof3 != '') $param.= '&amp;search_idprof3='.urlencode($search_idprof3);
  458. if ($search_idprof4 != '') $param.= '&amp;search_idprof4='.urlencode($search_idprof4);
  459. if ($search_idprof5 != '') $param.= '&amp;search_idprof5='.urlencode($search_idprof5);
  460. if ($search_idprof6 != '') $param.= '&amp;search_idprof6='.urlencode($search_idprof6);
  461. if ($search_country != '') $param.='&amp;search_country='.urlencode($search_country);
  462. if ($search_type_thirdparty != '') $param.='&amp;search_type_thirdparty='.urlencode($search_type_thirdparty);
  463. if ($optioncss != '') $param.='&amp;optioncss='.urlencode($optioncss);
  464. if ($search_status != '') $param.='&amp;search_status='.urlencode($search_status);
  465. if ($search_stcomm != '') $param.='&search_stcomm='.$search_stcomm;
  466. if ($search_level_from != '') $param.='&search_level_from='.$search_level_from;
  467. if ($search_level_to != '') $param.='&search_level_to='.$search_level_to;
  468. if ($type != '') $param.='&amp;type='.urlencode($type);
  469. // Add $param from extra fields
  470. foreach ($search_array_options as $key => $val)
  471. {
  472. $crit=$val;
  473. $tmpkey=preg_replace('/search_options_/','',$key);
  474. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  475. }
  476. // Show delete result message
  477. if (GETPOST('delsoc'))
  478. {
  479. setEventMessages($langs->trans("CompanyDeleted",GETPOST('delsoc')), null, 'mesgs');
  480. }
  481. // List of mass actions available
  482. $arrayofmassactions = array(
  483. // 'presend'=>$langs->trans("SendByMail"),
  484. // 'builddoc'=>$langs->trans("PDFMerge"),
  485. );
  486. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  487. if ($user->rights->societe->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
  488. if ($massaction == 'presend') $arrayofmassactions=array();
  489. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  490. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  491. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  492. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  493. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  494. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  495. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  496. print '<input type="hidden" name="page" value="'.$page.'">';
  497. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
  498. $langs->load("other");
  499. $textprofid=array();
  500. foreach(array(1,2,3,4,5,6) as $key)
  501. {
  502. $label=$langs->transnoentities("ProfId".$key.$mysoc->country_code);
  503. $textprofid[$key]='';
  504. if ($label != "ProfId".$key.$mysoc->country_code)
  505. { // Get only text between ()
  506. if (preg_match('/\((.*)\)/i',$label,$reg)) $label=$reg[1];
  507. $textprofid[$key]=$langs->trans("ProfIdShortDesc",$key,$mysoc->country_code,$label);
  508. }
  509. }
  510. if ($search_all)
  511. {
  512. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  513. print $langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall);
  514. }
  515. // Filter on categories
  516. $moreforfilter='';
  517. if ($type == 'c' || $type == 'p')
  518. {
  519. if (! empty($conf->categorie->enabled))
  520. {
  521. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  522. $moreforfilter.='<div class="divsearchfield">';
  523. $moreforfilter.=$langs->trans('Categories'). ': ';
  524. $moreforfilter.=$formother->select_categories('customer',$search_categ,'search_categ',1);
  525. $moreforfilter.='</div>';
  526. }
  527. }
  528. if ($type == 'f')
  529. {
  530. if (! empty($conf->categorie->enabled))
  531. {
  532. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  533. $moreforfilter.='<div class="divsearchfield">';
  534. $moreforfilter.=$langs->trans('Categories'). ': ';
  535. $moreforfilter.=$formother->select_categories('supplier',$search_categ,'search_categ',1);
  536. $moreforfilter.='</div>';
  537. }
  538. }
  539. // If the user can view prospects other than his'
  540. if ($user->rights->societe->client->voir || $socid)
  541. {
  542. $moreforfilter.='<div class="divsearchfield">';
  543. $moreforfilter.=$langs->trans('SalesRepresentatives'). ': ';
  544. $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user, 0, 1, 'maxwidth300');
  545. $moreforfilter.='</div>';
  546. }
  547. if ($moreforfilter)
  548. {
  549. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  550. print $moreforfilter;
  551. $parameters=array('type'=>$type);
  552. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  553. print $hookmanager->resPrint;
  554. print '</div>';
  555. }
  556. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  557. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  558. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  559. if (empty($arrayfields['customerorsupplier']['checked'])) print '<input type="hidden" name="type" value="'.$type.'">';
  560. print '<div class="div-table-responsive">';
  561. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  562. // Fields title search
  563. print '<tr class="liste_titre_filter">';
  564. if (! empty($arrayfields['s.nom']['checked']))
  565. {
  566. print '<td class="liste_titre">';
  567. if (! empty($search_nom_only) && empty($search_nom)) $search_nom=$search_nom_only;
  568. print '<input class="flat searchstring" type="text" name="search_nom" size="8" value="'.dol_escape_htmltag($search_nom).'">';
  569. print '</td>';
  570. }
  571. // Barcode
  572. if (! empty($arrayfields['s.barcode']['checked']))
  573. {
  574. print '<td class="liste_titre">';
  575. print '<input class="flat searchstring" type="text" name="sbarcode" size="6" value="'.dol_escape_htmltag($search_barcode).'">';
  576. print '</td>';
  577. }
  578. // Customer code
  579. if (! empty($arrayfields['s.code_client']['checked']))
  580. {
  581. print '<td class="liste_titre">';
  582. print '<input class="flat searchstring" size="8" type="text" name="search_customer_code" value="'.dol_escape_htmltag($search_customer_code).'">';
  583. print '</td>';
  584. }
  585. // Supplier code
  586. if (! empty($arrayfields['s.code_fournisseur']['checked']))
  587. {
  588. print '<td class="liste_titre">';
  589. print '<input class="flat searchstring" size="8" type="text" name="search_supplier_code" value="'.dol_escape_htmltag($search_supplier_code).'">';
  590. print '</td>';
  591. }
  592. // Account Customer code
  593. if (! empty($arrayfields['s.code_compta']['checked']))
  594. {
  595. print '<td class="liste_titre">';
  596. print '<input class="flat searchstring" size="8" type="text" name="search_account_customer_code" value="'.dol_escape_htmltag($search_account_customer_code).'">';
  597. print '</td>';
  598. }
  599. // Account Supplier code
  600. if (! empty($arrayfields['s.code_compta_fournisseur']['checked']))
  601. {
  602. print '<td class="liste_titre">';
  603. print '<input class="flat" size="8" type="text" name="search_account_supplier_code" value="'.dol_escape_htmltag($search_account_supplier_code).'">';
  604. print '</td>';
  605. }
  606. // Town
  607. if (! empty($arrayfields['s.town']['checked']))
  608. {
  609. print '<td class="liste_titre">';
  610. print '<input class="flat searchstring" size="6" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
  611. print '</td>';
  612. }
  613. // Zip
  614. if (! empty($arrayfields['s.zip']['checked']))
  615. {
  616. print '<td class="liste_titre">';
  617. print '<input class="flat searchstring" size="4" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
  618. print '</td>';
  619. }
  620. // State
  621. if (! empty($arrayfields['state.nom']['checked']))
  622. {
  623. print '<td class="liste_titre">';
  624. print '<input class="flat searchstring" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  625. print '</td>';
  626. }
  627. // Country
  628. if (! empty($arrayfields['country.code_iso']['checked']))
  629. {
  630. print '<td class="liste_titre" align="center">';
  631. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  632. print '</td>';
  633. }
  634. // Company type
  635. if (! empty($arrayfields['typent.code']['checked']))
  636. {
  637. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  638. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
  639. print '</td>';
  640. }
  641. if (! empty($arrayfields['s.email']['checked']))
  642. {
  643. // Email
  644. print '<td class="liste_titre">';
  645. print '<input class="flat searchemail" size="4" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
  646. print '</td>';
  647. }
  648. if (! empty($arrayfields['s.phone']['checked']))
  649. {
  650. // Phone
  651. print '<td class="liste_titre">';
  652. print '<input class="flat searchstring" size="4" type="text" name="search_phone" value="'.dol_escape_htmltag($search_phone).'">';
  653. print '</td>';
  654. }
  655. if (! empty($arrayfields['s.url']['checked']))
  656. {
  657. // Url
  658. print '<td class="liste_titre">';
  659. print '<input class="flat searchstring" size="4" type="text" name="search_url" value="'.dol_escape_htmltag($search_url).'">';
  660. print '</td>';
  661. }
  662. if (! empty($arrayfields['s.siren']['checked']))
  663. {
  664. // IdProf1
  665. print '<td class="liste_titre">';
  666. print '<input class="flat searchstring" size="4" type="text" name="search_idprof1" value="'.dol_escape_htmltag($search_idprof1).'">';
  667. print '</td>';
  668. }
  669. if (! empty($arrayfields['s.siret']['checked']))
  670. {
  671. // IdProf2
  672. print '<td class="liste_titre">';
  673. print '<input class="flat searchstring" size="4" type="text" name="search_idprof2" value="'.dol_escape_htmltag($search_idprof2).'">';
  674. print '</td>';
  675. }
  676. if (! empty($arrayfields['s.ape']['checked']))
  677. {
  678. // IdProf3
  679. print '<td class="liste_titre">';
  680. print '<input class="flat searchstring" size="4" type="text" name="search_idprof3" value="'.dol_escape_htmltag($search_idprof3).'">';
  681. print '</td>';
  682. }
  683. if (! empty($arrayfields['s.idprof4']['checked']))
  684. {
  685. // IdProf4
  686. print '<td class="liste_titre">';
  687. print '<input class="flat searchstring" size="4" type="text" name="search_idprof4" value="'.dol_escape_htmltag($search_idprof4).'">';
  688. print '</td>';
  689. }
  690. if (! empty($arrayfields['s.idprof5']['checked']))
  691. {
  692. // IdProf5
  693. print '<td class="liste_titre">';
  694. print '<input class="flat searchstring" size="4" type="text" name="search_idprof5" value="'.dol_escape_htmltag($search_idprof5).'">';
  695. print '</td>';
  696. }
  697. if (! empty($arrayfields['s.idprof6']['checked']))
  698. {
  699. // IdProf6
  700. print '<td class="liste_titre">';
  701. print '<input class="flat searchstring" size="4" type="text" name="search_idprof6" value="'.dol_escape_htmltag($search_idprof6).'">';
  702. print '</td>';
  703. }
  704. // Type (customer/prospect/supplier)
  705. if (! empty($arrayfields['customerorsupplier']['checked']))
  706. {
  707. print '<td class="liste_titre maxwidthonsmartphone" align="middle">';
  708. if ($type != '') print '<input type="hidden" name="type" value="'.$type.'">';
  709. print '<select class="flat" name="search_type">';
  710. print '<option value="-1"'.($search_type==''?' selected':'').'>&nbsp;</option>';
  711. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print '<option value="1,3"'.($search_type=='1,3'?' selected':'').'>'.$langs->trans('Customer').'</option>';
  712. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="2,3"'.($search_type=='2,3'?' selected':'').'>'.$langs->trans('Prospect').'</option>';
  713. //if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print '<option value="3"'.($search_type=='3'?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
  714. print '<option value="4"'.($search_type=='4'?' selected':'').'>'.$langs->trans('Supplier').'</option>';
  715. print '<option value="0"'.($search_type=='0'?' selected':'').'>'.$langs->trans('Others').'</option>';
  716. print '</select></td>';
  717. }
  718. if (! empty($arrayfields['s.fk_prospectlevel']['checked']))
  719. {
  720. // Prospect level
  721. print '<td class="liste_titre" align="center">';
  722. $options_from = '<option value="">&nbsp;</option>'; // Generate in $options_from the list of each option sorted
  723. foreach ($tab_level as $tab_level_sortorder => $tab_level_label)
  724. {
  725. $options_from .= '<option value="'.$tab_level_sortorder.'"'.($search_level_from == $tab_level_sortorder ? ' selected':'').'>';
  726. $options_from .= $langs->trans($tab_level_label);
  727. $options_from .= '</option>';
  728. }
  729. array_reverse($tab_level, true); // Reverse the list
  730. $options_to = '<option value="">&nbsp;</option>'; // Generate in $options_to the list of each option sorted in the reversed order
  731. foreach ($tab_level as $tab_level_sortorder => $tab_level_label)
  732. {
  733. $options_to .= '<option value="'.$tab_level_sortorder.'"'.($search_level_to == $tab_level_sortorder ? ' selected':'').'>';
  734. $options_to .= $langs->trans($tab_level_label);
  735. $options_to .= '</option>';
  736. }
  737. // Print these two select
  738. print $langs->trans("From").' <select class="flat" name="search_level_from">'.$options_from.'</select>';
  739. print ' ';
  740. print $langs->trans("to").' <select class="flat" name="search_level_to">'.$options_to.'</select>';
  741. print '</td>';
  742. }
  743. if (! empty($arrayfields['s.fk_stcomm']['checked']))
  744. {
  745. // Prospect status
  746. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  747. $arraystcomm=array();
  748. foreach($prospectstatic->cacheprospectstatus as $key => $val)
  749. {
  750. $arraystcomm[$val['id']]=($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
  751. }
  752. print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2);
  753. print '</td>';
  754. }
  755. // Extra fields
  756. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  757. {
  758. foreach($extrafields->attribute_label as $key => $val)
  759. {
  760. if (! empty($arrayfields["ef.".$key]['checked']))
  761. {
  762. $align=$extrafields->getAlignFlag($key);
  763. $typeofextrafield=$extrafields->attribute_type[$key];
  764. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  765. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  766. {
  767. $crit=$val;
  768. $tmpkey=preg_replace('/search_options_/','',$key);
  769. $searchclass='';
  770. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  771. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  772. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  773. }
  774. print '</td>';
  775. }
  776. }
  777. }
  778. // Fields from hook
  779. $parameters=array('arrayfields'=>$arrayfields);
  780. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  781. print $hookmanager->resPrint;
  782. // Date creation
  783. if (! empty($arrayfields['s.datec']['checked']))
  784. {
  785. print '<td class="liste_titre">';
  786. print '</td>';
  787. }
  788. // Date modification
  789. if (! empty($arrayfields['s.tms']['checked']))
  790. {
  791. print '<td class="liste_titre">';
  792. print '</td>';
  793. }
  794. // Status
  795. if (! empty($arrayfields['s.status']['checked']))
  796. {
  797. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  798. print $form->selectarray('search_status', array('0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')), $search_status, 1);
  799. print '</td>';
  800. }
  801. // Action column
  802. print '<td class="liste_titre" align="right">';
  803. $searchpicto=$form->showFilterButtons();
  804. print $searchpicto;
  805. print '</td>';
  806. print "</tr>\n";
  807. print '<tr class="liste_titre">';
  808. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
  809. if (! empty($arrayfields['s.barcode']['checked'])) print_liste_field_titre($arrayfields['s.barcode']['label'], $_SERVER["PHP_SELF"], "s.barcode",$param,'','',$sortfield,$sortorder);
  810. if (! empty($arrayfields['s.code_client']['checked'])) print_liste_field_titre($arrayfields['s.code_client']['label'],$_SERVER["PHP_SELF"],"s.code_client","",$param,'',$sortfield,$sortorder);
  811. if (! empty($arrayfields['s.code_fournisseur']['checked'])) print_liste_field_titre($arrayfields['s.code_fournisseur']['label'],$_SERVER["PHP_SELF"],"s.code_fournisseur","",$param,'',$sortfield,$sortorder);
  812. if (! empty($arrayfields['s.code_compta']['checked'])) print_liste_field_titre($arrayfields['s.code_compta']['label'],$_SERVER["PHP_SELF"],"s.code_compta","",$param,'',$sortfield,$sortorder);
  813. if (! empty($arrayfields['s.code_compta_fournisseur']['checked'])) print_liste_field_titre($arrayfields['s.code_compta_fournisseur']['label'],$_SERVER["PHP_SELF"],"s.code_compta_fournisseur","",$param,'',$sortfield,$sortorder);
  814. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],"s.town","",$param,'',$sortfield,$sortorder);
  815. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],"s.zip","",$param,'',$sortfield,$sortorder);
  816. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  817. if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
  818. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  819. if (! empty($arrayfields['s.email']['checked'])) print_liste_field_titre($arrayfields['s.email']['label'],$_SERVER["PHP_SELF"],"s.email","",$param,'',$sortfield,$sortorder);
  820. if (! empty($arrayfields['s.phone']['checked'])) print_liste_field_titre($arrayfields['s.phone']['label'],$_SERVER["PHP_SELF"],"s.phone","",$param,'',$sortfield,$sortorder);
  821. if (! empty($arrayfields['s.url']['checked'])) print_liste_field_titre($arrayfields['s.url']['label'],$_SERVER["PHP_SELF"],"s.url","",$param,'',$sortfield,$sortorder);
  822. if (! empty($arrayfields['s.siren']['checked'])) print_liste_field_titre($form->textwithpicto($langs->trans("ProfId1Short"),$textprofid[1],1,0),$_SERVER["PHP_SELF"],"s.siren","",$param,'class="nowrap"',$sortfield,$sortorder);
  823. if (! empty($arrayfields['s.siret']['checked'])) print_liste_field_titre($form->textwithpicto($langs->trans("ProfId2Short"),$textprofid[2],1,0),$_SERVER["PHP_SELF"],"s.siret","",$param,'class="nowrap"',$sortfield,$sortorder);
  824. if (! empty($arrayfields['s.ape']['checked'])) print_liste_field_titre($form->textwithpicto($langs->trans("ProfId3Short"),$textprofid[3],1,0),$_SERVER["PHP_SELF"],"s.ape","",$param,'class="nowrap"',$sortfield,$sortorder);
  825. if (! empty($arrayfields['s.idprof4']['checked'])) print_liste_field_titre($form->textwithpicto($langs->trans("ProfId4Short"),$textprofid[4],1,0),$_SERVER["PHP_SELF"],"s.idprof4","",$param,'class="nowrap"',$sortfield,$sortorder);
  826. if (! empty($arrayfields['s.idprof5']['checked'])) print_liste_field_titre($form->textwithpicto($langs->trans("ProfId5Short"),$textprofid[4],1,0),$_SERVER["PHP_SELF"],"s.idprof5","",$param,'class="nowrap"',$sortfield,$sortorder);
  827. if (! empty($arrayfields['s.idprof6']['checked'])) print_liste_field_titre($form->textwithpicto($langs->trans("ProfId6Short"),$textprofid[4],1,0),$_SERVER["PHP_SELF"],"s.idprof6","",$param,'class="nowrap"',$sortfield,$sortorder);
  828. if (! empty($arrayfields['customerorsupplier']['checked'])) print_liste_field_titre(''); // type of customer
  829. if (! empty($arrayfields['s.fk_prospectlevel']['checked'])) print_liste_field_titre($arrayfields['s.fk_prospectlevel']['label'],$_SERVER["PHP_SELF"],"s.fk_prospectlevel","",$param,'align="center"',$sortfield,$sortorder);
  830. if (! empty($arrayfields['s.fk_stcomm']['checked'])) print_liste_field_titre($arrayfields['s.fk_stcomm']['label'],$_SERVER["PHP_SELF"],"s.fk_stcomm","",$param,'align="center"',$sortfield,$sortorder);
  831. // Extra fields
  832. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  833. {
  834. foreach($extrafields->attribute_label as $key => $val)
  835. {
  836. if (! empty($arrayfields["ef.".$key]['checked']))
  837. {
  838. $align=$extrafields->getAlignFlag($key);
  839. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  840. }
  841. }
  842. }
  843. // Hook fields
  844. $parameters=array('arrayfields'=>$arrayfields);
  845. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  846. print $hookmanager->resPrint;
  847. if (! empty($arrayfields['s.datec']['checked'])) print_liste_field_titre($arrayfields['s.datec']['label'],$_SERVER["PHP_SELF"],"s.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  848. if (! empty($arrayfields['s.tms']['checked'])) print_liste_field_titre($arrayfields['s.tms']['label'],$_SERVER["PHP_SELF"],"s.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  849. if (! empty($arrayfields['s.status']['checked'])) print_liste_field_titre($arrayfields['s.status']['label'],$_SERVER["PHP_SELF"],"s.status","",$param,'align="center"',$sortfield,$sortorder);
  850. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  851. print "</tr>\n";
  852. $i = 0;
  853. while ($i < min($num, $limit))
  854. {
  855. $obj = $db->fetch_object($resql);
  856. $companystatic->id=$obj->rowid;
  857. $companystatic->name=$obj->name;
  858. $companystatic->canvas=$obj->canvas;
  859. $companystatic->client=$obj->client;
  860. $companystatic->status=$obj->status;
  861. $companystatic->fournisseur=$obj->fournisseur;
  862. $companystatic->code_client=$obj->code_client;
  863. $companystatic->code_fournisseur=$obj->code_fournisseur;
  864. $companystatic->code_compta_client=$obj->code_compta;
  865. $companystatic->code_compta_fournisseur=$obj->code_compta_fournisseur;
  866. $companystatic->fk_prospectlevel=$obj->fk_prospectlevel;
  867. $companystatic->name_alias=$obj->name_alias;
  868. print '<tr class="oddeven">';
  869. if (! empty($arrayfields['s.nom']['checked']))
  870. {
  871. print '<td class="tdoverflowmax200">';
  872. print $companystatic->getNomUrl(1,'',100);
  873. print "</td>\n";
  874. }
  875. // Barcode
  876. if (! empty($arrayfields['s.barcode']['checked']))
  877. {
  878. print '<td>'.$obj->barcode.'</td>';
  879. }
  880. // Customer code
  881. if (! empty($arrayfields['s.code_client']['checked']))
  882. {
  883. print '<td>'.$obj->code_client.'</td>';
  884. }
  885. // Supplier code
  886. if (! empty($arrayfields['s.code_fournisseur']['checked']))
  887. {
  888. print '<td>'.$obj->code_fournisseur.'</td>';
  889. }
  890. // Account customer code
  891. if (! empty($arrayfields['s.code_compta']['checked']))
  892. {
  893. print '<td>'.$obj->code_compta.'</td>';
  894. }
  895. // Account supplier code
  896. if (! empty($arrayfields['s.code_compta_fournisseur']['checked']))
  897. {
  898. print '<td>'.$obj->code_compta_fournisseur.'</td>';
  899. }
  900. // Town
  901. if (! empty($arrayfields['s.town']['checked']))
  902. {
  903. print "<td>".$obj->town."</td>\n";
  904. }
  905. // Zip
  906. if (! empty($arrayfields['s.zip']['checked']))
  907. {
  908. print "<td>".$obj->zip."</td>\n";
  909. }
  910. // State
  911. if (! empty($arrayfields['state.nom']['checked']))
  912. {
  913. print "<td>".$obj->state_name."</td>\n";
  914. }
  915. // Country
  916. if (! empty($arrayfields['country.code_iso']['checked']))
  917. {
  918. print '<td align="center">';
  919. $tmparray=getCountry($obj->fk_pays,'all');
  920. print $tmparray['label'];
  921. print '</td>';
  922. }
  923. // Type ent
  924. if (! empty($arrayfields['typent.code']['checked']))
  925. {
  926. print '<td align="center">';
  927. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  928. print $typenArray[$obj->typent_code];
  929. print '</td>';
  930. }
  931. if (! empty($arrayfields['s.email']['checked']))
  932. {
  933. print "<td>".$obj->email."</td>\n";
  934. }
  935. if (! empty($arrayfields['s.phone']['checked']))
  936. {
  937. print "<td>".$obj->phone."</td>\n";
  938. }
  939. if (! empty($arrayfields['s.url']['checked']))
  940. {
  941. print "<td>".$obj->url."</td>\n";
  942. }
  943. if (! empty($arrayfields['s.siren']['checked']))
  944. {
  945. print "<td>".$obj->idprof1."</td>\n";
  946. }
  947. if (! empty($arrayfields['s.siret']['checked']))
  948. {
  949. print "<td>".$obj->idprof2."</td>\n";
  950. }
  951. if (! empty($arrayfields['s.ape']['checked']))
  952. {
  953. print "<td>".$obj->idprof3."</td>\n";
  954. }
  955. if (! empty($arrayfields['s.idprof4']['checked']))
  956. {
  957. print "<td>".$obj->idprof4."</td>\n";
  958. }
  959. if (! empty($arrayfields['s.idprof5']['checked']))
  960. {
  961. print "<td>".$obj->idprof5."</td>\n";
  962. }
  963. if (! empty($arrayfields['s.idprof6']['checked']))
  964. {
  965. print "<td>".$obj->idprof6."</td>\n";
  966. }
  967. // Type
  968. if (! empty($arrayfields['customerorsupplier']['checked']))
  969. {
  970. print '<td align="center">';
  971. $s='';
  972. if (($obj->client==1 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
  973. {
  974. $companystatic->name=$langs->trans("Customer");
  975. $companystatic->name_alias='';
  976. $s.=$companystatic->getNomUrl(0,'customer');
  977. }
  978. if (($obj->client==2 || $obj->client==3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
  979. {
  980. if ($s) $s.=" / ";
  981. $companystatic->name=$langs->trans("Prospect");
  982. $companystatic->name_alias='';
  983. $s.=$companystatic->getNomUrl(0,'prospect');
  984. }
  985. if (! empty($conf->fournisseur->enabled) && $obj->fournisseur)
  986. {
  987. if ($s) $s.=" / ";
  988. $companystatic->name=$langs->trans("Supplier");
  989. $companystatic->name_alias='';
  990. $s.=$companystatic->getNomUrl(0,'supplier');
  991. }
  992. print $s;
  993. print '</td>';
  994. }
  995. if (! empty($arrayfields['s.fk_prospectlevel']['checked']))
  996. {
  997. // Prospect level
  998. print '<td align="center">';
  999. print $companystatic->getLibProspLevel();
  1000. print "</td>";
  1001. }
  1002. if (! empty($arrayfields['s.fk_stcomm']['checked']))
  1003. {
  1004. // Prospect status
  1005. print '<td align="center" class="nowrap"><div class="nowrap">';
  1006. print '<div class="inline-block">'.$companystatic->LibProspCommStatut($obj->stcomm_id,2,$prospectstatic->cacheprospectstatus[$obj->stcomm_id]['label']);
  1007. print '</div> - <div class="inline-block">';
  1008. foreach($prospectstatic->cacheprospectstatus as $key => $val)
  1009. {
  1010. $titlealt='default';
  1011. if (! empty($val['code']) && ! in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt=$val['label'];
  1012. if ($obj->stcomm_id != $val['id']) print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?stcommsocid='.$obj->rowid.'&stcomm='.$val['code'].'&action=setstcomm'.$param.($page?'&page='.urlencode($page):'').'">'.img_action($titlealt,$val['code']).'</a>';
  1013. }
  1014. print '</div></div></td>';
  1015. }
  1016. // Extra fields
  1017. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  1018. {
  1019. foreach($extrafields->attribute_label as $key => $val)
  1020. {
  1021. if (! empty($arrayfields["ef.".$key]['checked']))
  1022. {
  1023. print '<td';
  1024. $align=$extrafields->getAlignFlag($key);
  1025. if ($align) print ' align="'.$align.'"';
  1026. print '>';
  1027. $tmpkey='options_'.$key;
  1028. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  1029. print '</td>';
  1030. }
  1031. }
  1032. }
  1033. // Fields from hook
  1034. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  1035. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  1036. print $hookmanager->resPrint;
  1037. // Date creation
  1038. if (! empty($arrayfields['s.datec']['checked']))
  1039. {
  1040. print '<td align="center" class="nowrap">';
  1041. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  1042. print '</td>';
  1043. }
  1044. // Date modification
  1045. if (! empty($arrayfields['s.tms']['checked']))
  1046. {
  1047. print '<td align="center" class="nowrap">';
  1048. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  1049. print '</td>';
  1050. }
  1051. // Status
  1052. if (! empty($arrayfields['s.status']['checked']))
  1053. {
  1054. print '<td align="center" class="nowrap">'.$companystatic->getLibStatut(3).'</td>';
  1055. }
  1056. // Action column
  1057. print '<td class="nowrap" align="center">';
  1058. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1059. {
  1060. $selected=0;
  1061. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  1062. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  1063. }
  1064. print '</td>';
  1065. if (! $i) $totalarray['nbfield']++;
  1066. print '</tr>'."\n";
  1067. $i++;
  1068. }
  1069. $db->free($resql);
  1070. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1071. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  1072. print $hookmanager->resPrint;
  1073. print "</table>";
  1074. print "</div>";
  1075. print '</form>';
  1076. llxFooter();
  1077. $db->close();