survey_list.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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']) : null;
  24. // Tracking
  25. Event::event_access_tool(TOOL_SURVEY);
  26. /** @todo
  27. * This has to be moved to a more appropriate place (after the display_header
  28. * of the code)
  29. */
  30. $courseInfo = api_get_course_info();
  31. $sessionId = api_get_session_id();
  32. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  33. $currentUserId,
  34. $courseInfo
  35. );
  36. if ($isDrhOfCourse) {
  37. Display::display_header(get_lang('SurveyList'));
  38. SurveyUtil::displaySurveyListForDrh();
  39. Display::display_footer();
  40. exit;
  41. }
  42. if (!api_is_allowed_to_edit(false, true)) {
  43. // Coach can see this
  44. Display::display_header(get_lang('SurveyList'));
  45. SurveyUtil::getSurveyList($currentUserId);
  46. Display::display_footer();
  47. exit;
  48. }
  49. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  50. // Database table definitions
  51. $table_survey = Database::get_course_table(TABLE_SURVEY);
  52. $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
  53. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  54. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  55. // Language variables
  56. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  57. $interbreadcrumb[] = [
  58. 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php',
  59. 'name' => get_lang('SurveyList'),
  60. ];
  61. $tool_name = get_lang('SearchASurvey');
  62. } else {
  63. $tool_name = get_lang('SurveyList');
  64. }
  65. $listUrl = api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq();
  66. $surveyId = isset($_GET['survey_id']) ? $_GET['survey_id'] : 0;
  67. switch ($action) {
  68. case 'remove_multiplicate':
  69. $surveyData = SurveyManager::get_survey($surveyId);
  70. if (!empty($surveyData)) {
  71. SurveyManager::removeMultiplicateQuestions($surveyData);
  72. Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
  73. }
  74. header('Location: '.$listUrl);
  75. exit;
  76. break;
  77. case 'multiplicate':
  78. $surveyData = SurveyManager::get_survey($surveyId);
  79. if (!empty($surveyData)) {
  80. SurveyManager::multiplicateQuestions($surveyData);
  81. Display::cleanFlashMessages();
  82. Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
  83. }
  84. header('Location: '.$listUrl);
  85. exit;
  86. break;
  87. case 'copy_survey':
  88. if (!empty($surveyId) && api_is_allowed_to_edit()) {
  89. SurveyManager::copy_survey($surveyId);
  90. Display::addFlash(Display::return_message(get_lang('SurveyCopied'), 'confirmation', false));
  91. header('Location: '.$listUrl);
  92. exit;
  93. }
  94. break;
  95. case 'delete':
  96. if (!empty($surveyId)) {
  97. // Getting the information of the survey (used for when the survey is shared)
  98. $survey_data = SurveyManager::get_survey($surveyId);
  99. if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
  100. // The coach can't delete a survey not belonging to his session
  101. api_not_allowed();
  102. }
  103. // If the survey is shared => also delete the shared content
  104. if (isset($survey_data['survey_share']) &&
  105. is_numeric($survey_data['survey_share'])
  106. ) {
  107. SurveyManager::delete_survey($survey_data['survey_share'], true);
  108. }
  109. $return = SurveyManager::delete_survey($surveyId);
  110. if ($return) {
  111. Display::addFlash(Display::return_message(get_lang('SurveyDeleted'), 'confirmation', false));
  112. } else {
  113. Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
  114. }
  115. header('Location: '.$listUrl);
  116. exit;
  117. }
  118. break;
  119. case 'empty':
  120. $mysession = api_get_session_id();
  121. if ($mysession != 0) {
  122. if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
  123. api_is_element_in_the_session(TOOL_SURVEY, $surveyId))) {
  124. // The coach can't empty a survey not belonging to his session
  125. api_not_allowed();
  126. }
  127. } else {
  128. if (!(api_is_course_admin() || api_is_platform_admin())) {
  129. api_not_allowed();
  130. }
  131. }
  132. $return = SurveyManager::empty_survey($surveyId);
  133. if ($return) {
  134. Display::addFlash(Display::return_message(get_lang('SurveyEmptied'), 'confirmation', false));
  135. } else {
  136. Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
  137. }
  138. header('Location: '.$listUrl);
  139. exit;
  140. break;
  141. }
  142. // Header
  143. Display::display_header($tool_name, 'Survey');
  144. // Tool introduction
  145. Display::display_introduction_section('survey', 'left');
  146. // Action handling: searching
  147. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  148. SurveyUtil::display_survey_search_form();
  149. }
  150. // Action handling: performing the same action on multiple surveys
  151. if (isset($_POST['action']) && $_POST['action']) {
  152. if (is_array($_POST['id'])) {
  153. foreach ($_POST['id'] as $key => &$value) {
  154. // getting the information of the survey (used for when the survey is shared)
  155. $survey_data = SurveyManager::get_survey($value);
  156. // if the survey is shared => also delete the shared content
  157. if (is_numeric($survey_data['survey_share'])) {
  158. SurveyManager::delete_survey($survey_data['survey_share'], true);
  159. }
  160. // delete the actual survey
  161. SurveyManager::delete_survey($value);
  162. }
  163. echo Display::return_message(get_lang('SurveysDeleted'), 'confirmation', false);
  164. } else {
  165. echo Display::return_message(get_lang('NoSurveysSelected'), 'error', false);
  166. }
  167. }
  168. echo '<div class="actions">';
  169. if (!api_is_session_general_coach() || $extend_rights_for_coachs == 'true') {
  170. // Action links
  171. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.
  172. Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM).'</a> ';
  173. $url = api_get_path(WEB_CODE_PATH).'survey/create_meeting.php?'.api_get_cidreq();
  174. echo Display::url(Display::return_icon('add.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM), $url);
  175. }
  176. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.
  177. Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM).'</a>';
  178. echo '</div>';
  179. // Load main content
  180. if (api_is_session_general_coach() && $extend_rights_for_coachs == 'false') {
  181. SurveyUtil::display_survey_list_for_coach();
  182. } else {
  183. SurveyUtil::display_survey_list();
  184. }
  185. Display::display_footer();
  186. /* Bypass functions to make direct use from SortableTable possible */
  187. function get_number_of_surveys()
  188. {
  189. return SurveyUtil::get_number_of_surveys();
  190. }
  191. function get_survey_data($from, $number_of_items, $column, $direction)
  192. {
  193. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  194. }
  195. function modify_filter($survey_id)
  196. {
  197. return SurveyUtil::modify_filter($survey_id);
  198. }
  199. function modify_filter_drh($survey_id)
  200. {
  201. return SurveyUtil::modify_filter($survey_id, true);
  202. }
  203. function get_number_of_surveys_for_coach()
  204. {
  205. return SurveyUtil::get_number_of_surveys_for_coach();
  206. }
  207. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  208. {
  209. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  210. }
  211. function modify_filter_for_coach($survey_id)
  212. {
  213. return SurveyUtil::modify_filter_for_coach($survey_id);
  214. }
  215. function anonymous_filter($anonymous)
  216. {
  217. return SurveyUtil::anonymous_filter($anonymous);
  218. }
  219. function get_survey_data_drh($from, $number_of_items, $column, $direction)
  220. {
  221. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction, true);
  222. }