:::

8-2 /pdf.php

<?php
include_once "header.php";

include_once $GLOBALS['xoops']->path('/modules/system/include/functions.php');
$def_city    = system_CleanVars($_REQUEST, 'city', '', 'string');
$def_cate_sn = system_CleanVars($_REQUEST, 'cate_sn', '', 'int');
$def_county    = system_CleanVars($_REQUEST, 'county', '', 'string');
$def_keyword    = system_CleanVars($_REQUEST, 'keyword', '', 'string');
$sn = system_CleanVars($_REQUEST, 'sn', '', 'int');


require_once(TADTOOLS_PATH.'/tcpdf/tcpdf.php');
$pdf = new TCPDF("P");

$pdf->setPrintHeader(true); //不要頁首
$pdf->setPrintFooter(true); //不要頁尾
$pdf->SetMargins(10, 25);
$pdf->setHeaderMargin(5); //頁首上方與頁面頂端的距離
$pdf->setFooterMargin(20); //頁尾上方與頁面尾端的距離

$pdf->setHeaderData('pdf_logo.png', 50, '我的通訊錄', '常用電話', array(0, 0, 255), array(150, 150, 150));
$pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
$pdf->setHeaderFont(array('droidsansfallback', '', 12));
$pdf->setFooterFont(array('droidsansfallback', '', 12));


$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);  //設定自動分頁
$pdf->setFontSubsetting(true); //產生字型子集(有用到的字才放到文件中)
$pdf->SetFont('droidsansfallback', '', 10, '', true); //設定字型
$pdf->AddPage(); //新增頁面

if($sn){

  $myts = MyTextSanitizer::getInstance();

  $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "`
  where `sn` = '{$sn}' ";
  $result = $xoopsDB->query($sql) or web_error($sql);
  $all = $xoopsDB->fetchArray($result);

  //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
  foreach ($all as $k => $v) {
      $$k = $v;
  }

  //取得分類資料(phone_book_cate)
  //$phone_book_cate_arr = get_phone_book_cate($cate_sn);

  //過濾讀出的變數值
  $name     = $myts->htmlSpecialChars($name);
  $birthday = $myts->htmlSpecialChars($birthday);
  $phone    = $myts->htmlSpecialChars($phone);
  $email    = $myts->htmlSpecialChars($email);
  $zip      = $myts->htmlSpecialChars($zip);
  $county   = $myts->htmlSpecialChars($county);
  $city     = $myts->htmlSpecialChars($city);
  $addr     = $myts->htmlSpecialChars($addr);
  $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);

  $pdf->SetFont('droidsansfallback', '', 36, '', true); //設定字型

  $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());

  $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
  $pdf->Cell(80, 80, $name, 1, 0, 'C','','','','','','B');
  $pdf->setTextShadow(array('enabled'=>false));

  $pdf->SetFont('droidsansfallback', '', 16, '', true); //設定字型

  $pdf->Cell(30, 20, '電話', 1, 0, 'C');
  $pdf->Cell(80, 20, $phone, 1, 1, 'C');

  //$pdf->Cell(80, 80, '', 0, 0, 'C');
  $pdf->SetX(90);
  $pdf->Cell(30, 20, '信箱', 1, 0, 'C');
  $pdf->Cell(80, 20, $email, 1, 1, 'C');

  $pdf->SetX(90);
  $pdf->Cell(30, 20, '生日', 1, 0, 'C');
  $pdf->Cell(80, 20, $birthday, 1, 1, 'C');

  $pdf->SetX(90);
  $pdf->Cell(30, 20, '地址', 1, 0, 'C');
  //$pdf->Cell(80, 20, "{$zip}{$county}{$city}{$addr}", 1, 1, 'C','','',1);
  $pdf->MultiCell(80, 20, "{$zip}{$county}{$city}{$addr}", 1, 'L');


}else{

  $and_name=$and_cate_sn=$and_city="";
  if(!empty($def_keyword)){
      $and_name="and (`name` like '%{$def_keyword}%' or `city` like '%{$def_keyword}%' or `county` like '%{$def_keyword}%' or `addr` like '%{$def_keyword}%')";
  }else{
      $and_cate_sn = empty($def_cate_sn) ? "" : "and `cate_sn` = '{$def_cate_sn}'";
      $and_county = empty($def_county) ? "" : "and `county` = '{$def_county}'";
      $and_city = empty($def_city) ? "" : "and `city` = '{$def_city}'";
  }

  //取得分類資料
  $phone_book_cate_arr = get_phone_book_cate_arr();

  $myts = MyTextSanitizer::getInstance();

  $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where 1 $and_cate_sn $and_county $and_city $and_name limit 0,100";

  $result = $xoopsDB->query($sql)
  or web_error($sql);

  $html='<table width="100%" border="1" cellpadding="4" cellspacing="0">';
  while ($all = $xoopsDB->fetchArray($result)) {
      //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note
      foreach ($all as $k => $v) {
          $$k = $v;
      }

      //過濾讀出的變數值
      $name     = $myts->htmlSpecialChars($name);
      $birthday = $myts->htmlSpecialChars($birthday);
      $phone    = $myts->htmlSpecialChars($phone);
      $email    = $myts->htmlSpecialChars($email);
      $zip      = $myts->htmlSpecialChars($zip);
      $county   = $myts->htmlSpecialChars($county);
      $city     = $myts->htmlSpecialChars($city);
      $addr     = $myts->htmlSpecialChars($addr);
      $note     = $myts->displayTarea($note, 0, 1, 0, 1, 1);

      $html.="
      <tr>
        <td width=\"40\" align=\"center\" bgcolor=\"yellow\">$name</td>
        <td width=\"60\" align=\"center\">$birthday</td>
        <td width=\"75\" align=\"center\">$phone</td>
        <td width=\"120\">$email</td>
        <td width=\"190\">{$zip}{$county}{$city}{$addr}</td>
        <td width=\"55\" align=\"center\">{$phone_book_cate_arr[$cate_sn]['cate_title']}</td>
      </tr>
      ";
  }

  $html.="</table>";

  $pdf->writeHTML($html);

}


//PDF內容設定
$pdf->Output('通訊錄.pdf', 'I');
// $pdf->Output('通訊錄.pdf', 'I');
// $pdf->Output(XOOPS_ROOT_PATH.'/uploads/contact.pdf', 'F');

 


:::

搜尋

QR Code 區塊

https%3A%2F%2Fwww.tad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D39%26tbdsn%3D1267

書籍目錄

展開 | 闔起

線上使用者

78人線上 (35人在瀏覽線上書籍)

會員: 0

訪客: 78

更多…