* Add ical export to edit \'Actions\' selectbox, and list context menu'

svn commit -m '* Add ical export to edit \'Actions\' selectbox, and list context menu
This commit is contained in:
Nathan Gray 2012-04-16 19:12:19 +00:00
commit 77bc5da6ef
4 changed files with 352 additions and 7 deletions

View File

@ -0,0 +1,101 @@
<?php
/**
* eGroupWare
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package infolog
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray
* @version $Id$
*/
/**
* export iCal plugin of infolog
*/
class infolog_export_ical extends infolog_export_csv {
/**
* Exports records as defined in $_definition
*
* @param egw_record $_definition
*/
public function export( $_stream, importexport_definition $_definition) {
$options = $_definition->plugin_options;
$this->bo = new infolog_bo();
$limit_exception = bo_merge::is_export_limit_excepted();
if (!$limit_exception) $export_limit = bo_merge::getExportLimit('infolog');
$ids = array();
$query = array();
switch($options['selection'])
{
case 'search':
$query = array_merge($GLOBALS['egw']->session->appsession('session_data','infolog'), $query);
// Fall through
case 'all':
$query['num_rows'] = $export_limit ? $export_limit : -1;
$query['start'] = 0;
$selection = $this->bo->search($query);
break;
default:
$ids = $selection = explode(',',$options['selection']);
break;
}
$boical = new infolog_ical();
fwrite($_stream, $boical->exportvCalendar($selection));
}
/**
* returns translated name of plugin
*
* @return string name
*/
public static function get_name() {
return lang('Infolog iCal export');
}
/**
* returns translated (user) description of plugin
*
* @return string descriprion
*/
public static function get_description() {
return lang("Exports in iCal format.");
}
/**
* retruns file suffix for exported file
*
* @return string suffix
*/
public static function get_filesuffix() {
return 'ics';
}
public static function get_mimetype() {
return 'text/infolog';
}
/**
* return html for options.
*
*/
public function get_options_etpl() {
}
/**
* returns selectors of this plugin
*
*/
public function get_selectors_etpl() {
return array(
'name' => 'infolog.export_csv_selectors',
'content' => 'search'
);
}
}

View File

