<?php

$table_name67="Aprocess2";
$table_name100="signin2";
$table_name101="sig_map";
$table_name102="sig_map_text";
include("../../../admin/GoTool/cat.inc");
$connection = @mysqli_connect($host,$user,$password) or die(mysqli_error($connection));
$db = @mysqli_select_db($connection,$db_name) or die(mysqli_error($connection));

$CAPMIT=$_POST['dir_id'];

$printQ2H='';
$printQ2H1='';
$printQ2H0='';
$PrintApp1='';
$printQ2Extra='';
 $pic88a='';
$display_title='';


 $pic88a="blank.jpg";
 
  $pic88a="";
 
 if (isset($_POST['pic88'])) {
  	
  	/// $pic88="$loc2/$CAPMIT/GoSlider/$pic88a";	 




//$pic88="../../../$graggdir/GoSlider/blank.jpg";

if (file_exists("../../../$graggdir/GoSlider/blank.jpg")){

    $pic88="../../../$graggdir/GoSlider/blank.jpg";
    
    $pic88a="blank.jpg";
    
    }


if (file_exists("../../../$graggdir/GoSlider/nosig.jpg")){

    $pic88="../../../$graggdir/GoSlider/nosig.jpg";
    
    $pic88a="nosig.jpg";
    
    }


if (file_exists("../../../$graggdir/GoSlider/$pic88a")){

    $pic88="../../../$graggdir/GoSlider/$pic88a";
    
     $pic88a=$_POST['pic88'];
    
    }

}

 
 if (isset($_POST['printQ2H'])) {
$printQ2H=$_POST['printQ2H'];
$display_title="$printQ2H";
}

if (isset($_POST['printQ2H1'])) {
$printQ2H1=$_POST['printQ2H1'];
}



if (isset($_POST['PrintApp1'])) {
$PrintApp1=$_POST['PrintApp1'];
}

if (isset($_POST['printQ2Extra'])) {
$printQ2Extra=$_POST['printQ2Extra'];
}





     
// $MIT=$_POST['MIT'];

//$survey_idR=$_POST['survey_id'];
$map_id='';
$map_id55='';

//$CAPMIT=$_POST['dir_id'];
     
	$log=$_POST['log'];

$map_id=$_POST['map_id'];
	
	///$survey_idR=62;
	
	//$map_id='';
	$map_id55=$map_id;
	
$sql33 ="SELECT * FROM $table_name80 WHERE map_id = '$map_id' ";

//echo $sql33;

$result33 = @mysqli_query($connection,$sql33) or die(mysqli_error($connection));
	       $row22 =mysqli_fetch_array($result33,MYSQLI_ASSOC);
	        $survey_idR=  $row22['survey_id'];
	
$survey_num=$survey_idR;	

 $sq112ab="SELECT * FROM $table_name81 WHERE survey_id = '$survey_idR'";
$result222a = @mysqli_query($connection,$sq112ab) or die(mysqli_error($connection));
while ($row1ab = mysqli_fetch_array($result222a)) {
$survey_id=  $row1ab['survey_id'];
  $stitle=   stripslashes($row1ab['name']);
          }
          
          
 if  ($display_title !=$blink){
 $stitle=$display_title;
 }        

//$survey_num=$survey_idR;

//  $stitle=stripslashes($_POST['stitle77']);


$summary77="Document: $stitle";
$author1="GalliumGroup";
$title1 ="Sample PDF Document";
$subj1="Public Document";
$key1="Keywords, PDF, User Docs";
$today = date("Y-m-d h:i:s");
$Rtoday=$today;
$map_title=date("Ymshis");

//$map_id=$_GET['map_id'];
//if ($map_id==$blink){
//$map_id=$_POST['map_id'];
//}

$textX="0";
$textY="0";

$map_idC=$map_id;
///////
$sql33zx ="SELECT * FROM $table_name80 WHERE test_type = '$map_idC' order by survey_id ";
$result222azx = @mysqli_query($connection,$sql33zx) or die(mysqli_error($connection));
while ($row1abzx = mysqli_fetch_array($result222azx)) {
$survey_idR=  $row1abzx['survey_id'];
$map_id=  $row1abzx['map_id'];
$textX="$textX,$map_id";
$textY="$textY,$survey_idR";

}
//echo "$textX <br/>";
//echo "$textY <br/>";

$MX1=explode(",", $textX);
			$Mgrade3=count($MX1);
$MY1=explode(",", $textY);
			///$Mgrade3=count($MY1);	
			
					
