Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / resource / type / html / resource.class.php
bloba89c5820409476da49a4496a3a2501dffee9a968
1 <?php // $Id$
3 class resource_html extends resource_base {
6 function resource_html($cmid=0) {
7 parent::resource_base($cmid);
10 function add_instance($resource) {
11 $this->_postprocess($resource);
12 return parent::add_instance($resource);
16 function update_instance($resource) {
17 $this->_postprocess($resource);
18 return parent::update_instance($resource);
21 function _postprocess(&$resource) {
22 global $RESOURCE_WINDOW_OPTIONS;
23 $alloptions = $RESOURCE_WINDOW_OPTIONS;
25 if ($resource->windowpopup) {
26 $optionlist = array();
27 foreach ($alloptions as $option) {
28 $optionlist[] = $option."=".$resource->$option;
29 unset($resource->$option);
31 $resource->popup = implode(',', $optionlist);
32 unset($resource->windowpopup);
33 $resource->options = '';
35 } else {
36 if (empty($resource->blockdisplay)) {
37 $resource->options = '';
38 } else {
39 $resource->options = 'showblocks';
41 unset($resource->blockdisplay);
42 $resource->popup = '';
47 function display() {
48 global $CFG;
50 $formatoptions = new object();
51 $formatoptions->noclean = true;
53 /// Set up some shorthand variables
54 $cm = $this->cm;
55 $course = $this->course;
56 $resource = $this->resource;
58 // fix for MDL-9021, thanks Etienne Roz
59 // fix for MDL-15387, thanks to John Beedell
60 add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
62 /// Are we displaying the course blocks?
63 if ($this->resource->options == 'showblocks') {
65 parent::display_course_blocks_start();
67 echo format_text($this->resource->alltext, FORMAT_HTML, $formatoptions, $this->course->id);
69 parent::display_course_blocks_end();
71 } else {
73 /// Set up generic stuff first, including checking for access
74 parent::display();
76 $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
77 $inpopup = optional_param('inpopup', '', PARAM_BOOL);
79 if ($resource->popup) {
80 if ($inpopup) { /// Popup only
82 print_header();
83 print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id),
84 "center clearfix", "", "", "20");
85 print_footer($course);
86 } else { /// Make a page and a pop-up window
87 $navigation = build_navigation($this->navlinks, $cm);
89 print_header($pagetitle, $course->fullname, $navigation,
90 "", "", true, update_module_button($cm->id, $course->id, $this->strresource),
91 navmenu($course, $cm));
93 echo "\n<script type=\"text/javascript\">";
94 echo "\n//<![CDATA[\n";
95 echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
96 echo "\n//]]>\n";
97 echo '</script>';
99 if (trim(strip_tags($resource->summary))) {
100 print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center clearfix");
103 $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
105 echo '<div class="popupnotice">';
106 print_string('popupresource', 'resource');
107 echo '<br />';
108 print_string('popupresourcelink', 'resource', $link);
109 echo '</div>';
111 print_footer($course);
113 } else { /// not a popup at all
114 $navigation = build_navigation($this->navlinks, $cm);
116 print_header($pagetitle, $course->fullname, $navigation,
117 "", "", true, update_module_button($cm->id, $course->id, $this->strresource),
118 navmenu($course, $cm));
120 print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id), "center clearfix", "", "", "20");
122 $strlastmodified = get_string("lastmodified");
123 echo "<div class=\"modified\">$strlastmodified: ".userdate($resource->timemodified)."</div>";
125 print_footer($course);
132 function setup_preprocessing(&$defaults){
134 if (!isset($defaults['popup'])) {
135 // use form defaults
137 } else if (!empty($defaults['popup'])) {
138 $defaults['windowpopup'] = 1;
139 if (array_key_exists('popup', $defaults)) {
140 $rawoptions = explode(',', $defaults['popup']);
141 foreach ($rawoptions as $rawoption) {
142 $option = explode('=', trim($rawoption));
143 $defaults[$option[0]] = $option[1];
146 } else {
147 $defaults['windowpopup'] = 0;
148 if (array_key_exists('options', $defaults)) {
149 $defaults['blockdisplay'] = ($defaults['options']=='showblocks');
154 function setup_elements(&$mform) {
155 global $CFG, $RESOURCE_WINDOW_OPTIONS;
157 $mform->addElement('htmleditor', 'alltext', get_string('fulltext', 'resource'), array('cols'=>85, 'rows'=>30));
158 $mform->setType('alltext', PARAM_RAW);
159 $mform->setHelpButton('alltext', array('reading', 'writing', 'richtext'), false, 'editorhelpbutton');
160 $mform->addRule('alltext', get_string('required'), 'required', null, 'client');
162 $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
164 $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
165 $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
166 $mform->setDefault('windowpopup', !empty($CFG->resource_popup));
168 $mform->addElement('checkbox', 'blockdisplay', get_string('showcourseblocks', 'resource'));
169 $mform->setDefault('blockdisplay', 0);
170 $mform->disabledIf('blockdisplay', 'windowpopup', 'eq', '1');
171 $mform->setAdvanced('blockdisplay');
173 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
174 if ($option == 'height' or $option == 'width') {
175 $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
176 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
177 $mform->disabledIf($option, 'windowpopup', 'eq', '0');
178 } else {
179 $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
180 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
181 $mform->disabledIf($option, 'windowpopup', 'eq', '0');
183 $mform->setAdvanced($option);