diff --git a/dav/calendar.friendica.fnk.php b/dav/calendar.friendica.fnk.php
index 1d4600c6a..af4a0175f 100644
--- a/dav/calendar.friendica.fnk.php
+++ b/dav/calendar.friendica.fnk.php
@@ -22,11 +22,17 @@ define("CARDDAV_NAMESPACE_PHONECONTACTS", 2);
define("CALDAV_DB_VERSION", 1);
+/**
+ * @return int
+ */
function getCurMicrotime () {
list($usec, $sec) = explode(" ", microtime());
return sprintf("%14.0f", $sec * 10000 + $usec * 10000);
} // function getCurMicrotime
+/**
+ *
+ */
function debug_time() {
$cur = getCurMicrotime();
if ($GLOBALS["debug_time_last"] > 0) {
@@ -80,13 +86,30 @@ function dav_compat_principal2uid($principalUri = "")
return dav_compat_username2id($username);
}
+
+/**
+ * @param string $name
+ * @return null|string
+ */
+function dav_compat_getRequestVar($name = "") {
+ if (x($_REQUEST, $name)) return $_REQUEST[$name];
+ else return null;
+}
+
/**
* @param $text
- * @return mixed
+ * @return null|string
*/
-function wdcal_parse_text_serverside($text)
+function dav_compat_parse_text_serverside($text)
{
- return $text;
+ return dav_compat_getRequestVar($text);
+}
+
+/**
+ * @param string $uri
+ */
+function dav_compat_redirect($uri = "") {
+ goaway($uri);
}
/**
diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php
index 51b7f5e03..410c60dd2 100644
--- a/dav/common/calendar.fnk.php
+++ b/dav/common/calendar.fnk.php
@@ -477,6 +477,67 @@ function wdcal_get_list_range_params($day, $weekstartday, $num_days, $type)
}
+
+
+
+/**
+ * @param string $uri
+ * @param string $recurr_uri
+ * @param int $uid
+ * @param string $timezone
+ * @param string $goaway_url
+ * @return string
+ */
+function wdcal_postEditPage($uri, $recurr_uri = "", $uid = 0, $timezone = "", $goaway_url = "")
+{
+ $uid = IntVal($uid);
+ $localization = wdcal_local::getInstanceByUser($uid);
+
+ if (isset($_REQUEST["allday"])) {
+ $start = $localization->date_parseLocal($_REQUEST["start_date"] . " 00:00");
+ $end = $localization->date_parseLocal($_REQUEST["end_date"] . " 20:00");
+ $isallday = true;
+ } else {
+ $start = $localization->date_parseLocal($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]);
+ $end = $localization->date_parseLocal($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]);
+ $isallday = false;
+ }
+
+ if ($uri == "new") {
+ $cals = dav_getMyCals($uid);
+ foreach ($cals as $c) {
+ $cs = wdcal_calendar_factory($uid, $c->namespace, $c->namespace_id);
+ $p = $cs->getPermissionsCalendar($uid);
+
+ if ($p["write"]) try {
+ $cs->addItem($start, $end, dav_compat_getRequestVar("subject"), $isallday, dav_compat_parse_text_serverside("wdcal_desc"),
+ dav_compat_getRequestVar("location"), dav_compat_getRequestVar("color"), $timezone,
+ isset($_REQUEST["notification"]), $_REQUEST["notification_type"], $_REQUEST["notification_value"]);
+ } catch (Exception $e) {
+ notification(t("Error") . ": " . $e);
+ }
+ dav_compat_redirect($goaway_url);
+ }
+
+ } else {
+ $cals = dav_getMyCals($uid);
+ foreach ($cals as $c) {
+ $cs = wdcal_calendar_factory($uid, $c->namespace, $c->namespace_id);
+ $p = $cs->getPermissionsItem($uid, $uri, $recurr_uri);
+ if ($p["write"]) try {
+ $cs->updateItem($uri, $start, $end,
+ dav_compat_getRequestVar("subject"), $isallday, dav_compat_parse_text_serverside("wdcal_desc"),
+ dav_compat_getRequestVar("location"), dav_compat_getRequestVar("color"), $timezone,
+ isset($_REQUEST["notification"]), $_REQUEST["notification_type"], $_REQUEST["notification_value"]);
+ } catch (Exception $e) {
+ notification(t("Error") . ": " . $e);
+ }
+ dav_compat_redirect($goaway_url);
+ }
+ }
+}
+
+
/**
*
*/
diff --git a/dav/common/wdcal.js b/dav/common/wdcal.js
index cbdc5a435..877d38525 100644
--- a/dav/common/wdcal.js
+++ b/dav/common/wdcal.js
@@ -1,17 +1,53 @@
+function wdcal_edit_getStartEnd() {
+ "use strict";
+
+ var start = $("#cal_start_date").datepicker("getDate");
+ var start_time = $.timePicker("#cal_start_time").getTime();
+ start.setHours(start_time.getHours());
+ start.setMinutes(start_time.getMinutes());
+
+ var end = $("#cal_end_date").datepicker("getDate");
+ var end_time = $.timePicker("#cal_end_time").getTime();
+ end.setHours(end_time.getHours());
+ end.setMinutes(end_time.getMinutes());
+
+ return {"start": start, "end": end};
+}
+
+function wdcal_edit_checktime_startChanged() {
+ "use strict";
+ var time = wdcal_edit_getStartEnd();
+ if (time.start.getTime() >= time.end.getTime()) {
+ var newend = new Date(time.start.getTime() + 3600000);
+ $("#cal_end_date").datepicker("setDate", newend);
+ $.timePicker("#cal_end_time").setTime(newend);
+ }
+}
+
+function wdcal_edit_checktime_endChanged() {
+ "use strict";
+ var time = wdcal_edit_getStartEnd();
+ if (time.start.getTime() >= time.end.getTime()) {
+ var newstart = new Date(time.end.getTime() - 3600000);
+ $("#cal_start_date").datepicker("setDate", newstart);
+ $.timePicker("#cal_start_time").setTime(newstart);
+ }
+}
+
function wdcal_edit_init(dateFormat) {
"use strict";
$("#cal_color").colorPicker();
- $("#cal_start_time").timePicker({ step: 15 });
- $("#cal_end_time").timePicker();
+ $("#cal_start_time").timePicker({ step: 15 }).on("change", wdcal_edit_checktime_startChanged);
+ $("#cal_end_time").timePicker().on("change", wdcal_edit_checktime_endChanged);
$("#cal_start_date").datepicker({
"dateFormat": dateFormat
- });
+ }).on("change", wdcal_edit_checktime_startChanged);
$("#cal_end_date").datepicker({
"dateFormat": dateFormat
- });
+ }).on("change", wdcal_edit_checktime_endChanged);
$("#notification").on("click change", function() {
if ($(this).prop("checked")) $("#notification_detail").show();
diff --git a/dav/common/wdcal/js/jquery.calendar.js b/dav/common/wdcal/js/jquery.calendar.js
index 88987cf59..194ae5664 100644
--- a/dav/common/wdcal/js/jquery.calendar.js
+++ b/dav/common/wdcal/js/jquery.calendar.js
@@ -195,6 +195,7 @@
* {Number} Calendar height, false for page height by default.
*/
height:false,
+ baseurl: "",
/**
* @description {Config} url
* {String} Url to request calendar data.
@@ -1744,21 +1745,21 @@
temparr.push(i18n.xgcalendar.time, ':
| ');
temparr.push(i18n.xgcalendar.content, ': | ');
temparr.push(i18n.xgcalendar.example, ' |
');
+ temparr.push(i18n.xgcalendar.create_event, '" type="submit"/> ');
temparr.push(i18n.xgcalendar.update_detail, ' >> | | |
');
temparr.push('');
- var tempquickAddHanler = temparr.join("");
+ var tempquickAddHandler = temparr.join("");
temparr = null;
- $(document.body).append(tempquickAddHanler);
+ $(document.body).append(tempquickAddHandler);
buddle = $("#bbit-cal-buddle");
- $("#bubbleClose1").click(function () {
+ $("#bubbleClose1").on("click", function () {
$("#bbit-cal-buddle").css("visibility", "hidden");
releasedragevent();
});
- $("#bbit-cal-submitFORM").keyup(function (e) {
+ $("#bbit-cal-submitFORM").on("keyup", function (e) {
if (e.which == 27) $("#bubbleClose1").click();
});
- $("#bbit-cal-submitFORM").submit(function (e) {
+ $("#bbit-cal-submitFORM").on("submit", function (e) {
e.stopPropagation();
e.preventDefault();
if (option.isloading) {
@@ -1838,7 +1839,7 @@
}
return false;
});
- buddle.mousedown(function (e) {
+ buddle.on("mousedown", function (e) {
e.stopPropagation();
e.preventDefault();
});
@@ -1857,6 +1858,10 @@
$("#bbit-cal-allday").val(isallday ? "1" : "0");
$("#bbit-cal-start").val(start.getTime());
$("#bbit-cal-end").val(end.getTime());
+
+ var addurl = option.baseurl + "new/?start=" + Math.floor($("#bbit-cal-start").val() / 1000) + "&end=" + Math.floor($("#bbit-cal-end").val() / 1000) + "&isallday=" + (isallday ? "1" : "0");
+ buddle.find(".bbit-cal-editLink").attr("href", addurl);
+
buddle.css({ "visibility":"visible", left:off.left, top:off.top });
calwhat.blur().focus(); //add 2010-01-26 blur() fixed chrome
$(document).one("mousedown", function () {
diff --git a/dav/dav.php b/dav/dav.php
index 8c29e385d..1f35b06ad 100644
--- a/dav/dav.php
+++ b/dav/dav.php
@@ -2,7 +2,7 @@
/**
* Name: Calendar with CalDAV Support
* Description: A web-based calendar system with CalDAV-support. Also brings your Friendica-Contacts to your CardDAV-capable mobile phone. Requires PHP >= 5.3.
- * Version: 0.1
+ * Version: 0.1.1
* Author: Tobias Hößl
*/
diff --git a/dav/layout.fnk.php b/dav/layout.fnk.php
index a712a09bc..550f90b6a 100644
--- a/dav/layout.fnk.php
+++ b/dav/layout.fnk.php
@@ -18,8 +18,11 @@ function wdcal_addRequiredHeaders()
$a->page['htmlhead'] .= '' . "\r\n";
switch (get_config("system", "language")) {
- case "de": $a->page['htmlhead'] .= '' . "\r\n"; break;
- default: $a->page['htmlhead'] .= '' . "\r\n";
+ case "de":
+ $a->page['htmlhead'] .= '' . "\r\n";
+ break;
+ default:
+ $a->page['htmlhead'] .= '' . "\r\n";
}
$a->page['htmlhead'] .= '' . "\r\n";
@@ -80,6 +83,7 @@ function wdcal_printCalendar($calendars, $calendar_preselected, $data_feed_url,
"date_format_dm2" => $localization->dateformat_js_dm2(),
"date_format_dm3" => $localization->dateformat_js_dm3(),
"date_format_full" => $localization->dateformat_datepicker_js(),
+ "baseurl" => $a->get_baseurl() . "/dav/wdcal/",
);
$x = '
@@ -111,6 +115,9 @@ function wdcal_printCalendar($calendars, $calendar_preselected, $data_feed_url,
+
+ $x .= '">' . t("Day") . '
user["uid"]);
foreach ($cals as $c) {
$cs = wdcal_calendar_factory($a->user["uid"], $c->namespace, $c->namespace_id);
$p = $cs->getPermissionsItem($a->user["uid"], $uri, $recurr_uri);
@@ -199,54 +206,12 @@ function wdcal_getDetailPage($uri, $recurr_uri)
return $uri . " / " . $recurr_uri . "
" . print_r($details, true);
}
-
/**
* @param string $uri
* @param string $recurr_uri
* @return string
*/
-function wdcal_postEditPage($uri, $recurr_uri)
-{
-
- $a = get_app();
- $localization = wdcal_local::getInstanceByUser($a->user["uid"]);
-
- check_form_security_token_redirectOnErr($a->get_baseurl() . "/dav/wdcal/", "caledit");
-
- if (isset($_REQUEST["allday"])) {
- $start = $localization->date_parseLocal($_REQUEST["start_date"] . " 00:00");
- $end = $localization->date_parseLocal($_REQUEST["end_date"] . " 20:00");
- $isallday = true;
- } else {
- $start = $localization->date_parseLocal($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]);
- $end = $localization->date_parseLocal($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]);
- $isallday = false;
- }
-
-
- $cals = dav_getMyCals($a->user["uid"]);
- foreach ($cals as $c) {
- $cs = wdcal_calendar_factory($a->user["uid"], $c->namespace, $c->namespace_id);
- $p = $cs->getPermissionsItem($a->user["uid"], $uri, $recurr_uri);
- if ($p["write"]) try {
- $cs->updateItem($uri, $start, $end,
- stripslashes($_REQUEST["subject"]), $isallday, wdcal_parse_text_serverside($_REQUEST["wdcal_desc"]),
- stripslashes($_REQUEST["location"]), $_REQUEST["color"], $a->timezone,
- isset($_REQUEST["notification"]), $_REQUEST["notification_type"], $_REQUEST["notification_value"]);
- } catch (Exception $e) {
- notification(t("Error") . ": " . $e);
- }
- goaway($a->get_baseurl() . "/dav/wdcal/");
- }
-
-}
-
-/**
- * @param string $uri
- * @param string $recurr_uri
- * @return string
- */
-function wdcal_getEditPage($uri, $recurr_uri)
+function wdcal_getEditPage($uri, $recurr_uri = "")
{
$a = get_app();
@@ -290,8 +255,8 @@ function wdcal_getEditPage($uri, $recurr_uri)
"Subject" => $_REQUEST["title"],
"Location" => "",
"Description" => "",
- "StartTime" => $_REQUEST["start"],
- "EndTime" => $_REQUEST["end"],
+ "StartTime" => wdcal_php2MySqlTime($_REQUEST["start"]),
+ "EndTime" => wdcal_php2MySqlTime($_REQUEST["end"]),
"IsAllDayEvent" => $_REQUEST["isallday"],
"Color" => null,
"RecurringRule" => null,
@@ -311,10 +276,10 @@ function wdcal_getEditPage($uri, $recurr_uri)
"Subject" => "",
"Location" => "",
"Description" => "",
- "StartTime" => "",
- "EndTime" => "",
- "IsAllDayEvent" => "",
- "Color" => null,
+ "StartTime" => date("Y-m-d H:i:s"),
+ "EndTime" => date("Y-m-d H:i:s", time() + 3600),
+ "IsAllDayEvent" => "0",
+ "Color" => "#5858ff",
"RecurringRule" => null,
);
$notification_type = "hour";
@@ -322,26 +287,27 @@ function wdcal_getEditPage($uri, $recurr_uri)
$notification = true;
}
+ $postto = $a->get_baseurl() . "/dav/wdcal/" . ($uri == "new" ? "new/" : $uri . "/edit/");
$out = "
" . t("Go back to the calendar") . "";
- $out .= "