Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / attendance / backuplib.php
blob08c49c457d068a260134d407196f92b87e700472
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 function attendance_backup_mods($bf,$preferences) {
26 global $CFG;
28 $status = true;
30 //Iterate over attendance table
31 $attendances = get_records ("attendance","course",$preferences->backup_course,"id");
32 if ($attendances) {
33 foreach ($attendances as $attendance) {
34 //Start mod
35 fwrite ($bf,start_tag("MOD",3,true));
36 //Print choice data
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);
52 //End mod
53 $status =fwrite ($bf,end_tag("MOD",3,true));
56 return $status;
59 //Backup attendance_roll contents (executed from attendance_backup_mods)
60 function backup_attendance_roll ($bf,$preferences,$attendance) {
62 global $CFG;
64 $status = true;
66 $attendance_rolls = get_records("attendance_roll","dayid",$attendance,"id");
67 //If there is rolls
68 if ($attendance_rolls) {
69 //Write start tag
70 $status =fwrite ($bf,start_tag("ROLLS",4,true));
71 //Iterate over each roll
72 foreach ($attendance_rolls as $att_rol) {
73 //Start roll
74 $status =fwrite ($bf,start_tag("ROLL",5,true));
75 //Print roll contents
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));
81 //End roll
82 $status =fwrite ($bf,end_tag("ROLL",5,true));
84 //Write end tag
85 $status =fwrite ($bf,end_tag("ROLLS",4,true));
87 return $status;
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);
96 } else {
97 $info[0][1] = 0;
100 //Now, if requested, the user_data
101 if ($user_data) {
102 $info[1][0] = get_string("entries");
103 if ($ids = attendance_roll_ids_by_course ($course)) {
104 $info[1][1] = count($ids);
105 } else {
106 $info[1][1] = 0;
109 return $info;
117 // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
119 //Returns an array of attendances id
120 function attendance_ids ($course) {
122 global $CFG;
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) {
132 global $CFG;
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
138 r.dayid = a.id");