survey_list.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. */
  12. // Language file that needs to be included
  13. $language_file = 'survey';
  14. if (!isset ($_GET['cidReq'])){
  15. $_GET['cidReq'] = 'none'; // Prevent sql errors
  16. $cidReset = true;
  17. }
  18. // Including the global initialization file
  19. //require_once '../inc/global.inc.php';
  20. $this_section = SECTION_COURSES;
  21. $current_course_tool = TOOL_SURVEY;
  22. api_protect_course_script(true);
  23. // Including additional libraries
  24. require_once 'survey.lib.php';
  25. // Tracking
  26. Event::event_access_tool(TOOL_SURVEY);
  27. /** @todo This has to be moved to a more appropriate place (after the display_header of the code)*/
  28. if (!api_is_allowed_to_edit(false, true)) { // Coach can see this
  29. Display::display_header(get_lang('SurveyList'));
  30. SurveyUtil::survey_list_user($_user['user_id']);
  31. Display::display_footer();
  32. exit;
  33. }
  34. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  35. // Database table definitions
  36. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  37. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  38. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  39. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  40. // Language variables
  41. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  42. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
  43. $tool_name = get_lang('SearchASurvey');
  44. } else {
  45. $tool_name = get_lang('SurveyList');
  46. }
  47. // Header
  48. Display::display_header($tool_name, 'Survey');
  49. // Tool introduction
  50. Display::display_introduction_section('survey', 'left');
  51. // Action handling: searching
  52. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  53. SurveyUtil::display_survey_search_form();
  54. }
  55. // Action handling: deleting a survey
  56. if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['survey_id'])) {
  57. // Getting the information of the survey (used for when the survey is shared)
  58. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  59. if (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
  60. // The coach can't delete a survey not belonging to his session
  61. api_not_allowed();
  62. exit;
  63. }
  64. // If the survey is shared => also delete the shared content
  65. if (is_numeric($survey_data['survey_share'])) {
  66. survey_manager::delete_survey($survey_data['survey_share'], true);
  67. }
  68. $return = survey_manager :: delete_survey($_GET['survey_id']);
  69. if ($return) {
  70. Display::display_confirmation_message(get_lang('SurveyDeleted'), false);
  71. } else {
  72. Display::display_error_message(get_lang('ErrorOccurred'), false);
  73. }
  74. }
  75. if (isset($_GET['action']) && $_GET['action'] == 'empty') {
  76. $mysession = api_get_session_id();
  77. if ($mysession != 0) {
  78. if (!((api_is_course_coach() || api_is_platform_admin()) &&
  79. api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
  80. // The coach can't empty a survey not belonging to his session
  81. api_not_allowed();
  82. exit;
  83. }
  84. } else {
  85. if (!(api_is_course_admin() || api_is_platform_admin())) {
  86. api_not_allowed();
  87. exit;
  88. }
  89. }
  90. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  91. if ($return) {
  92. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  93. } else {
  94. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  95. }
  96. }
  97. // Action handling: performing the same action on multiple surveys
  98. if (isset($_POST['action']) && $_POST['action']) {
  99. if (is_array($_POST['id'])) {
  100. foreach ($_POST['id'] as $key => & $value) {
  101. // getting the information of the survey (used for when the survey is shared)
  102. $survey_data = survey_manager::get_survey($value);
  103. // if the survey is shared => also delete the shared content
  104. if (is_numeric($survey_data['survey_share'])) {
  105. survey_manager::delete_survey($survey_data['survey_share'], true);
  106. }
  107. // delete the actual survey
  108. survey_manager::delete_survey($value);
  109. }
  110. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  111. } else {
  112. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  113. }
  114. }
  115. echo '<div class="actions">';
  116. if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
  117. // Action links
  118. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'),'',ICON_SIZE_MEDIUM).'</a> ';
  119. }
  120. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.Display::return_icon('search.png', get_lang('Search'),'',ICON_SIZE_MEDIUM).'</a>';
  121. echo '</div>';
  122. // Load main content
  123. if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
  124. SurveyUtil::display_survey_list_for_coach();
  125. } else {
  126. SurveyUtil::display_survey_list();
  127. }
  128. // Footer
  129. Display :: display_footer();
  130. /* Bypass functions to make direct use from SortableTable possible */
  131. function get_number_of_surveys()
  132. {
  133. return SurveyUtil::get_number_of_surveys();
  134. }
  135. function get_survey_data($from, $number_of_items, $column, $direction)
  136. {
  137. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  138. }
  139. function modify_filter($survey_id)
  140. {
  141. return SurveyUtil::modify_filter($survey_id);
  142. }
  143. function get_number_of_surveys_for_coach()
  144. {
  145. return SurveyUtil::get_number_of_surveys_for_coach();
  146. }
  147. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  148. {
  149. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  150. }
  151. function modify_filter_for_coach($survey_id)
  152. {
  153. return SurveyUtil::modify_filter_for_coach($survey_id);
  154. }
  155. function anonymous_filter($anonymous)
  156. {
  157. return SurveyUtil::anonymous_filter($anonymous);
  158. }