Allowing the Tax Report to be printed to Excel/OO Calc
[fa-stable.git] / reporting / includes / excel_report.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/reporting/includes/Workbook.php");
13 include_once($path_to_root . "/admin/db/company_db.inc");
14 include_once($path_to_root . "/config.php");
15 // xls version
16 class FrontReport extends Spreadsheet_Excel_Writer_Workbook
17 {
18         var $size;
19         var $company;
20         var $user;
21         var $host;
22         var $fiscal_year;
23         var $title;
24         var $filename;
25         var $unique_name;
26         var $path;
27         var $code;
28         var $bottomMargin = 0;
29         var $lineHeight;
30         var $leftMargin = 0;
31
32         var $cols;
33         var $params;
34         var $headers;
35         var $aligns;
36         var $headers2;
37         var $aligns2;
38         var $cols2;
39         var $fontSize;
40         var $oldFontSize;
41         var $currency;
42         var $row = 9999999;
43         var $y;
44         var $numcols;
45         var $excelColWidthFactor;
46         var $endLine;
47
48         var $formatTitle;
49         var $formatDateTime;
50         var $formatDate;
51         var $formatHeaderLeft;
52         var $formatHeaderRight;
53         var $formatFooter;
54         var $formatAmount = array();
55         
56         var $sheet;
57
58         function FrontReport($title, $filename, $size = 'A4', $fontsize = 9, $orientation = 'P', $margins = NULL, $excelColWidthFactor = 6.5)
59         {
60                 global $comp_path, $dateseps, $page_security;
61                 if (!$_SESSION["wa_current_user"]->can_access_page($page_security))
62                 {
63                         display_error(_("The security settings on your account do not permit you to print this report"));
64                         end_page();
65                         exit;
66                 }
67                 $this->size = $size;
68                 $this->title = $title;
69                 $this->lineHeight = 12;
70                 $this->endLine = 760;
71                 $this->fontSize = $fontsize;
72                 $this->oldFontSize = 0;
73                 $this->y = 0;
74                 $this->currency = '';
75                 $this->excelColWidthFactor = $excelColWidthFactor;
76                 $rtl = ($_SESSION['language']->dir == 'rtl');
77                 $this->code = strtolower($_SESSION['language']->encoding);
78                 $this->filename = $filename.".xls";
79                 $this->unique_name = uniqid('').".xls";
80                 $this->path = $comp_path.'/'.user_company(). '/pdf_files';
81                 $this->Spreadsheet_Excel_Writer_Workbook($this->path."/".$this->unique_name);
82                 //$this->setCountry(48);
83                 if ($this->code != "iso-8859-1")
84                         $this->setVersion(8); // set biff version to 8 (0x0006 internal)
85                 $this->sheet =& $this->addWorksheet($this->worksheetNameGenerator($this->title));
86                 if ($this->code != "iso-8859-1")
87                         $this->sheet->setInputEncoding($this->code); // set sheet encoding
88                 if ($rtl)
89                         $this->sheet->setRTL();
90                 $this->formatTitle =& $this->addFormat();       
91                 $this->formatTitle->setSize(16);
92                 $this->formatTitle->setBold();
93                 $this->formatTitle->setAlign($rtl ? 'right' : 'left');
94                 $this->formatTitle->setTop(2);
95                 $this->formatTitle->setTopColor('gray');
96
97                 $how = user_date_format();
98                 $sep = $dateseps[user_date_sep()];
99                 if ($sep == '.')
100                         $sep = "\\.";
101                 if ($how == 0)
102                 {
103                         $dateformat_long = "mm{$sep}dd{$sep}yyyy\ \ hh:mm\ am/pm";
104                         $dateformat = "mm{$sep}dd{$sep}yyyy";
105                 }       
106                 elseif ($how == 1)      
107                 {
108                         $dateformat_long = "dd{$sep}mm{$sep}yyyy\ \ hh:mm";
109                         $dateformat = "dd{$sep}mm{$sep}yyyy";
110                 }       
111                 else    
112                 {
113                         $dateformat_long = "yyyy{$sep}mm{$sep}dd\ \ hh:mm";
114                         $dateformat = "yyyy{$sep}mm{$sep}dd";
115                 }       
116                 $this->formatDateTime =& $this->addFormat();
117                 $this->formatDateTime->setNumFormat($dateformat_long);
118                 $this->formatDateTime->setAlign($rtl ? 'right' : 'left');
119                 $this->formatDate =& $this->addFormat();
120                 $this->formatDate->setNumFormat($dateformat);
121                 $this->formatDate->setAlign($rtl ? 'right' : 'left');
122                 $this->formatRight =& $this->addFormat();
123                 $this->formatRight->setAlign($rtl ? 'left' : 'right');
124                 $this->formatLeft =& $this->addFormat();
125                 $this->formatLeft->setAlign($rtl ? 'right' : 'left');
126                 
127                 $this->formatHeaderLeft =& $this->addFormat();
128                 $this->formatHeaderLeft->setItalic();
129                 $this->formatHeaderLeft->setTop(2);
130                 $this->formatHeaderLeft->setTopColor('gray');
131                 $this->formatHeaderLeft->setBottom(2);
132                 $this->formatHeaderLeft->setBottomColor('gray');
133                 $this->formatHeaderLeft->setAlign('vcenter');
134                 $this->formatTopHeaderLeft =& $this->addFormat();
135                 $this->formatTopHeaderLeft->setItalic();
136                 $this->formatTopHeaderLeft->setTop(2);
137                 $this->formatTopHeaderLeft->setTopColor('gray');
138                 $this->formatTopHeaderLeft->setAlign('vcenter');
139                 $this->formatBottomHeaderLeft =& $this->addFormat();
140                 $this->formatBottomHeaderLeft->setItalic();
141                 $this->formatBottomHeaderLeft->setBottom(2);
142                 $this->formatBottomHeaderLeft->setBottomColor('gray');
143                 $this->formatBottomHeaderLeft->setAlign('vcenter');
144                 $this->formatDate->setAlign($rtl ? 'right' : 'left');
145                 $this->formatHeaderRight =& $this->addFormat();
146                 $this->formatHeaderRight->setItalic();
147                 $this->formatHeaderRight->setTop(2);
148                 $this->formatHeaderRight->setTopColor('gray');
149                 $this->formatHeaderRight->setBottom(2);
150                 $this->formatHeaderRight->setBottomColor('gray');
151                 $this->formatHeaderRight->setAlign('vcenter');
152                 $this->formatHeaderRight->setAlign('right');
153                 $this->formatTopHeaderRight =& $this->addFormat();
154                 $this->formatTopHeaderRight->setItalic();
155                 $this->formatTopHeaderRight->setTop(2);
156                 $this->formatTopHeaderRight->setTopColor('gray');
157                 $this->formatTopHeaderRight->setAlign('vcenter');
158                 $this->formatTopHeaderRight->setAlign('right');
159                 $this->formatBottomHeaderRight =& $this->addFormat();
160                 $this->formatBottomHeaderRight->setItalic();
161                 $this->formatBottomHeaderRight->setBottom(2);
162                 $this->formatBottomHeaderRight->setBottomColor('gray');
163                 $this->formatBottomHeaderRight->setAlign('vcenter');
164                 $this->formatBottomHeaderRight->setAlign('right');
165                 $this->formatFooter =& $this->addFormat();
166                 $this->formatFooter->setTop(2);
167                 $this->formatFooter->setTopColor('gray');
168         }
169         
170
171         // Check a given name to see if it's a valid Excel worksheet name,
172         // and fix if necessary
173         function worksheetNameGenerator($name)
174         {
175                 // First, strip out characters which aren't allowed
176                 $illegal_chars = array(':', '\\', '/', '?', '*', '[', ']');
177                 for ($i = 0; $i < count($illegal_chars); $i++)
178                         $name = str_replace($illegal_chars[$i], '', $name);
179                 // Now, if name is longer than 31 chars, truncate it
180                 if (strlen($name) > 31)
181                         $name = substr($name, 0, 31);
182                 return $name;
183         }
184         
185         function NumFormat($dec) 
186         {
187                 if (!isset($this->formatAmount[$dec]))
188                 {
189                         //global $thoseps,$decseps;
190                         $dec = (int)$dec;
191                         //$tsep = $thoseps[user_tho_sep()];
192                         //$dsep = $decseps[user_dec_sep()];
193                         $tsep = ',';
194                         $dsep = '.';
195                         $format = "###{$tsep}###{$tsep}###{$tsep}##0";
196                         if ($dec>0)
197                                 $format .= "{$dsep}".str_repeat('0',$dec);
198                         $this->formatAmount[$dec] =& $this->addFormat();
199                         $this->formatAmount[$dec]->setNumFormat($format);
200                         $this->formatAmount[$dec]->setAlign('right');
201                 }
202                 return $this->formatAmount[$dec];
203         }
204
205         function Font($fontname = '', $style = 'normal')
206         {
207         }
208
209         function Info($params, $cols, $headers, $aligns,
210                 $cols2 = null, $headers2 = null, $aligns2 = null)
211         {
212                 global $app_title, $version, $power_by, $power_url;
213                 $this->company = get_company_prefs();
214                 $year = get_current_fiscalyear();
215                 if ($year['closed'] == 0)
216                         $how = _("Active");
217                 else
218                         $how = _("Closed");
219                 $this->fiscal_year = sql2date($year['begin']) . " - " . sql2date($year['end']) . "  " . "(" . $how . ")";
220                 $this->user = $_SESSION["wa_current_user"]->name;
221                 $this->host = $_SERVER['SERVER_NAME'];
222                 $this->params = $params;
223                 $this->cols = $cols;
224                 $this->headers = $headers;
225                 $this->aligns = $aligns;
226                 $this->cols2 = $cols2;
227                 $this->headers2 = $headers2;
228                 $this->aligns2 = $aligns2;
229                 $this->numcols = count($this->headers);
230                 $tcols = count($this->headers2);
231                 if ($tcols > $this->numcols)
232                         $this->numcols = $tcols;
233                 for ($i = 0; $i < $this->numcols; $i++)
234                         $this->sheet->setColumn($i, $i, $this->px2units($this->cols[$i + 1] - $this->cols[$i]));
235         }
236
237         function Header()
238         {
239                 $tcol = $this->numcols - 1;
240                 $this->sheet->setRow($this->y, 20);
241                 for ($i = 0; $i < $this->numcols; $i++)
242                         $this->sheet->writeBlank($this->y, $i, $this->formatTitle);
243                 $this->sheet->writeString($this->y, 0, $this->title, $this->formatTitle);
244                 $this->sheet->mergeCells($this->y, 0, $this->y, $tcol);
245                 $this->NewLine();
246                 $str = _("Print Out Date") . ':';
247                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
248                 $this->sheet->writeString($this->y, 1, Today() . "  ".Now(), $this->formatLeft);
249                 $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
250                 $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
251                 $this->NewLine();
252                 $str = _("Fiscal Year") . ':';
253                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
254                 $str = $this->fiscal_year;
255                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
256                 $this->sheet->writeString($this->y, $tcol-1, $this->host, $this->formatLeft);
257                 $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
258                 for ($i = 1; $i < count($this->params); $i++)
259                 {
260                         if ($this->params[$i]['from'] != '')
261                         {
262                                 $this->NewLine();
263                                 $str = $this->params[$i]['text'] . ':';
264                                 $this->sheet->writeString($this->y, 0, $str);
265                                 $str = $this->params[$i]['from'];
266                                 if ($this->params[$i]['to'] != '')
267                                         $str .= " - " . $this->params[$i]['to'];
268                                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
269                                 if ($i == 1)
270                                 {
271                                         $this->sheet->writeString($this->y, $tcol-1, $this->user, $this->formatLeft);
272                                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
273                                 }       
274                         }
275                 }
276                 if ($this->params[0] != '') // Comments
277                 {
278                         $this->NewLine();
279                         $str = _("Comments") . ':';
280                         $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
281                         $this->sheet->writeString($this->y, 1, $this->params[0], $this->formatLeft);
282                 }
283                 $this->NewLine();
284                 if ($this->headers2 != null)
285                 {
286                         for ($i = 0, $j = 0; $i < $this->numcols; $i++)
287                         {
288                                 if ($this->cols2[$j] >= $this->cols[$i] && $this->cols2[$j] <= $this->cols[$i + 1])
289                                 {
290                                         if ($this->aligns2[$j] == "right")
291                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatHeaderRight);
292                                         else    
293                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatHeaderLeft);
294                                         $j++;   
295                                 }
296                                 else
297                                         $this->sheet->writeString($this->y, $i, "", $this->formatHeaderLeft);
298                         }               
299                         $this->NewLine();
300                 }
301
302                 for ($i = 0; $i < $this->numcols; $i++)
303                 {
304                         if (!isset($this->headers[$i]))
305                                 $header = "";
306                         else
307                                 $header = $this->headers[$i];
308                         if ($this->aligns[$i] == "right")
309                                 $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderRight);
310                         else    
311                                 $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderLeft);
312                 }
313                 $this->NewLine();
314         }
315
316         function Header2($myrow, $branch, $sales_order, $bankaccount, $doctype)
317         {
318                 return;
319         }
320
321         // Alternate header style - primary differences are for PDFs
322         function Header3()
323         {
324                 // Flag to make sure we only print the company name once
325                 $companyNamePrinted = false;
326                 
327                 $this->y = 0;
328                 $tcol = $this->numcols - 1;
329                 $this->sheet->setRow($this->y, 20);
330                 // Title
331                 for ($i = 0; $i < $this->numcols; $i++)
332                         $this->sheet->writeBlank($this->y, $i, $this->formatTitle);
333                 $this->sheet->writeString($this->y, 0, $this->title, $this->formatTitle);
334                 $this->sheet->mergeCells($this->y, 0, $this->y, $tcol);
335
336                 // Dimension 1 - optional
337                 // - only print if available and not blank
338                 if (count($this->params) > 3)
339                         if ($this->params[3]['from'] != '')
340                         {
341                                 $this->NewLine();
342                                 $str = $this->params[3]['text'] . ':';
343                                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
344                                 $this->sheet->writeString($this->y, 1, $this->params[3]['from'], $this->formatLeft);
345                                 // Company Name - at end of this row
346                                 if (!$companyNamePrinted)
347                                 {
348                                         $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
349                                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
350                                         $companyNamePrinted = true;
351                                 }
352                         }
353
354
355                 // Dimension 2 - optional
356                 // - only print if available and not blank
357                 if (count($this->params) > 4)
358                         if ($this->params[4]['from'] != '')
359                         {
360                                 $this->NewLine();
361                                 $str = $this->params[4]['text'] . ':';
362                                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
363                                 $this->sheet->writeString($this->y, 1, $this->params[4]['from'], $this->formatLeft);
364                                 // Company Name - at end of this row
365                                 if (!$companyNamePrinted)
366                                 {
367                                         $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
368                                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
369                                         $companyNamePrinted = true;
370                                 }
371                         }
372                         
373                 // Tags - optional
374                 // TBD!!!               
375         
376                 // Report Date - time period covered
377                 // - can specify a range, or just the end date (and the report contents
378                 //   should make it obvious what the beginning date is)
379                 $this->NewLine();
380                 $str = _("Report Date") . ':';
381                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
382                 $str = '';
383                 if ($this->params[1]['from'] != '')
384                         $str = $this->params[1]['from'] . ' - ';
385                 $str .= $this->params[1]['to'];
386                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
387                 // Company Name - at end of this row
388                 if (!$companyNamePrinted)
389                 {
390                         $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
391                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
392                         $companyNamePrinted = true;
393                 }
394                         
395                 // Timestamp of when this copy of the report was generated 
396                 $this->NewLine();
397                 $str = _("Generated At") . ':';
398                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
399                 $this->sheet->writeString($this->y, 1, Today() . "  ".Now(), $this->formatLeft);
400
401                 // Name of the user that generated this copy of the report
402                 $this->NewLine();
403                 $str = _("Generated By") . ':';
404                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
405                 $str = $this->user;
406                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
407
408                 // Comments - display any user-generated comments for this copy of the report
409                 if ($this->params[0] != '')
410                 {
411                         $this->NewLine();
412                         $str = _("Comments") . ':';
413                         $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
414                         $this->sheet->writeString($this->y, 1, $this->params[0], $this->formatLeft);
415                 }
416                 $this->NewLine();
417
418                 if ($this->headers2 != null)
419                 {
420                         for ($i = 0, $j = 0; $i < $this->numcols; $i++)
421                         {
422                                 if ($this->cols2[$j] >= $this->cols[$i] && $this->cols2[$j] <= $this->cols[$i + 1])
423                                 {
424                                         if ($this->aligns2[$j] == "right")
425                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatTopHeaderRight);
426                                         else    
427                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatTopHeaderLeft);
428                                         $j++;   
429                                 }
430                                 else
431                                         $this->sheet->writeString($this->y, $i, "", $this->formatTopHeaderLeft);
432                         }               
433                         $this->NewLine();
434                 }
435
436                 for ($i = 0; $i < $this->numcols; $i++)
437                 {
438                         if (!isset($this->headers[$i]))
439                                 $header = "";
440                         else
441                                 $header = $this->headers[$i];
442                         if ($this->aligns[$i] == "right")
443                                 if ($this->headers2 == null)
444                                         $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderRight);
445                                 else
446                                         $this->sheet->writeString($this->y, $i, $header, $this->formatBottomHeaderRight);
447                         else    
448                                 if ($this->headers2 == null)
449                                         $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderLeft);
450                                 else
451                                         $this->sheet->writeString($this->y, $i, $header, $this->formatBottomHeaderLeft);
452                 }
453                 $this->NewLine();
454         }
455
456         /**
457          * Format a numeric string date into something nicer looking.
458          *
459          * @param string $date Date string to be formatted.
460          * @param int $input_format Format of the input string.  Possible values are:<ul><li>0: user's default (default)</li></ul>
461          * @param int $output_format Format of the output string.  Possible values are:<ul><li>0: Month (word) Day (numeric), 4-digit Year - Example: January 1, 2000 (default)</li><li>1: Month 4-digit Year - Example: January 2000</li><li>2: Month Abbreviation 4-digit Year - Example: Jan 2000</li></ul>
462          * @access public
463          */
464         function DatePrettyPrint($date, $input_format = 0, $output_format = 0)
465         {
466                 if ($date != '')
467                 {
468                         $date = date2sql($date);
469                         $year = (int) (substr($date, 0, 4));
470                         $month = (int) (substr($date, 5, 2));
471                         $day = (int) (substr($date, 8, 2));
472                         if ($output_format == 0)
473                                 return(date('F j, Y', mktime(12, 0, 0, $month, $day, $year)));
474                         elseif ($output_format == 1)
475                                 return(date('F Y', mktime(12, 0, 0, $month, $day, $year)));
476                         elseif ($output_format == 2)
477                                 return(date('M Y', mktime(12, 0, 0, $month, $day, $year)));
478                 }
479                 else
480                         return $date;
481         }
482                 
483         function AddImage($logo, $x, $y, $w, $h)
484         {
485                 return;
486         }
487
488         function SetDrawColor($r, $g, $b)
489         {
490                 return;
491         }
492
493         function SetTextColor($r, $g, $b)
494         {
495                 return;
496         }
497
498         function SetFillColor($r, $g, $b)
499         {
500                 return;
501         }
502         
503         function GetCellPadding()
504         {
505                 return 0;
506         }
507         
508         function SetCellPadding($pad)
509         {
510                 return;
511         }
512         
513         function Text($c, $txt, $n=0, $corr=0, $r=0, $align='left', $border=0, $fill=0, $link=NULL, $stretch=0)
514         {
515                 return;
516         }
517
518         function TextWrap($xpos, $ypos, $len, $str, $align = 'left', $border = 0, $fill = 0, $link = NULL, $stretch = 0)
519         {
520                 return;
521         }
522
523         function TextCol($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0)
524         {
525                 if ($this->aligns[$c] == 'right')
526                         $this->sheet->writeString($this->y, $c, $txt, $this->formatRight);
527                 else    
528                         $this->sheet->writeString($this->y, $c, $txt, $this->formatLeft);
529                 if ($n - $c > 1)
530                         $this->sheet->mergeCells($this->y, $c, $this->y, $n - 1);
531         }
532
533         function AmountCol($c, $n, $txt, $dec=0, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0, $color_red=false) 
534         { 
535                 if (!is_numeric($txt))
536                         $txt = 0;
537                 $this->sheet->writeNumber($this->y, $c, $txt, $this->NumFormat($dec)); 
538         }
539         
540         function AmountCol2($c, $n, $txt, $dec=0, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0, $color_red=false, $amount_locale = NULL, $amount_format = NULL) 
541         { 
542                 if (!is_numeric($txt))
543                         $txt = 0;
544                 $this->sheet->writeNumber($this->y, $c, $txt, $this->NumFormat($dec)); 
545         }
546         
547         function DateCol($c, $n, $txt, $conv=false, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0) 
548         {
549                 if (!$conv)
550                         $txt = date2sql($txt);
551                 list($year, $mo, $day) = explode("-", $txt);    
552                 $date = $this->ymd2date((int)$year, (int)$mo, (int)$day);
553                 $this->sheet->writeNumber($this->y, $c, $date, $this->formatDate);
554         }
555
556         function TextCol2($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0)
557         {
558                 $this->sheet->writeString($this->y, $c, $txt, $this->formatLeft);
559                 if ($n - $c > 1)
560                         $this->sheet->mergeCells($this->y, $c, $this->y, $n - 1);
561         }
562
563         function TextColLines($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0)
564         {
565                 return;
566         }
567
568         function TextWrapLines($c, $width, $txt, $align='left', $border=0, $fill=0, $link=NULL, $stretch=0)
569         {
570                 return;
571         }
572
573         /**
574          * Crude text wrap calculator based on PDF version.
575          */
576         function TextWrapCalc($txt, $width, $spacebreak=false)
577         {
578                 // Assume an average character width
579                 $avg_char_width = 5;
580                 $ret = "";
581                 $txt2 = $txt;
582                 $w = strlen($txt) * $avg_char_width;
583                 if ($w > $width && $w > 0 && $width != 0)
584                 {
585                         $n = strlen($txt);
586                         $k = intval($n * $width / $w);
587                         if ($k > 0 && $k < $n)
588                         {
589                                 $txt2 = substr($txt, 0, $k);
590                                 if ($spacebreak && (($pos = strrpos($txt2, " ")) !== false))
591                                 {
592                                         $txt2 = substr($txt2, 0, $pos);
593                                         $ret = substr($txt, $pos+1);
594                                 }
595                                 else
596                                         $ret = substr($txt, $k);
597                         }
598                 }
599                 return array($txt2, $ret);
600         }
601
602         function SetLineStyle($style)
603         {
604                 return;
605         }
606
607         function SetLineWidth($width)
608         {
609                 return;
610         }
611         
612         function LineTo($from, $row, $to, $row2)
613         {
614                 return;
615         }
616
617         function Line($row, $height = 0)
618         {
619                 return;
620         }
621
622         function UnderlineCell($c, $r = 0, $type = 1, $linewidth = 0, $style = array())
623         {
624                 return;
625         }
626         
627         function NewLine($l=1, $np=0, $h=NULL)
628         {
629                 $this->y += $l;
630         }
631
632         function ymd2Date($year, $mon, $day) // XLS internal date representation is a number between 1900-01-01 and 2078-12-31
633         {                                                                               // if we need the time part too, we have to add this value after a decimalpoint.
634         $mo = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
635         $BASE = 1900;
636                 $MAXYEAR = 2075;
637                 if (($year % 4) == 0)
638                 $mo[2]++;
639         if ($mon < 1)
640             $mon = 1;
641         elseif ($mon > 12)
642             $mon = 12;
643         if ($day < 1)
644             $day = 1;
645         elseif ($day > $mo[$mon])
646             $day = $mo[$mon];
647         if ($year < $BASE)
648             $year = $BASE;
649         elseif ($year > $MAXYEAR)
650             $year = $MAXYEAR;
651         $jul = (int)$day;
652         for ($n = 1; $n < $mon; $n++)
653         {
654             $jul += $mo[$n];
655         }
656         for ($n = $BASE; $n < $year; $n++)
657         {
658             $jul += 365;
659             if (($n % 4) == 0)
660                 $jul++;
661         }
662         return $jul;
663         }
664   
665         function px2units($px) // XLS app conversion. Not bulletproof.
666         {
667                 $excel_column_width_factor = 256;
668                 $unit_offset_length = $this->excelColWidthFactor;
669                 return ($px / $unit_offset_length);
670         }       
671
672         function End($email=0, $subject=null, $myrow=null, $doctype = 0)
673         {
674                 for ($i = 0; $i < $this->numcols; $i++)
675                         $this->sheet->writeBlank($this->y, $i, $this->formatFooter);
676                 $this->sheet->mergeCells($this->y, 0, $this->y, $this->numcols - 1);
677                 $this->close();
678                 // first have a look through the directory, 
679                 // and remove old temporary pdfs
680                 if ($d = @opendir($this->path)) {
681                         while (($file = readdir($d)) !== false) {
682                                 if (!is_file($this->path.'/'.$file) || $file == 'index.php') continue;
683                                 // then check to see if this one is too old
684                                 $ftime = filemtime($this->path.'/'.$file);
685                                 // seems 3 min is enough for any report download, isn't it?
686                                 if (time()-$ftime > 180){
687                                         unlink($this->path.'/'.$file);
688                                 }
689                         }
690                         closedir($d);
691                 }
692                 meta_forward($_SERVER['PHP_SELF'], "xls=1&filename=$this->filename&unique=$this->unique_name");
693                 exit();
694         }
695 }
696
697 ?>