我为医生办公室拿到了这些标签,他们必须打印出来。通过自定义C#Outlook右键单击日历菜单加载项进行打印,因此不使用本地打印机。此外,这个PHP设置早在我的时间之前就建立了,并且没有为客户端重写。
ArrivalHelper.php
系统调用下面的脚本“PrintersMgmt.php”,然后调用PinnaclePDO.php
连接到在Ubuntu服务器上运行的MySQL实例以查找办公地点(在这个例子中,locID是2)然后找到该MySQL表中的打印机以及托管它的服务器(在本例中为cc-fp2)并将该信息发送回打印。
我需要找到一种方法来做得更好。我想过用JavaScript打开一个打印对话框,但我不知道如何在这里实现。有人可以给PHP noob一些指针吗?
<?php
class PrintersMgmt {
const PRINT_ALL_LABELS = 0x1;
const PRINT_ONE_LABEL = 0x10;
const PRINT_PASSPORT = 0x100;
const PRINT_REFERRAL = 0x1000;
const PRINTER_TYPE_LETTER = 1;
const PRINTER_TYPE_LABEL = 2;
const
ARRIVAL_URL = 'http://localhost/arrival.php';
const QUERY_GET_PRINTER_BY_LOC_TYPE =
'SELECT * FROM LocationPrinters
WHERE locID = :loc AND printerType = :type
ORDER BY printerPriority
LIMIT 1';
private $dbh;
public function __construct() {
$this->dbh = new PinnaclePDO();
}
public function getByLocationType( $loc, $type ) {
$stmt = $this->dbh->prepare( self::QUERY_GET_PRINTER_BY_LOC_TYPE );
$stmt->bindValue( ':loc', $loc );
$stmt->bindValue( ':type', $type );
$stmt->execute();
return $stmt->fetch();
}
public function printPassport( $locId, $hin, $date, $userName, $method ) {
$printFlags = $this->getPrintFlags($method);
$referral = ( ! ($printFlags & self::PRINT_REFERRAL) == 0 );
$passport = ( ! ($printFlags & self::PRINT_PASSPORT) == 0 );
$printer = $this->getByLocationType( $locId, 1 );
if ( $printer ) {
$cmd = '.\firefox.exe';
$args = sprintf(
' -print "%s?method=%s&hin=%s&user=%s&referral=%d&passport=%d"' .
' -printprinter "\\\\' . $printer[ 'printerHost' ] . '\\' . $printer[ 'printerName' ] .'"',
self::ARRIVAL_URL, 'listconfirmed',
$hin, urlencode( $userName ), $referral, $passport
);
if ( isset( $_GET[ 'debug' ] ) ) {
print "Print with args: '$cmd $args'<br/>";
}
chdir( "C:/Program Files/Mozilla Firefox2/" );
shell_exec($cmd.$args);
}
return true;
}
public function printLabel( $locId, $hin, $date, $method ) {
$printFlags = $this->getPrintFlags($method);
$printer = $this->getByLocationType( $locId, 2 );
$number = ( ( $printFlags & self::PRINT_ONE_LABEL ) == 0 ) ? 'all' : 'one' ;
$cmd = 'LabelPrinter.exe';
$args = sprintf(
' /print %s %s "%s" %s',
$hin, $date, $printer[ 'printerName' ], $number );
if ( isset( $_GET[ 'debug' ] ) ) {
print sprintf( 'Printing \'%s\' labels \'%s %s\'<br/>',
$number, $cmd, $args );
} else {
chdir( "C:/Program Files/(truncated)/(truncated) Tools" );
shell_exec( $cmd . $args);
}
return true;
}
public function getPrintFlags( $arriveMethod ) {
$printFlags = 0x1101;
switch ( $arriveMethod ) {
case 'arrive':
$printFlags =
( self::PRINT_ALL_LABELS
| self::PRINT_PASSPORT
| self::PRINT_REFERRAL );
break;
case 'reprintpassport':
$printFlags = self::PRINT_PASSPORT;
break;
case 'reprintreferral':
$printFlags = self::PRINT_REFERRAL;
break;
case 'reprintlabel':
$printFlags = self::PRINT_ONE_LABEL;
break;
default:
$printFlags = null;
}
return $printFlags;
}
}
?>