diff options
Diffstat (limited to 'src/lib/DB.class.php')
-rw-r--r-- | src/lib/DB.class.php | 164 |
1 files changed, 0 insertions, 164 deletions
diff --git a/src/lib/DB.class.php b/src/lib/DB.class.php deleted file mode 100644 index ac8dafe..0000000 --- a/src/lib/DB.class.php +++ /dev/null @@ -1,164 +0,0 @@ -<?php -require_once('Auth.class.php'); -require_once('Login.class.php'); -require_once('Database.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::getInstance($uid); - $logged_in_user = Auth::getInstance(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::getInstance($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) { - $db = Database::getInstance(); - $user = Auth::getInstance(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) { - $db = Database::getInstance(); - $user = Auth::getInstance(Login::isLoggedIn()); - if (!$user->isAdmin()) { - return false; - } - switch ($plugin) { - case 'system': - return $db->setSysConf($key, $value); - default: - return $db->setPluginConf($plugin, $key, $value); - } - } -} |