예제 #1
0
<?php

require_once 'common.inc.php';
use Battis\SimpleCache;
$cache = new SimpleCache($toolbox->getMySQL());
// FIXME this is a gaping security hole, allowing anything in the cache to be dumped to CSV -- needs a nonce or something
if (!empty($_REQUEST['data'])) {
    $data = $cache->getCache($_REQUEST['data']);
    if (is_array($data)) {
        $filename = empty($_REQUEST['filename']) ? date('Y-m-d_H-i-s') : $_REQUEST['filename'];
        if (!preg_match('/.*\\.csv$/i', $filename)) {
            $filename .= '.csv';
        }
        /* http://code.stephenmorley.org/php/creating-downloadable-csv-files/ */
        /* output headers so that the file is downloaded rather than displayed */
        header('Content-Type: text/csv; charset=utf-8');
        header("Content-Disposition: attachment; filename={$filename}");
        /* create a file pointer connected to the output stream */
        $output = fopen('php://output', 'w');
        foreach ($data as $row) {
            fputcsv($output, $row);
        }
        fclose($output);
    }
}
예제 #2
0
<?php

require_once 'common.inc.php';
use Battis\SimpleCache;
use smtech\StMarksSmarty\StMarksSmarty;
$smarty->assign('name', 'Generate Standards Map');
$smarty->assign('category', 'CurricUplan');
$cache = new Battis\SimpleCache($sql, basename(__FILE__, '.php'));
$cache->setLifetime(Battis\SimpleCache::IMMORTAL_LIFETIME);
/* have we been given a map ID to generate from cached data? */
if (!empty($_REQUEST['map'])) {
    /* initialize our containers empty */
    $courses = array();
    $map = array();
    $level = array();
    /* parse the HTML we've cached */
    $dom = DOMDocument::loadHTML(tidy_parse_string($cache->getCache($_REQUEST['map']), array('output-xhtml' => true)));
    /* walk through the parsed html, table row by table row */
    $xpath = new DOMXpath($dom);
    $parsingCourses = 0;
    $standard = '';
    foreach ($xpath->query("//tr[@class[contains(.,'stds')]]") as $node) {
        /* pull out standards and courses at that standard level and their coverage of that standard */
        $nextStandard = $xpath->query(".//th[@class[contains(.,'hier')]]", $node);
        $nextStandard = trim($nextStandard->length > 0 ? $nextStandard->item(0)->nodeValue : false);
        $course = $xpath->query(".//th[@class='rowgrouplabel']", $node);
        $course = trim($course->length > 0 ? $course->item(0)->nodeValue : false);
        $total = $xpath->query(".//span[@class='spanLevelMatches']", $node);
        $total = trim($total->length > 0 ? $total->item(0)->nodeValue : false);
        /* if we're still parsing courses (between standard title and first standard group)... */
        if ($parsingCourses !== false) {