survey_white.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php // $Id: index.php,v 1.44 2005/07/01 10:03:36 olivierb78 Exp $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 University of Ghent (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * Index of the admin tools
  22. *
  23. * @package dokeos.admin
  24. ==============================================================================
  25. */
  26. $langFile='survey';
  27. $cidReset=true;
  28. require_once ('../inc/global.inc.php');
  29. //api_protect_admin_script();
  30. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  31. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  32. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  33. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  34. require (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  35. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  36. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  37. $nbQuestionsPerPage = 5;
  38. $db_name = stripslashes($_REQUEST['db_name']);
  39. $surveyid = intval($_REQUEST['surveyid']);
  40. $temp = stripslashes($_REQUEST['temp']);
  41. $group_offset = $group_offset_dist = empty($_REQUEST['group_offset']) ? 0 : intval($_REQUEST['group_offset']);
  42. $question_offset = $question_offset_dist = empty($_REQUEST['question_offset']) ? 0 : intval($_REQUEST['question_offset']);
  43. $indiceQuestion = $indiceQuestionDist = empty($_REQUEST['indiceQuestion']) ? 1 : intval($_REQUEST['indiceQuestion']);
  44. $group_offset_back = empty($_REQUEST['group_offset_back']) ? 0 : intval($_REQUEST['group_offset_back']);
  45. $question_offset_back = empty($_REQUEST['question_offset_back']) ? 0 : intval($_REQUEST['question_offset_back']);
  46. $indiceQuestionBack = empty($_REQUEST['indiceQuestionBack']) ? 1 : intval($_REQUEST['indiceQuestionBack']);
  47. $sql = 'select * from '.$db_name.'.survey where survey_id='.$surveyid;
  48. $rs = api_sql_query($sql,__FILE__,__LINE__);
  49. $o_survey = mysql_fetch_object($rs);
  50. $interbredcrump[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  51. $tool_name = get_lang('preview');
  52. Display::display_header($tool_name);
  53. api_display_tool_title("Survey Name : ".$o_survey->title);
  54. // write the css template
  55. //echo '<link href="../css/survey_'.$template.'.css" rel="stylesheet" type="text/css">';
  56. // select the groups
  57. $sql = 'SELECT DISTINCT survey_group.*
  58. FROM '.$db_name.'.survey_group
  59. INNER JOIN '.$db_name.'.questions
  60. ON survey_group.group_id = questions.gid
  61. AND questions.survey_id = survey_group.survey_id
  62. WHERE survey_group.survey_id='.$surveyid.'
  63. ORDER BY sortby ASC LIMIT '.$group_offset.',1';
  64. $rsGroups = api_sql_query($sql);
  65. $sql = 'SELECT COUNT(DISTINCT survey_group.group_id)
  66. FROM '.$db_name.'.survey_group
  67. INNER JOIN '.$db_name.'.questions
  68. ON survey_group.group_id = questions.gid
  69. AND questions.survey_id = survey_group.survey_id
  70. WHERE survey_group.survey_id='.$surveyid;
  71. $rscount = api_sql_query($sql, __FILE__, __LINE__);
  72. list($nbGroups) = mysql_fetch_array($rscount);
  73. echo '<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F6F5F5">
  74. <tr><td>';
  75. while($o_group = mysql_fetch_object($rsGroups) ){
  76. $intro = strip_tags($o_group->introduction);
  77. if($o_group->groupname!='No Group' && !empty($intro))
  78. {
  79. echo "<tr><td><br><table cellpadding='2' border='0' style='border: 1px solid'><tr><td align='center'>";
  80. echo $o_group->introduction;
  81. echo "</td></tr></table><br><br>";
  82. }
  83. $sql = 'SELECT *
  84. FROM '.$db_name.'.questions
  85. WHERE survey_id='.$surveyid.'
  86. AND gid='.intval($o_group->group_id).'
  87. ORDER BY sortby
  88. LIMIT '.$question_offset.',999';
  89. $rsQuestions = api_sql_query($sql);
  90. $nbQuestions = mysql_num_rows($rsQuestions);
  91. $iQuestions = 0;
  92. while($o_question = mysql_fetch_object($rsQuestions)){
  93. if($iQuestions<$nbQuestionsPerPage || $o_group->groupname!='No Group'){
  94. // select the previous answer the user did
  95. $sql = ' SELECT answer
  96. FROM '.$db_name.'.survey_report
  97. WHERE user_id='.$_uid.' AND survey_id='.$surveyid.' AND qid='.$o_question->qid;
  98. $rsAttempt = api_sql_query($sql, __FILE__, __LINE__);
  99. list($answer) = mysql_fetch_array($rsAttempt);
  100. // remove the f*** <p></p> and other boring and stupid styles
  101. $o_question->caption = eregi_replace('^<p[^>]*>(.*)</p>','\\1', $o_question->caption);
  102. $o_question->caption = eregi_replace('(<[^ ]*) (style=."."[^>]*)(>)','\\1\\3', $o_question->caption);
  103. $o_question->caption = eregi_replace('(<[^ ]*) (style=.""[^>]*)(>)','\\1\\3', $o_question->caption);
  104. $o_question->caption = eregi_replace('(<[^ ]*)( style=."[^"]*")([^>]*)(>)','\\1\\2\\4', $o_question->caption);
  105. echo '<table><tr><td valign="top">'.$indiceQuestion.'- </td><td valign="top">'.stripslashes($o_question->caption).'</td></tr></table>';
  106. $sel1 = $sel2 = "";
  107. switch ($o_question -> qtype) {
  108. case 'Yes/No' :
  109. if($answer=='a1'){
  110. $sel1="checked";
  111. }
  112. else if($answer=='a2'){
  113. $sel2="checked";
  114. }
  115. echo "&nbsp;<input type=radio value='a1' $sel1 name='q[".$o_question->qid."]'>".stripslashes($o_question->a1)."
  116. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=radio value='a2' $sel2 name='q[".$o_question->qid."]'>".stripslashes($o_question->a2)."<BR><BR>";
  117. break;
  118. case 'Open Answer' :
  119. echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea cols='50' rows='6' name='q[".$o_question->qid."]'>".stripslashes($o_question->a1).
  120. stripslashes($answer)."</textarea><br><br>";
  121. break;
  122. case 'Multiple Choice (multiple answer)' :
  123. $answer = explode(',',$answer);
  124. $break = '';
  125. if($o_question->alignment=='vertical')
  126. {
  127. $break= "<br>";
  128. }
  129. echo '<table cellpadding="7" cellspacing="0"><tr><td>';
  130. for($i = 1 ; $i <=10 ; $i++) {
  131. $current = 'a'.$i;
  132. $checked = '';
  133. if(in_array($current,$answer)){
  134. $checked = 'checked';
  135. }
  136. if(!empty($o_question->$current)){
  137. if($i!=1 || $o_question->alignment=='vertical')
  138. echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  139. echo '<input value="'.$current.'" '.$checked.' type="checkbox" name="q['.$o_question->qid.'][]">'.stripslashes($o_question->$current.$break);
  140. }
  141. }
  142. echo "</td></tr></table><br><br>";
  143. break;
  144. case 'Multiple Choice (single answer)' :
  145. $break = '';
  146. if($o_question->alignment=='vertical')
  147. {
  148. $break= "<br>";
  149. }
  150. echo '<table cellpadding="7" cellspacing="0"><tr><td>';
  151. for($i = 1 ; $i <=10 ; $i++) {
  152. $current = 'a'.$i;
  153. $checked = '';
  154. if($current == $answer){
  155. $checked = 'checked';
  156. }
  157. if(!empty($o_question->$current)){
  158. if($i!=1 || $o_question->alignment=='vertical')
  159. echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  160. echo '<input value="'.$current.'" '.$checked.' type="radio" name="q['.$o_question->qid.']">'.stripslashes($o_question->$current.$break);
  161. }
  162. }
  163. echo "</td></tr></table><br><br>";
  164. break;
  165. case 'Numbered' :
  166. $answer = explode(',',$answer);
  167. for($i = 1 ; $i <=10 ; $i++) {
  168. $current = 'a'.$i;
  169. if(!empty($o_question->$current)){
  170. echo '&nbsp;&nbsp;&nbsp;<select name="q['.$o_question->qid.'][]">';
  171. for($j=0;$j<=10;$j++){
  172. $selected="";
  173. if($answer[$i]==$j){
  174. $selected="selected";
  175. }
  176. echo "<option value=$j $selected>".stripslashes($j)."</option>";
  177. }
  178. echo '</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.stripslashes($o_question->$current).'<br><br>';
  179. }
  180. }
  181. break;
  182. }
  183. $iQuestions++;
  184. $indiceQuestion++;
  185. }
  186. }
  187. if($o_group->groupname!='No Group' || $nbQuestions <= $iQuestions){
  188. $group_offset++;
  189. $question_offset=0;
  190. }
  191. else {
  192. $question_offset += $iQuestions;
  193. }
  194. }
  195. echo '</td></tr></table>';
  196. ?>
  197. <br /><br />
  198. <form method="get" action="<?=$_SERVER['PHP_SELF']?>">
  199. <input type="hidden" name="surveyid" value="<?=$surveyid;?>">
  200. <input type="hidden" name="db_name" value="<?=$db_name;?>">
  201. <input type="hidden" name="temp" value="<?=$temp;?>">
  202. <input type="hidden" name="cidReq" value="<?=$_GET['cidReq'];?>">
  203. <input type="hidden" name="group_offset" value="<?=$group_offset;?>">
  204. <input type="hidden" name="question_offset" value="<?=$question_offset;?>">
  205. <input type="hidden" name="indiceQuestion" value="<?=$indiceQuestion;?>">
  206. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  207. <tr>
  208. <td align="center">
  209. <?php
  210. echo "<input type=\"button\" name=\"Back\" value=\"Back\" onclick=\"history.back();\">";
  211. if($group_offset < $nbGroups)
  212. echo '<input type="submit" name="submit" value="Next">&nbsp;';
  213. else
  214. echo '<input type="button" value="Finish" onclick="document.location=\'survey_list.php?cidReq='.$cidReq.'\'">&nbsp;';
  215. ?>
  216. <input type="button" value="Print" onclick="window.print()"></td>
  217. </tr>
  218. </table>
  219. </form>
  220. <?php
  221. /*
  222. ==============================================================================
  223. FOOTER
  224. ==============================================================================
  225. */
  226. Display :: display_footer();
  227. ?>