list.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /* Copyright (C) 2013-2015 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 <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/opensurvey/list.php
  20. * \ingroup opensurvey
  21. * \brief Page to list surveys
  22. */
  23. require_once('../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. // Security check
  28. if (!$user->rights->opensurvey->read) accessforbidden();
  29. $action=GETPOST('action','aZ09');
  30. $id=GETPOST('id','alpha');
  31. $numsondage= $id;
  32. $search_ref = GETPOST('search_ref', 'alpha');
  33. $surveytitle=GETPOST('surveytitle', 'alpha');
  34. $status=GETPOST('status', 'int');
  35. //if (! isset($_POST['status']) && ! isset($_GET['status'])) $status='opened'; // If filter unknown, we choose 'opened'
  36. $sortfield = GETPOST("sortfield",'alpha');
  37. $sortorder = GETPOST("sortorder",'alpha');
  38. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  39. $page = GETPOST("page",'int');
  40. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  41. $offset = $limit * $page;
  42. $pageprev = $page - 1;
  43. $pagenext = $page + 1;
  44. if (! $sortfield) $sortfield="p.date_fin";
  45. if (! $sortorder) $sortorder="DESC";
  46. if ($page < 0) {
  47. $page = 0;
  48. }
  49. $langs->load("opensurvey");
  50. /*
  51. * Actions
  52. */
  53. if (GETPOST('button_removefilter'))
  54. {
  55. $status='';
  56. $surveytitle='';
  57. $search_ref='';
  58. }
  59. /*
  60. * View
  61. */
  62. $form=new Form($db);
  63. $opensurvey_static = new Opensurveysondage($db);
  64. $now = dol_now();
  65. llxHeader();
  66. $param='';
  67. $fieldtosortuser=empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?'firstname':'lastname';
  68. print load_fiche_titre($langs->trans("OpenSurveyArea"));
  69. // List of surveys into database
  70. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
  71. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  72. print '<input type="hidden" name="action" value="list">';
  73. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  74. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  75. print '<input type="hidden" name="page" value="'.$page.'">';
  76. $moreforfilter = '';
  77. print '<div class="div-table-responsive">';
  78. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  79. print '<tr class="liste_titre_filter">';
  80. print '<td class="liste_titre"><input type="text" class="maxwidth100" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
  81. print '<td class="liste_titre"><input type="text" class="maxwidth100onsmartphone" name="surveytitle" value="'.dol_escape_htmltag($surveytitle).'"></td>';
  82. print '<td class="liste_titre"></td>';
  83. print '<td class="liste_titre"></td>';
  84. print '<td class="liste_titre"></td>';
  85. $arraystatus=array(''=>'&nbsp;','expired'=>$langs->trans("Expired"),'opened'=>$langs->trans("Opened"));
  86. print '<td class="liste_titre" align="center">'. $form->selectarray('status', $arraystatus, $status).'</td>';
  87. print '<td class="liste_titre"></td>';
  88. print '<td class="liste_titre" align="right">';
  89. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  90. print $searchpicto;
  91. print '</td>';
  92. print '</tr>'."\n";
  93. print '<tr class="liste_titre">';
  94. print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.id_sondage", $param,"","",$sortfield,$sortorder);
  95. print_liste_field_titre($langs->trans("Title"), $_SERVER["PHP_SELF"], "p.titre", $param,"","",$sortfield,$sortorder);
  96. print_liste_field_titre($langs->trans("Type"));
  97. print_liste_field_titre($langs->trans("Author"), $_SERVER["PHP_SELF"], "u.".$fieldtosortuser, $param,"","",$sortfield,$sortorder);
  98. print_liste_field_titre($langs->trans("NbOfVoters"), $_SERVER["PHP_SELF"], "", $param,"",'align="right"',$sortfield,$sortorder);
  99. print_liste_field_titre($langs->trans("ExpireDate"), $_SERVER["PHP_SELF"], "p.date_fin", $param,"",'align="center"',$sortfield,$sortorder);
  100. print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "p.status", $param,"",'align="center"',$sortfield,$sortorder);
  101. print_liste_field_titre('');
  102. print '</tr>'."\n";
  103. $sql = "SELECT p.id_sondage, p.fk_user_creat, p.format, p.date_fin, p.status, p.titre, p.nom_admin,";
  104. $sql.= " u.login, u.firstname, u.lastname";
  105. $sql.= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as p";
  106. $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."user u ON u.rowid = p.fk_user_creat";
  107. // Count total nb of records
  108. $nbtotalofrecords = '';
  109. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  110. {
  111. $result = $db->query($sql);
  112. $nbtotalofrecords = $db->num_rows($result);
  113. }
  114. $sql.= " WHERE p.entity = ".getEntity('survey');
  115. if ($status == 'expired') $sql.=" AND date_fin < '".$db->idate($now)."'";
  116. if ($status == 'opened') $sql.=" AND date_fin >= '".$db->idate($now)."'";
  117. if ($search_ref) $sql.=natural_search("p.id_sondage", $search_ref);
  118. if ($surveytitle) $sql.=natural_search("p.titre", $surveytitle);
  119. $sql.= $db->order($sortfield,$sortorder);
  120. // Count total nb of records
  121. $nbtotalofrecords = '';
  122. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  123. {
  124. $result = $db->query($sql);
  125. $nbtotalofrecords = $db->num_rows($result);
  126. }
  127. $sql.= $db->plimit($limit + 1,$offset);
  128. $resql=$db->query($sql);
  129. if (! $resql) dol_print_error($db);
  130. $num=$db->num_rows($resql);
  131. $i = 0; $var = true;
  132. while ($i < min($num,$limit))
  133. {
  134. $obj=$db->fetch_object($resql);
  135. $sql2='select COUNT(*) as nb from '.MAIN_DB_PREFIX."opensurvey_user_studs where id_sondage='".$db->escape($obj->id_sondage)."'";
  136. $resql2=$db->query($sql2);
  137. if ($resql2)
  138. {
  139. $obj2=$db->fetch_object($resql2);
  140. $nbuser=$obj2->nb;
  141. }
  142. else dol_print_error($db);
  143. $opensurvey_static->id=$obj->id_sondage;
  144. $opensurvey_static->status=$obj->status;
  145. print '<tr>';
  146. print '<td>';
  147. print '<a href="'.dol_buildpath('/opensurvey/card.php',1).'?id='.$obj->id_sondage.'">'.img_picto('','object_opensurvey').' '.$obj->id_sondage.'</a>';
  148. print '</td><td>'.dol_htmlentities($obj->titre).'</td><td>';
  149. $type=($obj->format=='A')?'classic':'date';
  150. print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1);
  151. print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate");
  152. print '</td><td>';
  153. // Author
  154. if ($obj->fk_user_creat) {
  155. $userstatic = new User($db);
  156. $userstatic->id = $obj->fk_user_creat;
  157. $userstatic->firstname = $obj->firstname;
  158. $userstatic->lastname = $obj->lastname;
  159. $userstatic->login = $userstatic->getFullName($langs, 0, -1, 48);
  160. print $userstatic->getLoginUrl(1);
  161. } else {
  162. print dol_htmlentities($obj->nom_admin);
  163. }
  164. print '</td>';
  165. print'<td align="right">'.$nbuser.'</td>'."\n";
  166. print '<td align="center">'.dol_print_date($db->jdate($obj->date_fin),'day');
  167. if ($db->jdate($obj->date_fin) < time()) { print ' ('.$langs->trans("Expired").')'; }
  168. print '</td>';
  169. print'<td align="center">'.$opensurvey_static->getLibStatut(5).'</td>'."\n";
  170. print'<td align="center"></td>'."\n";
  171. print '</tr>'."\n";
  172. $i++;
  173. }
  174. print '</table>'."\n";
  175. print '</div>';
  176. print '</form>';
  177. llxFooter();
  178. $db->close();