Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lillem4n/larvconomy
Browse files Browse the repository at this point in the history
  • Loading branch information
lillem4n committed Nov 12, 2011
2 parents 0de6b5e + 44040ef commit 79f64b1
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
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 @@ -111,5 +137,6 @@ public function action_mark_as_paid()
$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;
}
}

}
2 changes: 1 addition & 1 deletion xsl/admin/bills.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<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:if test="paid_date = ''">
Expand Down

0 comments on commit 79f64b1

Please sign in to comment.