Skip to content

Commit 79f64b1

Browse files
committed
Merge branch 'master' of github.com:lillem4n/larvconomy
2 parents 0de6b5e + 44040ef commit 79f64b1

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

classes/controller/admin/bills.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ public function action_index()
1414
$this->xml_content_bills = $this->xml_content->appendChild($this->dom->createElement('bills'));
1515
xml::to_XML(Bills::get(), $this->xml_content_bills, 'bill', 'id');
1616
}
17+
18+
public function action_email()
19+
{
20+
//Get the bill data.
21+
$bill = New Bill($_GET['invoice']);
22+
$costumer = $bill->get_customer_data('costumer_email');
23+
24+
$mail = new Mail();
25+
$mail->from('Larv IT AB', '[email protected]');
26+
$mail->to($costumer);
27+
$mail->subject('Invoice from Larv IT');
28+
$mail->content('Invoice sent');
29+
$mail->attachment(url::base('http',FALSE).'/user_content/pdf/bill_'.$_GET['invoice'].'.pdf');
30+
31+
if($mail->send())
32+
{
33+
die('Email was sent and costumer = '.$costumer);
34+
}
35+
else
36+
{
37+
die('email was not sent and costumer = '.$costumer);
38+
}
39+
40+
// if email sent then update bills.invoice_sent with CURRENT_TIMESTAMP
41+
}
42+
1743

1844
public function action_new_bill()
1945
{
@@ -111,5 +137,6 @@ public function action_mark_as_paid()
111137
$bill->pay($pay_date);
112138
$this->redirect();
113139
}
140+
114141

115142
}

classes/mail.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php defined('SYSPATH') or die('No direct script access.');
2+
3+
class Mail extends Controller {
4+
5+
private $to = "";
6+
private $from = Array();
7+
private $subject = "";
8+
private $message = "";
9+
private $attachment = "";
10+
private $attname = "";
11+
12+
public function __construct()
13+
{
14+
15+
}
16+
17+
public function to($to)
18+
{
19+
$this->to = $to;
20+
}
21+
22+
public function from($name, $email)
23+
{
24+
$this->from['name'] = $name;
25+
$this->from['email'] = $email;
26+
}
27+
28+
public function subject($subject)
29+
{
30+
$this->subject = $subject;
31+
}
32+
33+
public function content($message)
34+
{
35+
$this->message = $message;
36+
}
37+
38+
public function attachment($fileURL)
39+
{
40+
$file = fopen($fileURL, 'rb');
41+
$fileContent = stream_get_contents($file);
42+
fclose($file);
43+
44+
$this->attachment = $fileContent;
45+
$this->attname = basename($fileURL);
46+
}
47+
48+
public function send()
49+
{
50+
$header = 'From: "'.$this->from['name'].'" <'.$this->from['email'].'>\r\n';
51+
$header .= 'Reply-To: '.$this->from['email'].'\r\n';
52+
$header .= 'Content-Type: text/plain; charset=UTF-8\r\n' .
53+
'Content-Transfer-Encoding: base64\r\n\r\n';
54+
55+
$content = "";
56+
if($this->attachment)
57+
{
58+
$semi_rand = md5(time());
59+
$mime_boundary = '==Multipart_Boundary_x'.$semi_rand.'x';
60+
61+
$header .= '\nMIME-Version: 1.0\n' .
62+
'Content-Type: multipart/mixed;\n' .
63+
'boundary=" '. $mime_boundary .'"';
64+
65+
$this->attachment = chunk_split(base64_encode($this->attachment));
66+
$content .= ''.$mime_boundary.'\n' .
67+
'Content-Type: application/pdf;\n' .
68+
'name="'. $this->attname .'"\n' .
69+
'Content-Disposition: attachment;\n' .
70+
'filename= "'. $this->attname .'"\n' .
71+
'Content-Transfer-Encoding: base64\n\n' .
72+
$this->attachment . '\n\n' .
73+
'-'.$mime_boundary.'-\n';
74+
}
75+
if( mail($this->to,$this->subject, $this->message, $header) )
76+
{
77+
return TRUE;
78+
}
79+
else
80+
{
81+
return FALSE;
82+
}
83+
}
84+
85+
}

xsl/admin/bills.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<xsl:value-of select="format-number(number(sum), '###,###,###.00')" />
7777
<xsl:text> SEK</xsl:text>
7878
</td>
79-
<td><a href="http://{root/meta/domain}{/root/meta/base}{concat('user_content/pdf/bill_',@id,'.pdf')}">Link</a></td>
79+
<td><a href="http://{/root/meta/domain}{/root/meta/base}{concat('user_content/pdf/bill_',@id,'.pdf')}">Link</a></td>
8080
<td>
8181
<xsl:text>[</xsl:text><a href="http://{/root/meta/domain}{/root/meta/base}bill?billnr={@id}">Details</a><xsl:text>]</xsl:text>
8282
<xsl:if test="paid_date = ''">

0 commit comments

Comments
 (0)