7 function wdcal_addRequiredHeaders()
11 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/jqueryui/jquery-ui-1.8.20.custom.css' . '" media="all" />' . "\r\n";
12 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/jqueryui/jquery-ui-1.8.20.custom.min.js"></script>' . "\r\n";
14 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/wdcal.css' . '" media="all" />' . "\r\n";
15 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/common/wdcal.js"></script>' . "\r\n";
17 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/wdcal/css/calendar.css' . '" media="all" />' . "\r\n";
18 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/wdcal/css/main.css' . '" media="all" />' . "\r\n";
20 switch (get_config("system", "language")) {
21 case "de": $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/common/wdcal/js/wdCalendar_lang_DE.js"></script>' . "\r\n"; break;
22 default: $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/common/wdcal/js/wdCalendar_lang_EN.js"></script>' . "\r\n";
25 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/common/wdcal/js/jquery.calendar.js"></script>' . "\r\n";
26 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/common/wdcal/js/main.js"></script>' . "\r\n";
32 function wdcal_addRequiredHeadersEdit()
36 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/jqueryui/jquery-ui-1.8.20.custom.css' . '" media="all" />' . "\r\n";
37 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/jqueryui/jquery-ui-1.8.20.custom.min.js"></script>' . "\r\n";
39 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/colorpicker/colorPicker.css' . '" media="all" />' . "\r\n";
40 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/colorpicker/jquery.colorPicker.min.js"></script>' . "\r\n";
42 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/timepicker/timePicker.css' . '" media="all" />' . "\r\n";
43 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/timepicker/jquery.timePicker.min.js"></script>' . "\r\n";
45 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/dav/wdcal.css' . '" media="all" />' . "\r\n";
46 $a->page['htmlhead'] .= '<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/dav/common/wdcal.js"></script>' . "\r\n";
52 * @param array|DBClass_friendica_calendars[] $calendars
53 * @param array $calendar_preselected
54 * @param string $data_feed_url
57 * @param int $height_diff
58 * @param bool $readonly
59 * @param string $curr_day
60 * @param array $add_params
61 * @param bool $show_nav
64 function wdcal_printCalendar($calendars, $calendar_preselected, $data_feed_url, $view = "week", $theme = 0, $height_diff = 175, $readonly = false, $curr_day = "", $add_params = array(), $show_nav = true)
68 $localization = wdcal_local::getInstanceByUser($a->user["uid"]);
70 $cals_avail = array();
71 foreach ($calendars as $c) $cals_avail[] = array("ns" => $c->namespace, "id" => $c->namespace_id, "displayname" => $c->displayname);
75 "readonly" => $readonly,
76 "height_diff" => $height_diff,
77 "weekstartday" => $localization->getFirstDayOfWeek(),
78 "data_feed_url" => $data_feed_url,
79 "date_format_dm1" => $localization->dateformat_js_dm1(),
80 "date_format_dm2" => $localization->dateformat_js_dm2(),
81 "date_format_dm3" => $localization->dateformat_js_dm3(),
82 "date_format_full" => $localization->dateformat_datepicker_js(),
88 $("#animexxcalendar").animexxCalendar(' . json_encode($opts) . ');
92 <div id="animexxcalendar" class="animexxcalendar">
93 <div class="calselect"><strong>Available Calendars:</strong>';
95 foreach ($cals_avail as $cal) {
96 $x .= '<label style="margin-left: 10px; margin-right: 10px;"><input type="checkbox" name="cals[]" value="' . $cal["ns"] . '-' . $cal["id"] . '"';
98 foreach ($calendar_preselected as $pre) if ($pre["ns"] == $cal["ns"] && $pre["id"] == $cal["id"]) $found = true;
99 if ($found) $x .= 'checked';
100 $x .= '> ' . escape_tags($cal["displayname"]) . '</label> ';
104 <div class="calhead" style="padding-left:1px;padding-right:1px;">
105 <div class="ptogtitle loaderror" style="display: none;">Sorry, could not load your data, please try again later</div>
110 $x .= '<div class="ctoolbar">
111 <div class="fbutton faddbtn" style="float: right;">
112 <div><a href="/dav/settings/"><span>' . t("Settings") . ' / ' . t("Help") . '</span></a></div>
114 <div class="btnseparator"></div>
115 <div class="fbutton showtodaybtn">
116 <div><span class="showtoday">' . t("Today") . '</span></div>
118 <div class="btnseparator"></div>
120 <div class="fbutton showdaybtn">
121 <div><span title="Day" class="showdayview ';
123 if ($view == "day") $x .= 'fcurrent';
125 $x .= '">Tag</span></div>
127 <div class="fbutton showweekbtn ';
129 if ($view == "week") $x .= "fcurrent";
132 <div><span title="Week" class="showweekview">' . t("Week") . '</span></div>
134 <div class="showmonthbtn fbutton ';
136 if ($view == "month") $x .= 'fcurrent';
139 <div><span title="Month" class="showmonthview">' . t("Month") . '</span></div>
142 <div class="btnseparator"></div>
143 <div class="fbutton showreflashbtn">
144 <div><span class="showdayflash">' . t("Reload") . '</span></div>
146 <div class="btnseparator"></div>
147 <div title="' . t("Previous") . '" class="fbutton sfprevbtn">
148 <span class="fprev"></span>
150 <div title="' . t("Next") . '" class="fbutton sfnextbtn">
151 <span class="fnext"></span>
153 <div class="fshowdatep fbutton" style="white-space: nowrap; position: relative;">
154 <input name="txtshow" class="hdtxtshow" style="position: absolute; bottom: 0; left: 0; width: 0; height: 0; border: 0; padding: 0; margin: 0;">
155 <span class="txtdatetimeshow">' . t("Date") . '</span>
157 <div style="float: right;">
158 <div class="clear"></div>
163 <div style="padding:1px;">
164 <div class="calmain printborder">
165 <div class="gridcontainer" style="overflow-y: visible;"></div>
176 * @param string $recurr_uri
179 function wdcal_getDetailPage($uri, $recurr_uri)
184 $cals = dav_getMyCals($a->user["uid"]);
185 foreach ($cals as $c) {
186 $cs = wdcal_calendar_factory($a->user["uid"], $c->namespace, $c->namespace_id);
187 $p = $cs->getPermissionsItem($a->user["uid"], $uri, $recurr_uri);
188 if ($p["read"]) try {
189 $redirect = $cs->getItemDetailRedirect($uri);
190 if ($redirect !== null) goaway($redirect);
191 $details = $cs->getItemByUri($uri);
192 } catch (Exception $e) {
193 notification(t("Error") . ": " . $e);
194 goaway("/dav/wdcal/");
199 return $uri . " / " . $recurr_uri . "<br>" . print_r($details, true);
205 * @param string $recurr_uri
208 function wdcal_postEditPage($uri, $recurr_uri)
212 $localization = wdcal_local::getInstanceByUser($a->user["uid"]);
214 check_form_security_token_redirectOnErr("/dav/wdcal/", "caledit");
216 if (isset($_REQUEST["allday"])) {
217 $start = $localization->date_parseLocal($_REQUEST["start_date"] . " 00:00");
218 $end = $localization->date_parseLocal($_REQUEST["end_date"] . " 20:00");
221 $start = $localization->date_parseLocal($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]);
222 $end = $localization->date_parseLocal($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]);
227 $cals = dav_getMyCals($a->user["uid"]);
228 foreach ($cals as $c) {
229 $cs = wdcal_calendar_factory($a->user["uid"], $c->namespace, $c->namespace_id);
230 $p = $cs->getPermissionsItem($a->user["uid"], $uri, $recurr_uri);
231 if ($p["write"]) try {
232 $cs->updateItem($uri, $start, $end,
233 stripslashes($_REQUEST["subject"]), $isallday, wdcal_parse_text_serverside($_REQUEST["wdcal_desc"]),
234 stripslashes($_REQUEST["location"]), $_REQUEST["color"], $a->timezone,
235 isset($_REQUEST["notification"]), $_REQUEST["notification_type"], $_REQUEST["notification_value"]);
236 } catch (Exception $e) {
237 notification(t("Error") . ": " . $e);
239 goaway("/dav/wdcal/");
246 * @param string $recurr_uri
249 function wdcal_getEditPage($uri, $recurr_uri)
253 $localization = wdcal_local::getInstanceByUser($a->user["uid"]);
255 if ($uri != "" && $uri != "new") {
256 $o = q("SELECT * FROM %s%sjqcalendar WHERE `uid` = %d AND `ical_uri` = '%s' AND `ical_recurr_uri` = '%s'",
257 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $a->user["uid"], dbesc($uri), dbesc($recurr_uri)
259 if (count($o) != 1) return t('Not found');
262 $calendarSource = wdcal_calendar_factory($a->user["uid"], $event["namespace"], $event["namespace_id"]);
264 $permissions = $calendarSource->getPermissionsItem($a->user["uid"], $uri, $recurr_uri, $event);
266 if (!$permissions["write"]) return t('No access');
268 $n = q("SELECT * FROM %s%snotifications WHERE `uid` = %d AND `ical_uri` = '%s' AND `ical_recurr_uri` = '%s'",
269 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $a->user["uid"], dbesc($uri), dbesc($recurr_uri)
272 $notification_type = $n[0]["rel_type"];
273 $notification_value = -1 * $n[0]["rel_value"];
274 $notification = true;
276 if ($event["IsAllDayEvent"]) {
277 $notification_type = "hour";
278 $notification_value = 24;
280 $notification_type = "minute";
281 $notification_value = 60;
283 $notification = false;
287 } elseif (isset($_REQUEST["start"]) && $_REQUEST["start"] > 0) {
290 "Subject" => $_REQUEST["title"],
293 "StartTime" => $_REQUEST["start"],
294 "EndTime" => $_REQUEST["end"],
295 "IsAllDayEvent" => $_REQUEST["isallday"],
297 "RecurringRule" => null,
299 if ($_REQUEST["isallday"]) {
300 $notification_type = "hour";
301 $notification_value = 24;
303 $notification_type = "hour";
304 $notification_value = 1;
307 $notification = true;
316 "IsAllDayEvent" => "",
318 "RecurringRule" => null,
320 $notification_type = "hour";
321 $notification_value = 1;
322 $notification = true;
326 $out = "<a href='/dav/wdcal/'>" . t("Go back to the calendar") . "</a><br><br>";
327 $out .= "<form method='POST' action='/dav/wdcal/$uri/edit/'><input type='hidden' name='form_security_token' value='" . get_form_security_token('caledit') . "'>\n";
329 $out .= "<label for='cal_subject'>Subject:</label>
330 <input name='color' id='cal_color' value='" . (strlen($event["Color"]) != 7 ? "#5858ff" : escape_tags($event["Color"])) . "'>
331 <input name='subject' id='cal_subject' value='" . escape_tags($event["Subject"]) . "'><br>\n";
332 $out .= "<label for='cal_allday'>Is All-Day event:</label><input type='checkbox' name='allday' id='cal_allday' " . ($event["IsAllDayEvent"] ? "checked" : "") . "><br>\n";
334 $out .= "<label for='cal_startdate'>Starts:</label>";
335 $out .= "<input name='start_date' value='" . $localization->dateformat_datepicker_php(wdcal_mySql2PhpTime($event["StartTime"])) . "' id='cal_start_date'>";
336 $out .= "<input name='start_time' value='" . substr($event["StartTime"], 11, 5) . "' id='cal_start_time'>";
339 $out .= "<label for='cal_enddate'>Ends:</label>";
340 $out .= "<input name='end_date' value='" . $localization->dateformat_datepicker_php(wdcal_mySql2PhpTime($event["EndTime"])) . "' id='cal_end_date'>";
341 $out .= "<input name='end_time' value='" . substr($event["EndTime"], 11, 5) . "' id='cal_end_time'>";
344 $out .= "<label for='cal_location'>Location:</label><input name='location' id='cal_location' value='" . escape_tags($event["Location"]) . "'><br>\n";
346 $out .= "<label for='event-desc-textarea'>" . t("Description") . ":</label> <textarea id='event-desc-textarea' name='wdcal_desc' style='vertical-align: top; width: 400px; height: 100px;'>" . escape_tags($event["Description"]) . "</textarea>";
347 $out .= "<br style='clear: both;'>";
349 $out .= "<label for='notification'>" . t('Notification') . ":</label>";
350 $out .= '<input type="checkbox" name="notification" id="notification" ';
351 if ($notification) $out .= "checked";
353 $out .= '<span id="notification_detail" style="display: none;">
354 <input name="notification_value" value="' . $notification_value . '" size="3">
355 <select name="notification_type" size="1">
356 <option value="minute" ';
357 if ($notification_type == "minute") $out .= "selected";
358 $out .= '> ' . t('Minutes') . '</option>
359 <option value="hour" ';
360 if ($notification_type == "hour") $out .= "selected";
361 $out .= '> ' . t('Hours') . '</option>
362 <option value="day" ';
363 if ($notification_type == "day") echo "selected";
364 $out .= '> ' . t('Days') . '</option>
365 </select> ' . t('before') . '
369 $out .= "<script>\$(function() {
370 wdcal_edit_init('" . $localization->dateformat_datepicker_js() . "');
373 $out .= "<input type='submit' name='save' value='Save'></form>";
383 function wdcal_getSettingsPage(&$a)
387 notice(t('Permission denied.') . EOL);
391 if (isset($_REQUEST["save"])) {
392 check_form_security_token_redirectOnErr('/dav/settings/', 'calprop');
393 set_pconfig($a->user["uid"], "dav", "dateformat", $_REQUEST["wdcal_date_format"]);
394 info(t('The new values have been saved.'));
399 $o .= "<a href='/dav/wdcal/'>" . t("Go back to the calendar") . "</a><br><br>";
401 $o .= '<h3>' . t('Calendar Settings') . '</h3>';
403 $current_format = wdcal_local::getInstanceByUser($a->user["uid"]);
404 $o .= '<form method="POST" action="/dav/settings/">';
405 $o .= "<input type='hidden' name='form_security_token' value='" . get_form_security_token('calprop') . "'>\n";
407 $o .= '<label for="wdcal_date_format">' . t('Date format') . ':</label><select name="wdcal_date_format" id="wdcal_date_format" size="1">';
408 $classes = wdcal_local::getInstanceClasses();
409 foreach ($classes as $c) {
410 $o .= '<option value="' . $c::getID() . '" ';
411 if ($c::getID() == $current_format::getID()) $o .= 'selected';
412 $o .= '>' . escape_tags($c::getName()) . '</option>';
414 $o .= '</select><br>';
416 $o .= '<label for="wdcal_time_zone">' . t('Time zone') . ':</label><input id="wdcal_time_zone" value="' . $a->timezone . '" disabled><br>';
418 $o .= '<input type="submit" name="save" value="' . t('Save') . '">';
421 $o .= "<br><h3>" . t("Limitations") . "</h3>";
423 $o .= "- The native friendica events are embedded as read-only, half-transparent in the calendar.<br>";
425 $o .= "<br><h3>" . t("Warning") . "</h3>";
427 $o .= "This plugin still is in a very early stage of development. Expect major bugs!<br>";
429 $o .= "<br><h3>" . t("Synchronization (iPhone, Thunderbird Lightning, Android, ...)") . "</h3>";
431 $o .= 'This plugin enables synchronization of your dates and contacts with CalDAV- and CardDAV-enabled programs or devices.<br>
432 As an example, the instructions how to set up two-way synchronization with an iPhone/iPodTouch are provided below.<br>
433 Unfortunately, Android does not have native support for CalDAV or CardDAV, so an app has to be installed.<br>
434 On desktops, the Lightning-extension to Mozilla Thunderbird should be able to use this plugin as a backend.<br><br>';
436 $o .= '<h4>' . t('Synchronizing this calendar with the iPhone') . '</h4>';
439 <li>Go to the settings</li>
440 <li>Mail, contacts, settings</li>
441 <li>Add a new account</li>
443 <li>Calendar -> CalDAV-Account</li>
444 <li><b>Server:</b> " . $a->get_hostname() . "/dav/ / <b>Username/Password:</b> <em>the same as your friendica-login</em></li>
447 $o .= '<h4>' . t('Synchronizing your Friendica-Contacts with the iPhone') . '</h4>';
450 <li>Go to the settings</li>
451 <li>Mail, contacts, settings</li>
452 <li>Add a new account</li>
454 <li>Contacts -> CardDAV-Account</li>
455 <li><b>Server:</b> " . $a->get_hostname() . "/dav/ / <b>Username/Password:</b> <em>the same as your friendica-login</em></li>