summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax/contact
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-08-03 04:20:14 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-08-03 21:32:27 +0200
commitbef63527cef4c642e141793eea1a1e9eab39cd30 (patch)
treedf5164e24a678ad2218a673dc521fa6958bcc8f9 /apps/contacts/ajax/contact
parent3610975bc10f93caa5f6fde517e5988756246cf9 (diff)
downloadnextcloud-server-bef63527cef4c642e141793eea1a1e9eab39cd30.tar.gz
nextcloud-server-bef63527cef4c642e141793eea1a1e9eab39cd30.zip
Reorganize ajax scripts.
Diffstat (limited to 'apps/contacts/ajax/contact')
-rw-r--r--apps/contacts/ajax/contact/add.php52
-rw-r--r--apps/contacts/ajax/contact/addproperty.php147
-rw-r--r--apps/contacts/ajax/contact/delete.php35
-rw-r--r--apps/contacts/ajax/contact/deleteproperty.php46
-rw-r--r--apps/contacts/ajax/contact/details.php57
-rw-r--r--apps/contacts/ajax/contact/list.php89
-rw-r--r--apps/contacts/ajax/contact/move.php41
-rw-r--r--apps/contacts/ajax/contact/saveproperty.php150
8 files changed, 617 insertions, 0 deletions
diff --git a/apps/contacts/ajax/contact/add.php b/apps/contacts/ajax/contact/add.php
new file mode 100644
index 00000000000..6aaf5a9df35
--- /dev/null
+++ b/apps/contacts/ajax/contact/add.php
@@ -0,0 +1,52 @@
+<?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/>.
+ *
+ */
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+
+$aid = isset($_POST['aid'])?$_POST['aid']:null;
+if(!$aid) {
+ $aid = min(OC_Contacts_Addressbook::activeIds()); // first active addressbook.
+}
+OC_Contacts_App::getAddressbook( $aid ); // is owner access check
+
+$isnew = isset($_POST['isnew'])?$_POST['isnew']:false;
+$fn = trim($_POST['fn']);
+$n = trim($_POST['n']);
+
+$vcard = new OC_VObject('VCARD');
+$vcard->setUID();
+$vcard->setString('FN', $fn);
+$vcard->setString('N', $n);
+
+$id = OC_Contacts_VCard::add($aid, $vcard, null, $isnew);
+if(!$id) {
+ OCP\JSON::error(array(
+ 'data' => array(
+ 'message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.'))));
+ OCP\Util::writeLog('contacts', 'ajax/addcontact.php: Recieved non-positive ID on adding card: '.$id, OCP\Util::ERROR);
+ exit();
+}
+
+OCP\JSON::success(array('data' => array( 'id' => $id, 'aid' => $aid )));
diff --git a/apps/contacts/ajax/contact/addproperty.php b/apps/contacts/ajax/contact/addproperty.php
new file mode 100644
index 00000000000..58b857547fb
--- /dev/null
+++ b/apps/contacts/ajax/contact/addproperty.php
@@ -0,0 +1,147 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @author Jakob Sack
+ * @copyright 2011 Jakob Sack mail@jakobsack.de
+ *
+ * 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/>.
+ *
+ */
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+
+require_once 'loghandler.php';
+
+$id = isset($_POST['id'])?$_POST['id']:null;
+$name = isset($_POST['name'])?$_POST['name']:null;
+$value = isset($_POST['value'])?$_POST['value']:null;
+$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
+
+$vcard = OC_Contacts_App::getContactVCard($id);
+$l10n = OC_Contacts_App::$l10n;
+
+if(!$name) {
+ bailOut($l10n->t('element name is not set.'));
+}
+if(!$id) {
+ bailOut($l10n->t('id is not set.'));
+}
+
+if(!$vcard) {
+ bailOut($l10n->t('Could not parse contact: ').$id);
+}
+
+if(!is_array($value)) {
+ $value = trim($value);
+ if(!$value
+ && in_array(
+ $name,
+ array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))
+ ) {
+ bailOut($l10n->t('Cannot add empty property.'));
+ }
+} elseif($name === 'ADR') { // only add if non-empty elements.
+ $empty = true;
+ foreach($value as $part) {
+ if(trim($part) != '') {
+ $empty = false;
+ break;
+ }
+ }
+ if($empty) {
+ bailOut($l10n->t('At least one of the address fields has to be filled out.'));
+ }
+}
+
+// Prevent setting a duplicate entry
+$current = $vcard->select($name);
+foreach($current as $item) {
+ $tmpvalue = (is_array($value)?implode(';', $value):$value);
+ if($tmpvalue == $item->value) {
+ bailOut($l10n->t('Trying to add duplicate property: '.$name.': '.$tmpvalue));
+ }
+}
+
+if(is_array($value)) {
+ // NOTE: Important, otherwise the compound value will
+ // be set in the order the fields appear in the form!
+ ksort($value);
+ $value = array_map('strip_tags', $value);
+} else {
+ $value = strip_tags($value);
+}
+
+/* preprocessing value */
+switch($name) {
+ case 'BDAY':
+ $date = New DateTime($value);
+ $value = $date->format(DateTime::ATOM);
+ case 'FN':
+ if(!$value) {
+ // create a method thats returns an alternative for FN.
+ //$value = getOtherValue();
+ }
+ case 'N':
+ case 'ORG':
+ case 'NOTE':
+ $value = str_replace('\n', ' \\n', $value);
+ break;
+ case 'NICKNAME':
+ // TODO: Escape commas and semicolons.
+ break;
+ case 'EMAIL':
+ $value = strtolower($value);
+ break;
+ case 'TEL':
+ case 'ADR': // should I delete the property if empty or throw an error?
+ break;
+}
+
+switch($name) {
+ case 'NOTE':
+ $vcard->setString('NOTE', $value);
+ break;
+ default:
+ $property = $vcard->addProperty($name, $value); //, $parameters);
+ break;
+}
+
+$line = count($vcard->children) - 1;
+
+// Apparently Sabre_VObject_Parameter doesn't do well with
+// multiple values or I don't know how to do it. Tanghus.
+foreach ($parameters as $key=>$element) {
+ if(is_array($element) && strtoupper($key) == 'TYPE') {
+ // NOTE: Maybe this doesn't only apply for TYPE?
+ // And it probably shouldn't be done here anyways :-/
+ foreach($element as $e) {
+ if($e != '' && !is_null($e)) {
+ $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $e);
+ }
+ }
+ } else {
+ $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $element);
+ }
+}
+$checksum = md5($vcard->children[$line]->serialize());
+
+if(!OC_Contacts_VCard::edit($id, $vcard)) {
+ bailOut($l10n->t('Error adding contact property: '.$name));
+}
+
+OCP\JSON::success(array('data' => array( 'checksum' => $checksum )));
diff --git a/apps/contacts/ajax/contact/delete.php b/apps/contacts/ajax/contact/delete.php
new file mode 100644
index 00000000000..9777046fc82
--- /dev/null
+++ b/apps/contacts/ajax/contact/delete.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @author Jakob Sack
+ * @copyright 2011 Jakob Sack mail@jakobsack.de
+ *
+ * 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/>.
+ *
+ */
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+require_once 'loghandler.php';
+
+$id = isset($_POST['id'])?$_POST['id']:null;
+if(!$id) {
+ bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
+}
+$card = OC_Contacts_App::getContactObject( $id );
+
+OC_Contacts_VCard::delete($id);
+OCP\JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/contact/deleteproperty.php b/apps/contacts/ajax/contact/deleteproperty.php
new file mode 100644
index 00000000000..205df8bc184
--- /dev/null
+++ b/apps/contacts/ajax/contact/deleteproperty.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @author Jakob Sack
+ * @copyright 2011 Jakob Sack mail@jakobsack.de
+ *
+ * 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/>.
+ *
+ */
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+require_once 'loghandler.php';
+
+$id = $_POST['id'];
+$checksum = $_POST['checksum'];
+$l10n = OC_Contacts_App::$l10n;
+
+$vcard = OC_Contacts_App::getContactVCard( $id );
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
+if(is_null($line)) {
+ bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.'));
+ exit();
+}
+
+unset($vcard->children[$line]);
+
+if(!OC_Contacts_VCard::edit($id, $vcard)) {
+ bailOut($l10n->t('Error deleting contact property.'));
+}
+
+OCP\JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/contact/details.php b/apps/contacts/ajax/contact/details.php
new file mode 100644
index 00000000000..27d7611ade9
--- /dev/null
+++ b/apps/contacts/ajax/contact/details.php
@@ -0,0 +1,57 @@
+<?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/>.
+ *
+ */
+
+require_once 'loghandler.php';
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+
+$id = isset($_GET['id'])?$_GET['id']:null;
+if(is_null($id)) {
+ bailOut(OC_Contacts_App::$l10n->t('Missing ID'));
+}
+$card = OC_Contacts_VCard::find($id);
+$vcard = OC_Contacts_App::getContactVCard( $id );
+if(is_null($vcard)) {
+ bailOut(OC_Contacts_App::$l10n->t('Error parsing VCard for ID: "'.$id.'"'));
+}
+$details = OC_Contacts_VCard::structureContact($vcard);
+
+// Make up for not supporting the 'N' field in earlier version.
+if(!isset($details['N'])) {
+ $details['N'] = array();
+ $details['N'][0] = array($details['FN'][0]['value'],'','','','');
+}
+
+// Don't wanna transfer the photo in a json string.
+if(isset($details['PHOTO'])) {
+ $details['PHOTO'] = true;
+ //unset($details['PHOTO']);
+} else {
+ $details['PHOTO'] = false;
+}
+$details['id'] = $id;
+$details['displayname'] = $card['fullname'];
+$details['addressbookid'] = $card['addressbookid'];
+OC_Contacts_App::setLastModifiedHeader($vcard);
+OCP\JSON::success(array('data' => $details));
diff --git a/apps/contacts/ajax/contact/list.php b/apps/contacts/ajax/contact/list.php
new file mode 100644
index 00000000000..c5eca292f15
--- /dev/null
+++ b/apps/contacts/ajax/contact/list.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+function cmp($a, $b)
+{
+ if ($a['displayname'] == $b['displayname']) {
+ return 0;
+ }
+ return ($a['displayname'] < $b['displayname']) ? -1 : 1;
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+
+$start = isset($_GET['startat'])?$_GET['startat']:0;
+$aid = isset($_GET['aid'])?$_GET['aid']:null;
+
+if(is_null($aid)) {
+ // Called initially to get the active addressbooks.
+ $active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
+} else {
+ // called each time more contacts has to be shown.
+ $active_addressbooks = array(OC_Contacts_Addressbook::find($aid));
+}
+
+
+session_write_close();
+
+// create the addressbook associate array
+$contacts_addressbook = array();
+$ids = array();
+foreach($active_addressbooks as $addressbook) {
+ $ids[] = $addressbook['id'];
+ if(!isset($contacts_addressbook[$addressbook['id']])) {
+ $contacts_addressbook[$addressbook['id']]
+ = array('contacts' => array('type' => 'book',));
+ $contacts_addressbook[$addressbook['id']]['displayname']
+ = $addressbook['displayname'];
+ }
+}
+
+$contacts_alphabet = array();
+
+// get next 50 for each addressbook.
+foreach($ids as $id) {
+ if($id) {
+ $contacts_alphabet = array_merge(
+ $contacts_alphabet,
+ OC_Contacts_VCard::all($id, $start, 50)
+ );
+ }
+}
+// Our new array for the contacts sorted by addressbook
+if($contacts_alphabet) {
+ foreach($contacts_alphabet as $contact) {
+ // This should never execute.
+ if(!isset($contacts_addressbook[$contact['addressbookid']])) {
+ $contacts_addressbook[$contact['addressbookid']] = array(
+ 'contacts' => array('type' => 'book',)
+ );
+ }
+ $display = trim($contact['fullname']);
+ if(!$display) {
+ $vcard = OC_Contacts_App::getContactVCard($contact['id']);
+ if(!is_null($vcard)) {
+ $struct = OC_Contacts_VCard::structureContact($vcard);
+ $display = isset($struct['EMAIL'][0])
+ ? $struct['EMAIL'][0]['value']
+ : '[UNKNOWN]';
+ }
+ }
+ $contacts_addressbook[$contact['addressbookid']]['contacts'][] = array(
+ 'type' => 'contact',
+ 'id' => $contact['id'],
+ 'addressbookid' => $contact['addressbookid'],
+ 'displayname' => htmlspecialchars($display)
+ );
+ }
+}
+unset($contacts_alphabet);
+uasort($contacts_addressbook, 'cmp');
+
+OCP\JSON::success(array('data' => array('entries' => $contacts_addressbook)));
+
diff --git a/apps/contacts/ajax/contact/move.php b/apps/contacts/ajax/contact/move.php
new file mode 100644
index 00000000000..a3336c3cb6c
--- /dev/null
+++ b/apps/contacts/ajax/contact/move.php
@@ -0,0 +1,41 @@
+<?php
+/**
+* @author Victor Dubiniuk
+* Copyright (c) 2012 Victor Dubiniuk <victor.dubiniuk@gmail.com>
+* 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();
+
+$ids = $_POST['ids'];
+$aid = intval($_POST['aid']);
+OC_Contacts_App::getAddressbook($aid);
+
+if(!is_array($ids)) {
+ $ids = array($ids,);
+}
+$goodids = array();
+foreach ($ids as $id){
+ try {
+ $card = OC_Contacts_App::getContactObject( intval($id) );
+ if($card) {
+ $goodids[] = $id;
+ }
+ } catch (Exception $e) {
+ OCP\Util::writeLog('contacts', 'Error moving contact "'.$id.'" to addressbook "'.$aid.'"'.$e->getMessage(), OCP\Util::ERROR);
+ }
+}
+try {
+ OC_Contacts_VCard::moveToAddressBook($aid, $ids);
+} catch (Exception $e) {
+ $msg = $e->getMessage();
+ OCP\Util::writeLog('contacts', 'Error moving contacts "'.implode(',', $ids).'" to addressbook "'.$aid.'"'.$msg, OCP\Util::ERROR);
+ OC_JSON::error(array('data' => array('message' => $msg,)));
+}
+
+OC_JSON::success(array('data' => array('ids' => $goodids,))); \ No newline at end of file
diff --git a/apps/contacts/ajax/contact/saveproperty.php b/apps/contacts/ajax/contact/saveproperty.php
new file mode 100644
index 00000000000..ef4d1b26c5b
--- /dev/null
+++ b/apps/contacts/ajax/contact/saveproperty.php
@@ -0,0 +1,150 @@
+<?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/>.
+ *
+ */
+require_once 'loghandler.php';
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+$id = isset($_POST['id'])?$_POST['id']:null;
+$name = isset($_POST['name'])?$_POST['name']:null;
+$value = isset($_POST['value'])?$_POST['value']:null;
+$parameters = isset($_POST['parameters'])?$_POST['parameters']:null;
+$checksum = isset($_POST['checksum'])?$_POST['checksum']:null;
+
+if(!$name) {
+ bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
+}
+if(!$id) {
+ bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
+}
+if(!$checksum) {
+ bailOut(OC_Contacts_App::$l10n->t('checksum is not set.'));
+}
+if(is_array($value)) {
+ $value = array_map('strip_tags', $value);
+ // NOTE: Important, otherwise the compound value will be
+ // set in the order the fields appear in the form!
+ ksort($value);
+ //if($name == 'CATEGORIES') {
+ // $value = OC_Contacts_VCard::escapeDelimiters($value, ',');
+ //} else {
+ $value = OC_Contacts_VCard::escapeDelimiters($value, ';');
+ //}
+} else {
+ $value = trim(strip_tags($value));
+}
+
+$vcard = OC_Contacts_App::getContactVCard( $id );
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
+if(is_null($line)) {
+ bailOut(OC_Contacts_App::$l10n->t(
+ 'Information about vCard is incorrect. Please reload the page: ').$checksum
+ );
+}
+$element = $vcard->children[$line]->name;
+
+if($element != $name) {
+ bailOut(OC_Contacts_App::$l10n->t(
+ 'Something went FUBAR. ').$name.' != '.$element
+ );
+}
+
+/* preprocessing value */
+switch($element) {
+ case 'BDAY':
+ $date = New DateTime($value);
+ $value = $date->format('Y-m-d');
+ break;
+ case 'FN':
+ if(!$value) {
+ // create a method thats returns an alternative for FN.
+ //$value = getOtherValue();
+ }
+ break;
+ case 'NOTE':
+ $value = str_replace('\n', '\\n', $value);
+ break;
+ case 'EMAIL':
+ $value = strtolower($value);
+ break;
+}
+
+if(!$value) {
+ unset($vcard->children[$line]);
+ $checksum = '';
+} else {
+ /* setting value */
+ switch($element) {
+ case 'BDAY':
+ // I don't use setDateTime() because that formats it as YYYYMMDD instead
+ // of YYYY-MM-DD which is what the RFC recommends.
+ $vcard->children[$line]->setValue($value);
+ $vcard->children[$line]->parameters = array();
+ $vcard->children[$line]->add(
+ new Sabre_VObject_Parameter('VALUE', 'DATE')
+ );
+ debug('Setting value:'.$name.' '.$vcard->children[$line]);
+ break;
+ case 'CATEGORIES':
+ debug('Setting string:'.$name.' '.$value);
+ $vcard->children[$line]->setValue($value);
+ break;
+ case 'EMAIL':
+ case 'TEL':
+ case 'ADR': // should I delete the property if empty or throw an error?
+ debug('Setting element: (EMAIL/TEL/ADR)'.$element);
+ $vcard->children[$line]->setValue($value);
+ $vcard->children[$line]->parameters = array();
+ if(!is_null($parameters)) {
+ debug('Setting parameters: '.$parameters);
+ foreach($parameters as $key => $parameter) {
+ debug('Adding parameter: '.$key);
+ foreach($parameter as $val) {
+ debug('Adding parameter: '.$key.'=>'.$val);
+ $vcard->children[$line]->add(new Sabre_VObject_Parameter(
+ $key,
+ strtoupper(strip_tags($val)))
+ );
+ }
+ }
+ }
+ break;
+ default:
+ debug('Setting string:'.$name.' '.$value);
+ $vcard->setString($name, $value);
+ break;
+ }
+ // Do checksum and be happy
+ $checksum = md5($vcard->children[$line]->serialize());
+}
+//debug('New checksum: '.$checksum);
+
+if(!OC_Contacts_VCard::edit($id, $vcard)) {
+ bailOut(OC_Contacts_App::$l10n->t('Error updating contact property.'));
+ exit();
+}
+
+OCP\JSON::success(array('data' => array(
+ 'line' => $line,
+ 'checksum' => $checksum,
+ 'oldchecksum' => $_POST['checksum']))
+);