Location: PHPKode > projects > KSMS bulk sms manager > ksms-e1.2.35/admin/print_order.php
<?php
// -------------------------------------------------------------------------//
// KSMS ^ Short Message System Manager										//
// -------------------------------------------------------------------------//
// Based on "DBSMS" (C) 2002 Paolo Remonato									//
// Copyright (C) 2002-2006 Paolo Remonato									//
// KSMS-PROJECT HOME  :  http://ksms.sourceforge.net/						//
// -------------------------------------------------------------------------//
//   Please,do not delete these lines	^^^									//
// -------------------------------------------------------------------------//
/*
  This program is free software; you can redistribute it and/or modify it under the terms
  of the GNU General Public License as published by the Free Software Foundation.
  The software is provided "as is" without any express or implied warranty of any kind,
  Including warranties of noninfringement, merchantability, or fitness for a particular purpose.
*/

###		@version 	: 2006-02-21,v1.2.35	kingmo
###		@last sing_upd 	: 
###		@filename 	: 

define('IN_KSMS', true);

// print_order.php
require("admcommon.inc.php");


##############################################
##											##
##    	NOT COMPLETE. UNDER REVISION		##
##											##
##############################################


?>

<?php
function select_printer($ord_number) {
   global $printer1, $printer2, $printer3, $printer4; ?>
   <table class="default" align="center" border="0" cellspacing="0" cellpadding="1">
   <form action="print_po.php" method="post" name="form1">
    <tr class="row_head"> 
      <td align="center" colspan="3" nowrap><b>Print Customer Order <?php echo $ord_number; ?></b></td>
    </tr>
    <tr class="row_even"> 
      <td align="right">Select Printer:</td>
      <td> 
         <select name="printer">
             <option value="printer1"><?php echo $printer1["name"]; ?></option>
             <option value="printer2"><?php echo $printer2["name"]; ?></option>
             <option value="printer3"><?php echo $printer3["name"]; ?></option>
             <option value="printer4"><?php echo $printer4["name"]; ?></option>
         </select>
      </td>
      <td>
         <img src="<?PHP echo $imgs_admin_dir ?>print_button.gif" alt="Print Customer Order" border="0"
            onClick="document.form1.submit();">
         <a href="print_po.php?action=cancel">
         <img src="<?PHP echo $imgs_admin_dir ?>abort.gif" alt="Abort" border="0" align="middle">
			</a>
      </td>
    </tr>
    <input type="hidden" name="action" value="print_gd_po">
    <input type="hidden" name="ord_number" value="<?php echo $ord_number; ?>">
   </form>
   </table> <?php
} ?>

