File: /home/centralexf/www/components/com_qcontacts/controllers/vcard.php
<?php
/**
* QContacts Contact manager component for Joomla! 1.5
*
* @version 1.0.6
* @package qcontacts
* @author Massimo Giagnoni
* @copyright Copyright (C) 2008 Massimo Giagnoni. All rights reserved.
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
/*
This file is part of QContacts.
QContacts is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
defined('_JEXEC') or die('Restricted access');
class QContactsControllerVCard extends QContactsController {
function display() {
global $mainframe;
// Initialize some variables
$db = & JFactory::getDBO();
$SiteName = $mainframe->getCfg('sitename');
$contactId = JRequest::getVar('contact_id', 0, '', 'int');
// Get a Contact table object and load the selected contact details
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_qcontacts'.DS.'tables');
$contact =& JTable::getInstance('contact', 'Table');
$contact->load($contactId);
// Get the contact detail parameters
$pparams = &$mainframe->getParams('com_qcontacts');
$params = new JParameter($contact->params);
$vc = $params->get('allow_vcard');
if($vc == '') {
$vc = $pparams->get('allow_vcard');
}
// Should we show the vcard?
if ($vc)
{
// Parse the contact name field and build the nam information for the vcard.
$firstname = null;
$middlename = null;
$surname = null;
// How many parts do we have?
$parts = explode(' ', $contact->name);
$count = count($parts);
switch ($count) {
case 1 :
// only a first name
$firstname = $parts[0];
break;
case 2 :
// first and last name
$firstname = $parts[0];
$surname = $parts[1];
break;
default :
// we have full name info
$firstname = $parts[0];
$surname = $parts[$count -1];
for ($i = 1; $i < $count -1; $i ++) {
$middlename .= $parts[$i].' ';
}
break;
}
// quick cleanup for the middlename value
$middlename = trim($middlename);
// Create a new vcard object and populate the fields
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_qcontacts'.DS.'helpers'.DS.'vcard.php');
$v = new JvCard();
$v->setPhoneNumber($contact->telephone, 'PREF;WORK;VOICE');
$v->setPhoneNumber($contact->fax, 'WORK;FAX');
$v->setName($surname, $firstname, $middlename, '');
$v->setAddress('', '', $contact->address, $contact->suburb, $contact->state, $contact->postcode, $contact->country, 'WORK;POSTAL');
$v->setEmail($contact->email_to);
$v->setNote($contact->misc);
$v->setURL( JURI::base(), 'WORK');
$v->setTitle($contact->con_position);
$v->setOrg($SiteName);
$filename = str_replace(' ', '_', $contact->name);
$v->setFilename($filename);
$output = $v->getVCard($SiteName);
$filename = $v->getFileName();
// Send vCard file headers
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Length: '.strlen($output));
header('Connection: close');
header('Content-Type: text/x-vCard; name='.$filename);
header('Cache-Control: store, cache');
header('Pragma: cache');
print $output;
} else {
JError::raiseWarning('SOME_ERROR_CODE', 'ContactController::vCard: '.JText::_('NOTAUTH'));
return false;
}
}
}
?>