Some additions
[moodle.git] / backup / lib.php
CommitLineData
afbe3de8 1<?PHP //$Id$
2 //This file contains all the function needed in the backup/restore utility
3 //except the mod-related funtions that are into every backuplib.php inside
4 //every mod directory
5
6 //Insert necessary category ids to backup_ids table
7 function insert_category_ids ($course,$backup_unique_code) {
8 global $CFG;
9 $status = true;
10 $status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids
11 (backup_code, table_name, old_id)
12 SELECT DISTINCT '$backup_unique_code','quiz_categories',t.category
13 FROM {$CFG->prefix}quiz_questions t,
14 {$CFG->prefix}quiz_question_grades g,
15 {$CFG->prefix}quiz q
16 WHERE q.course = '$course' AND
17 g.quiz = q.id AND
18 g.question = t.id",false);
19 return $status;
20 }
21
22 //Delete category ids from backup_ids table
23 function delete_category_ids ($backup_unique_code) {
24 global $CFG;
25 $status = true;
26 $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids
27 WHERE backup_code = '$backup_unique_code'",false);
28 return $status;
29 }
1b502431 30
31 //Calculate the number of users to backup and put their ids in backup_ids
32 //Return an array of info (name,value)
33 function user_check_backup($course,$backup_unique_code,$backup_users) {
34 //$backup_users=0-->all
35 // 1-->course
36 // 2-->needed-->NOT IMPLEMEMTED
37
38 global $CFG;
cfb9c525 39 global $db;
1b502431 40
cfb9c525 41 $count_users = 0;
42
43 //Select all users from user
44 $users = get_records ("user");
45 //Iterate over users putting their roles
46 foreach ($users as $user) {
47 $user->info = "";
48 //Is Admin in tables (not is_admin()) !!
49 if (record_exists("user_admins","userid",$user->id)) {
50 $user->info .= "admin";
51 $user->role_admin = true;
52 }
53 //Is Course Creator in tables (not is_coursecreator()) !!
54 if (record_exists("user_coursecreators","userid",$user->id)) {
55 $user->info .= "coursecreator";
56 $user->role_coursecreator = true;
57 }
58 //Is Teacher in tables (not is_teacher()) !!
59 if (record_exists("user_teachers","course",$course,"userid",$user->id)) {
60 $user->info .= "teacher";
61 $user->role_teacher = true;
62 }
63 //Is Student in tables (not is_student()) !!
64 if (record_exists("user_students","course",$course,"userid",$user->id)) {
65 $user->info .= "student";
66 $user->role_student = true;
67 }
68 //Now create the backup_id record
69 $backupids_rec->backup_code = $backup_unique_code;
70 $backupids_rec->table_name = "user";
71 $backupids_rec->old_id = $user->id;
72 $backupids_rec->info = $user->info;
73
74 //Insert the record id. backup_users decide it.
75 //When all users
76 if ($backup_users == 0) {
77 $status = insert_record("backup_ids",$backupids_rec,false);
78 $count_users++;
79 //When course users
80 } else if ($backup_users == 1) {
81 //Only if user has any role
82 if ($backupids_rec->info) {
83 $status = insert_record("backup_ids",$backupids_rec,false);
84 $count_users++;
85 }
86 }
1b502431 87 }
cfb9c525 88
89 //Prepare Info
1b502431 90 //Gets the user data
91 $info[0][0] = get_string("users");
cfb9c525 92 $info[0][1] = $count_users;
1b502431 93
94 return $info;
95 }
afbe3de8 96
3868b9c6 97 //Calculate the number of log entries to backup
98 //Return an array of info (name,value)
99 function log_check_backup($course) {
100
101 global $CFG;
102
103 //Execute the insert
104 $status = execute_sql($sql_insert,false);
105
106 //Now execute the select
107 $ids = get_records_sql("SELECT DISTINCT l.id,l.course
108 FROM {$CFG->prefix}log l
109 WHERE l.course = '$course'");
110 //Gets the user data
111 $info[0][0] = get_string("logs");
112 if ($ids) {
113 $info[0][1] = count($ids);
114 } else {
115 $info[0][1] = 0;
116 }
117
118 return $info;
119 }
120
121 //Calculate the number of user files to backup
122 //Under $CFG->dataroot/users
123 //and put them (their path) in backup_ids
124 //Return an array of info (name,value)
125 function user_files_check_backup($course,$backup_unique_code) {
126
127 global $CFG;
128
129 $rootdir = $CFG->dataroot."/users";
52b53862 130 //Check if directory exists
131 if (is_dir($rootdir)) {
132 $coursedirs = get_directory_list($rootdir);
133 foreach ($coursedirs as $dir) {
134 //Extracts user id from file path
135 $tok = strtok($dir,"/");
136 if ($tok) {
137 $userid = $tok;
138 } else {
139 $tok = "";
140 }
141 //Insert them into backup_files
142 $status = execute_sql("INSERT INTO {$CFG->prefix}backup_files
143 (backup_code, file_type, path, old_id)
144 VALUES
145 ('$backup_unique_code','user','$dir','$userid')",false);
3868b9c6 146 }
3868b9c6 147 }
148
149 //Now execute the select
150 $ids = get_records_sql("SELECT DISTINCT b.path, b.old_id
151 FROM {$CFG->prefix}backup_files b
152 WHERE backup_code = '$backup_unique_code' AND
153 file_type = 'user'");
154 //Gets the user data
155 $info[0][0] = get_string("files");
156 if ($ids) {
157 $info[0][1] = count($ids);
158 } else {
159 $info[0][1] = 0;
160 }
161
162 return $info;
163 }
164
165 //Calculate the number of course files to backup
166 //under $CFG->dataroot/$course, except $CFG->moddata
167 //and put them (their path) in backup_ids
168 //Return an array of info (name,value)
169 function course_files_check_backup($course,$backup_unique_code) {
170
171 global $CFG;
172
173 $rootdir = $CFG->dataroot."/$course";
52b53862 174 //Check if directory exists
175 if (is_dir($rootdir)) {
176 $coursedirs = get_directory_list($rootdir,$CFG->moddata);
177 foreach ($coursedirs as $dir) {
178 //Insert them into backup_files
179 $status = execute_sql("INSERT INTO {$CFG->prefix}backup_files
180 (backup_code, file_type, path)
181 VALUES
182 ('$backup_unique_code','course','$dir')",false);
183 }
3868b9c6 184 }
185
186 //Now execute the select
187 $ids = get_records_sql("SELECT DISTINCT b.path, b.old_id
188 FROM {$CFG->prefix}backup_files b
189 WHERE backup_code = '$backup_unique_code' AND
190 file_type = 'course'");
191 //Gets the user data
192 $info[0][0] = get_string("files");
193 if ($ids) {
194 $info[0][1] = count($ids);
195 } else {
196 $info[0][1] = 0;
197 }
198
199 return $info;
200 }
b0778a76 201
202 //Delete old data in backup tables (if exists)
203 //Two days seems to be apropiate
204 function backup_delete_old_data() {
674b30f5 205
206 global $CFG;
207
b0778a76 208 //Change this if you want !!
3b8bad6f 209 $days = 1;
b0778a76 210 //End change this
674b30f5 211 $seconds = $days * 24 * 60 * 60;
b0778a76 212 $delete_from = time()-$seconds;
213 //Now delete from tables
674b30f5 214 $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids
215 WHERE backup_code < '$delete_from'",false);
216 if ($status) {
217 $status = execute_sql("DELETE FROM {$CFG->prefix}backup_files
218 WHERE backup_code < '$delete_from'",false);
219 }
3b8bad6f 220 //Now, delete old directory (if exists)
221 if ($status) {
222 $status = backup_delete_old_dirs($delete_from);
223 }
b0778a76 224 return($status);
225 }
674b30f5 226
3b8bad6f 227 //Function to delete dirs/files into temp/backup directory
228 //older than $delete_from
229 function backup_delete_old_dirs($delete_from) {
230
231 global $CFG;
232
233 $status = true;
234 $list = get_directory_list($CFG->dataroot."/temp/backup", "", false);
235 foreach ($list as $file) {
236 $file_path = $CFG->dataroot."/temp/backup/".$file;
237 $moddate = filemtime($file_path);
238 if ($status and $moddate < $delete_from) {
cfb9c525 239 //If directory, recurse
240 if (is_dir($file_path)) {
241 $status = delete_dir_contents($file_path);
242 //There is nothing, delete the directory itself
243 if ($status) {
244 $status = rmdir($file_path);
245 }
246 //If file
247 } else {
248 unlink("$file_path");
3b8bad6f 249 }
250 }
251 }
252
253 return $status;
254 }
255
674b30f5 256 //Function to check if a directory exists
257 //and, optionally, create it
258 function check_dir_exists($dir,$create=false) {
259
260 global $CFG;
261
262 $status = true;
263 if(!is_dir($dir)) {
264 if (!$create) {
265 $status = false;
266 } else {
267 $status = mkdir ($dir,$CFG->directorypermissions);
268 }
269 }
270 return $status;
271 }
272
273 //Function to check and create the needed dir to
274 //save all the backup
275 function check_and_create_backup_dir($backup_unique_code) {
276
277 global $CFG;
278
279 $status = check_dir_exists($CFG->dataroot."/temp",true);
280 if ($status) {
281 $status = check_dir_exists($CFG->dataroot."/temp/backup",true);
282 }
283 if ($status) {
284 $status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code,true);
285 }
286
287 return $status;
288 }
289
290 //Function to delete all the directory contents recursively
291 //Copied from admin/delete.php
292 function delete_dir_contents ($rootdir) {
293
294 $dir = opendir($rootdir);
295
296 $status = true;
297
298 while ($file = readdir($dir)) {
299 if ($file != "." and $file != "..") {
300 $fullfile = "$rootdir/$file";
301 if (filetype($fullfile) == "dir") {
302 delete_dir_contents($fullfile);
303 if (!rmdir($fullfile)) {
3b8bad6f 304 $status = false;
674b30f5 305 }
306 } else {
307 if (!unlink("$fullfile")) {
3b8bad6f 308 $status = false;
674b30f5 309 }
310 }
311 }
312 }
313 closedir($dir);
314
315 return $status;
316
317 }
318
319 //Function to clear (empty) the contents of the backup_dir
320 //Copied from admin/delete.php
321 function clear_backup_dir($backup_unique_code) {
322
323 global $CFG;
324
325 $rootdir = $CFG->dataroot."/temp/backup/".$backup_unique_code;
326
327 //Delete recursively
328 $status = delete_dir_contents($rootdir);
329
330 return $status;
331 }
3b8bad6f 332
333 //Function to create, open and write header of the xml file
334 function backup_open_xml($backup_unique_code) {
335
336 global $CFG;
337
338 $status = true;
339
340 //Open for writing
cfb9c525 341
3b8bad6f 342 $file = $CFG->dataroot."/temp/backup/".$backup_unique_code."/moodle.xml";
343 $backup_file = fopen($file,"w");
344 //Writes the header
345 $status = fwrite ($backup_file,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
346 if ($status) {
347 $status = fwrite ($backup_file,start_tag("MOODLE_BACKUP",0,true));
348 }
349 if ($status) {
350 return $backup_file;
351 } else {
352 return false;
353 }
354 }
355
356 //Close the file
357 function backup_close_xml($backup_file) {
358 $status = fwrite ($backup_file,end_tag("MOODLE_BACKUP",0,true));
359 return fclose($backup_file);
360 }
361
362 //Return the xml start tag
363 function start_tag($tag,$level=0,$endline=false) {
364 if ($endline) {
365 $endchar = "\n";
366 } else {
367 $endchar = "";
368 }
369 return str_repeat(" ",$level*2)."<".strtoupper($tag).">".$endchar;
370 }
371
372 //Return the xml end tag
373 function end_tag($tag,$level=0,$endline=true) {
374 if ($endline) {
375 $endchar = "\n";
376 } else {
377 $endchar = "";
378 }
379 return str_repeat(" ",$level*2)."</".strtoupper($tag).">".$endchar;
380 }
381
382 //Return the start tag, the contents and the end tag
383 function full_tag($tag,$level=0,$endline=true,$content,$to_utf=true) {
384 $st = start_tag($tag,$level,$endline);
385 $co="";
386 if ($to_utf) {
52b53862 387 $co = utf8_encode(htmlspecialchars($content));
3b8bad6f 388 } else {
52b53862 389 $co = htmlspecialchars($content);
3b8bad6f 390 }
391 $et = end_tag($tag,0,true);
392 return $st.$co.$et;
393 }
394
395 //Prints General info about the course
396 //name, moodle_version (internal and release), backup_version, date, info in file...
397 function backup_general_info ($bf,$preferences) {
674b30f5 398
3b8bad6f 399 global $CFG;
400
401 fwrite ($bf,start_tag("INFO",1,true));
402
403 //The name of the backup
404 fwrite ($bf,full_tag("NAME",2,false,$preferences->backup_name));
405 //The moodle_version
406 fwrite ($bf,full_tag("MOODLE_VERSION",2,false,$preferences->moodle_version));
407 fwrite ($bf,full_tag("MOODLE_RELEASE",2,false,$preferences->moodle_release));
408 //The backup_version
409 fwrite ($bf,full_tag("BACKUP_VERSION",2,false,$preferences->backup_version));
410 fwrite ($bf,full_tag("BACKUP_RELEASE",2,false,$preferences->backup_release));
411 //The date
412 fwrite ($bf,full_tag("DATE",2,false,$preferences->backup_unique_code));
413 //Te includes tag
414 fwrite ($bf,start_tag("DETAILS",2,true));
415 //Now, go to mod element of preferences to print its status
416 foreach ($preferences->mods as $element) {
417 //Calculate info
418 $included = "false";
419 $userinfo = "false";
420 if ($element->backup) {
421 $included = "true";
422 if ($element->userinfo) {
423 $userinfo = "true";
424 }
425 }
426 //Prints the mod start
427 fwrite ($bf,start_tag("MOD",3,true));
428 fwrite ($bf,full_tag("NAME",4,false,$element->name));
429 fwrite ($bf,full_tag("INCLUDED",4,false,$included));
430 fwrite ($bf,full_tag("USERINFO",4,false,$userinfo));
431
432 //Print the end
433 fwrite ($bf,end_tag("MOD",3,true));
434 }
435 //The user in backup
436 if ($preferences->backup_users == 1) {
52b53862 437 fwrite ($bf,full_tag("USERS",3,false,"course"));
3b8bad6f 438 } else {
52b53862 439 fwrite ($bf,full_tag("USERS",3,false,"all"));
3b8bad6f 440 }
441 //The logs in backup
442 if ($preferences->backup_logs == 1) {
443 fwrite ($bf,full_tag("LOGS",3,false,"true"));
444 } else {
445 fwrite ($bf,full_tag("LOGS",3,false,"false"));
446 }
447 //The user files
448 if ($preferences->backup_user_files == 1) {
449 fwrite ($bf,full_tag("USERFILES",3,false,"true"));
450 } else {
451 fwrite ($bf,full_tag("USERFILES",3,false,"false"));
452 }
453 //The course files
454 if ($preferences->backup_course_files == 1) {
455 fwrite ($bf,full_tag("COURSEFILES",3,false,"true"));
456 } else {
457 fwrite ($bf,full_tag("COURSEFILES",3,false,"false"));
458 }
459
460 fwrite ($bf,end_tag("DETAILS",2,true));
461
462
52b53862 463 $status = fwrite ($bf,end_tag("INFO",1,true));
464
465 return $status;
466 }
467
468 //Prints course's general info (table course)
469 function backup_course_start ($bf,$preferences) {
470
471 global $CFG;
472
473 $status = true;
474
475 //Course open tag
476 fwrite ($bf,start_tag("COURSE",1,true));
477
478 //Get info from course
479 $course=false;
480 if ($courses = get_records("course","id",$preferences->backup_course)) {
481 $course = $courses[$preferences->backup_course];
482 }
483 if ($course) {
484 //Prints course info
485 fwrite ($bf,full_tag("ID",2,false,$course->id));
486 //Obtain the category
487 $category = false;
488 if ($categories = get_records("course_categories","id","$course->category")) {
489 $category = $categories[$course->category];
490 }
491 if ($category) {
492 //Prints category info
493 fwrite ($bf,start_tag("CATEGORY",2,true));
494 fwrite ($bf,full_tag("ID",3,false,$course->category));
495 fwrite ($bf,full_tag("NAME",3,false,$category->name));
496 fwrite ($bf,end_tag("CATEGORY",2,true));
497 }
498 //Continues with the course
499 fwrite ($bf,full_tag("PASSWORD",2,false,$course->password));
500 fwrite ($bf,full_tag("FULLNAME",2,false,$course->fullname));
501 fwrite ($bf,full_tag("SHORTNAME",2,false,$course->shortname));
502 fwrite ($bf,full_tag("SUMMARY",2,false,$course->summary));
503 fwrite ($bf,full_tag("FORMAT",2,false,$course->format));
504 fwrite ($bf,full_tag("NEWSITEMS",2,false,$course->newsitems));
505 fwrite ($bf,full_tag("TEACHER",2,false,$course->teacher));
506 fwrite ($bf,full_tag("TEACHERS",2,false,$course->teachers));
507 fwrite ($bf,full_tag("STUDENT",2,false,$course->student));
508 fwrite ($bf,full_tag("STUDENTS",2,false,$course->students));
509 fwrite ($bf,full_tag("GUEST",2,false,$course->guest));
510 fwrite ($bf,full_tag("STARDATE",2,false,$course->stardate));
511 fwrite ($bf,full_tag("NUMSECTIONS",2,false,$course->numsections));
512 fwrite ($bf,full_tag("SHOWRECENT",2,false,$course->showrecent));
513 fwrite ($bf,full_tag("MARKER",2,false,$course->marker));
514 fwrite ($bf,full_tag("TIMECREATED",2,false,$course->timecreated));
515 $status = fwrite ($bf,full_tag("TIMEMODIFIED",2,false,$course->timemodified));
516 } else {
517 $status = false;
518 }
519
520 return $status;
521 }
522
523 //Prints course's end tag
524 function backup_course_end ($bf,$preferences) {
525
526 //Course end tag
527 $status = fwrite ($bf,end_tag("COURSE",1,true));
528
529 return $status;
530
531 }
532
533 //Prints course's sections info (table course_sections)
cfb9c525 534 function backup_course_sections ($bf,$preferences) {
52b53862 535
536 global $CFG;
537
538 $status = true;
539
540
541 //Get info from sections
542 $section=false;
543 if ($sections = get_records("course_sections","course",$preferences->backup_course,"section")) {
544 //Section open tag
545 fwrite ($bf,start_tag("SECTIONS",2,true));
546 //Iterate over every section (ordered by section)
547 foreach ($sections as $section) {
548 //Begin Section
549 fwrite ($bf,start_tag("SECTION",3,true));
550 fwrite ($bf,full_tag("ID",4,false,$section->id));
551 fwrite ($bf,full_tag("NUMBER",4,false,$section->section));
552 fwrite ($bf,full_tag("SUMMARY",4,false,$section->summary));
553 fwrite ($bf,full_tag("VISIBLE",4,false,$section->visible));
cfb9c525 554 //Now print the mods in section
555 backup_course_modules ($bf,$preferences,$section);
52b53862 556 //End section
cfb9c525 557 fwrite ($bf,end_tag("SECTION",3,true));
52b53862 558 }
559 //Section close tag
560 $status = fwrite ($bf,end_tag("SECTIONS",2,true));
561 }
562
563 return $status;
564
3b8bad6f 565 }
cfb9c525 566
567 //Prints course's modules info (table course_modules)
568 //Only for selected mods in preferences
569 function backup_course_modules ($bf,$preferences,$section) {
570
571 global $CFG;
572
573 $status = true;
574
575 $first_record = true;
576
577 //Now print the mods in section
578 //Extracts mod id from sequence
579 $tok = strtok($section->sequence,",");
580 while ($tok) {
581 //Get module's type
582 $moduletype = get_module_type ($preferences->backup_course,$tok);
583 //Check if we've selected to backup that type
584 if ($moduletype and $preferences->mods[$moduletype]->backup) {
585 $selected = true;
586 } else {
587 $selected = false;
588 }
589
590 if ($selected) {
591 //Gets course_module data from db
592 $course_module = get_records ("course_modules","id",$tok);
593 //If it's the first, pring MODS tag
594 if ($first_record) {
595 fwrite ($bf,start_tag("MODS",4,true));
596 $first_record = false;
597 }
598 //Print mod info from course_modules
599 fwrite ($bf,start_tag("MOD",5,true));
600 //Save neccesary info to backup_ids
601 fwrite ($bf,full_tag("ID",6,false,$tok));
602 fwrite ($bf,full_tag("TYPE",6,false,$moduletype));
603 fwrite ($bf,full_tag("INSTANCE",6,false,$course_module[$tok]->instance));
604 fwrite ($bf,full_tag("DELETED",6,false,$course_module[$tok]->deleted));
605 fwrite ($bf,full_tag("SCORE",6,false,$course_module[$tok]->score));
606 fwrite ($bf,full_tag("VISIBLE",6,false,$course_module[$tok]->visible));
607 fwrite ($bf,end_tag("MOD",5,true));
608 }
609 //check for next
610 $tok = strtok(",");
611 }
612
613 //Si ha habido modulos, final de MODS
614 if (!$first_record) {
615 $status =fwrite ($bf,end_tag("MODS",4,true));
616 }
617
618 return $status;
619 }
620
621 //Returns the module type of a course_module's id in a course
622 function get_module_type ($courseid,$moduleid) {
623
624 global $CFG;
625
626 $results = get_records_sql ("SELECT cm.id, m.name
627 FROM {$CFG->prefix}course_modules cm,
628 {$CFG->prefix}modules m
629 WHERE cm.course = '$courseid' AND
630 cm.id = '$moduleid' AND
631 m.id = cm.module");
632
633 if ($results) {
634 $name = $results[$moduleid]->name;
635 } else {
636 $name = false;
637 }
638
639
640 return $name;
641 }
642
643 //Print users to xml
644 //Only users previously calculated in backup_ids will output
645 //
646 function backup_user_info ($bf,$preferences) {
647
648 global $CFG;
649
650 $status = true;
651
652 $users = get_records_sql("SELECT u.old_id, u.table_name,u.info
653 FROM {$CFG->prefix}backup_ids u
654 WHERE u.backup_code = '$preferences->backup_unique_code' AND
655 u.table_name = 'user'");
656
657 //If we have users to backup
658 if ($users) {
659 //Begin Users tag
660 fwrite ($bf,start_tag("USERS",2,true));
661 //With every user
662 foreach ($users as $user) {
663 //Get user data from table
664 $user_data = get_record("user","id",$user->old_id);
665 //Begin User tag
666 fwrite ($bf,start_tag("USER",3,true));
667 //Output all user data
668 fwrite ($bf,full_tag("ID",4,false,$user_data->id));
669 fwrite ($bf,full_tag("CONFIRMED",4,false,$user_data->confirmed));
670 fwrite ($bf,full_tag("DELETED",4,false,$user_data->deleted));
671 fwrite ($bf,full_tag("USERNAME",4,false,$user_data->username));
672 fwrite ($bf,full_tag("PASSWORD",4,false,$user_data->password));
673 fwrite ($bf,full_tag("IDNUMBER",4,false,$user_data->idnumber));
674 fwrite ($bf,full_tag("FIRSTNAME",4,false,$user_data->firsname));
675 fwrite ($bf,full_tag("LASTNAME",4,false,$user_data->lastname));
676 fwrite ($bf,full_tag("EMAIL",4,false,$user_data->email));
677 fwrite ($bf,full_tag("ICQ",4,false,$user_data->icq));
678 fwrite ($bf,full_tag("PHONE1",4,false,$user_data->phone1));
679 fwrite ($bf,full_tag("PHONE2",4,false,$user_data->phone2));
680 fwrite ($bf,full_tag("INSTITUTION",4,false,$user_data->institution));
681 fwrite ($bf,full_tag("DEPARTMENT",4,false,$user_data->department));
682 fwrite ($bf,full_tag("ADDRESS",4,false,$user_data->address));
683 fwrite ($bf,full_tag("CITY",4,false,$user_data->city));
684 fwrite ($bf,full_tag("COUNTRY",4,false,$user_data->country));
685 fwrite ($bf,full_tag("LANG",4,false,$user_data->lang));
686 fwrite ($bf,full_tag("TIMEZONE",4,false,$user_data->timezone));
687 fwrite ($bf,full_tag("FIRSTACCESS",4,false,$user_data->firstaccess));
688 fwrite ($bf,full_tag("LASTACCESS",4,false,$user_data->lastaccess));
689 fwrite ($bf,full_tag("LASTLOGIN",4,false,$user_data->lastlogin));
690 fwrite ($bf,full_tag("CURRENTLOGIN",4,false,$user_data->currentlogin));
691 fwrite ($bf,full_tag("LASTIP",4,false,$user_data->lastIP));
692 fwrite ($bf,full_tag("SECRET",4,false,$user_data->secret));
693 fwrite ($bf,full_tag("PICTURE",4,false,$user_data->picture));
694 fwrite ($bf,full_tag("URL",4,false,$user_data->url));
695 fwrite ($bf,full_tag("DESCRIPTION",4,false,$user_data->description));
696 fwrite ($bf,full_tag("MAILFORMAT",4,false,$user_data->mailformat));
697 fwrite ($bf,full_tag("MAILDISPLAY",4,false,$user_data->maildisplay));
698 fwrite ($bf,full_tag("HTMLEDITOR",4,false,$user_data->htmleditor));
699 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$user_data->timemodified));
700
701 //Output every user role (with its associated info)
702 $user->isadmin = strpos($user->info,"admin");
703 $user->iscoursecreator = strpos($user->info,"coursecreator");
704 $user->isteacher = strpos($user->info,"teacher");
705 $user->isstudent = strpos($user->info,"student");
706 if ($user->isadmin!==false or
707 $user->iscoursecreator!==false or
708 $user->isteacher!==false or
709 $user->isstudent!==false) {
710 //Begin ROLES tag
711 fwrite ($bf,start_tag("ROLES",4,true));
712 //PRINT ROLE INFO
713 //Admins
714 if ($user->isadmin!==false) {
715 //Print ROLE start
716 fwrite ($bf,start_tag("ROLE",5,true));
717 //Print Role info
718 fwrite ($bf,full_tag("TYPE",6,false,"admin"));
719 //Print ROLE end
720 fwrite ($bf,end_tag("ROLE",5,true));
721 }
722 //CourseCreator
723 if ($user->iscoursecreator!==false) {
724 //Print ROLE start
725 fwrite ($bf,start_tag("ROLE",5,true));
726 //Print Role info
727 fwrite ($bf,full_tag("TYPE",6,false,"coursecreator"));
728 //Print ROLE end
729 fwrite ($bf,end_tag("ROLE",5,true));
730 }
731 //Teacher
732 if ($user->isteacher!==false) {
733 //Print ROLE start
734 fwrite ($bf,start_tag("ROLE",5,true));
735 //Print Role info
736 fwrite ($bf,full_tag("TYPE",6,false,"teacher"));
737 //Get specific info for teachers
738 $tea = get_record("user_teachers","userid",$user->old_id,"course",$preferences->backup_course);
739 fwrite ($bf,full_tag("AUTHORITY",6,false,$tea->authority));
740 fwrite ($bf,full_tag("TEA_ROLE",6,false,$tea->role));
741 //Print ROLE end
742 fwrite ($bf,end_tag("ROLE",5,true));
743 }
744 //Student
745 if ($user->isstudent!==false) {
746 //Print ROLE start
747 fwrite ($bf,start_tag("ROLE",5,true));
748 //Print Role info
749 fwrite ($bf,full_tag("TYPE",6,false,"student"));
750 //Get specific info for students
751 $stu = get_record("user_students","userid",$user->old_id,"course",$preferences->backup_course);
752 fwrite ($bf,full_tag("TIMESTART",6,false,$stu->timestart));
753 fwrite ($bf,full_tag("TIMEEND",6,false,$stu->timeend));
754 fwrite ($bf,full_tag("TIME",6,false,$stu->time));
755 //Print ROLE end
756 fwrite ($bf,end_tag("ROLE",5,true));
757 }
758
759
760 //End ROLES tag
761 fwrite ($bf,end_tag("ROLES",4,true));
762 }
763 //End User tag
764 fwrite ($bf,end_tag("USER",3,true));
765 }
766 //End Users tag
767 fwrite ($bf,end_tag("USERS",2,true));
768 } else {
769 //There isn't users. Impossible !!
770 $status = false;
771 }
772
773 return $status;
774
775 }
afbe3de8 776?>