summaryrefslogtreecommitdiff
path: root/src/lib/Form.class.php
blob: 725bac5b311b880ae71e0c6d5fbe0e0eb47cc6a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
		}
	}
}