list.php 22 KB

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