mo_list.php 32 KB

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