function Shipping_label_response_content($params) { $streamName = Q_Request::uri()->shipmentStreamName; $publisherId = Users::communityId(); $stream = Streams::fetchOne($publisherId, $publisherId, 'Shipping/shipment/' . $streamName); if (!$stream->testReadLevel('see')) { throw new Users_Exception_NotAuthorized(); } $carrier = json_decode($stream->fields['carrier']) ?: new StdClass(); if (!is_object($carrier)) { throw new exception("carrier is not an object!"); } // TNT carrier if ($carrier->name == "TNT") { $xml = new XMLReader(); // check if XML valid if (!$xml->xml($stream->fields['carrierLabel'], NULL, LIBXML_DTDVALID)) { die("XML not valid"); } // add back button $stream->fields['carrierLabel'] = preg_replace("/<CONSIGNMENTBATCH>/", "<CONSIGNMENTBATCH>\n<ISWEBVIEW>" . Q_Request::isWebView() . "</ISWEBVIEW>", $stream->fields['carrierLabel']); // add FTR Exemptions $invoice = json_decode($stream->invoiceOptions) ?: new StdClass(); $stream->fields['carrierLabel'] = preg_replace("/<CONSIGNMENTBATCH>/", "<CONSIGNMENTBATCH>\n<FTR>" . $invoice->ftrExemptions . "</FTR>", $stream->fields['carrierLabel']); header("Content-Type:text/xml"); echo $stream->fields['carrierLabel']; exit; } elseif (in_array($carrier->name, array("UPS", "FEDEX"))) { $labels = Streams::related($stream->publisherId, $stream->publisherId, $stream->name, true, array("type" => "label")); $orient = Q_Config::expect('Shipping', 'labelsOption', 'orient'); $perPage = (int) Q_Config::expect('Shipping', 'labelsOption', 'perPage'); // angle label rotate 90 or -90 $angle = 1; // for UPS -90, for other 90 if ($carrier->name == "UPS") { $angle = -1; } // include labels size calculation for all labels Q_Response::addScript('js/labels.js'); Q_Response::addStylesheet('css/ShipmentLabels.css'); if ($orient == "vertical") { Q_Response::addStylesheet('css/ShipmentLabelsVertical.css'); } return Q::view('Shipping/content/imgLabels.php', compact('labels', 'perPage', 'angle')); } elseif ($carrier->name == "DHL") { $labels = Streams::related($stream->publisherId, $stream->publisherId, $stream->name, true, array("type" => "label")); $labelsCount = count($labels[1]); if ($labelsCount) { $label = array_shift($labels[1]); Shipping_Carrier_DHL::fixLabels(APP_DIR . "/web/" . $label->content, $stream); exit; //header("location: ".Q_Request::baseUrl().'/'.$label->content); //exit; } } $title = $stream->fields['title']; $addressFrom = json_decode($stream->fields['origin']); $addressTo = json_decode($stream->fields['destination']); $packages = json_decode($stream->fields['packages']); //$carrier = json_decode($stream->fields['carrier']); $invoiceOptions = json_decode($stream->fields['invoiceOptions']); $addressFrom = ($addressFrom->name ? $addressFrom->name . "<br>" : '') . $addressFrom->street . ($addressFrom->unit ? ' ' . $addressFrom->unit : '') . "<br>" . $addressFrom->city . ' ' . $addressFrom->zipcode . "<br>" . $addressFrom->country; $addressTo = ($addressTo->name ? $addressTo->name . "<br>" : '') . $addressTo->street . ($addressTo->unit ? ' ' . $addressTo->unit : '') . "<br>" . "<span class='city'>" . $addressTo->city . ' ' . $addressTo->zipcode . "</span><br>" . $addressTo->country; $exportDate = $invoiceOptions->exportDate; $class = "Shipping_Carrier_" . strtoupper($carrier->name); $labels = $class::labels($addressFrom, $addressTo, $packages, $carrier, $exportDate); echo <<<EOT \t<!DOCTYPE html> \t<html> \t<head> \t\t<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> \t\t<title>Labels for {$title}</title> \t</head> \t<body> \t{$labels} \t</body> </html> EOT; exit; }