Skip to content

Commit

Permalink
Merge pull request #2 from rockymontana/master
Browse files Browse the repository at this point in the history
mailfunktion
  • Loading branch information
lillem4n committed Nov 11, 2011
2 parents 0f51cb3 + c31e74e commit 44040ef
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
27 changes: 27 additions & 0 deletions classes/controller/admin/bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]');
$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()
{
Expand Down Expand Up @@ -109,5 +135,6 @@ public function action_mark_as_paid($details)
$bill->pay($pay_date);
$this->redirect();
}


}
85 changes: 85 additions & 0 deletions classes/mail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php defined('SYSPATH') or die('No direct script access.');

class Mail extends Controller {

private $to = "";
private $from = Array();
private $subject = "";
private $message = "";
private $attachment = "";
private $attname = "";

public function __construct()
{

}

public function to($to)
{
$this->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;
}
}

}
4 changes: 2 additions & 2 deletions xsl/admin/bills.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
<xsl:value-of select="format-number(number(sum), '###,###,###.00')" />
<xsl:text> SEK</xsl:text>
</td>
<td><a href="http://{root/meta/domain}{/root/meta/base}{concat('user_content/pdf/bill_',@id,'.pdf')}">Link</a></td>
<td><a href="http://{/root/meta/domain}{/root/meta/base}{concat('user_content/pdf/bill_',@id,'.pdf')}">Link</a></td>
<td>
<xsl:text>[</xsl:text><a href="http://{root/meta/domain}{/root/meta/base}bill?billnr={@id}">Details</a><xsl:text>]</xsl:text>
<xsl:text>[</xsl:text><a href="http://{/root/meta/domain}{/root/meta/base}bill?billnr={@id}">Details</a><xsl:text>]</xsl:text>
<xsl:if test="paid_date = ''">
<xsl:text>[</xsl:text><a href="bills/mark_as_paid/{@id}/{/root/meta/current_date}" class="paylink" id="paylink_{@id}">Mark as paid</a><xsl:text>]</xsl:text>
</xsl:if>
Expand Down

0 comments on commit 44040ef

Please sign in to comment.