return $status;
}
+
+ //Backup scales info (common and course scales)
+ function backup_scales_info($bf,$preferences) {
+
+ global $CFG;
+
+ $status = true;
+
+ //Counter, points to current record
+ $counter = 0;
+
+ //Get scales (common and course scales)
+ $scales = get_records_sql("SELECT id, courseid, userid, name, scale, description, timemodified
+ FROM {$CFG->prefix}scale
+ WHERE courseid = '0' or courseid = $preferences->backup_course");
+
+ //Pring scales header
+ if ($scales) {
+ //Pring scales header
+ fwrite ($bf,start_tag("SCALES",2,true));
+ //Iterate
+ foreach ($scales as $scale) {
+ //Begin scale tag
+ fwrite ($bf,start_tag("SCALE",3,true));
+ //Output scale tag
+ fwrite ($bf,full_tag("ID",4,false,$scale->id));
+ fwrite ($bf,full_tag("COURSEID",4,false,$scale->courseid));
+ fwrite ($bf,full_tag("USERID",4,false,$scale->userid));
+ fwrite ($bf,full_tag("NAME",4,false,$scale->name));
+ fwrite ($bf,full_tag("SCALETEXT",4,false,$scale->scale));
+ fwrite ($bf,full_tag("DESCRIPTION",4,false,$scale->description));
+ fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$scale->timemodified));
+ //End scale tag
+ fwrite ($bf,end_tag("SCALE",3,true));
+ }
+ //End scales tag
+ $status = fwrite ($bf,end_tag("SCALES",2,true));
+ }
+ return $status;
+ }
+
+
//Start the modules tag
function backup_modules_start ($bf,$preferences) {
return $info;
}
+ //This function read the xml file and store its data from the scales in
+ //backup_ids->info db (and scale's id in $info)
+ function restore_read_xml_scales ($restore,$xml_file) {
+
+ //We call the main read_xml function, with todo = SCALES
+ $info = restore_read_xml ($xml_file,"SCALES",$restore);
+
+ return $info;
+ }
+
//This function read the xml file and store its data from the modules in
//backup_ids->info
function restore_read_xml_modules ($restore,$xml_file) {
return $status;
}
+ //This function creates all the scales
+ function restore_create_scales($restore,$xml_file) {
+
+ global $CFG, $db;
+
+ $status = true;
+ //Check it exists
+ if (!file_exists($xml_file)) {
+ $status = false;
+ }
+ //Get info from xml
+ if ($status) {
+ //scales will contain the old_id of every scale
+ //in backup_ids->info will be the real info (serialized)
+ $scales = restore_read_xml_scales($restore,$xml_file);
+ }
+ //Now, if we have anything in scales, we have to restore that
+ //scales
+ if ($scales) {
+ if ($scales !== true) {
+ //Iterate over each scale
+ foreach ($scales as $scale) {
+ //Get record from backup_ids
+ $data = backup_getid($restore->backup_unique_code,"scale",$scale->id);
+ //Init variables
+ $create_scale = false;
+
+ if ($data) {
+ //Now get completed xmlized object
+ $info = $data->info;
+ //traverse_xmlize($info); //Debug
+ //print_object ($GLOBALS['traverse_array']); //Debug
+ //$GLOBALS['traverse_array']=""; //Debug
+
+ //Now build the SCALE record structure
+ $sca->id = backup_todb($info['SCALE']['#']['ID']['0']['#']);
+ $sca->courseid = backup_todb($info['SCALE']['#']['COURSEID']['0']['#']);
+ $sca->userid = backup_todb($info['SCALE']['#']['USERID']['0']['#']);
+ $sca->name = backup_todb($info['SCALE']['#']['NAME']['0']['#']);
+ $sca->scale = backup_todb($info['SCALE']['#']['SCALETEXT']['0']['#']);
+ $sca->description = backup_todb($info['SCALE']['#']['DESCRIPTION']['0']['#']);
+ $sca->timemodified = backup_todb($info['SCALE']['#']['TIMEMODIFIED']['0']['#']);
+
+ //Now search if that scale exists (by scale field)
+ $sca_db = get_record("scale","scale",$sca->scale);
+ //If it doesn't exist, create
+ if (!$sca_db) {
+ $create_scale = true;
+ } else {
+ //Exists. If the courseid in db is <> 0 and <> current course,
+ //we must create the scale too
+ if ($sca_db->courseid != 0 and $sca_db->courseid != $restore->course_id) {
+ $create_scale = true;
+ }
+ }
+ //If we must create the scale
+ if ($create_scale) {
+ //Me must recode the courseid if it's <> 0 (common scale)
+ if ($sca->courseid != 0) {
+ $sca->courseid = $restore->course_id;
+ }
+ //We must recode the userid
+ $user = backup_getid($restore->backup_unique_code,"user",$sca->userid);
+ if ($user) {
+ $sca->userid = $user->new_id;
+ } else {
+ //Assign it to admin
+ $sca->userid = 1;
+ }
+ //The structure is equal to the db, so insert the scale
+ $newid = insert_record ("scale",$sca);
+ } else {
+ //get current scale id
+ $newid = $sca_db->id;
+ }
+ if ($newid) {
+ //We have the newid, update backup_ids
+ backup_putid($restore->backup_unique_code,"scale",
+ $scale->id, $newid);
+ }
+ }
+ }
+ }
+ } else {
+ $status = false;
+ }
+ return $status;
+ }
+
//This function restores the userfiles from the temp (user_files) directory to the
//dataroot/users directory
function restore_user_files($restore) {
}
}
+ //This is the startTag handler we use where we are reading the scales zone (todo="SCALES")
+ function startElementScales($parser, $tagName, $attrs) {
+ //Refresh properties
+ $this->level++;
+ $this->tree[$this->level] = $tagName;
+
+ //if ($tagName == "SCALE" && $this->tree[3] == "SCALES") { //Debug
+ // echo "<P>SCALE: ".strftime ("%X",time()),"-"; //Debug
+ //} //Debug
+
+ //Output something to avoid browser timeouts...
+ backup_flush();
+
+ //Check if we are into SCALES zone
+ //if ($this->tree[3] == "SCALES") //Debug
+ // echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br>\n"; //Debug
+
+ //If we are under a SCALE tag under a SCALES zone, accumule it
+ if (($this->tree[4] == "SCALE") and ($this->tree[3] == "SCALES")) {
+ $this->temp .= "<".$tagName.">";
+ }
+ }
+
//This is the startTag handler we use where we are reading the modules zone (todo="MODULES")
function startElementModules($parser, $tagName, $attrs) {
//Refresh properties
$this->content = "";
}
- //This is the endTag handler we use where we are reading the modules zone (todo="QUESTIONS")
+ //This is the endTag handler we use where we are reading the questions zone (todo="QUESTIONS")
function endElementQuestions($parser, $tagName) {
//Check if we are into QUESTION_CATEGORIES zone
if ($this->tree[3] == "QUESTION_CATEGORIES") {
if (($this->level == 4) and ($tagName == "QUESTION_CATEGORY")) {
//Prepend XML standard header to info gathered
$xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
- //Call to xmlize for this portion of xml data (one MOD)
+ //Call to xmlize for this portion of xml data (one QUESTION_CATEGORY)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize($xml_data,0);
//echo strftime ("%X",time())."<p>"; //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
- //Get id and modtype from data
+ //Get id from data
$category_id = $data["QUESTION_CATEGORY"]["#"]["ID"]["0"]["#"];
//Save to db
$status = backup_putid($this->preferences->backup_unique_code,"quiz_categories",$category_id,
$this->content = "";
}
+ //This is the endTag handler we use where we are reading the scales zone (todo="SCALES")
+ function endElementScales($parser, $tagName) {
+ //Check if we are into SCALES zone
+ if ($this->tree[3] == "SCALES") {
+ //if (trim($this->content)) //Debug
+ // echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br>\n"; //Debug
+ //echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br>\n"; //Debug
+ //Acumulate data to info (content + close tag)
+ //Reconvert: strip htmlchars again and trim to generate xml data
+ $this->temp .= htmlspecialchars(trim($this->content))."</".$tagName.">";
+ //If we've finished a scale, xmlize it an save to db
+ if (($this->level == 4) and ($tagName == "SCALE")) {
+ //Prepend XML standard header to info gathered
+ $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
+ //Call to xmlize for this portion of xml data (one SCALE)
+ //echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
+ $data = xmlize($xml_data,0);
+ //echo strftime ("%X",time())."<p>"; //Debug
+ //traverse_xmlize($data); //Debug
+ //print_object ($GLOBALS['traverse_array']); //Debug
+ //$GLOBALS['traverse_array']=""; //Debug
+ //Now, save data to db. We'll use it later
+ //Get id and from data
+ $scale_id = $data["SCALE"]["#"]["ID"]["0"]["#"];
+ //Save to db
+ $status = backup_putid($this->preferences->backup_unique_code,"scale",$scale_id,
+ null,$data);
+ //Create returning info
+ $ret_info->id = $scale_id;
+ $this->info[] = $ret_info;
+ //Reset temp
+ unset($this->temp);
+ }
+ }
+
+ //Stop parsing if todo = SCALES and tagName = SCALE (en of the tag, of course)
+ //Speed up a lot (avoid parse all)
+ if ($tagName == "SCALES" and $this->level == 3) {
+ $this->finished = true;
+ }
+
+ //Clear things
+ $this->tree[$this->level] = "";
+ $this->level--;
+ $this->content = "";
+ }
+
//This is the endTag handler we use where we are reading the modules zone (todo="MODULES")
function endElementModules($parser, $tagName) {
//Check if we are into MODULES zone
} else if ($todo == "QUESTIONS") {
//Define handlers to that zone
xml_set_element_handler($xml_parser, "startElementQuestions", "endElementQuestions");
+ } else if ($todo == "SCALES") {
+ //Define handlers to that zone
+ xml_set_element_handler($xml_parser, "startElementScales", "endElementScales");
} else if ($todo == "MODULES") {
//Define handlers to that zone
xml_set_element_handler($xml_parser, "startElementModules", "endElementModules");