<?php require_once 'config.php'; require_once 'gini.php'; $path = '/rechnung/'; $allowedFileTypes = array('pdf', 'png', 'jpg', 'gif', 'jpeg'); if (!empty($_FILES)) { $tempFile = $_FILES['file']['tmp_name']; if (!checkFileType(basename($_FILES['file']['name']), $allowedFileTypes)) { $A['status'] = 0; $A['answer'] = 'file extension not supported'; header('Content-type: application/json'); echo json_encode($A); die; } $gini = new gini(); $status = $gini->upload($tempFile); header('Content-type: application/json'); echo json_encode(array('url' => $path . $status['document_id'])); die; } // does uploaded file has allowed extension? function checkFileType($filename, $allowedFileTypes) { $ext = getExtension($filename); return in_array($ext, $allowedFileTypes); } // get the file extension function getExtension($filename) { $extension = substr($filename, strrpos($filename, '.') + 1);
public function _process_pdf($file, $n, $data, $email) { global $tld, $protocol; // send to gini $status['extractions'] = false; if ($file) { $gini = new gini(); $status = $gini->upload(null, $file); } $json = json_decode($status['extractions']); $uid = md5(uniqid(time())); $header = 'From: rechnung@' . $tld . ' <rechnung@' . $tld . ">\r\n"; $header .= 'Reply-To: hallo@' . $tld . "\r\n"; $header .= 'X-Mailer: willzahlen/' . phpversion() . "\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= 'Content-Type: multipart/mixed; boundary="' . $uid . "\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= '--' . $uid . "\r\n"; $header .= "Content-type:text/html; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message . "\r\n\r\n"; if ($json->extractions && $json->extractions->docType->value != 'Other') { $subject = '€ Rechnung freigeben: ' . $email['header']->subject; $nachricht = '<b>Hallo, die Rechnung ist fertig!</b><br /><br />Überweisen: ' . $protocol . '://' . $tld . '/rechnung/' . $status['document_id'] . '<br /><br />'; if (isset($json->extractions)) { if (isset($json->extractions->senderName)) { $nachricht .= '<em>Empfänger:</em> ' . $json->extractions->senderName->value . '<br />'; } if (isset($json->extractions->iban)) { $nachricht .= '<em>IBAN:</em> ' . $json->extractions->iban->value . '<br />'; } if (isset($json->extractions->bic)) { $nachricht .= '<em>BIC:</em> ' . $json->extractions->bic->value . '<br />'; } if (isset($json->extractions->amountToPay)) { $amount = str_replace(':EUR', ' EUR', $json->extractions->amountToPay->value); $amount = str_replace('.', ',', $amount); $nachricht .= '<em>Betrag:</em> ' . $amount . '<br />'; } if (isset($json->extractions->paymentReference)) { $nachricht .= '<em>Referenz:</em> ' . $json->extractions->paymentReference->value . '<br />'; } $nachricht .= '<br /><br />'; } $nachricht .= 'Fragen? Antworte auf diese Nachricht und wir helfen dir gerne weiter.<br /><br /> Schönen Tag noch,<br />hallo@' . $tld; // move the email to Processed folder on the server $this->email_reader->move($email['index'], 'INBOX.Processed'); } else { $subject = '€ ' . $tld . ' Fehler: ' . $email['header']->subject; $nachricht = '<b>Hallo!</b><br/><br /> In deiner E-Mail an uns wurden <b>keine Rechnungsdaten gefunden</b>.<br /><br /> Sende eine <b>Rechnung</b> im <b>PDF Format</b> als <b>Anhang</b> an rechnung@' . $tld . '<br /><br /> Hier ist eine <a href="' . $protocol . '://' . $tld . '/assets/testrechnung.pdf">Rechnung zum testen</a><br /><br /> Fragen? Antworte auf diese Nachricht und wir helfen dir gerne weiter.<br /><br /> Schönen Tag noch,<br />hallo@' . $tld; $this->email_reader->move($email['index'], 'INBOX.Rejected'); } mail($data['username'] . ' <' . $data['email'] . '>', $subject, $nachricht, $header, '-f hallo@' . $tld); }