list.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. <?php
  2. /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  3. * Copyright (C) 2022 Open-Dsi <support@open-dsi.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/variants/list.php
  20. * \ingroup variants
  21. * \brief List page for product attribute
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array("products", "other"));
  28. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  29. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  30. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  31. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  32. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  33. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  34. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'productattributelist'; // To manage different context of search
  35. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  36. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  37. $id = GETPOST('id', 'int');
  38. // Load variable for pagination
  39. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  40. $sortfield = GETPOST('sortfield', 'aZ09comma');
  41. $sortorder = GETPOST('sortorder', 'aZ09comma');
  42. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  43. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  44. // If $page is not defined, or '' or -1 or if we click on clear filters
  45. $page = 0;
  46. }
  47. $offset = $limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. // Initialize technical objects
  51. $object = new ProductAttribute($db);
  52. //$extrafields = new ExtraFields($db);
  53. $diroutputmassaction = $conf->variants->dir_output.'/temp/massgeneration/'.$user->id;
  54. $hookmanager->initHooks(array('productattributelist')); // Note that conf->hooks_modules contains array
  55. // Fetch optionals attributes and labels
  56. //$extrafields->fetch_name_optionals_label($object->table_element);
  57. //$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  58. // Default sort order (if not yet defined by previous GETPOST)
  59. if (!$sortfield) {
  60. $sortfield = "t.position"; // Set here default search field. By default 1st field in definition.
  61. }
  62. if (!$sortorder) {
  63. $sortorder = "ASC";
  64. }
  65. // Initialize array of search criterias
  66. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  67. $search = array();
  68. foreach ($object->fields as $key => $val) {
  69. if (GETPOST('search_'.$key, 'alpha') !== '') {
  70. $search[$key] = GETPOST('search_'.$key, 'alpha');
  71. }
  72. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  73. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  74. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  75. }
  76. }
  77. $search['nb_of_values'] = GETPOST('search_nb_of_values', 'alpha');
  78. $search['nb_products'] = GETPOST('search_nb_products', 'alpha');
  79. // List of fields to search into when doing a "search in all"
  80. $fieldstosearchall = array();
  81. foreach ($object->fields as $key => $val) {
  82. if (!empty($val['searchall'])) {
  83. $fieldstosearchall['t.'.$key] = $val['label'];
  84. }
  85. }
  86. // Definition of array of fields for columns
  87. $arrayfields = array();
  88. foreach ($object->fields as $key => $val) {
  89. // If $val['visible']==0, then we never show the field
  90. if (!empty($val['visible'])) {
  91. $visible = (int) dol_eval($val['visible'], 1);
  92. $arrayfields['t.'.$key] = array(
  93. 'label'=>$val['label'],
  94. 'checked'=>(($visible < 0) ? 0 : 1),
  95. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
  96. 'position'=>$val['position'],
  97. 'help'=> isset($val['help']) ? $val['help'] : ''
  98. );
  99. }
  100. }
  101. $arrayfields['nb_of_values'] = array(
  102. 'label' => $langs->trans('NbOfDifferentValues'),
  103. 'checked' => 1,
  104. 'enabled' => 1,
  105. 'position' => 40,
  106. 'help' => ''
  107. );
  108. $arrayfields['nb_products'] = array(
  109. 'label' => $langs->trans('NbProducts'),
  110. 'checked' => 1,
  111. 'enabled' => 1,
  112. 'position' => 50,
  113. 'help' => ''
  114. );
  115. // Extra fields
  116. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  117. $object->fields = dol_sort_array($object->fields, 'position');
  118. $arrayfields = dol_sort_array($arrayfields, 'position');
  119. $permissiontoread = $user->rights->variants->read;
  120. $permissiontoadd = $user->rights->variants->write;
  121. $permissiontodelete = $user->rights->variants->delete;
  122. // Security check
  123. if (empty($conf->variants->enabled)) {
  124. accessforbidden('Module not enabled');
  125. }
  126. $socid = 0;
  127. if ($user->socid > 0) { // Protection if external user
  128. //$socid = $user->socid;
  129. accessforbidden();
  130. }
  131. if (!$permissiontoread) accessforbidden();
  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 (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  155. $search[$key.'_dtstart'] = '';
  156. $search[$key.'_dtend'] = '';
  157. }
  158. }
  159. $search['nb_of_values'] = '';
  160. $search['nb_products'] = '';
  161. $toselect = array();
  162. $search_array_options = array();
  163. }
  164. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  165. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  166. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  167. }
  168. if ($action == 'up' && $permissiontoadd) {
  169. $object->attributeMoveUp($rowid);
  170. header('Location: '.$_SERVER['PHP_SELF']);
  171. exit();
  172. } elseif ($action == 'down' && $permissiontoadd) {
  173. $object->attributeMoveDown($rowid);
  174. header('Location: '.$_SERVER['PHP_SELF']);
  175. exit();
  176. }
  177. // Mass actions
  178. $objectclass = 'ProductAttribute';
  179. $objectlabel = 'ProductAttribute';
  180. $uploaddir = $conf->variants->dir_output;
  181. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  182. }
  183. /*
  184. * View
  185. */
  186. $form = new Form($db);
  187. $now = dol_now();
  188. $help_url = '';
  189. $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("ProductAttributes"));
  190. $morejs = array();
  191. $morecss = array();
  192. // Build and execute select
  193. // --------------------------------------------------------------------
  194. $sql = "SELECT ";
  195. $sql .= " COUNT(DISTINCT pav.rowid) AS nb_of_values, COUNT(DISTINCT pac2v.fk_prod_combination) AS nb_products,";
  196. $sql .= $object->getFieldList("t");
  197. // Add fields from extrafields
  198. //if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  199. // foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  200. // $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.", " : "");
  201. // }
  202. //}
  203. // Add fields from hooks
  204. $parameters = array();
  205. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  206. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  207. $sql = preg_replace('/,\s*$/', '', $sql);
  208. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  209. //if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  210. // $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  211. //}
  212. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination2val AS pac2v ON pac2v.fk_prod_attr = t.rowid";
  213. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_value AS pav ON pav.fk_product_attribute = t.rowid";
  214. // Add table from hooks
  215. $parameters = array();
  216. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  217. $sql .= $hookmanager->resPrint;
  218. if ($object->ismultientitymanaged == 1) {
  219. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  220. } else {
  221. $sql .= " WHERE 1 = 1";
  222. }
  223. foreach ($search as $key => $val) {
  224. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  225. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  226. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  227. if (preg_match('/_dtstart$/', $key)) {
  228. $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'";
  229. }
  230. if (preg_match('/_dtend$/', $key)) {
  231. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  232. }
  233. }
  234. } elseif (array_key_exists($key, $object->fields)) {
  235. if ($key == 'status' && $search[$key] == -1) {
  236. continue;
  237. }
  238. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  239. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  240. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  241. $search[$key] = '';
  242. }
  243. $mode_search = 2;
  244. }
  245. if ($search[$key] != '') {
  246. $sql .= natural_search("t.".$key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  247. }
  248. }
  249. }
  250. if ($search_all) {
  251. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  252. }
  253. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  254. // Add where from extra fields
  255. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  256. // Add where from hooks
  257. $parameters = array();
  258. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  259. $sql .= $hookmanager->resPrint;
  260. $hasgroupby = true;
  261. $sql .= " GROUP BY ";
  262. foreach ($object->fields as $key => $val) {
  263. $sql .= "t." . $key . ", ";
  264. }
  265. // Add fields from extrafields
  266. //if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  267. // foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  268. // $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  269. // }
  270. //}
  271. // Add where from hooks
  272. $parameters = array();
  273. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  274. $sql .= $hookmanager->resPrint;
  275. $sql = preg_replace("/,\s*$/", "", $sql);
  276. $sql .= " HAVING 1=1";
  277. if ($search['nb_of_values'] != '') {
  278. $sql .= natural_search("nb_of_values", $search['nb_of_values'], 1);
  279. }
  280. if ($search['nb_products'] != '') {
  281. $sql .= natural_search("nb_products", $search['nb_products'], 1);
  282. }
  283. // Add HAVING from hooks
  284. $parameters = array();
  285. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  286. $sql .= empty($hookmanager->resPrint) ? "" : " ".$hookmanager->resPrint;
  287. // Count total nb of records
  288. $nbtotalofrecords = '';
  289. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  290. /* This old and fast method to get and count full list returns all record so use a high amount of memory.
  291. $resql = $db->query($sql);
  292. $nbtotalofrecords = $db->num_rows($resql);
  293. */
  294. /* The slow method does not consume memory on mysql (not tested on pgsql) */
  295. /*$resql = $db->query($sql, 0, 'auto', 1);
  296. while ($db->fetch_object($resql)) {
  297. $nbtotalofrecords++;
  298. }*/
  299. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  300. $sqlforcount = preg_replace("/^SELECT[a-z0-9\._\s\(\),]+FROM/i", "SELECT COUNT(*) as nbtotalofrecords FROM", $sql);
  301. $resql = $db->query($sqlforcount);
  302. if ($resql) {
  303. if ($hasgroupby) {
  304. $nbtotalofrecords = $db->num_rows($resql);
  305. } else {
  306. $objforcount = $db->fetch_object($resql);
  307. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  308. }
  309. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  310. $page = 0;
  311. $offset = 0;
  312. }
  313. $db->free($resql);
  314. }
  315. }
  316. // Complete request and execute it with limit
  317. $sql .= $db->order($sortfield, $sortorder);
  318. if ($limit) {
  319. $sql .= $db->plimit($limit + 1, $offset);
  320. }
  321. $resql = $db->query($sql);
  322. if (!$resql) {
  323. dol_print_error($db);
  324. exit;
  325. }
  326. $num = $db->num_rows($resql);
  327. // Direct jump if only one record found
  328. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  329. $obj = $db->fetch_object($resql);
  330. $id = $obj->rowid;
  331. header("Location: " . dol_buildpath('/variants/card.php', 2) . '?id=' . $id);
  332. exit;
  333. }
  334. // Output page
  335. // --------------------------------------------------------------------
  336. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  337. $arrayofselected = is_array($toselect) ? $toselect : array();
  338. $param = '';
  339. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  340. $param .= '&contextpage='.urlencode($contextpage);
  341. }
  342. if ($limit > 0 && $limit != $conf->liste_limit) {
  343. $param .= '&limit='.urlencode($limit);
  344. }
  345. foreach ($search as $key => $val) {
  346. if (is_array($search[$key]) && count($search[$key])) {
  347. foreach ($search[$key] as $skey) {
  348. if ($skey != '') {
  349. $param .= '&search_'.$key.'[]='.urlencode($skey);
  350. }
  351. }
  352. } elseif ($search[$key] != '') {
  353. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  354. }
  355. }
  356. if ($optioncss != '') {
  357. $param .= '&optioncss='.urlencode($optioncss);
  358. }
  359. // Add $param from extra fields
  360. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  361. // Add $param from hooks
  362. $parameters = array();
  363. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  364. $param .= $hookmanager->resPrint;
  365. // List of mass actions available
  366. $arrayofmassactions = array(
  367. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  368. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  369. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  370. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  371. );
  372. if ($permissiontodelete) {
  373. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  374. }
  375. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  376. $arrayofmassactions = array();
  377. }
  378. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  379. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  380. if ($optioncss != '') {
  381. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  382. }
  383. print '<input type="hidden" name="token" value="'.newToken().'">';
  384. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  385. print '<input type="hidden" name="action" value="list">';
  386. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  387. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  388. print '<input type="hidden" name="page" value="'.$page.'">';
  389. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  390. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/variants/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  391. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  392. // Add code for pre mass action (confirmation or email presend form)
  393. $topicmail = "SendProductAttributeRef";
  394. $modelmail = "productattribute";
  395. $objecttmp = new ProductAttribute($db);
  396. $trackid = 'pa'.$object->id;
  397. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  398. if ($search_all) {
  399. foreach ($fieldstosearchall as $key => $val) {
  400. $fieldstosearchall[$key] = $langs->trans($val);
  401. }
  402. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  403. }
  404. $moreforfilter = '';
  405. /*$moreforfilter.='<div class="divsearchfield">';
  406. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  407. $moreforfilter.= '</div>';*/
  408. $parameters = array();
  409. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  410. if (empty($reshook)) {
  411. $moreforfilter .= $hookmanager->resPrint;
  412. } else {
  413. $moreforfilter = $hookmanager->resPrint;
  414. }
  415. if (!empty($moreforfilter)) {
  416. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  417. print $moreforfilter;
  418. print '</div>';
  419. }
  420. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  421. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  422. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  423. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  424. print '<table id="tableattributes" class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  425. // Fields title search
  426. // --------------------------------------------------------------------
  427. print '<tr class="liste_titre">';
  428. foreach ($object->fields as $key => $val) {
  429. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  430. if ($key == 'status') {
  431. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  432. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  433. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  434. } elseif (in_array($val['type'], array('timestamp'))) {
  435. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  436. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  437. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  438. }
  439. if (!empty($arrayfields['t.'.$key]['checked'])) {
  440. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  441. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  442. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  443. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  444. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  445. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  446. print '<div class="nowrap">';
  447. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  448. print '</div>';
  449. print '<div class="nowrap">';
  450. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  451. print '</div>';
  452. } elseif ($key == 'lang') {
  453. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  454. $formadmin = new FormAdmin($db);
  455. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  456. } else {
  457. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  458. }
  459. print '</td>';
  460. }
  461. }
  462. // Extra fields
  463. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  464. $key = 'nb_of_values';
  465. if (!empty($arrayfields[$key]['checked'])) {
  466. print '<td class="liste_titre center">';
  467. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  468. print '</td>';
  469. }
  470. $key = 'nb_products';
  471. if (!empty($arrayfields[$key]['checked'])) {
  472. print '<td class="liste_titre center">';
  473. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  474. print '</td>';
  475. }
  476. // Fields from hook
  477. $parameters = array('arrayfields'=>$arrayfields);
  478. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  479. print $hookmanager->resPrint;
  480. // Action column
  481. print '<td class="liste_titre linecoledit width25"></td>';
  482. print '<td class="liste_titre maxwidthsearch">';
  483. $searchpicto = $form->showFilterButtons();
  484. print $searchpicto;
  485. print '</td>';
  486. print '<td class="liste_titre linecolmove width25"></td>';
  487. print '</tr>'."\n";
  488. // Fields title label
  489. // --------------------------------------------------------------------
  490. print '<tr class="liste_titre">';
  491. foreach ($object->fields as $key => $val) {
  492. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  493. if ($key == 'status') {
  494. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  495. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  496. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  497. } elseif (in_array($val['type'], array('timestamp'))) {
  498. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  499. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  500. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  501. }
  502. if (!empty($arrayfields['t.'.$key]['checked'])) {
  503. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  504. }
  505. }
  506. // Extra fields
  507. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  508. $key = 'nb_of_values';
  509. if (!empty($arrayfields[$key]['checked'])) {
  510. print getTitleFieldOfList($arrayfields[$key]['label'], 0, $_SERVER['PHP_SELF'], $key, '', $param, 'class="center"', $sortfield, $sortorder, 'center ')."\n";
  511. }
  512. $key = 'nb_products';
  513. if (!empty($arrayfields[$key]['checked'])) {
  514. print getTitleFieldOfList($arrayfields[$key]['label'], 0, $_SERVER['PHP_SELF'], $key, '', $param, 'class="center"', $sortfield, $sortorder, 'center ')."\n";
  515. }
  516. // Hook fields
  517. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  518. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  519. print $hookmanager->resPrint;
  520. // Action column
  521. print getTitleFieldOfList('', 0, '', '', '', '', '', '', '', 'linecoledit ')."\n";
  522. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  523. print getTitleFieldOfList('', 0, '', '', '', '', '', '', '', 'linecolmove ')."\n";
  524. print '</tr>'."\n";
  525. // Detect if we need a fetch on each output line
  526. $needToFetchEachLine = 0;
  527. //if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  528. // foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  529. // if (preg_match('/\$object/', $val)) {
  530. // $needToFetchEachLine++; // There is at least one compute field that use $object
  531. // }
  532. // }
  533. //}
  534. // Loop on record
  535. // --------------------------------------------------------------------
  536. $i = 0;
  537. $totalarray = array();
  538. $totalarray['nbfield'] = 0;
  539. while ($i < ($limit ? min($num, $limit) : $num)) {
  540. $obj = $db->fetch_object($resql);
  541. if (empty($obj)) {
  542. break; // Should not happen
  543. }
  544. $object->setVarsFromFetchObj($obj);
  545. // Show here line of result
  546. print '<tr id="row-' . $obj->rowid . '" class="oddeven drag drop">';
  547. foreach ($object->fields as $key => $val) {
  548. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  549. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  550. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  551. } elseif ($key == 'status') {
  552. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  553. }
  554. if (in_array($val['type'], array('timestamp'))) {
  555. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  556. } elseif ($key == 'ref') {
  557. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  558. }
  559. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  560. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  561. }
  562. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  563. if (!empty($arrayfields['t.' . $key]['checked'])) {
  564. print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
  565. if ($key == 'status') {
  566. print $object->getLibStatut(5);
  567. } elseif ($key == 'rowid') {
  568. print $object->showOutputField($val, $key, $object->id, '');
  569. } else {
  570. print $object->showOutputField($val, $key, $object->$key, '');
  571. }
  572. print '</td>';
  573. if (!$i) {
  574. $totalarray['nbfield']++;
  575. }
  576. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  577. if (!$i) {
  578. $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
  579. }
  580. if (!isset($totalarray['val'])) {
  581. $totalarray['val'] = array();
  582. }
  583. if (!isset($totalarray['val']['t.' . $key])) {
  584. $totalarray['val']['t.' . $key] = 0;
  585. }
  586. $totalarray['val']['t.' . $key] += $object->$key;
  587. }
  588. }
  589. }
  590. // Extra fields
  591. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  592. $key = 'nb_of_values';
  593. if (!empty($arrayfields[$key]['checked'])) {
  594. print '<td class="center">';
  595. print $obj->$key;
  596. print '</td>';
  597. if (!$i) {
  598. $totalarray['nbfield']++;
  599. }
  600. }
  601. $key = 'nb_products';
  602. if (!empty($arrayfields[$key]['checked'])) {
  603. print '<td class="center">';
  604. print $obj->$key;
  605. print '</td>';
  606. if (!$i) {
  607. $totalarray['nbfield']++;
  608. }
  609. }
  610. // Fields from hook
  611. $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
  612. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  613. print $hookmanager->resPrint;
  614. // Action column
  615. print '<td class="linecoledit center width25">';
  616. if ($permissiontoadd) {
  617. print '<a class="editfielda reposition" href="' . DOL_URL_ROOT . '/variants/card.php?id=' . $obj->rowid . '&action=edit&save_lastsearch_values=1&backtopage=' . urlencode($_SERVER['PHP_SELF']) . '">' . img_edit() . '</a>';
  618. }
  619. print '</td>';
  620. if (!$i) {
  621. $totalarray['nbfield']++;
  622. }
  623. print '<td class="nowrap center">';
  624. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  625. $selected = 0;
  626. if (in_array($object->id, $arrayofselected)) {
  627. $selected = 1;
  628. }
  629. print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  630. }
  631. print '</td>';
  632. if (!$i) {
  633. $totalarray['nbfield']++;
  634. }
  635. print '<td class="center linecolmove tdlineupdown">';
  636. if ($i > 0) {
  637. print '<a class="lineupdown" href="' . $_SERVER['PHP_SELF'] . '?action=up&amp;rowid=' . $obj->rowid . '">' . img_up('default', 0, 'imgupforline') . '</a>';
  638. }
  639. if ($i < $num - 1) {
  640. print '<a class="lineupdown" href="' . $_SERVER['PHP_SELF'] . '?action=down&amp;rowid=' . $obj->rowid . '">' . img_down('default', 0, 'imgdownforline') . '</a>';
  641. }
  642. print '</td>';
  643. if (!$i) {
  644. $totalarray['nbfield']++;
  645. }
  646. print '</tr>' . "\n";
  647. $i++;
  648. }
  649. // Show total line
  650. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  651. // If no record found
  652. if ($num == 0) {
  653. $colspan = 3;
  654. foreach ($arrayfields as $key => $val) {
  655. if (!empty($val['checked'])) {
  656. $colspan++;
  657. }
  658. }
  659. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  660. }
  661. $db->free($resql);
  662. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  663. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  664. print $hookmanager->resPrint;
  665. print '</table>'."\n";
  666. print '</div>'."\n";
  667. print '</form>'."\n";
  668. $forcereloadpage = empty($conf->global->MAIN_FORCE_RELOAD_PAGE) ? 0 : 1;
  669. $tagidfortablednd = (empty($tagidfortablednd) ? 'tableattributes' : $tagidfortablednd);
  670. ?>
  671. <script>
  672. $(document).ready(function(){
  673. $(".imgupforline, .imgdownforline").hide();
  674. $(".lineupdown").removeAttr('href');
  675. $(".tdlineupdown")
  676. .css("background-image", 'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)')
  677. .css("background-repeat", "no-repeat")
  678. .css("background-position", "center center")
  679. .hover(
  680. function () {
  681. $(this).addClass('showDragHandle');
  682. }, function () {
  683. $(this).removeClass('showDragHandle');
  684. }
  685. );
  686. $("#<?php echo $tagidfortablednd; ?>").tableDnD({
  687. onDrop: function(table, row) {
  688. console.log('drop');
  689. $('#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]').attr('id', ''); // Set extrafields id to empty value in order to ignore them in tableDnDSerialize function
  690. $('#<?php echo $tagidfortablednd; ?> tr[data-ignoreidfordnd=1]').attr('id', ''); // Set id to empty value in order to ignore them in tableDnDSerialize function
  691. var reloadpage = "<?php echo $forcereloadpage; ?>";
  692. var roworder = cleanSerialize(decodeURI($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
  693. $.post("<?php echo DOL_URL_ROOT; ?>/variants/ajax/orderAttribute.php",
  694. {
  695. roworder: roworder,
  696. token: "<?php echo currentToken(); ?>"
  697. },
  698. function() {
  699. if (reloadpage == 1) {
  700. location.href = '<?php echo dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']); ?>';
  701. }
  702. });
  703. },
  704. onDragClass: "dragClass",
  705. dragHandle: "td.tdlineupdown"
  706. });
  707. });
  708. </script>
  709. <?php
  710. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  711. $hidegeneratedfilelistifempty = 1;
  712. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  713. $hidegeneratedfilelistifempty = 0;
  714. }
  715. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  716. $formfile = new FormFile($db);
  717. // Show list of available documents
  718. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  719. $urlsource .= str_replace('&amp;', '&', $param);
  720. $filedir = $diroutputmassaction;
  721. $genallowed = $permissiontoread;
  722. $delallowed = $permissiontoadd;
  723. print $formfile->showdocuments('massfilesarea_productattribute', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  724. }
  725. // End of page
  726. llxFooter();
  727. $db->close();