for ($iuu = 1; $iuu < $Mgrade3; $iuu++) {
//$utf8text .="i= $iuu  mapid--$MX1[$iuu]  survey--- $MY1[$iuu] dd ($textX )  help = $Mgrade3 <p>";

$sq112ba="SELECT * FROM $table_name80 WHERE survey_id = '$MY1[$iuu]' AND map_id ='$MX1[$iuu]' AND map_id !=0 ";
   $result222 = @mysqli_query($connection,$sq112ba) or die(mysqli_error($connection));
while ($row1 = mysqli_fetch_array($result222)) {
///$survey_id=  $row1['survey_id'];
$survey_id= $MY1[$iuu];
///$map_id=  $row1['map_id'];
$map_id=  $MX1[$iuu];
///$map_id55=  $row1['test_type'];          //for the new survey

//echo "$map_id - $map_id55 <br/>";
//if ($map_id55<1){
//$map_id55=$map_id;
//}


  $firstname=   stripslashes($row1['firstname']);
//echo $firstname;
   $lastname=   stripslashes($row1['lastname']);
  $company=  stripslashes($row1['company']);
  $email=  stripslashes($row1['email']);
$Ccreate_dateR= $row1['create_date'];
  $Ccreate_dateR1=strtotime("$Ccreate_dateR");
  $Ccreate_dateR=date("n-j-Y","$Ccreate_dateR1");
$Ccreate_dateRS=date("n-j-Y h:m:s","$Ccreate_dateR1");
  $Ascore= $row1['Ascore'];

      include("../../../admin/GoTool/survey/survey-row1-variables.php");
   $cust_id=  stripslashes($row1['agent_id']);
   
   
   
   $sq112bb="SELECT * FROM $table_name36 WHERE customer_id = '$cust_id' ";
//echo "first1 $firstname1 - $sq112bb<br/>";

      $result222aa = @mysqli_query($connection,$sq112bb) or die(mysqli_error($connection));
      while ($row1dd = mysqli_fetch_array($result222aa)) {
$val_fname1=  stripslashes($row1dd['firstname']);
$val_lname1=  stripslashes($row1dd['lastname']);
$val_email=  stripslashes($row1dd['email']);
$val_phoneW=  stripslashes($row1dd['telephone']);
$val_phoneF=  stripslashes($row1dd['fax']);
$val_phoneC=  stripslashes($row1dd['cell']);
$val_phoneH=  stripslashes($row1dd['telephone']);
}

 $sq112bb="SELECT * FROM $table_name40 WHERE customer_id = '$cust_id' ";
//echo "first1 $firstname1 - $sq112bb<br/>";

      $result222aa = @mysqli_query($connection,$sq112bb) or die(mysqli_error($connection));
      while ($row1dd66 = mysqli_fetch_array($result222aa)) {
//$val_phoneH=  stripslashes($row1dd66['homeP']);
$val_addressH=  stripslashes($row1dd66['address_1']);
$stateH=  stripslashes($row1dd66['state_id']);
$val_cityH=  stripslashes($row1dd66['city']);
$countryH=  stripslashes($row1dd66['country_id']);
$ipH=  $row1dd66['ip'];
$val_zipH=  stripslashes($row1dd66['postcode']);
$webH=  stripslashes($row1dd66['web']);
$company=  stripslashes($row1dd66['company']);

$agent_idH=  stripslashes($row1dd66['agent_id']);


      }///while

if ($firstname==$blink){
$firstname=$val_fname1;
$lastname=$val_lname1;
}

$val_fname=$firstname;
$val_lname=$lastname;

if ($company ==$blink){
 $company="NA";
}
   
   
   
   
   
   
   }
$sq112a="SELECT * FROM $table_name76 WHERE survey_id ='$MY1[$iuu]' ORDER BY surveyQ_idK ASC, surveyQ_id ASC ";
$survey_num= $MY1[$iuu];

include("../../../admin/GoTool/survey/surv_display2.php");

$utf8text .="$display_blockAdminB";
$display_blockAdminB='';

}

///newloop
 $sack=stripslashes($_POST['sack']);
   //$good1=$_POST['good1'];
   // $pic88=$_POST['pic88'];
   // $pic88="../../../admin/GoTool/survey_MIT/$pic88";
 //    $stuff88="$good1.txt";
  //$sack=1;

 //$a312="$stitle";
$a312=date("Ymshis");
 //     $email=stripslashes($_POST['email']);
 // $c_email=stripslashes($_POST['c_email']);
  $fname=stripslashes($_POST['fname']);
   $lname=stripslashes($_POST['lname']);
//   $company=stripslashes($_POST['company']);

 $summaryT='';   
 $summaryTa=''; 

