survey_list.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php // $Id: survey_list.php 21933 2009-07-09 06:08:22Z ivantcholakov $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue Notre Dame, 152, B-1140 Evere, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * @package dokeos.survey
  19. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  20. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  21. * @author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
  22. * @version $Id: survey_list.php 21933 2009-07-09 06:08:22Z ivantcholakov $
  23. *
  24. * @todo use quickforms for the forms
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = 'survey';
  28. if (!isset ($_GET['cidReq'])){
  29. $_GET['cidReq']='none'; // prevent sql errors
  30. $cidReset = true;
  31. }
  32. // including the global dokeos file
  33. require ('../inc/global.inc.php');
  34. // including additional libraries
  35. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  36. require_once('survey.lib.php');
  37. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  38. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  39. if (!api_is_allowed_to_edit(false,true)) //coach can see this
  40. {
  41. Display :: display_header(get_lang('SurveyList'));
  42. SurveyUtil::survey_list_user($_user['user_id']);
  43. Display :: display_footer();
  44. exit;
  45. }
  46. $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
  47. // Database table definitions
  48. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  49. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  50. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  51. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  52. // language variables
  53. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  54. {
  55. $interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
  56. $tool_name = get_lang('SearchASurvey');
  57. }
  58. else
  59. {
  60. $tool_name = get_lang('SurveyList');
  61. }
  62. // Header
  63. Display :: display_header($tool_name,'Survey');
  64. //api_display_tool_title($tool_name);
  65. // Tool introduction
  66. Display::display_introduction_section('survey', 'left');
  67. // Action handling: searching
  68. if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
  69. {
  70. SurveyUtil::display_survey_search_form();
  71. }
  72. // Action handling: deleting a survey
  73. if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
  74. {
  75. // getting the information of the survey (used for when the survey is shared)
  76. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  77. if(api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id'])
  78. { // the coach can't delete a survey not belonging to his session
  79. api_not_allowed();
  80. exit;
  81. }
  82. // if the survey is shared => also delete the shared content
  83. if (is_numeric($survey_data['survey_share']))
  84. {
  85. survey_manager::delete_survey($survey_data['survey_share'], true);
  86. }
  87. $return = survey_manager :: delete_survey($_GET['survey_id']);
  88. if ($return)
  89. {
  90. Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
  91. }
  92. else
  93. {
  94. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  95. }
  96. }
  97. if(isset($_GET['action']) && $_GET['action'] == 'empty')
  98. {
  99. $mysession = api_get_session_id();
  100. if ( $mysession != 0 ) {
  101. if(!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id'])))) {
  102. // the coach can't empty a survey not belonging to his session
  103. api_not_allowed();
  104. exit;
  105. }
  106. } else {
  107. if (!(api_is_course_admin() || api_is_platform_admin())) {
  108. api_not_allowed();
  109. exit;
  110. }
  111. }
  112. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  113. if ($return)
  114. {
  115. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  116. }
  117. else
  118. {
  119. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  120. }
  121. }
  122. // Action handling: performing the same action on multiple surveys
  123. if ($_POST['action'])
  124. {
  125. if (is_array($_POST['id']))
  126. {
  127. foreach ($_POST['id'] as $key=>$value)
  128. {
  129. // getting the information of the survey (used for when the survey is shared)
  130. $survey_data = survey_manager::get_survey($value);
  131. // if the survey is shared => also delete the shared content
  132. if (is_numeric($survey_data['survey_share']))
  133. {
  134. survey_manager::delete_survey($survey_data['survey_share'], true);
  135. }
  136. // delete the actual survey
  137. survey_manager::delete_survey($value);
  138. }
  139. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  140. }
  141. else
  142. {
  143. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  144. }
  145. }
  146. echo $extended_rights_for_coachs;
  147. echo '<div class="actions">';
  148. if (!api_is_course_coach() || $extend_rights_for_coachs=='true')
  149. {
  150. // Action links
  151. echo Display::return_icon('surveyadd.gif', get_lang('CreateNewSurvey')) . '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.get_lang('CreateNewSurvey').'</a> ';
  152. }
  153. //echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> ';
  154. echo Display::return_icon('search.gif', get_lang('Search')) . '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.get_lang('Search').'</a>';
  155. echo '</div>';
  156. //Load main content
  157. if (api_is_course_coach() && $extend_rights_for_coachs=='false')
  158. SurveyUtil::display_survey_list_for_coach();
  159. else
  160. SurveyUtil::display_survey_list();
  161. // Footer
  162. Display :: display_footer();
  163. /* Bypass functions to make direct use from SortableTable possible */
  164. function get_number_of_surveys()
  165. {
  166. return SurveyUtil::get_number_of_surveys();
  167. }
  168. function get_survey_data($from, $number_of_items, $column, $direction)
  169. {
  170. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  171. }
  172. function modify_filter($survey_id)
  173. {
  174. return SurveyUtil::modify_filter($survey_id);
  175. }
  176. function get_number_of_surveys_for_coach()
  177. {
  178. return SurveyUtil::get_number_of_surveys_for_coach();
  179. }
  180. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  181. {
  182. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  183. }
  184. function modify_filter_for_coach($survey_id)
  185. {
  186. return SurveyUtil::modify_filter_for_coach($survey_id);
  187. }
  188. function anonymous_filter($anonymous)
  189. {
  190. return SurveyUtil::anonymous_filter($anonymous);
  191. }