Email addresses are now well and truly obfuscated on public profile pages
[moodle.git] / mod / resource / lib.php
CommitLineData
2a439ba7 1<?PHP // $Id$
2
3define("REFERENCE", "1");
4define("WEBPAGE", "2");
5define("UPLOADEDFILE","3");
6define("PLAINTEXT", "4");
7define("WEBLINK", "5");
8define("HTML", "6");
f7a5c8fa 9define("PROGRAM", "7");
3e9ca9fb 10define("WIKITEXT", "8");
2a439ba7 11
12$RESOURCE_TYPE = array (REFERENCE => get_string("resourcetype1", "resource"),
13 WEBPAGE => get_string("resourcetype2", "resource"),
14 UPLOADEDFILE => get_string("resourcetype3", "resource"),
15 PLAINTEXT => get_string("resourcetype4", "resource"),
16 WEBLINK => get_string("resourcetype5", "resource"),
f7a5c8fa 17 HTML => get_string("resourcetype6", "resource"),
3e9ca9fb 18 PROGRAM => get_string("resourcetype7", "resource"),
19 WIKITEXT => get_string("resourcetype8", "resource") );
2a439ba7 20
92a419a2 21$RESOURCE_FRAME_SIZE = 130;
22
23
2a439ba7 24function resource_list_all_resources($courseid=0, $sort="name ASC", $recent=0) {
25 // Returns list of all resource links in an array of strings
26
27 global $CFG, $USER;
28
29 if ($courseid) {
30 if (! $course = get_record("course", "id", $courseid)) {
31 error("Could not find the specified course");
32 }
33
34 require_login($course->id);
35
36 } else {
37 if (! $course = get_record("course", "category", 0)) {
38 error("Could not find a top-level course!");
39 }
40 }
41
42 if ($resources = get_all_instances_in_course("resource", $course->id, $sort)) {
43 foreach ($resources as $resource) {
44 $link = "<A HREF=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->coursemodule\">$resource->name</A>";
45 if ($USER->editing) {
46 $link .= "&nbsp; &nbsp;
47 <A HREF=\"$CFG->wwwroot/course/mod.php?delete=$resource->coursemodule\"><IMG
48 SRC=\"$CFG->wwwroot/pix/t/delete.gif\" BORDER=0 ALT=Delete></A>
49 <A HREF=\"$CFG->wwwroot/course/mod.php?update=$resource->coursemodule\"><IMG
50 SRC=\"$CFG->wwwroot/pix/t/edit.gif\" BORDER=0 ALT=Update></A>";
51 }
52 $links[] = $link;
53 }
54 }
55
56 return $links;
57}
58
59
60function resource_user_outline($course, $user, $mod, $resource) {
ebc3bd2b 61 if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
62 AND action='view' AND info='$resource->id'", "time ASC")) {
2a439ba7 63
64 $numviews = count($logs);
65 $lastlog = array_pop($logs);
66
67 $result->info = get_string("numviews", "", $numviews);
68 $result->time = $lastlog->time;
69
70 return $result;
71 }
72 return NULL;
73}
74
75
76function resource_user_complete($course, $user, $mod, $resource) {
77 global $CFG, $THEME;
78
ebc3bd2b 79 if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
80 AND action='view' AND info='$resource->id'", "time ASC")) {
2a439ba7 81 $numviews = count($logs);
82 $lastlog = array_pop($logs);
83
84 $strmostrecently = get_string("mostrecently");
85 $strnumviews = get_string("numviews", "", $numviews);
86
87 echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
88
89 } else {
4282d7dd 90 print_string("neverseen", "resource");
2a439ba7 91 }
92}
93
94function resource_add_instance($resource) {
95// Given an object containing all the necessary data,
96// (defined by the form in mod.html) this function
97// will create a new instance and return the id number
98// of the new instance.
99
100 $resource->timemodified = time();
101
102 return insert_record("resource", $resource);
103}
104
105
106function resource_update_instance($resource) {
107// Given an object containing all the necessary data,
108// (defined by the form in mod.html) this function
109// will update an existing instance with new data.
110
111 $resource->id = $resource->instance;
112 $resource->timemodified = time();
113
114 return update_record("resource", $resource);
115}
116
117
118function resource_delete_instance($id) {
119// Given an ID of an instance of this module,
120// this function will permanently delete the instance
121// and any data that depends on it.
122
123 if (! $resource = get_record("resource", "id", "$id")) {
124 return false;
125 }
126
127 $result = true;
128
129 if (! delete_records("resource", "id", "$resource->id")) {
130 $result = false;
131 }
132
133 return $result;
134}
135
136
137?>