summaryrefslogtreecommitdiff
blob: 4458eb4d05bfefdaa2da5b5d15984977b0c2500a (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?

	class DBUse {
	
		private $id;
		private $name;
		private $description;
		private $prefix;
		private $cp;
		private $type;
	
		function __construct($name, $type = 'global', $key = '') {
		
			$db =& MDB2::singleton();
			
			$this->name = $name;
			$this->type = $type;
			
			// Find out as much as we can
			$sql = "SELECT * FROM use WHERE name = ".$db->quote($name)." $where;";
			$row = $db->getRow($sql);
			
			if(is_array($row) && count($row)) {
				foreach($row as $key => $value)
					$this->$key = $value;
			} else {
			
				if($this->type == 'local') {
					$this->cp = $key;
// 					$sql = "SELECT package FROM view_package WHERE cp = ".$db->quote($this->cp).";";
// 					$this->package = $db->getOne($sql);
				} elseif($this->type == 'expand') {
					$this->prefix = $key;
				}
				
 				$this->createNew();
				
			}
			
		}
		
		public function __get($var) {
			return $this->$var;
		}
		
		public function __set($var, $value) {
			
			$db =& MDB2::singleton();
			
			if(in_array($var, array('name', 'description', 'prefix'))) {
			
				$arr_update = array(
					$var => $value,
				);
				
				$db->autoExecute('use', $arr_update, MDB2_AUTOQUERY_UPDATE, "id = ".$db->quote($this->id));
			
				$this->$var = $value;
			
			}
			
		}
		
		private function createNew() {
		
			$db =& MDB2::singleton();
		
			$arr_insert = array('name' => $this->name);
			
			if($this->type == 'expand' && $this->prefix)
				$arr_insert['prefix'] = $this->prefix;
		
			$db->autoExecute('use', $arr_insert, MDB2_AUTOQUERY_INSERT);
			
			$this->id = $db->lastInsertID();
		
		}
		
	}

?>