| 1 | <?php
|
| 2 |
|
| 3 | class Controller_Report extends Controller_cron
|
| 4 | {
|
| 5 | public function __construct()
|
| 6 | {
|
| 7 | parent::__construct();
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 | SWIFT_Ticket::LoadLanguageTable();
|
| 12 |
|
| 13 | return true;
|
| 14 | }
|
| 15 |
|
| 16 | public function __destruct()
|
| 17 | {
|
| 18 | parent::__destruct();
|
| 19 |
|
| 20 | return true;
|
| 21 | }
|
| 22 |
|
| 23 | Public function MyReports ($_CustomCode = '')
|
| 24 | {
|
| 25 | /*
|
| 26 | Enter your custom reports in this section, by repeating the $_MyCustomCodes line, the format is as follows:
|
| 27 |
|
| 28 | $_MyCustomCodes[] = Array(<Start Code>,<Report ID>,<Email Address to sent the report to>,<Email Subject>,<Email Body>);
|
| 29 |
|
| 30 | Example:
|
| 31 |
|
| 32 | $_MyCustomCodes[] = Array('22424324324324','111','gary@emailaddy.com','My new report!','This is my new report');
|
| 33 | $_MyCustomCodes[] = Array('466364','111','gary@emailaddy.com','The weekly info','Please find attached your weekly ticket update');
|
| 34 | $_MyCustomCodes[] = Array('72434242','111','gary@emailaddy.com','your daily report','Tickets submitted today');
|
| 35 |
|
| 36 | You can also create several reports with the same Start Code, then when that start code is called, all the reports using that code will be emailed out
|
| 37 |
|
| 38 | Example:
|
| 39 |
|
| 40 | $_MyCustomCodes[] = Array('22424324324324','111','gary@emailaddy.com','Tickets still open','Tickets which are not resolved yet');
|
| 41 | $_MyCustomCodes[] = Array('22424324324324','115','gary@emailaddy.com','Tickets closed this week','List of tickets closed this week');
|
| 42 | $_MyCustomCodes[] = Array('22424324324324','123','gary@emailaddy.com','Tickets created by your staff','List of how many tickets your staff created, grouped by staff name');
|
| 43 |
|
| 44 | ATTACH ALL REPORTS TO A SINGLE EMAIL
|
| 45 |
|
| 46 | If you wish to attach several reports to a single email for the same customer, you can do so by replacing the report number with an array, example below:
|
| 47 |
|
| 48 | $_MyCustomCodes[] = Array('22424324324324',array('111','65','46'),'gary@emailaddy.com','Your weekly reports','Please find attached all your weekly reports');
|
| 49 |
|
| 50 | How to Use, once your reports are setup, you can simply call the relevant URL, and the reports will be run
|
| 51 |
|
| 52 | Example:
|
| 53 |
|
| 54 | http://helpdeskURL/cron/index.php?/Tickets/Report/GeneralTasks/22424324324324
|
| 55 |
|
| 56 | You can then either schedule a task to call the reports URL as needed, or give the URL to your customers, who can then call the reports
|
| 57 | for themselves, whenever they wish. ( Obviously you will want to assign each customer a unique code )
|
| 58 |
|
| 59 | */
|
| 60 |
|
| 61 |
|
| 62 | $_MyCustomCodes[] = Array('codehere','reportidhere','emailhere','emailsubject','emailbody');
|
| 63 |
|
| 64 |
|
| 65 | // DO NOT EDIT BELOW THIS LINE
|
| 66 | $_SWIFT = SWIFT::GetInstance();
|
| 67 | $_firedreport = false;
|
| 68 | foreach ($_MyCustomCodes as $CustomReports)
|
| 69 | {
|
| 70 | If ($CustomReports[0] == $_CustomCode){
|
| 71 |
|
| 72 | if (is_array($CustomReports[1]))
|
| 73 | {
|
| 74 | $_Finalattachments = Array();
|
| 75 | $_rpttext = 'The reports have been emailed out via a single email<br>Reports attached:<br> ';
|
| 76 | foreach ($CustomReports[1] as $Mfile) {
|
| 77 | $_SWIFT_ReportObject = new SWIFT_Report(new SWIFT_DataID($Mfile));
|
| 78 | $_exportFormat = 'exportexcel2007';
|
| 79 | $_SWIFT_ReportExportObject = SWIFT_ReportExport::Process($_SWIFT_ReportObject, $_exportFormat);
|
| 80 | $_Finalattachments[] = $_SWIFT_ReportExportObject->DispatchMEFile($Mfile);
|
| 81 | }
|
| 82 |
|
| 83 | $this->Mail = new SWIFT_Mail();
|
| 84 | foreach ($_Finalattachments as $attachment){
|
| 85 | $this->Mail->Attach($attachment[0],$attachment[1] ,$attachment[2]);
|
| 86 | $_rpttext .= $attachment[2] . '<br>';
|
| 87 | }
|
| 88 | $this->Mail->SetToField($CustomReports[2]);
|
| 89 |
|
| 90 | $this->Mail->SetFromField($this->Settings->Get('general_returnemail'), SWIFT::Get('companyname'));
|
| 91 | $this->Mail->SetSubjectField($CustomReports[3]);
|
| 92 | $this->Mail->SetDataText($CustomReports[4]);
|
| 93 | $this->Mail->SetDataHTML($CustomReports[4]);
|
| 94 | $this->Mail->SendMail();
|
| 95 | $_firedreport = true;
|
| 96 | echo $_rpttext . '<br>Finished.<br>';
|
| 97 |
|
| 98 | }else{
|
| 99 | $_SWIFT_ReportObject = new SWIFT_Report(new SWIFT_DataID($CustomReports[1]));
|
| 100 | $_exportFormat = 'exportexcel2007';
|
| 101 | $_SWIFT_ReportExportObject = SWIFT_ReportExport::Process($_SWIFT_ReportObject, $_exportFormat);
|
| 102 | $_result = $_SWIFT_ReportExportObject->DispatchEFile($CustomReports[2],$CustomReports[3],$CustomReports[4]);
|
| 103 | echo 'The report: ' . $CustomReports[1] .' has been emailed out<br>';
|
| 104 | $_firedreport = true;
|
| 105 | }
|
| 106 |
|
| 107 |
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | if ($_firedreport != true){
|
| 112 | echo 'No Reports were found matching your request.';
|
| 113 | }
|
| 114 |
|
| 115 | return;
|
| 116 |
|
| 117 |
|
| 118 | }
|
| 119 |
|
| 120 | public function GeneralTasks($_CustomCode = '')
|
| 121 | {
|
| 122 | if (!$this->GetIsClassLoaded())
|
| 123 | {
|
| 124 | throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);
|
| 125 |
|
| 126 | return false;
|
| 127 | }
|
| 128 | if ($_CustomCode == '' ){
|
| 129 | echo 'sorry, no valid code was entered';
|
| 130 | return;
|
| 131 | }
|
| 132 | self::MyReports($_CustomCode);
|
| 133 |
|
| 134 | return true;
|
| 135 | }
|
| 136 |
|
| 137 | /**
|
| 138 | * Runs the Ticket Auto Close Routines
|
| 139 | *
|
| 140 | * @author Varun Shoor
|
| 141 | * @return bool "true" on Success, "false" otherwise
|
| 142 | * @throws SWIFT_Exception If the Class is not Loaded
|
| 143 | */
|
| 144 |
|
| 145 | }
|
| 146 | ?> |