copy_survey.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 __DIR__.'/../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('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
  16. // The section (for the tabs)
  17. $this_section = SECTION_COURSES;
  18. // Display the header
  19. Display::display_header(get_lang('CopySurvey'));
  20. echo Display::page_header(get_lang('CopySurvey'));
  21. /* MAIN CODE */
  22. // If a CourseSelectForm is posted or we should copy all resources, then copy them
  23. if (Security::check_token('post')) {
  24. // Clear token
  25. Security::clear_token();
  26. $surveyId = intval($_POST['surveys']);
  27. $courseId = Security::remove_XSS($_POST['destination_course']);
  28. $surveyCopyId = SurveyManager::copy_survey($surveyId, null, $courseId);
  29. // Copy the survey to the target course
  30. SurveyManager::empty_survey($surveyCopyId, $courseId);
  31. // Empty the copied survey
  32. Display::display_confirmation_message(get_lang('SurveyCopied'));
  33. }
  34. $surveys = SurveyManager::get_surveys(api_get_course_id(), api_get_session_id());
  35. $courses = CourseManager::get_courses_list();
  36. $form = new FormValidator('copy_survey', 'post', 'copy_survey.php?'.api_get_cidreq());
  37. if (!$surveys) {
  38. Display::display_error_message(get_lang('NoSurveyAvailable'));
  39. }
  40. if (count($courses) <= 1) {
  41. Display::display_error_message(get_lang('CourseListNotAvailable'));
  42. }
  43. if ($surveys && count($courses) > 1) {
  44. // Surveys select
  45. $options = array();
  46. foreach ($surveys as $survey) {
  47. $options[$survey['survey_id']] = $survey['title'];
  48. }
  49. $form->addElement('select', 'surveys', get_lang('SelectSurvey'), $options);
  50. // All-courses-but-current select
  51. $currentCourseId = api_get_course_int_id();
  52. $options = array();
  53. foreach ($courses as $course) {
  54. if ($course['id'] != $currentCourseId) {
  55. $options[$course['id']] = $course['title'];
  56. }
  57. }
  58. $form->addElement('select', 'destination_course', get_lang('SelectDestinationCourse'), $options);
  59. $form->addButtonCopy(get_lang('CopySurvey'));
  60. }
  61. // Add Security token
  62. $token = Security::get_token();
  63. $form->addElement('hidden', 'sec_token');
  64. $form->setConstants(array('sec_token' => $token));
  65. $form->display();
  66. Display::display_footer();