libdir.'/uploadlib.php'); require_once($CFG->libdir.'/xmlize.php'); require_once('preset_class.php'); $id = optional_param('id', 0, PARAM_INT); // course module id $d = optional_param('d', 0, PARAM_INT); // database activity id $action = optional_param('action', 'base', PARAM_ALPHANUM); // current action $fullname = optional_param('fullname', '', PARAM_PATH); // directory the preset is in $file = optional_param('file', '', PARAM_FILE); // uploaded file // find out preset owner userid and shortname $parts = explode('/', $fullname); $userid = empty($parts[0]) ? 0 : (int)$parts[0]; $shortname = empty($parts[1]) ? '' : $parts[1]; unset($parts); unset($fullname); if ($id) { if (! $cm = get_coursemodule_from_id('data', $id)) { error('Course Module ID was incorrect'); } if (! $course = get_record('course', 'id', $cm->course)) { error('Course is misconfigured'); } if (! $data = get_record('data', 'id', $cm->instance)) { error('Module Incorrect'); } } else if ($d) { if (! $data = get_record('data', 'id', $d)) { error('Database ID Incorrect'); } if (! $course = get_record('course', 'id', $data->course)) { error('Course is misconfigured'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { error('Course Module ID was incorrect'); } } else { error('Parameter missing'); } if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { error('Could not find context'); } require_login($course->id, false, $cm); require_capability('mod/data:managetemplates', $context); if ($userid && ($userid != $USER->id) && !has_capability('mod/data:viewalluserpresets', $context)) { error('You are not allowed to access presets from other users'); } /* Need sesskey security check here for import instruction */ $sesskey = sesskey(); /********************************************************************/ /* Output */ data_print_header($course, $cm, $data, 'presets'); $preset = new Data_Preset($shortname, $data->id, null, $userid); echo $preset->process_action($action, compact('shortname', 'fullname', 'data', 'userid', 'file', 'course', 'sesskey')); $presets = data_get_available_presets($context); $strimport = get_string('import'); $strfromfile = get_string('fromfile', 'data'); $strchooseorupload = get_string('chooseorupload', 'data'); $strusestandard = get_string('usestandard', 'data'); $strchoose = get_string('choose'); $strexport = get_string('export', 'data'); $strexportaszip = get_string('exportaszip', 'data'); $strsaveaspreset = get_string('saveaspreset', 'data'); $strsave = get_string('save', 'data'); $strdelete = get_string('delete'); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '

'.$strexport.'

'; helpbutton('exportzip', '', 'data'); echo ''; $options = new object(); $options->action = 'export'; $options->d = $data->id; $options->sesskey = sesskey(); print_single_button('preset.php', $options, $strexport, 'post'); echo '
'; helpbutton('savepreset', '', 'data'); echo ''; $options = new object(); $options->action = 'save1'; $options->d = $data->id; $options->sesskey = sesskey(); print_single_button('preset.php', $options, $strsave, 'post'); echo '

'.$strimport.'

'; helpbutton('importfromfile', '', 'data'); echo ''; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; helpbutton('usepreset', '', 'data'); echo ''; echo '
'; echo '
'; echo ''; echo ''; echo ''; $i = 0; foreach ($presets as $id => $preset) { $screenshot = ''; if (!empty($preset->user_id)) { $user = get_record('user', 'id', $preset->user_id); $desc = $preset->name.' ('.fullname($user, true).')'; } else { $desc = $preset->name; } if (!empty($preset->screenshot)) { $screenshot = ''.get_string('screenshot').' '.$desc.' '; } $fullname = $preset->user_id.'/'.$preset->shortname; $dellink = ''; if ($preset->user_id > 0 and ($preset->user_id == $USER->id || has_capability('mod/data:manageuserpresets', $context))) { $dellink = ' '. ''.$strdelete.' '.$desc.''; } echo ''.$dellink.'
'; } echo '
'; echo ''; echo '
'; echo '
'; echo '
'; print_footer($course); ?>