$printData = $db->printJob($id);
$template = '^XA
^XFE:TEMPLATE.ZPL^FS
^FN1^FD'.$printData['company_name'].'^FS
^FN2^FD'.$printData['street_name'].'^FS
^FN3^FD'.$printData['town_name'].'^FS
^FN4^FD'.$printData['post_code'].'^FS
^FN5^FD'.$printData['task_description'].'^FS
^FN6^FD'.$printData['bms_number'].'^FS
^FN7^FD'.$printData['order_number'].'^FS
^XZ';
$createTemplate = file_put_contents('template.zpl', $template);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.zebra.com/v2/devices/printers/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$template = "template.zpl";
$post = array(
'sn' => 'SERIALNUMBER',
'zpl_file' => new \CURLFile(realpath($template))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$headers[] = 'Apikey: APIKEY';
$headers[] = 'Tenant: TENANTID';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
switch($http_status) {
case 200:
echo $util->showMessage('Success', 'Print successfull.');
break;
case 400:
echo $util->showMessage('Error', 'Bad printer request (400).');
break;
case 401:
echo $util->showMessage('Error', 'Printer authentication information is missing or invalid (401).');
break;
case 403:
echo $util->showMessage('Error', 'Forbidden (403).');
break;
case 404:
echo $util->showMessage('Error', 'Printer not found or you dont have rights to access this printer (404).');
break;
case 429:
echo $util->showMessage('Error', 'Quota violation, you exceeded the 100 calls daily limit (429).');
break;
default:
echo $util->showMessage('Error', 'Unexpected error.');
break;
}