0

当我在服务器上运行 php 文件时,它没有执行脚本,但它要求我下载/打开 php 文件。仅供参考,问题发生在我的第二台服务器中。在主服务器上,我没有这个问题这些是文件的内容

// Insert the main code of the file here. 
?>
<html>
<head>

    <meta http_equiv="Cache-Control" content="no-cache">
    <meta http-equiv="pragma" content="no-cache">
    <link rel="icon" href="images/favicon.ico" type="image/x-icon">
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
    <title>Fetch Emails And Attachments.</title> 
    <link href="masterstylesheet.css" rel="stylesheet" type="text/css" />
</head>


<?php


require('imap_connect.php');
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Server: ' . imap_last_error());

require('IMAP_FetchEmails&Attachments_Functions.php');

require('IMAP_FetchEmails&Attachments_Variables.php');

        echo "Date: "     . $check->Date    . "<br />\n" ;
        echo "Driver: "   . $check->Driver  . "<br />\n" ;
        echo "Mailbox: "  . $check->Mailbox . "<br />\n" ;
        echo "Messages: " . $check->Nmsgs   . "<br />\n" ;
        echo "Recent: "   . $check->Recent  . "<br />\n" ;
        echo "Unread: "   . $check->Unread  . "<br />\n" ;
        echo "Deleted: "  . $check->Deleted . "<br />\n" ;
        echo "Size: "     . $check->Size    . "<br />\n" ;
        */
    } else {
        echo "imap_check() failed: " . imap_last_error() . "<br />\n";
    }


