survey_list.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. if (!isset($_GET['cidReq'])) {
  13. $_GET['cidReq'] = 'none'; // Prevent sql errors
  14. $cidReset = true;
  15. }
  16. // Including the global initialization file
  17. require_once '../inc/global.inc.php';
  18. $this_section = SECTION_COURSES;
  19. $current_course_tool = TOOL_SURVEY;
  20. api_protect_course_script(true);
  21. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  22. // Tracking
  23. Event::event_access_tool(TOOL_SURVEY);
  24. /** @todo
  25. * This has to be moved to a more appropriate place (after the display_header
  26. * of the code)
  27. */
  28. $courseInfo = api_get_course_info();
  29. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  30. api_get_user_id(),
  31. $courseInfo
  32. );
  33. if ($isDrhOfCourse) {
  34. Display::display_header(get_lang('SurveyList'));
  35. SurveyUtil::displaySurveyListForDrh();
  36. Display::display_footer();
  37. exit;
  38. }
  39. if (!api_is_allowed_to_edit(false, true)) {
  40. // Coach can see this
  41. Display::display_header(get_lang('SurveyList'));
  42. SurveyUtil::survey_list_user(api_get_user_id());
  43. Display::display_footer();
  44. exit;
  45. }
  46. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  47. // Database table definitions
  48. $table_survey = Database:: get_course_table(TABLE_SURVEY);
  49. $table_survey_question = Database:: get_course_table(TABLE_SURVEY_QUESTION);
  50. $table_course = Database:: get_main_table(TABLE_MAIN_COURSE);
  51. $table_user = Database:: get_main_table(TABLE_MAIN_USER);
  52. // Language variables
  53. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  54. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
  55. $tool_name = get_lang('SearchASurvey');
  56. } else {
  57. $tool_name = get_lang('SurveyList');
  58. }
  59. if ($action == 'copy_survey') {
  60. if (api_is_allowed_to_edit()) {
  61. survey_manager::copy_survey($_GET['survey_id']);
  62. $message = get_lang('Copied');
  63. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq());
  64. exit;
  65. }
  66. }
  67. // Header
  68. Display::display_header($tool_name, 'Survey');
  69. // Tool introduction
  70. Display::display_introduction_section('survey', 'left');
  71. // Action handling: searching
  72. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  73. SurveyUtil::display_survey_search_form();
  74. }
  75. // Action handling: deleting a survey
  76. if ($action == 'delete' && isset($_GET['survey_id'])) {
  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. survey_manager::delete_survey($survey_data['survey_share'], true);
  87. }
  88. $return = survey_manager::delete_survey($_GET['survey_id']);
  89. if ($return) {
  90. Display::display_confirmation_message(get_lang('SurveyDeleted'), false);
  91. } else {
  92. Display::display_error_message(get_lang('ErrorOccurred'), false);
  93. }
  94. }
  95. if ($action == 'empty') {
  96. $mysession = api_get_session_id();
  97. if ($mysession != 0) {
  98. if (!((api_is_course_coach() || api_is_platform_admin()) &&
  99. api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
  100. // The coach can't empty a survey not belonging to his session
  101. api_not_allowed();
  102. exit;
  103. }
  104. } else {
  105. if (!(api_is_course_admin() || api_is_platform_admin())) {
  106. api_not_allowed();
  107. exit;
  108. }
  109. }
  110. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  111. if ($return) {
  112. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  113. } else {
  114. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  115. }
  116. }
  117. // Action handling: performing the same action on multiple surveys
  118. if (isset($_POST['action']) && $_POST['action']) {
  119. if (is_array($_POST['id'])) {
  120. foreach ($_POST['id'] as $key => & $value) {
  121. // getting the information of the survey (used for when the survey is shared)
  122. $survey_data = survey_manager::get_survey($value);
  123. // if the survey is shared => also delete the shared content
  124. if (is_numeric($survey_data['survey_share'])) {
  125. survey_manager::delete_survey($survey_data['survey_share'], true);
  126. }
  127. // delete the actual survey
  128. survey_manager::delete_survey($value);
  129. }
  130. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  131. } else {
  132. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  133. }
  134. }
  135. echo '<div class="actions">';
  136. if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
  137. // Action links
  138. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.
  139. Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'),'',ICON_SIZE_MEDIUM).'</a> ';
  140. }
  141. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.
  142. Display::return_icon('search.png', get_lang('Search'),'',ICON_SIZE_MEDIUM).'</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. }
  150. // Footer
  151. Display :: display_footer();
  152. /* Bypass functions to make direct use from SortableTable possible */
  153. function get_number_of_surveys()
  154. {
  155. return SurveyUtil::get_number_of_surveys();
  156. }
  157. function get_survey_data($from, $number_of_items, $column, $direction)
  158. {
  159. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  160. }
  161. function modify_filter($survey_id)
  162. {
  163. return SurveyUtil::modify_filter($survey_id);
  164. }
  165. function modify_filter_drh($survey_id)
  166. {
  167. return SurveyUtil::modify_filter($survey_id, true);
  168. }
  169. function get_number_of_surveys_for_coach()
  170. {
  171. return SurveyUtil::get_number_of_surveys_for_coach();
  172. }
  173. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  174. {
  175. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  176. }
  177. function modify_filter_for_coach($survey_id)
  178. {
  179. return SurveyUtil::modify_filter_for_coach($survey_id);
  180. }
  181. function anonymous_filter($anonymous)
  182. {
  183. return SurveyUtil::anonymous_filter($anonymous);
  184. }
  185. function get_survey_data_drh($from, $number_of_items, $column, $direction)
  186. {
  187. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction, true);
  188. }