root/trunk/common/mvblog_log.php

Revision 776, 3.7 KB (checked in by michiel, 9 months ago)

update copyright year.

Closes #180

Line 
1<?php
2/**
3 * MvBlog -- An open source no-nosense blogtool
4 *
5 * Copyright (C) 2005-2008, Michiel van Baak
6 * Michiel van Baak <mvanbaak@users.sourceforge.net>
7 *
8 * See http://dev.mvblog.org for more information on MvBlog.
9 * That page also provides Bugtrackers, Filereleases etc.
10 *
11 * This program is free software, distributed under the terms of
12 * the GNU General Public License Version 2. See the LICENSE file
13 * at the top of the source tree.
14 *
15 * @package MvBlog
16 * @author Michiel van Baak
17 * @version %%VERSION%%
18 * @copyright 2005-2008 Michiel van Baak
19 */
20
21/**
22 * Class that holds methods to create/read action log.
23 * @package MvBlog
24 */
25Class MvBlog_log extends MvBlog_common {
26    /* constants */
27    /* variables */
28    /* methods */
29    /* __construct {{{ */
30    /**
31     * Class constructor.
32     */
33    public function __construct($basedir = "", $adminmode) {
34        parent::__construct($basedir."plugins/", $adminmode);
35    }
36    /* }}} */
37    /* data setters */
38    /* add_log {{{ */
39    /**
40     * Add a logentry to the database
41     *
42     * @param int $datetime Entry timestamp
43     * @param int $user_id The userid who generated event
44     * @param int $user_type The type of user. 1 for admin, 2 for bloguser
45     * @param string $msg The log message
46     * @return bool true on success, false on failure
47     */
48    public function add_log($datetime, $user_id, $user_type, $msg) {
49        $sql = sprintf("INSERT INTO log VALUES (%d, %d, %d, '%s');",
50            $datetime, $user_id, $user_type, $msg);
51        $res = $this->db->query($sql);
52        if (PEAR::isError($res))
53            return false;
54        return true;
55
56    }
57    /* }}} */
58    /* data getters */
59    /* get_log {{{ */
60    /**
61     * Get logrecords
62     *
63     * @param int $user_type If 1 only show author actions, if 2 only show user actions, if 0 show all actions.
64     * @param int $count If set only show this many logrecords
65     * @param int $ts_start If set, start showing records from this time
66     * @param int $ts_end If set, stop showing records at this time
67     */
68    public function get_log($user_type = 0, $count = 25, $ts_start = 0, $ts_end = 0) {
69        $logrecords = array();
70        switch ($user_type) {
71        case 1:
72        case 2:
73            $sql = sprintf("SELECT * FROM log WHERE user_type = %d ORDER BY time DESC", $user_type);
74            break;
75        default:
76            $sql = "SELECT * FROM log ORDER BY time DESC";
77            break;
78        }
79        $res = $this->db->query($sql);
80        while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
81            $row["human_time"] = date("Y-m-d H:i:s", $row["time"]);
82            if ($row["user_type"] == 1) {
83                $row["username"] = $this->authors[$row["user_id"]]["login"];
84                $row["fullname"] = $this->authors[$row["user_id"]]["fullname"];
85            } elseif ($row["user_type"] == 2) {
86                $row["username"] = $this->users[$row["user_id"]]["username"];
87                $row["fullname"] = $this->users[$row["user_id"]]["realname"];
88            }
89            $logrecords[] = $row;
90        }
91        return $logrecords;
92    }
93    /* }}} */
94    /* output functions */
95    /* show_log {{{ */
96    /**
97     * Show log overview
98     *
99     * @param int $user_type 1 for admin, 2 for users, 0 for everything
100     */
101    public function show_log($user_type = 1) {
102        $logrecords = $this->get_log($user_type);
103        echo "<table style=\"border: 1px solid black;\"><tr>\n";
104        echo "\t<td style=\"border: 1px solid black;\">date</td><td style=\"border: 1px solid black;\">login</td><td style=\"border: 1px solid black;\">fullname</td>\n";
105        echo "</tr>";
106        foreach ($logrecords as $logrecord) {
107            echo "<tr>\n";
108            echo sprintf("\t<td style=\"border: 1px solid black;\">%s</td><td style=\"border: 1px solid black;\">%s</td><td style=\"border: 1px solid black;\">%s</td>\n", $logrecord["human_time"],
109                $logrecord["username"], $logrecord["fullname"]);
110            echo "</tr><tr>\n";
111            echo sprintf("\t<td colspan=\"3\" style=\"border: 1px solid black;\">%s</td>\n", $logrecord["msg"]);
112            echo "</tr>";
113        }
114        echo "</table>";
115    }
116    /* }}} */
117}
Note: See TracBrowser for help on using the browser.