-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function to send reports by mail
- Loading branch information
1 parent
0d9b611
commit 11fccdb
Showing
5 changed files
with
167 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,16 @@ class Settings_Database | |
|
||
class Settings_Mail | ||
{ | ||
public static $From = "[email protected]"; | ||
public static $FromMail = "[email protected]"; | ||
public static $FromName = "Example"; | ||
public static $ToAlert = "[email protected]"; | ||
} | ||
|
||
class Settings_Report | ||
{ | ||
public static $Base_URL = "http:\\example.com"; | ||
public static $BaseURL = "http://example.com/Reports/run.php"; | ||
public static $ProjectName = "Project"; | ||
public static $ProjectPassword = "Password"; | ||
public static $VariableToday = "!TODAY!"; | ||
public static $VariableAnd = "!AND!"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
require_once "../Webservice/send_mail.php"; | ||
require_once "../Webservice/utility.php"; | ||
|
||
|
||
if (isset($_GET["MailTo"]) && isset($_GET["ReportName"]) && isset($_GET["Filters"])) | ||
{ | ||
if (!empty($_GET["MailTo"]) && !empty($_GET["ReportName"])) | ||
{ | ||
//Assign variables | ||
$MailTo = $_GET["MailTo"]; | ||
$ReportName = $_GET["ReportName"]; | ||
if (!empty($_GET["Filters"])) | ||
$Filters = $_GET["Filters"]; | ||
else | ||
$Filters = ""; | ||
|
||
//Format dates | ||
$VarToday = Settings_Report::$VariableToday; | ||
$VarAnd = Settings_Report::$VariableAnd; | ||
while (substr_count($Filters, $VarToday) > 0) | ||
{ | ||
$OccurencePos = strpos($Filters, $VarToday); | ||
if ($OccurencePos > 0) | ||
{ | ||
if (strpos($Filters,"$VarAnd",$OccurencePos) > 0) | ||
$OccurenceEnd = strpos ($Filters,"$VarAnd",$OccurencePos); | ||
else | ||
$OccurenceEnd = strlen ($Filters); | ||
$Operator = substr ($Filters, $OccurencePos + strlen($VarToday), 1); | ||
$Days = substr ($Filters, $OccurencePos + 1 + strlen($VarToday), $OccurenceEnd - $OccurencePos - 1 - strlen($VarToday)); | ||
if ($Operator == "-") | ||
$Date = date ("Y-m-d", strtotime ("-${Days} days")); | ||
else | ||
$Date = date ("Y-m-d"); | ||
$Filters = substr_replace ($Filters, $Date, $OccurencePos, $OccurenceEnd - $OccurencePos); | ||
} | ||
} | ||
|
||
//Replace "&" sign | ||
$Filters = str_replace($VarAnd,"&",$Filters); | ||
|
||
//Create URL | ||
$URL = Settings_Report::$BaseURL; | ||
$URL .= "?execute_mode=EXECUTE&target_format=PDF"; | ||
$URL .= "&project=".Settings_Report::$ProjectName; | ||
$URL .= "&project_password=".Settings_Report::$ProjectPassword; | ||
$URL .= "&xmlin=${ReportName}.xml"; | ||
if ($Filters <> "") | ||
$URL .= "&".$Filters; | ||
|
||
$Time = str_replace(".","",microtime(true)); | ||
$FilePath = "../Temp/${ReportName}_${Time}.pdf"; | ||
|
||
if (ManageFile::DownloadFile($URL,$FilePath)) | ||
{ | ||
$URL = str_replace("&project_password=".Settings_Report::$ProjectPassword,"",$URL); | ||
if (Send_Mail::ReportPDF($MailTo,$ReportName,$URL,$FilePath)) | ||
echo "Mail sent successfully"; | ||
if (file_exists($FilePath)) | ||
unlink ($FilePath); | ||
} | ||
} | ||
else | ||
{ | ||
echo ("Required parameter empty"); | ||
$Message = "Required parameter empty:"."<br>"; | ||
foreach ($_GET as $Key => $Value) | ||
{ | ||
$Message .= $Key." = '${Value}'"; | ||
$Message .= "<br>"; | ||
} | ||
$Message .= "<br>"."<br>"."Server data:"."<br>"; | ||
foreach ($_SERVER as $Key => $Value) | ||
{ | ||
$Message .= $Key." = '${Value}'"; | ||
$Message .= "<br>"; | ||
} | ||
|
||
Send_Mail::OnError($Message); | ||
} | ||
} | ||
else | ||
{ | ||
echo ("Required parameter missing"); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
class ManageFile | ||
{ | ||
public function DownloadFile ($URL,$FilePath) | ||
{ | ||
$Length = 5120; | ||
|
||
$Handle = fopen($URL, "rb"); | ||
$Write = fopen($FilePath, "w"); | ||
|
||
while (!feof($Handle)) | ||
{ | ||
$Buffer = fread($Handle, $Length); | ||
fwrite($Write, $Buffer); | ||
} | ||
|
||
fclose($Handle); | ||
fclose($Write); | ||
|
||
return file_exists ($FilePath); | ||
} | ||
} | ||
|
||
class Localize | ||
{ | ||
public function getLocationInfoByIp ($IpAddress) | ||
{ | ||
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$IpAddress)); | ||
if($ip_data && $ip_data->geoplugin_countryName != null) | ||
{ | ||
//$result["Country"] = $ip_data->geoplugin_countryName; | ||
//$result["City"] = $ip_data->geoplugin_city; | ||
$result = $ip_data->geoplugin_countryName; | ||
} | ||
return $result; | ||
} | ||
} | ||
?> |