if (isset($_POST['printQ2H0'])) {
$printQ2H0=$_POST['printQ2H0'];
$summaryT="$printQ2H<br/>";
//$summary771="$printQ2H0: $firstname $lastname ";
$summaryTa="$printQ2H1 - Applicant: $firstname $lastname <br/>";

}


//============================================================+
//
//
//
//string   	$name   	The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
//string   	$dest   	Destination where to send the document. It can take one of the following values:

//    I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
//    D: send to the browser and force a file download with the name given by name.
//    F: save to a local server file with the name given by name.
//    S: return the document as a string. name is ignored.
//    FI: equivalent to F + I option
//    FD: equivalent to F + D option
//============================================================+



//require_once('../config/lang/eng.php');
//require_once('../tcpdf.php');
require_once('tcpdf_include.php');    


require_once "FPDI/fpdi.php";
$pdf = new FPDI( 'P', 'mm', 'LETTER' ); //FPDI extends TCPDF

// create new PDF document
//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor("$author1");
$pdf->SetTitle("$title1");
$pdf->SetSubject("$subj1");
$pdf->SetKeywords("$keys1");

// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING);
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, "Document - $a312 - $map_idC", PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
//$pdf->setLanguageArray($l);

if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}


// ---------------------------------------------------------

// set default font subsetting mode
//$pdf->setFontSubsetting(true);
$pdf->setFontSubsetting(false);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
//$pdf->SetFont('dejavusans', '', 14, '', true);
$pdf->SetFont('dejavusans', '', 10, '', false);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
 //<h1>Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;color:black;"><span style="background-color:#CC0000;"> TC<span style="color:white;">PDF</span> </span></a>!</h1>

// set JPEG quality
//$pdf->setJPEGQuality(75);

// Image method signature:
// Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false)


// get esternal file content
//$utf8text = file_get_contents("$stuff88", false);
//$utf8text = file_get_contents("$stuff88");
//echo "$utf8text"; ’
$prob55="’";
$fix55="'";
//$utf8text=str_replace($prob55,$fix55,$utf8text);
//echo "$utf8text";

//$utf8text = iconv('UTF-8', 'ASCII//TRANSLIT', $utf8text); 
$utf8text = str_replace(chr(130), ',', $utf8text);  
$utf8text = str_replace(chr(146), "'", $utf8text);    // right single quote
$utf8text = str_replace(chr(147), '"', $utf8text);    // left double quote
$utf8text = str_replace(chr(132), '"', $utf8text);    // baseline double quote
$utf8text = str_replace(chr(133), '...', $utf8text);  // ellipsis
$utf8text = str_replace(chr(145), "'", $utf8text);    // left single quote
$utf8text = str_replace(chr(148), '"', $utf8text);    // right double quote

$utf8text = mb_convert_encoding($utf8text, 'HTML-ENTITIES', 'UTF-8');

$utf8text1=$printQ2Extra;

$utf8text1 = str_replace(chr(130), ',', $utf8text1);  
$utf8text1 = str_replace(chr(146), "'", $utf8text1);    // right single quote
$utf8text1 = str_replace(chr(147), '"', $utf8text1);    // left double quote
$utf8text1 = str_replace(chr(132), '"', $utf8text1);    // baseline double quote
$utf8text1 = str_replace(chr(133), '...', $utf8text1);  // ellipsis
$utf8text1 = str_replace(chr(145), "'", $utf8text1);    // left single quote
$utf8text1 = str_replace(chr(148), '"', $utf8text1);    // right double quote

$utf8text1 = mb_convert_encoding($utf8text1, 'HTML-ENTITIES', 'UTF-8');


$pdf->Write(0, "$summary77 - #$map_idC", '', 0, 'L', true, 0, false, false, 0);

$pdf->SetFont('helvetica', '', 8);

//$pdf->Image("$good1", 15, 140, 75, 113, 'JPG', 'http://www.tcpdf.org', '', true, 150, '', false, false, 1, false, false, false);
// Set some content to print
$html = <<<EOF
Date Recorded:$Ccreate_dateRS <br/>
$summaryT
$summaryTa
Submitted By: $val_fname $val_lname <br/><br/>
 $utf8text

EOF;

// Print text using writeHTMLCell()
//writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
//$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=1, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

//$pdf->Write(15, $utf8text, '', 0, '', false, 0, false, false, 0);
//$pdf->writeHTML($html, true, 0, true, 0);
//$pdf->writeHTML($html, true, false, false,false, 0);
//$pdf->writeHTML($utf8text, true, false, true, false, '');
$pdf->writeHTML($html, true, 0, true, 0);

