stocktransfer_list.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  4. * Copyright (C) ---Put here your own copyright and developer email---
  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 stocktransfer_list.php
  21. * \ingroup stocktransfer
  22. * \brief List page for stocktransfer
  23. */
  24. // Load Dolibarr environment
  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.'/core/lib/functions.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("stocks", "other"));
  33. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  34. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  35. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  36. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  37. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  38. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  39. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'stocktransferlist'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  41. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  42. $id = GETPOST('id', 'int');
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'alpha');
  46. $sortorder = GETPOST('sortorder', 'alpha');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. // Initialize technical objects
  53. $object = new StockTransfer($db);
  54. $extrafields = new ExtraFields($db);
  55. $diroutputmassaction = $conf->stocktransfer->dir_output.'/temp/massgeneration/'.$user->id;
  56. $hookmanager->initHooks(array('stocktransferlist')); // Note that conf->hooks_modules contains array
  57. // Fetch optionals attributes and labels
  58. $extrafields->fetch_name_optionals_label($object->table_element);
  59. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  60. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  61. // Default sort order (if not yet defined by previous GETPOST)
  62. if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  63. if (!$sortorder) $sortorder = "ASC";
  64. // Initialize array of search criterias
  65. $search_all = GETPOST('search_all', 'alphanohtml') ? trim(GETPOST('search_all', 'alphanohtml')) : trim(GETPOST('sall', 'alphanohtml'));
  66. $search = array();
  67. foreach ($object->fields as $key => $val) {
  68. if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha');
  69. }
  70. // List of fields to search into when doing a "search in all"
  71. $fieldstosearchall = array();
  72. foreach ($object->fields as $key => $val) {
  73. if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
  74. }
  75. // Definition of fields for list
  76. $arrayfields = array();
  77. foreach ($object->fields as $key => $val) {
  78. // If $val['visible']==0, then we never show the field
  79. if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>(verifCond($val['enabled']) && ($val['visible'] != 3)), 'position'=>$val['position']);
  80. }
  81. //var_dump($object->fields);
  82. // Extra fields
  83. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) {
  84. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  85. if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
  86. $arrayfields["ef.".$key] = array(
  87. 'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
  88. 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1),
  89. 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key],
  90. 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]),
  91. 'langfile'=>$extrafields->attributes[$object->table_element]['langfile'][$key]
  92. );
  93. }
  94. }
  95. }
  96. $object->fields = dol_sort_array($object->fields, 'position');
  97. $arrayfields = dol_sort_array($arrayfields, 'position');
  98. $permissiontoread = $user->rights->stocktransfer->stocktransfer->read;
  99. $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write;
  100. $permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete;
  101. // Security check
  102. if (empty($conf->stocktransfer->enabled)) accessforbidden('Module not enabled');
  103. $socid = 0;
  104. if ($user->socid > 0) { // Protection if external user
  105. //$socid = $user->socid;
  106. accessforbidden();
  107. }
  108. //$result = restrictedArea($user, 'stocktransfer', $id, '');
  109. if (!$permissiontoread) accessforbidden();
  110. /*
  111. * Actions
  112. */
  113. if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
  114. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
  115. $parameters = array();
  116. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  117. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  118. if (empty($reshook)) {
  119. // Selection of new fields
  120. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  121. // Purge search criteria
  122. 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
  123. foreach ($object->fields as $key => $val) {
  124. $search[$key] = '';
  125. }
  126. $toselect = '';
  127. $search_array_options = array();
  128. }
  129. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  130. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  131. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  132. }
  133. // Mass actions
  134. $objectclass = 'StockTransfer';
  135. $objectlabel = 'StockTransfer';
  136. $uploaddir = $conf->stocktransfer->dir_output;
  137. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  138. }
  139. /*
  140. * View
  141. */
  142. $form = new Form($db);
  143. $now = dol_now();
  144. //$help_url="EN:Module_StockTransfer|FR:Module_StockTransfer_FR|ES:Módulo_StockTransfer";
  145. $help_url = '';
  146. $title = $langs->trans('StockTransferList');
  147. // Build and execute select
  148. // --------------------------------------------------------------------
  149. $sql = 'SELECT ';
  150. foreach ($object->fields as $key => $val) {
  151. $sql .= "t.".$key.", ";
  152. }
  153. // Add fields from extrafields
  154. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  155. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
  156. }
  157. // Add fields from hooks
  158. $parameters = array();
  159. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  160. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  161. $sql = preg_replace('/,\s*$/', '', $sql);
  162. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  163. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  164. if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  165. else $sql .= " WHERE 1 = 1";
  166. foreach ($search as $key => $val) {
  167. if ($key == 'status' && $search[$key] == -1) continue;
  168. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  169. if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
  170. if ($search[$key] == '-1') $search[$key] = '';
  171. $mode_search = 2;
  172. }
  173. if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  174. }
  175. if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  176. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  177. // Add where from extra fields
  178. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  179. // Add where from hooks
  180. $parameters = array();
  181. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  182. $sql .= $hookmanager->resPrint;
  183. /* If a group by is required
  184. $sql.= " GROUP BY ";
  185. foreach($object->fields as $key => $val)
  186. {
  187. $sql.="t.".$key.", ";
  188. }
  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) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  192. }
  193. // Add where from hooks
  194. $parameters=array();
  195. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  196. $sql.=$hookmanager->resPrint;
  197. $sql=preg_replace('/,\s*$/','', $sql);
  198. */
  199. $sql .= $db->order($sortfield, $sortorder);
  200. // Count total nb of records
  201. $nbtotalofrecords = '';
  202. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  203. $resql = $db->query($sql);
  204. $nbtotalofrecords = $db->num_rows($resql);
  205. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  206. $page = 0;
  207. $offset = 0;
  208. }
  209. }
  210. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  211. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  212. $num = $nbtotalofrecords;
  213. } else {
  214. if ($limit) $sql .= $db->plimit($limit + 1, $offset);
  215. $resql = $db->query($sql);
  216. if (!$resql) {
  217. dol_print_error($db);
  218. exit;
  219. }
  220. $num = $db->num_rows($resql);
  221. }
  222. // Direct jump if only one record found
  223. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  224. $obj = $db->fetch_object($resql);
  225. $id = $obj->rowid;
  226. header("Location: ".dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$id);
  227. exit;
  228. }
  229. // Output page
  230. // --------------------------------------------------------------------
  231. llxHeader('', $title, $help_url);
  232. // Example : Adding jquery code
  233. print '<script type="text/javascript" language="javascript">
  234. jQuery(document).ready(function() {
  235. function init_myfunc()
  236. {
  237. jQuery("#myid").removeAttr(\'disabled\');
  238. jQuery("#myid").attr(\'disabled\',\'disabled\');
  239. }
  240. init_myfunc();
  241. jQuery("#mybutton").click(function() {
  242. init_myfunc();
  243. });
  244. });
  245. </script>';
  246. $arrayofselected = is_array($toselect) ? $toselect : array();
  247. $param = '';
  248. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  249. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  250. foreach ($search as $key => $val) {
  251. if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey);
  252. else $param .= '&search_'.$key.'='.urlencode($search[$key]);
  253. }
  254. if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
  255. // Add $param from extra fields
  256. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  257. // List of mass actions available
  258. $arrayofmassactions = array(
  259. //'validate'=>$langs->trans("Validate"),
  260. //'generate_doc'=>$langs->trans("ReGeneratePDF"),
  261. //'builddoc'=>$langs->trans("PDFMerge"),
  262. //'presend'=>$langs->trans("SendByMail"),
  263. );
  264. if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  265. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
  266. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  267. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  268. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  269. print '<input type="hidden" name="token" value="'.newToken().'">';
  270. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  271. print '<input type="hidden" name="action" value="list">';
  272. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  273. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  274. //print '<input type="hidden" name="page" value="'.$page.'">';
  275. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  276. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  277. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  278. // Add code for pre mass action (confirmation or email presend form)
  279. $topicmail = "SendStockTransferRef";
  280. $modelmail = "stocktransfer";
  281. $objecttmp = new StockTransfer($db);
  282. $trackid = 'xxxx'.$object->id;
  283. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  284. if ($search_all) {
  285. foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
  286. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  287. }
  288. $moreforfilter = '';
  289. /*$moreforfilter.='<div class="divsearchfield">';
  290. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  291. $moreforfilter.= '</div>';*/
  292. $parameters = array();
  293. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  294. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  295. else $moreforfilter = $hookmanager->resPrint;
  296. if (!empty($moreforfilter)) {
  297. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  298. print $moreforfilter;
  299. print '</div>';
  300. }
  301. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  302. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  303. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  304. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  305. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  306. // Fields title search
  307. // --------------------------------------------------------------------
  308. print '<tr class="liste_titre">';
  309. foreach ($object->fields as $key => $val) {
  310. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  311. if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  312. elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  313. elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  314. elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
  315. if (!empty($arrayfields['t.'.$key]['checked'])) {
  316. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  317. if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
  318. elseif (strpos($val['type'], 'integer:') === 0) {
  319. print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
  320. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
  321. print '</td>';
  322. }
  323. }
  324. // Extra fields
  325. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  326. // Fields from hook
  327. $parameters = array('arrayfields'=>$arrayfields);
  328. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  329. print $hookmanager->resPrint;
  330. // Action column
  331. print '<td class="liste_titre maxwidthsearch">';
  332. $searchpicto = $form->showFilterButtons();
  333. print $searchpicto;
  334. print '</td>';
  335. print '</tr>'."\n";
  336. // Fields title label
  337. // --------------------------------------------------------------------
  338. print '<tr class="liste_titre">';
  339. foreach ($object->fields as $key => $val) {
  340. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  341. if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  342. elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  343. elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  344. elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
  345. if (!empty($arrayfields['t.'.$key]['checked'])) {
  346. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  347. }
  348. }
  349. // Extra fields
  350. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  351. // Hook fields
  352. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  353. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  354. print $hookmanager->resPrint;
  355. // Action column
  356. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  357. print '</tr>'."\n";
  358. // Detect if we need a fetch on each output line
  359. $needToFetchEachLine = 0;
  360. if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  361. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  362. if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
  363. }
  364. }
  365. // Loop on record
  366. // --------------------------------------------------------------------
  367. $i = 0;
  368. $totalarray = array();
  369. while ($i < ($limit ? min($num, $limit) : $num)) {
  370. $obj = $db->fetch_object($resql);
  371. if (empty($obj)) break; // Should not happen
  372. // Store properties in $object
  373. $object->setVarsFromFetchObj($obj);
  374. // Show here line of result
  375. print '<tr class="oddeven">';
  376. foreach ($object->fields as $key => $val) {
  377. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  378. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
  379. elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
  380. if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  381. elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  382. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right';
  383. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  384. if (!empty($arrayfields['t.'.$key]['checked'])) {
  385. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  386. if ($key == 'status') print $object->getLibStatut(5);
  387. else {
  388. print $object->showOutputField($val, $key, $object->$key, '');
  389. if ($key === 'date_prevue_depart' && $object->lead_time_for_warning > 0 && $object->$key > 0) {
  390. $date_prevue_depart = $object->$key;
  391. $date_prevue_depart_plus_delai = $date_prevue_depart;
  392. if ($object->lead_time_for_warning > 0) $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day');
  393. if ($date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
  394. }
  395. }
  396. print '</td>';
  397. if (!$i) $totalarray['nbfield']++;
  398. if (!empty($val['isameasure'])) {
  399. if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  400. $totalarray['val']['t.'.$key] += $object->$key;
  401. }
  402. }
  403. }
  404. // Extra fields
  405. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  406. // Fields from hook
  407. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  408. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  409. print $hookmanager->resPrint;
  410. // Action column
  411. print '<td class="nowrap center">';
  412. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  413. $selected = 0;
  414. if (in_array($object->id, $arrayofselected)) $selected = 1;
  415. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  416. }
  417. print '</td>';
  418. if (!$i) $totalarray['nbfield']++;
  419. print '</tr>'."\n";
  420. $i++;
  421. }
  422. // Show total line
  423. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  424. // If no record found
  425. if ($num == 0) {
  426. $colspan = 1;
  427. foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
  428. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  429. }
  430. $db->free($resql);
  431. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  432. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  433. print $hookmanager->resPrint;
  434. print '</table>'."\n";
  435. print '</div>'."\n";
  436. print '</form>'."\n";
  437. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  438. $hidegeneratedfilelistifempty = 1;
  439. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
  440. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  441. $formfile = new FormFile($db);
  442. // Show list of available documents
  443. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  444. $urlsource .= str_replace('&amp;', '&', $param);
  445. $filedir = $diroutputmassaction;
  446. $genallowed = $permissiontoread;
  447. $delallowed = $permissiontoadd;
  448. print $formfile->showdocuments('massfilesarea_stocktransfer', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  449. }
  450. // End of page
  451. llxFooter();
  452. $db->close();