File: restore_form.html

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (388 lines) | stat: -rw-r--r-- 16,618 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php //$Id: restore_form.html,v 1.25 2006/04/10 19:03:31 stronk7 Exp $
    //This page prints the restore form to select everything yo want
    //to restore. Form is dinamically buid, depending of "info" object
    //that contains the backup contents and depending of every mod
    //capabilities.

    //Get objects from session
    if (!($info = $SESSION->info)) {
      error( 'info object missing from session' );
    }
    if (!($course_header = $SESSION->course_header)) {
      error( 'course_header object missing from session' );
    }

    //Check that we have all we need
    //backup_unique_code
    $backup_unique_code = required_param( 'backup_unique_code' );
    //file
    $file = required_param( 'file' );

    //Check login
    require_login();

    //Check admin
    if (!empty($id)) {
        if (!isteacheredit($id)) {
            error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
        }
    } else {
        if (!isadmin()) {
            error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");   
        }
    }

    //Check site
    if (!$site = get_site()) {
        error("Site not found!");
    } 

    //Checks for the required files/functions to restore every mod
    $count = 0;
    if ($allmods = get_records("modules") ) {
        foreach ($allmods as $mod) {
            $modname = $mod->name;
            $modfile = "$CFG->dirroot/mod/$modname/restorelib.php";
            $modrestore = $modname."_restore_mods";
            if (file_exists($modfile)) {
               include_once($modfile);
               if (function_exists($modrestore)) {
                   $var = "exists_".$modname;
                   $$var = true;
                   $count++;
               }
            }
            //Check data
            //Check module info
            $var = "restore_".$modname;
            if (!isset($$var)) {
                $$var = 1;
            }
            //Check include user info
            $var = "restore_user_info_".$modname;
            if (!isset($$var)) {
                $$var = 1;
            }
        }
    }

    //Check other parameters
    if (!isset($restore_metacourse)) {
        $restore_metacourse = 1;
    }
   
    if (!isset($restore_users)) {
        $restore_users = 1;
    }
   
    if (!isset($restore_logs)) {
        $restore_logs = 1;
    }

    if (!isset($restore_user_files)) {
        $restore_user_files = 1;
    }

    if (!isset($restore_course_files)) {
        $restore_course_files = 1;
    }

    if (!isset($restore_messages)) {
        $restore_messages = 1;
        }

    if (!isset($restore_restoreto)) {
        if (isteacheredit($id) and !isadmin()) {
            $restore_restoreto = 1;
        }
        if (isadmin()) {
            $restore_restoreto = 2;
        }
    }

    if ($count == 0) {
        notice("No restorable modules are installed!");
    }

?>

<script language="JavaScript" type="text/javascript">
<!--
function selectItemInMenuByName(formId, menuName, selectIndex ) {
    myForm = document.getElementById(formId)
    for (i=0,n=myForm.elements.length;i<n;i++) {
        myLen = menuName.length;
        myName = myForm.elements[i].name;
        myType = myForm.elements[i].type;
        if (myName.substring(0,myLen) == menuName && myType == "select-one") {
            myForm.elements[i].options[selectIndex].selected = true;
        }
    }
}

function selectItemInRadioByName(formId, radioName, selectIndex ) {
    myForm = document.getElementById(formId)
    for (i=0,n=myForm.elements.length;i<n;i++) {
        myLen = radioName.length;
        myName = myForm.elements[i].name;
        myType = myForm.elements[i].type;
        if (myName.substring(0,myLen) == radioName && myType == "radio") {
            myRadioGroup = myForm.elements[myName];
            myRadioGroup[selectIndex].checked = true;
        }
    }
}

function selectItemInCheckboxByName(formId, checkName, checked ) {
    myForm = document.getElementById(formId)
    for (i=0,n=myForm.elements.length;i<n;i++) {
        myLen = checkName.length;
        myName = myForm.elements[i].name;
        myType = myForm.elements[i].type;
        if (myName.substring(0,myLen) == checkName && myType == "checkbox") {
            myForm.elements[i].checked = checked;
        }
    }
}
-->
</script>

