survey_list.php 9.0 KB

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