From ca08ccb61c143bfbe821c7fbc5b136a2a8dfa293 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 28 Aug 2011 20:13:40 +0200 Subject: [PATCH] first add event function in calendar app --- apps/calendar/ajax/choosecalendar.php | 0 apps/calendar/ajax/editeventform.php | 0 apps/calendar/ajax/newevent.php | 143 +++++++++++++++++- apps/calendar/ajax/neweventform.php | 0 apps/calendar/l10n/xgettextfiles | 1 + apps/calendar/templates/calendar.php | 16 +- .../templates/part.choosecalendar.php | 11 +- apps/calendar/templates/part.newevent.php | 75 +++++++-- 8 files changed, 224 insertions(+), 22 deletions(-) mode change 100644 => 100755 apps/calendar/ajax/choosecalendar.php mode change 100644 => 100755 apps/calendar/ajax/editeventform.php mode change 100644 => 100755 apps/calendar/ajax/neweventform.php diff --git a/apps/calendar/ajax/choosecalendar.php b/apps/calendar/ajax/choosecalendar.php old mode 100644 new mode 100755 diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php old mode 100644 new mode 100755 diff --git a/apps/calendar/ajax/newevent.php b/apps/calendar/ajax/newevent.php index a87eab02af5..b51208f680a 100755 --- a/apps/calendar/ajax/newevent.php +++ b/apps/calendar/ajax/newevent.php @@ -18,6 +18,145 @@ * 59 Temple Place, Suite 330, Boston, * * MA 02111-1307 USA * *************************************************/ +require_once('../../../lib/base.php'); +$l10n = new OC_L10N('calendar'); +if(!OC_USER::isLoggedIn()) { + die(""); +} +//short variables +$title = $_POST["title"]; +$location = $_POST["location"]; +$cat = $_POST["cat"]; +$cal = $_POST["cal"]; +$cal = "1"; +$allday = $_POST["allday"]; +$from = $_POST["from"]; +$fromtime = $_POST["fromtime"]; +$to = $_POST["to"]; +$totime = $_POST["totime"]; +$description = $_POST["description"]; +$repeat = $_POST["repeat"]; +/*switch($_POST["repeatfreq"]){ + case "DAILY": + $repeatfreq = "DAILY"; + case "WEEKLY": + $repeatfreq = "WEEKLY"; + case "WEEKDAY": + $repeatfreq = "DAILY;BYDAY=MO,TU,WE,TH,FR"; //load weeksdayss from userconfig when weekdays are choosable + case "": + $repeatfreq = ""; + case "": + $repeatfreq = ""; + case "": + $repeatfreq = ""; + default: + $repeat = "false"; +}*/ +$repeat = "false"; +//validate variables +$errnum = 0; +$errarr = array("title"=>"false", "cal"=>"false", "from"=>"false", "fromtime"=>"false", "to"=>"false", "totime"=>"false", "endbeforestart"=>"false"); +if($title == ""){ + $errarr["title"] = "true"; + $errnum++; +} +$calendar = OC_Calendar_Calendar::findCalendar($cal); +if($calendar["userid"] != OC_User::getUser()){ + $errarr["cal"] = "true"; + $errnum++; +} +$fromday = substr($_POST["from"], 0, 2); +$frommonth = substr($_POST["from"], 3, 2); +$fromyear = substr($_POST["from"], 6, 4); +if(!checkdate($frommonth, $fromday, $fromyear)){ + $errarr["from"] = "true"; + $errnum++; +} +$fromhours = substr($_POST["fromtime"], 0, 2); +$fromminutes = substr($_POST["fromtime"], 3, 2); +if($fromhours > 24 || $fromminutes > 60 || $fromtime == ""){ + $errarr["fromtime"] = "true"; + $errnum++; +} -?> - +$today = substr($_POST["to"], 0, 2); +$tomonth = substr($_POST["to"], 3, 2); +$toyear = substr($_POST["to"], 6, 4); +if(!checkdate($tomonth, $today, $toyear)){ + $errarr["to"] = "true"; + $errnum++; +} +$tohours = substr($_POST["totime"], 0, 2); +$tominutes = substr($_POST["totime"], 3, 2); +if($tohours > 24 || $tominutes > 60 || $totime == ""){ + $errarr["totime"] = "true"; + $errnum++; +} +if($today < $fromday && $frommonth == $tomonth && $fromyear == $toyear){ + $errarr["endbeforestart"] = "true"; + $errnum++; +} +if($today == $fromday && $frommonth > $tomonth && $fromyear == $toyear){ + $errarr["endbeforestart"] = "true"; + $errnum++; +} +if($today == $fromday && $frommonth == $tomonth && $fromyear > $toyear){ + $errarr["endbeforestart"] = "true"; + $errnum++; +} +if($fromday == $today && $frommonth == $tomonth && $fromyear == $toyear){ + if($tohours < $fromhours){ + $errarr["endbeforestart"] = "true"; + $errnum++; + } + if($tohours == $fromhours && $tominutes < $fromminutes){ + $errarr["endbeforestart"] = "true"; + $errnum++; + } +} +if($errnum != 0){ + //show validate errors + $errarr["error"] = "true"; + echo json_encode($errarr); + exit; +}else{ + $data = "BEGIN:VCALENDAR\nPRODID:ownCloud Calendar\nVERSION:2.0\n"; + if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == ""){ + $timezone = "Europe/London"; + }else{ + $timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone"); + } + $created = date("Ymd") . "T" . date("His"); + $data .= "BEGIN:VEVENT\n"; + $data .= "CREATED:" . $created . "\nLAST-MODIFIED:" . $created . "\nDTSTAMP:" . $created . "\n"; + $data .= "SUMMARY:" . $title . "\n"; + if($allday == "true"){ + $start = $fromyear . $frommonth . $fromday; + $unixend = mktime(0,0,0,$tomonth, $today, $toyear) + (24 * 60 * 60); + $end = date("Ymd", $unixend); + $data .= "DTSTART;VALUE=DATE:" . $start . "\n"; + $data .= "DTEND;VALUE=DATE:" . $end . "\n"; + }else{ + $start = $fromyear . $frommonth . $fromday . "T" . $fromhours . $fromminutes . "00"; + $end = $toyear . $tomonth . $today . "T" . $tohours . $tominutes . "00"; + $data .= "DTSTART;TZID=" . $timezone . ":" . $start . "\n"; + $data .= "DTEND;TZID=" . $timezone . ":" . $end . "\n"; + } + if($location != ""){ + $data .= "LOCATION:" . $location . "\n"; + } + if($description != ""){ + $des = str_replace("\n","\\n", $description); + $data .= "DESCRIPTION:" . $des . "\n"; + } + if($cat != "none"){ + $data .= "CATEGORIES:" . $cat . "\n"; + } + if($repeat == "true"){ + $data .= "RRULE:" . $repeat . "\n"; + } + $data .= "END:VEVENT\nEND:VCALENDAR"; + echo $data; + $result = OC_Calendar_Calendar::addCalendarObject($cal, $data); +} +?> \ No newline at end of file diff --git a/apps/calendar/ajax/neweventform.php b/apps/calendar/ajax/neweventform.php old mode 100644 new mode 100755 diff --git a/apps/calendar/l10n/xgettextfiles b/apps/calendar/l10n/xgettextfiles index 37f68b82062..c94fb9d8b2e 100644 --- a/apps/calendar/l10n/xgettextfiles +++ b/apps/calendar/l10n/xgettextfiles @@ -3,5 +3,6 @@ ../templates/part.editevent.php ../templates/part.eventinfo.php ../templates/part.newevent.php +../templates/part.choosecalendar.php ../js/calendar.js ../js/calendar_init.js \ No newline at end of file diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index b9b11f8a274..8690d7a45d2 100755 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -907,7 +907,7 @@
- There was a fail, while parsing the file. + t("There was a fail, while parsing the file."); ?>
- + \ No newline at end of file diff --git a/apps/calendar/templates/part.choosecalendar.php b/apps/calendar/templates/part.choosecalendar.php index 487ee7645d7..0aef52b4388 100644 --- a/apps/calendar/templates/part.choosecalendar.php +++ b/apps/calendar/templates/part.choosecalendar.php @@ -1,10 +1,16 @@
"> +"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; } ?> +
t("Download") . "\" class=\"action\">t("Rename") . "\" class=\"action\">



">
@@ -20,7 +26,4 @@ for($i = 0; $i < count($option_calendars); $i++){ } } }); - function highlight_button(id){ - document.getElementById("button_" + id).style.color = "#000000"; - } diff --git a/apps/calendar/templates/part.newevent.php b/apps/calendar/templates/part.newevent.php index bc19042f10c..837e032c734 100644 --- a/apps/calendar/templates/part.newevent.php +++ b/apps/calendar/templates/part.newevent.php @@ -1,15 +1,16 @@
"> +
t("Title");?>: - " maxlength="100" /> + " maxlength="100" id="newevent_title"/>
t("Location");?>: - " maxlength="100" /> + " maxlength="100" id="newevent_location" />
@@ -17,14 +18,14 @@ t("Category");?>: -     t("Calendar");?>: - " id="totime"> - +
- +
- +
t("Description");?>:
+
- "> + " onclick="validate_newevent_form();"> +
\ No newline at end of file