<form name="form1" id="form1" method="post" action="restore.php">
<table cellpadding="5">
<?php

    //First, course destination
    //Print the full tr
    echo "<tr>";
    echo "<td align=\"right\"><b>";
    echo get_string("restoreto").":</b>";
    echo "</td><td colspan=\"3\">";
    if (isteacheredit($id) and !iscreator()) {
        $restore_restoreto_options[0] = get_string("currentcoursedeleting");
        $restore_restoreto_options[1] = get_string("currentcourseadding");
    } 
    if (iscreator()) {
        $restore_restoreto_options[0] = get_string("existingcoursedeleting");
        $restore_restoreto_options[1] = get_string("existingcourseadding");
        $restore_restoreto_options[2] = get_string("newcourse"); 
    }
    choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, "");
    echo "</td></tr>";
    //Line
    echo "<tr><td colspan=\"4\"><hr /></td></tr>";
    //Now, check modules and info and show posibilities
    if ($allmods = get_records("modules") ) {
        //Print option to select/deselect everything with 1 click.
        echo "<tr>";
        echo "<td align=\"right\">";
        echo '<b>'.get_string("include").":</b>";
        echo "</td><td>";
        echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'restore_', true);\">".
             get_string("all")."</a>/";
        echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'restore_', false);\">".
             get_string("none")."</a>";
        echo "</td>";
        echo "<td align=\"right\">";
        echo '<b>&nbsp;</b>';
        echo "</td><td>";
        echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'restore_user_info_', true);\">".
             get_string("all")."</a>/";
        echo "<a href=\"javascript:void(0);\" onclick=\"selectItemInCheckboxByName('form1', 'restore_user_info_', false);\">".
             get_string("none")."</a>";
        echo "</td>";
        echo "</tr>";
        echo "<tr><td colspan=\"4\"><hr /></td></tr>";
        $currentrow = 0;
        foreach ($allmods as $mod) {
            $modname = $mod->name;
            $modrestore = $modname."_restore_mods";
            //If exists the lib & function
            $exist = "exists_".$modname;
            $restore_var = "restore_".$modname;
            $user_info_var = "restore_user_info_".$modname;
            if (isset($$exist)) {
                if ($$exist) {
                    //Now check that we have that module info in the backup file
                    if (isset($info->mods[$modname]) && $info->mods[$modname]->backup == "true") {
                        //Print the full tr
                        echo "<tr class=\"r".$currentrow."\">";
                        echo "<td align=\"right\">&nbsp;";
                        echo "</td><td>";
                        $restore_options[1] = get_string("yes");
                        $restore_options[0] = get_string("no"); 
                        //choose_from_menu($restore_options, $restore_var, $$restore_var, "");
                        //choose_from_radio($restore_options, $restore_var, $$restore_var);
                        //Print the checkbox
                        print_checkbox($restore_var, $$restore_var, $$restore_var, get_string("modulenameplural",$modname),'','selectItemInCheckboxByName(\'form1\',\'restore_'.$modname.'\',this.checked)');
                        //If backup contains user data, then show menu, else fix it to
                        //without user data
                        echo "</td><td align=\"right\">&nbsp;";
                        echo "</td><td>";
                        if ($info->mods[$modname]->userinfo == "true") {
                            $restore_user_options[1] = get_string("yes");
                            $restore_user_options[0] = get_string("no"); 
                            //choose_from_menu($restore_user_options, $user_info_var, $$user_info_var, "");
                            //choose_from_radio($restore_user_options, $user_info_var, $$user_info_var);
                            print_checkbox($user_info_var, $$user_info_var, $$user_info_var, get_string("userdata"),'','selectItemInCheckboxByName(\'form1\',\'restore_user_info_'.$modname.'\',this.checked)');
                        } else {
                            //Module haven't userdata
                            echo get_string("withoutuserdata");
                            echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
                        }
                        echo "</td></tr>";
                        $instances = $info->mods[$modname]->instances;
                        if (!empty($instances) && is_array($instances)) {
                            echo '<tr><td></td><td colspan="3"><table class="restore-form-instances">';
                            foreach ($instances as $instance) {
                                echo '<tr><td>';
                                $var = 'restore_'.$modname.'_instance_'.$instance->id;
                                $$var = optional_param($var,1);
                                print_checkbox($var,$$var,$$var,$instance->name,$instance->name,'this.form.elements[\'restore_'.$modname.'\'].checked=1;');
                                echo '</td><td align="right">&nbsp;';
                                $var = 'restore_user_info_'.$modname.'_instance_'.$instance->id;
                                $$var = optional_param($var,1);
                                if ($info->mods[$modname]->instances[$instance->id]->userinfo == 'true') {
                                    print_checkbox($var,$$var,$$var,get_string('userdata'),'','this.form.elements[\'restore_user_info_'.$modname.'\'].checked=1;');
                                } else {
                                    echo '<input type="hidden" name="'.$var.'" value="0" />';
                                }
                                echo '</td></tr>';
                            }
                            echo '</table></td></tr>';
                        }
                    } else {
                        //Module isn't restorable
                        echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\" />";
                        echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
                    }
                } else {
                    //Module isn't restorable
                    echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\" />";
                    echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
                }
            } else {
                //Module isn't restorable
                echo "<input type=\"hidden\" name=\"$restore_var\" value=\"0\" />";
                echo "<input type=\"hidden\" name=\"$user_info_var\" value=\"0\" />";
            }
            $currentrow = ($currentrow + 1) % 2;
        }
        //Line
        echo "<tr><td colspan=\"4\"><hr /></td></tr>";

        //Now print the Metacourse tr
        echo "<tr>";
        echo "<td align=\"right\" colspan=\"2\"><b>";
        echo get_string("metacourse").":";                                               
        echo "</b></td><td colspan=\"2\">";
        //If metacourse are in the backup file, show menu, else fixed to no
        if ($info->backup_metacourse == "true") {
            $metacourse_options[0] = get_string("no");
            $metacourse_options[1] = get_string("yes"); 
            choose_from_menu($metacourse_options, "restore_metacourse", $restore_metacourse, ""); 
        } else {
            echo get_string("no");
            echo "<input type=\"hidden\" name=\"restore_metacourse\" value=\"0\" />";
        }
        echo "</td></tr>";
        //Now print the Users tr
        echo "<tr>";
        echo "<td align=\"right\" colspan=\"2\"><b>";
        echo get_string("users").":";
        echo "</b></td><td colspan=\"2\">";
        //If some user is present in the backup file
        if ($info->backup_users == "all" or $info->backup_users == "course") {
            //If all users are in the backup file
            if ($info->backup_users == "all") {
                $user_options[0] = get_string("all");
            }
            $user_options[1] = get_string("course");
            $user_options[2] = get_string("none");
            choose_from_menu($user_options, "restore_users", $restore_users, "");
        } else {
            echo get_string("none");
            echo "<input type=\"hidden\" name=\"restore_users\" value=\"2\" />";

        }
        echo "</td></tr>";

        //Now print the Logs tr
        echo "<tr>";
        echo "<td align=\"right\" colspan=\"2\"><b>";
        echo get_string("logs").":";                                               
        echo "</b></td><td colspan=\"2\">";
        //If logs are in the backup file, show menu, else fixed to no
        if ($info->backup_logs == "true") {
            $log_options[0] = get_string("no");
            $log_options[1] = get_string("yes"); 
            choose_from_menu($log_options, "restore_logs", $restore_logs, ""); 
        } else {
            echo get_string("no");
            echo "<input type=\"hidden\" name=\"restore_logs\" value=\"0\" />";
        }
        echo "</td></tr>";

        //Now print the User Files tr
        echo "<tr>";
        echo "<td align=\"right\" colspan=\"2\"><b>";
        echo get_string ("userfiles").":";
        echo "</b></td><td colspan=\"2\">";
        //If user files are in the backup file, show menu, else fixed to no
        if ($info->backup_user_files == "true") {
            $user_file_options[0] = get_string("no"); 
            $user_file_options[1] = get_string("yes"); 
            choose_from_menu($user_file_options, "restore_user_files", $restore_user_files, "");
        } else {
            echo get_string("no");
            echo "<input type=\"hidden\" name=\"restore_user_files\" value=\"0\" />";
        }
        echo "</td></tr>";

        //Now print the Course Files tr
        echo "<tr>";
        echo "<td align=\"right\" colspan=\"2\"><b>";
        echo get_string ("coursefiles").":";
        echo "</b></td><td colspan=\"2\">";
        echo "<input type=\"hidden\" name=\"backup_unique_code\" value=\"$backup_unique_code\" />";
        echo "<input type=\"hidden\" name=\"file\" value=\"$file\" />";
        //If course files are in the backup file, show menu, else fixed to no
        if ($info->backup_course_files == "true") {
            $course_file_options[0] = get_string("no");
            $course_file_options[1] = get_string("yes");
            choose_from_menu($course_file_options, "restore_course_files", $restore_course_files, "");
        } else {
            echo get_string("no");
            echo "<input type=\"hidden\" name=\"restore_course_files\" value=\"0\" />";
        }
        echo "</td></tr>";

        //Now print the Messages tr
        echo "<tr>";
        echo "<td align=\"right\" colspan=\"2\"><b>";
        
        //This tr is slighty different. Everything becomes hidden if
        //we haven't messages is the backup, to avoid confusions to users.
        //If messages are in the backup file, show menu, else fixed to no and show nothing
        if ($info->backup_messages == "true") {
            echo get_string ('messages','message').":";
            echo "</b></td><td colspan=\"2\">";
            $message_options[0] = get_string("no");
            $message_options[1] = get_string("yes");
            choose_from_menu($message_options, "restore_messages", $restore_messages, "");
        } else {
            echo "&nbsp;</b></td><td colspan=\"2\">";
            echo "<input type=\"hidden\" name=\"restore_messages\" value=\"0\" />";
        }
        echo "</td></tr>";
    }
?>
</table>
<br />
<center>
<input type="hidden" name="id"     value="<?php  p($id) ?>" />
<input type="hidden" name="launch" value="check" />
<input type="hidden" name="fromform" value="1" />
<input type="submit" value="<?php  print_string("continue") ?>" />
<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
</center>
</form>