2012-02-20 14:26:22 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Georg Ehrke <ownclouddev@georgswebsite.de>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
2012-04-17 21:31:29 +04:00
|
|
|
|
2012-06-09 16:40:15 +04:00
|
|
|
$id = strip_tags($_POST['id']);
|
|
|
|
$idtype = strip_tags($_POST['idtype']);
|
2012-02-20 14:26:22 +04:00
|
|
|
switch($idtype){
|
|
|
|
case 'calendar':
|
|
|
|
case 'event':
|
|
|
|
break;
|
|
|
|
default:
|
2012-06-06 13:46:11 +04:00
|
|
|
OCP\JSON::error(array('message'=>'unexpected parameter'));
|
2012-02-20 14:26:22 +04:00
|
|
|
exit;
|
|
|
|
}
|
2012-04-14 01:16:28 +04:00
|
|
|
if($idtype == 'calendar' && !OC_Calendar_App::getCalendar($id)){
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::error(array('message'=>'permission denied'));
|
2012-04-14 01:16:28 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if($idtype == 'event' && !OC_Calendar_App::getEventObject($id)){
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::error(array('message'=>'permission denied'));
|
2012-04-14 01:16:28 +04:00
|
|
|
exit;
|
|
|
|
}
|
2012-06-09 16:40:15 +04:00
|
|
|
$sharewith = $_POST['sharewith'];
|
|
|
|
$sharetype = strip_tags($_POST['sharetype']);
|
2012-02-20 14:26:22 +04:00
|
|
|
switch($sharetype){
|
|
|
|
case 'user':
|
|
|
|
case 'group':
|
|
|
|
case 'public':
|
|
|
|
break;
|
|
|
|
default:
|
2012-06-06 13:46:11 +04:00
|
|
|
OCP\JSON::error(array('message'=>'unexpected parameter'));
|
2012-02-20 14:26:22 +04:00
|
|
|
exit;
|
|
|
|
}
|
2012-05-01 21:04:20 +04:00
|
|
|
if($sharetype == 'user' && !OCP\User::userExists($sharewith)){
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::error(array('message'=>'user not found'));
|
2012-02-20 14:26:22 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if($sharetype == 'group' && !OC_Group::groupExists($sharewith)){
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::error(array('message'=>'group not found'));
|
2012-02-20 14:26:22 +04:00
|
|
|
exit;
|
|
|
|
}
|
2012-05-01 20:50:31 +04:00
|
|
|
if($sharetype == 'user' && OCP\USER::getUser() == $sharewith){
|
2012-06-06 13:46:11 +04:00
|
|
|
OCP\JSON::error(array('message'=>'you can not share with yourself'));
|
2012-02-20 14:26:22 +04:00
|
|
|
}
|
2012-05-01 20:50:31 +04:00
|
|
|
$success = OC_Calendar_Share::share(OCP\USER::getUser(), $sharewith, $sharetype, $id, (($idtype=='calendar') ? OC_Calendar_Share::CALENDAR : OC_Calendar_Share::EVENT));
|
2012-02-20 14:26:22 +04:00
|
|
|
if($success){
|
|
|
|
if($sharetype == 'public'){
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::success(array('message'=>$success));
|
2012-02-20 14:26:22 +04:00
|
|
|
}else{
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::success(array('message'=>'shared'));
|
2012-02-20 14:26:22 +04:00
|
|
|
}
|
|
|
|
}else{
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::error(array('message'=>'can not share'));
|
2012-02-20 14:26:22 +04:00
|
|
|
exit;
|
|
|
|
}
|