adding some strings
[moodle-linuxchix.git] / mod / resource / type / html / resource.class.php
blobbb72fdbcf317ac2a172a1707261a27e4e89c50ee
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 /// Are we displaying the course blocks?
54 if ($this->resource->options == 'showblocks') {
56 parent::display_course_blocks_start();
58 echo format_text($this->resource->alltext, FORMAT_HTML, $formatoptions, $this->course->id);
60 parent::display_course_blocks_end();
62 } else {
64 /// Set up generic stuff first, including checking for access
65 parent::display();
67 /// Set up some shorthand variables
68 $cm = $this->cm;
69 $course = $this->course;
70 $resource = $this->resource;
72 $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
73 $inpopup = optional_param('inpopup', '', PARAM_BOOL);
75 // fix for MDL-9021, thanks Etienne Roz
76 add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
78 if ($resource->popup) {
79 if ($inpopup) { /// Popup only
81 print_header();
82 print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id),
83 "center clearfix", "", "", "20");
84 print_footer($course);
85 } else { /// Make a page and a pop-up window
87 $this->navlinks[] = array('name' => format_string($resource->name), 'link' => '', 'type' => 'activityinstance');
88 $this->navigation = build_navigation($this->navlinks);
90 print_header($pagetitle, $course->fullname, $this->navigation,
91 "", "", true, update_module_button($cm->id, $course->id, $this->strresource),
92 navmenu($course, $cm));
94 echo "\n<script type=\"text/javascript\">";
95 echo "\n//<![CDATA[\n";
96 echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
97 echo "\n//]]>\n";
98 echo '</script>';
100 if (trim(strip_tags($resource->summary))) {
101 print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center clearfix");
104 $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>";
106 echo '<div class="popupnotice">';
107 print_string('popupresource', 'resource');
108 echo '<br />';
109 print_string('popupresourcelink', 'resource', $link);
110 echo '</div>';
112 print_footer($course);
114 } else { /// not a popup at all
116 $this->navlinks[] = array('name' => format_string($resource->name), 'link' => '', 'type' => 'activityinstance');
117 $this->navigation = build_navigation($this->navlinks);
119 print_header($pagetitle, $course->fullname, $this->navigation,
120 "", "", true, update_module_button($cm->id, $course->id, $this->strresource),
121 navmenu($course, $cm));
123 print_simple_box(format_text($resource->alltext, FORMAT_HTML, $formatoptions, $course->id), "center clearfix", "", "", "20");
125 $strlastmodified = get_string("lastmodified");
126 echo "<div class=\"modified\">$strlastmodified: ".userdate($resource->timemodified)."</div>";
128 print_footer($course);
135 function setup_preprocessing(&$defaults){
137 if (!isset($defaults['popup'])) {
138 // use form defaults
140 } else if (!empty($defaults['popup'])) {
141 $defaults['windowpopup'] = 1;
142 if (array_key_exists('popup', $defaults)) {
143 $rawoptions = explode(',', $defaults['popup']);
144 foreach ($rawoptions as $rawoption) {
145 $option = explode('=', trim($rawoption));
146 $defaults[$option[0]] = $option[1];
149 } else {
150 $defaults['windowpopup'] = 0;
151 if (array_key_exists('options', $defaults)) {
152 $defaults['blockdisplay'] = ($defaults['options']=='showblocks');
157 function setup_elements(&$mform) {
158 global $CFG, $RESOURCE_WINDOW_OPTIONS;
160 $mform->addElement('htmleditor', 'alltext', get_string('fulltext', 'resource'), array('cols'=>85, 'rows'=>30));
161 $mform->setType('alltext', PARAM_RAW);
162 $mform->setHelpButton('alltext', array('reading', 'writing', 'richtext'), false, 'editorhelpbutton');
163 $mform->addRule('alltext', get_string('required'), 'required', null, 'client');
165 $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
167 $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
168 $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
169 $mform->setDefault('windowpopup', !empty($CFG->resource_popup));
171 $mform->addElement('checkbox', 'blockdisplay', get_string('showcourseblocks', 'resource'));
172 $mform->setDefault('blockdisplay', 0);
173 $mform->disabledIf('blockdisplay', 'windowpopup', 'eq', '1');
174 $mform->setAdvanced('blockdisplay');
176 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
177 if ($option == 'height' or $option == 'width') {
178 $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
179 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
180 $mform->disabledIf($option, 'windowpopup', 'eq', '0');
181 } else {
182 $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
183 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
184 $mform->disabledIf($option, 'windowpopup', 'eq', '0');
186 $mform->setAdvanced($option);