<?php
function print_gd_po($db, $ord_number, $printer) {
   global $cfg, $printer1, $printer2, $printer3, $printer4;
   if ($cfg["os"] != "unix" && $cfg["os"] != "win") {
      echo "<table class=\"notice\" width=\"100%\"><tr><td>Invalid forms overlay configuration. Set os type.</td></tr></table>";
      return FALSE;
   }
   if (${$printer}["language"] != "ps" && ${$printer}["language"] != "pcl") {
      echo "<table class=\"notice\" width=\"100%\"><tr><td>Invalid forms overlay configuration. Set printer language.</td></tr></table>";
      return FALSE;
   }
   if (${$printer}["name"] == "NA" || ${$printer}["name"] == "") {
      echo "<table class=\"notice\" width=\"100%\"><tr><td>Select a valid configured printer from the list.</td></tr></table>";
      select_printer($ord_number);
      return FALSE;
   }
   if (!$pork = $db->Execute("SELECT * FROM orders WHERE ord_number=$ord_number")) {
      echo "<table class=\"notice\" width=\"100%\"><tr><td>DB ERROR: " . $db->ErrorMsg() . "</td></tr></table>";
      return FALSE;
   }
   if ($pork->RecordCount() == 0) {
      echo "<table class=\"notice\" width=\"100%\"><tr><td>PO number $ord_number not found.</td></tr></table>";
      return FALSE;
   }
   $orderdata = $pork->fields["date"];
   $ordernumb = $pork->fields["ord_number"];
   $orderk_id = $pork->fields["ordID"];
   $vendor_id = $pork->fields["id_vendor"];
   $cliorg_id = $pork->fields["id_organization"];
   $kgatew_id = $pork->fields["id_gwprovider"];
   $creat_usr = $po->fields["created_by"];
$kp_org = $db->Execute("SELECT * FROM organization WHERE id='$orderk_id'");
$kp_vendor = $db->Execute("SELECT * FROM vendor WHERE id='$vendor_id'");
$kp_gate = $db->Execute("SELECT name_gwprovider, nick_gwprovider FROM gwprovider WHERE id='$kgatew_id'");
$line_items = $db->Execute("SELECT * FROM ord_line_items WHERE order_number=$ordernumb ORDER BY id_row");
   echo "Generating print job. Please be patient...";
   flush();

   // Open the blank form image.
   $im = imagecreatefrompng("../image/k_template.png");
   $black = imagecolorallocate($im, 0, 0, 0);
   $white = imagecolorallocate($im, 255, 255, 255);

   // Fill in the form by drawing text on the image at appropriate coordinates.
   imagettftext($im, 20, 0, 900, 200, $black, $cfg["font_b"],
      $ord_number);
   imagettftext($im, 20, 0, 10, 450, $black, $cfg["font_r"],
      $po->fields["date"]);
   imagettftext($im, 20, 0, 125, 265, $black, $cfg["font_r"],
      $vendor->fields["name"]);
   imagettftext($im, 20, 0, 125, 302, $black, $cfg["font_r"],
      $vendor->fields["address1"]);
   imagettftext($im, 20, 0, 125, 339, $black, $cfg["font_r"],
      $vendor->fields["city"] . ", " . $vendor->fields["province"] . ", " . $vendor->fields["p_code"]);
   imagettftext($im, 20, 0, 125, 376, $black, $cfg["font_r"],
      "Attn: " . $vendor->fields["attn"]);
   imagettftext($im, 20, 0, 820, 265, $black, $cfg["font_r"],
      $org->fields["name"]);
   imagettftext($im, 20, 0, 820, 302, $black, $cfg["font_r"],
      $org->fields["address1"]);
   imagettftext($im, 20, 0, 820, 339, $black, $cfg["font_r"],
      $org->fields["city"] . ", " . $org->fields["province"] . ", " . $org->fields["p_code"]);
   imagettftext($im, 20, 0, 820, 376, $black, $cfg["font_r"],
      "Attn: " . $org->fields["contact"]);
   $i = 1;
   $po_total = 0;
   $baseline = 519;
   while (!$line_items->EOF) {
      imagettftext($im, 16, 0, 10, $baseline + 36 * $i, $black, $cfg["font_r"], $i);
      imagettftext($im, 16, 0, 55, $baseline + 36 * $i, $black, $cfg["font_r"],
         $line_items->fields["qty"]);
      imagettftext($im, 16, 0, 145, $baseline + 36 * $i, $black, $cfg["font_r"],
         $line_items->fields["unit"]);
      imagettftext($im, 16, 0, 220, $baseline + 36 * $i, $black, $cfg["font_r"],
         $line_items->fields["descrip"]);
      $bbox = imagettfbbox(12, 0, $cfg["font_r"], $line_items->fields["alloc"]);
      imagettftext($im, 12, 0, 880-$bbox[2], $baseline + 36 * $i, $black, $cfg["font_r"],
         $line_items->fields["alloc"]);
      if ($line_items->fields["unit_price"] != 0 ) {
         $bbox = imagettfbbox(16, 0, $cfg["font_r"], $line_items->fields["unit_price"]);
         imagettftext($im, 16, 0, 1030-$bbox[2], $baseline + 36 * $i, $black, $cfg["font_r"],
            $line_items->fields["unit_price"]);
         $bbox = imagettfbbox(16, 0, $cfg["font_r"], $line_items->fields["amount"]);
         imagettftext($im, 16, 0, 1180-$bbox[2], $baseline + 36 * $i, $black, $cfg["font_r"],
            $line_items->fields["amount"]);
      }
      $po_total += $line_items->fields["amount"];
      $i++;
      $line_items->MoveNext();
   }
   if ($po_total != 0) {
      $bbox = imagettfbbox(16, 0, $cfg["font_b"], sprintf("%s%01.2f", $cfg["curr"], $po_total));
      imagettftext($im, 16, 0, 1180-$bbox[2], 1375, $black, $cfg["font_b"],
         sprintf("%s%01.2f", $cfg["curr"], $po_total));
   }
   imagettftext($im, 20, 0, 20, 1455, $black, $cfg["font_r"],
      $cr_fullname->fields["fullname"]);
   imagettftext($im, 20, 0, 415, 1455, $black, $cfg["font_r"],
      $appr_fullname->fields["fullname"]);

   // Save the filled in form image...
   imagepng($im, "var/" . session_id() . ".png");
   // And print it.
   print_image($printer);
   echo "<table class=\"notice\" width=\"100%\"><tr><td>Customer Order $ord_number job queued to " . ${$printer}["name"] . ".</td></tr></table>";
} ?>

<?php
$privs = $_SESSION["privs"];
$projname = $_SESSION["project_name"];
if ($privs == '69'AND $projname == 'KeySMS') {
   $action = strtolower($action);
   switch ($action) {
      case "cancel":
         echo "<table class=\"notice\" width=\"100%\"><tr><td>Print Customer Order $ord_number job cancelled.</td></tr></table>";
         break;
      case "print_gd_po":
         print_gd_po($db, $ord_number, $printer);
         break;
      default:
         if ($cfg["gd"] == TRUE) {
            select_printer($ord_number);
         	} else { ?>
            <script language="JavaScript">
               window.open("print_html_order.php?ord_number=<?php echo $ord_number; ?>&orderid=<?php echo $orderid; ?>&controlcheck=administrator&prgmused=KSMS");
            </script> <?php
            echo "<table class=\"notice\" width=\"100%\"><tr><td>Customer Order $ord_number opened in a new browser window.</td></tr></table>";
         	}
   }
} else {
   echo "<table class=\"notice\" width=\"100%\"><tr><td>Insufficient privilege. See KSMS administrator.</td></tr></table>";
}
require("footer.inc.php");
?>
Return current item: KSMS bulk sms manager