]>
Commit | Line | Data |
---|---|---|
a5eae6b7 MR |
1 | <?php |
2 | /* $Id$ */ | |
3 | require_once 'helper.php'; | |
4 | ||
5 | class CalendarInfo { | |
6 | public $name; | |
7 | public $color; | |
8 | public $config; | |
9 | } | |
10 | ||
11 | class UserSettings { | |
12 | private $calendars; | |
13 | private $uid; | |
14 | private $viewStyle; | |
15 | private $startHour; | |
16 | private $endHour; | |
17 | private $startWeek; | |
18 | private $role; | |
19 | private $timeout; | |
20 | private $timezone; | |
21 | private $session_start; | |
22 | ||
23 | public function __construct($uid) { | |
24 | $this->calendars = array(); | |
25 | $this->uid = $uid; | |
26 | $this->session_start = time(); | |
27 | } | |
28 | ||
29 | public function setCalendars($calendars) { | |
30 | $this->calendars = $calendars; | |
31 | } | |
32 | ||
33 | public function addCalendar($id, CalendarInfo $calendar) { | |
34 | $this->calendars[$id] = $calendar; | |
35 | } | |
36 | ||
37 | public function removeCalendar($id) { | |
38 | unset($this->calendars[$id]); | |
39 | } | |
40 | ||
41 | public function setSettings($settings) { | |
42 | //file_put_contents('/tmp/davical.log', | |
43 | // __FILE__ . ": " . var_export($settings, TRUE), FILE_APPEND); | |
44 | $first = TRUE; | |
45 | foreach ($settings as $row) { | |
46 | if ($first) { | |
47 | $this->viewStyle = $row['userview']; | |
48 | $this->startWeek = ($row['weekstart']) ? TRUE : FALSE; | |
49 | $this->startHour = $row['daystart']; | |
50 | $this->endHour = $row['dayend']; | |
51 | $this->role = (int) $row['userrole']; | |
52 | $this->timeout = (int) $row['timeout']; | |
53 | $this->timezone = $row['timezone']; | |
54 | $first = FALSE; | |
55 | } | |
56 | if (isset($row['id']) && $row['id'] >= 0) { | |
57 | $calendar = new CalendarInfo(); | |
58 | $calendar->name = $row['name']; | |
59 | $calendar->color = $row['color']; | |
60 | $calendar->config = $row['config']; | |
61 | $this->calendars[$row['id']] = $calendar; | |
62 | } | |
63 | } | |
64 | $this->isTimeout(TRUE); | |
65 | } | |
66 | ||
67 | public function getCalendars() { | |
68 | return $this->calendars; | |
69 | } | |
70 | ||
71 | public function getCalendar($name) { | |
72 | foreach ($this->calendars as $calendar) { | |
73 | if ($calendar->name == $name) | |
74 | return $calendar->config; | |
75 | } | |
76 | return NULL; | |
77 | } | |
78 | ||
79 | public function getViewStyle() { | |
80 | return $this->viewStyle; | |
81 | } | |
82 | ||
83 | public function getStartWeek() { | |
84 | return $this->startWeek; | |
85 | } | |
86 | ||
87 | public function getStartHour() { | |
88 | return $this->startHour; | |
89 | } | |
90 | ||
91 | public function getEndHour() { | |
92 | return $this->endHour; | |
93 | } | |
94 | ||
95 | public function getRole() { | |
96 | return (int) $this->role; | |
97 | } | |
98 | ||
99 | public function getTimeout() { | |
100 | return $this->timeout; | |
101 | } | |
102 | ||
103 | public function isTimeout($reset = FALSE) { | |
104 | $terminate = TRUE; | |
105 | $now = time(); | |
106 | ||
107 | if ($reset) | |
108 | $this->session_start = $now; | |
109 | ||
110 | //echo "$this->session_start -> $this->timeout -> $now<br/>"; | |
111 | $_SESSION['isTimeout'] = TRUE; | |
112 | if ($this->session_start + $this->timeout > $now) { | |
113 | $this->session_start = $now; | |
114 | $terminate = FALSE; | |
115 | $remain = $this->timeout / 60; | |
116 | setcookie('WEBCAL_EXPIRE', $remain, 0, $_SESSION['WEB_ROOT']); | |
117 | } | |
118 | else { | |
119 | header('Location: ' . $_SESSION['WEB_ROOT'] . 'logout.php'); | |
120 | exit; | |
121 | } | |
122 | } | |
123 | ||
124 | public function getUid() { | |
125 | return $this->uid; | |
126 | } | |
127 | ||
128 | public function getTimezone() { | |
129 | return $this->timezone; | |
130 | } | |
131 | ||
132 | } |