survey_all_courses.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author unknown
  19. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
  20. * @version $Id: survey_all_courses.php 10680 2007-01-11 21:26:23Z pcool $
  21. *
  22. * @todo check if this page has to display all the shared surveys of the courses where the user is a teacher or only
  23. * the shared surveys of this course?
  24. */
  25. // name of the language file that needs to be included
  26. $language_file = 'survey';
  27. // including the global dokeos file
  28. require_once ('../inc/global.inc.php');
  29. // including additional libraries
  30. /** @todo check if these are all needed */
  31. /** @todo check if the starting / is needed. api_get_path probably ends with an / */
  32. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  33. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  34. // Database table definitions
  35. /** @todo use database constants for the survey tables */
  36. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  37. $table_group = Database :: get_course_table(TABLE_SURVEY_GROUP);
  38. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  39. $table_course_survey_rel = Database :: get_main_table(TABLE_MAIN_COURSE_SURVEY);
  40. /** @todo replace this with the correct code */
  41. /*
  42. $status = surveymanager::get_status();
  43. api_protect_course_script();
  44. if($status==5)
  45. {
  46. api_protect_admin_script();
  47. }
  48. */
  49. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  50. if (!api_is_allowed_to_edit())
  51. {
  52. Display :: display_header();
  53. Display :: display_error_message(get_lang('NotAllowedHere'));
  54. Display :: display_footer();
  55. exit;
  56. }
  57. // breadcrumbs
  58. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
  59. // Displaying the header
  60. Display::display_header(get_lang('CreateFromExistingSurveys'));
  61. // Displaying the tool title
  62. //api_display_tool_title(get_lang('CreateFromExistingSurveys'));
  63. ?>
  64. <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  65. <input type="hidden" name="action" value="add_survey">
  66. <input type="hidden" name="surveyid" value="<?php echo $_GET['survey_id']; ?>">
  67. <?php
  68. $rsDbs = mysql_list_dbs();
  69. $db_list = array();
  70. while($db = mysql_fetch_array($rsDbs))
  71. {
  72. $db_list[] = $db[0];
  73. }
  74. $nameTools=get_lang('CreateFromExistingSurveys');
  75. $table_group = Database :: get_course_table(TABLE_SURVEY_GROUP);
  76. $sql = "SELECT course_survey.*, visual_code
  77. FROM $table_course_survey_rel as course_survey
  78. INNER JOIN ".Database::get_main_table(TABLE_MAIN_COURSE)." as course
  79. ON course_survey.course_code = course.code";
  80. $parameters = array ();
  81. $parameters['surveyid']=$_GET['survey_id'];
  82. $parameters['newgroupid']=$groupid;
  83. $res = api_sql_query($sql,__FILE__,__LINE__);
  84. if (mysql_num_rows($res) > 0)
  85. {
  86. $surveys = array ();
  87. while ($obj = mysql_fetch_object($res))
  88. {
  89. $db_name = $obj->db_name;
  90. $course_name = $obj->visual_code;
  91. $survey_id = $obj->survey_id;
  92. //echo "<pre>";
  93. if(in_array($db_name, $db_list)){
  94. $sql_survey = "SELECT * FROM $db_name.survey WHERE survey_id = '$survey_id' AND is_shared='1'";
  95. //echo "</pre>";
  96. $res_survey = api_sql_query($sql_survey,__FILE__,__LINE__);
  97. $survey = array ();
  98. while($object=mysql_fetch_object($res_survey))
  99. {
  100. //$survey[] = '<input type="checkbox" name="course[]" value="'.$obj->group_id.'">';
  101. $survey[] = $object->title;
  102. //$groupid=$obj->group_id;
  103. $authorid=surveymanager::get_author($db_name,$survey_id);
  104. $author=surveymanager::get_survey_author($authorid);
  105. //$NoOfQuestion=surveymanager::no_of_question($groupid);
  106. $survey[] = $author;
  107. $survey[] = $course_name;
  108. $survey[] = $object->lang;
  109. $survey[] = $object->avail_from ;
  110. $survey[] = $object->avail_till ;
  111. $survey[] = "<a href=create_from_existing_survey.php?surveyid=$survey_id&db_name=$db_name><img src=\"../img/info_small.gif\" border=\"0\" align=\"absmiddle\" alt=view></a>";
  112. $surveys[] = $survey;
  113. }
  114. }
  115. }
  116. $table_header[] = array (get_lang('SurveyName'), true);
  117. $table_header[] = array (get_lang('Author'), true);
  118. $table_header[] = array (get_lang('CourseName'), true);
  119. $table_header[] = array (get_lang('Language'), true);
  120. $table_header[] = array (get_lang('AvailableFrom'), true);
  121. $table_header[] = array (get_lang('AvailableTill'), true);
  122. $table_header[] = array (' ', false);
  123. if(!empty($surveys))
  124. {
  125. Display :: display_sortable_table($table_header, $surveys, array (), array (), $parameters);
  126. }
  127. else
  128. {
  129. $flag=1;
  130. }
  131. ?>
  132. </form>
  133. <?php
  134. }
  135. else
  136. {
  137. echo get_lang('NoSearchResults');
  138. }
  139. if($flag=='1')
  140. {
  141. echo get_lang('SurveyNotShared');
  142. }
  143. ?>
  144. <form action="survey_list.php" method="post">
  145. <input type="submit" name="back1" value="<?php echo get_lang('Back'); ?>">
  146. </form>
  147. <?php
  148. /*
  149. -----------------------------------------------------------
  150. Footer
  151. -----------------------------------------------------------
  152. */
  153. Display :: display_footer();
  154. ?>