survey_list.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php // $Id: survey_list.php 21933 2009-07-09 06:08:22Z ivantcholakov $
  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 21933 2009-07-09 06:08:22Z ivantcholakov $
  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. if (!isset ($_GET['cidReq'])){
  29. $_GET['cidReq']='none'; // prevent sql errors
  30. $cidReset = true;
  31. }
  32. // including the global dokeos file
  33. require_once '../inc/global.inc.php';
  34. $this_section=SECTION_COURSES;
  35. // including additional libraries
  36. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  37. require_once('survey.lib.php');
  38. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  39. //Tracking
  40. event_access_tool(TOOL_SURVEY);
  41. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  42. if (!api_is_allowed_to_edit(false,true)) //coach can see this
  43. {
  44. Display :: display_header(get_lang('SurveyList'));
  45. SurveyUtil::survey_list_user($_user['user_id']);
  46. Display :: display_footer();
  47. exit;
  48. }
  49. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  50. // Database table definitions
  51. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  52. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  53. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  54. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  55. // language variables
  56. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  57. {
  58. $interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  59. $tool_name = get_lang('SearchASurvey');
  60. }
  61. else
  62. {
  63. $tool_name = get_lang('SurveyList');
  64. }
  65. // Header
  66. Display :: display_header($tool_name,'Survey');
  67. //api_display_tool_title($tool_name);
  68. // Tool introduction
  69. Display::display_introduction_section('survey', 'left');
  70. // Action handling: searching
  71. if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
  72. {
  73. SurveyUtil::display_survey_search_form();
  74. }
  75. // Action handling: deleting a survey
  76. if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
  77. {
  78. // getting the information of the survey (used for when the survey is shared)
  79. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  80. if(api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id'])
  81. { // the coach can't delete a survey not belonging to his session
  82. api_not_allowed();
  83. exit;
  84. }
  85. // if the survey is shared => also delete the shared content
  86. if (is_numeric($survey_data['survey_share']))
  87. {
  88. survey_manager::delete_survey($survey_data['survey_share'], true);
  89. }
  90. $return = survey_manager :: delete_survey($_GET['survey_id']);
  91. if ($return)
  92. {
  93. Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
  94. }
  95. else
  96. {
  97. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  98. }
  99. }
  100. if(isset($_GET['action']) && $_GET['action'] == 'empty')
  101. {
  102. $mysession = api_get_session_id();
  103. if ( $mysession != 0 ) {
  104. if(!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id'])))) {
  105. // the coach can't empty a survey not belonging to his session
  106. api_not_allowed();
  107. exit;
  108. }
  109. } else {
  110. if (!(api_is_course_admin() || api_is_platform_admin())) {
  111. api_not_allowed();
  112. exit;
  113. }
  114. }
  115. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  116. if ($return)
  117. {
  118. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  119. }
  120. else
  121. {
  122. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  123. }
  124. }
  125. // Action handling: performing the same action on multiple surveys
  126. if ($_POST['action'])
  127. {
  128. if (is_array($_POST['id']))
  129. {
  130. foreach ($_POST['id'] as $key=>$value)
  131. {
  132. // getting the information of the survey (used for when the survey is shared)
  133. $survey_data = survey_manager::get_survey($value);
  134. // if the survey is shared => also delete the shared content
  135. if (is_numeric($survey_data['survey_share']))
  136. {
  137. survey_manager::delete_survey($survey_data['survey_share'], true);
  138. }
  139. // delete the actual survey
  140. survey_manager::delete_survey($value);
  141. }
  142. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  143. }
  144. else
  145. {
  146. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  147. }
  148. }
  149. echo $extended_rights_for_coachs;
  150. echo '<div class="actions">';
  151. if (!api_is_course_coach() || $extend_rights_for_coachs=='true')
  152. {
  153. // Action links
  154. echo Display::return_icon('surveyadd.gif', get_lang('CreateNewSurvey')) . '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.get_lang('CreateNewSurvey').'</a> ';
  155. }
  156. //echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> ';
  157. echo Display::return_icon('search.gif', get_lang('Search')) . '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.get_lang('Search').'</a>';
  158. echo '</div>';
  159. //Load main content
  160. if (api_is_course_coach() && $extend_rights_for_coachs=='false')
  161. SurveyUtil::display_survey_list_for_coach();
  162. else
  163. SurveyUtil::display_survey_list();
  164. // Footer
  165. Display :: display_footer();
  166. /* Bypass functions to make direct use from SortableTable possible */
  167. function get_number_of_surveys()
  168. {
  169. return SurveyUtil::get_number_of_surveys();
  170. }
  171. function get_survey_data($from, $number_of_items, $column, $direction)
  172. {
  173. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  174. }
  175. function modify_filter($survey_id)
  176. {
  177. return SurveyUtil::modify_filter($survey_id);
  178. }
  179. function get_number_of_surveys_for_coach()
  180. {
  181. return SurveyUtil::get_number_of_surveys_for_coach();
  182. }
  183. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  184. {
  185. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  186. }
  187. function modify_filter_for_coach($survey_id)
  188. {
  189. return SurveyUtil::modify_filter_for_coach($survey_id);
  190. }
  191. function anonymous_filter($anonymous)
  192. {
  193. return SurveyUtil::anonymous_filter($anonymous);
  194. }