1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-02 14:24:10 +01:00
OwncloudContactsOfficial/ajax/addressbook/add.php

38 lines
1.1 KiB
PHP
Raw Normal View History

2012-07-15 04:15:57 +02:00
<?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.
*/
2012-07-15 04:15:57 +02:00
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once __DIR__.'/../loghandler.php';
2012-07-15 04:15:57 +02:00
debug('name: '.$_POST['name']);
$userid = OCP\USER::getUser();
$name = isset($_POST['name'])?trim(strip_tags($_POST['name'])):null;
2012-07-19 23:48:17 +02:00
$description = isset($_POST['description'])
? trim(strip_tags($_POST['description']))
: null;
2012-07-15 04:15:57 +02:00
if(is_null($name)) {
bailOut('Cannot add addressbook with an empty name.');
}
2012-10-25 03:34:12 +02:00
$bookid = OCA\Contacts\Addressbook::add($userid, $name, $description);
2012-07-15 04:15:57 +02:00
if(!$bookid) {
bailOut('Error adding addressbook: '.$name);
}
2012-10-25 03:34:12 +02:00
if(!OCA\Contacts\Addressbook::setActive($bookid, 1)) {
2012-07-15 04:15:57 +02:00
bailOut('Error activating addressbook.');
}
2012-10-25 03:34:12 +02:00
$addressbook = OCA\Contacts\Addressbook::find($bookid);
2012-08-02 19:03:45 +02:00
OCP\JSON::success(array('data' => array('addressbook' => $addressbook)));