Exemple #1
0
function login($username, $password)
{
    global $pdo;
    if (isset($_SESSION['userid']) && $username == $_SESSION['userid']) {
        return TRUE;
    }
    if ($pdo == null) {
        open_database();
    }
    $stmt = $pdo->prepare("SELECT * FROM users WHERE login=?");
    if (!$stmt->execute(array($username))) {
        die('Invalid query : [' . error_database() . ']' . $pdo->errorInfo());
    }
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $stmt->closeCursor();
    if (!isset($row['salt'])) {
        return FALSE;
    }
    $digest = encrypt_password($password, $row['salt']);
    if ($digest == $row['crypted_password']) {
        $_SESSION['userid'] = $row['id'];
        $_SESSION['username'] = $row['name'];
        $_SESSION['useraccess'] = $row['access_level'];
        $_SESSION['userpageaccess'] = $row['page_access_level'];
        return TRUE;
    } else {
        return FALSE;
    }
}
Exemple #2
0
function allSites()
{
    global $pdo;
    // Select all the rows in the markers table
    $result = $pdo->query("SELECT id, sitename, city, country, ST_X(ST_CENTROID(geometry)) AS lon, ST_Y(ST_CENTROID(geometry)) AS lat FROM sites;");
    if (!$result) {
        die('Invalid query: ' . error_database());
    }
    // Iterate through the rows, adding XML nodes for each
    while ($row = @$result->fetch(PDO::FETCH_ASSOC)) {
        addNode($row);
    }
}
Exemple #3
0
if (isset($_REQUEST['hostname'])) {
    $hostname = $_REQUEST['hostname'];
}
$modelid = "";
if (isset($_REQUEST['modelid'])) {
    $modelid = $_REQUEST['modelid'];
}
$siteid = "";
if (isset($_REQUEST['siteid'])) {
    $siteid = $_REQUEST['siteid'];
}
// get hosts
$query = "SELECT id, hostname FROM machines ORDER BY hostname";
$result = $pdo->query($query);
if (!$result) {
    die('Invalid query: ' . error_database());
}
$hosts = "";
while ($row = @$result->fetch(PDO::FETCH_ASSOC)) {
    if (in_array($row['hostname'], $hostlist)) {
        if ($hostname == $row['hostname']) {
            $hosts = "{$hosts}<option selected data-id='{$row['id']}'>{$row['hostname']}</option>\n";
        } else {
            $hosts = "{$hosts}<option data-id='{$row['id']}'>{$row['hostname']}</option>\n";
        }
    }
}
?>
<!DOCTYPE html>
<html>
<head>
Exemple #4
0
$q->bindParam(':startdate', $startdate, PDO::PARAM_STR);
$q->bindParam(':enddate', $enddate, PDO::PARAM_STR);
$q->bindParam(':params', $params, PDO::PARAM_STR);
$q->bindParam(':advanced_edit', $advanced_edit, PDO::PARAM_INT);
if ($q->execute() === FALSE) {
    die('Can\'t insert workflow : ' . error_database());
}
if ($db_bety_type == 'pgsql') {
    $workflowid = $pdo->lastInsertId('workflows_id_seq');
} else {
    $workflowid = $pdo->lastInsertId();
}
# folders
$folder = $output_folder . DIRECTORY_SEPARATOR . 'PEcAn_' . $workflowid;
if ($pdo->query("UPDATE workflows SET folder='{$folder}' WHERE id={$workflowid}") === FALSE) {
    die('Can\'t update workflow : ' . error_database());
}
# if on localhost replace with localhost
if ($hostname == $fqdn) {
    $hostname = "localhost";
}
# create pecan.xml
if (!mkdir($folder)) {
    die('Can\'t create output folder');
}
$fh = fopen($folder . DIRECTORY_SEPARATOR . "pecan.xml", 'w');
fwrite($fh, "<?xml version=\"1.0\"?>" . PHP_EOL);
fwrite($fh, "<pecan>" . PHP_EOL);
fwrite($fh, "  <outdir>{$folder}</outdir>" . PHP_EOL);
fwrite($fh, "  <database>" . PHP_EOL);
fwrite($fh, "    <bety>" . PHP_EOL);
Exemple #5
0
function print_select_options($name, $myid, $readonly, $query)
{
    global $pdo;
    if ($readonly) {
        if ($myid == "") {
            $query .= " WHERE id=-1";
        } else {
            $query .= " WHERE id={$myid}";
        }
    }
    $result = $pdo->query($query . " ORDER BY name");
    if (!$result) {
        die('Invalid query "' . $query . '" : [' . error_database() . ']' . error_database());
    }
    if ($readonly) {
        print "<select name=\"{$name}\" disabled>\n";
    } else {
        print "<select name=\"{$name}\">\n";
    }
    $html = "";
    $foundit = false;
    while ($row = @$result->fetch(PDO::FETCH_ASSOC)) {
        $name = $row['name'];
        if ($name == "") {
            $name = "NO NAME {$row['id']}";
        }
        if ($myid == $row['id']) {
            $html .= "<option value=\"{$row['id']}\" selected>{$name}</option>\n";
            $foundit = true;
        } else {
            if (!$readonly) {
                $html .= "<option value=\"{$row['id']}\">{$name}</option>\n";
            }
        }
    }
    if (!$foundit) {
        if ($myid == "" || $myid == "-1") {
            $html = "<option value=\"-1\" selected>Please make a selection</option>\n" . $html;
        } else {
            $html = "<option value=\"-1\" selected>No item with this id {$myid}</option>\n" . $html;
        }
    }
    print $html;
    print "</select>\n";
    $result->closeCursor();
}
Exemple #6
0
function get_sites()
{
    global $pdo, $dom, $root, $hostlist;
    global $earth, $met, $host, $model, $sitegroup;
    $parnode = $root->appendChild($dom->createElement("markers"));
    // 1. Get a list of all sites we have
    $subs = array();
    $where = "";
    $query = "SELECT sites.id, sites.sitename, sites.city, sites.country, ST_X(ST_CENTROID(sites.geometry)) AS lon, ST_Y(ST_CENTROID(sites.geometry)) AS lat FROM sites";
    if ($sitegroup) {
        $query .= " INNER JOIN sitegroups_sites ON sitegroups_sites.site_id=sites.id";
        $where .= $where == "" ? " WHERE" : " AND";
        $where .= " sitegroups_sites.sitegroup_id=?";
        $subs[] = $sitegroup;
    }
    $query .= $where;
    $stmt = $pdo->prepare($query);
    if (!$stmt->execute($subs)) {
        die('Invalid query: ' . error_database());
    }
    $sites = array();
    while ($row = @$stmt->fetch(PDO::FETCH_ASSOC)) {
        $row['format_id'] = array();
        $sites[$row['id']] = $row;
    }
    // in case of model we will need to filter those sites that can never be run
    if ($model) {
        // 1. Get list of all formats for each site
        $subs = array();
        $query = "SELECT DISTINCT sites.id, format_id FROM sites";
        $query .= " INNER JOIN inputs ON sites.id=inputs.site_id";
        $query .= " INNER JOIN dbfiles ON inputs.id=dbfiles.container_id";
        $where = " AND dbfiles.container_type='Input'";
        if ($sitegroup) {
            $query .= " INNER JOIN sitegroups_sites ON sitegroups_sites.site_id=sites.id";
            $where .= " AND sitegroups_sites.sitegroup_id=?";
            $subs[] = $sitegroup;
        }
        if ($host) {
            $query .= " INNER JOIN machines ON dbfiles.machine_id=machines.id";
            $where .= " AND machines.hostname=?";
            $subs[] = $host;
        }
        $query .= $where . " GROUP BY sites.id, format_id;";
        $stmt = $pdo->prepare($query);
        if (!$stmt->execute($subs)) {
            die('Invalid query: ' . error_database());
        }
        while ($row = @$stmt->fetch(PDO::FETCH_ASSOC)) {
            $sites[$row['id']]['format_id'][] = $row['format_id'];
        }
        $stmt->closeCursor();
        // 2. Find all formats that are in world
        $subs = array();
        $query = "SELECT DISTINCT format_id FROM inputs";
        $query .= " INNER JOIN dbfiles ON inputs.id=dbfiles.container_id";
        $where = " WHERE inputs.site_id={$earth} AND dbfiles.container_type='Input'";
        if ($host) {
            $query .= " INNER JOIN machines ON dbfiles.machine_id=machines.id";
            $where .= " AND machines.hostname=?";
            $subs[] = $host;
        }
        $query .= $where . " GROUP BY format_id;";
        $stmt = $pdo->prepare($query);
        if (!$stmt->execute($subs)) {
            die('Invalid query: ' . error_database());
        }
        while ($row = @$stmt->fetch(PDO::FETCH_ASSOC)) {
            foreach ($sites as &$site) {
                $site['format_id'][] = $row['format_id'];
            }
        }
        $stmt->closeCursor();
        // 3. Find all conversions possible
        if (isset($_REQUEST['conversion'])) {
            // Check for Download -> CF
            foreach ($sites as &$site) {
                if (!in_array($met['CF'], $site['format_id'])) {
                    $site['format_id'][] = $met['CF'];
                }
            }
            // Check for CF -> model
            $stmt = $pdo->prepare("SELECT modeltypes.name FROM modeltypes, models" . " WHERE modeltypes.id=models.modeltype_id" . " AND models.id=?;");
            if (!$stmt->execute(array($model))) {
                die('Invalid query: ' . error_database());
            }
            $modeltypes = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
            $stmt->closeCursor();
            foreach ($sites as &$site) {
                if (in_array($met['CF'], $site['format_id'])) {
                    foreach ($modeltypes as $mt) {
                        if (array_key_exists($mt, $met)) {
                            $site['format_id'][] = $met[$mt];
                        }
                    }
                }
            }
        }
        // 4. Get list of all formats needed for model
        $stmt = $pdo->prepare("SELECT format_id FROM modeltypes_formats, models" . " WHERE modeltypes_formats.modeltype_id=models.modeltype_id" . " AND modeltypes_formats.required = true" . " AND models.id=?;");
        if (!$stmt->execute(array($model))) {
            die('Invalid query: ' . error_database());
        }
        $formats = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
        $stmt->closeCursor();
        // 5. Filter all sites that have missing formats
        $filtered = array();
        foreach ($sites as $site) {
            if (count(array_diff($formats, $site['format_id'])) == 0) {
                $filtered[] = $site;
            }
        }
        $sites = $filtered;
    }
    // return a list of all all sites that have all formats
    foreach ($sites as $site) {
        $node = $dom->createElement("marker");
        $newnode = $parnode->appendChild($node);
        $newnode->setAttribute("siteid", $site['id']);
        $newnode->setAttribute("city", $site['city']);
        $newnode->setAttribute("country", $site['country']);
        $newnode->setAttribute("lat", $site['lat']);
        $newnode->setAttribute("lon", $site['lon']);
        if ($site['sitename'] != "") {
            $newnode->setAttribute("sitename", $site['sitename']);
        } else {
            $newnode->setAttribute("sitename", $site['id'] . " - " . $site['city']);
        }
    }
}