diff options
author | Georg Ehrke <georg.stefan.germany@googlemail.com> | 2011-08-28 20:13:40 +0200 |
---|---|---|
committer | Georg Ehrke <georg.stefan.germany@googlemail.com> | 2011-08-28 20:13:40 +0200 |
commit | ca08ccb61c143bfbe821c7fbc5b136a2a8dfa293 (patch) | |
tree | 1cfa4a90577ede9745fbb10ffa1e21e71bdbf161 /apps/calendar/ajax/newevent.php | |
parent | 84761b1518c54e9f43eae3a831c9456c0daad3ca (diff) | |
download | nextcloud-server-ca08ccb61c143bfbe821c7fbc5b136a2a8dfa293.tar.gz nextcloud-server-ca08ccb61c143bfbe821c7fbc5b136a2a8dfa293.zip |
first add event function in calendar app
Diffstat (limited to 'apps/calendar/ajax/newevent.php')
-rwxr-xr-x | apps/calendar/ajax/newevent.php | 143 |
1 files changed, 141 insertions, 2 deletions
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("<script type=\"text/javascript\">document.location = oc_webroot;</script>"); +} +//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 |