summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/DB.class.php164
-rw-r--r--src/lib/Database.class.php2
-rw-r--r--src/lib/Form.class.php57
3 files changed, 165 insertions, 58 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);
+ }
+ }
+}
diff --git a/src/lib/Database.class.php b/src/lib/Database.class.php
index ab56d09..13d9559 100644
--- a/src/lib/Database.class.php
+++ b/src/lib/Database.class.php
@@ -396,4 +396,4 @@ class Database {
return $out_list;
}
-} \ No newline at end of file
+}
diff --git a/src/lib/Form.class.php b/src/lib/Form.class.php
deleted file mode 100644
index 725bac5..0000000
--- a/src/lib/Form.class.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-
-require_once('Auth.class.php');
-
-class Form {
- public $getter = null;
- public $setter = null;
- public function __constructor($get, $set) {
- $this->getter = $get;
- $this->setter = $set;
- }
- private function getConf($key) {
- call_user_func($getter, $key);
- }
- public function setConf($key, $value) {
- call_user_func($setter, $key, $value);
- }
- private function getConfString($key) {
- $raw = $this->getConf($key);
- $value = $raw['value'];
- if ($value===false) return 'false';
- if ($value===true) return 'true';
- return $value;
- }
-
- public function updateValue($value, $value_base=null) {
- $doit = true;
- $forked = false;
- $have_old = ($value_base!==null);
- if ($have_old) {
- @$value_base = $old[$uid];
- $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;
- }
- }
-}