summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Form.class.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/Form.class.php b/src/lib/Form.class.php
new file mode 100644
index 0000000..725bac5
--- /dev/null
+++ b/src/lib/Form.class.php
@@ -0,0 +1,57 @@
+<?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;
+ }
+ }
+}