|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 //Prints course's messages info (tables message, message_read and message_contacts) 00003 function backup_messages ($bf,$preferences) { 00004 global $CFG, $DB; 00005 00006 $status = true; 00007 00009 $unreads = $DB->count_records ('message'); 00010 $reads = $DB->count_records ('message_read'); 00011 $contacts= $DB->count_records ('message_contacts'); 00012 00013 if ($unreads || $reads || $contacts) { 00014 $counter = 0; 00016 fwrite ($bf,start_tag("MESSAGES",2,true)); 00017 00018 if ($unreads) { 00019 $rs_unreads = $DB->get_recordset('message'); 00021 foreach ($rs_unreads as $unread) { 00023 fwrite($bf, start_tag("MESSAGE",3,true)); 00024 fwrite ($bf,full_tag("ID",4,false,$unread->id)); 00025 fwrite ($bf,full_tag("STATUS",4,false,"UNREAD")); 00026 fwrite ($bf,full_tag("USERIDFROM",4,false,$unread->useridfrom)); 00027 fwrite ($bf,full_tag("USERIDTO",4,false,$unread->useridto)); 00028 fwrite ($bf,full_tag("MESSAGE",4,false,$unread->message)); 00029 fwrite ($bf,full_tag("FORMAT",4,false,$unread->format)); 00030 fwrite ($bf,full_tag("TIMECREATED",4,false,$unread->timecreated)); 00031 fwrite ($bf,full_tag("MESSAGETYPE",4,false,$unread->messagetype)); 00033 fwrite ($bf,end_tag("MESSAGE",3,true)); 00034 00036 $counter++; 00037 if ($counter % 20 == 0) { 00038 echo "."; 00039 if ($counter % 400 == 0) { 00040 echo "<br />"; 00041 } 00042 backup_flush(300); 00043 } 00044 } 00045 $rs_unreads->close(); 00046 } 00047 00048 if ($reads) { 00049 $rs_reads = $DB->get_recordset('message_read'); 00051 foreach ($rs_reads as $read) { 00053 fwrite($bf, start_tag("MESSAGE",3,true)); 00054 fwrite ($bf,full_tag("ID",4,false,$read->id)); 00055 fwrite ($bf,full_tag("STATUS",4,false,"READ")); 00056 fwrite ($bf,full_tag("USERIDFROM",4,false,$read->useridfrom)); 00057 fwrite ($bf,full_tag("USERIDTO",4,false,$read->useridto)); 00058 fwrite ($bf,full_tag("MESSAGE",4,false,$read->message)); 00059 fwrite ($bf,full_tag("FORMAT",4,false,$read->format)); 00060 fwrite ($bf,full_tag("TIMECREATED",4,false,$read->timecreated)); 00061 fwrite ($bf,full_tag("MESSAGETYPE",4,false,$read->messagetype)); 00062 fwrite ($bf,full_tag("TIMEREAD",4,false,$read->timeread)); 00063 fwrite ($bf,full_tag("MAILED",4,false,$read->mailed)); 00065 fwrite ($bf,end_tag("MESSAGE",3,true)); 00066 00068 $counter++; 00069 if ($counter % 20 == 0) { 00070 echo "."; 00071 if ($counter % 400 == 0) { 00072 echo "<br />"; 00073 } 00074 backup_flush(300); 00075 } 00076 } 00077 $rs_reads->close(); 00078 } 00079 00080 if ($contacts) { 00081 fwrite($bf, start_tag("CONTACTS",3,true)); 00082 $rs_contacts = $DB->get_recordset('message_contacts'); 00084 foreach ($rs_contacts as $contact) { 00086 fwrite($bf, start_tag("CONTACT",4,true)); 00087 fwrite ($bf,full_tag("ID",5,false,$contact->id)); 00088 fwrite ($bf,full_tag("USERID",5,false,$contact->userid)); 00089 fwrite ($bf,full_tag("CONTACTID",5,false,$contact->contactid)); 00090 fwrite ($bf,full_tag("BLOCKED",5,false,$contact->blocked)); 00092 fwrite ($bf,end_tag("CONTACT",4,true)); 00093 00095 $counter++; 00096 if ($counter % 20 == 0) { 00097 echo "."; 00098 if ($counter % 400 == 0) { 00099 echo "<br />"; 00100 } 00101 backup_flush(300); 00102 } 00103 } 00104 $rs_contacts->close(); 00105 fwrite($bf, end_tag("CONTACTS",3,true)); 00106 } 00107 00109 $status = fwrite ($bf,end_tag("MESSAGES",2,true)); 00110 } 00111 00112 return $status; 00113 00114 } 00115 00116 //Print blogs info (post table, module=blog, course=0) 00117 function backup_blogs($bf, $preferences) { 00118 global $CFG, $DB; 00119 00120 $status = true; 00121 00123 $siteblogs = $DB->count_records('post', array('module'=>'blog', 'courseid'=>0)); 00124 00125 if ($siteblogs) { 00126 $counter = 0; 00128 fwrite ($bf, start_tag("BLOGS",2,true)); 00129 00130 if ($siteblogs) { 00131 $rs_blogs = $DB->get_records('post', array('module'=>'blog', 'courseid'=>0)); 00133 foreach ($rs_blogs as $blog) { 00134 backup_blog($bf, $blog->id, 3); 00135 00137 $counter++; 00138 if ($counter % 20 == 0) { 00139 echo "."; 00140 if ($counter % 400 == 0) { 00141 echo "<br />"; 00142 } 00143 backup_flush(300); 00144 } 00145 } 00146 $rs_blogs-close(); 00147 } 00149 $status = fwrite($bf, end_tag("BLOGS",2,true)); 00150 } 00151 00152 return $status; 00153 } 00154 00155 00156 function backup_blog($bf, $blogid, $level) { 00157 global $DB; 00158 $blog = $DB->get_record('post', array('module'=>'blog', 'id'=>$blogid)); 00159 00161 fwrite($bf, start_tag("BLOG",$level,true)); 00163 fwrite ($bf,full_tag("ID",$level+1,false,$blog->id)); 00164 fwrite ($bf,full_tag("MODULE",$level+1,false,$blog->module)); 00165 fwrite ($bf,full_tag("USERID",$level+1,false,$blog->userid)); 00166 fwrite ($bf,full_tag("COURSEID",$level+1,false,$blog->courseid)); 00167 fwrite ($bf,full_tag("GROUPID",$level+1,false,$blog->groupid)); 00168 fwrite ($bf,full_tag("MODULEID",$level+1,false,$blog->moduleid)); 00169 fwrite ($bf,full_tag("COURSEMODULEID",$level+1,false,$blog->coursemoduleid)); 00170 fwrite ($bf,full_tag("SUBJECT",$level+1,false,$blog->subject)); 00171 fwrite ($bf,full_tag("SUMMARY",$level+1,false,$blog->summary)); 00172 fwrite ($bf,full_tag("CONTENT",$level+1,false,$blog->content)); 00173 fwrite ($bf,full_tag("UNIQUEHASH",$level+1,false,$blog->uniquehash)); 00174 fwrite ($bf,full_tag("RATING",$level+1,false,$blog->rating)); 00175 fwrite ($bf,full_tag("FORMAT",$level+1,false,$blog->format)); 00176 fwrite ($bf,full_tag("ATTACHMENT",$level+1,false,$blog->attachment)); 00177 fwrite ($bf,full_tag("PUBLISHSTATE",$level+1,false,$blog->publishstate)); 00178 fwrite ($bf,full_tag("LASTMODIFIED",$level+1,false,$blog->lastmodified)); 00179 fwrite ($bf,full_tag("CREATED",$level+1,false,$blog->created)); 00180 fwrite ($bf,full_tag("USERMODIFIED",$level+1,false,$blog->usermodified)); 00181 00184 if (!empty($CFG->usetags)) { 00185 if ($tags = tag_get_tags('post', $blog->id)) { //This return them ordered by default 00187 fwrite ($bf,start_tag("BLOG_TAGS",$level+1,true)); 00189 foreach ($tags as $tag) { 00190 fwrite ($bf,start_tag("BLOG_TAG",$level+2,true)); 00191 fwrite ($bf,full_tag("NAME",$level+3,false,$tag->name)); 00192 fwrite ($bf,full_tag("RAWNAME",$level+3,false,$tag->rawname)); 00193 fwrite ($bf,end_tag("BLOG_TAG",$level+2,true)); 00194 } 00196 fwrite ($bf,end_tag("BLOG_TAGS",$level+1,true)); 00197 } 00198 } 00200 fwrite($bf, end_tag("BLOG",$level,true)); 00201 } 00202 00203 //Prints course's format data (any data the format might want to save). 00204 function backup_format_data ($bf,$preferences) { 00205 global $CFG, $DB; 00206 00207 // Check course format 00208 if(!($format = $DB->get_field('course','format', array('id'=>$preferences->backup_course)))) { 00209 return false; 00210 } 00211 // Write appropriate tag. Note that we always put this tag there even if 00212 // blank, it makes parsing easier 00213 fwrite ($bf,start_tag("FORMATDATA",2,true)); 00214 00215 $file=$CFG->dirroot."/course/format/$format/backuplib.php"; 00216 if(file_exists($file)) { 00217 // If the file is there, the function must be or it's an error. 00218 require_once($file); 00219 $function=$format.'_backup_format_data'; 00220 if(!function_exists($function)) { 00221 return false; 00222 } 00223 if(!$function($bf,$preferences)) { 00224 return false; 00225 } 00226 } 00227 00228 // This last return just checks the file writing has been ok (ish) 00229 return fwrite ($bf,end_tag("FORMATDATA",2,true)); 00230 } 00231 00232 function backup_gradebook_categories_history_info($bf, $preferences) { 00233 global $CFG, $DB; 00234 00235 $status = true; 00236 00237 // find all grade categories history 00238 if ($chs = $DB->get_records('grade_categories_history', array('courseid'=>$preferences->backup_course))) { 00239 fwrite ($bf,start_tag("GRADE_CATEGORIES_HISTORIES",3,true)); 00240 foreach ($chs as $ch) { 00241 fwrite ($bf,start_tag("GRADE_CATEGORIES_HISTORY",4,true)); 00242 fwrite ($bf,full_tag("ID",5,false,$ch->id)); 00243 fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); 00244 fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); 00245 fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); 00246 fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); 00247 fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); 00248 fwrite ($bf,full_tag("PARENT",5,false,$ch->parent)); 00249 fwrite ($bf,full_tag("DEPTH",5,false,$ch->depth)); 00250 fwrite ($bf,full_tag("PATH",5,false,$ch->path)); 00251 fwrite ($bf,full_tag("FULLNAME",5,false,$ch->fullname)); 00252 fwrite ($bf,full_tag("AGGRETGATION",5,false,$ch->aggregation)); 00253 fwrite ($bf,full_tag("KEEPHIGH",5,false,$ch->keephigh)); 00254 fwrite ($bf,full_tag("DROPLOW",5,false,$ch->droplow)); 00255 fwrite ($bf,full_tag("AGGREGATEONLYGRADED",5,false,$ch->aggregateonlygraded)); 00256 fwrite ($bf,full_tag("AGGREGATEOUTCOMES",5,false,$ch->aggregateoutcomes)); 00257 fwrite ($bf,full_tag("AGGREGATESUBCATS",5,false,$ch->aggregatesubcats)); 00258 fwrite ($bf,end_tag("GRADE_CATEGORIES_HISTORY",4,true)); 00259 } 00260 $status = fwrite ($bf,end_tag("GRADE_CATEGORIES_HISTORIES",3,true)); 00261 } 00262 return $status; 00263 } 00264 00265 function backup_gradebook_grades_history_info($bf, $preferences) { 00266 global $CFG, $DB; 00267 $status = true; 00268 00269 // find all grade categories history 00270 if ($chs = $DB->get_records_sql("SELECT ggh.* 00271 FROM {grade_grades_history} ggh 00272 JOIN {grade_item} gi ON gi.id = ggh.itemid 00273 WHERE gi.courseid = ?", array($preferences->backup_course))) { 00274 fwrite ($bf,start_tag("GRADE_GRADES_HISTORIES",3,true)); 00275 foreach ($chs as $ch) { 00277 if (backup_getid($preferences->backup_unique_code, 'user', $ch->userid)) { 00278 fwrite ($bf,start_tag("GRADE_GRADES_HISTORY",4,true)); 00279 fwrite ($bf,full_tag("ID",5,false,$ch->id)); 00280 fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); 00281 fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); 00282 fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); 00283 fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); 00284 fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); 00285 fwrite ($bf,full_tag("ITEMID",5,false,$ch->itemid)); 00286 fwrite ($bf,full_tag("USERID",5,false,$ch->userid)); 00287 fwrite ($bf,full_tag("RAWGRADE",5,false,$ch->rawgrade)); 00288 fwrite ($bf,full_tag("RAWGRADEMAX",5,false,$ch->rawgrademax)); 00289 fwrite ($bf,full_tag("RAWGRADEMIN",5,false,$ch->rawgrademin)); 00290 fwrite ($bf,full_tag("RAWSCALEID",5,false,$ch->rawscaleid)); 00291 fwrite ($bf,full_tag("USERMODIFIED",5,false,$ch->usermodified)); 00292 fwrite ($bf,full_tag("FINALGRADE",5,false,$ch->finalgrade)); 00293 fwrite ($bf,full_tag("HIDDEN",5,false,$ch->hidden)); 00294 fwrite ($bf,full_tag("LOCKED",5,false,$ch->locked)); 00295 fwrite ($bf,full_tag("LOCKTIME",5,false,$ch->locktime)); 00296 fwrite ($bf,full_tag("EXPORTED",5,false,$ch->exported)); 00297 fwrite ($bf,full_tag("OVERRIDDEN",5,false,$ch->overridden)); 00298 fwrite ($bf,full_tag("EXCLUDED",5,false,$ch->excluded)); 00299 fwrite ($bf,full_tag("FEEDBACK",5,false,$ch->feedback)); 00300 fwrite ($bf,full_tag("FEEDBACKFORMAT",5,false,$ch->feedbackformat)); 00301 fwrite ($bf,full_tag("INFORMATION",5,false,$ch->information)); 00302 fwrite ($bf,full_tag("INFORMATIONFORMAT",5,false,$ch->informationformat)); 00303 fwrite ($bf,end_tag("GRADE_GRADES_HISTORY",4,true)); 00304 } 00305 } 00306 $status = fwrite ($bf,end_tag("GRADE_GRADES_HISTORIES",3,true)); 00307 } 00308 return $status; 00309 } 00310 00311 function backup_gradebook_items_history_info($bf, $preferences) { 00312 global $CFG, $DB; 00313 $status = true; 00314 00315 // find all grade categories history 00316 if ($chs = $DB->get_records('grade_items_history', array('courseid'=>$preferences->backup_course))) { 00317 fwrite ($bf,start_tag("GRADE_ITEM_HISTORIES",3,true)); 00318 foreach ($chs as $ch) { 00319 fwrite ($bf,start_tag("GRADE_ITEM_HISTORY",4,true)); 00320 fwrite ($bf,full_tag("ID",5,false,$ch->id)); 00321 fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); 00322 fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); 00323 fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); 00324 fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); 00325 fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); 00326 fwrite ($bf,full_tag("CATEGORYID",5,false,$ch->categoryid)); 00327 fwrite ($bf,full_tag("ITEMNAME",5,false,$ch->itemname)); 00328 fwrite ($bf,full_tag("ITEMTYPE",5,false,$ch->itemtype)); 00329 fwrite ($bf,full_tag("ITEMMODULE",5,false,$ch->itemmodule)); 00330 fwrite ($bf,full_tag("ITEMINSTANCE",5,false,$ch->iteminstance)); 00331 fwrite ($bf,full_tag("ITEMNUMBER",5,false,$ch->itemnumber)); 00332 fwrite ($bf,full_tag("ITEMINFO",5,false,$ch->iteminfo)); 00333 fwrite ($bf,full_tag("IDNUMBER",5,false,$ch->idnumber)); 00334 fwrite ($bf,full_tag("CALCULATION",5,false,$ch->calculation)); 00335 fwrite ($bf,full_tag("GRADETYPE",5,false,$ch->gradetype)); 00336 fwrite ($bf,full_tag("GRADEMAX",5,false,$ch->grademax)); 00337 fwrite ($bf,full_tag("GRADEMIN",5,false,$ch->grademin)); 00338 fwrite ($bf,full_tag("SCALEID",5,false,$ch->scaleid)); 00339 fwrite ($bf,full_tag("OUTCOMEID",5,false,$ch->outcomeid)); 00340 fwrite ($bf,full_tag("GRADEPASS",5,false,$ch->gradepass)); 00341 fwrite ($bf,full_tag("MULTFACTOR",5,false,$ch->multfactor)); 00342 fwrite ($bf,full_tag("PLUSFACTOR",5,false,$ch->plusfactor)); 00343 fwrite ($bf,full_tag("AGGREGATIONCOEF",5,false,$ch->aggregationcoef)); 00344 fwrite ($bf,full_tag("SORTORDER",5,false,$ch->sortorder)); 00345 //fwrite ($bf,full_tag("DISPLAY",7,false,$ch->display)); 00346 //fwrite ($bf,full_tag("DECIMALS",7,false,$ch->decimals)); 00347 fwrite ($bf,full_tag("HIDDEN",5,false,$ch->hidden)); 00348 fwrite ($bf,full_tag("LOCKED",5,false,$ch->locked)); 00349 fwrite ($bf,full_tag("LOCKTIME",5,false,$ch->locktime)); 00350 fwrite ($bf,full_tag("NEEDSUPDATE",5,false,$ch->needsupdate)); 00351 fwrite ($bf,end_tag("GRADE_ITEM_HISTORY",4,true)); 00352 } 00353 $status = fwrite ($bf,end_tag("GRADE_ITEM_HISTORIES",3,true)); 00354 00355 } 00356 return $status; 00357 } 00358 00359 function backup_gradebook_outcomes_history($bf, $preferences) { 00360 global $CFG, $DB; 00361 $status = true; 00362 00363 // find all grade categories history 00364 if ($chs = $DB->get_records('grade_outcomes_history', array('courseid'=>$preferences->backup_course))) { 00365 fwrite ($bf,start_tag("GRADE_OUTCOME_HISTORIES",3,true)); 00366 foreach ($chs as $ch) { 00367 fwrite ($bf,start_tag("GRADE_OUTCOME_HISTORY",4,true)); 00368 fwrite ($bf,full_tag("ID",5,false,$ch->id)); 00369 fwrite ($bf,full_tag("OLDID",5,false,$ch->oldid)); 00370 fwrite ($bf,full_tag("ACTION",5,false,$ch->action)); 00371 fwrite ($bf,full_tag("SOURCE",5,false,$ch->source)); 00372 fwrite ($bf,full_tag("TIMEMODIFIED",5,false,$ch->timemodified)); 00373 fwrite ($bf,full_tag("LOGGEDUSER",5,false,$ch->loggeduser)); 00374 fwrite ($bf,full_tag("SHORTNAME",5,false,$ch->shortname)); 00375 fwrite ($bf,full_tag("FULLNAME",5,false,$ch->fullname)); 00376 fwrite ($bf,full_tag("SCALEID",5,false,$ch->scaleid)); 00377 fwrite ($bf,full_tag("DESCRIPTION",5,false,$ch->description)); 00378 fwrite ($bf,end_tag("GRADE_OUTCOME_HISTORY",4,true)); 00379 } 00380 $status = fwrite ($bf,end_tag("GRADE_OUTCOME_HISTORIES",3,true)); 00381 } 00382 return $status; 00383 } 00384 00385 //Backup events info (course events) 00386 function backup_events_info($bf,$preferences) { 00387 global $CFG, $DB; 00388 00389 $status = true; 00390 00391 //Counter, points to current record 00392 $counter = 0; 00393 00394 //Get events (course events) 00395 $events = $DB->get_records("event", array("courseid"=>$preferences->backup_course, 'instance'=>0),"id"); 00396 00397 //Pring events header 00398 if ($events) { 00399 //Pring events header 00400 fwrite ($bf,start_tag("EVENTS",2,true)); 00401 //Iterate 00402 foreach ($events as $event) { 00403 //Begin event tag 00404 fwrite ($bf,start_tag("EVENT",3,true)); 00405 //Output event tag 00406 fwrite ($bf,full_tag("ID",4,false,$event->id)); 00407 fwrite ($bf,full_tag("NAME",4,false,$event->name)); 00408 fwrite ($bf,full_tag("DESCRIPTION",4,false,$event->description)); 00409 fwrite ($bf,full_tag("FORMAT",4,false,$event->format)); 00410 fwrite ($bf,full_tag("GROUPID",4,false,$event->groupid)); 00411 fwrite ($bf,full_tag("USERID",4,false,$event->userid)); 00412 fwrite ($bf,full_tag("REPEATID",4,false,$event->repeatid)); 00413 fwrite ($bf,full_tag("EVENTTYPE",4,false,$event->eventtype)); 00414 fwrite ($bf,full_tag("MODULENAME",4,false,$event->modulename)); 00415 fwrite ($bf,full_tag("TIMESTART",4,false,$event->timestart)); 00416 fwrite ($bf,full_tag("TIMEDURATION",4,false,$event->timeduration)); 00417 fwrite ($bf,full_tag("VISIBLE",4,false,$event->visible)); 00418 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$event->timemodified)); 00419 //End event tag 00420 fwrite ($bf,end_tag("EVENT",3,true)); 00421 } 00422 //End events tag 00423 $status = fwrite ($bf,end_tag("EVENTS",2,true)); 00424 } 00425 return $status; 00426 }