From 26de8d35cee7b82d29cbcacfe7557c6e0d42394e Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 11 Jan 2007 19:47:08 +0000 Subject: [PATCH] fixed text field widths in new forms --- lib/form/choosecoursefile.php | 2 +- mod/assignment/mod_form.php | 2 +- mod/chat/mod_form.php | 2 +- mod/choice/mod_form.php | 2 +- mod/data/mod_form.php | 2 +- mod/exercise/mod_form.php | 2 +- mod/forum/mod_form.php | 2 +- mod/forum/post_form.php | 4 +- mod/glossary/mod_form.php | 2 +- mod/journal/mod_form.php | 2 +- mod/label/mod_form.php | 2 +- mod/lesson/mod_form.php | 2 +- mod/quiz/mod_form.php | 2 +- mod/resource/mod_form.php | 55 +++ mod/resource/type/file/resource.class.php | 267 +++++++------ mod/resource/type/html/resource.class.php | 195 ++++------ mod/resource/type/ims/resource.class.php | 236 ++++++------ .../type/repository/resource.class.php | 350 +++++++++--------- mod/resource/type/text/resource.class.php | 201 ++++------ 19 files changed, 633 insertions(+), 699 deletions(-) create mode 100644 mod/resource/mod_form.php diff --git a/lib/form/choosecoursefile.php b/lib/form/choosecoursefile.php index dabb5ac29e..4ac002b48c 100644 --- a/lib/form/choosecoursefile.php +++ b/lib/form/choosecoursefile.php @@ -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]; diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index e8796d8347..eea5bd594c 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -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'); diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php index 2afd8dd418..833bdc3e07 100644 --- a/mod/chat/mod_form.php +++ b/mod/chat/mod_form.php @@ -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'); diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index b9b67f6e05..1063bbafaa 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -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'); diff --git a/mod/data/mod_form.php b/mod/data/mod_form.php index 4eebcdc10a..b85fb19e97 100644 --- a/mod/data/mod_form.php +++ b/mod/data/mod_form.php @@ -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'); diff --git a/mod/exercise/mod_form.php b/mod/exercise/mod_form.php index 1aecf74692..fcf002d2e2 100644 --- a/mod/exercise/mod_form.php +++ b/mod/exercise/mod_form.php @@ -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'); diff --git a/mod/forum/mod_form.php b/mod/forum/mod_form.php index 395674dc6a..4e2b4f84da 100644 --- a/mod/forum/mod_form.php +++ b/mod/forum/mod_form.php @@ -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'); diff --git a/mod/forum/post_form.php b/mod/forum/post_form.php index 3a44d956ee..519d71a872 100644 --- a/mod/forum/post_form.php +++ b/mod/forum/post_form.php @@ -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'); diff --git a/mod/glossary/mod_form.php b/mod/glossary/mod_form.php index 28b0f25d4f..13b0865eaf 100644 --- a/mod/glossary/mod_form.php +++ b/mod/glossary/mod_form.php @@ -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'); diff --git a/mod/journal/mod_form.php b/mod/journal/mod_form.php index 896ff2616d..c2a6358526 100644 --- a/mod/journal/mod_form.php +++ b/mod/journal/mod_form.php @@ -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'); diff --git a/mod/label/mod_form.php b/mod/label/mod_form.php index cd61950920..dcc59ee31f 100644 --- a/mod/label/mod_form.php +++ b/mod/label/mod_form.php @@ -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'); diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 20d5d64a77..8de878dc87 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -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'); diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index d0703b3ab1..02d971d640 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -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")); diff --git a/mod/resource/mod_form.php b/mod/resource/mod_form.php new file mode 100644 index 0000000000..34d33a73ac --- /dev/null +++ b/mod/resource/mod_form.php @@ -0,0 +1,55 @@ +_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); + } + +} +?> \ No newline at end of file diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php index f119239e4d..b335809042 100644 --- a/mod/resource/type/file/resource.class.php +++ b/mod/resource/type/file/resource.class.php @@ -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 ''; + 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('&amp;', $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 .= '&amp;'.$querystring; } } @@ -294,7 +295,7 @@ function display() { } else { $relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}"; if ($querystring) { - $relativeurl .= '&'.$querystring; + $relativeurl .= '&amp;'.$querystring; } } $fullurl = "$CFG->wwwroot$relativeurl"; @@ -509,122 +510,120 @@ function display() { } +//backwards compatible with existing resources +function set_encrypted_parameter() { + global $CFG; -/** -* 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\""; + 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); + } } + return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase); +} - $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 (array_key_exists('options', $defaults)) { + $defaults['framepage'] = ($defaults['options']=='frame'); } } - if (empty($form->reference)) { - $form->reference = $CFG->resource_defaulturl; + /// 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; -/// set the 5 parameter defaults - $alltextfield = array(); - for ($i = 0; $i < $this->maxparameters; $i++) { - $alltextfield[] = array('parameter' => '', - 'parse' => ''); + $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); } - /// 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]; - } + + 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')); - include("$CFG->dirroot/mod/resource/type/file/file.html"); + $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)); - parent::setup_end(); -} + $mform->addElement('checkbox', 'framepage', get_string('frameifpossible', 'resource')); + $mform->setDefault('framepage', 0); +// $mform->disabledIf('framepage', 'windowpopup', '', 0); -//backwards compatible with existing resources -function set_encrypted_parameter() { - global $CFG; + 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); + } + } - 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); + $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, '-'); } - return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase); } } diff --git a/mod/resource/type/html/resource.class.php b/mod/resource/type/html/resource.class.php index d260beb077..3c25c51d0f 100644 --- a/mod/resource/type/html/resource.class.php +++ b/mod/resource/type/html/resource.class.php @@ -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. + $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); - - } else if (isset($resource->windowpage)) { - $resource->popup = ""; - } - - if (isset($resource->blockdisplay)) { - $resource->options = 'showblocks'; - } else { + unset($resource->windowpopup); $resource->options = ''; - } - if (isset($resource->parametersettingspref)) { - set_user_preference('resource_parametersettingspref', $resource->parametersettingspref); - } - if (isset($resource->windowsettingspref)) { - set_user_preference('resource_windowsettingspref', $resource->windowsettingspref); + } else { + if ($resource->blockdisplay) { + $resource->options = 'showblocks'; + } else { + $resource->options = ''; + } + unset($resource->blockdisplay); + $resource->popup = ''; } - - return update_record("resource", $resource); } - 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'); } } +} + +function setup_elements(&$mform) { + global $CFG, $RESOURCE_WINDOW_OPTIONS; - include("$CFG->dirroot/mod/resource/type/html/html.html"); + $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'); - parent::setup_end(); + $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); + } + } } diff --git a/mod/resource/type/ims/resource.class.php b/mod/resource/type/ims/resource.class.php index 6120dcb06e..42b3af8ecb 100644 --- a/mod/resource/type/ims/resource.class.php +++ b/mod/resource/type/ims/resource.class.php @@ -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"'; - } - } + $defaults['windowpopup'] = 0; + } + //Converts the alltext to form fields + 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)); - $windowtype = ($CFG->resource_popup) ? 'popup' : 'page'; - if (empty($form->options)) { - $form->options = 'frame'; - $form->reference = $CFG->resource_defaulturl; + 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); } } - 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"); - - parent::setup_end(); + $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);//???????? + } } //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}&amp;type={$resource->type}&amp;page={$page}&amp;frameset=ims\">$strprevious</a></span>"; + $contents .= "<span class=\"ims-nav-button\"><a href=\"view.php?id={$cm->id}&amp;type={$resource->type}&amp;page={$page}&amp;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}&amp;type={$resource->type}&amp;page={$page}&amp;frameset=ims\">$strnext</a></span>"; } else { diff --git a/mod/resource/type/repository/resource.class.php b/mod/resource/type/repository/resource.class.php index 06c0b9b388..63a524c815 100644 --- a/mod/resource/type/repository/resource.class.php +++ b/mod/resource/type/repository/resource.class.php @@ -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( -/** -* Add new instance of repository resource -* -* Create alltext field before calling base class function. -* -* @param resource object -*/ -function add_instance($resource) { - $optionlist = array(); + 'label1' => array('langstr' => get_string('user'), + 'value' => 'optgroup'), - 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; - } + '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; } +} - $resource->alltext = implode(',', $optionlist); +function add_instance($resource) { + $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('&amp;', $querys); } /// Set up some variables - $inpopup = !empty($_GET["inpopup"]); - + $inpopup = optional_param('inpopup', 0, PARAM_BOOL); + $fullurl = $resource->reference. '&amp;HIVE_SESSION='.$SESSION->HIVE_SESSION; if (!empty($querystring)) { $urlpieces = parse_url($resource->reference); if (empty($urlpieces['query'])) { $fullurl .= '?'.$querystring; } else { - $fullurl .= '&'.$querystring; + $fullurl .= '&amp;'.$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,122 +501,122 @@ function display() { } +//backwards compatible with existing resources +function set_encrypted_parameter() { + global $CFG; -/** -* 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; + 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); + } + } + 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++; + } + } +} - parent::setup($form); +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')); - $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"); + $options = 'menubar,location,toolbar,scrollbars,resizable,width=750,height=500'; - foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { - $stringname = "str$optionname"; - $$stringname = get_string("new$optionname", "resource"); - $window->$optionname = ""; - $jsoption[] = "\"$optionname\""; - } + $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); - $frameoption = "\"framepage\""; - $popupoptions = implode(",", $jsoption); - $jsoption[] = $frameoption; - $alloptions = implode(",", $jsoption); + $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')); - 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"; + $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)); - if ($optionname == 'height' or $optionname == 'width') { - $window->$optionname = $CFG->$defaultvalue; - } else if ($CFG->$defaultvalue) { - $window->$optionname = 'checked="checked"'; - } - } + $mform->addElement('checkbox', 'framepage', get_string('frameifpossible', 'resource')); + $mform->setDefault('framepage', 0); +// $mform->disabledIf('framepage', 'windowpopup', '', 0); - $windowtype = ($CFG->resource_popup) ? 'popup' : 'page'; - if (empty($form->options)) { - $form->options = 'frame'; - $form->reference = $CFG->resource_defaulturl; + 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); } } - if (empty($form->reference)) { - $form->reference = $CFG->resource_defaulturl; - } + $mform->addElement('header', 'parameters', get_string('parameters', 'resource')); -/// 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]; + $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); - 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")) { - include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php"; - if (function_exists(extern_server_file)) { - return extern_server_file($this->resource->reference); - } + $mform->setDefault($parametername, '-'); } - return md5($_SERVER['REMOTE_ADDR'].$CFG->resource_secretphrase); } } diff --git a/mod/resource/type/text/resource.class.php b/mod/resource/type/text/resource.class.php index e9e2b9dc5f..94257f0b55 100644 --- a/mod/resource/type/text/resource.class.php +++ b/mod/resource/type/text/resource.class.php @@ -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 = ""; - } - - 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); + } else { + if ($resource->blockdisplay) { + $resource->options = 'showblocks'; + } else { + $resource->options = ''; + } + unset($resource->blockdisplay); + $resource->popup = ''; } - - 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'); } } +} + +function setup_elements(&$mform) { + global $CFG, $RESOURCE_WINDOW_OPTIONS; + + $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'); - $format_array = format_text_menu(); - unset($format_array[FORMAT_HTML]); - include("$CFG->dirroot/mod/resource/type/text/text.html"); + $mform->addElement('format', 'reference', get_string('format'), null, false); + $mform->setDefault('reference', FORMAT_PLAIN); - parent::setup_end(); + $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); + } + } } -- 2.39.5