mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
fixed text field widths in new forms
This commit is contained in:
parent
0ac1cfc359
commit
26de8d35ce
@ -65,7 +65,7 @@ class MoodleQuickForm_choosecoursefile extends MoodleQuickForm_group
|
||||
global $COURSE;
|
||||
$this->_elements = array();
|
||||
|
||||
$this->_elements[0] =& MoodleQuickForm::createElement('text', 'value', '');
|
||||
$this->_elements[0] =& MoodleQuickForm::createElement('text', 'value', '', array('size'=>'48'));
|
||||
$this->_elements[1] =& MoodleQuickForm::createElement('button', 'popup', get_string('chooseafile', 'resource') .' ...');
|
||||
|
||||
$button =& $this->_elements[1];
|
||||
|
@ -31,7 +31,7 @@ class mod_assignment_mod_form extends moodleform_mod {
|
||||
|
||||
// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('assignmentname', 'assignment'));
|
||||
$mform->addElement('text', 'name', get_string('assignmentname', 'assignment'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -11,7 +11,7 @@ class mod_chat_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('chatname', 'chat'));
|
||||
$mform->addElement('text', 'name', get_string('chatname', 'chat'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -11,7 +11,7 @@ class mod_choice_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('choicename', 'choice'));
|
||||
$mform->addElement('text', 'name', get_string('choicename', 'choice'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -11,7 +11,7 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('name'));
|
||||
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -11,7 +11,7 @@ class mod_exercise_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('title', 'exercise'));
|
||||
$mform->addElement('text', 'name', get_string('title', 'exercise'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -11,7 +11,7 @@ class mod_forum_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('forumname', 'forum'));
|
||||
$mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -21,11 +21,11 @@ class mod_forum_post_form extends moodleform {
|
||||
|
||||
$mform->addElement('header', 'general', '');//fill in the data depending on page params
|
||||
//later using set_defaults
|
||||
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="60"');
|
||||
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="64"');
|
||||
$mform->setType('subject', PARAM_TEXT);
|
||||
$mform->addRule('subject', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$mform->addElement('htmleditor', 'message', get_string('message', 'forum'));
|
||||
$mform->addElement('htmleditor', 'message', get_string('message', 'forum'), array('cols'=>85, 'rows'=>30));
|
||||
$mform->setType('message', PARAM_RAW);
|
||||
$mform->addRule('message', get_string('required'), 'required', null, 'client');
|
||||
$mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
|
||||
|
@ -11,7 +11,7 @@ class mod_glossary_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('name'));
|
||||
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -11,7 +11,7 @@ class mod_journal_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('journalname', 'journal'));
|
||||
$mform->addElement('text', 'name', get_string('journalname', 'journal'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -7,7 +7,7 @@ class mod_label_mod_form extends moodleform_mod {
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
$mform->addElement('htmleditor', 'content', get_string('labeltext', 'label'));
|
||||
$mform->addElement('htmleditor', 'content', get_string('labeltext', 'label'), array('size'=>'64'));
|
||||
$mform->setType('content', PARAM_RAW);
|
||||
$mform->addRule('content', get_string('required'), 'required', null, 'client');
|
||||
$mform->setHelpButton('content', array('questions', 'richtext'), false, 'editorhelpbutton');
|
||||
|
@ -20,7 +20,7 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('name'));
|
||||
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
|
@ -14,7 +14,7 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('name'));
|
||||
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
|
||||
$mform->addElement('htmleditor', 'intro', get_string("introduction", "quiz"));
|
||||
|
55
mod/resource/mod_form.php
Normal file
55
mod/resource/mod_form.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
require_once ('moodleform_mod.php');
|
||||
|
||||
class mod_resource_mod_form extends moodleform_mod {
|
||||
var $_resinstance;
|
||||
|
||||
function definition() {
|
||||
global $CFG;
|
||||
$mform =& $this->_form;
|
||||
|
||||
// this hack is needed for different settings of each subtype
|
||||
if (!empty($this->_instance)) {
|
||||
if($res = get_record('resource', 'id', (int)$this->_instance)) {
|
||||
$type = $res->type;
|
||||
} else {
|
||||
error('incorrect assignment');
|
||||
}
|
||||
} else {
|
||||
$type = required_param('type', PARAM_ALPHA);
|
||||
}
|
||||
$mform->addElement('hidden', 'type', $type);
|
||||
$mform->setDefault('type', $type);
|
||||
|
||||
require($CFG->dirroot.'/mod/resource/type/'.$type.'/resource.class.php');
|
||||
$resclass = 'resource_'.$type;
|
||||
$this->_resinstance = new $resclass();
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('htmleditor', 'summary', get_string('summary'));
|
||||
$mform->setType('summary', PARAM_RAW);
|
||||
$mform->setHelpButton('summary', array('summary', get_string('summary'), 'resource'));
|
||||
$mform->addRule('summary', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$mform->addElement('header', 'typedesc', get_string('resourcetype'.$type,'resource'));
|
||||
$this->_resinstance->setup_elements($mform);
|
||||
|
||||
$this->standard_coursemodule_elements();
|
||||
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
function defaults_preprocessing(&$default_values){
|
||||
$this->_resinstance->setup_preprocessing($default_values);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -82,7 +82,7 @@ function set_parameters() {
|
||||
);
|
||||
|
||||
if (!empty($USER->id)) {
|
||||
|
||||
|
||||
$userparameters = array(
|
||||
|
||||
'label1' => array('langstr' => get_string('user'),
|
||||
@ -92,8 +92,6 @@ function set_parameters() {
|
||||
'value' => $USER->id),
|
||||
'userusername' => array('langstr' => get_string('username'),
|
||||
'value' => $USER->username),
|
||||
'userpassword' => array('langstr' => get_string('password'),
|
||||
'value' => $USER->password),
|
||||
'useridnumber' => array('langstr' => get_string('idnumber'),
|
||||
'value' => $USER->idnumber),
|
||||
'userfirstname' => array('langstr' => get_string('firstname'),
|
||||
@ -123,57 +121,61 @@ function set_parameters() {
|
||||
'userurl' => array('langstr' => get_string('webpage'),
|
||||
'value' => $USER->url)
|
||||
);
|
||||
|
||||
$this->parameters = array_merge($userparameters, $this->parameters);
|
||||
|
||||
$this->parameters = $userparameters + $this->parameters;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add new instance of file resource
|
||||
*
|
||||
* Create alltext field before calling base class function.
|
||||
*
|
||||
* @param resource object
|
||||
*/
|
||||
function add_instance($resource) {
|
||||
$optionlist = array();
|
||||
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$parametername = "parameter$i";
|
||||
$parsename = "parse$i";
|
||||
if (!empty($resource->$parsename) and $resource->$parametername != "-") {
|
||||
$optionlist[] = $resource->$parametername."=".$resource->$parsename;
|
||||
}
|
||||
}
|
||||
|
||||
$resource->alltext = implode(',', $optionlist);
|
||||
|
||||
$this->_postprocess($resource);
|
||||
return parent::add_instance($resource);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update instance of file resource
|
||||
*
|
||||
* Create alltext field before calling base class function.
|
||||
*
|
||||
* @param resource object
|
||||
*/
|
||||
function update_instance($resource) {
|
||||
$optionlist = array();
|
||||
$this->_postprocess($resource);
|
||||
/* echo '<xmp>';
|
||||
var_dump($_POST);
|
||||
var_dump($resource);die;*/
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
function _postprocess(&$resource) {
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
$alloptions = $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
if ($resource->windowpopup) {
|
||||
$optionlist = array();
|
||||
foreach ($alloptions as $option) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
unset($resource->$option);
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
unset($resource->windowpopup);
|
||||
$resource->options = '';
|
||||
|
||||
} else {
|
||||
if ($resource->framepage) {
|
||||
$resource->options = 'frame';
|
||||
} else {
|
||||
$resource->options = '';
|
||||
}
|
||||
unset($resource->framepage);
|
||||
$resource->popup = '';
|
||||
}
|
||||
|
||||
$optionlist = array();
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$parametername = "parameter$i";
|
||||
$parsename = "parse$i";
|
||||
if (!empty($resource->$parsename) and $resource->$parametername != "-") {
|
||||
$optionlist[] = $resource->$parametername."=".$resource->$parsename;
|
||||
}
|
||||
unset($resource->$parsename);
|
||||
unset($resource->$parametername);
|
||||
}
|
||||
|
||||
$resource->alltext = implode(',', $optionlist);
|
||||
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
|
||||
@ -252,14 +254,13 @@ function display() {
|
||||
$field = explode('=', $fieldstring);
|
||||
$querys[] = urlencode($field[1]).'='.urlencode($this->parameters[$field[0]]['value']);
|
||||
}
|
||||
$querystring = implode('&', $querys);
|
||||
$querystring = implode('&', $querys);
|
||||
}
|
||||
|
||||
|
||||
/// Set up some variables
|
||||
|
||||
$inpopup_param = optional_param( 'inpopup','' );
|
||||
$inpopup = !empty( $inpopup_param );
|
||||
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
|
||||
|
||||
if (resource_is_url($resource->reference)) {
|
||||
$fullurl = $resource->reference;
|
||||
@ -268,7 +269,7 @@ function display() {
|
||||
if (empty($urlpieces['query'])) {
|
||||
$fullurl .= '?'.$querystring;
|
||||
} else {
|
||||
$fullurl .= '&'.$querystring;
|
||||
$fullurl .= '&'.$querystring;
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,7 +295,7 @@ function display() {
|
||||
} else {
|
||||
$relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}";
|
||||
if ($querystring) {
|
||||
$relativeurl .= '&'.$querystring;
|
||||
$relativeurl .= '&'.$querystring;
|
||||
}
|
||||
}
|
||||
$fullurl = "$CFG->wwwroot$relativeurl";
|
||||
@ -509,116 +510,11 @@ function display() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Setup a new file resource
|
||||
*
|
||||
* Display a form to create a new or edit an existing file resource
|
||||
*
|
||||
* @param form object
|
||||
* @param CFG global object
|
||||
* @param usehtmleditor global integer
|
||||
* @param RESOURCE_WINDOW_OPTIONS global array
|
||||
*/
|
||||
function setup($form) {
|
||||
global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
parent::setup($form);
|
||||
|
||||
$this->set_parameters(); // set the parameter array for the form
|
||||
|
||||
|
||||
$strfilename = get_string("location");
|
||||
$strnote = get_string("note", "resource");
|
||||
$strchooseafile = get_string("chooseafile", "resource");
|
||||
$strnewwindow = get_string("newwindow", "resource");
|
||||
$strnewwindowopen = get_string("newwindowopen", "resource");
|
||||
$strsearch = get_string("searchweb", "resource");
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$stringname = "str$optionname";
|
||||
$$stringname = get_string("new$optionname", "resource");
|
||||
$window->$optionname = "";
|
||||
$jsoption[] = "\"$optionname\"";
|
||||
}
|
||||
|
||||
$frameoption = "\"framepage\"";
|
||||
$popupoptions = implode(",", $jsoption);
|
||||
$jsoption[] = $frameoption;
|
||||
$alloptions = implode(",", $jsoption);
|
||||
|
||||
|
||||
|
||||
if ($form->instance) { // Re-editing
|
||||
if (!$form->popup) {
|
||||
$windowtype = "page"; // No popup text => in page
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
}
|
||||
} else {
|
||||
$windowtype = "popup";
|
||||
$rawoptions = explode(',', $form->popup);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
$option = explode('=', trim($rawoption));
|
||||
$optionname = $option[0];
|
||||
$optionvalue = $option[1];
|
||||
if ($optionname == 'height' or $optionname == 'width') {
|
||||
$window->$optionname = $optionvalue;
|
||||
} else if ($optionvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
|
||||
if ($optionname == 'height' or $optionname == 'width') {
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
} else if ($CFG->$defaultvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
$windowtype = ($CFG->resource_popup) ? 'popup' : 'page';
|
||||
if (empty($form->options)) {
|
||||
$form->options = 'frame';
|
||||
$form->reference = $CFG->resource_defaulturl;
|
||||
}
|
||||
}
|
||||
if (empty($form->reference)) {
|
||||
$form->reference = $CFG->resource_defaulturl;
|
||||
}
|
||||
|
||||
|
||||
/// set the 5 parameter defaults
|
||||
$alltextfield = array();
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$alltextfield[] = array('parameter' => '',
|
||||
'parse' => '');
|
||||
}
|
||||
/// load up any stored parameters
|
||||
if (!empty($form->alltext)) {
|
||||
$parray = explode(',', $form->alltext);
|
||||
foreach ($parray as $key => $fieldstring) {
|
||||
$field = explode('=', $fieldstring);
|
||||
$alltextfield[$key]['parameter'] = $field[0];
|
||||
$alltextfield[$key]['parse'] = $field[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
include("$CFG->dirroot/mod/resource/type/file/file.html");
|
||||
|
||||
parent::setup_end();
|
||||
}
|
||||
|
||||
//backwards compatible with existing resources
|
||||
function set_encrypted_parameter() {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource//type/file/externserverfile.php")) {
|
||||
if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource/type/file/externserverfile.php")) {
|
||||
include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php";
|
||||
if (function_exists(extern_server_file)) {
|
||||
return extern_server_file($this->resource->reference);
|
||||
@ -627,6 +523,109 @@ function set_encrypted_parameter() {
|
||||
return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase);
|
||||
}
|
||||
|
||||
function setup_preprocessing(&$defaults){
|
||||
if (!empty($defaults['popup'])) {
|
||||
$defaults['windowpopup'] = 1;
|
||||
if (array_key_exists('popup', $defaults)) {
|
||||
$rawoptions = explode(',', $defaults['popup']);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
$option = explode('=', trim($rawoption));
|
||||
$defaults[$option[0]] = $option[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$defaults['windowpopup'] = 0;
|
||||
if (array_key_exists('options', $defaults)) {
|
||||
$defaults['framepage'] = ($defaults['options']=='frame');
|
||||
}
|
||||
}
|
||||
/// load up any stored parameters
|
||||
if (!empty($defaults['alltext'])) {
|
||||
$parray = explode(',', $defaults['alltext']);
|
||||
$i=0;
|
||||
foreach ($parray as $rawpar) {
|
||||
list($param, $varname) = explode('=', $rawpar);
|
||||
$defaults["parse$i"] = $varname;
|
||||
$defaults["parameter$i"] = $param;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setup_elements(&$mform) {
|
||||
global $CFG, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$this->set_parameters(); // set the parameter array for the form
|
||||
|
||||
$mform->addElement('choosecoursefile', 'reference', get_string('location'));
|
||||
$mform->setDefault('reference', $CFG->resource_defaulturl);
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
if (!empty($CFG->resource_websearch)) {
|
||||
$searchbutton = $mform->addElement('button', 'searchbutton', get_string('searchweb', 'resource').'...');
|
||||
$buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return window.open('$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,scrollbars,resizable,width=800,height=600');");
|
||||
$searchbutton->updateAttributes($buttonattributes);
|
||||
}
|
||||
|
||||
if (!empty($CFG->resource_allowlocalfiles)) {
|
||||
$lfbutton = $mform->addElement('button', 'localfilesbutton', get_string('localfilechoose', 'resource').'...');
|
||||
$options = 'menubar=0,location=0,scrollbars,resizable,width=600,height=400';
|
||||
$url = '/mod/resource/type/file/localfile.php?choose=id_reference_value';
|
||||
$buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return openpopup('$url', '".$lfbutton->getName()."', '$options', 0);");
|
||||
$lfbutton->updateAttributes($buttonattributes);
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
|
||||
|
||||
$woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
|
||||
$mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
|
||||
$mform->setDefault('windowpopup', !empty($CFG->resource_popup));
|
||||
|
||||
$mform->addElement('checkbox', 'framepage', get_string('frameifpossible', 'resource'));
|
||||
$mform->setDefault('framepage', 0);
|
||||
// $mform->disabledIf('framepage', 'windowpopup', '', 0);
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if ($option == 'height' or $option == 'width') {
|
||||
$mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
} else {
|
||||
$mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
|
||||
|
||||
$options = array();
|
||||
$options['-'] = get_string('chooseparameter', 'resource').'...';
|
||||
$optgroup = '';
|
||||
foreach ($this->parameters as $pname=>$param) {
|
||||
if ($param['value']=='/optgroup') {
|
||||
$optgroup = '';
|
||||
continue;
|
||||
}
|
||||
if ($param['value']=='optgroup') {
|
||||
$optgroup = $param['langstr'];
|
||||
continue;
|
||||
}
|
||||
$options[$pname] = $optgroup.' - '.$param['langstr'];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$parametername = "parameter$i";
|
||||
$parsename = "parse$i";
|
||||
$group = array();
|
||||
$group[] =& $mform->createElement('text', $parsename, '', array('size'=>'12'));//TODO: accessiblity
|
||||
$group[] =& $mform->createElement('select', $parametername, '', $options);//TODO: accessiblity
|
||||
$mform->addGroup($group, 'pargroup', get_string('variablename', 'resource').'='.get_string('parameter', 'resource'), ' ', false);
|
||||
|
||||
$mform->setDefault($parametername, '-');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -8,89 +8,45 @@ function resource_html($cmid=0) {
|
||||
}
|
||||
|
||||
function add_instance($resource) {
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// will create a new instance and return the id number
|
||||
// of the new instance.
|
||||
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$resource->timemodified = time();
|
||||
|
||||
if (isset($resource->windowpopup)) {
|
||||
$optionlist = array();
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if (isset($resource->$option)) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
}
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
|
||||
} else if (isset($resource->windowpage)) {
|
||||
$resource->popup = "";
|
||||
}
|
||||
|
||||
if (isset($resource->blockdisplay)) {
|
||||
$resource->options = 'showblocks';
|
||||
} else {
|
||||
$resource->options = '';
|
||||
}
|
||||
|
||||
if (isset($resource->parametersettingspref)) {
|
||||
set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
|
||||
}
|
||||
if (isset($resource->windowsettingspref)) {
|
||||
set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
|
||||
}
|
||||
|
||||
return insert_record("resource", $resource);
|
||||
$this->_postprocess($resource);
|
||||
return parent::add_instance($resource);
|
||||
}
|
||||
|
||||
|
||||
function update_instance($resource) {
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// will update an existing instance with new data.
|
||||
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$resource->id = $resource->instance;
|
||||
$resource->timemodified = time();
|
||||
|
||||
if (isset($resource->windowpopup)) {
|
||||
$optionlist = array();
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if (isset($resource->$option)) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
}
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
|
||||
} else if (isset($resource->windowpage)) {
|
||||
$resource->popup = "";
|
||||
}
|
||||
|
||||
if (isset($resource->blockdisplay)) {
|
||||
$resource->options = 'showblocks';
|
||||
} else {
|
||||
$resource->options = '';
|
||||
}
|
||||
|
||||
if (isset($resource->parametersettingspref)) {
|
||||
set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
|
||||
}
|
||||
if (isset($resource->windowsettingspref)) {
|
||||
set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
|
||||
}
|
||||
|
||||
return update_record("resource", $resource);
|
||||
$this->_postprocess($resource);
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
function _postprocess(&$resource) {
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
$alloptions = $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
if ($resource->windowpopup) {
|
||||
$optionlist = array();
|
||||
foreach ($alloptions as $option) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
unset($resource->$option);
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
unset($resource->windowpopup);
|
||||
$resource->options = '';
|
||||
|
||||
} else {
|
||||
if ($resource->blockdisplay) {
|
||||
$resource->options = 'showblocks';
|
||||
} else {
|
||||
$resource->options = '';
|
||||
}
|
||||
unset($resource->blockdisplay);
|
||||
$resource->popup = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function display() {
|
||||
global $CFG;
|
||||
|
||||
|
||||
$formatoptions = new object();
|
||||
$formatoptions->noclean = true;
|
||||
|
||||
@ -109,9 +65,9 @@ function display() {
|
||||
parent::display();
|
||||
|
||||
/// Set up some shorthand variables
|
||||
$cm = $this->cm;
|
||||
$cm = $this->cm;
|
||||
$course = $this->course;
|
||||
$resource = $this->resource;
|
||||
$resource = $this->resource;
|
||||
|
||||
$pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
|
||||
$inpopup = optional_param('inpopup', '', PARAM_BOOL);
|
||||
@ -120,13 +76,13 @@ function display() {
|
||||
if ($inpopup) { /// Popup only
|
||||
add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
|
||||
print_header();
|
||||
print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id),
|
||||
print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id),
|
||||
"center", "", "", "20");
|
||||
print_footer($course);
|
||||
} else { /// Make a page and a pop-up window
|
||||
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
navmenu($course, $cm));
|
||||
|
||||
echo "\n<script type=\"text/javascript\">";
|
||||
@ -153,7 +109,7 @@ function display() {
|
||||
|
||||
add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
navmenu($course, $cm));
|
||||
|
||||
print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id), "center", "", "", "20");
|
||||
@ -168,74 +124,53 @@ function display() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setup($form) {
|
||||
global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
parent::setup($form);
|
||||
|
||||
|
||||
$strfilename = get_string("filename", "resource");
|
||||
$strnote = get_string("note", "resource");
|
||||
$strchooseafile = get_string("chooseafile", "resource");
|
||||
$strnewwindow = get_string("newwindow", "resource");
|
||||
$strnewwindowopen = get_string("newwindowopen", "resource");
|
||||
$strsearch = get_string("searchweb", "resource");
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$stringname = "str$optionname";
|
||||
$$stringname = get_string("new$optionname", "resource");
|
||||
$window->$optionname = "";
|
||||
$jsoption[] = "\"$optionname\"";
|
||||
}
|
||||
|
||||
$blockoption = "\"blockdisplay\"";
|
||||
$popupoptions = implode(",", $jsoption);
|
||||
$jsoption[] = $blockoption;
|
||||
$alloptions = implode(",", $jsoption);
|
||||
|
||||
if ($form->instance) { // Re-editing
|
||||
if (!$form->popup) {
|
||||
$windowtype = "page"; // No popup text => in page
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
}
|
||||
} else {
|
||||
$windowtype = "popup";
|
||||
$rawoptions = explode(',', $form->popup);
|
||||
function setup_preprocessing(&$defaults){
|
||||
if (!empty($defaults['popup'])) {
|
||||
$defaults['windowpopup'] = 1;
|
||||
if (array_key_exists('popup', $defaults)) {
|
||||
$rawoptions = explode(',', $defaults['popup']);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
$option = explode('=', trim($rawoption));
|
||||
$optionname = $option[0];
|
||||
$optionvalue = $option[1];
|
||||
if ($optionname == "height" or $optionname == "width") {
|
||||
$window->$optionname = $optionvalue;
|
||||
} else if ($optionvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
$defaults[$option[0]] = $option[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
|
||||
if ($optionname == "height" or $optionname == "width") {
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
} else if ($CFG->$defaultvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
$windowtype = ($CFG->resource_popup) ? 'popup' : 'page';
|
||||
if (!isset($form->options)) {
|
||||
$form->options = '';
|
||||
$defaults['windowpopup'] = 0;
|
||||
if (array_key_exists('options', $defaults)) {
|
||||
$defaults['blockdisplay'] = ($defaults['options']=='showblocks');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include("$CFG->dirroot/mod/resource/type/html/html.html");
|
||||
function setup_elements(&$mform) {
|
||||
global $CFG, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
parent::setup_end();
|
||||
$mform->addElement('htmleditor', 'alltext', get_string('fulltext', 'resource'), array('cols'=>85, 'rows'=>30));
|
||||
$mform->setType('alltext', PARAM_RAW);
|
||||
$mform->setHelpButton('alltext', array('reading', 'writing', 'richtext'), false, 'editorhelpbutton');
|
||||
$mform->addRule('alltext', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
|
||||
|
||||
$woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
|
||||
$mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
|
||||
$mform->setDefault('windowpopup', !empty($CFG->resource_popup));
|
||||
|
||||
$mform->addElement('checkbox', 'blockdisplay', get_string('showcourseblocks', 'resource'));
|
||||
$mform->setDefault('blockdisplay', 0);
|
||||
// $mform->disabledIf('blockdisplay', 'windowpopup', '', 0);
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if ($option == 'height' or $option == 'width') {
|
||||
$mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
} else {
|
||||
$mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->dirroot.'/mod/resource/type/ims/repository_config.php');
|
||||
|
||||
/**
|
||||
* Extend the base resource class for ims resources
|
||||
* Extend the base resource class for ims resources
|
||||
*/
|
||||
class resource_ims extends resource_base {
|
||||
|
||||
@ -56,14 +56,14 @@ class resource_ims extends resource_base {
|
||||
}
|
||||
/// set own attributes
|
||||
$this->parameters = $this->alltext2parameters($this->resource->alltext);
|
||||
|
||||
|
||||
/// navigation menu forces other settings
|
||||
if ($this->parameters->navigationmenu) {
|
||||
$this->parameters->tableofcontents = 0;
|
||||
$this->parameters->navigationuparrow = 0;
|
||||
$this->parameters->skipsubmenus = 1;
|
||||
}
|
||||
|
||||
|
||||
/// Is it in the repository material or not?
|
||||
if (isset($this->resource->reference)) {
|
||||
$file = $this->resource->reference;
|
||||
@ -80,7 +80,7 @@ class resource_ims extends resource_base {
|
||||
}
|
||||
|
||||
/***
|
||||
* This function converts parameters stored in the alltext field to the proper
|
||||
* This function converts parameters stored in the alltext field to the proper
|
||||
* this->parameters object storing the special configuration of this resource type
|
||||
*/
|
||||
function alltext2parameters($alltext) {
|
||||
@ -142,7 +142,7 @@ class resource_ims extends resource_base {
|
||||
* 2 = Zip file doesn't exist
|
||||
* 3 = Package not deployed.
|
||||
* 4 = Package has changed since deployed.
|
||||
* If the IMS CP is one from the central repository, then we instead check
|
||||
* If the IMS CP is one from the central repository, then we instead check
|
||||
* with the following codes:
|
||||
* 5 = Not deployed. Since repository is central must be admin to deploy so terminate
|
||||
*/
|
||||
@ -152,12 +152,12 @@ class resource_ims extends resource_base {
|
||||
if ($this->isrepository) {
|
||||
/// Calculate the path were the IMS package must be deployed
|
||||
$deploydir = $CFG->repository . $file;
|
||||
|
||||
|
||||
/// Confirm that the IMS package has been deployed. These files must exist if
|
||||
/// the package is deployed: moodle_index.ser and moodle_hash.ser
|
||||
if (!file_exists($deploydir.'/moodle_inx.ser')) {
|
||||
return 5; //Error
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/// Check for zip file type
|
||||
@ -165,24 +165,24 @@ class resource_ims extends resource_base {
|
||||
if ($mimetype != "application/zip") {
|
||||
return 1; //Error
|
||||
}
|
||||
|
||||
|
||||
/// Check if the uploaded file exists
|
||||
if (!file_exists($CFG->dataroot.'/'.$course->id.'/'.$file)) {
|
||||
return 2; //Error
|
||||
}
|
||||
|
||||
|
||||
/// Calculate the path were the IMS package must be deployed
|
||||
$deploydir = $CFG->dataroot.'/'.$course->id.'/'.$CFG->moddata.'/resource/'.$resource->id;
|
||||
|
||||
|
||||
|
||||
|
||||
/// Confirm that the IMS package has been deployed. These files must exist if
|
||||
/// the package is deployed: moodle_index.ser and moodle_hash.ser
|
||||
if (!file_exists($deploydir.'/moodle_inx.ser') ||
|
||||
!file_exists($deploydir.'/moodle_hash.ser')) {
|
||||
return 3; //Error
|
||||
}
|
||||
|
||||
/// If teacheredit, make, hash check. It's the md5 of the name of the file
|
||||
}
|
||||
|
||||
/// If teacheredit, make, hash check. It's the md5 of the name of the file
|
||||
/// plus its size and modification date
|
||||
/// not sure if this capability is suitable
|
||||
if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
@ -196,7 +196,7 @@ class resource_ims extends resource_base {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*** This function will check that the ims package (zip file) uploaded
|
||||
/*** This function will check that the ims package (zip file) uploaded
|
||||
* isn't changed since it was deployed.
|
||||
*/
|
||||
function checkpackagehash($file, $course, $resource) {
|
||||
@ -243,12 +243,7 @@ class resource_ims extends resource_base {
|
||||
* @param resource object
|
||||
*/
|
||||
function add_instance($resource) {
|
||||
|
||||
/// Load parameters to this->parameters
|
||||
$this->parameters = $this->form2parameters($resource);
|
||||
/// Save parameters into the alltext field
|
||||
$resource->alltext = $this->parameters2alltext($this->parameters);
|
||||
|
||||
$this->_postprocess($resource);
|
||||
return parent::add_instance($resource);
|
||||
}
|
||||
|
||||
@ -261,13 +256,30 @@ class resource_ims extends resource_base {
|
||||
* @param resource object
|
||||
*/
|
||||
function update_instance($resource) {
|
||||
$this->_postprocess($resource);
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
function _postprocess(&$resource) {
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
$alloptions = $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
if ($resource->windowpopup) {
|
||||
$optionlist = array();
|
||||
foreach ($alloptions as $option) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
unset($resource->$option);
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
unset($resource->windowpopup);
|
||||
|
||||
} else {
|
||||
$resource->popup = '';
|
||||
}
|
||||
/// Load parameters to this->parameters
|
||||
$this->parameters = $this->form2parameters($resource);
|
||||
/// Save parameters into the alltext field
|
||||
$resource->alltext = $this->parameters2alltext($this->parameters);
|
||||
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
/** Delete instance of IMS-CP resource
|
||||
@ -276,9 +288,9 @@ class resource_ims extends resource_base {
|
||||
* @param resource object
|
||||
*/
|
||||
function delete_instance($resource) {
|
||||
|
||||
|
||||
global $CFG;
|
||||
|
||||
|
||||
/// Delete moddata resource dir completely unless repository.
|
||||
if (!$this->isrepository) {
|
||||
$resource_dir = $CFG->dataroot.'/'.$resource->course.'/'.$CFG->moddata.'/resource/'.$resource->id;
|
||||
@ -301,7 +313,7 @@ class resource_ims extends resource_base {
|
||||
*
|
||||
* @param CFG global object
|
||||
*/
|
||||
function display() {
|
||||
function display() {
|
||||
global $CFG, $THEME, $USER;
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
@ -327,6 +339,9 @@ class resource_ims extends resource_base {
|
||||
$mimetype = mimeinfo("type", $resource->reference);
|
||||
$pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
|
||||
|
||||
$formatoptions = new object();
|
||||
$formatoptions->noclean = true;
|
||||
|
||||
/// Cache this per request
|
||||
static $items;
|
||||
|
||||
@ -415,7 +430,6 @@ class resource_ims extends resource_base {
|
||||
echo '</script>';
|
||||
|
||||
if (trim(strip_tags($resource->summary))) {
|
||||
$formatoptions->noclean = true;
|
||||
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center");
|
||||
}
|
||||
|
||||
@ -449,7 +463,7 @@ class resource_ims extends resource_base {
|
||||
global $standard_javascript;
|
||||
$standard_javascript = $CFG->javascript; // Save original javascript file
|
||||
$CFG->javascript = $CFG->dirroot.'/mod/resource/type/ims/javascript.php'; //Use our custom IMS javascript code
|
||||
|
||||
|
||||
/// moodle header
|
||||
if ($resource->popup) {
|
||||
//print_header($pagetitle, $course->fullname.' : '.$resource->name);
|
||||
@ -477,11 +491,11 @@ class resource_ims extends resource_base {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Function print_ims prints nearly the whole page. Stupid name subject to change :-)
|
||||
function print_ims($cm, $course, $items, $resource, $page) {
|
||||
global $CFG;
|
||||
|
||||
|
||||
/// Set the correct contentframe id based on $this->parameters->navigationmenu
|
||||
if (!empty($this->parameters->navigationmenu)) {
|
||||
$contentframe = 'ims-contentframe';
|
||||
@ -517,7 +531,7 @@ class resource_ims extends resource_base {
|
||||
$page = 1;
|
||||
if (!empty($this->parameters->skipsubmenus)) {
|
||||
while (empty($items[$page]->href) && !empty($items[$page])) {
|
||||
$page++;
|
||||
$page++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -537,23 +551,23 @@ class resource_ims extends resource_base {
|
||||
}
|
||||
}
|
||||
|
||||
/// print navigation buttons if needed
|
||||
/// print navigation buttons if needed
|
||||
if (!empty($this->parameters->navigationbuttons)) {
|
||||
$this->print_nav($items, $resource, $page);
|
||||
}
|
||||
|
||||
|
||||
echo '<div id="ims-containerdiv">';
|
||||
/// adds side navigation bar if needed. must also adjust width of iframe to accomodate
|
||||
/// adds side navigation bar if needed. must also adjust width of iframe to accomodate
|
||||
if (!empty($this->parameters->navigationmenu)) {
|
||||
echo "<div id=\"ims-menudiv\">"; $this->print_navmenu($items, $resource, $page); echo "</div>";
|
||||
}
|
||||
|
||||
|
||||
/// prints iframe filled with $fullurl
|
||||
echo "<iframe id=\"".$contentframe."\" name=\"".$contentframe."\" src=\"{$fullurl}\" title=\"".get_string('modulename','resource')."\">Your browser does not support inline frames or is currently configured not to display inline frames. Content can be viewed at {$fullurl}</iframe>"; //Content frame
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/// Prints TOC
|
||||
/// Prints TOC
|
||||
function print_toc($items, $resource, $page) {
|
||||
$table = new stdClass;
|
||||
if (empty($page)) {
|
||||
@ -566,11 +580,11 @@ class resource_ims extends resource_base {
|
||||
print_table($table);
|
||||
}
|
||||
|
||||
/// Prints side navigation menu. This is just the full TOC with no surround.
|
||||
/// Prints side navigation menu. This is just the full TOC with no surround.
|
||||
function print_navmenu($items, $resource, $page=0) {
|
||||
echo ims_generate_toc ($items, $resource, 0, $page);
|
||||
}
|
||||
|
||||
|
||||
/// Prints navigation bar at the top of the page.
|
||||
function print_nav($items, $resource, $page) {
|
||||
echo '<div class="ims-nav-bar" id="ims-nav-bar">';
|
||||
@ -584,96 +598,74 @@ class resource_ims extends resource_base {
|
||||
echo ims_get_toc_nav_button ($items, $this, $page);
|
||||
/// Footer
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a new file resource
|
||||
*
|
||||
* Display a form to create a new or edit an existing file resource
|
||||
*
|
||||
* @param form object
|
||||
* @param CFG global object
|
||||
* @param usehtmleditor global integer
|
||||
* @param RESOURCE_WINDOW_OPTIONS global array
|
||||
*/
|
||||
function setup($form) {
|
||||
global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
parent::setup($form);
|
||||
|
||||
$strfilename = get_string("location");
|
||||
$strnote = get_string("note", "resource");
|
||||
$strchooseafile = get_string("chooseafile", "resource");
|
||||
$strnewwindow = get_string("newwindow", "resource");
|
||||
$strnewwindowopen = get_string("newwindowopen", "resource");
|
||||
$strsearch = get_string("searchweb", "resource");
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$stringname = "str$optionname";
|
||||
$$stringname = get_string("new$optionname", "resource");
|
||||
$window->$optionname = "";
|
||||
$jsoption[] = "\"$optionname\"";
|
||||
}
|
||||
|
||||
$frameoption = "\"framepage\"";
|
||||
$popupoptions = implode(",", $jsoption);
|
||||
$jsoption[] = $frameoption;
|
||||
$alloptions = implode(",", $jsoption);
|
||||
|
||||
if ($form->instance) { // Re-editing
|
||||
if (!$form->popup) {
|
||||
$windowtype = "page"; // No popup text => in page
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
}
|
||||
} else {
|
||||
$windowtype = "popup";
|
||||
$rawoptions = explode(',', $form->popup);
|
||||
function setup_preprocessing(&$defaults){
|
||||
if (!empty($defaults['popup'])) {
|
||||
$defaults['windowpopup'] = 1;
|
||||
if (array_key_exists('popup', $defaults)) {
|
||||
$rawoptions = explode(',', $defaults['popup']);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
$option = explode('=', trim($rawoption));
|
||||
$optionname = $option[0];
|
||||
$optionvalue = $option[1];
|
||||
if ($optionname == 'height' or $optionname == 'width') {
|
||||
$window->$optionname = $optionvalue;
|
||||
} else if ($optionvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
$defaults[$option[0]] = $option[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
|
||||
if ($optionname == 'height' or $optionname == 'width') {
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
} else if ($CFG->$defaultvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
$windowtype = ($CFG->resource_popup) ? 'popup' : 'page';
|
||||
if (empty($form->options)) {
|
||||
$form->options = 'frame';
|
||||
$form->reference = $CFG->resource_defaulturl;
|
||||
}
|
||||
$defaults['windowpopup'] = 0;
|
||||
}
|
||||
if (empty($form->reference)) {
|
||||
$form->reference = $CFG->resource_defaulturl;
|
||||
}
|
||||
|
||||
//Converts the alltext to form fields
|
||||
$parameters=$this->alltext2parameters($form->alltext);
|
||||
$form->param_tableofcontents = $parameters->tableofcontents;
|
||||
$form->param_navigationbuttons = $parameters->navigationbuttons;
|
||||
$form->param_skipsubmenus = $parameters->skipsubmenus;
|
||||
$form->param_navigationmenu = $parameters->navigationmenu;
|
||||
$form->param_navigationupbutton = $parameters->navigationupbutton;
|
||||
//Show the setup form
|
||||
include("$CFG->dirroot/mod/resource/type/ims/ims.html");
|
||||
if (!empty($defaults['alltext'])) {
|
||||
$parameters = $this->alltext2parameters($defaults['alltext']);
|
||||
$defaults['param_tableofcontents'] = $parameters->tableofcontents;
|
||||
$defaults['param_navigationbuttons'] = $parameters->navigationbuttons;
|
||||
$defaults['param_skipsubmenus'] = $parameters->skipsubmenus;
|
||||
$defaults['param_navigationmenu'] = $parameters->navigationmenu;
|
||||
$defaults['param_navigationupbutton'] = $parameters->navigationupbutton;
|
||||
}
|
||||
}
|
||||
|
||||
function setup_elements(&$mform) {
|
||||
global $CFG, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$mform->addElement('choosecoursefile', 'reference', get_string('location'));
|
||||
$mform->addRule('name', null, 'required', null, 'client');
|
||||
|
||||
$mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
|
||||
|
||||
$woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
|
||||
$mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
|
||||
$mform->setDefault('windowpopup', !empty($CFG->resource_popup));
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if ($option == 'height' or $option == 'width') {
|
||||
$mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
} else {
|
||||
$mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
|
||||
|
||||
$mform->addElement('selectyesno', 'param_navigationmenu', get_string('navigationmenu', 'resource'));
|
||||
$mform->setDefault('param_navigationmenu', 1);
|
||||
$mform->addElement('selectyesno', 'param_tableofcontents', get_string('tableofcontents', 'resource'));
|
||||
// $mform->disabledIf($option, 'param_navigationmenu', '', 1);
|
||||
$mform->setDefault('param_tableofcontents', 0);
|
||||
$mform->addElement('selectyesno', 'param_navigationbuttons', get_string('navigationbuttons', 'resource'));
|
||||
$mform->setDefault('param_navigationbuttons', 0);
|
||||
$mform->addElement('selectyesno', 'param_skipsubmenus', get_string('skipsubmenus', 'resource'));
|
||||
$mform->setDefault('param_skipsubmenus', 1);
|
||||
// $mform->disabledIf($option, 'param_navigationmenu', '', 1);
|
||||
$mform->addElement('selectyesno', 'param_navigationupbutton', get_string('navigationup', 'resource'));
|
||||
$mform->setDefault('param_navigationup', 1);
|
||||
// $mform->disabledIf($option, 'param_navigationmenu', '', 1);
|
||||
// $mform->disabledIf($option, 'param_navigationmenu', '', 0);//????????
|
||||
|
||||
parent::setup_end();
|
||||
}
|
||||
|
||||
} //End class
|
||||
@ -767,7 +759,7 @@ class resource_ims extends resource_base {
|
||||
}
|
||||
/// We are after page and inside it (level > endlevel)
|
||||
if ($item->id > $page && $item->level > $endlevel) {
|
||||
/// Start Level
|
||||
/// Start Level
|
||||
if ($item->level > $currlevel) {
|
||||
$contents .= '<ol class="listlevel_'.$item->level.'">';
|
||||
$openlielement = false;
|
||||
@ -828,7 +820,7 @@ class resource_ims extends resource_base {
|
||||
}
|
||||
|
||||
if ($page >= 1 ) { //0 and 1 pages haven't previous
|
||||
$contents .= "<span class=\"ims-nav-button\"><a href=\"view.php?id={$cm->id}&type={$resource->type}&page={$page}&frameset=ims\">$strprevious</a></span>";
|
||||
$contents .= "<span class=\"ims-nav-button\"><a href=\"view.php?id={$cm->id}&type={$resource->type}&page={$page}&frameset=ims\">$strprevious</a></span>";
|
||||
} else {
|
||||
$contents .= '<span class="ims-nav-dimmed">'.$strprevious.'</span>';
|
||||
}
|
||||
@ -846,7 +838,7 @@ class resource_ims extends resource_base {
|
||||
$resource = $resource_obj->resource;
|
||||
|
||||
$contents = '';
|
||||
|
||||
|
||||
$page++;
|
||||
/// Skips any menu pages since these are redundant with sidemenu.
|
||||
if (!empty($resource_obj->parameters->skipsubmenus)) {
|
||||
@ -854,7 +846,7 @@ class resource_ims extends resource_base {
|
||||
$page++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($items[$page])) { //If the next page exists
|
||||
$contents .= "<span class=\"ims-nav-button\"><a href=\"view.php?id={$cm->id}&type={$resource->type}&page={$page}&frameset=ims\">$strnext</a></span>";
|
||||
} else {
|
||||
|
@ -39,45 +39,6 @@ function set_parameters() {
|
||||
$site = get_site();
|
||||
|
||||
$this->parameters = array(
|
||||
|
||||
'label1' => array('langstr' => get_string('user'),
|
||||
'value' => 'optgroup'),
|
||||
|
||||
'userid' => array('langstr' => 'id',
|
||||
'value' => $USER->id),
|
||||
'userusername' => array('langstr' => get_string('username'),
|
||||
'value' => $USER->username),
|
||||
'userpassword' => array('langstr' => get_string('password'),
|
||||
'value' => $USER->password),
|
||||
'useridnumber' => array('langstr' => get_string('idnumber'),
|
||||
'value' => $USER->idnumber),
|
||||
'userfirstname' => array('langstr' => get_string('firstname'),
|
||||
'value' => $USER->firstname),
|
||||
'userlastname' => array('langstr' => get_string('lastname'),
|
||||
'value' => $USER->lastname),
|
||||
'userfullname' => array('langstr' => get_string('fullname'),
|
||||
'value' => fullname($USER)),
|
||||
'useremail' => array('langstr' => get_string('email'),
|
||||
'value' => $USER->email),
|
||||
'usericq' => array('langstr' => get_string('icqnumber'),
|
||||
'value' => $USER->icq),
|
||||
'userphone1' => array('langstr' => get_string('phone').' 1',
|
||||
'value' => $USER->phone1),
|
||||
'userphone2' => array('langstr' => get_string('phone').' 2',
|
||||
'value' => $USER->phone2),
|
||||
'userinstitution' => array('langstr' => get_string('institution'),
|
||||
'value' => $USER->institution),
|
||||
'userdepartment' => array('langstr' => get_string('department'),
|
||||
'value' => $USER->department),
|
||||
'useraddress' => array('langstr' => get_string('address'),
|
||||
'value' => $USER->address),
|
||||
'usercity' => array('langstr' => get_string('city'),
|
||||
'value' => $USER->city),
|
||||
'usertimezone' => array('langstr' => get_string('timezone'),
|
||||
'value' => get_user_timezone_offset()),
|
||||
'userurl' => array('langstr' => get_string('webpage'),
|
||||
'value' => $USER->url),
|
||||
|
||||
'label2' => array('langstr' => "",
|
||||
'value' =>'/optgroup'),
|
||||
'label3' => array('langstr' => get_string('course'),
|
||||
@ -122,56 +83,104 @@ function set_parameters() {
|
||||
|
||||
'label6' => array('langstr' => "",
|
||||
'value' =>'/optgroup')
|
||||
);
|
||||
);
|
||||
|
||||
if (!empty($USER->id)) {
|
||||
|
||||
$userparameters = array(
|
||||
|
||||
'label1' => array('langstr' => get_string('user'),
|
||||
'value' => 'optgroup'),
|
||||
|
||||
'userid' => array('langstr' => 'id',
|
||||
'value' => $USER->id),
|
||||
'userusername' => array('langstr' => get_string('username'),
|
||||
'value' => $USER->username),
|
||||
'useridnumber' => array('langstr' => get_string('idnumber'),
|
||||
'value' => $USER->idnumber),
|
||||
'userfirstname' => array('langstr' => get_string('firstname'),
|
||||
'value' => $USER->firstname),
|
||||
'userlastname' => array('langstr' => get_string('lastname'),
|
||||
'value' => $USER->lastname),
|
||||
'userfullname' => array('langstr' => get_string('fullname'),
|
||||
'value' => fullname($USER)),
|
||||
'useremail' => array('langstr' => get_string('email'),
|
||||
'value' => $USER->email),
|
||||
'usericq' => array('langstr' => get_string('icqnumber'),
|
||||
'value' => $USER->icq),
|
||||
'userphone1' => array('langstr' => get_string('phone').' 1',
|
||||
'value' => $USER->phone1),
|
||||
'userphone2' => array('langstr' => get_string('phone').' 2',
|
||||
'value' => $USER->phone2),
|
||||
'userinstitution' => array('langstr' => get_string('institution'),
|
||||
'value' => $USER->institution),
|
||||
'userdepartment' => array('langstr' => get_string('department'),
|
||||
'value' => $USER->department),
|
||||
'useraddress' => array('langstr' => get_string('address'),
|
||||
'value' => $USER->address),
|
||||
'usercity' => array('langstr' => get_string('city'),
|
||||
'value' => $USER->city),
|
||||
'usertimezone' => array('langstr' => get_string('timezone'),
|
||||
'value' => get_user_timezone_offset()),
|
||||
'userurl' => array('langstr' => get_string('webpage'),
|
||||
'value' => $USER->url)
|
||||
);
|
||||
|
||||
$this->parameters = $userparameters + $this->parameters;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add new instance of repository resource
|
||||
*
|
||||
* Create alltext field before calling base class function.
|
||||
*
|
||||
* @param resource object
|
||||
*/
|
||||
function add_instance($resource) {
|
||||
$optionlist = array();
|
||||
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$parametername = "parameter$i";
|
||||
$parsename = "parse$i";
|
||||
if (!empty($resource->$parsename) and $resource->$parametername != "-") {
|
||||
$optionlist[] = $resource->$parametername."=".$resource->$parsename;
|
||||
}
|
||||
}
|
||||
|
||||
$resource->alltext = implode(',', $optionlist);
|
||||
|
||||
$this->_postprocess($resource);
|
||||
return parent::add_instance($resource);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update instance of repository resource
|
||||
*
|
||||
* Create alltext field before calling base class function.
|
||||
*
|
||||
* @param resource object
|
||||
*/
|
||||
function update_instance($resource) {
|
||||
$optionlist = array();
|
||||
$this->_postprocess($resource);
|
||||
/* echo '<xmp>';
|
||||
var_dump($_POST);
|
||||
var_dump($resource);die;*/
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
function _postprocess(&$resource) {
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
$alloptions = $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
if ($resource->windowpopup) {
|
||||
$optionlist = array();
|
||||
foreach ($alloptions as $option) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
unset($resource->$option);
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
unset($resource->windowpopup);
|
||||
$resource->options = '';
|
||||
|
||||
} else {
|
||||
if ($resource->framepage) {
|
||||
$resource->options = 'frame';
|
||||
} else {
|
||||
$resource->options = '';
|
||||
}
|
||||
unset($resource->framepage);
|
||||
$resource->popup = '';
|
||||
}
|
||||
|
||||
$optionlist = array();
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$parametername = "parameter$i";
|
||||
$parsename = "parse$i";
|
||||
if (!empty($resource->$parsename) and $resource->$parametername != "-") {
|
||||
$optionlist[] = $resource->$parametername."=".$resource->$parsename;
|
||||
}
|
||||
unset($resource->$parsename);
|
||||
unset($resource->$parametername);
|
||||
}
|
||||
|
||||
$resource->alltext = implode(',', $optionlist);
|
||||
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
|
||||
@ -215,6 +224,9 @@ function display() {
|
||||
$mimetype = mimeinfo("type", $resource->reference);
|
||||
$pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
|
||||
|
||||
$formatoptions = new object();
|
||||
$formatoptions->noclean = true;
|
||||
|
||||
if ($resource->options != "frame") {
|
||||
if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
|
||||
$resourcetype = "image";
|
||||
@ -247,21 +259,21 @@ function display() {
|
||||
$field = explode('=', $fieldstring);
|
||||
$querys[] = urlencode($field[1]).'='.urlencode($this->parameters[$field[0]]['value']);
|
||||
}
|
||||
$querystring = implode('&', $querys);
|
||||
$querystring = implode('&', $querys);
|
||||
}
|
||||
|
||||
|
||||
/// Set up some variables
|
||||
|
||||
$inpopup = !empty($_GET["inpopup"]);
|
||||
|
||||
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
|
||||
|
||||
$fullurl = $resource->reference. '&HIVE_SESSION='.$SESSION->HIVE_SESSION;
|
||||
if (!empty($querystring)) {
|
||||
$urlpieces = parse_url($resource->reference);
|
||||
if (empty($urlpieces['query'])) {
|
||||
$fullurl .= '?'.$querystring;
|
||||
} else {
|
||||
$fullurl .= '&'.$querystring;
|
||||
$fullurl .= '&'.$querystring;
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,7 +345,8 @@ function display() {
|
||||
|
||||
/// Now check whether we need to display a frameset
|
||||
|
||||
if (empty($_GET['frameset']) and !$embedded and !$inpopup and $resource->options == "frame" and empty($USER->screenreader)) {
|
||||
$frameset = optional_param('frameset', '', PARAM_ALPHA);
|
||||
if (empty($frameset) and !$embedded and !$inpopup and $resource->options == "frame" and empty($USER->screenreader)) {
|
||||
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
|
||||
echo "<html dir=\"ltr\">\n";
|
||||
echo '<head>';
|
||||
@ -359,11 +372,10 @@ function display() {
|
||||
|
||||
/// If we are in a frameset, just print the top of it
|
||||
|
||||
if (!empty($_GET['frameset']) and $_GET['frameset'] == "top") {
|
||||
if (!empty($frameset) and $frameset == "top") {
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name), "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));
|
||||
|
||||
$options->para = false;
|
||||
echo '<div class="summary">'.format_text($resource->summary, FORMAT_HTML, $options).'</div>';
|
||||
echo '<div class="summary">'.format_text($resource->summary, FORMAT_HTML, $formatoptions).'</div>';
|
||||
if (!empty($localpath)) { // Show some help
|
||||
echo '<div align="right" class="helplink">';
|
||||
link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
|
||||
@ -489,116 +501,11 @@ function display() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Setup a new repository resource
|
||||
*
|
||||
* Display a form to create a new or edit an existing repository resource
|
||||
*
|
||||
* @param form object
|
||||
* @param CFG global object
|
||||
* @param usehtmleditor global integer
|
||||
* @param RESOURCE_WINDOW_OPTIONS global array
|
||||
*/
|
||||
function setup($form) {
|
||||
global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
parent::setup($form);
|
||||
|
||||
$this->set_parameters(); // set the parameter array for the form
|
||||
|
||||
|
||||
$strfilename = get_string("location");
|
||||
$strnote = get_string("note", "resource");
|
||||
$strchooseafile = get_string("chooseafile", "resource");
|
||||
$strnewwindow = get_string("newwindow", "resource");
|
||||
$strnewwindowopen = get_string("newwindowopen", "resource");
|
||||
$strsearch = get_string("searchweb", "resource");
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$stringname = "str$optionname";
|
||||
$$stringname = get_string("new$optionname", "resource");
|
||||
$window->$optionname = "";
|
||||
$jsoption[] = "\"$optionname\"";
|
||||
}
|
||||
|
||||
$frameoption = "\"framepage\"";
|
||||
$popupoptions = implode(",", $jsoption);
|
||||
$jsoption[] = $frameoption;
|
||||
$alloptions = implode(",", $jsoption);
|
||||
|
||||
|
||||
|
||||
if ($form->instance) { // Re-editing
|
||||
if (!$form->popup) {
|
||||
$windowtype = "page"; // No popup text => in page
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
}
|
||||
} else {
|
||||
$windowtype = "popup";
|
||||
$rawoptions = explode(',', $form->popup);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
$option = explode('=', trim($rawoption));
|
||||
$optionname = $option[0];
|
||||
$optionvalue = $option[1];
|
||||
if ($optionname == 'height' or $optionname == 'width') {
|
||||
$window->$optionname = $optionvalue;
|
||||
} else if ($optionvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
|
||||
if ($optionname == 'height' or $optionname == 'width') {
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
} else if ($CFG->$defaultvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
$windowtype = ($CFG->resource_popup) ? 'popup' : 'page';
|
||||
if (empty($form->options)) {
|
||||
$form->options = 'frame';
|
||||
$form->reference = $CFG->resource_defaulturl;
|
||||
}
|
||||
}
|
||||
if (empty($form->reference)) {
|
||||
$form->reference = $CFG->resource_defaulturl;
|
||||
}
|
||||
|
||||
|
||||
/// set the 5 parameter defaults
|
||||
$alltextfield = array();
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$alltextfield[] = array('parameter' => '',
|
||||
'parse' => '');
|
||||
}
|
||||
/// load up any stored parameters
|
||||
if (!empty($form->alltext)) {
|
||||
$parray = explode(',', $form->alltext);
|
||||
foreach ($parray as $key => $fieldstring) {
|
||||
$field = explode('=', $fieldstring);
|
||||
$alltextfield[$key]['parameter'] = $field[0];
|
||||
$alltextfield[$key]['parse'] = $field[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
include("$CFG->dirroot/mod/resource/type/repository/repository.html");
|
||||
|
||||
parent::setup_end();
|
||||
}
|
||||
|
||||
//backwards compatible with existing resources
|
||||
function set_encrypted_parameter() {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource//type/file/externserverfile.php")) {
|
||||
if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource/type/file/externserverfile.php")) {
|
||||
include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php";
|
||||
if (function_exists(extern_server_file)) {
|
||||
return extern_server_file($this->resource->reference);
|
||||
@ -607,6 +514,111 @@ function set_encrypted_parameter() {
|
||||
return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase);
|
||||
}
|
||||
|
||||
|
||||
function setup_preprocessing(&$defaults){
|
||||
if (!empty($defaults['popup'])) {
|
||||
$defaults['windowpopup'] = 1;
|
||||
if (array_key_exists('popup', $defaults)) {
|
||||
$rawoptions = explode(',', $defaults['popup']);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
$option = explode('=', trim($rawoption));
|
||||
$defaults[$option[0]] = $option[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$defaults['windowpopup'] = 0;
|
||||
if (array_key_exists('options', $defaults)) {
|
||||
$defaults['framepage'] = ($defaults['options']=='frame');
|
||||
}
|
||||
}
|
||||
/// load up any stored parameters
|
||||
if (!empty($defaults['alltext'])) {
|
||||
$parray = explode(',', $defaults['alltext']);
|
||||
$i=0;
|
||||
foreach ($parray as $rawpar) {
|
||||
list($param, $varname) = explode('=', $rawpar);
|
||||
$defaults["parse$i"] = $varname;
|
||||
$defaults["parameter$i"] = $param;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setup_elements(&$mform) {
|
||||
global $CFG, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$this->set_parameters(); // set the parameter array for the form
|
||||
|
||||
$mform->addElement('text', 'reference', get_string('location'), array('size'=>'48'));
|
||||
|
||||
$options = 'menubar,location,toolbar,scrollbars,resizable,width=750,height=500';
|
||||
|
||||
$button = $mform->addElement('button', 'browsebutton', 'Browse for content in hive...');
|
||||
$url = '/mod/resource/type/repository/hive/openlitebrowse.php';
|
||||
$buttonattributes = array('title'=>'Browse for content in hive', 'onclick'=>"return openpopup('$url', '".$button->getName()."', '$options', 0);");
|
||||
$button->updateAttributes($buttonattributes);
|
||||
|
||||
$button = $mform->addElement('button', 'browsebutton', 'Search for content in Hive...');
|
||||
$url = '/mod/resource/type/repository/hive/openlitesearch.php';
|
||||
$buttonattributes = array('title'=>'Search for content in Hive', 'onclick'=>"return openpopup('$url', '".$button->getName()."', '$options', 0);");
|
||||
$button->updateAttributes($buttonattributes);
|
||||
|
||||
$button = $mform->addElement('button', 'browsebutton', 'Add new item to Hive...');
|
||||
$url = '/mod/resource/type/repository/hive/openlitepublish.php';
|
||||
$buttonattributes = array('title'=>'Add new item to Hive', 'onclick'=>"return openpopup('$url', '".$button->getName()."', '$options', 0);");
|
||||
$button->updateAttributes($buttonattributes);
|
||||
|
||||
$mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
|
||||
|
||||
$woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
|
||||
$mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
|
||||
$mform->setDefault('windowpopup', !empty($CFG->resource_popup));
|
||||
|
||||
$mform->addElement('checkbox', 'framepage', get_string('frameifpossible', 'resource'));
|
||||
$mform->setDefault('framepage', 0);
|
||||
// $mform->disabledIf('framepage', 'windowpopup', '', 0);
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if ($option == 'height' or $option == 'width') {
|
||||
$mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
} else {
|
||||
$mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
|
||||
|
||||
$options = array();
|
||||
$options['-'] = get_string('chooseparameter', 'resource').'...';
|
||||
$optgroup = '';
|
||||
foreach ($this->parameters as $pname=>$param) {
|
||||
if ($param['value']=='/optgroup') {
|
||||
$optgroup = '';
|
||||
continue;
|
||||
}
|
||||
if ($param['value']=='optgroup') {
|
||||
$optgroup = $param['langstr'];
|
||||
continue;
|
||||
}
|
||||
$options[$pname] = $optgroup.' - '.$param['langstr'];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->maxparameters; $i++) {
|
||||
$parametername = "parameter$i";
|
||||
$parsename = "parse$i";
|
||||
$group = array();
|
||||
$group[] =& $mform->createElement('text', $parsename, '', array('size'=>'12'));//TODO: accessiblity
|
||||
$group[] =& $mform->createElement('select', $parametername, '', $options);//TODO: accessiblity
|
||||
$mform->addGroup($group, 'pargroup', get_string('variablename', 'resource').'='.get_string('parameter', 'resource'), ' ', false);
|
||||
|
||||
$mform->setDefault($parametername, '-');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -7,79 +7,40 @@ function resource_text($cmid=0) {
|
||||
parent::resource_base($cmid);
|
||||
}
|
||||
|
||||
|
||||
function add_instance($resource) {
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// will create a new instance and return the id number
|
||||
// of the new instance.
|
||||
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$resource->timemodified = time();
|
||||
|
||||
if (isset($resource->windowpopup)) {
|
||||
$optionlist = array();
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if (isset($resource->$option)) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
}
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
|
||||
} else if (isset($resource->windowpage)) {
|
||||
$resource->popup = "";
|
||||
}
|
||||
|
||||
if (isset($resource->blockdisplay)) {
|
||||
$resource->options = 'showblocks';
|
||||
}
|
||||
|
||||
if (isset($resource->parametersettingspref)) {
|
||||
set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
|
||||
}
|
||||
if (isset($resource->windowsettingspref)) {
|
||||
set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
|
||||
}
|
||||
|
||||
return insert_record("resource", $resource);
|
||||
$this->_postprocess($resource);
|
||||
return parent::add_instance($resource);
|
||||
}
|
||||
|
||||
|
||||
function update_instance($resource) {
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
// will update an existing instance with new data.
|
||||
$this->_postprocess($resource);
|
||||
return parent::update_instance($resource);
|
||||
}
|
||||
|
||||
function _postprocess(&$resource) {
|
||||
global $RESOURCE_WINDOW_OPTIONS;
|
||||
$alloptions = $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$resource->id = $resource->instance;
|
||||
$resource->timemodified = time();
|
||||
|
||||
if (isset($resource->windowpopup)) {
|
||||
if ($resource->windowpopup) {
|
||||
$optionlist = array();
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if (isset($resource->$option)) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
}
|
||||
foreach ($alloptions as $option) {
|
||||
$optionlist[] = $option."=".$resource->$option;
|
||||
unset($resource->$option);
|
||||
}
|
||||
$resource->popup = implode(',', $optionlist);
|
||||
unset($resource->windowpopup);
|
||||
$resource->options = '';
|
||||
|
||||
} else if (isset($resource->windowpage)) {
|
||||
$resource->popup = "";
|
||||
} else {
|
||||
if ($resource->blockdisplay) {
|
||||
$resource->options = 'showblocks';
|
||||
} else {
|
||||
$resource->options = '';
|
||||
}
|
||||
unset($resource->blockdisplay);
|
||||
$resource->popup = '';
|
||||
}
|
||||
|
||||
if (isset($resource->blockdisplay)) {
|
||||
$resource->options = 'showblocks';
|
||||
}
|
||||
|
||||
if (isset($resource->parametersettingspref)) {
|
||||
set_user_preference('resource_parametersettingspref', $resource->parametersettingspref);
|
||||
}
|
||||
if (isset($resource->windowsettingspref)) {
|
||||
set_user_preference('resource_windowsettingspref', $resource->windowsettingspref);
|
||||
}
|
||||
|
||||
return update_record("resource", $resource);
|
||||
}
|
||||
|
||||
function display() {
|
||||
@ -105,25 +66,25 @@ function display() {
|
||||
parent::display();
|
||||
|
||||
/// Set up some shorthand variables
|
||||
$cm = $this->cm;
|
||||
$cm = $this->cm;
|
||||
$course = $this->course;
|
||||
$resource = $this->resource;
|
||||
$resource = $this->resource;
|
||||
|
||||
$pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
|
||||
$inpopup = optional_param('inpopup', '', PARAM_BOOL);
|
||||
|
||||
if ($resource->popup) {
|
||||
if ($inpopup) { /// Popup only
|
||||
add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}",
|
||||
add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}",
|
||||
$resource->id, $cm->id);
|
||||
print_header();
|
||||
print_simple_box(format_text($resource->alltext, $resource->options, $formatoptions, $course->id),
|
||||
print_simple_box(format_text($resource->alltext, $resource->reference, $formatoptions, $course->id),
|
||||
"center", "", "", "20");
|
||||
print_footer($course);
|
||||
} else { /// Make a page and a pop-up window
|
||||
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
navmenu($course, $cm));
|
||||
|
||||
echo "\n<script type=\"text/javascript\">";
|
||||
@ -150,10 +111,10 @@ function display() {
|
||||
|
||||
add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation ".format_string($resource->name),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
|
||||
navmenu($course, $cm));
|
||||
|
||||
print_simple_box(format_text($resource->alltext, $resource->options, $formatoptions, $course->id),
|
||||
print_simple_box(format_text($resource->alltext, $resource->options, $formatoptions, $course->id),
|
||||
"center", "", "", "20");
|
||||
|
||||
$strlastmodified = get_string("lastmodified");
|
||||
@ -167,76 +128,56 @@ function display() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setup($form) {
|
||||
global $CFG, $editorfields, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
$editorfields = 'summary';
|
||||
|
||||
parent::setup($form);
|
||||
|
||||
$strfilename = get_string("filename", "resource");
|
||||
$strnote = get_string("note", "resource");
|
||||
$strchooseafile = get_string("chooseafile", "resource");
|
||||
$strnewwindow = get_string("newwindow", "resource");
|
||||
$strnewwindowopen = get_string("newwindowopen", "resource");
|
||||
$strsearch = get_string("searchweb", "resource");
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$stringname = "str$optionname";
|
||||
$$stringname = get_string("new$optionname", "resource");
|
||||
$window->$optionname = "";
|
||||
$jsoption[] = "\"$optionname\"";
|
||||
}
|
||||
|
||||
$blockoption = "\"blockdisplay\"";
|
||||
$popupoptions = implode(",", $jsoption);
|
||||
$jsoption[] = $blockoption;
|
||||
$alloptions = implode(",", $jsoption);
|
||||
|
||||
if ($form->instance) { // Re-editing
|
||||
if (!$form->popup) {
|
||||
$windowtype = "page"; // No popup text => in page
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
}
|
||||
} else {
|
||||
$windowtype = "popup";
|
||||
$rawoptions = explode(',', $form->popup);
|
||||
function setup_preprocessing(&$defaults){
|
||||
if (!empty($defaults['popup'])) {
|
||||
$defaults['windowpopup'] = 1;
|
||||
if (array_key_exists('popup', $defaults)) {
|
||||
$rawoptions = explode(',', $defaults['popup']);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
$option = explode('=', trim($rawoption));
|
||||
$optionname = $option[0];
|
||||
$optionvalue = $option[1];
|
||||
if ($optionname == "height" or $optionname == "width") {
|
||||
$window->$optionname = $optionvalue;
|
||||
} else if ($optionvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
$defaults[$option[0]] = $option[1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) {
|
||||
$defaultvalue = "resource_popup$optionname";
|
||||
|
||||
if ($optionname == "height" or $optionname == "width") {
|
||||
$window->$optionname = $CFG->$defaultvalue;
|
||||
} else if ($CFG->$defaultvalue) {
|
||||
$window->$optionname = 'checked="checked"';
|
||||
}
|
||||
}
|
||||
|
||||
$windowtype = ($CFG->resource_popup) ? 'popup' : 'page';
|
||||
if (!isset($form->options)) {
|
||||
$form->options = '';
|
||||
$defaults['windowpopup'] = 0;
|
||||
if (array_key_exists('options', $defaults)) {
|
||||
$defaults['blockdisplay'] = ($defaults['options']=='showblocks');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$format_array = format_text_menu();
|
||||
unset($format_array[FORMAT_HTML]);
|
||||
include("$CFG->dirroot/mod/resource/type/text/text.html");
|
||||
function setup_elements(&$mform) {
|
||||
global $CFG, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
parent::setup_end();
|
||||
$mform->addElement('textarea', 'alltext', get_string('fulltext', 'resource'), array('cols'=>85, 'rows'=>30));
|
||||
$mform->setType('alltext', PARAM_RAW);
|
||||
$mform->setHelpButton('alltext', array('reading', 'writing', 'richtext'), false, 'editorhelpbutton');
|
||||
$mform->addRule('alltext', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$mform->addElement('format', 'reference', get_string('format'), null, false);
|
||||
$mform->setDefault('reference', FORMAT_PLAIN);
|
||||
|
||||
$mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
|
||||
|
||||
$woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
|
||||
$mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
|
||||
$mform->setDefault('windowpopup', !empty($CFG->resource_popup));
|
||||
|
||||
$mform->addElement('checkbox', 'blockdisplay', get_string('showcourseblocks', 'resource'));
|
||||
$mform->setDefault('blockdisplay', 0);
|
||||
// $mform->disabledIf('blockdisplay', 'windowpopup', '', 0);
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
if ($option == 'height' or $option == 'width') {
|
||||
$mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
} else {
|
||||
$mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
|
||||
$mform->setDefault($option, $CFG->{'resource_popup'.$option});
|
||||
// $mform->disabledIf($option, 'windowpopup', '', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user