public static function sendMail($dbh, $cron, $file, $subject = "[CRON MANAGER] Task Completed")
 {
     require_once (GenConfig::LOCATION == 2 ? System::L_SYSTEM_PATH : System::D_SYSTEM_PATH) . "includes/emailSpool/class.emailSpool.php";
     $email = new EmailSpool();
     $email->fromName = "TrafficSynergy CRON Manager";
     $email->fromAdd = "*****@*****.**";
     $email->toAddress = $cron["email_address"];
     # self::getToAddress($id, $dbh); # can be , seperated ; seperated or array
     $cc = self::getCCAddresses($cron["cron_id"], $dbh);
     $bcc = self::getBCCAddresses($cron["cron_id"], $dbh);
     if (!empty($cc)) {
         $email->ccAddress = $cc;
         # can be , seperated ; seperated or array
     }
     if (!empty($bcc)) {
         $email->bccAddress = $bcc;
         # can be , seperated ; seperated or array
     }
     $email->fileAttach = array($file);
     # array of filenames
     # $email->htmlBody 		= file_get_contents($file); #html body - if you want to send an text email set only the textBody
     $email->textBody = file_get_contents($file);
     #this can be the alt Body or text only body
     $email->priority = 4;
     #1 is low 5 is high default 3
     $email->subject = $subject;
     $email->program = "CronManager";
     $email->key = $cron["cron_id"];
     # $id;    # (Optional) A key to identify this email in the context of the program [idnumber/transactionID]
     $email->ref = "";
     # (Optional) Ref to who send the email. Blank for auto email
     if ($_id = $email->submitEmail()) {
         # returns an unique id that is a reference to the inserted email
         SR_Agent::Log(GenConfig::API, SystemReporter::MSG_MESSAGE, "Mail message sent, id #" . $_id);
         return "Message was sent successfully with ID : %lightblue%{$_id}%white% \n";
     } else {
         SR_Agent::Log(GenConfig::API, SystemReporter::MSG_ERROR, "There was an error sending the message :" . $email->error . "\n");
         return "There was an error sending the message : %red%" . $email->error . "%white%\n";
     }
 }
 /**
  * Private Fucntion completeRun
  * @description
  * Function is called after all the databases have been backed up, in order to create a final MD5 checksum of the databases and then compress it all as a single file
  */
 private function completeRun()
 {
     // Check if it is the LIVE environment
     if (LIVE === true) {
         $backupDir = "/ts_backups/mysql_backups/";
     } else {
         $backupDir = "/srv_admin/srv_backups/mysql/";
     }
     // Check if it was a full or incremental backup run
     if (date("D") == "Fri") {
         $backupDir .= "full_backups/";
     } else {
         $backupDir .= "incremental_backups/";
     }
     // Setup paths and filenames
     $folder = $backupDir;
     $backupDir .= date("d_m_Y") . "/";
     $compressed_file = $folder . date("d_m_Y") . ".tar.gz";
     // Check if it is a simulated run
     if (!$this->simulation) {
         exec("md5sum {$backupDir}/*.tar.gz > {$backupDir}/databases.md5");
         if (DEBUG === true) {
             OutputHandler::displayOutput("[%lightgreen%DEBUG%lightgray%] Generated MD5 Hashes of DB Backups%lightgray%", $this->color);
         }
     }
     $command = "tar -zcvf {$compressed_file} {$backupDir}";
     if (DEBUG === true) {
         OutputHandler::displayOutput("[%lightgreen%DEBUG%lightgray%] Command : %lightblue%{$command}%lightgray%", $this->color);
     }
     // Check if it is a simulated run
     if (!$this->simulation) {
         exec($command, $command_output);
         // Generate MD5 checksum of the compressed file (usefull for integrity checks)
         exec("md5sum {$compressed_file} > {$compressed_file}.md5");
     } else {
         $command_output = array("Folder compressed");
     }
     // Check if debugging is enabled
     if (DEBUG === true) {
         // Display debugging information
         foreach ($command_output as $cmd_output) {
             OutputHandler::displayOutput("[%lightgreen%DEBUG%lightgray%] [%lightblue%{$backupDir}%lightgray%]\t" . $cmd_output, $this->color);
         }
     }
     // Check if it is a simulated run
     if (!$this->simulation) {
         exec("rm -rf {$backupDir}");
     }
     SR_Agent::Log(APPID, SystemReporter::MSG_SUCCESS, "Backup complete for " . date("d/m/Y"));
 }