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