<?php
/* include the ACS class page */
require_once("../../classes/ACS.php");

/******* Code For reading the db format and generate pdf format file in specific location******************/

/* Step 1: create object of the ACS class */

$ACS=new ACS();
$tables=$ACS->getDBTables();
if(isset($_POST['import']))
{
	// set whether first row is Tag or not (true or false)
		
	//set tablename of the database
	$ACS->dbTableName=$_POST['dbTable'];
	
	//set columns of the database table name
	$ACS->columns=$_POST['column_name'];
	
	// save the file on Specific location or display in browser (browser or save)
	$ACS->fileOutputMode=$_POST['browserMode'];
	// set the output path where file want to save converted file format
	$output=$_POST['outputPath'];
		
	/* Step 3: call the convert method to reading the db Format and generate file in pdf format*/			
	$ACS->convert("db","pdf","",$output);
	
	if(!isset($ACS->error))
	{
		$message="<div class='success'>Operation done successfully</div>";
	}
	else
	{
		$message="<div class='error'>There is error in operation. Please check error message: ".$ACS->error."</div>";	
	}
	
	/*Debug Operations - Uncomment below code lines to debug values */
	/*echo $ACS->error; //To display any error occured
	echo $ACS->messages; //It displays various messages at various points to check where code breaks
	print_r($ACS->inputDataArray);// To print the array of data generated after reading the csv file
	print_r($ACS->formattedDataArray);// To print the formatted array of data generated by code before final operation*/
	
}
require_once("../../header.php");
?>

<h4>Import DB to PDF</h4>
<hr />
<div class="from">
  <?php if(isset($message)) echo $message; ?>
  <form method="post" enctype="multipart/form-data">
    <div class="formRow">
      <div class="formLabel">Select Table</div>
      <div class="formField">
        <select name="dbTable" class="imported_table" onchange="show()">
          <option>--select--</option>
          <?php foreach($tables as $table) { ?>
          <option value="<?php echo $table;?>"><?php echo $table;?></option>
          <?php } ?>
        </select>
      </div>
    </div>
    <div id="hiddenContent">
      <div style="height:95px">
        <div class="formLabel">Select Coulmns</div>
        <div class="formField result-table"></div>
      </div>
      <div class="formRow">
        <div class="formLabel">Is First Row Header</div>
        <div class="formField">
          <input type="radio" name="firstRowHeader" value="true" checked="checked"/>
          &nbsp;&nbsp;True&nbsp;&nbsp;&nbsp;
          <input type="radio" name="firstRowHeader" value="false"/>
          &nbsp;&nbsp;False</div>
      </div>
      <div class="formRow">
        <div class="formLabel">File Output Mode</div>
        <div class="formField">
          <input type="radio" name="browserMode" value="save"/>
          &nbsp;&nbsp;Save file on the server&nbsp;&nbsp;&nbsp;
          <input type="radio" name="browserMode" value="browser" checked="checked"/>
          &nbsp;&nbsp;Output in Browser</div>
      </div>
      <div class="formRow">
        <div class="formLabel">Output File Name</div>
        <div class="formField">
          <input type="text" name="outputPath" value="file.pdf" />
        </div>
      </div>
      <div class="formRow">
        <div class="formLabel"></div>
        <div class="formField submit">
          <input type="submit" name="import" value="Save"/>
          <input type="reset" name="reset" />
        </div>
      </div>
    </div>
  </form>
</div>
<div id="code1" class="code" style="visibility:hidden;">
  <h5 class="head5">Code For DB</h5>
  <pre>
<code data-language="php">&lt;?php
/* include the ACS class page */
   require_once("../../classes/ACS.php");

/* Step 1: create object of the ACS class */
   $ACS=new ACS();
   
/* Step 2: set values of required parameters */
//set tablename of the database
   $ACS->dbTableName=$_POST['dbTable'];

//set columns of the database table name
   $ACS->columns=$_POST['column_name'];

/* Step 3: call the convert method for reading the csv Format and inserting data in database  */
/* $outputFileLocation = location of the output file (i.e. complete path of the output file)  */	
   $ACS->convert("db","pdf",'',$outputFileLocation);
?&gt;    
</code>
</pre>
</div>
