From: Georg Ehrke Date: Mon, 20 Feb 2012 10:26:22 +0000 (+0100) Subject: add moved files to clean up ajax folder X-Git-Tag: v4.0.0beta~201^2~20^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b7de1850a00b91be34af062957df73424c95469b;p=nextcloud-server.git add moved files to clean up ajax folder --- diff --git a/apps/calendar/ajax/calendar/activation.php b/apps/calendar/ajax/calendar/activation.php new file mode 100644 index 00000000000..7677d85aff3 --- /dev/null +++ b/apps/calendar/ajax/calendar/activation.php @@ -0,0 +1,19 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +$calendarid = $_POST['calendarid']; +$calendar = OC_Calendar_App::getCalendar($calendarid);//access check +OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); +$calendar = OC_Calendar_App::getCalendar($calendarid); +OC_JSON::success(array( + 'active' => $calendar['active'], + 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar), +)); diff --git a/apps/calendar/ajax/calendar/delete.php b/apps/calendar/ajax/calendar/delete.php new file mode 100644 index 00000000000..a2f5311731c --- /dev/null +++ b/apps/calendar/ajax/calendar/delete.php @@ -0,0 +1,21 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); + +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +$cal = $_POST["calendarid"]; +$calendar = OC_Calendar_App::getCalendar($cal); +$del = OC_Calendar_Calendar::deleteCalendar($cal); +if($del == true){ + OC_JSON::success(); +}else{ + OC_JSON::error(array('error'=>'dberror')); +} +?> diff --git a/apps/calendar/ajax/calendar/edit.form.php b/apps/calendar/ajax/calendar/edit.form.php new file mode 100644 index 00000000000..8922b3eba4e --- /dev/null +++ b/apps/calendar/ajax/calendar/edit.form.php @@ -0,0 +1,20 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +$calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions(); +$calendar = OC_Calendar_App::getCalendar($_GET['calendarid']); +$tmpl = new OC_Template("calendar", "part.editcalendar"); +$tmpl->assign('new', false); +$tmpl->assign('calendarcolor_options', $calendarcolor_options); +$tmpl->assign('calendar', $calendar); +$tmpl->printPage(); +?> diff --git a/apps/calendar/ajax/calendar/edit.php b/apps/calendar/ajax/calendar/edit.php new file mode 100644 index 00000000000..8922b3eba4e --- /dev/null +++ b/apps/calendar/ajax/calendar/edit.php @@ -0,0 +1,20 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +$calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions(); +$calendar = OC_Calendar_App::getCalendar($_GET['calendarid']); +$tmpl = new OC_Template("calendar", "part.editcalendar"); +$tmpl->assign('new', false); +$tmpl->assign('calendarcolor_options', $calendarcolor_options); +$tmpl->assign('calendar', $calendar); +$tmpl->printPage(); +?> diff --git a/apps/calendar/ajax/calendar/new.form.php b/apps/calendar/ajax/calendar/new.form.php new file mode 100644 index 00000000000..6e7423cbe92 --- /dev/null +++ b/apps/calendar/ajax/calendar/new.form.php @@ -0,0 +1,24 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); +$l10n = new OC_L10N('calendar'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +$calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions(); +$calendar = array( + 'id' => 'new', + 'displayname' => '', + 'calendarcolor' => '', +); +$tmpl = new OC_Template('calendar', 'part.editcalendar'); +$tmpl->assign('new', true); +$tmpl->assign('calendarcolor_options', $calendarcolor_options); +$tmpl->assign('calendar', $calendar); +$tmpl->printPage(); +?> diff --git a/apps/calendar/ajax/calendar/new.php b/apps/calendar/ajax/calendar/new.php new file mode 100644 index 00000000000..228e6247724 --- /dev/null +++ b/apps/calendar/ajax/calendar/new.php @@ -0,0 +1,37 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); + +// Check if we are a user +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +if(trim($_POST['name']) == ''){ + OC_JSON::error(array('message'=>'empty')); + exit; +} +$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +foreach($calendars as $cal){ + if($cal['displayname'] == $_POST['name']){ + OC_JSON::error(array('message'=>'namenotavailable')); + exit; + } +} + +$userid = OC_User::getUser(); +$calendarid = OC_Calendar_Calendar::addCalendar($userid, strip_tags($_POST['name']), 'VEVENT,VTODO,VJOURNAL', null, 0, $_POST['color']); +OC_Calendar_Calendar::setCalendarActive($calendarid, 1); + +$calendar = OC_Calendar_Calendar::find($calendarid); +$tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields'); +$tmpl->assign('calendar', $calendar); +OC_JSON::success(array( + 'page' => $tmpl->fetchPage(), + 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar), +)); diff --git a/apps/calendar/ajax/calendar/overview.php b/apps/calendar/ajax/calendar/overview.php new file mode 100644 index 00000000000..2f73f5d0710 --- /dev/null +++ b/apps/calendar/ajax/calendar/overview.php @@ -0,0 +1,15 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); +$l10n = new OC_L10N('calendar'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +$output = new OC_TEMPLATE("calendar", "part.choosecalendar"); +$output -> printpage(); +?> diff --git a/apps/calendar/ajax/calendar/updatecalendar.php b/apps/calendar/ajax/calendar/updatecalendar.php new file mode 100644 index 00000000000..f400c8c14b4 --- /dev/null +++ b/apps/calendar/ajax/calendar/updatecalendar.php @@ -0,0 +1,38 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); + +// Check if we are a user +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +if(trim($_POST['name']) == ''){ + OC_JSON::error(array('message'=>'empty')); + exit; +} +$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +foreach($calendars as $cal){ + if($cal['displayname'] == $_POST['name'] && $cal['id'] != $_POST['id']){ + OC_JSON::error(array('message'=>'namenotavailable')); + exit; + } +} + +$calendarid = $_POST['id']; +$calendar = OC_Calendar_App::getCalendar($calendarid);//access check +OC_Calendar_Calendar::editCalendar($calendarid, strip_tags($_POST['name']), null, null, null, $_POST['color']); +OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); + +$calendar = OC_Calendar_App::getCalendar($calendarid); +$tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields'); +$tmpl->assign('calendar', $calendar); +OC_JSON::success(array( + 'page' => $tmpl->fetchPage(), + 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar), +)); diff --git a/apps/calendar/ajax/event/delete.php b/apps/calendar/ajax/event/delete.php new file mode 100644 index 00000000000..862dec6bf5b --- /dev/null +++ b/apps/calendar/ajax/event/delete.php @@ -0,0 +1,19 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); + +$l10n = new OC_L10N('calendar'); + +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +$id = $_POST['id']; +$event_object = OC_Calendar_App::getEventObject($id); +$result = OC_Calendar_Object::delete($id); +OC_JSON::success(); +?> diff --git a/apps/calendar/ajax/event/edit.form.php b/apps/calendar/ajax/event/edit.form.php new file mode 100644 index 00000000000..837edbbbf05 --- /dev/null +++ b/apps/calendar/ajax/event/edit.form.php @@ -0,0 +1,248 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); + +if(!OC_USER::isLoggedIn()) { + die(''); +} +OC_JSON::checkAppEnabled('calendar'); + +$id = $_GET['id']; +$data = OC_Calendar_App::getEventObject($id); +$object = OC_VObject::parse($data['calendardata']); +$vevent = $object->VEVENT; + +$dtstart = $vevent->DTSTART; +$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); +switch($dtstart->getDateType()) { + case Sabre_VObject_Element_DateTime::LOCALTZ: + case Sabre_VObject_Element_DateTime::LOCAL: + $startdate = $dtstart->getDateTime()->format('d-m-Y'); + $starttime = $dtstart->getDateTime()->format('H:i'); + $enddate = $dtend->getDateTime()->format('d-m-Y'); + $endtime = $dtend->getDateTime()->format('H:i'); + $allday = false; + break; + case Sabre_VObject_Element_DateTime::DATE: + $startdate = $dtstart->getDateTime()->format('d-m-Y'); + $starttime = ''; + $dtend->getDateTime()->modify('-1 day'); + $enddate = $dtend->getDateTime()->format('d-m-Y'); + $endtime = ''; + $allday = true; + break; +} + +$summary = $vevent->getAsString('SUMMARY'); +$location = $vevent->getAsString('LOCATION'); +$categories = $vevent->getAsArray('CATEGORIES'); +$description = $vevent->getAsString('DESCRIPTION'); +foreach($categories as $category){ + if (!in_array($category, $category_options)){ + array_unshift($category_options, $category); + } +} +$last_modified = $vevent->__get('LAST-MODIFIED'); +if ($last_modified){ + $lastmodified = $last_modified->getDateTime()->format('U'); +}else{ + $lastmodified = 0; +} +if($data['repeating'] == 1){ + $rrule = explode(';', $vevent->getAsString('RRULE')); + $rrulearr = array(); + foreach($rrule as $rule){ + list($attr, $val) = explode('=', $rule); + $rrulearr[$attr] = $val; + } + if(!isset($rrulearr['INTERVAL']) || $rrulearr['INTERVAL'] == ''){ + $rrulearr['INTERVAL'] = 1; + } + if(array_key_exists('BYDAY', $rrulearr)){ + if(substr_count($rrulearr['BYDAY'], ',') == 0){ + if(strlen($rrulearr['BYDAY']) == 2){ + $repeat['weekdays'] = array($rrulearr['BYDAY']); + }elseif(strlen($rrulearr['BYDAY']) == 3){ + $repeat['weekofmonth'] = substr($rrulearr['BYDAY'], 0, 1); + $repeat['weekdays'] = array(substr($rrulearr['BYDAY'], 1, 2)); + }elseif(strlen($rrulearr['BYDAY']) == 4){ + $repeat['weekofmonth'] = substr($rrulearr['BYDAY'], 0, 2); + $repeat['weekdays'] = array(substr($rrulearr['BYDAY'], 2, 2)); + } + }else{ + $byday_days = explode(',', $rrulearr['BYDAY']); + foreach($byday_days as $byday_day){ + if(strlen($byday_day) == 2){ + $repeat['weekdays'][] = $byday_day; + }elseif(strlen($byday_day) == 3){ + $repeat['weekofmonth'] = substr($byday_day , 0, 1); + $repeat['weekdays'][] = substr($byday_day , 1, 2); + }elseif(strlen($byday_day) == 4){ + $repeat['weekofmonth'] = substr($byday_day , 0, 2); + $repeat['weekdays'][] = substr($byday_day , 2, 2); + } + } + } + } + if(array_key_exists('BYMONTHDAY', $rrulearr)){ + if(substr_count($rrulearr['BYMONTHDAY'], ',') == 0){ + $repeat['bymonthday'][] = $rrulearr['BYMONTHDAY']; + }else{ + $bymonthdays = explode(',', $rrulearr['BYMONTHDAY']); + foreach($bymonthdays as $bymonthday){ + $repeat['bymonthday'][] = $bymonthday; + } + } + } + if(array_key_exists('BYYEARDAY', $rrulearr)){ + if(substr_count($rrulearr['BYYEARDAY'], ',') == 0){ + $repeat['byyearday'][] = $rrulearr['BYYEARDAY']; + }else{ + $byyeardays = explode(',', $rrulearr['BYYEARDAY']); + foreach($byyeardays as $yearday){ + $repeat['byyearday'][] = $yearday; + } + } + } + if(array_key_exists('BYWEEKNO', $rrulearr)){ + if(substr_count($rrulearr['BYWEEKNO'], ',') == 0){ + $repeat['byweekno'][] = (string) $rrulearr['BYWEEKNO']; + }else{ + $byweekno = explode(',', $rrulearr['BYWEEKNO']); + foreach($byweekno as $weekno){ + $repeat['byweekno'][] = (string) $weekno; + } + } + } + if(array_key_exists('BYMONTH', $rrulearr)){ + $months = OC_Calendar_App::getByMonthOptions(); + if(substr_count($rrulearr['BYMONTH'], ',') == 0){ + $repeat['bymonth'][] = $months[$month]; + }else{ + $bymonth = explode(',', $rrulearr['BYMONTH']); + foreach($bymonth as $month){ + $repeat['bymonth'][] = $months[$month]; + } + } + } + switch($rrulearr['FREQ']){ + case 'DAILY': + $repeat['repeat'] = 'daily'; + break; + case 'WEEKLY': + if($rrulearr['INTERVAL'] % 2 == 0){ + $repeat['repeat'] = 'biweekly'; + $rrulearr['INTERVAL'] = $rrulearr['INTERVAL'] / 2; + }elseif($rrulearr['BYDAY'] == 'MO,TU,WE,TH,FR'){ + $repeat['repeat'] = 'weekday'; + }else{ + $repeat['repeat'] = 'weekly'; + } + break; + case 'MONTHLY': + $repeat['repeat'] = 'monthly'; + if(array_key_exists('BYDAY', $rrulearr)){ + $repeat['month'] = 'weekday'; + }else{ + $repeat['month'] = 'monthday'; + } + break; + case 'YEARLY': + $repeat['repeat'] = 'yearly'; + if(array_key_exists('BYMONTH', $rrulearr)){ + $repeat['year'] = 'bydaymonth'; + }elseif(array_key_exists('BYWEEKNO', $rrulearr)){ + $repeat['year'] = 'byweekno'; + }else{ + $repeat['year'] = 'byyearday'; + } + } + $repeat['interval'] = $rrulearr['INTERVAL']; + if(array_key_exists('COUNT', $rrulearr)){ + $repeat['end'] = 'count'; + $repeat['count'] = $rrulearr['COUNT']; + }elseif(array_key_exists('UNTIL', $rrulearr)){ + $repeat['end'] = 'date'; + $endbydate_day = substr($rrulearr['UNTIL'], 6, 2); + $endbydate_month = substr($rrulearr['UNTIL'], 4, 2); + $endbydate_year = substr($rrulearr['UNTIL'], 0, 4); + $repeat['date'] = $endbydate_day . '-' . $endbydate_month . '-' . $endbydate_year; + }else{ + $repeat['end'] = 'never'; + } + if(array_key_exists('weekdays', $repeat)){ + $repeat_weekdays_ = array(); + $days = OC_Calendar_App::getWeeklyOptions(); + foreach($repeat['weekdays'] as $weekday){ + $repeat_weekdays_[] = $days[$weekday]; + } + $repeat['weekdays'] = $repeat_weekdays_; + } +}else{ + $repeat['repeat'] = 'doesnotrepeat'; +} + +$calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +$category_options = OC_Calendar_App::getCategoryOptions(); +$repeat_options = OC_Calendar_App::getRepeatOptions(); +$repeat_end_options = OC_Calendar_App::getEndOptions(); +$repeat_month_options = OC_Calendar_App::getMonthOptions(); +$repeat_year_options = OC_Calendar_App::getYearOptions(); +$repeat_weekly_options = OC_Calendar_App::getWeeklyOptions(); +$repeat_weekofmonth_options = OC_Calendar_App::getWeekofMonth(); +$repeat_byyearday_options = OC_Calendar_App::getByYearDayOptions(); +$repeat_bymonth_options = OC_Calendar_App::getByMonthOptions(); +$repeat_byweekno_options = OC_Calendar_App::getByWeekNoOptions(); +$repeat_bymonthday_options = OC_Calendar_App::getByMonthDayOptions(); + +$tmpl = new OC_Template('calendar', 'part.editevent'); +$tmpl->assign('id', $id); +$tmpl->assign('lastmodified', $lastmodified); +$tmpl->assign('calendar_options', $calendar_options); +$tmpl->assign('category_options', $category_options); +$tmpl->assign('repeat_options', $repeat_options); +$tmpl->assign('repeat_month_options', $repeat_month_options); +$tmpl->assign('repeat_weekly_options', $repeat_weekly_options); +$tmpl->assign('repeat_end_options', $repeat_end_options); +$tmpl->assign('repeat_year_options', $repeat_year_options); +$tmpl->assign('repeat_byyearday_options', $repeat_byyearday_options); +$tmpl->assign('repeat_bymonth_options', $repeat_bymonth_options); +$tmpl->assign('repeat_byweekno_options', $repeat_byweekno_options); +$tmpl->assign('repeat_bymonthday_options', $repeat_bymonthday_options); +$tmpl->assign('repeat_weekofmonth_options', $repeat_weekofmonth_options); + +$tmpl->assign('title', $summary); +$tmpl->assign('location', $location); +$tmpl->assign('categories', $categories); +$tmpl->assign('calendar', $data['calendarid']); +$tmpl->assign('allday', $allday); +$tmpl->assign('startdate', $startdate); +$tmpl->assign('starttime', $starttime); +$tmpl->assign('enddate', $enddate); +$tmpl->assign('endtime', $endtime); +$tmpl->assign('description', $description); + +$tmpl->assign('repeat', $repeat['repeat']); +if($repeat['repeat'] != 'doesnotrepeat'){ + $tmpl->assign('repeat_month', $repeat['month']); + $tmpl->assign('repeat_weekdays', $repeat['weekdays']); + $tmpl->assign('repeat_interval', $repeat['interval']); + $tmpl->assign('repeat_end', $repeat['end']); + $tmpl->assign('repeat_count', $repeat['count']); + $tmpl->assign('repeat_weekofmonth', $repeat['weekofmonth']); + $tmpl->assign('repeat_date', $repeat['date']); + $tmpl->assign('repeat_year', $repeat['year']); + $tmpl->assign('repeat_byyearday', $repeat['byyearday']); + $tmpl->assign('repeat_bymonthday', $repeat['bymonthday']); + $tmpl->assign('repeat_bymonth', $repeat['bymonth']); + $tmpl->assign('repeat_byweekno', $repeat['byweekno']); +} +$tmpl->printpage(); + +?> \ No newline at end of file diff --git a/apps/calendar/ajax/event/edit.php b/apps/calendar/ajax/event/edit.php new file mode 100644 index 00000000000..64daffddef0 --- /dev/null +++ b/apps/calendar/ajax/event/edit.php @@ -0,0 +1,33 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +$errarr = OC_Calendar_Object::validateRequest($_POST); +if($errarr){ + //show validate errors + OC_JSON::error($errarr); + exit; +}else{ + $id = $_POST['id']; + $cal = $_POST['calendar']; + $data = OC_Calendar_App::getEventObject($id); + $vcalendar = OC_VObject::parse($data['calendardata']); + + OC_Calendar_App::isNotModified($vcalendar->VEVENT, $_POST['lastmodified']); + OC_Calendar_Object::updateVCalendarFromRequest($_POST, $vcalendar); + + $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); + if ($data['calendarid'] != $cal) { + OC_Calendar_Object::moveToCalendar($id, $cal); + } + OC_JSON::success(); +} +?> diff --git a/apps/calendar/ajax/event/move.php b/apps/calendar/ajax/event/move.php new file mode 100644 index 00000000000..8150fdbaa32 --- /dev/null +++ b/apps/calendar/ajax/event/move.php @@ -0,0 +1,43 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); + +$id = $_POST['id']; + +$vcalendar = OC_Calendar_App::getVCalendar($id); +$vevent = $vcalendar->VEVENT; + +$allday = $_POST['allDay']; +$delta = new DateInterval('P0D'); +$delta->d = $_POST['dayDelta']; +$delta->i = $_POST['minuteDelta']; + +OC_Calendar_App::isNotModified($vevent, $_POST['lastmodified']); + +$dtstart = $vevent->DTSTART; +$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); +$start_type = $dtstart->getDateType(); +$end_type = $dtend->getDateType(); +if ($allday && $start_type != Sabre_VObject_Element_DateTime::DATE){ + $start_type = $end_type = Sabre_VObject_Element_DateTime::DATE; + $dtend->setDateTime($dtend->getDateTime()->modify('+1 day'), $end_type); +} +if (!$allday && $start_type == Sabre_VObject_Element_DateTime::DATE){ + $start_type = $end_type = Sabre_VObject_Element_DateTime::LOCALTZ; +} +$dtstart->setDateTime($dtstart->getDateTime()->add($delta), $start_type); +$dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); +unset($vevent->DURATION); + +$vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC); +$vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC); + +$result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); +$lastmodified = $vevent->__get('LAST-MODIFIED')->getDateTime(); +OC_JSON::success(array('lastmodified'=>(int)$lastmodified->format('U'))); diff --git a/apps/calendar/ajax/event/new.form.php b/apps/calendar/ajax/event/new.form.php new file mode 100644 index 00000000000..c19928a727e --- /dev/null +++ b/apps/calendar/ajax/event/new.form.php @@ -0,0 +1,76 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); + +if(!OC_USER::isLoggedIn()) { + die(''); +} +OC_JSON::checkAppEnabled('calendar'); + +if (!isset($_POST['start'])){ + OC_JSON::error(); + die; +} +$start = $_POST['start']; +$end = $_POST['end']; +$allday = $_POST['allday']; + +if (!$end){ + $duration = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'duration', '60'); + $end = $start + ($duration * 60); +} +$start = new DateTime('@'.$start); +$end = new DateTime('@'.$end); +$timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); +$start->setTimezone(new DateTimeZone($timezone)); +$end->setTimezone(new DateTimeZone($timezone)); + +$calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +$category_options = OC_Calendar_App::getCategoryOptions(); +$repeat_options = OC_Calendar_App::getRepeatOptions(); +$repeat_end_options = OC_Calendar_App::getEndOptions(); +$repeat_month_options = OC_Calendar_App::getMonthOptions(); +$repeat_year_options = OC_Calendar_App::getYearOptions(); +$repeat_weekly_options = OC_Calendar_App::getWeeklyOptions(); +$repeat_weekofmonth_options = OC_Calendar_App::getWeekofMonth(); +$repeat_byyearday_options = OC_Calendar_App::getByYearDayOptions(); +$repeat_bymonth_options = OC_Calendar_App::getByMonthOptions(); +$repeat_byweekno_options = OC_Calendar_App::getByWeekNoOptions(); +$repeat_bymonthday_options = OC_Calendar_App::getByMonthDayOptions(); + +$tmpl = new OC_Template('calendar', 'part.newevent'); +$tmpl->assign('calendar_options', $calendar_options); +$tmpl->assign('category_options', $category_options); +$tmpl->assign('repeat_options', $repeat_options); +$tmpl->assign('repeat_month_options', $repeat_month_options); +$tmpl->assign('repeat_weekly_options', $repeat_weekly_options); +$tmpl->assign('repeat_end_options', $repeat_end_options); +$tmpl->assign('repeat_year_options', $repeat_year_options); +$tmpl->assign('repeat_byyearday_options', $repeat_byyearday_options); +$tmpl->assign('repeat_bymonth_options', $repeat_bymonth_options); +$tmpl->assign('repeat_byweekno_options', $repeat_byweekno_options); +$tmpl->assign('repeat_bymonthday_options', $repeat_bymonthday_options); +$tmpl->assign('repeat_weekofmonth_options', $repeat_weekofmonth_options); + +$tmpl->assign('startdate', $start->format('d-m-Y')); +$tmpl->assign('starttime', $start->format('H:i')); +$tmpl->assign('enddate', $end->format('d-m-Y')); +$tmpl->assign('endtime', $end->format('H:i')); +$tmpl->assign('allday', $allday); +$tmpl->assign('repeat', 'doesnotrepeat'); +$tmpl->assign('repeat_month', 'monthday'); +$tmpl->assign('repeat_weekdays', array()); +$tmpl->assign('repeat_interval', 1); +$tmpl->assign('repeat_end', 'never'); +$tmpl->assign('repeat_count', '10'); +$tmpl->assign('repeat_weekofmonth', 'auto'); +$tmpl->assign('repeat_date', ''); +$tmpl->assign('repeat_year', 'bydate'); +$tmpl->printpage(); +?> diff --git a/apps/calendar/ajax/event/new.php b/apps/calendar/ajax/event/new.php new file mode 100644 index 00000000000..59fda79da73 --- /dev/null +++ b/apps/calendar/ajax/event/new.php @@ -0,0 +1,27 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); + +$l10n = new OC_L10N('calendar'); + +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +$errarr = OC_Calendar_Object::validateRequest($_POST); +if($errarr){ + //show validate errors + OC_JSON::error($errarr); + exit; +}else{ + $cal = $_POST['calendar']; + $vcalendar = OC_Calendar_Object::createVCalendarFromRequest($_POST); + $result = OC_Calendar_Object::add($cal, $vcalendar->serialize()); + OC_JSON::success(); +} +?> diff --git a/apps/calendar/ajax/event/resize.php b/apps/calendar/ajax/event/resize.php new file mode 100644 index 00000000000..aa2d420e77d --- /dev/null +++ b/apps/calendar/ajax/event/resize.php @@ -0,0 +1,32 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); + +$id = $_POST['id']; + +$vcalendar = OC_Calendar_App::getVCalendar($id); +$vevent = $vcalendar->VEVENT; + +$delta = new DateInterval('P0D'); +$delta->d = $_POST['dayDelta']; +$delta->i = $_POST['minuteDelta']; + +OC_Calendar_App::isNotModified($vevent, $_POST['lastmodified']); + +$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); +$end_type = $dtend->getDateType(); +$dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); +unset($vevent->DURATION); + +$vevent->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Element_DateTime::UTC); +$vevent->setDateTime('DTSTAMP', 'now', Sabre_VObject_Element_DateTime::UTC); + +$result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); +$lastmodified = $vevent->__get('LAST-MODIFIED')->getDateTime(); +OC_JSON::success(array('lastmodified'=>(int)$lastmodified->format('U'))); diff --git a/apps/calendar/ajax/import/dialog.php b/apps/calendar/ajax/import/dialog.php new file mode 100644 index 00000000000..2e002092150 --- /dev/null +++ b/apps/calendar/ajax/import/dialog.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_Util::checkAppEnabled('calendar'); +$l10n = new OC_L10N('calendar'); +$tmpl = new OC_Template('calendar', 'part.import'); +$tmpl->assign('path', $_POST['path']); +$tmpl->assign('filename', $_POST['filename']); +$tmpl->printpage(); +?> diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php new file mode 100644 index 00000000000..96d7af48341 --- /dev/null +++ b/apps/calendar/ajax/import/import.php @@ -0,0 +1,120 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +//check for calendar rights or create new one +ob_start(); +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_Util::checkAppEnabled('calendar'); +$nl = "\n"; +$progressfile = OC::$SERVERROOT . '/apps/calendar/import_tmp/' . md5(session_id()) . '.txt'; +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '10'); + fclose($progressfopen); +} +$file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); +if($_POST['method'] == 'new'){ + $id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname']); + OC_Calendar_Calendar::setCalendarActive($id, 1); +}else{ + $calendar = OC_Calendar_App::getCalendar($_POST['id']); + if($calendar['userid'] != OC_USER::getUser()){ + OC_JSON::error(); + exit(); + } + $id = $_POST['id']; +} +//analyse the calendar file +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '20'); + fclose($progressfopen); +} +$searchfor = array('VEVENT', 'VTODO', 'VJOURNAL'); +$parts = $searchfor; +$filearr = explode($nl, $file); +$inelement = false; +$parts = array(); +$i = 0; +foreach($filearr as $line){ + foreach($searchfor as $search){ + if(substr_count($line, $search) == 1){ + list($attr, $val) = explode(':', $line); + if($attr == 'BEGIN'){ + $parts[]['begin'] = $i; + $inelement = true; + } + if($attr == 'END'){ + $parts[count($parts) - 1]['end'] = $i; + $inelement = false; + } + } + } + $i++; +} +//import the calendar +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '40'); + fclose($progressfopen); +} +$start = ''; +for ($i = 0; $i < $parts[0]['begin']; $i++) { + if($i == 0){ + $start = $filearr[0]; + }else{ + $start .= $nl . $filearr[$i]; + } +} +$end = ''; +for($i = $parts[count($parts) - 1]['end'] + 1;$i <= count($filearr) - 1; $i++){ + if($i == $parts[count($parts) - 1]['end'] + 1){ + $end = $filearr[$parts[count($parts) - 1]['end'] + 1]; + }else{ + $end .= $nl . $filearr[$i]; + } +} +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '50'); + fclose($progressfopen); +} +$importready = array(); +foreach($parts as $part){ + for($i = $part['begin']; $i <= $part['end'];$i++){ + if($i == $part['begin']){ + $content = $filearr[$i]; + }else{ + $content .= $nl . $filearr[$i]; + } + } + $importready[] = $start . $nl . $content . $nl . $end; +} +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '70'); + fclose($progressfopen); +} +if(count($parts) == 1){ + OC_Calendar_Object::add($id, $file); +}else{ + foreach($importready as $import){ + OC_Calendar_Object::add($id, $import); + } +} +//done the import +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '100'); + fclose($progressfopen); +} +sleep(3); +if(is_writable('import_tmp/')){ + unlink($progressfile); +} +OC_JSON::success(); \ No newline at end of file diff --git a/apps/calendar/ajax/settings/gettimezonedetection.php b/apps/calendar/ajax/settings/gettimezonedetection.php new file mode 100644 index 00000000000..11255fe8ef3 --- /dev/null +++ b/apps/calendar/ajax/settings/gettimezonedetection.php @@ -0,0 +1,11 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +OC_JSON::success(array('detection' => OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezonedetection'))); \ No newline at end of file diff --git a/apps/calendar/ajax/settings/guesstimezone.php b/apps/calendar/ajax/settings/guesstimezone.php new file mode 100755 index 00000000000..cfa92e1aee8 --- /dev/null +++ b/apps/calendar/ajax/settings/guesstimezone.php @@ -0,0 +1,48 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +function make_array_out_of_xml ($xml){ + $returnarray = array(); + $xml = (array)$xml ; + foreach ($xml as $property => $value){ + $value = (array)$value; + if(!isset($value[0])){ + $returnarray[$property] = make_array_out_of_xml($value); + }else{ + $returnarray[$property] = trim($value[0]); + } + } + return $returnarray; +} +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +$l = new OC_L10N('calendar'); +$lat = $_GET['lat']; +$long = $_GET['long']; +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'position') == $lat . '-' . $long && OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone') != null){ + OC_JSON::success(); + exit; +} +OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'position', $lat . '-' . $long); +$geolocation = file_get_contents('http://ws.geonames.org/timezone?lat=' . $lat . '&lng=' . $long); +//Information are by Geonames (http://www.geonames.org) and licensed under the Creative Commons Attribution 3.0 License +$geoxml = simplexml_load_string($geolocation); +$geoarray = make_array_out_of_xml($geoxml); +if($geoarray['timezone']['timezoneId'] == OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone')){ + OC_JSON::success(); + exit; +} +if(in_array($geoarray['timezone']['timezoneId'], DateTimeZone::listIdentifiers())){ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $geoarray['timezone']['timezoneId']); + $message = array('message'=> $l->t('New Timezone:') . $geoarray['timezone']['timezoneId']); + OC_JSON::success($message); +}else{ + OC_JSON::error(); +} + +?> diff --git a/apps/calendar/ajax/settings/settimeformat.php b/apps/calendar/ajax/settings/settimeformat.php new file mode 100644 index 00000000000..8f65447065c --- /dev/null +++ b/apps/calendar/ajax/settings/settimeformat.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +if(isset($_POST["timeformat"])){ + OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'timeformat', $_POST["timeformat"]); + OC_JSON::success(); +}else{ + OC_JSON::error(); +} +?> + diff --git a/apps/calendar/ajax/settings/settimezone.php b/apps/calendar/ajax/settings/settimezone.php new file mode 100644 index 00000000000..c639753fe2f --- /dev/null +++ b/apps/calendar/ajax/settings/settimezone.php @@ -0,0 +1,27 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +// Init owncloud +require_once('../../../../lib/base.php'); + +$l=new OC_L10N('calendar'); + +// Check if we are a user +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +// Get data +if( isset( $_POST['timezone'] ) ){ + $timezone=$_POST['timezone']; + OC_Preferences::setValue( OC_User::getUser(), 'calendar', 'timezone', $timezone ); + OC_JSON::success(array('data' => array( 'message' => $l->t('Timezone changed') ))); +}else{ + OC_JSON::error(array('data' => array( 'message' => $l->t('Invalid request') ))); +} + +?> diff --git a/apps/calendar/ajax/settings/timeformat.php b/apps/calendar/ajax/settings/timeformat.php new file mode 100644 index 00000000000..e0dbe8d3cd7 --- /dev/null +++ b/apps/calendar/ajax/settings/timeformat.php @@ -0,0 +1,12 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +$timeformat = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'timeformat', "24"); +OC_JSON::encodedPrint(array("timeformat" => $timeformat)); +?> diff --git a/apps/calendar/ajax/settings/timezonedetection.php b/apps/calendar/ajax/settings/timezonedetection.php new file mode 100644 index 00000000000..f67bab901e7 --- /dev/null +++ b/apps/calendar/ajax/settings/timezonedetection.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +if($_POST['timezonedetection'] == 'on'){ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezonedetection', 'true'); +}else{ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezonedetection', 'false'); +} +OC_JSON::success(); + diff --git a/apps/calendar/ajax/share/changepermission.php b/apps/calendar/ajax/share/changepermission.php new file mode 100644 index 00000000000..d91f87b613f --- /dev/null +++ b/apps/calendar/ajax/share/changepermission.php @@ -0,0 +1,40 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +$id = strip_tags($_GET['id']); +$idtype = strip_tags($_GET['idtype']); +$permission = (int) strip_tags($_GET['permission']); +switch($idtype){ + case 'calendar': + case 'event': + break; + default: + OC_JSON::error(array('message'=>'unexspected parameter')); + exit; +} +$sharewith = $_GET['sharewith']; +$sharetype = strip_tags($_GET['sharetype']); +switch($sharetype){ + case 'user': + case 'group': + case 'public': + break; + default: + OC_JSON::error(array('message'=>'unexspected parameter')); + exit; +} +if($sharetype == 'user' && !OC_User::userExists($sharewith)){ + OC_JSON::error(array('message'=>'user not found')); + exit; +} +if($sharetype == 'group' && !OC_Group::groupExists($sharewith)){ + OC_JSON::error(array('message'=>'group not found')); + exit; +} +$success = OC_Calendar_Share::changepermission($sharewith, $sharetype, $id, $permission, (($idtype=='calendar') ? OC_Calendar_Share::CALENDAR : OC_Calendar_Share::Event)); +OC_JSON::success(); \ No newline at end of file diff --git a/apps/calendar/ajax/share/dropdown.php b/apps/calendar/ajax/share/dropdown.php new file mode 100644 index 00000000000..eb396d38fd9 --- /dev/null +++ b/apps/calendar/ajax/share/dropdown.php @@ -0,0 +1,18 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +$user = OC_USER::getUser(); +$calid = $_GET['calid']; +$calendar = OC_Calendar_Calendar::find($calid); +if($calendar['userid'] != $user){ + OC_JSON::error(); + exit; +} +$tmpl = new OC_Template('calendar', 'share.dropdown'); +$tmpl->assign('calid', $calid); +$tmpl->printPage(); \ No newline at end of file diff --git a/apps/calendar/ajax/share/share.php b/apps/calendar/ajax/share/share.php new file mode 100644 index 00000000000..d892727701a --- /dev/null +++ b/apps/calendar/ajax/share/share.php @@ -0,0 +1,51 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +$id = strip_tags($_GET['id']); +$idtype = strip_tags($_GET['idtype']); +switch($idtype){ + case 'calendar': + case 'event': + break; + default: + OC_JSON::error(array('message'=>'unexspected parameter')); + exit; +} +$sharewith = $_GET['sharewith']; +$sharetype = strip_tags($_GET['sharetype']); +switch($sharetype){ + case 'user': + case 'group': + case 'public': + break; + default: + OC_JSON::error(array('message'=>'unexspected parameter')); + exit; +} +if($sharetype == 'user' && !OC_User::userExists($sharewith)){ + OC_JSON::error(array('message'=>'user not found')); + exit; +} +if($sharetype == 'group' && !OC_Group::groupExists($sharewith)){ + OC_JSON::error(array('message'=>'group not found')); + exit; +} +if($sharetype == 'user' && OC_User::getUser() == $sharewith){ + OC_JSON::error(array('meesage'=>'you can not share with yourself')); +} +$success = OC_Calendar_Share::share(OC_User::getUser(), $sharewith, $sharetype, $id, (($idtype=='calendar') ? OC_Calendar_Share::CALENDAR : OC_Calendar_Share::Event)); +if($success){ + if($sharetype == 'public'){ + OC_JSON::success(array('message'=>$success)); + }else{ + OC_JSON::success(array('message'=>'shared')); + } +}else{ + OC_JSON::error(array('message'=>'can not share')); + exit; +} \ No newline at end of file diff --git a/apps/calendar/ajax/share/unshare.php b/apps/calendar/ajax/share/unshare.php new file mode 100644 index 00000000000..ec3150a89aa --- /dev/null +++ b/apps/calendar/ajax/share/unshare.php @@ -0,0 +1,44 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../../lib/base.php'); +$id = strip_tags($_GET['id']); +$idtype = strip_tags($_GET['idtype']); +switch($idtype){ + case 'calendar': + case 'event': + break; + default: + OC_JSON::error(array('message'=>'unexspected parameter')); + exit; +} +$sharewith = $_GET['sharewith']; +$sharetype = strip_tags($_GET['sharetype']); +switch($sharetype){ + case 'user': + case 'group': + case 'public': + break; + default: + OC_JSON::error(array('message'=>'unexspected parameter')); + exit; +} +if($sharetype == 'user' && !OC_User::userExists($sharewith)){ + OC_JSON::error(array('message'=>'user not found')); + exit; +} +if($sharetype == 'group' && !OC_Group::groupExists($sharewith)){ + OC_JSON::error(array('message'=>'group not found')); + exit; +} +$success = OC_Calendar_Share::unshare(OC_User::getUser(), $sharewith, $sharetype, $id, (($idtype=='calendar') ? OC_Calendar_Share::CALENDAR : OC_Calendar_Share::Event)); +if($success){ + OC_JSON::success(); +}else{ + OC_JSON::error(array('message'=>'can not unshare')); + exit; +} \ No newline at end of file