survey_list.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php // $Id: survey_list.php 16739 2008-11-13 15:36:40Z pcool $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue Notre Dame, 152, B-1140 Evere, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * @package dokeos.survey
  19. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  20. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  21. * @author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
  22. * @version $Id: survey_list.php 16739 2008-11-13 15:36:40Z pcool $
  23. *
  24. * @todo use quickforms for the forms
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = 'survey';
  28. // including the global dokeos file
  29. require ('../inc/global.inc.php');
  30. // including additional libraries
  31. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  32. require_once('survey.lib.php');
  33. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  34. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  35. if (!api_is_allowed_to_edit(false,true)) //coach can see this
  36. {
  37. Display :: display_header(get_lang('SurveyList'));
  38. SurveyUtil::survey_list_user($_user['user_id']);
  39. Display :: display_footer();
  40. exit;
  41. }
  42. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  43. // Database table definitions
  44. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  45. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  46. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  47. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  48. // language variables
  49. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  50. {
  51. $interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  52. $tool_name = get_lang('SearchASurvey');
  53. }
  54. else
  55. {
  56. $tool_name = get_lang('SurveyList');
  57. }
  58. // Header
  59. Display :: display_header($tool_name,'Survey');
  60. //api_display_tool_title($tool_name);
  61. // introduction section
  62. Display::display_introduction_section('survey', 'left');
  63. // Action handling: searching
  64. if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
  65. {
  66. SurveyUtil::display_survey_search_form();
  67. }
  68. // Action handling: deleting a survey
  69. if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
  70. {
  71. // getting the information of the survey (used for when the survey is shared)
  72. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  73. if(api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id'])
  74. { // the coach can't delete a survey not belonging to his session
  75. api_not_allowed();
  76. exit;
  77. }
  78. // if the survey is shared => also delete the shared content
  79. if (is_numeric($survey_data['survey_share']))
  80. {
  81. survey_manager::delete_survey($survey_data['survey_share'], true);
  82. }
  83. $return = survey_manager :: delete_survey($_GET['survey_id']);
  84. if ($return)
  85. {
  86. Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
  87. }
  88. else
  89. {
  90. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  91. }
  92. }
  93. if(isset($_GET['action']) && $_GET['action'] == 'empty')
  94. {
  95. if(!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id']))))
  96. {// the coach can't empty a survey not belonging to his session
  97. api_not_allowed();
  98. exit;
  99. }
  100. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  101. if ($return)
  102. {
  103. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  104. }
  105. else
  106. {
  107. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  108. }
  109. }
  110. // Action handling: performing the same action on multiple surveys
  111. if ($_POST['action'])
  112. {
  113. if (is_array($_POST['id']))
  114. {
  115. foreach ($_POST['id'] as $key=>$value)
  116. {
  117. // getting the information of the survey (used for when the survey is shared)
  118. $survey_data = survey_manager::get_survey($value);
  119. // if the survey is shared => also delete the shared content
  120. if (is_numeric($survey_data['survey_share']))
  121. {
  122. survey_manager::delete_survey($survey_data['survey_share'], true);
  123. }
  124. // delete the actual survey
  125. survey_manager::delete_survey($value);
  126. }
  127. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  128. }
  129. else
  130. {
  131. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  132. }
  133. }
  134. echo $extended_rights_for_coachs;
  135. echo '<div class="actions">';
  136. if (!api_is_course_coach() || $extend_rights_for_coachs=='true')
  137. {
  138. // Action links
  139. echo Display::return_icon('surveyadd.gif') . '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.get_lang('CreateNewSurvey').'</a> ';
  140. }
  141. //echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> ';
  142. echo Display::return_icon('search.gif') . '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.get_lang('Search').'</a>';
  143. echo '</div>';
  144. //Load main content
  145. if (api_is_course_coach() && $extend_rights_for_coachs=='false')
  146. SurveyUtil::display_survey_list_for_coach();
  147. else
  148. SurveyUtil::display_survey_list();
  149. // Footer
  150. Display :: display_footer();
  151. /* Bypass functions to make direct use from SortableTable possible */
  152. function get_number_of_surveys()
  153. {
  154. return SurveyUtil::get_number_of_surveys();
  155. }
  156. function get_survey_data($from, $number_of_items, $column, $direction)
  157. {
  158. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  159. }
  160. function modify_filter($survey_id)
  161. {
  162. return SurveyUtil::modify_filter($survey_id);
  163. }
  164. function get_number_of_surveys_for_coach()
  165. {
  166. return SurveyUtil::get_number_of_surveys_for_coach();
  167. }
  168. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  169. {
  170. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  171. }
  172. function modify_filter_for_coach($survey_id)
  173. {
  174. return SurveyUtil::modify_filter_for_coach($survey_id);
  175. }
  176. function anonymous_filter($anonymous)
  177. {
  178. return SurveyUtil::anonymous_filter($anonymous);
  179. }