2011-08-07 00:32:06 +04: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-07 01:29:25 +04:00
|
|
|
function contacts_namesort($a,$b){
|
2011-12-09 18:10:51 +04:00
|
|
|
return strcmp($a['fullname'],$b['fullname']);
|
2011-08-07 00:32:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init owncloud
|
|
|
|
require_once('../../lib/base.php');
|
|
|
|
|
|
|
|
// Check if we are a user
|
2011-09-18 23:31:56 +04:00
|
|
|
OC_Util::checkLoggedIn();
|
2011-10-01 01:05:10 +04:00
|
|
|
OC_Util::checkAppEnabled('contacts');
|
2011-08-07 00:32:06 +04:00
|
|
|
|
2011-12-11 19:26:00 +04:00
|
|
|
// Get active address books. This creates a default one if none exists.
|
|
|
|
$addressbooks = OC_Contacts_Addressbook::activeAddressbooks(OC_User::getUser());
|
2011-08-07 01:29:25 +04:00
|
|
|
|
2011-08-07 00:32:06 +04:00
|
|
|
// Load the files we need
|
|
|
|
OC_App::setActiveNavigationEntry( 'contacts_index' );
|
|
|
|
|
|
|
|
// Load a specific user?
|
|
|
|
$id = isset( $_GET['id'] ) ? $_GET['id'] : null;
|
|
|
|
|
2011-08-07 01:29:25 +04:00
|
|
|
// sort addressbooks (use contactsort)
|
|
|
|
usort($addressbooks,'contacts_namesort');
|
2011-08-07 00:32:06 +04:00
|
|
|
|
|
|
|
$contacts = array();
|
2011-12-11 19:26:00 +04:00
|
|
|
foreach( $addressbooks as $addressbook ){
|
|
|
|
$addressbookcontacts = OC_Contacts_VCard::all($addressbook['id']);
|
2011-08-07 00:32:06 +04:00
|
|
|
foreach( $addressbookcontacts as $contact ){
|
2011-09-09 01:36:47 +04:00
|
|
|
if(is_null($contact['fullname'])){
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-09 18:10:51 +04:00
|
|
|
$contacts[] = $contact;
|
2011-08-07 00:32:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-07 01:29:25 +04:00
|
|
|
usort($contacts,'contacts_namesort');
|
2011-08-07 00:32:06 +04:00
|
|
|
|
2011-12-07 01:33:20 +04:00
|
|
|
$details = array();
|
|
|
|
if( !is_null($id)/* || count($contacts)*/){
|
2011-08-09 15:53:58 +04:00
|
|
|
if(is_null($id)) $id = $contacts[0]['id'];
|
2011-12-07 01:31:04 +04:00
|
|
|
$vcard = OC_Contacts_App::getContactVCard($id);
|
2011-09-17 02:26:57 +04:00
|
|
|
$details = OC_Contacts_VCard::structureContact($vcard);
|
2011-08-07 00:32:06 +04:00
|
|
|
}
|
|
|
|
|
2011-12-04 23:25:46 +04:00
|
|
|
// Include Style and Script
|
|
|
|
OC_Util::addScript('contacts','interface');
|
|
|
|
OC_Util::addStyle('contacts','styles');
|
|
|
|
OC_Util::addStyle('contacts','formtastic');
|
|
|
|
OC_Util::addScript('', 'jquery.multiselect');
|
|
|
|
OC_Util::addStyle('', 'jquery.multiselect');
|
|
|
|
|
2011-12-07 01:31:04 +04:00
|
|
|
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
|
|
|
|
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
|
2011-12-09 18:10:51 +04:00
|
|
|
|
2011-08-07 00:32:06 +04:00
|
|
|
// Process the template
|
|
|
|
$tmpl = new OC_Template( 'contacts', 'index', 'user' );
|
2011-11-18 02:54:14 +04:00
|
|
|
$tmpl->assign('adr_types',$adr_types);
|
|
|
|
$tmpl->assign('phone_types',$phone_types);
|
2011-08-07 01:29:25 +04:00
|
|
|
$tmpl->assign('addressbooks', $addressbooks);
|
2011-08-07 00:32:06 +04:00
|
|
|
$tmpl->assign('contacts', $contacts);
|
|
|
|
$tmpl->assign('details', $details );
|
|
|
|
$tmpl->assign('id',$id);
|
|
|
|
$tmpl->printPage();
|