summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax/addproperty.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/ajax/addproperty.php')
-rw-r--r--apps/contacts/ajax/addproperty.php23
1 files changed, 15 insertions, 8 deletions
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index a4b5c591197..c90af217c87 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -54,6 +54,21 @@ if(!is_array($value)){
}
$parameters = isset($_POST['parameters']) ? $_POST['parameters'] : array();
+// Prevent setting a duplicate entry
+$current = $vcard->select($name);
+foreach($current as $item) {
+ $tmpvalue = (is_array($value)?implode(';', $value):$value);
+ if($tmpvalue == $item->value) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Trying to add duplicate property: ').$name.': '.$tmpvalue)));
+ OC_Log::write('contacts','ajax/addproperty.php: Trying to add duplicate property: '.$name.': '.$tmpvalue, OC_Log::DEBUG);
+ exit();
+ }
+}
+
+if(is_array($value)) {
+ ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form!
+}
+
$property = $vcard->addProperty($name, $value); //, $parameters);
$line = count($vcard->children) - 1;
@@ -74,14 +89,6 @@ foreach ($parameters as $key=>$element) {
}
$checksum = md5($vcard->children[$line]->serialize());
-/* FIXME: OC_Contacts_App::getPropertyLineByChecksum throws an OC_JSON error when doing this check.
- Fix for v. 3.1
-if(!is_null(OC_Contacts_App::getPropertyLineByChecksum($id, $checksum))) {
- OC_JSON::error(array('data' => array('message' => $l->t('Trying to add duplicate property.'))));
- OC_Log::write('contacts','ajax/addproperty.php: Trying to add duplicate property: '.$name, OC_Log::DEBUG);
- exit();
-}
-*/
if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
OC_JSON::error(array('data' => array('message' => $l->t('Error adding contact property.'))));
OC_Log::write('contacts','ajax/addproperty.php: Error updating contact property: '.$name, OC_Log::ERROR);