From 76fc062f27a178be97b2f4bf285f7f07c6361f60 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Tue, 9 Aug 2011 13:53:58 +0200 Subject: [PATCH] Some more work on the address book --- apps/contacts/ajax/addcard.php | 54 +++++++ apps/contacts/ajax/addphoto.php | 59 +++++++ apps/contacts/ajax/addproperty.php | 73 +++++++++ apps/contacts/ajax/deletebook.php | 44 ++++++ apps/contacts/ajax/deletecard.php | 50 ++++++ apps/contacts/ajax/deleteproperty.php | 62 ++++++++ .../{details.php => ajax/getdetails.php} | 9 +- apps/contacts/ajax/setphoto.php | 77 +++++++++ apps/contacts/ajax/setproperty.php | 93 +++++++++++ apps/contacts/ajax/showaddcard.php | 39 +++++ apps/contacts/ajax/showaddproperty.php | 51 ++++++ apps/contacts/ajax/showsetproperty.php | 62 ++++++++ apps/contacts/carddav.php | 20 +++ apps/contacts/css/styles.css | 2 +- apps/contacts/index.php | 3 +- apps/contacts/js/interface.js | 148 +++++++++++++++++- apps/contacts/lib/addressbook.php | 71 +++++++-- apps/contacts/lib/connector_sabre.php | 26 ++- apps/contacts/templates/_details.php | 4 - apps/contacts/templates/index.php | 15 +- apps/contacts/templates/part.addcardform.php | 13 ++ .../templates/part.addpropertyform.php | 43 +++++ .../{_contacts.php => part.contacts.php} | 2 +- apps/contacts/templates/part.details.php | 22 +++ apps/contacts/templates/part.property.php | 50 ++++++ .../templates/part.setpropertyform.php | 21 +++ apps/contacts/temporaryupdate.php | 20 +++ 27 files changed, 1085 insertions(+), 48 deletions(-) create mode 100644 apps/contacts/ajax/addcard.php create mode 100644 apps/contacts/ajax/addphoto.php create mode 100644 apps/contacts/ajax/addproperty.php create mode 100644 apps/contacts/ajax/deletebook.php create mode 100644 apps/contacts/ajax/deletecard.php create mode 100644 apps/contacts/ajax/deleteproperty.php rename apps/contacts/{details.php => ajax/getdetails.php} (87%) create mode 100644 apps/contacts/ajax/setphoto.php create mode 100644 apps/contacts/ajax/setproperty.php create mode 100644 apps/contacts/ajax/showaddcard.php create mode 100644 apps/contacts/ajax/showaddproperty.php create mode 100644 apps/contacts/ajax/showsetproperty.php delete mode 100644 apps/contacts/templates/_details.php create mode 100644 apps/contacts/templates/part.addcardform.php create mode 100644 apps/contacts/templates/part.addpropertyform.php rename apps/contacts/templates/{_contacts.php => part.contacts.php} (95%) create mode 100644 apps/contacts/templates/part.details.php create mode 100644 apps/contacts/templates/part.property.php create mode 100644 apps/contacts/templates/part.setpropertyform.php diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php new file mode 100644 index 0000000000..24766931d7 --- /dev/null +++ b/apps/contacts/ajax/addcard.php @@ -0,0 +1,54 @@ +. + * + */ + +// 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 0000000000..03d5e6b3ce --- /dev/null +++ b/apps/contacts/ajax/addphoto.php @@ -0,0 +1,59 @@ +. + * + */ + +// 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 0000000000..35b4d122bd --- /dev/null +++ b/apps/contacts/ajax/addproperty.php @@ -0,0 +1,73 @@ +. + * + */ + +// 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 0000000000..ba36c494cd --- /dev/null +++ b/apps/contacts/ajax/deletebook.php @@ -0,0 +1,44 @@ +. + * + */ + +// 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 0000000000..839936d3fa --- /dev/null +++ b/apps/contacts/ajax/deletecard.php @@ -0,0 +1,50 @@ +. + * + */ + +// 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 0000000000..9f8b5dbbaf --- /dev/null +++ b/apps/contacts/ajax/deleteproperty.php @@ -0,0 +1,62 @@ +. + * + */ + +// 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 7ab1b64de2..4ee3625afc 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 0000000000..c29b532602 --- /dev/null +++ b/apps/contacts/ajax/setphoto.php @@ -0,0 +1,77 @@ +. + * + */ + +// 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 0000000000..6f33c68631 --- /dev/null +++ b/apps/contacts/ajax/setproperty.php @@ -0,0 +1,93 @@ +. + * + */ + +// 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;$ichildren[$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 0000000000..41ebb41d3e --- /dev/null +++ b/apps/contacts/ajax/showaddcard.php @@ -0,0 +1,39 @@ +. + * + */ + +// 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 0000000000..becc39b120 --- /dev/null +++ b/apps/contacts/ajax/showaddproperty.php @@ -0,0 +1,51 @@ +. + * + */ + +// 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 0000000000..75c3ff88f5 --- /dev/null +++ b/apps/contacts/ajax/showsetproperty.php @@ -0,0 +1,62 @@ +. + * + */ + +// 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 ae2c5b9736..581bf4a717 100644 --- a/apps/contacts/carddav.php +++ b/apps/contacts/carddav.php @@ -1,4 +1,24 @@ . + * + */ // Do not load FS ... $RUNTIME_NOSETUPFS = true; diff --git a/apps/contacts/css/styles.css b/apps/contacts/css/styles.css index 8d1c8b69c3..c7680f4a71 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 1e01b1c9fb..4330c31043 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 6af160b392..0aae7d15d4 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 c0f26c7df5..b744465390 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;$ichildren 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 98e2598b3a..96a90dfc5d 100644 --- a/apps/contacts/lib/connector_sabre.php +++ b/apps/contacts/lib/connector_sabre.php @@ -1,13 +1,23 @@ . + * */ /** diff --git a/apps/contacts/templates/_details.php b/apps/contacts/templates/_details.php deleted file mode 100644 index e27b17ef2e..0000000000 --- a/apps/contacts/templates/_details.php +++ /dev/null @@ -1,4 +0,0 @@ -Name - - - \ No newline at end of file diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index ca189cb4c8..e6dd45739b 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'); ?> -
+
Addressbooks
@@ -13,12 +14,14 @@ OC_Util::addStyle('contacts','styles');
To use this addressbook, use .../apps/contacts/carddav.php/addressbooks/USERNAME/addressbookname.php
- -
+
*/ +?> +
    - inc("_contacts"); ?> + inc("part.contacts"); ?>
