Viewing file: programX.php (8.48 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php set_time_limit(0); include_once("../../class/clsConnection.php"); include_once("../../class/clsDB.php"); include_once "../global.php"; include_once "../class/clsSendReceive.php"; include_once "../class/clsCollegeDetail.php"; include_once "../class/clsCollegeDetail.php";
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
$oTsr = new sendreceive($oC); $oTsr2 = new sendreceive($oC); $oTsr3 = new sendreceive($oC); $oTsr4 = new sendreceive($oC); $oCd = new collegedetail($oC); ?> <html> <head> <title>ตรวจสอบการดาวน์โหลดเอกสาร</title> <meta http-equiv="Content-Type" content="text/html; charset=tis-620"> <link href="../source/style.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#F9FCFF"><br> <table width="90%" align="center"> <tr> <td><strong><img src="../picture/download.gif"> <font size="2">ตรวจสอบการดาวน์โหลดเอกสาร</font></strong></td> </tr>
<?
//----update doc status = r1 to r2 $i=0; if($tsr_idselect==''){ $oTsr3->SearchBytsr_status(r1); while($oTsr3->GetRecord()){ $oTsr3->Edit(); $oTsr3->tsr_status='r2'; $oTsr3->Save(); $i++; } }else{ //case select each doc
$str = $tsr_idselect; $tmp = explode("," ,$str); $tmp = array_reverse($tmp); $reversed_str = join(',', $tmp); $store_DrsID_exp = explode("," ,$reversed_str); $store_DrsID_exp_count=count($store_del_exp); $store_DrsID_exp_count=count($store_DrsID_exp); $checkdoc=0; for($j=0; $j<$store_DrsID_exp_count;$j++){ $tsr_id = trim($store_DrsID_exp[$j]); if(strlen($tsr_id)!=0){ $oTsr3->SearchByKey($tsr_id); while($oTsr3->GetRecord()){ if($oTsr3->tsr_status=='r1'){ $oTsr3->Edit(); $oTsr3->tsr_status='r2'; $oTsr3->Save(); $i++; } } } } } echo "<tr><td> </td></tr>"; if($i==0){ echo "<tr><td align=\"center\"><b> ------------------------ ยังไม่มีเอกสารที่จะดาวน์โหลด ------------------------</b></td></tr>"; }
//----select doc status = r2 start download $oTsr->SearchBytsr_status('r2'); while($oTsr->GetRecord()){ $tsr_id =$oTsr->tsr_id; $tsr_docid =$oTsr->tsr_docid; $tsr_doc_url=$oTsr->tsr_doc_url; $tsr_doc_chksum=$oTsr->tsr_doc_chksum; $tsr_fr_node=$oTsr->tsr_fr_node; $tsr_docname=$oTsr->tsr_docname; $tsr_statusDocAtt=$oTsr->tsr_statusDocAtt; $tsr_DocTelOwner=$oTsr->tsr_DocTelOwner; $tsr_DocDeptOwner=$oTsr->tsr_DocDeptOwner; $tsr_DocFaxOwner=$oTsr->tsr_DocFaxOwner; $tsr_DocCopySend=$oTsr->tsr_DocCopySend; $tsr_DocContactE=$oTsr->tsr_DocContactE; $tsr_CountDoc=$oTsr->tsr_CountDoc;
$oCd->SearchByKey($oTsr->tsr_fr_node); $oCd->GetRecord(); echo "<tr><td align=\"center\"><b> ------------------------ กำลังดาวน์โหลดเอกสาร ------------------------</b></td></tr>"; echo "<tr><td align=\"left\"><b> ชื่อเรื่อง :: </b>".$oTsr->tsr_DocSubject."</td></tr>"; echo "<tr><td align=\"left\"><b> ที่หนังสือ :: </b>".$oTsr->tsr_DocNo."</td></tr>"; echo "<tr><td align=\"left\"><b> จาก :: </b>".$oCd->collegeAbbr."</td></tr>"; echo "<tr><td align=\"left\"><b> สถานะการดาวน์โหลดเอกสาร :: </b></td></tr>"; //---download each Doc $i=0; // echo " === > ".$tsr_doc_url; exit; while($tsr_doc_url!=''){ list($downloadurl,$tsr_doc_url)=preg_split('[,]',$tsr_doc_url,2); list($downloadfilename,$tsr_docname)=preg_split('[,]',$tsr_docname,2); list($downloadchksum,$tsr_doc_chksum)=preg_split('[,]',$tsr_doc_chksum,2); $checktsr_statusDocAtt.='Y'; $i++; echo "<tr><td align=\"left\"><b> แฟ้ม :: </b>".$downloadfilename."</td></tr>"; echo "<tr><td align=\"left\"> "; if(downloadRemoteFile($tsr_fr_node,$downloadurl, $GLOBALS['path_upload_documentsTmp'])==true){ echo "</td></tr>"; $file_name = basename($downloadurl); $file_name_write=$file_name; $filename_=''; $filetype_=''; list($filename_,$filetype_)=preg_split("/\./",$file_name_write); $filewrite=$filename_.'-'.$tsr_fr_node.'.'.$filetype_; $fileN=substr(strrchr($downloadurl, '/'),1); $pathfile=$GLOBALS['path_upload_documentsTmp'].$filewrite; $checksum=md5_file($pathfile); $c=0; if($downloadchksum==""){ $c=1; } if(($checksum==$downloadchksum) || $c==1){ //--update tsr_statusDocAtt $count=strlen($tsr_statusDocAtt); if($count!=$i){ $tsr_statusDocAtt = substr_replace($tsr_statusDocAtt, "Y", $i-1,-($count-1-($i-1))); }else{ $tsr_statusDocAtt = substr_replace($tsr_statusDocAtt, "Y", $count-1); } $oTsr2->SearchByKey($oTsr->tsr_id); $oTsr2->GetRecord(); $oTsr2->Edit(); $oTsr2->tsr_statusDocAtt=$tsr_statusDocAtt; $oTsr2->Save(); $oTsr2->Close(); echo "<tr><td align=\"left\"> >>>>> ดาวน์โหลดเอกสารสมบูรณ์ <<<<<</td></tr>"; }else{ echo "<tr><td align=\"left\"> >>>>> เอกสารที่ดาวน์โหลดมาไม่สมบูรณ์ <<<<<</td></tr>"; } }else{ echo "<tr><td align=\"left\"> >>>>> ไม่สามารถดาวน์โหลดเอกสารได้ <<<<<</td></tr>"; } //-----if finish download all doc if($tsr_statusDocAtt==$checktsr_statusDocAtt){ //if chksum OK -------------update status = r3-------------- $oTsr2->SearchByKey($oTsr->tsr_id); $oTsr2->GetRecord(); $oTsr2->Edit(); $oTsr2->tsr_status='r3'; $oTsr2->Save(); $tsr_docid2 =$oTsr2->tsr_docid; $tsr_fr_node2=$oTsr2->tsr_fr_node; $tsr_id2=$oTsr2->tsr_id_send; $oTsr2->Close(); //if chksum OK -------------sendTos3----------------- $oCd = new collegedetail($oC); $oCd->SearchByKey($tsr_fr_node2); $oCd->GetRecord(); $msg='?fn=s3&tsr_id='.$tsr_id2; if($tsr_fr_node2==99){ $folder=$GLOBALS["FOLDERFORSEND1"]; }else if($tsr_fr_node2==8){ $folder=$GLOBALS["FOLDERFORSEND3"]; }else{ $folder=$GLOBALS["FOLDERFORSEND2"]; } $path_send='http://'.$oCd->collegeHost.'/'.$folder.'/'.'eoffice/admin/sendTSR.php'.$msg; $res=file_get_contents($path_send); //if chksum OK --------------set r3 to r4 not wait return fn=s3------------------------ $oTsr4->SearchBytsr_id_send_tsr_fr_node($tsr_id2,$tsr_fr_node2); $oTsr4->GetRecord(); $oTsr4->Edit(); $oTsr4->tsr_status='r4'; $oTsr4->Save(); } } //split tsr_doc_url } echo "</table>"; if($tsr_idselect==''){ echo "<meta http-equiv='refresh' content='10; URL=programX.php'>"; } ?> </body> </html> <? function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); }
function downloadRemoteFile($tsr_fr_node,$url,$dir,$file_name = NULL){
if($file_name == NULL){ $file_name = basename($url); } $file_name_write=$file_name; $url_stuff = parse_url($url);
$port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;
$fp = fsockopen($url_stuff['host'], $port); if(!$fp){ return false;}
$query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n"; $query .= 'Host: ' . $url_stuff['host']; $query .= "\n\n"; fwrite($fp, $query); while ($tmp = fread($fp, 1024)) { $buffer .= $tmp; echo "."; flush(); //ob_flush(); } echo "<br>"; preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts); $file_binary = substr($buffer, - $parts[1]); if($file_name == NULL){ $temp = explode(".",$url); $file_name = $temp[count($temp)-1]; } //$file_open = fopen($dir . "/" . date('Y-m-d_His').$file_name,'w'); //---add collegeId into filename list($filename_,$filetype_)=preg_split("/\./",$file_name_write); $filewrite=$filename_.'-'.$tsr_fr_node.'.'.$filetype_; $file_open = fopen($dir . "/" .$filewrite,'w'); if(!$file_open){ return false; } fwrite($file_open,$file_binary); fclose($file_open); return true;
} ?>
|