使用MySQL连接进行PHP打印效果不好,有更好的方法吗?

使用MySQL连接进行PHP打印效果不好,有更好的方法吗?,php,printing,citrix,Php,Printing,Citrix,我给医生办公室买了这些标签,必须打印出来。打印是通过自定义的C Outlook右键单击日历菜单加载项完成的,因此不使用本地打印机。而且,这个PHP设置早在我的时间之前就建立了,并且没有为客户端重写 ArrivalHelper.php系统调用下面的脚本PrintersMgmt.php,然后调用PinnaclePDO.php连接到运行在Ubuntu服务器上的MySQL实例,在该实例中查找办公室位置locID为2,然后在该MySQL表中查找打印机,以及哪个服务器cc-fp2,在本例中,它承载并将该信息

我给医生办公室买了这些标签,必须打印出来。打印是通过自定义的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;
  }

}

?>

那么到底是什么问题呢?您对当前的打印机选择方法不满意,但我认为您没有解释原因。你能解释一下吗?我认为web服务器通过LAN将作业发送到正确的打印机主机?据我所知,您不能使用浏览器的打印对话框,因为无法使用JavaScript指定要使用的打印机。问题是他们想要使用打印对话框,我可以让他们在Citrix会话中从重定向的打印机中进行选择。当我尝试将打印机添加到MySQL表时,情况就不一样了。我可以继续说这个系统出了什么问题,但最后,我只需要他们能够打开一个打印对话框,而不是允许它选择打印机。我是个笨蛋。我知道的足够灵活,可以学到更多,但是我从PHP资源中找到的打印内容并没有告诉我足够的信息来使用Windows对话框进行打印。对,这涉及到Citrix会话。你能编辑一下你的问题来解释一下这里是怎么用的吗?这感觉像是一个关键的细节,特别是如果你现在正在打印的话。你不需要在你的问题上滔滔不绝,但是如果你在MySQL中做一些事情,那么描述事情是如何破坏的可能很重要,也许有一个简单的解决方法!。好的,当我在MySQL的locationprinters表中添加一个新的打印机时,打印机不再从Citrix会话打印,而Citrix会话正在使用这个脚本。但是,如果您将安装在PC上的打印机用作本地计算机上的网络打印机,则可以正常工作。我已经在该服务器上重新启动了IIS管理服务,该服务从该服务器运行并托管在该服务器上,我已经重新启动了Apache并终止了它用来运行的firefox进程。出于某种原因,它就是不起作用。