Example #1
0
 private static function doLogFile($logId, $action)
 {
     $files = array('email' => array('file' => Form::getEmailLogFile(), 'as' => 'email-log.txt'), 'data' => array('file' => Form::getFormDataFile(), 'as' => 'form-data.csv'));
     $file = $files[$logId];
     if (!is_file($file['file'])) {
         self::header();
         echo "<b>No " . ($logId == 'email' ? 'email traffic log' : 'form data') . " found.</b>";
         self::footer();
         return;
     }
     switch ($action) {
         case 'view':
             self::header();
             if ($logId == 'data') {
                 $dm = new DataManager();
                 $dm->displayRecords();
             } else {
                 $content = file_get_contents($file['file']);
                 echo "<pre>" . htmlspecialchars($content) . "</pre>";
             }
             self::footer();
             break;
         case 'download':
             self::download($file['file'], $file['as'], true, 1);
             // skip the first line
             break;
         case 'delete':
             self::header();
             $yes = unlink($file['file']);
             echo $yes ? 'Log file deleted.' : 'Failed to delte log file.';
             self::footer();
             break;
     }
     // switch
 }
 private function saveLogs()
 {
     $line = str_repeat('--------', 8);
     $this->addLog("\n\n" . $line);
     $this->addLog(date("Y-m-d H:i:s"));
     $this->addLog("Email Sent: " . ($this->isSent ? 'OK' : 'Failed (' . $this->sendError . ')'));
     $this->addLog($this->sentMIMEMessage);
     $this->addLog($line . "\n\n");
     $logFile = Form::getEmailLogFile();
     Form::secureFile($logFile);
     file_put_contents($logFile, join("\n", $this->logs), FILE_APPEND);
     $this->logs = array();
     // clear
 }