Add 'export survey' feature - refs #7169

1.10.x
Imanol Losada 11 years ago
parent 24d619b861
commit 2e0fbd7ef7
  1. 3
      main/course_info/maintenance.php
  2. 82
      main/survey/copy_survey.php
  3. 21
      main/survey/survey.lib.php

@ -38,6 +38,9 @@ echo Display::page_header($nameTools);
<div class="sectiontitle"><?php Display::display_icon('copy.gif', get_lang('CopyCourse')); ?>&nbsp;&nbsp;<a href="../coursecopy/copy_course.php?<?php echo api_get_cidreq(); ?>"><?php echo get_lang('CopyCourse'); ?></a></div>
<div class="sectioncomment"><?php echo get_lang('DescriptionCopyCourse'); ?></div>
<div class="sectiontitle"><?php Display::display_icon('copy.gif', get_lang('CopySurvey')); ?>&nbsp;&nbsp;<a href="../survey/copy_survey.php?<?php echo api_get_cidreq(); ?>"><?php echo get_lang('CopySurvey'); ?></a></div>
<div class="sectioncomment"><?php echo get_lang('DescriptionCopySurvey'); ?></div>
<div class="sectiontitle"><?php Display::display_icon('tool_delete.gif', get_lang('recycle_course')); ?>&nbsp;&nbsp;<a href="../coursecopy/recycle_course.php?<?php echo api_get_cidreq(); ?>"><?php echo get_lang('recycle_course'); ?></a></div>
<div class="sectioncomment"><?php echo get_lang('DescriptionRecycleCourse'); ?></div>

@ -0,0 +1,82 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.backup
*/
/**
* Code
*/
// Language files that need to be included
$language_file = array('exercice', 'coursebackup', 'admin');
// Setting the global file that gets the general configuration, the databases, the languages, ...
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true);
// Notice for unauthorized people.
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
// Breadcrumbs
$interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
// The section (for the tabs)
$this_section = SECTION_COURSES;
// Display the header
Display::display_header(get_lang('CopySurvey'));
echo Display::page_header(get_lang('CopySurvey'));
/* MAIN CODE */
// If a CourseSelectForm is posted or we should copy all resources, then copy them
if (Security::check_token('post')) {
// Clear token
Security::clear_token();
$surveyId = intval($_POST['surveys']);
$courseId = Security::remove_XSS($_POST['destination_course']);
$surveyCopyId = survey_manager::copy_survey($surveyId, null, $courseId);
// Copy the survey to the target course
survey_manager::empty_survey($surveyCopyId, $courseId);
// Empty the copied survey
Display::display_confirmation_message(get_lang('SurveyCopied'));
}
$surveys = survey_manager::get_surveys(api_get_course_id(), api_get_session_id());
$courses = CourseManager::get_courses_list();
$form = new FormValidator('copy_survey', 'post', 'copy_survey.php?'.api_get_cidreq());
if (!$surveys) {
Display::display_error_message(get_lang('NoSurveysAvailable'));
}
if (count($courses) <= 1) {
Display::display_error_message(get_lang('NoCoursesAvailable'));
}
if ($surveys && count($courses) > 1) {
// Surveys select
$options = array();
foreach ($surveys as $survey) {
$options[$survey['survey_id']] = $survey['title'];
}
$form->addElement('select', 'surveys', get_lang('SelectSurvey'), $options);
// All-courses-but-current select
$currentCourseId = api_get_course_int_id();
$options = array();
foreach ($courses as $course) {
if ($course['id'] != $currentCourseId) {
$options[$course['id']] = $course['title'];
}
}
$form->addElement('select', 'destination_course', get_lang('SelectDestinationCourse'), $options);
$form->addElement('style_submit_button', 'submit', get_lang('CopySurvey'), 'class="save"');
}
// Add Security token
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$form->display();
Display::display_footer();

@ -534,12 +534,16 @@ class survey_manager
/**
* @param int $survey_id
* @param int $new_survey_id
* @param int $targetCourseId
*
* @return bool
*/
public static function copy_survey($survey_id, $new_survey_id = null)
public static function copy_survey($survey_id, $new_survey_id = null, $targetCourseId = null)
{
$course_id = api_get_course_int_id();
if (!$targetCourseId) {
$targetCourseId = $course_id;
}
// Database table definitions
$table_survey = Database::get_course_table(TABLE_SURVEY);
@ -557,7 +561,7 @@ class survey_manager
if (empty($new_survey_id)) {
$params = $survey_data;
$params['code'] = self::generate_unique_code($params['code']);
$params['c_id'] = $course_id;
$params['c_id'] = $targetCourseId;
unset($params['survey_id']);
$params['session_id'] = api_get_session_id();
$params['title'] = $params['title'] . ' ' . get_lang('Copy');
@ -575,7 +579,7 @@ class survey_manager
$res = Database::query($sql);
while($row = Database::fetch_array($res, 'ASSOC')) {
$params = array(
'c_id' => $course_id,
'c_id' => $targetCourseId,
'name' => $row['name'],
'description' => $row['description'],
'survey_id' => $new_survey_id
@ -591,7 +595,7 @@ class survey_manager
$res = Database::query($sql);
while ($row = Database::fetch_array($res, 'ASSOC')) {
$params = array(
'c_id' => $course_id,
'c_id' => $targetCourseId,
'survey_id' => $new_survey_id,
'survey_question' => $row['survey_question'],
'survey_question_comment' => $row['survey_question_comment'],
@ -615,7 +619,7 @@ class survey_manager
$res = Database::query($sql);
while ($row = Database::fetch_array($res ,'ASSOC')) {
$params = array(
'c_id' => $course_id,
'c_id' => $targetCourseId,
'question_id' => $question_id[$row['question_id']],
'survey_id' => $new_survey_id,
'option_text' => $row['option_text'],
@ -625,26 +629,27 @@ class survey_manager
Database::insert($table_survey_options, $params);
}
return true;
return $new_survey_id;
}
/**
* This function duplicates a survey (and also all the question in that survey
*
* @param int $survey_id id of the survey that has to be duplicated
* @param int $courseId id of the course which survey has to be duplicated
* @return true
*
* @author Eric Marguin <e.marguin@elixir-interactive.com>, Elixir Interactive
* @version October 2007
*/
public static function empty_survey($survey_id)
public static function empty_survey($survey_id, $courseId = null)
{
// Database table definitions
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$course_id = api_get_course_int_id();
$course_id = $courseId ? $courseId : api_get_course_int_id();
$datas = survey_manager::get_survey($survey_id);
$session_where = '';

Loading…
Cancel
Save