2 //This php script contains all the stuff to backup/restore
5 //This is the "graphical" structure of the dialogue mod:
12 // dialogue_conversations
13 // (UL,pk->id, fk->dialogueid)
18 // (UL,pk->id, fk->dialogueid,conversationid)
20 // Meaning: pk->primary key field of the table
21 // fk->foreign key to link with parent
22 // nt->nested field (recursive data)
23 // CL->course level info
24 // UL->user level info
25 // files->table may have files)
27 //-----------------------------------------------------------
29 function dialogue_backup_mods($bf,$preferences) {
35 //Iterate over dialogue table
36 $dialogues = get_records ("dialogue","course",$preferences->backup_course
,"id");
38 foreach ($dialogues as $dialogue) {
40 fwrite ($bf,start_tag("MOD",3,true));
42 fwrite ($bf,full_tag("ID",4,false,$dialogue->id
));
43 fwrite ($bf,full_tag("MODTYPE",4,false,"dialogue"));
44 fwrite ($bf,full_tag("NAME",4,false,$dialogue->name
));
45 fwrite ($bf,full_tag("INTRO",4,false,$dialogue->intro
));
46 fwrite ($bf,full_tag("DELETEAFTER",4,false,$dialogue->deleteafter
));
47 fwrite ($bf,full_tag("DIALOGUETYPE",4,false,$dialogue->dialoguetype
));
48 fwrite ($bf,full_tag("MULTIPLECONVERSATIONS",4,false,$dialogue->multipleconversations
));
49 fwrite ($bf,full_tag("MAILDEFAULT",4,false,$dialogue->maildefault
));
50 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$dialogue->timemodified
));
52 //if we've selected to backup users info, then execute backup_dialogue_conversations
53 if ($preferences->mods
["dialogue"]->userinfo
) {
54 $status = backup_dialogue_conversations($bf,$preferences,$dialogue->id
);
57 $status =fwrite ($bf,end_tag("MOD",3,true));
63 //Backup dialogue_conversations contents (executed from dialogue_backup_mods)
64 function backup_dialogue_conversations ($bf,$preferences,$dialogue) {
70 $dialogue_conversations = get_records("dialogue_conversations","dialogueid",$dialogue,"id");
71 //If there is conversations
72 if ($dialogue_conversations) {
74 $status =fwrite ($bf,start_tag("CONVERSATIONS",4,true));
75 //Iterate over each entry
76 foreach ($dialogue_conversations as $conversation) {
78 $status =fwrite ($bf,start_tag("CONVERSATION",5,true));
79 //Print dialogue_entries contents
80 fwrite ($bf,full_tag("ID",6,false,$conversation->id
));
81 fwrite ($bf,full_tag("USERID",6,false,$conversation->userid
));
82 fwrite ($bf,full_tag("RECIPIENTID",6,false,$conversation->recipientid
));
83 fwrite ($bf,full_tag("LASTID",6,false,$conversation->lastid
));
84 fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$conversation->timemodified
));
85 fwrite ($bf,full_tag("CLOSED",6,false,$conversation->closed
));
86 fwrite ($bf,full_tag("SEENON",6,false,$conversation->seenon
));
87 fwrite ($bf,full_tag("CTYPE",6,false,$conversation->ctype
));
88 fwrite ($bf,full_tag("FORMAT",6,false,$conversation->format
));
89 fwrite ($bf,full_tag("SUBJECT",6,false,$conversation->subject
));
91 //if we've selected to backup users info, then execute backup_dialogue_entries
92 if ($preferences->mods
["dialogue"]->userinfo
) {
93 $status = backup_dialogue_entries($bf,$preferences,$conversation->id
);
96 $status =fwrite ($bf,end_tag("CONVERSATION",5,true));
100 $status =fwrite ($bf,end_tag("CONVERSATIONS",4,true));
105 //Backup dialogue_entries contents (executed from dialogue_backup_mods)
106 function backup_dialogue_entries ($bf,$preferences,$conversationid) {
112 $dialogue_entries = get_records("dialogue_entries","conversationid",$conversationid,"id");
113 //If there is entries
114 if ($dialogue_entries) {
116 $status =fwrite ($bf,start_tag("ENTRIES",4,true));
117 //Iterate over each entry
118 foreach ($dialogue_entries as $entry) {
120 $status =fwrite ($bf,start_tag("ENTRY",5,true));
121 //Print dialogue_entries contents
122 fwrite ($bf,full_tag("ID",6,false,$entry->id
));
123 fwrite ($bf,full_tag("USERID",6,false,$entry->userid
));
124 fwrite ($bf,full_tag("TIMECREATED",6,false,$entry->timecreated
));
125 fwrite ($bf,full_tag("MAILED",6,false,$entry->mailed
));
126 fwrite ($bf,full_tag("TEXT",6,false,$entry->text
));
128 $status =fwrite ($bf,end_tag("ENTRY",5,true));
131 $status =fwrite ($bf,end_tag("ENTRIES",4,true));
136 ////Return an array of info (name,value)
137 function dialogue_check_backup_mods($course,$user_data=false,$backup_unique_code) {
138 //First the course data
139 $info[0][0] = get_string("modulenameplural","dialogue");
140 if ($ids = dialogue_ids ($course)) {
141 $info[0][1] = count($ids);
146 //Now, if requested, the user_data
148 $info[1][0] = get_string("entries");
149 if ($ids = dialogue_entry_ids_by_course ($course)) {
150 $info[1][1] = count($ids);
163 // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
165 //Returns an array of dialogues id
166 function dialogue_ids ($course) {
170 return get_records_sql ("SELECT a.id, a.course
171 FROM {$CFG->prefix}dialogue a
172 WHERE a.course = '$course'");
175 //Returns an array of dialogue entries id
176 function dialogue_entry_ids_by_course ($course) {
180 return get_records_sql ("SELECT s.id , s.dialogueid
181 FROM {$CFG->prefix}dialogue_entries s,
182 {$CFG->prefix}dialogue a
183 WHERE a.course = '$course' AND
184 s.dialogueid = a.id");