]> git.datanom.net - webcal.git/blob - utils/persistens.php
Initial upload
[webcal.git] / utils / persistens.php
1 <?php
2 /* $Id$ */
3
4 include_once 'config.inc.php';
5 require_once 'helper.php';
6
7 require_once 'sqlite.php';
8 require_once 'pgsql.php';
9
10 class DefaultConfig {
11 public $viewStyle;
12 public $timeout;
13 public $startWeek;
14 public $startHour;
15 public $endHour;
16 public $title;
17 public $timezone;
18 public $errorDisplay;
19 public $errorLog;
20 public $logFile;
21 public $topFolder;
22 public $webRoot;
23 public $dns;
24 public $role;
25 }
26
27 interface WebcalSupport {
28 function getViewStyle($uid);
29 function getTimeout($uid);
30 function getRole($uid);
31 function getStartWeek($uid);
32 function getStartHour($uid);
33 function getEndHour($uid);
34 function getTimezone($uid);
35 function authenticate($uid, $pwd);
36 function createDatabase($name);
37 function initDatabase($name, $pwd, $uid);
38 function addUser($data);
39 function setUserSettings($uid, $data);
40 function deleteUser($uid);
41 function addCalendar($uid, CalendarInfo $calendar);
42 function deleteCalendar($uid, $id);
43 function updateCalendar($uid, $id, CalendarInfo $calendar);
44 function changePassword($uid, $pwd);
45 function getAllUsers($limit, $offset);
46 function getRoles();
47 function getRoleName($id);
48 function changeDefault($data);
49 function getVersion();
50 function execute($sql);
51 function getCalendarConfig($id);
52 function nextTableNumber($name);
53 function getLdapConfig();
54 function setLdapConfig(array $config);
55 }
56
57 class Persistens {
58
59 private static $instance = NULL;
60 private $con;
61
62 private function __construct($driver, $dns) {
63 $this->con = new $driver($dns);
64 }
65
66 private function __clone() {}
67
68 static function getInstance($db = NULL, $dns = NULL) {
69 if (! self::$instance) {
70 if (! $db)
71 throw new Exception('Missing database driver');
72 switch (strtolower($db)) {
73 case 'sqlite':
74 self::$instance = new Persistens('SQLite', $dns); break;
75 break;
76 case 'pgsql':
77 self::$instance = new Persistens('Pgsql', $dns); break;
78 break;
79 default: throw new Exception("$db: Unsupported driver");
80 }
81 }
82 return self::$instance;
83 }
84
85 function getViewStyle($uid) {
86 return $this->con->getViewStyle($uid);
87 }
88
89 function getStartWeek($uid) {
90 return $this->con->getStartWeek($uid);
91 }
92
93 function getStartHour($uid) {
94 return $this->con->getStartHour($uid);
95 }
96
97 function getEndHour($uid) {
98 return $this->con->getEndHour($uid);
99 }
100
101 function authenticate($uid, $pwd) {
102 return $this->con->authenticate($uid, sha1($pwd));
103 }
104
105 function getTimeout($uid) {
106 return $this->con->getTimeout($uid);
107 }
108
109 function getRole($uid) {
110 return $this->con->getRole($uid);
111 }
112
113 function createDatabase($name) {
114 $this->con->createDatabase($name);
115 }
116
117 function initDatabase($name, $pwd, $uid = 'webcal') {
118 $this->con->initDatabase($name, $pwd, $uid = 'webcal');
119 $this->con = NULL;
120 self::$instance = NULL;
121 }
122
123 function newUser($data) {
124 return $this->con->addUser($data);
125 }
126
127 function setUserSettings($uid, $settings) {
128 return $this->con->setUserSettings($uid, $settings);
129 }
130
131 function deleteUser($uid) {
132 return $this->con->deleteUser($uid);
133 }
134
135 function addCalendar($uid, CalendarInfo $calendar) {
136 return $this->con->addCalendar($uid, $calendar);
137 }
138
139 function deleteCalendar($uid, $id) {
140 return $this->con->deleteCalendar($uid, $id);
141 }
142
143 function updateCalendar($uid, $id, CalendarInfo $calendar) {
144 return $this->con->updateCalendar($uid, $id, $calendar);
145 }
146
147 function changePassword($uid, $pwd) {
148 return $this->con->changePassword($uid, $pwd);
149 }
150
151 function getAllUsers($limit = -1, $offset = 0) {
152 return $this->con->getAllUsers($limit, $offset);
153 }
154
155 function getRoles() {
156 return $this->con->getRoles();
157 }
158
159 function getRoleName($id) {
160 return $this->con->getRoleName($id);
161 }
162
163 function changeDefault($data) {
164 return $this->con->changeDefault($data);
165 }
166
167 function getVersion() {
168 $res = $this->con->getVersion();
169 if (! is_array($res))
170 throw new Exception($res);
171 return $res;
172 }
173
174 function execute($sql) {
175 return $this->con->execute($sql);
176 }
177
178 function getCalendarConfig($id = -1) {
179 return $this->con->getCalendarConfig($id);
180 }
181
182 function nextTableNumber($name) {
183 return $this->con->nextTableNumber($name);
184 }
185
186 function getLdapConfig() {
187 return $this->con->getLdapConfig();
188 }
189
190 function setLdapConfig(array $config) {
191 return $this->con->setLdapConfig($config);
192 }
193
194 }
This page took 0.075303 seconds and 6 git commands to generate.