mo_list.php 30 KB

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