fwrite($handle, $data);
        fclose($handle);
    }
} else {
    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
        // Generate ClientPrintJob? only if clientPrint param is in the query string
        $urlParts = parse_url($_SERVER['REQUEST_URI']);
        $rawQuery = $urlParts['query'];
        if (isset($rawQuery)) {
            if ($rawQuery[WebClientPrint::CLIENT_PRINT_JOB]) {
                //we need the session id to look for the ini file containing printer settings & commands
                parse_str($rawQuery, $qs);
                $sid = $qs['sid'];
                if (isset($sid)) {
                    // try to get ini file from cache
                    $cacheFileName = (Utils::strEndsWith(WebClientPrint::$wcpCacheFolder, '/') ? WebClientPrint::$wcpCacheFolder : WebClientPrint::$wcpCacheFolder . '/') . $sid . '.ini';
                    if (file_exists($cacheFileName)) {
                        $print_info = parse_ini_file($cacheFileName);
                        //remove file from cache
                        unlink($cacheFileName);
                        // create print job...
                        if (isset($print_info)) {
                            //get printer commands
                            $printerCommands = base64_decode($print_info['printerCommands']);
                            //get printer settings
                            $printerTypeId = base64_decode($print_info['pid']);
                            $clientPrinter = NULL;
                            if ($printerTypeId == '0') {
                                $clientPrinter = new DefaultPrinter();
                            } else {
                                if ($printerTypeId == '1') {
Example #2
0
 /**
  * Sends this ClientPrintJob object to the client for further processing.
  * The ClientPrintJob object will be processed by the WCPP installed at the client machine.
  * @return string A string representing a ClientPrintJob object.
  */
 public function sendToClient()
 {
     header('Content-type: application/octet-stream');
     $cpjHeader = chr(99) . chr(112) . chr(106) . chr(2);
     $buffer = '';
     if (!Utils::isNullOrEmptyString($this->printerCommands)) {
         if ($this->formatHexValues) {
             $buffer = Utils::formatHexValues($this->printerCommands);
         } else {
             $buffer = $this->printerCommands;
         }
     } else {
         if (isset($this->printFile)) {
             $buffer = $this->printFile->serialize();
         } else {
             if (isset($this->printFileGroup)) {
                 $buffer = 'wcpPFG:';
                 $zip = new ZipArchive();
                 $cacheFileName = (Utils::strEndsWith(WebClientPrint::$wcpCacheFolder, '/') ? WebClientPrint::$wcpCacheFolder : WebClientPrint::$wcpCacheFolder . '/') . 'PFG' . uniqid() . '.zip';
                 $res = $zip->open($cacheFileName, ZipArchive::CREATE);
                 if ($res === TRUE) {
                     foreach ($this->printFileGroup as $printFile) {
                         $zip->addFromString($printFile->fileName, $printFile->getFileContent());
                     }
                     $zip->close();
                     $handle = fopen($cacheFileName, 'rb');
                     $buffer .= fread($handle, filesize($cacheFileName));
                     fclose($handle);
                     unlink($cacheFileName);
                 } else {
                     $buffer = 'Creating PrintFileGroup failed. Cannot create zip file.';
                 }
             }
         }
     }
     $arrIdx1 = Utils::intToArray(strlen($buffer));
     if (!isset($this->clientPrinter)) {
         $this->clientPrinter = new UserSelectedPrinter();
     }
     $buffer .= $this->clientPrinter->serialize();
     $arrIdx2 = Utils::intToArray(strlen($buffer));
     $lo = '';
     if (Utils::isNullOrEmptyString(WebClientPrint::$licenseOwner)) {
         $lo = substr(uniqid(), 0, 8);
     } else {
         $lo = WebClientPrint::$licenseOwner;
     }
     $lk = '';
     if (Utils::isNullOrEmptyString(WebClientPrint::$licenseKey)) {
         $lk = substr(uniqid(), 0, 8);
     } else {
         $lk = WebClientPrint::$licenseKey;
     }
     $buffer .= $lo . chr(124) . $lk;
     return $cpjHeader . $arrIdx1 . $arrIdx2 . $buffer;
 }