list.php 47 KB

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