diff --git a/mod/attendance/backuplib.php b/mod/attendance/backuplib.php new file mode 100644 index 00000000000..3fd1997aeb1 --- /dev/null +++ b/mod/attendance/backuplib.php @@ -0,0 +1,138 @@ +id) + // | + // | + // | + // attendance_roll + // (UL,pk->id, fk->dayid) + // + // Meaning: pk->primary key field of the table + // fk->foreign key to link with parent + // nt->nested field (recursive data) + // CL->course level info + // UL->user level info + // files->table may have files) + // + //----------------------------------------------------------- + + function attendance_backup_mods($bf,$preferences) { + + global $CFG; + + $status = true; + + //Iterate over attendance table + $attendances = get_records ("attendance","course",$preferences->backup_course,"id"); + if ($attendances) { + foreach ($attendances as $attendance) { + //Start mod + fwrite ($bf,start_tag("MOD",3,true)); + //Print choice data + fwrite ($bf,full_tag("ID",4,false,$attendance->id)); + fwrite ($bf,full_tag("MODTYPE",4,false,"attendance")); + fwrite ($bf,full_tag("NAME",4,false,$attendance->name)); + fwrite ($bf,full_tag("DAY",4,false,$attendance->day)); + fwrite ($bf,full_tag("HOURS",4,false,$attendance->hours)); + fwrite ($bf,full_tag("ROLL",4,false,$attendance->roll)); + fwrite ($bf,full_tag("NOTES",4,false,$attendance->notes)); + fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$attendance->timemodified)); + fwrite ($bf,full_tag("DYNSECTION",4,false,$attendance->dynsection)); + //if we've selected to backup users info, then execute backup_attendance_roll + if ($preferences->mods["attendance"]->userinfo) { + $status = backup_attendance_roll($bf,$preferences,$attendance->id); + } + //End mod + $status =fwrite ($bf,end_tag("MOD",3,true)); + } + } + return $status; + } + + //Backup attendance_roll contents (executed from attendance_backup_mods) + function backup_attendance_roll ($bf,$preferences,$attendance) { + + global $CFG; + + $status = true; + + $attendance_rolls = get_records("attendance_roll","dayid",$attendance,"id"); + //If there is rolls + if ($attendance_rolls) { + //Write start tag + $status =fwrite ($bf,start_tag("ROLLS",4,true)); + //Iterate over each roll + foreach ($attendance_rolls as $att_rol) { + //Start roll + $status =fwrite ($bf,start_tag("ROLL",5,true)); + //Print roll contents + fwrite ($bf,full_tag("ID",6,false,$att_rol->id)); + fwrite ($bf,full_tag("USERID",6,false,$att_rol->userid)); + fwrite ($bf,full_tag("HOUR",6,false,$att_rol->hour)); + fwrite ($bf,full_tag("STATUS",6,false,$att_rol->status)); + fwrite ($bf,full_tag("NOTES",6,false,$att_rol->notes)); + //End roll + $status =fwrite ($bf,end_tag("ROLL",5,true)); + } + //Write end tag + $status =fwrite ($bf,end_tag("ROLLS",4,true)); + } + return $status; + } + + ////Return an array of info (name,value) + function attendance_check_backup_mods($course,$user_data=false,$backup_unique_code) { + //First the course data + $info[0][0] = get_string("modulenameplural","attendance"); + if ($ids = attendance_ids ($course)) { + $info[0][1] = count($ids); + } else { + $info[0][1] = 0; + } + + //Now, if requested, the user_data + if ($user_data) { + $info[1][0] = get_string("rolls","attendance"); + if ($ids = attendance_roll_ids_by_course ($course)) { + $info[1][1] = count($ids); + } else { + $info[1][1] = 0; + } + } + return $info; + } + + + + + + + // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE + + //Returns an array of attendances id + function attendance_ids ($course) { + + global $CFG; + + return get_records_sql ("SELECT a.id, a.course + FROM {$CFG->prefix}attendance a + WHERE a.course = '$course'"); + } + + //Returns an array of attendance_rolls id + function attendance_roll_ids_by_course ($course) { + + global $CFG; + + return get_records_sql ("SELECT r.id , r.dayid + FROM {$CFG->prefix}attendance_roll r, + {$CFG->prefix}attendance a + WHERE a.course = '$course' AND + r.dayid = a.id"); + } +?> diff --git a/mod/attendance/restorelib.php b/mod/attendance/restorelib.php new file mode 100644 index 00000000000..e479e83241f --- /dev/null +++ b/mod/attendance/restorelib.php @@ -0,0 +1,139 @@ +id) + // | + // | + // | + // attendance_roll + // (UL,pk->id, fk->dayid) + // + // Meaning: pk->primary key field of the table + // fk->foreign key to link with parent + // nt->nested field (recursive data) + // CL->course level info + // UL->user level info + // files->table may have files) + // + //----------------------------------------------------------- + + //This function executes all the restore procedure about this mod + function attendance_restore_mods($mod,$restore) { + + global $CFG; + + $status = true; + + //Get record from backup_ids + $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id); + + 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 ATTENDANCE record structure + $attendance->course = $restore->course_id; + $attendance->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); + $attendance->day = backup_todb($info['MOD']['#']['DAY']['0']['#']); + $attendance->hours = backup_todb($info['MOD']['#']['HOURS']['0']['#']); + $attendance->roll = backup_todb($info['MOD']['#']['ROLL']['0']['#']); + $attendance->notes = backup_todb($info['MOD']['#']['NOTES']['0']['#']); + $attendance->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); + $attendance->dynsection = backup_todb($info['MOD']['#']['DYNSECTION']['0']['#']); + + //The structure is equal to the db, so insert the attendance + $newid = insert_record ("attendance",$attendance); + + //Do some output + echo "