survey_list.php 6.3 KB

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