public function handleTask(&$context) { $printer = $this->get('printer'); if (empty($printer) || $printer == -1) { $this->addStat('You must configure printer before you could use this block!'); return "yes"; } $workingFiles = array(); $files = json_decode($this->get("files"), true); if (is_array($files) && count($files) > 0) { // Module greifen auf Datenbank zurück. Daher vorher speichern! $context->save(); foreach ($files as $key => $value) { if (is_string($value)) { $value = array($value, false, array()); } if (strpos($key, 's#') === 0) { $tmpParts = explode('#', $key, 2); $specialAttachments = \Workflow\Attachment::getAttachments($tmpParts[1], $value, $context, \Workflow\Attachment::MODE_NOT_ADD_NEW_ATTACHMENTS); foreach ($specialAttachments as $attachment) { if ($attachment[0] === 'ID') { $tmp = \Workflow\VtUtils::getFileDataFromAttachmentsId($attachment[1]); $workingFiles[] = array('path' => $tmp['path'], 'filename' => $tmp['filename']); } elseif ($attachment[0] === 'PATH') { $workingFiles[] = array('path' => $attachment[1], 'filename' => $attachment[2]['filename']); } } } } if (count($workingFiles) > 0) { $capabilities = $this->get('capability'); $capabilityOption = array(); foreach ($capabilities as $capability => $value) { switch ($capability) { case 'page_orientation': $capabilityOption['page_orientation']['type'] = $value; break; case 'duplex': $capabilityOption['duplex']['type'] = $value; break; } } foreach ($workingFiles as $file) { $resarray = $this->gcp->sendPrintToPrinter($printer, 'VtigerCRM Print ' . $file['filename'], $file['path'], "application/pdf", json_encode($capabilityOption)); } } } return "yes"; }