mo_list.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file mo_list.php
  19. * \ingroup mrp
  20. * \brief List page for mo
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. // load mrp libraries
  28. require_once __DIR__.'/class/mo.class.php';
  29. // for other modules
  30. //dol_include_once('/othermodule/class/otherobject.class.php');
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("mrp", "other"));
  33. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  34. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  35. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  36. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  37. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  38. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  39. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'molist'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  41. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  42. $id = GETPOST('id', 'int');
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  49. // If $page is not defined, or '' or -1 or if we click on clear filters
  50. $page = 0;
  51. }
  52. $offset = $limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. //if (! $sortfield) $sortfield="p.date_fin";
  56. //if (! $sortorder) $sortorder="DESC";
  57. // Initialize technical objects
  58. $object = new Mo($db);
  59. $extrafields = new ExtraFields($db);
  60. $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
  61. $hookmanager->initHooks(array('molist')); // Note that conf->hooks_modules contains array
  62. // Fetch optionals attributes and labels
  63. $extrafields->fetch_name_optionals_label($object->table_element);
  64. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  65. // Default sort order (if not yet defined by previous GETPOST)
  66. if (!$sortfield) {
  67. $sortfield = "t.ref"; // Set here default search field. By default 1st field in definition.
  68. }
  69. if (!$sortorder) {
  70. $sortorder = "ASC";
  71. }
  72. // Initialize array of search criterias
  73. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  74. $search = array();
  75. foreach ($object->fields as $key => $val) {
  76. if (GETPOST('search_'.$key, 'alpha') !== '') {
  77. $search[$key] = GETPOST('search_'.$key, 'alpha');
  78. }
  79. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  80. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  81. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  82. }
  83. }
  84. // List of fields to search into when doing a "search in all"
  85. $fieldstosearchall = array();
  86. foreach ($object->fields as $key => $val) {
  87. if (!empty($val['searchall'])) {
  88. $fieldstosearchall['t.'.$key] = $val['label'];
  89. }
  90. }
  91. // Definition of array of fields for columns
  92. $arrayfields = array();
  93. foreach ($object->fields as $key => $val) {
  94. // If $val['visible']==0, then we never show the field
  95. if (!empty($val['visible'])) {
  96. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  97. $arrayfields['t.'.$key] = array(
  98. 'label'=>$val['label'],
  99. 'checked'=>(($visible < 0) ? 0 : 1),
  100. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  101. 'position'=>$val['position'],
  102. 'help'=> isset($val['help']) ? $val['help'] : ''
  103. );
  104. }
  105. if ($key == 'fk_parent_line') {
  106. $visible = (int) dol_eval($val['visible'], 1);
  107. $arrayfields['t.'.$key] = array(
  108. 'label'=>$val['label'],
  109. 'checked'=>(($visible <= 0) ? 0 : 1),
  110. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
  111. 'position'=>$val['position'],
  112. 'help'=> isset($val['help']) ? $val['help'] : ''
  113. );
  114. }
  115. }
  116. // Extra fields
  117. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  118. $object->fields = dol_sort_array($object->fields, 'position');
  119. $arrayfields = dol_sort_array($arrayfields, 'position');
  120. $permissiontoread = $user->rights->mrp->read;
  121. $permissiontoadd = $user->rights->mrp->write;
  122. $permissiontodelete = $user->rights->mrp->delete;
  123. // Security check
  124. if ($user->socid > 0) {
  125. // Protection if external user
  126. accessforbidden();
  127. }
  128. $result = restrictedArea($user, 'mrp');
  129. /*
  130. * Actions
  131. */
  132. if (GETPOST('cancel', 'alpha')) {
  133. $action = 'list';
  134. $massaction = '';
  135. }
  136. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  137. $massaction = '';
  138. }
  139. $parameters = array();
  140. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  141. if ($reshook < 0) {
  142. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  143. }
  144. if (empty($reshook)) {
  145. // Selection of new fields
  146. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  147. // Purge search criteria
  148. 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
  149. foreach ($object->fields as $key => $val) {
  150. $search[$key] = '';
  151. if ($key == 'status') {
  152. $search[$key] = -1;
  153. }
  154. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  155. $search[$key.'_dtstart'] = '';
  156. $search[$key.'_dtend'] = '';
  157. }
  158. }
  159. $toselect = array();
  160. $search_array_options = array();
  161. }
  162. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  163. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  164. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  165. }
  166. // Mass actions
  167. $objectclass = 'Mo';
  168. $objectlabel = 'Mo';
  169. $uploaddir = $conf->mrp->dir_output;
  170. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  171. }
  172. /*
  173. * View
  174. */
  175. $form = new Form($db);
  176. $now = dol_now();
  177. //$help_url="EN:Module_Mo|FR:Module_Mo_FR|ES:Módulo_Mo";
  178. $help_url = '';
  179. $title = $langs->trans('ListOfManufacturingOrders');
  180. $morejs = array();
  181. $morecss = array();
  182. // Build and execute select
  183. // --------------------------------------------------------------------
  184. $sql = 'SELECT ';
  185. $sql .= $object->getFieldList('t');
  186. // Add fields from extrafields
  187. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  188. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  189. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : "");
  190. }
  191. }
  192. // Add fields from hooks
  193. $parameters = array();
  194. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  195. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  196. $sql = preg_replace('/,\s*$/', '', $sql);
  197. $sqlfields = $sql; // $sql fields to remove for count total
  198. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  199. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  200. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  201. }
  202. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production as lineparent ON t.fk_parent_line = lineparent.rowid";
  203. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_mo as moparent ON lineparent.fk_mo = moparent.rowid";
  204. // Add table from hooks
  205. $parameters = array();
  206. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  207. $sql .= $hookmanager->resPrint;
  208. if ($object->ismultientitymanaged == 1) {
  209. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  210. } else {
  211. $sql .= " WHERE 1 = 1";
  212. }
  213. foreach ($search as $key => $val) {
  214. if (array_key_exists($key, $object->fields)) {
  215. if ($key == 'status' && $search[$key] == -1) {
  216. continue;
  217. }
  218. if ($key == 'fk_parent_line' && $search[$key] != '') {
  219. $sql .= natural_search('moparent.ref', $search[$key], 0);
  220. continue;
  221. }
  222. if ($key == 'status') {
  223. $sql .= natural_search('t.status', $search[$key], 0);
  224. continue;
  225. }
  226. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  227. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  228. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  229. $search[$key] = '';
  230. }
  231. $mode_search = 2;
  232. }
  233. if ($search[$key] != '') {
  234. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  235. }
  236. } else {
  237. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  238. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  239. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  240. if (preg_match('/_dtstart$/', $key)) {
  241. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  242. }
  243. if (preg_match('/_dtend$/', $key)) {
  244. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  245. }
  246. }
  247. }
  248. }
  249. }
  250. if ($search_all) {
  251. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  252. }
  253. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  254. // Add where from extra fields
  255. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  256. // Add where from hooks
  257. $parameters = array();
  258. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  259. $sql .= $hookmanager->resPrint;
  260. /* If a group by is required
  261. $sql.= " GROUP BY ";
  262. foreach($object->fields as $key => $val) {
  263. $sql .= "t.".$key.", ";
  264. }
  265. // Add fields from extrafields
  266. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  267. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  268. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.", " : "");
  269. }
  270. }
  271. // Add where from hooks
  272. $parameters=array();
  273. $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  274. $sql.=$hookmanager->resPrint;
  275. $sql=preg_replace('/,\s*$/','', $sql);
  276. */
  277. // Count total nb of records
  278. $nbtotalofrecords = '';
  279. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  280. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  281. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  282. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  283. $resql = $db->query($sqlforcount);
  284. if ($resql) {
  285. $objforcount = $db->fetch_object($resql);
  286. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  287. } else {
  288. dol_print_error($db);
  289. }
  290. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  291. $page = 0;
  292. $offset = 0;
  293. }
  294. $db->free($resql);
  295. }
  296. // Complete request and execute it with limit
  297. $sql .= $db->order($sortfield, $sortorder);
  298. if ($limit) {
  299. $sql .= $db->plimit($limit + 1, $offset);
  300. }
  301. $resql = $db->query($sql);
  302. if (!$resql) {
  303. dol_print_error($db);
  304. exit;
  305. }
  306. $num = $db->num_rows($resql);
  307. // Direct jump if only one record found
  308. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  309. $obj = $db->fetch_object($resql);
  310. $id = $obj->rowid;
  311. header("Location: ".dol_buildpath('/mrp/mo_card.php', 1).'?id='.$id);
  312. exit;
  313. }
  314. // Output page
  315. // --------------------------------------------------------------------
  316. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  317. $arrayofselected = is_array($toselect) ? $toselect : array();
  318. $param = '';
  319. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  320. $param .= '&contextpage='.urlencode($contextpage);
  321. }
  322. if ($limit > 0 && $limit != $conf->liste_limit) {
  323. $param .= '&limit='.urlencode($limit);
  324. }
  325. foreach ($search as $key => $val) {
  326. if (is_array($search[$key]) && count($search[$key])) {
  327. foreach ($search[$key] as $skey) {
  328. if ($skey != '') {
  329. $param .= '&search_'.$key.'[]='.urlencode($skey);
  330. }
  331. }
  332. } elseif ($search[$key] != '') {
  333. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  334. }
  335. }
  336. if ($optioncss != '') {
  337. $param .= '&optioncss='.urlencode($optioncss);
  338. }
  339. // Add $param from extra fields
  340. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  341. // Add $param from hooks
  342. $parameters = array();
  343. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  344. $param .= $hookmanager->resPrint;
  345. // List of mass actions available
  346. $arrayofmassactions = array(
  347. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  348. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  349. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  350. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  351. );
  352. if ($permissiontodelete) {
  353. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  354. }
  355. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  356. $arrayofmassactions = array();
  357. }
  358. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  359. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  360. if ($optioncss != '') {
  361. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  362. }
  363. print '<input type="hidden" name="token" value="'.newToken().'">';
  364. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  365. print '<input type="hidden" name="action" value="list">';
  366. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  367. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  368. print '<input type="hidden" name="page" value="'.$page.'">';
  369. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  370. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/mrp/mo_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  371. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  372. // Add code for pre mass action (confirmation or email presend form)
  373. $topicmail = "SendMoRef";
  374. $modelmail = "mo";
  375. $objecttmp = new Mo($db);
  376. $trackid = 'mo'.$object->id;
  377. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  378. if ($search_all) {
  379. foreach ($fieldstosearchall as $key => $val) {
  380. $fieldstosearchall[$key] = $langs->trans($val);
  381. }
  382. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  383. }
  384. $moreforfilter = '';
  385. /*$moreforfilter.='<div class="divsearchfield">';
  386. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  387. $moreforfilter.= '</div>';*/
  388. $parameters = array();
  389. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  390. if (empty($reshook)) {
  391. $moreforfilter .= $hookmanager->resPrint;
  392. } else {
  393. $moreforfilter = $hookmanager->resPrint;
  394. }
  395. if (!empty($moreforfilter)) {
  396. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  397. print $moreforfilter;
  398. print '</div>';
  399. }
  400. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  401. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  402. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  403. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  404. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  405. // Fields title search
  406. // --------------------------------------------------------------------
  407. print '<tr class="liste_titre">';
  408. // Action column
  409. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  410. print '<td class="liste_titre maxwidthsearch">';
  411. $searchpicto = $form->showFilterButtons('left');
  412. print $searchpicto;
  413. print '</td>';
  414. }
  415. foreach ($object->fields as $key => $val) {
  416. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  417. if ($key == 'status') {
  418. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  419. } elseif ($key == 'fk_parent_line') {
  420. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  421. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  422. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  423. } elseif (in_array($val['type'], array('timestamp'))) {
  424. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  425. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  426. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  427. }
  428. if (!empty($arrayfields['t.'.$key]['checked'])) {
  429. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  430. if ($key == 'fk_parent_line') {
  431. print '<input type="text" class="flat maxwidth75" name="search_fk_parent_line">';
  432. print '</td>';
  433. continue;
  434. }
  435. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  436. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  437. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  438. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  439. } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  440. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  441. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  442. print '<div class="nowrap">';
  443. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  444. print '</div>';
  445. print '<div class="nowrap">';
  446. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  447. print '</div>';
  448. }
  449. print '</td>';
  450. }
  451. }
  452. // Extra fields
  453. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  454. // Fields from hook
  455. $parameters = array('arrayfields'=>$arrayfields);
  456. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  457. print $hookmanager->resPrint;
  458. // Action column
  459. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  460. print '<td class="liste_titre maxwidthsearch">';
  461. $searchpicto = $form->showFilterButtons();
  462. print $searchpicto;
  463. print '</td>';
  464. }
  465. print '</tr>'."\n";
  466. // Fields title label
  467. // --------------------------------------------------------------------
  468. print '<tr class="liste_titre">';
  469. // Action column
  470. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  471. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  472. }
  473. foreach ($object->fields as $key => $val) {
  474. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  475. if ($key == 'status') {
  476. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  477. } elseif ($key == 'fk_parent_line') {
  478. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  479. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  480. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  481. } elseif (in_array($val['type'], array('timestamp'))) {
  482. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  483. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  484. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  485. }
  486. if (!empty($arrayfields['t.'.$key]['checked'])) {
  487. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  488. }
  489. }
  490. // Extra fields
  491. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  492. // Hook fields
  493. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  494. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  495. print $hookmanager->resPrint;
  496. // Action column
  497. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  498. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  499. }
  500. print '</tr>'."\n";
  501. // Detect if we need a fetch on each output line
  502. $needToFetchEachLine = 0;
  503. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  504. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  505. if (preg_match('/\$object/', $val)) {
  506. $needToFetchEachLine++; // There is at least one compute field that use $object
  507. }
  508. }
  509. }
  510. // Loop on record
  511. // --------------------------------------------------------------------
  512. $i = 0;
  513. $totalarray = array();
  514. $totalarray['nbfield'] = 0;
  515. while ($i < ($limit ? min($num, $limit) : $num)) {
  516. $obj = $db->fetch_object($resql);
  517. if (empty($obj)) {
  518. break; // Should not happen
  519. }
  520. // Store properties in $object
  521. $object->setVarsFromFetchObj($obj);
  522. // Show here line of result
  523. print '<tr class="oddeven">';
  524. // Action column
  525. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  526. print '<td class="nowrap center">';
  527. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  528. $selected = 0;
  529. if (in_array($object->id, $arrayofselected)) {
  530. $selected = 1;
  531. }
  532. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  533. }
  534. print '</td>';
  535. }
  536. foreach ($object->fields as $key => $val) {
  537. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  538. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  539. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  540. } elseif ($key == 'status') {
  541. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  542. } elseif ($key == 'fk_parent_line') {
  543. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  544. }
  545. if (in_array($val['type'], array('timestamp'))) {
  546. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  547. } elseif ($key == 'ref') {
  548. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  549. }
  550. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  551. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  552. }
  553. if (!empty($arrayfields['t.'.$key]['checked'])) {
  554. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  555. if ($key == 'status') {
  556. print $object->getLibStatut(5);
  557. } elseif ($key == 'fk_parent_line') {
  558. $moparent = $object->getMoParent();
  559. if (is_object($moparent)) print $moparent->getNomUrl(1);
  560. } elseif ($key == 'rowid') {
  561. print $object->showOutputField($val, $key, $object->id, '');
  562. } else {
  563. print $object->showOutputField($val, $key, $object->$key, '');
  564. }
  565. print '</td>';
  566. if (!$i) {
  567. $totalarray['nbfield']++;
  568. }
  569. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  570. if (!$i) {
  571. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  572. }
  573. if (!isset($totalarray['val'])) {
  574. $totalarray['val'] = array();
  575. }
  576. if (!isset($totalarray['val']['t.'.$key])) {
  577. $totalarray['val']['t.'.$key] = 0;
  578. }
  579. $totalarray['val']['t.'.$key] += $object->$key;
  580. }
  581. }
  582. }
  583. // Extra fields
  584. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  585. // Fields from hook
  586. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  587. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  588. print $hookmanager->resPrint;
  589. // Action column
  590. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  591. print '<td class="nowrap center">';
  592. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  593. $selected = 0;
  594. if (in_array($object->id, $arrayofselected)) {
  595. $selected = 1;
  596. }
  597. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  598. }
  599. print '</td>';
  600. }
  601. if (!$i) {
  602. $totalarray['nbfield']++;
  603. }
  604. print '</tr>'."\n";
  605. $i++;
  606. }
  607. // Show total line
  608. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  609. // If no record found
  610. if ($num == 0) {
  611. $colspan = 1;
  612. foreach ($arrayfields as $key => $val) {
  613. if (!empty($val['checked'])) {
  614. $colspan++;
  615. }
  616. }
  617. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  618. }
  619. $db->free($resql);
  620. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  621. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  622. print $hookmanager->resPrint;
  623. print '</table>'."\n";
  624. print '</div>'."\n";
  625. print '</form>'."\n";
  626. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  627. $hidegeneratedfilelistifempty = 1;
  628. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  629. $hidegeneratedfilelistifempty = 0;
  630. }
  631. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  632. $formfile = new FormFile($db);
  633. // Show list of available documents
  634. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  635. $urlsource .= str_replace('&amp;', '&', $param);
  636. $filedir = $diroutputmassaction;
  637. $genallowed = $permissiontoread;
  638. $delallowed = $permissiontoadd;
  639. print $formfile->showdocuments('massfilesarea_mrp', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  640. }
  641. // End of page
  642. llxFooter();
  643. $db->close();