commit | author | age
|
532ae5
|
1 |
<?php |
L |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2010, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
//* The purpose of this library is to provide some general functions. |
|
32 |
//* This class is loaded automatically by the ispconfig framework. |
|
33 |
|
|
34 |
class functions { |
|
35 |
|
|
36 |
|
|
37 |
public function mail($to, $subject, $text, $from, $filepath = '', $filetype = 'application/pdf', $filename = '') { |
|
38 |
global $app,$conf; |
|
39 |
|
|
40 |
if($conf['demo_mode'] == true) $app->error("Mail sending disabled in demo mode."); |
|
41 |
|
|
42 |
if($filepath != '') { |
|
43 |
if(!file_exists($filepath)) $app->error("Mail attachement does not exist ".$filepath); |
|
44 |
|
|
45 |
$content = file_get_contents($filepath); |
|
46 |
$content = chunk_split(base64_encode($content)); |
|
47 |
$uid = strtoupper(md5(uniqid(time()))); |
fea974
|
48 |
$subject = "=?utf-8?B?".base64_encode($subject)."?="; |
532ae5
|
49 |
|
L |
50 |
if($filename == '') { |
|
51 |
$path_parts = pathinfo($filepath); |
|
52 |
$filename = $path_parts["basename"]; |
|
53 |
unset($path_parts); |
|
54 |
} |
|
55 |
|
46598e
|
56 |
$header = "Return-Path: $form\nFrom: $from\nReply-To: $from\n"; |
532ae5
|
57 |
$header .= "MIME-Version: 1.0\n"; |
L |
58 |
$header .= "Content-Type: multipart/mixed; boundary=$uid\n"; |
|
59 |
|
|
60 |
$header .= "--$uid\n"; |
5645a5
|
61 |
$header .= "Content-Type: text/plain;\n\tcharset=\"UTF-8\"\n"; |
532ae5
|
62 |
$header .= "Content-Transfer-Encoding: 8bit\n\n"; |
L |
63 |
$header .= "$text\n"; |
|
64 |
|
|
65 |
$header .= "--$uid\n"; |
|
66 |
$header .= "Content-Type: $filetype; name=\"$filename\"\n"; |
|
67 |
|
|
68 |
$header .= "Content-Transfer-Encoding: base64\n"; |
|
69 |
$header .= "Content-Disposition: attachment; filename=\"$filename\"\n\n"; |
|
70 |
$header .= "$content\n"; |
|
71 |
|
|
72 |
$header .= "--$uid--"; |
|
73 |
|
|
74 |
mail($to, $subject, "", $header); |
|
75 |
} else { |
|
76 |
$header = "From: $from\nReply-To: $from\n"; |
f442da
|
77 |
$header .= "Content-Type: text/plain;\n\tcharset=\"UTF-8\"\n"; |
T |
78 |
$header .= "Content-Transfer-Encoding: 8bit\n\n"; |
fea974
|
79 |
$subject = "=?utf-8?B?".base64_encode($subject)."?="; |
532ae5
|
80 |
mail($to, $subject, $text, $header); |
L |
81 |
} |
|
82 |
|
|
83 |
return true; |
|
84 |
} |
|
85 |
|
|
86 |
public function array_merge($array1,$array2) { |
|
87 |
$out = $array1; |
|
88 |
foreach($array2 as $key => $val) { |
|
89 |
$out[$key] = $val; |
|
90 |
} |
|
91 |
return $out; |
|
92 |
} |
|
93 |
|
|
94 |
public function currency_format($number) { |
|
95 |
global $app; |
|
96 |
$number_format_decimals = (int)$app->lng('number_format_decimals'); |
|
97 |
$number_format_dec_point = $app->lng('number_format_dec_point'); |
|
98 |
$number_format_thousands_sep = $app->lng('number_format_thousands_sep'); |
|
99 |
if($number_format_thousands_sep == 'number_format_thousands_sep') $number_format_thousands_sep = ''; |
|
100 |
return number_format((double)$number, $number_format_decimals, $number_format_dec_point, $number_format_thousands_sep); |
|
101 |
} |
|
102 |
|
|
103 |
public function get_ispconfig_url() { |
5b92a4
|
104 |
$url = (stristr($_SERVER['SERVER_PROTOCOL'],'HTTPS') || stristr($_SERVER['HTTPS'],'on'))?'https':'http'; |
532ae5
|
105 |
$url .= '://'.$_SERVER['SERVER_NAME']; |
L |
106 |
if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { |
|
107 |
$url .= ':'.$_SERVER['SERVER_PORT']; |
|
108 |
} |
|
109 |
return $url; |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
} |
|
114 |
|
5bbfc1
|
115 |
?> |