diff options
author | Simon Rettberg | 2013-10-29 20:02:30 +0100 |
---|---|---|
committer | Simon Rettberg | 2013-10-29 20:02:30 +0100 |
commit | 010656745dd6f7db6b09ec501ad3bb1e202b9a96 (patch) | |
tree | 2900c8daafe4b0b79cd6766348eb6db0b763bc54 /inc | |
parent | DB-Support, add user functionality (diff) | |
download | slx-admin-010656745dd6f7db6b09ec501ad3bb1e202b9a96.tar.gz slx-admin-010656745dd6f7db6b09ec501ad3bb1e202b9a96.tar.xz slx-admin-010656745dd6f7db6b09ec501ad3bb1e202b9a96.zip |
First version of basic minilinux configuration
Diffstat (limited to 'inc')
-rw-r--r-- | inc/message.inc.php | 2 | ||||
-rw-r--r-- | inc/permission.inc.php | 25 | ||||
-rw-r--r-- | inc/user.inc.php | 6 | ||||
-rw-r--r-- | inc/util.inc.php | 10 |
4 files changed, 43 insertions, 0 deletions
diff --git a/inc/message.inc.php b/inc/message.inc.php index b24bf2a1..b90ed630 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -8,6 +8,8 @@ $error_text = array( 'password-mismatch' => 'Passwort und Passwortbestätigung stimmen nicht überein', 'empty-field' => 'Ein benötigtes Feld wurde nicht ausgefüllt', 'adduser-success' => 'Benutzer erfolgreich hinzugefügt', + 'no-permission' => 'Keine ausreichenden Rechte, um auf diese Seite zuzugreifen', + 'settings-updated' => 'Einstellungen wurden aktualisiert', ); class Message diff --git a/inc/permission.inc.php b/inc/permission.inc.php new file mode 100644 index 00000000..b63e9d45 --- /dev/null +++ b/inc/permission.inc.php @@ -0,0 +1,25 @@ +<?php + +class Permission +{ + private static $permissions = false; + + public static function get($permission) + { + self::init(); + if (!isset(self::$permissions[$permission])) Util::traceError('Invalid permission: ' . $permission); + return self::$permissions[$permission]; + } + + private static function init() + { + if (self::$permissions !== false) return; + self::$permissions = array(); + $res = Database::simpleQuery('SELECT mask, identifier FROM permission'); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + self::$permissions[$row['identifier']] = $row['mask']; + } + } + +} + diff --git a/inc/user.inc.php b/inc/user.inc.php index b988bbeb..38e57e33 100644 --- a/inc/user.inc.php +++ b/inc/user.inc.php @@ -17,6 +17,12 @@ class User return self::$user['fullname']; } + public static function hasPermission($permission) + { + if (self::$user === false) return false; + return (self::$user['permissions'] & Permission::get($permission)) != 0; + } + public static function load() { if (Session::load()) { diff --git a/inc/util.inc.php b/inc/util.inc.php index b4a0036e..0d85b989 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -32,5 +32,15 @@ class Util Message::addError('token'); return false; } + + function markup($string) + { + $string = htmlspecialchars($string); + $string = preg_replace('#(^|[\n \-_/\.])\*(.+?)\*($|[ \-_/\.\!\?,])#is', '$1<b>$2</b>$3', $string); + $string = preg_replace('#(^|[\n \-\*/\.])_(.+?)_($|[ \-\*/\.\!\?,])#is', '$1<u>$2</u>$3', $string); + $string = preg_replace('#(^|[\n \-_\*\.])/(.+?)/($|[ \-_\*\.\!\?,])#is', '$1<i>$2</i>$3', $string); + return nl2br($string); + } + } |