survey_list.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  5. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  6. * @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
  7. *
  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. require_once __DIR__.'/../inc/global.inc.php';
  17. $this_section = SECTION_COURSES;
  18. $current_course_tool = TOOL_SURVEY;
  19. $currentUserId = api_get_user_id();
  20. api_protect_course_script(true);
  21. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
  22. // Tracking
  23. Event::event_access_tool(TOOL_SURVEY);
  24. $logInfo = [
  25. 'tool' => TOOL_SURVEY,
  26. 'tool_id' => 0,
  27. 'tool_id_detail' => 0,
  28. ];
  29. Event::registerLog($logInfo);
  30. /** @todo
  31. * This has to be moved to a more appropriate place (after the display_header
  32. * of the code)
  33. */
  34. $courseInfo = api_get_course_info();
  35. $sessionId = api_get_session_id();
  36. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  37. $currentUserId,
  38. $courseInfo
  39. );
  40. if ($isDrhOfCourse) {
  41. Display::display_header(get_lang('Survey list'));
  42. // Tool introduction
  43. Display::display_introduction_section('survey', 'left');
  44. SurveyUtil::displaySurveyListForDrh();
  45. Display::display_footer();
  46. exit;
  47. }
  48. if (!api_is_allowed_to_edit(false, true)) {
  49. // Coach can see this
  50. Display::display_header(get_lang('Survey list'));
  51. // Tool introduction
  52. Display::display_introduction_section('survey', 'left');
  53. SurveyUtil::getSurveyList($currentUserId);
  54. Display::display_footer();
  55. exit;
  56. }
  57. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  58. // Database table definitions
  59. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  60. $interbreadcrumb[] = [
  61. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
  62. 'name' => get_lang('Survey list'),
  63. ];
  64. $tool_name = get_lang('Search a survey');
  65. } else {
  66. $tool_name = get_lang('Survey list');
  67. }
  68. $listUrl = api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq();
  69. $surveyId = isset($_GET['survey_id']) ? $_GET['survey_id'] : 0;
  70. switch ($action) {
  71. case 'remove_multiplicate':
  72. $surveyData = SurveyManager::get_survey($surveyId);
  73. if (!empty($surveyData)) {
  74. SurveyManager::removeMultiplicateQuestions($surveyData);
  75. Display::addFlash(Display::return_message(get_lang('Update successful'), 'confirmation', false));
  76. }
  77. header('Location: '.$listUrl);
  78. exit;
  79. break;
  80. case 'multiplicate':
  81. $surveyData = SurveyManager::get_survey($surveyId);
  82. if (!empty($surveyData)) {
  83. SurveyManager::multiplicateQuestions($surveyData);
  84. Display::cleanFlashMessages();
  85. Display::addFlash(Display::return_message(get_lang('Update successful'), 'confirmation', false));
  86. }
  87. header('Location: '.$listUrl);
  88. exit;
  89. break;
  90. case 'copy_survey':
  91. if (!empty($surveyId) && api_is_allowed_to_edit()) {
  92. SurveyManager::copy_survey($surveyId);
  93. Display::addFlash(Display::return_message(get_lang('Survey copied'), 'confirmation', false));
  94. header('Location: '.$listUrl);
  95. exit;
  96. }
  97. break;
  98. case 'delete':
  99. if (!empty($surveyId)) {
  100. // Getting the information of the survey (used for when the survey is shared)
  101. $survey_data = SurveyManager::get_survey($surveyId);
  102. if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
  103. // The coach can't delete a survey not belonging to his session
  104. api_not_allowed();
  105. }
  106. // If the survey is shared => also delete the shared content
  107. if (isset($survey_data['survey_share']) &&
  108. is_numeric($survey_data['survey_share'])
  109. ) {
  110. SurveyManager::delete_survey($survey_data['survey_share'], true);
  111. }
  112. $return = SurveyManager::delete_survey($surveyId);
  113. if ($return) {
  114. Display::addFlash(Display::return_message(get_lang('The survey has been deleted.'), 'confirmation', false));
  115. } else {
  116. Display::addFlash(Display::return_message(get_lang('An error occurred.'), 'error', false));
  117. }
  118. header('Location: '.$listUrl);
  119. exit;
  120. }
  121. break;
  122. case 'empty':
  123. $mysession = api_get_session_id();
  124. if ($mysession != 0) {
  125. if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
  126. api_is_element_in_the_session(TOOL_SURVEY, $surveyId))) {
  127. // The coach can't empty a survey not belonging to his session
  128. api_not_allowed();
  129. }
  130. } else {
  131. if (!(api_is_course_admin() || api_is_platform_admin())) {
  132. api_not_allowed();
  133. }
  134. }
  135. $return = SurveyManager::empty_survey($surveyId);
  136. if ($return) {
  137. Display::addFlash(Display::return_message(get_lang('Answers to survey successfully deleted'), 'confirmation', false));
  138. } else {
  139. Display::addFlash(Display::return_message(get_lang('An error occurred.'), 'error', false));
  140. }
  141. header('Location: '.$listUrl);
  142. exit;
  143. break;
  144. }
  145. Display::display_header($tool_name, 'Survey');
  146. // Tool introduction
  147. Display::display_introduction_section('survey', 'left');
  148. // Action handling: searching
  149. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  150. SurveyUtil::display_survey_search_form();
  151. }
  152. // Action handling: performing the same action on multiple surveys
  153. if (isset($_POST['action']) && $_POST['action']) {
  154. if (is_array($_POST['id'])) {
  155. foreach ($_POST['id'] as $key => &$value) {
  156. // getting the information of the survey (used for when the survey is shared)
  157. $survey_data = SurveyManager::get_survey($value);
  158. // if the survey is shared => also delete the shared content
  159. if (is_numeric($survey_data['survey_share'])) {
  160. SurveyManager::delete_survey($survey_data['survey_share'], true);
  161. }
  162. // delete the actual survey
  163. SurveyManager::delete_survey($value);
  164. }
  165. echo Display::return_message(get_lang('Surveys deleted'), 'confirmation', false);
  166. } else {
  167. echo Display::return_message(get_lang('No surveys have been selected.'), 'error', false);
  168. }
  169. }
  170. echo '<div class="actions">';
  171. if (!api_is_session_general_coach() || $extend_rights_for_coachs == 'true') {
  172. // Action links
  173. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.
  174. Display::return_icon('new_survey.png', get_lang('Create survey'), '', ICON_SIZE_MEDIUM).'</a> ';
  175. $url = api_get_path(WEB_CODE_PATH).'survey/create_meeting.php?'.api_get_cidreq();
  176. echo Display::url(Display::return_icon('add_doodle.png', get_lang('Create surveyDoodle'), '', ICON_SIZE_MEDIUM), $url);
  177. }
  178. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.
  179. Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM).'</a>';
  180. echo '</div>';
  181. // Load main content
  182. if (api_is_session_general_coach() && $extend_rights_for_coachs == 'false') {
  183. SurveyUtil::display_survey_list_for_coach();
  184. } else {
  185. SurveyUtil::display_survey_list();
  186. }
  187. Display::display_footer();
  188. /* Bypass functions to make direct use from SortableTable possible */
  189. function get_number_of_surveys()
  190. {
  191. return SurveyUtil::get_number_of_surveys();
  192. }
  193. function get_survey_data($from, $number_of_items, $column, $direction)
  194. {
  195. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  196. }
  197. function modify_filter($survey_id)
  198. {
  199. return SurveyUtil::modify_filter($survey_id);
  200. }
  201. function modify_filter_drh($survey_id)
  202. {
  203. return SurveyUtil::modify_filter($survey_id, true);
  204. }
  205. function get_number_of_surveys_for_coach()
  206. {
  207. return SurveyUtil::get_number_of_surveys_for_coach();
  208. }
  209. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  210. {
  211. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  212. }
  213. function modify_filter_for_coach($survey_id)
  214. {
  215. return SurveyUtil::modify_filter_for_coach($survey_id);
  216. }
  217. function anonymous_filter($anonymous)
  218. {
  219. return SurveyUtil::anonymous_filter($anonymous);
  220. }
  221. function get_survey_data_drh($from, $number_of_items, $column, $direction)
  222. {
  223. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction, true);
  224. }