summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax/setproperty.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/ajax/setproperty.php')
-rw-r--r--apps/contacts/ajax/setproperty.php49
1 files changed, 13 insertions, 36 deletions
diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php
index c9102c4a2ee..bcc4c161cc0 100644
--- a/apps/contacts/ajax/setproperty.php
+++ b/apps/contacts/ajax/setproperty.php
@@ -23,48 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_POST['id'];
-$checksum = $_POST['checksum'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
-
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
+$id = $_POST['id'];
+$checksum = $_POST['checksum'];
-$line = null;
-for($i=0;$i<count($vcard->children);$i++){
- if(md5($vcard->children[$i]->serialize()) == $checksum ){
- $line = $i;
- }
-}
-if(is_null($line)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
- exit();
-}
+$vcard = OC_Contacts_App::getContactVCard( $id );
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
// Set the value
$value = $_POST['value'];
if(is_array($value)){
- $value = OC_Contacts_VCard::escapeSemicolons($value);
+ $value = OC_VObject::escapeSemicolons($value);
}
$vcard->children[$line]->setValue($value);
@@ -104,10 +76,15 @@ $checksum = md5($vcard->children[$line]->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize());
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
-$tmpl = new OC_Template('contacts','part.property');
+if ($vcard->children[$line]->name == 'FN'){
+ $tmpl = new OC_Template('contacts','part.property.FN');
+}
+else{
+ $tmpl = new OC_Template('contacts','part.property');
+}
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line));