survey_list.php 8.8 KB

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