mo_list.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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 <http://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 == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  49. $page = 0;
  50. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. //if (! $sortfield) $sortfield="p.date_fin";
  55. //if (! $sortorder) $sortorder="DESC";
  56. // Initialize technical objects
  57. $object = new Mo($db);
  58. $extrafields = new ExtraFields($db);
  59. $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
  60. $hookmanager->initHooks(array('molist')); // Note that conf->hooks_modules contains array
  61. // Fetch optionals attributes and labels
  62. $extrafields->fetch_name_optionals_label($object->table_element);
  63. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  64. // Default sort order (if not yet defined by previous GETPOST)
  65. if (!$sortfield) {
  66. $sortfield = "t.ref"; // Set here default search field. By default 1st field in definition.
  67. }
  68. if (!$sortorder) {
  69. $sortorder = "ASC";
  70. }
  71. // Initialize array of search criterias
  72. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  73. $search = array();
  74. foreach ($object->fields as $key => $val) {
  75. if (GETPOST('search_'.$key, 'alpha') !== '') {
  76. $search[$key] = GETPOST('search_'.$key, 'alpha');
  77. }
  78. }
  79. // List of fields to search into when doing a "search in all"
  80. $fieldstosearchall = array();
  81. foreach ($object->fields as $key => $val) {
  82. if (!empty($val['searchall'])) {
  83. $fieldstosearchall['t.'.$key] = $val['label'];
  84. }
  85. }
  86. // Definition of fields for list
  87. $arrayfields = array();
  88. foreach ($object->fields as $key => $val) {
  89. // If $val['visible']==0, then we never show the field
  90. if (!empty($val['visible'])) {
  91. $arrayfields['t.'.$key] = array(
  92. 'label'=>$val['label'],
  93. 'checked'=>(($visible < 0) ? 0 : 1),
  94. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
  95. 'position'=>$val['position'],
  96. 'help'=>$val['help']
  97. );
  98. }
  99. }
  100. // Extra fields
  101. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  102. $object->fields = dol_sort_array($object->fields, 'position');
  103. $arrayfields = dol_sort_array($arrayfields, 'position');
  104. $permissiontoread = $user->rights->mrp->read;
  105. $permissiontoadd = $user->rights->mrp->write;
  106. $permissiontodelete = $user->rights->mrp->delete;
  107. // Security check
  108. if ($user->socid > 0) {
  109. // Protection if external user
  110. accessforbidden();
  111. }
  112. $result = restrictedArea($user, 'mrp');
  113. /*
  114. * Actions
  115. */
  116. if (GETPOST('cancel', 'alpha')) {
  117. $action = 'list'; $massaction = '';
  118. }
  119. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  120. $massaction = '';
  121. }
  122. $parameters = array();
  123. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  124. if ($reshook < 0) {
  125. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  126. }
  127. if (empty($reshook)) {
  128. // Selection of new fields
  129. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  130. // Purge search criteria
  131. 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
  132. foreach ($object->fields as $key => $val) {
  133. $search[$key] = '';
  134. }
  135. $toselect = array();
  136. $search_array_options = array();
  137. }
  138. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  139. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  140. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  141. }
  142. // Mass actions
  143. $objectclass = 'Mo';
  144. $objectlabel = 'Mo';
  145. $uploaddir = $conf->mrp->dir_output;
  146. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  147. }
  148. /*
  149. * View
  150. */
  151. $form = new Form($db);
  152. $now = dol_now();
  153. //$help_url="EN:Module_Mo|FR:Module_Mo_FR|ES:Módulo_Mo";
  154. $help_url = '';
  155. $title = $langs->trans('ListOfManufacturingOrders');
  156. // Build and execute select
  157. // --------------------------------------------------------------------
  158. $sql = 'SELECT ';
  159. foreach ($object->fields as $key => $val) {
  160. $sql .= 't.'.$key.', ';
  161. }
  162. // Add fields from extrafields
  163. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  164. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  165. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
  166. }
  167. }
  168. // Add fields from hooks
  169. $parameters = array();
  170. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  171. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  172. $sql = preg_replace('/,\s*$/', '', $sql);
  173. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  174. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  175. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  176. }
  177. if ($object->ismultientitymanaged == 1) {
  178. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  179. } else {
  180. $sql .= " WHERE 1 = 1";
  181. }
  182. foreach ($search as $key => $val) {
  183. if ($key == 'status' && $search[$key] == -1) {
  184. continue;
  185. }
  186. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  187. if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
  188. if ($search[$key] == '-1') {
  189. $search[$key] = '';
  190. }
  191. $mode_search = 2;
  192. }
  193. if ($search[$key] != '') {
  194. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  195. }
  196. }
  197. if ($search_all) {
  198. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  199. }
  200. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  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. }
  217. // Add where from hooks
  218. $parameters=array();
  219. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  220. $sql.=$hookmanager->resPrint;
  221. $sql=preg_replace('/,\s*$/','', $sql);
  222. */
  223. $sql .= $db->order($sortfield, $sortorder);
  224. // Count total nb of records
  225. $nbtotalofrecords = '';
  226. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  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. $page = 0;
  231. $offset = 0;
  232. }
  233. }
  234. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  235. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  236. $num = $nbtotalofrecords;
  237. } else {
  238. if ($limit) {
  239. $sql .= $db->plimit($limit + 1, $offset);
  240. }
  241. $resql = $db->query($sql);
  242. if (!$resql) {
  243. dol_print_error($db);
  244. exit;
  245. }
  246. $num = $db->num_rows($resql);
  247. }
  248. // Direct jump if only one record found
  249. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  250. $obj = $db->fetch_object($resql);
  251. $id = $obj->rowid;
  252. header("Location: ".dol_buildpath('/mrp/mo_card.php', 1).'?id='.$id);
  253. exit;
  254. }
  255. // Output page
  256. // --------------------------------------------------------------------
  257. llxHeader('', $title, $help_url);
  258. $arrayofselected = is_array($toselect) ? $toselect : array();
  259. $param = '';
  260. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  261. $param .= '&contextpage='.urlencode($contextpage);
  262. }
  263. if ($limit > 0 && $limit != $conf->liste_limit) {
  264. $param .= '&limit='.urlencode($limit);
  265. }
  266. foreach ($search as $key => $val) {
  267. if (is_array($search[$key]) && count($search[$key])) {
  268. foreach ($search[$key] as $skey) {
  269. $param .= '&search_'.$key.'[]='.urlencode($skey);
  270. }
  271. } else {
  272. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  273. }
  274. }
  275. if ($optioncss != '') {
  276. $param .= '&optioncss='.urlencode($optioncss);
  277. }
  278. // Add $param from extra fields
  279. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  280. // List of mass actions available
  281. $arrayofmassactions = array(
  282. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  283. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  284. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  285. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  286. );
  287. if ($permissiontodelete) {
  288. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  289. }
  290. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  291. $arrayofmassactions = array();
  292. }
  293. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  294. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  295. if ($optioncss != '') {
  296. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  297. }
  298. print '<input type="hidden" name="token" value="'.newToken().'">';
  299. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  300. print '<input type="hidden" name="action" value="list">';
  301. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  302. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  303. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  304. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/mrp/mo_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  305. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'mrp', 0, $newcardbutton, '', $limit, 0, 0, 1);
  306. // Add code for pre mass action (confirmation or email presend form)
  307. $topicmail = "SendMoRef";
  308. $modelmail = "mo";
  309. $objecttmp = new Mo($db);
  310. $trackid = 'mo'.$object->id;
  311. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  312. if ($search_all) {
  313. foreach ($fieldstosearchall as $key => $val) {
  314. $fieldstosearchall[$key] = $langs->trans($val);
  315. }
  316. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  317. }
  318. $moreforfilter = '';
  319. /*$moreforfilter.='<div class="divsearchfield">';
  320. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  321. $moreforfilter.= '</div>';*/
  322. $parameters = array();
  323. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  324. if (empty($reshook)) {
  325. $moreforfilter .= $hookmanager->resPrint;
  326. } else {
  327. $moreforfilter = $hookmanager->resPrint;
  328. }
  329. if (!empty($moreforfilter)) {
  330. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  331. print $moreforfilter;
  332. print '</div>';
  333. }
  334. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  335. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  336. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  337. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  338. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  339. // Fields title search
  340. // --------------------------------------------------------------------
  341. print '<tr class="liste_titre">';
  342. foreach ($object->fields as $key => $val) {
  343. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  344. if ($key == 'status') {
  345. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  346. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  347. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  348. } elseif (in_array($val['type'], array('timestamp'))) {
  349. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  350. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  351. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  352. }
  353. if (!empty($arrayfields['t.'.$key]['checked'])) {
  354. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  355. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  356. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  357. } elseif (strpos($val['type'], 'integer:') === 0) {
  358. print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth125', 1);
  359. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  360. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
  361. }
  362. print '</td>';
  363. }
  364. }
  365. // Extra fields
  366. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  367. // Fields from hook
  368. $parameters = array('arrayfields'=>$arrayfields);
  369. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  370. print $hookmanager->resPrint;
  371. // Action column
  372. print '<td class="liste_titre maxwidthsearch">';
  373. $searchpicto = $form->showFilterButtons();
  374. print $searchpicto;
  375. print '</td>';
  376. print '</tr>'."\n";
  377. // Fields title label
  378. // --------------------------------------------------------------------
  379. print '<tr class="liste_titre">';
  380. foreach ($object->fields as $key => $val) {
  381. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  382. if ($key == 'status') {
  383. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  384. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  385. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  386. } elseif (in_array($val['type'], array('timestamp'))) {
  387. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  388. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  389. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  390. }
  391. if (!empty($arrayfields['t.'.$key]['checked'])) {
  392. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  393. }
  394. }
  395. // Extra fields
  396. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  397. // Hook fields
  398. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  399. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  400. print $hookmanager->resPrint;
  401. // Action column
  402. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  403. print '</tr>'."\n";
  404. // Detect if we need a fetch on each output line
  405. $needToFetchEachLine = 0;
  406. if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  407. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  408. if (preg_match('/\$object/', $val)) {
  409. $needToFetchEachLine++; // There is at least one compute field that use $object
  410. }
  411. }
  412. }
  413. // Loop on record
  414. // --------------------------------------------------------------------
  415. $i = 0;
  416. $totalarray = array();
  417. while ($i < ($limit ? min($num, $limit) : $num)) {
  418. $obj = $db->fetch_object($resql);
  419. if (empty($obj)) {
  420. break; // Should not happen
  421. }
  422. // Store properties in $object
  423. $object->setVarsFromFetchObj($obj);
  424. // Show here line of result
  425. print '<tr class="oddeven">';
  426. foreach ($object->fields as $key => $val) {
  427. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  428. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  429. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  430. } elseif ($key == 'status') {
  431. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  432. }
  433. if (in_array($val['type'], array('timestamp'))) {
  434. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  435. } elseif ($key == 'ref') {
  436. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  437. }
  438. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
  439. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  440. }
  441. if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) {
  442. $cssforfield = 'tdoverflowmax100';
  443. }
  444. if (!empty($arrayfields['t.'.$key]['checked'])) {
  445. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  446. if ($key == 'status') {
  447. print $object->getLibStatut(5);
  448. } else {
  449. print $object->showOutputField($val, $key, $object->$key, '');
  450. }
  451. print '</td>';
  452. if (!$i) {
  453. $totalarray['nbfield']++;
  454. }
  455. if (!empty($val['isameasure'])) {
  456. if (!$i) {
  457. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  458. }
  459. if (!isset($totalarray['val'])) {
  460. $totalarray['val'] = array();
  461. }
  462. if (!isset($totalarray['val']['t.'.$key])) {
  463. $totalarray['val']['t.'.$key] = 0;
  464. }
  465. $totalarray['val']['t.'.$key] += $object->$key;
  466. }
  467. }
  468. }
  469. // Extra fields
  470. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  471. // Fields from hook
  472. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  473. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  474. print $hookmanager->resPrint;
  475. // Action column
  476. print '<td class="nowrap center">';
  477. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  478. $selected = 0;
  479. if (in_array($object->id, $arrayofselected)) {
  480. $selected = 1;
  481. }
  482. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  483. }
  484. print '</td>';
  485. if (!$i) {
  486. $totalarray['nbfield']++;
  487. }
  488. print '</tr>'."\n";
  489. $i++;
  490. }
  491. // Show total line
  492. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  493. // If no record found
  494. if ($num == 0) {
  495. $colspan = 1;
  496. foreach ($arrayfields as $key => $val) {
  497. if (!empty($val['checked'])) {
  498. $colspan++;
  499. }
  500. }
  501. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  502. }
  503. $db->free($resql);
  504. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  505. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  506. print $hookmanager->resPrint;
  507. print '</table>'."\n";
  508. print '</div>'."\n";
  509. print '</form>'."\n";
  510. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  511. $hidegeneratedfilelistifempty = 1;
  512. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  513. $hidegeneratedfilelistifempty = 0;
  514. }
  515. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  516. $formfile = new FormFile($db);
  517. // Show list of available documents
  518. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  519. $urlsource .= str_replace('&amp;', '&', $param);
  520. $filedir = $diroutputmassaction;
  521. $genallowed = $permissiontoread;
  522. $delallowed = $permissiontoadd;
  523. print $formfile->showdocuments('massfilesarea_mrp', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  524. }
  525. // End of page
  526. llxFooter();
  527. $db->close();