diff options
Diffstat (limited to 'apps/journal/ajax')
-rw-r--r-- | apps/journal/ajax/categories/categoriesfor.php | 28 | ||||
-rw-r--r-- | apps/journal/ajax/categories/delete.php | 54 | ||||
-rw-r--r-- | apps/journal/ajax/categories/list.php | 17 | ||||
-rw-r--r-- | apps/journal/ajax/categories/rescan.php | 42 | ||||
-rw-r--r-- | apps/journal/ajax/delete.php | 37 | ||||
-rw-r--r-- | apps/journal/ajax/entries.php | 36 | ||||
-rw-r--r-- | apps/journal/ajax/saveproperty.php | 138 | ||||
-rw-r--r-- | apps/journal/ajax/setdefaultcalendar.php | 36 | ||||
-rw-r--r-- | apps/journal/ajax/util.php | 40 |
9 files changed, 428 insertions, 0 deletions
diff --git a/apps/journal/ajax/categories/categoriesfor.php b/apps/journal/ajax/categories/categoriesfor.php new file mode 100644 index 00000000000..846af300de8 --- /dev/null +++ b/apps/journal/ajax/categories/categoriesfor.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('contacts'); + +$id = isset($_GET['id'])?$_GET['id']:null; +if(is_null($id)) { + OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('No ID provided')))); + exit(); +} +$vcard = OC_Contacts_App::getContactVCard( $id ); +foreach($vcard->children as $property){ + //OCP\Util::writeLog('contacts','ajax/categories/checksumfor.php: '.$property->name, OCP\Util::DEBUG); + if($property->name == 'CATEGORIES') { + $checksum = md5($property->serialize()); + OCP\JSON::success(array('data' => array('value'=>$property->value, 'checksum'=>$checksum))); + exit(); + } +} +OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error setting checksum.')))); +?> diff --git a/apps/journal/ajax/categories/delete.php b/apps/journal/ajax/categories/delete.php new file mode 100644 index 00000000000..e68d608c5da --- /dev/null +++ b/apps/journal/ajax/categories/delete.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('contacts'); +OCP\JSON::callCheck(); + +foreach ($_POST as $key=>$element) { + debug('_POST: '.$key.'=>'.print_r($element, true)); +} + +require_once('../util.php'); + +$categories = isset($_POST['categories'])?$_POST['categories']:null; + +if(is_null($categories)) { + bailOut(OC_Contacts_App::$l10n->t('No categories selected for deletion.')); +} + +debug(print_r($categories, true)); + +$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser()); +if(count($addressbooks) == 0) { + bailOut(OC_Contacts_App::$l10n->t('No address books found.')); +} +$addressbookids = array(); +foreach($addressbooks as $addressbook) { + $addressbookids[] = $addressbook['id']; +} +$contacts = OC_Contacts_VCard::all($addressbookids); +if(count($contacts) == 0) { + bailOut(OC_Contacts_App::$l10n->t('No contacts found.')); +} + +$cards = array(); +foreach($contacts as $contact) { + $cards[] = array($contact['id'], $contact['carddata']); +} + +debug('Before delete: '.print_r($categories, true)); + +$catman = new OC_VCategories('contacts'); +$catman->delete($categories, $cards); +debug('After delete: '.print_r($catman->categories(), true)); +OC_Contacts_VCard::updateDataByID($cards); +OCP\JSON::success(array('data' => array('categories'=>$catman->categories()))); + +?> diff --git a/apps/journal/ajax/categories/list.php b/apps/journal/ajax/categories/list.php new file mode 100644 index 00000000000..ac8976fa0ec --- /dev/null +++ b/apps/journal/ajax/categories/list.php @@ -0,0 +1,17 @@ +<?php +/** + * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('journal'); + +$categories = OC_Journal_App::getCategories(); + +OCP\JSON::success(array('data' => array('categories'=>$categories))); + +?> diff --git a/apps/journal/ajax/categories/rescan.php b/apps/journal/ajax/categories/rescan.php new file mode 100644 index 00000000000..d746f9179fe --- /dev/null +++ b/apps/journal/ajax/categories/rescan.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('journal'); + +foreach ($_POST as $key=>$element) { + debug('_POST: '.$key.'=>'.print_r($element, true)); +} + +function bailOut($msg) { + OCP\JSON::error(array('data' => array('message' => $msg))); + OCP\Util::writeLog('journal','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG); + exit(); +} +function debug($msg) { + OCP\Util::writeLog('journal','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG); +} + +$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); +if(count($calendars) == 0) { + bailOut(OC_Calendar_App::$l10n->t('No calendars found.')); +} +$events = array(); +foreach($calendars as $calendar) { + $calendar_events = OC_Calendar_Object::all($calendar['id']); + $events = $events + $calendar_events; +} +if(count($events) == 0) { + bailOut(OC_Calendar_App::$l10n->t('No events found.')); +} + +OC_Calendar_App::scanCategories($events); +$categories = OC_Calendar_App::getCategoryOptions(); + +OCP\JSON::success(array('data' => array('categories'=>$categories)));
\ No newline at end of file diff --git a/apps/journal/ajax/delete.php b/apps/journal/ajax/delete.php new file mode 100644 index 00000000000..4013e4440a6 --- /dev/null +++ b/apps/journal/ajax/delete.php @@ -0,0 +1,37 @@ +<?php +/** + * ownCloud - Journal + * + * @copyright 2012 Thomas Tanghus <thomas@tanghus.net> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('journal'); +OCP\JSON::callCheck(); + +$id = isset($_POST['id'])?$_POST['id']:null; +if(is_null($id)) { + OCP\JSON::error(array('data'=>array('message' => OC_Journal_App::$l10n->t('ID is not set!')))); + exit; +} +$journal = OC_Calendar_App::getEventObject($id); +if($journal) { + OC_Calendar_Object::delete($id); + OCP\JSON::success(array('data' => array( 'id' => $id ))); +} else { + OCP\JSON::error(array('data' => array('id' => $id, 'message' => OC_Journal_App::$l10n->t('Could not find journal entry: '.$id)))); +}
\ No newline at end of file diff --git a/apps/journal/ajax/entries.php b/apps/journal/ajax/entries.php new file mode 100644 index 00000000000..03f2366d33b --- /dev/null +++ b/apps/journal/ajax/entries.php @@ -0,0 +1,36 @@ +<?php +/** + * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +// Init owncloud +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('journal'); + +$calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser(), true); +$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get()); +session_write_close(); +$journals = array(); +foreach( $calendars as $calendar ){ + $calendar_journals = OC_Calendar_Object::all($calendar['id']); + foreach( $calendar_journals as $journal ) { + if($journal['objecttype']!='VJOURNAL') { + continue; + } + if(is_null($journal['summary'])) { + continue; + } + $object = OC_VObject::parse($journal['calendardata']); + $vjournalobj = $object->VJOURNAL; + try { + $journals[] = OC_Journal_App::arrayForJSON($journal['id'], $vjournalobj, $user_timezone); + } catch(Exception $e) { + OCP\Util::writeLog('journal', 'ajax/getentries.php. id: '.$journal['id'].' '.$e->getMessage(), OCP\Util::ERROR); + } + } +} + +OCP\JSON::success(array('data' => array('entries' => $journals))); diff --git a/apps/journal/ajax/saveproperty.php b/apps/journal/ajax/saveproperty.php new file mode 100644 index 00000000000..016f922a9af --- /dev/null +++ b/apps/journal/ajax/saveproperty.php @@ -0,0 +1,138 @@ +<?php +/** + * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +$htmlwrap = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head></head><body>%s</body></html>'; +$divwrap = '<div>%s</div>'; +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('journal'); +OCP\JSON::callCheck(); + +$id = isset($_POST['id'])?$_POST['id']:null; +$property = isset($_POST['type'])?$_POST['type']:null; +$value = isset($_POST['value'])?$_POST['value']:null; +if(is_null($id)) { + OCP\JSON::error(array('data'=>array('message' => OC_Journal_App::$l10n->t('ID is not set!')))); + exit; +} +if(is_null($property)) { + OCP\JSON::error(array('data'=>array('message' => OC_Journal_App::$l10n->t('Property name is not set!')))); + exit; +} +if(is_null($value)) { + OCP\JSON::error(array('data'=>array('message' => OC_Journal_App::$l10n->t('Property value is not set!')))); + exit; +} + +foreach($_POST as $key => $val) { + error_log($key.': '.print_r($val, true)); +} + +$parameters = isset($_POST['parameters'])? $_POST['parameters']:null; +if($id == 'new') { + $vcalendar = OC_Journal_App::createVCalendar(); +} else { + $vcalendar = OC_Calendar_App::getVCalendar( $id ); +} +error_log('saveproperty: '.$property.': '.print_r($value, true)); +$vjournal = $vcalendar->VJOURNAL; +switch($property) { + case 'DESCRIPTION': + $hasgenericformat = false; + $haskdeformat = false; + if(!$vjournal->DESCRIPTION) { + $vjournal->setString('DESCRIPTION', $value); + } + if($parameters && isset($parameters['FORMAT']) && strtoupper($parameters['FORMAT']) == 'HTML') { + if($value[0] != '<') { // Fugly hack coming up + $value = sprintf($divwrap, $value); + } + $vjournal->DESCRIPTION->value = sprintf($htmlwrap, $value); + foreach($vjournal->DESCRIPTION->parameters as $parameter){ + if(stripos($parameter->name, 'X-KDE-TEXTFORMAT') !== false && stripos($parameter->value, 'HTML') !== false){ + $haskdeformat = true; + } + if(stripos($parameter->name, 'X-TEXTFORMAT') !== false && stripos($parameter->value, 'HTML') !== false){ + $hasgenericformat = true; + } + } + if(!$haskdeformat) { + try { + $vjournal->DESCRIPTION->add(new Sabre_VObject_Parameter('X-KDE-TEXTFORMAT', 'HTML')); + } catch (Exception $e) { + OCP\JSON::error(array('data'=>array('message'=>OC_Journal_App::$l10n->t('Error setting rich text format parameter: '.$e->getMessage())))); + exit(); + } + } + if(!$hasgenericformat) { // Add a more generic text formatting parameter in case other clients would use VJOURNAL this way. + try { + $vjournal->DESCRIPTION->add(new Sabre_VObject_Parameter('X-TEXTFORMAT', 'HTML')); + } catch (Exception $e) { + OCP\JSON::error(array('data'=>array('message'=>OC_Journal_App::$l10n->t('Error setting rich text format parameter: '.$e->getMessage())))); + exit(); + } + } + } else { + $vjournal->DESCRIPTION->value = $value; + } + break; + case 'DTSTART': + try { + $date_only = isset($_POST['date_only']) && (bool)$_POST['date_only'] == true?true:false; + $timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get()); + $timezone = new DateTimeZone($timezone); + //$dtstart = new DateTime($value, $timezone); + $dtstart = new DateTime('@'.$value); + $dtstart->setTimezone($timezone); + $type = Sabre_VObject_Property_DateTime::LOCALTZ; + if ($date_only) { + $type = Sabre_VObject_Property_DateTime::DATE; + } + $vjournal->setDateTime('DTSTART', $value, $type); + } catch (Exception $e) { + OCP\JSON::error(array('data'=>array('message'=>OC_Journal_App::$l10n->t('Invalid date/time: '.$e->getMessage())))); + exit(); + } + break; + case 'ORGANIZER': + case 'SUMMARY': + case 'CATEGORIES': + $vobject = $vjournal->getVObject(); + if(isset($vobject[$property])) { + $vobject[$property]['value'] = $value; + } else { + $vjournal->setString($property, $value); + } + break; + $vjournal->setString($property, $value); + break; + default: + OCP\JSON::error(array('data'=>array('message'=>'Unknown type: '.$property))); + exit(); +} + +$vjournal->setDateTime('LAST-MODIFIED', 'now', Sabre_VObject_Property_DateTime::UTC); +$vjournal->setDateTime('DTSTAMP', 'now', Sabre_VObject_Property_DateTime::UTC); + +if($id == 'new') { + // TODO: Have a calendar ID parameter in request. + $cid = OCP\Config::getUserValue(OCP\User::getUser(), 'journal', 'default_calendar', null); + // Check that the calendar exists and that it's ours. + $cid = OC_Calendar_App::getCalendar($cid, true); + if(!$cid) { + OCP\Util::writeLog('journal', 'The default calendar '.$cid.' is either not owned by '.OCP\User::getUser().' or doesn\'t exist.', OCP\Util::WARN); + $calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser(), true); + $first_calendar = reset($calendars); + $cid = $first_calendar['id']; + } + $id = OC_Calendar_Object::add($cid, $vcalendar->serialize()); +} else { + OC_Calendar_Object::edit($id, $vcalendar->serialize()); +} +$user_timezone = OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone', date_default_timezone_get()); +$journal_info = OC_Journal_App::arrayForJSON($id, $vjournal, $user_timezone); +OCP\JSON::success(array('data' => $journal_info)); diff --git a/apps/journal/ajax/setdefaultcalendar.php b/apps/journal/ajax/setdefaultcalendar.php new file mode 100644 index 00000000000..a82c1e3cf1f --- /dev/null +++ b/apps/journal/ajax/setdefaultcalendar.php @@ -0,0 +1,36 @@ +<?php +/** + * ownCloud - Addressbook + * + * @copyright 2012 Thomas Tanghus <thomas@tanghus.net> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('journal'); +OCP\JSON::callCheck(); + +$id = isset($_POST['id'])?$_POST['id']:null; +if(is_null($id)) { + OCP\JSON::error(array('data'=>array('message' => OC_Journal_App::$l10n->t('ID is not set!')))); + exit; +} +if(OCP\Config::setUserValue(OCP\USER::getUser(), 'journal', 'default_calendar', $id)) { + OC_Calendar_Object::delete($id); + OCP\JSON::success(array('data' => array( 'id' => $id ))); +} else { + OCP\JSON::error(array('data' => array('id' => $id, 'message' => OC_Journal_App::$l10n->t('Could not set default calendar: '.$id)))); +}
\ No newline at end of file diff --git a/apps/journal/ajax/util.php b/apps/journal/ajax/util.php new file mode 100644 index 00000000000..b690b2e1948 --- /dev/null +++ b/apps/journal/ajax/util.php @@ -0,0 +1,40 @@ +<?php +/** + * ownCloud - Addressbook + * + * @author Thomas Tanghus + * @copyright 2012 Thomas Tanghus <thomas@tanghus.net> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +function bailOut($msg, $tracelevel=1, $debuglevel=OCP\Util::ERROR) { + OCP\JSON::error(array('data' => array('message' => $msg))); + debug($msg, $tracelevel, $debuglevel); + exit(); +} + +function debug($msg, $tracelevel=0, $debuglevel=OCP\Util::DEBUG) { + if(PHP_VERSION >= "5.4") { + $call = debug_backtrace(false, $tracelevel+1); + } else { + $call = debug_backtrace(false); + } + error_log('trace: '.print_r($call, true)); + $call = $call[$tracelevel]; + if($debuglevel !== false) { + OCP\Util::writeLog('journal', $call['file'].'. Line: '.$call['line'].': '.$msg, $debuglevel); + } +} |