@ -108,6 +108,29 @@ class infolog_ical extends infolog_bo
$this->clientProperties = $_clientProperties;
}
/**
* Exports multiple InfoLogs
*
* @param array $tasks array of info_ids or task arrays
* @param string $_version='2.0'
* @param string $_method=null only set for iTip messages
* @param string $charset='UTF-8'
* @return string|boolean string with vCal or false on error (eg. no permission to read the event)
*/
function exportVCalendar(array $tasks, $_version='2.0', $_method=null, $charset='UTF-8')
{
$vcal = new Horde_iCalendar;
foreach($tasks as $task)
{
if (!$this->exportVTODO($task, $_version, $_method, $charset, $vcal))
{
return false;
}
}
return $vcal->exportVCalendar();
}
/**
* Exports one InfoLog tast to an iCalendar VTODO
*
@ -115,10 +138,11 @@ class infolog_ical extends infolog_bo
* @param string $_version='2.0' could be '1.0' too
* @param string $_method='PUBLISH'
* @param string $charset='UTF-8' encoding of the vcalendar, default UTF-8
* @param Horde_iCalendar $vcal=null optional iCalendar object to add vtodo to
*
* @return string|boolean string with vCal or false on error (eg. no permission to read the event)
*/
function exportVTODO($task, $_version='2.0',$_method='PUBLISH', $charset='UTF-8')
function exportVTODO($task, $_version='2.0',$_method='PUBLISH', $charset='UTF-8',Horde_iCalendar $vcal=null)
{
if (is_array($task))
{
@ -166,11 +190,11 @@ class infolog_ical extends infolog_bo
array2string($taskData)."\n",3,$this->logfile);
}
$vcal = new Horde_iCalendar;
if (!isset($vcal)) $vcal = new Horde_iCalendar;
$vcal->setAttribute('PRODID','-//EGroupware//NONSGML EGroupware InfoLog '.$GLOBALS['egw_info']['apps']['infolog']['version'].'//'.
strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
$vcal->setAttribute('VERSION',$_version);
if ($_method) $vcal->setAttribute('METHOD',$_method);
strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']),array(),false);
$vcal->setAttribute('VERSION',$_version,array(),false);
if ($_method) $vcal->setAttribute('METHOD',$_method,array(),false);
$tzid = $this->tzid;
if ($tzid && $tzid != 'UTC')

View File

@ -0,0 +1,201 @@
<?php
/**
* eGroupWare
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package calendar
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray
* @version $Id$
*/
/**
* import ical for infolog
* Not a lot of options for this, just uses the ical class
*/
class infolog_import_ical implements importexport_iface_import_plugin {
private static $plugin_options = array(
'conditions', /* => array containing condition arrays:
'type' => exists, // exists
'string' => '#kundennummer',
'true' => array(
'action' => update,
'last' => true,
),
'false' => array(
'action' => insert,
'last' => true,
),*/
);
/**
* actions wich could be done to data entries
*/
protected static $actions = array();
/**
* conditions for actions
*
* @var array
*/
protected static $conditions = array();
/**
* @var definition
*/
private $definition;
/**
* @var bo
*/
private $bo;
/**
* @var bool
*/
private $dry_run = false;
/**
* List of import warnings
*/
protected $warnings = array();
/**
* List of import errors
*/
protected $errors = array();
/**
* List of actions, and how many times that action was taken
*/
protected $results = array();
/**
* imports entries according to given definition object.
* @param resource $_stream
* @param string $_charset
* @param definition $_definition
*/
public function import( $_stream, importexport_definition $_definition ) {
$this->definition = $_definition;
// dry run?
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
$success = 0;
// Failures
$this->errors = array();
@set_time_limit(0); // try switching execution time limit off
$infolog_ical = new infolog_ical();
if (!$infolog_ical->importVTODO(stream_get_contents($_stream)))
{
$this->errors[] = lang('Error: importing the iCal');
}
else
{
$success++;
}
$this->results['imported'] = $success;
return $success;
}
/**
* returns translated name of plugin
*
* @return string name
*/
public static function get_name() {
return lang('Infolog iCal import');
}
/**
* returns translated (user) description of plugin
*
* @return string descriprion
*/
public static function get_description() {
return lang("Imports TODOs into Infolog from an iCal File.");
}
/**
* retruns file suffix(s) plugin can handle (e.g. csv)
*
* @return string suffix (comma seperated)
*/
public static function get_filesuffix() {
return 'ics';
}
/**
* return etemplate components for options.
* @abstract We can't deal with etemplate objects here, as an uietemplate
* objects itself are scipt orientated and not "dialog objects"
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* preserv => array,
* )
*/
public function get_options_etpl() {
// lets do it!
}
/**
* returns etemplate name for slectors of this plugin
*
* @return string etemplate name
*/
public function get_selectors_etpl() {
// lets do it!
}
/**
* Returns warnings that were encountered during importing
* Maximum of one warning message per record, but you can append if you need to
*
* @return Array (
* record_# => warning message
* )
*/
public function get_warnings() {
return $this->warnings;
}
/**
* Returns errors that were encountered during importing
* Maximum of one error message per record, but you can append if you need to
*
* @return Array (
* record_# => error message
* )
*/
public function get_errors() {
return $this->errors;
}
/**
* Returns a list of actions taken, and the number of records for that action.
* Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
*
* @return Array (
* action => record count
* )
*/
public function get_results() {
return $this->results;
}
} // end of iface_export_plugin
?>

View File

@ -1086,6 +1086,12 @@ class infolog_ui
$this->prefs['document_dir'], ++$group, 'Insert in document', 'document_',
$this->prefs['default_document']
);
$actions['ical'] = array(
'icon' => 'calendar/navbar',
'caption' => 'Export iCal',
'group' => $group,
'allowOnMultiple' => true,
);
$actions['delete'] = array(
'caption' => 'Delete',
@ -1210,6 +1216,13 @@ class infolog_ui
// remember filter to restore it, if infolog icon get's clicked next time
if ($query['filter']) egw_cache::setSession('infolog', 'filter_reset_from', $query['filter']);
return $this->index(array(),'sp',$checked,0);
case 'ical':
// infolog_ical lets horde be auto-loaded, so it must go first
$boical = new infolog_ical();
ExecMethod2('phpgwapi.browser.content_header','todo.ics','text/calendar');
echo $boical->exportvCalendar($checked);
common::egw_exit();
}
// Actions that need to loop
@ -1717,7 +1730,7 @@ class infolog_ui
);
}
// new call via GET or some actions handled here, as they can happen both ways ($_GET[action] or button/action in GUI)
if (!$submit || in_array($action,array('sp','copy','schedule')))
if (!$submit || in_array($action,array('sp','copy','schedule','ical')))
{
switch ($action)
{
@ -1728,7 +1741,12 @@ class infolog_ui
'link_id' => $info_id,
));
break;
case 'ical':
$boical = new infolog_ical();
$result = $boical->exportVTODO($content,'2.0','PUBLISH',false);
ExecMethod2('phpgwapi.browser.content_header','todo.ical','text/calendar');
echo $result;
common::egw_exit();
case 'sp':
case 'copy':
$info_id = 0;
@ -1947,6 +1965,7 @@ class infolog_ui
'copy' => array('label' => 'Copy', 'title' => 'Copy this Infolog'),
'sp' => 'Sub-entry',
'print' => array('label' => 'Print', 'title' => 'Print this Infolog'),
'ical' => array('label' => 'Export iCal', 'title' => 'Export iCal'),
),
);
if ($GLOBALS['egw_info']['user']['apps']['calendar'])