1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-11 22:24:32 +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.');
}
$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);
2012-08-02 19:03:45 +02:00
OCP\JSON::success(array('data' => array('addressbook' => $addressbook)));