Ejemplo n.º 1
0
function displayUsers()
{
    /*
     * Shows all users and gives the option to edit any fields
     */
    $admin = $_SESSION['admin'];
    if ($admin >= 50 && isValidUser()) {
        $mysqli = connectToSQL();
        $myq = "SELECT *\r\n                FROM EMPLOYEE";
        $result = $mysqli->query($myq);
        if (!$result) {
            throw new Exception("Database Error [{$mysqli->errno}] {$mysqli->error}");
        }
        //build table
        resultTable($mysqli, $result);
        //write any updates to DB when Save is pressed
        if (isset($_POST['saveBtn'])) {
            //saveBtn created in resultTable()
            $result = $mysqli->query($myq);
            $i = 0;
            $fieldNameArray = array();
            $values = array();
            while ($finfo = mysqli_fetch_field($result)) {
                $tableName = $finfo->orgtable;
                $fieldNameArray[$i] = $finfo->orgname;
                $values["{$fieldNameArray[$i]}"] = $fieldNameArray[$i] . "=" . "'" . $mysqli->real_escape_string($_POST["{$fieldNameArray[$i]}"]) . "'";
                $i++;
            }
            //turn the array into comma seperated values
            $csvValues = implode(',', $values);
            $updateQuery = "UPDATE " . $tableName . " SET " . $csvValues . " \r\n            WHERE " . $values['ID'];
            echo "<br>" . $updateQuery;
            $updateResult = $mysqli->query($updateQuery);
            if (!$updateResult) {
                throw new Exception("Database Error [{$mysqli->errno}] {$mysqli->error}");
            }
        }
    }
}
Ejemplo n.º 2
0
function exportHTML($toPrint, $array, $action, $showSummary, $rptname, $summary, $style)
{
    $html_start = "<html><head>\n";
    $html_start .= "<META http-equiv=Content-Type content='text/html; charset=iso-8859-1'>\n";
    $html_start .= "<style>\n";
    $style_applied = false;
    $path_to_style = "../templates/{$style}";
    if (!isset($style) || $style == '') {
        $path_to_style = "../css";
        $style = "___EMPTY___";
    }
    $hdr_image_txt = "";
    $ftr_image_txt = "";
    $hdr_img = "s.gif";
    $ftr_img = "s.gif";
    $hdr_image_src = "../../images/s.gif";
    $ftr_image_src = "../../images/s.gif";
    if (isset($style) && $style != '') {
        if (!(file_exists($path_to_style) && is_dir($path_to_style))) {
            $path_to_style = "templates/{$style}";
        }
        if (file_exists($path_to_style) && is_dir($path_to_style)) {
            $path_to_css = "{$path_to_style}/empty.css";
            if ($style != '___EMPTY___') {
                $path_to_css = "{$path_to_style}/style.css";
                $path_to_hdr_img = "../templates/{$style}/rgHeader.gif";
                $path_to_ftr_img = "../templates/{$style}/rgFooter.gif";
                $path_to_config = "{$path_to_style}/config.php";
            }
            if (file_exists($path_to_hdr_img)) {
                $hdr_image_src = "../{$path_to_hdr_img}";
                $hdr_img = "rgHeader.gif";
            }
            if (file_exists($path_to_ftr_img)) {
                $ftr_image_src = "../{$path_to_ftr_img}";
                $ftr_img = "rgFooter.gif";
            }
            if (file_exists($path_to_config)) {
                include_once $path_to_config;
                if (isset($SUBHEADING)) {
                    $hdr_image_txt = $SUBHEADING;
                }
                if (isset($FOOTER)) {
                    $ftr_image_txt = $FOOTER;
                }
            }
            if (file_exists($path_to_css)) {
                $styleh = fopen($path_to_css, 'r') or warn("Unable to open STYLE file {$path_to_css}");
                if (!isset($styleh)) {
                    echo "/* Unable to open STYLE file {$path_to_css} */";
                } else {
                    $style_data = fread($styleh, filesize($path_to_css));
                    fclose($styleh);
                    $html_start .= preg_replace("/\\#resultspane /", "", $style_data);
                    $style_applied = true;
                }
            }
        }
    }
    if ($style_applied == false) {
        $html_start .= "#rgSummary { color: #000; font: 10px Verdana; font-weight: bold; line-height: 1em; }\n";
        $html_start .= "#rptTitle { font-size: 12px; text-decoration: underline; }\n";
        $html_start .= "#rptSubheading{ color: #000; font: 10px Verdana; font-weight: bold; line-height: 1em; }\n";
        $html_start .= "th { border:1px solid #000;padding:.25em;background-color:#000;color:#9c3; font-size:10px; }\n";
        $html_start .= "td { border:0px; padding:.25em; font-size:10px; line-height:1em; }\n";
        $html_start .= ".yui-dt-even { background-color:#FFF; }\n";
        $html_start .= ".yui-dt-odd { background-color:#ddfccd; }\n";
        $html_start .= "#rptFooterTxt { color: #000; font: 10px Verdana, Arial; line-height: 1em; }\n";
        $html_start .= "#rgSummary { color: #000; font: 10px Verdana; font-weight: bold; line-height: 1em; }\n";
    }
    $html_start .= "</style>\n";
    $html_start .= "<title>{$rptname}</title>\n";
    $html_start .= "\n</head>\n";
    if ($action == 'print') {
        $html_start .= "\n<body onload='window.print();'>\n";
    } else {
        $html_start .= "\n<body>\n";
    }
    $html_header = "<div id='rptHeader'>\n";
    if (isset($toPrint) && $toPrint == true) {
        $html_header .= "<img id='rptHdrImg' src='{$hdr_image_src}'><br>\n";
    } else {
        $html_header .= "<img id='rptHdrImg' src='{$hdr_img}'><br>\n";
    }
    $html_header .= "<span id='rptTitle'>{$rptname} Report</span><br>\n";
    $html_header .= "<span id='rptSubheading'>{$hdr_image_txt}</span><br>\n";
    $html_header .= "<span id='rptSummary'>\n";
    if ($showSummary == 1) {
        $html_header .= "{$summary}\n";
    }
    $html_header .= "</span>\n";
    $html_header .= "</div>\n";
    $html_footer .= "<div id='rptFooter'>\n";
    $html_footer .= "<span id='rptFooterTxt'>{$ftr_image_txt}</span>\n";
    if (isset($toPrint) && $toPrint == true) {
        $html_footer .= "<img id='rptFtrImg' src='{$ftr_image_src}'>\n";
    } else {
        $html_footer .= "<img id='rptFtrImg' src='{$ftr_img}'>\n";
    }
    $html_footer .= "</div>\n";
    $html_data = resultTable($toPrint, $array, 'exporthtml');
    $html_end = "\n</body>\n";
    $html_end .= "</html>\n";
    $timenow = date("m-d-Y");
    $storage_area = "storage";
    if (!file_exists($storage_area) || !is_dir($storage_area)) {
        mkdir($storage_area);
    }
    if (!isset($rptname) || $rptname == '') {
        $filename = "Report_" . $timenow . ".html";
    } else {
        $filename = $rptname . "_" . $timenow . ".html";
    }
    $exported_file = "{$storage_area}/{$filename}";
    $htmlh = fopen($exported_file, 'w') or warn("Unable to write to HTML file {$exported_file} locally");
    if (!isset($htmlh)) {
        echo "Unable to write to HTML file locally";
        return;
    }
    fwrite($htmlh, $html_start);
    fwrite($htmlh, $html_header);
    fwrite($htmlh, $html_data);
    fwrite($htmlh, $html_footer);
    fwrite($htmlh, $html_end);
    fclose($htmlh);
    $preview_link = "lib/storage/{$filename}";
    if (file_exists($exported_file)) {
        if (isset($toPrint) && $toPrint == true) {
            echo $preview_link;
        }
        return $filename;
    } else {
        return "";
    }
}
function approvedTimeUseReport($config)
{
    //what pay period are we currently in?
    $mysqli = $config->mysqli;
    $payPeriodQuery = "SELECT * FROM PAYPERIOD WHERE NOW() BETWEEN PPBEG AND PPEND";
    $ppResult = $mysqli->query($payPeriodQuery);
    $ppArray = $ppResult->fetch_assoc();
    /* $ppOffset stands for the number of pay periods to adjust the query by 
     * relative to the current period
     */
    $ppOffset = isset($_GET['ppOffset']) ? $_GET['ppOffset'] : '0';
    //set the right URI for link
    if (isset($ppOffset)) {
        //strip off the old GET variable and its value
        $uri = preg_replace("/&ppOffset=.*/", "", $_SERVER['REQUEST_URI']) . "&ppOffset=";
    } else {
        $uri = $_SERVER['REQUEST_URI'] . "&ppOffset=";
    }
    //1st time set
    $startDate = new DateTime("{$ppArray['PPBEG']}");
    if ($ppOffset < 0) {
        //backward in time by $ppOffset number of periods
        $startDate->sub(new DateInterval("P" . abs($ppOffset) * 14 . "D"));
    } else {
        //forward in time by $ppOffset number of periods
        $startDate->add(new DateInterval("P" . $ppOffset * 14 . "D"));
    }
    $endDate = new DateTime("{$ppArray['PPEND']}");
    if ($ppOffset < 0) {
        //backward in time by $ppOffset number of periods
        $endDate->sub(new DateInterval("P" . abs($ppOffset) * 14 . "D"));
    } else {
        //forward in time by $ppOffset number of periods
        $endDate->add(new DateInterval("P" . $ppOffset * 14 . "D"));
    }
    ?>
    <p><a href="<?php 
    echo $_SERVER['REQUEST_URI'] . '&cust=true';
    ?>
">Use Custom Date Range</a></br>
    <?php 
    if (isset($_GET['cust'])) {
        echo "<form name='custRange' action='" . $_SERVER['REQUEST_URI'] . "' method='post'>";
        echo "<p> Start";
        displayDateSelect('start', 'date_1');
        echo "End";
        displayDateSelect('end', 'date_2');
        echo "<input type='submit' value='Go' /></p></form>";
        //overwrite current period date variables with
        //those provided by user
        if (isset($_POST['start']) && isset($_POST['end'])) {
            $startDate = new DateTime($_POST['start']);
            $endDate = new DateTime($_POST['end']);
            ?>
 <h3><center>Time Gained/Used from <?php 
            echo $startDate->format('j M Y');
            ?>
 through <?php 
            echo $endDate->format('j M Y');
            ?>
.</center></h3> <?php 
        }
    } else {
        ?>
    <p><div style="float:left"><a href="<?php 
        echo $uri . ($ppOffset - 1);
        ?>
">Previous</a></div>  
    <div style="float:right"><a href="<?php 
        echo $uri . ($ppOffset + 1);
        ?>
">Next</a></div></p>
    <h3><center>Time Gained/Used in pay period <?php 
        echo $startDate->format('j M Y');
        ?>
 through <?php 
        echo $endDate->format('j M Y');
        ?>
.</center></h3>
    <?php 
        $myq = "SELECT REFER 'RefNo', CONCAT_WS(', ',REQ.LNAME,REQ.FNAME) 'Name', DATE_FORMAT(USEDATE,'%a %d %b %Y') 'Used', \r\n                    DATE_FORMAT(BEGTIME,'%H%i') 'Start',\r\n                    DATE_FORMAT(ENDTIME,'%H%i') 'End', HOURS 'Hrs',\r\n                    T.DESCR 'Type', SUBTYPE 'Subtype', CALLOFF 'Calloff', NOTE 'Comment', \r\n                    APR.LNAME 'ApprovedBy', REASON 'Reason' \r\n            FROM REQUEST\r\n            LEFT JOIN EMPLOYEE AS REQ ON REQ.IDNUM=REQUEST.IDNUM\r\n            LEFT JOIN EMPLOYEE AS APR ON APR.IDNUM=REQUEST.APPROVEDBY\r\n            INNER JOIN TIMETYPE AS T ON T.TIMETYPEID=REQUEST.TIMETYPEID\r\n            WHERE USEDATE BETWEEN '" . $config->mysqli->real_escape_string($startDate->format('Y-m-d')) . "' \r\n                AND '" . $config->mysqli->real_escape_string($endDate->format('Y-m-d')) . "'\r\n            AND STATUS='APPROVED'\r\n            ORDER BY REQ.LNAME";
        $result = $mysqli->query($myq);
        SQLerrorCatch($mysqli, $result);
        echo "<h2>Approved Requests</h2>";
        resultTable($mysqli, $result);
    }
    //show a print button. printed look defined by print.css
    echo '<a href="javascript:window.print()">Print</a>';
}
Ejemplo n.º 4
0
 if ($rptAction == 'mailhtml' || $rptAction == 'mailcsv') {
     $toPrint = false;
 }
 if (isset($rptAction) && ($rptAction == 'exportcsv' || $rptAction == 'mailcsv')) {
     $selMailFormat = "CSV";
     // Print CSV output to be dumped into a hidden IFRAME
     $rgOutput = exportCSV($toPrint, $array, $rptName);
 } else {
     if (isset($rptAction) && ($rptAction == 'exporthtml' || $rptAction == 'preview' || $rptAction == 'print' || $rptAction == 'mailhtml')) {
         $selMailFormat = "HTML";
         logger("Temlate - {$selTemplate}");
         // Print HTML output to be dumped into a new window
         $rgOutput = exportHTML($toPrint, $array, $rptAction, $selSummary, $rptName, $summary, $selTemplate);
     } else {
         // Print Tabularized output for formatting later - see ULTRA COOL in filter.js
         resultTable($toPrint, $array, $rptAction);
     }
 }
 if ($rptAction == 'mailhtml' || $rptAction == 'mailcsv') {
     if ($servername == "") {
         $servername = $_SERVER['SERVERNAME'];
     }
     logger("Trying to mail report ({$rgOutput}) to {$selMailTo}... ");
     if (RPT_SCHEDULE == 1) {
         $run_schedules = 1;
     }
     $err = sendRptMail($run_schedules, $servername, $selMailTo, $selMailCC, $selMailSubject, $selMailBody, $selMailFormat, $rgOutput, $selTemplate);
     if ($err != 0) {
         logger($err);
     }
     $file_path = "./storage/{$rgOutput}";