survey_list.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. // Including additional libraries
  22. require_once 'survey.lib.php';
  23. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  24. // Tracking
  25. event_access_tool(TOOL_SURVEY);
  26. /** @todo This has to be moved to a more appropriate place (after the display_header of the code)*/
  27. if (!api_is_allowed_to_edit(false, true)) { // Coach can see this
  28. Display :: display_header(get_lang('SurveyList'));
  29. SurveyUtil::survey_list_user($_user['user_id']);
  30. Display :: display_footer();
  31. exit;
  32. }
  33. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  34. // Database table definitions
  35. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  36. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  37. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  38. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  39. // Language variables
  40. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  41. $interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  42. $tool_name = get_lang('SearchASurvey');
  43. } else {
  44. $tool_name = get_lang('SurveyList');
  45. }
  46. // Header
  47. Display :: display_header($tool_name, 'Survey');
  48. //api_display_tool_title($tool_name);
  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']) && is_numeric($_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()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id'])))) {
  79. // The coach can't empty a survey not belonging to his session
  80. api_not_allowed();
  81. exit;
  82. }
  83. } else {
  84. if (!(api_is_course_admin() || api_is_platform_admin())) {
  85. api_not_allowed();
  86. exit;
  87. }
  88. }
  89. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  90. if ($return) {
  91. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  92. } else {
  93. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  94. }
  95. }
  96. // Action handling: performing the same action on multiple surveys
  97. if ($_POST['action']) {
  98. if (is_array($_POST['id'])) {
  99. foreach ($_POST['id'] as $key => & $value) {
  100. // getting the information of the survey (used for when the survey is shared)
  101. $survey_data = survey_manager::get_survey($value);
  102. // if the survey is shared => also delete the shared content
  103. if (is_numeric($survey_data['survey_share'])) {
  104. survey_manager::delete_survey($survey_data['survey_share'], true);
  105. }
  106. // delete the actual survey
  107. survey_manager::delete_survey($value);
  108. }
  109. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  110. } else {
  111. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  112. }
  113. }
  114. echo $extended_rights_for_coachs;
  115. echo '<div class="actions">';
  116. if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
  117. // Action links
  118. 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> ';
  119. }
  120. //echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> ';
  121. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.Display::return_icon('search.png', get_lang('Search'),'',ICON_SIZE_MEDIUM).'</a>';
  122. echo '</div>';
  123. // Load main content
  124. if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
  125. SurveyUtil::display_survey_list_for_coach();
  126. } else {
  127. SurveyUtil::display_survey_list();
  128. }
  129. // Footer
  130. Display :: display_footer();
  131. /* Bypass functions to make direct use from SortableTable possible */
  132. function get_number_of_surveys() {
  133. return SurveyUtil::get_number_of_surveys();
  134. }
  135. function get_survey_data($from, $number_of_items, $column, $direction) {
  136. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  137. }
  138. function modify_filter($survey_id) {
  139. return SurveyUtil::modify_filter($survey_id);
  140. }
  141. function get_number_of_surveys_for_coach() {
  142. return SurveyUtil::get_number_of_surveys_for_coach();
  143. }
  144. function get_survey_data_for_coach($from, $number_of_items, $column, $direction) {
  145. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  146. }
  147. function modify_filter_for_coach($survey_id) {
  148. return SurveyUtil::modify_filter_for_coach($survey_id);
  149. }
  150. function anonymous_filter($anonymous) {
  151. return SurveyUtil::anonymous_filter($anonymous);
  152. }