3 class resource_text
extends resource_base
{
6 function resource_text($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
= '';
36 if (empty($resource->blockdisplay
)) {
37 $resource->options
= '';
39 $resource->options
= 'showblocks';
41 unset($resource->blockdisplay
);
42 $resource->popup
= '';
49 $formatoptions = new object();
50 $formatoptions->noclean
= true;
52 /// Are we displaying the course blocks?
53 if ($this->resource->options
== 'showblocks') {
55 parent
::display_course_blocks_start();
57 if (trim(strip_tags($this->resource->alltext
))) {
58 echo format_text($this->resource->alltext
, FORMAT_MOODLE
, $formatoptions, $this->course
->id
);
61 parent
::display_course_blocks_end();
65 /// Set up generic stuff first, including checking for access
68 /// Set up some shorthand variables
70 $course = $this->course
;
71 $resource = $this->resource;
73 $pagetitle = strip_tags($course->shortname
.': '.format_string($resource->name
));
74 $inpopup = optional_param('inpopup', '', PARAM_BOOL
);
76 if ($resource->popup
) {
77 if ($inpopup) { /// Popup only
78 add_to_log($course->id
, "resource", "view", "view.php?id={$cm->id}",
79 $resource->id
, $cm->id
);
81 print_simple_box(format_text($resource->alltext
, $resource->reference
, $formatoptions, $course->id
),
82 "center", "", "", "20");
83 print_footer($course);
84 } else { /// Make a page and a pop-up window
86 print_header($pagetitle, $course->fullname
, "$this->navigation ".format_string($resource->name
),
87 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
),
88 navmenu($course, $cm));
90 echo "\n<script type=\"text/javascript\">";
91 echo "\n//<![CDATA[\n";
92 echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
96 if (trim(strip_tags($resource->summary
))) {
97 print_simple_box(format_text($resource->summary
, FORMAT_MOODLE
, $formatoptions, $course->id
), "center");
100 $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name
,true)."</a>";
102 echo '<div class="popupnotice">';
103 print_string('popupresource', 'resource');
105 print_string('popupresourcelink', 'resource', $link);
108 print_footer($course);
110 } else { /// not a popup at all
112 add_to_log($course->id
, "resource", "view", "view.php?id={$cm->id}", $resource->id
, $cm->id
);
113 $this->navlinks
[] = array('name' => format_string($resource->name
), 'link' => '', 'type' => 'title');
114 $this->navigation
= build_navigation($this->navlinks
);
116 print_header($pagetitle, $course->fullname
, $this->navigation
,
117 "", "", true, update_module_button($cm->id
, $course->id
, $this->strresource
),
118 navmenu($course, $cm));
120 print_simple_box(format_text($resource->alltext
, $resource->reference
, $formatoptions, $course->id
),
121 "center", "", "", "20");
123 $strlastmodified = get_string("lastmodified");
124 echo "<div class=\"modified\">$strlastmodified: ".userdate($resource->timemodified
)."</div>";
126 print_footer($course);
134 function setup_preprocessing(&$defaults){
136 if (!isset($defaults['popup'])) {
139 } else if (!empty($defaults['popup'])) {
140 $defaults['windowpopup'] = 1;
141 if (array_key_exists('popup', $defaults)) {
142 $rawoptions = explode(',', $defaults['popup']);
143 foreach ($rawoptions as $rawoption) {
144 $option = explode('=', trim($rawoption));
145 $defaults[$option[0]] = $option[1];
149 $defaults['windowpopup'] = 0;
150 if (array_key_exists('options', $defaults)) {
151 $defaults['blockdisplay'] = ($defaults['options']=='showblocks');
156 function setup_elements(&$mform) {
157 global $CFG, $RESOURCE_WINDOW_OPTIONS;
159 $mform->addElement('textarea', 'alltext', get_string('fulltext', 'resource'), array('cols'=>85, 'rows'=>30));
160 $mform->setType('alltext', PARAM_RAW
);
161 $mform->setHelpButton('alltext', array('reading', 'writing', 'richtext'), false, 'editorhelpbutton');
162 $mform->addRule('alltext', get_string('required'), 'required', null, 'client');
164 $mform->addElement('format', 'reference', get_string('format'), null, false);
165 $mform->setDefault('reference', FORMAT_PLAIN
);
167 $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
169 $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
170 $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
171 $mform->setDefault('windowpopup', !empty($CFG->resource_popup
));
173 $mform->addElement('checkbox', 'blockdisplay', get_string('showcourseblocks', 'resource'));
174 $mform->setDefault('blockdisplay', 0);
175 $mform->disabledIf('blockdisplay', 'windowpopup', 'eq', 1);
176 $mform->setAdvanced('blockdisplay');
178 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
179 if ($option == 'height' or $option == 'width') {
180 $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
181 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
182 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
184 $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
185 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
186 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
188 $mform->setAdvanced($option);