ecffc7d3bba2401636e441d2cb46a76cb8c162ed
[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 $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 = 0;
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 = company_path(). '/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                 $tcol = $this->numcols - 1;
241                 $this->sheet->setRow($this->y, 20);
242                 for ($i = 0; $i < $this->numcols; $i++)
243                         $this->sheet->writeBlank($this->y, $i, $this->formatTitle);
244                 $this->sheet->writeString($this->y, 0, $this->title, $this->formatTitle);
245                 $this->sheet->mergeCells($this->y, 0, $this->y, $tcol);
246                 $this->NewLine();
247                 $str = _("Print Out Date") . ':';
248                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
249                 $this->sheet->writeString($this->y, 1, Today() . "  ".Now(), $this->formatLeft);
250                 $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
251                 $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
252                 $this->NewLine();
253                 $str = _("Fiscal Year") . ':';
254                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
255                 $str = $this->fiscal_year;
256                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
257                 $this->sheet->writeString($this->y, $tcol-1, $this->host, $this->formatLeft);
258                 $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
259                 for ($i = 1; $i < count($this->params); $i++)
260                 {
261                         if ($this->params[$i]['from'] != '')
262                         {
263                                 $this->NewLine();
264                                 $str = $this->params[$i]['text'] . ':';
265                                 $this->sheet->writeString($this->y, 0, $str);
266                                 $str = $this->params[$i]['from'];
267                                 if ($this->params[$i]['to'] != '')
268                                         $str .= " - " . $this->params[$i]['to'];
269                                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
270                                 if ($i == 1)
271                                 {
272                                         $this->sheet->writeString($this->y, $tcol-1, $this->user, $this->formatLeft);
273                                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
274                                 }       
275                         }
276                 }
277                 if ($this->params[0] != '') // Comments
278                 {
279                         $this->NewLine();
280                         $str = _("Comments") . ':';
281                         $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
282                         $this->sheet->writeString($this->y, 1, $this->params[0], $this->formatLeft);
283                 }
284                 $this->NewLine();
285                 if ($this->headers2 != null)
286                 {
287                         for ($i = 0, $j = 0; $i < $this->numcols; $i++)
288                         {
289                                 if ($this->cols2[$j] >= $this->cols[$i] && $this->cols2[$j] <= $this->cols[$i + 1])
290                                 {
291                                         if ($this->aligns2[$j] == "right")
292                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatHeaderRight);
293                                         else    
294                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatHeaderLeft);
295                                         $j++;   
296                                 }
297                                 else
298                                         $this->sheet->writeString($this->y, $i, "", $this->formatHeaderLeft);
299                         }               
300                         $this->NewLine();
301                 }
302
303                 for ($i = 0; $i < $this->numcols; $i++)
304                 {
305                         if (!isset($this->headers[$i]))
306                                 $header = "";
307                         else
308                                 $header = $this->headers[$i];
309                         if ($this->aligns[$i] == "right")
310                                 $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderRight);
311                         else    
312                                 $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderLeft);
313                 }
314                 $this->NewLine();
315         }
316
317         function Header2($myrow, $branch, $sales_order, $bankaccount, $doctype)
318         {
319                 return;
320         }
321
322         // Alternate header style - primary differences are for PDFs
323         function Header3()
324         {
325                 // Flag to make sure we only print the company name once
326                 $companyNamePrinted = false;
327                 
328                 $this->y = 0;
329                 $tcol = $this->numcols - 1;
330                 $this->sheet->setRow($this->y, 20);
331                 // Title
332                 for ($i = 0; $i < $this->numcols; $i++)
333                         $this->sheet->writeBlank($this->y, $i, $this->formatTitle);
334                 $this->sheet->writeString($this->y, 0, $this->title, $this->formatTitle);
335                 $this->sheet->mergeCells($this->y, 0, $this->y, $tcol);
336
337                 // Dimension 1 - optional
338                 // - only print if available and not blank
339                 if (count($this->params) > 3)
340                         if ($this->params[3]['from'] != '')
341                         {
342                                 $this->NewLine();
343                                 $str = $this->params[3]['text'] . ':';
344                                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
345                                 $this->sheet->writeString($this->y, 1, $this->params[3]['from'], $this->formatLeft);
346                                 // Company Name - at end of this row
347                                 if (!$companyNamePrinted)
348                                 {
349                                         $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
350                                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
351                                         $companyNamePrinted = true;
352                                 }
353                         }
354
355
356                 // Dimension 2 - optional
357                 // - only print if available and not blank
358                 if (count($this->params) > 4)
359                         if ($this->params[4]['from'] != '')
360                         {
361                                 $this->NewLine();
362                                 $str = $this->params[4]['text'] . ':';
363                                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
364                                 $this->sheet->writeString($this->y, 1, $this->params[4]['from'], $this->formatLeft);
365                                 // Company Name - at end of this row
366                                 if (!$companyNamePrinted)
367                                 {
368                                         $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
369                                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
370                                         $companyNamePrinted = true;
371                                 }
372                         }
373                         
374                 // Tags - optional
375                 // TBD!!!               
376         
377                 // Report Date - time period covered
378                 // - can specify a range, or just the end date (and the report contents
379                 //   should make it obvious what the beginning date is)
380                 $this->NewLine();
381                 $str = _("Report Date") . ':';
382                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
383                 $str = '';
384                 if ($this->params[1]['from'] != '')
385                         $str = $this->params[1]['from'] . ' - ';
386                 $str .= $this->params[1]['to'];
387                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
388                 // Company Name - at end of this row
389                 if (!$companyNamePrinted)
390                 {
391                         $this->sheet->writeString($this->y, $tcol-1, $this->company['coy_name'], $this->formatLeft);
392                         $this->sheet->mergeCells($this->y, $tcol-1, $this->y, $tcol);
393                         $companyNamePrinted = true;
394                 }
395                         
396                 // Timestamp of when this copy of the report was generated 
397                 $this->NewLine();
398                 $str = _("Generated At") . ':';
399                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
400                 $this->sheet->writeString($this->y, 1, Today() . "  ".Now(), $this->formatLeft);
401
402                 // Name of the user that generated this copy of the report
403                 $this->NewLine();
404                 $str = _("Generated By") . ':';
405                 $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
406                 $str = $this->user;
407                 $this->sheet->writeString($this->y, 1, $str, $this->formatLeft);
408
409                 // Comments - display any user-generated comments for this copy of the report
410                 if ($this->params[0] != '')
411                 {
412                         $this->NewLine();
413                         $str = _("Comments") . ':';
414                         $this->sheet->writeString($this->y, 0, $str, $this->formatLeft);
415                         $this->sheet->writeString($this->y, 1, $this->params[0], $this->formatLeft);
416                 }
417                 $this->NewLine();
418
419                 if ($this->headers2 != null)
420                 {
421                         for ($i = 0, $j = 0; $i < $this->numcols; $i++)
422                         {
423                                 if ($this->cols2[$j] >= $this->cols[$i] && $this->cols2[$j] <= $this->cols[$i + 1])
424                                 {
425                                         if ($this->aligns2[$j] == "right")
426                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatTopHeaderRight);
427                                         else    
428                                                 $this->sheet->writeString($this->y, $i, $this->headers2[$j], $this->formatTopHeaderLeft);
429                                         $j++;   
430                                 }
431                                 else
432                                         $this->sheet->writeString($this->y, $i, "", $this->formatTopHeaderLeft);
433                         }               
434                         $this->NewLine();
435                 }
436
437                 for ($i = 0; $i < $this->numcols; $i++)
438                 {
439                         if (!isset($this->headers[$i]))
440                                 $header = "";
441                         else
442                                 $header = $this->headers[$i];
443                         if ($this->aligns[$i] == "right")
444                                 if ($this->headers2 == null)
445                                         $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderRight);
446                                 else
447                                         $this->sheet->writeString($this->y, $i, $header, $this->formatBottomHeaderRight);
448                         else    
449                                 if ($this->headers2 == null)
450                                         $this->sheet->writeString($this->y, $i, $header, $this->formatHeaderLeft);
451                                 else
452                                         $this->sheet->writeString($this->y, $i, $header, $this->formatBottomHeaderLeft);
453                 }
454                 $this->NewLine();
455         }
456
457         /**
458          * Format a numeric string date into something nicer looking.
459          *
460          * @param string $date Date string to be formatted.
461          * @param int $input_format Format of the input string.  Possible values are:<ul><li>0: user's default (default)</li></ul>
462          * @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>
463          * @access public
464          */
465         function DatePrettyPrint($date, $input_format = 0, $output_format = 0)
466         {
467                 if ($date != '')
468                 {
469                         $date = date2sql($date);
470                         $year = (int) (substr($date, 0, 4));
471                         $month = (int) (substr($date, 5, 2));
472                         $day = (int) (substr($date, 8, 2));
473                         if ($output_format == 0)
474                                 return(date('F j, Y', mktime(12, 0, 0, $month, $day, $year)));
475                         elseif ($output_format == 1)
476                                 return(date('F Y', mktime(12, 0, 0, $month, $day, $year)));
477                         elseif ($output_format == 2)
478                                 return(date('M Y', mktime(12, 0, 0, $month, $day, $year)));
479                 }
480                 else
481                         return $date;
482         }
483                 
484         function AddImage($logo, $x, $y, $w, $h)
485         {
486                 return;
487         }
488
489         function SetDrawColor($r, $g, $b)
490         {
491                 return;
492         }
493
494         function SetTextColor($r, $g, $b)
495         {
496                 return;
497         }
498
499         function SetFillColor($r, $g, $b)
500         {
501                 return;
502         }
503         
504         function GetCellPadding()
505         {
506                 return 0;
507         }
508         
509         function SetCellPadding($pad)
510         {
511                 return;
512         }
513         
514         function Text($c, $txt, $n=0, $corr=0, $r=0, $align='left', $border=0, $fill=0, $link=NULL, $stretch=0)
515         {
516                 return;
517         }
518
519         function TextWrap($xpos, $ypos, $len, $str, $align = 'left', $border = 0, $fill = 0, $link = NULL, $stretch = 0)
520         {
521                 return;
522         }
523
524         function TextCol($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0)
525         {
526                 $txt = html_entity_decode($txt);        
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                 $txt = html_entity_decode($txt);        
561                 $this->sheet->writeString($this->y, $c, $txt, $this->formatLeft);
562                 if ($n - $c > 1)
563                         $this->sheet->mergeCells($this->y, $c, $this->y, $n - 1);
564         }
565
566         function TextColLines($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=0)
567         {
568                 return;
569         }
570
571         function TextWrapLines($c, $width, $txt, $align='left', $border=0, $fill=0, $link=NULL, $stretch=0)
572         {
573                 return;
574         }
575
576         /**
577          * Crude text wrap calculator based on PDF version.
578          */
579         function TextWrapCalc($txt, $width, $spacebreak=false)
580         {
581                 // Assume an average character width
582                 $avg_char_width = 5;
583                 $ret = "";
584                 $txt2 = $txt;
585                 $w = strlen($txt) * $avg_char_width;
586                 if ($w > $width && $w > 0 && $width != 0)
587                 {
588                         $n = strlen($txt);
589                         $k = intval($n * $width / $w);
590                         if ($k > 0 && $k < $n)
591                         {
592                                 $txt2 = substr($txt, 0, $k);
593                                 if ($spacebreak && (($pos = strrpos($txt2, " ")) !== false))
594                                 {
595                                         $txt2 = substr($txt2, 0, $pos);
596                                         $ret = substr($txt, $pos+1);
597                                 }
598                                 else
599                                         $ret = substr($txt, $k);
600                         }
601                 }
602                 return array($txt2, $ret);
603         }
604
605         function SetLineStyle($style)
606         {
607                 return;
608         }
609
610         function SetLineWidth($width)
611         {
612                 return;
613         }
614         
615         function LineTo($from, $row, $to, $row2)
616         {
617                 return;
618         }
619
620         function Line($row, $height = 0)
621         {
622                 return;
623         }
624
625         function UnderlineCell($c, $r = 0, $type = 1, $linewidth = 0, $style = array())
626         {
627                 return;
628         }
629         
630         function NewLine($l=1, $np=0, $h=NULL)
631         {
632                 $this->y += $l;
633         }
634         
635         function NewPage()
636         {
637                 return;
638         }
639         
640         function ymd2Date($year, $mon, $day) // XLS internal date representation is a number between 1900-01-01 and 2078-12-31
641         {                                                                               // if we need the time part too, we have to add this value after a decimalpoint.
642         $mo = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
643         $BASE = 1900;
644                 $MAXYEAR = 2075;
645                 if (($year % 4) == 0)
646                 $mo[2]++;
647         if ($mon < 1)
648             $mon = 1;
649         elseif ($mon > 12)
650             $mon = 12;
651         if ($day < 1)
652             $day = 1;
653         elseif ($day > $mo[$mon])
654             $day = $mo[$mon];
655         if ($year < $BASE)
656             $year = $BASE;
657         elseif ($year > $MAXYEAR)
658             $year = $MAXYEAR;
659         $jul = (int)$day;
660         for ($n = 1; $n < $mon; $n++)
661         {
662             $jul += $mo[$n];
663         }
664         for ($n = $BASE; $n < $year; $n++)
665         {
666             $jul += 365;
667             if (($n % 4) == 0)
668                 $jul++;
669         }
670         return $jul;
671         }
672   
673         function px2units($px) // XLS app conversion. Not bulletproof.
674         {
675                 $excel_column_width_factor = 256;
676                 $unit_offset_length = $this->excelColWidthFactor;
677                 return ($px / $unit_offset_length);
678         }       
679
680         function End($email=0, $subject=null, $myrow=null, $doctype = 0)
681         {
682                 for ($i = 0; $i < $this->numcols; $i++)
683                         $this->sheet->writeBlank($this->y, $i, $this->formatFooter);
684                 $this->sheet->mergeCells($this->y, 0, $this->y, $this->numcols - 1);
685                 $this->close();
686                 // first have a look through the directory, 
687                 // and remove old temporary pdfs
688                 if ($d = @opendir($this->path)) {
689                         while (($file = readdir($d)) !== false) {
690                                 if (!is_file($this->path.'/'.$file) || $file == 'index.php') continue;
691                                 // then check to see if this one is too old
692                                 $ftime = filemtime($this->path.'/'.$file);
693                                 // seems 3 min is enough for any report download, isn't it?
694                                 if (time()-$ftime > 180){
695                                         unlink($this->path.'/'.$file);
696                                 }
697                         }
698                         closedir($d);
699                 }
700                 meta_forward($_SERVER['PHP_SELF'], "xls=1&filename=$this->filename&unique=$this->unique_name");
701                 exit();
702         }
703 }
704
705 ?>