list.php 59 KB

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