00001 <?php
00002 include_once ('class.pdf.php');
00003
00004 class Cezpdf extends Cpdf
00005 {
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 var $ez = array('fontSize' => 10);
00022 var $y = 0.0;
00023 var $ezPages = array(
00024 );
00025
00026 var $ezPageCount = 0;
00027
00028
00029
00030 function Cezpdf($paper = 'a4', $orientation = 'portrait')
00031 {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 if (!is_array($paper))
00047 {
00048 switch (strtoupper($paper))
00049 {
00050 case '4A0':
00051 {
00052 $size = array
00053 (
00054 0,
00055 0,
00056 4767.87,
00057 6740.79
00058 );
00059
00060 break;
00061 }
00062
00063 case '2A0':
00064 {
00065 $size = array
00066 (
00067 0,
00068 0,
00069 3370.39,
00070 4767.87
00071 );
00072
00073 break;
00074 }
00075
00076 case 'A0':
00077 {
00078 $size = array
00079 (
00080 0,
00081 0,
00082 2383.94,
00083 3370.39
00084 );
00085
00086 break;
00087 }
00088
00089 case 'A1':
00090 {
00091 $size = array
00092 (
00093 0,
00094 0,
00095 1683.78,
00096 2383.94
00097 );
00098
00099 break;
00100 }
00101
00102 case 'A2':
00103 {
00104 $size = array
00105 (
00106 0,
00107 0,
00108 1190.55,
00109 1683.78
00110 );
00111
00112 break;
00113 }
00114
00115 case 'A3':
00116 {
00117 $size = array
00118 (
00119 0,
00120 0,
00121 841.89,
00122 1190.55
00123 );
00124
00125 break;
00126 }
00127
00128 case 'A4':
00129 default:
00130 {
00131 $size = array
00132 (
00133 0,
00134 0,
00135 595.28,
00136 841.89
00137 );
00138
00139 break;
00140 }
00141
00142 case 'A5':
00143 {
00144 $size = array
00145 (
00146 0,
00147 0,
00148 419.53,
00149 595.28
00150 );
00151
00152 break;
00153 }
00154
00155 case 'A6':
00156 {
00157 $size = array
00158 (
00159 0,
00160 0,
00161 297.64,
00162 419.53
00163 );
00164
00165 break;
00166 }
00167
00168 case 'A7':
00169 {
00170 $size = array
00171 (
00172 0,
00173 0,
00174 209.76,
00175 297.64
00176 );
00177
00178 break;
00179 }
00180
00181 case 'A8':
00182 {
00183 $size = array
00184 (
00185 0,
00186 0,
00187 147.40,
00188 209.76
00189 );
00190
00191 break;
00192 }
00193
00194 case 'A9':
00195 {
00196 $size = array
00197 (
00198 0,
00199 0,
00200 104.88,
00201 147.40
00202 );
00203
00204 break;
00205 }
00206
00207 case 'A10':
00208 {
00209 $size = array
00210 (
00211 0,
00212 0,
00213 73.70,
00214 104.88
00215 );
00216
00217 break;
00218 }
00219
00220 case 'B0':
00221 {
00222 $size = array
00223 (
00224 0,
00225 0,
00226 2834.65,
00227 4008.19
00228 );
00229
00230 break;
00231 }
00232
00233 case 'B1':
00234 {
00235 $size = array
00236 (
00237 0,
00238 0,
00239 2004.09,
00240 2834.65
00241 );
00242
00243 break;
00244 }
00245
00246 case 'B2':
00247 {
00248 $size = array
00249 (
00250 0,
00251 0,
00252 1417.32,
00253 2004.09
00254 );
00255
00256 break;
00257 }
00258
00259 case 'B3':
00260 {
00261 $size = array
00262 (
00263 0,
00264 0,
00265 1000.63,
00266 1417.32
00267 );
00268
00269 break;
00270 }
00271
00272 case 'B4':
00273 {
00274 $size = array
00275 (
00276 0,
00277 0,
00278 708.66,
00279 1000.63
00280 );
00281
00282 break;
00283 }
00284
00285 case 'B5':
00286 {
00287 $size = array
00288 (
00289 0,
00290 0,
00291 498.90,
00292 708.66
00293 );
00294
00295 break;
00296 }
00297
00298 case 'B6':
00299 {
00300 $size = array
00301 (
00302 0,
00303 0,
00304 354.33,
00305 498.90
00306 );
00307
00308 break;
00309 }
00310
00311 case 'B7':
00312 {
00313 $size = array
00314 (
00315 0,
00316 0,
00317 249.45,
00318 354.33
00319 );
00320
00321 break;
00322 }
00323
00324 case 'B8':
00325 {
00326 $size = array
00327 (
00328 0,
00329 0,
00330 175.75,
00331 249.45
00332 );
00333
00334 break;
00335 }
00336
00337 case 'B9':
00338 {
00339 $size = array
00340 (
00341 0,
00342 0,
00343 124.72,
00344 175.75
00345 );
00346
00347 break;
00348 }
00349
00350 case 'B10':
00351 {
00352 $size = array
00353 (
00354 0,
00355 0,
00356 87.87,
00357 124.72
00358 );
00359
00360 break;
00361 }
00362
00363 case 'C0':
00364 {
00365 $size = array
00366 (
00367 0,
00368 0,
00369 2599.37,
00370 3676.54
00371 );
00372
00373 break;
00374 }
00375
00376 case 'C1':
00377 {
00378 $size = array
00379 (
00380 0,
00381 0,
00382 1836.85,
00383 2599.37
00384 );
00385
00386 break;
00387 }
00388
00389 case 'C2':
00390 {
00391 $size = array
00392 (
00393 0,
00394 0,
00395 1298.27,
00396 1836.85
00397 );
00398
00399 break;
00400 }
00401
00402 case 'C3':
00403 {
00404 $size = array
00405 (
00406 0,
00407 0,
00408 918.43,
00409 1298.27
00410 );
00411
00412 break;
00413 }
00414
00415 case 'C4':
00416 {
00417 $size = array
00418 (
00419 0,
00420 0,
00421 649.13,
00422 918.43
00423 );
00424
00425 break;
00426 }
00427
00428 case 'C5':
00429 {
00430 $size = array
00431 (
00432 0,
00433 0,
00434 459.21,
00435 649.13
00436 );
00437
00438 break;
00439 }
00440
00441 case 'C6':
00442 {
00443 $size = array
00444 (
00445 0,
00446 0,
00447 323.15,
00448 459.21
00449 );
00450
00451 break;
00452 }
00453
00454 case 'C7':
00455 {
00456 $size = array
00457 (
00458 0,
00459 0,
00460 229.61,
00461 323.15
00462 );
00463
00464 break;
00465 }
00466
00467 case 'C8':
00468 {
00469 $size = array
00470 (
00471 0,
00472 0,
00473 161.57,
00474 229.61
00475 );
00476
00477 break;
00478 }
00479
00480 case 'C9':
00481 {
00482 $size = array
00483 (
00484 0,
00485 0,
00486 113.39,
00487 161.57
00488 );
00489
00490 break;
00491 }
00492
00493 case 'C10':
00494 {
00495 $size = array
00496 (
00497 0,
00498 0,
00499 79.37,
00500 113.39
00501 );
00502
00503 break;
00504 }
00505
00506 case 'RA0':
00507 {
00508 $size = array
00509 (
00510 0,
00511 0,
00512 2437.80,
00513 3458.27
00514 );
00515
00516 break;
00517 }
00518
00519 case 'RA1':
00520 {
00521 $size = array
00522 (
00523 0,
00524 0,
00525 1729.13,
00526 2437.80
00527 );
00528
00529 break;
00530 }
00531
00532 case 'RA2':
00533 {
00534 $size = array
00535 (
00536 0,
00537 0,
00538 1218.90,
00539 1729.13
00540 );
00541
00542 break;
00543 }
00544
00545 case 'RA3':
00546 {
00547 $size = array
00548 (
00549 0,
00550 0,
00551 864.57,
00552 1218.90
00553 );
00554
00555 break;
00556 }
00557
00558 case 'RA4':
00559 {
00560 $size = array
00561 (
00562 0,
00563 0,
00564 609.45,
00565 864.57
00566 );
00567
00568 break;
00569 }
00570
00571 case 'SRA0':
00572 {
00573 $size = array
00574 (
00575 0,
00576 0,
00577 2551.18,
00578 3628.35
00579 );
00580
00581 break;
00582 }
00583
00584 case 'SRA1':
00585 {
00586 $size = array
00587 (
00588 0,
00589 0,
00590 1814.17,
00591 2551.18
00592 );
00593
00594 break;
00595 }
00596
00597 case 'SRA2':
00598 {
00599 $size = array
00600 (
00601 0,
00602 0,
00603 1275.59,
00604 1814.17
00605 );
00606
00607 break;
00608 }
00609
00610 case 'SRA3':
00611 {
00612 $size = array
00613 (
00614 0,
00615 0,
00616 907.09,
00617 1275.59
00618 );
00619
00620 break;
00621 }
00622
00623 case 'SRA4':
00624 {
00625 $size = array
00626 (
00627 0,
00628 0,
00629 637.80,
00630 907.09
00631 );
00632
00633 break;
00634 }
00635
00636 case 'LETTER':
00637 {
00638 $size = array
00639 (
00640 0,
00641 0,
00642 612.00,
00643 792.00
00644 );
00645
00646 break;
00647 }
00648
00649 case 'LEGAL':
00650 {
00651 $size = array
00652 (
00653 0,
00654 0,
00655 612.00,
00656 1008.00
00657 );
00658
00659 break;
00660 }
00661
00662 case 'EXECUTIVE':
00663 {
00664 $size = array
00665 (
00666 0,
00667 0,
00668 521.86,
00669 756.00
00670 );
00671
00672 break;
00673 }
00674
00675 case 'FOLIO':
00676 {
00677 $size = array
00678 (
00679 0,
00680 0,
00681 612.00,
00682 936.00
00683 );
00684
00685 break;
00686 }
00687 }
00688
00689 switch (strtolower($orientation))
00690 {
00691 case 'landscape':
00692 $a = $size[3];
00693
00694 $size[3] = $size[2];
00695 $size[2] = $a;
00696 break;
00697 }
00698 }
00699 else
00700 {
00701 if (count($paper) > 2)
00702 {
00703
00704 $size = $paper;
00705 }
00706 else
00707 {
00708 $size[0] = 0;
00709 $size[1] = 0;
00710 $size[2] = ($paper[0] / 2.54) * 72;
00711 $size[3] = ($paper[1] / 2.54) * 72;
00712 }
00713 }
00714
00715 $this->Cpdf($size);
00716 $this->ez['pageWidth'] = $size[2];
00717 $this->ez['pageHeight'] = $size[3];
00718
00719
00720 $this->ez['topMargin'] = 30;
00721 $this->ez['bottomMargin'] = 30;
00722 $this->ez['leftMargin'] = 30;
00723 $this->ez['rightMargin'] = 30;
00724
00725
00726 $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
00727
00728 $this->ezPages[1] = $this->getFirstPageId();
00729 $this->ezPageCount = 1;
00730 }
00731
00732
00733
00734
00735 function ezSetCmMargins($top, $bottom, $left, $right)
00736 {
00737 $top = ($top / 2.54) * 72;
00738 $bottom = ($bottom / 2.54) * 72;
00739 $left = ($left / 2.54) * 72;
00740 $right = ($right / 2.54) * 72;
00741 $this->ezSetMargins($top, $bottom, $left, $right);
00742 }
00743
00744
00745 function ezColumnsStart($options = array(
00746 ))
00747 {
00748
00749 if (isset($this->ez['columns']) && $this->ez['columns'] == 1)
00750 {
00751
00752 return;
00753 }
00754
00755 $def = array
00756 (
00757 'gap' => 10,
00758 'num' => 2
00759 );
00760
00761 foreach ($def as $k => $v)
00762 {
00763 if (!isset($options[$k]))
00764 {
00765 $options[$k] = $v;
00766 }
00767 }
00768
00769
00770 $this->ez['columns'] = array
00771 (
00772 'on' => 1,
00773 'colNum' => 1
00774 );
00775
00776
00777 $this->ez['columns']['margins'] = array
00778 (
00779 $this->ez['leftMargin'],
00780 $this->ez['rightMargin'],
00781 $this->ez['topMargin'],
00782 $this->ez['bottomMargin']
00783 );
00784
00785
00786 $this->ez['columns']['options'] = $options;
00787
00788
00789 $this->ez['topMargin'] = $this->ez['pageHeight'] - $this->y;
00790 $width = ($this->ez['pageWidth'] - $this->ez['leftMargin'] - $this->ez['rightMargin'] - ($options['num'] - 1)
00791 * $options['gap']) / $options['num'];
00792 $this->ez['columns']['width'] = $width;
00793 $this->ez['rightMargin'] = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $width;
00794 }
00795
00796
00797 function ezColumnsStop()
00798 {
00799 if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
00800 {
00801 $this->ez['columns']['on'] = 0;
00802 $this->ez['leftMargin'] = $this->ez['columns']['margins'][0];
00803 $this->ez['rightMargin'] = $this->ez['columns']['margins'][1];
00804 $this->ez['topMargin'] = $this->ez['columns']['margins'][2];
00805 $this->ez['bottomMargin'] = $this->ez['columns']['margins'][3];
00806 }
00807 }
00808
00809
00810 function ezInsertMode($status = 1, $pageNum = 1, $pos = 'before')
00811 {
00812
00813
00814 switch ($status)
00815 {
00816 case '1':
00817 if (isset($this->ezPages[$pageNum]))
00818 {
00819 $this->ez['insertMode'] = 1;
00820 $this->ez['insertOptions'] = array
00821 (
00822 'id' => $this->ezPages[$pageNum],
00823 'pos' => $pos
00824 );
00825 }
00826
00827 break;
00828
00829 case '0':
00830 $this->ez['insertMode'] = 0;
00831
00832 break;
00833 }
00834 }
00835
00836
00837 function ezNewPage()
00838 {
00839 $pageRequired = 1;
00840
00841 if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
00842 {
00843
00844
00845
00846 $this->ez['columns']['colNum']++;
00847
00848
00849 if ($this->ez['columns']['colNum'] <= $this->ez['columns']['options']['num'])
00850 {
00851
00852 $pageRequired = 0;
00853 }
00854 else
00855 {
00856 $this->ez['columns']['colNum'] = 1;
00857 $this->ez['topMargin'] = $this->ez['columns']['margins'][2];
00858 }
00859
00860 $width = $this->ez['columns']['width'];
00861 $this->ez['leftMargin'] = $this->ez['columns']['margins'][0] + ($this->ez['columns']['colNum'] - 1)
00862 * ($this->ez['columns']['options']['gap'] + $width);
00863 $this->ez['rightMargin'] = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $width;
00864 }
00865
00866
00867 if ($pageRequired)
00868 {
00869
00870 $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
00871
00872 $this->ezPageCount++;
00873
00874 if (isset($this->ez['insertMode']) && $this->ez['insertMode'] == 1)
00875 {
00876 $id = $this->ezPages[$this->ezPageCount] = $this->newPage(1, $this->ez['insertOptions']['id'],
00877 $this->ez['insertOptions']['pos']);
00878
00879 $this->ez['insertOptions']['id'] = $id;
00880 $this->ez['insertOptions']['pos'] = 'after';
00881 }
00882 else
00883 {
00884 $this->ezPages[$this->ezPageCount] = $this->newPage();
00885 }
00886 }
00887 else
00888 {
00889 $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
00890 }
00891 }
00892
00893
00894
00895 function ezSetMargins($top, $bottom, $left, $right)
00896 {
00897
00898 $this->ez['topMargin'] = $top;
00899 $this->ez['bottomMargin'] = $bottom;
00900 $this->ez['leftMargin'] = $left;
00901 $this->ez['rightMargin'] = $right;
00902
00903
00904
00905 if ($this->y > $this->ez['pageHeight'] - $top)
00906 {
00907
00908 $this->y = $this->ez['pageHeight'] - $top;
00909 }
00910
00911 if ($this->y < $bottom)
00912 {
00913
00914 $this->ezNewPage();
00915 }
00916 }
00917
00918
00919
00920 function ezGetCurrentPageNumber()
00921 {
00922
00923 return $this->ezPageCount;
00924 }
00925
00926
00927
00928 function ezStartPageNumbers($x, $y, $size, $pos = 'left', $pattern = '{PAGENUM} of {TOTALPAGENUM}', $num = '')
00929 {
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939 if (!$pos || !strlen($pos))
00940 {
00941 $pos = 'left';
00942 }
00943
00944 if (!$pattern || !strlen($pattern))
00945 {
00946 $pattern = '{PAGENUM} of {TOTALPAGENUM}';
00947 }
00948
00949 if (!isset($this->ez['pageNumbering']))
00950 {
00951 $this->ez['pageNumbering'] = array(
00952 );
00953 }
00954
00955 $i = count($this->ez['pageNumbering']);
00956 $this->ez['pageNumbering'][$i][$this->ezPageCount] = array
00957 (
00958 'x' => $x,
00959 'y' => $y,
00960 'pos' => $pos,
00961 'pattern' => $pattern,
00962 'num' => $num,
00963 'size' => $size
00964 );
00965
00966 return $i;
00967 }
00968
00969
00970
00971 function ezWhatPageNumber($pageNum, $i = 0)
00972 {
00973
00974
00975 $num = 0;
00976 $start = 1;
00977 $startNum = 1;
00978
00979 if (!isset($this->ez['pageNumbering']))
00980 {
00981 $this->addMessage('WARNING: page numbering called for and wasn\'t started with ezStartPageNumbers');
00982 return 0;
00983 }
00984
00985 foreach ($this->ez['pageNumbering'][$i] as $k => $v)
00986 {
00987 if ($k <= $pageNum)
00988 {
00989 if (is_array($v))
00990 {
00991
00992 if (strlen($v['num']))
00993 {
00994
00995 $start = $v['num'];
00996 $startNum = $k;
00997 $num = $pageNum - $startNum + $start;
00998 }
00999 }
01000 else
01001 {
01002
01003 $num = 0;
01004 }
01005 }
01006 }
01007
01008 return $num;
01009 }
01010
01011
01012
01013 function ezStopPageNumbers($stopTotal = 0, $next = 0, $i = 0)
01014 {
01015
01016
01017
01018 if (!isset($this->ez['pageNumbering']))
01019 {
01020 $this->ez['pageNumbering'] = array(
01021 );
01022 }
01023
01024 if ($next && isset($this->ez['pageNumbering'][$i][$this->ezPageCount]) && is_array(
01025 $this->ez['pageNumbering'][$i][$this->ezPageCount]))
01026 {
01027
01028
01029 if ($stopTotal)
01030 {
01031 $this->ez['pageNumbering'][$i][$this->ezPageCount]['stoptn'] = 1;
01032 }
01033 else
01034 {
01035 $this->ez['pageNumbering'][$i][$this->ezPageCount]['stopn'] = 1;
01036 }
01037 }
01038 else
01039 {
01040 if ($stopTotal)
01041 {
01042 $this->ez['pageNumbering'][$i][$this->ezPageCount] = 'stopt';
01043 }
01044 else
01045 {
01046 $this->ez['pageNumbering'][$i][$this->ezPageCount] = 'stop';
01047 }
01048
01049 if ($next)
01050 {
01051 $this->ez['pageNumbering'][$i][$this->ezPageCount] .= 'n';
01052 }
01053 }
01054 }
01055
01056
01057
01058 function ezPRVTpageNumberSearch($lbl, &$tmp)
01059 {
01060 foreach ($tmp as $i => $v)
01061 {
01062 if (is_array($v))
01063 {
01064 if (isset($v[$lbl]))
01065 {
01066 return $i;
01067 }
01068 }
01069 else
01070 {
01071 if ($v == $lbl)
01072 {
01073 return $i;
01074 }
01075 }
01076 }
01077
01078 return 0;
01079 }
01080
01081
01082
01083 function ezPRVTaddPageNumbers()
01084 {
01085
01086 if (isset($this->ez['pageNumbering']))
01087 {
01088 $totalPages1 = $this->ezPageCount;
01089 $tmp1 = $this->ez['pageNumbering'];
01090 $status = 0;
01091
01092 foreach ($tmp1 as $i => $tmp)
01093 {
01094
01095
01096 $k = $this->ezPRVTpageNumberSearch('stopt', $tmp);
01097
01098 if ($k && $k > 0)
01099 {
01100 $totalPages = $k - 1;
01101 }
01102 else
01103 {
01104 $l = $this->ezPRVTpageNumberSearch('stoptn', $tmp);
01105
01106 if ($l && $l > 0)
01107 {
01108 $totalPages = $l;
01109 }
01110 else
01111 {
01112 $totalPages = $totalPages1;
01113 }
01114 }
01115
01116 foreach ($this->ezPages as $pageNum => $id)
01117 {
01118 if (isset($tmp[$pageNum]))
01119 {
01120 if (is_array($tmp[$pageNum]))
01121 {
01122
01123 $status = 1;
01124 $info = $tmp[$pageNum];
01125 $info['dnum'] = $info['num'] - $pageNum;
01126
01127
01128 if (isset($info['stopn']) || isset($info['stoptn']))
01129 {
01130 $status = 2;
01131 }
01132 }
01133 else if ($tmp[$pageNum] == 'stop' || $tmp[$pageNum] == 'stopt')
01134 {
01135
01136 $status = 0;
01137 }
01138 else if ($status == 1 && ($tmp[$pageNum] == 'stoptn' || $tmp[$pageNum] == 'stopn'))
01139 {
01140
01141 $status = 2;
01142 }
01143 }
01144
01145 if ($status)
01146 {
01147
01148 if (strlen($info['num']))
01149 {
01150 $num = $pageNum + $info['dnum'];
01151 }
01152 else
01153 {
01154 $num = $pageNum;
01155 }
01156
01157 $total = $totalPages + $num - $pageNum;
01158 $pat = str_replace('{PAGENUM}', $num, $info['pattern']);
01159 $pat = str_replace('{TOTALPAGENUM}', $total, $pat);
01160 $this->reopenObject($id);
01161
01162 switch ($info['pos'])
01163 {
01164 case 'right':
01165 $this->addText($info['x'], $info['y'], $info['size'], $pat);
01166
01167 break;
01168
01169 default:
01170 $w = $this->getTextWidth($info['size'], $pat);
01171
01172 $this->addText($info['x'] - $w, $info['y'], $info['size'], $pat);
01173 break;
01174 }
01175
01176 $this->closeObject();
01177 }
01178
01179 if ($status == 2)
01180 {
01181 $status = 0;
01182 }
01183 }
01184 }
01185 }
01186 }
01187
01188
01189
01190 function ezPRVTcleanUp()
01191 {
01192 $this->ezPRVTaddPageNumbers();
01193 }
01194
01195
01196
01197 function ezStream($options = '')
01198 {
01199 $this->ezPRVTcleanUp();
01200 $this->stream($options);
01201 }
01202
01203
01204
01205 function ezOutput($options = 0)
01206 {
01207 $this->ezPRVTcleanUp();
01208 return $this->output($options);
01209 }
01210
01211
01212
01213 function ezSetY($y)
01214 {
01215
01216 $this->y = $y;
01217
01218 if ($this->y < $this->ez['bottomMargin'])
01219 {
01220
01221 $this->ezNewPage();
01222 }
01223 }
01224
01225
01226
01227 function ezSetDy($dy, $mod = '')
01228 {
01229
01230
01231
01232
01233
01234 $this->y += $dy;
01235
01236 if ($this->y < $this->ez['bottomMargin'])
01237 {
01238
01239 $this->ezNewPage();
01240
01241 if ($mod == 'makeSpace')
01242 {
01243 $this->y += $dy;
01244 }
01245 }
01246 }
01247
01248
01249
01250 function ezPrvtTableDrawLines($pos, $gap, $x0, $x1, $y0, $y1, $y2, $col, $inner, $outer, $opt = 1)
01251 {
01252 $x0 = 1000;
01253 $x1 = 0;
01254 $this->setStrokeColor($col[0], $col[1], $col[2]);
01255 $cnt = 0;
01256 $n = count($pos);
01257
01258 foreach ($pos as $x)
01259 {
01260 $cnt++;
01261
01262 if ($cnt == 1 || $cnt == $n)
01263 {
01264 $this->setLineStyle($outer);
01265 }
01266 else
01267 {
01268 $this->setLineStyle($inner);
01269 }
01270
01271 $this->line($x - $gap / 2, $y0, $x - $gap / 2, $y2);
01272
01273 if ($x > $x1)
01274 {
01275 $x1 = $x;
01276 }
01277
01278 ;
01279
01280 if ($x < $x0)
01281 {
01282 $x0 = $x;
01283 }
01284
01285 ;
01286 }
01287
01288 $this->setLineStyle($outer);
01289 $this->line($x0 - $gap / 2 - $outer / 2, $y0, $x1 - $gap / 2 + $outer / 2, $y0);
01290
01291
01292
01293 if ($y0 != $y1 && $opt < 2)
01294 {
01295 $this->line($x0 - $gap / 2, $y1, $x1 - $gap / 2, $y1);
01296 }
01297
01298 $this->line($x0 - $gap / 2 - $outer / 2, $y2, $x1 - $gap / 2 + $outer / 2, $y2);
01299 }
01300
01301
01302
01303 function ezPrvtTableColumnHeadings($cols, $pos, $maxWidth, $height, $decender, $gap, $size, &$y,
01304 $optionsAll = array(
01305 ))
01306 {
01307
01308
01309
01310
01311 if (isset($optionsAll['cols']))
01312 {
01313 $options = $optionsAll['cols'];
01314 }
01315 else
01316 {
01317 $options = array(
01318 );
01319 }
01320
01321 $mx = 0;
01322 $startPage = $this->ezPageCount;
01323 $secondGo = 0;
01324
01325
01326
01327
01328
01329
01330
01331
01332 $this->transaction('start');
01333 $ok = 0;
01334
01335 $y -= $gap;
01336
01337 while ($ok == 0)
01338 {
01339 foreach ($cols as $colName => $colHeading)
01340 {
01341 $this->ezSetY($y);
01342
01343 if (isset($options[$colName]) && isset($options[$colName]['justification']))
01344 {
01345 $justification = $options[$colName]['justification'];
01346 }
01347 else
01348 {
01349 $justification = 'left';
01350 }
01351
01352 $this->ezText($colHeading,
01353 $size,
01354 array('aleft' => $pos[$colName], 'aright' => ($maxWidth[$colName] + $pos[$colName]),
01355 'justification' => $justification));
01356 $dy = $y - $this->y;
01357
01358 if ($dy > $mx)
01359 {
01360 $mx = $dy;
01361 }
01362 }
01363
01364 $y = $y - $mx - $gap + $decender;
01365
01366
01367
01368
01369
01370 if ($this->ezPageCount != $startPage && $secondGo == 0)
01371 {
01372 $this->transaction('rewind');
01373 $this->ezNewPage();
01374 $y = $this->y - $gap - $decender;
01375 $ok = 0;
01376 $secondGo = 1;
01377
01378 $mx = 0;
01379 }
01380 else
01381 {
01382 $this->transaction('commit');
01383 $ok = 1;
01384 }
01385 }
01386
01387 return $mx + $gap * 2 - $decender;
01388 }
01389
01390
01391
01392 function ezPrvtGetTextWidth($size, $text)
01393 {
01394
01395
01396 $mx = 0;
01397 $lines = explode("\n", $text);
01398
01399 foreach ($lines as $line)
01400 {
01401 $w = $this->getTextWidth($size, $line);
01402
01403 if ($w > $mx)
01404 {
01405 $mx = $w;
01406 }
01407 }
01408
01409 return $mx;
01410 }
01411
01412
01413
01414 function ezTable(&$data, $cols = '', $title = '', $options = '')
01415 {
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453 if (!is_array($data))
01454 {
01455 return;
01456 }
01457
01458 if (!is_array($cols))
01459 {
01460
01461 reset ($data);
01462 list($k, $v) = each($data);
01463
01464 if (!is_array($v))
01465 {
01466 return;
01467 }
01468
01469 $cols = array(
01470 );
01471
01472 foreach ($v as $k1 => $v1)
01473 {
01474 $cols[$k1] = $k1;
01475 }
01476 }
01477
01478 if (!is_array($options))
01479 {
01480 $options = array(
01481 );
01482 }
01483
01484 $defaults = array
01485 (
01486 'shaded' => 1,
01487 'showLines' => 1,
01488 'shadeCol' => array(0.8, 0.8, 0.8),
01489 'shadeCol2' => array(0.7, 0.7, 0.7),
01490 'fontSize' => 10,
01491 'titleFontSize' => 12,
01492 'titleGap' => 5,
01493 'lineCol' => array(0, 0, 0),
01494 'gap' => 5,
01495 'xPos' => 'centre',
01496 'xOrientation' => 'centre',
01497 'showHeadings' => 1,
01498 'textCol' => array(0, 0, 0),
01499 'width' => 0,
01500 'maxWidth' => 0,
01501 'cols' => array(
01502 ),
01503 'minRowSpace' => -100,
01504 'rowGap' => 2,
01505 'colGap' => 5,
01506 'innerLineThickness' => 1,
01507 'outerLineThickness' => 1,
01508 'splitRows' => 0,
01509 'protectRows' => 1
01510 );
01511
01512 foreach ($defaults as $key => $value)
01513 {
01514 if (is_array($value))
01515 {
01516 if (!isset($options[$key]) || !is_array($options[$key]))
01517 {
01518 $options[$key] = $value;
01519 }
01520 }
01521 else
01522 {
01523 if (!isset($options[$key]))
01524 {
01525 $options[$key] = $value;
01526 }
01527 }
01528 }
01529
01530 $options['gap'] = 2 * $options['colGap'];
01531
01532 $middle = ($this->ez['pageWidth'] - $this->ez['rightMargin']) / 2 + ($this->ez['leftMargin']) / 2;
01533
01534 $maxWidth = array(
01535 );
01536
01537 foreach ($cols as $colName => $colHeading)
01538 {
01539 $maxWidth[$colName] = 0;
01540 }
01541
01542
01543 foreach ($data as $row)
01544 {
01545 foreach ($cols as $colName => $colHeading)
01546 {
01547 $w = $this->ezPrvtGetTextWidth($options['fontSize'], (string)$row[$colName]) * 1.01;
01548
01549 if ($w > $maxWidth[$colName])
01550 {
01551 $maxWidth[$colName] = $w;
01552 }
01553 }
01554 }
01555
01556
01557 foreach ($cols as $colName => $colTitle)
01558 {
01559 $w = $this->ezPrvtGetTextWidth($options['fontSize'], (string)$colTitle) * 1.01;
01560
01561 if ($w > $maxWidth[$colName])
01562 {
01563 $maxWidth[$colName] = $w;
01564 }
01565 }
01566
01567
01568 $pos = array(
01569 );
01570
01571 $x = 0;
01572 $t = $x;
01573 $adjustmentWidth = 0;
01574 $setWidth = 0;
01575
01576 foreach ($maxWidth as $colName => $w)
01577 {
01578 $pos[$colName] = $t;
01579
01580
01581
01582 if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['width'])
01583 && $options['cols'][$colName]['width'] > 0)
01584 {
01585 $t = $t + $options['cols'][$colName]['width'];
01586 $maxWidth[$colName] = $options['cols'][$colName]['width'] - $options['gap'];
01587 $setWidth += $options['cols'][$colName]['width'];
01588 }
01589 else
01590 {
01591 $t = $t + $w + $options['gap'];
01592 $adjustmentWidth += $w;
01593 $setWidth += $options['gap'];
01594 }
01595 }
01596
01597 $pos['_end_'] = $t;
01598
01599
01600
01601 if ($options['width'] == 0 && $options['maxWidth'] && ($t - $x) > $options['maxWidth'])
01602 {
01603
01604 $options['width'] = $options['maxWidth'];
01605 }
01606
01607 if ($options['width'] && $adjustmentWidth > 0 && $setWidth < $options['width'])
01608 {
01609
01610 $cols0 = array(
01611 );
01612
01613 $cols1 = array(
01614 );
01615
01616 $xq = 0;
01617 $presentWidth = 0;
01618 $last = '';
01619
01620 foreach ($pos as $colName => $p)
01621 {
01622 if (!isset($options['cols'][$last]) || !isset($options['cols'][$last]['width'])
01623 || $options['cols'][$last]['width'] <= 0)
01624 {
01625 if (strlen($last))
01626 {
01627 $cols0[$last] = $p - $xq - $options['gap'];
01628 $presentWidth += ($p - $xq - $options['gap']);
01629 }
01630 }
01631 else
01632 {
01633 $cols1[$last] = $p - $xq;
01634 }
01635
01636 $last = $colName;
01637 $xq = $p;
01638 }
01639
01640
01641 $neededWidth = $options['width'] - $setWidth;
01642
01643
01644 if ($presentWidth < $neededWidth)
01645 {
01646 foreach ($cols0 as $colName => $w)
01647 {
01648 $cols0[$colName] += ($neededWidth - $presentWidth) / count($cols0);
01649 }
01650 }
01651 else
01652 {
01653 $cnt = 0;
01654
01655 while ($presentWidth > $neededWidth && $cnt < 100)
01656 {
01657 $cnt++;
01658
01659 $aWidest = array(
01660 );
01661
01662 $nWidest = 0;
01663 $widest = 0;
01664
01665 foreach ($cols0 as $colName => $w)
01666 {
01667 if ($w > $widest)
01668 {
01669 $aWidest = array($colName);
01670 $nWidest = $widest;
01671 $widest = $w;
01672 }
01673 else if ($w == $widest)
01674 {
01675 $aWidest[] = $colName;
01676 }
01677 }
01678
01679
01680 $newWidestWidth = $widest - ($presentWidth - $neededWidth) / count($aWidest);
01681
01682 if ($newWidestWidth > $nWidest)
01683 {
01684
01685 foreach ($aWidest as $colName)
01686 {
01687 $cols0[$colName] = $newWidestWidth;
01688 }
01689
01690 $presentWidth = $neededWidth;
01691 }
01692 else
01693 {
01694
01695
01696 foreach ($aWidest as $colName)
01697 {
01698 $cols0[$colName] = $nWidest;
01699 }
01700
01701 $presentWidth = $presentWidth - ($widest - $nWidest) * count($aWidest);
01702 }
01703 }
01704 }
01705
01706
01707
01708 $xq = 0;
01709
01710 foreach ($pos as $colName => $p)
01711 {
01712 $pos[$colName] = $xq;
01713
01714 if (!isset($options['cols'][$colName]) || !isset($options['cols'][$colName]['width'])
01715 || $options['cols'][$colName]['width'] <= 0)
01716 {
01717 if (isset($cols0[$colName]))
01718 {
01719 $xq += $cols0[$colName] + $options['gap'];
01720 $maxWidth[$colName] = $cols0[$colName];
01721 }
01722 }
01723 else
01724 {
01725 if (isset($cols1[$colName]))
01726 {
01727 $xq += $cols1[$colName];
01728 }
01729 }
01730 }
01731
01732 $t = $x + $options['width'];
01733 $pos['_end_'] = $t;
01734 }
01735
01736
01737 switch ($options['xPos'])
01738 {
01739 case 'left':
01740 $xref = $this->ez['leftMargin'];
01741
01742 break;
01743
01744 case 'right':
01745 $xref = $this->ez['pageWidth'] - $this->ez['rightMargin'];
01746
01747 break;
01748
01749 case 'centre':
01750 case 'center':
01751 $xref = $middle;
01752
01753 break;
01754
01755 default:
01756 $xref = $options['xPos'];
01757
01758 break;
01759 }
01760
01761 switch ($options['xOrientation'])
01762 {
01763 case 'left':
01764 $dx = $xref - $t;
01765
01766 break;
01767
01768 case 'right':
01769 $dx = $xref;
01770
01771 break;
01772
01773 case 'centre':
01774 case 'center':
01775 $dx = $xref - $t / 2;
01776
01777 break;
01778 }
01779
01780 foreach ($pos as $k => $v)
01781 {
01782 $pos[$k] = $v + $dx;
01783 }
01784
01785 $x0 = $x + $dx;
01786 $x1 = $t + $dx;
01787
01788 $baseLeftMargin = $this->ez['leftMargin'];
01789 $basePos = $pos;
01790 $baseX0 = $x0;
01791 $baseX1 = $x1;
01792
01793
01794 $this->setColor($options['textCol'][0], $options['textCol'][1], $options['textCol'][2]);
01795 $this->setStrokeColor($options['shadeCol'][0], $options['shadeCol'][1], $options['shadeCol'][2]);
01796
01797 $middle = ($x1 + $x0) / 2;
01798
01799
01800 if ($options['protectRows'] > 0)
01801 {
01802 $this->transaction('start');
01803 $movedOnce = 0;
01804 }
01805
01806 $abortTable = 1;
01807
01808 while ($abortTable)
01809 {
01810 $abortTable = 0;
01811
01812 $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01813
01814 foreach ($basePos as $k => $v)
01815 {
01816 $pos[$k] = $v + $dm;
01817 }
01818
01819 $x0 = $baseX0 + $dm;
01820 $x1 = $baseX1 + $dm;
01821 $middle = ($x1 + $x0) / 2;
01822
01823
01824 if (strlen($title))
01825 {
01826 $w = $this->getTextWidth($options['titleFontSize'], $title);
01827 $this->y -= $this->getFontHeight($options['titleFontSize']);
01828
01829 if ($this->y < $this->ez['bottomMargin'])
01830 {
01831 $this->ezNewPage();
01832
01833 $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01834
01835 foreach ($basePos as $k => $v)
01836 {
01837 $pos[$k] = $v + $dm;
01838 }
01839
01840 $x0 = $baseX0 + $dm;
01841 $x1 = $baseX1 + $dm;
01842 $middle = ($x1 + $x0) / 2;
01843 $this->y -= $this->getFontHeight($options['titleFontSize']);
01844 }
01845
01846 $this->addText($middle - $w / 2, $this->y, $options['titleFontSize'], $title);
01847 $this->y -= $options['titleGap'];
01848 }
01849
01850
01851 $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01852
01853 foreach ($basePos as $k => $v)
01854 {
01855 $pos[$k] = $v + $dm;
01856 }
01857
01858 $x0 = $baseX0 + $dm;
01859 $x1 = $baseX1 + $dm;
01860
01861 $y = $this->y;
01862
01863
01864 $height = $this->getFontHeight($options['fontSize']);
01865 $decender = $this->getFontDecender($options['fontSize']);
01866
01867 $y0 = $y + $decender;
01868 $dy = 0;
01869
01870 if ($options['showHeadings'])
01871 {
01872 if ($options['shaded'])
01873 {
01874 $this->saveState();
01875 $textObjectId = $this->openObject();
01876 }
01877
01878
01879 $headingHeight = $this->ezPrvtTableColumnHeadings(
01880 $cols, $pos, $maxWidth, $height, $decender, $options['rowGap'],
01881 $options['fontSize'], $y, $options);
01882 $y0 = $y + $headingHeight;
01883 $y1 = $y;
01884
01885 $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01886
01887 foreach ($basePos as $k => $v)
01888 {
01889 $pos[$k] = $v + $dm;
01890 }
01891
01892 $x0 = $baseX0 + $dm;
01893 $x1 = $baseX1 + $dm;
01894
01895 if ($options['shaded'])
01896 {
01897 $this->closeObject();
01898 $this->setColor($options['shadeCol'][0], $options['shadeCol'][1], $options['shadeCol'][2], 1);
01899 $this->filledRectangle($x0 - $options['gap'] / 2, $y1, $x1 - $x0, $headingHeight);
01900 $this->addObject($textObjectId);
01901 $this->closeObject();
01902 $this->restoreState();
01903 }
01904 }
01905 else
01906 {
01907 $y1 = $y0;
01908 }
01909
01910 $firstLine = 1;
01911
01912
01913 if ($options['shaded'])
01914 {
01915 $this->saveState();
01916 $textObjectId = $this->openObject();
01917 $this->closeObject();
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927 $this->addObject($textObjectId);
01928
01929
01930
01931
01932 $this->reopenObject($textObjectId);
01933 }
01934
01935 $cnt = 0;
01936 $newPage = 0;
01937
01938 foreach ($data as $row)
01939 {
01940 $cnt++;
01941
01942
01943 if ($options['splitRows'] == 0)
01944 {
01945 $pageStart = $this->ezPageCount;
01946
01947 if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
01948 {
01949 $columnStart = $this->ez['columns']['colNum'];
01950 }
01951
01952 $this->transaction('start');
01953 $row_orig = $row;
01954 $y_orig = $y;
01955 $y0_orig = $y0;
01956 $y1_orig = $y1;
01957 }
01958
01959 $ok = 0;
01960 $secondTurn = 0;
01961
01962 while (!$abortTable && $ok == 0)
01963 {
01964 $mx = 0;
01965 $newRow = 1;
01966
01967 while (!$abortTable && ($newPage || $newRow))
01968 {
01969 $y -= $height;
01970
01971 if ($newPage || $y < $this->ez['bottomMargin'] || (isset($options['minRowSpace']) && $y
01972 < ($this->ez['bottomMargin']
01973 + $options['minRowSpace'])))
01974 {
01975
01976 if ($options['protectRows'] > 0 && $movedOnce == 0 && $cnt <= $options['protectRows'])
01977 {
01978
01979 $movedOnce = 1;
01980 $abortTable = 1;
01981 }
01982
01983 $y2 = $y - $mx + 2 * $height + $decender - $newRow * $height;
01984
01985 if ($options['showLines'])
01986 {
01987 if (!$options['showHeadings'])
01988 {
01989 $y0 = $y1;
01990 }
01991
01992 $this->ezPrvtTableDrawLines($pos,
01993 $options['gap'],
01994 $x0,
01995 $x1,
01996 $y0,
01997 $y1,
01998 $y2,
01999 $options['lineCol'],
02000 $options['innerLineThickness'],
02001 $options['outerLineThickness'],
02002 $options['showLines']);
02003 }
02004
02005 if ($options['shaded'])
02006 {
02007 $this->closeObject();
02008 $this->restoreState();
02009 }
02010
02011 $this->ezNewPage();
02012
02013
02014
02015 $dm = $this->ez['leftMargin'] - $baseLeftMargin;
02016
02017 foreach ($basePos as $k => $v)
02018 {
02019 $pos[$k] = $v + $dm;
02020 }
02021
02022
02023
02024 $x0 = $baseX0 + $dm;
02025 $x1 = $baseX1 + $dm;
02026
02027 if ($options['shaded'])
02028 {
02029 $this->saveState();
02030 $textObjectId = $this->openObject();
02031 $this->closeObject();
02032 $this->addObject($textObjectId);
02033 $this->reopenObject($textObjectId);
02034 }
02035
02036 $this->setColor($options['textCol'][0], $options['textCol'][1], $options['textCol'][2], 1);
02037 $y = $this->ez['pageHeight'] - $this->ez['topMargin'];
02038 $y0 = $y + $decender;
02039 $mx = 0;
02040
02041 if ($options['showHeadings'])
02042 {
02043 $this->ezPrvtTableColumnHeadings(
02044 $cols, $pos, $maxWidth, $height, $decender, $options['rowGap'],
02045 $options['fontSize'], $y, $options);
02046 $y1 = $y;
02047 }
02048 else
02049 {
02050 $y1 = $y0;
02051 }
02052
02053 $firstLine = 1;
02054 $y -= $height;
02055 }
02056
02057 $newRow = 0;
02058
02059
02060
02061 $newPage = 0;
02062 $leftOvers = array(
02063 );
02064
02065 foreach ($cols as $colName => $colTitle)
02066 {
02067 $this->ezSetY($y + $height);
02068 $colNewPage = 0;
02069
02070 if (isset($row[$colName]))
02071 {
02072 if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['link'])
02073 && strlen($options['cols'][$colName]['link']))
02074 {
02075 $lines = explode("\n", $row[$colName]);
02076
02077 if (isset($row[$options['cols'][$colName]['link']])
02078 && strlen($row[$options['cols'][$colName]['link']]))
02079 {
02080 foreach ($lines as $k => $v)
02081 {
02082 $lines[$k]
02083 = '<c:alink:' . $row[$options['cols'][$colName]['link']] . '>' . $v
02084 . '</c:alink>';
02085 }
02086 }
02087 }
02088 else
02089 {
02090 $lines = explode("\n", $row[$colName]);
02091 }
02092 }
02093 else
02094 {
02095 $lines = array(
02096 );
02097 }
02098
02099 $this->y -= $options['rowGap'];
02100
02101 foreach ($lines as $line)
02102 {
02103 $line = $this->ezProcessText($line);
02104 $start = 1;
02105
02106 while (strlen($line) || $start)
02107 {
02108 $start = 0;
02109
02110 if (!$colNewPage)
02111 {
02112 $this->y = $this->y - $height;
02113 }
02114
02115 if ($this->y < $this->ez['bottomMargin'])
02116 {
02117
02118 $newPage = 1;
02119 $colNewPage = 1;
02120 }
02121
02122 if ($colNewPage)
02123 {
02124 if (isset($leftOvers[$colName]))
02125 {
02126 $leftOvers[$colName] .= "\n" . $line;
02127 }
02128 else
02129 {
02130 $leftOvers[$colName] = $line;
02131 }
02132
02133 $line = '';
02134 }
02135 else
02136 {
02137 if (isset($options['cols'][$colName]) && isset(
02138 $options['cols'][$colName]['justification']))
02139 {
02140 $just = $options['cols'][$colName]['justification'];
02141 }
02142 else
02143 {
02144 $just = 'left';
02145 }
02146
02147 $line = $this->addTextWrap(
02148 $pos[$colName], $this->y, $maxWidth[$colName], $options['fontSize'],
02149 $line, $just);
02150 }
02151 }
02152 }
02153
02154 $dy = $y + $height - $this->y + $options['rowGap'];
02155
02156 if ($dy - $height * $newPage > $mx)
02157 {
02158 $mx = $dy - $height * $newPage;
02159 }
02160 }
02161
02162
02163 $row = $leftOvers;
02164
02165
02166 if ($options['shaded'] && $cnt % 2 == 0)
02167 {
02168 $this->closeObject();
02169 $this->setColor($options['shadeCol'][0], $options['shadeCol'][1], $options['shadeCol'][2],
02170 1);
02171 $this->filledRectangle($x0 - $options['gap'] / 2, $y + $decender + $height - $mx, $x1 - $x0,
02172 $mx);
02173 $this->reopenObject($textObjectId);
02174 }
02175
02176 if ($options['shaded'] == 2 && $cnt % 2 == 1)
02177 {
02178 $this->closeObject();
02179 $this->setColor($options['shadeCol2'][0], $options['shadeCol2'][1],
02180 $options['shadeCol2'][2], 1);
02181 $this->filledRectangle($x0 - $options['gap'] / 2, $y + $decender + $height - $mx, $x1 - $x0,
02182 $mx);
02183 $this->reopenObject($textObjectId);
02184 }
02185
02186 if ($options['showLines'] > 1)
02187 {
02188
02189
02190 $this->saveState();
02191 $this->setStrokeColor($options['lineCol'][0], $options['lineCol'][1],
02192 $options['lineCol'][2], 1);
02193
02194
02195 if ($firstLine)
02196 {
02197 $this->setLineStyle($options['outerLineThickness']);
02198 $firstLine = 0;
02199 }
02200 else
02201 {
02202 $this->setLineStyle($options['innerLineThickness']);
02203 }
02204
02205 $this->line($x0 - $options['gap'] / 2, $y + $decender + $height, $x1 - $options['gap'] / 2,
02206 $y + $decender + $height);
02207 $this->restoreState();
02208
02209 }
02210 }
02211
02212 $y = $y - $mx + $height;
02213
02214
02215 if ($options['splitRows'] == 0)
02216 {
02217 if ((($this->ezPageCount != $pageStart) || (isset($this->ez['columns'])
02218 && $this->ez['columns']['on'] == 1
02219 && $columnStart
02220 != $this->ez['columns']['colNum']))
02221 && $secondTurn == 0)
02222 {
02223
02224 $newPage = 1;
02225 $secondTurn = 1;
02226 $this->transaction('rewind');
02227 $row = $row_orig;
02228 $y = $y_orig;
02229 $y0 = $y0_orig;
02230 $y1 = $y1_orig;
02231 $ok = 0;
02232
02233 $dm = $this->ez['leftMargin'] - $baseLeftMargin;
02234
02235 foreach ($basePos as $k => $v)
02236 {
02237 $pos[$k] = $v + $dm;
02238 }
02239
02240 $x0 = $baseX0 + $dm;
02241 $x1 = $baseX1 + $dm;
02242 }
02243 else
02244 {
02245 $this->transaction('commit');
02246 $ok = 1;
02247 }
02248 }
02249 else
02250 {
02251 $ok = 1;
02252 }
02253 }
02254
02255 if ($abortTable)
02256 {
02257 if ($ok == 0)
02258 {
02259 $this->transaction('abort');
02260 }
02261
02262
02263 $this->transaction('rewind');
02264 $this->ezNewPage();
02265 break;
02266 }
02267 }
02268 }
02269
02270
02271 $this->transaction('commit');
02272
02273 $y2 = $y + $decender;
02274
02275 if ($options['showLines'])
02276 {
02277 if (!$options['showHeadings'])
02278 {
02279 $y0 = $y1;
02280 }
02281
02282 $this->ezPrvtTableDrawLines($pos, $options['gap'],
02283 $x0, $x1,
02284 $y0, $y1,
02285 $y2, $options['lineCol'],
02286 $options['innerLineThickness'], $options['outerLineThickness'],
02287 $options['showLines']);
02288 }
02289
02290
02291 if ($options['shaded'])
02292 {
02293 $this->closeObject();
02294 $this->restoreState();
02295 }
02296
02297 $this->y = $y;
02298 return $y;
02299 }
02300
02301
02302 function ezProcessText($text)
02303 {
02304
02305
02306 $search = array
02307 (
02308 '<u>',
02309 '<U>',
02310 '</u>',
02311 '</U>'
02312 );
02313
02314 $replace = array
02315 (
02316 '<c:uline>',
02317 '<c:uline>',
02318 '</c:uline>',
02319 '</c:uline>'
02320 );
02321
02322 return str_replace($search, $replace, $text);
02323 }
02324
02325
02326
02327 function ezText($text, $size = 0, $options = array(
02328 ), $test = 0)
02329 {
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350 $text = $this->ezProcessText($text);
02351
02352 $newPage = false;
02353 $store_y = $this->y;
02354
02355 if (is_array($options) && isset($options['aleft']))
02356 {
02357 $left = $options['aleft'];
02358 }
02359 else
02360 {
02361 $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left'])) ? $options['left'] : 0);
02362 }
02363
02364 if (is_array($options) && isset($options['aright']))
02365 {
02366 $right = $options['aright'];
02367 }
02368 else
02369 {
02370 $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array(
02371 $options) && isset($options['right']))
02372 ? $options['right'] : 0);
02373 }
02374
02375 if ($size <= 0)
02376 {
02377 $size = $this->ez['fontSize'];
02378 }
02379 else
02380 {
02381 $this->ez['fontSize'] = $size;
02382 }
02383
02384 if (is_array($options) && isset($options['justification']))
02385 {
02386 $just = $options['justification'];
02387 }
02388 else
02389 {
02390 $just = 'left';
02391 }
02392
02393
02394 if (is_array($options) && isset($options['leading']))
02395 { ## use leading instead of spacing
02396 $height = $options['leading'];
02397 }
02398 else if (is_array($options) && isset($options['spacing']))
02399 {
02400 $height = $this->getFontHeight($size) * $options['spacing'];
02401 }
02402 else
02403 {
02404 $height = $this->getFontHeight($size);
02405 }
02406
02407 $lines = explode("\n", $text);
02408
02409 foreach ($lines as $line)
02410 {
02411 $start = 1;
02412
02413 while (strlen($line) || $start)
02414 {
02415 $start = 0;
02416 $this->y = $this->y - $height;
02417
02418 if ($this->y < $this->ez['bottomMargin'])
02419 {
02420 if ($test)
02421 {
02422 $newPage = true;
02423 }
02424 else
02425 {
02426 $this->ezNewPage();
02427
02428 }
02429 }
02430
02431 if (is_array($options) && isset($options['aleft']))
02432 {
02433 $left = $options['aleft'];
02434 }
02435 else
02436 {
02437 $left = $this->ez['leftMargin'] + ((is_array(
02438 $options) && isset(
02439 $options['left'])) ? $options['left'] : 0);
02440 }
02441
02442 if (is_array($options) && isset($options['aright']))
02443 {
02444 $right = $options['aright'];
02445 }
02446 else
02447 {
02448 $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options)
02449 && isset($options['right']))
02450 ? $options['right'] : 0);
02451 }
02452
02453 $line = $this->addTextWrap($left, $this->y, $right - $left, $size, $line, $just, 0, $test);
02454 }
02455 }
02456
02457 if ($test)
02458 {
02459 $this->y = $store_y;
02460 return $newPage;
02461 }
02462 else
02463 {
02464 return $this->y;
02465 }
02466 }
02467
02468
02469
02470 function ezImage($image, $pad = 5, $width = 0, $resize = 'full', $just = 'center', $border = '')
02471 {
02472
02473 if (stristr($image, ':
02474 {
02475 $fp = @fopen($image, "rb");
02476
02477 while (!feof($fp))
02478 {
02479 $cont .= fread($fp, 1024);
02480 }
02481
02482 fclose ($fp);
02483 $image = tempnam("/tmp", "php-pdf");
02484 $fp2 = @fopen($image, "w");
02485 fwrite($fp2, $cont);
02486 fclose ($fp2);
02487 $temp = true;
02488 }
02489
02490 if (!(file_exists($image)))
02491 return false;
02492
02493 $imageInfo = getimagesize($image);
02494
02495 switch ($imageInfo[2])
02496 {
02497 case 2:
02498 $type = "jpeg";
02499
02500 break;
02501
02502 case 3:
02503 $type = "png";
02504
02505 break;
02506
02507 default: return false;
02508 }
02509
02510 if ($width == 0)
02511 $width = $imageInfo[0];
02512
02513 $ratio = $imageInfo[0] / $imageInfo[1];
02514
02515
02516 if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
02517 {
02518 $bigwidth = $this->ez['columns']['width'] - ($pad * 2);
02519 }
02520 else
02521 {
02522 $bigwidth = $this->ez['pageWidth'] - ($pad * 2);
02523 }
02524
02525
02526 if ($resize == 'full' || $resize == 'width' || $width > $bigwidth)
02527 {
02528 $width = $bigwidth;
02529 }
02530
02531 $height = ($width / $ratio);
02532
02533
02534 if ($height > ($this->y - $this->ez['bottomMargin'] - ($pad * 2)))
02535 {
02536 if ($resize != 'full')
02537 {
02538 $this->ezNewPage();
02539 }
02540 else
02541 {
02542 $height = ($this->y - $this->ez['bottomMargin'] - ($pad * 2));
02543 $width = ($height * $ratio);
02544 }
02545 }
02546
02547
02548 if ($width < $bigwidth)
02549 {
02550
02551 if ($just == 'center')
02552 {
02553 $offset = ($bigwidth - $width) / 2;
02554 }
02555
02556
02557 if ($just == 'right')
02558 {
02559 $offset = ($bigwidth - $width);
02560 }
02561
02562
02563 if ($just == 'left')
02564 {
02565 $offset = 0;
02566 }
02567 }
02568
02569
02570 if ($type == "jpeg")
02571 {
02572 $this->addJpegFromFile($image,
02573 $this->ez['leftMargin'] + $pad + $offset,
02574 $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,
02575 $width);
02576 }
02577
02578 if ($type == "png")
02579 {
02580 $this->addPngFromFile($image,
02581 $this->ez['leftMargin'] + $pad + $offset,
02582 $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,
02583 $width);
02584 }
02585
02586
02587 if ($border != '')
02588 {
02589 if (!(isset($border['color'])))
02590 {
02591 $border['color']['red'] = .5;
02592 $border['color']['blue'] = .5;
02593 $border['color']['green'] = .5;
02594 }
02595
02596 if (!(isset($border['width'])))
02597 $border['width'] = 1;
02598
02599 if (!(isset($border['cap'])))
02600 $border['cap'] = 'round';
02601
02602 if (!(isset($border['join'])))
02603 $border['join'] = 'round';
02604
02605 $this->setStrokeColor($border['color']['red'], $border['color']['green'], $border['color']['blue']);
02606 $this->setLineStyle($border['width'], $border['cap'], $border['join']);
02607 $this->rectangle($this->ez['leftMargin'] + $pad + $offset,
02608 $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,
02609 $width,
02610 $height);
02611 }
02612
02613
02614 $this->y = $this->y - $pad - $height;
02615
02616
02617 if ($temp == true)
02618 unlink ($image);
02619 }
02620
02621
02622
02623
02624
02625 function loadTemplate($templateFile)
02626 {
02627
02628
02629
02630
02631 if (!file_exists($templateFile))
02632 {
02633 return -1;
02634 }
02635
02636 $code = implode('', file($templateFile));
02637
02638 if (!strlen($code))
02639 {
02640 return;
02641 }
02642
02643 $code = trim($code);
02644
02645 if (substr($code, 0, 5) == '<?php')
02646 {
02647 $code = substr($code, 5);
02648 }
02649
02650 if (substr($code, -2) == '?>')
02651 {
02652 $code = substr($code, 0, strlen($code) - 2);
02653 }
02654
02655 if (isset($this->ez['numTemplates']))
02656 {
02657 $newNum = $this->ez['numTemplates'];
02658 $this->ez['numTemplates']++;
02659 }
02660 else
02661 {
02662 $newNum = 0;
02663 $this->ez['numTemplates'] = 1;
02664 $this->ez['templates'] = array(
02665 );
02666 }
02667
02668 $this->ez['templates'][$newNum]['code'] = $code;
02669
02670 return $newNum;
02671 }
02672
02673
02674
02675 function execTemplate($id, $data = array(
02676 ), $options = array(
02677 ))
02678 {
02679
02680 if (!isset($this->ez['templates'][$id]))
02681 {
02682 return;
02683 }
02684
02685 eval ($this->ez['templates'][$id]['code']);
02686 }
02687
02688
02689 function ilink($info)
02690 {
02691 $this->alink($info, 1);
02692 }
02693
02694 function alink($info, $internal = 0)
02695 {
02696
02697 $lineFactor = 0.05;
02698
02699 switch ($info['status'])
02700 {
02701 case 'start':
02702 case 'sol':
02703
02704
02705 if (!isset($this->ez['links']))
02706 {
02707 $this->ez['links'] = array(
02708 );
02709 }
02710
02711 $i = $info['nCallback'];
02712 $this->ez['links'][$i] = array
02713 (
02714 'x' => $info['x'],
02715 'y' => $info['y'],
02716 'angle' => $info['angle'],
02717 'decender' => $info['decender'],
02718 'height' => $info['height'],
02719 'url' => $info['p']
02720 );
02721
02722 if ($internal == 0)
02723 {
02724 $this->saveState();
02725 $this->setColor(0, 0, 1);
02726 $this->setStrokeColor(0, 0, 1);
02727 $thick = $info['height'] * $lineFactor;
02728 $this->setLineStyle($thick);
02729 }
02730
02731 break;
02732
02733 case 'end':
02734 case 'eol':
02735
02736
02737 $i = $info['nCallback'];
02738
02739 $start = $this->ez['links'][$i];
02740
02741
02742 if ($internal)
02743 {
02744 $this->addInternalLink($start['url'], $start['x'], $start['y'] + $start['decender'], $info['x'],
02745 $start['y'] + $start['decender'] + $start['height']);
02746 }
02747 else
02748 {
02749 $a = deg2rad((float)$start['angle'] - 90.0);
02750 $drop = $start['height'] * $lineFactor * 1.5;
02751 $dropx = cos($a) * $drop;
02752 $dropy = -sin($a) * $drop;
02753 $this->line($start['x'] - $dropx, $start['y'] - $dropy, $info['x'] - $dropx, $info['y'] - $dropy);
02754 $this->addLink($start['url'], $start['x'], $start['y'] + $start['decender'], $info['x'],
02755 $start['y'] + $start['decender'] + $start['height']);
02756 $this->restoreState();
02757 }
02758
02759 break;
02760 }
02761 }
02762
02763
02764
02765 function uline($info)
02766 {
02767
02768 $lineFactor = 0.05;
02769
02770 switch ($info['status'])
02771 {
02772 case 'start':
02773 case 'sol':
02774
02775
02776 if (!isset($this->ez['links']))
02777 {
02778 $this->ez['links'] = array(
02779 );
02780 }
02781
02782 $i = $info['nCallback'];
02783 $this->ez['links'][$i] = array
02784 (
02785 'x' => $info['x'],
02786 'y' => $info['y'],
02787 'angle' => $info['angle'],
02788 'decender' => $info['decender'],
02789 'height' => $info['height']
02790 );
02791
02792 $this->saveState();
02793 $thick = $info['height'] * $lineFactor;
02794 $this->setLineStyle($thick);
02795 break;
02796
02797 case 'end':
02798 case 'eol':
02799
02800
02801 $i = $info['nCallback'];
02802
02803 $start = $this->ez['links'][$i];
02804
02805 $a = deg2rad((float)$start['angle'] - 90.0);
02806 $drop = $start['height'] * $lineFactor * 1.5;
02807 $dropx = cos($a) * $drop;
02808 $dropy = -sin($a) * $drop;
02809 $this->line($start['x'] - $dropx, $start['y'] - $dropy, $info['x'] - $dropx, $info['y'] - $dropy);
02810 $this->restoreState();
02811 break;
02812 }
02813 }
02814
02815
02816
02817 }
02818 ?>