myobject_list.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/modulebuilder/template/myobject_list.php
  20. * \ingroup mymodule
  21. * \brief List page for myobject
  22. */
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Do not create database handler $db
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Do not load object $user
  25. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // Do not load object $mysoc
  26. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Do not load object $langs
  27. //if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION','1'); // Do not check injection attack on GET parameters
  28. //if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION','1'); // Do not check injection attack on POST parameters
  29. //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
  30. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
  31. //if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
  32. //if (! defined('NOIPCHECK')) define('NOIPCHECK','1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  33. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu
  34. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
  35. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); // Do not load ajax.lib.php library
  36. //if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
  37. //if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT','auto'); // Force lang to a particular value
  38. //if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE','aloginmodule'); // Force authentication handler
  39. //if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN',1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
  40. //if (! defined("XFRAMEOPTIONS_ALLOWALL")) define('XFRAMEOPTIONS_ALLOWALL',1); // Do not add the HTTP header 'X-Frame-Options: SAMEORIGIN' but 'X-Frame-Options: ALLOWALL'
  41. // Load Dolibarr environment
  42. $res=0;
  43. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  44. if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  45. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  46. $tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
  47. while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
  48. if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include substr($tmp, 0, ($i+1))."/main.inc.php";
  49. if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include dirname(substr($tmp, 0, ($i+1)))."/main.inc.php";
  50. // Try main.inc.php using relative path
  51. if (! $res && file_exists("../main.inc.php")) $res=@include "../main.inc.php";
  52. if (! $res && file_exists("../../main.inc.php")) $res=@include "../../main.inc.php";
  53. if (! $res && file_exists("../../../main.inc.php")) $res=@include "../../../main.inc.php";
  54. if (! $res) die("Include of main fails");
  55. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  56. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  57. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  58. dol_include_once('/mymodule/class/myobject.class.php');
  59. // Load translation files required by the page
  60. $langs->loadLangs(array("mymodule@mymodule","other"));
  61. $action = GETPOST('action','aZ09')?GETPOST('action','aZ09'):'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  62. $massaction = GETPOST('massaction','alpha'); // The bulk action (combo box choice into lists)
  63. $show_files = GETPOST('show_files','int'); // Show files area generated by bulk actions ?
  64. $confirm = GETPOST('confirm','alpha'); // Result of a confirmation
  65. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  66. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  67. $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectlist'; // To manage different context of search
  68. $backtopage = GETPOST('backtopage','alpha'); // Go back to a dedicated page
  69. $optioncss = GETPOST('optioncss','aZ'); // Option for the css output (always '' except when 'print')
  70. $id = GETPOST('id','int');
  71. // Load variable for pagination
  72. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  73. $sortfield = GETPOST('sortfield','alpha');
  74. $sortorder = GETPOST('sortorder','alpha');
  75. $page = GETPOST('page','int');
  76. if (empty($page) || $page == -1 || GETPOST('button_search','alpha') || GETPOST('button_removefilter','alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  77. $offset = $limit * $page;
  78. $pageprev = $page - 1;
  79. $pagenext = $page + 1;
  80. //if (! $sortfield) $sortfield="p.date_fin";
  81. //if (! $sortorder) $sortorder="DESC";
  82. // Initialize technical objects
  83. $object = new MyObject($db);
  84. $extrafields = new ExtraFields($db);
  85. $diroutputmassaction = $conf->mymodule->dir_output . '/temp/massgeneration/'.$user->id;
  86. $hookmanager->initHooks(array('myobjectlist')); // Note that conf->hooks_modules contains array
  87. // Fetch optionals attributes and labels
  88. $extralabels = $extrafields->fetch_name_optionals_label('myobject'); // Load $extrafields->attributes['myobject']
  89. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,'','search_');
  90. // Default sort order (if not yet defined by previous GETPOST)
  91. if (! $sortfield) $sortfield="t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  92. if (! $sortorder) $sortorder="ASC";
  93. // Security check
  94. $socid=0;
  95. if ($user->societe_id > 0) // Protection if external user
  96. {
  97. //$socid = $user->societe_id;
  98. accessforbidden();
  99. }
  100. //$result = restrictedArea($user, 'mymodule', $id, '');
  101. // Initialize array of search criterias
  102. $search_all=trim(GETPOST("search_all",'alpha'));
  103. $search=array();
  104. foreach($object->fields as $key => $val)
  105. {
  106. if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha');
  107. }
  108. // List of fields to search into when doing a "search in all"
  109. $fieldstosearchall = array();
  110. foreach($object->fields as $key => $val)
  111. {
  112. if ($val['searchall']) $fieldstosearchall['t.'.$key]=$val['label'];
  113. }
  114. // Definition of fields for list
  115. $arrayfields=array();
  116. foreach($object->fields as $key => $val)
  117. {
  118. // If $val['visible']==0, then we never show the field
  119. if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled'], 'position'=>$val['position']);
  120. }
  121. // Extra fields
  122. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)
  123. {
  124. foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val)
  125. {
  126. if (! empty($extrafields->attributes[$object->table_element]['list'][$key]))
  127. $arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key])!=3 && $extrafields->attributes[$object->table_element]['perms'][$key]));
  128. }
  129. }
  130. $object->fields = dol_sort_array($object->fields, 'position');
  131. $arrayfields = dol_sort_array($arrayfields, 'position');
  132. /*
  133. * Actions
  134. */
  135. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  136. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  137. $parameters=array();
  138. $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  139. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  140. if (empty($reshook))
  141. {
  142. // Selection of new fields
  143. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  144. // Purge search criteria
  145. 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
  146. {
  147. foreach($object->fields as $key => $val)
  148. {
  149. $search[$key]='';
  150. }
  151. $toselect='';
  152. $search_array_options=array();
  153. }
  154. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
  155. || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
  156. {
  157. $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  158. }
  159. // Mass actions
  160. $objectclass='MyObject';
  161. $objectlabel='MyObject';
  162. $permtoread = $user->rights->mymodule->read;
  163. $permtodelete = $user->rights->mymodule->delete;
  164. $uploaddir = $conf->mymodule->dir_output;
  165. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  166. }
  167. /*
  168. * View
  169. */
  170. $form=new Form($db);
  171. $now=dol_now();
  172. //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  173. $help_url='';
  174. $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects"));
  175. // Build and execute select
  176. // --------------------------------------------------------------------
  177. $sql = 'SELECT ';
  178. foreach($object->fields as $key => $val)
  179. {
  180. $sql.='t.'.$key.', ';
  181. }
  182. // Add fields from extrafields
  183. if (! empty($extrafields->attributes[$object->table_element]['label']))
  184. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
  185. // Add fields from hooks
  186. $parameters=array();
  187. $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  188. $sql.=$hookmanager->resPrint;
  189. $sql=preg_replace('/, $/','', $sql);
  190. $sql.= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  191. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  192. if ($object->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity($object->element).")";
  193. else $sql.=" WHERE 1 = 1";
  194. foreach($search as $key => $val)
  195. {
  196. if ($key == 'status' && $search[$key] == -1) continue;
  197. $mode_search=(($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))?1:0);
  198. if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'status')?2:$mode_search));
  199. }
  200. if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_all);
  201. // Add where from extra fields
  202. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  203. // Add where from hooks
  204. $parameters=array();
  205. $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  206. $sql.=$hookmanager->resPrint;
  207. /* If a group by is required
  208. $sql.= " GROUP BY "
  209. foreach($object->fields as $key => $val)
  210. {
  211. $sql.='t.'.$key.', ';
  212. }
  213. // Add fields from extrafields
  214. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  215. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  216. // Add where from hooks
  217. $parameters=array();
  218. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  219. $sql.=$hookmanager->resPrint;
  220. $sql=preg_replace('/, $/','', $sql);
  221. */
  222. $sql.=$db->order($sortfield,$sortorder);
  223. // Count total nb of records
  224. $nbtotalofrecords = '';
  225. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  226. {
  227. $resql = $db->query($sql);
  228. $nbtotalofrecords = $db->num_rows($resql);
  229. if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
  230. {
  231. $page = 0;
  232. $offset = 0;
  233. }
  234. }
  235. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  236. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
  237. {
  238. $num = $nbtotalofrecords;
  239. }
  240. else
  241. {
  242. $sql.= $db->plimit($limit+1, $offset);
  243. $resql=$db->query($sql);
  244. if (! $resql)
  245. {
  246. dol_print_error($db);
  247. exit;
  248. }
  249. $num = $db->num_rows($resql);
  250. }
  251. // Direct jump if only one record found
  252. if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
  253. {
  254. $obj = $db->fetch_object($resql);
  255. $id = $obj->rowid;
  256. header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id);
  257. exit;
  258. }
  259. // Output page
  260. // --------------------------------------------------------------------
  261. llxHeader('', $title, $help_url);
  262. // Example : Adding jquery code
  263. print '<script type="text/javascript" language="javascript">
  264. jQuery(document).ready(function() {
  265. function init_myfunc()
  266. {
  267. jQuery("#myid").removeAttr(\'disabled\');
  268. jQuery("#myid").attr(\'disabled\',\'disabled\');
  269. }
  270. init_myfunc();
  271. jQuery("#mybutton").click(function() {
  272. init_myfunc();
  273. });
  274. });
  275. </script>';
  276. $arrayofselected=is_array($toselect)?$toselect:array();
  277. $param='';
  278. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  279. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  280. foreach($search as $key => $val)
  281. {
  282. $param.= '&search_'.$key.'='.urlencode($search[$key]);
  283. }
  284. if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
  285. // Add $param from extra fields
  286. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  287. // List of mass actions available
  288. $arrayofmassactions = array(
  289. //'presend'=>$langs->trans("SendByMail"),
  290. //'builddoc'=>$langs->trans("PDFMerge"),
  291. );
  292. if ($user->rights->mymodule->delete) $arrayofmassactions['predelete']=$langs->trans("Delete");
  293. if (GETPOST('nomassaction','int') || in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  294. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  295. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  296. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  297. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  298. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  299. print '<input type="hidden" name="action" value="list">';
  300. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  301. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  302. print '<input type="hidden" name="page" value="'.$page.'">';
  303. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  304. $newcardbutton='';
  305. //if ($user->rights->mymodule->creer)
  306. //{
  307. $newcardbutton='<a class="butActionNew" href="myobject_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']).'"><span class="valignmiddle">'.$langs->trans('New').'</span>';
  308. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  309. $newcardbutton.= '</a>';
  310. //}
  311. //else
  312. //{
  313. // $newcardbutton='<a class="butActionNewRefused" href="#">'.$langs->trans('New');
  314. // $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  315. // $newcardbutton.= '</a>';
  316. //}
  317. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit);
  318. // Add code for pre mass action (confirmation or email presend form)
  319. $topicmail="SendMyObjectRef";
  320. $modelmail="myobject";
  321. $objecttmp=new MyObject($db);
  322. $trackid='xxxx'.$object->id;
  323. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  324. if ($sall)
  325. {
  326. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  327. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
  328. }
  329. $moreforfilter = '';
  330. /*$moreforfilter.='<div class="divsearchfield">';
  331. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  332. $moreforfilter.= '</div>';*/
  333. $parameters=array();
  334. $reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  335. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  336. else $moreforfilter = $hookmanager->resPrint;
  337. if (! empty($moreforfilter))
  338. {
  339. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  340. print $moreforfilter;
  341. print '</div>';
  342. }
  343. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  344. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  345. $selectedfields.=(count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  346. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  347. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  348. // Fields title search
  349. // --------------------------------------------------------------------
  350. print '<tr class="liste_titre">';
  351. foreach($object->fields as $key => $val)
  352. {
  353. $cssforfield='';
  354. if (in_array($val['type'], array('date','datetime','timestamp'))) $cssforfield.=($cssforfield?' ':'').'center';
  355. if (in_array($val['type'], array('timestamp'))) $cssforfield.=($cssforfield?' ':'').'nowrap';
  356. if ($key == 'status') $cssforfield.=($cssforfield?' ':'').'center';
  357. if (! empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($cssforfield?' '.$cssforfield:'').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>';
  358. }
  359. // Extra fields
  360. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  361. // Fields from hook
  362. $parameters=array('arrayfields'=>$arrayfields);
  363. $reshook=$hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  364. print $hookmanager->resPrint;
  365. // Action column
  366. print '<td class="liste_titre" align="right">';
  367. $searchpicto=$form->showFilterButtons();
  368. print $searchpicto;
  369. print '</td>';
  370. print '</tr>'."\n";
  371. // Fields title label
  372. // --------------------------------------------------------------------
  373. print '<tr class="liste_titre">';
  374. foreach($object->fields as $key => $val)
  375. {
  376. $cssforfield='';
  377. if (in_array($val['type'], array('date','datetime','timestamp'))) $cssforfield.=($cssforfield?' ':'').'center';
  378. if (in_array($val['type'], array('timestamp'))) $cssforfield.=($cssforfield?' ':'').'nowrap';
  379. if ($key == 'status') $cssforfield.=($cssforfield?' ':'').'center';
  380. if (! empty($arrayfields['t.'.$key]['checked']))
  381. {
  382. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield?'class="'.$cssforfield.'"':''), $sortfield, $sortorder, ($cssforfield?$cssforfield.' ':''))."\n";
  383. }
  384. }
  385. // Extra fields
  386. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  387. // Hook fields
  388. $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
  389. $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  390. print $hookmanager->resPrint;
  391. // Action column
  392. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],'','','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n";
  393. print '</tr>'."\n";
  394. // Detect if we need a fetch on each output line
  395. $needToFetchEachLine=0;
  396. if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
  397. {
  398. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
  399. {
  400. if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object
  401. }
  402. }
  403. // Loop on record
  404. // --------------------------------------------------------------------
  405. $i=0;
  406. $totalarray=array();
  407. while ($i < min($num, $limit))
  408. {
  409. $obj = $db->fetch_object($resql);
  410. if (empty($obj)) break; // Should not happen
  411. // Store properties in $object
  412. $object->id = $obj->rowid;
  413. foreach($object->fields as $key => $val)
  414. {
  415. if (isset($obj->$key)) $object->$key = $obj->$key;
  416. }
  417. // Show here line of result
  418. print '<tr class="oddeven">';
  419. foreach($object->fields as $key => $val)
  420. {
  421. $cssforfield='';
  422. if (in_array($val['type'], array('date','datetime','timestamp'))) $cssforfield.=($cssforfield?' ':'').'center';
  423. elseif ($key == 'status') $cssforfield.=($cssforfield?' ':'').'center';
  424. if (in_array($val['type'], array('timestamp'))) $cssforfield.=($cssforfield?' ':'').'nowrap';
  425. elseif ($key == 'ref') $cssforfield.=($cssforfield?' ':'').'nowrap';
  426. if (! empty($arrayfields['t.'.$key]['checked']))
  427. {
  428. print '<td';
  429. if ($cssforfield || $val['css']) print ' class="';
  430. print $cssforfield;
  431. if ($cssforfield && $val['css']) print ' ';
  432. print $val['css'];
  433. if ($cssforfield || $val['css']) print '"';
  434. print '>';
  435. print $object->showOutputField($val, $key, $obj->$key, '');
  436. print '</td>';
  437. if (! $i) $totalarray['nbfield']++;
  438. if (! empty($val['isameasure']))
  439. {
  440. if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
  441. $totalarray['val']['t.'.$key] += $obj->$key;
  442. }
  443. }
  444. }
  445. // Extra fields
  446. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  447. // Fields from hook
  448. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  449. $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  450. print $hookmanager->resPrint;
  451. // Action column
  452. print '<td class="nowrap" align="center">';
  453. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  454. {
  455. $selected=0;
  456. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  457. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  458. }
  459. print '</td>';
  460. if (! $i) $totalarray['nbfield']++;
  461. print '</tr>';
  462. $i++;
  463. }
  464. // Show total line
  465. if (isset($totalarray['pos']))
  466. {
  467. print '<tr class="liste_total">';
  468. $i=0;
  469. while ($i < $totalarray['nbfield'])
  470. {
  471. $i++;
  472. if (! empty($totalarray['pos'][$i])) print '<td align="right">'.price($totalarray['val'][$totalarray['pos'][$i]]).'</td>';
  473. else
  474. {
  475. if ($i == 1)
  476. {
  477. if ($num < $limit) print '<td class="left">'.$langs->trans("Total").'</td>';
  478. else print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  479. }
  480. else print '<td></td>';
  481. }
  482. }
  483. print '</tr>';
  484. }
  485. // If no record found
  486. if ($num == 0)
  487. {
  488. $colspan=1;
  489. foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; }
  490. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  491. }
  492. $db->free($resql);
  493. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  494. $reshook=$hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  495. print $hookmanager->resPrint;
  496. print '</table>'."\n";
  497. print '</div>'."\n";
  498. print '</form>'."\n";
  499. if (in_array('builddoc',$arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords))
  500. {
  501. $hidegeneratedfilelistifempty=1;
  502. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0;
  503. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  504. $formfile = new FormFile($db);
  505. // Show list of available documents
  506. $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  507. $urlsource.=str_replace('&amp;','&',$param);
  508. $filedir=$diroutputmassaction;
  509. $genallowed=$user->rights->mymodule->read;
  510. $delallowed=$user->rights->mymodule->create;
  511. print $formfile->showdocuments('massfilesarea_mymodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty);
  512. }
  513. // End of page
  514. llxFooter();
  515. $db->close();