:::

8-2 /pdf.php

001<?php
002include_once "header.php";
003 
004include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php');
005$def_city    = system_CleanVars($_REQUEST, 'city', '', 'string');
006$def_cate_sn = system_CleanVars($_REQUEST, 'cate_sn', '', 'int');
007$def_county    = system_CleanVars($_REQUEST, 'county', '', 'string');
008$def_keyword    = system_CleanVars($_REQUEST, 'keyword', '', 'string');
009$sn = system_CleanVars($_REQUEST, 'sn', '', 'int');
010 
011 
012require_once(TADTOOLS_PATH.'/tcpdf/tcpdf.php');
013$pdf = new TCPDF("P");
014 
015$pdf->setPrintHeader(true); //不要頁首
016$pdf->setPrintFooter(true); //不要頁尾
017$pdf->SetMargins(10, 25);
018$pdf->setHeaderMargin(5); //頁首上方與頁面頂端的距離
019$pdf->setFooterMargin(20); //頁尾上方與頁面尾端的距離
020 
021$pdf->setHeaderData('pdf_logo.png', 50, '我的通訊錄', '常用電話', array(0, 0, 255), array(150, 150, 150));
022$pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
023$pdf->setHeaderFont(array('droidsansfallback', '', 12));
024$pdf->setFooterFont(array('droidsansfallback', '', 12));
025 
026 
027$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);  //設定自動分頁
028$pdf->setFontSubsetting(true); //產生字型子集(有用到的字才放到文件中)
029$pdf->SetFont('droidsansfallback', '', 10, '', true); //設定字型
030$pdf->AddPage(); //新增頁面
031 
032if($sn){
033 
034  $myts = MyTextSanitizer::getInstance();
035 
036  $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "`
037  where `sn` = '{$sn}' ";
038  $result = $xoopsDB->query($sql) or web_error($sql);
039  $all = $xoopsDB->fetchArray($result);
040 
041  //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
042  foreach ($all as $k => $v) {
043      $$k = $v;
044  }
045 
046  //取得分類資料(phone_book_cate)
047  //$phone_book_cate_arr = get_phone_book_cate($cate_sn);
048 
049  //過濾讀出的變數值
050  $name     = $myts->htmlSpecialChars($name);
051  $birthday = $myts->htmlSpecialChars($birthday);
052  $phone    = $myts->htmlSpecialChars($phone);
053  $email    = $myts->htmlSpecialChars($email);
054  $zip      = $myts->htmlSpecialChars($zip);
055  $county   = $myts->htmlSpecialChars($county);
056  $city     = $myts->htmlSpecialChars($city);
057  $addr     = $myts->htmlSpecialChars($addr);
058  $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);
059 
060  $pdf->SetFont('droidsansfallback', '', 36, '', true); //設定字型
061 
062  $pdf->Image(XOOPS_ROOT_PATH.'/uploads/photo.jpg', $x='', $y='', 80, 80, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array());
063 
064  $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
065  $pdf->Cell(80, 80, $name, 1, 0, 'C','','','','','','B');
066  $pdf->setTextShadow(array('enabled'=>false));
067 
068  $pdf->SetFont('droidsansfallback', '', 16, '', true); //設定字型
069 
070  $pdf->Cell(30, 20, '電話', 1, 0, 'C');
071  $pdf->Cell(80, 20, $phone, 1, 1, 'C');
072 
073  //$pdf->Cell(80, 80, '', 0, 0, 'C');
074  $pdf->SetX(90);
075  $pdf->Cell(30, 20, '信箱', 1, 0, 'C');
076  $pdf->Cell(80, 20, $email, 1, 1, 'C');
077 
078  $pdf->SetX(90);
079  $pdf->Cell(30, 20, '生日', 1, 0, 'C');
080  $pdf->Cell(80, 20, $birthday, 1, 1, 'C');
081 
082  $pdf->SetX(90);
083  $pdf->Cell(30, 20, '地址', 1, 0, 'C');
084  //$pdf->Cell(80, 20, "{$zip}{$county}{$city}{$addr}", 1, 1, 'C','','',1);
085  $pdf->MultiCell(80, 20, "{$zip}{$county}{$city}{$addr}", 1, 'L');
086 
087 
088}else{
089 
090  $and_name=$and_cate_sn=$and_city="";
091  if(!empty($def_keyword)){
092      $and_name="and (`name` like '%{$def_keyword}%' or `city` like '%{$def_keyword}%' or `county` like '%{$def_keyword}%' or `addr` like '%{$def_keyword}%')";
093  }else{
094      $and_cate_sn = empty($def_cate_sn) ? "" : "and `cate_sn` = '{$def_cate_sn}'";
095      $and_county = empty($def_county) ? "" : "and `county` = '{$def_county}'";
096      $and_city = empty($def_city) ? "" : "and `city` = '{$def_city}'";
097  }
098 
099  //取得分類資料
100  $phone_book_cate_arr = get_phone_book_cate_arr();
101 
102  $myts = MyTextSanitizer::getInstance();
103 
104  $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where 1 $and_cate_sn $and_county $and_city $and_name limit 0,100";
105 
106  $result = $xoopsDB->query($sql)
107  or web_error($sql);
108 
109  $html='<table width="100%" border="1" cellpadding="4" cellspacing="0">';
110  while ($all = $xoopsDB->fetchArray($result)) {
111      //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
112      foreach ($all as $k => $v) {
113          $$k = $v;
114      }
115 
116      //過濾讀出的變數值
117      $name     = $myts->htmlSpecialChars($name);
118      $birthday = $myts->htmlSpecialChars($birthday);
119      $phone    = $myts->htmlSpecialChars($phone);
120      $email    = $myts->htmlSpecialChars($email);
121      $zip      = $myts->htmlSpecialChars($zip);
122      $county   = $myts->htmlSpecialChars($county);
123      $city     = $myts->htmlSpecialChars($city);
124      $addr     = $myts->htmlSpecialChars($addr);
125      $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);
126 
127      $html.="
128      <tr>
129        <td width=\"40\" align=\"center\" bgcolor=\"yellow\">$name</td>
130        <td width=\"60\" align=\"center\">$birthday</td>
131        <td width=\"75\" align=\"center\">$phone</td>
132        <td width=\"120\">$email</td>
133        <td width=\"190\">{$zip}{$county}{$city}{$addr}</td>
134        <td width=\"55\" align=\"center\">{$phone_book_cate_arr[$cate_sn]['cate_title']}</td>
135      </tr>
136      ";
137  }
138 
139  $html.="</table>";
140 
141  $pdf->writeHTML($html);
142 
143}
144 
145 
146//PDF內容設定
147$pdf->Output('通訊錄.pdf', 'I');
148// $pdf->Output('通訊錄.pdf', 'I');
149// $pdf->Output(XOOPS_ROOT_PATH.'/uploads/contact.pdf', 'F');

 


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp22.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1267%26tbsn%3D39

書籍目錄

展開 | 闔起

線上使用者

39人線上 (6人在瀏覽線上書籍)

會員: 0

訪客: 39

更多…