survey_white.php 10 KB

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