Advertisement
Guest User

Old Version with Edit capabilities

a guest
Sep 2nd, 2011
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.14 KB | None | 0 0
  1.         case "Ordination Credentials":
  2.  
  3.             $q = "SELECT o.date_purchased, fd.template_fn, o.customers_name, op.orders_id, opa.orders_products_id, products_name, op.products_quantity, field_name, products_options_values
  4.                     FROM orders_products AS op
  5.                     join orders as o on o.orders_id = op.orders_id
  6.                     JOIN fulfillment_doc_products AS fdp ON fdp.product_id = op.products_id
  7.                     JOIN fulfillment_docs AS fd ON fd.doc_id = fdp.doc_id
  8.                     JOIN orders_products_attributes AS opa ON opa.orders_products_id = op.orders_products_id
  9.                     right JOIN fulfillment_doc_fields AS fdf ON fdf.products_options_name = opa.products_options
  10.                     AND fdf.doc_products_id = fdp.doc_products_id
  11.                     WHERE op.orders_id
  12.                     BETWEEN $in
  13.                     AND $out
  14.                     AND fd.doc_id = $doc_id
  15.                     ORDER BY o.orders_id, products_name, opa.orders_products_id, field_name, products_options_values";
  16.                    
  17.             $r = mysql_query($q) or die(mysql_error());
  18.            
  19.             while($row = mysql_fetch_array($r)) {
  20.  
  21.                 //Template Filename is managed on admin front end
  22.                 $template_fn = getcwd().'/templates/' . $row['template_fn'];
  23.  
  24.                 //Standard db output filtering and processing into multi-dimensional array as seen above               
  25.                 $datas[$row['orders_products_id']][$row['field_name']] = sanitize_db_output($row['products_options_values']);
  26.                 $datas[$row['orders_products_id']]['order_number'] = $row['orders_id'];
  27.                 $datas[$row['orders_products_id']]['products_quantity'] = $row['products_quantity'];
  28.             }
  29.            
  30.             //pdftk allows us to stuff things into custom fields in pdf files
  31.             require('pdftk-php/pdftk-php.php');
  32.            
  33.             //create new pdftk object
  34.             $pdfmaker = new pdftk_php;
  35.            
  36.             //init stuff
  37.             $fdf_data_names = array();
  38.             $fields_hidden = array();
  39.             $fields_readonly = array();
  40.            
  41.             //go through array now
  42.             foreach($datas as $data) {
  43.            
  44.                 //multiple qty gets multiple credentials
  45.                 for ($i = 1; $i <= $data['products_quantity']; $i++) {
  46.                    
  47.                     //day must look like 1st, 2nd, 3rd etc..
  48.                     $data['date-day'] = ordinalize($data['date-day']);
  49.                    
  50.                     //compiling pdf
  51.                     $pdf_content = $pdfmaker->make_pdf($data, $fdf_data_names, $fields_hidden, $fields_readonly, $template_fn);
  52.                    
  53.                     //report errors, show debug info
  54.                     if(empty($pdf_content)) {
  55.                         echo "pdf empty " . $template_fn;
  56.                         echo "<br><pre>" . print_r($data) . "</pre>";
  57.                         die();
  58.                     }
  59.                    
  60.                     //write data to temp file with prefix+random characters filename
  61.                     $pdf_filename = tempnam('/tmp/', 'ulc-fulfillment');
  62.                     $handle = fopen($pdf_filename, "w");
  63.                     fwrite($handle, $pdf_content);
  64.                     fclose($handle);
  65.                    
  66.                     //add filename to array for combination
  67.                     $pdfs[] = $pdf_filename;
  68.                 }
  69.             }
  70.            
  71.             //combine all temp pdfs in array
  72.             $final_pdf = $pdfmaker->combine_pdf($pdfs);
  73.            
  74.             //clean up temp files
  75.             foreach($pdfs as $pdf) {
  76.                 if (file_exists($pdf)) { unlink($pdf); }
  77.             }
  78.  
  79.             //send to browser
  80.             header("Content-type: application/octet-stream");
  81.             header("Content-Disposition: attachment; filename=ordination-credentials-$datestamp.pdf");
  82.             header("Pragma: no-cache");
  83.             header("Expires: 0");
  84.             echo $final_pdf;
  85.            
  86.         break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement