Added a new help string
[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
5925d0ef 21if (!isset($CFG->resource_framesize)) {
22 set_config("resource_framesize", 130);
23}
92a419a2 24
86aa7ccf 25$RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location",
26 "menubar", "toolbar", "status", "height", "width");
92a419a2 27
cccb016a 28function resource_add_instance($resource) {
29// Given an object containing all the necessary data,
30// (defined by the form in mod.html) this function
31// will create a new instance and return the id number
32// of the new instance.
2a439ba7 33
86aa7ccf 34 global $RESOURCE_WINDOW_OPTIONS;
35
cccb016a 36 $resource->timemodified = time();
2a439ba7 37
86aa7ccf 38 if (isset($resource->setnewwindow)) {
39 $optionlist = array();
40 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
41 if (isset($resource->$option)) {
42 $optionlist[] = $option."=".$resource->$option;
43 }
44 }
45 $resource->alltext = implode(',', $optionlist);
46 }
47
cccb016a 48 return insert_record("resource", $resource);
49}
2a439ba7 50
cccb016a 51
52function resource_update_instance($resource) {
53// Given an object containing all the necessary data,
54// (defined by the form in mod.html) this function
55// will update an existing instance with new data.
56
86aa7ccf 57 global $RESOURCE_WINDOW_OPTIONS;
58
cccb016a 59 $resource->id = $resource->instance;
60 $resource->timemodified = time();
61
86aa7ccf 62 if (isset($resource->setnewwindow)) {
63 $optionlist = array();
64 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
65 if (isset($resource->$option)) {
66 $optionlist[] = $option."=".$resource->$option;
67 }
68 }
69 $resource->alltext = implode(',', $optionlist);
70 }
71
cccb016a 72 return update_record("resource", $resource);
73}
74
75
76function resource_delete_instance($id) {
77// Given an ID of an instance of this module,
78// this function will permanently delete the instance
79// and any data that depends on it.
80
81 if (! $resource = get_record("resource", "id", "$id")) {
82 return false;
2a439ba7 83 }
84
cccb016a 85 $result = true;
86
87 if (! delete_records("resource", "id", "$resource->id")) {
88 $result = false;
2a439ba7 89 }
90
cccb016a 91 return $result;
2a439ba7 92}
cccb016a 93
2a439ba7 94
95function resource_user_outline($course, $user, $mod, $resource) {
ebc3bd2b 96 if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
97 AND action='view' AND info='$resource->id'", "time ASC")) {
2a439ba7 98
99 $numviews = count($logs);
100 $lastlog = array_pop($logs);
101
102 $result->info = get_string("numviews", "", $numviews);
103 $result->time = $lastlog->time;
104
105 return $result;
106 }
107 return NULL;
108}
109
110
111function resource_user_complete($course, $user, $mod, $resource) {
112 global $CFG, $THEME;
113
ebc3bd2b 114 if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
115 AND action='view' AND info='$resource->id'", "time ASC")) {
2a439ba7 116 $numviews = count($logs);
117 $lastlog = array_pop($logs);
118
119 $strmostrecently = get_string("mostrecently");
120 $strnumviews = get_string("numviews", "", $numviews);
121
122 echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
123
124 } else {
4282d7dd 125 print_string("neverseen", "resource");
2a439ba7 126 }
127}
128
84caf038 129function resource_get_participants($resourceid) {
130//Returns the users with data in one resource
131//(NONE, byt must exists on EVERY mod !!)
132
133 return false;
134}
2a439ba7 135
8dddba42 136function resource_get_coursemodule_info($coursemodule) {
137/// Given a course_module object, this function returns any
138/// "extra" information that may be needed when printing
139/// this activity in a course listing.
140///
141/// See get_array_of_activities() in course/lib.php
142///
143
144 if ($resource = get_record("resource", "id", $coursemodule->instance)) {
145 if (($resource->type == UPLOADEDFILE or $resource->type == WEBLINK) and !empty($resource->alltext)) {
146 return urlencode("target=\"resource$resource->id\" onClick=\"return ".
147 "openpopup('/mod/resource/view.php?inpopup=true&id=".
148 $coursemodule->id.
149 "','resource$resource->id','$resource->alltext');\"");
150 }
151 }
152
153 return false;
154}
155
156
2a439ba7 157?>