diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-10-09 17:09:15 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-10-09 17:09:15 -0400 |
commit | a19ef60df3870ba039f57324e97de02555c26633 (patch) | |
tree | 185a31f933800c5beb58cbc311749db7ec0e6d4f /src/lib/DB.class.php | |
parent | 29efffc7568a6b76a17bf73df056c631fd70fe19 (diff) | |
parent | 4d2de268b75f08e6fa774063a277c2c50f603ef7 (diff) |
Merge branch 'master' into multiuser-view
Conflicts:
src/views/pages/users/index.html.php
Diffstat (limited to 'src/lib/DB.class.php')
-rw-r--r-- | src/lib/DB.class.php | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/src/lib/DB.class.php b/src/lib/DB.class.php new file mode 100644 index 0000000..5954726 --- /dev/null +++ b/src/lib/DB.class.php @@ -0,0 +1,164 @@ +<?php + +require_once('Auth.class.php'); +require_once('Login.class.php'); + +class DB { + public static function set($table, $unit, $key, $value, $orig_value) { + $value_base = $orig_value; + + $doit = true; + $forked = false; + $have_old = ($value_base!==null); + if ($have_old) { + $we_changed_it = $value_base != $value; + if ($we_changed_it) { + $value_fork = $this->getConfString($key); + $someone_else_changed_it = + $value_fork != $value_base; + if ($someone_else_changed_it) { + if ($value == $value_fork) { + // we might as well not have + $we_changed_it = false; + } else { + $forked = true; + } + } + } + if (!$we_changed_it) { + $doit = false;// nothing to do + } + } + if ($doit) { + return $this->setConf($key, $value); + } + if ($forked) { + return $value_fork; + } + } + + public static function get($table, $unit, $key) { + switch ($table) { + case 'conf': + case 'plugins': + return self::admin_get($unit, $key); + break; + case 'users': + return self::user_get($unit, $key); + break; + default: + return false; + } + } + public static function raw_set($table, $unit, $key, $value) { + switch ($table) { + case 'conf': + case 'plugins': + return self::admin_get($unit, $key, $value); + break; + case 'users': + return self::user_set($unit, $key, $value); + break; + default: + return false; + } + } + + private static function user_get($uid, $key) { + $user = Auth::getObj($uid); + $logged_in_user = Auth::getObj(Login::isLoggedIn()); + + $post_key = $key."[$uid]"; + @$value = $_POST[$post_key]; + $editable = $user->canEdit(); + + switch ($key) { + case 'auth_uid': + $value = $user->getUID(); + $editable = false; + break; + case 'auth_name': + $value = $user->getName(); + break; + case 'auth_user': + $editable = $editable && $logged_in_user->isAdmin(); + $value = $user->isUser()?'true':'false'; + break; + case 'auth_admin': + $editable = $editable && $logged_in_user->isAdmin(); + $value = $user->isAdmin()?'true':'false'; + break; + case 'auth_delete': + $editable = $editable && $logged_in_user->isAdmin(); + $value = 'false'; + break; + default: + $value = $user->getConf($key); + if ($value===false) $value=''; + break; + } + + return array('value'=>$value, + 'post_key'=>$post_key, + 'editable'=>$editable); + } + private static function user_set($uid, $key, $value) { + $user = Auth::getObj($uid); + + switch ($key) { + case 'auth_uid': + return false; + break; + case 'auth_name': + return $user->setName($value); + break; + case 'auth_user': + return $user->setUser($value=='true'); + break; + case 'auth_admin': + return $user->setAdmin($value=='true'); + break; + case 'auth_delete': + if ($value=='true') return $user->delete(); + default: + return $user->setConf($key, $value); + break; + } + } + + private static function admin_get($plugin, $key) { + global $mm; $db = $mm->database(); + $user = Auth::getObj(Login::isLoggedIn()); + if ($user->isAdmin()) { + $editable = true; + switch ($plugin) { + case 'system': + $value = $db->getSysConf($key); + break; + default: + $value = $db->getPluginConf($plugin, $key); + break; + } + } else { + $editable = false; + $value = false; + } + + return array('value'=>$value, + 'post_key'=>'to be implemented',// FIXME + 'editable'=>$editable); + } + private static function admin_set($plugin, $key, $value) { + global $mm; $db = $mm->database(); + $user = Auth::getObj(Login::isLoggedIn()); + if (!$user->isAdmin()) { + return false; + } + switch ($plugin) { + case 'system': + return $db->setSysConf($key, $value); + default: + return $db->setPluginConf($plugin, $key, $value); + } + } +} |