2011-12-11 19:26:00 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2012-04-17 21:31:29 +04:00
|
|
|
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::checkLoggedIn();
|
|
|
|
OCP\JSON::checkAppEnabled('contacts');
|
2011-12-11 19:26:00 +04:00
|
|
|
|
2012-05-01 20:50:31 +04:00
|
|
|
$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
|
2012-06-17 04:29:35 +04:00
|
|
|
$contacts_alphabet = OC_Contacts_VCard::all($ids);
|
|
|
|
$active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
|
|
|
|
|
|
|
|
// Our new array for the contacts sorted by addressbook
|
|
|
|
$contacts_addressbook = array();
|
|
|
|
foreach($contacts_alphabet as $contact):
|
|
|
|
if(is_null($contacts_addressbook[$contact['addressbookid']])) {
|
|
|
|
$contacts_addressbook[$contact['addressbookid']] = array();
|
|
|
|
}
|
|
|
|
$contacts_addressbook[$contact['addressbookid']][] = $contact;
|
|
|
|
endforeach;
|
|
|
|
|
|
|
|
// FIXME: this is kind of ugly - just to replace the keys of the array
|
|
|
|
// perhaps we could do some magic combine_array() instead...
|
|
|
|
foreach($contacts_addressbook as $addressbook_id => $contacts):
|
|
|
|
foreach($active_addressbooks as $addressbook):
|
|
|
|
if($addressbook_id == $addressbook['id']) {
|
|
|
|
unset($contacts_addressbook[$addressbook_id]);
|
|
|
|
$contacts_addressbook[$addressbook['displayname']] = $contacts;
|
|
|
|
}
|
|
|
|
endforeach;
|
|
|
|
endforeach;
|
|
|
|
// This one should be ok for a small amount of Addressbooks
|
|
|
|
ksort($contacts_addressbook);
|
|
|
|
|
2012-05-07 01:00:36 +04:00
|
|
|
$tmpl = new OCP\Template("contacts", "part.contacts");
|
2012-06-17 04:29:35 +04:00
|
|
|
$tmpl->assign('contacts', $contacts_addressbook, false);
|
2011-12-11 19:26:00 +04:00
|
|
|
$page = $tmpl->fetchPage();
|
|
|
|
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::success(array('data' => array( 'page' => $page )));
|
2011-12-11 19:26:00 +04:00
|
|
|
?>
|