[svn r16101] FS#2734 : Fix a bug when copying surveys in another course

skala
Julian Prud'homme 16 years ago
parent cf25c63f59
commit dbc5172618
  1. 4
      documentation/changelog.html
  2. 158
      main/coursecopy/classes/CourseRestorer.class.php
  3. 8
      main/survey/survey.lib.php

@ -71,7 +71,9 @@
<li>The mails sent in exercises tool are sent from the address defined in admin (FS#2712)</li>
<li>"Next" and "Previous" page now works when searching a session (FS#2721)</li>
<li>Fixed bug when launching a quiz with one question per page (FS#2738)</li>
<li>fix a javascript bug with swap menu in ie6 (FS#2815)</li>
<li>fix a javascript bug with swap menu in ie6 (FS#2815)</li>
<li>Fix a bug in surveys when we want to display answers of an invited person (FS#2731)</li>
<li>Fix a bug when copying a course with surveys. There is now a check for existing surveys with the same code and language (FS#2734)</li>
</ul>
<br />
<h3>Known issues</h3>

@ -1,4 +1,4 @@
<?php // $Id: CourseRestorer.class.php 15802 2008-07-17 04:52:13Z yannoo $
<?php // $Id: CourseRestorer.class.php 16101 2008-08-28 08:52:29Z elixir_julian $
/*
==============================================================================
Dokeos - elearning and course management software
@ -656,7 +656,15 @@ class CourseRestorer
$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION, $this->course->destination_db);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_SURVEY] as $id => $survey)
{
{
$sql_check = 'SELECT survey_id FROM '.$table_sur.'
WHERE code = "'.Database::escape_string($survey->code).'"
AND lang="'.Database::escape_string($survey->lang).'"
';
$result_check = api_sql_query($sql_check, __FILE__, __LINE__);
$doc = '';
$sql = "INSERT INTO ".$table_sur." " .
"SET code = '".Database::escape_string($survey->code)."', " .
@ -675,24 +683,146 @@ class CourseRestorer
"answered = '0', " .
"invite_mail = '".Database::escape_string($survey->invite_mail)."', " .
"reminder_mail = '".Database::escape_string($survey->reminder_mail)."'";
api_sql_query($sql, __FILE__, __LINE__);
$new_id = Database::get_last_insert_id();
$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
foreach ($survey->question_ids as $index => $question_id)
//An existing survey exists with the same code and the same language
if(Database::num_rows($result_check) == 1)
{
switch ($this->file_option) {
case FILE_SKIP:
//Do nothing
break;
case FILE_RENAME:
$survey_code = $survey->code.'_';
$i=1;
$temp_survey_code = $survey_code.$i;
while (!$this->is_survey_code_available($temp_survey_code))
{
$temp_survey_code = $survey_code.++$i;
}
$survey_code = $temp_survey_code;
$sql = "INSERT INTO ".$table_sur." " .
"SET code = '".Database::escape_string($survey_code)."', " .
"title = '".Database::escape_string($survey->title)."', " .
"subtitle = '".Database::escape_string($survey->subtitle)."', " .
"author = '".Database::escape_string($survey->author)."', " .
"lang = '".Database::escape_string($survey->lang)."', " .
"avail_from = '".Database::escape_string($survey->avail_from)."', " .
"avail_till = '".Database::escape_string($survey->avail_till)."', " .
"is_shared = '".Database::escape_string($survey->is_shared)."', " .
"template = '".Database::escape_string($survey->template)."', " .
"intro = '".Database::escape_string($survey->intro)."', " .
"surveythanks = '".Database::escape_string($survey->surveythanks)."', " .
"creation_date = '".Database::escape_string($survey->creation_date)."', " .
"invited = '0', " .
"answered = '0', " .
"invite_mail = '".Database::escape_string($survey->invite_mail)."', " .
"reminder_mail = '".Database::escape_string($survey->reminder_mail)."'";
//Insert the new source survey
api_sql_query($sql, __FILE__, __LINE__);
$new_id = Database::get_last_insert_id();
$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
foreach ($survey->question_ids as $index => $question_id)
{
$qid = $this->restore_survey_question($question_id);
$sql = "UPDATE ".$table_que." " .
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
$sql = "UPDATE ".$table_ans." ".
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
}
break;
case FILE_OVERWRITE:
// Delete the existing survey with the same code and language and import the one of the source course
// getting the information of the survey (used for when the survey is shared)
require_once(api_get_path(SYS_CODE_PATH).'survey/survey.lib.php');
$sql_select_existing_survey = "SELECT * FROM $table_sur WHERE survey_id='".Database::escape_string(mysql_result($result_check,0,0))."'";
$result = api_sql_query($sql_select_existing_survey, __FILE__, __LINE__);
$survey_data = Database::fetch_array($result,'ASSOC');
// if the survey is shared => also delete the shared content
if (is_numeric($survey_data['survey_share']))
{
survey_manager::delete_survey($survey_data['survey_share'], true,$this->course->destination_db);
}
$return = survey_manager :: delete_survey($survey_data['survey_id'],false,$this->course->destination_db);
//Insert the new source survey
api_sql_query($sql, __FILE__, __LINE__);
$new_id = Database::get_last_insert_id();
$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
foreach ($survey->question_ids as $index => $question_id)
{
$qid = $this->restore_survey_question($question_id);
$sql = "UPDATE ".$table_que." " .
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
$sql = "UPDATE ".$table_ans." ".
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
}
break;
default:
break;
}
}
//No existing survey with the same language and the same code, we just copy the survey
else
{
$qid = $this->restore_survey_question($question_id);
$sql = "UPDATE ".$table_que." " .
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
$sql = "UPDATE ".$table_ans." ".
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
$new_id = Database::get_last_insert_id();
$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
foreach ($survey->question_ids as $index => $question_id)
{
$qid = $this->restore_survey_question($question_id);
$sql = "UPDATE ".$table_que." " .
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
$sql = "UPDATE ".$table_ans." ".
"SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid."";
api_sql_query($sql, __FILE__, __LINE__);
}
}
}
}
}
/**
* Check availability of a survey code
*/
function is_survey_code_available($survey_code){
$table_sur = Database :: get_course_table(TABLE_SURVEY, $this->course->destination_db);
$sql = "SELECT * FROM $table_sur WHERE code='".Database::escape_string($survey_code)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
if(Database::num_rows($result) > 0) return false; else return true;
}
/**
* Restore survey-questions
*/

@ -24,7 +24,7 @@
* @package dokeos.survey
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
@author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
* @version $Id: survey.lib.php 16077 2008-08-27 08:18:04Z elixir_julian $
* @version $Id: survey.lib.php 16101 2008-08-28 08:52:29Z elixir_julian $
*
* @todo move this file to inc/lib
* @todo use consistent naming for the functions (save vs store for instance)
@ -376,11 +376,11 @@ class survey_manager
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function delete_survey($survey_id, $shared=false)
function delete_survey($survey_id, $shared=false, $course_code = '')
{
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$table_survey = Database :: get_course_table(TABLE_SURVEY,$course_code);
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP,$course_code);
if ($shared)
{
$table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY);

Loading…
Cancel
Save