$val) { if(is_array($val)) { if($name==null) $ret .= queryString($val, $key); else $ret .= queryString($val, $name."[$key]"); } else { if($name!=null) $ret.=$name."[$key]"."=$val&"; else $ret.= "$key=$val&"; } } return $ret; } function LIB_removeGETinput($getValue=NULL, $removeSearch=false) { $otherInput = ""; foreach($_GET as $currPara => $currGETValue) { if (is_array($getValue)) { if (!in_array($currPara, $getValue)) { if (($removeSearch == true) && (strstr($currPara, "UT_SCH_") != "")) { } else { if ($currGETValue != "") { if ($otherInput == "") $otherInput .= "?"; else $otherInput .= "&"; $otherInput .= $currPara . "=" . $currGETValue; } } } } else if ($currPara != $getValue) { if ($otherInput == "") $otherInput .= "?" . $currPara . "=" . $currGETValue; else $otherInput .= "&" . $currPara . "=" . $currGETValue; } } if ($otherInput == "") $otherInput .= "?"; else $otherInput .= "&"; return $otherInput; } function unhtml($content){ $content=htmlspecialchars($content); $content=str_replace(chr(13),"
",$content); $content=str_replace(chr(32)," ",$content); $content=str_replace("[_[","<",$content); $content=str_replace("]_]",">",$content); $content=str_replace("|_|"," ",$content); return trim($content); } function getResizePercent($source_w, $source_h, $inside_w, $inside_h) { if ($source_w < $inside_w && $source_h < $inside_h) { return 1; // Percent = 1, 如果都比預計縮圖的小就不用縮 } $w_percent = $inside_w / $source_w; $h_percent = $inside_h / $source_h; return ($w_percent > $h_percent) ? $h_percent : $w_percent; } // $v = getResizePercent($source_w, $source_h, $inside_w, $inside_h); // widthh='$width * $v' height='$height * $v' /************************************** get db data ********************************************/ function get_db_array($table_name, $key, $display, $sqlCondition = ""){ $db = new DB; $sql = "select " . $key . ", " . $display . " from ".$table_name." where true " . $sqlCondition; $db->query($sql); $ret=""; while($db->next_record()){ $ret[$db->f($key)] = $db->f($display); } return $ret; } function Seletion($obj="", $data_arr="", $id, $index="1", $width="150"){ $output = "\r\n"; return $output; } function check_db_table($table_name){ $db = new DB; $sql = "SELECT table_name FROM information_schema.tables WHERE table_name = '".$table_name."'"; $db->query($sql); if($db->next_record()){ return true; }else{ return false; } } /****************************** 中文 substr **************************************/ //echo utf8_strlen('測試ABC'); ==> 7 function utf8_strlen($str) { $count = 0; for($i = 0; $i < strlen($str); $i++){ $value = ord($str[$i]); $value; if($value > 127) { $count++; if($value >= 192 && $value <= 223) $i++; elseif($value >= 224 && $value <= 239) $i = $i + 2; elseif($value >= 240 && $value <= 247) $i = $i + 3; else die('Not a UTF-8 compatible string'); } $count++; } return $count; } //echo utf8_substr('測A測測CD',5); ==> 測A function utf8_substr($str,$num) { for($i = 0; $i < strlen($str); $i++){ $value = ord($str[$i]); if($value > 127) { if($value >= 192 && $value <= 223)$ii = 2; elseif($value >= 224 && $value <= 239)$ii = 3; elseif($value >= 240 && $value <= 247)$ii = 4; } else $ii = 1; $word = substr($str,$i,$ii); $i = $i + $ii-1; $count = ($ii>=2)?$count + $ii-1:$count + $ii; if($count>$num) return $nstr; $nstr .= $word; } return $nstr; } //eg : if(utf8_strlen(db->f("n_name")) > limited_word) // $topic = utf8_substr(db->f("n_name"), limited_word)."..."; /******************************Page class**************************************/ class SubPages{ private $each_disNums;//每頁顯示的條目數 private $nums;//總條目數 private $current_page;//當前被選中的頁 private $sub_pages;//每次顯示的頁數 private $pageNums;//總頁數 private $page_array = array();//用來構造分頁的數組 private $subPage_link;//每個分頁的鏈接 private $subPage_type;//顯示分頁的類型 public $output;// chiu add it /* __construct是SubPages的構造函數,用來在創建類的時候自動運行. @$each_disNums 每頁顯示的條目數 @nums 總條目數 @current_num 當前被選中的頁 @sub_pages 每次顯示的頁數 @subPage_link 每個分頁的鏈接 @subPage_type 顯示分頁的類型 當@subPage_type=1的時候為普通分頁模式 example: 共4523條記錄,每頁顯示10條,當前第1/453頁 [首頁] [上頁] [下頁] [尾頁] 當@subPage_type=2的時候為經典分頁樣式 example: 當前第1/453頁 [首頁] [上頁] 1 2 3 4 5 6 7 8 9 10 [下頁] [尾頁] */ function __construct($each_disNums,$nums,$current_page,$sub_pages,$subPage_link,$subPage_type){ $this->each_disNums=intval($each_disNums); $this->nums=intval($nums); if(!$current_page){ $this->current_page=1; }else{ $this->current_page=intval($current_page); } $this->sub_pages=intval($sub_pages); $this->pageNums=ceil($nums/$each_disNums); $this->subPage_link=$subPage_link; $this->show_SubPages($subPage_type); //echo $this->pageNums."--".$this->sub_pages; } /* __destruct析構函數,當類不在使用的時候調用,該函數用來釋放資源。 */ function __destruct(){ unset($each_disNums); unset($nums); unset($current_page); unset($sub_pages); unset($pageNums); unset($page_array); unset($subPage_link); unset($subPage_type); } /* show_SubPages函數用在構造函數里面。而且用來判斷顯示什麼樣子的分頁 */ function show_SubPages($subPage_type){ if($subPage_type == 1){ $this->subPageCss1(); }elseif ($subPage_type == 2){ $this->subPageCss2(); }elseif($subPage_type == 3) $this->subPageCss3(); } /* 用來給建立分頁的數組初始化的函數。 */ function initArray(){ for($i=0;$i<$this->sub_pages;$i++){ $this->page_array[$i]=$i; } return $this->page_array; } /* construct_num_Page該函數使用來構造顯示的條目 即使:[1][2][3][4][5][6][7][8][9][10] */ function construct_num_Page(){ if($this->pageNums < $this->sub_pages){ $current_array=array(); for($i=0;$i<$this->pageNums;$i++){ $current_array[$i]=$i+1; } }else{ $current_array=$this->initArray(); if($this->current_page <= 3){ for($i=0;$icurrent_page <= $this->pageNums && $this->current_page > $this->pageNums - $this->sub_pages + 1 ){ for($i=0;$ipageNums)-($this->sub_pages)+1+$i; } }else{ for($i=0;$icurrent_page-2+$i; } } } return $current_array; } /* 構造普通模式的分頁 共4523條記錄,每頁顯示10條,當前第1/453頁 [首頁] [上頁] [下頁] [尾頁] */ function subPageCss1(){ $output =""; $output .="共".$this->nums."條記錄,"; $output .="每頁顯示".$this->each_disNums."條,"; $output .="當前第".$this->current_page."/".$this->pageNums."頁 "; if($this->current_page > 1){ $firstPageUrl=$this->subPage_link."1"; $prewPageUrl=$this->subPage_link.($this->current_page-1); $output .="[首頁] "; $output .="[上一頁] "; }else { $output .="[首頁] "; $output .="[上一頁] "; } if($this->current_page < $this->pageNums){ $lastPageUrl=$this->subPage_link.$this->pageNums; $nextPageUrl=$this->subPage_link.($this->current_page+1); $output .=" [下一頁] "; $output .="[尾頁] "; }else { $output .="[下一頁] "; $output .="[尾頁] "; } $this->output = $output ; } /* 構造經典模式的分頁 當前第1/453頁 [首頁] [上頁] 1 2 3 4 5 6 7 8 9 10 [下頁] [尾頁] */ function subPageCss2(){ $output=""; $output.="當前第".$this->current_page."/".$this->pageNums."頁 "; if($this->current_page > 1){ $firstPageUrl=$this->subPage_link."1"; $prewPageUrl=$this->subPage_link.($this->current_page-1); $output.="[首頁] "; $output.="[上一頁] "; }else { $output.="[首頁] "; $output.="[上一頁] "; } $a=$this->construct_num_Page(); for($i=0;$icurrent_page ){ $output.="[".$s."]"; }else{ $url=$this->subPage_link.$s; $output.="[".$s."]"; } } if($this->current_page < $this->pageNums){ $lastPageUrl=$this->subPage_link.$this->pageNums; $nextPageUrl=$this->subPage_link.($this->current_page+1); $output.=" [下一頁] "; $output.="[尾頁] "; }else { $output.="[下一頁] "; $output.="[尾頁] "; } $this->output = $output; } function subPageCss3(){// chiu add it $output ="
\r\n"; //$output.="T:".$this->nums."  ".$this->current_page." of ".$this->pageNums."  "; if($this->current_page > 1){ $firstPageUrl=$this->subPage_link."1"; $prewPageUrl=$this->subPage_link.($this->current_page-1); $output .=" << "; $output .=" < "; }else { $output .=" << "; $output .=" < "; } $a=$this->construct_num_Page(); for($i=0;$icurrent_page ){ $output .="".$s.""; }else{ $url=$this->subPage_link.$s; $output .="".$s.""; } } if($this->current_page < $this->pageNums){ $lastPageUrl=$this->subPage_link.$this->pageNums; $nextPageUrl=$this->subPage_link.($this->current_page+1); $output .=" > "; $output .=" >> "; }else { $output .=" > "; $output .=" >> "; } $output .="
"; $output .="
\r\n"; $this->output = $output; // chiu add it } }// end class /********** Check View **********/ function LIB_isViewRec() { return($_GET["mode"] == "View" && (!is_null($_GET["id"]))); } function LIB_isNewRec() { return($_GET["mode"] == "New"); } function LIB_isListRec() { return($_GET["mode"] == ""); } /********** Create Folder **********/ function LIB_createFolder($basePath, $subPath, $folderMode=0777) { $currPath = $basePath; if (is_array($subPath)) { foreach($subPath as $currDir) { $currPath .= $currDir . "/"; if (!file_exists($currPath)) { mkdir($currPath); chmod($currPath, $folderMode); } } } else { $currPath .= $subPath . "/"; if (!file_exists($currPath)) { mkdir($currPath); chmod($currPath, $folderMode); } } if (file_exists($currPath)) return (true); else return (false); } /********* Date to mktime ***********/ function date2mktime($timestr) { if (($timestr != "" ) && ($timestr != 0)) { list($date, $time) = explode(' ', $timestr); list($yyyy, $mm, $dd) = explode('-', $date); if ($time != "") list($hr, $min, $ss) = explode(':', $time); else { $hr=$min=$ss=0; } return mktime(intval($hr), intval($min), intval($ss), intval($mm), intval($dd), intval($yyyy)); } else return 0; } function LIB_nl2li($str) { $str = "
  • " . $str ."
  • "; $str = str_replace("\n","\n
  • ",$str); return $str; } ?>