summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-03-07 16:39:56 +0100
committerThomas Tanghus <thomas@tanghus.net>2012-03-07 16:39:56 +0100
commit75323b86d157c48031b9ac8c151e4a41577a1481 (patch)
tree6e047d81b17a4bcbd15e9799ef8c5209c96a0ea5 /apps/contacts/ajax
parentfaf6055baa224fbf4248a70d28ae4416c9c7eb1c (diff)
downloadnextcloud-server-75323b86d157c48031b9ac8c151e4a41577a1481.tar.gz
nextcloud-server-75323b86d157c48031b9ac8c151e4a41577a1481.zip
Contacts: UI updates and ajax methods for categories.
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r--apps/contacts/ajax/addproperty.php15
-rw-r--r--apps/contacts/ajax/categories/add.php39
-rw-r--r--apps/contacts/ajax/categories/checksumfor.php28
-rw-r--r--apps/contacts/ajax/categories/delete.php60
-rw-r--r--apps/contacts/ajax/categories/edit.php28
-rw-r--r--apps/contacts/ajax/categories/list.php17
-rw-r--r--apps/contacts/ajax/contactdetails.php2
-rw-r--r--apps/contacts/ajax/saveproperty.php32
8 files changed, 199 insertions, 22 deletions
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index 028974e1c66..a28aed34d2c 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -27,14 +27,16 @@ require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$id = $_POST['id'];
-$vcard = OC_Contacts_App::getContactVCard( $id );
+$id = isset($_POST['id'])?$_POST['id']:null;
+$name = isset($_POST['name'])?$_POST['name']:null;
+$value = isset($_POST['value'])?$_POST['value']:null;
+$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
+
+$vcard = OC_Contacts_App::getContactVCard($id);
-$name = $_POST['name'];
-$value = $_POST['value'];
if(!is_array($value)){
$value = trim($value);
- if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'NICKNAME'))) {
+ if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'NICKNAME', 'NOTE'))) {
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add empty property.'))));
exit();
}
@@ -51,7 +53,6 @@ if(!is_array($value)){
exit();
}
}
-$parameters = isset($_POST['parameters']) ? $_POST['parameters'] : array();
// Prevent setting a duplicate entry
$current = $vcard->select($name);
@@ -82,7 +83,9 @@ switch($name) {
}
case 'N':
case 'ORG':
+ case 'NOTE':
case 'NICKNAME':
+ // TODO: Escape commas and semicolons.
break;
case 'EMAIL':
$value = strtolower($value);
diff --git a/apps/contacts/ajax/categories/add.php b/apps/contacts/ajax/categories/add.php
new file mode 100644
index 00000000000..9b6c262978b
--- /dev/null
+++ b/apps/contacts/ajax/categories/add.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../../lib/base.php');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('contacts');
+
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('contacts','ajax/categories/add.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('contacts','ajax/categories/add.php: '.$msg, OC_Log::DEBUG);
+}
+
+$category = isset($_GET['category'])?strip_tags($_GET['category']):null;
+
+if(is_null($category)) {
+ bailOut(OC_Contacts_App::$l10n->t('No category to add?'));
+}
+
+debug(print_r($category, true));
+
+$categories = new OC_VCategories('contacts');
+if($categories->hasCategory($category)) {
+ bailOut(OC_Contacts_App::$l10n->t('This category already exists: '.$category));
+} else {
+ $categories->add($category, true);
+}
+
+OC_JSON::success(array('data' => array('categories'=>$categories->categories())));
+
+?>
diff --git a/apps/contacts/ajax/categories/checksumfor.php b/apps/contacts/ajax/categories/checksumfor.php
new file mode 100644
index 00000000000..ff535866bf0
--- /dev/null
+++ b/apps/contacts/ajax/categories/checksumfor.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../../lib/base.php');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('contacts');
+
+$id = isset($_GET['id'])?$_GET['id']:null;
+if(is_null($id)) {
+ OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('No ID provided'))));
+ exit();
+}
+$vcard = OC_Contacts_App::getContactVCard( $id );
+foreach($vcard->children as $property){
+ //OC_Log::write('contacts','ajax/categories/checksumfor.php: '.$property->name, OC_Log::DEBUG);
+ if($property->name == 'CATEGORIES') {
+ $checksum = md5($property->serialize());
+ OC_JSON::success(array('data' => array('checksum'=>$checksum)));
+ exit();
+ }
+}
+OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error setting checksum.'))));
+?>
diff --git a/apps/contacts/ajax/categories/delete.php b/apps/contacts/ajax/categories/delete.php
new file mode 100644
index 00000000000..3ba5aa16068
--- /dev/null
+++ b/apps/contacts/ajax/categories/delete.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../../lib/base.php');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('contacts');
+
+foreach ($_POST as $key=>$element) {
+ debug('_POST: '.$key.'=>'.print_r($element, true));
+}
+
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('contacts','ajax/categories/delete.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('contacts','ajax/categories/delete.php: '.$msg, OC_Log::DEBUG);
+}
+
+$categories = isset($_POST['categories'])?$_POST['categories']:null;
+
+if(is_null($categories)) {
+ bailOut(OC_Contacts_App::$l10n->t('No categories selected for deletion.'));
+}
+
+debug(print_r($categories, true));
+
+$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
+if(count($addressbooks) == 0) {
+ bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
+}
+$addressbookids = array();
+foreach($addressbooks as $addressbook) {
+ $addressbookids[] = $addressbook['id'];
+}
+$contacts = OC_Contacts_VCard::all($addressbookids);
+if(count($contacts) == 0) {
+ bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
+}
+
+$cards = array();
+foreach($contacts as $contact) {
+ $cards[] = array($contact['id'], $contact['carddata']);
+}
+
+debug('Before delete: '.print_r($categories, true));
+
+$catman = new OC_VCategories('contacts');
+$catman->delete($categories, $cards);
+debug('After delete: '.print_r($catman->categories(), true));
+OC_Contacts_VCard::updateDataByID($cards);
+OC_JSON::success(array('data' => array('categories'=>$catman->categories())));
+
+?>
diff --git a/apps/contacts/ajax/categories/edit.php b/apps/contacts/ajax/categories/edit.php
new file mode 100644
index 00000000000..8ecc3540b11
--- /dev/null
+++ b/apps/contacts/ajax/categories/edit.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../../lib/base.php');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('contacts');
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('contacts','ajax/categories/edit.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('contacts','ajax/categories/edit.php: '.$msg, OC_Log::DEBUG);
+}
+
+$tmpl = new OC_TEMPLATE("contacts", "part.edit_categories_dialog");
+
+$categories = OC_Contacts_App::$categories->categories();
+debug(print_r($categories, true));
+$tmpl->assign('categories',$categories);
+$tmpl->printpage();
+
+?>
diff --git a/apps/contacts/ajax/categories/list.php b/apps/contacts/ajax/categories/list.php
new file mode 100644
index 00000000000..3b41b7bfa95
--- /dev/null
+++ b/apps/contacts/ajax/categories/list.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../../lib/base.php');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('contacts');
+
+$categories = OC_Contacts_App::$categories->categories();
+
+OC_JSON::success(array('data' => array('categories'=>$categories)));
+
+?>
diff --git a/apps/contacts/ajax/contactdetails.php b/apps/contacts/ajax/contactdetails.php
index f35fd595c56..03895c862aa 100644
--- a/apps/contacts/ajax/contactdetails.php
+++ b/apps/contacts/ajax/contactdetails.php
@@ -71,5 +71,5 @@ if(isset($details['PHOTO'])) {
$details['PHOTO'] = false;
}
$details['id'] = $id;
-
+OC_Contacts_App::setLastModifiedHeader($vcard);
OC_JSON::success(array('data' => $details));
diff --git a/apps/contacts/ajax/saveproperty.php b/apps/contacts/ajax/saveproperty.php
index 6f8366243fe..e31c4b7c238 100644
--- a/apps/contacts/ajax/saveproperty.php
+++ b/apps/contacts/ajax/saveproperty.php
@@ -36,7 +36,7 @@ function debug($msg) {
OC_Log::write('contacts','ajax/saveproperty.php: '.$msg, OC_Log::DEBUG);
}
foreach ($_POST as $key=>$element) {
- debug('_POST: '.$key.'=>'.$element);
+ debug('_POST: '.$key.'=>'.print_r($element, true));
}
$id = isset($_POST['id'])?$_POST['id']:null;
@@ -51,12 +51,8 @@ $checksum = isset($_POST['checksum'])?$_POST['checksum']:null;
// }
// }
-if(is_array($value)){
- $value = array_map('strip_tags', $value);
- ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form!
- $value = OC_VObject::escapeSemicolons($value);
-} else {
- $value = trim(strip_tags($value));
+if(!$name) {
+ bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
}
if(!$id) {
bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
@@ -64,14 +60,22 @@ if(!$id) {
if(!$checksum) {
bailOut(OC_Contacts_App::$l10n->t('checksum is not set.'));
}
-if(!$name) {
- bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
+if(is_array($value)){
+ $value = array_map('strip_tags', $value);
+ ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form!
+ if($name == 'CATEGORIES') {
+ $value = OC_Contacts_VCard::escapeDelimiters($value, ',');
+ } else {
+ $value = OC_Contacts_VCard::escapeDelimiters($value, ';');
+ }
+} else {
+ $value = trim(strip_tags($value));
}
$vcard = OC_Contacts_App::getContactVCard( $id );
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
if(is_null($line)) {
- bailOut(OC_Contacts_App::$l10n->t('Information about vCard is incorrect. Please reload the page.'.$checksum.' "'.$line.'"'));
+ bailOut(OC_Contacts_App::$l10n->t('Information about vCard is incorrect. Please reload the page: ').$checksum);
}
$element = $vcard->children[$line]->name;
@@ -91,7 +95,9 @@ switch($element) {
}
case 'N':
case 'ORG':
+ case 'NOTE':
case 'NICKNAME':
+ case 'CATEGORIES':
debug('Setting string:'.$name.' '.$value);
$vcard->setString($name, $value);
break;
@@ -123,12 +129,8 @@ $checksum = md5($vcard->children[$line]->serialize());
debug('New checksum: '.$checksum);
if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
- OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error updating contact property.'))));
- OC_Log::write('contacts','ajax/setproperty.php: Error updating contact property: '.$value, OC_Log::ERROR);
+ bailOut(OC_Contacts_App::$l10n->t('Error updating contact property.'));
exit();
}
-//$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
-//$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
-
OC_JSON::success(array('data' => array( 'line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'] )));