survey_list.php 7.4 KB

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