survey_list.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.survey
  5. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  6. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  7. * @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
  8. * @version $Id: survey_list.php 21933 2009-07-09 06:08:22Z ivantcholakov $
  9. *
  10. * @todo use quickforms for the forms
  11. */
  12. // Language file that needs to be included
  13. $language_file = 'survey';
  14. if (!isset($_GET['cidReq'])) {
  15. $_GET['cidReq'] = 'none'; // Prevent sql errors
  16. $cidReset = true;
  17. }
  18. // Including the global initialization file
  19. require_once '../inc/global.inc.php';
  20. $this_section = SECTION_COURSES;
  21. $current_course_tool = TOOL_SURVEY;
  22. api_protect_course_script(true);
  23. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  24. // Including additional libraries
  25. require_once 'survey.lib.php';
  26. // Tracking
  27. event_access_tool(TOOL_SURVEY);
  28. /** @todo
  29. * This has to be moved to a more appropriate place (after the display_header
  30. * of the code)
  31. */
  32. $courseInfo = api_get_course_info();
  33. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  34. api_get_user_id(),
  35. $courseInfo
  36. );
  37. if ($isDrhOfCourse) {
  38. Display::display_header(get_lang('SurveyList'));
  39. SurveyUtil::displaySurveyListForDrh();
  40. Display::display_footer();
  41. exit;
  42. }
  43. if (!api_is_allowed_to_edit(false, true)) {
  44. // Coach can see this
  45. Display::display_header(get_lang('SurveyList'));
  46. SurveyUtil::survey_list_user(api_get_user_id());
  47. Display::display_footer();
  48. exit;
  49. }
  50. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  51. // Database table definitions
  52. $table_survey = Database:: get_course_table(TABLE_SURVEY);
  53. $table_survey_question = Database:: get_course_table(TABLE_SURVEY_QUESTION);
  54. $table_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  55. $table_user = Database:: get_main_table(TABLE_MAIN_USER);
  56. // Language variables
  57. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  58. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
  59. $tool_name = get_lang('SearchASurvey');
  60. } else {
  61. $tool_name = get_lang('SurveyList');
  62. }
  63. if ($action == 'copy_survey') {
  64. if (api_is_allowed_to_edit()) {
  65. survey_manager::copy_survey($_GET['survey_id']);
  66. $message = get_lang('Copied');
  67. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq());
  68. exit;
  69. }
  70. }
  71. // Header
  72. Display::display_header($tool_name, 'Survey');
  73. // Tool introduction
  74. Display::display_introduction_section('survey', 'left');
  75. // Action handling: searching
  76. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  77. SurveyUtil::display_survey_search_form();
  78. }
  79. // Action handling: deleting a survey
  80. if ($action == 'delete' && isset($_GET['survey_id'])) {
  81. // Getting the information of the survey (used for when the survey is shared)
  82. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  83. if (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
  84. // The coach can't delete a survey not belonging to his session
  85. api_not_allowed();
  86. exit;
  87. }
  88. // If the survey is shared => also delete the shared content
  89. if (is_numeric($survey_data['survey_share'])) {
  90. survey_manager::delete_survey($survey_data['survey_share'], true);
  91. }
  92. $return = survey_manager::delete_survey($_GET['survey_id']);
  93. if ($return) {
  94. Display::display_confirmation_message(get_lang('SurveyDeleted'), false);
  95. } else {
  96. Display::display_error_message(get_lang('ErrorOccurred'), false);
  97. }
  98. }
  99. if ($action == 'empty') {
  100. $mysession = api_get_session_id();
  101. if ($mysession != 0) {
  102. if (!((api_is_course_coach() || api_is_platform_admin()) &&
  103. api_is_element_in_the_session(TOOL_SURVEY, $_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. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  117. } else {
  118. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  119. }
  120. }
  121. // Action handling: performing the same action on multiple surveys
  122. if (isset($_POST['action']) && $_POST['action']) {
  123. if (is_array($_POST['id'])) {
  124. foreach ($_POST['id'] as $key => & $value) {
  125. // getting the information of the survey (used for when the survey is shared)
  126. $survey_data = survey_manager::get_survey($value);
  127. // if the survey is shared => also delete the shared content
  128. if (is_numeric($survey_data['survey_share'])) {
  129. survey_manager::delete_survey($survey_data['survey_share'], true);
  130. }
  131. // delete the actual survey
  132. survey_manager::delete_survey($value);
  133. }
  134. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  135. } else {
  136. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  137. }
  138. }
  139. echo '<div class="actions">';
  140. if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
  141. // Action links
  142. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.
  143. Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'),'',ICON_SIZE_MEDIUM).'</a> ';
  144. }
  145. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.
  146. Display::return_icon('search.png', get_lang('Search'),'',ICON_SIZE_MEDIUM).'</a>';
  147. echo '</div>';
  148. // Load main content
  149. if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
  150. SurveyUtil::display_survey_list_for_coach();
  151. } else {
  152. SurveyUtil::display_survey_list();
  153. }
  154. // Footer
  155. Display :: display_footer();
  156. /* Bypass functions to make direct use from SortableTable possible */
  157. function get_number_of_surveys()
  158. {
  159. return SurveyUtil::get_number_of_surveys();
  160. }
  161. function get_survey_data($from, $number_of_items, $column, $direction)
  162. {
  163. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  164. }
  165. function modify_filter($survey_id)
  166. {
  167. return SurveyUtil::modify_filter($survey_id);
  168. }
  169. function modify_filter_drh($survey_id)
  170. {
  171. return SurveyUtil::modify_filter($survey_id, true);
  172. }
  173. function get_number_of_surveys_for_coach()
  174. {
  175. return SurveyUtil::get_number_of_surveys_for_coach();
  176. }
  177. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  178. {
  179. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  180. }
  181. function modify_filter_for_coach($survey_id)
  182. {
  183. return SurveyUtil::modify_filter_for_coach($survey_id);
  184. }
  185. function anonymous_filter($anonymous)
  186. {
  187. return SurveyUtil::anonymous_filter($anonymous);
  188. }
  189. function get_survey_data_drh($from, $number_of_items, $column, $direction)
  190. {
  191. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction, true);
  192. }