Example #1
0
/**
 * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
$bookid = isset($_GET['bookid']) ? $_GET['bookid'] : null;
$contactid = isset($_GET['contactid']) ? $_GET['contactid'] : null;
$selectedids = isset($_GET['selectedids']) ? $_GET['selectedids'] : null;
$nl = "\n";
if (!is_null($bookid)) {
    try {
        $addressbook = OCA\Contacts\Addressbook::find($bookid);
    } catch (Exception $e) {
        OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
        exit;
    }
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
    $start = 0;
    $batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20);
    while ($cardobjects = OCA\Contacts\VCard::all($bookid, $start, $batchsize, array('carddata'))) {
        foreach ($cardobjects as $card) {
            echo $card['carddata'] . $nl;
        }
        $start += $batchsize;
    }
} elseif (!is_null($contactid)) {
Example #2
0
    if ($a['fullname'] == $b['fullname']) {
        return 0;
    }
    return $a['fullname'] < $b['fullname'] ? -1 : 1;
}
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$aid = isset($_GET['aid']) ? $_GET['aid'] : null;
$active_addressbooks = array();
if (is_null($aid)) {
    // Called initially to get the active addressbooks.
    $active_addressbooks = OCA\Contacts\Addressbook::active(OCP\USER::getUser());
} else {
    // called each time more contacts has to be shown.
    $active_addressbooks = array(OCA\Contacts\Addressbook::find($aid));
}
$lastModified = OCA\Contacts\App::lastModified();
if (!is_null($lastModified)) {
    OCP\Response::enableCaching();
    OCP\Response::setLastModifiedHeader($lastModified);
    OCP\Response::setETagHeader(md5($lastModified->format('U')));
}
session_write_close();
// create the addressbook associate array
$contacts_addressbook = array();
$ids = array();
foreach ($active_addressbooks as $addressbook) {
    $ids[] = $addressbook['id'];
    /*if(!isset($contacts_addressbook[$addressbook['id']])) {
    		$contacts_addressbook[$addressbook['id']]
Example #3
0
/**
* @author  Victor Dubiniuk
* Copyright (c) 2012 Victor Dubiniuk <*****@*****.**>
* Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
$id = intval($_POST['id']);
$aid = intval($_POST['aid']);
$isaddressbook = isset($_POST['isaddressbook']) ? true : false;
// Ownership checking
try {
    OCA\Contacts\Addressbook::find($id);
    // is owner access check
} catch (Exception $e) {
    OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
    exit;
}
try {
    OCA\Contacts\VCard::moveToAddressBook($aid, $id, $isaddressbook);
} catch (Exception $e) {
    $msg = $e->getMessage();
    OCP\Util::writeLog('contacts', 'Error moving contacts "' . implode(',', $id) . '" to addressbook "' . $aid . '"' . $msg, OCP\Util::ERROR);
    OC_JSON::error(array('data' => array('message' => $msg)));
    exit;
}
OC_JSON::success(array('data' => array('ids' => $id)));
Example #4
0
<?php

/**
 * Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$catmgr = OCA\Contacts\App::getVCategories();
$categories = $catmgr->categories(OC_VCategories::FORMAT_MAP);
foreach ($categories as &$category) {
    $ids = array();
    $contacts = $catmgr->itemsForCategory($category['name'], array('tablename' => '*PREFIX*contacts_cards', 'fields' => array('id')));
    foreach ($contacts as $contact) {
        $ids[] = $contact['id'];
    }
    $category['contacts'] = $ids;
}
$favorites = $catmgr->getFavorites();
// workaround for https://github.com/owncloud/core/issues/2814
$sharedAddressbooks = array();
$maybeSharedAddressBook = OCP\Share::getItemsSharedWith('addressbook', OCA\Contacts\Share_Backend_Addressbook::FORMAT_ADDRESSBOOKS);
foreach ($maybeSharedAddressBook as $sharedAddressbook) {
    if (isset($sharedAddressbook['id']) && OCA\Contacts\Addressbook::find($sharedAddressbook['id'])) {
        $sharedAddressbooks[] = $sharedAddressbook;
    }
}
OCP\JSON::success(array('data' => array('categories' => $categories, 'favorites' => $favorites, 'shared' => $sharedAddressbooks, 'lastgroup' => OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'lastgroup', 'all'), 'sortorder' => OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'groupsort', ''))));