MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / resource / type / text / resource.class.php
blob138c2184b7f7fde48a9207224d24a752b679f0ac
1 <?php // $Id$
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 = '';
35 } else {
36 if (empty($resource->blockdisplay)) {
37 $resource->options = '';
38 } else {
39 $resource->options = 'showblocks';
41 unset($resource->blockdisplay);
42 $resource->popup = '';
46 function display() {
47 global $CFG;
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();
63 } else {
65 /// Set up generic stuff first, including checking for access
66 parent::display();
68 /// Set up some shorthand variables
69 $cm = $this->cm;
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);
80 print_header();
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 $this->navlinks[] = array('name' => format_string($resource->name), 'link' => null, 'type' => 'misc');
87 $this->navigation = build_navigation($this->navlinks);
89 print_header($pagetitle, $course->fullname, $this->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");
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
115 add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
116 $this->navlinks[] = array('name' => format_string($resource->name), 'link' => '', 'type' => 'title');
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, $resource->reference, $formatoptions, $course->id),
124 "center", "", "", "20");
126 $strlastmodified = get_string("lastmodified");
127 echo "<div class=\"modified\">$strlastmodified: ".userdate($resource->timemodified)."</div>";
129 print_footer($course);
137 function setup_preprocessing(&$defaults){
139 if (!isset($defaults['popup'])) {
140 // use form defaults
142 } else if (!empty($defaults['popup'])) {
143 $defaults['windowpopup'] = 1;
144 if (array_key_exists('popup', $defaults)) {
145 $rawoptions = explode(',', $defaults['popup']);
146 foreach ($rawoptions as $rawoption) {
147 $option = explode('=', trim($rawoption));
148 $defaults[$option[0]] = $option[1];
151 } else {
152 $defaults['windowpopup'] = 0;
153 if (array_key_exists('options', $defaults)) {
154 $defaults['blockdisplay'] = ($defaults['options']=='showblocks');
159 function setup_elements(&$mform) {
160 global $CFG, $RESOURCE_WINDOW_OPTIONS;
162 $mform->addElement('textarea', 'alltext', get_string('fulltext', 'resource'), array('cols'=>85, 'rows'=>30));
163 $mform->setType('alltext', PARAM_RAW);
164 $mform->setHelpButton('alltext', array('reading', 'writing', 'richtext'), false, 'editorhelpbutton');
165 $mform->addRule('alltext', get_string('required'), 'required', null, 'client');
167 $mform->addElement('format', 'reference', get_string('format'), null, false);
168 $mform->setDefault('reference', FORMAT_PLAIN);
170 $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
172 $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
173 $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
174 $mform->setDefault('windowpopup', !empty($CFG->resource_popup));
176 $mform->addElement('checkbox', 'blockdisplay', get_string('showcourseblocks', 'resource'));
177 $mform->setDefault('blockdisplay', 0);
178 $mform->disabledIf('blockdisplay', 'windowpopup', 'eq', 1);
179 $mform->setAdvanced('blockdisplay');
181 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
182 if ($option == 'height' or $option == 'width') {
183 $mform->addElement('text', $option, get_string('new'.$option, 'resource'), array('size'=>'4'));
184 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
185 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
186 } else {
187 $mform->addElement('checkbox', $option, get_string('new'.$option, 'resource'));
188 $mform->setDefault($option, $CFG->{'resource_popup'.$option});
189 $mform->disabledIf($option, 'windowpopup', 'eq', 0);
191 $mform->setAdvanced($option);