Revize 1704
Přidáno uživatelem David Raška před asi 12 roky(ů)
freenetis/branches/1.1/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'export device templates' => 'Export šablon zařízení',
|
||
'export of device' => 'Export zařízení',
|
||
'export of registration' => 'Export přihlášky',
|
||
'export only main users' => 'Exportovat pouze hlavní uživatele',
|
||
'export to xls' => 'Exportovat do XLS',
|
||
'export to csv' => 'Exportovat do CSV',
|
||
'export vcard' => 'Exportovat vCard',
|
||
'expiry time of registration' => 'Čas vypršení registrace',
|
||
'facility' => 'Služba',
|
||
'failed' => 'Selhání',
|
freenetis/branches/1.1/application/controllers/users.php | ||
---|---|---|
'limit_results' => $limit_results,
|
||
'filter' => $filter_form
|
||
));
|
||
|
||
// export vCard
|
||
$grid->add_new_button(
|
||
'vcard/export' . server::query_string(),
|
||
'Export vCard', array
|
||
(
|
||
'title' => __('Export vCard'),
|
||
'class' => 'popup_link'
|
||
)
|
||
);
|
||
|
||
$grid->order_field('id')
|
||
->label('ID');
|
freenetis/branches/1.1/application/controllers/vcard.php | ||
---|---|---|
<?php
|
||
|
||
defined('SYSPATH') or die('No direct script access.');
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is released under GPLv3 licence.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*
|
||
*/
|
||
|
||
/**
|
||
* Handles export of users contacts in vCard format
|
||
*
|
||
* @author David Raška
|
||
* @package Controller
|
||
*/
|
||
class Vcard_Controller extends Controller
|
||
{
|
||
/**
|
||
* Function exports contacts of members to vCard file
|
||
*
|
||
* @author David Raška
|
||
*/
|
||
public function export()
|
||
{
|
||
if (!$this->acl_check_view('Members_Controller', 'members'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$form = new Forge();
|
||
|
||
$form->set_attr('class', 'form nopopup');
|
||
|
||
$form->dropdown('format')
|
||
->options( array
|
||
(
|
||
'vcard21' => 'vCard 2.1',
|
||
'vcard40' => 'vCard 4.0',
|
||
))
|
||
->selected('vcard40');
|
||
|
||
$form->checkbox('main_only')
|
||
->label('Export only main users');
|
||
|
||
$form->submit('Submit');
|
||
|
||
if ($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
$main_only = (isset($form_data['main_only']) && $form_data['main_only'] == '1');
|
||
|
||
$filter_form = new Filter_form('u');
|
||
$filter_form->autoload();
|
||
|
||
$user = new User_Model();
|
||
|
||
try
|
||
{
|
||
$items = $user->get_all_users(0, 50, 'id', 'ASC', $filter_form->as_sql());
|
||
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$items = array();
|
||
}
|
||
|
||
// empty result?
|
||
if (!count($items))
|
||
{
|
||
status::error('Invalid data - no data available');
|
||
}
|
||
else
|
||
{
|
||
/* Generate file */
|
||
|
||
// set content header
|
||
header('Content-type: text/vcard');
|
||
header('Content-Disposition: attachment; filename="'.__('Members').'.vcf"');
|
||
|
||
switch ($form_data['format'])
|
||
{
|
||
case 'vcard21':
|
||
echo self::vcard21($items, $main_only);
|
||
break;
|
||
case 'vcard40':
|
||
default:
|
||
echo self::vcard40($items, $main_only);
|
||
}
|
||
|
||
// do not display view
|
||
die();
|
||
}
|
||
}
|
||
|
||
$title = __('Export');
|
||
|
||
$view = new View('main');
|
||
$view->title = $title;
|
||
$view->content = new View('form');
|
||
$view->content->headline = $title;
|
||
$view->content->form = $form;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Function Generates vCard in version 4.0
|
||
*
|
||
* @param array $users Array of all users
|
||
* @param bool $main_only Export only main users
|
||
*/
|
||
private function vcard40($users = NULL, $main_only = false)
|
||
{
|
||
$vCard = '';
|
||
|
||
/* Generate vCard for each user */
|
||
foreach ($users AS $user)
|
||
{
|
||
/* Skip all users except main users */
|
||
if ($main_only && $user->type != User_Model::MAIN_USER)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
$pre_title = empty($user->pre_title) ? '' : "$user->pre_title ";
|
||
$name = empty($user->name) ? '' : "$user->name ";
|
||
$middle_name = empty($user->middle_name) ? '' : "$user->middle_name ";
|
||
$post_title = empty($user->post_title) ? '' : " $user->post_title";
|
||
|
||
/* Begining of vCard */
|
||
$vCard .=
|
||
"BEGIN:VCARD\n".
|
||
"VERSION:4.0\n".
|
||
"N:$user->surname;$user->name;$user->middle_name;$user->pre_title;$user->post_title\n".
|
||
"FN:$pre_title$name$middle_name$user->surname$post_title\n";
|
||
|
||
$cm = new Contact_Model();
|
||
$contacts = $cm->find_all_users_contacts($user->id);
|
||
|
||
/* Add all contacts of user */
|
||
foreach ($contacts AS $c)
|
||
{
|
||
$unknown = false;
|
||
|
||
switch ($c->type)
|
||
{
|
||
case Contact_Model::TYPE_ICQ:
|
||
$vCard .= "X-ICQ:";
|
||
break;
|
||
case Contact_Model::TYPE_JABBER:
|
||
$vCard .= "X-JABBER:";
|
||
break;
|
||
case Contact_Model::TYPE_EMAIL:
|
||
$vCard .= "EMAIL;TYPE=PREF,INTERNET:";
|
||
break;
|
||
case Contact_Model::TYPE_PHONE:
|
||
$vCard .= "TEL;TYPE=HOME,VOICE:+";
|
||
break;
|
||
case Contact_Model::TYPE_SKYPE:
|
||
$vCard .= "X-SKYPE:";
|
||
break;
|
||
case Contact_Model::TYPE_MSN:
|
||
$vCard .= "X-MSN:";
|
||
break;
|
||
case Contact_Model::TYPE_WEB:
|
||
$vCard .= "URL:";
|
||
break;
|
||
default:
|
||
$vCard .= "";
|
||
$unknown = true;
|
||
break;
|
||
}
|
||
|
||
if (!$unknown)
|
||
{
|
||
$vCard .= "$c->value\n";
|
||
}
|
||
}
|
||
|
||
$vCard .= "END:VCARD\n\n";
|
||
}
|
||
|
||
return $vCard;
|
||
}
|
||
|
||
/**
|
||
* Function Generates vCard in version 2.1
|
||
*
|
||
* @param array $users Array of all users
|
||
* @param bool $main_only Export only main users
|
||
*/
|
||
private function vcard21($users = NULL, $main_only = false)
|
||
{
|
||
$vCard = '';
|
||
|
||
/* Generate vCard for each user */
|
||
foreach ($users AS $user)
|
||
{
|
||
/* Skip all users except main users */
|
||
if ($main_only && $user->type != User_Model::MAIN_USER)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
$name = empty($user->name) ? '' : "$user->name ";
|
||
|
||
/* Begining of vCard */
|
||
$vCard .=
|
||
"BEGIN:VCARD\n".
|
||
"VERSION:2.1\n".
|
||
"N:$user->surname;$user->name\n".
|
||
"FN:$name$user->surname\n";
|
||
|
||
$cm = new Contact_Model();
|
||
$contacts = $cm->find_all_users_contacts($user->id);
|
||
|
||
/* Add all contacts of user */
|
||
foreach ($contacts AS $c)
|
||
{
|
||
$unknown = false;
|
||
|
||
switch ($c->type)
|
||
{
|
||
case Contact_Model::TYPE_ICQ:
|
||
$vCard .= "X-ICQ:";
|
||
break;
|
||
case Contact_Model::TYPE_JABBER:
|
||
$vCard .= "X-JABBER:";
|
||
break;
|
||
case Contact_Model::TYPE_EMAIL:
|
||
$vCard .= "EMAIL;PREF;INTERNET:";
|
||
break;
|
||
case Contact_Model::TYPE_PHONE:
|
||
$vCard .= "TEL;HOME;VOICE:+";
|
||
break;
|
||
case Contact_Model::TYPE_SKYPE:
|
||
$vCard .= "X-SKYPE:";
|
||
break;
|
||
case Contact_Model::TYPE_MSN:
|
||
$vCard .= "X-MSN:";
|
||
break;
|
||
case Contact_Model::TYPE_WEB:
|
||
$vCard .= "URL:";
|
||
break;
|
||
default:
|
||
$vCard .= "";
|
||
$unknown = true;
|
||
break;
|
||
}
|
||
|
||
if (!$unknown)
|
||
{
|
||
$vCard .= "$c->value\n";
|
||
}
|
||
}
|
||
|
||
$vCard .= "END:VCARD\n\n";
|
||
}
|
||
|
||
return $vCard;
|
||
}
|
||
|
||
|
||
}
|
Také k dispozici: Unified diff
Upravy:
- #109: Implementace exportu kontaktu uzivatelu pomoci vCard ve verzich 2.1 a 4.0