survey_list.php 6.6 KB

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