]> git.datanom.net - webcal.git/blame - utils/calendar.php
Initial upload
[webcal.git] / utils / calendar.php
CommitLineData
a5eae6b7
MR
1<?php
2/* $Id$ */
3require_once 'config.inc.php';
4require_once 'user_settings.inc.php';
5require_once 'user_validate.php';
6require_once 'helper.php';
7
8valid_user();
9
10if (! defined($_SESSION['__ROOT__']) && empty($_SESSION['__ROOT__'])) {
11 if (session_id())
12 session_destroy();
13 header('Location: ' . WEB_ROOT . 'error.html');
14 exit;
15}
16
17require_once 'persistens.php';
18//var_dump($_POST);
19//exit();
20include TOP_FOLDER.'/include/header.inc.php';
21include TOP_FOLDER.'/include/menu.inc.php';
22
23function colors($selected = null) {
24 $list = array('aqua', 'black', 'blue', 'fuchsia', 'gray', 'green',
25 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver',
26 'teal', 'white', 'yellow');
27
28 $colors = '';
29 foreach ($list as $color) {
30 $colors .= "<option value=\"$color\" style=\"background: $color\"";
31 if ($selected && $selected == $color)
32 $colors .= ' selected="true"';
33 $colors .= ">$color</option>";
34 }
35 return $colors;
36}
37
38$user = $_SESSION['user_settings'];
39if (count($_POST) > 0 && isset($_POST['action'])) {
40 $db = Persistens::getInstance(DBDRIVER);
41 $calconf = $_POST['calendar'];
42 if ($_POST['action'] == 'new') {
43 $row = $calconf;
44 $text = "url={$row['url']}\nuid={$row['uid']}\npwd={$row['pwd']}";
45 $text = encode($text);
46 $calendar = new CalendarInfo();
47 $calendar->name = $row['name'];
48 $calendar->color = $row['color'];
49 $calendar->config = $text;
50 $id = $db->addCalendar($user->getUid(), $calendar);
51 if (is_numeric($id)) {
52 $user->addCalendar($id, $calendar);
53 $pageView = "<p class=\"usermanage\">Calendar was added with id $id</p>";
54 }
55 else {
56 $pageView = "<p class=\"usermanage\">$id</p>";
57 }
58 }
59 else {
60 foreach ($calconf as $id => $row) {
61 if (! isset($row[check]))
62 continue;
63 if ($_POST['action'] == 'update') {
64 $text = "url={$row['url']}\nuid={$row['uid']}\npwd={$row['pwd']}";
65 $text = encode($text);
66 $calendar = new CalendarInfo();
67 $calendar->name = $row['name'];
68 $calendar->color = $row['color'];
69 $calendar->config = $text;
70 $res = $db->updateCalendar($user->getUid(), $id, $calendar);
71 if ($res === TRUE) {
72 $user->addCalendar($id, $calendar);
73 $pageView = "<p class=\"usermanage\">Calendar with id $id was updated</p>";
74 }
75 else {
76 $pageView = "<p class=\"usermanage\">$id</p>";
77 }
78 }
79 else {
80 $res = $db->deleteCalendar($user->getUid(), $id);
81 if ($res === TRUE) {
82 $user->removeCalendar($id);
83 $pageView = "<p class=\"usermanage\">Calendar with id $id was removed</p>";
84 }
85 else {
86 $pageView = "<p class=\"usermanage\">$id</p>";
87 }
88 }
89 }
90 }
91 $pageView .= '</table>';
92}
93else if (count($_POST) > 0 && isset($_POST['new'])) {
94 $colors = colors();
95 $pageView = '<form id="form" action="'.$_SERVER[PHP_SELF].'" method="post">
96 <table class="config">';
97 $pageView .= "<tr><td>Name</td>
98 <td><input name=\"calendar[name]\" type=\"text\" size=\"20\"/></td>
99 </tr>
100 <tr>
101 <td>Color</td>
102 <td>
103 <select name=\"calendar[color]\">
104 $colors
105 </select>
106 </td>
107 </tr>
108 <tr>
109 <td>URL</td>
110 <td><input name=\"calendar[url]\" type=\"text\" size=\"50\"/></td>
111 </tr>
112 <tr>
113 <td>Username</td>
114 <td><input name=\"calendar[uid]\" type=\"text\" size=\"20\"/></td>
115 </tr>
116 <tr>
117 <td>Password</td>
118 <td><input name=\"calendar[pwd]\" type=\"password\" size=\"20\"/></td>
119 </tr>";
120 $pageView .= '<tr>
121 <td colspan="6" style="text-align: center">
122 <input type="button" value="Submit"
123 onclick="document.getElementById(\'form\').submit()">
124 <input type="hidden" name="action" value="new"/>
125 </td>
126 </tr>';
127 $pageView .= '</table></form>';
128}
129else {
130 //var_dump($_SESSION['authenticate']);
131 //var_dump($user);
132 //exit();
133 $calendars = $user->getCalendars();
134 //var_dump($calendars);
135 //exit();
136 $pageView = '<form id="form" action="'.$_SERVER[PHP_SELF].'" method="post">
137 <table id="cal">';
138
139 if (count($calendars) > 0) {
140 foreach ($calendars as $id => $cal) {
141 $text = decode($cal->config);
142 $color = colors($cal->color);
143 $info = implode_cal($text);
144 $pageView .= "<tr><td>Name</td>
145 <td><input name=\"calendar[$id][name]\" type=\"text\" size=\"8\" value=\"{$cal->name}\"/></td>
146 <td>Color</td>
147 <td>
148 <select name=\"calendar[$id][color]\">
149 $color
150 </select>
151 </td>
152 <td>URL</td>
153 <td><input name=\"calendar[$id][url]\" type=\"text\" size=\"40\" value=\"{$info['url']}\"/>
154 </td>
155 <td>Username</td>
156 <td><input name=\"calendar[$id][uid]\" type=\"text\" size=\"8\" value=\"{$info['uid']}\"/></td>
157 <td>Password</td>
158 <td><input name=\"calendar[$id][pwd]\" type=\"password\" size=\"8\" value=\"{$info['pwd']}\"/></td>
159 <td><input type=\"checkbox\" name=\"calendar[$id][check]\" value=\"$id\"/></td>
160 </tr>";
161 }
162 $pageView .= '<tr>
163 <td colspan="11" style="text-align: center">
164 <input type="radio" name="action" value="delete">Delete</input>
165 <input type="radio" name="action" value="update">Update</input>
166 </td>
167 </tr>
168 <tr>
169 <td colspan="11" style="text-align: center">
170 <input type="button" value="Submit"
171 onclick="document.getElementById(\'form\').submit()">
172 <input type="submit" name="new" value="New Calendar"/>
173 </td>
174 </tr>';
175 }
176 else {
177 $pageView .= '<tr>
178 <td>
179 <input type="submit" name="new" value="New Calendar"/>
180 </td>
181 </tr>';
182 }
183 $pageView .= '</table></form>';
184}
185print "<div id=\"ui\">$pageView</div>";
186
187include TOP_FOLDER.'/include/footer.inc.php';
188?>
This page took 0.05806 seconds and 5 git commands to generate.