source: contrib/Timesheet/inc/class.export_timesheet_openoffice.inc.php @ 3526

Revision 3526, 5.7 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado modulos Timesheet e DMS para a comunidade.

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * eGroupWare
4 *
5 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
6 * @package timesheet
7 * @subpackage importexport
8 * @link http://www.egroupware.org
9 * @author Knut Moeller <k.moeller@metaways.de>
10 * @copyright Knut Moeller <k.moeller@metaways.de>
11 * @version $Id: $
12 */
13
14require_once(PHPGW_INCLUDE_ROOT. '/etemplate/inc/class.etemplate.inc.php');
15require_once(PHPGW_INCLUDE_ROOT. '/importexport/inc/class.iface_export_plugin.inc.php');
16require_once(PHPGW_INCLUDE_ROOT. '/timesheet/inc/class.uitimesheet.inc.php');
17require_once(PHPGW_INCLUDE_ROOT. '/timesheet/inc/class.botimesheet.inc.php');
18
19/**
20 * export plugin of addressbook
21 */
22class export_timesheet_openoffice implements iface_export_plugin {
23
24
25
26        /**
27         * Exports records as defined in $_definition
28         *
29         * @param phpgw_record $_definition
30         */
31        public static function export( $_stream, $_charset, definition $_definition) {
32
33                $options = $_definition->options;
34
35                $botimesheet = new botimesheet();
36
37                        // get current display selection
38
39                $query = $GLOBALS['phpgw']->session->appsession('index',TIMESHEET_APP);
40
41                $bo_pm = CreateObject('projectmanager.boprojectmanager');
42            $childs = $bo_pm->children( $query['col_filter']['pm_id'] );
43            $childs[] = $query['col_filter']['pm_id'];
44            $pmChilds = implode(",",$childs);
45            $botimesheet->db->select(    'phpgw_links','link_id, link_id1','',
46                           __LINE__,__FILE__,False,
47                           '',False,0,
48                           'JOIN phpgw_pm_projects ON (pm_id = link_id2)
49                                                JOIN phpgw_timesheet ON (ts_id=link_id1)
50                            WHERE
51                               link_app1 = \'timesheet\' AND
52                               link_app2 = \'projectmanager\' AND
53                               link_id2 IN ('.$pmChilds.') AND ts_start >= '.$query['startdate'].' AND ts_start < '.$query['enddate'] );
54
55                while($row = $botimesheet->db->row(true)) {
56               $tslist[$row['link_id']] = $row['link_id1'];
57            }
58
59//error_log(print_r($query,true));
60//error_log(print_r($tslist,true));
61
62                $ids = implode(',', $tslist);
63
64                // no result
65                if (strlen($ids)==0) return false;
66
67//error_log('IDS: '.$ids);
68
69                        // get full result
70
71                $rows = $botimesheet->search(array("phpgw_timesheet.ts_id IN ($ids)"),
72                                                                        false, 'ts_owner,ts_start', array('cat_name') ,
73                                                                        '', false, 'AND', false, null,
74                                        'LEFT JOIN phpgw_categories ON (phpgw_categories.cat_id=phpgw_timesheet.cat_id AND phpgw_categories.cat_appname=\'timesheet\')');
75
76
77                if (is_array($rows) && count($rows)>0 ) {
78//error_log(print_r($rows,true));
79                                // export rows
80
81                        $export_object = new export_openoffice($_stream, $charset, (array)$options);
82                        $export_object->init();
83
84
85                                // get date values
86
87                        $tstamp_min = 0;                                // date range for table date entries (KW...)
88                        $tstamp_max = 0;
89
90                        foreach($rows as $row)  {
91                                if ($row['ts_start']<$tstamp_min || $tstamp_min == 0) $tstamp_min = $row['ts_start'];
92                                if ($row['ts_start']>$tstamp_max || $tstamp_max == 0) $tstamp_max = $row['ts_start'];
93                        }
94
95
96                                // init summarytable
97                        $export_object->create_summarytable();
98
99
100                                // user tables
101                        $last_username = 0;
102                        $first_table = true;
103
104                        foreach($rows as $row)  {
105
106                                        // read in extra values (custom fields)
107                                $extrarows = $botimesheet->search(array("phpgw_timesheet.ts_id=".$row['ts_id']), false, '', 'ts_extra_name,ts_extra_value' ,
108                                                                                        '', false, 'AND', false, null,
109                                                                                        'LEFT JOIN phpgw_timesheet_extra ON (phpgw_timesheet_extra.ts_id=phpgw_timesheet.ts_id)'  );
110                                $extras = array();
111                                foreach($extrarows as $extrarow) {
112                                        $extras[$extrarow['ts_extra_name']] = $extrarow['ts_extra_value'];
113                                }
114
115                                // change projectname
116                                $titleRegex = '/^.*:.*-\s(.*)$/';
117                                preg_match($titleRegex,  $row['ts_project'], $title);
118                                $row['ts_project'] = $title[1];
119
120                                // get firstname, lastname
121                                $res = array();
122//                              $nameRegex = '/\s(.*)\s(.*)$/';  // z.B. "[admin] Richard Blume"
123                                $nameRegex = '/(.*),\s(.*)$/';  // z.B. "Blume, Richard"
124                                preg_match($nameRegex, $GLOBALS['phpgw']->common->grab_owner_name($row['ts_owner']), $res);
125// error_log('|'.$name . '| -> ' . print_r($res,true));
126                                $firstname = $res[2];
127                                $lastname = $res[1];
128                                $fullname = $firstname.' '.$lastname;
129
130                                // new table on username change
131                                if ($row['ts_owner'] != $last_username) {
132
133                                                // create sum as last tablerow before creating new table
134                                        if (!$first_table) {
135                                                $export_object->summarize();
136                                        }
137                                        else {
138                                                $first_table = false;
139                                        }
140
141                                                // create new table sheet
142                                        $export_object->create_usertable($lastname,
143                                                                                $fullname, $tstamp_min, $tstamp_max);
144
145                                }
146                                $export_object->add_record($row, $extras);
147                                $last_username = $row['ts_owner'];
148                        }
149                        $export_object->summarize();  // for last table
150
151                                // fill collected sums into sum-table
152                        $export_object->fill_summarytable($tstamp_min, $tstamp_max);
153
154                                // write to zipfile, cleanup
155                        $export_object->finalize();
156                }
157        }
158
159        /**
160         * returns translated name of plugin
161         *
162         * @return string name
163         */
164        public static function get_name() {
165                return lang('Timesheet OpenOffice export');
166        }
167
168        /**
169         * returns translated (user) description of plugin
170         *
171         * @return string descriprion
172         */
173        public static function get_description() {
174                return lang("Export to OpenOffice Spreadsheet");
175        }
176
177        /**
178         * retruns file suffix for exported file
179         *
180         * @return string suffix
181         */
182        public static function get_filesuffix() {
183                return 'ods';
184        }
185
186        /**
187         * return html for options.
188         * this way the plugin has all opertunities for options tab
189         *
190         * @return string html
191         */
192        public static function get_options_etpl() {
193                return 'timesheet.export_openoffice_options';
194        }
195
196        /**
197         * returns slectors of this plugin via xajax
198         *
199         */
200        public static function get_selectors_etpl() {
201                return '<b>Selectors:</b>';
202        }
203}
204
205
Note: See TracBrowser for help on using the repository browser.