/** equip_loan_post()
 		Display the form for printing/pdf output.
 	*/
 public function equip_loan_post()
 {
     $Inventory = new Inventory($_REQUEST['user']);
     // Set title
     $this->title = _('FOG Equipment Loan Form');
     // This gets the download links for which type of file you want.
     print "\n\t\t\t\t<h2>" . '<a href="export.php?type=pdf&filename=' . $Inventory->get('primaryuser') . 'EquipmentLoanForm" alt="Export PDF" title="Export PDF" target="_blank">' . $this->pdffile . '</a></h2>';
     // Report Maker
     $ReportMaker = new ReportMaker();
     // Get the current Inventory based on what was selected.
     // Title Information
     $ReportMaker->appendHTML("<!-- " . _("FOOTER CENTER") . " \"" . '$PAGE' . " " . _("of") . " " . '$PAGES' . " - " . _("Printed") . ": " . $this->nice_date()->format("D M j G:i:s T Y") . "\" -->");
     $ReportMaker->appendHTML("<center><h2>" . _("[YOUR ORGANIZATION HERE]") . "</h2></center>");
     $ReportMaker->appendHTML("<center><h3>" . _("[sub-unit here]") . "</h3></center>");
     $ReportMaker->appendHTML("<center><h2><u>" . _("PC Check-Out Agreement") . "</u></h2></center>");
     // Personal Information
     $ReportMaker->appendHTML("<h4><u>" . _("Personal Information") . "</u></h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Name") . ": </b><u>" . $Inventory->get('primaryUser') . "</u></h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Location") . ": </b><u>" . _("Your Location Here") . "</u></h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Home Address") . ": </b>__________________________________________________________________</h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("City / State / Zip") . ": </b>__________________________________________________________________</h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Extension") . ":</b>_________________ &nbsp;&nbsp;&nbsp;<b>" . _("Home Phone") . ":</b> (__________)_____________________________</h4>");
     // Computer Information
     $ReportMaker->appendHTML("<h4><u>" . _("Computer Information") . "</u></h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Serial Number / Service Tag") . ": </b><u>" . $Inventory->get('sysserial') . " / " . $Inventory->get('caseasset') . "_____________________</u></h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Barcode Numbers") . ": </b><u>" . $Inventory->get('other1') . "   " . $Inventory->get('other2') . "</u>________________________</h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Date of Checkout") . ": </b>____________________________________________</h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Notes / Miscellaneous / Included Items") . ": </b></h4>");
     $ReportMaker->appendHTML("<h4><b>_____________________________________________________________________________________________</b></h4>");
     $ReportMaker->appendHTML("<h4><b>_____________________________________________________________________________________________</b></h4>");
     $ReportMaker->appendHTML("<h4><b>_____________________________________________________________________________________________</b></h4>");
     $ReportMaker->appendHTML("<hr />");
     $ReportMaker->appendHTML("<h4><b>" . _("Releasing Staff Initials") . ": </b>_____________________     " . _("(To be released only by XXXXXXXXX)") . "</h4>");
     $ReportMaker->appendHTML("<h4>" . _("I have read, understood, and agree to all the Terms and Condidtions on the following pages of this document.") . "</h4>");
     $ReportMaker->appendHTML("<br />");
     $ReportMaker->appendHTML("<h4><b>" . _("Signed") . ": </b>X _____________________________  " . _("Date") . ": _________/_________/20_______</h4>");
     $ReportMaker->appendHTML(_("<!-- " . _("NEW PAGE") . " -->"));
     $ReportMaker->appendHTML("<!-- " . _("FOOTER CENTER") . " \"" . '$PAGE' . " " . _("of") . " " . '$PAGES' . " - " . _("Printed") . ": " . $this->nice_date()->format("D M j G:i:s T Y") . "\" -->");
     $ReportMaker->appendHTML("<center><h3>" . _("Terms and Conditions") . "</h3></center>");
     $ReportMaker->appendHTML("<hr />");
     $ReportMaker->appendHTML("<h4>" . _("Your terms and conditions here") . "</h4>");
     $ReportMaker->appendHTML("<h4><b>" . _("Signed") . ": </b>" . _("X") . " _____________________________  " . _("Date") . ": _________/_________/20_______</h4>");
     print "\n\t\t\t<p>" . _('Your form is ready.') . '</p>';
     $_SESSION['foglastreport'] = serialize($ReportMaker);
 }
 /** export()
 		Exports the hosts from the database.
 	*/
 public function export()
 {
     $this->title = 'Export Hosts';
     // Header Data
     unset($this->headerData);
     // Attributes
     $this->attributes = array(array(), array());
     // Templates
     $this->templates = array('${field}', '${input}');
     // Fields
     $fields = array(_('Click the button to download the hosts table backup.') => '<input type="submit" value="' . _('Export') . '" />');
     $report = new ReportMaker();
     $Hosts = $this->getClass('HostManager')->find();
     foreach ((array) $Hosts as $Host) {
         if ($Host && $Host->isValid()) {
             $macs[] = $Host->get('mac');
             foreach ($Host->get('additionalMACs') as $AddMAC) {
                 if ($AddMAC && $AddMAC->isValid()) {
                     $macs[] = $AddMAC->__toString();
                 }
             }
             $report->addCSVCell(implode('|', (array) $macs));
             $report->addCSVCell($Host->get('name'));
             $report->addCSVCell($Host->get('ip'));
             $report->addCSVCell('"' . $Host->get('description') . '"');
             $report->addCSVCell($Host->get('imageID'));
             $this->HookManager->processEvent('HOST_EXPORT_REPORT', array('report' => &$report, 'Host' => &$Host));
             $report->endCSVLine();
             unset($macs);
         }
     }
     $_SESSION['foglastreport'] = serialize($report);
     print "\n\t\t\t" . '<form method="post" action="export.php?type=host">';
     foreach ((array) $fields as $field => $input) {
         $this->data[] = array('field' => $field, 'input' => $input);
     }
     // Hook
     $this->HookManager->processEvent('HOST_EXPORT', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes));
     // Output
     $this->render();
     print "</form>";
 }
 private function makeReport()
 {
     print '<h2>' . _('FOG Hosts and Users Login') . '<a href="export.php?type=csv&filename=HostsandUsers" target="_blank"><img class="noBorder" src="images/csv.png" /></a><a href="export.php?type=pdf&filename=HostsandUsers" target="_blank"><img class="noBorder" src="images/pdf.png" /></a></h2>';
     $Hosts = $this->getClass('HostManager')->find();
     $report = new ReportMaker();
     $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">');
     $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>');
     $report->addCSVCell('Hostname');
     $report->addCSVCell('MAC');
     $report->addCSVCell('Registered');
     $report->endCSVLine();
     $cnt = 0;
     foreach ($Hosts as $Host) {
         $bg = $cnt++ % 2 == 0 ? "#E7E7E7" : '';
         $report->appendHTML('<tr bgcolor="' . $bg . '"><td>' . $Host->get('name') . '</td><td>' . $Host->get('mac') . '</td><td>' . $Host->get('createdTime') . '</td></tr>');
         $report->addCSVCell($Host->get('name'));
         $report->addCSVCell($Host->get('mac'));
         $report->addCSVCell($Host->get('createdTime'));
         if ($Host->get('users')) {
             $report->endCSVLine();
             $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Username</b></td><td><b>Action</b></td><td><b>Date</b></td><td><b>Time</b></td></tr>');
             $report->addCSVCell('Username');
             $report->addCSVCell('Action');
             $report->addCSVCell('Time');
             $report->endCSVLine();
             $cnt1 = 0;
             foreach ($Host->get('users') as $User) {
                 $bg1 = $cnt1++ % 2 == 0 ? "#E7E7E7" : '';
                 $logintext = $User->get('action') == 1 ? 'Login' : (!$User->get('action') ? 'Logout' : ($User->get('action') == 99 ? 'Service Start' : 'N/A'));
                 if ($logintext == 'Login' || $logintext == 'Logout') {
                     $report->appendHTML('<tr bgcolor="' . $bg1 . '"><td>' . $User->get('username') . '</td><td>' . $logintext . '</td><td>' . $User->get('date') . '</td><td>' . $User->get('datetime') . '</td></tr>');
                     $report->addCSVCell($User->get('username'));
                     $report->addCSVCell($logintext);
                     $report->addCSVCell($User->get('date'));
                     $report->addCSVCell($User->get('datetime'));
                     $report->endCSVLine();
                 }
             }
             $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">');
             $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>');
             $report->addCSVCell('Hostname');
             $report->addCSVCell('MAC');
             $report->addCSVCell('Registered');
             $report->endCSVLine();
         } else {
             $report->endCSVLine();
         }
     }
     $report->appendHTML('</table>');
     $report->outputReport(ReportMaker::FOG_REPORT_HTML);
     $_SESSION['foglastreport'] = serialize($report);
 }
