summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-08-09 13:53:58 +0200
committerJakob Sack <kde@jakobsack.de>2011-08-09 13:53:58 +0200
commit76fc062f27a178be97b2f4bf285f7f07c6361f60 (patch)
treed69727c82e394f22bd08be14d146890592da3d70 /apps/contacts/ajax
parent4e5b6f72c17ec361757495e89d3f1929f3981dbb (diff)
downloadnextcloud-server-76fc062f27a178be97b2f4bf285f7f07c6361f60.tar.gz
nextcloud-server-76fc062f27a178be97b2f4bf285f7f07c6361f60.zip
Some more work on the address book
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r--apps/contacts/ajax/addcard.php54
-rw-r--r--apps/contacts/ajax/addphoto.php59
-rw-r--r--apps/contacts/ajax/addproperty.php73
-rw-r--r--apps/contacts/ajax/deletebook.php44
-rw-r--r--apps/contacts/ajax/deletecard.php50
-rw-r--r--apps/contacts/ajax/deleteproperty.php62
-rw-r--r--apps/contacts/ajax/getdetails.php56
-rw-r--r--apps/contacts/ajax/setphoto.php77
-rw-r--r--apps/contacts/ajax/setproperty.php93
-rw-r--r--apps/contacts/ajax/showaddcard.php39
-rw-r--r--apps/contacts/ajax/showaddproperty.php51
-rw-r--r--apps/contacts/ajax/showsetproperty.php62
12 files changed, 720 insertions, 0 deletions
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
new file mode 100644
index 00000000000..24766931d71
--- /dev/null
+++ b/apps/contacts/ajax/addcard.php
@@ -0,0 +1,54 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$aid = $_POST['id'];
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $aid );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your addressbook!'))));
+ exit();
+}
+
+$fn = $_POST['fn'];
+
+$vcard = new Sabre_VObject_Component('VCARD');
+$vcard->add(new Sabre_VObject_Property('FN',$fn));
+$vcard->add(new Sabre_VObject_Property('UID',OC_Contacts_Addressbook::createUID()));
+$id = OC_Contacts_Addressbook::addCard($aid,$vcard->serialize());
+
+$details = OC_Contacts_Addressbook::structureContact($vcard);
+$tmpl = new OC_Template('contacts','part.details');
+$tmpl->assign('details',$details);
+$tmpl->assign('id',$id);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));
diff --git a/apps/contacts/ajax/addphoto.php b/apps/contacts/ajax/addphoto.php
new file mode 100644
index 00000000000..03d5e6b3ceb
--- /dev/null
+++ b/apps/contacts/ajax/addphoto.php
@@ -0,0 +1,59 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_POST['id'];
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+$mimetype = $_FILES['photo']['type'] ? $_FILES['photo']['type'] : 'image/jpeg';
+$photobase = base64_encode(file_get_contents($_FILES['photo']['tmp_name']));
+$photo = new Sabre_VObject_Property( 'PHOTO', $photobase );
+$photo->parameters[] = new Sabre_VObject_Parameter('TYPE',$mimetype);
+$photo->parameters[] = new Sabre_VObject_Parameter('ENCODING','b');
+$vcard->add($photo);
+
+$line = count($vcard->children) - 1;
+$checksum = md5($vcard->children[$line]->serialize());
+
+OC_Contacts_Addressbook::editCard($id,$vcard->serialize());
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'line' => $line, 'checksum' => $checksum )));
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
new file mode 100644
index 00000000000..35b4d122bda
--- /dev/null
+++ b/apps/contacts/ajax/addproperty.php
@@ -0,0 +1,73 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_POST['id'];
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+
+$name = $_POST['name'];
+$value = $_POST['value'];
+$parameters = $_POST['parameters'];
+
+if(is_array($value)){
+ $value = OC_Contacts_Addressbook::escapeSemicolons($value);
+}
+$property = new Sabre_VObject_Property( $name, $value );
+$parameternames = array_keys($parameters);
+foreach($parameternames as $i){
+ $property->parameters[] = new Sabre_VObject_Parameter($i,$parameters[$i]);
+}
+
+$vcard->add($property);
+
+$line = count($vcard->children) - 1;
+$checksum = md5($property->serialize());
+
+OC_Contacts_Addressbook::editCard($id,$vcard->serialize());
+
+$tmpl = new OC_Template('contacts','part.property');
+$tmpl->assign('property',OC_Contacts_Addressbook::structureProperty($property,$line));
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php
new file mode 100644
index 00000000000..ba36c494cdf
--- /dev/null
+++ b/apps/contacts/ajax/deletebook.php
@@ -0,0 +1,44 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_GET['id'];
+
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $id );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+OC_Contacts_Addressbook::deleteAddressbook($id);
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
new file mode 100644
index 00000000000..839936d3fad
--- /dev/null
+++ b/apps/contacts/ajax/deletecard.php
@@ -0,0 +1,50 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_GET['id'];
+
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+OC_Contacts_Addressbook::deleteCard($id);
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
new file mode 100644
index 00000000000..9f8b5dbbaf1
--- /dev/null
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -0,0 +1,62 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_GET['id'];
+$line = $_GET['line'];
+$checksum = $_GET['checksum'];
+
+
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+
+if(md5($vcard->children[$line]->serialize()) != $checksum ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload page!'))));
+ exit();
+}
+
+unset($vcard->children[$line]);
+
+OC_Contacts_Addressbook::editCard($id,$vcard->serialize());
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php
new file mode 100644
index 00000000000..4ee3625afc2
--- /dev/null
+++ b/apps/contacts/ajax/getdetails.php
@@ -0,0 +1,56 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_GET['id'];
+
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+$details = OC_Contacts_Addressbook::structureContact($vcard);
+$tmpl = new OC_Template('contacts','part.details');
+$tmpl->assign('details',$details);
+$tmpl->assign('id',$id);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));
diff --git a/apps/contacts/ajax/setphoto.php b/apps/contacts/ajax/setphoto.php
new file mode 100644
index 00000000000..c29b5326027
--- /dev/null
+++ b/apps/contacts/ajax/setphoto.php
@@ -0,0 +1,77 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_POST['id'];
+$line = $_POST['line'];
+$checksum = $_POST['checksum'];
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+$mimetype = $_FILES['photo']['type'] ? $_FILES['photo']['type'] : 'image/jpeg';
+$photobase = base64_encode(file_get_contents($_FILES['photo']['tmp_name']));
+
+if(md5($vcard->children[$line]->serialize()) != $checksum){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload page!'))));
+ exit();
+}
+
+// replace photo
+$vcard->children[$line]->setValue($photobase);
+$encoding = $type = false;
+foreach($vcard->children[$line]->parameters as &$parameter){
+ if($parameter->name == 'TYPE'){
+ $parameter->value = $mimetype;
+ $type = true;
+ }
+ elseif($parameter->name == 'ENCODING'){
+ $parameter->value = 'b';
+ $encoding = true;
+ }
+} unset($parameter);
+if(!$encoding) $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter('ENCODING','b');
+if(!$type) $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter('TYPE',$mimetype);
+
+$checksum = md5($vcard->children[$line]->serialize());
+
+OC_Contacts_Addressbook::editCard($id,$vcard->serialize());
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'line' => $line, 'checksum' => $checksum )));
diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php
new file mode 100644
index 00000000000..6f33c68631a
--- /dev/null
+++ b/apps/contacts/ajax/setproperty.php
@@ -0,0 +1,93 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_POST['id'];
+$line = $_POST['line'];
+$checksum = $_POST['checksum'];
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+
+if(md5($vcard->children[$line]->serialize()) != $checksum){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload page!'))));
+ exit();
+}
+
+// Set the value
+$value = $_POST['value'];
+if(is_array($value)){
+ $value = OC_Contacts_Addressbook::escapeSemicolons($value);
+}
+$vcard->children[$line]->setValue($value);
+
+// Add parameters
+$postparameters = isset($_POST['parameters'])?$_POST['parameters']:array();
+for($i=0;$i<count($vcard->children[$line]->parameters);$i++){
+ $name = $vcard->children[$line]->parameters[$i]->name;
+ if(array_key_exists($name,$postparameters)){
+ if($postparameters[$name] == '' || is_null($postparameters[$name])){
+ unset($vcard->children[$line]->parameters[$i]);
+ }
+ else{
+ $vcard->children[$line]->parameters[$i]->value = $postparameters[$name];
+ }
+ unset($postparameters[$name]);
+ }
+}
+$missingparameters = array_keys($postparameters);
+foreach($missingparameters as $i){
+ if(!$postparameters[$i] == '' && !is_null($postparameters[$i])){
+ $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($i,$postparameters[$i]);
+ }
+}
+
+// Do checksum and be happy
+$checksum = md5($vcard->children[$line]->serialize());
+
+OC_Contacts_Addressbook::editCard($id,$vcard->serialize());
+
+$tmpl = new OC_Template('contacts','part.property');
+$tmpl->assign('property',OC_Contacts_Addressbook::structureProperty($vcard->children[$line],$line));
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page, 'line' => $line, 'oldchecksum' => $_POST['checksum'] )));
diff --git a/apps/contacts/ajax/showaddcard.php b/apps/contacts/ajax/showaddcard.php
new file mode 100644
index 00000000000..41ebb41d3e9
--- /dev/null
+++ b/apps/contacts/ajax/showaddcard.php
@@ -0,0 +1,39 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$addressbooks = OC_Contacts_Addressbook::allAddressbooks(OC_USER::getUser());
+$tmpl = new OC_Template('contacts','part.addcardform');
+$tmpl->assign('addressbooks',$addressbooks);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/showaddproperty.php b/apps/contacts/ajax/showaddproperty.php
new file mode 100644
index 00000000000..becc39b120a
--- /dev/null
+++ b/apps/contacts/ajax/showaddproperty.php
@@ -0,0 +1,51 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_GET['id'];
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$tmpl = new OC_Template('contacts','part.addpropertyform');
+$tmpl->assign('id',$id);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php
new file mode 100644
index 00000000000..75c3ff88f5f
--- /dev/null
+++ b/apps/contacts/ajax/showsetproperty.php
@@ -0,0 +1,62 @@
+<?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/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$id = $_GET['id'];
+$line = $_GET['line'];
+$checksum = $_GET['checksum'];
+$l10n = new OC_L10N('contacts');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$card = OC_Contacts_Addressbook::findCard( $id );
+if( $card === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Contact!'))));
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::findAddressbook( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact!'))));
+ exit();
+}
+
+$vcard = Sabre_VObject_Reader::read($card['carddata']);
+if(md5($vcard->children[$line]->serialize()) != $checksum){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload page!'))));
+ exit();
+}
+
+
+$tmpl = new OC_Template('contacts','part.setpropertyform');
+$tmpl->assign('id',$id);
+$tmpl->assign('checksum',$checksum);
+$tmpl->assign('property',OC_Contacts_Addressbook::structureProperty($vcard->children[$line],$line));
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));