2011-08-06 20:32:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud - Addressbook
|
|
|
|
*
|
|
|
|
* @author Jakob Sack
|
|
|
|
* @copyright 2011 Jakob Sack mail@jakobsack.de
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-08-06 21:29:25 +00:00
|
|
|
function contacts_namesort($a,$b){
|
2011-08-06 20:32:06 +00:00
|
|
|
return strcmp($a['name'],$b['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init owncloud
|
|
|
|
require_once('../../lib/base.php');
|
|
|
|
|
|
|
|
// Check if we are a user
|
|
|
|
if( !OC_User::isLoggedIn()){
|
|
|
|
header( 'Location: '.OC_Helper::linkTo( '', 'index.php' ));
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2011-08-06 21:29:25 +00:00
|
|
|
// Check if the user has an addressbook
|
2011-09-16 22:26:57 +00:00
|
|
|
$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
|
2011-08-06 21:29:25 +00:00
|
|
|
if( count($addressbooks) == 0){
|
2011-09-16 22:26:57 +00:00
|
|
|
OC_Contacts_Addressbook::add(OC_User::getUser(),'default','Default Address Book');
|
|
|
|
$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
|
2011-08-09 12:49:28 +00:00
|
|
|
}
|
|
|
|
$prefbooks = OC_Preferences::getValue(OC_User::getUser(),'contacts','openaddressbooks',null);
|
|
|
|
if(is_null($prefbooks)){
|
|
|
|
$prefbooks = $addressbooks[0]['id'];
|
|
|
|
OC_Preferences::setValue(OC_User::getUser(),'contacts','openaddressbooks',$prefbooks);
|
2011-08-06 21:29:25 +00:00
|
|
|
}
|
|
|
|
|
2011-08-06 20:32:06 +00:00
|
|
|
// Load the files we need
|
|
|
|
OC_App::setActiveNavigationEntry( 'contacts_index' );
|
|
|
|
|
|
|
|
// Load a specific user?
|
|
|
|
$id = isset( $_GET['id'] ) ? $_GET['id'] : null;
|
|
|
|
|
2011-08-06 21:29:25 +00:00
|
|
|
// sort addressbooks (use contactsort)
|
|
|
|
usort($addressbooks,'contacts_namesort');
|
2011-08-06 20:32:06 +00:00
|
|
|
// Addressbooks to load
|
2011-08-09 12:49:28 +00:00
|
|
|
$openaddressbooks = explode(';',$prefbooks);
|
2011-08-06 20:32:06 +00:00
|
|
|
|
|
|
|
$contacts = array();
|
|
|
|
foreach( $openaddressbooks as $addressbook ){
|
2011-09-16 22:26:57 +00:00
|
|
|
$addressbookcontacts = OC_Contacts_VCard::all($addressbook);
|
2011-08-06 20:32:06 +00:00
|
|
|
foreach( $addressbookcontacts as $contact ){
|
2011-09-08 21:36:47 +00:00
|
|
|
if(is_null($contact['fullname'])){
|
|
|
|
continue;
|
|
|
|
}
|
2011-08-06 20:32:06 +00:00
|
|
|
$contacts[] = array( 'name' => $contact['fullname'], 'id' => $contact['id'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-06 21:29:25 +00:00
|
|
|
usort($contacts,'contacts_namesort');
|
2011-08-06 20:32:06 +00:00
|
|
|
$details = array();
|
|
|
|
|
|
|
|
if( !is_null($id) || count($contacts)){
|
2011-08-09 11:53:58 +00:00
|
|
|
if(is_null($id)) $id = $contacts[0]['id'];
|
2011-09-16 22:26:57 +00:00
|
|
|
$contact = OC_Contacts_VCard::find($id);
|
|
|
|
$vcard = OC_Contacts_VCard::parse($contact['carddata']);
|
|
|
|
$details = OC_Contacts_VCard::structureContact($vcard);
|
2011-08-06 20:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process the template
|
|
|
|
$tmpl = new OC_Template( 'contacts', 'index', 'user' );
|
2011-08-06 21:29:25 +00:00
|
|
|
$tmpl->assign('addressbooks', $addressbooks);
|
2011-08-06 20:32:06 +00:00
|
|
|
$tmpl->assign('contacts', $contacts);
|
|
|
|
$tmpl->assign('details', $details );
|
|
|
|
$tmpl->assign('id',$id);
|
|
|
|
$tmpl->printPage();
|