list.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?php
  2. /* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file resource/index.php
  19. * \ingroup resource
  20. * \brief Page to manage resource objects
  21. */
  22. require '../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
  24. // Load translations files required by page
  25. $langs->load("resource");
  26. $langs->load("companies");
  27. $langs->load("other");
  28. // Get parameters
  29. $id = GETPOST('id','int');
  30. $action = GETPOST('action','alpha');
  31. $lineid = GETPOST('lineid','int');
  32. $element = GETPOST('element','alpha');
  33. $element_id = GETPOST('element_id','int');
  34. $resource_id = GETPOST('resource_id','int');
  35. $sortorder = GETPOST('sortorder','alpha');
  36. $sortfield = GETPOST('sortfield','alpha');
  37. // Initialize context for list
  38. $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'resourcelist';
  39. $object = new Dolresource($db);
  40. $extrafields = new ExtraFields($db);
  41. // fetch optionals attributes and labels
  42. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  43. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  44. $search_ref=GETPOST("search_ref");
  45. $search_type=GETPOST("search_type");
  46. $filter=array();
  47. if ($search_ref != ''){
  48. $param.='&search_ref='.$search_ref;
  49. $filter['t.ref']=$search_ref;
  50. }
  51. if ($search_type != ''){
  52. $param.='&search_type='.$search_type;
  53. $filter['ty.label']=$search_type;
  54. }
  55. if ($search_label != '') $param.='&search_label='.$search_label;
  56. // Add $param from extra fields
  57. foreach ($search_array_options as $key => $val)
  58. {
  59. $crit=$val;
  60. $tmpkey=preg_replace('/search_options_/','',$key);
  61. $typ=$extrafields->attribute_type[$tmpkey];
  62. if ($val != '') {
  63. $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  64. }
  65. $mode=0;
  66. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  67. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  68. {
  69. $filter['ef.'.$tmpkey]=natural_search('ef.'.$tmpkey, $crit, $mode);
  70. }
  71. }
  72. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  73. $hookmanager->initHooks(array('resource_list'));
  74. if (empty($sortorder)) $sortorder="ASC";
  75. if (empty($sortfield)) $sortfield="t.rowid";
  76. if (empty($arch)) $arch = 0;
  77. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  78. $page = GETPOST("page");
  79. $page = is_numeric($page) ? $page : 0;
  80. $page = $page == -1 ? 0 : $page;
  81. $offset = $limit * $page ;
  82. $pageprev = $page - 1;
  83. $pagenext = $page + 1;
  84. if( ! $user->rights->resource->read) {
  85. accessforbidden();
  86. }
  87. $arrayfields = array(
  88. 't.ref' => array(
  89. 'label' => $langs->trans("Ref"),
  90. 'checked' => 1
  91. ),
  92. 'ty.label' => array(
  93. 'label' => $langs->trans("ResourceType"),
  94. 'checked' => 1
  95. ),
  96. );
  97. // Extra fields
  98. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) {
  99. foreach ( $extrafields->attribute_label as $key => $val ) {
  100. $typeofextrafield=$extrafields->attribute_type[$key];
  101. if ($typeofextrafield!='separate') {
  102. $arrayfields["ef." . $key] = array(
  103. 'label' => $extrafields->attribute_label[$key],
  104. 'checked' => $extrafields->attribute_list[$key],
  105. 'position' => $extrafields->attribute_pos[$key],
  106. 'enabled' => $extrafields->attribute_perms[$key]
  107. );
  108. }
  109. }
  110. }
  111. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  112. // Do we click on purge search criteria ?
  113. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  114. {
  115. $search_ref="";
  116. $search_label="";
  117. $search_array_options=array();
  118. $filter=array();
  119. }
  120. /*
  121. * Action
  122. */
  123. $parameters=array();
  124. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  125. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  126. /*
  127. * View
  128. */
  129. $form=new Form($db);
  130. $pagetitle=$langs->trans('ResourcePageIndex');
  131. llxHeader('',$pagetitle,'');
  132. // Confirmation suppression resource line
  133. if ($action == 'delete_resource')
  134. {
  135. print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_resource",'','',1);
  136. }
  137. // Load object list
  138. $ret = $object->fetch_all($sortorder, $sortfield, $limit, $offset, $filter);
  139. if($ret == -1) {
  140. dol_print_error($db,$object->error);
  141. exit;
  142. } else {
  143. print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret+1, $object->num_all,'title_generic.png');
  144. }
  145. $var=true;
  146. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  147. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);
  148. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  149. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  150. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  151. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  152. print '<input type="hidden" name="action" value="list">';
  153. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  154. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  155. print '<input type="hidden" name="page" value="'.$page.'">';
  156. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  157. $moreforfilter = '';
  158. print '<div class="div-table-responsive">';
  159. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  160. print '<tr class="liste_titre_filter">';
  161. if (! empty($arrayfields['t.ref']['checked']))
  162. {
  163. print '<td class="liste_titre">';
  164. print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
  165. print '</td>';
  166. }
  167. if (! empty($arrayfields['ty.label']['checked']))
  168. {
  169. print '<td class="liste_titre">';
  170. print '<input type="text" class="flat" name="search_type" value="'.$search_type.'" size="6">';
  171. print '</td>';
  172. }
  173. // Extra fields
  174. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  175. {
  176. foreach($extrafields->attribute_label as $key => $val)
  177. {
  178. if (! empty($arrayfields["ef.".$key]['checked']))
  179. {
  180. $align=$extrafields->getAlignFlag($key);
  181. $typeofextrafield=$extrafields->attribute_type[$key];
  182. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  183. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  184. {
  185. $crit=$val;
  186. $tmpkey=preg_replace('/search_options_/','',$key);
  187. $searchclass='';
  188. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  189. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  190. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  191. }
  192. print '</td>';
  193. }
  194. }
  195. }
  196. // Action column
  197. print '<td class="liste_titre" align="right">';
  198. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  199. print $searchpicto;
  200. print '</td>';
  201. print "</tr>\n";
  202. print '<tr class="liste_titre">';
  203. if (! empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'],$_SERVER["PHP_SELF"],"t.ref","",$param,"",$sortfield,$sortorder);
  204. if (! empty($arrayfields['ty.label']['checked'])) print_liste_field_titre($arrayfields['ty.label']['label'],$_SERVER["PHP_SELF"],"t.code","",$param,"",$sortfield,$sortorder);
  205. // Extra fields
  206. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  207. {
  208. foreach($extrafields->attribute_label as $key => $val)
  209. {
  210. if (! empty($arrayfields["ef.".$key]['checked']))
  211. {
  212. $align=$extrafields->getAlignFlag($key);
  213. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  214. }
  215. }
  216. }
  217. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  218. print "</tr>\n";
  219. if ($ret)
  220. {
  221. foreach ($object->lines as $resource)
  222. {
  223. $style='';
  224. if ($resource->id == GETPOST('lineid')) $style='style="background: orange;"';
  225. print '<tr '.$bc[$var].' '.$style.'>';
  226. if (! empty($arrayfields['t.ref']['checked']))
  227. {
  228. print '<td>';
  229. print $resource->getNomUrl(5);
  230. print '</td>';
  231. }
  232. if (! empty($arrayfields['ty.label']['checked']))
  233. {
  234. print '<td>';
  235. print $resource->type_label;
  236. print '</td>';
  237. }
  238. // Extra fields
  239. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  240. {
  241. foreach($extrafields->attribute_label as $key => $val)
  242. {
  243. if (! empty($arrayfields["ef.".$key]['checked']))
  244. {
  245. print '<td';
  246. $align=$extrafields->getAlignFlag($key);
  247. if ($align) print ' align="'.$align.'"';
  248. print '>';
  249. $tmpkey='options_'.$key;
  250. print $extrafields->showOutputField($key, $resource->array_options[$tmpkey], '', 1);
  251. print '</td>';
  252. }
  253. }
  254. if (! $i) $totalarray['nbfield']++;
  255. }
  256. print '<td align="center">';
  257. print '<a href="./card.php?action=edit&id='.$resource->id.'">';
  258. print img_edit();
  259. print '</a>';
  260. print '&nbsp;';
  261. print '<a href="./card.php?action=delete&id='.$resource->id.'">';
  262. print img_delete();
  263. print '</a>';
  264. print '</td>';
  265. print '</tr>';
  266. }
  267. print '</table>';
  268. print "</form>\n";
  269. }
  270. else
  271. {
  272. print '<tr><td class="opacitymedium">'.$langs->trans('NoResourceInDatabase').'</td></tr>';
  273. }
  274. llxFooter();
  275. $db->close();