surveytemp_white.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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_answer';
  27. $cidReset=true;
  28. session_start();
  29. $lang = $_REQUEST['lang'];
  30. $_SESSION["user_language_choice"]=$lang;
  31. require_once ('../inc/global.inc.php');
  32. //api_protect_admin_script();
  33. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  34. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  35. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  36. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  37. require (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  38. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  39. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  40. if(!isset($_SESSION['page'])){
  41. $_SESSION['page'] = 0;
  42. }
  43. else if($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']!=$_SERVER['HTTP_REFERER']){
  44. $_SESSION['page']++;
  45. }
  46. if(isset($_GET['page'])){
  47. $_SESSION['page'] = $_GET['page'];
  48. }
  49. $page = $_SESSION['page'];
  50. if(!isset($_SESSION['page'.$page])){
  51. $_SESSION['page'.$page] = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
  52. }
  53. $nbQuestionsPerPage = 5;
  54. $db_name = stripslashes($_REQUEST['db_name']);
  55. $surveyid = intval($_REQUEST['surveyid']);
  56. $temp = stripslashes($_REQUEST['temp']);
  57. $uid1 = intval($_REQUEST['uid1']);
  58. $mail = stripslashes($_REQUEST['mail']);
  59. $group_offset = $group_offset_dist = empty($_REQUEST['group_offset']) ? 0 : intval($_REQUEST['group_offset']);
  60. $question_offset = $question_offset_dist = empty($_REQUEST['question_offset']) ? 0 : intval($_REQUEST['question_offset']);
  61. $indiceQuestion = $indiceQuestionDist = empty($_REQUEST['indiceQuestion']) ? 1 : intval($_REQUEST['indiceQuestion']);
  62. $sql = 'select * from '.$db_name.'.survey where survey_id='.$surveyid;
  63. $rs = api_sql_query($sql,__FILE__,__LINE__);
  64. $o_survey = mysql_fetch_object($rs);
  65. if(isset($_POST['saveandexit']) || isset($_POST['next']) || isset($_POST['finish']) || isset($_POST['printall'])){
  66. if(is_array($_POST['q'])){
  67. foreach($_POST['q'] as $question => $answer){
  68. if(is_array($answer)){
  69. $answer = implode(',',$answer);
  70. }
  71. $sql = 'SELECT 1
  72. FROM '.$db_name.'.survey_report
  73. WHERE user_id='.$uid1.'
  74. AND survey_id='.$surveyid.'
  75. AND qid='.intval($question);
  76. $rsAnswers = api_sql_query($sql,__FILE__,__LINE__);
  77. // if the answer soon exists we update it, else we insert it
  78. if(mysql_num_rows($rsAnswers)>0){
  79. $sql = 'UPDATE '.$db_name.'.survey_report
  80. SET answer="'.addslashes($answer).'"
  81. WHERE qid='.intval($question).'
  82. AND user_id='.$uid1.'
  83. AND survey_id='.$surveyid;
  84. }
  85. else {
  86. $sql = 'INSERT INTO '.$db_name.'.survey_report
  87. (id, qid, answer, survey_id, user_id) VALUES
  88. ("",'.intval($question).',"'.addslashes($answer).'", '.$surveyid.', '.$uid1.')';
  89. }
  90. $rs=api_sql_query($sql,__FILE__,__LINE__);
  91. }
  92. }
  93. if(isset($_POST['saveandexit'])){
  94. header("Location:thanks1.php?temp=$temp&surveyid=$surveyid&uid1=$uid1&db_name=$db_name&mail=$mail&lang=$lang");
  95. exit;
  96. }
  97. if(isset($_POST['finish']) || isset($_POST['printall'])){
  98. $survey_user_info_table = Database :: get_main_table(MAIN_SURVEY_USER_TABLE);
  99. $sql = 'UPDATE '.$survey_user_info_table.' SET
  100. attempted="yes"
  101. WHERE survey_id='.$surveyid.'
  102. AND db_name = "'.$db_name.'"
  103. AND email = "'.$mail.'"';
  104. $rs=api_sql_query($sql,__FILE__,__LINE__);
  105. if(isset($_POST['finish'])){
  106. header("Location:thanks1.php?temp=$temp&surveyid=$surveyid&uid1=$uid1&db_name=$db_name&mail=$mail&lang=$lang");
  107. exit;
  108. }
  109. }
  110. }
  111. $interbredcrump[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  112. $tool_name = $o_survey->title;
  113. Display::display_header($tool_name);
  114. api_display_tool_title("Survey Name : ".$o_survey->title);
  115. ob_start();
  116. // submit the answers
  117. // select the groups
  118. if(!isset($_POST['printall'])){
  119. $sql = 'SELECT DISTINCT survey_group.*
  120. FROM '.$db_name.'.survey_group
  121. INNER JOIN '.$db_name.'.questions
  122. ON survey_group.group_id = questions.gid
  123. AND questions.survey_id = survey_group.survey_id
  124. WHERE survey_group.survey_id='.$surveyid.'
  125. ORDER BY sortby ASC LIMIT '.$group_offset.',1';
  126. }
  127. else {
  128. $indiceQuestion = 1;
  129. $sql = 'SELECT DISTINCT survey_group.*
  130. FROM '.$db_name.'.survey_group
  131. INNER JOIN '.$db_name.'.questions
  132. ON survey_group.group_id = questions.gid
  133. AND questions.survey_id = survey_group.survey_id
  134. WHERE survey_group.survey_id='.$surveyid.'
  135. ORDER BY sortby ASC LIMIT 0,999';
  136. }
  137. $rsGroups = api_sql_query($sql);
  138. $sql = 'SELECT COUNT(DISTINCT survey_group.group_id)
  139. FROM '.$db_name.'.survey_group
  140. INNER JOIN '.$db_name.'.questions
  141. ON survey_group.group_id = questions.gid
  142. AND questions.survey_id = survey_group.survey_id
  143. WHERE survey_group.survey_id='.$surveyid;
  144. $rscount = api_sql_query($sql, __FILE__, __LINE__);
  145. list($nbGroups) = mysql_fetch_array($rscount);
  146. if(isset($_POST['printall'])){
  147. //display the name of the guy
  148. $sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(MAIN_SURVEY_USER_TABLE).' WHERE user_id='.$uid1;
  149. $rsname = api_sql_query($sql, __FILE__, __LINE__);
  150. $user = api_store_result($rsname);
  151. echo '<center><strong>'.$user[0]['firstname'].' '.$user[0]['lastname'].'</strong></center><br /><br />';
  152. }
  153. echo '<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F6F5F5">
  154. <tr><td>';
  155. while($o_group = mysql_fetch_object($rsGroups) ){
  156. $intro = strip_tags($o_group->introduction);
  157. if($o_group->groupname!='No Group' && !empty($intro))
  158. {
  159. echo "<tr><td><br><table cellpadding='2' border='0' style='border: 1px solid'><tr><td align='center'>";
  160. echo $o_group->introduction;
  161. echo "</td></tr></table><br><br>";
  162. }
  163. $sql = 'SELECT *
  164. FROM '.$db_name.'.questions
  165. WHERE survey_id='.$surveyid.'
  166. AND gid='.intval($o_group->group_id).'
  167. ORDER BY sortby
  168. LIMIT '.$question_offset.',999';
  169. $rsQuestions = api_sql_query($sql);
  170. $nbQuestions = mysql_num_rows($rsQuestions);
  171. $iQuestions = 0;
  172. while($o_question = mysql_fetch_object($rsQuestions)){
  173. if(($iQuestions<$nbQuestionsPerPage || $o_group->groupname!='No Group' )|| isset($_POST['printall'])){
  174. // select the previous answer the user did
  175. $sql = ' SELECT answer
  176. FROM '.$db_name.'.survey_report
  177. WHERE user_id='.$uid1.' AND survey_id='.$surveyid.' AND qid='.$o_question->qid;
  178. $rsAttempt = api_sql_query($sql, __FILE__, __LINE__);
  179. list($answer) = mysql_fetch_array($rsAttempt);
  180. $o_question->caption = eregi_replace('^<p[^>]*>(.*)</p>','\\1', $o_question->caption);
  181. $o_question->caption = eregi_replace('(<[^ ]*) (style=."."[^>]*)(>)','\\1\\3', $o_question->caption);
  182. $o_question->caption = eregi_replace('(<[^ ]*) (style=.""[^>]*)(>)','\\1\\3', $o_question->caption);
  183. $o_question->caption = eregi_replace('(<[^ ]*)( style=."[^"]*")([^>]*)(>)','\\1\\2\\4', $o_question->caption);
  184. echo '<table><tr><td valign="top">'.$indiceQuestion.'- </td><td valign="top">'.stripslashes($o_question->caption).'</td></tr></table>';
  185. $sel1 = $sel2 = "";
  186. switch ($o_question -> qtype) {
  187. case 'Yes/No' :
  188. if($answer=='a1'){
  189. $sel1="checked";
  190. }
  191. else if($answer=='a2'){
  192. $sel2="checked";
  193. }
  194. echo "&nbsp;<input type=radio value='a1' $sel1 name='q[".$o_question->qid."]'>".$o_question->a1."
  195. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=radio value='a2' $sel2 name='q[".$o_question->qid."]'>".$o_question->a2."<BR><BR>";
  196. break;
  197. case 'Open Answer' :
  198. echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<textarea cols='50' rows='6' name='q[".$o_question->qid."]'>".stripslashes($o_question->a1).
  199. "$answer</textarea><br><br>";
  200. break;
  201. case 'Multiple Choice (multiple answer)' :
  202. $answer = explode(',',$answer);
  203. $break = '';
  204. if($o_question->alignment=='vertical')
  205. {
  206. $break= "<tr>";
  207. }
  208. echo '<table cellpadding="4" cellspacing="0" align="left"><tr>';
  209. for($i = 1 ; $i <=10 ; $i++) {
  210. $current = 'a'.$i;
  211. $checked = '';
  212. if(in_array($current,$answer)){
  213. $checked = 'checked';
  214. }
  215. if(!empty($o_question->$current)){
  216. echo '<td><input value="'.$current.'" '.$checked.' type="checkbox" name="q['.$o_question->qid.'][]"></td><td align="left">'.stripslashes($o_question->$current).'</td>'.$break;
  217. }
  218. }
  219. echo "</tr></table><br><br>";
  220. break;
  221. case 'Multiple Choice (single answer)' :
  222. $break = '';
  223. if($o_question->alignment=='vertical')
  224. {
  225. $break= "<tr>";
  226. }
  227. echo '<table cellpadding="4" cellspacing="0" align="left"><tr>';
  228. for($i = 1 ; $i <=10 ; $i++) {
  229. $current = 'a'.$i;
  230. $checked = '';
  231. if($current == $answer){
  232. $checked = 'checked';
  233. }
  234. if(!empty($o_question->$current)){
  235. echo '<td align="left"><input value="'.$current.'" '.$checked.' type="radio" name="q['.$o_question->qid.']"></td><td align="left">'.stripslashes($o_question->$current).'</td>'.$break;
  236. }
  237. }
  238. echo "</tr></table><br><br>";
  239. break;
  240. case 'Numbered' :
  241. $answer = explode(',',$answer);
  242. echo '<table align="center">';
  243. for($i = 1 ; $i <=10 ; $i++) {
  244. $current = 'a'.$i;
  245. if(!empty($o_question->$current)){
  246. echo '<tr><td valign="top"><select name="q['.$o_question->qid.'][]">';
  247. for($j=0;$j<=10;$j++){
  248. $selected="";
  249. if($answer[$i-1]==$j){
  250. $selected="selected";
  251. }
  252. echo "<option value=$j $selected>".stripslashes($j)."</option>";
  253. }
  254. echo '</select><td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;'.$o_question->$current.'<br><br></tr></tr>';
  255. }
  256. }
  257. echo '</table>';
  258. break;
  259. }
  260. $iQuestions++;
  261. $indiceQuestion++;
  262. }
  263. }
  264. if($o_group->groupname!='No Group' || $nbQuestions <= $iQuestions){
  265. $group_offset++;
  266. $question_offset=0;
  267. }
  268. else {
  269. $question_offset += $iQuestions;
  270. }
  271. }
  272. echo '</td></tr></table><br /><br />';
  273. $content = ob_get_contents();
  274. ob_end_clean();
  275. $content = '<form method="post" action="'.$_SERVER['PHP_SELF'].'?surveyid='.$surveyid.'&db_name='.$db_name.'&temp='.$temp.'&uid1='.$uid1.'&mail='.$mail.'&group_offset='.$group_offset.'&question_offset='.$question_offset.'&indiceQuestion='.$indiceQuestion.'&cidReq='.$cidReq.'&lang='.$lang.'">'.$content;
  276. echo $content;
  277. ?>
  278. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  279. <tr>
  280. <td align="center">
  281. <?php
  282. if(!isset($_POST['printall'])){
  283. if($_SESSION['page']==0)
  284. echo "<input type=\"button\" name=\"Back\" value=\"".get_lang('Back')."\" onclick=\"document.location='welcome_1.php?surveyid=".$surveyid.'&db_name='.$db_name.'&temp='.$temp.'&uid1='.$uid1.'&mail='.$mail."';\">";
  285. else {
  286. echo "<input type=\"button\" name=\"Back\" value=\"".get_lang('Back')."\" onclick=\"document.location='".$_SESSION['page'.($_SESSION['page']-1)]."&page=".($_SESSION['page']-1)."';\">";
  287. }
  288. if($group_offset < $nbGroups){
  289. echo '<input type="submit" name="saveandexit" value="'.get_lang('saveandexit').'" onclick="return confirm(\'Are you sure ?\')">';
  290. echo '<input type="submit" name="next" value="'.get_lang('Next').'">&nbsp;';
  291. }
  292. else {
  293. echo '<input type="submit" name="printall" value="'.get_lang('PrintAll').'">';
  294. echo '<input type="submit" name="finish" value="'.get_lang('Next').'" onclick="return confirm(\''.get_lang('AreYouSure').'\')">';
  295. }
  296. }
  297. else {
  298. echo '<script type="text/javascript">window.print()</script>';
  299. echo '<input type="submit" name="finish" value="'.get_lang('Finish').'" onclick="return confirm(\''.get_lang('AreYouSure').'\')">';
  300. }
  301. ?>
  302. </tr>
  303. </table>
  304. </form>
  305. <?php
  306. /*
  307. ==============================================================================
  308. FOOTER
  309. ==============================================================================
  310. */
  311. Display :: display_footer();
  312. ?>