survey.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 unknown
  19. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  20. * @version $Id: survey.php 14636 2008-03-17 22:24:08Z yannoo $
  21. *
  22. * @todo use quickforms for the forms
  23. */
  24. // name of the language file that needs to be included
  25. $language_file = 'survey';
  26. // including the global dokeos file
  27. require ('../inc/global.inc.php');
  28. // including additional libraries
  29. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  30. require_once('survey.lib.php');
  31. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  32. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  33. if (!api_is_allowed_to_edit())
  34. {
  35. Display :: display_header(get_lang('Survey'));
  36. Display :: display_error_message(get_lang('NotAllowed'), false);
  37. Display :: display_footer();
  38. exit;
  39. }
  40. // Database table definitions
  41. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  42. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  43. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  44. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  45. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  46. $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  47. // breadcrumbs
  48. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
  49. // getting the survey information
  50. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  51. $tool_name = substr(strip_tags($survey_data['title']), 0, 40);
  52. if (strlen(strip_tags($survey_data['title'])) > 40)
  53. {
  54. $tool_name .= '...';
  55. }
  56. // Displaying the header
  57. Display::display_header($tool_name);
  58. // Action handling
  59. if (isset($_GET['action']))
  60. {
  61. if (($_GET['action'] == 'moveup' OR $_GET['action'] == 'movedown') AND isset($_GET['question_id']))
  62. {
  63. survey_manager::move_survey_question($_GET['action'], $_GET['question_id'], $_GET['survey_id']);
  64. Display::display_confirmation_message('SurveyQuestionMoved', false);
  65. }
  66. if ($_GET['action'] == 'delete' AND is_numeric($_GET['question_id']))
  67. {
  68. survey_manager::delete_survey_question($_GET['survey_id'], $_GET['question_id'], $survey_data['is_shared']);
  69. }
  70. }
  71. if (isset($_GET['message']))
  72. {
  73. // we have created the survey or updated the survey
  74. if (in_array($_GET['message'], array('SurveyUpdatedSuccesfully','SurveyCreatedSuccesfully')))
  75. {
  76. Display::display_confirmation_message(get_lang($_GET['message']).'<br />'.get_lang('YouCanNowAddQuestionToYourSurvey'), false);
  77. }
  78. // we have added a question
  79. if (in_array($_GET['message'], array('QuestionAdded','QuestionUpdated')))
  80. {
  81. Display::display_confirmation_message(get_lang($_GET['message']), false);
  82. }
  83. }
  84. // We exit here is the first or last question is a pagebreak (which causes errors)
  85. check_first_last_question($_GET['survey_id']);
  86. // Action links
  87. $survey_actions = get_lang('Survey').': ';
  88. $survey_actions .= '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$_GET['survey_id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  89. $survey_actions .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$_GET['survey_id'].'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurvey").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  90. //$survey_actions .= '<a href="create_survey_in_another_language.php?id_survey='.$_GET['survey_id'].'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
  91. $survey_actions .= '<a href="preview.php?'.api_get_cidreq().'&amp;survey_id='.$_GET['survey_id'].'">'.Display::return_icon('preview.gif', get_lang('Preview')).'</a>';
  92. $survey_actions .= '<a href="survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$_GET['survey_id'].'">'.Display::return_icon('survey_publish.gif', get_lang('Publish')).'</a>';
  93. $survey_actions .= '<a href="reporting.php?'.api_get_cidreq().'&amp;survey_id='.$_GET['survey_id'].'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>';
  94. echo '<div style="float:right;">'.$survey_actions.'</div>';
  95. echo '<div>';
  96. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=yesno&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/yesno.gif" /><br />'.get_lang('YesNo').'</a></div>';
  97. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=multiplechoice&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/mcua.gif" /><br />'.get_lang('MultipleChoice').'</a></div>';
  98. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=multipleresponse&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/mcma.gif" /><br />'.get_lang('MultipleResponse').'</a></div>';
  99. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=open&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/open_answer.gif" /><br />'.get_lang('Open').'</a></div>';
  100. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=dropdown&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/dropdown.gif" /><br />'.get_lang('Dropdown').'</a></div>';
  101. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=percentage&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/percentagequestion.gif" /><br />'.get_lang('Percentage').'</a></div>';
  102. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=score&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/scorequestion.gif" /><br />'.get_lang('Score').'</a></div>';
  103. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=comment&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/commentquestion.gif" /><br />'.get_lang('Comment').'</a></div>';
  104. echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?'.api_get_cidreq().'&amp;action=add&type=pagebreak&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/page_end.gif" /><br />'.get_lang('Pagebreak').'</a></div>';
  105. echo '</div>';
  106. echo '<div style="clear:both;"></div>';
  107. // Displaying the table header with all the questions
  108. echo '<table class="data_table">';
  109. echo ' <tr class="row_odd">';
  110. echo ' <th width="15">'.get_lang('QuestionNumber').'</th>';
  111. echo ' <th>'.get_lang('Title').'</th>';
  112. echo ' <th>'.get_lang('Type').'</th>';
  113. echo ' <th>'.get_lang('NumberOfOptions').'</th>';
  114. echo ' <th width="100">'.get_lang('Modify').'</th>';
  115. echo ' </tr>';
  116. // Displaying the table contents with all the questions
  117. $question_counter = 1;
  118. $sql = "SELECT survey_question.*, count(survey_question_option.question_option_id) as number_of_options
  119. FROM $table_survey_question survey_question
  120. LEFT JOIN $table_survey_question_option survey_question_option
  121. ON survey_question.question_id = survey_question_option.question_id
  122. WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  123. GROUP BY survey_question.question_id
  124. ORDER BY survey_question.sort ASC";
  125. $result = api_sql_query($sql, __FILE__, __LINE__);
  126. $question_counter_max = mysql_num_rows($result);
  127. while ($row = mysql_fetch_assoc($result))
  128. {
  129. echo '<tr>';
  130. echo ' <td>'.$question_counter.'</td>';
  131. echo ' <td>';
  132. if (strlen($row['survey_question']) > 100)
  133. {
  134. echo substr(strip_tags($row['survey_question']),0, 100).' ... ';
  135. }
  136. else
  137. {
  138. echo $row['survey_question'];
  139. }
  140. echo '</td>';
  141. echo ' <td>'.get_lang(ucfirst($row['type'])).'</td>';
  142. echo ' <td>'.$row['number_of_options'].'</td>';
  143. echo ' <td>';
  144. echo ' <a href="question.php?'.api_get_cidreq().'&amp;action=edit&amp;type='.$row['type'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  145. echo ' <a href="survey.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurveyQuestion").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  146. if ($question_counter > 1)
  147. {
  148. echo ' <a href="survey.php?'.api_get_cidreq().'&amp;action=moveup&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('up.gif', get_lang('MoveUp')).'</a>';
  149. }
  150. if ($question_counter < $question_counter_max)
  151. {
  152. echo ' <a href="survey.php?'.api_get_cidreq().'&amp;action=movedown&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('down.gif', get_lang('MoveDown')).'</a>';
  153. }
  154. echo ' </td>';
  155. $question_counter++;
  156. }
  157. echo '</table>';
  158. // Footer
  159. Display :: display_footer();
  160. ?>