Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1985

Přidáno uživatelem David Raška před více než 11 roky(ů)

closes #109 - Dokonceni implementace exportu kontaktu do vCard

Zobrazit rozdíly:

freenetis/branches/1.1/application/i18n/cs_CZ/texts.php
'contact information' => 'Kontaktní informace',
'contact list on redirect page' => 'Kontaktní informace na stránce přesměrování',
'contact value' => 'Data kontaktu',
'contacts' => 'Kontakty',
'contains' => 'obsahuje',
'contains not' => 'neobsahuje',
'content of file htaccess' => 'Obsah souboru .htaccess',
......
'expenditure-earning' => 'Výdej-Příjem',
'expenses' => 'Výdaje',
'export' => 'Exportovat',
'export contacts' => 'Exportovat kontakty',
'export device templates' => 'Export šablon zařízení',
'export of device' => 'Export zařízení',
'export of registration' => 'Export přihlášky',
......
'export to xls' => 'Exportovat do XLS',
'export to xml' => 'Exportovat do XML',
'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/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;
}
}
freenetis/branches/1.1/application/controllers/users.php
if (!$hide_grid)
{
// export vCard
// export contacts
$grid->add_new_button(
'vcard/export' . server::query_string(),
'Export vCard', array
'export/vcard/users' . server::query_string(),
'Export contacts', array
(
'title' => __('Export vCard'),
'title' => __('Export contacts'),
'class' => 'popup_link'
)
);
freenetis/branches/1.1/application/controllers/members.php
if (!$hide_grid && $this->acl_check_view(get_class($this), 'members'))
{
// export contacts
$grid->add_new_button(
'export/vcard/members' . server::query_string(),
'Export contacts', array
(
'title' => __('Export contacts'),
'class' => 'popup_link'
)
);
// csv export of members
$grid->add_new_button(
'export/csv/members' . server::query_string(),
......
'members_whitelists/show_by_member/'.$member->id, __('Whitelists')
);
}
// export contacts
$member_links[] = html::anchor(
'export/vcard/' . $member_id . server::query_string(),
__('Export contacts'),
array
(
'title' => __('Export contacts'),
'class' => 'popup_link'
)
);
$member_links[] = html::anchor(
'members/registration_export/'.$member->id,
freenetis/branches/1.1/application/controllers/export.php
$view->content->form = $form;
$view->render(TRUE);
}
/**
* Function exports contacts to vCard file
*
* @author David Raška
*/
public function vcard($export = NULL)
{
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')
->checked($export == 'members');
$form->submit('Submit');
if ($form->validate())
{
$form_data = $form->as_array();
$main_only = (isset($form_data['main_only']) && $form_data['main_only'] == '1') || $export == 'members';
$filter_form = new Filter_form('u');
$filter_form->autoload();
$user = new User_Model();
try
{
if (!is_numeric($export))
{
$export = NULL;
}
$items = $user->get_all_users(0, 50, 'id', 'ASC', $filter_form->as_sql(), $export);
}
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="'.__('Contacts').'.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 contacts');
$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 4.0 format
*
* @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 2.1 format
*
* @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;
}
/**
* Function returns organization logo for export
*
* @author David Raska

Také k dispozici: Unified diff