+ t('Add Contact'); ?>
-
- inc("_details"); ?> +
+ inc("part.details"); ?>
diff --git a/apps/contacts/templates/part.addcardform.php b/apps/contacts/templates/part.addcardform.php new file mode 100644 index 0000000000..94a59fe097 --- /dev/null +++ b/apps/contacts/templates/part.addcardform.php @@ -0,0 +1,13 @@ +
+ + + + + +
+ +
diff --git a/apps/contacts/templates/part.addpropertyform.php b/apps/contacts/templates/part.addpropertyform.php new file mode 100644 index 0000000000..ff9090b76d --- /dev/null +++ b/apps/contacts/templates/part.addpropertyform.php @@ -0,0 +1,43 @@ +
+ + +
+ +
+ +
+ 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 bf633b79b0..fa6d4790cf 100644 --- a/apps/contacts/templates/_contacts.php +++ b/apps/contacts/templates/part.contacts.php @@ -1,3 +1,3 @@ -
  • +
  • diff --git a/apps/contacts/templates/part.details.php b/apps/contacts/templates/part.details.php new file mode 100644 index 0000000000..4aca8dbc79 --- /dev/null +++ b/apps/contacts/templates/part.details.php @@ -0,0 +1,22 @@ + + + +inc('part.property', array('property' => $_['details']['FN'][0])); ?> + + inc('part.property', array('property' => $_['details']['BDAY'][0])); ?> + + + inc('part.property', array('property' => $_['details']['ORG'][0])); ?> + + + + +
    + + inc('part.property',array('property' => $property )); ?> + + + + + + diff --git a/apps/contacts/templates/part.property.php b/apps/contacts/templates/part.property.php new file mode 100644 index 0000000000..1a4266b3a2 --- /dev/null +++ b/apps/contacts/templates/part.property.php @@ -0,0 +1,50 @@ +
    + +
    t('Name'); ?>
    +
    + + +
    + +
    t('Birthday'); ?>
    +
    + l('date',new DateTime($_['property']['value'])); ?> + + +
    + +
    t('Organisation'); ?>
    +
    + + + +
    + +
    t('Email'); ?>
    +
    + + + +
    + +
    t('Telefon'); ?>
    +
    + + + +
    + +
    t('Address'); ?>
    +
    + t('PO Box'); ?>
    + t('Extended Address'); ?>
    + t('Street Name'); ?>
    + t('City'); ?>
    + t('Region'); ?>
    + t('Postal Code'); ?>
    + t('Country'); ?> + + +
    + +
    diff --git a/apps/contacts/templates/part.setpropertyform.php b/apps/contacts/templates/part.setpropertyform.php new file mode 100644 index 0000000000..cd774ee659 --- /dev/null +++ b/apps/contacts/templates/part.setpropertyform.php @@ -0,0 +1,21 @@ +
    + + + + + t('PO Box'); ?> + t('Extended Address'); ?> + t('Street Name'); ?> + t('City'); ?> + t('Region'); ?> + t('Postal Code'); ?> + t('Country'); ?> + + + + + + + + +
    diff --git a/apps/contacts/temporaryupdate.php b/apps/contacts/temporaryupdate.php index bb5ff7604f..4b6453364e 100644 --- a/apps/contacts/temporaryupdate.php +++ b/apps/contacts/temporaryupdate.php @@ -1,4 +1,24 @@ . + * + */ // Init owncloud require_once('../../lib/base.php'); $connector = new OC_Connector_Sabre_Principal;