Skip to content

Instantly share code, notes, and snippets.

@FMCorz
Created April 22, 2014 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FMCorz/11173370 to your computer and use it in GitHub Desktop.
Save FMCorz/11173370 to your computer and use it in GitHub Desktop.
<?php
require('config.php');
require_once($CFG->libdir.'/formslib.php');
class test_form extends moodleform {
function definition() {
$mform =& $this->_form;
// $mform->addElement('static', 'infoeditor', 'Editor limit', 'Max files: Unlimited; Max file size: 1MB; Global limit: 2Mo;');
$mform->addElement('editor', 'html_editor', 'HTML Editor', null, $this->_customdata['editor']);
$mform->addElement('static', 'hr', '', '<hr>');
// $mform->addElement('static', 'infopicker', 'Attachments limit', 'Max files: 3; Max file size: 1MB; Global limit: 2Mo;');
$mform->addElement('filemanager', 'attachments_filemanager', 'Attachments', null, $this->_customdata['picker']);
$mform->addElement('static', 'hr', '', '<hr>');
// $mform->addElement('static', 'infoone', 'Attachments limit', 'Max files: 1; Max file size: 1MB; Global limit: 2Mo;');
$mform->addElement('filepicker', 'attachments_filepicker', 'One file', null, $this->_customdata['one']);
$this->add_action_buttons();
}
}
$context = context_system::instance();
$editor = array('maxfiles' => -1, 'maxbytes' => 1024 * 1024, 'areamaxbytes' => 1024 * 1024 * 2, 'trusttext' => true, 'context' => $context);
$picker = array('maxfiles' => 3, 'maxbytes' => 1024 * 1024, 'areamaxbytes' => 1024 * 1024 * 2, 'accepted_types' => array('.jpg'));
$one = array('maxbytes' => 1024 * 1024, 'accepted_types' => '*');
$PAGE->set_url('/test_filemanager.php');
$PAGE->set_context($context);
$PAGE->set_title('Test File Manager');
$PAGE->set_heading('Test File Manager');
$PAGE->set_pagelayout('popup');
$entry = new stdClass();
$entry->id = 1;
$entry->html = get_user_preferences('test_filemanager_fred', '', $USER);
$entry->htmlformat = 1;
$entry = file_prepare_standard_editor($entry, 'html', $editor, $context, 'user', 'testeditor', $entry->id);
$entry = file_prepare_standard_filemanager($entry, 'attachments', $picker, $context, 'user', 'testfiles', $entry->id);
$form = new test_form(null, compact('editor', 'picker', 'one'));
$form->set_data($entry);
if ($data = $form->get_data()) {
file_postupdate_standard_editor($data, 'html', $editor, $context, 'user', 'testeditor', $entry->id);
file_postupdate_standard_filemanager($data, 'attachments', $picker, $context, 'user', 'testfiles', $entry->id);
set_user_preference('test_filemanager_fred', $data->html, $USER);
redirect($PAGE->url->out());
}
echo $OUTPUT->header();
echo $form->display();
echo $OUTPUT->footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment