| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: resource.class.php,v 1.37.2.1 2007/10/12 16:09:47 tjhunt Exp $ 2 3 class resource_text extends resource_base { 4 5 6 function resource_text($cmid=0) { 7 parent::resource_base($cmid); 8 } 9 10 function add_instance($resource) { 11 $this->_postprocess($resource); 12 return parent::add_instance($resource); 13 } 14 15 16 function update_instance($resource) { 17 $this->_postprocess($resource); 18 return parent::update_instance($resource); 19 } 20 21 function _postprocess(&$resource) { 22 global $RESOURCE_WINDOW_OPTIONS; 23 $alloptions = $RESOURCE_WINDOW_OPTIONS; 24 25 if ($resource->windowpopup) { 26 $optionlist = array(); 27 foreach ($alloptions as $option) { 28 $optionlist[] = $option."=".$resource->$option; 29 unset($resource->$option); 30 } 31 $resource->popup = implode(',', $optionlist); 32 unset($resource->windowpopup); 33 $resource->options = ''; 34 35 } else { 36 if (empty($resource->blockdisplay)) { 37 $resource->options = ''; 38 } else { 39 $resource->options = 'showblocks'; 40 } 41 unset($resource->blockdisplay); 42 $resource->popup = ''; 43 } 44 } 45 46 function display() { 47 global $CFG; 48 49 $formatoptions = new object(); 50 $formatoptions->noclean = true; 51 52 /// Are we displaying the course blocks? 53 if ($this->resource->options == 'showblocks') { 54 55 parent::display_course_blocks_start(); 56 57 if (trim(strip_tags($this->resource->alltext))) { 58 echo format_text($this->resource->alltext, FORMAT_MOODLE, $formatoptions, $this->course->id); 59 } 60 61 parent::display_course_blocks_end(); 62 63 } else { 64 65 /// Set up generic stuff first, including checking for access 66 parent::display(); 67 68 /// Set up some shorthand variables 69 $cm = $this->cm; 70 $course = $this->course; 71 $resource = $this->resource; 72 73 $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name)); 74 $inpopup = optional_param('inpopup', '', PARAM_BOOL); 75 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 85 $navigation = build_navigation($this->navlinks, $cm); 86 87 print_header($pagetitle, $course->fullname, $navigation, 88 "", "", true, update_module_button($cm->id, $course->id, $this->strresource), 89 navmenu($course, $cm)); 90 91 echo "\n<script type=\"text/javascript\">"; 92 echo "\n//<![CDATA[\n"; 93 echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n"; 94 echo "\n//]]>\n"; 95 echo '</script>'; 96 97 if (trim(strip_tags($resource->summary))) { 98 print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center"); 99 } 100 101 $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 103 echo '<div class="popupnotice">'; 104 print_string('popupresource', 'resource'); 105 echo '<br />'; 106 print_string('popupresourcelink', 'resource', $link); 107 echo '</div>'; 108 109 print_footer($course); 110 } 111 } else { /// not a popup at all 112 113 add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); 114 $navigation = build_navigation($this->navlinks, $cm); 115 116 print_header($pagetitle, $course->fullname, $navigation, 117 "", "", true, update_module_button($cm->id, $course->id, $this->strresource), 118 navmenu($course, $cm)); 119 120 print_simple_box(format_text($resource->alltext, $resource->reference, $formatoptions, $course->id), 121 "center", "", "", "20"); 122 123 $strlastmodified = get_string("lastmodified"); 124 echo "<div class=\"modified\">$strlastmodified: ".userdate($resource->timemodified)."</div>"; 125 126 print_footer($course); 127 } 128 129 } 130 131 } 132 133 134 function setup_preprocessing(&$defaults){ 135 136 if (!isset($defaults['popup'])) { 137 // use form defaults 138 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]; 146 } 147 } 148 } else { 149 $defaults['windowpopup'] = 0; 150 if (array_key_exists('options', $defaults)) { 151 $defaults['blockdisplay'] = ($defaults['options']=='showblocks'); 152 } 153 } 154 } 155 156 function setup_elements(&$mform) { 157 global $CFG, $RESOURCE_WINDOW_OPTIONS; 158 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'); 163 164 $mform->addElement('format', 'reference', get_string('format'), null, false); 165 $mform->setDefault('reference', FORMAT_PLAIN); 166 167 $mform->addElement('header', 'displaysettings', get_string('display', 'resource')); 168 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)); 172 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'); 177 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); 183 } else { 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); 187 } 188 $mform->setAdvanced($option); 189 } 190 } 191 192 193 } 194 195 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |