OC_Cache::set($progresskey, $pct, 300); } writeProgress('10'); $view = $file = null; if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') { $view = OCP\Files::getStorage('contacts'); $file = $view->file_get_contents('/imports/' . $_POST['file']); } else { $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); } if (!$file) { OCP\JSON::error(array('data' => array('message' => 'Import file was empty.'))); exit; } if (isset($_POST['method']) && $_POST['method'] == 'new') { $id = OCA\Contacts\Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']); if (!$id) { OCP\JSON::error(array('data' => array('message' => 'Error creating address book.'))); exit; } OCA\Contacts\Addressbook::setActive($id, 1); } else { $id = $_POST['id']; if (!$id) { OCP\JSON::error(array('data' => array('message' => 'Error getting the ID of the address book.', 'file' => $_POST['file']))); exit; } try { OCA\Contacts\Addressbook::find($id); // is owner access check } catch (Exception $e) {
<?php /** * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**> * Copyright (c) 2011 Bart Visscher <*****@*****.**> * 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 __DIR__ . '/../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 = OCA\Contacts\Addressbook::add($userid, $name, $description); if (!$bookid) { bailOut('Error adding addressbook: ' . $name); } if (!OCA\Contacts\Addressbook::setActive($bookid, 1)) { bailOut('Error activating addressbook.'); } $addressbook = OCA\Contacts\Addressbook::find($bookid); OCP\JSON::success(array('data' => array('addressbook' => $addressbook)));