mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-16 18:31:26 +01:00
Backport 29600 - Update importexport names/classes to reflect changes in importexport
This commit is contained in:
commit
2302a198ef
512
timesheet/inc/class.export_openoffice.inc.php
Normal file
512
timesheet/inc/class.export_openoffice.inc.php
Normal file
@ -0,0 +1,512 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare importexport
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package importexport
|
||||
* @link http://www.egroupware.org
|
||||
* @author Knut Moeller <k.moeller@metaways.de>
|
||||
* @copyright Knut Moeller <k.moeller@metaways.de>
|
||||
* @version $Id: $
|
||||
*/
|
||||
|
||||
require_once(EGW_INCLUDE_ROOT. '/timesheet/inc/class.spreadsheet.inc.php');
|
||||
|
||||
/**
|
||||
* class export_cmslite
|
||||
*
|
||||
* special export class (metaways openoffice calc table)
|
||||
* adapter to spreadsheet class
|
||||
*
|
||||
*/
|
||||
class export_openoffice implements importexport_iface_export_record
|
||||
{
|
||||
|
||||
/**
|
||||
* array with field mapping in form egw_field_name => exported_field_name
|
||||
* @var array
|
||||
*/
|
||||
protected $mapping = array();
|
||||
|
||||
/**
|
||||
* array with conversions to be done in form: egw_field_name => conversion_string
|
||||
* @var array
|
||||
*/
|
||||
protected $conversion = array();
|
||||
|
||||
/**
|
||||
* array holding the current record
|
||||
* @access protected
|
||||
*/
|
||||
protected $record = array();
|
||||
|
||||
/**
|
||||
* holds (charset) translation object
|
||||
* @var object
|
||||
*/
|
||||
protected $translation;
|
||||
|
||||
/**
|
||||
* holds number of exported records
|
||||
* @var unknown_type
|
||||
*/
|
||||
protected $num_of_records = 0;
|
||||
|
||||
/**
|
||||
* stream resource of csv file
|
||||
* @var resource
|
||||
*/
|
||||
protected $handle;
|
||||
|
||||
protected $document;
|
||||
protected $table;
|
||||
|
||||
protected $summarytable; // link to first table
|
||||
protected $summary; // array, project -> user -> time
|
||||
protected $summaryweekend; // same for weekend
|
||||
|
||||
private $tablecount;
|
||||
private $columncount;
|
||||
private $rowcount;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param object _handle resource where records are exported to.
|
||||
* @param string _charset charset the records are exported to.
|
||||
* @param array _options options for specific backends
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
public function __construct( $_handle, array $_options ) {
|
||||
$this->handle = $_handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets field mapping
|
||||
*
|
||||
* @param array $_mapping egw_field_name => csv_field_name
|
||||
*/
|
||||
public function set_mapping( array $_mapping) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets conversion.
|
||||
* See import_export_helper_functions::conversion.
|
||||
*
|
||||
* @param array $_conversion
|
||||
*/
|
||||
public function set_conversion( array $_conversion) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* exports a record into resource of handle
|
||||
*
|
||||
* @param iface_egw_record record
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
public function export_record( importexport_iface_egw_record $_record ) {
|
||||
|
||||
}
|
||||
|
||||
public function create_summarytable($_tablename='Gesamtzeiten') {
|
||||
$this->summarytable = new SpreadSheetTable($this->document, $_tablename);
|
||||
$this->tablecount++;
|
||||
$this->summary = array();
|
||||
$this->summaryweekend = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return weekdate array (1-7) for given week
|
||||
*/
|
||||
private function week_dates($_timestamp) {
|
||||
$week_dates = array();
|
||||
$day = (int) date("w", $_timestamp);
|
||||
|
||||
if ($day != 1) {
|
||||
$diff = $day - 1;
|
||||
if ($day==0) $diff = 6;
|
||||
$monday = strtotime("-".$diff." days" , $_timestamp);
|
||||
}
|
||||
else {
|
||||
$monday = $_timestamp;
|
||||
}
|
||||
|
||||
for ($i=0; $i < 7; $i++) {
|
||||
$week_dates[$i+1] = strtotime("+".$i." days", $monday);
|
||||
}
|
||||
return($week_dates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function fill_summarytable($_tstamp_min, $_tstamp_max) {
|
||||
|
||||
// prepare data --------------------------
|
||||
|
||||
uksort($this->summary, "strnatcasecmp");
|
||||
uksort($this->summaryweekend, "strnatcasecmp");
|
||||
|
||||
// get user-array
|
||||
$users = array();
|
||||
foreach ($this->summary as $project => $user_time) {
|
||||
foreach($user_time as $user => $time) {
|
||||
if (!in_array($user, $users)) $users[] = $user;
|
||||
}
|
||||
}
|
||||
asort($users);
|
||||
$usersweekend = array();
|
||||
foreach ($this->summaryweekend as $project => $user_time) {
|
||||
foreach($user_time as $user => $time) {
|
||||
if (!in_array($user, $usersweekend)) $usersweekend[] = $user;
|
||||
}
|
||||
}
|
||||
asort($usersweekend);
|
||||
|
||||
|
||||
// get project-array (sites)
|
||||
$projects = array();
|
||||
foreach ($this->summary as $project => $user_time) {
|
||||
if (!in_array($project ,$projects)) $projects[] = $project;
|
||||
}
|
||||
foreach ($this->summaryweekend as $project => $user_time) {
|
||||
if (!in_array($project ,$projects)) $projects[] = $project;
|
||||
}
|
||||
asort($projects);
|
||||
|
||||
$this->summarytable->addColumn('co20');
|
||||
for ($i=1; $i <= count($users) + count($usersweekend) + 2; $i++) {
|
||||
$this->summarytable->addColumn();
|
||||
}
|
||||
|
||||
|
||||
// populate table --------------------------
|
||||
|
||||
|
||||
// create table-headlines
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->summarytable->addCell($row, 'string', 'CMS Lite Support / Montag - Freitag / 08.00 Uhr - 18.00 Uhr', array('bold'));
|
||||
|
||||
for ($i=0; $i<count($users); $i++) {
|
||||
$this->summarytable->addCell($row, 'string', '');
|
||||
}
|
||||
$this->summarytable->addCell($row, 'string', 'CMS Lite Support / Wochenende', array('bold'));
|
||||
|
||||
|
||||
// headline, row 1
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->summarytable->addCell($row, 'string', 'Mitarbeiter:', array('bold'));
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->summarytable->addCell($row, 'string', $user, array('bold'));
|
||||
}
|
||||
$this->summarytable->addCell($row, 'string', 'Mitarbeiter:', array('bold'));
|
||||
foreach ($usersweekend as $user) {
|
||||
$this->summarytable->addCell($row, 'string', $user, array('bold'));
|
||||
}
|
||||
|
||||
// fixed date rows, row 2
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->summarytable->addCell($row, 'string', 'Zeitraum:', array('bold'));
|
||||
$kw_min = strftime("%V", $_tstamp_min);
|
||||
$kw_max = strftime("%V", $_tstamp_max);
|
||||
$kw = ($kw_min == $kw_max) ? "KW $kw_min" : "KW $kw_min - KW $kw_max";
|
||||
for ($i=0; $i < count($users); $i++) {
|
||||
$this->summarytable->addCell($row, 'string', $kw, array('bold'));
|
||||
}
|
||||
$this->summarytable->addCell($row, 'string', 'Zeitraum:', array('bold'));
|
||||
for ($i=0; $i < count ($usersweekend); $i++) {
|
||||
$this->summarytable->addCell($row, 'string', $kw, array('bold'));
|
||||
}
|
||||
|
||||
|
||||
// weekdays, row 3 left
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->summarytable->addCell($row, 'string', '', array('bold'));
|
||||
|
||||
$week_dates = $this->week_dates($_tstamp_min);
|
||||
|
||||
if ($kw_min != $kw_max) {
|
||||
$days = strftime("%d.%m.%y", $_tstamp_min).' - '.strftime("%d.%m.%y", $_tstamp_max);
|
||||
}
|
||||
else {
|
||||
// monday-friday
|
||||
$days = strftime("%d.%m.%y", $week_dates[1]).' - '.strftime("%d.%m.%y", $week_dates[5]);
|
||||
}
|
||||
for ($i=0; $i < count($users); $i++) {
|
||||
$this->summarytable->addCell($row, 'string', $days, array('bold'));
|
||||
}
|
||||
|
||||
// weekend, row 3 right
|
||||
$this->summarytable->addCell($row, 'string', '', array('bold'));
|
||||
if ($kw_min != $kw_max) {
|
||||
$days = strftime("%d.%m.%y", $_tstamp_min).' - '.strftime("%d.%m.%y", $_tstamp_max);
|
||||
}
|
||||
else {
|
||||
$days = strftime("%d.%m.%y", $week_dates[6]).' - '.strftime("%d.%m.%y", $week_dates[7]);
|
||||
}
|
||||
for ($i=0; $i < count($usersweekend); $i++) {
|
||||
$this->summarytable->addCell($row, 'string', $days, array('bold'));
|
||||
}
|
||||
|
||||
$this->rowcount = 4;
|
||||
|
||||
|
||||
|
||||
// project lines (sitenames)
|
||||
foreach ($projects as $project) {
|
||||
|
||||
// 1.Cell: projectname
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->rowcount++;
|
||||
$this->summarytable->addCell($row, 'string', $project);
|
||||
|
||||
// iterate all users for each line
|
||||
foreach ($users as $user) {
|
||||
|
||||
if (array_key_exists($project, $this->summary) && array_key_exists($user, $this->summary[$project])) {
|
||||
$this->summarytable->addCell($row, 'float', (float) ($this->summary[$project][$user] / 60) );
|
||||
}
|
||||
else { // add empty cell if no user-entry
|
||||
$this->summarytable->addCell($row, 'string', '');
|
||||
}
|
||||
}
|
||||
$this->summarytable->addCell($row, 'string', '');
|
||||
foreach ($usersweekend as $user) {
|
||||
|
||||
// weekend
|
||||
if (array_key_exists($project, $this->summaryweekend) && array_key_exists($user, $this->summaryweekend[$project])) {
|
||||
$this->summarytable->addCell($row, 'float', (float) ($this->summaryweekend[$project][$user] / 60) );
|
||||
}
|
||||
else { // add empty cell if no user-entry
|
||||
$this->summarytable->addCell($row, 'string', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// summary line 1
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->rowcount++;
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->rowcount++;
|
||||
$this->summarytable->addCell($row, 'string', 'Summe:');
|
||||
for ($i=1; $i <= count($users); $i++) {
|
||||
$this->table->addCell($row, 'formula', 'SUM([.'.chr(65+$i).'5:.'.chr(65 + $i).($this->rowcount - 1).'])');
|
||||
}
|
||||
$this->summarytable->addCell($row, 'string', 'Summe:');
|
||||
for ($i= count($users)+2; $i <= count($usersweekend)+count($users)+1; $i++) {
|
||||
$this->table->addCell($row, 'formula', 'SUM([.'.chr(65+$i).'5:.'.chr(65 + $i).($this->rowcount - 1).'])');
|
||||
}
|
||||
|
||||
|
||||
// summary line 2
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->rowcount++;
|
||||
$row = $this->summarytable->addRow();
|
||||
$this->rowcount++;
|
||||
$this->summarytable->addCell($row, 'string', 'Gesamt:');
|
||||
$this->table->addCell($row, 'formula', 'SUM([.B'. ($this->rowcount - 2) . ':.' . chr(65 + count($users)) . ($this->rowcount - 2) . '])');
|
||||
for ($i=1; $i <= count($users)-1; $i++) {
|
||||
$this->table->addCell($row, 'string', '');
|
||||
}
|
||||
|
||||
$this->summarytable->addCell($row, 'string', 'Gesamt:');
|
||||
$this->table->addCell($row, 'formula', 'SUM([.'.chr(65 + count($users) + 2) . ($this->rowcount - 2).
|
||||
':.'.chr(65 + count($users) + 2 + count($usersweekend) - 1) . ($this->rowcount - 2).'])');
|
||||
}
|
||||
|
||||
|
||||
public function create_usertable($_tablename, $_username, $_tstamp_min, $_tstamp_max) {
|
||||
$this->table = new SpreadSheetTable($this->document, $_tablename);
|
||||
for ($i=10; $i < 19; $i++) {
|
||||
$this->table->addColumn('co'.$i);
|
||||
}
|
||||
|
||||
$row = $this->table->addRow();
|
||||
$this->table->addCell($row, 'string', 'Monat:' . strftime("%m/%Y", $_tstamp_min), array('bold'));
|
||||
$this->table->addCell($row, 'string', 'KW ' . strftime("%V", $_tstamp_min), array('bold'));
|
||||
|
||||
$row = $this->table->addRow();
|
||||
$this->table->addCell($row, 'string', 'Mitarbeiter:', array('bold') );
|
||||
$this->table->addCell($row, 'string', $_username, array('bold'));
|
||||
|
||||
// create table-headlines
|
||||
$headlines = array(
|
||||
'Datum',
|
||||
'Site',
|
||||
'Ansprechpartner',
|
||||
'Projekttyp',
|
||||
'Ticket#',
|
||||
'Std.',
|
||||
'Newsletter',
|
||||
// 'SOW-Nr.',
|
||||
'Bemerkungen'
|
||||
);
|
||||
$row = $this->table->addRow('double');
|
||||
$this->table->addCells($row, 'string', $headlines, array('bold', 'border'));
|
||||
|
||||
$this->tablecount++;
|
||||
$this->rowcount = 3;
|
||||
$this->columncount = count($headlines);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* exports a record into resource of handle
|
||||
*
|
||||
* @param iface_egw_record record
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
public function add_record( $_record, $_extras ) {
|
||||
|
||||
if (is_array($_record)) {
|
||||
$row = $this->table->addRow();
|
||||
$this->rowcount++;
|
||||
|
||||
$this->table->addCell($row, 'date', strftime("%d.%m.%Y", $_record['ts_start']));
|
||||
$this->table->addCell($row, 'string', $_record['ts_project']);
|
||||
$this->table->addCell($row, 'string', $_extras['asp']);
|
||||
$this->table->addCell($row, 'string', $_record['cat_name']);// $_extras['typ']);
|
||||
$this->table->addCell($row, 'string', $_extras['ticket']);
|
||||
$this->table->addCell($row, 'float', (float) ($_record['ts_duration'] / 60) );
|
||||
$this->table->addCell($row, 'string', $_extras['newsletter']);
|
||||
// $this->table->addCell($row, 'string', $_extras['sow']);
|
||||
$this->table->addCell($row, 'string', $_record['ts_description']);
|
||||
|
||||
|
||||
// collect statistics
|
||||
|
||||
// username
|
||||
$res = array();
|
||||
// $nameRegex = '/\s(.*)\s(.*)$/'; // z.B. "[admin] Richard Blume"
|
||||
$nameRegex = '/(.*),\s(.*)$/'; // z.B. "Blume, Richard"
|
||||
preg_match($nameRegex, $GLOBALS['egw']->common->grab_owner_name($_record['ts_owner']), $res);
|
||||
// $user = $res[1];
|
||||
$user = $res[0]; // full name
|
||||
|
||||
$site = $_record['ts_project'];
|
||||
$time = $_record['ts_duration'];
|
||||
$weekday = (int) strftime("%w", $_record['ts_start']);
|
||||
|
||||
if ( $weekday == 0 || $weekday == 6 ) {
|
||||
|
||||
// weekend
|
||||
if (!array_key_exists($site, $this->summaryweekend)) {
|
||||
$this->summaryweekend[$site] = array();
|
||||
$this->summaryweekend[$site][$user] = $time;
|
||||
}
|
||||
elseif (!array_key_exists($user, $this->summaryweekend[$site])) {
|
||||
$this->summaryweekend[$site][$user] = $time;
|
||||
}
|
||||
else {
|
||||
$this->summaryweekend[$site][$user] += $time;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// site -> user -> sum
|
||||
if (!array_key_exists($site, $this->summary)) {
|
||||
$this->summary[$site] = array();
|
||||
$this->summary[$site][$user] = $time;
|
||||
}
|
||||
elseif (!array_key_exists($user, $this->summary[$site])) {
|
||||
$this->summary[$site][$user] = $time;
|
||||
}
|
||||
else {
|
||||
$this->summary[$site][$user] += $time;
|
||||
}
|
||||
}
|
||||
|
||||
$this->num_of_records++;
|
||||
$this->record = array();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function summarize() {
|
||||
if ($this->rowcount > 1) {
|
||||
$row = $this->table->addRow();
|
||||
$this->rowcount++;
|
||||
$row = $this->table->addRow();
|
||||
$this->rowcount++;
|
||||
|
||||
$this->table->addCell($row, 'string', '');
|
||||
$this->table->addCell($row, 'string', '');
|
||||
$this->table->addCell($row, 'string', '');
|
||||
$this->table->addCell($row, 'string', '');
|
||||
$this->table->addCell($row, 'string', '');
|
||||
$this->table->addCell($row, 'formula', 'SUM([.F2:.F'.($this->rowcount-2).'])');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function init() {
|
||||
$this->document = new SpreadSheetDocument($this->handle);
|
||||
|
||||
// global usertable styles
|
||||
$columnwidth = array(
|
||||
'2.767cm',
|
||||
'5.067cm',
|
||||
'5.067cm',
|
||||
'3.267cm',
|
||||
'2.267cm',
|
||||
'2.267cm',
|
||||
'2.267cm',
|
||||
// '2.267cm',
|
||||
'6.267cm'
|
||||
);
|
||||
|
||||
for ($i=0; $i < count($columnwidth); $i++) {
|
||||
$this->document->addColumnStyle('co'.($i + 10), $columnwidth[$i]);
|
||||
}
|
||||
|
||||
// first column, summary-table
|
||||
$this->document->addColumnStyle('co20', '5.2cm');
|
||||
}
|
||||
|
||||
public function finalize() {
|
||||
$this->document->finalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total number of exported records.
|
||||
*
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
public function get_num_of_records() {
|
||||
return $this->num_of_records;
|
||||
}
|
||||
|
||||
/**
|
||||
* destructor
|
||||
*
|
||||
* @return
|
||||
* @access public
|
||||
*/
|
||||
public function __destruct() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
148
timesheet/inc/class.timesheet_egw_record.inc.php
Normal file
148
timesheet/inc/class.timesheet_egw_record.inc.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare - Addressbook - importexport
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package addressbook
|
||||
* @subpackage importexport
|
||||
* @link http://www.egroupware.org
|
||||
* @author Cornelius Weiss <nelius@cwtech.de>, Knut Moeller <k.moeller@metaways.de>
|
||||
* @copyright Cornelius Weiss <nelius@cwtech.de>, Knut Moeller <k.moeller@metaways.de>
|
||||
* @version $Id: class.egw_addressbook_record.inc.php 22827 2006-11-10 15:35:35Z nelius_weiss $
|
||||
*/
|
||||
|
||||
/**
|
||||
* class egw_addressbook_record
|
||||
* compability layer for iface_egw_record needet for importexport
|
||||
*/
|
||||
class timesheet_egw_record implements importexport_iface_egw_record
|
||||
{
|
||||
|
||||
private $identifier = '';
|
||||
private $timesheetentry = array();
|
||||
private $botimesheet;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* reads record from backend if identifier is given.
|
||||
*
|
||||
* @param string $_identifier
|
||||
*/
|
||||
public function __construct( $_identifier='' ){
|
||||
$this->identifier = $_identifier;
|
||||
$this->botimesheet = new timesheet_bo();
|
||||
$this->timesheetentry = $this->botimesheet->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->timesheetentry;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets title of record
|
||||
*
|
||||
*@return string title
|
||||
*/
|
||||
public function get_title() {
|
||||
// TODO get_record gibts nicht ?
|
||||
// if (empty($this->timesheetentry)) {
|
||||
// $this->get_record();
|
||||
// }
|
||||
return $this->timesheetentry['ts_project'] . ' - ' . $this->timesheetentry['ts_title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* sets complete record from associative array
|
||||
*
|
||||
* @todo add some checks
|
||||
* @return void
|
||||
*/
|
||||
public function set_record(array $_record){
|
||||
$this->timesheetentry = $_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 ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* copies 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() {
|
||||
unset ($this->botimesheet);
|
||||
}
|
||||
|
||||
} // end of egw_timesheet_record
|
91
timesheet/inc/class.timesheet_export_csv.inc.php
Normal file
91
timesheet/inc/class.timesheet_export_csv.inc.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package timesheet
|
||||
* @subpackage importexport
|
||||
* @link http://www.egroupware.org
|
||||
* @author Knut Moeller <k.moeller@metaways.de>
|
||||
* @copyright Knut Moeller <k.moeller@metaways.de>
|
||||
* @version $Id: $
|
||||
*/
|
||||
|
||||
/**
|
||||
* export plugin of addressbook
|
||||
*/
|
||||
class timesheet_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;
|
||||
|
||||
$uitimesheet = new timesheet_ui();
|
||||
$selection = array();
|
||||
|
||||
$query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP);
|
||||
$query['num_rows'] = -1; // all
|
||||
|
||||
$uitimesheet->get_rows($query,$selection,$readonlys,true); // true = only return the id's
|
||||
|
||||
$options['begin_with_fieldnames'] = true;
|
||||
$export_object = new importexport_export_csv($_stream, (array)$options);
|
||||
|
||||
// $options['selection'] is array of identifiers as this plugin doesn't
|
||||
// support other selectors atm.
|
||||
foreach ($selection as $identifier) {
|
||||
$timesheetentry = new timesheet_egw_record($identifier);
|
||||
$export_object->export_record($timesheetentry);
|
||||
unset($timesheetentry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('Timesheet CSV export');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Exports entries from your Timesheet into a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators.");
|
||||
}
|
||||
|
||||
/**
|
||||
* returns file suffix for exported file
|
||||
*
|
||||
* @return string suffix
|
||||
*/
|
||||
public static function get_filesuffix() {
|
||||
return 'csv';
|
||||
}
|
||||
|
||||
/**
|
||||
* return html for options.
|
||||
* this way the plugin has all opportunities for options tab
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public function get_options_etpl() {
|
||||
return 'timesheet.export_csv_options';
|
||||
}
|
||||
|
||||
/**
|
||||
* returns slectors of this plugin via xajax
|
||||
*
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
return '<b>Selectors:</b>';
|
||||
}
|
||||
}
|
200
timesheet/inc/class.timesheet_export_openoffice.inc.php
Normal file
200
timesheet/inc/class.timesheet_export_openoffice.inc.php
Normal file
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package timesheet
|
||||
* @subpackage importexport
|
||||
* @link http://www.egroupware.org
|
||||
* @author Knut Moeller <k.moeller@metaways.de>
|
||||
* @copyright Knut Moeller <k.moeller@metaways.de>
|
||||
* @version $Id: $
|
||||
*/
|
||||
|
||||
/**
|
||||
* export plugin of addressbook
|
||||
*/
|
||||
class timesheet_export_openoffice implements importexport_iface_export_plugin {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Exports records as defined in $_definition
|
||||
*
|
||||
* @param egw_record $_definition
|
||||
*/
|
||||
public function export( $_stream, importexport_definition $_definition) {
|
||||
|
||||
$options = $_definition->options;
|
||||
|
||||
$botimesheet = new timesheet_bo();
|
||||
|
||||
// get current display selection
|
||||
|
||||
$query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP);
|
||||
|
||||
$bo_pm = CreateObject('projectmanager.boprojectmanager');
|
||||
$childs = $bo_pm->children( $query['col_filter']['pm_id'] );
|
||||
$childs[] = $query['col_filter']['pm_id'];
|
||||
$pmChilds = implode(",",$childs);
|
||||
$botimesheet->db->select( 'egw_links','link_id, link_id1','',
|
||||
__LINE__,__FILE__,False,
|
||||
'',False,0,
|
||||
'JOIN egw_pm_projects ON (pm_id = link_id2)
|
||||
JOIN egw_timesheet ON (ts_id=link_id1)
|
||||
WHERE
|
||||
link_app1 = \'timesheet\' AND
|
||||
link_app2 = \'projectmanager\' AND
|
||||
link_id2 IN ('.$pmChilds.') AND ts_start >= '.$query['startdate'].' AND ts_start < '.$query['enddate'] );
|
||||
|
||||
while($row = $botimesheet->db->row(true)) {
|
||||
$tslist[$row['link_id']] = $row['link_id1'];
|
||||
}
|
||||
|
||||
//error_log(print_r($query,true));
|
||||
//error_log(print_r($tslist,true));
|
||||
|
||||
$ids = implode(',', $tslist);
|
||||
|
||||
// no result
|
||||
if (strlen($ids)==0) return false;
|
||||
|
||||
//error_log('IDS: '.$ids);
|
||||
|
||||
// get full result
|
||||
|
||||
$rows = $botimesheet->search(array("egw_timesheet.ts_id IN ($ids)"),
|
||||
false, 'ts_owner,ts_start', array('cat_name') ,
|
||||
'', false, 'AND', false, null,
|
||||
'LEFT JOIN egw_categories ON (egw_categories.cat_id=egw_timesheet.cat_id AND egw_categories.cat_appname=\'timesheet\')');
|
||||
|
||||
|
||||
if (is_array($rows) && count($rows)>0 ) {
|
||||
//error_log(print_r($rows,true));
|
||||
// export rows
|
||||
|
||||
$export_object = new export_openoffice($_stream, $charset, (array)$options);
|
||||
$export_object->init();
|
||||
|
||||
|
||||
// get date values
|
||||
|
||||
$tstamp_min = 0; // date range for table date entries (KW...)
|
||||
$tstamp_max = 0;
|
||||
|
||||
foreach($rows as $row) {
|
||||
if ($row['ts_start']<$tstamp_min || $tstamp_min == 0) $tstamp_min = $row['ts_start'];
|
||||
if ($row['ts_start']>$tstamp_max || $tstamp_max == 0) $tstamp_max = $row['ts_start'];
|
||||
}
|
||||
|
||||
|
||||
// init summarytable
|
||||
$export_object->create_summarytable();
|
||||
|
||||
|
||||
// user tables
|
||||
$last_username = 0;
|
||||
$first_table = true;
|
||||
|
||||
foreach($rows as $row) {
|
||||
|
||||
// read in extra values (custom fields)
|
||||
$extrarows = $botimesheet->search(array("egw_timesheet.ts_id=".$row['ts_id']), false, '', 'ts_extra_name,ts_extra_value' ,
|
||||
'', false, 'AND', false, null,
|
||||
'LEFT JOIN egw_timesheet_extra ON (egw_timesheet_extra.ts_id=egw_timesheet.ts_id)' );
|
||||
$extras = array();
|
||||
foreach($extrarows as $extrarow) {
|
||||
$extras[$extrarow['ts_extra_name']] = $extrarow['ts_extra_value'];
|
||||
}
|
||||
|
||||
// change projectname
|
||||
$titleRegex = '/^.*:.*-\s(.*)$/';
|
||||
preg_match($titleRegex, $row['ts_project'], $title);
|
||||
$row['ts_project'] = $title[1];
|
||||
|
||||
// get firstname, lastname
|
||||
$res = array();
|
||||
// $nameRegex = '/\s(.*)\s(.*)$/'; // z.B. "[admin] Richard Blume"
|
||||
$nameRegex = '/(.*),\s(.*)$/'; // z.B. "Blume, Richard"
|
||||
preg_match($nameRegex, $GLOBALS['egw']->common->grab_owner_name($row['ts_owner']), $res);
|
||||
// error_log('|'.$name . '| -> ' . print_r($res,true));
|
||||
$firstname = $res[2];
|
||||
$lastname = $res[1];
|
||||
$fullname = $firstname.' '.$lastname;
|
||||
|
||||
// new table on username change
|
||||
if ($row['ts_owner'] != $last_username) {
|
||||
|
||||
// create sum as last tablerow before creating new table
|
||||
if (!$first_table) {
|
||||
$export_object->summarize();
|
||||
}
|
||||
else {
|
||||
$first_table = false;
|
||||
}
|
||||
|
||||
// create new table sheet
|
||||
$export_object->create_usertable($lastname,
|
||||
$fullname, $tstamp_min, $tstamp_max);
|
||||
|
||||
}
|
||||
$export_object->add_record($row, $extras);
|
||||
$last_username = $row['ts_owner'];
|
||||
}
|
||||
$export_object->summarize(); // for last table
|
||||
|
||||
// fill collected sums into sum-table
|
||||
$export_object->fill_summarytable($tstamp_min, $tstamp_max);
|
||||
|
||||
// write to zipfile, cleanup
|
||||
$export_object->finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('Timesheet OpenOffice export');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Export to OpenOffice Spreadsheet");
|
||||
}
|
||||
|
||||
/**
|
||||
* retruns file suffix for exported file
|
||||
*
|
||||
* @return string suffix
|
||||
*/
|
||||
public static function get_filesuffix() {
|
||||
return 'ods';
|
||||
}
|
||||
|
||||
/**
|
||||
* return html for options.
|
||||
* this way the plugin has all opertunities for options tab
|
||||
*
|
||||
* @return string html
|
||||
*/
|
||||
public function get_options_etpl() {
|
||||
return 'timesheet.export_openoffice_options';
|
||||
}
|
||||
|
||||
/**
|
||||
* returns slectors of this plugin via xajax
|
||||
*
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
return '<b>Selectors:</b>';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user