diff --git a/classes/controller/admin/bills.php b/classes/controller/admin/bills.php index 0ea0498..70ef583 100644 --- a/classes/controller/admin/bills.php +++ b/classes/controller/admin/bills.php @@ -14,6 +14,32 @@ public function action_index() $this->xml_content_bills = $this->xml_content->appendChild($this->dom->createElement('bills')); xml::to_XML(Bills::get(), $this->xml_content_bills, 'bill', 'id'); } + + public function action_email() + { + //Get the bill data. + $bill = New Bill($_GET['invoice']); + $costumer = $bill->get_customer_data('costumer_email'); + + $mail = new Mail(); + $mail->from('Larv IT AB', 'info@larvit.se'); + $mail->to($costumer); + $mail->subject('Invoice from Larv IT'); + $mail->content('Invoice sent'); + $mail->attachment(url::base('http',FALSE).'/user_content/pdf/bill_'.$_GET['invoice'].'.pdf'); + + if($mail->send()) + { + die('Email was sent and costumer = '.$costumer); + } + else + { + die('email was not sent and costumer = '.$costumer); + } + + // if email sent then update bills.invoice_sent with CURRENT_TIMESTAMP + } + public function action_new_bill() { @@ -109,5 +135,6 @@ public function action_mark_as_paid($details) $bill->pay($pay_date); $this->redirect(); } + } diff --git a/classes/mail.php b/classes/mail.php new file mode 100644 index 0000000..5ec07c6 --- /dev/null +++ b/classes/mail.php @@ -0,0 +1,85 @@ +to = $to; + } + + public function from($name, $email) + { + $this->from['name'] = $name; + $this->from['email'] = $email; + } + + public function subject($subject) + { + $this->subject = $subject; + } + + public function content($message) + { + $this->message = $message; + } + + public function attachment($fileURL) + { + $file = fopen($fileURL, 'rb'); + $fileContent = stream_get_contents($file); + fclose($file); + + $this->attachment = $fileContent; + $this->attname = basename($fileURL); + } + + public function send() + { + $header = 'From: "'.$this->from['name'].'" <'.$this->from['email'].'>\r\n'; + $header .= 'Reply-To: '.$this->from['email'].'\r\n'; + $header .= 'Content-Type: text/plain; charset=UTF-8\r\n' . + 'Content-Transfer-Encoding: base64\r\n\r\n'; + + $content = ""; + if($this->attachment) + { + $semi_rand = md5(time()); + $mime_boundary = '==Multipart_Boundary_x'.$semi_rand.'x'; + + $header .= '\nMIME-Version: 1.0\n' . + 'Content-Type: multipart/mixed;\n' . + 'boundary=" '. $mime_boundary .'"'; + + $this->attachment = chunk_split(base64_encode($this->attachment)); + $content .= '–'.$mime_boundary.'\n' . + 'Content-Type: application/pdf;\n' . + 'name="'. $this->attname .'"\n' . + 'Content-Disposition: attachment;\n' . + 'filename= "'. $this->attname .'"\n' . + 'Content-Transfer-Encoding: base64\n\n' . + $this->attachment . '\n\n' . + '-'.$mime_boundary.'-\n'; + } + if( mail($this->to,$this->subject, $this->message, $header) ) + { + return TRUE; + } + else + { + return FALSE; + } + } + +} diff --git a/xsl/admin/bills.xsl b/xsl/admin/bills.xsl index d917458..d15ed3b 100644 --- a/xsl/admin/bills.xsl +++ b/xsl/admin/bills.xsl @@ -76,9 +76,9 @@ SEK - Link + Link - [Details] + [Details] [Mark as paid]