| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | Class MvBlog_log extends MvBlog_common { |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | public function __construct($basedir = "", $adminmode) { |
|---|
| 34 | parent::__construct($basedir."plugins/", $adminmode); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 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 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 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 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 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 | } |
|---|