list.php 6.6 KB

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