productlot_list.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <?php
  2. /* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018-2021 Ferran Marcet <fmarcet@2byte.es>
  4. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file product/stock/productlot_list.php
  21. * \ingroup stock
  22. * \brief This file is an example of a php page
  23. * Initialy built by build_class_from_table on 2016-05-17 12:22
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('stocks', 'productbatch', 'other', 'users'));
  33. // Get parameters
  34. $id = GETPOST('id', 'int');
  35. $action = GETPOST('action', 'aZ09');
  36. $massaction = GETPOST('massaction', 'alpha');
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  39. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'productlotlist'; // To manage different context of search
  40. $optioncss = GETPOST('optioncss', 'alpha');
  41. $search_entity = GETPOST('search_entity', 'int');
  42. $search_product = GETPOST('search_product', 'alpha');
  43. $search_batch = GETPOST('search_batch', 'alpha');
  44. $search_fk_user_creat = GETPOST('search_fk_user_creat', 'int');
  45. $search_fk_user_modif = GETPOST('search_fk_user_modif', 'int');
  46. $search_import_key = GETPOST('search_import_key', 'int');
  47. // Load variable for pagination
  48. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  59. $object = new Productlot($db);
  60. $extrafields = new ExtraFields($db);
  61. $diroutputmassaction = $conf->productbatch->dir_output.'/temp/massgeneration/'.$user->id;
  62. $hookmanager->initHooks(array('product_lotlist'));
  63. // Fetch optionals attributes and labels
  64. $extrafields->fetch_name_optionals_label($object->table_element);
  65. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  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.".key($object->fields); // 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. }
  82. // List of fields to search into when doing a "search in all"
  83. $fieldstosearchall = array();
  84. foreach ($object->fields as $key => $val) {
  85. if (!empty($val['searchall'])) {
  86. $fieldstosearchall['t.'.$key] = $val['label'];
  87. }
  88. }
  89. // Definition of array of fields for columns
  90. $arrayfields = array();
  91. foreach ($object->fields as $key => $val) {
  92. // If $val['visible']==0, then we never show the field
  93. if (!empty($val['visible'])) {
  94. $visible = dol_eval($val['visible'], 1, 1, '1');
  95. $arrayfields['t.'.$key] = array(
  96. 'label'=>$val['label'],
  97. 'checked'=>(($visible < 0) ? 0 : 1),
  98. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  99. 'position'=>$val['position']
  100. );
  101. }
  102. }
  103. // Extra fields
  104. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  105. $object->fields = dol_sort_array($object->fields, 'position');
  106. $arrayfields = dol_sort_array($arrayfields, 'position');
  107. $usercanread = $user->rights->produit->lire;
  108. $usercancreate = $user->rights->produit->creer;
  109. $usercandelete = $user->rights->produit->supprimer;
  110. $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
  111. $permissiontoread = $usercanread;
  112. $permissiontoadd = $usercancreate;
  113. //$permissiontodelete = $usercandelete;
  114. // Security check
  115. if (empty($conf->productbatch->enabled)) {
  116. accessforbidden('Module not enabled');
  117. }
  118. $socid = 0;
  119. if ($user->socid > 0) { // Protection if external user
  120. //$socid = $user->socid;
  121. accessforbidden();
  122. }
  123. //$result = restrictedArea($user, 'productbatch');
  124. if (!$permissiontoread) accessforbidden();
  125. /*
  126. * Actions
  127. */
  128. if (GETPOST('cancel', 'alpha')) {
  129. $action = 'list'; $massaction = '';
  130. }
  131. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  132. $massaction = '';
  133. }
  134. $parameters = array();
  135. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  136. if ($reshook < 0) {
  137. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  138. }
  139. if (empty($reshook)) {
  140. // Selection of new fields
  141. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  142. // Purge search criteria
  143. 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
  144. foreach ($object->fields as $key => $val) {
  145. $search[$key] = '';
  146. }
  147. $toselect = array();
  148. $search_array_options = array();
  149. }
  150. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  151. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  152. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  153. }
  154. // Mass actions
  155. $objectclass = 'ProductLot';
  156. $objectlabel = 'LotSerial';
  157. $uploaddir = $conf->productbatch->dir_output;
  158. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  159. }
  160. /*
  161. * VIEW
  162. */
  163. $form = new Form($db);
  164. $now = dol_now();
  165. $help_url = 'EN:Module_Lot_/_Serial|FR:Module_Lot_/_Série';
  166. $title = $langs->trans('LotSerialList');
  167. // Build and execute select
  168. // --------------------------------------------------------------------
  169. $sql = 'SELECT ';
  170. foreach ($object->fields as $key => $val) {
  171. $sql .= "t.".$key.", ";
  172. }
  173. // Add fields from extrafields
  174. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  175. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  176. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
  177. }
  178. }
  179. // Add fields from hooks
  180. $parameters = array();
  181. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  182. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  183. $sql = preg_replace('/,\s*$/', '', $sql);
  184. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  185. if ( !empty($extrafields->attributes[$object->table_element]['label']) && ($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  186. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  187. }
  188. if ($object->ismultientitymanaged == 1) {
  189. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  190. } else {
  191. $sql .= " WHERE 1 = 1";
  192. }
  193. foreach ($search as $key => $val) {
  194. if (array_key_exists($key, $object->fields)) {
  195. if ($key == 'status' && $search[$key] == -1) {
  196. continue;
  197. }
  198. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  199. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  200. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  201. $search[$key] = '';
  202. }
  203. $mode_search = 2;
  204. }
  205. if ($search[$key] != '') {
  206. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  207. }
  208. } else {
  209. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  210. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  211. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  212. if (preg_match('/_dtstart$/', $key)) {
  213. $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'";
  214. }
  215. if (preg_match('/_dtend$/', $key)) {
  216. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  217. }
  218. }
  219. }
  220. }
  221. }
  222. if ($search_all) {
  223. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  224. }
  225. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  226. // Add where from extra fields
  227. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  228. // Add where from hooks
  229. $parameters = array();
  230. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  231. $sql .= $hookmanager->resPrint;
  232. /* If a group by is required
  233. $sql.= " GROUP BY ";
  234. foreach($object->fields as $key => $val)
  235. {
  236. $sql .= "t.".$key.", ";
  237. }
  238. // Add fields from extrafields
  239. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  240. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  241. }
  242. // Add where from hooks
  243. $parameters=array();
  244. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  245. $sql.=$hookmanager->resPrint;
  246. $sql=preg_replace('/,\s*$/','', $sql);
  247. */
  248. // Count total nb of records
  249. $nbtotalofrecords = '';
  250. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  251. /* This old and fast method to get and count full list returns all record so use a high amount of memory.
  252. $resql = $db->query($sql);
  253. $nbtotalofrecords = $db->num_rows($resql);
  254. */
  255. /* The slow method does not consume memory on mysql (not tested on pgsql) */
  256. /*$resql = $db->query($sql, 0, 'auto', 1);
  257. while ($db->fetch_object($resql)) {
  258. $nbtotalofrecords++;
  259. }*/
  260. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  261. $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  262. $resql = $db->query($sqlforcount);
  263. $objforcount = $db->fetch_object($resql);
  264. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  265. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  266. $page = 0;
  267. $offset = 0;
  268. }
  269. $db->free($resql);
  270. }
  271. // Complete request and execute it with limit
  272. $sql .= $db->order($sortfield, $sortorder);
  273. if ($limit) {
  274. $sql .= $db->plimit($limit + 1, $offset);
  275. }
  276. $resql = $db->query($sql);
  277. if (!$resql) {
  278. dol_print_error($db);
  279. exit;
  280. }
  281. $num = $db->num_rows($resql);
  282. // Direct jump if only one record found
  283. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  284. $obj = $db->fetch_object($resql);
  285. $id = $obj->rowid;
  286. header("Location: ".DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$id);
  287. exit;
  288. }
  289. // Output page
  290. // --------------------------------------------------------------------
  291. llxHeader('', $title, $help_url);
  292. $arrayofselected = is_array($toselect) ? $toselect : array();
  293. $param = '';
  294. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  295. $param .= '&contextpage='.urlencode($contextpage);
  296. }
  297. if ($limit > 0 && $limit != $conf->liste_limit) {
  298. $param .= '&limit='.urlencode($limit);
  299. }
  300. foreach ($search as $key => $val) {
  301. if (is_array($search[$key]) && count($search[$key])) {
  302. foreach ($search[$key] as $skey) {
  303. $param .= '&search_'.$key.'[]='.urlencode($skey);
  304. }
  305. } else {
  306. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  307. }
  308. }
  309. if ($optioncss != '') {
  310. $param .= '&optioncss='.urlencode($optioncss);
  311. }
  312. // Add $param from extra fields
  313. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  314. // List of mass actions available
  315. $arrayofmassactions = array(
  316. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  317. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  318. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  319. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  320. );
  321. if (!empty($permissiontodelete)) {
  322. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  323. }
  324. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  325. $arrayofmassactions = array();
  326. }
  327. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  328. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  329. if ($optioncss != '') {
  330. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  331. }
  332. print '<input type="hidden" name="token" value="'.newToken().'">';
  333. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  334. print '<input type="hidden" name="action" value="list">';
  335. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  336. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  337. //print '<input type="hidden" name="page" value="'.$page.'">';
  338. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  339. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/product/stock/productlot_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  340. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  341. // Add code for pre mass action (confirmation or email presend form)
  342. $topicmail = "Information";
  343. $modelmail = "productlot";
  344. $objecttmp = new Productlot($db);
  345. $trackid = 'lot'.$object->id;
  346. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  347. if ($search_all) {
  348. foreach ($fieldstosearchall as $key => $val) {
  349. $fieldstosearchall[$key] = $langs->trans($val);
  350. }
  351. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  352. }
  353. $moreforfilter = '';
  354. /*$moreforfilter.='<div class="divsearchfield">';
  355. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  356. $moreforfilter.= '</div>';*/
  357. $parameters = array();
  358. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  359. if (empty($reshook)) {
  360. $moreforfilter .= $hookmanager->resPrint;
  361. } else {
  362. $moreforfilter = $hookmanager->resPrint;
  363. }
  364. if (!empty($moreforfilter)) {
  365. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  366. print $moreforfilter;
  367. print '</div>';
  368. }
  369. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  370. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  371. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  372. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  373. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  374. // Fields title search
  375. // --------------------------------------------------------------------
  376. print '<tr class="liste_titre">';
  377. foreach ($object->fields as $key => $val) {
  378. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  379. if ($key == 'status') {
  380. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  381. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  382. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  383. } elseif (in_array($val['type'], array('timestamp'))) {
  384. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  385. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  386. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  387. }
  388. if (!empty($arrayfields['t.'.$key]['checked'])) {
  389. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  390. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  391. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  392. } elseif (strpos($val['type'], 'integer:') === 0) {
  393. print $object->showInputField($val, $key, !empty($search[$key])?$search[$key]:0, '', '', 'search_', 'maxwidth150', 1);
  394. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  395. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(!empty($search[$key])?$search[$key]:'').'">';
  396. }
  397. print '</td>';
  398. }
  399. }
  400. // Extra fields
  401. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  402. // Fields from hook
  403. $parameters = array('arrayfields'=>$arrayfields);
  404. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  405. print $hookmanager->resPrint;
  406. // Action column
  407. print '<td class="liste_titre maxwidthsearch">';
  408. $searchpicto = $form->showFilterButtons();
  409. print $searchpicto;
  410. print '</td>';
  411. print '</tr>'."\n";
  412. // Fields title label
  413. // --------------------------------------------------------------------
  414. print '<tr class="liste_titre">';
  415. foreach ($object->fields as $key => $val) {
  416. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  417. if ($key == 'status') {
  418. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  419. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  420. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  421. } elseif (in_array($val['type'], array('timestamp'))) {
  422. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  423. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  424. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  425. }
  426. if (!empty($arrayfields['t.'.$key]['checked'])) {
  427. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  428. }
  429. }
  430. // Extra fields
  431. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  432. // Hook fields
  433. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  434. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  435. print $hookmanager->resPrint;
  436. // Action column
  437. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  438. print '</tr>'."\n";
  439. // Detect if we need a fetch on each output line
  440. $needToFetchEachLine = 0;
  441. if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  442. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  443. if (preg_match('/\$object/', $val)) {
  444. $needToFetchEachLine++; // There is at least one compute field that use $object
  445. }
  446. }
  447. }
  448. // Loop on record
  449. // --------------------------------------------------------------------
  450. $i = 0;
  451. $totalarray = array();
  452. $totalarray['nbfield'] = 0;
  453. while ($i < ($limit ? min($num, $limit) : $num)) {
  454. $obj = $db->fetch_object($resql);
  455. if (empty($obj)) {
  456. break; // Should not happen
  457. }
  458. // Store properties in $object
  459. $object->setVarsFromFetchObj($obj);
  460. // Show here line of result
  461. print '<tr class="oddeven">';
  462. foreach ($object->fields as $key => $val) {
  463. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  464. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  465. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  466. } elseif ($key == 'status') {
  467. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  468. }
  469. if (in_array($val['type'], array('timestamp'))) {
  470. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  471. } elseif ($key == 'ref' || $key == 'batch') {
  472. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  473. }
  474. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status'))) {
  475. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  476. }
  477. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  478. if (!empty($arrayfields['t.'.$key]['checked'])) {
  479. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  480. if ($key == 'status') {
  481. print $object->getLibStatut(5);
  482. } elseif ($key == 'rowid') {
  483. print $object->id;
  484. } else {
  485. if ($key == 'batch') {
  486. print $object->getNomUrl(1);
  487. } else {
  488. print $object->showOutputField($val, $key, $object->$key, '');
  489. }
  490. }
  491. print '</td>';
  492. if (!$i) {
  493. $totalarray['nbfield']++;
  494. }
  495. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  496. if (!$i) {
  497. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  498. }
  499. if (!isset($totalarray['val'])) {
  500. $totalarray['val'] = array();
  501. }
  502. if (!isset($totalarray['val']['t.'.$key])) {
  503. $totalarray['val']['t.'.$key] = 0;
  504. }
  505. $totalarray['val']['t.'.$key] += $object->$key;
  506. }
  507. }
  508. }
  509. // Extra fields
  510. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  511. // Fields from hook
  512. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  513. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  514. print $hookmanager->resPrint;
  515. // Action column
  516. print '<td class="nowrap center">';
  517. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  518. $selected = 0;
  519. if (in_array($object->id, $arrayofselected)) {
  520. $selected = 1;
  521. }
  522. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  523. }
  524. print '</td>';
  525. if (!$i) {
  526. $totalarray['nbfield']++;
  527. }
  528. print '</tr>'."\n";
  529. $i++;
  530. }
  531. // Show total line
  532. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  533. // If no record found
  534. if ($num == 0) {
  535. $colspan = 1;
  536. foreach ($arrayfields as $key => $val) {
  537. if (!empty($val['checked'])) {
  538. $colspan++;
  539. }
  540. }
  541. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  542. }
  543. $db->free($resql);
  544. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  545. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  546. print $hookmanager->resPrint;
  547. print '</table>'."\n";
  548. print '</div>'."\n";
  549. print '</form>'."\n";
  550. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  551. $hidegeneratedfilelistifempty = 1;
  552. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  553. $hidegeneratedfilelistifempty = 0;
  554. }
  555. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  556. $formfile = new FormFile($db);
  557. // Show list of available documents
  558. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  559. $urlsource .= str_replace('&amp;', '&', $param);
  560. $filedir = $diroutputmassaction;
  561. $genallowed = $permissiontoread;
  562. $delallowed = $permissiontoadd;
  563. print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  564. }
  565. // End of page
  566. llxFooter();
  567. $db->close();