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) {
+
+ //We call the main read_xml function, with todo = MODULES
+ $info = restore_read_xml ($xml_file,"MODULES",$restore);
+
+ return $info;
+ }
+
//This function prints the contents from the info parammeter passed
function restore_print_info ($info) {
//For each, user, take its info from backup_ids
foreach ($info->users as $userid) {
$rec = backup_getid($restore->backup_unique_code,"user",$userid);
- $user = unserialize($rec->info);
+ //First strip slashes
+ $temp = stripslashes($rec->info);
+ //Now unserialize
+ $user = unserialize($temp);
//Calculate if it is a course user
//Has role teacher or student or admin or coursecreator
$is_course_user = ($user->roles[teacher] or $user->roles[student] or
}
+ //This function creates all the structures for every module in backup file
+ //Depending what has been selected.
+ function restore_create_modules($restore,$xml_file) {
+
+ global $CFG;
+
+ $status = true;
+ //Check it exists
+ if (!file_exists($xml_file)) {
+ $status = false;
+ }
+ //Get info from xml
+ if ($status) {
+ //info will contain the old_id of every module
+ //in backup_ids->info will be the real info (serialized)
+ $info = restore_read_xml_modules($restore,$xml_file);
+ }
+
+ }
+
//=====================================================================================
//== ==
//== XML Functions (SAX) ==
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br>\n"; //Debug
}
+ //This is the startTag handler we use where we are reading the modules zone (todo="MODULES")
+ function startElementModules($parser, $tagName, $attrs) {
+ //Refresh properties
+ $this->level++;
+ $this->tree[$this->level] = $tagName;
+ //Check if we are into MODULES zone
+ //if ($this->tree[3] == "MODULES") //Debug
+ // echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br>\n"; //Debug
+ //If we are under a MOD tag under a MODULES zone, accumule it
+ if (($this->tree[4] == "MOD") and ($this->tree[3] == "MODULES")) {
+ $this->info .= "<".$tagName.">";
+ }
+ }
+
//This is the startTag default handler we use when todo is undefined
function startElement($parser, $tagName, $attrs) {
$this->level++;
switch ($tagName) {
case "USER":
//We've finalized a user, get it and save to db
+ //First serialize
+ $ser_temp = serialize($this->info->tempuser);
+ //Now add slashes
+ $sla_temp = addslashes($ser_temp);
+ //Save to db
backup_putid($this->preferences->backup_unique_code,"user",$this->info->tempuser->id,
- null,serialize($this->info->tempuser));
+ null,$sla_temp);
//Delete temp obejct
unset($this->info->tempuser);
break;
$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
+ if ($this->tree[3] == "MODULES") {
+ //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 it to utf & htmlchars and trim to generate xml data
+ $this->info .= utf8_encode(htmlspecialchars(trim($this->content)))."</".$tagName.">";
+ //If we've finished a mod, xmlize it an save to db
+ if (($this->level == 4) and ($tagName == "MOD")) {
+ //Prepend XML standard header to info gathered
+ $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->info;
+ //Call to xmlize for this portion of xml data (one MOD)
+ $data = xmlize($xml_data);
+ //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 modtype from data
+ $mod_id = $data["MOD"]["#"]["ID"]["0"]["#"];
+ $mod_type = $data["MOD"]["#"]["MODTYPE"]["0"]["#"];
+ //Serialize it
+ $mod_temp = serialize($data);
+ //Now add slashes
+ $sla_mod_temp = addslashes($mod_temp);
+ //Save to db
+ backup_putid($this->preferences->backup_unique_code,$mod_type,$mod_id,
+ null,$sla_mod_temp);
+ //Reset info to empty
+ $this->info = "";
+ }
+
+
+
+
+ }
+
+ //Stop parsing if todo = MODULES and tagName = MODULES (en of the tag, of course)
+ //Speed up a lot (avoid parse all)
+ if ($tagName == "MODULES" and $this->level == 3) {
+ $this->finished = true;
+ }
+
+ //Clear things
+ $this->tree[$this->level] = "";
+ $this->level--;
+ $this->content = "";
+ }
+
//This is the endTag default handler we use when todo is undefined
function endElement($parser, $tagName) {
if (trim($this->content)) //Debug
} else if ($todo == "USERS") {
//Define handlers to that zone
xml_set_element_handler($xml_parser, "startElementUsers", "endElementUsers");
+ } else if ($todo == "MODULES") {
+ //Define handlers to that zone
+ xml_set_element_handler($xml_parser, "startElementModules", "endElementModules");
} else {
//Define default handlers (must no be invoked when everything become finished)
xml_set_element_handler($xml_parser, "startElementInfo", "endElementInfo");