]> source.dussan.org Git - nextcloud-server.git/commitdiff
Some more work on the address book
authorJakob Sack <kde@jakobsack.de>
Tue, 9 Aug 2011 11:53:58 +0000 (13:53 +0200)
committerJakob Sack <kde@jakobsack.de>
Tue, 9 Aug 2011 11:53:58 +0000 (13:53 +0200)
29 files changed:
apps/contacts/ajax/addcard.php [new file with mode: 0644]
apps/contacts/ajax/addphoto.php [new file with mode: 0644]
apps/contacts/ajax/addproperty.php [new file with mode: 0644]
apps/contacts/ajax/deletebook.php [new file with mode: 0644]
apps/contacts/ajax/deletecard.php [new file with mode: 0644]
apps/contacts/ajax/deleteproperty.php [new file with mode: 0644]
apps/contacts/ajax/getdetails.php [new file with mode: 0644]
apps/contacts/ajax/setphoto.php [new file with mode: 0644]
apps/contacts/ajax/setproperty.php [new file with mode: 0644]
apps/contacts/ajax/showaddcard.php [new file with mode: 0644]
apps/contacts/ajax/showaddproperty.php [new file with mode: 0644]
apps/contacts/ajax/showsetproperty.php [new file with mode: 0644]
apps/contacts/carddav.php
apps/contacts/css/styles.css
apps/contacts/details.php [deleted file]
apps/contacts/index.php
apps/contacts/js/interface.js
apps/contacts/lib/addressbook.php
apps/contacts/lib/connector_sabre.php
apps/contacts/templates/_contacts.php [deleted file]
apps/contacts/templates/_details.php [deleted file]
apps/contacts/templates/index.php
apps/contacts/templates/part.addcardform.php [new file with mode: 0644]
apps/contacts/templates/part.addpropertyform.php [new file with mode: 0644]
apps/contacts/templates/part.contacts.php [new file with mode: 0644]
apps/contacts/templates/part.details.php [new file with mode: 0644]
apps/contacts/templates/part.property.php [new file with mode: 0644]
apps/contacts/templates/part.setpropertyform.php [new file with mode: 0644]
apps/contacts/temporaryupdate.php

diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
new file mode 100644 (file)
index 0000000..2476693
--- /dev/null
@@ -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 (file)
index 0000000..03d5e6b
--- /dev/null
@@ -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 (file)
index 0000000..35b4d12
--- /dev/null
@@ -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 (file)
index 0000000..ba36c49
--- /dev/null
@@ -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 (file)
index 0000000..839936d
--- /dev/null
@@ -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 (file)
index 0000000..9f8b5db
--- /dev/null
@@ -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 (file)
index 0000000..4ee3625
--- /dev/null
@@ -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 (file)
index 0000000..c29b532
--- /dev/null
@@ -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 (file)
index 0000000..6f33c68
--- /dev/null
@@ -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 (file)
index 0000000..41ebb41
--- /dev/null
@@ -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 (file)
index 0000000..becc39b
--- /dev/null
@@ -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 (file)
index 0000000..75c3ff8
--- /dev/null
@@ -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 )));
index ae2c5b973635e091c290bf002513f356f1eefb58..581bf4a717b325b85b8a9dbf97b0d55818f741b7 100644 (file)
@@ -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;
index 8d1c8b69c3fce7bea45c73efd06983e3c419a92f..c7680f4a71685d67a7ccaaa4109ad50af975ad0f 100644 (file)
@@ -1 +1 @@
+.contacts_propertyname {float:left;}
diff --git a/apps/contacts/details.php b/apps/contacts/details.php
deleted file mode 100644 (file)
index 7ab1b64..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?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 $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','_details');
-$tmpl->assign('details',$details);
-$tmpl->assign('id',$id);
-$page = $tmpl->fetchPage();
-
-echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
index 1e01b1c9fbd2d89f819d083f2e1d89b6d3de8167..4330c31043cc1700da4ab68c7ab0b3447deecb63 100644 (file)
@@ -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);
 }
index 6af160b39272a9f7fde6501979c0cd3049a3eebf..0aae7d15d4559a482974c745a2f467e52b68a707 100644 (file)
@@ -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();
+       });
 });
index c0f26c7df55f2a2511f324cf2acb54dab28d9ae8..b7444653907ee89c47c9862ca175916f2565db53 100644 (file)
@@ -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;
+       }
 }
index 98e2598b3a75cd8e7d889c545762fcdb47e9f070..96a90dfc5deed343f5e43552d6934f67b8a4df39 100644 (file)
@@ -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/_contacts.php b/apps/contacts/templates/_contacts.php
deleted file mode 100644 (file)
index bf633b7..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?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>
-<?php endforeach; ?>
diff --git a/apps/contacts/templates/_details.php b/apps/contacts/templates/_details.php
deleted file mode 100644 (file)
index e27b17e..0000000
+++ /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
index ca189cb4c8af5d6dbad6b2a296915bfcbdfd769f..e6dd45739bc5a5c82f53727978d770a2456eea57 100644 (file)
@@ -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 (file)
index 0000000..94a59fe
--- /dev/null
@@ -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 (file)
index 0000000..ff9090b
--- /dev/null
@@ -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/part.contacts.php b/apps/contacts/templates/part.contacts.php
new file mode 100644 (file)
index 0000000..fa6d479
--- /dev/null
@@ -0,0 +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>
+<?php endforeach; ?>
diff --git a/apps/contacts/templates/part.details.php b/apps/contacts/templates/part.details.php
new file mode 100644 (file)
index 0000000..4aca8db
--- /dev/null
@@ -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 (file)
index 0000000..1a4266b
--- /dev/null
@@ -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 (file)
index 0000000..cd774ee
--- /dev/null
@@ -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>
index bb5ff7604f3db18c6b3a56d385188676f9d3191d..4b6453364e3332e4db86bc728165432277e293e4 100644 (file)
@@ -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;