public function __construct($course, $cm, $module, $fullname) { global $USER; list($userid, $shortname) = explode('/', $fullname, 2); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if ($userid && ($userid != $USER->id) && !has_capability('mod/data:manageuserpresets', $context) && !has_capability('mod/data:viewalluserpresets', $context)) { throw new coding_exception('Invalid preset provided'); } $this->userid = $userid; $filepath = data_preset_path($course, $userid, $shortname); parent::__construct($course, $cm, $module, $filepath); }
$optionsno = new object(); $optionsno->d = $data->id; notice_yesno($strwarning, 'preset.php', 'preset.php', $options, $optionsno, 'post', 'get'); print_footer($course); exit; break; case 'delete': if (!data_submitted() and !confirm_sesskey()) { error("Invalid request"); } if ($userid > 0 and $userid == $USER->id || has_capability('mod/data:manageuserpresets', $context)) { //ok can delete } else { error("Invalid request"); } $presetpath = data_preset_path($course, $userid, $shortname); if (!clean_preset($presetpath)) { error("Error deleting a preset!"); } @rmdir($presetpath); $strdeleted = get_string('deleted', 'data'); notify("{$shortname} {$strdeleted}", 'notifysuccess'); break; /***************** Importing *****************/ /***************** Importing *****************/ case 'importpreset': if (!data_submitted() or !confirm_sesskey()) { error("Invalid request"); } $pimporter = new PresetImporter($course, $cm, $data, $userid, $shortname); $pimporter->import_options();
function PresetImporter($course, $cm, $data, $userid, $shortname) { global $CFG; $this->course = $course; $this->cm = $cm; $this->data = $data; $this->userid = $userid; $this->shortname = $shortname; $this->folder = data_preset_path($course, $userid, $shortname); }