Better set_config (give immediate results)
[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
86aa7ccf 23$RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location",
24 "menubar", "toolbar", "status", "height", "width");
92a419a2 25
cccb016a 26function resource_add_instance($resource) {
27// Given an object containing all the necessary data,
28// (defined by the form in mod.html) this function
29// will create a new instance and return the id number
30// of the new instance.
2a439ba7 31
86aa7ccf 32 global $RESOURCE_WINDOW_OPTIONS;
33
cccb016a 34 $resource->timemodified = time();
2a439ba7 35
86aa7ccf 36 if (isset($resource->setnewwindow)) {
37 $optionlist = array();
38 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
39 if (isset($resource->$option)) {
40 $optionlist[] = $option."=".$resource->$option;
41 }
42 }
43 $resource->alltext = implode(',', $optionlist);
44 }
45
cccb016a 46 return insert_record("resource", $resource);
47}
2a439ba7 48
cccb016a 49
50function resource_update_instance($resource) {
51// Given an object containing all the necessary data,
52// (defined by the form in mod.html) this function
53// will update an existing instance with new data.
54
86aa7ccf 55 global $RESOURCE_WINDOW_OPTIONS;
56
cccb016a 57 $resource->id = $resource->instance;
58 $resource->timemodified = time();
59
86aa7ccf 60 if (isset($resource->setnewwindow)) {
61 $optionlist = array();
62 foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
63 if (isset($resource->$option)) {
64 $optionlist[] = $option."=".$resource->$option;
65 }
66 }
67 $resource->alltext = implode(',', $optionlist);
68 }
69
cccb016a 70 return update_record("resource", $resource);
71}
72
73
74function resource_delete_instance($id) {
75// Given an ID of an instance of this module,
76// this function will permanently delete the instance
77// and any data that depends on it.
78
79 if (! $resource = get_record("resource", "id", "$id")) {
80 return false;
2a439ba7 81 }
82
cccb016a 83 $result = true;
84
85 if (! delete_records("resource", "id", "$resource->id")) {
86 $result = false;
2a439ba7 87 }
88
cccb016a 89 return $result;
2a439ba7 90}
cccb016a 91
2a439ba7 92
93function resource_user_outline($course, $user, $mod, $resource) {
ebc3bd2b 94 if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
95 AND action='view' AND info='$resource->id'", "time ASC")) {
2a439ba7 96
97 $numviews = count($logs);
98 $lastlog = array_pop($logs);
99
100 $result->info = get_string("numviews", "", $numviews);
101 $result->time = $lastlog->time;
102
103 return $result;
104 }
105 return NULL;
106}
107
108
109function resource_user_complete($course, $user, $mod, $resource) {
110 global $CFG, $THEME;
111
ebc3bd2b 112 if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
113 AND action='view' AND info='$resource->id'", "time ASC")) {
2a439ba7 114 $numviews = count($logs);
115 $lastlog = array_pop($logs);
116
117 $strmostrecently = get_string("mostrecently");
118 $strnumviews = get_string("numviews", "", $numviews);
119
120 echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
121
122 } else {
4282d7dd 123 print_string("neverseen", "resource");
2a439ba7 124 }
125}
126
2a439ba7 127
128?>