Skip to content

Commit 5bbfc1b

Browse files
committed
Added global functions library which conatins a mail functin that supports attachments and a array_merge function that merges arrays that conatain numeric keys and strings correctly.
1 parent 1061fcf commit 5bbfc1b

File tree

3 files changed

+98
-4
lines changed

3 files changed

+98
-4
lines changed

interface/lib/app.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct() {
7373
if(empty($_SESSION['s']['language'])) $_SESSION['s']['language'] = $conf['language'];
7474
}
7575

76-
$this->uses('auth,plugin');
76+
$this->uses('auth,plugin,functions');
7777
}
7878

7979
public function uses($classes) {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
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())));
48+
49+
if($filename == '') {
50+
$path_parts = pathinfo($filepath);
51+
$filename = $path_parts["basename"];
52+
unset($path_parts);
53+
}
54+
55+
$header = "From: $from\nReply-To: $from\n";
56+
$header .= "MIME-Version: 1.0\n";
57+
$header .= "Content-Type: multipart/mixed; boundary=$uid\n";
58+
59+
$header .= "--$uid\n";
60+
$header .= "Content-Type: text/plain\n";
61+
$header .= "Content-Transfer-Encoding: 8bit\n\n";
62+
$header .= "$text\n";
63+
64+
$header .= "--$uid\n";
65+
$header .= "Content-Type: $filetype; name=\"$filename\"\n";
66+
67+
$header .= "Content-Transfer-Encoding: base64\n";
68+
$header .= "Content-Disposition: attachment; filename=\"$filename\"\n\n";
69+
$header .= "$content\n";
70+
71+
$header .= "--$uid--";
72+
73+
mail($to, $subject, "", $header);
74+
} else {
75+
$header = "From: $from\nReply-To: $from\n";
76+
mail($to, $subject, $text, $header);
77+
}
78+
79+
return true;
80+
}
81+
82+
public function array_merge($array1,$array2) {
83+
$out = $array1;
84+
foreach($array2 as $key => $val) {
85+
$out[$key] = $val;
86+
}
87+
return $out;
88+
}
89+
90+
91+
92+
}
93+
94+
?>

interface/lib/classes/tform.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function loadFormDef($file,$module = '') {
145145
}
146146

147147
if(is_array($wb_global)) {
148-
$wb = $wb_global + $wb;
148+
$wb = $app->functions->array_merge($wb_global,$wb);
149149
}
150150
if(isset($wb_global)) unset($wb_global);
151151

@@ -363,7 +363,7 @@ function getHTML($record, $tab, $action = 'NEW') {
363363
if(isset($field['datasource']) && is_array($field['datasource'])) {
364364
if(is_array($field["value"])) {
365365
//$field["value"] = array_merge($field["value"],$this->getDatasourceData($field, $record));
366-
$field["value"] = $field["value"]+$this->getDatasourceData($field, $record);
366+
$field["value"] = $app->functions->array_merge($field["value"],$this->getDatasourceData($field, $record));
367367
} else {
368368
$field["value"] = $this->getDatasourceData($field, $record);
369369
}
@@ -478,7 +478,7 @@ function getHTML($record, $tab, $action = 'NEW') {
478478
// If Datasource is set, get the data from there
479479
if(@is_array($field['datasource'])) {
480480
if(is_array($field["value"])) {
481-
$field["value"] = array_merge($field["value"],$this->getDatasourceData($field, $record));
481+
$field["value"] = $app->functions->array_merge($field["value"],$this->getDatasourceData($field, $record));
482482
} else {
483483
$field["value"] = $this->getDatasourceData($field, $record);
484484
}

0 commit comments

Comments
 (0)