list.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <?php
  2. /* Copyright (C) 2013-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  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/opensurvey/list.php
  20. * \ingroup opensurvey
  21. * \brief Page to list surveys
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  25. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  26. require_once DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php";
  27. // Load translation files required by the page
  28. $langs->load("opensurvey");
  29. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  30. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  31. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  32. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  33. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  34. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  35. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'opensurveylist'; // To manage different context of search
  36. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  37. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  38. $id = GETPOST('id', 'alpha');
  39. $search_ref = GETPOST('search_ref', 'alpha');
  40. $search_title = GETPOST('search_title', 'alpha');
  41. $search_status = GETPOST('search_status', 'alpha');
  42. // Load variable for pagination
  43. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  48. $page = 0;
  49. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. // Initialize technical objects
  54. $object = new Opensurveysondage($db);
  55. $opensurvey_static = new Opensurveysondage($db);
  56. $extrafields = new ExtraFields($db);
  57. $diroutputmassaction = $conf->opensurvey->dir_output.'/temp/massgeneration/'.$user->id;
  58. $hookmanager->initHooks(array('surveylist')); // Note that conf->hooks_modules contains array
  59. // Fetch optionals attributes and labels
  60. $extrafields->fetch_name_optionals_label($object->table_element);
  61. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  62. // Default sort order (if not yet defined by previous GETPOST)
  63. if (!$sortfield) {
  64. $sortfield = "p.date_fin";
  65. }
  66. if (!$sortorder) {
  67. $sortorder = "DESC";
  68. }
  69. // Security check
  70. if (!$user->rights->opensurvey->read) {
  71. accessforbidden();
  72. }
  73. // Definition of fields for list
  74. $arrayfields = array();
  75. foreach ($arrayfields as $key => $val) {
  76. // If $val['visible']==0, then we never show the field
  77. if (!empty($val['visible'])) {
  78. $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>$val['enabled'], 'position'=>$val['position']);
  79. }
  80. }
  81. // Extra fields
  82. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) {
  83. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  84. if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
  85. $arrayfields["ef.".$key] = array(
  86. 'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
  87. 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1),
  88. 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key],
  89. 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])
  90. );
  91. }
  92. }
  93. }
  94. $object->fields = dol_sort_array($object->fields, 'position');
  95. $arrayfields = dol_sort_array($arrayfields, 'position');
  96. $permissiontoread = $user->rights->opensurvey->read;
  97. $permissiontoadd = $user->rights->opensurvey->write;
  98. // permission delete doesn't exists
  99. $permissiontodelete = $user->rights->opensurvey->write;
  100. /*
  101. * Actions
  102. */
  103. if (GETPOST('cancel', 'alpha')) {
  104. $action = 'list'; $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. if (empty($reshook)) {
  115. // Selection of new fields
  116. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  117. // Purge search criteria
  118. 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
  119. $search_status = '';
  120. $search_title = '';
  121. $search_ref = '';
  122. $toselect = array();
  123. $search_array_options = array();
  124. }
  125. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  126. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  127. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  128. }
  129. // Mass actions
  130. $objectclass = 'Opensurveysondage';
  131. $objectlabel = 'Opensurveysondage';
  132. $uploaddir = $conf->opensurvey->dir_output;
  133. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  134. }
  135. /*
  136. * View
  137. */
  138. $form = new Form($db);
  139. $now = dol_now();
  140. //$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  141. $help_url = '';
  142. $title = $langs->trans('OpenSurveyArea');
  143. $sql = "SELECT p.id_sondage as rowid, p.fk_user_creat, p.format, p.date_fin, p.status, p.titre as title, p.nom_admin, p.tms,";
  144. $sql .= " u.login, u.firstname, u.lastname";
  145. $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as p";
  146. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u ON u.rowid = p.fk_user_creat";
  147. $sql .= " WHERE p.entity IN (".getEntity('survey').")";
  148. if ($search_status != '-1' && $search_status != '') {
  149. $sql .= natural_search("p.status", $search_status, 2);
  150. }
  151. if ($search_expired == 'expired') {
  152. $sql .= " AND p.date_fin < '".$db->idate($now)."'";
  153. }
  154. if ($search_expired == 'opened') {
  155. $sql .= " AND p.date_fin >= '".$db->idate($now)."'";
  156. }
  157. if ($search_ref) {
  158. $sql .= natural_search("p.id_sondage", $search_ref);
  159. }
  160. if ($search_title) {
  161. $sql .= natural_search("p.titre", $search_title);
  162. }
  163. // Add where from extra fields
  164. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  165. // Add where from hooks
  166. $parameters = array();
  167. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  168. $sql .= $hookmanager->resPrint;
  169. $sql .= $db->order($sortfield, $sortorder);
  170. // Count total nb of records
  171. $nbtotalofrecords = '';
  172. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  173. $resql = $db->query($sql);
  174. $nbtotalofrecords = $db->num_rows($resql);
  175. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  176. $page = 0;
  177. $offset = 0;
  178. }
  179. }
  180. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  181. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
  182. $num = $nbtotalofrecords;
  183. } else {
  184. $sql .= $db->plimit($limit + 1, $offset);
  185. $resql = $db->query($sql);
  186. if (!$resql) {
  187. dol_print_error($db);
  188. exit;
  189. }
  190. $num = $db->num_rows($resql);
  191. }
  192. // Direct jump if only one record found
  193. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) {
  194. $obj = $db->fetch_object($resql);
  195. $id = $obj->rowid;
  196. header("Location: ".dol_buildpath('/opensurvey/card.php', 1).'?id='.$id);
  197. exit;
  198. }
  199. // Output page
  200. // --------------------------------------------------------------------
  201. llxHeader('', $title, $help_url);
  202. $arrayofselected = is_array($toselect) ? $toselect : array();
  203. $param = '';
  204. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  205. $param .= '&contextpage='.urlencode($contextpage);
  206. }
  207. if ($limit > 0 && $limit != $conf->liste_limit) {
  208. $param .= '&limit='.urlencode($limit);
  209. }
  210. $fieldtosortuser = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 'firstname' : 'lastname';
  211. if ($optioncss != '') {
  212. $param .= '&optioncss='.urlencode($optioncss);
  213. }
  214. // Add $param from extra fields
  215. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  216. // List of mass actions available
  217. $arrayofmassactions = array(
  218. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  219. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  220. );
  221. if ($permissiontodelete) {
  222. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  223. }
  224. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  225. $arrayofmassactions = array();
  226. }
  227. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  228. // List of surveys into database
  229. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  230. if ($optioncss != '') {
  231. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  232. }
  233. print '<input type="hidden" name="token" value="'.newToken().'">';
  234. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  235. print '<input type="hidden" name="action" value="list">';
  236. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  237. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  238. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  239. $newcardbutton = dolGetButtonTitle($langs->trans('NewSurvey'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/opensurvey/wizard/index.php', '', $user->rights->opensurvey->write);
  240. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'poll', 0, $newcardbutton, '', $limit, 0, 0, 1);
  241. // Add code for pre mass action (confirmation or email presend form)
  242. $topicmail = "SendOpenSurveyRef";
  243. $modelmail = "opensurvey";
  244. $objecttmp = new Opensurveysondage($db);
  245. $trackid = 'surv'.$object->id;
  246. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  247. if ($sall) {
  248. foreach ($fieldstosearchall as $key => $val) {
  249. $fieldstosearchall[$key] = $langs->trans($val);
  250. }
  251. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  252. }
  253. $moreforfilter = '';
  254. /*$moreforfilter.='<div class="divsearchfield">';
  255. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  256. $moreforfilter.= '</div>';*/
  257. $parameters = array();
  258. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  259. if (empty($reshook)) {
  260. $moreforfilter .= $hookmanager->resPrint;
  261. } else {
  262. $moreforfilter = $hookmanager->resPrint;
  263. }
  264. if (!empty($moreforfilter)) {
  265. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  266. print $moreforfilter;
  267. print '</div>';
  268. }
  269. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  270. //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  271. $selectedfields = '';
  272. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  273. print '<div class="div-table-responsive">';
  274. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  275. // Fields title search
  276. // --------------------------------------------------------------------
  277. print '<tr class="liste_titre_filter">';
  278. print '<td class="liste_titre"><input type="text" class="maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  279. print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="search_title" value="'.dol_escape_htmltag($search_title).'"></td>';
  280. print '<td class="liste_titre"></td>';
  281. print '<td class="liste_titre"></td>';
  282. print '<td class="liste_titre"></td>';
  283. print '<td class="liste_titre"></td>';
  284. print '<td class="liste_titre"></td>';
  285. $arraystatus = array('-1'=>'&nbsp;', '0'=>$langs->trans("Draft"), '1'=>$langs->trans("Opened"), '2'=>$langs->trans("Closed"));
  286. print '<td class="liste_titre" align="center">'.$form->selectarray('search_status', $arraystatus, $search_status).'</td>';
  287. // Extra fields
  288. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  289. // Fields from hook
  290. $parameters = array('arrayfields'=>$arrayfields);
  291. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  292. print $hookmanager->resPrint;
  293. // Action column
  294. print '<td class="liste_titre maxwidthsearch">';
  295. $searchpicto = $form->showFilterButtons();
  296. print $searchpicto;
  297. print '</td>';
  298. print '</tr>'."\n";
  299. // Fields title label
  300. // --------------------------------------------------------------------
  301. print '<tr class="liste_titre">';
  302. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.id_sondage", $param, "", "", $sortfield, $sortorder);
  303. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "p.titre", $param, "", "", $sortfield, $sortorder);
  304. print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "p.format", $param, "", "", $sortfield, $sortorder);
  305. print_liste_field_titre("Author", $_SERVER["PHP_SELF"], "u.".$fieldtosortuser, $param, "", "", $sortfield, $sortorder);
  306. print_liste_field_titre("NbOfVoters", $_SERVER["PHP_SELF"], "", $param, "", 'align="right"', $sortfield, $sortorder);
  307. print_liste_field_titre("ExpireDate", $_SERVER["PHP_SELF"], "p.date_fin", $param, "", 'align="center"', $sortfield, $sortorder);
  308. print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "p.tms", $param, "", 'align="center"', $sortfield, $sortorder);
  309. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "p.status", $param, "", 'align="center"', $sortfield, $sortorder);
  310. // Extra fields
  311. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  312. // Hook fields
  313. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  314. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  315. print $hookmanager->resPrint;
  316. // Action column
  317. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ')."\n";
  318. print '</tr>'."\n";
  319. // Loop on record
  320. // --------------------------------------------------------------------
  321. $i = 0;
  322. $totalarray = array();
  323. $totalarray['nbfield'] = 0;
  324. while ($i < min($num, $limit)) {
  325. $obj = $db->fetch_object($resql);
  326. if (empty($obj)) {
  327. break; // Should not happen
  328. }
  329. $sql2 = 'select COUNT(*) as nb from '.MAIN_DB_PREFIX."opensurvey_user_studs where id_sondage='".$db->escape($obj->rowid)."'";
  330. $resql2 = $db->query($sql2);
  331. if ($resql2) {
  332. $obj2 = $db->fetch_object($resql2);
  333. $nbuser = $obj2->nb;
  334. } else {
  335. dol_print_error($db);
  336. }
  337. $opensurvey_static->id = $obj->rowid;
  338. $opensurvey_static->ref = $obj->rowid;
  339. $opensurvey_static->title = $obj->title;
  340. $opensurvey_static->status = $obj->status;
  341. $opensurvey_static->date_fin = $db->jdate($obj->date_fin);
  342. // Show here line of result
  343. print '<tr class="oddeven">';
  344. // Ref
  345. print '<td>';
  346. print $opensurvey_static->getNomUrl(1);
  347. print '</td>';
  348. if (!$i) {
  349. $totalarray['nbfield']++;
  350. }
  351. // Title
  352. print '<td>'.dol_htmlentities($obj->title).'</td>';
  353. if (!$i) {
  354. $totalarray['nbfield']++;
  355. }
  356. // Type
  357. print '<td>';
  358. $type = ($obj->format == 'A') ? 'classic' : 'date';
  359. print img_picto('', dol_buildpath('/opensurvey/img/'.($type == 'classic' ? 'chart-32.png' : 'calendar-32.png'), 1), 'width="16"', 1);
  360. print ' '.$langs->trans($type == 'classic' ? "TypeClassic" : "TypeDate");
  361. print '</td>';
  362. if (!$i) {
  363. $totalarray['nbfield']++;
  364. }
  365. print '<td>';
  366. // Author
  367. if ($obj->fk_user_creat) {
  368. $userstatic = new User($db);
  369. $userstatic->id = $obj->fk_user_creat;
  370. $userstatic->firstname = $obj->firstname;
  371. $userstatic->lastname = $obj->lastname;
  372. $userstatic->login = $userstatic->getFullName($langs, 0, -1, 48);
  373. print $userstatic->getLoginUrl(1);
  374. } else {
  375. print dol_htmlentities($obj->nom_admin);
  376. }
  377. print '</td>';
  378. if (!$i) {
  379. $totalarray['nbfield']++;
  380. }
  381. // Nb of voters
  382. print'<td class="right">'.$nbuser.'</td>'."\n";
  383. if (!$i) {
  384. $totalarray['nbfield']++;
  385. }
  386. print '<td class="center">'.dol_print_date($db->jdate($obj->date_fin), 'day');
  387. if ($db->jdate($obj->date_fin) < $now && $obj->status == Opensurveysondage::STATUS_VALIDATED) {
  388. print img_warning($langs->trans("Expired"));
  389. }
  390. print '</td>';
  391. if (!$i) {
  392. $totalarray['nbfield']++;
  393. }
  394. print '<td class="center">'.dol_print_date($db->jdate($obj->tms), 'dayhour');
  395. print '</td>';
  396. if (!$i) {
  397. $totalarray['nbfield']++;
  398. }
  399. print '<td class="center">'.$opensurvey_static->getLibStatut(5).'</td>'."\n";
  400. if (!$i) {
  401. $totalarray['nbfield']++;
  402. }
  403. // Extra fields
  404. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  405. // Fields from hook
  406. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  407. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  408. print $hookmanager->resPrint;
  409. // Action column
  410. print '<td class="nowrap center">';
  411. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  412. $selected = 0;
  413. if (in_array($obj->rowid, $arrayofselected)) {
  414. $selected = 1;
  415. }
  416. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  417. }
  418. print '</td>';
  419. if (!$i) {
  420. $totalarray['nbfield']++;
  421. }
  422. print '</tr>'."\n";
  423. $i++;
  424. }
  425. // Show total line
  426. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  427. // If no record found
  428. if ($num == 0) {
  429. $colspan = 8;
  430. foreach ($arrayfields as $key => $val) {
  431. if (!empty($val['checked'])) {
  432. $colspan++;
  433. }
  434. }
  435. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  436. }
  437. $db->free($resql);
  438. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  439. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  440. print $hookmanager->resPrint;
  441. print '</table>'."\n";
  442. print '</div>'."\n";
  443. print '</form>'."\n";
  444. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  445. $hidegeneratedfilelistifempty = 1;
  446. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  447. $hidegeneratedfilelistifempty = 0;
  448. }
  449. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  450. $formfile = new FormFile($db);
  451. // Show list of available documents
  452. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  453. $urlsource .= str_replace('&amp;', '&', $param);
  454. $filedir = $diroutputmassaction;
  455. $genallowed = $permissiontoread;
  456. $delallowed = $permissiontoadd;
  457. print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  458. }
  459. // End of page
  460. llxFooter();
  461. $db->close();