Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / attendance / restorelib.php
blob316c5c8ff0ef02c35a0fd245b5d6aad5975d950e
1 <?php //$Id$
2 //This php script contains all the stuff to backup/restore
3 //attendance mods
5 //This is the "graphical" structure of the attendance mod:
6 //
7 // attendance
8 // (CL,pk->id)
9 // |
10 // |
11 // |
12 // attendance_roll
13 // (UL,pk->id, fk->dayid)
15 // Meaning: pk->primary key field of the table
16 // fk->foreign key to link with parent
17 // nt->nested field (recursive data)
18 // CL->course level info
19 // UL->user level info
20 // files->table may have files)
22 //-----------------------------------------------------------
24 //This function executes all the restore procedure about this mod
25 function attendance_restore_mods($mod,$restore) {
27 global $CFG;
29 $status = true;
31 //Get record from backup_ids
32 $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
34 if ($data) {
35 //Now get completed xmlized object
36 $info = $data->info;
37 //traverse_xmlize($info); //Debug
38 //print_object ($GLOBALS['traverse_array']); //Debug
39 //$GLOBALS['traverse_array']=""; //Debug
41 //Now, build the ATTENDANCE record structure
42 $attendance->course = $restore->course_id;
43 $attendance->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
44 $attendance->day = backup_todb($info['MOD']['#']['DAY']['0']['#']);
45 $attendance->hours = backup_todb($info['MOD']['#']['HOURS']['0']['#']);
46 $attendance->roll = backup_todb($info['MOD']['#']['ROLL']['0']['#']);
47 $attendance->notes = backup_todb($info['MOD']['#']['NOTES']['0']['#']);
48 $attendance->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
49 $attendance->dynsection = backup_todb($info['MOD']['#']['DYNSECTION']['0']['#']);
50 $attendance->edited = backup_todb($info['MOD']['#']['EDITED']['0']['#']);
51 $attendance->autoattend = backup_todb($info['MOD']['#']['AUTOATTEND']['0']['#']);
53 //The structure is equal to the db, so insert the attendance
54 $newid = insert_record ("attendance",$attendance);
56 //Do some output
57 echo "<li>".get_string("modulename","attendance")." \"".$attendance->name."\"</li>";
58 backup_flush(300);
60 if ($newid) {
61 //We have the newid, update backup_ids
62 backup_putid($restore->backup_unique_code,$mod->modtype,
63 $mod->id, $newid);
64 //Now check if want to restore user data and do it.
65 if ($restore->mods['attendance']->userinfo) {
66 //Restore attendance_roll
67 $status = attendance_roll_restore_mods ($newid,$info,$restore);
69 } else {
70 $status = false;
72 } else {
73 $status = false;
76 return $status;
79 //This function restores the attendance_roll
80 function attendance_roll_restore_mods($attendance_id,$info,$restore) {
82 global $CFG;
84 $status = true;
86 //Get the rolls array
87 $rolls = $info['MOD']['#']['ROLLS']['0']['#']['ROLL'];
89 //Iterate over rolls
90 for($i = 0; $i < sizeof($rolls); $i++) {
91 $rol_info = $rolls[$i];
92 //traverse_xmlize($rol_info); //Debug
93 //print_object ($GLOBALS['traverse_array']); //Debug
94 //$GLOBALS['traverse_array']=""; //Debug
96 //We'll need this later!!
97 $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
98 $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
100 //Now, build the ATTENDANCE_ROLL record structure
101 $roll->dayid = $attendance_id;
102 $roll->userid = backup_todb($rol_info['#']['USERID']['0']['#']);
103 $roll->hour = backup_todb($rol_info['#']['HOUR']['0']['#']);
104 $roll->status = backup_todb($rol_info['#']['STATUS']['0']['#']);
105 $roll->notes = backup_todb($rol_info['#']['NOTES']['0']['#']);
107 //We have to recode the userid field
108 $user = backup_getid($restore->backup_unique_code,"user",$roll->userid);
109 if ($user) {
110 $roll->userid = $user->new_id;
113 //The structure is equal to the db, so insert the attendance_roll
114 $newid = insert_record ("attendance_roll",$roll);
116 //Do some output
117 if (($i+1) % 50 == 0) {
118 echo ".";
119 if (($i+1) % 1000 == 0) {
120 echo "<br />";
122 backup_flush(300);
125 if ($newid) {
126 //We have the newid, update backup_ids
127 backup_putid($restore->backup_unique_code,"attendance_roll",$oldid,
128 $newid);
129 } else {
130 $status = false;
134 return $status;