survey_list.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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_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['action'] == 'search') {
  42. $interbreadcrumb[] = array('url' => '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
  52. $action = isset($_GET['action']) ? $_GET['action'] : null;
  53. switch ($action) {
  54. case 'search' :
  55. SurveyUtil::display_survey_search_form();
  56. break;
  57. case 'delete':
  58. if (isset($_GET['survey_id'])) {
  59. // Getting the information of the survey (used for when the survey is shared)
  60. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  61. if (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
  62. // The coach can't delete a survey not belonging to his session
  63. api_not_allowed();
  64. exit;
  65. }
  66. // If the survey is shared => also delete the shared content
  67. if (is_numeric($survey_data['survey_share'])) {
  68. survey_manager::delete_survey($survey_data['survey_share'], true);
  69. }
  70. $return = survey_manager :: delete_survey($_GET['survey_id']);
  71. if ($return) {
  72. Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
  73. } else {
  74. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  75. }
  76. }
  77. break;
  78. case 'empty':
  79. $mysession = api_get_session_id();
  80. if ($mysession != 0) {
  81. if (!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(
  82. TOOL_SURVEY,
  83. intval($_GET['survey_id'])
  84. ))
  85. ) {
  86. // The coach can't empty a survey not belonging to his session
  87. api_not_allowed();
  88. exit;
  89. }
  90. } else {
  91. if (!(api_is_course_admin() || api_is_platform_admin())) {
  92. api_not_allowed();
  93. exit;
  94. }
  95. }
  96. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  97. if ($return) {
  98. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  99. } else {
  100. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  101. }
  102. break;
  103. case 'copy_survey':
  104. survey_manager::copy_survey($_GET['survey_id']);
  105. break;
  106. }
  107. // Action handling: performing the same action on multiple surveys
  108. if (isset($_POST['action']) && $_POST['action']) {
  109. if (is_array($_POST['id'])) {
  110. foreach ($_POST['id'] as $key => & $value) {
  111. // getting the information of the survey (used for when the survey is shared)
  112. $survey_data = survey_manager::get_survey($value);
  113. // if the survey is shared => also delete the shared content
  114. if (is_numeric($survey_data['survey_share'])) {
  115. survey_manager::delete_survey($survey_data['survey_share'], true);
  116. }
  117. // delete the actual survey
  118. survey_manager::delete_survey($value);
  119. }
  120. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  121. } else {
  122. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  123. }
  124. }
  125. echo '<div class="actions">';
  126. if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
  127. // Action links
  128. echo '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.Display::return_icon(
  129. 'new_survey.png',
  130. get_lang('CreateNewSurvey'),
  131. '',
  132. ICON_SIZE_MEDIUM
  133. ).'</a> ';
  134. }
  135. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=search">'.Display::return_icon(
  136. 'search.png',
  137. get_lang('Search'),
  138. '',
  139. ICON_SIZE_MEDIUM
  140. ).'</a>';
  141. echo '</div>';
  142. // Load main content
  143. if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
  144. SurveyUtil::display_survey_list_for_coach();
  145. } else {
  146. SurveyUtil::display_survey_list();
  147. }
  148. // Footer
  149. Display :: display_footer();
  150. /* Bypass functions to make direct use from SortableTable possible */
  151. function get_number_of_surveys()
  152. {
  153. return SurveyUtil::get_number_of_surveys();
  154. }
  155. function get_survey_data($from, $number_of_items, $column, $direction)
  156. {
  157. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  158. }
  159. function modify_filter($survey_id)
  160. {
  161. return SurveyUtil::modify_filter($survey_id);
  162. }
  163. function get_number_of_surveys_for_coach()
  164. {
  165. return SurveyUtil::get_number_of_surveys_for_coach();
  166. }
  167. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  168. {
  169. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  170. }
  171. function modify_filter_for_coach($survey_id)
  172. {
  173. return SurveyUtil::modify_filter_for_coach($survey_id);
  174. }
  175. function anonymous_filter($anonymous)
  176. {
  177. return SurveyUtil::anonymous_filter($anonymous);
  178. }