// set JPEG quality
$pdf->setJPEGQuality(75);

// Image method signature:
// $pdf->Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false)
/////////
if ($pic88a != $blink){

 $file_E=  "$pic88a"; 
 
 
 //$pic88="../../../$graggdir/GoSlider/blank.jpg";



if (file_exists("$dlocZ/$CAPMIT/GoSlider/$pic88a")){

   $file_E=  $pic88a; 
    
    }
 
 
///$pic88="$loc2/$CAPMIT/GoSlider/$pic88a";

$fullPathToPDF = "$dlocZ/$CAPMIT/GoSlider/$file_E";

$pdf->AddPage();
$html2 = <<<EOF
Attachment(s) <br/>
 <br/>

EOF;

$pdf->writeHTML($html2, true, 0, true, 0);

$pdf->Image($fullPathToPDF, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=true);

$pdf->lastPage();
}
//////////


$sql33d11 ="SELECT DISTINCT information FROM $table_name806A WHERE approver ='$map_idC' AND (information LIKE '%.jpg' OR information LIKE '%.png') Order by date_added Desc ";
$result33d11 = @mysqli_query($connection,$sql33d11) or die(mysqli_error($connection));
 while ($row12 = mysqli_fetch_array($result33d11)) {

      $file_E=  $row12['information']; 


$fullPathToPDF = "$dlocZ/$CAPMIT/forms_dep2/$file_E";

$pdf->AddPage();
$html2 = <<<EOF
Attachment(s) <br/>
 <br/>

EOF;

$pdf->writeHTML($html2, true, 0, true, 0);

$pdf->Image($fullPathToPDF, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=true);

}
// reset pointer to the last page
$pdf->lastPage();


//require_once('FPDI/fpdf.php');
///require_once('FPDI/fpdi.php');

// initiate FPDI
///$pdf = new FPDI();
// add a page
//$pdf->AddPage();
//$fullPathToPDF = '/usr/local/common/my.pdf';

$sam=1;

If($sam==1){
$sql33d11 ="SELECT DISTINCT information FROM $table_name806A WHERE approver ='$map_idC' AND information LIKE '%.pdf'  Order by date_added Desc ";
$result33d11 = @mysqli_query($connection,$sql33d11) or die(mysqli_error($connection));
 while ($row12 = mysqli_fetch_array($result33d11)) {

      $file_E=  $row12['information']; 


$fullPathToPDF = "$dlocZ/$CAPMIT/forms_dep2/$file_E";
//$pageCount = $pdf->setSourceFile($fullPathToPDF);
$pageCount = $pdf->setSourceFile($fullPathToPDF);
//$pages = $pdf->setSourceFile( 'Summary.pdf' );

//$page = $pdf->ImportPage( 1 );
//$pdf->useTemplate( $page, 10, 10 );


for ($i = 1; $i <= $pageCount; $i++) {
    //$pdf->importPage($i);
    $page = $pdf->ImportPage($i );
    $pdf->AddPage();
   // $pdf->useTemplate($i);
   $pdf->useTemplate( $page, 10, 10 );
}
}
} //if
// set the source file
//$pdf->setSourceFile("1084.pdf");
// import page 1
//$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
///$pdf->useTemplate($tplIdx, 10, 10, 100);

// now write some text above the imported page
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
//$pdf->Write(0, 'This is just a simple text');

$display_uploadsPT="Other Uploads:<br/>";
$sql33d11 ="SELECT DISTINCT information FROM $table_name806A WHERE approver ='$map_idC' AND information NOT LIKE '%.pdf' AND information NOT LIKE '%.jpg' AND information NOT LIKE '%.png'  Order by date_added Desc ";
$result33d11 = @mysqli_query($connection,$sql33d11) or die(mysqli_error($connection));
 while ($row12 = mysqli_fetch_array($result33d11)) {

      $file_E=  $row12['information']; 
      $display_uploadsP.="<a href=\"$loc2/$CAPMIT/forms_dep2/$file_E\" target=\"blank\">$file_E</a> <br/>";
		  

}

if ($display_uploadsP != $blink){
$display_uploadsP="$display_uploadsPT $display_uploadsP";

$pdf->AddPage();
$html3 = <<<EOF
$display_uploadsP <br/>
 <br/>

EOF;

$pdf->writeHTML($html3, true, 0, true, 0);

}

$pdf->Output();

// ---------------------------------------------------------

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output("$a312.pdf", 'FD');

//header('Location:https://411webhost.com/guest_forms/download.html');
//============================================================+
// END OF FILE
//============================================================+
?>
