Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / dialogue / backuplib.php
blob1ad94113a3acc620376636b089c1f3a052a3ced1
1 <?php //$Id$
2 //This php script contains all the stuff to backup/restore
3 //dialogue mods
5 //This is the "graphical" structure of the dialogue mod:
6 //
7 // dialogue
8 // (CL,pk->id)
9 // |
10 // |
11 // |
12 // dialogue_conversations
13 // (UL,pk->id, fk->dialogueid)
14 // |
15 // |
16 // |
17 // dialogue_entries
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) {
31 global $CFG;
33 $status = true;
35 //Iterate over dialogue table
36 $dialogues = get_records ("dialogue","course",$preferences->backup_course,"id");
37 if ($dialogues) {
38 foreach ($dialogues as $dialogue) {
39 //Start mod
40 fwrite ($bf,start_tag("MOD",3,true));
41 //Print dialogue data
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);
56 //End mod
57 $status =fwrite ($bf,end_tag("MOD",3,true));
60 return $status;
63 //Backup dialogue_conversations contents (executed from dialogue_backup_mods)
64 function backup_dialogue_conversations ($bf,$preferences,$dialogue) {
66 global $CFG;
68 $status = true;
70 $dialogue_conversations = get_records("dialogue_conversations","dialogueid",$dialogue,"id");
71 //If there is conversations
72 if ($dialogue_conversations) {
73 //Write start tag
74 $status =fwrite ($bf,start_tag("CONVERSATIONS",4,true));
75 //Iterate over each entry
76 foreach ($dialogue_conversations as $conversation) {
77 //Start entry
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);
95 //End entry
96 $status =fwrite ($bf,end_tag("CONVERSATION",5,true));
99 //Write end tag
100 $status =fwrite ($bf,end_tag("CONVERSATIONS",4,true));
102 return $status;
105 //Backup dialogue_entries contents (executed from dialogue_backup_mods)
106 function backup_dialogue_entries ($bf,$preferences,$conversationid) {
108 global $CFG;
110 $status = true;
112 $dialogue_entries = get_records("dialogue_entries","conversationid",$conversationid,"id");
113 //If there is entries
114 if ($dialogue_entries) {
115 //Write start tag
116 $status =fwrite ($bf,start_tag("ENTRIES",4,true));
117 //Iterate over each entry
118 foreach ($dialogue_entries as $entry) {
119 //Start 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));
127 //End entry
128 $status =fwrite ($bf,end_tag("ENTRY",5,true));
130 //Write end tag
131 $status =fwrite ($bf,end_tag("ENTRIES",4,true));
133 return $status;
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);
142 } else {
143 $info[0][1] = 0;
146 //Now, if requested, the user_data
147 if ($user_data) {
148 $info[1][0] = get_string("entries");
149 if ($ids = dialogue_entry_ids_by_course ($course)) {
150 $info[1][1] = count($ids);
151 } else {
152 $info[1][1] = 0;
155 return $info;
163 // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
165 //Returns an array of dialogues id
166 function dialogue_ids ($course) {
168 global $CFG;
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) {
178 global $CFG;
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");