Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/07/2011, 03:13
zxeus
 
Fecha de Ingreso: junio-2011
Ubicación: Marbella
Mensajes: 10
Antigüedad: 13 años, 5 meses
Puntos: 0
Respuesta: Hosting sin soporte para PDFlib

Código PHP:
<?PHP

class pdf  {
    
    var 
$p;
    
    function 
generate_pdf ($page_method$table_name$table_key_name$table_key_values) {
        if  (!
defined("CURRENCY_SYMBOL_PRINT")) {
            
define("CURRENCY_SYMBOL_PRINT","$");
        }
        global 
$db_hostname;
        global 
$db_user;
        global 
$db_password;
        global 
$db_name;
        global 
$db_type;
        
$user_serial false;
        
$company_serial false;
        
        if (!
$table_name || !$table_key_name || !$table_key_values) {
            return 
false;
        }
        
$this->conn = &ADONewConnection($db_type);
        
$this->conn->PConnect($db_hostname,$db_user,$db_password,$db_name);
        
$this->conn->SetFetchMode(ADODB_FETCH_ASSOC);
        if (!empty(
$GLOBALS['debug_mode'])) {
            
$this->conn->debug=$GLOBALS['debug_mode'];
        } else {
            
$this->conn->debug=false;
        }            
        
        
$data_class = new data_class;
        
$variable_array $data_class->variable_array($page_method);
        
$need_comma=false;
        
$foreign_tables=null;
        
$extra_where_clauses' ' $table_key_name ' in (' $table_key_values ') ';
        
$foreign_where_clausenull;
        
$foreign_table_name_posix=1;
        
$order_by_clause=null;
        
$query_sql 'select ';
        
$need_where true;
        
        
$query_sql .= ' * ';
        
// get the field names required
        
        
foreach ($variable_array as $key=>$value) {
            if (isset(
$value['field_order_by']) && $value['field_order_by']) {
                if (
$order_by_clause) {
                    if (isset(
$value['field_order_by_reverse']) && $value['field_order_by_reverse']) {
                        
$order_by_clause .= ', ' $key ' DESC ';
                    } else {
                        
$order_by_clause .= ', ' $key ' ';
                    }
                } else {
                    if (isset(
$value['field_order_by_reverse']) && $value['field_order_by_reverse']) {
                        
$order_by_clause .= ' order by ' $key ' DESC ';
                    } else {
                        
$order_by_clause .= ' order by ' $key ' ';
                    }
                }
            }
            
$need_comma=true;
        }
        
        
$query_sql .= " from " $table_name;
        
        if (
$extra_where_clauses) {
            if (
$need_where) {
                
$query_sql .= " where ";
            } else {
                
$query_sql .= " and ";
            }
            
$need_where false;
            
$query_sql .= $extra_where_clauses;
        }
        if (
$order_by_clause) {
            
$query_sql .= $order_by_clause;
        }
        
        
$rs $this->conn->Execute($query_sql);
        
        if (!
$rs) {
            
// This means the record was not found
            
return false;
        } else {
            
/* This is where font/image/PDF input files live. Adjust as necessary. */
            
$searchpath BASE_DIR '/pdf/data';
            
            
PDF_set_parameter($this->p"SearchPath"$searchpath);
            
PDF_set_value($this->p"compress"9);
            
            
PDF_set_info($this->p"Creator""PDFlib");
            
PDF_set_info($this->p"Author"SYSTEM_NAME);
            
PDF_set_info($this->p"Title"'Land Document');
            
            
$query_sql 'select distinct template_serial from template, deal, company where deal.deal_serial in (' $table_key_values ') and deal.deal_company_serial = company.company_serial and template.template_serial = company.company_template_serial';
            
$rs_template $this->conn->Execute($query_sql);
            if (!
$template $rs_template->FetchRow()) {
                return 
false;
            } else {
                
// Let's generate the pdf
                
$infile BASE_DIR '/templates/template_' $template['template_serial'] . '.pdf';
                
$blockcontainer PDF_open_pdi($this->p$infile""0);
                if (
$blockcontainer == 0){
                    die (
"Couldn't open input file $infile.\n");
                }
                
                while (
$data $rs->FetchRow()) {
                    for (
$page_number=1$page_number 14$page_number++) {
                        
$page PDF_open_pdi_page($this->p$blockcontainer$page_number"");
                        if (
$page == 0){
                            
// no problem just break out of the for loop
                            
continue;
                        }
                        
PDF_begin_page($this->p2020);        /* dummy page size */
                        
                        /* This will adjust the page size to the block container's size. */
                        
PDF_fit_pdi_page($this->p$page00"adjustpage");
                        
/* Fill all text blocks with dynamic data */
                        
foreach ($variable_array as $key=>$value) {
                            
$i=0;
                            while (
$blockname PDF_get_pdi_parameter($this->p"vdp/Blocks[$i]/Name"$blockcontainer$page0)) {
                                if (
$blockname == $key || ((strpos($key'___') === (strlen($key) - 4)) && $blockname == $key)) {
                                    if (
strpos($key'___') === (strlen($key) - 4)) {
                                        
$key substr($key,strlen($key) - 4);
                                    }
                                    if (isset(
$data[$key]) && !empty($data[$key]) && ($value['field_type'] == 'text' || $value['field_type'] == 'select' || $value['field_type'] == 'hidden' || $value['field_type'] == 'key')) {
                                        
$suffix null;
                                        
$prefix null;
                                        
$suffix PDF_get_pdi_parameter($this->p"vdp/Blocks/$blockname/Custom/suffix"$blockcontainer$page0);
                                        
$prefix PDF_get_pdi_parameter($this->p"vdp/Blocks/$blockname/Custom/prefix"$blockcontainer$page0);
                                        
                                        if (
$value['field_value_type'] == 'currency') {
                                            if (isset(
$data[$key '_poa']) && $data[$key '_poa']) {
                                                
$temp_value 'P.O.A.';
                                            } else {