/** snapin_log_post()
 		Display's the dates to filter through.
 	*/
 public function snapin_log_post()
 {
     // Set title
     $this->title = _('FOG Snapin Log');
     // This gets the download links for which type of file you want.
     print "\n\t\t\t\t<h2>" . '<a href="export.php?type=csv&filename=SnapinLog" alt="Export CSV" title="Export CSV" target="_blank">' . $this->csvfile . '</a> <a href="export.php?type=pdf&filename=SnapinLog" alt="Export PDF" title="Export PDF" target="_blank">' . $this->pdffile . '</a></h2>';
     // Header Data
     $this->headerData = array(_('Snapin Name'), _('State'), _('Return Code'), _('Return Desc'), _('Create Date'), _('Create Time'));
     // Templates
     $this->templates = array('${snap_name}', '${snap_state}', '${snap_return}', '${snap_detail}', '${snap_create}', '${snap_time}');
     // Setup Report Maker for this class.
     $ReportMaker = new ReportMaker();
     // Set dates and check order is proper
     $date1 = $_REQUEST['date1'];
     $date2 = $_REQUEST['date2'];
     if ($date1 > $date2) {
         $date1 = $_REQUEST['date2'];
         $date2 = $_REQUEST['date1'];
     }
     $date2 = date('Y-m-d', strtotime($date2 . '+1 day'));
     // This is just for the header in the CSV:
     $csvHead = array(_('Host ID'), _('Host Name'), _('Host MAC'), _('Snapin ID'), _('Snapin Name'), _('Snapin Description'), _('Snapin File'), _('Snapin Args'), _('Snapin Run With'), _('Snapin Run With Args'), _('Snapin State'), _('Snapin Return Code'), _('Snapin Return Detail'), _('Snapin Creation Date'), _('Snapin Creation Time'), _('Job Create Date'), _('Job Create Time'), _('Task Checkin Date'), _('Task Checkin Time'));
     foreach ((array) $csvHead as $csvHeader) {
         $ReportMaker->addCSVCell($csvHeader);
     }
     $ReportMaker->endCSVLine();
     // Find all snapin tasks
     $SnapinTasks = $this->getClass('SnapinTaskManager')->find(array('checkin' => '', 'complete' => ''), 'OR', '', '', "BETWEEN '{$date1}' AND '{$date2}'");
     foreach ((array) $SnapinTasks as $SnapinTask) {
         $SnapinCheckin1 = $this->nice_date($SnapinTask->get('checkin'));
         $SnapinCheckin2 = $this->nice_date($SnapinTask->get('complete'));
         // Get the Task based on create date thru complete date
         // Get the snapin
         $Snapin = new Snapin($SnapinTask->get('snapinID'));
         // Get the Job
         $SnapinJob = new SnapinJob($SnapinTask->get('jobID'));
         // Get the Host
         $Host = new Host($SnapinJob->get('hostID'));
         $hostID = $SnapinJob->get('hostID');
         $hostName = $Host->isValid() ? $Host->get('name') : '';
         $hostMac = $Host->isValid() ? $Host->get('mac') : '';
         $snapinID = $SnapinTask->get('snapinID');
         $snapinName = $Snapin->isValid() ? $Snapin->get('name') : '';
         $snapinDesc = $Snapin->isValid() ? $Snapin->get('description') : '';
         $snapinFile = $Snapin->isValid() ? $Snapin->get('file') : '';
         $snapinArgs = $Snapin->isValid() ? $Snapin->get('args') : '';
         $snapinRw = $Snapin->isValid() ? $Snapin->get('runWith') : '';
         $snapinRwa = $Snapin->isValid() ? $Snapin->get('runWithArgs') : '';
         $snapinState = $SnapinTask->get('stateID');
         $snapinReturn = $SnapinTask->get('return');
         $snapinDetail = $SnapinTask->get('detail');
         $snapinCreateDate = $Snapin->isValid() ? $this->formatTime($Snapin->get('createdTime'), 'Y-m-d') : '';
         $snapinCreateTime = $Snapin->isValid() ? $this->formatTime($Snapin->get('createdTime'), 'H:i:s') : '';
         $jobCreateDate = $this->formatTime($SnapinJob->get('createdTime'), 'Y-m-d');
         $jobCreateTime = $this->formatTime($SnapinJob->get('createdTime'), 'H:i:s');
         $TaskCheckinDate = $SnapinCheckin1->format('Y-m-d');
         $TaskCheckinTime = $SnapinCheckin2->format('H:i:s');
         $this->data[] = array('snap_name' => $snapinName, 'snap_state' => $snapinState, 'snap_return' => $snapinReturn, 'snap_detail' => $snapinDetail, 'snap_create' => $snapinCreateDate, 'snap_time' => $snapinCreateTime);
         $ReportMaker->addCSVCell($hostID);
         $ReportMaker->addCSVCell($hostName);
         $ReportMaker->addCSVCell($HostMac);
         $ReportMaker->addCSVCell($snapinID);
         $ReportMaker->addCSVCell($snapinName);
         $ReportMaker->addCSVCell($snapinDesc);
         $ReportMaker->addCSVCell($snapinFile);
         $ReportMaker->addCSVCell($snapinArgs);
         $ReportMaker->addCSVCell($snapinRw);
         $ReportMaker->addCSVCell($snapinRwa);
         $ReportMaker->addCSVCell($snapinState);
         $ReportMaker->addCSVCell($snapinReturn);
         $ReportMaker->addCSVCell($snapinDetail);
         $ReportMaker->addCSVCell($snapinCreateDate);
         $ReportMaker->addCSVCell($snapinCreateTime);
         $ReportMaker->addCSVCell($jobCreateDate);
         $ReportMaker->addCSVCell($jobCreateTime);
         $ReportMaker->addCSVCell($TaskCheckinDate);
         $ReportMaker->addCSVCell($TaskCheckinTime);
         $ReportMaker->endCSVLine();
     }
     // This is for the pdf.
     $ReportMaker->appendHTML($this->process());
     $ReportMaker->outputReport(false);
     $_SESSION['foglastreport'] = serialize($ReportMaker);
 }
 public function active_snapins_post()
 {
     if (isset($_REQUEST['rmid'])) {
         // Get the snapin task.
         $SnapinTask = new SnapinTask($_REQUEST['rmid']);
         // Get the job associated with the task.
         $SnapinJob = new SnapinJob($SnapinTask->get('jobID'));
         // Get the referenced host.
         $Host = new Host($SnapinJob->get('hostID'));
         // Get the active task.
         $Task = current($this->getClass('TaskManager')->find(array('hostID' => $Host->get('id'), 'stateID' => array(1, 2, 3))));
         // Check the Jobs to Snapin tasks to verify if this is the only one.
         $SnapinJobManager = $this->getClass('SnapinTaskManager')->find(array('jobID' => $SnapinJob->get('id')));
         // This task is the last task, destroy the job and the task
         if (count($SnapinJobManager) <= 1) {
             $SnapinJob->destroy();
             if ($Task) {
                 $Task->cancel();
             }
         }
         // Destroy the individual task.
         $SnapinTask->destroy();
         // Redirect to the current page.
         $this->FOGCore->redirect("?node=" . $this->node . "&sub=active-snapins");
     }
 }