$custom_day_interval= date("Y-m-d", strtotime("-1 day"));
$today = date("y-m-d"); 
$emails = imap_search ($inbox, "UNSEEN");
if($emails) {
  foreach($emails as $email_number) {
    $email_count = $email_count + 1;
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $headerlist = imap_headerinfo($inbox, $email_number);

    $structure = imap_fetchstructure($inbox, $email_number);


   $dataTxt = get_part($inbox, $email_number, "TEXT/PLAIN", $structure);

   $dataHtml = get_part($inbox, $email_number, "TEXT/HTML", $structure);

   if ($dataHtml != "") {
       $msgBody = $dataHtml;
        $mailformat = "html";
   } else {
        $msgBody = ereg_replace("\n","<br>",$dataTxt);
        $mailformat = "text";
   }

        $pattern = 'utf-8';
        $subMatch = strpos("{$overview[0]->subject}",$pattern); //decoded subject
        $toMatch = strpos("{$headerlist->toaddress}",$pattern); //decoded to
        $fromMatch = strpos("{$overview[0]->from}",$pattern); //decoded from
        if(isset($headerlist->ccaddress)){$ccMatch =  strpos("$headerlist->ccaddress",$pattern);}else{$ccMatch="";} //decoded cc
        if(isset($headerlist->bccaddress)){$bccMatch = strpos("$headerlist->bccaddress",$pattern);}else{$bccMatch="";} //decoded bcc

        if($subMatch>"0" || $toMatch>"0" || $fromMatch>"0" || $ccMatch>"0" || $bccMatch>"0")
        {
        //below is decoded subject, to, from, cc, bcc
            $desubject = iconv_mime_decode("{$overview[0]->subject}");
            $defrom = iconv_mime_decode("{$overview[0]->from}");
            $deto = iconv_mime_decode("{$headerlist->toaddress}");
            if(isset($headerlist->ccaddress)){$decc = iconv_mime_decode("{$headerlist->ccaddress}");}
            if(isset($headerlist->bccaddress)){$debcc = iconv_mime_decode("{$headerlist->bccaddress}");}

                    $subject = $desubject;
                    $subject = addslashes($subject);
                    $From =$defrom;
                    //$From = addslashes ($From);
                    $date = $overview[0]->date;

                    $toemaillist = $deto; 
                    //$toemaillist = addslashes($toemaillist);
                    $ccemaillist = $decc; 
                    $ccemaillist = addslashes($ccemaillist);    
                }
        else
        {       
            $subject = $overview[0]->subject;
            $subject = addslashes($subject);
            $From =$overview[0]->from;

            $Email_date = $overview[0]->date;

            $toemaillist = $headerlist->toaddress; 

            $ccemaillist = $headerlist->ccaddress; 
            $ccemaillist = addslashes($ccemaillist);    
        }

    $EmailDate = date('Y-m-d H:i:s',strtotime($Email_date));
    $Email_date_in_body = date('l, F d, Y h:i:s A', strtotime($Email_date));

    $From = str_replace('"','',$From);  //clearing the double quotes
    $From = str_replace("'","",$From);  //clearing the double quotes
    $From = str_replace("<","",$From); //clearing the Angular brackets 
    $From = str_replace(">","",$From); //clearing the Angular brackets 

    $toemaillist = str_replace('"','',$toemaillist); //clearing the double quotes
    $toemaillist = str_replace("'","",$toemaillist); //clearing the double quotes
    $toemaillist = str_replace("<","",$toemaillist); //clearing the  Angular brackets 
    $toemaillist = str_replace(">","",$toemaillist); //clearing the  Angular brackets 


    $completeMessage = "From: "  .$From . "</br>\n" ;
    $completeMessage .= "Sent: " .$Email_date_in_body. "</br>\n" ;
    $completeMessage .= "TO: " .$toemaillist. "</br>\n" ;
    $completeMessage .= "CC: " .$ccemaillist. "</br>\n" ;
    $completeMessage .= "Subject: ".$subject. "</br></br>\n" ;
    $omessage = addslashes ($msgBody);
    $completeMessage .= $omessage ;

echo "<b>Fetched enamil number</b> ".$email_number."<br>";
///////////Create/Build Call id fetch from Emails.......    
////////////////Algo need to be changed after standardization of CALL ID in subject..................   

                    $Callid1=ereg_replace('  ','', $subject);
            $Callid2=ereg_replace(' ','', $Callid1);

            $Callid3=ereg_replace(':','', $Callid2);

            $Callid11=ereg_replace('id','ID', $Callid3);

            $Callid12=ereg_replace('iD','ID', $Callid11);

            $Callid13=ereg_replace('Id','ID', $Callid12);


if ($Callid13[6]=='S'&& $Callid13[7]=='I' && $Callid13[8]=='T')
{
$Callid4 = substr($Callid13, strpos($Callid13, 'ID') + 2);
$Callid6=explode("-",$Callid4);

echo "if",$Callid4;
} else {
$Callid14=ereg_replace('ids','ID', $Callid13);
            $Callid15=ereg_replace('iDs','ID', $Callid14);
            $Callid16=ereg_replace('Ids','ID', $Callid15);
            $Callid17=ereg_replace('IDs','ID', $Callid16);

            $Callid18=ereg_replace('IDS','ID', $Callid17);


$Callid4 = substr($Callid18, strpos($Callid18, 'ID') + 2);
$Callid6=explode("-",$Callid4);


echo "else",$Callid4;

}



            if(($Callid6[0]=='INS' && $Callid6[1]=='PHX' ) || ($Callid6[0]=='INS' && $Callid6[1]=='SNMP' )|| ($Callid6[0]=='TPSINT') || ($Callid6[0]=='VTS' ))
            {
                $Callid9 = substr($Callid6[3],0,7);
                $Callid = $Callid6[0]."-".$Callid6[1]."-".$Callid6[2]."-".$Callid9;
            }
            elseif(($Callid6[0]=='TPS') && ($Callid6[1]=='INT'))
            {
             if (($Callid6[2]=='INS' && $Callid6[3]=='PHX') || ($Callid6[2]=='INS' && $Callid6[3]=='SNMP') || ($Callid6[2]=='VTS'))
                  {
                   $Callid19 = substr($Callid6[5],0,7);
                   $Callid = $Callid6[0]."-".$Callid6[1]."-".$Callid6[2]."-".$Callid6[3]."-".$Callid6[4]."-".$Callid19;
                  }
                  else
                  {  
                    $Callid10 = substr($Callid6[4],0,7);
                    $Callid = $Callid6[0]."-".$Callid6[1]."-".$Callid6[2]."-".$Callid6[3]."-".$Callid10;
                   }
             } 



/// Conditions for TEST,UAT, SIT

elseif(($Callid6[0]=='TEST' )|| ($Callid6[0]=='UAT' )|| ($Callid6[0]=='SIT' ))
            { echo "entered";
             if (($Callid6[1]=='INS' && $Callid6[2]=='PHX') || ($Callid6[1]=='INS' && $Callid6[2]=='SNMP') || ($Callid6[1]=='VTS'))
                  {
                   $Callid19 = substr($Callid6[4],0,7);
echo "call id 9e",$Callid19;
                   $Callid = $Callid6[0]."-".$Callid6[1]."-".$Callid6[2]."-".$Callid6[3]."-".$Callid6[4];
                  }
                  else
                  {  
                    $Callid10 = substr($Callid6[3],0,7);
                    $Callid = $Callid6[0]."-".$Callid6[1]."-".$Callid6[2]."-".$Callid6[3];
                   }
             } 


            else
            {
            $Callid8 = substr($Callid6[2],0,7);
            $Callid = $Callid6[0]."-".$Callid6[1]."-".$Callid8;
            }

            echo "<br><b>Call ID is: </b>".$Callid."<br>";

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
    require ('db_connect_Insert_update.php');
    $sql = "select APP_NUMBER from rpworkflow.supportmasterrecords where actualcallid = '".$Callid."'";
    $result = mysql_query($sql);
    $row=mysql_fetch_array($result);

    echo $row['APP_NUMBER']. "<BR>";
      $AppNum = $row['APP_NUMBER'];
    echo "<br><b>Sequence count</b>". $email_count . "<br>";
    echo "today is " . $today;
    mysql_free_result($result);
    require ('db_close.php');   
    require ('db_connect_Insert_update.php');   

    //Insertion of Email 
    mysql_select_db(wf_workflow);
    $date_email_fetchedon = date("Y-m-d H:i:s");
    $query="set max_allowed_packet = 1073741824";
    $result = mysql_query($query);
    mysql_free_result($result);

    // Below Insert email record with body
    $query  = "
    INSERT INTO wf_workflow.tps_trans_fetch_support_emails
    (Subject, email_body, email_from, email_to, Email_Date, callid, case_number, Date_email_fetched_on, status ) 
    VALUES ('{$subject}','{$completeMessage}','{$From}','{$toemaillist}','{$EmailDate}','{$Callid}','{$row['APP_NUMBER']}', '{$date_email_fetchedon}', '{$email_count}')";

    /*
        NAME: Ali / Salman
        Date: 11 Jan 2012 1138
        Purpose: patch introduced for the rectification of STATUS having zero as a default value.
    */
    $query="
    INSERT INTO wf_workflow.tps_trans_fetch_support_emails
    (Subject, email_body, email_from, email_to, Email_Date, callid, case_number, Date_email_fetched_on, status ) 
    VALUES ('{$subject}','{$completeMessage}','{$From}','{$toemaillist}','{$EmailDate}','{$Callid}','{$row['APP_NUMBER']}', '{$date_email_fetchedon}', '0')";

    //  $query  = "INSERT INTO wf_workflow.tps_trans_fetch_support_emails(Subject, email_body, email_from, email_to, Email_Date, callid, case_number, Date_email_fetched_on, status ) VALUES ('{$subject}','{$ali}','{$From}','{$toemaillist}','{$EmailDate}','{$Callid}','{$row['APP_NUMBER']}', '{$date_email_fetchedon}', '{$email_count}')";

//  echo $query."<br>";

    $result = mysql_query($query);
    mysql_free_result($result);
    require ('db_close.php');   

    require ('db_connect_Insert_update.php');


    //In Below Query
    // we ommitted the emailto and mailfrom parameters from the above select query because of the add slashed function used onto them, we can
    // use those parameter if we want to make more tight query
    //$sql = "select Fetch_Email_ID, email_date, case_number from wf_workflow.tps_trans_fetch_support_emails WHERE `Subject` = '{$subject}' AND Email_Date =  '{$EmailDate}' AND callid = '{$Callid}' AND case_number =  '{$row['APP_NUMBER']}' AND Date_email_fetched_on =  '{$date_email_fetchedon}'";

    //below is tight query with everything
    $sql = "
            SELECT Fetch_Email_ID
            FROM tps_trans_fetch_support_emails
            WHERE `Subject` = '{$subject}'
            AND `email_from` = '{$From}'
            AND `email_to` = '{$toemaillist}'
            AND `Email_Date` = '{$EmailDate}'
            AND `Callid` = '{$Callid}'
            AND `case_number` = '{$row['APP_NUMBER']}'
            AND Date_email_fetched_on =  '{$date_email_fetchedon}'

    ";
    //echo "<br> ".$sql."<br> "; // to display the Query above


    $result2 = mysql_query($sql);
    $roww=mysql_fetch_array($result2);
    echo "<BR><b>Fetch_Email_ID:</b> ".$roww['Fetch_Email_ID']. "<BR>";   

    $fetchMailID = $roww['Fetch_Email_ID'];

    $numRow = mysql_numrows($result2); 

    mysql_free_result($result2);

    // Below check is to verify that this email must not exist in Support Notes Table so that Attachment are downloaded

    $check_note_existance=" SELECT 1 FROM wf_workflow.tps_trans_support_notes where currentdate='" . $roww[email_date]. "'  and caseNumber='" . $roww[case_number]. "'";

    $check_note_existance_result= mysql_query($check_note_existance);   
    $count_of_note_existance = mysql_numrows($check_note_existance_result);

require ('db_close.php'); 


    if($AppNum>0)
    {
        require ('db_connect_Insert_update.php');
        $query  = "update wf_workflow.tps_trans_fetch_support_emails set status='1' where `Fetch_Email_ID` = '$fetchMailID' AND `case_number` = '$AppNum'";
        $result = mysql_query($query);
        mysql_free_result($result);
        //echo ($fetchMailID. "Case Number found</br>.".$query);
        require ('db_close.php');
    }
    else
    {
        require ('db_connect_Insert_update.php');
        $query  = "update wf_workflow.tps_trans_fetch_support_emails set status='3' where `Fetch_Email_ID` = '$fetchMailID'";
        $result = mysql_query($query);
        mysql_free_result($result);
        //echo ($fetchMailID. "No case Number found</br>.".$query);
        require ('db_close.php');
    }




    if(($numRow==1) && ($fetchMailID>0))
    {

    // Now Fetching Attachments if They Exist, in every importent email

  $AppNum = $row['APP_NUMBER'];
if($Download_Attachments==1) //checking if it is allowed to download the attachments
{
 if(isset($AppNum) && $count_of_note_existance ==0)  // if App number exist AND checking if this mail already exist in Notes table 
    {
       $attachments = array();   //defining an array type array to store arrays of attachment information
       if(isset($structure->parts)) {


         for($i = 0; $i < count($structure->parts); $i++) {

         $total_attachments = count($structure->parts);   // Array inside attachments array 
           $attachments[$i] = array(                        //  to store attachments details
              'is_attachment' => false,                 // from support's Email address
              'filename' => '',
              'name' => '',
              'attachment' => '',
              'size' => '',
              'index' => '',
              'type' => '',
              'encoding' => '',
              'write_location' => '',
              'local_location' => '',
              'access_location' => ''
              );



           if($structure->parts[$i]->ifdparameters) {
             foreach($structure->parts[$i]->dparameters as $object) {
               if(strtolower($object->attribute) == 'filename') {   // cecking if there is an element with title filename in part structure
                 $attachments[$i]['is_attachment'] = true;          // marking "is_attachment" to true so that the emial is written on the file system
                 $attachments[$i]['filename'] = $object->value;     //Extracting the file names with extention of each email and storing it in array
               }
             }
           }

           if($structure->parts[$i]->ifparameters) {
             foreach($structure->parts[$i]->parameters as $object) {
               if(strtolower($object->attribute) == 'name') {
                 $attachments[$i]['is_attachment'] = true;
                 $attachments[$i]['name'] = $object->value;
               }
             }
           }

           if($structure->parts[$i]->bytes) {           // fetching the size of current Mail being fetched
                 $attachments[$i]['is_attachment'] = true;  
                 $attachments[$i]['size'] = $structure->parts[$i]->bytes;
           }  

           if($i) {
                 $attachments[$i]['is_attachment'] = true;
                 $attachments[$i]['index'] = $i;
           } 

            if($structure->parts[$i]->ifdparameters) {
             foreach($structure->parts[$i]->dparameters as $object) {
               if(strtolower($object->attribute) == 'filename') {   // cecking if there is an element with title filename in part structure
                 $attachments[$i]['is_attachment'] = true;          // marking "is_attachment" to true so that the emial is written on the file system


                            $attachments[$i]['type'] = ".".pathinfo($object->value, PATHINFO_EXTENSION);    //Extracting the file extention of each email and storing it in array

               }
             }
           }


           if($i) {//This if code will be used to create teh path for file if not exists, and create a complete string of location of the file to be stored
              $attachments[$i]['is_attachment'] = true;

                $nameoffile = str_replace($attachments[$i]['type'],"",$attachments[$i]['filename']);
                $DateFileName = date('Ymd_His');
                 $randName = $nameoffile."_".$AppNum."_".$DateFileName."_".$attachments[$i]['index'];
                    //CHecking the existance of the path, if does not exist will create it.
                    $mypath=$fileStore."".$AppNum;
                    $attachments[$i]['dir_location'] = $mypath;
                    $mypath_access = str_replace("\\","/",$mypath);
                    $posi = strpos($mypath_access, $Attachments_Folder);
                    $posi = $posi + "12";
                    $path = substr($mypath_access,$posi);
                // manageing paths for storing into DB
                 $fileLocat = $mypath."\\".$randName."".$attachments[$i]['type'];
                 $attachments[$i]['write_location'] = $fileLocat;   // this is used to write files on File system 
                 $attachments[$i]['local_location'] = $mypath_access."/".$randName."".$attachments[$i]['type']; // this is used to store the complete path of atachment in DB
                 $attachments[$i]['access_location'] = $path."/".$randName."".$attachments[$i]['type']; // this is used to store the  path of atachment, and used in html file in DB
            } 


           if($attachments[$i]['is_attachment']) {   //checking if there is an attachment then
             $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1);  //fetching the complete body of email

             //Decoding the Entire Body with the either of the two decoding function after verifying the encoding type
             if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
               $attachments[$i]['encoding'] = $structure->parts[$i]->encoding." BASE64";
               $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
             }
             elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
             $attachments[$i]['encoding'] = $structure->parts[$i]->encoding." QUOTED-PRINTABLE";
               $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
             }             
             elseif($structure->parts[$i]->encoding == 0) { // 4 = 7-BIT
             $attachments[$i]['encoding'] = $structure->parts[$i]->encoding." 7-BIT";
               $attachments[$i]['attachment'] = imap_utf7_decode($attachments[$i]['attachment']);
             }             
             elseif($structure->parts[$i]->encoding == 1) { // 4 = 8-BIT
             $attachments[$i]['encoding'] = $structure->parts[$i]->encoding." 8-BIT";
               $attachments[$i]['attachment'] = imap_utf8($attachments[$i]['attachment']);
             }             
             elseif($structure->parts[$i]->encoding == 2) { // 4 = BINARY
             $attachments[$i]['encoding'] = $structure->parts[$i]->encoding." BINARY";
               //$attachments[$i]['attachment'] = ($attachments[$i]['attachment']);
             }             
             elseif($structure->parts[$i]->encoding == 5) { // 4 = Other
              // $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
             }
           }             
         } 

         // writing the fetched Email on to the File System

           $date_attachment_fetchedon = date("Y-m-d H:i:s");
           $Total_Attachment = null;
             for($i = 0; $i < count($structure->parts); $i++) 
            {
            //Below is the code for checking wanted File Extentions, The veriable must not be "" i.e. the default value in order to proceed
        require ('db_connect_Insert_update.php');
            $File_Type_Clearance = "";
            $lowerFileType = $attachments[$i]['type'];
            $lowerFileType = strtolower($lowerFileType);
            $File_Type_Clearance = array_search($lowerFileType,$Allowed_Exts);

            if($attachments[$i]['type']!=null)
            {


            if($File_Type_Clearance=="")
            {
                $filNam = $attachments[$i]['filename'];
                $filTyp = $attachments[$i]['type'];
                $fisiz = $attachments[$i]['size'];
                $filLoc = $attachments[$i]['local_location'];
                $filAxes = $attachments[$i]['access_location'];
                $filindx = $attachments[$i]['index'];
                $filEncod = $attachments[$i]['encoding'];
                $reason_not_downloaded="File Type Restricted";
                echo "</br>The file type not Allowed, ".$filName. "is having the file Type ". $filTyp. "</br>";
                require ('db_connect_Insert_update.php');   
                //Insertion of Attachments 
                mysql_select_db(wf_workflow);
                $query  = "INSERT INTO wf_workflow.tps_trans_fetch_support_attachments
                (`File name`, `File Type`, `File Size`, `FileSystem_Write_Date`, `Location_on_FileSystem`, `Location_on_Server`, `APP_Attachment_IND`, `Decode_TYPE`, `Fetch_Email_ID`, `Case Number`, Reasons_Not_downloaded) 
                VALUES ('$filNam', '$filTyp', '$fisiz', '$today', '$filLoc', '$filAxes', '$filindx', '$filEncod', '$fetchMailID', '$AppNum', '$reason_not_downloaded')";

                $result = mysql_query($query);
                mysql_free_result($result);
                require ('db_close.php'); 
                $Total_Attachment = $Total_Attachment + "1";


            }
            else
            {


            if($attachments[$i]['size']<=$Max_Attachment_size) //checking the file size allowed
            {


                if($attachments[$i]['filename']!=null)
                {
                mkdir($attachments[$i]['dir_location'],0777,TRUE); // Making Folders

                $fp=fopen($attachments[$i]['write_location'],'w');
                fputs($fp,$attachments[$i]['attachment']);
                fclose($fp);

                echo "<ul>";
                echo "<li>".$attachments[$i]['filename']." is ".$attachments[$i]['size']." having Index ".$attachments[$i]['index']." and file TYpe is ".$attachments[$i]['type']." WITH ENCODING TYPE ".$attachments[$i]['encoding']."<br></li>";
                echo "</ul>";
                // preparing variable to be used in insert query below  
                $filNam = $attachments[$i]['filename'];
                $filTyp = $attachments[$i]['type'];
                $fisiz = $attachments[$i]['size'];
                $filLoc = $attachments[$i]['local_location'];
                $filAxes = $attachments[$i]['access_location'];
                $filindx = $attachments[$i]['index'];
                $filEncod = $attachments[$i]['encoding'];
                $reason_not_downloaded="Download Successful";


                //Insertion of Attachments 
                mysql_select_db(wf_workflow);
                $query  = "INSERT INTO wf_workflow.tps_trans_fetch_support_attachments(`File name`, `File Type`, `File Size`, `FileSystem_Write_Date`, `Location_on_FileSystem`, `Location_on_Server`, `APP_Attachment_IND`, `Decode_TYPE`, `Fetch_Email_ID`, `Case Number`, `Is_Written to_FileSystem`, `Reasons_Not_downloaded`) 
                VALUES ('$filNam', '$filTyp', '$fisiz', '$date_attachment_fetchedon', '$filLoc', '$filAxes', '$filindx', '$filEncod', '$fetchMailID', '$AppNum', true, '$reason_not_downloaded')";

                $result = mysql_query($query);
                mysql_free_result($result);

            require ('db_close.php'); 

                $Total_Attachment = $Total_Attachment + "1";
                }
            }
            else //Inserting the recordof attachments which were not downloaded due to size restrictions. 
                {

                $filNam = $attachments[$i]['filename'];
                $filTyp = $attachments[$i]['type'];
                $fisiz = $attachments[$i]['size'];
                $filLoc = $attachments[$i]['local_location'];
                $filAxes = $attachments[$i]['access_location'];
                $filindx = $attachments[$i]['index'];
                $filEncod = $attachments[$i]['encoding'];
                $reason_not_downloaded="Exceeded File Size Restrictions";
                echo "</br>The file is exceeds the file size allowed. ".$filName. "is having the file size as ". $fisiz. "</br>";
                require ('db_connect_Insert_update.php');   
                //Insertion of Attachments 
                mysql_select_db(wf_workflow);
                $query  = "INSERT INTO wf_workflow.tps_trans_fetch_support_attachments
                (`File name`, `File Type`, `File Size`, `FileSystem_Write_Date`, `Location_on_FileSystem`, `Location_on_Server`, `APP_Attachment_IND`, `Decode_TYPE`, `Fetch_Email_ID`, `Case Number`, Reasons_Not_downloaded) 
                VALUES ('$filNam', '$filTyp', '$fisiz', '$today', '$filLoc', '$filAxes', '$filindx', '$filEncod', '$fetchMailID', '$AppNum', '$reason_not_downloaded')";

                $result = mysql_query($query);
                mysql_free_result($result);
                require ('db_close.php'); 
                $Total_Attachment = $Total_Attachment + "1";

                }


            }
            }
            }//End of For Loop for writing files to file system and inserting attachment record to DB

            if($Total_Attachment==0 || $Total_Attachment==null)
            {
                        $Total_Attachment=null;

            echo "<br>No attachment fetched for Email having App_Number <b>".$row['APP_NUMBER']."</b> And Callid <b>".$Callid."</b><br>";
            }
            else
            { // updating the master table for recently added emails regarding Attachments
            $Geand_Total_Attachment=$Geand_Total_Attachment + $Total_Attachment;
            require ('db_connect_Insert_update.php');

            mysql_select_db($wf_workflow);
            $query  = "update wf_workflow.tps_trans_fetch_support_emails set Num_of_Attachments='$Total_Attachment', Is_Attachments_Fetched=True where Fetch_Email_ID='$fetchMailID' ";
            $result = mysql_query($query);
            mysql_free_result($result);

            echo "<br>Attachment fetched for Email having App_Nnumber <b>".$row['APP_NUMBER']."</b> And Callid <b>".$Callid."</b><br>";
                require ('db_close.php'); 
            }

       }

    }


    }
    }

  echo "<br><hr style='background-color: blue;   border: 0px;   clear: left; color: #006699;  float: center; height: 2px; margin: 4px 0px 4px 0px; width: 99%;'>";
  }

    //require ('db_close.php'); 
}
else 
{
    echo ("None  are found");
}

/* close the connection */
imap_close($inbox);

$execution_time_end = date('Y-m-d H:i:s');

echo "<div align='center'><table width='50%' >
<tr><th align='Left' class='tableHeader'>Total Emails Red</th><td align='Right'><b> ".$email_count." <hr></b></td></tr>
<tr><th align='center'>Total Attachments Fetched</th><td align='Right'><b> ".$Geand_Total_Attachment." <hr></b></td></tr>
<tr><th align='Left' class='tableHeader'><b>Execution Start Time</th><td align='Right'>".$execution_time_start." <hr></td></tr>
<tr><th align='center'>Execution End TIme</th><td align='Right'>".$execution_time_end." <hr></td></tr>

    </table></div>";

?>

</html>

<?php
// use $last_insert_ID;
require('log_update.php');
require ('log_end.php');
require ('inc_Report_footer.php');
require ('send_mail.php');
}
else
{
    $faulty_log = '1';
    // use $last_insert_ID;
    require('log_update.php');
}

?>
4

0 回答 0