summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-01-11 20:07:15 +0100
committerThomas Tanghus <thomas@tanghus.net>2012-01-11 20:07:15 +0100
commit237ba65a20edfbd346405e03583a96808602a2ca (patch)
treee101b9a441ac0e4704affabb3293da897c07c11d /apps/contacts/ajax
parenteae3e134ff9005e50ea4e611b2c2daba94ad49ea (diff)
downloadnextcloud-server-237ba65a20edfbd346405e03583a96808602a2ca.tar.gz
nextcloud-server-237ba65a20edfbd346405e03583a96808602a2ca.zip
Localizin strings and adding error checking.
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r--apps/contacts/ajax/activation.php9
-rw-r--r--apps/contacts/ajax/addcard.php7
-rw-r--r--apps/contacts/ajax/addproperty.php6
-rw-r--r--apps/contacts/ajax/createaddressbook.php14
-rw-r--r--apps/contacts/ajax/deleteproperty.php8
-rw-r--r--apps/contacts/ajax/setproperty.php7
-rw-r--r--apps/contacts/ajax/updateaddressbook.php17
7 files changed, 59 insertions, 9 deletions
diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php
index f4a2c94a148..fda63a528a4 100644
--- a/apps/contacts/ajax/activation.php
+++ b/apps/contacts/ajax/activation.php
@@ -10,10 +10,17 @@
require_once ("../../../lib/base.php");
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
+$l=new OC_L10N('contacts');
+
$bookid = $_POST['bookid'];
-OC_Contacts_Addressbook::setActive($bookid, $_POST['active']);
+if(!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Error (de)activating addressbook.'))));
+ OC_Log::write('contacts','ajax/activation.php: Error activating addressbook: '.$bookid, OC_Log::ERROR);
+ exit();
+}
$book = OC_Contacts_App::getAddressbook($bookid);
+
/* is there an OC_JSON::error() ? */
OC_JSON::success(array(
'active' => OC_Contacts_Addressbook::isActive($bookid),
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
index 9d9a99de33c..7e47659d23b 100644
--- a/apps/contacts/ajax/addcard.php
+++ b/apps/contacts/ajax/addcard.php
@@ -26,6 +26,7 @@ require_once('../../../lib/base.php');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
+$l=new OC_L10N('contacts');
$aid = $_POST['id'];
$addressbook = OC_Contacts_App::getAddressbook( $aid );
@@ -74,5 +75,11 @@ foreach( $add as $propname){
}
}
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
+if(!$id) {
+ OC_JSON::error(array('data' => array('message' => $l->t('There was an error adding the contact.'))));
+ OC_Log::write('contacts','ajax/addcard.php: Recieved non-positive ID on adding card: '.$name, OC_Log::ERROR);
+ exit();
+}
+// NOTE: Why is this in OC_Contacts_App?
OC_Contacts_App::renderDetails($id, $vcard);
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index 74f1c3d0e9e..6e3ba3566c0 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -61,7 +61,11 @@ foreach ($parameters as $key=>$element) {
}
}
-OC_Contacts_VCard::edit($id,$vcard->serialize());
+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);
+ exit();
+}
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php
index f94ad34e8dc..edcf794f497 100644
--- a/apps/contacts/ajax/createaddressbook.php
+++ b/apps/contacts/ajax/createaddressbook.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
+ * Copyright (c) 2011-2012 Thomas Tanghus <thomas@tanghus.net>
* Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
@@ -16,7 +16,17 @@ OC_JSON::checkAppEnabled('contacts');
$userid = OC_User::getUser();
$bookid = OC_Contacts_Addressbook::add($userid, $_POST['name'], null);
-OC_Contacts_Addressbook::setActive($bookid, 1);
+if(!$bookid) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Error adding addressbook.'))));
+ OC_Log::write('contacts','ajax/createaddressbook.php: Error adding addressbook: '.$_POST['name'], OC_Log::ERROR);
+ exit();
+}
+
+if(!OC_Contacts_Addressbook::setActive($bookid, 1)) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Error activating addressbook.'))));
+ OC_Log::write('contacts','ajax/createaddressbook.php: Error activating addressbook: '.$bookid, OC_Log::ERROR);
+ //exit();
+}
$addressbook = OC_Contacts_App::getAddressbook($bookid);
$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $addressbook);
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
index f69735e61c6..89cf292f4f8 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -26,6 +26,7 @@ require_once('../../../lib/base.php');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
+$l10n = new OC_L10N('contacts');
$id = $_GET['id'];
$checksum = $_GET['checksum'];
@@ -35,5 +36,10 @@ $line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
unset($vcard->children[$line]);
-OC_Contacts_VCard::edit($id,$vcard->serialize());
+if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Error deleting contact property.'))));
+ OC_Log::write('contacts','ajax/deleteproperty.php: Error deleting contact property', OC_Log::ERROR);
+ exit();
+}
+
OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php
index bcc4c161cc0..e0cd70236c8 100644
--- a/apps/contacts/ajax/setproperty.php
+++ b/apps/contacts/ajax/setproperty.php
@@ -72,9 +72,14 @@ foreach($missingparameters as $i){
}
// Do checksum and be happy
+// NOTE: This checksum is not used..?
$checksum = md5($vcard->children[$line]->serialize());
-OC_Contacts_VCard::edit($id,$vcard->serialize());
+if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Error updating contact property.'))));
+ OC_Log::write('contacts','ajax/setproperty.php: Error updating contact property: '.$value, OC_Log::ERROR);
+ exit();
+}
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/updateaddressbook.php
index 516736cc502..7d9e2aea917 100644
--- a/apps/contacts/ajax/updateaddressbook.php
+++ b/apps/contacts/ajax/updateaddressbook.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * Copyright (c) 2011-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.
@@ -15,8 +15,19 @@ OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$bookid = $_POST['id'];
-OC_Contacts_Addressbook::edit($bookid, $_POST['name'], null);
-OC_Contacts_Addressbook::setActive($bookid, $_POST['active']);
+
+if(!OC_Contacts_Addressbook::edit($bookid, $_POST['name'], null)) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Error updating addressbook.'))));
+ OC_Log::write('contacts','ajax/updateaddressbook.php: Error adding addressbook: ', OC_Log::ERROR);
+ //exit();
+}
+
+if(!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
+ OC_JSON::error(array('data' => array('message' => $l->t('Error (de)activating addressbook.'))));
+ OC_Log::write('contacts','ajax/updateaddressbook.php: Error (de)activating addressbook: '.$bookid, OC_Log::ERROR);
+ //exit();
+}
+
$addressbook = OC_Contacts_App::getAddressbook($bookid);
$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $addressbook);