From: Georg Ehrke Date: Sat, 21 Jul 2012 15:37:10 +0000 (+0200) Subject: Merge branch 'master' into calendar_import X-Git-Tag: v4.5.0beta1~74^2~370 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f9d33888544ac8abdaf287cc8d558d057de01720;p=nextcloud-server.git Merge branch 'master' into calendar_import --- f9d33888544ac8abdaf287cc8d558d057de01720 diff --cc apps/calendar/ajax/import/import.php index cbb4b550569,38008af4a9d..b1dfc464d00 --- a/apps/calendar/ajax/import/import.php +++ b/apps/calendar/ajax/import/import.php @@@ -5,41 -5,34 +5,42 @@@ * later. * See the COPYING-README file. */ -//check for calendar rights or create new one -ob_start(); - OCP\JSON::checkLoggedIn(); OCP\App::checkAppEnabled('calendar'); + OCP\JSON::callCheck(); session_write_close(); - -$nl="\r\n"; -$comps = array('VEVENT'=>true, 'VTODO'=>true, 'VJOURNAL'=>true); - -global $progresskey; -$progresskey = 'calendar.import-' . $_POST['progresskey']; - -if (isset($_POST['progress']) && $_POST['progress']) { - echo OC_Cache::get($progresskey); - die; +if (isset($_POST['progresskey']) && isset($_POST['getprogress'])) { + echo OCP\JSON::success(array('percent'=>OC_Cache::get($_POST['progresskey']))); + exit; } - -function writeProgress($pct) { - global $progresskey; - OC_Cache::set($progresskey, $pct, 300); -} -writeProgress('10'); $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); +if(!$file){ + OCP\JSON::error(array('error'=>'404')); +} +$import = new OC_Calendar_Import($file); +$import->setUserID(OCP\User::getUser()); +$import->setTimeZone(OC_Calendar_App::$tz); +$import->enableProgressCache(); +$import->setProgresskey($_POST['progresskey']); +if(!$import->isValid()){ + OCP\JSON::error(array('error'=>'notvalid')); + exit; +} +$newcal = false; if($_POST['method'] == 'new'){ - $id = OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), $_POST['calname']); - OC_Calendar_Calendar::setCalendarActive($id, 1); + $calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser()); + foreach($calendars as $calendar){ + if($calendar['displayname'] == $_POST['calname']){ + $id = $calendar['id']; + $newcal = false; + break; + } + $newcal = true; + } + if($newcal){ + $id = OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), strip_tags($_POST['calname']),'VEVENT,VTODO,VJOURNAL',null,0,strip_tags($_POST['calcolor'])); + OC_Calendar_Calendar::setCalendarActive($id, 1); + } }else{ $calendar = OC_Calendar_App::getCalendar($_POST['id']); if($calendar['userid'] != OCP\USER::getUser()){ @@@ -147,4 -120,4 +148,4 @@@ foreach($uids as $uid) writeProgress('100'); sleep(3); OC_Cache::remove($progresskey); - OCP\JSON::success();*/ -OCP\JSON::success(); ++OCP\JSON::success();*/ diff --cc apps/calendar/appinfo/app.php index 09b18ed397b,c8fccc326c3..4fdba291262 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@@ -9,8 -9,8 +9,9 @@@ OC::$CLASSPATH['OC_Calendar_Repeat'] = OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php'; OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php'; OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php'; +OC::$CLASSPATH['OC_Calendar_Import'] = 'apps/calendar/lib/import.php'; //General Hooks + OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'createUser'); OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); //Repeating Events Hooks OCP\Util::connectHook('OC_Calendar', 'addEvent', 'OC_Calendar_Repeat', 'generate');