3 function logging_pagesetup() {
6 function logging_init() {
8 global $CFG, $db, $messages;
10 $tables = $db->Metatables();
11 if (!in_array($CFG->prefix
. "logging",$tables)) {
12 modify_database($CFG->dirroot
. "mod/logging/table.sql");
13 print_continue("index.php");
17 listen_for_event("all","all","logging_logger");
21 function logging_logger($object_type, $event, $object) {
23 global $CFG, $messages, $db;
25 if ($event != "create") {
29 if ($event == "update" ||
$event == "delete") {
30 if (!empty($object->ident
)) {
31 $messages[] = "select ident, new_access from ".$CFG->prefix
."logging where object_type = ".$db->qstr($object_type)." and object_id = ".$db->qstr($object->ident
)." order by timestamp desc limit 1";
32 if ($previous = get_records_sql("select ident, new_access from ".$CFG->prefix
."logging where object_type = ".$db->qstr($object_type)." and object_id = ".$db->qstr($object->ident
)." order by timestamp desc limit 1")) {
33 foreach($previous as $prev_item) {
34 $prev_access = $prev_item->new_access
;
42 $log->timestamp
= time();
43 $log->object_type
= $object_type;
44 $log->event_type
= $event;
45 $log->object_id
= $object->ident
;
46 $log->old_access
= $prev_access;
47 $log->new_access
= $object->access
;
48 $log->user_id
= $_SESSION['userid'];
50 if (!insert_record('logging',$log)) {
51 $messages[] = gettext("Logging failed.");