forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_runner.php
129 lines (118 loc) · 4.1 KB
/
report_runner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/php
<?php
//--------------------------------------------------------------------
// report_runner.php
// This program is designed to run reports in batch command mode for
// weberp. Much thanks to Phil Daintree as the major author of WEBERP.
//
// --------------------------------------------------------------------
// Written by Alan B Jones ([email protected])
// based on code orgiginally from weberp
// (c) alan jones 2006.
// (c) 2006 logic works Ltd and others
// licenced under the terms of the GPL V(2)
// if you want to know the details of the use of this software
// and how you are licenced to use it under the terms of the
// see here http://www.gnu.org/licenses/gpl.txt
//--------------------------------------------------------------------
//you must tell the script where you main installation is located
//Rememeber this is different for each location
//$weberp_home=/srv/www/htdocs/weberp
$usage="USAGE\n".$argv[0].":\n".
" -r reportnumber (the number of the weberp report)\n".
" -n reportname (the name you want to give the report)\n".
" -e emailaddress[;emailaddress;emailaddres...] (who you want to send it to)\n".
" -d database name (the mysql db to use for the data for the report)\n".
" [-t reporttext ] (some words you want to send with the report-optional)\n".
" [ -H weberpHOME] (the home directory for weberp - or edit the php file)\n";
if ($argc < 7 ) {
echo $usage;
exit;
}
for ($i=1;$i<$argc;$i++){
switch($argv[$i]) {
case '-r':
$i++;
$reportnumber=$argv[$i];
break;
case '-n':
$i++;
$reportname=$argv[$i];
break;
case '-e':
$i++;
$emailaddresses=$argv[$i];
break;
case '-d':
$i++;
$DatabaseName=$argv[$i];
break;
case '-H':
$i++;
$WEBERPHOME=$argv[$i];
break;
case '-t':
$i++;
$mailtext=$argv[$i];
break;
default:
echo "unknown option".$argv[$i]."\n";
echo $usage;
exit;
break;
}
}
// test the existance
if (( $reportname=="") ||
( $reportnumber=="") ||
( $emailaddresses=="")) {
echo $usage;
exit;
}
// do we have a variable
if ($WEBERPHOME!="") {
$weberp_home=$WEBERPHOME;
}
if ($weberp_home=="") {
echo "weberp home is not set in this file or -H is not set";
}
// change directory to the weberp home to get all the includes to work nicely
chdir($weberp_home);
// get me the report name from the command line
$_GET['ReportID'] = $reportnumber;
$Recipients = explode(";",$emailaddresses);
//wrap in angles so that mail can accept it
for ($i=0;$i<count($Recipients); $i++) {
$Recipient[$i]="<".$Recipient[$i].">";
}
$AllowAnyone = true;
include('includes/session.php');
include ('includes/ConstructSQLForUserDefinedSalesReport.inc');
include ('includes/PDFSalesAnalysis.inc');
include('includes/htmlMimeMail.php');
$mail = new htmlMimeMail();
if ($Counter >0){ /* the number of lines of the sales report is more than 0 ie there is a report to send! */
$pdfcode = $pdf->output();
$fp = fopen( $_SESSION['reports_dir']. "/".$reportname,"wb");
fwrite ($fp, $pdfcode);
fclose ($fp);
$attachment = $mail->getFile( $_SESSION['reports_dir'] . "/".$reportname);
$mail->setText($mailtext."\nPlease find herewith ".$reportname." report");
$mail->setSubject($reportname." Report");
$mail->addAttachment($attachment, $reportname, 'application/pdf');
if($_SESSION['SmtpSetting']==0){
$mail->setFrom("");
$result = $mail->send($Recipients);
}else{
$result = SendmailBySmtp($mail,$Recipients);
}
} else {
$mail->setText("Error running automated sales report number $ReportID");
if($_SESSION['SmtpSetting']==0){
$mail->setFrom("Do_not_reply_".$_SESSION['CompanyRecord']['coyname'] . "<" . $_SESSION['CompanyRecord']['email'] . ">");
$result = $mail->send($Recipients);
}else{
$result = SendmailBySmtp($mail,$Recipients);
}
}
?>