$urlParts = parse_url($_SERVER['REQUEST_URI']);
$rawQuery = $urlParts['query'];
if (isset($rawQuery)) {
    if ($rawQuery[WebClientPrint::CLIENT_PRINT_JOB]) {
        parse_str($rawQuery, $qs);
        $useDefaultPrinter = $qs['useDefaultPrinter'] === 'checked';
        $printerName = urldecode($qs['printerName']);
        $pr = new Printer();
        $students = $pr->get_print_job();
        $students_arr = explode(",", $students);
        if (count($students_arr) > 0) {
            foreach ($students_arr as $studentid) {
                $cert_path = $_SERVER['DOCUMENT_ROOT'] . "/lms/custom/certificates/{$studentid}/certificate.jpg";
                $fileName = uniqid() . '.' . $cert_path;
                $filePath = $cert_path;
                if (!Utils::isNullOrEmptyString($filePath)) {
                    //Create a ClientPrintJob obj that will be processed at the client side by the WCPP
                    $cpj = new ClientPrintJob();
                    $cpj->printFile = new PrintFile($filePath, $fileName, null);
                    if ($useDefaultPrinter || $printerName === 'null') {
                        $cpj->clientPrinter = new DefaultPrinter();
                    } else {
                        $cpj->clientPrinter = new InstalledPrinter($printerName);
                    }
                    // end else
                    //Send ClientPrintJob back to the client
                    ob_clean();
                    echo $cpj->sendToClient();
                }
                // end if !Utils::isNullOrEmptyString($filePath)
            }
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;
 }