survey_list.php 7.0 KB

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