function authorUsr($ss, $msg, $flag, $url, $usr){
if($usr=='Admin'){
if($ss=='' || $ss !='Administrator'){
ShowMsg($msg,$flag,$url, pageCharSet);
exit;
}
}else{
if($ss==''){
ShowMsg($msg,$flag,$url, pageCharSet);
exit;
}
}
}
function ShowMsg($msg,$flag,$myurl, $en){
if($en==''){
$en='big5';
}
echo "\n
\n\n";
echo "Show Message\n\n\n\n\n";
}
/*
Set a Random Number OR Set a GUID
$MygetRand=new getRands;
$MygetRand->randStart=30;
$MygetRand->randEnd=50;
$MygetRand->ArrSize=5;
$MygetRand->randomStr="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
$MygetRand->getRandStr();
$Ary=$MygetRand->PushArray();
for($i=0;$i";
}
*/
class aVariable {
var $randStart=0; //random number range start
var $randEnd=0; //random number range end
var $ArrSize=0; //random array size
var $randomStr; // string like $str="a,b,c,d,e,f"; for split to array
var $inAry=array(); //initial a array
var $val='123';
//Set a Random number
function getRand(){
srand((double)microtime()*1000000);
$getRand=Abs(rand($this->randStart,$this->randEnd));
return $getRand;
}
//Set Random Array
function PushArray(){
while(sizeof($this->inAry)<$this->ArrSize){
$this->val=$this->getRand();
//echo "..".$this->val."
";
if(!in_array($this->val, $this->inAry) && $this->val!=""){
array_push($this->inAry, $this->val);
}
}
return $this->inAry;
}
//random string
function getRandStr(){
$arr=split(",", $this->randomStr);
$this->randStart=0;
$this->randEnd=sizeof($arr)-1;
$str="";
for($i=0;$i<$this->ArrSize;$i++){
$str.=$arr[$this->getRand()];
}
unset($arr);
return $str;
}
//Set GUID
function getGUID(){
return md5(uniqid(rand()));
}
}
/*
Output data to html or file
$MyDB = new DB;
$MyDB->command_sql=$SQL;
$Rs=$MyDB->ExecCmd();
$MyFile=new OutputData;
$MyFile->OutputExcelRec=$Rs;
$MyFile->OutputExcel();
$MyDB->dbClose();
*/
class OutputData {
var $OutputExcelRec;
function OutputExcel(){
// header("Content-type:application/vnd.ms-excel");
// header("Content-Disposition:attachment;filename=php2excel.xls");
$totalRows=mysql_num_rows($this->OutputExcelRec);
if($totalRows>65535){
echo "超過65535筆資料無法匯出,請與資訊人員聯繫";
exit;
}else{
echo "\n";
//表頭///////////
$num_fields = mysql_num_fields($this->OutputExcelRec);
echo "\n";
for($i=0; $i<$num_fields; $i++){
$fields[$i] = mysql_fetch_field($this->OutputExcelRec);
echo "\t| ".$fields[$i]->name." | \n";
}
echo "
\n";
//表頭 end ///////////
//內文 ////////////////////////////
while($row = mysql_fetch_array($this->OutputExcelRec)){
echo "\n";
for($i=0;$i<$num_fields;$i++){
echo "\t| ".$row[$i]." | \n";
}
echo "
\n";
}
//內文 end ////////////////////////
echo "
";
}
mysql_free_result($this->OutputExcelRec);
}
}
/*
$MyMail=new sMail;
$MyMail->charset="UTF-8";
$MyMail->ContentType="text/html";
$MyMail->FName=$MyMail->Base64EnCode($CUName);
$MyMail->FMail=$CUEmail;
$MyMail->TName=$MyMail->Base64EnCode(iconv("big5",$en,"查理寄"));
$MyMail->TMail="charlie@kehch.com";
$MyMail->Subject=$MyMail->Base64EnCode("中文的主旨測試");
$MyMail->Content=base64_encode($MailBody);
$MyMail->Send();
*/
class sMail {
var $charset="big5";
var $encode="base64";
var $ContentType="text/html"; //multipart/alternative , text/plain
var $Priority=3;
var $FName="";
var $FMail="";
var $TName="";
var $TMail="";
var $Subject="";
var $Content="";
function Base64EnCode($Str) {
$Str="=?".$this->charset."?B?".base64_encode($Str)."?= ";
return $Str;
}
function EncodeHeader(){
//$Headers="Return-Path: ".$this->FromMail."\r\n";
$Headers.="From: "."".$this->FName.""."<".$this->FMail.">".""."\r\n";
$Headers.="Bcc: ".$this->BccEmail."\r\n";
$Headers.="Reply-To: "."".$this->FName.""."<".$this->FMail.">".""."\r\n";
//$Headers.="MIME-Version: 1.0 \r\n ";
$Headers.="Content-Type: "."".$this->ContentType."".";charset="."".$this->charset.""." \n";
$Headers.="Content-Transfer-Encoding: "."".$this->encode.""." \n";
$Headers.="X-Priority:"."".$this->Priority."";
return $Headers;
}
function Send() {
$ToWho=$this->TName."<".$this->TMail.">";
$SendHeader=$this->EncodeHeader();
$SendMail_Params="-f".$this->FMail;
$Result=mail($ToWho, $this->Subject, $this->Content, $SendHeader, $SendMail_Params);
//return $Result;
}
/*
function mbSend() {
$Headers="MIME-Version: 1.0 \n";
$Headers.="From: "."".mb_encode_mimeheader(mb_convert_encoding($this->FName, $this->charset, "AUTO")).""."<".$this->FMail."> \n";
$Headers.="Reply-To: "."".mb_encode_mimeheader(mb_convert_encoding($this->FName, $this->charset, "AUTO")).""."<".$this->FMail."> \n";
$Headers.="Content-Type: "."".$this->ContentType."".";charset="."".$this->charset.""." \n";
$Headers.="Content-Transfer-Encoding: "."".$this->encode.""." \n";
$Headers.="X-Priority:"."".$this->Priority."";
$SendMail_Params="-f".$this->FMail;
$ToWho=mb_encode_mimeheader(mb_convert_encoding($this->TName, $this->charset, "AUTO")).""."<".$this->TMail.">";
$MailBody=mb_convert_encoding($this->Content, $this->charset,"AUTO");
mb_language("uni");
$MailSubject=mb_convert_encoding($this->Subject, $this->charset,"AUTO");
$MailSubject=mb_encode_mimeheader($MailSubject);
$Result=mail($ToWho, $MailSubject, $MailBody, $Headers, $SendMail_Params);
return $Result;
}
*/
}
/*
* example **
$uploadsPath="uploads/";
$MyUpload=new fileHandler;
$MyUpload->targetPath=$uploadsPath;
$MyUpload->uploadForm=$_FILES['uploadedfile']; //get upload form object
$A=$MyUpload->UploadAttribute(); // get upload file attribute
$MyUpload->ListAttribute($A); // display upload file attribute
echo $MyUpload->ShowUploadError(); // display upload error
$MyUpload->fileTypeList=array(
'image/pjpeg'=>'jpg'
,'image/jpeg'=>'jpg'
,'image/jpeg'=>'jpeg'
,'image/gif'=>'gif'
,'image/X-PNG'=>'png'
,'image/PNG'=>'png'
,'image/png'=>'png'
,'image/x-png'=>'png'
,'image/JPG'=>'jpg'
,'image/GIF'=>'gif'
);
if($MyUpload->ValidFileType($A)=="FALSE"){ echo "
not valid";}
$MyVar=new aVariable;
$newFileName=$MyVar->getGUID().".".$MyUpload->uploadFileExtension($A['UploadFileName']);
$MyUpload->saveFileName=$newFileName;
if($MyUpload->SaveUploadFile($A)=="TRUE"){
echo "
".$newFileName."==> upload
";
}else{
echo "
".$newFileName."==> upload false
";
}
echo "".$uploadsPath.$newFileName."
";
*/
class fileHandler {
var $targetPath="uploads/"; // don't gorget "/" behind the path string
var $uploadForm;
var $saveFileName;
var $fileTypeList=array(
'image/pjpeg'=>'jpg'
,'image/jpeg'=>'jpg'
,'image/jpeg'=>'jpeg'
,'image/gif'=>'gif'
,'image/X-PNG'=>'png'
,'image/PNG'=>'png'
,'image/png'=>'png'
,'image/x-png'=>'png'
,'image/JPG'=>'jpg'
,'image/GIF'=>'gif'
,'image/bmp'=>'bmp'
,'image/bmp'=>'BMP'
,'text/html'=>'htm'
,'text/html'=>'html'
,'text/plain'=>'txt'
,'application/msword'=>'doc'
,'application/vnd.ms-excel'=>'xls'
);
// list upload file attribute to array()
// return a array() of UploadAttribute()
function UploadAttribute() {
$UA=array(
'UploadError'=>$this->uploadForm['error'],
'UploadFileName'=>$this->uploadForm['name'],
'UploadFileSize'=>$this->uploadForm['size'],
'UploadFileTmpName'=>$this->uploadForm['tmp_name'],
'UploadFileType'=>$this->uploadForm['type']
);
return $UA;
}
// check upload file MIME Type exist in $fileTypeList
// input a array of UploadAttribute()
// return text "TRUE" or "FALSE"
function ValidFileType($Attribute){
if(array_key_exists($Attribute['UploadFileType'], $this->fileTypeList)){
return "TRUE";
}else{
return "FALSE";
}
}
// get upload file extension name
// input a var $FileName return file extension name
function uploadFileExtension($FileName){
$fileName = pathinfo($FileName);
$exten=$fileName["extension"];
return $exten;
}
// save upload file to the target path & new name
// input a array of UploadAttribute()
// return text "TRUE" or "FALSE"
function SaveUploadFile($Attribute){
if(move_uploaded_file($Attribute['UploadFileTmpName'], $this->targetPath.$this->saveFileName)){
return "TRUE";
}else{
return "FALSE";
}
}
// input a array of UploadAttribute()
// display UploadAttribute() all Attribute
function ListAttribute($Attribute) {
foreach($Attribute as $key => $value){
echo $key."==".$value."
";
}
}
// transfer upload error code to display
function ShowUploadError() {
$ErrorCode=$this->UploadAttribute();
switch ($ErrorCode['UploadError']){
case 0:
$Msg="UPLOAD_ERR_OK";
break;
case 1:
$Msg="UPLOAD_ERR_INI_SIZE(upload_max_filesize)";
break;
case 2:
$Msg="UPLOAD_ERR_FORM_SIZE(MAX_FILE_SIZE)";
break;
case 3:
$Msg="UPLOAD_ERR_PARTIAL";
break;
case 4:
$Msg="UPLOAD_ERR_NO_FILE";
break;
case 6:
$Msg="UPLOAD_ERR_NO_TMP_DIR";
break;
default:
$Msg=$ErrorCode.":other error";
break;
}
return $Msg;
}
}
/**
$MyImg=new imageResize;
$MyImg->inFilePath=$uploadsPath.$newFileName;
$MyImg->outputStyle=1;
$MyImg->resizeLimit=1;
$FA=$MyImg->inFileAttribute();
$MyImg->outFilePath=$uploadsPath.$FA['filename']."_s.".$FA['extension'];
$MyImg->ListAttribute($FA);
$MyImg->resizeImage();
*/
class imageResize {
var $inFilePath; // input file path + name
var $srcImgX; // original images width
var $srcImgY; // original images height
var $tmpImg; // tmp images
var $outFilePath; // output file path + name
var $newImg; // output images file
var $resizeX=100; // target images width
var $resizeY=100; // target images height
var $outputStyle="header"; // output resize image files style; "output": output file , "header":output to header
var $newImgX; // output image files width
var $newImgY; // output image files height
var $resizeLimit="fixSize"; // define a shape of output images; "limitSize":resizeToSizeLimit() , "fixSize":originalSizeFix()
// list input file attribute to array()
// return array()
function inFileAttribute() {
$path_parts=pathinfo($this->inFilePath);
if(version_compare(phpversion(), "5.2.0", "<")) {
$FA=array(
'dirname'=>$path_parts['dirname'],
'basename'=>$path_parts['basename'],
'extension'=>$path_parts['extension'],
'filename'=>basename($this->inFilePath, ".".$path_parts['extension'])
);
}else{
$FA=array(
'dirname'=>$path_parts['dirname'],
'basename'=>$path_parts['basename'],
'extension'=>$path_parts['extension'],
'filename'=>$path_parts['filename']
);
}
return $FA;
}
// get input file MIME Type
// return file MIME Type
function getInFileMIME() {
if(function_exists('mime_content_type')){
$IFM=mime_content_type($this->inFilePath);
}else{
$finfo=finfo_open(FILEINFO_MIME);
$IFM=finfo_file($finfo, $this->inFilePath);
finfo_close($finfo);
}
return $IFM;
}
// resize image files
function resizeImage(){
$this->initImage(); // initial original image files to $this->tmpImg
$this->srcImgX=imagesx($this->tmpImg); // original images width
$this->srcImgY=imagesy($this->tmpImg); // original images height
switch ($this->resizeLimit){
case 'limitSize':
$this->resizeToSizeLimit();
break;
case 'fixSize':
$this->originalSizeFix();
break;
}
$this->newImg=imagecreatetruecolor($this->newImgX, $this->newImgY); // Create new true color images ( this can't for gif ) GD 2.0.1 or heigher
//$newImg=ImageCreate($this->newImgX, $this->newImgY); // Create new basic color images ( old GD lower version )
imagecopyresampled($this->newImg, $this->tmpImg, 0, 0, 0, 0, $this->newImgX, $this->newImgY, $this->srcImgX, $this->srcImgY); // copy image to new images GD 2.0.1 or heigher
//ImageCopyResized($newImg, $srcImg, 0, 0, 0, 0, $this->newImgX, $this->newImgY, $this->srcImgX, $this->srcImgY);
switch ($this->outputStyle){
case "output":
$rs=$this->completeResize();
break;
case "header":
$rs=$this->outputResizeImages();
break;
}
ImageDestroy($this->newImg);
ImageDestroy($this->tmpImg);
return $rs;
}
// follow original width or height to resize image
function originalSizeFix(){
if($this->srcImgX > $this->srcImgY){ // resize percent
$resizePercent=$this->resizeX / $this->srcImgX;
}else{
$resizePercent=$this->resizeY / $this->srcImgY;
}
if($resizePercent>1){
$resizePercent=1;
}
$this->newImgX=ceil($resizePercent*$this->srcImgX);
$this->newImgY=ceil($resizePercent*$this->srcImgY);
}
// guarantee width or heigh of image fixed in resizeX and resizeY
function resizeToSizeLimit(){
$this->originalSizeFix();
if($this->newImgX > $this->resizeX || $this->newImgY > $this->resizeY){
if($this->newImgX > $this->resizeX){
$resizePercent=$this->resizeX / $this->newImgX;
}
if($this->newImgY > $this->resizeY){
$resizePercent=$this->resizeY / $this->newImgY;
}
$this->newImgX=ceil($resizePercent*$this->newImgX);
$this->newImgY=ceil($resizePercent*$this->newImgY);
}
}
// finally resize image to a file
function completeResize(){
$imgType=$this->inFileAttribute();
$rs="";
switch (strtolower($imgType['extension'])){
case "jpg":
case "jpeg":
$rs=imagejpeg($this->newImg,$this->outFilePath);
break;
case "gif":
$rs=imagegif($this->newImg,$this->outFilePath);
break;
case "x-png":
case "png":
$rs=imagepng($this->newImg,$this->outFilePath);
break;
case "bmp":
$rs=imagewbmp($this->newImg,$this->outFilePath);
break;
default :
echo "Error msg : not outpup type - stop program
";
exit;
break;
}
return $rs;
}
// output image files to screen
function outputResizeImages(){
$imgType=$this->inFileAttribute();
switch (strtolower($imgType['extension'])){
case "jpg":
case "jpeg":
header("Content-type: ".$this->getInFileMIME());
imagejpeg($this->newImg);
break;
case "gif":
header("Content-type: ".$this->getInFileMIME());
imagegif($this->newImg);
break;
case "x-png":
case "png":
header("Content-type: ".$this->getInFileMIME());
imagepng($this->newImg);
break;
case "bmp":
header("Content-type: ".$this->getInFileMIME());
imagewbmp($this->newImg);
break;
default :
header("Content-type: text/html;");
echo "Error msg : not outpup type - stop program
";
exit;
break;
}
}
function initImage(){
$imgType=$this->inFileAttribute();
switch (strtolower($imgType['extension'])){
case "jpg":
case "jpeg":
$this->tmpImg=imagecreatefromjpeg($this->inFilePath);
break;
case "gif":
$this->tmpImg=imagecreatefromgif($this->inFilePath);
break;
case "x-png":
case "png":
$this->tmpImg=imagecreatefrompng($this->inFilePath);
break;
case "bmp":
$this->tmpImg=imagecreatefromwbmp($this->inFilePath);
break;
default :
echo "Error msg : No Images type - stop program
";
exit;
break;
}
if(!$this->tmpImg){
echo "create temp images error - stop program";
exit;
}
}
// display upload file all Attribute
function ListAttribute($Attribute) {
foreach($Attribute as $key => $value){
echo $key."==".$value."
";
}
}
}
/*
$Str:字串
$strType:計算函式
$enCode:編碼
*/
function getStrLen($Str, $strType, $enCode){
$Len=0;
if($strType=="mb"){
$Len=mb_strlen($Str,$enCode);
}else{
$Len=strlen($Str);
}
return $Len;
}
function cutStrByLen($Str, $srart, $length, $strType, $enCode){
if($strType=="mb"){
if($length=='0'){
$cStr=mb_substr($Str ,$start ,null ,$enCode);
}else{
$cStr=mb_substr($Str ,$start ,$length ,$enCode);
}
}else{
if($length=='0'){
$cStr=substr($Str ,$start ,null);
}else{
$cStr=substr($Str ,$start ,$length);
}
}
return $cStr;
}
function IsEmail($email){
if (eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email))
return true;
else
return false;
}
/*
// for php5 up
if(!filter_var($_GET['mail'], FILTER_VALIDATE_EMAIL))
{
echo "Wrong e-mail format";
}else{
echo "Right e-mail format";
}
*/
class strHandler {
var $cplumType;
var $inputStr;
var $outputStr;
function cplum(){
switch($this->cplumType){
case 'stripcslashes':
$op=str_replace('\'','\'\'',stripcslashes($this->inputStr));
$op=str_replace('"','""',stripcslashes($op));
break;
}
return $op;
}
}
/*
處理 sqlinjection
function quotes($content)
{
//如果magic_quotes_gpc=Off,那麽就開始處理
if (!get_magic_quotes_gpc()) {
//判斷$content是否爲陣列
if (is_array($content)) {
//如果$content是陣列,那麽就處理它的每一個單無
foreach ($content as $key=>$value) {
$content[$key] = addslashes($value);
}
} else {
//如果$content不是陣列,那麽就僅處理一次
addslashes($content);
}
} else {
//如果magic_quotes_gpc=On,那麽就不處理
}
//返回$content
return $content;
}
*/
class showPageOption{
var $path;
var $pg;
var $pgTotal;
function showPageList(){
echo ''."\n";
echo ''."\n";
echo "\t".'
'."\n";
echo '
'."\n";
echo ''."\n";
echo ''."\n";
}
}
?>