copy_survey.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.backup
  5. */
  6. // Setting the global file that gets the general configuration, the databases, the languages, ...
  7. //require_once '../inc/global.inc.php';
  8. $current_course_tool = TOOL_COURSE_MAINTENANCE;
  9. api_protect_course_script(true);
  10. // Notice for unauthorized people.
  11. if (!api_is_allowed_to_edit()) {
  12. api_not_allowed(true);
  13. }
  14. // Breadcrumbs
  15. $interbreadcrumb[] = array(
  16. 'url' => '../course_info/maintenance.php?'.api_get_cidreq(),
  17. 'name' => get_lang('Maintenance')
  18. );
  19. // The section (for the tabs)
  20. $this_section = SECTION_COURSES;
  21. // Display the header
  22. Display::display_header(get_lang('CopySurvey'));
  23. echo Display::page_header(get_lang('CopySurvey'));
  24. /* MAIN CODE */
  25. // If a CourseSelectForm is posted or we should copy all resources, then copy them
  26. if (Security::check_token('post')) {
  27. // Clear token
  28. Security::clear_token();
  29. $surveyId = intval($_POST['surveys']);
  30. $courseId = Security::remove_XSS($_POST['destination_course']);
  31. $surveyCopyId = SurveyManager::copy_survey($surveyId, null, $courseId);
  32. // Copy the survey to the target course
  33. SurveyManager::empty_survey($surveyCopyId, $courseId);
  34. // Empty the copied survey
  35. Display::display_confirmation_message(get_lang('SurveyCopied'));
  36. }
  37. $surveys = SurveyManager::get_surveys(api_get_course_id(), api_get_session_id());
  38. $courses = CourseManager::get_courses_list();
  39. $form = new FormValidator('copy_survey', 'post', 'copy_survey.php?'.api_get_cidreq());
  40. if (!$surveys) {
  41. Display::display_error_message(get_lang('NoSurveyAvailable'));
  42. }
  43. if (count($courses) <= 1) {
  44. Display::display_error_message(get_lang('CourseListNotAvailable'));
  45. }
  46. if ($surveys && count($courses) > 1) {
  47. // Surveys select
  48. $options = array();
  49. foreach ($surveys as $survey) {
  50. $options[$survey['survey_id']] = $survey['title'];
  51. }
  52. $form->addElement('select', 'surveys', get_lang('SelectSurvey'), $options);
  53. // All-courses-but-current select
  54. $currentCourseId = api_get_course_int_id();
  55. $options = array();
  56. foreach ($courses as $course) {
  57. if ($course['id'] != $currentCourseId) {
  58. $options[$course['id']] = $course['title'];
  59. }
  60. }
  61. $form->addElement('select', 'destination_course', get_lang('SelectDestinationCourse'), $options);
  62. $form->addButtonCopy(get_lang('CopySurvey'));
  63. }
  64. // Add Security token
  65. $token = Security::get_token();
  66. $form->addElement('hidden', 'sec_token');
  67. $form->setConstants(array('sec_token' => $token));
  68. $form->display();
  69. Display::display_footer();