survey_list.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 __DIR__.'/../inc/global.inc.php';
  18. $this_section = SECTION_COURSES;
  19. $current_course_tool = TOOL_SURVEY;
  20. $currentUserId = api_get_user_id();
  21. api_protect_course_script(true);
  22. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  23. // Tracking
  24. Event::event_access_tool(TOOL_SURVEY);
  25. /** @todo
  26. * This has to be moved to a more appropriate place (after the display_header
  27. * of the code)
  28. */
  29. $courseInfo = api_get_course_info();
  30. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  31. $currentUserId,
  32. $courseInfo
  33. );
  34. if ($isDrhOfCourse) {
  35. Display::display_header(get_lang('SurveyList'));
  36. SurveyUtil::displaySurveyListForDrh();
  37. Display::display_footer();
  38. exit;
  39. }
  40. if (!api_is_allowed_to_edit(false, true)) {
  41. // Coach can see this
  42. Display::display_header(get_lang('SurveyList'));
  43. SurveyUtil::getSurveyList($currentUserId);
  44. Display::display_footer();
  45. exit;
  46. }
  47. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  48. // Database table definitions
  49. $table_survey = Database::get_course_table(TABLE_SURVEY);
  50. $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
  51. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  52. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  53. // Language variables
  54. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  55. $interbreadcrumb[] = array(
  56. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
  57. 'name' => get_lang('SurveyList')
  58. );
  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. SurveyManager::copy_survey($_GET['survey_id']);
  66. $message = get_lang('SurveyCopied');
  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. $sessionId = api_get_session_id();
  80. // Action handling: deleting a survey
  81. if ($action === 'delete' && isset($_GET['survey_id'])) {
  82. // Getting the information of the survey (used for when the survey is shared)
  83. $survey_data = SurveyManager::get_survey($_GET['survey_id']);
  84. if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
  85. // The coach can't delete a survey not belonging to his session
  86. api_not_allowed();
  87. exit;
  88. }
  89. // If the survey is shared => also delete the shared content
  90. if (isset($survey_data['survey_share']) &&
  91. is_numeric($survey_data['survey_share'])
  92. ) {
  93. SurveyManager::delete_survey($survey_data['survey_share'], true);
  94. }
  95. $return = SurveyManager::delete_survey($_GET['survey_id']);
  96. if ($return) {
  97. echo Display::return_message(get_lang('SurveyDeleted'), 'confirmation', false);
  98. } else {
  99. echo Display::return_message(get_lang('ErrorOccurred'), 'error', false);
  100. }
  101. }
  102. if ($action == 'empty') {
  103. $mysession = api_get_session_id();
  104. if ($mysession != 0) {
  105. if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
  106. api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
  107. // The coach can't empty a survey not belonging to his session
  108. api_not_allowed();
  109. exit;
  110. }
  111. } else {
  112. if (!(api_is_course_admin() || api_is_platform_admin())) {
  113. api_not_allowed();
  114. exit;
  115. }
  116. }
  117. $return = SurveyManager::empty_survey(intval($_GET['survey_id']));
  118. if ($return) {
  119. echo Display::return_message(get_lang('SurveyEmptied'), 'confirmation', false);
  120. } else {
  121. echo Display::return_message(get_lang('ErrorOccurred'), 'error', false);
  122. }
  123. }
  124. // Action handling: performing the same action on multiple surveys
  125. if (isset($_POST['action']) && $_POST['action']) {
  126. if (is_array($_POST['id'])) {
  127. foreach ($_POST['id'] as $key => & $value) {
  128. // getting the information of the survey (used for when the survey is shared)
  129. $survey_data = SurveyManager::get_survey($value);
  130. // if the survey is shared => also delete the shared content
  131. if (is_numeric($survey_data['survey_share'])) {
  132. SurveyManager::delete_survey($survey_data['survey_share'], true);
  133. }
  134. // delete the actual survey
  135. SurveyManager::delete_survey($value);
  136. }
  137. echo Display::return_message(get_lang('SurveysDeleted'), 'confirmation', false);
  138. } else {
  139. echo Display::return_message(get_lang('NoSurveysSelected'), 'error', false);
  140. }
  141. }
  142. echo '<div class="actions">';
  143. if (!api_is_session_general_coach() || $extend_rights_for_coachs == 'true') {
  144. // Action links
  145. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.
  146. Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM).'</a> ';
  147. }
  148. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.
  149. Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM).'</a>';
  150. echo '</div>';
  151. // Load main content
  152. if (api_is_session_general_coach() && $extend_rights_for_coachs == 'false') {
  153. SurveyUtil::display_survey_list_for_coach();
  154. } else {
  155. SurveyUtil::display_survey_list();
  156. }
  157. Display::display_footer();
  158. /* Bypass functions to make direct use from SortableTable possible */
  159. function get_number_of_surveys()
  160. {
  161. return SurveyUtil::get_number_of_surveys();
  162. }
  163. function get_survey_data($from, $number_of_items, $column, $direction)
  164. {
  165. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  166. }
  167. function modify_filter($survey_id)
  168. {
  169. return SurveyUtil::modify_filter($survey_id);
  170. }
  171. function modify_filter_drh($survey_id)
  172. {
  173. return SurveyUtil::modify_filter($survey_id, true);
  174. }
  175. function get_number_of_surveys_for_coach()
  176. {
  177. return SurveyUtil::get_number_of_surveys_for_coach();
  178. }
  179. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  180. {
  181. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  182. }
  183. function modify_filter_for_coach($survey_id)
  184. {
  185. return SurveyUtil::modify_filter_for_coach($survey_id);
  186. }
  187. function anonymous_filter($anonymous)
  188. {
  189. return SurveyUtil::anonymous_filter($anonymous);
  190. }
  191. function get_survey_data_drh($from, $number_of_items, $column, $direction)
  192. {
  193. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction, true);
  194. }