global $sugar_config;
$language = $sugar_config['default_language'];
$app_list_strings = return_app_list_strings_language($language);
$app_strings = return_application_language($language);
$reportSchedule = new ReportSchedule();
// Process Enterprise Schedule reports via CSV
$reportsToEmailEnt = $reportSchedule->get_ent_reports_to_email("", "ent");
global $report_modules, $modListHeader, $locale;
foreach ($reportsToEmailEnt as $scheduleId => $scheduleInfo) {
    $user = BeanFactory::getBean('Users', $scheduleInfo['user_id']);
    $current_user = $user;
    // should this be the global $current_user? global $current_user isn't referenced
    $modListHeader = query_module_access_list($current_user);
    $report_modules = getAllowedReportModules($modListHeader);
    // Acquire the enterprise report to be sent
    $reportMaker = new ReportMaker();
    $reportMaker->retrieve($scheduleInfo['report_id']);
    $mod_strings = return_module_language($language, 'Reports');
    // Process data sets into CSV files
    // loop through data sets;
    $dataSets = $reportMaker->get_data_sets();
    $tempFiles = array();
    foreach ($dataSets as $key => $dataSet) {
        $csv = $dataSet->export_csv();
        $filenamestamp = "{$dataSet->name}_{$user->user_name}_" . date(translate("LBL_CSV_TIMESTAMP", "Reports"), time());
        $filename = str_replace(" ", "_", "{$reportMaker->name}{$filenamestamp}.csv");
        $fp = sugar_fopen(sugar_cached("csv/") . $filename, "w");
        fwrite($fp, $csv);
        fclose($fp);
        $tempFiles[$filename] = $filename;
    }
$query_object2->name = $mod_strings['LBL_Q'] . "2";
$query_object2->description = $mod_strings['LBL_Q2_DESC'];
$query_object2->query_locked = "off";
$query_object2->team_id = 1;
if ($query_object2->db->dbType == 'oci8') {
} elseif ($query_object1->db->dbType == 'mssql') {
    $query_object2->custom_query = "SELECT accounts.name AS 'Account Name',\n\tcase MONTH(opportunities.date_closed) when MONTH(GETDATE()) then SUM(opportunities.amount_usdollar) else SUM(0) end '{sc}0{sc}0',\n\tcase MONTH(opportunities.date_closed) when DATEADD(mm,1,GETDATE()) then SUM(opportunities.amount_usdollar) else SUM(0) end '{sc}0{sc}1',\n\tcase MONTH(opportunities.date_closed) when DATEADD(mm,2,GETDATE()) then SUM(opportunities.amount_usdollar) else SUM(0) end '{sc}0{sc}2',\n\tcase MONTH(opportunities.date_closed) when DATEADD(mm,3,GETDATE()) then SUM(opportunities.amount_usdollar) else SUM(0) end '{sc}0{sc}3',\n\tcase MONTH(opportunities.date_closed) when DATEADD(mm,4,GETDATE()) then SUM(opportunities.amount_usdollar) else SUM(0) end '{sc}0{sc}4',\n\tcase MONTH(opportunities.date_closed) when DATEADD(mm,5,GETDATE()) then SUM(opportunities.amount_usdollar) else SUM(0) end '{sc}0{sc}5',\n\tSUM(opportunities.amount_usdollar) AS 'Total Revenue'\n \n\tFROM opportunities\n\tLEFT JOIN accounts_opportunities ON opportunities.id=accounts_opportunities.opportunity_id \n\tLEFT JOIN accounts ON accounts_opportunities.account_id=accounts.id\n\tWHERE opportunities.date_closed <= DATEADD(mm,5,GETDATE()) AND  opportunities.date_closed >= GETDATE()\n\tGROUP BY opportunities.date_closed, accounts.id, accounts.name order by accounts.name\n\t";
} elseif ($query_object1->db->dbType == 'mysql') {
    $query_object2->custom_query = "SELECT accounts.name AS 'Account Name'\n\t,SUM(IF(MONTH(opportunities.date_closed) = MONTH(CURDATE()), opportunities.amount_usdollar,0)) as '{sc}0{sc}0'\n\t,SUM(IF(MONTH(opportunities.date_closed) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH)), opportunities.amount_usdollar,0)) as '{sc}0{sc}1'\n\t,SUM(IF(MONTH(opportunities.date_closed) = MONTH(DATE_ADD(CURDATE(),INTERVAL 2 MONTH)), opportunities.amount_usdollar,0)) as '{sc}0{sc}2'\n\t,SUM(IF(MONTH(opportunities.date_closed) = MONTH(DATE_ADD(CURDATE(),INTERVAL 3 MONTH)), opportunities.amount_usdollar,0)) as '{sc}0{sc}3'\n\t,SUM(IF(MONTH(opportunities.date_closed) = MONTH(DATE_ADD(CURDATE(),INTERVAL 4 MONTH)), opportunities.amount_usdollar,0)) as '{sc}0{sc}4'\n\t,SUM(IF(MONTH(opportunities.date_closed) = MONTH(DATE_ADD(CURDATE(),INTERVAL 5 MONTH)), opportunities.amount_usdollar,0)) as '{sc}0{sc}5'\n\t,SUM(opportunities.amount_usdollar) AS 'Total Revenue'\n\t \n\tFROM opportunities\n\t LEFT JOIN accounts_opportunities \n\tON opportunities.id=accounts_opportunities.opportunity_id \n\tLEFT JOIN accounts \n\tON accounts_opportunities.account_id=accounts.id\n\tWHERE opportunities.date_closed <= DATE_ADD(CURDATE(),INTERVAL 5 MONTH)\n\tAND opportunities.date_closed >= CURDATE()\n\tGROUP BY accounts.id ORDER BY accounts.name";
    //end if else mysql or oracle
}
$query_object2->save();
$query_id1 = $query_object1->id;
$query_id2 = $query_object2->id;
//Create new Report
$report_object = new ReportMaker();
$report_object->name = $mod_strings['LBL_R1'];
$report_object->title = $mod_strings['LBL_R1'];
$report_object->description = $mod_strings['LBL_R1_DESC'];
$report_object->report_align = "center";
$report_object->team_id = 1;
$report_object->save();
$report_id = $report_object->id;
//Create the data sets for the two custom queries
$format_object = new DataSet();
$format_object->name = $mod_strings['LBL_OPP'] . "1";
$format_object->description = $mod_strings['LBL_OPP1_DESC'];
$format_object->report_id = $report_id;
$format_object->query_id = $query_id1;
$format_object->list_order_y = 0;
$format_object->exportable = "on";
 public function index()
 {
     $this->title = _('FOG Hosts and Users Login');
     print '<center><a href="export.php?type=csv" target="_blank"><i class="fa fa-file-excel-o fa-2x"></i></a><a href="export.php?type=pdf" target="_blank"><i class="fa fa-file-pdf-o fa-2x"></i></a></center><br/>';
     $report = new ReportMaker();
     $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">');
     $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>');
     $report->addCSVCell('Hostname');
     $report->addCSVCell('MAC');
     $report->addCSVCell('Registered');
     $report->endCSVLine();
     $Hosts = $this->FOGCore->getClass('HostManager')->find('', '', '', '', '', 'name');
     $cnt = 0;
     foreach ($Hosts as $Host) {
         $bg = $cnt++ % 2 == 0 ? "#E7E7E7" : '';
         $report->appendHTML('<tr bgcolor="' . $bg . '"><td>' . $Host->get('name') . '</td><td>' . $Host->get('mac') . '</td><td>' . $Host->get('createdTime') . '</td></tr>');
         $report->addCSVCell($Host->get('name'));
         $report->addCSVCell($Host->get('mac'));
         $report->addCSVCell($Host->get('createdTime'));
         if ($Host->get('users')) {
             $report->endCSVLine();
             $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Username</b></td><td><b>Action</b></td><td><b>Date</b></td><td><b>Time</b></td></tr>');
             $report->addCSVCell('Username');
             $report->addCSVCell('Action');
             $report->addCSVCell('Time');
             $report->endCSVLine();
             $cnt1 = 0;
             $Users = $this->getClass('UserTrackingManager')->find(array('hostID' => $Host->get('id'), 'action' => array(null, 0, 1)), '', array('username', 'datetime'), 'DESC', '', 'username');
             foreach ($Users as $User) {
                 if ($User->get('username') != 'Array') {
                     $bg1 = $cnt1++ % 2 == 0 ? "#E7E7E7" : '';
                     $logintext = $User->get('action') == 1 ? 'Login' : 'Logout';
                     $report->appendHTML('<tr bgcolor="' . $bg1 . '"><td>' . $User->get('username') . '</td><td>' . $logintext . '</td><td>' . $User->get('date') . '</td><td>' . $User->get('datetime') . '</td></tr>');
                     $report->addCSVCell($User->get('username'));
                     $report->addCSVCell($logintext);
                     $report->addCSVCell($User->get('date'));
                     $report->addCSVCell($User->get('datetime'));
                     $report->endCSVLine();
                 }
             }
             $report->appendHTML('<table cellpadding="0" cellspacing="0" border="0" width="100%">');
             $report->appendHTML('<tr bgcolor="#BDBDBD"><td><b>Hostname</b></td><td><b>MAC</b></td><td><b>Registered</b></td></tr>');
             $report->addCSVCell('Hostname');
             $report->addCSVCell('MAC');
             $report->addCSVCell('Registered');
             $report->endCSVLine();
         }
     }
     $report->appendHTML('</table>');
     $report->outputReport(0);
     $_SESSION['foglastreport'] = serialize($report);
 }