1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-10 21:24:33 +01:00
OwncloudContactsOfficial/index.php

92 lines
2.8 KiB
PHP
Raw Normal View History

2011-08-06 22:32:06 +02: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 23:29:25 +02:00
function contacts_namesort($a,$b){
return strcmp($a['fullname'],$b['fullname']);
2011-08-06 22:32:06 +02:00
}
// Init owncloud
require_once('../../lib/base.php');
// Check if we are a user
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
2011-08-06 22:32:06 +02:00
// Get active address books. This creates a default one if none exists.
$ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser());
$contacts = OC_Contacts_VCard::all($ids);
2011-12-16 17:42:07 +01:00
$addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser());
2011-08-06 23:29:25 +02:00
2011-08-06 22:32:06 +02: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 23:29:25 +02:00
// sort addressbooks (use contactsort)
usort($addressbooks,'contacts_namesort');
2011-08-06 22:32:06 +02:00
$contacts = array();
foreach( $addressbooks as $addressbook ){
$addressbookcontacts = OC_Contacts_VCard::all($addressbook['id']);
2011-08-06 22:32:06 +02:00
foreach( $addressbookcontacts as $contact ){
2011-09-08 23:36:47 +02:00
if(is_null($contact['fullname'])){
continue;
}
$contacts[] = $contact;
2011-08-06 22:32:06 +02:00
}
}
2011-08-06 23:29:25 +02:00
usort($contacts,'contacts_namesort');
*/
$details = array();
// FIXME: This cannot work..?
if( !is_null($id)/* || count($contacts)*/){
2011-08-09 13:53:58 +02:00
if(is_null($id)) $id = $contacts[0]['id'];
$vcard = OC_Contacts_App::getContactVCard($id);
$details = OC_Contacts_VCard::structureContact($vcard);
2011-08-06 22:32:06 +02: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');
$property_types = OC_Contacts_App::getAddPropertyOptions();
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
2011-08-06 22:32:06 +02:00
// Process the template
$tmpl = new OC_Template( 'contacts', 'index', 'user' );
$tmpl->assign('property_types',$property_types);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
2011-08-06 23:29:25 +02:00
$tmpl->assign('addressbooks', $addressbooks);
2011-08-06 22:32:06 +02:00
$tmpl->assign('contacts', $contacts);
$tmpl->assign('details', $details );
$tmpl->assign('id',$id);
$tmpl->printPage();