diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
new file mode 100644
index 0000000000000000000000000000000000000000..24766931d71814da524d3bf469bb342a690d8520
--- /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 0000000000000000000000000000000000000000..03d5e6b3ceb40f5da5c8160def34bcac580ceb28
--- /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 0000000000000000000000000000000000000000..35b4d122bda89d97ef4d83566d9e9b56fb600fb6
--- /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 0000000000000000000000000000000000000000..ba36c494cdf95456b655df99be57d5c1ff4d267c
--- /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 0000000000000000000000000000000000000000..839936d3fadfadd56221de5402541fc732b248d0
--- /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 0000000000000000000000000000000000000000..9f8b5dbbaf11c8f9daf981d287f21182d0ce218f
--- /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/details.php b/apps/contacts/ajax/getdetails.php
similarity index 87%
rename from apps/contacts/details.php
rename to apps/contacts/ajax/getdetails.php
index 7ab1b64de243ca5117adea203b0d7212296583ba..4ee3625afc2b0dc29dbdd7b0d17a66e98fec90f4 100644
--- a/apps/contacts/details.php
+++ b/apps/contacts/ajax/getdetails.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../lib/base.php');
+require_once('../../../lib/base.php');
 
 $id = $_GET['id'];
 
@@ -29,7 +29,7 @@ $l10n = new OC_L10N('contacts');
 
 // Check if we are a user
 if( !OC_User::isLoggedIn()){
-	echo $l10n->t('You need to log in!');
+	echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
 	exit();
 }
 
@@ -48,10 +48,9 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
 
 $vcard = Sabre_VObject_Reader::read($card['carddata']);
 $details = OC_Contacts_Addressbook::structureContact($vcard);
-
-$tmpl = new OC_Template('contacts','_details');
+$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( 'page' => $page )));
+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 0000000000000000000000000000000000000000..c29b532602795f77f53a4702e41808232c20d5e0
--- /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 0000000000000000000000000000000000000000..6f33c68631ac0daf16a6491051477dd3530c2d90
--- /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 0000000000000000000000000000000000000000..41ebb41d3e9d31bffb2c2e38f8de3d2977bf2090
--- /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 0000000000000000000000000000000000000000..becc39b120a01307ae65cfd1d3306defd472519d
--- /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 0000000000000000000000000000000000000000..75c3ff88f5ffef3a096e1e87e65a3bea9d61d0e0
--- /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 )));
diff --git a/apps/contacts/carddav.php b/apps/contacts/carddav.php
index ae2c5b973635e091c290bf002513f356f1eefb58..581bf4a717b325b85b8a9dbf97b0d55818f741b7 100644
--- a/apps/contacts/carddav.php
+++ b/apps/contacts/carddav.php
@@ -1,4 +1,24 @@
 <?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/>.
+ *
+ */
 
 // Do not load FS ...
 $RUNTIME_NOSETUPFS = true;
diff --git a/apps/contacts/css/styles.css b/apps/contacts/css/styles.css
index 8d1c8b69c3fce7bea45c73efd06983e3c419a92f..c7680f4a71685d67a7ccaaa4109ad50af975ad0f 100644
--- a/apps/contacts/css/styles.css
+++ b/apps/contacts/css/styles.css
@@ -1 +1 @@
- 
+.contacts_propertyname {float:left;}
diff --git a/apps/contacts/index.php b/apps/contacts/index.php
index 1e01b1c9fbd2d89f819d083f2e1d89b6d3de8167..4330c31043cc1700da4ab68c7ab0b3447deecb63 100644
--- a/apps/contacts/index.php
+++ b/apps/contacts/index.php
@@ -63,7 +63,8 @@ usort($contacts,'contacts_namesort');
 $details = array();
 
 if( !is_null($id) || count($contacts)){
-	$contact = OC_Contacts_Addressbook::findCard(is_null($id)?$contacts[0]['id']:$id);
+	if(is_null($id)) $id = $contacts[0]['id'];
+	$contact = OC_Contacts_Addressbook::findCard($id);
 	$vcard = Sabre_VObject_Reader::read($contact['carddata']);
 	$details = OC_Contacts_Addressbook::structureContact($vcard);
 }
diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js
index 6af160b39272a9f7fde6501979c0cd3049a3eebf..0aae7d15d4559a482974c745a2f467e52b68a707 100644
--- a/apps/contacts/js/interface.js
+++ b/apps/contacts/js/interface.js
@@ -1,9 +1,15 @@
 $(document).ready(function(){
-	$('.contacts_contacts').find('li').live('click',function(){
+	/* $('.contacts_addressbooksexpander').click(function(){
+		$('.contacts_addressbooksdetails').toggle();
+		return false;
+	});*/
+
+	$('#contacts_contacts li').live('click',function(){
 		var id = $(this).attr('x-id');
-		$.getJSON('details.php',{'id':id},function(jsondata){
+		$.getJSON('ajax/getdetails.php',{'id':id},function(jsondata){
 			if(jsondata.status == 'success'){
-				$('.contacts_details').html(jsondata.data.page);
+				$('#contacts_details').attr('x-id',jsondata.data.id);
+				$('#contacts_details').html(jsondata.data.page);
 			}
 			else{
 				alert(jsondata.data.message);
@@ -12,8 +18,140 @@ $(document).ready(function(){
 		return false;
 	});
 
-	$('.contacts_addressbooksexpander').click(function(){
-		$('.contacts_addressbooksdetails').toggle();
+	$('#contacts_deletecard').live('click',function(){
+		var id = $('#contacts_details').attr('x-id');
+		$.getJSON('ajax/deletecard.php',{'id':id},function(jsondata){
+			if(jsondata.status == 'success'){
+				$('#contacts_contacts [x-id="'+jsondata.data.id+'"]').remove();
+				$('#contacts_details').attr('x-id','');
+				$('#contacts_details').html('');
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		});
+		return false;
+	});
+
+	$('#contacts_addproperty').live('click',function(){
+		var id = $('#contacts_details').attr('x-id');
+		$.getJSON('ajax/showaddproperty.php',{'id':id},function(jsondata){
+			if(jsondata.status == 'success'){
+				$('#contacts_details').append(jsondata.data.page);
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		});
 		return false;
 	});
+
+	$('#contacts_addpropertyform [name="name"]').live('change',function(){
+		$('#contacts_addpropertyform #contacts_addresspart').remove();
+		$('#contacts_addpropertyform #contacts_phonepart').remove();
+		$('#contacts_addpropertyform #contacts_fieldpart').remove();
+		$('#contacts_addpropertyform #contacts_generic').remove();
+		if($(this).val() == 'ADR'){
+			$('#contacts_addresspart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
+		}
+		else if($(this).val() == 'TEL'){
+			$('#contacts_phonepart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
+		}
+		else if($(this).val() == 'NOTE'){
+			$('#contacts_fieldpart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
+		}
+		else{
+			$('#contacts_generic').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
+		}
+	});
+
+	$('#contacts_addpropertyform input[type="submit"]').live('click',function(){
+		$.post('ajax/addproperty.php',$('#contacts_addpropertyform').serialize(),function(jsondata){
+			if(jsondata.status == 'success'){
+				$('#contacts_details').append(jsondata.data.page);
+				$('#contacts_addpropertyform').remove();
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		}, 'json');
+		return false;
+	});
+	
+	$('#contacts_newcontact').click(function(){
+		$.getJSON('ajax/showaddcard.php',{},function(jsondata){
+			if(jsondata.status == 'success'){
+				$('#contacts_details').attr('x-id','');
+				$('#contacts_details').html(jsondata.data.page);
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		});
+		return false;
+	});
+
+	$('#contacts_addcardform input[type="submit"]').live('click',function(){
+		$.post('ajax/addcard.php',$('#contacts_addcardform').serialize(),function(jsondata){
+			if(jsondata.status == 'success'){
+				$('#contacts_details').attr('x-id',jsondata.data.id);
+				$('#contacts_details').html(jsondata.data.page);
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		}, 'json');
+		return false;
+	});
+
+	$('.contacts_property [x-use="edit"]').live('click',function(){
+		var id = $('#contacts_details').attr('x-id');
+		var checksum = $(this).parent().parent().attr('x-checksum');
+		var line = $(this).parent().parent().attr('x-line');
+		$.getJSON('ajax/showsetproperty.php',{'id': id, 'checksum': checksum, 'line': line },function(jsondata){
+			if(jsondata.status == 'success'){
+				$('.contacts_property[x-line="'+line+'"][x-checksum="'+checksum+'"] .contacts_propertyvalue').html(jsondata.data.page);
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		});
+		return false;
+	});
+
+	$('#contacts_setpropertyform input[type="submit"]').live('click',function(){
+		$.post('ajax/setproperty.php',$('#contacts_setpropertyform').serialize(),function(jsondata){
+			if(jsondata.status == 'success'){
+				$('.contacts_property[x-line="'+jsondata.data.line+'"][x-checksum="'+jsondata.data.oldchecksum+'"]').replaceWith(jsondata.data.page);
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		},'json');
+		return false;
+	});
+
+	$('.contacts_property [x-use="delete"]').live('click',function(){
+		var id = $('#contacts_details').attr('x-id');
+		var checksum = $(this).parent().parent().attr('x-checksum');
+		var line = $(this).parent().parent().attr('x-line');
+		$.getJSON('ajax/deleteproperty.php',{'id': id, 'checksum': checksum, 'line': line },function(jsondata){
+			if(jsondata.status == 'success'){
+				$('.contacts_property[x-line="'+line+'"][x-checksum="'+checksum+'"]').remove();
+			}
+			else{
+				alert(jsondata.data.message);
+			}
+		});
+		return false;
+	});
+
+
+	$('.contacts_property').live('mouseenter',function(){
+		$(this).find('span').show();
+	});
+	
+	$('.contacts_property').live('mouseleave',function(){
+		$(this).find('span').hide();
+	});
 });
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index c0f26c7df55f2a2511f324cf2acb54dab28d9ae8..b7444653907ee89c47c9862ca175916f2565db53 100644
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -167,14 +167,14 @@ class OC_Contacts_Addressbook{
 				$uri = $property->value.'.vcf';
 			}
 		}
-		$uri = self::createUID().'.vcf';
+		if(is_null($uri)) $uri = self::createUID().'.vcf';
 
 		$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
 		$result = $stmt->execute(array($id,$fn,$data,$uri,time()));
 
-		self::touch($id);
+		self::touchAddressbook($id);
 
-		return OC_DB::insertid;
+		return OC_DB::insertid();
 	}
 
 	public static function addCardFromDAVData($id,$uri,$data){
@@ -189,13 +189,13 @@ class OC_Contacts_Addressbook{
 		$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' );
 		$result = $stmt->execute(array($id,$fn,$data,$uri,time()));
 
-		self::touch($id);
+		self::touchAddressbook($id);
 
-		return OC_DB::insertid;
+		return OC_DB::insertid();
 	}
 
 	public static function editCard($id, $data){
-		$oldcard = self::findCard($id,$aid,$uri);
+		$oldcard = self::findCard($id);
 		$fn = null;
 		$card = Sabre_VObject_Reader::read($data);
 		foreach($card->children as $property){
@@ -207,7 +207,7 @@ class OC_Contacts_Addressbook{
 		$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
 		$result = $stmt->execute(array($fn,$data,time(),$id));
 
-		self::touch($oldcard['addressbookid']);
+		self::touchAddressbook($oldcard['addressbookid']);
 
 		return true;
 	}
@@ -226,20 +226,20 @@ class OC_Contacts_Addressbook{
 		$stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?' );
 		$result = $stmt->execute(array($fn,$data,time(),$oldcard['id']));
 
-		self::touch($oldcard['addressbookid']);
+		self::touchAddressbook($oldcard['addressbookid']);
 
 		return true;
 	}
 	
 	public static function deleteCard($id){
-		$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
+		$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' );
 		$stmt->execute(array($id));
 
 		return true;
 	}
 
 	public static function deleteCardFromDAVData($aid,$uri){
-		$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE addressbookid = ? AND uri=?' );
+		$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri=?' );
 		$stmt->execute(array($aid,$uri));
 
 		return true;
@@ -265,23 +265,60 @@ class OC_Contacts_Addressbook{
 		return $userid;
 	}
 
+	public static function escapeSemicolons($value){
+		foreach($value as &$i ){
+			$i = implode("\\\\;", explode(';', $i));
+		} unset($i);
+		return implode(';',$value);
+	}
+
+	public static function unescapeSemicolons($value){
+		$array = explode(';',$value);
+		for($i=0;$i<count($array);$i++){
+			if(substr($array[$i],-2,2)=="\\\\"){
+				if(isset($array[$i+1])){
+					$array[$i] = substr($array[$i],0,count($array[$i])-2).';'.$array[$i+1];
+					unset($array[$i+1]);
+				}
+				else{
+					$array[$i] = substr($array[$i],0,count($array[$i])-2).';';
+				}
+				$i = $i - 1;
+			}
+		}
+		return $array;
+	}
+
 	public static function structureContact($object){
 		$details = array();
+		$line = 0;
 		foreach($object->children as $property){
-			$temp = array(
-				'name' => $property->name,
-				'value' => ($property->name == 'PHOTO' || $property->name == 'LOGO' ? null : $property->value ),
-				'parameters' => array());
-			foreach($property->parameters as $parameter){
-				$temp['parameters'][] = array( 'name' => $parameter->name, 'value' => $parameter->value);
-			}
+			$temp = self::structureProperty($property,$line);
 			if(array_key_exists($property->name,$details)){
 				$details[$property->name][] = $temp;
 			}
 			else{
 				$details[$property->name] = array($temp);
 			}
+			$line++;
 		}
 		return $details;
 	}
+	
+	public static function structureProperty($property,$line=null){
+		$value = $property->value;
+		if($property->name == 'ADR'){
+			$value = self::unescapeSemicolons($value);
+		}
+		$temp = array(
+			'name' => $property->name,
+			'value' => $value,
+			'line' => $line,
+			'parameters' => array(),
+			'checksum' => md5($property->serialize()));
+		foreach($property->parameters as $parameter){
+			$temp['parameters'][$parameter->name] = $parameter->value;
+		}
+		return $temp;
+	}
 }
diff --git a/apps/contacts/lib/connector_sabre.php b/apps/contacts/lib/connector_sabre.php
index 98e2598b3a75cd8e7d889c545762fcdb47e9f070..96a90dfc5deed343f5e43552d6934f67b8a4df39 100644
--- a/apps/contacts/lib/connector_sabre.php
+++ b/apps/contacts/lib/connector_sabre.php
@@ -1,13 +1,23 @@
 <?php
-
 /**
- * PDO CardDAV backend
- * 
- * @package Sabre
- * @subpackage CardDAV
- * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
- * @author Evert Pot (http://www.rooftopsolutions.nl/) 
- * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ * 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/>.
+ *
  */
 
 /**
diff --git a/apps/contacts/templates/_details.php b/apps/contacts/templates/_details.php
deleted file mode 100644
index e27b17ef2ebe5c86ee6676de37c05f1886bd8536..0000000000000000000000000000000000000000
--- a/apps/contacts/templates/_details.php
+++ /dev/null
@@ -1,4 +0,0 @@
-Name <?php echo $_['details']['FN'][0]['value']; ?>
-<?php if(array_key_exists('PHOTO',$_['details'])): ?>
-	<img src="photo.php?id=<?php echo $_['id']; ?>">
-<?php endif; ?>
\ No newline at end of file
diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php
index ca189cb4c8af5d6dbad6b2a296915bfcbdfd769f..e6dd45739bc5a5c82f53727978d770a2456eea57 100644
--- a/apps/contacts/templates/index.php
+++ b/apps/contacts/templates/index.php
@@ -3,7 +3,8 @@ OC_Util::addScript('contacts','interface');
 OC_Util::addStyle('contacts','styles');
 ?>
 
-<div class="contacts_addressbooks">
+<?php
+/*<div class="contacts_addressbooks">
 	<div class="contacts_addressbooksexpander">
 		Addressbooks
 	</div>
@@ -13,12 +14,14 @@ OC_Util::addStyle('contacts','styles');
 		<?php endforeach; ?>
 		<br>To use this addressbook, use .../apps/contacts/carddav.php/addressbooks/USERNAME/addressbookname.php
 	</div>
-</div>
-<div class="contacts_contacts leftcontent">
+</div>*/
+?>
+<div id="contacts_contacts" class="leftcontent">
 	<ul>
-		<?php echo $this->inc("_contacts"); ?>
+		<?php echo $this->inc("part.contacts"); ?>
 	</ul>
+	<a id="contacts_newcontact"><?php echo $l->t('Add Contact'); ?></a>
 </div>
-<div class="contacts_details rightcontent">
-	<?php echo $this->inc("_details"); ?>
+<div id="contacts_details" class="rightcontent" x-id="<?php echo $_['id']; ?>">
+	<?php echo $this->inc("part.details"); ?>
 </div>
diff --git a/apps/contacts/templates/part.addcardform.php b/apps/contacts/templates/part.addcardform.php
new file mode 100644
index 0000000000000000000000000000000000000000..94a59fe097cca777b8bbc5ed78af3af1695c6d83
--- /dev/null
+++ b/apps/contacts/templates/part.addcardform.php
@@ -0,0 +1,13 @@
+<form id="contacts_addcardform">
+	<?php if(count($_['addressbooks'])==1): ?>
+		<input type="hidden" name="id" value="<?php echo $_['addressbooks'][0]['id']; ?>">
+	<?php else: ?>
+		<select name="id" size="1">
+			<?php foreach($_['addressbooks'] as $addressbook): ?>
+				<option value="<?php echo $addressbook['id']; ?>"><?php echo $addressbook['displayname']; ?></option>
+			<?php endforeach; ?>
+		</select>
+	<?php endif; ?>
+	<input type="text" name="fn" value=""><br>
+	<input type="submit">
+</form>
diff --git a/apps/contacts/templates/part.addpropertyform.php b/apps/contacts/templates/part.addpropertyform.php
new file mode 100644
index 0000000000000000000000000000000000000000..ff9090b76d87c530ecc18774eba1b6efb8c69289
--- /dev/null
+++ b/apps/contacts/templates/part.addpropertyform.php
@@ -0,0 +1,43 @@
+<form id="contacts_addpropertyform">
+	<input type="hidden" name="id" value="<?php echo $_['id']; ?>">
+	<select name="name" size="1">
+		<option value="BDAY"><?php echo $l->t('Birthday'); ?></option>
+		<option value="ADR"><?php echo $l->t('Address'); ?></option>
+		<option value="TEL"><?php echo $l->t('Telephone'); ?></option>
+		<option value="EMAIL" selected="selected"><?php echo $l->t('Email'); ?></option>
+		<option value="ORG"><?php echo $l->t('Organization'); ?></option>
+	</select>
+	<div id="contacts_generic">
+		<input type="text" name="value" value="">
+	</div>
+	<input type="submit">
+</form>
+<div id="contacts_addcontactsparts" style="display:none;">
+	<div id="contacts_addresspart">
+		<select name="parameters[TYPE]" size="1">
+			<option value="WORK"><?php echo $l->t('Work'); ?></option>
+			<option value="HOME" selected="selected"><?php echo $l->t('Home'); ?></option>
+		</select>
+		<?php echo $l->t('PO Box'); ?> <input type="text" name="value[0]" value="">
+		<?php echo $l->t('Extended Address'); ?> <input type="text" name="value[1]" value="">
+		<?php echo $l->t('Street Name'); ?> <input type="text" name="value[2]" value="">
+		<?php echo $l->t('City'); ?> <input type="text" name="value[3]" value="">
+		<?php echo $l->t('Region'); ?> <input type="text" name="value[4]" value="">
+		<?php echo $l->t('Postal Code'); ?> <input type="text" name="value[5]" value="">
+		<?php echo $l->t('Country'); ?> <input type="text" name="value[6]" value="">
+	</div>
+	<div id="contacts_phonepart">
+		<select name="parameters[TYPE]" size="1">
+			<option value="WORK"><?php echo $l->t('Work'); ?></option>
+			<option value="CELL" selected="selected"><?php echo $l->t('Mobile'); ?></option>
+			<option value="HOME"><?php echo $l->t('Home'); ?></option>
+		</select>
+		<input type="text" name="value" value="">
+	</div>
+	<div id="contacts_fieldpart">
+		<textarea type="text" name="value"></textarea>
+	</div>
+	<div id="contacts_generic">
+		<input type="text" name="value" value="">
+	</div>
+</div>
diff --git a/apps/contacts/templates/_contacts.php b/apps/contacts/templates/part.contacts.php
similarity index 95%
rename from apps/contacts/templates/_contacts.php
rename to apps/contacts/templates/part.contacts.php
index bf633b79b047890620869fe6d458ec595cc6c2cc..fa6d4790cfc8ebf54113abe2e5af25cf4efb8c62 100644
--- a/apps/contacts/templates/_contacts.php
+++ b/apps/contacts/templates/part.contacts.php
@@ -1,3 +1,3 @@
 <?php foreach( $_['contacts'] as $contact ): ?>
-	<li x-id="<?php echo $contact['id']; ?>"><a href="index.php?id=<?php echo $contact['id']; ?>"><?php echo $contact['name']; ?></a></li>
+	<li x-id="<?php echo $contact['id']; ?>"><a href="index.php?id=<?php echo $contact['id']; ?>"><?php echo $contact['name']; ?></a> </li>
 <?php endforeach; ?>
diff --git a/apps/contacts/templates/part.details.php b/apps/contacts/templates/part.details.php
new file mode 100644
index 0000000000000000000000000000000000000000..4aca8dbc7901f15f47ac333a24a1beb7331f0a7e
--- /dev/null
+++ b/apps/contacts/templates/part.details.php
@@ -0,0 +1,22 @@
+<?php if(array_key_exists('PHOTO',$_['details'])): ?>
+	<img src="photo.php?id=<?php echo $_['id']; ?>">
+<?php endif; ?>
+<?php echo $this->inc('part.property', array('property' => $_['details']['FN'][0])); ?>
+<?php if(isset($_['details']['BDAY'])): // Emails first ?>
+	<?php echo $this->inc('part.property', array('property' => $_['details']['BDAY'][0])); ?>
+<?php endif; ?>
+<?php if(isset($_['details']['ORG'])): // Emails first ?>
+	<?php echo $this->inc('part.property', array('property' => $_['details']['ORG'][0])); ?>
+<?php endif; ?>
+
+<?php foreach(array('EMAIL','TEL','ADR') as $type): ?>
+	<?php if(isset($_['details'][$type])): // Emails first ?>
+		<br>
+		<?php foreach($_['details'][$type] as $property): ?>
+			<?php echo $this->inc('part.property',array('property' => $property )); ?>
+		<?php endforeach; ?>
+	<?php endif; ?>
+<?php endforeach; ?>
+
+<a id="contacts_deletecard"><img src="../../core/img/actions/delete.png"></a>
+<a id="contacts_addproperty"><img src="../../core/img/actions/download.png"></a>
diff --git a/apps/contacts/templates/part.property.php b/apps/contacts/templates/part.property.php
new file mode 100644
index 0000000000000000000000000000000000000000..1a4266b3a2b86ce28e490c5a6004f954f2738130
--- /dev/null
+++ b/apps/contacts/templates/part.property.php
@@ -0,0 +1,50 @@
+<div class="contacts_property" x-line="<?php echo $_['property']['line']; ?>" x-checksum="<?php echo $_['property']['checksum']; ?>">
+	<?php if($_['property']['name'] == 'FN'): ?>
+		<div class="contacts_propertyname"><?php echo $l->t('Name'); ?></div>
+		<div class="contacts_propertyvalue">
+			<span style="display:none;" x-use="edit"><img src="../../core/img/actions/rename.png"></span>
+			<?php echo $_['property']['value']; ?>
+		</div>
+	<?php elseif($_['property']['name'] == 'BDAY'): ?>
+		<div class="contacts_propertyname"><?php echo $l->t('Birthday'); ?></div>
+		<div class="contacts_propertyvalue">
+		<?php echo $l->l('date',new DateTime($_['property']['value'])); ?>
+			<span style="display:none;" x-use="edit"><img src="../../core/img/actions/rename.png"></span>
+			<span style="display:none;" x-use="delete"><img src="../../core/img/actions/delete.png"></span>
+		</div>
+	<?php elseif($_['property']['name'] == 'ORG'): ?>
+		<div class="contacts_propertyname"><?php echo $l->t('Organisation'); ?></div>
+		<div class="contacts_propertyvalue">
+			<?php echo $_['property']['value']; ?>
+			<span style="display:none;" x-use="edit"><img src="../../core/img/actions/rename.png"></span>
+			<span style="display:none;" x-use="delete"><img src="../../core/img/actions/delete.png"></span>
+		</div>
+	<?php elseif($_['property']['name'] == 'EMAIL'): ?>
+		<div class="contacts_propertyname"><?php echo $l->t('Email'); ?></div>
+		<div class="contacts_propertyvalue">
+			<?php echo $_['property']['value']; ?>
+			<span style="display:none;" x-use="edit"><img src="../../core/img/actions/rename.png"></span>
+			<span style="display:none;" x-use="delete"><img src="../../core/img/actions/delete.png"></span>
+		</div>
+	<?php elseif($_['property']['name'] == 'TEL'): ?>
+		<div class="contacts_propertyname"><?php echo $l->t('Telefon'); ?></div>
+		<div class="contacts_propertyvalue">
+			<?php echo $_['property']['value']; ?>
+			<span style="display:none;" x-use="edit"><img src="../../core/img/actions/rename.png"></span>
+			<span style="display:none;" x-use="delete"><img src="../../core/img/actions/delete.png"></span>
+		</div>
+	<?php elseif($_['property']['name'] == 'ADR'): ?>
+		<div class="contacts_propertyname"><?php echo $l->t('Address'); ?></div>
+		<div class="contacts_propertyvalue">
+			<?php echo $l->t('PO Box'); ?> <?php echo $_['property']['value'][0]; ?><br>
+			<?php echo $l->t('Extended Address'); ?> <?php echo $_['property']['value'][1]; ?><br>
+			<?php echo $l->t('Street Name'); ?> <?php echo $_['property']['value'][2]; ?><br>
+			<?php echo $l->t('City'); ?> <?php echo $_['property']['value'][3]; ?><br>
+			<?php echo $l->t('Region'); ?> <?php echo $_['property']['value'][4]; ?><br>
+			<?php echo $l->t('Postal Code'); ?> <?php echo $_['property']['value'][5]; ?><br>
+			<?php echo $l->t('Country'); ?> <?php echo $_['property']['value'][6]; ?> 
+			<span style="display:none;" x-use="edit"><img src="../../core/img/actions/rename.png"></span>
+			<span style="display:none;" x-use="delete"><img src="../../core/img/actions/delete.png"></span>
+		</div>
+	<?php endif; ?>
+</div>
diff --git a/apps/contacts/templates/part.setpropertyform.php b/apps/contacts/templates/part.setpropertyform.php
new file mode 100644
index 0000000000000000000000000000000000000000..cd774ee659350a5caaeee5b71e87071100be3c17
--- /dev/null
+++ b/apps/contacts/templates/part.setpropertyform.php
@@ -0,0 +1,21 @@
+<form id="contacts_setpropertyform">
+	<input type="hidden" name="checksum" value="<?php echo $_['property']['checksum']; ?>">
+	<input type="hidden" name="line" value="<?php echo $_['property']['line']; ?>">
+	<input type="hidden" name="id" value="<?php echo $_['id']; ?>">
+	<?php if($_['property']['name']=='ADR'): ?>
+		<?php echo $l->t('PO Box'); ?> <input type="text" name="value[0]" value="<?php echo $_['property']['value'][0]; ?>">
+		<?php echo $l->t('Extended Address'); ?> <input type="text" name="value[1]" value="<?php echo $_['property']['value'][1]; ?>">
+		<?php echo $l->t('Street Name'); ?> <input type="text" name="value[2]" value="<?php echo $_['property']['value'][2]; ?>">
+		<?php echo $l->t('City'); ?> <input type="text" name="value[3]" value="<?php echo $_['property']['value'][3]; ?>">
+		<?php echo $l->t('Region'); ?> <input type="text" name="value[4]" value="<?php echo $_['property']['value'][4]; ?>">
+		<?php echo $l->t('Postal Code'); ?> <input type="text" name="value[5]" value="<?php echo $_['property']['value'][5]; ?>">
+		<?php echo $l->t('Country'); ?> <input type="text" name="value[6]" value="<?php echo $_['property']['value'][6]; ?>">
+	<?php elseif($_['property']['name']=='TEL'): ?>
+		<input type="text" name="value" value="<?php echo $_['property']['value']; ?>">
+	<?php elseif($_['property']['name']=='NOTE'): ?>
+		<textarea type="text" name="value"><?php echo $_['property']['value']; ?></textarea>
+	<?php else: ?>
+		<input type="text" name="value" value="<?php echo $_['property']['value']; ?>">
+	<?php endif; ?>
+	<input type="submit">
+</form>
diff --git a/apps/contacts/temporaryupdate.php b/apps/contacts/temporaryupdate.php
index bb5ff7604f3db18c6b3a56d385188676f9d3191d..4b6453364e3332e4db86bc728165432277e293e4 100644
--- a/apps/contacts/temporaryupdate.php
+++ b/apps/contacts/temporaryupdate.php
@@ -1,4 +1,24 @@
 <?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');
 $connector = new OC_Connector_Sabre_Principal;