Sindbad~EG File Manager
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Amanote configuration form.
*
* @package mod_amanote
* @copyright 2018 Amaplex Software
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot.'/mod/amanote/locallib.php');
require_once($CFG->libdir.'/filelib.php');
/**
* Amanote settings form.
*
* @package mod_amanote
* @copyright 2018 Amaplex Software
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_amanote_mod_form extends moodleform_mod {
/**
* Defines forms elements.
*/
public function definition() {
global $CFG, $DB;
$mform =& $this->_form;
$config = get_config('mod_amanote');
// General section.
$mform->addElement('header', 'general', get_string('general', 'form'));
// Resource name.
$mform->addElement('text', 'name', get_string('name'), array('size' => '48'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
// Resource description.
$this->standard_intro_elements();
$element = $mform->getElement('introeditor');
$attributes = $element->getAttributes();
$attributes['rows'] = 5;
$element->setAttributes($attributes);
// Resource file manager.
$filemanageroptions = array();
$filemanageroptions['accepted_types'] = array(
'application/pdf',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
);
$filemanageroptions['maxbytes'] = 0;
$filemanageroptions['maxfiles'] = 1;
$filemanageroptions['subdirs'] = 0;
$mform->addElement('filemanager', 'files', get_string('selectfiles'), null, $filemanageroptions);
// Appearance section.
$mform->addElement('header', 'optionssection', get_string('appearance'));
$mform->addElement('checkbox', 'showsize', get_string('showsize', 'amanote'));
$mform->setDefault('showsize', $config->showsize);
$mform->addHelpButton('showsize', 'showsize', 'amanote');
$mform->addElement('checkbox', 'showdate', get_string('showdate', 'amanote'));
$mform->setDefault('showdate', $config->showdate);
$mform->addHelpButton('showdate', 'showdate', 'amanote');
// Common sections.
$this->standard_coursemodule_elements();
// Common buttons.
$this->add_action_buttons();
// Add hidden element revision.
$mform->addElement('hidden', 'revision');
$mform->setType('revision', PARAM_INT);
$mform->setDefault('revision', 1);
}
/**
* Form data preprocessor.
*
* @param array $defaultvalues passed by reference
*/
public function data_preprocessing(&$defaultvalues) {
if ($this->current->instance) {
$draftitemid = file_get_submitted_draft_itemid('files');
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_amanote', 'content', 0, array('subdirs' => true));
$defaultvalues['files'] = $draftitemid;
}
if (!empty($defaultvalues['displayoptions'])) {
$displayoptions = unserialize($defaultvalues['displayoptions']);
if (isset($displayoptions['printintro'])) {
$defaultvalues['printintro'] = $displayoptions['printintro'];
}
if (!empty($displayoptions['showsize'])) {
$defaultvalues['showsize'] = $displayoptions['showsize'];
} else {
// Must set explicitly to 0 here otherwise it will use system
// default which may be 1.
$defaultvalues['showsize'] = 0;
}
if (!empty($displayoptions['showdate'])) {
$defaultvalues['showdate'] = $displayoptions['showdate'];
} else {
$defaultvalues['showdate'] = 0;
}
}
}
/**
* Validate the data.
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
public function validation($data, $files) {
global $USER;
$errors = parent::validation($data, $files);
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();
if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['files'], 'sortorder, id', false)) {
$errors['files'] = get_string('required');
return $errors;
}
return $errors;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists