!c99Shell v. 1.0 pre-release build #16!

Software: Apache/2.2.3 (CentOS). PHP/5.1.6 

uname -a: Linux mx-ll-110-164-51-230.static.3bb.co.th 2.6.18-194.el5PAE #1 SMP Fri Apr 2 15:37:44
EDT 2010 i686
 

uid=48(apache) gid=48(apache) groups=48(apache) 

Safe-mode: OFF (not secure)

/var/www/html/mistk/mistk/mistk/eoffice/admin/   drwxr-xr-x
Free 53.7 GB of 127.8 GB (42.02%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     mobliedetail.php (161.24 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
$fn 
= (! isset($_REQUEST['fn'])? "" $_REQUEST['fn']);

if(
$fn=='loginmoblie'){ 
include_once(
"../../class/clsConnection.php");
include_once(
"../../class/clsDB.php");
include_once 
"../global.php";
include_once 
"../class/clsUmuser.php";

$Username = (! isset($_REQUEST['Username'])? "" $_REQUEST['Username']);
$Password = (! isset($_REQUEST['Password'])? "" $_REQUEST['Password']);
//====== Test Case For Apple ===================
if($Username == "demosaraban" && $Password == "DEMOSARABAN"){
    
$Username "namphon";
    
$Password "57namphon7";
}
//==============================================
$oUm = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_UMS'], $GLOBALS['DBUSER_UMS'], $GLOBALS['DBPASS_UMS']);
$oUus = new umuser($oUm);

        
$oUus->SearchByLoginMoblie($Username$Password);
        if (
$oUus->GetRecord()) {
            echo 
$oUus->UsPsCode;
        }else{
            echo 
0;
        }
}else if(
$fn=='addsend'){

include_once(
"../../class/clsConnection.php");
include_once(
"../../class/clsDB.php");
include_once 
"../global.php";
include_once 
"../class/clsDepartment.php";
include_once 
"../class/clsPerson.php";
include_once 
"../link/function.php";
include_once 
"../link/functionshow.php";
include_once 
"../class/clsDocLinePosition.php";
include_once 
"../class/clsDocLineConfig.php";
include_once 
"../class/clsReceiveSendType.php";
include_once 
"../class/clsDocType.php";
include_once 
"../class/clsDocSpeedLevel.php";
include_once 
"../class/clsDocSecreLevel.php";
include_once 
"../class/clsDocattatchesTmp.php";
include_once 
"../class/clsDocuments.php";
include_once 
"../class/clsDocattatches.php";
include_once 
"../class/clsDocReceiveSend.php";
include_once 
"../class/clsRunningDoc.php";
include_once 
"functMobile.php";
include_once 
"../class/clspsdept.php";
include_once 
"../class/clsDocSendtoPsTmp.php";

$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
$oDP = new Department($oC);
$oDP2 = new Department($oC);
$oDP3 = new Department($oC);
$oDP4 = new Department($oC);
$oDP5 = new Department($oC);
$oDPt = new Department($oC);
$oDPt2 = new Department($oC);
$oDPt3 = new Department($oC);
$oDPt4 = new Department($oC);

$oPS = new person($oC);
$oPS2 = new person($oC);
$oPS3 = new person($oC);
$oPS4 = new person($oC);
$oPS6 = new person($oC);
$oDlc = new DocLineConfig($oC);
$oDlc2 = new DocLineConfig($oC);
$oDlc3 = new DocLineConfig($oC);
$oDlc6 = new DocLineConfig($oC);
$oDlp = new docLinePosition($oC);
$oDlp1 = new docLinePosition($oC);
$oDlp2 = new docLinePosition($oC);
$oRSt = new receiveSendType($oC);
$oDt = new doctype($oC);
$oDsl = new DocSpeedLevel($oC);
$oDcl = new DocSecretLevel($oC);
$oDtmp = new DocattatchesTmp($oC);
$oDoc = new Documents($oC);
$oDoc2 = new Documents($oC);
$oDoc3 = new Documents($oC);
$oDoc4 = new Documents($oC);
$oDoc5 = new Documents($oC);
$oDatt = new Docattatches($oC);
$oDatt2 = new Docattatches($oC);
$oRs = new DocReceiveSend($oC);
$oRs1 = new DocReceiveSend($oC);
$oRs2 = new DocReceiveSend($oC);
$oRs3 = new DocReceiveSend($oC);
$oRs4 = new DocReceiveSend($oC);
$oRs5 = new DocReceiveSend($oC);
$oRs6 = new DocReceiveSend($oC);
$oRs7 = new DocReceiveSend($oC);
$oRs8 = new DocReceiveSend($oC);
$oRs9 = new DocReceiveSend($oC);
$oRs10 = new DocReceiveSend($oC);
$oRs11 = new DocReceiveSend($oC);
$oRd = new runningdoc($oC);
$oStmp=new DocSendToPsTmp($oC);
$oPSd = new psdept($oC);

$oRs->SearchByKey($DrsID); $oRs->GetRecord(); 
$oRs7->SearchByshowSendDocSign($oRs->DrsFromDrsID); $oRs7->GetRecord(); 

$oPS6->SearchByKey($oRs->DrsPsIDCreate); $oPS6->GetRecord();
$oDlp2->SearchByKey($oDlc6->SearchByKeyName($oRs->DrsDlcIDCreate,'DlpID'));  $oDlp2->GetRecord();


$oDPt->SearchByShowselectdoc($oDlc->deptId);
$oDPt->GetRecord();
$DlcdeptId=$oDlc->deptId;
//---unuse
$checkAllPs=0;
$checkAll=0;
    
    
$DocID = (! isset($_REQUEST['DocID'])? "" $_REQUEST['DocID']);
    
$DlcID = (! isset($_REQUEST['DlcID'])? "" $_REQUEST['DlcID']);
    
$DrsID = (! isset($_REQUEST['DrsID'])? "" $_REQUEST['DrsID']);
    
$DrsSend = (! isset($_REQUEST['DrsSend'])? "" $_REQUEST['DrsSend']);
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
    
$DocSpeedLevelDueDate = (! isset($_REQUEST['DocSpeedLevelDueDate'])? "" $_REQUEST['DocSpeedLevelDueDate']);
    
$PtID = (! isset($_REQUEST['PtID'])? "" $_REQUEST['PtID']);
    
$checkDocSpeedDate = (! isset($_REQUEST['checkDocSpeedDate'])? "" $_REQUEST['checkDocSpeedDate']);
    
    
$JsondeptPs = (! isset($_REQUEST['deptPs'])? "" $_REQUEST['deptPs']);
    
$JsonPs = (! isset($_REQUEST['Ps'])? "" $_REQUEST['Ps']);
    if( 
get_magic_quotes_gpc() ){
        
$JsondeptPs  stripslashes$JsondeptPs );
        
$JsonPs  stripslashes$JsonPs );
    } 
    
    
    
$deptPs json_decode$JsondeptPstrue ); 
    
$Ps json_decode$JsonPstrue );
    echo 
'<?xml version="1.0" encoding="UTF-8" ?><BBBB>'.iconv('TIS-620','UTF-8','AAA')."</BBBB>";



$useacceptDoc=$oSys->SearchacceptDoc();

$MaxDocGroup=$oDP->SearchMaxDocGroup();
$DrsSend iconv('UTF-8','TIS-620',$DrsSend);

    
//---main document    
    
$oDoc2->SearchByKey($DocID);
    
$oDoc2->GetRecord();
        
    
$oRs11->SearchByDocGroupDocIDStatus3($oDoc2->DocGroup,$DocID);
    
$oRs11->GetRecord();
    
    if(
$oRs11->DsID=='3' && $oRs11->DrsSendDate=='0000-00-00 00:00:00'){   //can send case normal

    
$flagCommit true;
    
$checkflagCommittrue;
    
$oC->BeginTrans();
    
                    
$DocIDParent=GetParentDoc($DocID);
                    
//echo "DocIDParent=".$DocIDParent."<br>";
                    
                    //---select after sendtops
                    
if($showsendtops=="Y"){
                        
$oDoc5->SearchByKey($DocID);
                        
$oDoc5->GetRecord();
                        
$oDoc5->Edit();
                        
$oDoc5->sendToPs="Y";
                        
$oDoc5->Save();        
                    }    
                    
                
                    
                    if(
$useacceptDoc=="Y"){
                        
$oRs10->SearchByDocGroupDocIDStatus3($oDoc2->DocGroup,$DocID);
                        if(
$oRs10->GetRecord()==1){
                            
$sendPersonId=$oRs10->DrsPsIDCreate;
                        }else{
                            
$sendPersonId="";
                        }                    
                        
$oRs6->SearchByDocGroupDocIDStatus2($oDoc2->DocGroup,$DocID);
                        if(
$oRs6->GetRecord()==1){
                            
$signPersonId=$oRs6->DrsPsIDCreate;
                        }else{
                            
$signPersonId="";
                        }
                        
$oRs7->SearchByDocGroupDocIDStatus1($oDoc2->DocGroup,$DocID);
                        if(
$oRs7->GetRecord()==1){
                            
$regisPersonId=$oRs7->DrsPsIDCreate;
                        }else{
                            
$regisPersonId="";
                        }        
                    }
                
                    
                    
$oRs4->SearchByDrsIDRegisterDoc($DrsID);
                    
$oRs4->GetRecord();
                
                    
$oRs9->SearchByKey($DrsID);
                    
$oRs9->GetRecord();    
                    
$oRs9->Edit();
                    
$oRs9->DlcID=$DlcID;
                    
$oRs9->DrsReceivePersonId=$personId;
                    
$oRs9->Save();
                
                    
                    
$oRs8->SearchPreDocSignforDlpID0_Update2($DlcID,$personId,$oRs9->DrsFromDrsID);
        
                
                        
                    
$timesend=getNowDateTh()." ".date('H:i:s');
                    
                    
$checkupdate=0;
                    
$checkupdate2=0;
                    
$checkupdate3=0;
                    
                    
                        
//-----------------send to Dept----------------------------------
                //----send All deptId----------------------------------------------------------------
                        
if($checkAll=="1"){ //send All deptId
                        
                            
if($maindept!=1){
                                
$oDPt->SearchByKey($DlcdeptId);
                                
$oDPt->GetRecord();
                            
                                
//---send to deptParentId------------------------                
                                
if($oDPt->deptParentId==0){
                                    
$oDPt2->RSmenuByDeptParent2($oDPt->deptParentId);
                                    while(
$oDPt2->GetRecord()){
                                        if(
$oDPt2->deptId!=$DlcdeptId){
                                            
$pssend=ShowSendtoPs2($oDPt2->deptId); 
                                            if(
$pssend!=''){
                                                    
$oDoc->AddNew();
                                                    
$oDoc->DocID=$oDoc->GetNextCode();
                                                    
$oDoc->DocPID=$DocIDParent;
                                                    
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                    
$oDoc->DlcID=$pssend;   
                                                    
//echo "pssend=".$pssend."<br>";
                                                    
$oDoc->PtID=$PtID;
                                                    
//echo "PtID=".$oDoc->PtID."<br>";
                                                    
$oDoc->DtID=$oDoc2->DtID
                                                    
$oDoc->DslID=$oDoc2->DslID;
                                                    
$oDoc->DclID=$oDoc2->DclID;
                                                    
$oDoc->DsID="0";
                                                    
$oDoc->RsID="3"//sendin
                                                    
$oDoc->DocDateCreate=$timesend;
                                                    
$DocDateCreate=$oDoc->DocDateCreate;
                                                    
$oDoc->DocUserCreate=$pssend;
                                                    
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                    //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                    
$oDoc->DocTypeNo=$oDoc->DocTypeNo;
                                                    
//echo "DocTypeNo=".$DocTypeNo."<br>";
                                                    
$oDoc->DocDate=$oDoc2->DocDate;
                                                    
$oDoc->DocNo=$oDoc2->DocNo;
                                                    
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                    
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                    
$oDoc->DocTo=$oDoc2->DocTo;
                                                    
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                    
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                    
//echo "speedDate=".$speedDate."<br>";
                                                    
$oDoc->DocStart=$oDoc2->DocStart;
                                                    
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                    
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                    
$oDoc->DocRef=$oDoc2->DocRef;
                                                    
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                    
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                    
$oDoc->DocOther=$oDoc2->DocOther;
                                                    
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                    
$oDoc->fDelete=$oDoc2->fDelete;
                                                    
$oDoc->endDoc=$oDoc->endDoc;
                                                    
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                    
$oDoc->AnID=$AnID;
                                                    
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                    
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                        
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                        
                                                    }
                                                        if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                            
$addDocShowInOut="3";
                                                        }else{
                                                            if(
$DocShowIn=="1"){
                                                                
$addDocShowInOut=$DocShowIn;
                                                            }else if(
$DocShowOut=="2"){
                                                                
$addDocShowInOut=$DocShowOut;
                                                            }
                                                        }
                                                    
                                                    
$oDoc->DocShowInOut=$addDocShowInOut;
                                                    
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                    
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                    
$oDoc->eDoc=$oDoc2->eDoc;
                                                    
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                    
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                    
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                    
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                    
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                    
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                    
$checkflagCommit $oDoc->Save();
                                                    
//echo "-----".$checkflagCommit."<br>";
                                                    
if(!$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                    
//echo "end<br>";
                                                    
$checkupdate++;
                                                    
                                                    
$oRs2->AddNew();
                                                    
$oRs2->DrsID=$oRs2->GetNextCode();
                                                    
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                    
$oRs2->DocID=$oDoc->DocID;
                                                    
$oRs2->DlcID=$pssend;
                                                    
$oRs2->DsID="0";
                                                    
$oRs2->PtID=$PtID;
                                                    
//echo "PtID2=".$oRs2->PtID."<br>";
                                                    
$oRs2->DrsReceiveDate=$timesend;
                                                    
$oRs2->DrsReceivePersonId='';
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                    
$oRs2->DrsDocDueDate=$speedDate;
                                                    
//echo "speedDate2=".$speedDate."<br>";
                                                    
$oRs2->DrsDlcIDCreate=$DlcID;
                                                    
$oRs2->DrsPsIDCreate=$personId;
                                                    
$oRs2->DrsPropose=$DrsSend;
                                                    
$oRs2->DrsSign="";
                                                    
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                    
$oRs2->DocGroup=$MaxDocGroup;
                                                    
$oRs2->AnID=$AnID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                        
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                        
                                                    }
                                                    if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$pssend && $mainDepts!=''){
                                                        
$oRs2->DrsMainDept='Y';
                                                    }else{
                                                        
$oRs2->DrsMainDept='';
                                                    }
                                                    
$checkflagCommit $oRs2->Save();
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                            }
                                        } 
//not send to my deptId    
                                    ///-----------my child
                                            //-----send to child deptId
                                            
if($oDPt2->deptId==$DlcdeptId){
                                                
$oDPt4->RSmenuByDeptParent2($oDPt2->deptId);
                                                while(
$oDPt4->GetRecord()){
                                                    
$pssend=ShowSendtoPs2($oDPt4->deptId); 
                                                    if(
$pssend!=''){
                                                        
//echo "send to child deptId =".$oDPt4->deptName." pssend=".$pssend." <br>";
                                                        //--------------add documents
                                                        
$oDoc->AddNew();
                                                        
$oDoc->DocID=$oDoc->GetNextCode();
                                                        
$oDoc->DocPID=$DocIDParent;
                                                        
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                        
$oDoc->DlcID=$pssend;   
                                                        
//echo "pssend=".$pssend."<br>";
                                                        
$oDoc->PtID=$PtID;
                                                        
//echo "PtID=".$oDoc->PtID."<br>";
                                                        
$oDoc->DtID=$oDoc2->DtID
                                                        
$oDoc->DslID=$oDoc2->DslID;
                                                        
$oDoc->DclID=$oDoc2->DclID;
                                                        
$oDoc->DsID="0";
                                                        
$oDoc->RsID="3"//sendin
                                                        
$oDoc->DocDateCreate=$timesend;
                                                        
$DocDateCreate=$oDoc->DocDateCreate;
                                                        
$oDoc->DocUserCreate=$pssend;
                                                        
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                        //echo "DocTypeNo=".$DocTypeNo."<br>";
                                                        
$oDoc->DocDate=$oDoc2->DocDate;
                                                        
$oDoc->DocNo=$oDoc2->DocNo;
                                                        
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                        
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                        
$oDoc->DocTo=$oDoc2->DocTo;
                                                        
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                        if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                        
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                        
//echo "speedDate=".$speedDate."<br>";
                                                        
$oDoc->DocStart=$oDoc2->DocStart;
                                                        
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                        
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                        
$oDoc->DocRef=$oDoc2->DocRef;
                                                        
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                        
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                        
$oDoc->DocOther=$oDoc2->DocOther;
                                                        
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                        
$oDoc->fDelete=$oDoc2->fDelete;
                                                        
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                        
$oDoc->AnID=$AnID;
                                                        
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                        
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                        if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                            
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                            
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                        }else{
                                                            
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                            
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                            
                                                        }
                                                        
                                                            if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                                
$addDocShowInOut="3";
                                                            }else{
                                                                if(
$DocShowIn=="1"){
                                                                    
$addDocShowInOut=$DocShowIn;
                                                                }else if(
$DocShowOut=="2"){
                                                                    
$addDocShowInOut=$DocShowOut;
                                                                }
                                                            }
                                                        
                                                        
$oDoc->DocShowInOut=$addDocShowInOut;
                                                        
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                        
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                        
$oDoc->eDoc=$oDoc2->eDoc;
                                                        
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                        
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                        
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                        
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                        
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                        
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                        
$checkflagCommit $oDoc->Save();
                                                        
//echo "-----".$checkflagCommit."<br>";
                                                        
if(!$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                        
//echo "end<br>";
                                                        
$checkupdate++;
                                                        
                                                        
$oRs2->AddNew();
                                                        
$oRs2->DrsID=$oRs2->GetNextCode();
                                                        
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                        
$oRs2->DocID=$oDoc->DocID;
                                                        
$oRs2->DlcID=$pssend;
                                                        
$oRs2->DsID="0";
                                                        
$oRs2->PtID=$PtID;
                                                        
//echo "PtID2=".$oRs2->PtID."<br>";
                                                        
$oRs2->DrsReceiveDate=$timesend;
                                                        
$oRs2->DrsReceivePersonId='';
                                                        if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                        
$oRs2->DrsDocDueDate=$speedDate;
                                                        
//echo "speedDate2=".$speedDate."<br>";
                                                        
$oRs2->DrsDlcIDCreate=$DlcID;
                                                        
$oRs2->DrsPsIDCreate=$personId;
                                                        
$oRs2->DrsPropose=$DrsSend;
                                                        
$oRs2->DrsSign="";
                                                        
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                        
$oRs2->DocGroup=$MaxDocGroup;
                                                        
$oRs2->AnID=$AnID;
                                                        if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                            
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                            
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                        }else{
                                                            
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                            
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                            
                                                        }
                                                        if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$pssend && $mainDepts!=''){
                                                            
$oRs2->DrsMainDept='Y';
                                                        }else{
                                                            
$oRs2->DrsMainDept='';
                                                        }
                                                        
$checkflagCommit $oRs2->Save();
                                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                    }
                                                }
                                            }
                                        
///-----------end my child                        
                                    
}
                                }else{  
                                
//---send to not deptParentId = 0------------------------
                                    //------send to parent dept----------------------
                                    
$oDPt2->SearchByKey($oDPt->deptParentId);
                                    
$oDPt2->GetRecord();
                                            
$pssend=ShowSendtoPs2($oDPt2->deptId); 
                                            if(
$pssend!=''){
                                             
//echo "send to parent dept=".$oDPt2->deptName." pssend=".$pssend." <br>";
                                                /////////////////////
                                                    
$oDoc->AddNew();
                                                    
$oDoc->DocID=$oDoc->GetNextCode();
                                                    
$oDoc->DocPID=$DocIDParent;
                                                    
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                    
$oDoc->DlcID=$pssend;   
                                                    
//echo "pssend=".$pssend."<br>";
                                                    
$oDoc->PtID=$PtID;
                                                    
//echo "PtID=".$oDoc->PtID."<br>";
                                                    
$oDoc->DtID=$oDoc2->DtID
                                                    
$oDoc->DslID=$oDoc2->DslID;
                                                    
$oDoc->DclID=$oDoc2->DclID;
                                                    
$oDoc->DsID="0";
                                                    
$oDoc->RsID="3"//sendin
                                                    
$oDoc->DocDateCreate=$timesend;
                                                    
$DocDateCreate=$oDoc->DocDateCreate;
                                                    
$oDoc->DocUserCreate=$pssend;
                                                    
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                    //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                    //echo "DocTypeNo=".$DocTypeNo."<br>";
                                                    
$oDoc->DocDate=$oDoc2->DocDate;
                                                    
$oDoc->DocNo=$oDoc2->DocNo;
                                                    
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                    
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                    
$oDoc->DocTo=$oDoc2->DocTo;
                                                    
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                    
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                    
//echo "speedDate=".$speedDate."<br>";
                                                    
$oDoc->DocStart=$oDoc2->DocStart;
                                                    
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                    
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                    
$oDoc->DocRef=$oDoc2->DocRef;
                                                    
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                    
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                    
$oDoc->DocOther=$oDoc2->DocOther;
                                                    
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                    
$oDoc->fDelete=$oDoc2->fDelete;
                                                    
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                    
$oDoc->AnID=$AnID;
                                                    
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                    
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                        
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                        
                                                    }
                                                    
                                                        if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                            
$addDocShowInOut="3";
                                                        }else{
                                                            if(
$DocShowIn=="1"){
                                                                
$addDocShowInOut=$DocShowIn;
                                                            }else if(
$DocShowOut=="2"){
                                                                
$addDocShowInOut=$DocShowOut;
                                                            }
                                                        }
                                                    
                                                    
$oDoc->DocShowInOut=$addDocShowInOut;
                                                    
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                    
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                    
$oDoc->eDoc=$oDoc2->eDoc;
                                                    
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                    
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                    
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                    
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                    
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                    
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                    
$checkflagCommit $oDoc->Save();
                                                    
//echo "-----".$checkflagCommit."<br>";
                                                    
if(!$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                    
//echo "end<br>";
                                                    
$checkupdate++;
                                                    
                                                    
$oRs2->AddNew();
                                                    
$oRs2->DrsID=$oRs2->GetNextCode();
                                                    
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                    
$oRs2->DocID=$oDoc->DocID;
                                                    
$oRs2->DlcID=$pssend;
                                                    
$oRs2->DsID="0";
                                                    
$oRs2->PtID=$PtID;
                                                    
//echo "PtID2=".$oRs2->PtID."<br>";
                                                    
$oRs2->DrsReceiveDate=$timesend;
                                                    
$oRs2->DrsReceivePersonId='';
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                    
$oRs2->DrsDocDueDate=$speedDate;
                                                    
//echo "speedDate2=".$speedDate."<br>";
                                                    
$oRs2->DrsDlcIDCreate=$DlcID;
                                                    
$oRs2->DrsPsIDCreate=$personId;
                                                    
$oRs2->DrsPropose=$DrsSend;
                                                    
$oRs2->DrsSign="";
                                                    
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                    
$oRs2->DocGroup=$MaxDocGroup;
                                                    
$oRs2->AnID=$AnID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                        
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                        
                                                    }
                                                    if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$pssend && $mainDepts!=''){
                                                        
$oRs2->DrsMainDept='Y';
                                                    }else{
                                                        
$oRs2->DrsMainDept='';
                                                    }
                                                    
$checkflagCommit $oRs2->Save();
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                             } 
                                    
                                    
//------send to balance dept----------------------
                                    
$oDPt3->RSmenuByDeptParent2($oDPt2->deptId);
                                    while(
$oDPt3->GetRecord()){
                                        if(
$oDPt3->deptId!=$DlcdeptId){
                                            
$pssend=ShowSendtoPs2($oDPt3->deptId); 
                                            if(
$pssend!=''){
                                             
//echo "send to balance dept=".$oDPt3->deptName." pssend=".$pssend." <br>";
                                                /////////////////////
                                                    
$oDoc->AddNew();
                                                    
$oDoc->DocID=$oDoc->GetNextCode();
                                                    
$oDoc->DocPID=$DocIDParent;
                                                    
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                    
$oDoc->DlcID=$pssend;   
                                                    
//echo "pssend=".$pssend."<br>";
                                                    
$oDoc->PtID=$PtID;
                                                    
//echo "PtID=".$oDoc->PtID."<br>";
                                                    
$oDoc->DtID=$oDoc2->DtID
                                                    
$oDoc->DslID=$oDoc2->DslID;
                                                    
$oDoc->DclID=$oDoc2->DclID;
                                                    
$oDoc->DsID="0";
                                                    
$oDoc->RsID="3"//sendin
                                                    
$oDoc->DocDateCreate=$timesend;
                                                    
$DocDateCreate=$oDoc->DocDateCreate;
                                                    
$oDoc->DocUserCreate=$pssend;
                                                    
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                    //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                    
$oDoc->DocTypeNo=$oDoc->DocTypeNo;
                                                    
//echo "DocTypeNo=".$DocTypeNo."<br>";
                                                    
$oDoc->DocDate=$oDoc2->DocDate;
                                                    
$oDoc->DocNo=$oDoc2->DocNo;
                                                    
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                    
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                    
$oDoc->DocTo=$oDoc2->DocTo;
                                                    
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                    
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                    
//echo "speedDate=".$speedDate."<br>";
                                                    
$oDoc->DocStart=$oDoc2->DocStart;
                                                    
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                    
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                    
$oDoc->DocRef=$oDoc2->DocRef;
                                                    
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                    
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                    
$oDoc->DocOther=$oDoc2->DocOther;
                                                    
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                    
$oDoc->fDelete=$oDoc2->fDelete;
                                                    
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                    
$oDoc->AnID=$AnID;
                                                    
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                    
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                        
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                        
                                                    }
                                                
                                                        if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                            
$addDocShowInOut="3";
                                                        }else{
                                                            if(
$DocShowIn=="1"){
                                                                
$addDocShowInOut=$DocShowIn;
                                                            }else if(
$DocShowOut=="2"){
                                                                
$addDocShowInOut=$DocShowOut;
                                                            }
                                                        }
                                                    
                                                    
$oDoc->DocShowInOut=$addDocShowInOut;
                                                    
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                    
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                    
$oDoc->eDoc=$oDoc2->eDoc;
                                                    
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                    
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                    
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                    
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                    
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                    
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                    
$checkflagCommit $oDoc->Save();
                                                    
//echo "-----".$checkflagCommit."<br>";
                                                    
if(!$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                    
//echo "end<br>";
                                                    
$checkupdate++;
                                                    
                                                    
$oRs2->AddNew();
                                                    
$oRs2->DrsID=$oRs2->GetNextCode();
                                                    
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                    
$oRs2->DocID=$oDoc->DocID;
                                                    
$oRs2->DlcID=$pssend;
                                                    
$oRs2->DsID="0";
                                                    
$oRs2->PtID=$PtID;
                                                    
//echo "PtID2=".$oRs2->PtID."<br>";
                                                    
$oRs2->DrsReceiveDate=$timesend;
                                                    
$oRs2->DrsReceivePersonId='';
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                    
$oRs2->DrsDocDueDate=$speedDate;
                                                    
//echo "speedDate2=".$speedDate."<br>";
                                                    
$oRs2->DrsDlcIDCreate=$DlcID;
                                                    
$oRs2->DrsPsIDCreate=$personId;
                                                    
$oRs2->DrsPropose=$DrsSend;
                                                    
$oRs2->DrsSign="";
                                                    
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                    
$oRs2->DocGroup=$MaxDocGroup;
                                                    
$oRs2->AnID=$AnID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                        
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                        
                                                    }
                                                    if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$pssend && $mainDepts!=''){
                                                        
$oRs2->DrsMainDept='Y';
                                                    }else{
                                                        
$oRs2->DrsMainDept='';
                                                    }
                                                    
$checkflagCommit $oRs2->Save();
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                             } 
                                        }    
                                            
//------send to child dept----------------------
                                            
if($oDPt3->deptId==$oDPt->deptId){
                                                
$oDPt4->RSmenuByDeptParent2($oDPt3->deptId);
                                                while(
$oDPt4->GetRecord()){
                                                        
$pssend=ShowSendtoPs2($oDPt4->deptId); 
                                                        if(
$pssend!=''){
                                                        
// echo "send to child dept=".$oDPt4->deptName." pssend=".$pssend." <br>";
                                                            /////////////////////
                                                                
$oDoc->AddNew();
                                                                
$oDoc->DocID=$oDoc->GetNextCode();
                                                                
$oDoc->DocPID=$DocIDParent;
                                                                
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                                
$oDoc->DlcID=$pssend;   
                                                                
//echo "pssend=".$pssend."<br>";
                                                                
$oDoc->PtID=$PtID;
                                                                
//echo "PtID=".$oDoc->PtID."<br>";
                                                                
$oDoc->DtID=$oDoc2->DtID
                                                                
$oDoc->DslID=$oDoc2->DslID;
                                                                
$oDoc->DclID=$oDoc2->DclID;
                                                                
$oDoc->DsID="0";
                                                                
$oDoc->RsID="3"//sendin
                                                                
$oDoc->DocDateCreate=$timesend;
                                                                
$DocDateCreate=$oDoc->DocDateCreate;
                                                                
$oDoc->DocUserCreate=$pssend;
                                                                
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                                //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                                //echo "DocTypeNo=".$DocTypeNo."<br>";
                                                                
$oDoc->DocDate=$oDoc2->DocDate;
                                                                
$oDoc->DocNo=$oDoc2->DocNo;
                                                                
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                                
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                                
$oDoc->DocTo=$oDoc2->DocTo;
                                                                
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                                if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                                
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                                
//echo "speedDate=".$speedDate."<br>";
                                                                
$oDoc->DocStart=$oDoc2->DocStart;
                                                                
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                                
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                                
$oDoc->DocRef=$oDoc2->DocRef;
                                                                
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                                
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                                
$oDoc->DocOther=$oDoc2->DocOther;
                                                                
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                                
$oDoc->fDelete=$oDoc2->fDelete;
                                                                
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                                
$oDoc->AnID=$AnID;
                                                                
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                                
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                                if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                                    
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                                    
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                                }else{
                                                                    
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                                    
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                                    
                                                                }
                                                                
                                                                    if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                                        
$addDocShowInOut="3";
                                                                    }else{
                                                                        if(
$DocShowIn=="1"){
                                                                            
$addDocShowInOut=$DocShowIn;
                                                                        }else if(
$DocShowOut=="2"){
                                                                            
$addDocShowInOut=$DocShowOut;
                                                                        }
                                                                    }
                                                                
                                                                
$oDoc->DocShowInOut=$addDocShowInOut;
                                                                
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                                
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                                
$oDoc->eDoc=$oDoc2->eDoc;
                                                                
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                                
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                                
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                                
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                                
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                                
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                                
$checkflagCommit $oDoc->Save();
                                                                
//echo "-----".$checkflagCommit."<br>";
                                                                
if(!$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                                
//echo "end<br>";
                                                                
$checkupdate++;
                                                                
                                                                
$oRs2->AddNew();
                                                                
$oRs2->DrsID=$oRs2->GetNextCode();
                                                                
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                                
$oRs2->DocID=$oDoc->DocID;
                                                                
$oRs2->DlcID=$pssend;
                                                                
$oRs2->DsID="0";
                                                                
$oRs2->PtID=$PtID;
                                                                
//echo "PtID2=".$oRs2->PtID."<br>";
                                                                
$oRs2->DrsReceiveDate=$timesend;
                                                                
$oRs2->DrsReceivePersonId='';
                                                                if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                                
$oRs2->DrsDocDueDate=$speedDate;
                                                                
//echo "speedDate2=".$speedDate."<br>";
                                                                
$oRs2->DrsDlcIDCreate=$DlcID;
                                                                
$oRs2->DrsPsIDCreate=$personId;
                                                                
$oRs2->DrsPropose=$DrsSend;
                                                                
$oRs2->DrsSign="";
                                                                
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                                
$oRs2->DocGroup=$MaxDocGroup;
                                                                
$oRs2->AnID=$AnID;
                                                                if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                                    
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                                    
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                                }else{
                                                                    
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                                    
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                                    
                                                                }
                                                                if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$pssend && $mainDepts!=''){
                                                                    
$oRs2->DrsMainDept='Y';
                                                                }else{
                                                                    
$oRs2->DrsMainDept='';
                                                                }
                                                                
$checkflagCommit $oRs2->Save();
                                                                if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                         } 
                                                }
                                            }
                                    }            
                                }
                            }else{ 
//--maindept=1
                            
                                
$oDPt2->RSDeptByMaxdeptDate2();
                                while(
$oDPt2->GetRecord()){
                                    for(
$i=0;$i<count();$i++){
                                        if(
$deptPs[$i]==$oDPt2->deptId){
                                            if(
$deptPs[$i]!=""){
                                                    
                                                        
$oDoc->AddNew();
                                                        
$oDoc->DocID=$oDoc->GetNextCode();
                                                        
$oDoc->DocPID=$DocIDParent;
                                                        
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                        
$oDoc->DlcID=$deptPs[$i];
                                                        
//echo "DlcID=".$oDoc->DlcID."<br>";
                                                        
$oDoc->PtID=$PtID;
                                                        
//echo "PtID=".$oDoc->PtID."<br>";
                                                        
$oDoc->DtID=$oDoc2->DtID
                                                        
$oDoc->DslID=$oDoc2->DslID;
                                                        
$oDoc->DclID=$oDoc2->DclID;
                                                        
$oDoc->DsID="0";
                                                        
$oDoc->RsID="3"//sendin
                                                        
$oDoc->DocDateCreate=$timesend;
                                                        
$DocDateCreate=$oDoc->DocDateCreate;
                                                        
$oDoc->DocUserCreate=$deptPssend[$oDPt2->deptId];
                                                        
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                        //echo "DocTypeNo=".$DocTypeNo."<br>";
                                                        
$oDoc->DocDate=$oDoc2->DocDate;
                                                        
$oDoc->DocNo=$oDoc2->DocNo;
                                                        
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                        
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                        
$oDoc->DocTo=$oDoc2->DocTo;
                                                        
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                        if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                        
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                        
//echo "speedDate=".$speedDate."<br>";
                                                        
$oDoc->DocStart=$oDoc2->DocStart;
                                                        
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                        
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                        
$oDoc->DocRef=$oDoc2->DocRef;
                                                        
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                        
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                        
$oDoc->DocOther=$oDoc2->DocOther;
                                                        
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                        
$oDoc->fDelete=$oDoc2->fDelete;
                                                        
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                        
$oDoc->AnID=$AnID;
                                                        
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                        
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                        if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                            
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                            
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                        }else{
                                                            
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                            
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                            
                                                        }
                                
                                                            if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                                
$addDocShowInOut="3";
                                                            }else{
                                                                if(
$DocShowIn=="1"){
                                                                    
$addDocShowInOut=$DocShowIn;
                                                                }else if(
$DocShowOut=="2"){
                                                                    
$addDocShowInOut=$DocShowOut;
                                                                }
                                                            }
                                
                                                        
                                                        
$oDoc->DocShowInOut=$addDocShowInOut;
                                                        
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                        
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                        
$oDoc->eDoc=$oDoc2->eDoc;
                                                        
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                        
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                        
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                        
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                        
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                        
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                        
$checkflagCommit $oDoc->Save();
                                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                        
//echo "end<br>";
                                                        
$checkupdate++;
                                                        
                                                        
$oRs2->AddNew();
                                                        
$oRs2->DrsID=$oRs2->GetNextCode();
                                                        
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                        
$oRs2->DocID=$oDoc->DocID;
                                                        
$oRs2->DlcID=$deptPs[$i];
                                                        
$oRs2->DsID="0";
                                                        
$oRs2->PtID=$PtID;
                                                        
//echo "PtID2=".$oRs2->PtID."<br>";
                                                        
$oRs2->DrsReceiveDate=$timesend;
                                                        
$oRs2->DrsReceivePersonId='';
                                                        if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                        
$oRs2->DrsDocDueDate=$speedDate;
                                                        
//echo "speedDate2=".$speedDate."<br>";
                                                        
$oRs2->DrsDlcIDCreate=$DlcID;
                                                        
$oRs2->DrsPsIDCreate=$personId;
                                                        
$oRs2->DrsPropose=$DrsSend;
                                                        
$oRs2->DrsSign="";
                                                        
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                        
$oRs2->DocGroup=$MaxDocGroup;
                                                        
$oRs2->AnID=$AnID;
                                                        if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                            
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                            
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                        }else{
                                                            
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                            
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                            
                                                        }
                                                        if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$deptPs[$oDPt2->deptId] && $mainDepts!=''){
                                                            
$oRs2->DrsMainDept='Y';
                                                        }else{
                                                            
$oRs2->DrsMainDept='';
                                                        }
                                                        
$checkflagCommit $oRs2->Save();
                                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                            }
                                        }
                                    }
                                } 
//loop dept
                            
}
                                
                        }else{
                
//----not send All deptId----------------------------------------------------------------
                        //--case not maindept
                        
                        
$maindept 1;
                        if(
$maindept!=1){
                            
                                
$oDPt->SearchByKey($DlcdeptId);
                                
$oDPt->GetRecord();
                                
                                
//---send to deptParentId=0------------------------
                                
if($oDPt->deptParentId==0){
                                    
$oDPt2->RSmenuByDeptParent2($oDPt->deptParentId);
                                    while(
$oDPt2->GetRecord()){
                                            if(
$deptPs[$oDPt2->deptId]!=""){
                                                
//echo "send to deptParentId=0 =".$oDPt2->deptName." pssend=".$deptPs[$oDPt2->deptId]." <br>";
                                                    //--------------add documents
                                                    
$oDoc->AddNew();
                                                    
$oDoc->DocID=$oDoc->GetNextCode();
                                                    
$oDoc->DocPID=$DocIDParent;
                                                    
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                    
$oDoc->DlcID=$deptPs[$oDPt2->deptId];
                                                    
//echo "DlcID=".$oDoc->DlcID."<br>";
                                                    
$oDoc->PtID=$PtID;
                                                    
//echo "PtID=".$oDoc->PtID."<br>";
                                                    
$oDoc->DtID=$oDoc2->DtID
                                                    
$oDoc->DslID=$oDoc2->DslID;
                                                    
$oDoc->DclID=$oDoc2->DclID;
                                                    
$oDoc->DsID="0";
                                                    
$oDoc->RsID="3"//sendin
                                                    
$oDoc->DocDateCreate=$timesend;
                                                    
$DocDateCreate=$oDoc->DocDateCreate;
                                                    
$oDoc->DocUserCreate=$deptPssend[$oDPt2->deptId];
                                                    
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                    //echo "DocTypeNo=".$DocTypeNo."<br>";
                                                    
$oDoc->DocDate=$oDoc2->DocDate;
                                                    
$oDoc->DocNo=$oDoc2->DocNo;
                                                    
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                    
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                    
$oDoc->DocTo=$oDoc2->DocTo;
                                                    
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                    
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                    
//echo "speedDate=".$speedDate."<br>";
                                                    
$oDoc->DocStart=$oDoc2->DocStart;
                                                    
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                    
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                    
$oDoc->DocRef=$oDoc2->DocRef;
                                                    
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                    
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                    
$oDoc->DocOther=$oDoc2->DocOther;
                                                    
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                    
$oDoc->fDelete=$oDoc2->fDelete;
                                                    
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                    
$oDoc->AnID=$AnID;
                                                    
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                    
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                        
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                        
                                                    }
                            
                                                        if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                            
$addDocShowInOut="3";
                                                        }else{
                                                            if(
$DocShowIn=="1"){
                                                                
$addDocShowInOut=$DocShowIn;
                                                            }else if(
$DocShowOut=="2"){
                                                                
$addDocShowInOut=$DocShowOut;
                                                            }
                                                        }
                            
                                                    
                                                    
$oDoc->DocShowInOut=$addDocShowInOut;
                                                    
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                    
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                    
$oDoc->eDoc=$oDoc2->eDoc;
                                                    
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                    
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                    
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                    
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                    
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                    
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                    
$checkflagCommit $oDoc->Save();
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                    
//echo "end<br>";
                                                    
$checkupdate++;
                                                    
                                                    
$oRs2->AddNew();
                                                    
$oRs2->DrsID=$oRs2->GetNextCode();
                                                    
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                    
$oRs2->DocID=$oDoc->DocID;
                                                    
$oRs2->DlcID=$deptPs[$oDPt2->deptId];
                                                    
$oRs2->DsID="0";
                                                    
$oRs2->PtID=$PtID;
                                                    
//echo "PtID2=".$oRs2->PtID."<br>";
                                                    
$oRs2->DrsReceiveDate=$timesend;
                                                    
$oRs2->DrsReceivePersonId='';
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                    
$oRs2->DrsDocDueDate=$speedDate;
                                                    
//echo "speedDate2=".$speedDate."<br>";
                                                    
$oRs2->DrsDlcIDCreate=$DlcID;
                                                    
$oRs2->DrsPsIDCreate=$personId;
                                                    
$oRs2->DrsPropose=$DrsSend;
                                                    
$oRs2->DrsSign="";
                                                    
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                    
$oRs2->DocGroup=$MaxDocGroup;
                                                    
$oRs2->AnID=$AnID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                        
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                        
                                                    }
                                                    if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$deptPs[$oDPt2->deptId] && $mainDepts!=''){
                                                        
$oRs2->DrsMainDept='Y';
                                                    }else{
                                                            
$oRs2->DrsMainDept='';
                                                    }
                                                    
$checkflagCommit $oRs2->Save();
                                                
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                            }
                                                                    
                                            
                                    
                                    
                                    
///-----------my child
                                            //-----send to child deptId
                                            //------send to child dept----------------------
                                            
if($oDPt2->deptId==$oDPt->deptId){
                                                
$oDPt4->RSmenuByDeptParent2($oDPt2->deptId);
                                                while(
$oDPt4->GetRecord()){
                                                        
$pssend=ShowSendtoPs2($oDPt4->deptId); 
                                                        if(
$deptPs[$oDPt4->deptId]!=""){
                                                            
//echo "send to deptParentId=0 =".$oDPt2->deptName." pssend=".$deptPs[$oDPt2->deptId]." <br>";
                                                                //--------------add documents
                                                                
$oDoc->AddNew();
                                                                
$oDoc->DocID=$oDoc->GetNextCode();
                                                                
$oDoc->DocPID=$DocIDParent;
                                                                
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                                
$oDoc->DlcID=$deptPs[$oDPt4->deptId];
                                                                
//echo "DlcID=".$oDoc->DlcID."<br>";
                                                                
$oDoc->PtID=$PtID;
                                                                
//echo "PtID=".$oDoc->PtID."<br>";
                                                                
$oDoc->DtID=$oDoc2->DtID
                                                                
$oDoc->DslID=$oDoc2->DslID;
                                                                
$oDoc->DclID=$oDoc2->DclID;
                                                                
$oDoc->DsID="0";
                                                                
$oDoc->RsID="3"//sendin
                                                                
$oDoc->DocDateCreate=$timesend;
                                                                
$DocDateCreate=$oDoc->DocDateCreate;
                                                                
$oDoc->DocUserCreate=$deptPssend[$oDPt4->deptId];
                                                                
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                                //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                                //echo "DocTypeNo=".$DocTypeNo."<br>";
                                                                
$oDoc->DocDate=$oDoc2->DocDate;
                                                                
$oDoc->DocNo=$oDoc2->DocNo;
                                                                
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                                
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                                
$oDoc->DocTo=$oDoc2->DocTo;
                                                                
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                                if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                                
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                                
//echo "speedDate=".$speedDate."<br>";
                                                                
$oDoc->DocStart=$oDoc2->DocStart;
                                                                
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                                
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                                
$oDoc->DocRef=$oDoc2->DocRef;
                                                                
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                                
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                                
$oDoc->DocOther=$oDoc2->DocOther;
                                                                
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                                
$oDoc->fDelete=$oDoc2->fDelete;
                                                                
$oDoc->endDoc=$oDoc->endDoc;
                                                                
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                                
$oDoc->AnID=$AnID;
                                                                
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                                
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                                if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                                    
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                                    
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                                }else{
                                                                    
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                                    
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                                    
                                                                }
                                        
                                                                    if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                                        
$addDocShowInOut="3";
                                                                    }else{
                                                                        if(
$DocShowIn=="1"){
                                                                            
$addDocShowInOut=$DocShowIn;
                                                                        }else if(
$DocShowOut=="2"){
                                                                            
$addDocShowInOut=$DocShowOut;
                                                                        }
                                                                    }
                                        
                                                                
                                                                
$oDoc->DocShowInOut=$addDocShowInOut;
                                                                
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                                
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                                
$oDoc->eDoc=$oDoc2->eDoc;
                                                                
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                                
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                                
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                                
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                                
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                                
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                                
$checkflagCommit $oDoc->Save();
                                                                if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                                
//echo "end<br>";
                                                                
$checkupdate++;
                                                                
                                                                
$oRs2->AddNew();
                                                                
$oRs2->DrsID=$oRs2->GetNextCode();
                                                                
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                                
$oRs2->DocID=$oDoc->DocID;
                                                                
$oRs2->DlcID=$deptPs[$oDPt4->deptId];
                                                                
$oRs2->DsID="0";
                                                                
$oRs2->PtID=$PtID;
                                                                
//echo "PtID2=".$oRs2->PtID."<br>";
                                                                
$oRs2->DrsReceiveDate=$timesend;
                                                                
$oRs2->DrsReceivePersonId='';
                                                                if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                                
$oRs2->DrsDocDueDate=$speedDate;
                                                                
//echo "speedDate2=".$speedDate."<br>";
                                                                
$oRs2->DrsDlcIDCreate=$DlcID;
                                                                
$oRs2->DrsPsIDCreate=$personId;
                                                                
$oRs2->DrsPropose=$DrsSend;
                                                                
$oRs2->DrsSign="";
                                                                
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                                
$oRs2->DocGroup=$MaxDocGroup;
                                                                
$oRs2->AnID=$AnID;
                                                                if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                                    
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                                    
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                                }else{
                                                                    
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                                    
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                                    
                                                                }
                                                                if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$deptPs[$oDPt4->deptId] && $mainDepts!=''){
                                                                    
$oRs2->DrsMainDept='Y';
                                                                }else{
                                                                    
$oRs2->DrsMainDept='';
                                                                }
                                                                
$checkflagCommit $oRs2->Save();
                                                                
                                                                if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                         } 
                                                }
                                            }
                
                                    
                                    }                    
                                }else{  
                                
//---send to not deptParentId = 0------------------------
                                    //------send to parent dept----------------------
                                    
$oDPt2->SearchByKey($oDPt->deptParentId);
                                    
$oDPt2->GetRecord();
                                    if(
$deptPs[$oDPt2->deptId]!=""){
                                        
//echo "send to parent dept =".$oDPt2->deptName." pssend=".$deptPs[$oDPt2->deptId]." <br>";
                                            //--------------add documents
                                            
$oDoc->AddNew();
                                            
$oDoc->DocID=$oDoc->GetNextCode();
                                            
$oDoc->DocPID=$DocIDParent;
                                            
//echo "DocPID=".$oDoc->DocPID."<br>";
                                            
$oDoc->DlcID=$deptPs[$oDPt2->deptId];
                                            
//echo "DlcID=".$oDoc->DlcID."<br>";
                                            
$oDoc->PtID=$PtID;
                                            
//echo "PtID=".$oDoc->PtID."<br>";
                                            
$oDoc->DtID=$oDoc2->DtID
                                            
$oDoc->DslID=$oDoc2->DslID;
                                            
$oDoc->DclID=$oDoc2->DclID;
                                            
$oDoc->DsID="0";
                                            
$oDoc->RsID="3"//sendin
                                            
$oDoc->DocDateCreate=$timesend;
                                            
$DocDateCreate=$oDoc->DocDateCreate;
                                            
$oDoc->DocUserCreate=$deptPssend[$oDPt2->deptId];
                                            
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                            //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                            
$oDoc->DocTypeNo=$oDoc->DocTypeNo;
                                            
//echo "DocTypeNo=".$DocTypeNo."<br>";
                                            
$oDoc->DocDate=$oDoc2->DocDate;
                                            
$oDoc->DocNo=$oDoc2->DocNo;
                                            
$oDoc->DocSubject=$oDoc2->DocSubject;
                                            
$oDoc->DocFrom=$oDoc2->DocFrom;
                                            
$oDoc->DocTo=$oDoc2->DocTo;
                                            
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                            if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                            
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                            
//echo "speedDate=".$speedDate."<br>";
                                            
$oDoc->DocStart=$oDoc2->DocStart;
                                            
$oDoc->DocFinish=$oDoc2->DocFinish;
                                            
$oDoc->DocGroup=$oDoc2->DocGroup;
                                            
$oDoc->DocRef=$oDoc2->DocRef;
                                            
$oDoc->DocCircular=$oDoc2->DocCircular;
                                            
$oDoc->DocfCir=$oDoc2->DocfCir;
                                            
$oDoc->DocOther=$oDoc2->DocOther;
                                            
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                            
$oDoc->fDelete=$oDoc2->fDelete;
                                            
$oDoc->endDoc=$oDoc->endDoc;
                                            
$oDoc->sendToPs=$oDoc2->sendToPs;
                                            
$oDoc->AnID=$AnID;
                                            
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                            
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                            if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                            }else{
                                                
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                
                                            }
                                            
$oDoc->DocMainPost=$oDoc->DocMainPost;
                                            
$oDoc->DocGetPost=$oDoc->DocGetPost;
                                            
                    
                                                if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                    
$addDocShowInOut="3";
                                                }else{
                                                    if(
$DocShowIn=="1"){
                                                        
$addDocShowInOut=$DocShowIn;
                                                    }else if(
$DocShowOut=="2"){
                                                        
$addDocShowInOut=$DocShowOut;
                                                    }
                                                }
                    
                                            
                                            
$oDoc->DocShowInOut=$addDocShowInOut;
                                            
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                            
$oDoc->DocforSign=$oDoc2->DocforSign;
                                            
$oDoc->eDoc=$oDoc2->eDoc;
                                            
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                            
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                            
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                            
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                            
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                            
$oDoc->DocContactE=$oDoc2->DocContactE;
                                            
$checkflagCommit $oDoc->Save();
                                            if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                            
//echo "end<br>";
                                            
$checkupdate++;
                                            
                                            
$oRs2->AddNew();
                                            
$oRs2->DrsID=$oRs2->GetNextCode();
                                            
//echo "DrsID=".$oRs2->DrsID."<br>";
                                            
$oRs2->DocID=$oDoc->DocID;
                                            
$oRs2->DlcID=$deptPs[$oDPt2->deptId];
                                            
$oRs2->DsID="0";
                                            
$oRs2->PtID=$PtID;
                                            
//echo "PtID2=".$oRs2->PtID."<br>";
                                            
$oRs2->DrsReceiveDate=$timesend;
                                            
$oRs2->DrsReceivePersonId='';
                                            if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                            
$oRs2->DrsDocDueDate=$speedDate;
                                            
//echo "speedDate2=".$speedDate."<br>";
                                            
$oRs2->DrsDlcIDCreate=$DlcID;
                                            
$oRs2->DrsPsIDCreate=$personId;
                                            
$oRs2->DrsPropose=$DrsSend;
                                            
$oRs2->DrsSign="";
                                            
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                            
$oRs2->DocGroup=$MaxDocGroup;
                                            
$oRs2->AnID=$AnID;
                                            if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                            }else{
                                                
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                
                                            }
                                            if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$deptPs[$oDPt2->deptId] && $mainDepts!=''){
                                                    
$oRs2->DrsMainDept='Y';
                                            }else{
                                                        
$oRs2->DrsMainDept='';
                                            }
                                            
$checkflagCommit $oRs2->Save();
                                        
                                            if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                    }                    
                                    
                                    
//------send to balance dept----------------------
                                    
$oDPt3->RSmenuByDeptParent2($oDPt2->deptId);
                                    while(
$oDPt3->GetRecord()){
                                            if(
$deptPs[$oDPt3->deptId]!=""){
                                                
//echo "send to balance dept =".$oDPt3->deptName." pssend=".$deptPs[$oDPt3->deptId]." <br>";
                                                    //--------------add documents
                                                    
$oDoc->AddNew();
                                                    
$oDoc->DocID=$oDoc->GetNextCode();
                                                    
$oDoc->DocPID=$DocIDParent;
                                                    
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                    
$oDoc->DlcID=$deptPs[$oDPt3->deptId];
                                                    
//echo "DlcID=".$oDoc->DlcID."<br>";
                                                    
$oDoc->PtID=$PtID;
                                                    
//echo "PtID=".$oDoc->PtID."<br>";
                                                    
$oDoc->DtID=$oDoc2->DtID
                                                    
$oDoc->DslID=$oDoc2->DslID;
                                                    
$oDoc->DclID=$oDoc2->DclID;
                                                    
$oDoc->DsID="0";
                                                    
$oDoc->RsID="3"//sendin
                                                    
$oDoc->DocDateCreate=$timesend;
                                                    
$DocDateCreate=$oDoc->DocDateCreate;
                                                    
$oDoc->DocUserCreate=$deptPssend[$oDPt3->deptId];
                                                    
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                    //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                    
$oDoc->DocTypeNo=$oDoc->DocTypeNo;
                                                    
//echo "DocTypeNo=".$DocTypeNo."<br>";
                                                    
$oDoc->DocDate=$oDoc2->DocDate;
                                                    
$oDoc->DocNo=$oDoc2->DocNo;
                                                    
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                    
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                    
$oDoc->DocTo=$oDoc2->DocTo;
                                                    
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                    
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                    
//echo "speedDate=".$speedDate."<br>";
                                                    
$oDoc->DocStart=$oDoc2->DocStart;
                                                    
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                    
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                    
$oDoc->DocRef=$oDoc2->DocRef;
                                                    
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                    
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                    
$oDoc->DocOther=$oDoc2->DocOther;
                                                    
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                    
$oDoc->fDelete=$oDoc2->fDelete;
                                                    
$oDoc->endDoc=$oDoc->endDoc;
                                                    
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                    
$oDoc->AnID=$AnID;
                                                    
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                    
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                        
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                        
                                                    }
                                                    
$oDoc->DocMainPost=$oDoc->DocMainPost;
                                                    
$oDoc->DocGetPost=$oDoc->DocGetPost;
                                                    
                            
                                                        if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                            
$addDocShowInOut="3";
                                                        }else{
                                                            if(
$DocShowIn=="1"){
                                                                
$addDocShowInOut=$DocShowIn;
                                                            }else if(
$DocShowOut=="2"){
                                                                
$addDocShowInOut=$DocShowOut;
                                                            }
                                                        }
                            
                                                    
                                                    
$oDoc->DocShowInOut=$addDocShowInOut;
                                                    
$oDoc->DocDateGetPost=$oDoc->DocDateGetPost;
                                                    
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                    
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                    
$oDoc->eDoc=$oDoc2->eDoc;
                                                    
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                    
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                    
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                    
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                    
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                    
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                    
$checkflagCommit $oDoc->Save();
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                    
//echo "end<br>";
                                                    
$checkupdate++;
                                                    
                                                    
$oRs2->AddNew();
                                                    
$oRs2->DrsID=$oRs2->GetNextCode();
                                                    
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                    
$oRs2->DocID=$oDoc->DocID;
                                                    
$oRs2->DlcID=$deptPs[$oDPt3->deptId];
                                                    
$oRs2->DsID="0";
                                                    
$oRs2->PtID=$PtID;
                                                    
//echo "PtID2=".$oRs2->PtID."<br>";
                                                    
$oRs2->DrsReceiveDate=$timesend;
                                                    
$oRs2->DrsReceivePersonId='';
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                    
$oRs2->DrsDocDueDate=$speedDate;
                                                    
//echo "speedDate2=".$speedDate."<br>";
                                                    
$oRs2->DrsDlcIDCreate=$DlcID;
                                                    
$oRs2->DrsPsIDCreate=$personId;
                                                    
$oRs2->DrsPropose=$DrsSend;
                                                    
$oRs2->DrsSign="";
                                                    
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                    
$oRs2->DocGroup=$MaxDocGroup;
                                                    
$oRs2->AnID=$AnID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                        
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                        
                                                    }
                                                    if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$deptPs[$oDPt3->deptId] && $mainDepts!=''){
                                                        
$oRs2->DrsMainDept='Y';
                                                    }else{
                                                        
$oRs2->DrsMainDept='';
                                                    }
                                                    
$checkflagCommit $oRs2->Save();
                                                    
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                            }
                                    
                                            
//-----send to child deptId
                                            
if($oDPt3->deptId==$oDPt->deptId){
                                                
$oDPt4->RSmenuByDeptParent2($oDPt3->deptId);
                                                while(
$oDPt4->GetRecord()){
                                                    if(
$deptPs[$oDPt4->deptId]!=""){
                                                        
//echo "send to child deptId =".$oDPt4->deptName." pssend=".$deptPs[$oDPt4->deptId]." <br>";
                                                        //--------------add documents
                                                        
$oDoc->AddNew();
                                                        
$oDoc->DocID=$oDoc->GetNextCode();
                                                        
$oDoc->DocPID=$DocIDParent;
                                                        
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                        
$oDoc->DlcID=$deptPs[$oDPt4->deptId];
                                                        
//echo "DlcID=".$oDoc->DlcID."<br>";
                                                        
$oDoc->PtID=$PtID;
                                                        
//echo "PtID=".$oDoc->PtID."<br>";
                                                        
$oDoc->DtID=$oDoc2->DtID
                                                        
$oDoc->DslID=$oDoc2->DslID;
                                                        
$oDoc->DclID=$oDoc2->DclID;
                                                        
$oDoc->DsID="0";
                                                        
$oDoc->RsID="3"//sendin
                                                        
$oDoc->DocDateCreate=$timesend;
                                                        
$DocDateCreate=$oDoc->DocDateCreate;
                                                        
$oDoc->DocUserCreate=$deptPssend[$oDPt4->deptId];
                                                        
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                        //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                        
$oDoc->DocTypeNo=$oDoc->DocTypeNo;
                                                        
//echo "DocTypeNo=".$DocTypeNo."<br>";
                                                        
$oDoc->DocDate=$oDoc2->DocDate;
                                                        
$oDoc->DocNo=$oDoc2->DocNo;
                                                        
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                        
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                        
$oDoc->DocTo=$oDoc2->DocTo;
                                                        
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                        if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                        
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                        
//echo "speedDate=".$speedDate."<br>";
                                                        
$oDoc->DocStart=$oDoc2->DocStart;
                                                        
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                        
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                        
$oDoc->DocRef=$oDoc2->DocRef;
                                                        
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                        
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                        
$oDoc->DocOther=$oDoc2->DocOther;
                                                        
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                        
$oDoc->fDelete=$oDoc2->fDelete;
                                                        
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                        
$oDoc->AnID=$AnID;
                                                        
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                        
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                        if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                            
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                            
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                        }else{
                                                            
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                            
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                            
                                                        }
                                
                                                            if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                                
$addDocShowInOut="3";
                                                            }else{
                                                                if(
$DocShowIn=="1"){
                                                                    
$addDocShowInOut=$DocShowIn;
                                                                }else if(
$DocShowOut=="2"){
                                                                    
$addDocShowInOut=$DocShowOut;
                                                                }
                                                            }
                                
                                                        
                                                        
$oDoc->DocShowInOut=$addDocShowInOut;
                                                        
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                        
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                        
$oDoc->eDoc=$oDoc2->eDoc;
                                                        
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                        
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                        
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                        
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                        
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                        
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                        
$checkflagCommit $oDoc->Save();
                                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                        
//echo "end<br>";
                                                        
$checkupdate++;
                                                        
                                                        
$oRs2->AddNew();
                                                        
$oRs2->DrsID=$oRs2->GetNextCode();
                                                        
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                        
$oRs2->DocID=$oDoc->DocID;
                                                        
$oRs2->DlcID=$deptPs[$oDPt4->deptId];
                                                        
$oRs2->DsID="0";
                                                        
$oRs2->PtID=$PtID;
                                                        
//echo "PtID2=".$oRs2->PtID."<br>";
                                                        
$oRs2->DrsReceiveDate=$timesend;
                                                        
$oRs2->DrsReceivePersonId='';
                                                        if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                        
$oRs2->DrsDocDueDate=$speedDate;
                                                        
//echo "speedDate2=".$speedDate."<br>";
                                                        
$oRs2->DrsDlcIDCreate=$DlcID;
                                                        
$oRs2->DrsPsIDCreate=$personId;
                                                        
$oRs2->DrsPropose=$DrsSend;
                                                        
$oRs2->DrsSign="";
                                                        
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                        
$oRs2->DocGroup=$MaxDocGroup;
                                                        
$oRs2->AnID=$AnID;
                                                        if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                            
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                            
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                        }else{
                                                            
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                            
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                            
                                                        }
                                                        if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$deptPs[$oDPt4->deptId] && $mainDepts!=''){
                                                            
$oRs2->DrsMainDept='Y';
                                                        }else{
                                                            
$oRs2->DrsMainDept='';
                                                        }
                                                        
