MDL-14591 added my name next to a portfolio todo
[moodle.git] / mod / resource / lib.php
CommitLineData
d1290cec 1<?php // $Id$
2a439ba7 2
713d78ea 3define('RESOURCE_LOCALPATH', 'LOCALPATH');
4
220a90c5 5global $RESOURCE_WINDOW_OPTIONS; // must be global because it might be included from a function!
ec81373f 6$RESOURCE_WINDOW_OPTIONS = array('resizable', 'scrollbars', 'directories', 'location',
6d77bd61 7 'menubar', 'toolbar', 'status', 'width', 'height');
3d30a455 8
220a90c5 9if (!isset($CFG->resource_hide_repository)) {
10 set_config("resource_hide_repository", "1");
83891eda 11}
12
d18830fe 13/**
14* resource_base is the base class for resource types
15*
16* This class provides all the functionality for a resource
17*/
18
19class resource_base {
20
65634a81 21 var $cm;
22 var $course;
23 var $resource;
65634a81 24 var $navlinks;
25
26 /**
27 * Constructor for the base resource class
28 *
29 * Constructor for the base resource class.
30 * If cmid is set create the cm, course, resource objects.
31 * and do some checks to make sure people can be here, and so on.
32 *
33 * @param cmid integer, the current course module id - not set for new resources
34 */
35 function resource_base($cmid=0) {
5f5cd33c 36 global $CFG, $COURSE, $DB;
65634a81 37
bddd9f6f 38 $this->navlinks = array();
65634a81 39
40 if ($cmid) {
41 if (! $this->cm = get_coursemodule_from_id('resource', $cmid)) {
baa336f0 42 print_error('invalidcoursemodule');
65634a81 43 }
44
5f5cd33c 45 if (! $this->course = $DB->get_record("course", array("id"=>$this->cm->course))) {
baa336f0 46 print_error('coursemisconf');
65634a81 47 }
48
5f5cd33c 49 if (! $this->resource = $DB->get_record("resource", array("id"=>$this->cm->instance))) {
baa336f0 50 print_error('invalidid', 'resource');
65634a81 51 }
52
53 $this->strresource = get_string("modulename", "resource");
54 $this->strresources = get_string("modulenameplural", "resource");
55
65634a81 56 if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
57 $pagetitle = strip_tags($this->course->shortname.': '.$this->strresource);
38e179a4 58 $navigation = build_navigation($this->navlinks, $this->cm);
65634a81 59
38e179a4 60 print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm));
65634a81 61 notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
62 }
d18830fe 63
65634a81 64 } else {
65 $this->course = $COURSE;
d18830fe 66 }
65634a81 67 }
6aac6eef 68
6aac6eef 69
65634a81 70 /**
71 * Display function does nothing in the base class
72 */
73 function display() {
6aac6eef 74
ec81373f 75 }
d18830fe 76
77
65634a81 78 /**
79 * Display the resource with the course blocks.
80 */
81 function display_course_blocks_start() {
6aac6eef 82
5f5cd33c 83 global $CFG, $USER, $THEME;
d18830fe 84
65634a81 85 require_once($CFG->libdir.'/blocklib.php');
86 require_once($CFG->libdir.'/pagelib.php');
87 require_once($CFG->dirroot.'/course/lib.php'); //required by some blocks
d18830fe 88
65634a81 89 $PAGE = page_create_object(PAGE_COURSE_VIEW, $this->course->id);
90 $this->PAGE = $PAGE;
91 $pageblocks = blocks_setup($PAGE);
0440482f 92
65634a81 93 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
0440482f 94
65634a81 95 /// Print the page header
0440482f 96
65634a81 97 $edit = optional_param('edit', -1, PARAM_BOOL);
0440482f 98
65634a81 99 if (($edit != -1) and $PAGE->user_allowed_editing()) {
100 $USER->editing = $edit;
101 }
d2b23346 102
65634a81 103 $morenavlinks = array($this->strresources => 'index.php?id='.$this->course->id,
104 $this->resource->name => '');
d2b23346 105
ca29e37d 106 $PAGE->print_header($this->course->shortname.': %fullname%', $morenavlinks, "", "",
107 update_module_button($this->cm->id, $this->course->id, $this->strresource));
0440482f 108
65634a81 109 echo '<table id="layout-table"><tr>';
0440482f 110
f58fcc82 111 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
112 foreach ($lt as $column) {
113 $lt1[] = $column;
114 if ($column == 'middle') break;
115 }
116 foreach ($lt1 as $column) {
117 switch ($column) {
118 case 'left':
119 if((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
120 echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
121 print_container_start();
122 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
123 print_container_end();
124 echo '</td>';
125 }
126 break;
127
128 case 'middle':
129 echo '<td id="middle-column">';
130 print_container_start(false, 'middle-column-wrap');
131 echo '<div id="resource">';
132 break;
133
134 case 'right':
135 if((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
136 echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
137 print_container_start();
138 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
139 print_container_end();
140 echo '</td>';
141 }
142 break;
143 }
65634a81 144 }
65634a81 145 }
0440482f 146
147
65634a81 148 /**
149 * Finish displaying the resource with the course blocks
150 */
151 function display_course_blocks_end() {
5f5cd33c 152 global $CFG, $THEME;
0440482f 153
65634a81 154 $PAGE = $this->PAGE;
155 $pageblocks = blocks_setup($PAGE);
156 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
0440482f 157
f58fcc82 158 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
159 foreach ($lt as $column) {
160 if ($column != 'middle') {
161 array_shift($lt);
162 } else if ($column == 'middle') {
163 break;
164 }
165 }
166 foreach ($lt as $column) {
167 switch ($column) {
168 case 'left':
169 if((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
170 echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
171 print_container_start();
172 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
173 print_container_end();
174 echo '</td>';
175 }
176 break;
177
178 case 'middle':
179 echo '</div>';
180 print_container_end();
181 echo '</td>';
182 break;
183
184 case 'right':
185 if((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
186 echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
187 print_container_start();
188 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
189 print_container_end();
190 echo '</td>';
191 }
192 break;
193 }
65634a81 194 }
0440482f 195
65634a81 196 echo '</tr></table>';
0440482f 197
65634a81 198 print_footer($this->course);
199
200 }
0440482f 201
202
65634a81 203 function add_instance($resource) {
c18269c7 204 global $DB;
65634a81 205 // Given an object containing all the necessary data,
7cac0c4b 206 // (defined by the form in mod_form.php) this function
65634a81 207 // will create a new instance and return the id number
208 // of the new instance.
2a439ba7 209
65634a81 210 $resource->timemodified = time();
2a439ba7 211
c18269c7 212 return $DB->insert_record("resource", $resource);
65634a81 213 }
2a439ba7 214
cccb016a 215
65634a81 216 function update_instance($resource) {
c18269c7 217 global $DB;
65634a81 218 // Given an object containing all the necessary data,
7cac0c4b 219 // (defined by the form in mod_form.php) this function
65634a81 220 // will update an existing instance with new data.
cccb016a 221
65634a81 222 $resource->id = $resource->instance;
223 $resource->timemodified = time();
cccb016a 224
c18269c7 225 return $DB->update_record("resource", $resource);
65634a81 226 }
cccb016a 227
228
65634a81 229 function delete_instance($resource) {
c18269c7 230 global $DB;
65634a81 231 // Given an object containing the resource data
232 // this function will permanently delete the instance
233 // and any data that depends on it.
cccb016a 234
65634a81 235 $result = true;
cccb016a 236
c18269c7 237 if (! $DB->delete_records("resource", array("id"=>$resource->id))) {
65634a81 238 $result = false;
239 }
2a439ba7 240
65634a81 241 return $result;
242 }
cccb016a 243
65634a81 244 function setup_elements(&$mform) {
245 //override to add your own options
246 }
2a439ba7 247
65634a81 248 function setup_preprocessing(&$default_values){
249 //override to add your own options
250 }
d18830fe 251
252} /// end of class definition
253
254
255
256function resource_add_instance($resource) {
257 global $CFG;
ec81373f 258
1b1d3422 259 $resource->type = clean_param($resource->type, PARAM_SAFEDIR); // Just to be safe
79035d46 260
d18830fe 261 require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
1aef6fb7 262 $resourceclass = "resource_$resource->type";
263 $res = new $resourceclass();
d18830fe 264
265 return $res->add_instance($resource);
266}
267
268function resource_update_instance($resource) {
269 global $CFG;
ec81373f 270
1b1d3422 271 $resource->type = clean_param($resource->type, PARAM_SAFEDIR); // Just to be safe
79035d46 272
d18830fe 273 require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
1aef6fb7 274 $resourceclass = "resource_$resource->type";
275 $res = new $resourceclass();
d18830fe 276
277 return $res->update_instance($resource);
278}
279
280function resource_delete_instance($id) {
c18269c7 281 global $CFG, $DB;
ec81373f 282
c18269c7 283 if (! $resource = $DB->get_record("resource", array("id"=>$id))) {
d18830fe 284 return false;
285 }
79035d46 286
1b1d3422 287 $resource->type = clean_param($resource->type, PARAM_SAFEDIR); // Just to be safe
ec81373f 288
d18830fe 289 require_once("$CFG->dirroot/mod/resource/type/$resource->type/resource.class.php");
1aef6fb7 290 $resourceclass = "resource_$resource->type";
291 $res = new $resourceclass();
d18830fe 292
f0c6abbf 293 return $res->delete_instance($resource);
d18830fe 294}
295
296
2a439ba7 297function resource_user_outline($course, $user, $mod, $resource) {
5f5cd33c 298 global $DB;
299
300 if ($logs = $DB->get_records("log", array('userid'=>$user->id, 'module'=>'resource',
301 'action'=>'view', 'info'=>$resource->id), "time ASC")) {
2a439ba7 302
303 $numviews = count($logs);
304 $lastlog = array_pop($logs);
305
9f741612 306 $result = new object();
2a439ba7 307 $result->info = get_string("numviews", "", $numviews);
308 $result->time = $lastlog->time;
309
310 return $result;
311 }
312 return NULL;
313}
314
315
316function resource_user_complete($course, $user, $mod, $resource) {
5f5cd33c 317 global $CFG, $DB;
2a439ba7 318
5f5cd33c 319 if ($logs = $DB->get_records("log", array('userid'=>$user->id, 'module'=>'resource',
320 'action'=>'view', 'info'=>$resource->id), "time ASC")) {
2a439ba7 321 $numviews = count($logs);
322 $lastlog = array_pop($logs);
323
324 $strmostrecently = get_string("mostrecently");
325 $strnumviews = get_string("numviews", "", $numviews);
326
327 echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
328
329 } else {
4282d7dd 330 print_string("neverseen", "resource");
2a439ba7 331 }
332}
333
84caf038 334function resource_get_participants($resourceid) {
335//Returns the users with data in one resource
336//(NONE, byt must exists on EVERY mod !!)
337
338 return false;
339}
2a439ba7 340
8dddba42 341function resource_get_coursemodule_info($coursemodule) {
ec81373f 342/// Given a course_module object, this function returns any
8dddba42 343/// "extra" information that may be needed when printing
344/// this activity in a course listing.
345///
346/// See get_array_of_activities() in course/lib.php
347///
5f5cd33c 348 global $CFG, $DB;
9d361034 349
350 $info = NULL;
351
5f5cd33c 352 if ($resource = $DB->get_record("resource", array("id"=>$coursemodule->instance), 'id, popup, reference, type, name')) {
dd97c328 353 $info = new object();
1ea543df 354 $info->name = $resource->name;
85e8239e 355 if (!empty($resource->popup)) {
bfca8b17 356 $info->extra = urlencode("onclick=\"this.target='resource$resource->id'; return ".
839f2456 357 "openpopup('/mod/resource/view.php?inpopup=true&amp;id=".
8dddba42 358 $coursemodule->id.
d18830fe 359 "','resource$resource->id','$resource->popup');\"");
8dddba42 360 }
9d361034 361
f1e0649c 362 require_once($CFG->libdir.'/filelib.php');
9d361034 363
85e8239e 364 if ($resource->type == 'file') {
ec81373f 365 $icon = mimeinfo("icon", $resource->reference);
9d361034 366 if ($icon != 'unknown.gif') {
ec81373f 367 $info->icon ="f/$icon";
85e8239e 368 } else {
ec81373f 369 $info->icon ="f/web.gif";
9d361034 370 }
d18830fe 371 } else if ($resource->type == 'directory') {
ec81373f 372 $info->icon ="f/folder.gif";
9d361034 373 }
8dddba42 374 }
375
9d361034 376 return $info;
8dddba42 377}
ec81373f 378
8367faba 379function resource_fetch_remote_file ($cm, $url, $headers = "" ) {
3bfe3922 380/// Snoopy is an HTTP client in PHP
381
382 global $CFG;
383
384 require_once("$CFG->libdir/snoopy/Snoopy.class.inc");
385
b2b8471e 386 $client = new Snoopy();
ec81373f 387 $ua = 'Moodle/'. $CFG->release . ' (+http://moodle.org';
bf46cd22 388 if ( $CFG->resource_usecache ) {
389 $ua = $ua . ')';
390 } else {
391 $ua = $ua . '; No cache)';
392 }
393 $client->agent = $ua;
394 $client->read_timeout = 5;
395 $client->use_gzip = true;
b2b8471e 396 if (is_array($headers) ) {
397 $client->rawheaders = $headers;
398 }
ec81373f 399
b2b8471e 400 @$client->fetch($url);
bf46cd22 401 if ( $client->status >= 200 && $client->status < 300 ) {
402 $tags = array("A" => "href=",
403 "IMG" => "src=",
404 "LINK" => "href=",
405 "AREA" => "href=",
406 "FRAME" => "src=",
407 "IFRAME" => "src=",
408 "FORM" => "action=");
ec81373f 409
bf46cd22 410 foreach ($tags as $tag => $key) {
839f2456 411 $prefix = "fetch.php?id=$cm->id&amp;url=";
bf46cd22 412 if ( $tag == "IMG" or $tag == "LINK" or $tag == "FORM") {
413 $prefix = "";
414 }
415 $client->results = resource_redirect_tags($client->results, $url, $tag, $key,$prefix);
416 }
417 } else {
418 if ( $client->status >= 400 && $client->status < 500) {
419 $client->results = get_string("fetchclienterror","resource"); // Client error
420 } elseif ( $client->status >= 500 && $client->status < 600) {
421 $client->results = get_string("fetchservererror","resource"); // Server error
422 } else {
423 $client->results = get_string("fetcherror","resource"); // Redirection? HEAD? Unknown error.
af65e103 424 }
af65e103 425 }
b2b8471e 426 return $client;
af65e103 427}
428
429function resource_redirect_tags($text, $url, $tagtoparse, $keytoparse,$prefix = "" ) {
bf46cd22 430 $valid = 1;
af65e103 431 if ( strpos($url,"?") == FALSE ) {
432 $valid = 1;
433 }
434 if ( $valid ) {
435 $lastpoint = strrpos($url,".");
436 $lastslash = strrpos($url,"/");
437 if ( $lastpoint > $lastslash ) {
438 $root = substr($url,0,$lastslash+1);
439 } else {
440 $root = $url;
441 }
ec81373f 442 if ( $root == "http://" or
af65e103 443 $root == "https://") {
444 $root = $url;
445 }
446 if ( substr($root,strlen($root)-1) == '/' ) {
447 $root = substr($root,0,-1);
448 }
ec81373f 449
af65e103 450 $mainroot = $root;
451 $lastslash = strrpos($mainroot,"/");
452 while ( $lastslash > 9) {
453 $mainroot = substr($mainroot,0,$lastslash);
ec81373f 454
af65e103 455 $lastslash = strrpos($mainroot,"/");
456 }
8dddba42 457
ec81373f 458 $regex = "/<$tagtoparse (.+?)>/is";
459 $count = preg_match_all($regex, $text, $hrefs);
af65e103 460 for ( $i = 0; $i < $count; $i++) {
461 $tag = $hrefs[1][$i];
ec81373f 462
af65e103 463 $poshref = strpos(strtolower($tag),strtolower($keytoparse));
464 $start = $poshref + strlen($keytoparse);
465 $left = substr($tag,0,$start);
466 if ( $tag[$start] == '"' ) {
467 $left .= '"';
468 $start++;
469 }
470 $posspace = strpos($tag," ", $start+1);
471 $right = "";
472 if ( $posspace != FALSE) {
473 $right = substr($tag, $posspace);
474 }
475 $end = strlen($tag)-1;
476 if ( $tag[$end] == '"' ) {
477 $right = '"' . $right;
478 }
479 $finalurl = substr($tag,$start,$end-$start+$diff);
480 // Here, we could have these possible values for $finalurl:
481 // file.ext Add current root dir
482 // http://(domain) don't care
483 // http://(domain)/ don't care
484 // http://(domain)/folder don't care
485 // http://(domain)/folder/ don't care
486 // http://(domain)/folder/file.ext don't care
487 // folder/ Add current root dir
488 // folder/file.ext Add current root dir
489 // /folder/ Add main root dir
490 // /folder/file.ext Add main root dir
491
492 // Special case: If finalurl contains a ?, it won't be parsed
bf46cd22 493 $valid = 1;
af65e103 494
495 if ( strpos($finalurl,"?") == FALSE ) {
496 $valid = 1;
497 }
498 if ( $valid ) {
499 if ( $finalurl[0] == "/" ) {
500 $finalurl = $mainroot . $finalurl;
ec81373f 501 } elseif ( strtolower(substr($finalurl,0,7)) != "http://" and
af65e103 502 strtolower(substr($finalurl,0,8)) != "https://") {
503 if ( $finalurl[0] == "/") {
504 $finalurl = $mainroot . $finalurl;
505 } else {
506 $finalurl = "$root/$finalurl";
507 }
508 }
ec81373f 509
af65e103 510 $text = str_replace($tag,"$left$prefix$finalurl$right",$text);
511 }
512 }
513 }
514 return $text;
515}
8dddba42 516
d18830fe 517function resource_is_url($path) {
427c8ccb 518 if (strpos($path, '://')) { // eg http:// https:// ftp:// etc
d18830fe 519 return true;
520 }
427c8ccb 521 if (strpos($path, '/') === 0) { // Starts with slash
522 return true;
523 }
524 return false;
d18830fe 525}
526
89bfeee0 527function resource_get_types() {
9f741612 528 global $CFG;
529
89bfeee0 530 $types = array();
6da4b261 531
3d30a455 532 $standardresources = array('text','html','file','directory');
6da4b261 533 foreach ($standardresources as $resourcetype) {
89bfeee0 534 $type = new object();
535 $type->modclass = MOD_CLASS_RESOURCE;
d81f018f 536 $type->name = $resourcetype;
89bfeee0 537 $type->type = "resource&amp;type=$resourcetype";
538 $type->typestr = get_string("resourcetype$resourcetype", 'resource');
539 $types[] = $type;
6da4b261 540 }
541
542 /// Drop-in extra resource types
543 $resourcetypes = get_list_of_plugins('mod/resource/type');
544 foreach ($resourcetypes as $resourcetype) {
37147357 545 if (!empty($CFG->{'resource_hide_'.$resourcetype})) { // Not wanted
546 continue;
547 }
89bfeee0 548 if (!in_array($resourcetype, $standardresources)) {
549 $type = new object();
550 $type->modclass = MOD_CLASS_RESOURCE;
d81f018f 551 $type->name = $resourcetype;
89bfeee0 552 $type->type = "resource&amp;type=$resourcetype";
553 $type->typestr = get_string("resourcetype$resourcetype", 'resource');
554 $types[] = $type;
6da4b261 555 }
556 }
89bfeee0 557
558 return $types;
6da4b261 559}
f3221af9 560
561function resource_get_view_actions() {
562 return array('view','view all');
563}
564
565function resource_get_post_actions() {
566 return array();
567}
568
a69be0d8 569function resource_renamefiles($course, $wdir, $oldname, $name) {
5f5cd33c 570 global $CFG, $DB;
a69be0d8 571
572 $status = '<p align=\"center\"><strong>'.get_string('affectedresources', 'resource').':</strong><ul>';
573 $updates = false;
574
575 $old = trim($wdir.'/'.$oldname, '/');
576 $new = trim($wdir.'/'.$name, '/');
577
578 $sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
5f5cd33c 579 FROM {resource} r, {course_modules} cm, {modules} m
580 WHERE r.course = :courseid
581 AND m.name = 'resource'
582 AND cm.module = m.id
583 AND cm.instance = r.id
584 AND (r.type = 'file' OR r.type = 'directory')
585 AND (r.reference LIKE :old1 OR r.reference = :old2)";
586 $params = array('courseid'=>$course->id, 'old1'=>"{$old}/%", 'old2'=>$old);
587 if ($resources = $DB->get_records_sql($sql, $params)) {
a69be0d8 588 foreach ($resources as $resource) {
589 $r = new object();
590 $r->id = $resource->id;
591 $r->reference = '';
592 if ($resource->reference == $old) {
5f5cd33c 593 $r->reference = $new;
a69be0d8 594 } else {
5f5cd33c 595 $r->reference = preg_replace('|^'.preg_quote($old, '|').'/|', $new.'/', $resource->reference);
a69be0d8 596 }
597 if ($r->reference !== '') {
598 $updates = true;
599 $status .= "<li><a href=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name</a>: $resource->reference ==> $r->reference</li>";
600 if (!empty($CFG->resource_autofilerename)) {
5f5cd33c 601 if (!$DB->update_record('resource', $r)) {
baa336f0 602 print_error('cannotupdate', 'resource');
a69be0d8 603 }
604 }
605 }
606 }
607 }
608 $status .= '</ul></p>';
609
610 if ($updates) {
611 echo $status;
612 if (empty($CFG->resource_autofilerename)) {
613 notify(get_string('warningdisabledrename', 'resource'));
614 }
615 }
616}
617
618function resource_delete_warning($course, $files) {
5f5cd33c 619 global $CFG, $DB;
a69be0d8 620
621 $found = array();
622
623 foreach($files as $key=>$file) {
624 $files[$key] = trim($file, '/');
625 }
626 $sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
5f5cd33c 627 FROM {resource} r,
628 {course_modules} cm,
629 {modules} m
630 WHERE r.course = ?
631 AND m.name = 'resource'
632 AND cm.module = m.id
633 AND cm.instance = r.id
634 AND (r.type = 'file' OR r.type = 'directory')";
635 if ($resources = $DB->get_records_sql($sql, array($course->id))) {
a69be0d8 636 foreach ($resources as $resource) {
637 if ($resource->reference == '') {
638 continue; // top shared directory does not prevent anything
639 }
640 if (in_array($resource->reference, $files)) {
641 $found[$resource->id] = $resource;
642 } else {
643 foreach($files as $file) {
644 if (preg_match('|^'.preg_quote($file, '|').'/|', $resource->reference)) {
645 $found[$resource->id] = $resource;
646 }
647 }
648 }
649 }
650 }
651
652 if (!empty($found)) {
653
654 print_simple_box_start("center");
655 echo '<p><strong>'.get_string('affectedresources', 'resource').':</strong><ul>';
656 foreach($found as $resource) {
657 echo "<li><a href=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name</a>: $resource->reference</li>";
658 }
659 echo '</ul></p>';
660 print_simple_box_end();
661
662 return true;
663 } else {
664 return false;
665 }
666}
667
0b5a80a1 668/**
669 * This function is used by the reset_course_userdata function in moodlelib.
670 * @param $data the data submitted from the reset course.
671 * @return array status array
672 */
673function resource_reset_userdata($data) {
674 return array();
675}
f432bebf 676
677/**
678 * Returns all other caps used in module
679 */
680function resource_get_extra_capabilities() {
681 return array('moodle/site:accessallgroups');
682}
683
2a439ba7 684?>