2 //This php script contains all the stuff to backup/restore
5 //This is the "graphical" structure of the attendance mod:
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 function attendance_backup_mods($bf,$preferences) {
30 //Iterate over attendance table
31 $attendances = get_records ("attendance","course",$preferences->backup_course
,"id");
33 foreach ($attendances as $attendance) {
35 fwrite ($bf,start_tag("MOD",3,true));
37 fwrite ($bf,full_tag("ID",4,false,$attendance->id
));
38 fwrite ($bf,full_tag("MODTYPE",4,false,"attendance"));
39 fwrite ($bf,full_tag("NAME",4,false,$attendance->name
));
40 fwrite ($bf,full_tag("DAY",4,false,$attendance->day
));
41 fwrite ($bf,full_tag("HOURS",4,false,$attendance->hours
));
42 fwrite ($bf,full_tag("ROLL",4,false,$attendance->roll
));
43 fwrite ($bf,full_tag("NOTES",4,false,$attendance->notes
));
44 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$attendance->timemodified
));
45 fwrite ($bf,full_tag("DYNSECTION",4,false,$attendance->dynsection
));
46 fwrite ($bf,full_tag("EDITED",4,false,$attendance->edited
));
47 fwrite ($bf,full_tag("AUTOATTEND",4,false,$attendance->autoattend
));
48 //if we've selected to backup users info, then execute backup_attendance_roll
49 if ($preferences->mods
["attendance"]->userinfo
) {
50 $status = backup_attendance_roll($bf,$preferences,$attendance->id
);
53 $status =fwrite ($bf,end_tag("MOD",3,true));
59 //Backup attendance_roll contents (executed from attendance_backup_mods)
60 function backup_attendance_roll ($bf,$preferences,$attendance) {
66 $attendance_rolls = get_records("attendance_roll","dayid",$attendance,"id");
68 if ($attendance_rolls) {
70 $status =fwrite ($bf,start_tag("ROLLS",4,true));
71 //Iterate over each roll
72 foreach ($attendance_rolls as $att_rol) {
74 $status =fwrite ($bf,start_tag("ROLL",5,true));
76 fwrite ($bf,full_tag("ID",6,false,$att_rol->id
));
77 fwrite ($bf,full_tag("USERID",6,false,$att_rol->userid
));
78 fwrite ($bf,full_tag("HOUR",6,false,$att_rol->hour
));
79 fwrite ($bf,full_tag("STATUS",6,false,$att_rol->status
));
80 fwrite ($bf,full_tag("NOTES",6,false,$att_rol->notes
));
82 $status =fwrite ($bf,end_tag("ROLL",5,true));
85 $status =fwrite ($bf,end_tag("ROLLS",4,true));
90 ////Return an array of info (name,value)
91 function attendance_check_backup_mods($course,$user_data=false,$backup_unique_code) {
92 //First the course data
93 $info[0][0] = get_string("modulenameplural","attendance");
94 if ($ids = attendance_ids ($course)) {
95 $info[0][1] = count($ids);
100 //Now, if requested, the user_data
102 $info[1][0] = get_string("entries");
103 if ($ids = attendance_roll_ids_by_course ($course)) {
104 $info[1][1] = count($ids);
117 // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
119 //Returns an array of attendances id
120 function attendance_ids ($course) {
124 return get_records_sql ("SELECT a.id, a.course
125 FROM {$CFG->prefix}attendance a
126 WHERE a.course = '$course'");
129 //Returns an array of attendance_rolls id
130 function attendance_roll_ids_by_course ($course) {
134 return get_records_sql ("SELECT r.id , r.dayid
135 FROM {$CFG->prefix}attendance_roll r,
136 {$CFG->prefix}attendance a
137 WHERE a.course = '$course' AND