$checkflagCommit $oRs2->Save();
                                                        
                                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                  }
                                                }
                                            }
                                    }            
                                }
                            }else{ 
//---case main dept
                                
$oDPt2->RSDeptByMaxdeptDate2();
                                
                                while(
$oDPt2->GetRecord()){
                                    
                                    for(
$i=0;$i<count($deptPs);$i++){
                                        if(
$deptPs[$i]!=""){
                                                
                                                    
$oDoc->AddNew();
                                                    
$oDoc->DocID=$oDoc->GetNextCode();
                                                    
$oDoc->DocPID=$DocIDParent;
                                                    
//echo "DocPID=".$oDoc->DocPID."<br>";
                                                    
$oDoc->DlcID=$deptPs[$i];
                                                    
//echo "DlcID=".$oDoc->DlcID."<br>";
                                                    
$oDoc->PtID=$PtID;
                                                    
//echo "PtID=".$oDoc->PtID."<br>";
                                                    
$oDoc->DtID=$oDoc2->DtID
                                                    
$oDoc->DslID=$oDoc2->DslID;
                                                    
$oDoc->DclID=$oDoc2->DclID;
                                                    
$oDoc->DsID="0";
                                                    
$oDoc->RsID="3"//sendin
                                                    
$oDoc->DocDateCreate=$timesend;
                                                    
$DocDateCreate=$oDoc->DocDateCreate;
                                                    
$oDoc->DocUserCreate=$deptPssend[$oDPt2->deptId];
                                                    
//echo "DocUserCreate=".$oDoc->DocUserCreate."<br>";
                                                    //$DocTypeNo=ShowRunningDoc($oDoc->RsID,$oDoc->DtID,$oDP2->deptId); 
                                                    
$oDoc->DocTypeNo=$oDoc->DocTypeNo;
                                                    
//echo "DocTypeNo=".$DocTypeNo."<br>";
                                                    
$oDoc->DocDate=$oDoc2->DocDate;
                                                    
$oDoc->DocNo=$oDoc2->DocNo;
                                                    
$oDoc->DocSubject=$oDoc2->DocSubject;
                                                    
$oDoc->DocFrom=$oDoc2->DocFrom;
                                                    
$oDoc->DocTo=$oDoc2->DocTo;
                                                    
$oDoc->DocShortDesc=$oDoc2->DocShortDesc;
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc->DocSpeedLevelDueDate; }
                                                    
$oDoc->DocSpeedLevelDueDate=$speedDate;
                                                    
//echo "speedDate=".$speedDate."<br>";
                                                    
$oDoc->DocStart=$oDoc2->DocStart;
                                                    
$oDoc->DocFinish=$oDoc2->DocFinish;
                                                    
$oDoc->DocGroup=$oDoc2->DocGroup;
                                                    
$oDoc->DocRef=$oDoc2->DocRef;
                                                    
$oDoc->DocCircular=$oDoc2->DocCircular;
                                                    
$oDoc->DocfCir=$oDoc2->DocfCir;
                                                    
$oDoc->DocOther=$oDoc2->DocOther;
                                                    
$oDoc->CertificatePs=$oDoc2->CertificatePs;
                                                    
$oDoc->fDelete=$oDoc2->fDelete;
                                                    
$oDoc->endDoc=$oDoc->endDoc;
                                                    
$oDoc->sendToPs=$oDoc2->sendToPs;
                                                    
$oDoc->AnID=$AnID;
                                                    
$oDoc->DocRefAns=$oDoc2->DocRefAns;
                                                    
$oDoc->DocRefAnsID=$oDoc2->DocRefAnsID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oDoc->DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oDoc->DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oDoc->DocstartDatePost=$oDoc2->DocstartDatePost;
                                                        
$oDoc->DocendDatePost=$oDoc2->DocendDatePost;
                                                        
                                                    }
                                                    
                            
                                                        if(
$DocShowIn=="1" && $DocShowOut=="2"){
                                                            
$addDocShowInOut="3";
                                                        }else{
                                                            if(
$DocShowIn=="1"){
                                                                
$addDocShowInOut=$DocShowIn;
                                                            }else if(
$DocShowOut=="2"){
                                                                    
$addDocShowInOut=$DocShowOut;
                                                            }
                                                        }
                            
                                                    
                                                    
$oDoc->DocShowInOut=$addDocShowInOut;
                                                    
$oDoc->useMainDocNo=$oDoc2->useMainDocNo;
                                                    
$oDoc->DocforSign=$oDoc2->DocforSign;
                                                    
$oDoc->eDoc=$oDoc2->eDoc;
                                                    
$oDoc->DocDeptOwner=$oDoc2->DocDeptOwner;
                                                    
$oDoc->DocTelOwner=$oDoc2->DocTelOwner;
                                                    
$oDoc->DocSendReal=$oDoc2->DocSendReal;
                                                    
$oDoc->DocFaxOwner=$oDoc2->DocFaxOwner;
                                                    
$oDoc->DocCopySend=$oDoc2->DocCopySend;
                                                    
$oDoc->DocContactE=$oDoc2->DocContactE;
                                                    
$checkflagCommit $oDoc->Save();
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                                    
//echo "end<br>";
                                                    
$checkupdate++;
                                                    
                                                    
$oRs2->AddNew();
                                                    
$oRs2->DrsID=$oRs2->GetNextCode();
                                                    
//echo "DrsID=".$oRs2->DrsID."<br>";
                                                    
$oRs2->DocID=$oDoc->DocID;
                                                    
$oRs2->DlcID=$deptPs[$i];
                                                    
$oRs2->DsID="0";
                                                    
$oRs2->PtID=$PtID;
                                                    
//echo "PtID2=".$oRs2->PtID."<br>";
                                                    
$oRs2->DrsDocTypeNo=$oRs2->DrsDocTypeNo;
                                                    
$oRs2->DrsReceiveDate=$timesend;
                                                    
$oRs2->DrsReceivePersonId='';
                                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                                    
$oRs2->DrsDocDueDate=$speedDate;
                                                    
//echo "speedDate2=".$speedDate."<br>";
                                                    
$oRs2->DrsDlcIDCreate=$DlcID;
                                                    
$oRs2->DrsPsIDCreate=$personId;
                                                    
$oRs2->DrsPropose=$DrsSend;
                                                    
$oRs2->DrsSign="";
                                                    
$oRs2->DrsFromDrsID=$oRs4->DrsID;
                                                    
$oRs2->DocGroup=$MaxDocGroup;
                                                    
$oRs2->AnID=$AnID;
                                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                        
$oRs2->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                        
$oRs2->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                                    }else{
                                                        
$oRs2->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                        
$oRs2->DrsendDatePost=$oRs4->DrsendDatePost;
                                                        
                                                    }
                                                    if(
$PtID!=&& $PtID!=&& $PtID!=&& $PtID!=&& $mainDepts==$deptPs[$oDPt2->deptId] && $mainDepts!=''){
                                                        
$oRs2->DrsMainDept='Y';
                                                    }else{
                                                            
$oRs2->DrsMainDept='';
                                                    }
                                                    
$checkflagCommit $oRs2->Save();
                                                    
                                                    if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                        }
                                    }
                                } 
//loop dept
                                
                            
//end case check main dept                  
                        
//end
                                    
                        //-----------------send to person in dept----------------------------------
                        
                        
$oPS2->SearchByDeptId($deptId); 
                        while(
$oPS2->GetRecord()){
                            if(
$checkAllPs=="1"){ //send All ps in deptId
                                    
$oRs1->AddNew();
                                    
$oRs1->DrsID=$oRs1->GetNextCode();
                                    
$oRs1->DocID=$DocID;
                                    
$oRs1->DlcID="0";
                                    if(((
$oPS2->personId==$regisPersonId) || ($oPS2->personId==$signPersonId) || ($oPS2->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                        
$oRs1->DsID=5;
                                    }else{
                                        
$oRs1->DsID=0;
                                    }
                                    
$oRs1->personId=$oPS2->personId;
                                    
//echo "send All ps=".$oRs1->personId."<br>";
                                    
$oRs1->PtID=$PtID;
                                    
$oRs1->DrsDocTypeNo=$oRs4->DrsDocTypeNo;
                                    
$oRs1->DrsReceiveDate=$timesend;
                                    
$oRs1->DrsReceivePersonId=$oPS2->personId;
                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                    
$oRs1->DrsDocDueDate=$speedDate;
                                    
$oRs1->DrsDlcIDCreate=$DlcID;
                                    
$oRs1->DrsPsIDCreate=$personId;
                                    
$oRs1->DrsPropose=$DrsSend;
                                    
$oRs1->DrsSign=$oRs1->DrsSign;
                                    
$oRs1->DrsFromDrsID=$oRs4->DrsID;
                                    
$oRs1->DocGroup=$MaxDocGroup;
                                    if(
$mainPs==$oPS2->personId && ($PtID!=&& $PtID!=&& $PtID!=&& $PtID!=6)){ $DrsMainPs="Y"; }else{ $DrsMainPs=""; }
                                    
$oRs1->DrsMainPs=$DrsMainPs;
                                    
//echo "DrsMainPs=".$DrsMainPs."<br>";
                                    
$oRs1->AnID=$AnID;
                                    if(((
$oPS2->personId==$regisPersonId) || ($oPS2->personId==$signPersonId) || ($oPS2->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                        
$oRs1->DrsDocReceiveDate=$timesend;
                                    }                    
                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                        
$oRs1->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                        
$oRs1->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                    }else{
                                        
$oRs1->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                        
$oRs1->DrsendDatePost=$oRs4->DrsendDatePost;
                                        
                                    }
                                    if(((
$oPS2->personId==$regisPersonId) || ($oPS2->personId==$signPersonId) || ($oPS2->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                        
$DrsReadDoc=GetDrsReadDocSet1($DocID);
                                    }else{
                                        
$DrsReadDoc=GetDrsReadDoc($DocID);
                                    }
                                    
                                    
$oRs1->DrsReadDoc=$DrsReadDoc;
                    
                                        
$checkflagCommit $oRs1->Save();
                                        
                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                    
$checkupdate2++;
                            }else{ 
                            
                                for(
$i=0;$i<count($Ps);$i++){
                                    if(
$Ps[$i]==$oPS2->personId){
                                        if(
$Ps[$i]!="" || $mainPs==$oPS2->personId){
                                            
//echo "addnew send to person in dept<br>";
                                            
$oRs1->AddNew();
                                            
$oRs1->DrsID=$oRs1->GetNextCode();
                                            
$oRs1->DocID=$DocID;
                                            
$oRs1->DlcID="0";
                                            if(((
$oPS2->personId==$regisPersonId) || ($oPS2->personId==$signPersonId) || ($oPS2->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                                
$oRs1->DsID=5;
                                            }else{
                                                
$oRs1->DsID=0;
                                            }
                                            
$oRs1->personId=$oPS2->personId;
                                            
//echo "send All ps=".$oRs1->personId."<br>";
                                            
$oRs1->PtID=$PtID;
                                            
$oRs1->DrsDocTypeNo=$oRs4->DrsDocTypeNo;
                                            
$oRs1->DrsReceiveDate=$timesend;
                                            
$oRs1->DrsReceivePersonId=$oPS2->personId;
                                            if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                            
$oRs1->DrsDocDueDate=$speedDate;
                                            
$oRs1->DrsDlcIDCreate=$DlcID;
                                            
$oRs1->DrsPsIDCreate=$personId;
                                            
$oRs1->DrsPropose=$DrsSend;
                                            
$oRs1->DrsFromDrsID=$oRs4->DrsID;
                                            
$oRs1->DocGroup=$MaxDocGroup;
                                            if(
$mainPs==$oPS2->personId && ($PtID!=&& $PtID!=&& $PtID!=&& $PtID!=6)){ $DrsMainPs="Y"; }else{ $DrsMainPs=""; }
                                            
$oRs1->DrsMainPs=$DrsMainPs;
                                            
//echo "DrsMainPs=".$DrsMainPs."<br>";
                                            
$oRs1->AnID=$AnID;
                                            if(((
$oPS2->personId==$regisPersonId) || ($oPS2->personId==$signPersonId) || ($oPS2->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                                
$oRs1->DrsDocReceiveDate=$timesend;
                                            }                    
                                            if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                                
$oRs1->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                                
$oRs1->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                            }else{
                                                
$oRs1->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                                
$oRs1->DrsendDatePost=$oRs4->DrsendDatePost;
                                                
                                            }
                                            if(((
$oPS2->personId==$regisPersonId) || ($oPS2->personId==$signPersonId) || ($oPS2->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                                
$DrsReadDoc=GetDrsReadDocSet1($DocID);
                                            }else{
                                                
$DrsReadDoc=GetDrsReadDoc($DocID);
                                            }
                                            
$oRs1->DrsReadDoc=$DrsReadDoc;
                                                                
                                                
$checkflagCommit $oRs1->Save();
                                                
                                                if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                            
$checkupdate2++;
                                        }
                                    }
                                }
                            }    
                        }
                        
//--------------------------------------------send to psdept----------------------------------------
                        
$oPSd->SearchBydeptId($deptId);
                    
                        while(
$oPSd->GetRecord()){
                            for(
$i=0;$i<count($Ps);$i++){
                                if(
$oPSd->personId==$Ps[$i]){
                                    if(
$Ps[$i]!="" || $mainPs==$oPSd->personId){
                                        
//echo "addnew send to person in dept<br>";
                                        
$oRs1->AddNew();
                                        
$oRs1->DrsID=$oRs1->GetNextCode();
                                        
$oRs1->DocID=$DocID;
                                        
$oRs1->DlcID="0";
                                        if(((
$oPSd->personId==$regisPersonId) || ($oPSd->personId==$signPersonId) || ($oPSd->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                            
$oRs1->DsID=5;
                                        }else{
                                            
$oRs1->DsID=0;
                                        }
                                        
$oRs1->personId=$oPSd->personId;
                                        
//echo "send All ps=".$oRs1->personId."<br>";
                                        
$oRs1->PtID=$PtID;
                                        
$oRs1->DrsDocTypeNo=$oRs4->DrsDocTypeNo;
                                        
$oRs1->DrsReceiveDate=$timesend;
                                        
$oRs1->DrsReceivePersonId=$oPSd->personId;
                                        if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                        
$oRs1->DrsDocDueDate=$speedDate;
                                        
$oRs1->DrsDlcIDCreate=$DlcID;
                                        
$oRs1->DrsPsIDCreate=$personId;
                                        
$oRs1->DrsPropose=$DrsSend;
                                        
$oRs1->DrsFromDrsID=$oRs4->DrsID;
                                        
$oRs1->DocGroup=$MaxDocGroup;
                                        if(
$mainPs==$oPSd->personId && ($PtID!=&& $PtID!=&& $PtID!=&& $PtID!=6)){ $DrsMainPs="Y"; }else{ $DrsMainPs=""; }
                                        
$oRs1->DrsMainPs=$DrsMainPs;
                                        
//echo "DrsMainPs=".$DrsMainPs."<br>";
                                        
$oRs1->AnID=$AnID;
                                        if(((
$oPSd->personId==$regisPersonId) || ($oPSd->personId==$signPersonId) || ($oPSd->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                            
$oRs1->DrsDocReceiveDate=$timesend;
                                        }                    
                                        if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                            
$oRs1->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                            
$oRs1->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                        }else{
                                            
$oRs1->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                            
$oRs1->DrsendDatePost=$oRs4->DrsendDatePost;
                                            
                                        }
                                        if(((
$oPSd->personId==$regisPersonId) || ($oPSd->personId==$signPersonId) || ($oPSd->personId==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                            
$DrsReadDoc=GetDrsReadDocSet1($DocID);
                                        }else{
                                            
$DrsReadDoc=GetDrsReadDoc($DocID);
                                        }
                                        
$oRs1->DrsReadDoc=$DrsReadDoc;
                                                            
                                        
$checkflagCommit $oRs1->Save();
                                        
                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                        
$checkupdate2++;
                                    }
                                }
                            }
                        }
                        if(
$showsendtops=="Y"){
                            
//-----SendToPs
                            
$oStmp->SearchByDrsID($DrsID);
                            while(
$oStmp->GetRecord()){
                            
//echo $oStmp->PsID."<br>";
                                    
$oRs5->AddNew();
                                    
$oRs5->DrsID=$oRs5->GetNextCode();
                                    
$oRs5->DocID=$DocID;
                                    
$oRs5->DlcID="0";
                                    if(          ((
$oStmp->PsID==$regisPersonId) || ($oStmp->PsID==$signPersonId) || ($oStmp->PsID==$sendPersonId)) && ($useacceptDoc=="Y")             ){   //send to me
                                        
$oRs5->DsID=5;
                                    }else{
                                        
$oRs5->DsID=0;
                                    }
                                    
$oRs5->personId=$oStmp->PsID;
                                    
//echo "send person=".$oRs5->personId."<br>";
                                    
$oRs5->PtID=$PtID;
                                    
$oRs5->DrsDocTypeNo=$oRs4->DrsDocTypeNo;
                                    
$oRs5->DrsReceiveDate=$timesend;
                                    
$oRs5->DrsReceivePersonId=$oStmp->PsID;
                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                    
$oRs5->DrsDocDueDate=$speedDate;
                                    
$oRs5->DrsDlcIDCreate=$DlcID;
                                    
$oRs5->DrsPsIDCreate=$personId;
                                    
$oRs5->DrsPropose=$DrsSend;
                                    
$oRs5->DrsSign=$oRs5->DrsSign;
                                    
$oRs5->DrsFromDrsID=$oRs4->DrsID;
                                    
$oRs5->DocGroup=$MaxDocGroup;
                                    
$oRs5->DrsSendToPs="Y";
                                    
$oRs5->AnID=$AnID;
                                    if(((
$oStmp->PsID==$regisPersonId) || ($oStmp->PsID==$signPersonId) || ($oStmp->PsID==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                        
$oRs5->DrsDocReceiveDate=$timesend;
                                    }                    
                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                            
$oRs5->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                            
$oRs5->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                        }else{
                                            
$oRs5->DrsstartDatePost=$oRs4->DrsstartDatePost;
                                            
$oRs5->DrsendDatePost=$oRs4->DrsendDatePost;
                                            
                                    }
                                    if(((
$oStmp->PsID==$regisPersonId) || ($oStmp->PsID==$signPersonId) || ($oStmp->PsID==$sendPersonId)) && ($useacceptDoc=="Y")){   //send to me
                                        
$DrsReadDoc=GetDrsReadDocSet1($DocID);
                                    }else{
                                        
$DrsReadDoc=GetDrsReadDoc($DocID);
                                    }
                                    
$oRs5->DrsReadDoc=$DrsReadDoc;
                                    
                                            
$checkflagCommit $oRs5->Save();
                                            if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                            
$checkupdate3++;
                                            
//echo 'ddddddd';
                            
                            
}
                        }        
                        
                        
//echo "1=".$checkupdate."2=".$checkupdate2."<br>";
                        
if($checkupdate!="0" || $checkupdate2!="0" || ($checkupdate3!="0" && $showsendtops=="Y")){
                            
//------------------update  RSdoc status=3
                                    
$oRs->SearchByKey($DrsID);
                                    
//echo "update  RSdoc status=3<br>";
                                    //echo "DrsID_edit=".$DrsID."<br>";
                                    
$oRs->GetRecord();
                                    
$oRs->Edit();
                                    
$oRs->PtID=$PtID;
                                    
$oRs->DrsSendDate=$timesend;
                                    
//echo "DrsSendDate=".$oRs->DrsSendDate."<br>";
                                    
$oRs->DrsSendPersonId=$oRs->DrsSendPersonId;
                                    
$oRs->DrsSendDlcID=$oRs->DrsSendDlcID;
                                    if(
$checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$DrsDocDueDate; }
                                    
$oRs->DrsDocDueDate=$speedDate;
                                    
$oRs->AnID=$AnID;
                                    if(
$firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                        
$oRs->DrsstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                        
$oRs->DrsendDatePost=splitDateForm($DrsendDatePost,"/");
                                    }else{
                                        
$oRs->DrsstartDatePost=$oRs->DrsstartDatePost;
                                        
$oRs->DrsendDatePost=$oRs->DrsendDatePost;
                                        
                                    }
                                        
$checkflagCommit $oRs->Save();
                                        if(!
$checkflagCommit){ $flagCommit=$checkflagCommit;   }
                                    
                                        
                        } 
//checkupdate!=0
                
                        
if($checkupdate!="0" || $checkupdate2!="0" || ($checkupdate3!="0" && $showsendtops=="Y")){
                                    
//echo "update  RSdoc status=3<br>";
                                    
$oDoc3->SearchByKey($DocID);
                                    
$oDoc3->GetRecord();
                                    
$oDoc3->Edit();
                                    
$oDoc3->PtID=$PtID;
                                    
//echo "PtID=".$oDoc3->PtID."<br>";
                                    
if($checkDocSpeedDate=="Y"){ $speedDate=splitDateForm($DocSpeedLevelDueDate,"/"); }else{ $speedDate=$oDoc3->DocSpeedLevelDueDate; }
                                    
$oDoc3->DocSpeedLevelDueDate=$speedDate;
                                    
//echo "DocSpeedLevelDueDate=".$oDoc3->DocSpeedLevelDueDate."<br>";
                                    
$oDoc3->AnID=$AnID;
                                    
//echo "AnID=".$oDoc3->AnID."<br>";
                                    
if($firstpost=="1" && ($AnID!="" && $AnID!="0")){
                                        
$DocstartDatePost=splitDateForm($DrsstartDatePost,"/");
                                        
$DocendDatePost=splitDateForm($DrsendDatePost,"/");
                                        
//echo "DocstartDatePost1=".$oDoc3->DocstartDatePost."<br>";
                                        //echo "DocendDatePost1=".$oDoc3->DocendDatePost."<br>";
                                    
}else{
                                        
$DocstartDatePost=$oDoc3->DocstartDatePost;
                                        
$DocendDatePost=$oDoc3->DocendDatePost;
                                        
                                        
                                    }
                                    
$oDoc3->DocstartDatePost=$DocstartDatePost;
                                    
$oDoc3->DocendDatePost=$DocendDatePost;
                
                                    if(
$firstpost=="1"){
                                        
$oDoc3->DocMainPost="Y";
                                    }else{
                                        
$oDoc3->DocMainPost=$oDoc3->DocMainPost;
                                    }
                                    
//echo "DocMainPost=".$oDoc3->DocMainPost."<br>";
                                    
                
                                        
if($DocShowIn=="1" && $DocShowOut=="2"){
                                            
$addDocShowInOut="3";
                                        }else{
                                            if(
$DocShowIn=="1"){
                                                
$addDocShowInOut=$DocShowIn;
                                            }else if(
$DocShowOut=="2"){
                                                
$addDocShowInOut=$DocShowOut;
                                            }
                                        }
                
                                    
$oDoc3->DocShowInOut=$addDocShowInOut;
                                    
//echo "DocShowInOut=".$oDoc3->DocShowInOut."<br>";
                                    
$oDoc3->Save();
                                    
//    if(!$checkflagCommit){ $flagCommit=$checkflagCommit;  echo "grtgtg"; }        
                        
}
                
                        
                        
$oStmp->SearchByDrsID($DrsID);
                        while(
$oStmp->GetRecord()){
                                
$oStmp->Delete();
                        }
                        
                    if(
$flagCommit){
                        
$oC->CommitTrans();
                
                    }
                    else{
                        
$oC->RollbackTrans();    
                
                    }                        
                        
                        if(
$cansend=="Y"){
                            
// Chain Comment For Mobile
        //echo "<meta http-equiv='refresh' content='0; URL=signDoc.php?searchpredocdate=$searchpredocdate&selectpredocdatevalue=$selectpredocdatevalue&folderstaff2=$folderstaff2&forfolderstaff2=$forfolderstaff2'>";
                        
}else{
                            
// Chain Comment For Mobile
        //echo "<meta http-equiv='refresh' content='0; URL=sendDoc.php?page_id2=$page_id2&searchpredocdate=$searchpredocdate&selectpredocdatevalue=$selectpredocdatevalue&searchNamePre=$searchNamePre&searchNoPre=$searchNoPre&selectpreDtID=$selectpreDtID&folderstaff2=$folderstaff2&forfolderstaff2=$forfolderstaff2&searchPreTypeNoF=$searchPreTypeNoF&searchPreTypeNoT=$searchPreTypeNoT&searchNoPre=$searchNoPre'>";
                        
}
        
    }else{ 
//can send case normal
        
        // Chain Comment For Mobile
        //echo "<meta http-equiv='refresh' content='0; URL=sendDoc.php?page_id2=$page_id2&searchpredocdate=$searchpredocdate&selectpredocdatevalue=$selectpredocdatevalue&searchNamePre=$searchNamePre&searchNoPre=$searchNoPre&selectpreDtID=$selectpreDtID&folderstaff2=$folderstaff2&forfolderstaff2=$forfolderstaff2&searchPreTypeNoF=$searchPreTypeNoF&searchPreTypeNoT=$searchPreTypeNoT&searchNoPre=$searchNoPre'>";
        
    
}
    

}else if(
$fn=='sendTest'){ 

include_once(
"../../class/clsConnection.php");
include_once(
"../../class/clsDB.php");
include_once 
"../global.php";
include_once 
"../class/clsPerson.php";

include_once 
"../class/clsTable.php";
include_once 
"../class/clsDepartment.php";
include_once 
"../class/clsPerson.php";

include_once 
"../class/clsDocLinePosition.php";
include_once 
"../class/clsDocLineConfig.php";
include_once 
"../class/clsReceiveSendType.php";
include_once 
"../class/clsDocType.php";
include_once 
"../class/clsDocSpeedLevel.php";
include_once 
"../class/clsDocSecreLevel.php";
include_once 
"../class/clsDocattatchesTmp.php";
include_once 
"../class/clsDocuments.php";
include_once 
"../class/clsDocattatches.php";
include_once 
"../class/clsDocReceiveSend.php";
include_once 
"../class/clsProposeType.php";

include_once 
"../class/clsDocSendtoPsTmp.php";
include_once 
"../class/clsannounceDocType.php";
include_once 
"../class/clsannounceDocType.php";
include_once 
"../class/clspsdept.php";
include_once 
"../class/clsDocWSign.php";
include_once 
"functMobile.php";
include_once 
"../class/clsSysConfig.php";
include_once 
"../class/clsDocInboxStaff.php";

$DocID = (! isset($_REQUEST['DocID'])? "" $_REQUEST['DocID']);
$DlcID = (! isset($_REQUEST['DlcID'])? "" $_REQUEST['DlcID']);
$DrsID = (! isset($_REQUEST['DrsID'])? "" $_REQUEST['DrsID']);

$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);

$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
$oDP = new Department($oC);
$oDP2 = new Department($oC);
$oDP3 = new Department($oC);
$oDP4 = new Department($oC);
$oDP5 = new Department($oC);
$oDPt = new Department($oC);
$oDPt2 = new Department($oC);
$oDPt3 = new Department($oC);
$oDPt4 = new Department($oC);
$oPS = new person($oC);
$oPS2 = new person($oC);
$oPS3 = new person($oC);
$oPS4 = new person($oC);
$oPS5 = new person($oC);
$oPS6 = new person($oC);
$oPS7 = new person($oC);
//$oUG = new umgroup($oCu);
$oDlc = new DocLineConfig($oC);
$oDlc2 = new DocLineConfig($oC);
$oDlc3 = new DocLineConfig($oC);
$oDlc4 = new DocLineConfig($oC);
$oDlc5 = new DocLineConfig($oC);
$oDlc6 = new DocLineConfig($oC);
$oDlc7 = new DocLineConfig($oC);
$oDlp = new docLinePosition($oC);
$oDlp1 = new docLinePosition($oC);
$oDlp2= new docLinePosition($oC);
$oRSt = new receiveSendType($oC);
$oDt = new doctype($oC);
$oDsl = new DocSpeedLevel($oC);
$oDcl = new DocSecretLevel($oC);
$oDtmp = new DocattatchesTmp($oC);
$oDoc = new Documents($oC);
$oDoc2 = new Documents($oC);
$oDoc3 = new Documents($oC);
$oDoc4 = new Documents($oC);
$oDoc5 = new Documents($oC);
$oDatt = new Docattatches($oC);
$oRs = new DocReceiveSend($oC);
$oRs1 = new DocReceiveSend($oC);
$oRs2 = new DocReceiveSend($oC);
$oRs3 = new DocReceiveSend($oC);
$oRs4 = new DocReceiveSend($oC);
$oRs6 = new DocReceiveSend($oC);
$oRs7 = new DocReceiveSend($oC);
$oRs8 = new DocReceiveSend($oC);
$oRs9 = new DocReceiveSend($oC);
$oRs10 = new DocReceiveSend($oC);
$oRs11 = new DocReceiveSend($oC);
$oRstt = new DocReceiveSend($oC);
$oPt = new ProposeType($oC);
$oStmp=new DocSendToPsTmp($oC);
$oStmp2=new DocSendToPsTmp($oC);
$oAn=new announceDocType($oC);
$oAn=new announceDocType($oC);
$oPSd = new psdept($oC);
$MaxDocGroup=$oDP->SearchMaxDocGroup();
$oDws = new docwsign($oC);
$oSys = new sysConfig($oC);
$InputThai=$oSys->SearchByInputThai();
$oDws = new docwsign($oC);
$oDbxS = new DocInboxStaff($oC);
$oDbxS1 = new DocInboxStaff($oC);
$oDbxS3 = new DocInboxStaff($oC);
$oDbxS2 = new DocInboxStaff($oC);


$oRs->SearchByKey($DrsID); $oRs->GetRecord(); 
$oRs7->SearchByshowSendDocSign($oRs->DrsFromDrsID); $oRs7->GetRecord(); 

$oPS6->SearchByKey($oRs->DrsPsIDCreate); $oPS6->GetRecord();
$oDlp2->SearchByKey($oDlc6->SearchByKeyName($oRs->DrsDlcIDCreate,'DlpID'));  $oDlp2->GetRecord();

$list='<?xml version="1.0" encoding="UTF-8" ?><Send>';
$list.='<DrsSign>'.iconv('TIS-620','UTF-8',$oRs->DrsSign).'</DrsSign>';
$list.="<FName>".iconv('TIS-620','UTF-8',$oPS6->fName)."</FName>";
$list.="<LName>".iconv('TIS-620','UTF-8',$oPS6->lName)."</LName>";
$list.="<DlpName>".iconv('TIS-620','UTF-8',$oDlp2->DlpName)."</DlpName>";
$list.="<Date>".iconv('TIS-620','UTF-8',$oRs7->DrsSendDate)."</Date>";
//list($DocD,$DocT) = preg_split('[ ]',$oRs7->DrsSendDate);
//$list.="<Time>".iconv('TIS-620','UTF-8',$DocT)."</Time>";

$oDPt->SearchByShowselectdoc($oDlc->deptId);
$oDPt->GetRecord();
$DlcdeptId=$oDlc->deptId;
if(
$oDPt->deptParentId==0){
    
$oDPt2->RSmenuByDeptParent2($oDPt->deptParentId);
    while(
$oDPt2->GetRecord()){ 
        
$pssend=ShowSendtoPs2($oDPt2->deptId);
        if(
$pssend!=''){
            
$oDlc4->SearchByKey($pssend); $oDlc4->GetRecord(); 
            
$oPS2->SearchByKey($oDlc4->personId); $oPS2->GetRecord();         
            
$list.="<Dept><DeptID>".iconv('TIS-620','UTF-8',$oDPt2->deptId)."</DeptID><DeptName>".iconv('TIS-620','UTF-8',$oDPt2->deptName)."</DeptName></Dept>";
            if(
$DlcdeptId==$oDPt2->deptId){
                    
$oDPt3->RSmenuByDeptParent2($oDPt2->deptId);
                    while(
$oDPt3->GetRecord()){
                        
$pssend=ShowSendtoPs2($oDPt3->deptId);
                        if(
$pssend!=''){
                            
$oDlc5->SearchByKey($pssend); $oDlc5->GetRecord(); 
                            
$oPS2->SearchByKey($oDlc5->personId); $oPS2->GetRecord(); 
                            
$list.="<Dept><DeptID>".iconv('TIS-620','UTF-8',$oDPt3->deptId)."</DeptID><DeptName>".iconv('TIS-620','UTF-8',$oDPt3->deptName)."</DeptName></Dept>";
                        }
                    }
            }
        }
    }
}else{
    
$oDPt2->SearchByKey($oDPt->deptParentId);
    
$oDPt2->GetRecord();
    
$pssend=ShowSendtoPs2($oDPt2->deptId);
    if(
$pssend!=''){
        
$oDlc4->SearchByKey($pssend); $oDlc4->GetRecord(); 
        
$oPS2->SearchByKey($oDlc4->personId); $oPS2->GetRecord();         
        
$list.="<Dept><DeptID>".iconv('TIS-620','UTF-8',$oDPt2->deptId)."</DeptID><DeptName>".iconv('TIS-620','UTF-8',$oDPt2->deptName)."</DeptName></Dept>";
    }
    
$oDPt3->RSmenuByDeptParent2($oDPt2->deptId);
    while(
$oDPt3->GetRecord()){
        
$pssend=ShowSendtoPs2($oDPt3->deptId); 
        if(
$pssend!=''){
            
$oDlc4->SearchByKey($pssend); $oDlc4->GetRecord(); 
            
$oPS2->SearchByKey($oDlc4->personId); $oPS2->GetRecord();         
            
$list.="<Dept><DeptID>".iconv('TIS-620','UTF-8',$oDPt3->deptId)."</DeptID><DeptName>".iconv('TIS-620','UTF-8',$oDPt3->deptName)."</DeptName></Dept>";
            if(
$oDPt3->deptId==$oDPt->deptId){
                
$oDPt4->RSmenuByDeptParent2($oDPt3->deptId);
                while(
$oDPt4->GetRecord()){
                    
$pssend=ShowSendtoPs2($oDPt4->deptId); 
                    if(
$pssend!=''){
                        
$oDlc4->SearchByKey($pssend); $oDlc4->GetRecord(); 
                        
$oPS2->SearchByKey($oDlc4->personId); $oPS2->GetRecord();         
                        
$list.="<Dept><DeptID>".iconv('TIS-620','UTF-8',$oDPt4->deptId)."</DeptID><DeptName>".iconv('TIS-620','UTF-8',$oDPt4->deptName)."</DeptName></Dept>";
                    }
                }
            }
        }
    }
}



$oPt->RSProposeType();

while(
$oPt->GetRecord()){
    
$list.="<PtNames>";
    
$list.= "<PtName>".iconv('TIS-620','UTF-8',$oPt->PtName)."</PtName>";
    
$list.= "<PtID>".iconv('TIS-620','UTF-8',$oPt->PtID)."</PtID>";
    
$list.="</PtNames>";
}

$oPS->SearchByKey($personId); $oPS->GetRecord();
$list.= "<PSFName>".iconv('TIS-620','UTF-8',$oPS->fName)."</PSFName>";
$list.= "<PSLName>".iconv('TIS-620','UTF-8',$oPS->lName)."</PSLName>";
$oDlc->SearchByKey($DlcID); $oDlc->GetRecord(); 
$oDlp->SearchByKey($oDlc->DlpID);  $oDlp->GetRecord();
$list.= "<PSDlpName>".iconv('TIS-620','UTF-8',$oDlp->DlpName)."</PSDlpName>";


$oPS2->SearchByDeptIdadminId($oDlc->deptId);

while(
$oPS2->GetRecord()){     
    
$list.= "<PS2>";
    
$list.= "<personId>".iconv('TIS-620','UTF-8',$oPS2->personId)."</personId>";
    
$list.= "<PS2FName>".iconv('TIS-620','UTF-8',$oPS2->fName)."</PS2FName>";
    
$list.= "<PS2LName>".iconv('TIS-620','UTF-8',$oPS2->lName)."</PS2LName>";
    
$list.= "</PS2>";
}

$oPSd->SearchBydeptId($oDlc->deptId);
        
$countPSd=$oPSd->NumRow();
        if(
$countPSd!="" && $countPSd!="0"){
            while(
$oPSd->GetRecord()){
                
$oPS->SearchByKey($oPSd->personId);
                
$oPS->GetRecord();
                
$list.="<PSD><personId>".iconv('TIS-620','UTF-8',$oPS->personId)."</personId><PSDFName>".iconv('TIS-620','UTF-8',$oPS->fName)."</PSDFName>";
                
$list.="<PSDLName>".iconv('TIS-620','UTF-8',$oPS->lName)."</PSDLName></PSD>";                
            }
        }

    
$list.="<DrsDocDueDate>".iconv('TIS-620','UTF-8',$oRs->DrsDocDueDate)."</DrsDocDueDate>"

$list.="</Send>";
echo 
$list;


}else if(
$fn=='user_detail'){
include_once(
"../../class/clsConnection.php");
include_once(
"../../class/clsDB.php");
include_once 
"../global.php";
include_once 
"../class/clsPerson.php";
include_once 
"../class/clsPersonPE.php";

$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);

$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
$oCc = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EPERSON'], $GLOBALS['DBUSER_EPERSON'], $GLOBALS['DBPASS_EPERSON']);

$oPSp = new PersonPE($oCc);
$oPS = new person($oC);

        
$oPS->SearchByPersonIdNamefNamePrefix($personId);
        if (
$oPS->GetRecord()) {
            
$prefixName=$oPSp->SearchPrefixName($oPS->prefixId);
            echo 
iconv('TIS-620''UTF-8',$prefixName).','.iconv('TIS-620''UTF-8',$oPS->fName).','.iconv('TIS-620''UTF-8',$oPS->lName);
        }


}else if(
$fn=='detail_work_moblie'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"../class/clsUmuser.php";    
    include_once 
"../class/clsUmUserGroup.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDepartment.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../link/keyThai.php";
    include_once 
"../class/clsDocForSign.php";
    include_once 
"../class/clsSendReceive.php";
    
    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);    
    
    
$oUs = new umuser($oC);
    
$oUg = new umusergroup($oC);
    
$oRs = new DocReceiveSend($oC);
    
$oRs2 = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDoc2 = new Documents($oC);
    
$oDoc3 = new Documents($oC);
    
$oDP = new Department($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDlp2 = new docLinePosition($oC);
    
$oDlp3 = new docLinePosition($oC);
    
$oDlp4 = new docLinePosition($oC);
    
$oDlc = new docLineConfig($oC);
    
$oDlc1 = new docLineConfig($oC);
    
$oDlc2 = new docLineConfig($oC);
    
$oDlc3 = new docLineConfig($oC);
    
$oDlc4 = new docLineConfig($oC);
    
$oDlc5 = new docLineConfig($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$Maxgroup=$oDP->SearchMaxDocGroup();
    
$oDfs = new DocForSign($oC);
    
$oTsr = new sendreceive($oC);

    
$oUs->SearchUsIDByUsPsCode($personId,$GLOBALS['DBNAME_UMS']);
    
$oUs->GetRecord();   //---find  -> $oUs->UsID;

    
$list='<?xml version="1.0" encoding="UTF-8" ?><work>';
    
$oUg->RSgroupByUgUsIDMobile($oUs->UsID,$GLOBALS['DBNAME_UMS'],'UgGpID');
    while(
$oUg->GetRecord()){  
            
//------------------------------staff sarabun----------------------------------------------------------------
            
            
if($oUg->UgGpID==SearchGroupSarabunStaff()){             
                
$oDlp->SearchByGpID(SearchGroupSarabunStaff());
                while(
$oDlp->GetRecord()){
                        
$oDlc->SearchByPsPositionDlpIDActiveYUnion($personId,$oDlp->DlpID,$Maxgroup);
                        while(
$oDlc->GetRecord()){  
                                    
$list.="<workgroup>";
                                    
$oDP->SearchByKey($oDlc->deptId);
                                    
$oDP->GetRecord(); 
            
                                    if(
$oDlp->DlpPID!="0"){ 
                                        
$DlcPS2=$oDlc3->SearchDlc2($oDlc->DlcSeq,$oDlp->DlpPID,$oDlc->deptId);
                                     }else{
                                        
$DlcPS2=$oDlc3->SearchDlc2($oDlc->DlcSeq,$oDlp->DlpPID,$oDlc->deptId);
                                    }
                                    
$list.="<positionname>".iconv('TIS-620''UTF-8',$oDlp->DlpName)."(".iconv('TIS-620''UTF-8',$oDP->deptName).")</positionname>";
                                    
$list.="<dlcid> ".$oDlc->DlcID." </dlcid>";
                                    
$list.="<mainworklist>";
                                    
                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>receivedoc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือเข้า/ลงรับ</worklisttypename>";
                                    
$i=0;
                                    
$i=$oDoc->SearchCountDocIDByDlcIDDocGroupPSDlcID2DsID0DrsSendDate($oDlc->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$i."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sendBack_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือแจ้งการส่งผิด</worklisttypename>";
                                    
$j=0;
                                    
$j=$oRs->SearchCountDrsIDByDlcIDDocGroupDrsSendBackDrsSendBackDlcID($oDlc->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$j."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";
                                    
                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>send_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือลงนามแล้วรอส่ง</worklisttypename>";
                                    
$k=0;
                                    
$k=$oDoc3->SearchCountDocIDByDlcIDDocGroupPSDlcID2DsID3DrsSendDateDrsSEndnotY2($oDlc->DlcID,$Maxgroup,$DlcPS2,$oDlc->DlcID);
                                    
$list.="<worklistamount>".$k."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>statusDocforSign</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือเสนอลงนามแล้วรอรับหนังสือ</worklisttypename>";
                                    
$m=0;
                                    
$m=$oDfs->SearchDlcIDstatusNoGetNumCaseSign($oDlc->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$m."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>statusDocforSignEdit</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือเสนอลงนาม(ยังไม่ลงนาม)มีการแจ้งแก้ไข</worklisttypename>";
                                    
$p=0;
                                    
$p=$oDfs->SearchDlcIDstatusNoGetNumCaseEdit($oDlc->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$p."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";
                                    
                                                                    
                                    if(
SearchSendAll_receive($oDlc->DlpID)=="All"){
                                    
//----------------------------------
                                            
$list.="<worklist>";
                                            
$list.="<worklisttype>receiveEdoc</worklisttype>";
                                            
$list.="<worklisttypename>รายการหนังสือเข้าอิเล็กทรอนิกส์</worklisttypename>";
                                            
$n=0;    
                                            
$n$oTsr->SearchCountBytsr_status(r1);
                                            
$list.="<worklistamount>".$n."</worklistamount>";
                                            
$list.="<worklistunit>ฉบับ</worklistunit>";
                                            
$list.="</worklist>";
                                    }
                                    
$list.="</mainworklist>";
                                    
$list.="</workgroup>";
                        }
                }                
            } 
//--umusergroup

            //------------------------------head sarabun----------------------------------------------------------------
            
if($oUg->UgGpID==SearchGroupSarabunHead()){
                
$oDlp2->SearchByGpID(SearchGroupSarabunHead());
                while(
$oDlp2->GetRecord()){
                        
$group2=0;
                        
$oDlc2->SearchByPsPositionDlpIDActiveY($personId,$oDlp2->DlpID,$Maxgroup);
                        while(
$oDlc2->GetRecord()){
                                    
$list.="<workgroup>";
                                    
$oDP->SearchByKey($oDlc2->deptId);
                                    
$oDP->GetRecord(); 
                                    
                                    if(
$oDlp2->DlpPID!="0"){ 
                                            
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp2->DlpPID,$oDlc2->deptId);
                                    }else{
                                            
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp2->DlpPID,$oDlc2->deptId);
                                    }

                                    
$list.="<positionname>".iconv('TIS-620''UTF-8',$oDlp2->DlpName)."(".iconv('TIS-620''UTF-8',$oDP->deptName).")</positionname>";
                                    
$list.="<dlcid> ".$oDlc2->DlcID." </dlcid>";
                                    
$list.="<mainworklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sign_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือที่ยังไม่ได้ลงนาม</worklisttypename>";
                                    
$i=0;
                                    
$i $oDoc->SearchCountDocIDByDocGroupDsID2DocIDDlcIDDrsReceiveDlcID2Status2($Maxgroup,$oDlc2->DlcID,$DlcPS2);
                                    
$list.="<worklistamount>".$i."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sendBack_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือแจ้งการส่งผิด</worklisttypename>";
                                    
$j=0;
                                    
$j $oRs->SearchCountDrsIDByDlcIDDocGroupDrsSendBackDrsSendBackDlcID($oDlc2->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$j."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>send_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือลงนามแล้วรอส่ง</worklisttypename>";
                                    
$k=0;    
                                    if(
$oDlp2->DlpPID=="0"){  $a=2$b=1;   }else{  $a=3$b=2;  }
                                    
$DlcSeq=$oDlc2->DlcSeq-$a;   
                                    
$DlcSeq2=$oDlc2->DlcSeq-$b
                                    
$oDlc4->SearchByNextDlcID($DlcSeq,$oDlc2->docGroup,$oDlc2->deptId); $oDlc4->GetRecord();   $DLCID2=$oDlc4->DlcID;
                                    
$oDlc5->SearchByNextDlcID($DlcSeq2,$oDlc2->docGroup,$oDlc2->deptId); $oDlc5->GetRecord();  $DlcPS22=$oDlc5->DlcID;
                                    
$k $oDoc3->SearchCountSendDocFirstPage($DLCID2,$Maxgroup,$DlcPS22);
                                    
$list.="<worklistamount>".$k."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
$list.="</mainworklist>";
                                    
$list.="</workgroup>";
                        }
                }
            } 
//--umusergroup
            
            //------------------------------head in dept----------------------------------------------------------------
            
if($oUg->UgGpID==SearchGroupHeadDept()){
                
$oDlp3->SearchByGpID(SearchGroupHeadDept());
                while(
$oDlp3->GetRecord()){
                        
$group3=0;
                        
$oDlc2->SearchByPsPositionDlpIDActiveY($personId,$oDlp3->DlpID,$Maxgroup);
                        while(
$oDlc2->GetRecord()){
                                    
$list.="<workgroup>";
                                    
$oDP->SearchByKey($oDlc2->deptId);
                                    
$oDP->GetRecord(); 
                                    
                                    if(
$oDlp3->DlpPID!="0"){ 
                                            
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp3->DlpPID,$oDlc2->deptId);
                                    }else{
                                            
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp3->DlpPID,$oDlc2->deptId);
                                    }    

                                    
$list.="<positionname>".iconv('TIS-620''UTF-8',$oDlp3->DlpName)."(".iconv('TIS-620''UTF-8',$oDP->deptName).")</positionname>";
                                    
$list.="<dlcid> ".$oDlc2->DlcID." </dlcid>";
                                    
$list.="<mainworklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sign_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือที่ยังไม่ได้ลงนาม</worklisttypename>";
                                    
$i=0;
                                    
$i =$oDoc->SearchCountDocIDByDocGroupDsID2DocIDDlcIDDrsReceiveDlcID2Status2($Maxgroup,$oDlc2->DlcID,$DlcPS2);
                                    
$list.="<worklistamount>".$i."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sendBack_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือแจ้งการส่งผิด</worklisttypename>";
                                    
$j=0;
                                    
$j =$oRs->SearchCountDrsIDByDlcIDDocGroupDrsSendBackDrsSendBackDlcID($oDlc2->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$j."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>send_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือลงนามแล้วรอส่ง</worklisttypename>";
                                    
$k=0;    
                                    
$DlcSeq=$oDlc2->DlcSeq-$a;   
                                    
$DlcSeq2=$oDlc2->DlcSeq-$b
                                    
$oDlc4->SearchByNextDlcID($DlcSeq,$oDlc2->docGroup,$oDlc2->deptId); $oDlc4->GetRecord();   $DLCID2=$oDlc4->DlcID;
                                    
$oDlc5->SearchByNextDlcID($DlcSeq2,$oDlc2->docGroup,$oDlc2->deptId); $oDlc5->GetRecord();  $DlcPS22=$oDlc5->DlcID;
                                    
$k $oDoc3->SearchCountSendDocFirstPage($DLCID2,$Maxgroup,$DlcPS22);
                                    
$list.="<worklistamount>".$k."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";
                                    
$list.="</mainworklist>";
                                    
$list.="</workgroup>";

                        }
                }

            } 
//--umusergroup
            
            //------------------------------header----------------------------------------------------------------
            
if($oUg->UgGpID==SearchGroupBoss()){  
                
$oDlp4->SearchByGpID(SearchGroupBoss());
                while(
$oDlp4->GetRecord()){ 
                        
$group4=0
                        
$oDlc2->SearchByPsPositionDlpIDActiveY($personId,$oDlp4->DlpID,$Maxgroup);
                        while(
$oDlc2->GetRecord()){
                                    
$list.="<workgroup>";                    

                                    
$oDP->SearchByKey($oDlc2->deptId);
                                    
$oDP->GetRecord(); 

                                            if(
$oDlp4->DlpPID!="0"){ 
                                                
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp4->DlpPID,$oDlc2->deptId);
                                            }else{
                                                
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp4->DlpPID,$oDlc2->deptId);
                                            }

                                    
$list.="<positionname>".iconv('TIS-620''UTF-8',$oDlp4->DlpName)."(".iconv('TIS-620''UTF-8',$oDP->deptName).")</positionname>";
                                    
$list.="<dlcid> ".$oDlc2->DlcID." </dlcid>";
                                    
$list.="<mainworklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sign_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือที่ยังไม่ได้ลงนาม</worklisttypename>";
                                    
$i=0;
                                    
$i =$oDoc->SearchCountDocIDByDocGroupDsID2DocIDDlcIDDrsReceiveDlcID2Status2($Maxgroup,$oDlc2->DlcID,$DlcPS2);
                                    
$list.="<worklistamount>".$i."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sendBack_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือแจ้งการส่งผิด</worklisttypename>";
                                    
$j=0;
                                    
$j =$oRs->SearchCountDrsIDByDlcIDDocGroupDrsSendBackDrsSendBackDlcID($oDlc2->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$j."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>send_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือลงนามแล้วรอส่ง</worklisttypename>";
                                    
$k=0;    
                                    
$DlcSeq=$oDlc2->DlcSeq-$a;   
                                    
$DlcSeq2=$oDlc2->DlcSeq-$b
                                    
$oDlc4->SearchByNextDlcID($DlcSeq,$oDlc2->docGroup,$oDlc2->deptId); $oDlc4->GetRecord();   $DLCID2=$oDlc4->DlcID;
                                    
$oDlc5->SearchByNextDlcID($DlcSeq2,$oDlc2->docGroup,$oDlc2->deptId); $oDlc5->GetRecord();  $DlcPS22=$oDlc5->DlcID;
                                    
$k $oDoc3->SearchCountSendDocFirstPage($DLCID2,$Maxgroup,$DlcPS22);
                                    
$list.="<worklistamount>".$k."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";
                                    
$list.="</mainworklist>";
                                    
$list.="</workgroup>";

                        }
                }
            } 
//--umusergroup
            
                //------------------------------head----------------------------------------------------------------
            
if($oUg->UgGpID==SearchGroupBossSecond()){
                
$oDlp3->SearchByGpID(SearchGroupBossSecond());
                while(
$oDlp3->GetRecord()){ 
                        
$group5=0;
                        
$oDlc2->SearchByPsPositionDlpIDActiveY($personId,$oDlp3->DlpID,$Maxgroup);
                        while(
$oDlc2->GetRecord()){
                                    
$list.="<workgroup>";        

                                    
$oDP->SearchByKey($oDlc2->deptId);
                                    
$oDP->GetRecord(); 
                                    

                                            if(
$oDlp3->DlpPID!="0"){ 
                                                
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp3->DlpPID,$oDlc2->deptId);
                                            }else{
                                                
$DlcPS2=$oDlc3->SearchDlc2($oDlc2->DlcSeq,$oDlp3->DlpPID,$oDlc2->deptId);
                                            }

                                    
$list.="<positionname>".iconv('TIS-620''UTF-8',$oDlp3->DlpName)."(".iconv('TIS-620''UTF-8',$oDP->deptName).")</positionname>";
                                    
$list.="<dlcid> ".$oDlc2->DlcID." </dlcid>";
                                    
$list.="<mainworklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sign_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือที่ยังไม่ได้ลงนาม</worklisttypename>";
                                    
$i=0;

                                        if(
$oDlp3->DlpPID!="0"){ 
                                            
$i$oDoc->SearchCountDocIDByDocGroupDsID2DocIDDlcIDDrsReceiveDlcID2StatusR($Maxgroup,$oDlc2->DlcID,$DlcPS2);
                                        }else{  
                                            
$i$oDoc->SearchCountDocIDByDocGroupDsID2DocIDDlcIDDrsReceiveDlcID2Status2($Maxgroup,$oDlc2->DlcID,$DlcPS2);
                                        }    
                                    
$list.="<worklistamount>".$i."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>sendBack_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือแจ้งการส่งผิด</worklisttypename>";
                                    
$j=0;
                                    
$j =$oRs->SearchCountDrsIDByDlcIDDocGroupDrsSendBackDrsSendBackDlcID($oDlc2->DlcID,$Maxgroup,$DlcPS2);
                                    
$list.="<worklistamount>".$j."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>send_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือลงนามแล้วรอส่ง</worklisttypename>";
                                    
$k=0;    
                                    
$DlcSeq=$oDlc2->DlcSeq-$a;   
                                    
$DlcSeq2=$oDlc2->DlcSeq-$b
                                    
$oDlc4->SearchByNextDlcID($DlcSeq,$oDlc2->docGroup,$oDlc2->deptId); $oDlc4->GetRecord();   $DLCID2=$oDlc4->DlcID;
                                    
$oDlc5->SearchByNextDlcID($DlcSeq2,$oDlc2->docGroup,$oDlc2->deptId); $oDlc5->GetRecord();  $DlcPS22=$oDlc5->DlcID;
                                    
$k $oDoc3->SearchCountSendDocFirstPage($DLCID2,$Maxgroup,$DlcPS22);
                                    
$list.="<worklistamount>".$k."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                                    
$list.="</mainworklist>";
                                    
$list.="</workgroup>";

                        }
                }

            } 
//--umusergroup

            //-------------------------------person----------------------------------------------------------------------
            
if($oUg->UgGpID==SearchGroupUsers()){
                    
$list.="<workgroup>";    
                    
$list.="<positionname>ผู้ใช้ทั่วไป</positionname>";
                    
$list.="<dlcid> ".'0'." </dlcid>";
                    
$list.="<mainworklist>";
                    
$i=0;
                    
$i $oRs2->SearchCountBypersonIdDocGroupDsID0($personId,$Maxgroup); 
                                    
//----------------------------------
                                    
$list.="<worklist>";
                                    
$list.="<worklisttype>entry_doc</worklisttype>";
                                    
$list.="<worklisttypename>รายการหนังสือเข้าที่ยังไม่ได้เปิดอ่าน</worklisttypename>";
                                    
$list.="<worklistamount>".$i."</worklistamount>";
                                    
$list.="<worklistunit>ฉบับ</worklistunit>";
                                    
$list.="</worklist>";

                    
$list.="</mainworklist>";
                    
$list.="</workgroup>";
            } 

    } 
//end while umusergroup
    
$list.='</work>';
    echo 
$list;

}else if(
$fn=='receivedoc'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);
    
    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"../class/clsDepartment.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"funct.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"functforRptEx.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
    
$oDP = new Department($oC);
    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlc3 = new DocLineConfig($oC);
    
$oDlc4 = new DocLineConfig($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDoc = new Documents($oC);
    
$oDoc5 = new Documents($oC);
    
$MaxDocGroup=$oDP->SearchMaxDocGroup();

        
$oDlc->SearchByKey($dlcid); $oDlc->GetRecord(); 
        
$oDlp1->SearchByKey($oDlc->DlpID);  $oDlp1->GetRecord();
        
$deptcenter=checkSarabunMain($oDlc->DlpID);  //$deptcenter=1
        
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);

                    if(
$oDlp1->GsarabunHead=="Y" || $oDlp1->GheadDept=="Y" || $oDlp1->Gboss=="Y" || $oDlp1->Gboss2=="Y"){ 
                            
$DlcSeq=$oDlc->DlcSeq-$a;   
                            
$DlcSeq2=$oDlc->DlcSeq-$b
                            
$oDlc3->SearchByNextDlcID($DlcSeq,$oDlc->docGroup,$oDlc->deptId); $oDlc3->GetRecord();   $searchDLCID=$oDlc3->DlcID;
                            
$oDlc4->SearchByNextDlcID($DlcSeq2,$oDlc->docGroup,$oDlc->deptId); $oDlc4->GetRecord();  $searchDlcPS2=$oDlc4->DlcID;    
                    }else{
                        
$searchDLCID=$dlcid;
                        
$searchDlcPS2=$DlcPS2;
                    }
            
                        
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';
                        
$oDoc->SearchDetailReceiveMoblie($searchDLCID,$MaxDocGroup,$searchDlcPS2);
                        while(
$oDoc->GetRecord()){ 
                            
$DocFrom='';
                            
$DocSubject='';
                            
//echo $oDoc->DocID.'<br>';
                            
$list.='<booklist>';
                            
$list.='<DocNo>'.iconv('TIS-620''UTF-8',$oDoc->DocNo).'</DocNo>';
                            
$list.='<DocDate>'.iconv('TIS-620''UTF-8',abbreDateMoblie($oDoc->DocDate)).'</DocDate>';


                            if(
$oDoc->DtID=="1" || $oDoc->DtID=="2" || $oDoc->DtID=="14"){
                                                
$DocFrom=$oDoc->DocFrom."<br>";
                            }else{
                                        if(
$oDoc->DocPID=="0"){
                                                
$oDlc2->SearchByKey($oDoc->DlcID); $oDlc2->GetRecord();
                                                
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();
                                        }else{
                                                
$oDoc5->SearchByKey($oDoc->DocPID); $oDoc5->GetRecord();
                                                
$oDlc2->SearchByKey($oDoc5->DlcID); $oDlc2->GetRecord();
                                                
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();
                                        }
                                                
$DocFrom=$oDoc->DocFrom."(".$oDlp->DlpName.")";
                            }    
                            
$list.='<deptName>'.iconv('TIS-620''UTF-8',$oDoc->DocFrom).'</deptName>';
                            if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
                            
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';
                            
$list.='<DrsReceiveDate>'.iconv('TIS-620''UTF-8',abbreDateTimeMoblie($oDoc->DrsReceiveDate)).'</DrsReceiveDate>';

                            
$list.='<DocID>'.iconv('TIS-620''UTF-8',$oDoc->DocID).'</DocID>';
                            
$list.='<RsID>'.iconv('TIS-620''UTF-8',$oDoc->RsID).'</RsID>';
                            
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oDoc->DtID).'</DtID>';
                            
$list.='<DrsID>'.iconv('TIS-620''UTF-8',$oDoc->DrsID).'</DrsID>';                            
                            
$list.='</booklist>';
                        }
                        
$list.='</book>';

    echo 
$list;
}else if(
$fn=='entry_doc'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"functforRptEx.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oRs = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDoc4 = new Documents($oC);
    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDlp1 = new docLinePosition($oC);

                
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';
                   
$oRs->SearchBypersonIdDrsDeleteMoblie($personId);                 
                  while(
$oRs->GetRecord()){ 
                        
$oDoc->SearchByKey($oRs->DocID); $oDoc->GetRecord();
                        
$list.='<booklist>';
                        
$list.='<DocNo>'.iconv('TIS-620''UTF-8',$oDoc->DocNo).'</DocNo>';

                          if(
$oDoc->DtID=="1" || $oDoc->DtID=="2" || $oDoc->DtID=="14"){
                                            
$list.='<deptName>'.iconv('TIS-620''UTF-8',$oDoc->DocFrom).'</deptName>';
                          }else{
                                if(
$oDoc->DocPID=="0"){
                                        
$oDlc2->SearchByKey($oDoc->DlcID); $oDlc2->GetRecord();
                                        
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();
                                        
$DocFrom=$oDoc->DocFrom."(".$oDlp->DlpName.")";
                                        
$list.='<deptName>'.iconv('TIS-620''UTF-8',$DocFrom).'</deptName>';
                                }else{
                                        
$oDoc4->SearchByKey($oDoc->DocPID); $oDoc4->GetRecord();
                                        
$oDlc2->SearchByKey($oDoc4->DlcID); $oDlc2->GetRecord();
                                        
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();
                                        
$DocFrom=$oDoc->DocFrom."(".$oDlp->DlpName.")";
                                        
$list.='<deptName>'.iconv('TIS-620''UTF-8',$DocFrom).'</deptName>';
                                }
                            }

                        
                        if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
                        
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';
                        
$list.='<DrsReceiveDate>'.iconv('TIS-620''UTF-8',abbreDateTimeMoblie($oRs->DrsReceiveDate)).'</DrsReceiveDate>';
                        
$list.='<DocID>'.iconv('TIS-620''UTF-8',$oDoc->DocID).'</DocID>';
                        
$list.='<RsID>'.iconv('TIS-620''UTF-8',$oDoc->RsID).'</RsID>';
                        
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oDoc->DtID).'</DtID>';
                        
$list.='<DrsID>'.iconv('TIS-620''UTF-8',$oRs->DrsID).'</DrsID>';                            
                        
$list.='</booklist>';
                        
                }
                
$list.='</book>';
    echo 
$list;    
}else if(
$fn=='sign_doc'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"../class/clsDepartment.php";
    include_once 
"functforRptEx.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oRs = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDoc4 = new Documents($oC);
    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$oDP = new Department($oC);
    
$MaxDocGroup=$oDP->SearchMaxDocGroup();

        
$oDlc->SearchByKey($dlcid); $oDlc->GetRecord(); 
        
$oDlp1->SearchByKey($oDlc->DlpID);  $oDlp1->GetRecord();


                if(
$oDlp1->DlpPID!="0"){   
                                
$DlcPS2=$dlcid;
                                
$buddy=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                                
$oDoc->SearchDetailSignMoblie($MaxDocGroup,$dlcid,$DlcPS2,$buddy);
                }else{
                                
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                                
$oDoc->SearchDetailSignMoblie2($MaxDocGroup,$dlcid,$DlcPS2);
                }

                
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';    
                  while(
$oDoc->GetRecord()){ 
                        
$list.='<booklist>';
                        
$list.='<DocNo>'.iconv('TIS-620''UTF-8',$oDoc->DocNo).'</DocNo>';
                        
$list.='<DocDate>'.iconv('TIS-620''UTF-8',abbreDateMoblie($oDoc->DocDate)).'</DocDate>';


                            if(
$oDoc->DtID=="1" || $oDoc->DtID=="2" || $oDoc->DtID=="14"){
                                        
$list.='<deptName>'.iconv('TIS-620''UTF-8',$oDoc->DocFrom).'</deptName>';
                            }else{
                                if(
$oDoc->DocPID=="0"){
                                        
$oDlc2->SearchByKey($oDoc->DlcID); $oDlc2->GetRecord();
                                        
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();                        
                                }else{
                                        
$oD_DlcID=$oDoc4->SearchDlcID($oDoc->DocPID); 
                                        
$oDlc2->SearchByKey($oD_DlcID); $oDlc2->GetRecord();
                                        
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();
                                    
                                }        
                                        
$DocFrom=$oDoc->DocFrom."(".$oDlp->DlpName.")";
                                        
$list.='<deptName>'.iconv('TIS-620''UTF-8',$DocFrom).'</deptName>';
                            }

                        if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
                        
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';
                        
$list.='<DocID>'.iconv('TIS-620''UTF-8',$oDoc->DocID).'</DocID>';
                        
$list.='<RsID>'.iconv('TIS-620''UTF-8',$oDoc->RsID).'</RsID>';
                        
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oDoc->DtID).'</DtID>';
                        
$list.='<DrsID>'.iconv('TIS-620''UTF-8',$oDoc->DrsID).'</DrsID>';                            
                        
$list.='</booklist>';
                        
                }
                
$list.='</book>';
    echo 
$list;    
}else if(
$fn=='sendBack_doc'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"../class/clsDepartment.php";
    include_once 
"../class/clsPerson.php";
    include_once 
"getPrefix.php";
    include_once 
"functforRptEx.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oRs = new DocReceiveSend($oC);
    
$oRs4 = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDoc6 = new Documents($oC);
    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDP = new Department($oC);
    
$oPS = new person($oC);
    
$MaxDocGroup=$oDP->SearchMaxDocGroup();

        
$oDlc->SearchByKey($dlcid); $oDlc->GetRecord(); 
        
$oDlp1->SearchByKey($oDlc->DlpID);  $oDlp1->GetRecord();


                if(
$oDlp1->DlpPID!="0"){ 
                    
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                 }else{
                    
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                }

                
$oRs->SearchDetailSendBackDocMoblie($dlcid,$MaxDocGroup,$DlcPS2);

                
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';    
                  while(
$oRs->GetRecord()){ 
                        
$oDoc6->SearchDocID($oRs->DocID);
                        
$oDoc6->GetRecord();
                        if(
$oDoc6->DocPID=="0" || $oDoc6->DocPID==""){  $searchDoc=$oDoc6->DocID; }else{ $searchDoc=$oDoc6->DocPID; }
                                            
                        
$oDoc->SearchByKey($searchDoc);
                        
$oDoc->GetRecord();
                        
$oRs4->SearchByDocIDDsID3($searchDoc);
                        
$oRs4->GetRecord();

                        
$list.='<booklist>';
                        
$list.='<DocNo>'.iconv('TIS-620''UTF-8',$oDoc->DocNo).'</DocNo>';
                        if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
                        
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';

                        if(
$oRs->DlcID==0){    
                                            
$oPS->SearchByKey($oRs->personId); $oPS->GetRecord();  
                                            
$sendername=GetPrefix($oPS->prefixId).$oPS->fName." ".$oPS->lName
                                            
$list.='<personSendBack>'.iconv('TIS-620''UTF-8',$sendername).'</personSendBack>';
                                            
$list.='<DrsSendBack>'.iconv('TIS-620''UTF-8',$oRs->DrsSendBack).'</DrsSendBack>';
                                            
$list.='<DrsReceiveDate>'.iconv('TIS-620''UTF-8',abbreDateTimeMoblie($oRs->DrsReceiveDate)).'</DrsReceiveDate>';                                    
                        }else{
                                        
$oDlc2->SearchByKey($oRs->DlcID); $oDlc2->GetRecord(); 
                                        
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();
                                        
$oPS->SearchByKey($oRs->DrsPsIDCreate); $oPS->GetRecord();  
                                        
$sendername=GetPrefix($oPS->prefixId).$oPS->fName." ".$oPS->lName."(".$oDlp->DlpName.")"
                                        
$list.='<personSendBack>'.iconv('TIS-620''UTF-8',$sendername).'</personSendBack>';
                                        
$list.='<DrsSendBack>'.iconv('TIS-620''UTF-8',$oRs->DrsSendBack).'</DrsSendBack>';
                                        
$list.='<DrsReceiveDate>'.iconv('TIS-620''UTF-8',abbreDateTimeMoblie($oRs->DrsReceiveDate)).'</DrsReceiveDate>';
                        }

                        
$list.='<DocID>'.iconv('TIS-620''UTF-8',$oDoc->DocID).'</DocID>';
                        
$list.='<RsID>'.iconv('TIS-620''UTF-8',$oDoc->RsID).'</RsID>';
                        
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oDoc->DtID).'</DtID>';
                        
$list.='<DrsID>'.iconv('TIS-620''UTF-8',$oRs4->DrsID).'</DrsID>';                            
                        
$list.='</booklist>';
                        
                }
                
$list.='</book>';
    echo 
$list;    
}else if(
$fn=='send_doc'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"../class/clsDepartment.php";
    include_once 
"functforRptEx.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oRs = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDoc4 = new Documents($oC);
    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlc3 = new DocLineConfig($oC);
    
$oDlc4 = new DocLineConfig($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$oDP = new Department($oC);
    
$MaxDocGroup=$oDP->SearchMaxDocGroup();

        
$oDlc->SearchByKey($dlcid); $oDlc->GetRecord(); 
        
$oDlp1->SearchByKey($oDlc->DlpID);  $oDlp1->GetRecord();

                   if(
$oDlp1->GsarabunHead=="Y" || $oDlp1->GheadDept=="Y" || $oDlp1->Gboss=="Y" || $oDlp1->Gboss2=="Y"){ 
                                if(
$oDlp1->DlpPID=="0"){  $a=2$b=1;   }else{  $a=3$b=2;  }
                                
$DlcSeq=$oDlc->DlcSeq-$a;   
                                
$DlcSeq2=$oDlc->DlcSeq-$b
                                
$oDlc3->SearchByNextDlcID($DlcSeq,$oDlc->docGroup,$oDlc->deptId); $oDlc3->GetRecord();   $DLCID2=$oDlc3->DlcID;
                                
$oDlc4->SearchByNextDlcID($DlcSeq2,$oDlc->docGroup,$oDlc->deptId); $oDlc4->GetRecord();  $DlcPS22=$oDlc4->DlcID;
                                
$oDoc->SearchSendDocMoblie($DLCID2,$MaxDocGroup,$DlcPS22,$dlcid);
                }else{
                                
$oDoc->SearchSendDocMoblie2($dlcid,$MaxDocGroup,$DlcPS2,$dlcid);                                
                }

                
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';    
                  while(
$oDoc->GetRecord()){ 
                        
$list.='<booklist>';
                        
$list.='<DocTypeNo>'.$oDoc->DocTypeNo.'</DocTypeNo>';
                        
$list.='<DocNo>'.iconv('TIS-620''UTF-8',$oDoc->DocNo).'</DocNo>';
                        
$list.='<DocDate>'.iconv('TIS-620''UTF-8',abbreDateMoblie($oDoc->DocDate)).'</DocDate>';


                            if(
$oDoc->DocPID=="0"){
                                    
$oDlc2->SearchByKey($oDoc->DlcID); $oDlc2->GetRecord();
                                    
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();                    
                            }else{
                                    
$od_DlcID=$oDoc4->SearchDlcID($oDoc->DocPID); 
                                    
$oDlc2->SearchByKey($od_DlcID); $oDlc2->GetRecord();
                                    
$oDlp->SearchByKey($oDlc2->DlpID);  $oDlp->GetRecord();
                            }        

                        if(
$oDoc->DtID=="1" || $oDoc->DtID=="2" || $oDoc->DtID=="14"){
                                
$DocFrom=$oDoc->DocFrom;
                        }else{  
                                
$DocFrom=$oDoc->DocFrom."(".$oDlp->DlpName.")";
                                
                        }
                        
$list.='<deptName>'.iconv('TIS-620''UTF-8',$DocFrom).'</deptName>';
                        if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
                        
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';
                        
$list.='<DocID>'.iconv('TIS-620''UTF-8',$oDoc->DocID).'</DocID>';
                        
$list.='<RsID>'.iconv('TIS-620''UTF-8',$oDoc->RsID).'</RsID>';
                        
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oDoc->DtID).'</DtID>';
                        
$list.='<DrsID>'.iconv('TIS-620''UTF-8',$oDoc->DrsID).'</DrsID>';                            
                        
$list.='</booklist>';                
                }
                
$list.='</book>';
    echo 
$list;    

}else if(
$fn=='receiveEdoc'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"../class/clsSendReceive.php";
    include_once 
"../class/clsCollegeDetail.php";
    include_once 
"functforRptEx.php";    

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlc3 = new DocLineConfig($oC);
    
$oDlc4 = new DocLineConfig($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$oTsr = new sendreceive($oC);
    
$oTsr2 = new sendreceive($oC);
    
$oTsr3 = new sendreceive($oC);
    
$oCd = new collegedetail($oC);
    
$oCd2 = new collegedetail($oC);
    
$oCd3 = new collegedetail($oC);

        
$oDlc->SearchByKey($dlcid); $oDlc->GetRecord(); 
        
$oDlp1->SearchByKey($oDlc->DlpID);  $oDlp1->GetRecord();

        if(
SearchSendAll_receive($oDlc->DlpID)=="All"){
                
$oTsr->SearchDocEMoblie(r1);
                
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';    
                  while(
$oTsr->GetRecord()){ 
                        
$list.='<booklist>';
                        
$list.='<DocNo>'.iconv('TIS-620''UTF-8',$oTsr->tsr_DocNo).'</DocNo>';
                        
$list.='<DocDate>'.iconv('TIS-620''UTF-8',abbreDateMoblie($oTsr->tsr_DocDate)).'</DocDate>';
                        
$oCd2->SearchByKey($oTsr->tsr_fr_node); $oCd2->GetRecord(); 
                        
$DocSubject=$oTsr->tsr_DocSubject.'('.iconv('UTF-8''TIS-620','จาก').$oCd2->collegeAbbr.')'
                        
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';
                        
$list.='<DrsReceiveDate>'.iconv('TIS-620''UTF-8',abbreDateTimeMoblie($oTsr->tsr_to_node_date)).'</DrsReceiveDate>';
                        
$list.='<RsID>1</RsID>';
                        
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oTsr->tsr_DtID).'</DtID>';        
                        
$list.='<trs_id>'.iconv('TIS-620''UTF-8',$oTsr->tsr_id).'</trs_id>';                                
                        
$list.='</booklist>';                
                }
                
$list.='</book>';
    echo 
$list;    

        }
}else if(
$fn=='statusDocforSign'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"../class/clsDepartment.php";
    include_once 
"../class/clsDocForSign.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oRs = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDoc4 = new Documents($oC);
    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlc3 = new DocLineConfig($oC);
    
$oDlc4 = new DocLineConfig($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$oDP = new Department($oC);
    
$oDfs = new DocForSign($oC);
    
$MaxDocGroup=$oDP->SearchMaxDocGroup();

        
$oDlc->SearchByKey($dlcid); $oDlc->GetRecord(); 
        
$oDlp1->SearchByKey($oDlc->DlpID);  $oDlp1->GetRecord();

                if(
$oDlp1->DlpPID!="0"){ 
                    
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                 }else{
                    
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                }

                if(
$oDlp1->GsarabunHead=="Y" || $oDlp1->GheadDept=="Y" || $oDlp1->Gboss=="Y" || $oDlp1->Gboss2=="Y"){ 
                        if(
$oDlp->DlpPID=="0"){  $a=2$b=1;   }else{  $a=3$b=2;  }
                                
$DlcSeq=$oDlc->DlcSeq-$a;   
                                
$DlcSeq2=$oDlc->DlcSeq-$b
                                
$oDlc3->SearchByNextDlcID($DlcSeq,$oDlc->docGroup,$oDlc->deptId); $oDlc3->GetRecord();   $DLCID2=$oDlc3->DlcID;
                            
                                if(
$oDlp->DlpPID=="0"){  
                                    
$oDlc4->SearchByNextDlcID($DlcSeq2,$oDlc->docGroup,$oDlc->deptId); $oDlc4->GetRecord();  $DlcPS22=$oDlc4->DlcID;
                                }else{ 
                                    
$oDlc4->SearchByNextDlcID($DlcSeq2,$oDlc->docGroup,$oDlc->deptId); $oDlc4->GetRecord();  $DlcPS22=$oDlc4->DlcID;
                                }
                                
$oDoc->SearchGetDocForSignDlcIDMoblie($MaxDocGroup,$DLCID2,$DlcPS22);
                }else{
                    
$oDoc->SearchGetDocForSignDlcIDMoblie($MaxDocGroup,$dlcid,$DlcPS2);
                    
                }

                
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';    
                  while(
$oDoc->GetRecord()){ 
                        
$list.='<booklist>';
                        
$list.='<DocTypeNo>'.$oDoc->DocTypeNo.'</DocTypeNo>';
                        if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
                        
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';
                        
$list.='<DocID>'.iconv('TIS-620''UTF-8',$oDoc->DocID).'</DocID>';
                        
$list.='<RsID>'.iconv('TIS-620''UTF-8',$oDoc->RsID).'</RsID>';
                        
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oDoc->DtID).'</DtID>';                    
                        
$list.='</booklist>';                
                }
                
$list.='</book>';
    echo 
$list;    

}else if(
$fn=='statusDocforSignEdit'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$dlcid = (! isset($_REQUEST['dlcid'])? "" $_REQUEST['dlcid']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocLinePosition.php";
    include_once 
"../class/clsDepartment.php";
    include_once 
"../class/clsDocForSign.php";
    include_once 
"../class/clsPerson.php";
    include_once 
"getPrefix.php";
    include_once 
"functforRptEx.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oRs = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDoc4 = new Documents($oC);
    
$oDlc = new DocLineConfig($oC);
    
$oDlc2 = new DocLineConfig($oC);
    
$oDlc3 = new DocLineConfig($oC);
    
$oDlc4 = new DocLineConfig($oC);
    
$oDlc5 = new DocLineConfig($oC);
    
$oDlp = new docLinePosition($oC);
    
$oDlp1 = new docLinePosition($oC);
    
$oDlp2 = new docLinePosition($oC);
    
$oDP = new Department($oC);
    
$oDP4 = new Department($oC);
    
$oDfs = new DocForSign($oC);
    
$oPS = new person($oC);
    
$MaxDocGroup=$oDP->SearchMaxDocGroup();

        
$oDlc->SearchByKey($dlcid); $oDlc->GetRecord(); 
        
$oDlp1->SearchByKey($oDlc->DlpID);  $oDlp1->GetRecord();

                if(
$oDlp1->DlpPID!="0"){ 
                    
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                 }else{
                    
$DlcPS2=$oDlc2->SearchDlc2($oDlc->DlcSeq,$oDlp1->DlpPID,$oDlc->deptId);
                }

                if(
$oDlp1->GsarabunHead=="Y" || $oDlp1->GheadDept=="Y" || $oDlp1->Gboss=="Y" || $oDlp1->Gboss2=="Y"){ 
                        if(
$oDlp->DlpPID=="0"){  $a=2$b=1;   }else{  $a=3$b=2;  }
                                
$DlcSeq=$oDlc->DlcSeq-$a;   
                                
$DlcSeq2=$oDlc->DlcSeq-$b
                                
$oDlc3->SearchByNextDlcID($DlcSeq,$oDlc->docGroup,$oDlc->deptId); $oDlc3->GetRecord();   $DLCID2=$oDlc3->DlcID;
                            
                                if(
$oDlp->DlpPID=="0"){  
                                    
$oDlc4->SearchByNextDlcID($DlcSeq2,$oDlc->docGroup,$oDlc->deptId); $oDlc4->GetRecord();  $DlcPS22=$oDlc4->DlcID;
                                }else{ 
                                    
$oDlc4->SearchByNextDlcID($DlcSeq2,$oDlc->docGroup,$oDlc->deptId); $oDlc4->GetRecord();  $DlcPS22=$oDlc4->DlcID;
                                }
                                
$oDoc->SearchGetDocForSignDlcIDDocforsignEditMoblie($MaxDocGroup,$DLCID2,$DlcPS22);
                }else{
                    
$oDoc->SearchGetDocForSignDlcIDDocforsignEditMoblie($MaxDocGroup,$dlcid,$DlcPS2);
                    
                }

                
$list='<?xml version="1.0" encoding="UTF-8" ?><book>';    
                  while(
$oDoc->GetRecord()){ 
                        
$list.='<booklist>';
                        
$list.='<DocTypeNo>'.$oDoc->DocTypeNo.'</DocTypeNo>';
                        if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
                        
$list.='<docSubject>'.iconv('TIS-620''UTF-8',$DocSubject).'</docSubject>';
                        
$oPS->SearchByKey($oDoc->psComment); $oPS->GetRecord();  
                        
$oDlc5->SearchByKey($oDoc->DlcIDsign);  $oDlc5->GetRecord();    
                        
$oDlp2->SearchByKey($oDlc5->DlpID);  $oDlp2->GetRecord();   
                        
$oDP4->SearchByKey($oDoc->DeptSign);  $oDP4->GetRecord();

                        
$sendername=GetPrefix($oPS->prefixId).$oPS->fName." ".$oPS->lName
                        
$list.='<personSendEdit>'.iconv('TIS-620''UTF-8',$sendername).'('.iconv('TIS-620''UTF-8',$oDlp2->DlpName).')'.'</personSendEdit>';
                        
$list.='<deptName>'.iconv('TIS-620''UTF-8',$oDP4->deptName).'</deptName>';
                        
$list.='<SendEdit>'.iconv('TIS-620''UTF-8',$oDoc->DocEditComment).'</SendEdit>';
                        
$list.='<DrsReceiveDate>'.iconv('TIS-620''UTF-8',abbreDateTimeMoblie($oDoc->DocNoticeDate)).'</DrsReceiveDate>';
                        
$list.='<DocID>'.iconv('TIS-620''UTF-8',$oDoc->DocID).'</DocID>';
                        
$list.='<RsID>'.iconv('TIS-620''UTF-8',$oDoc->RsID).'</RsID>';
                        
$list.='<DtID>'.iconv('TIS-620''UTF-8',$oDoc->DtID).'</DtID>';                    
                        
$list.='</booklist>';                
                }
                
$list.='</book>';
    echo 
$list;    

}else if(
$fn=='workListDetail'){
    
$personId = (! isset($_REQUEST['personId'])? "" $_REQUEST['personId']);
    
$DocID = (! isset($_REQUEST['DocID'])? "" $_REQUEST['DocID']);
    
$RsID = (! isset($_REQUEST['RsID'])? "" $_REQUEST['RsID']);
    
$DtID = (! isset($_REQUEST['DtID'])? "" $_REQUEST['DtID']);
    
$DlcID = (! isset($_REQUEST['DlcID'])? "" $_REQUEST['DlcID']);
    
$DrsID = (! isset($_REQUEST['DrsID'])? "" $_REQUEST['DrsID']);
    
$type = (! isset($_REQUEST['type'])? "" $_REQUEST['type']);

    include_once(
"../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../link/keyThai.php";
    include_once 
"functforRptEx.php";
    include_once 
"../class/clsDocSpeedLevel.php";
    include_once 
"../class/clsDocSecreLevel.php";
    include_once 
"../class/clsDocattatches.php";
    include_once 
"../class/clsSendReceive.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);

    
$oRs = new DocReceiveSend($oC);
    
$oDoc = new Documents($oC);
    
$oDsl = new DocSpeedLevel($oC);
    
$oDcl = new DocSecretLevel($oC);
    
$oDatt = new Docattatches($oC);
    
$oDatt2 = new Docattatches($oC);
    
$oTsr = new sendreceive($oC);

    if(
$type!='receiveEdoc'){
    
        if(
$type=='entry_doc'){ // ปรับสถานะว่าเปิดหนังสือแล้ว
            
$oRs->SearchByKey($DrsID); $oRs->GetRecord(); 
            if(
$oRs->DsID=="0"){
                    
UpdatereadDoc($oRs->DrsID,$DocID,"Y");
            }
        }
        
        
$oDoc->SearchByKey($DocID); $oDoc->GetRecord();
        if(
$oDoc->DocDate!="" && $oDoc->DocDate!="0000-00-00"){ 
            
$DocDate=abbreDateMoblie($oDoc->DocDate,'/');
        }
        if(
$oDoc->DtID=="13"){  $DocSubject="ชื่อผู้ได้รับการรับรอง<br>".$oDoc->CertificatePs;  }else{  $DocSubject=$oDoc->DocSubject; } 
        
$oDsl->SearchByKey($oDoc->DslID); $oDsl->GetRecord();  $DslID=$oDsl->DslName;
        
$oDcl->SearchByKey($oDoc->DclID); $oDcl->GetRecord();  $DclID=$oDcl->DclName;
        if(
$oDoc->endDoc=="Y"){  $endDoc="Y";  }else{  $endDoc="";   }


        
$list='<?xml version="1.0" encoding="UTF-8" ?><BookDetail>';    
        
$list.='<DocNo>'.iconv('TIS-620''UTF-8',isset($oDoc->DocNo)?$oDoc->DocNo:"-").'</DocNo>';
        
$list.='<DocDate>'.iconv('TIS-620''UTF-8',isset($DocDate)?$DocDate:"-").'</DocDate>';
        
$list.='<DocSubject>'.iconv('TIS-620''UTF-8',isset($DocSubject)?$DocSubject:"-").'</DocSubject>';
        
$list.='<DocFrom>'.iconv('TIS-620''UTF-8',isset($oDoc->DocFrom)?$oDoc->DocFrom:"-").'</DocFrom>';
        
$list.='<DocTo>'.iconv('TIS-620''UTF-8',isset($oDoc->DocTo)?$oDoc->DocTo:"-").'</DocTo>';
        
$list.='<Docattatches>';    
                            
        if(
$oDoc->DocPID=="0" || $oDoc->DocPID==""){  $searchDoc=$oDoc->DocID; }else{ $searchDoc=$oDoc->DocPID; }   
        
$oDatt->SearchByDocID($searchDoc);
        while(
$oDatt->GetRecord()){  
            
$pathfile="http://".$_SERVER['SERVER_NAME'].'/mispbri/eoffice/documents/'.$oDatt->DaUpFileName;
            
$list.='<docFile><docFilelist>';    
            
$list.='<docFileURL>'.$pathfile.'</docFileURL>';        
            
$list.='<docFileName>'.iconv('TIS-620''UTF-8',$oDatt->DaFileName).'</docFileName>';                    
            
$list.='<docAddNew>N</docAddNew>';                    
            
$list.='</docFilelist></docFile>';    
        } 
        
$oDatt2->SearchByDocIDSended($searchDoc);
        while(
$oDatt2->GetRecord()){  
            
$pathfile2="http://".$_SERVER['SERVER_NAME'].'/mispbri/eoffice/documents/'.$oDatt2->DaUpFileName;
            
$list.='<docFile><docFilelist>';    
            
$list.='<docFileURL>'.$pathfile2.'</docFileURL>';        
            
$list.='<docFileName>'.iconv('TIS-620''UTF-8',$oDatt2->DaFileName).'</docFileName>';                
            
$list.='<docAddNew>Y</docAddNew>';                    
            
$list.='</docFilelist></docFile>';    
        }

        
$list.='</Docattatches>';    


        
$list.='<DocRef>'.iconv('TIS-620''UTF-8',isset($oDoc->DocRef)?$oDoc->DocRef:"-").'</DocRef>';  //อ้างถึง
        
$list.='<DocOther>'.iconv('TIS-620''UTF-8',isset($oDoc->DocOther)?$oDoc->DocOther:"-").'</DocOther>';  //สิ่งที่ส่งมาด้วย
        
$list.='<DocRefAns>'.iconv('TIS-620''UTF-8',isset($oDoc->DocRefAns)?$oDoc->DocRefAns:"-").'</DocRefAns>'//อ้างถึงหนังสือเพื่อตอบกลับ
        
$list.='<DslID>'.iconv('TIS-620''UTF-8',$DslID).'</DslID>'//ชั้นความเร็ว
        
$list.='<DclID>'.iconv('TIS-620''UTF-8',$DclID).'</DclID>'//ชั้นความลับ
        
$list.='<DocDeptOwner>'.iconv('TIS-620''UTF-8',isset($oDoc->DocDeptOwner)?$oDoc->DocDeptOwner:"-").'</DocDeptOwner>'//หน่วยงานเจ้าของเรื่อง
        
$list.='<DocTelOwner>'.iconv('TIS-620''UTF-8',isset($oDoc->DocTelOwner)?$oDoc->DocTelOwner:"-").'</DocTelOwner>'//โทรศัพท์เจ้าของเรื่อง
        
$list.='<DocFaxOwner>'.iconv('TIS-620''UTF-8',isset($oDoc->DocFaxOwner)?$oDoc->DocFaxOwner:"-").'</DocFaxOwner>'//โทรสารเจ้าของเรื่อง
        
$list.='<DocCopySend>'.iconv('TIS-620''UTF-8',isset($oDoc->DocCopySend)?$oDoc->DocCopySend:"-").'</DocCopySend>'//สำเนาส่ง
        
$list.='<DocContactE>'.iconv('TIS-620''UTF-8',isset($oDoc->DocContactE)?$oDoc->DocContactE:"-").'</DocContactE>'//การติดต่อทางอิเล็กทรอนิกส์
        
$list.='<DocShortDesc>'.iconv('TIS-620''UTF-8',isset($oDoc->DocShortDesc)?$oDoc->DocShortDesc:"-").'</DocShortDesc>'//หมายเหตุ
        
$list.='<sendToPs>'.iconv('TIS-620''UTF-8',isset($oDoc->sendToPs)?$oDoc->sendToPs:"-").'</sendToPs>'//ส่งด่วน
        
$list.='<DocSendReal>'.iconv('TIS-620''UTF-8',isset($oDoc->DocSendReal)?$oDoc->DocSendReal:"-").'</DocSendReal>'//ส่งหนังสือตัวจริงตามไปด้วย
        
$list.='<endDoc>'.$endDoc.'</endDoc>'//ยุติหนังสือ
        
$list.='</BookDetail>';
        echo 
$list;    
    
//------------------------------------------------------------------------------------------------------
    
}else{
        
$oTsr->SearchByKey($DocID);
        
$oTsr->GetRecord();

    
        if(
$oTsr->tsr_DocDate!="" && $oTsr->tsr_DocDate!="0000-00-00"){ 
            
$DocDate=abbreDateMoblie($oTsr->tsr_DocDate,'/');
        }
        
$oDsl->SearchByKey($oTsr->tsr_DslID); $oDsl->GetRecord();  $DslID=$oDsl->DslName;
        
$oDcl->SearchByKey($oTsr->tsr_DclID); $oDcl->GetRecord();  $DclID=$oDcl->DclName;
    
        
$list='<?xml version="1.0" encoding="UTF-8" ?><BookDetail>';    
        
$list.='<DocNo>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocNo)?$oTsr->tsr_DocNo:"-").'</DocNo>';
        
$list.='<DocDate>'.iconv('TIS-620''UTF-8',$DocDate).'</DocDate>';    
        
$list.='<DocSubject>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocSubject)?$oTsr->tsr_DocSubject:"-").'</DocSubject>';
        
$list.='<DocFrom>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocFrom)?$oTsr->tsr_DocFrom:"-").'</DocFrom>';
        
$list.='<DocTo>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocTo)?$oTsr->tsr_DocTo:"-").'</DocTo>';
        
$list.='<Docattatches>';    


        
$tsr_docname=$oTsr->tsr_docname;
        
$tsr_statusDocAtt=$oTsr->tsr_statusDocAtt
        
$tsr_doc_url=$oTsr->tsr_doc_url
        
$i=0;
        while(
$tsr_docname!=''){ $i++;
                list(
$downloadfilename,$tsr_docname)=preg_split('[,]',$tsr_docname,2);
                list(
$downloadurl,$tsr_doc_url)=preg_split('[,]',$tsr_doc_url,2);                    
                
$count=strlen($tsr_statusDocAtt);
                if(
$count!=$i){
                        
$statusDoc substr($tsr_statusDocAtt,$i-1,-($count-1-($i-1)));
                }else{
                        
$statusDoc substr($tsr_statusDocAtt,$count-1);
                }        
                

                
$list.='<docFile><docFilelist>';    
                if(
$statusDoc=='Y'){
                            
$file_name basename($downloadurl); 
                            list(
$filename_,$filetype_)=preg_split("/\./",$file_name);
                            
$pathfile=$downloadurl
                            
$list.='<docFileURL>'.$pathfile.'</docFileURL>';        
                            
$list.='<docFileName>'.iconv('TIS-620''UTF-8',$downloadfilename).'</docFileName>';                    
                            
$list.='<docAddNew></docAddNew>';                    
                            
$list.='</docFilelist></docFile>';    
                }else{
                        
//ยังไม่ดาวน์โหลด
                            
$pathfile=''
                            
$list.='<docFileURL>'.$pathfile.'</docFileURL>';        
                            
$list.='<docFileName>'.iconv('TIS-620''UTF-8',$downloadfilename).'(ยังไม่ได้ดาวน์โหลด)'.'</docFileName>';                    
                            
$list.='<docAddNew></docAddNew>';                    
                            
$list.='</docFilelist></docFile>';    
                }

                        
            } 

        
$list.='</Docattatches>';    

        
$list.='<DocRef>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocRef)?$oTsr->tsr_DocRef:"-").'</DocRef>';  //อ้างถึง
        
$list.='<DocOther>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocOther)?$oTsr->tsr_DocOther:"-").'</DocOther>';  //สิ่งที่ส่งมาด้วย
        
$list.='<DslID>'.iconv('TIS-620''UTF-8',$DslID).'</DslID>'//ชั้นความเร็ว
        
$list.='<DclID>'.iconv('TIS-620''UTF-8',$DclID).'</DclID>'//ชั้นความลับ
        
$list.='<DocDeptOwner>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocDeptOwner)?$oTsr->tsr_DocDeptOwner:"-").'</DocDeptOwner>'//หน่วยงานเจ้าของเรื่อง
        
$list.='<DocTelOwner>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocTelOwner)?$oTsr->tsr_DocTelOwner:"-").'</DocTelOwner>'//โทรศัพท์เจ้าของเรื่อง
        
$list.='<DocFaxOwner>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocFaxOwner)?$oTsr->tsr_DocFaxOwner:"-").'</DocFaxOwner>'//โทรสารเจ้าของเรื่อง
        
$list.='<DocCopySend>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocCopySend)?$oTsr->tsr_DocCopySend:"-").'</DocCopySend>'//สำเนาส่ง
        
$list.='<DocContactE>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocContactE)?$oTsr->tsr_DocContactE:"-").'</DocContactE>'//การติดต่อทางอิเล็กทรอนิกส์
        
$list.='<DocShortDesc>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocShortDesc)?$oTsr->tsr_DocShortDesc:"-").'</DocShortDesc>'//หมายเหตุ
        
$list.='<DocSendReal>'.iconv('TIS-620''UTF-8',isset($oTsr->tsr_DocSendReal)?$oTsr->tsr_DocSendReal:"-").'</DocSendReal>'//ส่งหนังสือตัวจริงตามไปด้วย
        
        
$list.='</BookDetail>';
        echo 
$list;    
    }
}else if(
$fn=='readDocEntryDoc'){
    
//echo "readDocEntryDoc";
    
    
include_once("../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../link/keyThai.php";
    include_once 
"functforRptEx.php";
    include_once 
"../class/clsDocReceiveSend.php";

    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
    
    
$oRs = new DocReceiveSend($oC);
    
$oRs1 = new DocReceiveSend($oC);
    
$DrsID = (! isset($_REQUEST['DrsID'])? "" $_REQUEST['DrsID']);
    
$DaSeq = (! isset($_REQUEST['indexBook'])? "" $_REQUEST['indexBook']);
    
    
$oRs->SearchByKey($DrsID);
    
$oRs->GetRecord();
    
$oRs->Edit();
    
$oRs->DsID=5;
    
    
$DrsReadDoc $oRs->DrsReadDoc;
    
//echo "<br>DrsReadDoc = ".$DrsReadDoc;
    //echo "<br>DrsID = ".$DrsID;
    //echo "<br>DaSeq = ".$DaSeq;
    //----update DrsReadDoc
    
if($DaSeq!=0){
        
$count=strlen($DrsReadDoc);
        if(
$count!=$DaSeq){
            
$newDrsReadDoc substr_replace($DrsReadDoc"1"$DaSeq-1,-($count-1-($DaSeq-1)));
        }else{
            
$newDrsReadDoc substr_replace($DrsReadDoc"1"$count-1);
        }
        
$oRs->DrsReadDoc=$newDrsReadDoc
    }
    
//echo "<br>newDrsReadDoc = ".$newDrsReadDoc;
    //-----------------------
    
$oRs->Save();    
    echo 
"Success readDocEntryDoc";
}else if(
$fn=='signDocAction'){ //ลงนาม

    //echo "GET";
    
$personId    =  $_GET['personId'];
    
$DLCID        =  $_GET['DLCID'];
    
$DrsID        =  $_GET['DrsID'];
    
$DocID        =  $_GET['DocID'];
    
$DrsSign    =  $_GET['DrsSign'];

//echo $personId." | ".$DLCID." | ".$DrsID." | ".$DocID." | ".$DrsSign; 
//die;
    
include_once("../../class/clsConnection.php");
    include_once(
"../../class/clsDB.php");
    include_once 
"../global.php";    
    include_once 
"funct.php";
    include_once 
"../link/function.php";
    include_once 
"../link/functionshow.php";
    include_once 
"../class/clsDocLineConfig.php";
    include_once 
"../class/clsDocuments.php";
    include_once 
"../class/clsDocReceiveSend.php";
    include_once 
"../class/clsDocForSign.php";

    
$oDlc = new DocLineConfig($oC);
    
$oDoc = new Documents($oC);
    
$oRs = new DocReceiveSend($oC);
    
$oRs1 = new DocReceiveSend($oC);
    
$oRs2 = new DocReceiveSend($oC);
    
$oRs3 = new DocReceiveSend($oC);
    
$oDfs = new DocForSign($oC);
    
    
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
    
    
//-----------------------------------------------------------
    
$oDoc->SearchByKey($DocID); $oDoc->GetRecord();
    
$oDlc->SearchByKey($DLCID); $oDlc->GetRecord(); 

    
$DlcPs=GetUpPrePsSend($DLCID,$oDlc->deptId); 

    if(
$oDoc->DtID==15){  
        
$DocForSign=1
    }
    
    
$cansend="N"//ไม่ส่งหนังสือเอง
    
$DlcIDlogin $DLCID;
    
$DrsSign str_replace("|"," ",$DrsSign);
    
//$DrsSign = iconv('UTF-8', 'TIS-620',$DrsSign);
    //echo $DrsSign;die;
    //-----------------------------------------------------------
    
$flagCommit true;
    
$oC->BeginTrans();
    
    
$oDoc->SearchByKey($DocID);
    if(
$oDoc->GetRecord()=="1"){
            
$oDoc->Edit();
            
$oDoc->DsID="3";
            
$flagCommit $oDoc->Save();
    }
    
$oRs->SearchByKey($DrsID);
    
$oRs->GetRecord();
    
$oRs->Edit();
    
$oRs->DlcID=$DlcIDlogin;
    
$oRs->DrsReceivePersonId=$personId;
    
$oRs->DrsSendDate=getNowDateTh()." ".date('H:i:s');
    
//echo "DrsSendDate=".$oRs->DrsSendDate;
    
    
if($cansend!="Y"){
        
//$oRs->DrsSendPersonId=$DlcPsId;
        
$oRs->DrsSendPersonId='';
    }else if(
$cansend=="Y"){
        
$oRs->DrsSendPersonId=$personId;
    }
    
    
//echo "DrsSendPersonId=".$oRs->DrsSendPersonId;
    
if($cansend!="Y"){
        
$oRs->DrsSendDlcID=$DlcPs;
    }else if(
$cansend=="Y"){
        
$oRs->DrsSendDlcID=$DlcIDlogin;
    }
    
//echo "DrsSendDlcID=".$oRs->DrsSendDlcID;
    
$oRs->DrsSign=$DrsSign;    
    
$oRs->Save();

    
$oRs2->SearchPreDocSignforDlpID0_Update2($DlcIDlogin,$personId,$oRs->DrsFromDrsID);

    
    
//---------------add DocReceiveSend
    
$oRs1->AddNew();
    
$oRs1->DrsID=$oRs1->GetNextCode();
    
$oRs1->DocID=$DocID;
    if(
$cansend!="Y"){
        
$oRs1->DlcID=$DlcPs;
    }else if(
$cansend=="Y"){
        
$oRs1->DlcID=$DlcIDlogin;
    }
    
$oRs1->DsID=3;
    
$oRs1->PtID=$oRs->PtID;
    
$oRs1->DrsDocTypeNo=$oRs->DrsDocTypeNo;
    
$oRs1->DrsReceiveDate=$oRs->DrsSendDate;
    
//$oRs1->DrsReceivePersonId=$DlcPsId;
    
$oRs1->DrsReceivePersonId='';
    
$oRs1->DrsDocDueDate=$oRs->DrsDocDueDate;
    
$oRs1->DrsDlcIDCreate=$DlcIDlogin;
    
$oRs1->DrsPsIDCreate=$personId;
    
$oRs1->DrsPropose=$oRs->DrsPropose;
    
$oRs1->DrsSign=$DrsSign;
    
$oRs1->DrsFromDrsID=$oRs->DrsID;
    
//echo "DrsFromDrsID=".$oRs1->DrsFromDrsID;
    
$oRs1->DocGroup=$oRs->DocGroup;
    if(
$cansend!="Y"){
        
$oRs1->DrsSend=$oRs1->DrsSend;
    }else if(
$cansend=="Y"){
        
$oRs1->DrsSend="Y";
    }
    
$oRs1->AnID=$oRs->AnID;
    
$oRs1->DrsstartDatePost=$oRs->DrsstartDatePost;
    
$oRs1->DrsendDatePost=$oRs->DrsendDatePost;    
    
$flagCommit $oRs1->Save();
    
    if(
$DocForSign==&& $DocPID!="0"){
        
$oDlc->SearchByKey($DlcIDlogin); $oDlc->GetRecord(); 
        
$oRs2->SearchDeptSendDocforSign($oDoc->DocID);
        
$oRs2->GetRecord();
        
$oRs3->SearchByKey($oRs2->DrsFromDrsID);
        
$oRs3->GetRecord();
        
        
$oDfs->AddNew();
        
$oDfs->dfID=$oDfs->GetNextCode();
        
$oDfs->DocID=$oRs3->DocID;
        
$oDfs->DlcID=$oRs2->DrsDlcIDCreate;
        
$oDfs->DocGroup=$oRs3->DocGroup;
        
$oDfs->DlcIDsign=$DlcIDlogin;
        
$oDfs->DeptSign=$oDlc->deptId;
        
$oDfs->Save();
        
//echo $oRs8->DrsID.'--'.$oRs8->DrsDlcIDCreate.'--'.$oRs8->DrsPsIDCreate.'-'.$oRs8->DrsFromDrsID;        
    
}
            
    if(
$flagCommit)
        
$oC->CommitTrans();
    else
        
$oC->RollbackTrans();
    
    echo 
"Success signDocAction";

}
?>

:: Command execute ::

Enter:
 
Select:
 

:: Shadow's tricks :D ::

Useful Commands
 
Warning. Kernel may be alerted using higher levels
Kernel Info:

:: Preddy's tricks :D ::

Php Safe-Mode Bypass (Read Files)

File:

eg: /etc/passwd

Php Safe-Mode Bypass (List Directories):

Dir:

eg: /etc/

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c999shell v. 1.0 pre-release build #16 Modded by Shadow & Preddy | RootShell Security Group | r57 c99 shell | Generation time: 0.0509 ]--