list.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. /* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
  3. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  4. * Copyright (C) 2018-2021 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 htdocs/resource/list.php
  21. * \ingroup resource
  22. * \brief Page to manage resource objects
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("resource", "companies", "other"));
  29. // Get parameters
  30. $id = GETPOST('id', 'int');
  31. $action = GETPOST('action', 'alpha');
  32. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  33. $lineid = GETPOST('lineid', 'int');
  34. $element = GETPOST('element', 'alpha');
  35. $element_id = GETPOST('element_id', 'int');
  36. $resource_id = GETPOST('resource_id', 'int');
  37. $sortorder = GETPOST('sortorder', 'aZ09comma');
  38. $sortfield = GETPOST('sortfield', 'aZ09comma');
  39. $optioncss = GETPOST('optioncss', 'alpha');
  40. // Initialize context for list
  41. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'resourcelist';
  42. // Initialize technical objects
  43. $object = new Dolresource($db);
  44. $extrafields = new ExtraFields($db);
  45. // fetch optionals attributes and labels
  46. $extrafields->fetch_name_optionals_label($object->table_element);
  47. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  48. if (!is_array($search_array_options)) {
  49. $search_array_options = array();
  50. }
  51. $search_ref = GETPOST("search_ref", 'alpha');
  52. $search_type = GETPOST("search_type", 'alpha');
  53. // Load variable for pagination
  54. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  55. $filter = array();
  56. $hookmanager->initHooks(array('resourcelist'));
  57. if (empty($sortorder)) {
  58. $sortorder = "ASC";
  59. }
  60. if (empty($sortfield)) {
  61. $sortfield = "t.ref";
  62. }
  63. if (empty($arch)) {
  64. $arch = 0;
  65. }
  66. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  67. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  68. if (empty($page) || $page == -1) {
  69. $page = 0;
  70. } // If $page is not defined, or '' or -1
  71. $offset = $limit * $page;
  72. $pageprev = $page - 1;
  73. $pagenext = $page + 1;
  74. $arrayfields = array(
  75. 't.ref' => array(
  76. 'label' => $langs->trans("Ref"),
  77. 'checked' => 1
  78. ),
  79. 'ty.label' => array(
  80. 'label' => $langs->trans("ResourceType"),
  81. 'checked' => 1
  82. ),
  83. );
  84. // Extra fields
  85. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  86. $object->fields = dol_sort_array($object->fields, 'position');
  87. $arrayfields = dol_sort_array($arrayfields, 'position');
  88. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  89. // Do we click on purge search criteria ?
  90. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  91. $search_ref = "";
  92. $search_type = "";
  93. $search_array_options = array();
  94. $filter = array();
  95. }
  96. if (empty($user->rights->resource->read)) {
  97. accessforbidden();
  98. }
  99. /*
  100. * Actions
  101. */
  102. if (GETPOST('cancel', 'alpha')) {
  103. $action = 'list';
  104. $massaction = '';
  105. }
  106. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  107. $massaction = '';
  108. }
  109. $parameters = array();
  110. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  111. if ($reshook < 0) {
  112. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  113. }
  114. /*
  115. * View
  116. */
  117. $form = new Form($db);
  118. //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  119. $help_url = '';
  120. $title = $langs->trans('Resources');
  121. llxHeader('', $title, $help_url);
  122. $sql = '';
  123. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  124. $param = '';
  125. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  126. $param .= '&contextpage='.urlencode($contextpage);
  127. }
  128. if ($limit > 0 && $limit != $conf->liste_limit) {
  129. $param .= '&limit='.((int) $limit);
  130. }
  131. if ($search_ref != '') {
  132. $param .= '&search_ref='.urlencode($search_ref);
  133. $filter['t.ref'] = $search_ref;
  134. }
  135. if ($search_type != '') {
  136. $param .= '&search_type='.urlencode($search_type);
  137. $filter['ty.label'] = $search_type;
  138. }
  139. // Including the previous script generate the correct SQL filter for all the extrafields
  140. // we are playing with the behaviour of the Dolresource::fetchAll() by generating a fake
  141. // extrafields filter key to make it works
  142. $filter['ef.resource'] = $sql;
  143. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  144. // Add $param from extra fields
  145. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  146. // Confirmation suppression resource line
  147. if ($action == 'delete_resource') {
  148. print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResourceElement"), "confirm_delete_resource", '', '', 1);
  149. }
  150. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  151. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN'));
  152. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  153. if ($optioncss != '') {
  154. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  155. }
  156. print '<input type="hidden" name="token" value="'.newToken().'">';
  157. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  158. print '<input type="hidden" name="action" value="list">';
  159. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  160. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  161. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  162. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  163. $ret = $object->fetchAll('', '', 0, 0, $filter);
  164. if ($ret == -1) {
  165. dol_print_error($db, $object->error);
  166. exit;
  167. } else {
  168. $nbtotalofrecords = $ret;
  169. }
  170. }
  171. // Load object list
  172. $ret = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
  173. if ($ret == -1) {
  174. dol_print_error($db, $object->error);
  175. exit;
  176. } else {
  177. $newcardbutton = '';
  178. if ($user->rights->resource->write) {
  179. $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create');
  180. }
  181. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret + 1, $nbtotalofrecords, 'object_resource', 0, $newcardbutton, '', $limit, 0, 0, 1);
  182. }
  183. $moreforfilter = '';
  184. print '<div class="div-table-responsive">';
  185. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  186. print '<tr class="liste_titre_filter">';
  187. // Action column
  188. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  189. print '<td class="liste_titre maxwidthsearch">';
  190. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  191. print $searchpicto;
  192. print '</td>';
  193. }
  194. if (!empty($arrayfields['t.ref']['checked'])) {
  195. print '<td class="liste_titre">';
  196. print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
  197. print '</td>';
  198. }
  199. if (!empty($arrayfields['ty.label']['checked'])) {
  200. print '<td class="liste_titre">';
  201. print '<input type="text" class="flat" name="search_type" value="'.$search_type.'" size="6">';
  202. print '</td>';
  203. }
  204. // Extra fields
  205. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  206. // Action column
  207. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  208. print '<td class="liste_titre maxwidthsearch">';
  209. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  210. print $searchpicto;
  211. print '</td>';
  212. }
  213. print "</tr>\n";
  214. print '<tr class="liste_titre">';
  215. // Action column
  216. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  217. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  218. }
  219. if (!empty($arrayfields['t.ref']['checked'])) {
  220. print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], "t.ref", "", $param, "", $sortfield, $sortorder);
  221. }
  222. if (!empty($arrayfields['ty.label']['checked'])) {
  223. print_liste_field_titre($arrayfields['ty.label']['label'], $_SERVER["PHP_SELF"], "ty.label", "", $param, "", $sortfield, $sortorder);
  224. }
  225. // Extra fields
  226. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  227. // Action column
  228. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  229. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  230. }
  231. print "</tr>\n";
  232. if ($ret) {
  233. foreach ($object->lines as $resource) {
  234. print '<tr class="oddeven">';
  235. // Action column
  236. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  237. print '<td class="center">';
  238. print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
  239. print img_edit();
  240. print '</a>';
  241. print '&nbsp;';
  242. print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
  243. print img_delete('', 'class="marginleftonly"');
  244. print '</a>';
  245. print '</td>';
  246. }
  247. if (!empty($arrayfields['t.ref']['checked'])) {
  248. print '<td>';
  249. print $resource->getNomUrl(5);
  250. print '</td>';
  251. if (!$i) {
  252. $totalarray['nbfield']++;
  253. }
  254. }
  255. if (!empty($arrayfields['ty.label']['checked'])) {
  256. print '<td>';
  257. print $resource->type_label;
  258. print '</td>';
  259. if (!$i) {
  260. $totalarray['nbfield']++;
  261. }
  262. }
  263. // Extra fields
  264. $obj = (Object) $resource->array_options;
  265. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  266. // Action column
  267. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  268. print '<td class="center">';
  269. print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
  270. print img_edit();
  271. print '</a>';
  272. print '&nbsp;';
  273. print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
  274. print img_delete('', 'class="marginleftonly"');
  275. print '</a>';
  276. print '</td>';
  277. }
  278. if (!$i) {
  279. $totalarray['nbfield']++;
  280. }
  281. print '</tr>';
  282. }
  283. } else {
  284. $colspan = 1;
  285. foreach ($arrayfields as $key => $val) {
  286. if (!empty($val['checked'])) {
  287. $colspan++;
  288. }
  289. }
  290. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  291. }
  292. print '</table>';
  293. print "</form>\n";
  294. // End of page
  295. llxFooter();
  296. $db->close();