<?php

if (!cms_is_employee()) {
    log_msg(__FILE__, __LINE__, "Access denied");
    Location("../access_denied.php");
}
include "cms/db.php";
include "cms/forms.php";
include "cms/pr_template_def.rec";
$form_fields = array("server" => array("pr_template_def", "server", EDIT, OPTIONAL | CHOOSER), "address" => array("pr_template_def", "address", EDIT, OPTIONAL), "freq" => array("pr_template_def", "freq", EDIT, OPTIONAL), "count" => array("pr_template_def", "count", EDIT, OPTIONAL), "yellowtime" => array("pr_template_def", "yellowtime", EDIT, OPTIONAL), "redtime" => array("pr_template_def", "redtime", EDIT, OPTIONAL));
$cms = new DB_CMS();
while ($__act == "submit") {
    cms_leave_if_canceled();
    foreach ($HTTP_GET_VARS as $key => $value) {
        $fields[$key] = $HTTP_GET_VARS[$key];
    }
    if (!cms_fieldcheck($form_fields, $fields)) {
        break;
    }
    $cms->query("begin");
    if ($fields['contact'] < 1) {
        $fields['contact'] = 1;
    }
    $q = sprintf("insert into pr_probe_template set server = '%s', address = '%s', freq = '%s', " . "redtime = '%s', yellowtime = '%s'", $fields['server'], $fields['address'], $fields['freq'], $fields['redtime'], $fields['yellowtime']);
    $cms->query($q);
    $pr_probe_templateid = $cms->insert_id();
    $newstate = 'running';
    cms_add_history($fields['contact'], "CREATE", "pr_probe_template", $pr_probe_templateid, $fields['setup'] . " for " . $fields['contacttext']);
    $cms->query("commit");
    previous_location();
    break;
<?php

$form_fields = array("server" => array("pr_template_def", "server", SHOW, OPTIONAL | WITHLINK), "address" => array("pr_template_def", "address", SHOW, OPTIONAL), "freq" => array("pr_template_def", "freq", SHOW, OPTIONAL), "count" => array("pr_template_def", "count", SHOW, OPTIONAL), "yellowmiss" => array("pr_template_def", "yellowmiss", SHOW, OPTIONAL), "redmiss" => array("pr_template_def", "redmiss", SHOW, OPTIONAL), "color" => array("pr_template_def", "color", SHOW, WITHLINK), "stattime" => array("pr_template_def", "stattime", SHOW, OPTIONAL), "expires" => array("pr_template_def", "expires", SHOW, OPTIONAL), "message" => array("pr_template_def", "message", SHOW, OPTIONAL));
$extra_fields = array("servertext");
if (!cms_is_employee()) {
    unset($form_fields["color"]);
}
$cms = new DB_CMS();
$cms->query("select pr_template_def.*, server.id, server.name as servertext " . "from   pr_template_def, server " . "where  pr_template_def.id = {$id} and server.id = pr_template_def.server");
if ($cms->num_rows() == 0) {
    log_msg(__FILE__, __LINE__, "pr_template_def with id = {$id} not found");
    Location("index.php");
}
$cms->next_record();
$contact = $cms->f('contact');
if (!cms_represents($contact, R_ANY)) {
    log_msg(__FILE__, __LINE__, "Access denied");
    Location("../access_denied.php");
}
remember_location();
if (!cms_represents($contact, R_TECH)) {
    unset($form_fields["password"]);
    unset($form_fields["routerpwd"]);
}
foreach ($form_fields as $key => $value) {
    $fields[$key] = $cms->f($key);
}
foreach ($extra_fields as $value) {
    $fields[$value] = $cms->f($value);
}
form_start("notused");
<?php

remember_location();
include "cms/db.php";
include "cms/forms.php";
include "cms/pr_template_def.rec";
$cms = new DB_CMS();
include "site-pr_template_defshow.php";
if (!cms_is_employee()) {
    return;
}
$q = "select history.id, created, contact, history.type, lookup, lookupid, value, " . "       co.name as contacttext, cr.name as creatortext " . "from   history, contact co, contact cr " . "where  co.id = history.contact and cr.id = history.creator " . "       and lookup = 'pr_template_def' and lookupid = '{$id}' ";
if (isset($sort)) {
    $q .= " order by " . $sort;
    if (isset($sortdir)) {
        $q .= " " . $sortdir;
    }
} else {
    $q .= " order by created desc";
}
$cms->query($q . " limit 100");
include "historyshow.php";
<?php

if (!cms_is_employee()) {
    log_msg(__FILE__, __LINE__, "Access denied");
    Location("../access_denied.php");
}
include "cms/db.php";
include "cms/forms.php";
include "cms/pr_template_def.rec";
$form_fields = array("server" => array("pr_template_def", "server", EDIT, OPTIONAL | CHOOSER), "address" => array("pr_template_def", "address", EDIT, OPTIONAL), "freq" => array("pr_template_def", "freq", EDIT, OPTIONAL), "count" => array("pr_template_def", "count", EDIT, OPTIONAL), "yellowmiss" => array("pr_template_def", "yellowmiss", EDIT, OPTIONAL), "redmiss" => array("pr_template_def", "redmiss", EDIT, OPTIONAL), "color" => array("pr_template_def", "color", EDIT, WITHLINK));
$extra_fields = array("servertext");
$cms = new DB_CMS();
while ($__act == "submit") {
    cms_leave_if_canceled();
    foreach ($HTTP_POST_VARS as $key => $value) {
        $fields[$key] = $HTTP_POST_VARS[$key];
    }
    if (!cms_fieldcheck($form_fields, $fields)) {
        break;
    }
    $cms->query("begin");
    cms_update($cms, $form_fields, "pr_template_def", "id", $fields);
    $changed_fields = cms_changed_fields($form_fields, $fields);
    foreach ($changed_fields as $value) {
        $oldvar = "org" . $value;
        $q = sprintf("insert into history set created = NOW(), creator = '%s', contact = '%s', " . "type = 'CHANGED', lookup = 'pr_template_def', lookupid = '%s', value = '%s'", $sess->u_id, $fields['contact'], $id, mysql_escape_string($value . " from '" . $fields[$oldvar] . "' to '" . $fields[$value] . "'"));
        echo $q;
        $cms->query($q);
    }
    $cms->query("commit");
    previous_location();
<?php

remember_location();
include "cms/db.php";
include "cms/forms.php";
include "cms/pr_template_def.rec";
$cms = new DB_CMS();
include "site-pr_template_defshow.php";
if (!cms_is_employee()) {
    return;
}
$q = "select * from pr_template_hist where probe = '{$id}'";
if (isset($sort)) {
    $q .= " order by " . $sort;
    if (isset($sortdir)) {
        $q .= " " . $sortdir;
    }
} else {
    $q .= " order by stattime desc";
}
$cms->query($q . " limit 50");
include "site-pr_histshow.php";