survey_list.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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['search'] == 'advanced') {
  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. //api_display_tool_title($tool_name);
  50. // Tool introduction
  51. Display::display_introduction_section('survey', 'left');
  52. // Action handling: searching
  53. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  54. SurveyUtil::display_survey_search_form();
  55. }
  56. // Action handling: deleting a survey
  57. if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['survey_id']) && is_numeric($_GET['survey_id'])) {
  58. // Getting the information of the survey (used for when the survey is shared)
  59. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  60. if (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
  61. // The coach can't delete a survey not belonging to his session
  62. api_not_allowed();
  63. exit;
  64. }
  65. // If the survey is shared => also delete the shared content
  66. if (is_numeric($survey_data['survey_share'])) {
  67. survey_manager::delete_survey($survey_data['survey_share'], true);
  68. }
  69. $return = survey_manager :: delete_survey($_GET['survey_id']);
  70. if ($return) {
  71. Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
  72. } else {
  73. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  74. }
  75. }
  76. if (isset($_GET['action']) && $_GET['action'] == 'empty') {
  77. $mysession = api_get_session_id();
  78. if ( $mysession != 0 ) {
  79. if (!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_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 ($_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 $extended_rights_for_coachs;
  116. echo '<div class="actions">';
  117. if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
  118. // Action links
  119. echo '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'),'',ICON_SIZE_MEDIUM).'</a> ';
  120. }
  121. //echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> ';
  122. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.Display::return_icon('search.png', get_lang('Search'),'',ICON_SIZE_MEDIUM).'</a>';
  123. echo '</div>';
  124. // Load main content
  125. if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
  126. SurveyUtil::display_survey_list_for_coach();
  127. } else {
  128. SurveyUtil::display_survey_list();
  129. }
  130. // Footer
  131. Display :: display_footer();
  132. /* Bypass functions to make direct use from SortableTable possible */
  133. function get_number_of_surveys() {
  134. return SurveyUtil::get_number_of_surveys();
  135. }
  136. function get_survey_data($from, $number_of_items, $column, $direction) {
  137. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  138. }
  139. function modify_filter($survey_id) {
  140. return SurveyUtil::modify_filter($survey_id);
  141. }
  142. function get_number_of_surveys_for_coach() {
  143. return SurveyUtil::get_number_of_surveys_for_coach();
  144. }
  145. function get_survey_data_for_coach($from, $number_of_items, $column, $direction) {
  146. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  147. }
  148. function modify_filter_for_coach($survey_id) {
  149. return SurveyUtil::modify_filter_for_coach($survey_id);
  150. }
  151. function anonymous_filter($anonymous) {
  152. return SurveyUtil::anonymous_filter($anonymous);
  153. }