3 //This php script contains all the stuff to backup/restore data mod
5 //This is the "graphical" structure of the data mod:
12 // ---------------------------------------------------------------------------------
14 //data_records (UL,pk->id, fk->data) data_fields (pk->id, fk->data)
17 // ----------------------------------------------------------------------------- |
19 //data_ratings(fk->recordid, pk->id) data_comments (fk->recordid, pk->id) | |
20 // data_content(pk->id, fk->recordid, fk->fieldid)
24 // Meaning: pk->primary key field of the table
25 // fk->foreign key to link with parent
26 // nt->nested field (recursive data)
27 // CL->course level info
28 // UL->user level info
29 // files->table may have files)
31 //-----------------------------------------------------------
33 //Backup data files because we've selected to backup user info
34 //and files are user info's level
37 //Return a content encoded to support interactivities linking. Every module
39 function data_backup_mods($bf,$preferences) {
45 if ($datas = get_records('data','course',$preferences->backup_course
,"id")) {
46 foreach ($datas as $data) {
47 if (function_exists('backup_mod_selected')) {
49 $backup_mod_selected = backup_mod_selected($preferences, 'data', $data->id
);
52 $backup_mod_selected = true;
54 if ($backup_mod_selected) {
55 $status = data_backup_one_mod($bf,$preferences,$data);
56 // backup files happens in backup_one_mod now too.
63 function data_backup_one_mod($bf,$preferences,$data) {
66 if (is_numeric($data)) { // backwards compatibility
67 $data = get_record('data','id',$data);
69 $instanceid = $data->id
;
74 fwrite ($bf,start_tag("MOD",3,true));
76 fwrite ($bf,full_tag("ID",4,false,$data->id
));
77 fwrite ($bf,full_tag("MODTYPE",4,false,"data"));
78 fwrite ($bf,full_tag("NAME",4,false,$data->name
));
79 fwrite ($bf,full_tag("INTRO",4,false,$data->intro
));
80 fwrite ($bf,full_tag("COMMENTS",4,false,$data->comments
));
81 fwrite ($bf,full_tag("TIMEAVAILABLEFROM",4,false,$data->timeavailablefrom
));
82 fwrite ($bf,full_tag("TIMEAVAILABLETO",4,false,$data->timeavailableto
));
83 fwrite ($bf,full_tag("TIMEVIEWFROM",4,false,$data->timeviewfrom
));
84 fwrite ($bf,full_tag("TIMEVIEWTO",4,false,$data->timeviewto
));
85 fwrite ($bf,full_tag("REQUIREDENTRIES",4,false,$data->requiredentries
));
86 fwrite ($bf,full_tag("REQUIREDENTRIESTOVIEW",4,false,$data->requiredentriestoview
));
87 fwrite ($bf,full_tag("MAXENTRIES",4,false,$data->maxentries
));
88 fwrite ($bf,full_tag("RSSARTICLES",4,false,$data->rssarticles
));
89 fwrite ($bf,full_tag("SINGLETEMPLATE",4,false,$data->singletemplate
));
90 fwrite ($bf,full_tag("LISTTEMPLATE",4,false,$data->listtemplate
));
91 fwrite ($bf,full_tag("LISTTEMPLATEHEADER",4,false,$data->listtemplateheader
));
92 fwrite ($bf,full_tag("LISTTEMPLATEFOOTER",4,false,$data->listtemplatefooter
));
93 fwrite ($bf,full_tag("ADDTEMPLATE",4,false,$data->addtemplate
));
94 fwrite ($bf,full_tag("RSSTEMPLATE",4,false,$data->rsstemplate
));
95 fwrite ($bf,full_tag("RSSTITLETEMPLATE",4,false,$data->rsstitletemplate
));
96 fwrite ($bf,full_tag("CSSTEMPLATE",4,false,$data->csstemplate
));
97 fwrite ($bf,full_tag("JSTEMPLATE",4,false,$data->jstemplate
));
98 fwrite ($bf,full_tag("APPROVAL",4,false,$data->approval
));
99 fwrite ($bf,full_tag("SCALE",4,false,$data->scale
));
100 fwrite ($bf,full_tag("ASSESSED",4,false,$data->assessed
));
102 // if we've selected to backup users info, then call any other functions we need
103 // including backing up individual files
105 $status = backup_data_fields($bf,$preferences,$data->id
);
107 if (backup_userdata_selected($preferences,'data',$data->id
)) {
108 //$status = backup_someuserdata_for_this_instance();
109 //$status = backup_somefiles_for_this_instance();
112 $status = backup_data_records($bf,$preferences,$data->id
);
114 $status = backup_data_files_instance($bf,$preferences,$data->id
); //recursive copy
117 fwrite ($bf,end_tag("MOD",3,true));
123 function backup_data_fields($bf,$preferences,$dataid){
127 $data_fields = get_records("data_fields","dataid",$dataid);
129 //If there is submissions
132 $status =fwrite ($bf,start_tag("FIELDS",4,true));
133 //Iterate over each submission
134 foreach ($data_fields as $fie_sub) {
136 $status =fwrite ($bf,start_tag("FIELD",5,true));
137 //Print submission contents
138 fwrite ($bf,full_tag("ID",6,false,$fie_sub->id
));
139 fwrite ($bf,full_tag("DATAID",6,false,$fie_sub->dataid
));
140 fwrite ($bf,full_tag("TYPE",6,false,$fie_sub->type
));
141 fwrite ($bf,full_tag("NAME",6,false,$fie_sub->name
));
142 fwrite ($bf,full_tag("DESCRIPTION",6,false,$fie_sub->description
));
143 fwrite ($bf,full_tag("PARAM1",6,false,$fie_sub->param1
));
144 fwrite ($bf,full_tag("PARAM2",6,false,$fie_sub->param2
));
145 fwrite ($bf,full_tag("PARAM3",6,false,$fie_sub->param3
));
146 fwrite ($bf,full_tag("PARAM4",6,false,$fie_sub->param4
));
147 fwrite ($bf,full_tag("PARAM5",6,false,$fie_sub->param5
));
148 fwrite ($bf,full_tag("PARAM6",6,false,$fie_sub->param6
));
149 fwrite ($bf,full_tag("PARAM7",6,false,$fie_sub->param7
));
150 fwrite ($bf,full_tag("PARAM8",6,false,$fie_sub->param8
));
151 fwrite ($bf,full_tag("PARAM9",6,false,$fie_sub->param9
));
152 fwrite ($bf,full_tag("PARAM10",6,false,$fie_sub->param10
));
155 $status =fwrite ($bf,end_tag("FIELD",5,true));
158 $status =fwrite ($bf,end_tag("FIELDS",4,true));
163 function backup_data_content($bf,$preferences,$recordid){
167 $data_contents = get_records("data_content","recordid",$recordid);
169 //If there is submissions
170 if ($data_contents) {
172 $status =fwrite ($bf,start_tag("CONTENTS",6,true));
173 //Iterate over each submission
174 foreach ($data_contents as $cnt_sub) {
176 $status =fwrite ($bf,start_tag("CONTENT",7,true));
177 //Print submission contents
178 fwrite ($bf,full_tag("ID",8,false,$cnt_sub->id
));
179 fwrite ($bf,full_tag("RECORDID",8,false,$cnt_sub->recordid
));
180 fwrite ($bf,full_tag("FIELDID",8,false,$cnt_sub->fieldid
));
181 fwrite ($bf,full_tag("CONTENT",8,false,$cnt_sub->content
));
182 fwrite ($bf,full_tag("CONTENT1",8,false,$cnt_sub->content1
));
183 fwrite ($bf,full_tag("CONTENT2",8,false,$cnt_sub->content2
));
184 fwrite ($bf,full_tag("CONTENT3",8,false,$cnt_sub->content3
));
185 fwrite ($bf,full_tag("CONTENT4",8,false,$cnt_sub->content4
));
187 $status =fwrite ($bf,end_tag("CONTENT",7,true));
190 $status =fwrite ($bf,end_tag("CONTENTS",6,true));
195 function backup_data_ratings($bf,$preferences,$recordid){
198 $data_ratings = get_records("data_ratings","recordid",$recordid);
200 //If there is submissions
203 $status =fwrite ($bf,start_tag("RATINGS",6,true));
204 //Iterate over each submission
205 foreach ($data_ratings as $rat_sub) {
207 $status =fwrite ($bf,start_tag("RATING",7,true));
208 //Print submission contents
209 fwrite ($bf,full_tag("ID",8,false,$rat_sub->id
));
210 fwrite ($bf,full_tag("RECORDID",8,false,$rat_sub->recordid
));
211 fwrite ($bf,full_tag("USERID",8,false,$rat_sub->userid
));
212 fwrite ($bf,full_tag("RATING",8,false,$rat_sub->rating
));
214 $status =fwrite ($bf,end_tag("RATING",7,true));
217 $status =fwrite ($bf,end_tag("RATINGS",6,true));
223 function backup_data_comments($bf,$preferences,$recordid){
226 $data_comments = get_records("data_comments","recordid",$recordid);
228 //If there is submissions
229 if ($data_comments) {
231 $status =fwrite ($bf,start_tag("COMMENTS",6,true));
232 //Iterate over each submission
233 foreach ($data_comments as $com_sub) {
235 $status =fwrite ($bf,start_tag("COMMENT",7,true));
236 //Print submission contents
237 fwrite ($bf,full_tag("ID",8,false,$com_sub->id
));
238 fwrite ($bf,full_tag("RECORDID",8,false,$com_sub->recordid
));
239 fwrite ($bf,full_tag("USERID",8,false,$com_sub->userid
));
240 fwrite ($bf,full_tag("CONTENT",8,false,$com_sub->content
));
241 fwrite ($bf,full_tag("CREATED",8,false,$com_sub->created
));
242 fwrite ($bf,full_tag("MODIFIED",8,false,$com_sub->modified
));
244 $status =fwrite ($bf,end_tag("COMMENT",7,true));
247 $status =fwrite ($bf,end_tag("COMMENTS",6,true));
253 function backup_data_files_instance($bf,$preferences,$instanceid) {
258 //First we check to moddata exists and create it as necessary
259 //in temp/backup/$backup_code dir
260 $status = check_and_create_moddata_dir($preferences->backup_unique_code
);
261 $status = check_dir_exists($CFG->dataroot
."/temp/backup/".$preferences->backup_unique_code
."/moddata/data/",true);
262 //Now copy the data dir
264 //Only if it exists !! Thanks to Daniel Miksik.
265 if (is_dir($CFG->dataroot
."/".$preferences->backup_course
."/".$CFG->moddata
."/data/".$instanceid)) {
266 $status = backup_copy_file($CFG->dataroot
."/".$preferences->backup_course
."/".$CFG->moddata
."/data/".$instanceid,
267 $CFG->dataroot
."/temp/backup/".$preferences->backup_unique_code
."/moddata/data/".$instanceid);
273 function backup_data_records($bf,$preferences,$dataid){
278 $data_records = get_records("data_records","dataid",$dataid);
279 //If there is submissions
282 $status =fwrite ($bf,start_tag("RECORDS",4,true));
283 //Iterate over each submission
284 foreach ($data_records as $rec_sub) {
286 $status =fwrite ($bf,start_tag("RECORD",5,true));
287 //Print submission contents
288 fwrite ($bf,full_tag("ID",6,false,$rec_sub->id
));
289 fwrite ($bf,full_tag("USERID",6,false,$rec_sub->userid
));
290 fwrite ($bf,full_tag("GROUPID",6,false,$rec_sub->groupid
));
291 fwrite ($bf,full_tag("DATAID",6,false,$rec_sub->dataid
));
292 fwrite ($bf,full_tag("TIMECREATED",6,false,$rec_sub->timecreated
));
293 fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$rec_sub->timemodified
));
294 fwrite ($bf,full_tag("APPROVED",6,false,$rec_sub->approved
));
297 backup_data_content($bf,$preferences,$rec_sub->id
);
298 backup_data_ratings($bf,$preferences,$rec_sub->id
);
299 backup_data_comments($bf,$preferences,$rec_sub->id
);
301 $status =fwrite ($bf,end_tag("RECORD",5,true));
304 $status =fwrite ($bf,end_tag("RECORDS",4,true));
310 function backup_data_files($bf,$preferences) {
316 //First we check to moddata exists and create it as necessary
317 //in temp/backup/$backup_code dir
318 $status = check_and_create_moddata_dir($preferences->backup_unique_code
);
319 //Now copy the data dir
321 //Only if it exists !! Thanks to Daniel Miksik.
322 if (is_dir($CFG->dataroot
."/".$preferences->backup_course
."/".$CFG->moddata
."/data")) {
323 $status = backup_copy_file($CFG->dataroot
."/".$preferences->backup_course
."/".$CFG->moddata
."/data",
324 $CFG->dataroot
."/temp/backup/".$preferences->backup_unique_code
."/moddata/data");
331 function backup_data_file_instance($bf,$preferences,$instanceid) {
336 //First we check to moddata exists and create it as necessary
337 //in temp/backup/$backup_code dir
338 $status = check_and_create_moddata_dir($preferences->backup_unique_code
);
339 $status = check_dir_exists($CFG->dataroot
."/temp/backup/".$preferences->backup_unique_code
."/moddata/data/",true);
340 //Now copy the data dir
342 //Only if it exists !! Thanks to Daniel Miksik.
343 if (is_dir($CFG->dataroot
."/".$preferences->backup_course
."/".$CFG->moddata
."/data/".$instanceid)) {
344 $status = backup_copy_file($CFG->dataroot
."/".$preferences->backup_course
."/".$CFG->moddata
."/data/".$instanceid,
345 $CFG->dataroot
."/temp/backup/".$preferences->backup_unique_code
."/moddata/data/".$instanceid);
351 function data_check_backup_mods_instances($instance,$backup_unique_code) {
352 $info[$instance->id
.'0'][0] = '<b>'.$instance->name
.'</b>';
353 $info[$instance->id
.'0'][1] = '';
354 if (!empty($instance->userdata
)) {
355 // any other needed stuff
360 function data_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
361 if (!empty($instances) && is_array($instances) && count($instances)) {
363 foreach ($instances as $id => $instance) {
364 $info +
= data_check_backup_mods_instances($instance,$backup_unique_code);
369 // otherwise continue as normal
370 //First the course data
371 $info[0][0] = get_string("modulenameplural","data");
372 if ($ids = data_ids ($course)) {
373 $info[0][1] = count($ids);
378 //Now, if requested, the user_data
380 // any other needed stuff
386 function data_ids($course) {
387 // stub function, return number of modules