function do_report($ref, $from_y, $from_m, $from_d, $to_y, $to_m, $to_d, $download = true, $add_border = false)
{
    # Run report with id $ref for the date range specified. Returns a result array.
    global $lang, $baseurl;
    $report = sql_query("select * from report where ref='{$ref}'");
    $report = $report[0];
    $report['name'] = get_report_name($report);
    if ($download) {
        $filename = str_replace(array(" ", "(", ")", "-", "/"), "_", $report["name"]) . "_" . $from_y . "_" . $from_m . "_" . $from_d . "_" . $lang["to"] . "_" . $to_y . "_" . $to_m . "_" . $to_d . ".csv";
        header("Content-type: application/octet-stream");
        header("Content-disposition: attachment; filename=" . $filename . "");
    }
    if ($results = hook("customreport", "", array($ref, $from_y, $from_m, $from_d, $to_y, $to_m, $to_d, $download, $add_border, $report))) {
    } else {
        $sql = $report["query"];
        $sql = str_replace("[from-y]", $from_y, $sql);
        $sql = str_replace("[from-m]", $from_m, $sql);
        $sql = str_replace("[from-d]", $from_d, $sql);
        $sql = str_replace("[to-y]", $to_y, $sql);
        $sql = str_replace("[to-m]", $to_m, $sql);
        $sql = str_replace("[to-d]", $to_d, $sql);
        global $view_title_field;
        #back compatibility for three default reports, to replace "title" with the view_title_field.
        #all reports should either use r.title or view_title_field when referencing the title column on the resource table.
        if ($ref == 7 || $ref == 8 || $ref == 9) {
            $sql = str_replace(",title", ",field" . $view_title_field, $sql);
        }
        $sql = str_replace("view_title_field", "field" . $view_title_field, $sql);
        $sql = str_replace("r.title", "field" . $view_title_field, $sql);
        $results = sql_query($sql);
        #echo "\"Number of results: " . count($results) . "\"\n";
    }
    if ($download) {
        for ($n = 0; $n < count($results); $n++) {
            $result = $results[$n];
            if ($n == 0) {
                $f = 0;
                foreach ($result as $key => $value) {
                    $f++;
                    if ($f > 1) {
                        echo ",";
                    }
                    if ($key != "thumbnail") {
                        echo "\"" . lang_or_i18n_get_translated($key, "columnheader-") . "\"";
                    }
                }
                echo "\n";
            }
            $f = 0;
            foreach ($result as $key => $value) {
                $f++;
                if ($f > 1) {
                    echo ",";
                }
                $custom = hook('customreportfield', '', array($result, $key, $value, $download));
                if ($custom !== false) {
                    echo $custom;
                } else {
                    if ($key != "thumbnail") {
                        $value = lang_or_i18n_get_translated($value, "usergroup-");
                        $value = str_replace('"', '""', $value);
                        # escape double quotes
                        if (substr($value, 0, 1) == ",") {
                            $value = substr($value, 1);
                        }
                        # Remove comma prefix on dropdown / checkbox values
                        echo "\"" . $value . "\"";
                    }
                }
            }
            echo "\n";
        }
    } else {
        # Not downloading - output a table
        $border = "";
        if ($add_border) {
            $border = "border=\"1\"";
        }
        $output = "<br /><h2>" . $report['name'] . "</h2><style>.InfoTable td {padding:5px;}</style><table {$border} class=\"InfoTable\">";
        for ($n = 0; $n < count($results); $n++) {
            $result = $results[$n];
            if ($n == 0) {
                $f = 0;
                $output .= "<tr>\r\n";
                foreach ($result as $key => $value) {
                    $f++;
                    if ($key == "thumbnail") {
                        $output .= "<td><strong>Link</strong></td>\r\n";
                    } else {
                        $output .= "<td><strong>" . lang_or_i18n_get_translated($key, "columnheader-") . "</strong></td>\r\n";
                    }
                }
                $output .= "</tr>\r\n";
            }
            $f = 0;
            $output .= "<tr>\r\n";
            foreach ($result as $key => $value) {
                $f++;
                if ($key == "thumbnail") {
                    $thm_path = get_resource_path($value, true, "thm", false, "", $scramble = -1, $page = 1, false);
                    if (!file_exists($thm_path)) {
                        $resourcedata = get_resource_data($value);
                        $thm_url = $baseurl . "/gfx/" . get_nopreview_icon($resourcedata["resource_type"], $resourcedata["file_extension"], true);
                    } else {
                        $thm_url = get_resource_path($value, false, "col", false, "", -1, 1, false);
                    }
                    $output .= "<td><a href=\"" . $baseurl . "/?r=" . $value . "\" target=\"_blank\"><img src=\"" . $thm_url . "\"></a></td>\r\n";
                } else {
                    $custom = hook('customreportfield', '', array($result, $key, $value, $download));
                    if ($custom !== false) {
                        $output .= $custom;
                    } else {
                        $output .= "<td>" . lang_or_i18n_get_translated($value, "usergroup-") . "</td>\r\n";
                    }
                }
            }
            $output .= "</tr>\r\n";
        }
        $output .= "</table>\r\n";
        if (count($results) == 0) {
            $output .= $lang["reportempty"];
        }
        return $output;
    }
    exit;
}
Esempio n. 2
0
<section id="admin-results" style='padding-left: 0%;'>
<?php 
if (isset($_POST['export'])) {
    $result = report_to_csv($dbc, $_POST['export']);
    if ($result === 1) {
        echo "Report successfully generated.";
    } else {
        echo "Unable to generate Report.";
    }
    $_POST['submit'] = $_POST['export'];
}
if (isset($_POST['submit'])) {
    $result = generate_report($dbc, $_POST['submit']);
    if ($result != false && $result->num_rows != 0) {
        echo "<h3>" . get_report_name($_POST['submit']) . "</h3>";
        echo "<form method='post' action='./save-generated-report.php' target='_blank'>\r\n\t\t\t\t\t\t\t<button class='btn btn-primary' id='admin-report-button' name='export' value='" . $_POST['submit'] . "'>\r\n\t\t\t\t\t\t\t\t<span class='glyphicon glyphicon-download-alt'></span> Download\r\n\t\t\t\t\t\t\t</button>\r\n\t\t\t\t\t\t</form>";
        echo "<table class='table table-striped table-hover' id='admin-search' align='center'>";
        if ($_POST['submit'] < 4) {
            ?>
					<tr>
						<th id="admin-th">NetID</th>
						<th id="admin-th">Serial Number</th>
						<th id="admin-th">Make</th>
						<th id="admin-th">Model/Type</th>
						<th id="admin-th">Missing</th>
					</tr>
<?php 
            while ($row = mysqli_fetch_assoc($result)) {
                $missing = $row['Missing'] == 0 ? "No" : "Yes";
                echo "<tr>\r\n\t\t\t\t\t\t\t\t\t<td id='admin-search-td'>" . $row['NetID'] . "</td>\r\n\t\t\t\t\t\t\t\t\t<td id='admin-search-td'>" . $row['Serial'] . "</td>\r\n\t\t\t\t\t\t\t\t\t<td id='admin-search-td'>" . $row['Make'] . "</td>\r\n\t\t\t\t\t\t\t\t\t<td id='admin-search-td'>" . $row['Model'] . "</td>\r\n\t\t\t\t\t\t\t\t\t<td id='admin-search-td'>" . $missing . "</td>\r\n\t\t\t\t\t\t\t\t\t</tr>";
Esempio n. 3
0
</script>

<div id="content">		
		
		<div id="contentHeader">
			<h1 <?php 
if ($report_active == 1) {
    ?>
 style="top: 26px;"<?php 
}
?>
><?php 
if ($report_active != 1) {
    echo $report_name;
} else {
    echo $report_name_active . ' ' . get_report_name($_POST);
}
?>
</h1>
		</div> <!-- #contentHeader -->	
		
		<div class="container">
			
				
			<div class="grid-24">
			
           <?php 
if (isset($errormessage)) {
    ?>
            <div class="box plain"><div class="notify notify-error"><h3>Error</h3><p><?php 
    echo $errormessage;