mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-27 10:23:28 +01:00
Add import / export support through importexport app
This commit is contained in:
commit
f8e69a190a
149
calendar/inc/class.calendar_egw_record.inc.php
Normal file
149
calendar/inc/class.calendar_egw_record.inc.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare - Calendar - importexport
|
||||
*
|
||||
* @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$
|
||||
*/
|
||||
|
||||
/**
|
||||
* class calendar_egw_record
|
||||
* compability layer for iface_egw_record needet for importexport
|
||||
*/
|
||||
class calendar_egw_record implements importexport_iface_egw_record
|
||||
{
|
||||
|
||||
private $identifier = '';
|
||||
private $record = array();
|
||||
private static $bo;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* reads record from backend if identifier is given.
|
||||
*
|
||||
* @param string $_identifier
|
||||
*/
|
||||
public function __construct( $_identifier='' ){
|
||||
$this->identifier = $_identifier;
|
||||
if(!is_object($this->bo)) {
|
||||
$this->bo = new calendar_bo();
|
||||
}
|
||||
if($this->identifier) {
|
||||
$this->record = $this->bo->read($this->identifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* magic method to set attributes of record
|
||||
*
|
||||
* @param string $_attribute_name
|
||||
*/
|
||||
public function __get($_attribute_name) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* magig method to set attributes of record
|
||||
*
|
||||
* @param string $_attribute_name
|
||||
* @param data $data
|
||||
*/
|
||||
public function __set($_attribute_name, $data) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* converts this object to array.
|
||||
* @abstract We need such a function cause PHP5
|
||||
* dosn't allow objects do define it's own casts :-(
|
||||
* once PHP can deal with object casts we will change to them!
|
||||
*
|
||||
* @return array complete record as associative array
|
||||
*/
|
||||
public function get_record_array() {
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets title of record
|
||||
*
|
||||
*@return string tiltle
|
||||
*/
|
||||
public function get_title() {
|
||||
if (empty($this->record)) {
|
||||
$this->get_record();
|
||||
}
|
||||
return $this->record['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* sets complete record from associative array
|
||||
*
|
||||
* @todo add some checks
|
||||
* @return void
|
||||
*/
|
||||
public function set_record(array $_record){
|
||||
$this->record = $_record;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets identifier of this record
|
||||
*
|
||||
* @return string identifier of current record
|
||||
*/
|
||||
public function get_identifier() {
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* saves record into backend
|
||||
*
|
||||
* @return string identifier
|
||||
*/
|
||||
public function save ( $_dst_identifier ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* copys current record to record identified by $_dst_identifier
|
||||
*
|
||||
* @param string $_dst_identifier
|
||||
* @return string dst_identifier
|
||||
*/
|
||||
public function copy ( $_dst_identifier ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* moves current record to record identified by $_dst_identifier
|
||||
* $this will become moved record
|
||||
*
|
||||
* @param string $_dst_identifier
|
||||
* @return string dst_identifier
|
||||
*/
|
||||
public function move ( $_dst_identifier ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* delets current record from backend
|
||||
*
|
||||
*/
|
||||
public function delete () {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* destructor
|
||||
*
|
||||
*/
|
||||
public function __destruct() {
|
||||
}
|
||||
|
||||
} // end of calendar_egw_record
|
||||
?>
|
101
calendar/inc/class.calendar_export_csv.inc.php
Normal file
101
calendar/inc/class.calendar_export_csv.inc.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?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$
|
||||
*/
|
||||
|
||||
/**
|
||||
* export CSV plugin of calendar
|
||||
*/
|
||||
class calendar_export_csv implements importexport_iface_export_plugin {
|
||||
|
||||
/**
|
||||
* Exports records as defined in $_definition
|
||||
*
|
||||
* @param egw_record $_definition
|
||||
*/
|
||||
public function export( $_stream, importexport_definition $_definition) {
|
||||
$options = $_definition->plugin_options;
|
||||
$this->bo = new calendar_bo();
|
||||
$events =& $this->bo->search(array(
|
||||
'start' => $options['selection']['start'],
|
||||
'end' => $options['selection']['end'],
|
||||
'categories' => $options['categories'] ? $options['categories'] : $options['selection']['categories'],
|
||||
'enum_recuring' => false,
|
||||
'daywise' => false,
|
||||
'owner' => $options['owner'],
|
||||
'date_format' => $options['date_format'],
|
||||
));
|
||||
|
||||
$export_object = new importexport_export_csv($_stream, (array)$options);
|
||||
$export_object->set_mapping($options['mapping']);
|
||||
|
||||
// $options['selection'] is array of identifiers as this plugin doesn't
|
||||
// support other selectors atm.
|
||||
$record = new calendar_egw_record();
|
||||
foreach ($events as $event) {
|
||||
$record->set_record($event);
|
||||
$export_object->export_record($record);
|
||||
}
|
||||
unset($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('Calendar CSV export');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Exports events from your Calendar into a CSV File.");
|
||||
}
|
||||
|
||||
/**
|
||||
* retruns file suffix for exported file
|
||||
*
|
||||
* @return string suffix
|
||||
*/
|
||||
public static function get_filesuffix() {
|
||||
return 'csv';
|
||||
}
|
||||
|
||||
public static function get_mimetype() {
|
||||
return 'text/csv';
|
||||
}
|
||||
|
||||
/**
|
||||
* return html for options.
|
||||
*
|
||||
*/
|
||||
public function get_options_etpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns selectors of this plugin
|
||||
*
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
return array(
|
||||
'name' => 'calendar.export_csv_select',
|
||||
'content' => array(
|
||||
'start' => time(),
|
||||
'end' => time()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
91
calendar/inc/class.calendar_export_ical.inc.php
Normal file
91
calendar/inc/class.calendar_export_ical.inc.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?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$
|
||||
*/
|
||||
|
||||
/**
|
||||
* export iCal plugin of calendar
|
||||
*/
|
||||
class calendar_export_ical extends calendar_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 calendar_bo();
|
||||
$boical = new calendar_ical();
|
||||
$events =& $this->bo->search(array(
|
||||
'start' => $options['selection']['start'],
|
||||
'end' => $options['selection']['end'],
|
||||
'categories' => $options['categories'] ? $options['categories'] : $options['selection']['categories'],
|
||||
'enum_recuring' => false,
|
||||
'daywise' => false,
|
||||
'date_format' => 'server',
|
||||
));
|
||||
$ical =& $boical->exportVCal($events,'2.0','PUBLISH',false);
|
||||
fwrite($_stream, $ical);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('Calendar iCal export');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Exports events from your Calendar 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/calendar';
|
||||
}
|
||||
|
||||
/**
|
||||
* return html for options.
|
||||
*
|
||||
*/
|
||||
public function get_options_etpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns selectors of this plugin
|
||||
*
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
return array(
|
||||
'name' => 'calendar.export_csv_select',
|
||||
'content' => array(
|
||||
'start' => time(),
|
||||
'end' => time()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
346
calendar/inc/class.calendar_import_csv.inc.php
Normal file
346
calendar/inc/class.calendar_import_csv.inc.php
Normal file
@ -0,0 +1,346 @@
|
||||
<?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$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* class import_csv for calendar
|
||||
*/
|
||||
class calendar_import_csv implements importexport_iface_import_plugin {
|
||||
|
||||
private static $plugin_options = array(
|
||||
'fieldsep', // char
|
||||
'charset', // string
|
||||
'owner', // int
|
||||
'update_cats', // string {override|add} overides record
|
||||
// with cat(s) from csv OR add the cat from
|
||||
// csv file to exeisting cat(s) of record
|
||||
'num_header_lines', // int number of header lines
|
||||
'field_conversion', // array( $csv_col_num => conversion)
|
||||
'field_mapping', // array( $csv_col_num => adb_filed)
|
||||
'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( 'none', 'update', 'insert' );
|
||||
|
||||
/**
|
||||
* conditions for actions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $conditions = array();
|
||||
|
||||
/**
|
||||
* @var definition
|
||||
*/
|
||||
private $definition;
|
||||
|
||||
/**
|
||||
* @var bo
|
||||
*/
|
||||
private $bo;
|
||||
|
||||
/**
|
||||
* For figuring out if an entry has changed
|
||||
*/
|
||||
protected $tracking;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $dry_run = false;
|
||||
|
||||
/**
|
||||
* @var bool is current user admin?
|
||||
*/
|
||||
private $is_admin = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $user = null;
|
||||
|
||||
/**
|
||||
* 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 ) {
|
||||
$import_csv = new importexport_import_csv( $_stream, array(
|
||||
'fieldsep' => $_definition->plugin_options['fieldsep'],
|
||||
'charset' => $_definition->plugin_options['charset'],
|
||||
));
|
||||
|
||||
$this->definition = $_definition;
|
||||
|
||||
// user, is admin ?
|
||||
$this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin'];
|
||||
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
||||
|
||||
// dry run?
|
||||
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
||||
|
||||
// fetch the addressbook bo
|
||||
$this->bo= new calendar_boupdate();
|
||||
|
||||
// Get the tracker for changes
|
||||
$this->tracking = new calendar_tracking();
|
||||
|
||||
// set FieldMapping.
|
||||
$import_csv->mapping = $_definition->plugin_options['field_mapping'];
|
||||
|
||||
// set FieldConversion
|
||||
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
||||
|
||||
//check if file has a header lines
|
||||
if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
|
||||
$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
|
||||
} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
|
||||
// First method is preferred
|
||||
$import_csv->skip_records(1);
|
||||
}
|
||||
|
||||
// set eventOwner
|
||||
$_definition->plugin_options['owner'] = isset( $_definition->plugin_options['owner'] ) ?
|
||||
$_definition->plugin_options['owner'] : $this->user;
|
||||
|
||||
// Start counting successes
|
||||
$count = 0;
|
||||
$this->results = array();
|
||||
|
||||
// Failures
|
||||
$this->errors = array();
|
||||
|
||||
while ( $record = $import_csv->get_record() ) {
|
||||
$success = false;
|
||||
|
||||
// don't import empty records
|
||||
if( count( array_unique( $record ) ) < 2 ) continue;
|
||||
|
||||
// Set owner, unless it's supposed to come from CSV file
|
||||
if($_definition->plugin_options['owner_from_csv']) {
|
||||
if(!is_numeric($record['owner'])) {
|
||||
$this->errors[$import_csv->get_current_position()] = lang(
|
||||
'Invalid owner ID: %1. Might be a bad field translation. Used %2 instead.',
|
||||
$record['owner'],
|
||||
$_definition->plugin_options['owner']
|
||||
);
|
||||
$record['owner'] = $_definition->plugin_options['owner'];
|
||||
}
|
||||
} else {
|
||||
$record['owner'] = $_definition->plugin_options['owner'];
|
||||
}
|
||||
|
||||
if ( $_definition->plugin_options['conditions'] ) {
|
||||
foreach ( $_definition->plugin_options['conditions'] as $condition ) {
|
||||
switch ( $condition['type'] ) {
|
||||
// exists
|
||||
case 'exists' :
|
||||
$records = $this->bo->search(
|
||||
|
||||
);
|
||||
|
||||
if ( is_array( $records ) && count( array_keys( $records ) >= 1 ) ) {
|
||||
// apply action to all records matching this exists condition
|
||||
$action = $condition['true'];
|
||||
foreach ( (array)$records as $record ) {
|
||||
$record['id'] = $record['id'];
|
||||
if ( $_definition->plugin_options['update_cats'] == 'add' ) {
|
||||
if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
|
||||
$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $record['cat_id'] ) ) );
|
||||
}
|
||||
$success = $this->action( $action['action'], $record, $import_csv->get_current_position() );
|
||||
}
|
||||
} else {
|
||||
$action = $condition['false'];
|
||||
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position() ));
|
||||
}
|
||||
break;
|
||||
|
||||
// not supported action
|
||||
default :
|
||||
die('condition / action not supported!!!');
|
||||
break;
|
||||
}
|
||||
if ($action['last']) break;
|
||||
}
|
||||
} else {
|
||||
// unconditional insert
|
||||
$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
|
||||
}
|
||||
if($success) $count++;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* perform the required action
|
||||
*
|
||||
* @param int $_action one of $this->actions
|
||||
* @param array $_data record data for the action
|
||||
* @return bool success or not
|
||||
*/
|
||||
private function action ( $_action, $_data, $record_num = 0 ) {
|
||||
switch ($_action) {
|
||||
case 'none' :
|
||||
return true;
|
||||
case 'update' :
|
||||
// Only update if there are changes
|
||||
$old = $this->bo->read($_data['id']);
|
||||
|
||||
// Don't change a user account into a record
|
||||
if(!$this->definition->plugin_options['change_owner']) {
|
||||
// Don't change owner of an existing record
|
||||
unset($_data['owner']);
|
||||
}
|
||||
|
||||
// Merge to deal with fields not in import record
|
||||
$_data = array_merge($old, $_data);
|
||||
$changed = $this->tracking->changed_fields($_data, $old);
|
||||
if(count($changed) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fall through
|
||||
case 'insert' :
|
||||
if($_action == 'insert') {
|
||||
// Backend doesn't like inserting with ID specified, can overwrite existing
|
||||
unset($_data['id']);
|
||||
}
|
||||
// Make sure participants are set
|
||||
if(!$_data['participants']) {
|
||||
$user = $_data['owner'] ? $_data['owner'] : $this->user;
|
||||
$_data['participants'] = array(
|
||||
$user => 'U'
|
||||
);
|
||||
}
|
||||
if ( $this->dry_run ) {
|
||||
//print_r($_data);
|
||||
$this->results[$_action]++;
|
||||
return true;
|
||||
} else {
|
||||
$result = $this->bo->save( $_data, $this->is_admin);
|
||||
if(!$result) {
|
||||
$this->errors[$record_num] = lang('Unable to save');
|
||||
} else {
|
||||
$this->results[$_action]++;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
default:
|
||||
throw new egw_exception('Unsupported action');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('CSV import');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Imports events into your Calendar from a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators.");
|
||||
}
|
||||
|
||||
/**
|
||||
* retruns file suffix(s) plugin can handle (e.g. csv)
|
||||
*
|
||||
* @return string suffix (comma seperated)
|
||||
*/
|
||||
public static function get_filesuffix() {
|
||||
return 'csv';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
?>
|
212
calendar/inc/class.calendar_import_ical.inc.php
Normal file
212
calendar/inc/class.calendar_import_ical.inc.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?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 calendar
|
||||
*/
|
||||
class calendar_import_ical implements importexport_iface_import_plugin {
|
||||
|
||||
private static $plugin_options = array(
|
||||
'fieldsep', // char
|
||||
'charset', // string
|
||||
'owner', // int
|
||||
'update_cats', // string {override|add} overides record
|
||||
// with cat(s) from csv OR add the cat from
|
||||
// csv file to exeisting cat(s) of record
|
||||
'num_header_lines', // int number of header lines
|
||||
'field_conversion', // array( $csv_col_num => conversion)
|
||||
'field_mapping', // array( $csv_col_num => adb_filed)
|
||||
'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;
|
||||
|
||||
/**
|
||||
* For figuring out if an entry has changed
|
||||
*/
|
||||
protected $tracking;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $dry_run = false;
|
||||
|
||||
/**
|
||||
* @var bool is current user admin?
|
||||
*/
|
||||
private $is_admin = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $user = null;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
// user, is admin ?
|
||||
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
||||
|
||||
// dry run?
|
||||
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
||||
|
||||
// fetch the addressbook bo
|
||||
$this->bo= new calendar_boupdate();
|
||||
|
||||
|
||||
// Failures
|
||||
$this->errors = array();
|
||||
|
||||
@set_time_limit(0); // try switching execution time limit off
|
||||
|
||||
$calendar_ical = new calendar_ical;
|
||||
$calendar_ical->setSupportedFields('file', '');
|
||||
if (!$calendar_ical->importVCal(stream_get_contents($_stream)))
|
||||
{
|
||||
$this->errors[] = lang('Error: importing the iCal');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->results['imported'] = $calendar_ical->events_imported;
|
||||
}
|
||||
|
||||
return $calendar_ical->events_imported;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('iCal import');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Imports events into your Calendar 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 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
|
||||
?>
|
@ -912,7 +912,7 @@ ORDER BY cal_user_type, cal_usre_id
|
||||
// event (without uid), not strong enough uid
|
||||
$event['cal_uid'] = $GLOBALS['egw']->common->generate_uid('calendar',$cal_id);
|
||||
$this->db->update($this->cal_table, array('cal_uid' => $event['cal_uid']),
|
||||
array('cal_id' => $event['cal_id']),__LINE__,__FILE__,'calendar');
|
||||
array('cal_id' => $cal_id),__LINE__,__FILE__,'calendar');
|
||||
}
|
||||
|
||||
if ($event['recur_type'] == MCAL_RECUR_NONE)
|
||||
|
27
calendar/inc/class.calendar_wizard_export_csv.inc.php
Normal file
27
calendar/inc/class.calendar_wizard_export_csv.inc.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare - Wizard for Adressbook CSV export
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package calendar
|
||||
* @link http://www.egroupware.org
|
||||
* @author Nathan Gray
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
class calendar_wizard_export_csv extends importexport_wizard_basic_export_csv
|
||||
{
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// Field mapping
|
||||
$bo = new calendar_tracking();
|
||||
$this->export_fields = $bo->field2label;
|
||||
$custom = config::get_customfields('calendar', true);
|
||||
foreach($custom as $name => $data) {
|
||||
$this->export_fields['#'.$name] = $data['label'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
52
calendar/inc/class.calendar_wizard_import_csv.inc.php
Normal file
52
calendar/inc/class.calendar_wizard_import_csv.inc.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare - Wizard for user CSV import
|
||||
*
|
||||
* @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
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
class calendar_wizard_import_csv extends importexport_wizard_basic_import_csv
|
||||
{
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->steps += array(
|
||||
'wizard_step50' => lang('Manage mapping'),
|
||||
);
|
||||
// No conditions yet
|
||||
unset($this->steps['wizard_step55']);
|
||||
|
||||
// Field mapping
|
||||
$tracking = new calendar_tracking();
|
||||
$this->mapping_fields = $tracking->field2label;
|
||||
|
||||
// Actions
|
||||
$this->actions = array(
|
||||
'none' => lang('none'),
|
||||
'update' => lang('update'),
|
||||
'insert' => lang('insert'),
|
||||
);
|
||||
|
||||
// Conditions
|
||||
$this->conditions = array(
|
||||
);
|
||||
}
|
||||
|
||||
function wizard_step50(&$content, &$sel_options, &$readonlys, &$preserv)
|
||||
{
|
||||
$result = parent::wizard_step50($content, $sel_options, $readonlys, $preserv);
|
||||
$content['msg'] .= "\n*" ;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
/**
|
||||
* eGroupWare - eTemplates for Application calendar
|
||||
* http://www.egroupware.org
|
||||
* generated by soetemplate::dump4setup() 2010-10-07 08:23
|
||||
* generated by soetemplate::dump4setup() 2010-10-12 16:44
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package calendar
|
||||
@ -45,6 +45,8 @@ $templ_data[] = array('name' => 'calendar.edit_series','template' => '','lang' =
|
||||
|
||||
$templ_data[] = array('name' => 'calendar.export','template' => '','lang' => '','group' => '0','version' => '1.0.1.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:8:{i:0;a:2:{s:2:"h5";s:2:",1";s:2:"h1";s:6:",!@msg";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:8:",,,start";s:5:"label";s:5:"Start";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:5:"start";s:4:"help";s:23:"Startdate of the export";}}i:3;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:6:",,,end";s:5:"label";s:3:"End";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:3:"end";s:4:"help";s:21:"Enddate of the export";}}i:4;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:7:",,,file";s:5:"label";s:8:"Filename";}s:1:"B";a:3:{s:4:"type";s:4:"text";s:4:"name";s:4:"file";s:4:"help";s:24:"Filename of the download";}}i:5;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:10:",,,version";s:5:"label";s:7:"Version";}s:1:"B";a:2:{s:4:"type";s:6:"select";s:4:"name";s:7:"version";}}i:6;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:3:{s:4:"type";s:6:"button";s:5:"label";s:8:"Download";s:4:"name";s:8:"download";}}i:7;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:7;s:4:"cols";i:2;s:5:"align";s:6:"center";s:7:"options";a:0:{}}}','size' => '','style' => '','modified' => '1130738737',);
|
||||
|
||||
$templ_data[] = array('name' => 'calendar.export_csv_select','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:5:{i:0;a:1:{s:2:"h1";s:6:",!@msg";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:8:",,,start";s:5:"label";s:5:"Start";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:16:"selection[start]";s:4:"help";s:23:"Startdate of the export";}}i:3;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:6:",,,end";s:5:"label";s:3:"End";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:14:"selection[end]";s:4:"help";s:21:"Enddate of the export";}}i:4;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:4;s:4:"cols";i:2;s:5:"align";s:6:"center";s:7:"options";a:0:{}}}','size' => '','style' => '','modified' => '1286919523',);
|
||||
|
||||
$templ_data[] = array('name' => 'calendar.freetimesearch','template' => '','lang' => '','group' => '0','version' => '1.3.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:0:{}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:9:",size120b";s:5:"label";s:15:"Freetime Search";}s:1:"B";a:4:{s:4:"type";s:5:"label";s:4:"span";s:10:",redItalic";s:7:"no_lang";s:1:"1";s:4:"name";s:3:"msg";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:17:"Startdate / -time";}s:1:"B";a:3:{s:4:"type";s:9:"date-time";s:4:"name";s:5:"start";s:4:"help";s:33:"Startdate and -time of the search";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:8:"Duration";}s:1:"B";a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";i:1;a:6:{s:4:"type";s:6:"select";s:7:"no_lang";s:1:"1";s:4:"name";s:8:"duration";s:4:"help";s:23:"Duration of the meeting";s:8:"onchange";s:92:"set_style_by_class(\'table\',\'end_hide\',\'visibility\',this.value == \'\' ? \'visible\' : \'hidden\');";s:4:"size";s:12:"Use end date";}i:2;a:4:{s:4:"type";s:9:"date-time";s:4:"name";s:3:"end";s:4:"help";s:57:"Enddate / -time of the meeting, eg. for more then one day";s:4:"span";s:9:",end_hide";}}}i:4;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:9:"Timeframe";}s:1:"B";a:7:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"5";i:1;a:3:{s:4:"type";s:13:"date-houronly";s:4:"name";s:10:"start_time";s:4:"help";s:19:"Timeframe to search";}i:2;a:2:{s:4:"type";s:5:"label";s:5:"label";s:3:"til";}i:3;a:3:{s:4:"type";s:13:"date-houronly";s:4:"name";s:8:"end_time";s:4:"help";s:19:"Timeframe to search";}i:4;a:2:{s:4:"type";s:5:"label";s:5:"label";s:8:"Weekdays";}i:5;a:4:{s:4:"type";s:10:"select-dow";s:4:"size";s:1:"3";s:4:"name";s:8:"weekdays";s:4:"help";s:25:"Weekdays to use in search";}}}i:5;a:2:{s:1:"A";a:4:{s:4:"type";s:6:"button";s:5:"label";s:10:"New search";s:4:"name";s:6:"search";s:4:"help";s:36:"new search with the above parameters";}s:1:"B";a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";i:1;a:4:{s:4:"type";s:6:"select";s:7:"no_lang";s:1:"1";s:4:"name";s:13:"search_window";s:4:"help";s:34:"how far to search (from startdate)";}i:2;a:5:{s:4:"type";s:6:"button";s:4:"name";s:6:"cancel";s:5:"label";s:6:"Cancel";s:4:"help";s:16:"Close the window";s:7:"onclick";s:15:"window.close();";}}}i:6;a:2:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:8:"freetime";s:4:"span";s:3:"all";s:4:"name";s:4:"rows";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:6;s:4:"cols";i:2;}}','size' => '','style' => '.size120b { text-size: 120%; font-weight: bold; }
|
||||
.redItalic { color: red; font-style: italic; }
|
||||
.end_hide { visibility: hidden; }','modified' => '1149297367',);
|
||||
|
Loading…
Reference in New Issue
Block a user