survey_list.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php // $Id: survey_list.php 19694 2009-04-09 21:45:33Z 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 19694 2009-04-09 21:45:33Z 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. $fck_attribute['Width'] = '100%';
  67. $fck_attribute['Height'] = '300';
  68. $fck_attribute['ToolbarSet'] = 'Introduction';
  69. Display::display_introduction_section('survey', 'left');
  70. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  71. // Action handling: searching
  72. if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
  73. {
  74. SurveyUtil::display_survey_search_form();
  75. }
  76. // Action handling: deleting a survey
  77. if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
  78. {
  79. // getting the information of the survey (used for when the survey is shared)
  80. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  81. if(api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id'])
  82. { // the coach can't delete a survey not belonging to his session
  83. api_not_allowed();
  84. exit;
  85. }
  86. // if the survey is shared => also delete the shared content
  87. if (is_numeric($survey_data['survey_share']))
  88. {
  89. survey_manager::delete_survey($survey_data['survey_share'], true);
  90. }
  91. $return = survey_manager :: delete_survey($_GET['survey_id']);
  92. if ($return)
  93. {
  94. Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
  95. }
  96. else
  97. {
  98. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  99. }
  100. }
  101. if(isset($_GET['action']) && $_GET['action'] == 'empty')
  102. {
  103. $mysession = api_get_session_id();
  104. if ( $mysession != 0 ) {
  105. if(!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id'])))) {
  106. // the coach can't empty a survey not belonging to his session
  107. api_not_allowed();
  108. exit;
  109. }
  110. } else {
  111. if (!(api_is_course_admin() || api_is_platform_admin())) {
  112. api_not_allowed();
  113. exit;
  114. }
  115. }
  116. $return = survey_manager::empty_survey(intval($_GET['survey_id']));
  117. if ($return)
  118. {
  119. Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
  120. }
  121. else
  122. {
  123. Display :: display_error_message(get_lang('ErrorOccurred'), false);
  124. }
  125. }
  126. // Action handling: performing the same action on multiple surveys
  127. if ($_POST['action'])
  128. {
  129. if (is_array($_POST['id']))
  130. {
  131. foreach ($_POST['id'] as $key=>$value)
  132. {
  133. // getting the information of the survey (used for when the survey is shared)
  134. $survey_data = survey_manager::get_survey($value);
  135. // if the survey is shared => also delete the shared content
  136. if (is_numeric($survey_data['survey_share']))
  137. {
  138. survey_manager::delete_survey($survey_data['survey_share'], true);
  139. }
  140. // delete the actual survey
  141. survey_manager::delete_survey($value);
  142. }
  143. Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
  144. }
  145. else
  146. {
  147. Display :: display_error_message(get_lang('NoSurveysSelected'), false);
  148. }
  149. }
  150. echo $extended_rights_for_coachs;
  151. echo '<div class="actions">';
  152. if (!api_is_course_coach() || $extend_rights_for_coachs=='true')
  153. {
  154. // Action links
  155. 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> ';
  156. }
  157. //echo '<a href="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</a> ';
  158. echo Display::return_icon('search.gif', get_lang('Search')) . '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.get_lang('Search').'</a>';
  159. echo '</div>';
  160. //Load main content
  161. if (api_is_course_coach() && $extend_rights_for_coachs=='false')
  162. SurveyUtil::display_survey_list_for_coach();
  163. else
  164. SurveyUtil::display_survey_list();
  165. // Footer
  166. Display :: display_footer();
  167. /* Bypass functions to make direct use from SortableTable possible */
  168. function get_number_of_surveys()
  169. {
  170. return SurveyUtil::get_number_of_surveys();
  171. }
  172. function get_survey_data($from, $number_of_items, $column, $direction)
  173. {
  174. return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
  175. }
  176. function modify_filter($survey_id)
  177. {
  178. return SurveyUtil::modify_filter($survey_id);
  179. }
  180. function get_number_of_surveys_for_coach()
  181. {
  182. return SurveyUtil::get_number_of_surveys_for_coach();
  183. }
  184. function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
  185. {
  186. return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
  187. }
  188. function modify_filter_for_coach($survey_id)
  189. {
  190. return SurveyUtil::modify_filter_for_coach($survey_id);
  191. }
  192. function anonymous_filter($anonymous)
  193. {
  194. return SurveyUtil::anonymous_filter($anonymous);
  195. }