4 * This is the page that is the menu item in the config database
8 require_once('../../config.php');
9 require_once('lib.php');
10 require_once($CFG->libdir
.'/uploadlib.php');
11 require_once($CFG->libdir
.'/xmlize.php');
12 require_once('preset_class.php');
14 $id = optional_param('id', 0, PARAM_INT
); // course module id
15 $d = optional_param('d', 0, PARAM_INT
); // database activity id
16 $action = optional_param('action', 'base', PARAM_ALPHANUM
); // current action
17 $fullname = optional_param('fullname', '', PARAM_PATH
); // directory the preset is in
18 $file = optional_param('file', '', PARAM_FILE
); // uploaded file
20 // find out preset owner userid and shortname
21 $parts = explode('/', $fullname);
22 $userid = empty($parts[0]) ?
0 : (int)$parts[0];
23 $shortname = empty($parts[1]) ?
'' : $parts[1];
28 if (! $cm = get_coursemodule_from_id('data', $id)) {
29 error('Course Module ID was incorrect');
31 if (! $course = get_record('course', 'id', $cm->course
)) {
32 error('Course is misconfigured');
34 if (! $data = get_record('data', 'id', $cm->instance
)) {
35 error('Module Incorrect');
38 if (! $data = get_record('data', 'id', $d)) {
39 error('Database ID Incorrect');
41 if (! $course = get_record('course', 'id', $data->course
)) {
42 error('Course is misconfigured');
44 if (! $cm = get_coursemodule_from_instance('data', $data->id
, $course->id
)) {
45 error('Course Module ID was incorrect');
48 error('Parameter missing');
51 if (!$context = get_context_instance(CONTEXT_MODULE
, $cm->id
)) {
52 error('Could not find context');
55 require_login($course->id
, false, $cm);
57 require_capability('mod/data:managetemplates', $context);
59 if ($userid && ($userid != $USER->id
) && !has_capability('mod/data:viewalluserpresets', $context)) {
60 error('You are not allowed to access presets from other users');
63 /* Need sesskey security check here for import instruction */
66 /********************************************************************/
68 data_print_header($course, $cm, $data, 'presets');
70 $preset = new Data_Preset($shortname, $data->id
, null, $userid);
71 echo $preset->process_action($action, compact('shortname', 'fullname', 'data', 'userid', 'file', 'course', 'sesskey'));
73 $presets = data_get_available_presets($context);
75 $strimport = get_string('import');
76 $strfromfile = get_string('fromfile', 'data');
77 $strchooseorupload = get_string('chooseorupload', 'data');
78 $strusestandard = get_string('usestandard', 'data');
79 $strchoose = get_string('choose');
80 $strexport = get_string('export', 'data');
81 $strexportaszip = get_string('exportaszip', 'data');
82 $strsaveaspreset = get_string('saveaspreset', 'data');
83 $strsave = get_string('save', 'data');
84 $strdelete = get_string('delete');
86 echo '<div style="text-align:center">';
87 echo '<table class="presets" cellpadding="5">';
88 echo '<tr><td valign="top" colspan="2" align="center"><h3>'.$strexport.'</h3></td></tr>';
90 echo '<tr><td><label>'.$strexportaszip.'</label>';
91 helpbutton('exportzip', '', 'data');
93 $options = new object();
94 $options->action
= 'export';
95 $options->d
= $data->id
;
96 $options->sesskey
= sesskey();
97 print_single_button('preset.php', $options, $strexport, 'post');
100 echo '<tr><td><label>'.$strsaveaspreset.'</label>';
101 helpbutton('savepreset', '', 'data');
103 $options = new object();
104 $options->action
= 'save1';
105 $options->d
= $data->id
;
106 $options->sesskey
= sesskey();
107 print_single_button('preset.php', $options, $strsave, 'post');
111 echo '<tr><td valign="top" colspan="2" align="center"><h3>'.$strimport.'</h3></td></tr>';
113 echo '<tr><td><label for="fromfile">'.$strfromfile.'</label>';
114 helpbutton('importfromfile', '', 'data');
117 echo '<form id="uploadpreset" method="post" action="preset.php">';
118 echo '<fieldset class="invisiblefieldset">';
119 echo '<input type="hidden" name="d" value="'.$data->id
.'" />';
120 echo '<input type="hidden" name="action" value="importzip" />';
121 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
122 echo '<input name="file" size="20" value="" id="fromfile" type="text" /><input name="coursefiles" value="'.$strchooseorupload.'" onclick="return openpopup('."'/files/index.php?id=2&choose=uploadpreset.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0".');" type="button" />';
123 echo '<input type="submit" value="'.$strimport.'" />';
124 echo '</fieldset></form>';
128 echo '<tr valign="top"><td><label>'.$strusestandard.'</label>';
129 helpbutton('usepreset', '', 'data');
132 echo '<form id="presets" method="post" action="preset.php" >';
133 echo '<fieldset class="invisiblefieldset">';
134 echo '<input type="hidden" name="d" value="'.$data->id
.'" />';
135 echo '<input type="hidden" name="action" value="importpreset" />';
136 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
139 foreach ($presets as $id => $preset) {
141 if (!empty($preset->user_id
)) {
142 $user = get_record('user', 'id', $preset->user_id
);
143 $desc = $preset->name
.' ('.fullname($user, true).')';
145 $desc = $preset->name
;
148 if (!empty($preset->screenshot
)) {
149 $screenshot = '<img width="150" class="presetscreenshot" src="'.$preset->screenshot
.'" alt="'.get_string('screenshot').' '.$desc.'" /> ';
152 $fullname = $preset->user_id
.'/'.$preset->shortname
;
155 if ($preset->user_id
> 0 and ($preset->user_id
== $USER->id ||
has_capability('mod/data:manageuserpresets', $context))) {
156 $dellink = ' <a href="preset.php?d='.$data->id
.'&action=confirmdelete&fullname='.$fullname.'&sesskey='.sesskey().'">'.
157 '<img src="'.$CFG->pixpath
.'/t/delete.gif" class="iconsmall" alt="'.$strdelete.' '.$desc.'" /></a>';
160 echo '<input type="radio" name="fullname" id="usepreset'.$i.'" value="'.$fullname.'" /><label for="usepreset'.$i++
.'">'.$desc.'</label>'.$dellink.'<br />';
163 echo '<input type="submit" value="'.$strchoose.'" />';
164 echo '</fieldset></form>';
169 print_footer($course);