<?php

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

$CAPMIT=$_POST['dir_id'];

$bMIT1=$_POST['datat'];
$bTITle1=$_POST['datat1'];
 $bTITle1a='';
 if (isset($_POST['datat12'])) {
 $bTITle1a=$_POST['datat12'];
 
 if ($bTITle1a !=$blink){
 
 $testy1=$bTITle1a; //locations
		 $sql33 ="SELECT * FROM $table_name92 WHERE information_id = '$testy1' ";
		 $result33 = @mysql_query($sql33,$connection) or die(mysql_error());
		      $row22 =mysql_fetch_array($result33,MYSQL_ASSOC);
		        $display_blocka2=  $row22['description'];
		           $display_blocka2=stripslashes($display_blocka2);
		               $welcome22=htmlspecialchars_decode($display_blocka2);
		                  $welcome22=mb_convert_encoding($welcome22,  "HTML-ENTITIES");
		
		$bTITle1a =$welcome22;
 
 
 }
 
 }
//$bMIT1="file.txt";
//echo "hi $bMIT1 - $bTITle1a <br/>";

//$myfile = fopen("$bMIT1", "r") or die("Unable to open file!");
// Output one line until end-of-file
$bMIT = file_get_contents("$bMIT1");
///fclose($myfile);

//$CAPMIT="WARMIT";
//$CAPMIT="survey";

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




 $pic88a='';
 
 if (isset($_POST['pic88'])) {
 $pic88=$_POST['pic88'];
 
  	 if (file_exists("../../../$graggdir/GoSlider/$pic8")){

  //  $pic88="../../../$graggdir/GoSlider/$pic88";
    
     $pic88a=$_POST['pic88'];
     }
      if (file_exists("$dlocZ/$CAPMIT/forms_dep2/$pic88")){
    $pic88a=$_POST['pic88'];
    }
  	/// $pic88="$loc2/$CAPMIT/GoSlider/$pic88a";	 
}
 
 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='';

$summary77="$stitle";
$author1="GalliumGroup";
$title1 ="$bTITle1";
$subj1="$bTITle1";
$key1="GalliumTable, PDF, $bTITle1";
$today = date("Y-m-d h:i:s");
$Rtoday=$today;
$map_title=date("Ymshis");

$Ccreate_dateRSa = date("m-d-Y h:i");

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

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

if($appcharge==3003){
  
  $appmath="<br/><br/><table border=\"1\" cellpadding=\"1\" cellspacing=\"0\" width=\"400\"><tr>
  <td>App Names</td><td>$appname</td>
  </tr>
  <tr>
  <td>Apps Hosted</td><td>$appNum</td></tr>
  
  <tr>
  <td>App Pricing Per Month</td><td>$appPrice</td>
  </tr>
  
  </table><br/><br/>
  
  <table border=\"1\" cellpadding=\"1\" cellspacing=\"0\" width=\"400\">
  <tr>
  <td  bgcolor=\"#C0C0C0\"><b>Total App Hosting Charges</b></td><td bgcolor=\"#C0C0C0\"><b>$payapp</b></td>
  </tr></table>
  
  ";
  
  }
  
  
  echo "hey $bMIT";

   $stuff="
   $bMIT
   ";
   
///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");
///- $map_idC
// 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 ", 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);

///Submitted By: $val_fname $val_lname <br/><br/>
// $utf8text
//$summaryT
//$summaryTa -  Date:   <br/>

//$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
$bTITle1 - Printed $Ccreate_dateRSa<br/>
$bTITle1a

$stuff


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="$loc2/$CAPMIT/GoSlider/$pic88a";

$fullPathToPDF = "$dlocZ/$CAPMIT/forms_dep2/$file_E";
    
  if (file_exists("$fullPathToPDF")){

$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();
}
//////////
/// $sql33AA1 ="SELECT DISTINCT information FROM $table_name36001 WHERE status>0 AND map_id='$map_id' AND customer_id = '$text_account3' AND type_id='103' Order by date_added Desc ";
	
$sql33d11 ="SELECT DISTINCT information FROM $table_name36001 WHERE status>'0' AND map_id!='0' AND map_id='$map_idC' AND (information LIKE '%.jpg' OR information LIKE '%.png' OR information LIKE '%.JPG' OR information LIKE '%.PNG' OR information LIKE '%.Jpg' OR information LIKE '%.Png') Order by date_added Desc ";
///echo $sql33d11;

$result33d11 = @mysql_query($sql33d11,$connection) or die(mysql_error());
 while ($row12 = mysql_fetch_array($result33d11)) {

      $file_E=  $row12['information']; 


$fullPathToPDF = "$dlocZ/survey/forms_dep2/$file_E";
  if (file_exists("$fullPathToPDF")){
$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();


/////////

$sam=2;
If($sam==2){
$sql33d11 ="SELECT DISTINCT information FROM $table_name36001 WHERE status>0 AND map_id='$map_idC' AND map_id >'0'  AND (information LIKE '%.pdf' OR information LIKE '%.PDF'  OR information LIKE '%.Pdf'  ) Order by date_added Desc ";
$result33d11 = @mysql_query($sql33d11,$connection) or die(mysql_error());
 while ($row12 = mysql_fetch_array($result33d11)) {

      $file_E=  $row12['information']; 


$fullPathToPDF = "$dlocZ/survey/forms_dep2/$file_E";
//$pageCount = $pdf->setSourceFile($fullPathToPDF);

  if (file_exists("$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




//////

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

      $file_E=  $row12['information']; 


$fullPathToPDF = "$dlocZ/$CAPMIT/forms_dep2/$file_E";
  if (file_exists("$fullPathToPDF")){
$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=0;

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

      $file_E=  $row12['information']; 


$fullPathToPDF = "$dlocZ/$CAPMIT/forms_dep2/$file_E";
  if (file_exists("$fullPathToPDF")){

//$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/>";
$display_uploadsP='';
///////

$sql33d11 ="SELECT DISTINCT information FROM $table_name36001 WHERE status>0 AND map_id!='0' AND map_id='$map_idC' AND information NOT LIKE '%.pdf' AND information NOT LIKE '%.PDF' AND information NOT LIKE '%.Pdf' AND information NOT LIKE '%.jpg' AND information NOT LIKE '%.JPG' AND information NOT LIKE '%.Jpg' AND information NOT LIKE '%.png' AND information NOT LIKE '%.Png' AND information NOT LIKE '%.PNG'  Order by date_added Desc ";
$result33d11 = @mysql_query($sql33d11,$connection) or die(mysql_error());
 while ($row12 = mysql_fetch_array($result33d11)) {

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

}


/////

$sql33d11 ="SELECT DISTINCT information FROM $table_name806A WHERE approver !='0' AND approver ='$map_idC' AND information NOT LIKE '%.pdf' AND information NOT LIKE '%.PDF' AND information NOT LIKE '%.Pdf' AND information NOT LIKE '%.jpg' AND information NOT LIKE '%.JPG' AND information NOT LIKE '%.Jpg' AND information NOT LIKE '%.png' AND information NOT LIKE '%.Png' AND information NOT LIKE '%.PNG'  Order by date_added Desc ";
$result33d11 = @mysql_query($sql33d11,$connection) or die(mysql_error());
 while ($row12 = mysql_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", 'D');

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