dolibarr  7.0.0-beta
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
4  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
8  * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
9  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34 
35 $langs->loadLangs(array("companies", "suppliers"));
36 
37 $action=GETPOST('action','alpha');
38 $massaction=GETPOST('massaction','alpha');
39 $show_files=GETPOST('show_files','int');
40 $confirm=GETPOST('confirm','alpha');
41 $toselect = GETPOST('toselect', 'array');
42 
43 // Security check
44 $id = GETPOST('id','int');
45 $contactid = GETPOST('id','int');
46 $ref = ''; // There is no ref for contacts
47 if ($user->societe_id) $socid=$user->societe_id;
48 $result = restrictedArea($user, 'contact', $contactid,'');
49 
50 $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
51 $search_cti=preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
52 $search_phone=GETPOST("search_phone",'alpha');
53 
54 $search_id=trim(GETPOST("search_id","int"));
55 $search_firstlast_only=GETPOST("search_firstlast_only",'alpha');
56 $search_lastname=GETPOST("search_lastname",'alpha');
57 $search_firstname=GETPOST("search_firstname",'alpha');
58 $search_societe=GETPOST("search_societe",'alpha');
59 $search_poste=GETPOST("search_poste",'alpha');
60 $search_phone_perso=GETPOST("search_phone_perso",'alpha');
61 $search_phone_pro=GETPOST("search_phone_pro",'alpha');
62 $search_phone_mobile=GETPOST("search_phone_mobile",'alpha');
63 $search_fax=GETPOST("search_fax",'alpha');
64 $search_email=GETPOST("search_email",'alpha');
65 $search_skype=GETPOST("search_skype",'alpha');
66 $search_priv=GETPOST("search_priv",'alpha');
67 $search_categ=GETPOST("search_categ",'int');
68 $search_categ_thirdparty=GETPOST("search_categ_thirdparty",'int');
69 $search_categ_supplier=GETPOST("search_categ_supplier",'int');
70 $search_status=GETPOST("search_status",'int');
71 $search_type=GETPOST('search_type','alpha');
72 $search_zip=GETPOST('search_zip','alpha');
73 $search_town=GETPOST('search_town','alpha');
74 $search_import_key=GETPOST("search_import_key","alpha");
75 
76 if ($search_status=='') $search_status=1; // always display activ customer first
77 
78 $optioncss = GETPOST('optioncss','alpha');
79 
80 
81 $type=GETPOST("type");
82 $view=GETPOST("view");
83 
84 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
85 $sortfield = GETPOST('sortfield', 'alpha');
86 $sortorder = GETPOST('sortorder', 'alpha');
87 $page = GETPOST('page', 'int');
88 $userid=GETPOST('userid','int');
89 $begin=GETPOST('begin');
90 if (! $sortorder) $sortorder="ASC";
91 if (! $sortfield) $sortfield="p.lastname";
92 if (empty($page) || $page < 0) { $page = 0; }
93 $offset = $limit * $page;
94 
95 $contextpage='contactlist';
96 $titre = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
97 if ($type == "p")
98 {
99  $contextpage='contactprospectlist';
100  $titre.=' ('.$langs->trans("ThirdPartyProspects").')';
101  $urlfiche="card.php";
102 }
103 if ($type == "c")
104 {
105  $contextpage='contactcustomerlist';
106  $titre.=' ('.$langs->trans("ThirdPartyCustomers").')';
107  $urlfiche="card.php";
108 }
109 else if ($type == "f")
110 {
111  $contextpage='contactsupplierlist';
112  $titre.=' ('.$langs->trans("ThirdPartySuppliers").')';
113  $urlfiche="card.php";
114 }
115 else if ($type == "o")
116 {
117  $contextpage='contactotherlist';
118  $titre.=' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
119  $urlfiche="";
120 }
121 
122 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
123 $hookmanager->initHooks(array($contextpage));
124 $extrafields = new ExtraFields($db);
125 
126 // fetch optionals attributes and labels
127 $extralabels = $extrafields->fetch_name_optionals_label('contact');
128 $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
129 
130 // List of fields to search into when doing a "search in all"
131 $fieldstosearchall = array(
132  'p.lastname'=>'Lastname',
133  'p.firstname'=>'Firstname',
134  'p.email'=>'EMail',
135  's.nom'=>"ThirdParty",
136 );
137 
138 // Definition of fields for list
139 $arrayfields=array(
140  'p.rowid'=>array('label'=>"TechnicalID", 'checked'=>($conf->global->MAIN_SHOW_TECHNICAL_ID?1:0), 'enabled'=>($conf->global->MAIN_SHOW_TECHNICAL_ID?1:0)),
141  'p.lastname'=>array('label'=>"Lastname", 'checked'=>1),
142  'p.firstname'=>array('label'=>"Firstname", 'checked'=>1),
143  'p.poste'=>array('label'=>"PostOrFunction", 'checked'=>1),
144  'p.town'=>array('label'=>"Town", 'checked'=>0),
145  'p.zip'=>array('label'=>"Zip", 'checked'=>0),
146  'p.phone'=>array('label'=>"Phone", 'checked'=>1),
147  'p.phone_perso'=>array('label'=>"PhonePerso", 'checked'=>0),
148  'p.phone_mobile'=>array('label'=>"PhoneMobile", 'checked'=>1),
149  'p.fax'=>array('label'=>"Fax", 'checked'=>1),
150  'p.email'=>array('label'=>"EMail", 'checked'=>1),
151  'p.skype'=>array('label'=>"Skype", 'checked'=>1, 'enabled'=>(! empty($conf->skype->enabled))),
152  'p.thirdparty'=>array('label'=>"ThirdParty", 'checked'=>1, 'enabled'=>empty($conf->global->SOCIETE_DISABLE_CONTACTS)),
153  'p.priv'=>array('label'=>"ContactVisibility", 'checked'=>1, 'position'=>200),
154  'p.datec'=>array('label'=>"DateCreationShort", 'checked'=>0, 'position'=>500),
155  'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
156  'p.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
157  'p.import_key'=>array('label'=>"ImportId", 'checked'=>0, 'position'=>1100),
158 );
159 // Extra fields
160 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
161 {
162  foreach($extrafields->attribute_label as $key => $val)
163  {
164  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]));
165  }
166 }
167 
168 $object=new Contact($db);
169 if (($id > 0 || ! empty($ref)) && $action != 'add')
170 {
171  $result=$object->fetch($id,$ref);
172  if ($result < 0) dol_print_error($db);
173 }
174 
175 
176 /*
177  * Actions
178  */
179 
180 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
181 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
182 
183 $parameters=array();
184 $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
185 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
186 
187 if (empty($reshook))
188 {
189  // Selection of new fields
190  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
191 
192  // Did we click on purge search criteria ?
193  if (GETPOST('button_removefilter_x') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter')) // All tests are required to be compatible with all browsers
194  {
195  $sall="";
196  $search_id='';
197  $search_firstlast_only="";
198  $search_lastname="";
199  $search_firstname="";
200  $search_societe="";
201  $search_poste="";
202  $search_phone="";
203  $search_phone_perso="";
204  $search_phone_pro="";
205  $search_phone_mobile="";
206  $search_fax="";
207  $search_email="";
208  $search_skype="";
209  $search_priv="";
210  $search_status=-1;
211  $search_categ='';
212  $search_categ_thirdparty='';
213  $search_categ_supplier='';
214  $search_import_key='';
215  $toselect='';
216  $search_array_options=array();
217  }
218 
219  // Mass actions
220  $objectclass='Contact';
221  $objectlabel='Contact';
222  $permtoread = $user->rights->societe->lire;
223  $permtodelete = $user->rights->societe->supprimer;
224  $uploaddir = $conf->societe->dir_output;
225  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
226 }
227 
228 if ($search_priv < 0) $search_priv='';
229 
230 
231 /*
232  * View
233  */
234 
235 $form=new Form($db);
236 $formother=new FormOther($db);
237 $contactstatic=new Contact($db);
238 
239 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
240 
241 $sql = "SELECT s.rowid as socid, s.nom as name,";
242 $sql.= " p.rowid, p.lastname as lastname, p.statut, p.firstname, p.zip, p.town, p.poste, p.email, p.skype,";
243 $sql.= " p.phone as phone_pro, p.phone_mobile, p.phone_perso, p.fax, p.fk_pays, p.priv, p.datec as date_creation, p.tms as date_update,";
244 $sql.= " co.code as country_code";
245 // Add fields from extrafields
246 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
247 // Add fields from hooks
248 $parameters=array();
249 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
250 $sql.=$hookmanager->resPrint;
251 $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
252 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (p.rowid = ef.fk_object)";
253 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays";
254 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
255 if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cc ON p.rowid = cc.fk_socpeople"; // We need this table joined to the select in order to filter by categ
256 if (! empty($search_categ_thirdparty)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; // We need this table joined to the select in order to filter by categ
257 if (! empty($search_categ_supplier)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs2 ON s.rowid = cs2.fk_soc"; // We need this table joined to the select in order to filter by categ
258 if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
259 $sql.= ' WHERE p.entity IN ('.getEntity('societe').')';
260 if (!$user->rights->societe->client->voir && !$socid) //restriction
261 {
262  $sql .= " AND (sc.fk_user = " .$user->id." OR p.fk_soc IS NULL)";
263 }
264 if (! empty($userid)) // propre au commercial
265 {
266  $sql .= " AND p.fk_user_creat=".$db->escape($userid);
267 }
268 
269 // Filter to exclude not owned private contacts
270 if ($search_priv != '0' && $search_priv != '1')
271 {
272  $sql .= " AND (p.priv='0' OR (p.priv='1' AND p.fk_user_creat=".$user->id."))";
273 }
274 else
275 {
276  if ($search_priv == '0') $sql .= " AND p.priv='0'";
277  if ($search_priv == '1') $sql .= " AND (p.priv='1' AND p.fk_user_creat=".$user->id.")";
278 }
279 
280 if ($search_categ > 0) $sql.= " AND cc.fk_categorie = ".$db->escape($search_categ);
281 if ($search_categ == -2) $sql.= " AND cc.fk_categorie IS NULL";
282 if ($search_categ_thirdparty > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ_thirdparty);
283 if ($search_categ_thirdparty == -2) $sql.= " AND cs.fk_categorie IS NULL";
284 if ($search_categ_supplier > 0) $sql.= " AND cs2.fk_categorie = ".$db->escape($search_categ_supplier);
285 if ($search_categ_supplier == -2) $sql.= " AND cs2.fk_categorie IS NULL";
286 
287 if ($sall) $sql.= natural_search(array_keys($fieldstosearchall), $sall);
288 if (strlen($search_phone)) $sql.= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_phone);
289 if (strlen($search_cti)) $sql.= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_cti);
290 if (strlen($search_firstlast_only)) $sql.= natural_search(array('p.lastname', 'p.firstname'), $search_firstlast_only);
291 
292 if ($search_id > 0) $sql.= natural_search("p.rowid",$search_id,1);
293 if ($search_lastname) $sql.= natural_search('p.lastname', $search_lastname);
294 if ($search_firstname) $sql.= natural_search('p.firstname', $search_firstname);
295 if ($search_societe) $sql.= natural_search('s.nom', $search_societe);
296 if (strlen($search_poste)) $sql.= natural_search('p.poste', $search_poste);
297 if (strlen($search_phone_perso)) $sql.= natural_search('p.phone_perso', $search_phone_perso);
298 if (strlen($search_phone_pro)) $sql.= natural_search('p.phone', $search_phone);
299 if (strlen($search_phone_mobile)) $sql.= natural_search('p.phone_mobile', $search_phone_mobile);
300 if (strlen($search_fax)) $sql.= natural_search('p.fax', $search_fax);
301 if (strlen($search_skype)) $sql.= natural_search('p.skype', $search_skype);
302 if (strlen($search_email)) $sql.= natural_search('p.email', $search_email);
303 if ($search_status != '' && $search_status >= 0) $sql.= " AND p.statut = ".$db->escape($search_status);
304 if ($search_import_key) $sql.= natural_search("p.import_key",$search_import_key);
305 if ($type == "o") // filtre sur type
306 {
307  $sql .= " AND p.fk_soc IS NULL";
308 }
309 else if ($type == "f") // filtre sur type
310 {
311  $sql .= " AND s.fournisseur = 1";
312 }
313 else if ($type == "c") // filtre sur type
314 {
315  $sql .= " AND s.client IN (1, 3)";
316 }
317 else if ($type == "p") // filtre sur type
318 {
319  $sql .= " AND s.client IN (2, 3)";
320 }
321 if (! empty($socid))
322 {
323  $sql .= " AND s.rowid = ".$socid;
324 }
325 // Add where from extra fields
326 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
327 // Add where from hooks
328 $parameters=array();
329 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
330 $sql.=$hookmanager->resPrint;
331 // Add order
332 if ($view == "recent")
333 {
334  $sql.= $db->order("p.datec","DESC");
335 }
336 else
337 {
338  $sql.= $db->order($sortfield,$sortorder);
339 }
340 
341 // Count total nb of records
342 $nbtotalofrecords = '';
343 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
344 {
345  $result = $db->query($sql);
346  $nbtotalofrecords = $db->num_rows($result);
347 }
348 
349 $sql.= $db->plimit($limit+1, $offset);
350 
351 $result = $db->query($sql);
352 if (! $result)
353 {
354  dol_print_error($db);
355  exit;
356 }
357 
358 $num = $db->num_rows($result);
359 
360 $arrayofselected=is_array($toselect)?$toselect:array();
361 
362 if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($sall != '' || $seearch_cti != ''))
363 {
364  $obj = $db->fetch_object($resql);
365  $id = $obj->rowid;
366  header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
367  exit;
368 }
369 
370 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
371 llxHeader('',$title,$help_url);
372 
373 $param='';
374 if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
375 if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
376 $param.='&begin='.urlencode($begin).'&view='.urlencode($view).'&userid='.urlencode($userid).'&contactname='.urlencode($sall);
377 $param.='&type='.urlencode($type).'&view='.urlencode($view);
378 if (!empty($search_categ)) $param.='&search_categ='.urlencode($search_categ);
379 if (!empty($search_categ_thirdparty)) $param.='&search_categ_thirdparty='.urlencode($search_categ_thirdparty);
380 if (!empty($search_categ_supplier)) $param.='&search_categ_supplier='.urlencode($search_categ_supplier);
381 if ($sall != '') $param.='&amp;sall='.urlencode($sall);
382 if ($search_id > 0) $param.= "&search_id=".urlencode($search_id);
383 if ($search_lastname != '') $param.='&amp;search_lastname='.urlencode($search_lastname);
384 if ($search_firstname != '') $param.='&amp;search_firstname='.urlencode($search_firstname);
385 if ($search_societe != '') $param.='&amp;search_societe='.urlencode($search_societe);
386 if ($search_zip != '') $param.='&amp;search_zip='.urlencode($search_zip);
387 if ($search_town != '') $param.='&amp;search_town='.urlencode($search_town);
388 if ($search_job != '') $param.='&amp;search_job='.urlencode($search_job);
389 if ($search_phone_pro != '') $param.='&amp;search_phone_pro='.urlencode($search_phone_pro);
390 if ($search_phone_perso != '') $param.='&amp;search_phone_perso='.urlencode($search_phone_perso);
391 if ($search_phone_mobile != '') $param.='&amp;search_phone_mobile='.urlencode($search_phone_mobile);
392 if ($search_fax != '') $param.='&amp;search_fax='.urlencode($search_fax);
393 if ($search_email != '') $param.='&amp;search_email='.urlencode($search_email);
394 if ($search_status != '') $param.='&amp;search_status='.urlencode($search_status);
395 if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".urlencode($search_priv);
396 if ($search_import_key != '') $param.='&search_import_key='.urlencode($search_import_key);
397 if ($optioncss != '') $param.='&optioncss='.$optioncss;
398 
399 // Add $param from extra fields
400 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
401 
402 // List of mass actions available
403 $arrayofmassactions = array(
404 // 'presend'=>$langs->trans("SendByMail"),
405 // 'builddoc'=>$langs->trans("PDFMerge"),
406 );
407 //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
408 if ($user->rights->societe->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
409 if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
410 $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
411 
412 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
413 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
414 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
415 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
416 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
417 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
418 print '<input type="hidden" name="page" value="'.$page.'">';
419 print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
420 
421 print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies.png', 0, '', '', $limit);
422 
423 $topicmail="Information";
424 $modelmail="contact";
425 $objecttmp=new Contact($db);
426 $trackid='ctc'.$object->id;
427 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
428 
429 if ($sall)
430 {
431  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
432  print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
433 }
434 if ($search_firstlast_only)
435 {
436  print $langs->trans("FilterOnInto", $search_firstlast_only) . $langs->trans("Lastname").", ".$langs->trans("Firstname");
437 }
438 
439 $moreforfilter='';
440 if (! empty($conf->categorie->enabled))
441 {
442  require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
443  $moreforfilter.='<div class="divsearchfield">';
444  $moreforfilter.=$langs->trans('Categories'). ': ';
445  $moreforfilter.=$formother->select_categories(Categorie::TYPE_CONTACT,$search_categ,'search_categ',1);
446  $moreforfilter.='</div>';
447  if (empty($type) || $type == 'c' || $type == 'p')
448  {
449  $moreforfilter.='<div class="divsearchfield">';
450  if ($type == 'c') $moreforfilter.=$langs->trans('CustomersCategoriesShort'). ': ';
451  else if ($type == 'p') $moreforfilter.=$langs->trans('ProspectsCategoriesShort'). ': ';
452  else $moreforfilter.=$langs->trans('CustomersProspectsCategoriesShort'). ': ';
453  $moreforfilter.=$formother->select_categories(Categorie::TYPE_CUSTOMER,$search_categ_thirdparty,'search_categ_thirdparty',1);
454  $moreforfilter.='</div>';
455  }
456  if (empty($type) || $type == 'f')
457  {
458  $moreforfilter.='<div class="divsearchfield">';
459  $moreforfilter.=$langs->trans('SuppliersCategoriesShort'). ': ';
460  $moreforfilter.=$formother->select_categories(Categorie::TYPE_SUPPLIER,$search_categ_supplier,'search_categ_supplier',1);
461  $moreforfilter.='</div>';
462  }
463 }
464 if ($moreforfilter)
465 {
466  print '<div class="liste_titre liste_titre_bydiv centpercent">';
467  print $moreforfilter;
468  $parameters=array('type'=>$type);
469  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
470  print $hookmanager->resPrint;
471  print '</div>';
472 }
473 
474 $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
475 $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
476 if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
477 
478 print '<div class="div-table-responsive">';
479 print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
480 
481 // Lines for filter fields
482 print '<tr class="liste_titre_filter">';
483 if (! empty($arrayfields['p.rowid']['checked']))
484 {
485  print '<td class="liste_titre">';
486  print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
487  print '</td>';
488 }
489 if (! empty($arrayfields['p.lastname']['checked']))
490 {
491  print '<td class="liste_titre">';
492  print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
493  print '</td>';
494 }
495 if (! empty($arrayfields['p.firstname']['checked']))
496 {
497  print '<td class="liste_titre">';
498  print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
499  print '</td>';
500 }
501 if (! empty($arrayfields['p.zip']['checked']))
502 {
503  print '<td class="liste_titre">';
504  print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
505  print '</td>';
506 }
507 if (! empty($arrayfields['p.town']['checked']))
508 {
509  print '<td class="liste_titre">';
510  print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
511  print '</td>';
512 }
513 if (! empty($arrayfields['p.poste']['checked']))
514 {
515  print '<td class="liste_titre">';
516  print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
517  print '</td>';
518 }
519 if (! empty($arrayfields['p.phone']['checked']))
520 {
521  print '<td class="liste_titre">';
522  print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
523  print '</td>';
524 }
525 if (! empty($arrayfields['p.phone_perso']['checked']))
526 {
527  print '<td class="liste_titre">';
528  print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
529  print '</td>';
530 }
531 if (! empty($arrayfields['p.phone_mobile']['checked']))
532 {
533  print '<td class="liste_titre">';
534  print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
535  print '</td>';
536 }
537 if (! empty($arrayfields['p.fax']['checked']))
538 {
539  print '<td class="liste_titre">';
540  print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
541  print '</td>';
542 }
543 if (! empty($arrayfields['p.email']['checked']))
544 {
545  print '<td class="liste_titre">';
546  print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
547  print '</td>';
548 }
549 if (! empty($arrayfields['p.skype']['checked']))
550 {
551  print '<td class="liste_titre">';
552  print '<input class="flat" type="text" name="search_skype" size="6" value="'.dol_escape_htmltag($search_skype).'">';
553  print '</td>';
554 }
555 if (! empty($arrayfields['p.thirdparty']['checked']))
556 {
557  print '<td class="liste_titre">';
558  print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
559  print '</td>';
560 }
561 if (! empty($arrayfields['p.priv']['checked']))
562 {
563  print '<td class="liste_titre" align="center">';
564  $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
565  print $form->selectarray('search_priv',$selectarray,$search_priv,1);
566  print '</td>';
567 }
568 // Extra fields
569 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
570 
571 // Fields from hook
572 $parameters=array('arrayfields'=>$arrayfields);
573 $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
574 print $hookmanager->resPrint;
575 // Date creation
576 if (! empty($arrayfields['p.datec']['checked']))
577 {
578  print '<td class="liste_titre">';
579  print '</td>';
580 }
581 // Date modification
582 if (! empty($arrayfields['p.tms']['checked']))
583 {
584  print '<td class="liste_titre">';
585  print '</td>';
586 }
587 // Status
588 if (! empty($arrayfields['p.statut']['checked']))
589 {
590  print '<td class="liste_titre center">';
591  print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('ActivityCeased'),'1'=>$langs->trans('InActivity')),$search_status);
592  print '</td>';
593 }
594 if (! empty($arrayfields['p.import_key']['checked']))
595 {
596  print '<td class="liste_titre center">';
597  print '<input class="flat searchstring" type="text" name="search_import_key" size="3" value="'.dol_escape_htmltag($search_import_key).'">';
598  print '</td>';
599 }
600 // Action column
601 print '<td class="liste_titre" align="right">';
602 $searchpicto=$form->showFilterButtons();
603 print $searchpicto;
604 print '</td>';
605 
606 print '</tr>';
607 
608 // Ligne des titres
609 print '<tr class="liste_titre">';
610 if (! empty($arrayfields['p.rowid']['checked'])) print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"],"p.rowid","",$param,"",$sortfield,$sortorder);
611 if (! empty($arrayfields['p.lastname']['checked'])) print_liste_field_titre($arrayfields['p.lastname']['label'],$_SERVER["PHP_SELF"],"p.lastname", $begin, $param, '', $sortfield,$sortorder);
612 if (! empty($arrayfields['p.firstname']['checked'])) print_liste_field_titre($arrayfields['p.firstname']['label'],$_SERVER["PHP_SELF"],"p.firstname", $begin, $param, '', $sortfield,$sortorder);
613 if (! empty($arrayfields['p.zip']['checked'])) print_liste_field_titre($arrayfields['p.zip']['label'],$_SERVER["PHP_SELF"],"p.zip", $begin, $param, '', $sortfield,$sortorder);
614 if (! empty($arrayfields['p.town']['checked'])) print_liste_field_titre($arrayfields['p.town']['label'],$_SERVER["PHP_SELF"],"p.town", $begin, $param, '', $sortfield,$sortorder);
615 if (! empty($arrayfields['p.poste']['checked'])) print_liste_field_titre($arrayfields['p.poste']['label'],$_SERVER["PHP_SELF"],"p.poste", $begin, $param, '', $sortfield,$sortorder);
616 if (! empty($arrayfields['p.phone']['checked'])) print_liste_field_titre($arrayfields['p.phone']['label'],$_SERVER["PHP_SELF"],"p.phone", $begin, $param, '', $sortfield,$sortorder);
617 if (! empty($arrayfields['p.phone_perso']['checked'])) print_liste_field_titre($arrayfields['p.phone_perso']['label'],$_SERVER["PHP_SELF"],"p.phone_perso", $begin, $param, '', $sortfield,$sortorder);
618 if (! empty($arrayfields['p.phone_mobile']['checked'])) print_liste_field_titre($arrayfields['p.phone_mobile']['label'],$_SERVER["PHP_SELF"],"p.phone_mobile", $begin, $param, '', $sortfield,$sortorder);
619 if (! empty($arrayfields['p.fax']['checked'])) print_liste_field_titre($arrayfields['p.fax']['label'],$_SERVER["PHP_SELF"],"p.fax", $begin, $param, '', $sortfield,$sortorder);
620 if (! empty($arrayfields['p.email']['checked'])) print_liste_field_titre($arrayfields['p.email']['label'],$_SERVER["PHP_SELF"],"p.email", $begin, $param, '', $sortfield,$sortorder);
621 if (! empty($arrayfields['p.skype']['checked'])) print_liste_field_titre($arrayfields['p.skype']['label'],$_SERVER["PHP_SELF"],"p.skype", $begin, $param, '', $sortfield,$sortorder);
622 if (! empty($arrayfields['p.thirdparty']['checked'])) print_liste_field_titre($arrayfields['p.thirdparty']['label'],$_SERVER["PHP_SELF"],"s.nom", $begin, $param, '', $sortfield,$sortorder);
623 if (! empty($arrayfields['p.priv']['checked'])) print_liste_field_titre($arrayfields['p.priv']['label'],$_SERVER["PHP_SELF"],"p.priv", $begin, $param, 'align="center"', $sortfield,$sortorder);
624 // Extra fields
625 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
626 // Hook fields
627 $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
628 $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
629 print $hookmanager->resPrint;
630 if (! empty($arrayfields['p.datec']['checked'])) print_liste_field_titre($arrayfields['p.datec']['label'],$_SERVER["PHP_SELF"],"p.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
631 if (! empty($arrayfields['p.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'],$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
632 if (! empty($arrayfields['p.statut']['checked'])) print_liste_field_titre($arrayfields['p.statut']['label'],$_SERVER["PHP_SELF"],"p.statut","",$param,'align="center"',$sortfield,$sortorder);
633 if (! empty($arrayfields['p.import_key']['checked'])) print_liste_field_titre($arrayfields['p.import_key']['label'],$_SERVER["PHP_SELF"],"p.import_key","",$param,'align="center"',$sortfield,$sortorder);
634 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
635 print "</tr>\n";
636 
637 
638 $i = 0;
639 $totalarray=array();
640 while ($i < min($num,$limit))
641 {
642  $obj = $db->fetch_object($result);
643 
644  print '<tr class="oddeven">';
645 
646  $contactstatic->lastname=$obj->lastname;
647  $contactstatic->firstname='';
648  $contactstatic->id=$obj->rowid;
649  $contactstatic->statut=$obj->statut;
650  $contactstatic->poste=$obj->poste;
651  $contactstatic->email=$obj->email;
652  $contactstatic->phone_pro=$obj->phone_pro;
653  $contactstatic->phone_perso=$obj->phone_perso;
654  $contactstatic->phone_mobile=$obj->phone_mobile;
655  $contactstatic->zip=$obj->zip;
656  $contactstatic->town=$obj->town;
657 
658  // ID
659  if (! empty($arrayfields['p.rowid']['checked']))
660  {
661  print '<td class="tdoverflowmax50">';
662  print $obj->rowid;
663  print "</td>\n";
664  if (! $i) $totalarray['nbfield']++;
665  }
666  // Name
667  if (! empty($arrayfields['p.lastname']['checked']))
668  {
669  print '<td valign="middle">';
670  print $contactstatic->getNomUrl(1,'',0);
671  print '</td>';
672  if (! $i) $totalarray['nbfield']++;
673  }
674  // Firstname
675  if (! empty($arrayfields['p.firstname']['checked']))
676  {
677  print '<td>'.$obj->firstname.'</td>';
678  if (! $i) $totalarray['nbfield']++;
679  }
680  // Zip
681  if (! empty($arrayfields['p.zip']['checked']))
682  {
683  print '<td>'.$obj->zip.'</td>';
684  if (! $i) $totalarray['nbfield']++;
685  }
686  // Town
687  if (! empty($arrayfields['p.town']['checked']))
688  {
689  print '<td>'.$obj->town.'</td>';
690  if (! $i) $totalarray['nbfield']++;
691  }
692  // Function
693  if (! empty($arrayfields['p.poste']['checked']))
694  {
695  print '<td>'.dol_trunc($obj->poste,20).'</td>';
696  if (! $i) $totalarray['nbfield']++;
697  }
698  // Phone
699  if (! empty($arrayfields['p.phone']['checked']))
700  {
701  print '<td>'.dol_print_phone($obj->phone_pro,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
702  if (! $i) $totalarray['nbfield']++;
703  }
704  // Phone perso
705  if (! empty($arrayfields['p.phone_perso']['checked']))
706  {
707  print '<td>'.dol_print_phone($obj->phone_perso,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
708  if (! $i) $totalarray['nbfield']++;
709  }
710  // Phone mobile
711  if (! empty($arrayfields['p.phone_mobile']['checked']))
712  {
713  print '<td>'.dol_print_phone($obj->phone_mobile,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
714  if (! $i) $totalarray['nbfield']++;
715  }
716  // Fax
717  if (! empty($arrayfields['p.fax']['checked']))
718  {
719  print '<td>'.dol_print_phone($obj->fax,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').'</td>';
720  if (! $i) $totalarray['nbfield']++;
721  }
722  // EMail
723  if (! empty($arrayfields['p.email']['checked']))
724  {
725  print '<td>'.dol_print_email($obj->email,$obj->rowid,$obj->socid,'AC_EMAIL',18).'</td>';
726  if (! $i) $totalarray['nbfield']++;
727  }
728  // Skype
729  if (! empty($arrayfields['p.skype']['checked']))
730  {
731  if (! empty($conf->skype->enabled)) { print '<td>'.dol_print_skype($obj->skype,$obj->rowid,$obj->socid,'AC_SKYPE',18).'</td>'; }
732  if (! $i) $totalarray['nbfield']++;
733  }
734  // Company
735  if (! empty($arrayfields['p.thirdparty']['checked']))
736  {
737  print '<td>';
738  if ($obj->socid)
739  {
740  $objsoc = new Societe($db);
741  $objsoc->fetch($obj->socid);
742  print $objsoc->getNomUrl(1);
743  }
744  else
745  print '&nbsp;';
746  print '</td>';
747  if (! $i) $totalarray['nbfield']++;
748  }
749 
750  // Private/Public
751  if (! empty($arrayfields['p.priv']['checked']))
752  {
753  print '<td align="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
754  if (! $i) $totalarray['nbfield']++;
755  }
756 
757  // Extra fields
758  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
759  // Fields from hook
760  $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
761  $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
762  print $hookmanager->resPrint;
763  // Date creation
764  if (! empty($arrayfields['p.datec']['checked']))
765  {
766  print '<td align="center">';
767  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
768  print '</td>';
769  if (! $i) $totalarray['nbfield']++;
770  }
771  // Date modification
772  if (! empty($arrayfields['p.tms']['checked']))
773  {
774  print '<td align="center">';
775  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
776  print '</td>';
777  if (! $i) $totalarray['nbfield']++;
778  }
779  // Status
780  if (! empty($arrayfields['p.statut']['checked']))
781  {
782  print '<td align="center">'.$contactstatic->getLibStatut(3).'</td>';
783  if (! $i) $totalarray['nbfield']++;
784  }
785  if (! empty($arrayfields['p.import_key']['checked']))
786  {
787  print '<td class="tdoverflowmax100">';
788  print $obj->import_key;
789  print "</td>\n";
790  if (! $i) $totalarray['nbfield']++;
791  }
792 
793  // Action column
794  print '<td class="nowrap" align="center">';
795  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
796  {
797  $selected=0;
798  if (in_array($obj->rowid, $arrayofselected)) $selected=1;
799  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
800  }
801  print '</td>';
802  if (! $i) $totalarray['nbfield']++;
803 
804  print "</tr>\n";
805  $i++;
806 }
807 
808 $db->free($result);
809 
810 $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
811 $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
812 print $hookmanager->resPrint;
813 
814 print "</table>";
815 print "</div>";
816 
817 //if ($num > $limit || $page) print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies.png', 0, '', '', $limit, 1);
818 
819 print '</form>';
820 
821 
822 llxFooter();
823 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage contact/addresses.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:46
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.