summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax/addaddressbook.php
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-07-15 04:15:57 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-07-15 04:17:30 +0200
commiteba4f080159f0a97f82c79f8b57b6ce45ef127b5 (patch)
tree0165b3ac9e77d4ddf36fff25521c1657c742bcd3 /apps/contacts/ajax/addaddressbook.php
parent87912a8c6595e90b3248bc84dce6e0693253b81d (diff)
downloadnextcloud-server-eba4f080159f0a97f82c79f8b57b6ce45ef127b5.tar.gz
nextcloud-server-eba4f080159f0a97f82c79f8b57b6ce45ef127b5.zip
Refactored contacts import.
Diffstat (limited to 'apps/contacts/ajax/addaddressbook.php')
-rw-r--r--apps/contacts/ajax/addaddressbook.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/apps/contacts/ajax/addaddressbook.php b/apps/contacts/ajax/addaddressbook.php
new file mode 100644
index 00000000000..3d7885fe468
--- /dev/null
+++ b/apps/contacts/ajax/addaddressbook.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * 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.
+ * See the COPYING-README file.
+ */
+
+
+// Check if we are a user
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+require_once('loghandler.php');
+
+debug('name: '.$_POST['name']);
+
+$userid = OCP\USER::getUser();
+$name = isset($_POST['name'])?trim(strip_tags($_POST['name'])):null;
+$description = isset($_POST['description'])?trim(strip_tags($_POST['description'])):null;
+
+if(is_null($name)) {
+ bailOut('Cannot add addressbook with an empty name.');
+}
+$bookid = OC_Contacts_Addressbook::add($userid, $name, $description);
+if(!$bookid) {
+ bailOut('Error adding addressbook: '.$name);
+}
+
+if(!OC_Contacts_Addressbook::setActive($bookid, 1)) {
+ bailOut('Error activating addressbook.');
+}
+$addressbook = OC_Contacts_App::getAddressbook($bookid);
+OCP\JSON::success(array('data' => $addressbook));