File:
0.04.13a/server/web/localtest.action.php (
View as Code)
1: 2: /* -------------------------------------------------------------
3: This file is part of FreeNATS
4:
5: FreeNATS is (C) Copyright 2008 PurplePixie Systems
6:
7: FreeNATS is free software: you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation, either version 3 of the License, or
10: (at your option) any later version.
11:
12: FreeNATS is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with FreeNATS. If not, see www.gnu.org/licenses
19:
20: For more information see www.purplepixie.org/freenats
21: -------------------------------------------------------------- */
22:
23: ob_start();
24: require("include.php");
25: $NATS->Start();
26: if (!$NATS_Session->Check($NATS->DB))
27: {
28: header("Location: ./?login_msg=Invalid+Or+Expired+Session");
29: exit();
30: }
31: if ($NATS_Session->userlevel<5) UL_Error("Action Local Test");
32:
33: switch ($_REQUEST['action'])
34: {
35: case "create":
36: if (isset($_REQUEST['testcreatedisabled'])) $tenable=0;
37: else $tenable=1;
38: $q="INSERT INTO fnlocaltest(nodeid,testtype,testparam,testenabled) VALUES(";
39: $q.="\"".ss($_REQUEST['nodeid'])."\",\"".ss($_REQUEST['testtype'])."\",\"".ss($_REQUEST['testparam'])."\",".$tenable.")";
40: //echo $q;
41: //exit();
42: $NATS->DB->Query($q);
43: //echo $q;
44: //exit();
45: // Following user feedback (added to 0.02.35a)
46: //$loc="localtest.edit.php?localtestid=".$NATS->DB->Insert_Id();
47:
48: /* -- the old code just to appear in the list, now opens like a node create for the options
49: $loc="node.edit.php?nodeid=".$_REQUEST['nodeid']; // no message - just appears in list like evals
50: */
51: $loc="localtest.edit.php?localtestid=".$NATS->DB->Insert_Id();
52: header("Location: ".$loc);
53: exit();
54:
55: break;
56: case "save_form":
57: if (isset($_REQUEST['testrecord'])) $tr=$_REQUEST['testrecord'];
58: else $tr=0;
59: if (isset($_REQUEST['simpleeval'])) $se=$_REQUEST['simpleeval'];
60: else $se=0;
61: if (isset($_REQUEST['testenabled'])) $te=1;
62: else $te=0;
63: $q="UPDATE fnlocaltest SET testparam=\"".ss($_REQUEST['testparam'])."\",testrecord=".ss($tr).",simpleeval=".ss($se).",testenabled=".$te.",";
64: $q.="testname=\"".ss($_REQUEST['testname'])."\",attempts=".ss($_REQUEST['attempts']).",timeout=".ss($_REQUEST['timeout']);
65:
66: // get and update parameters if available
67: for ($a=1; $a<10; $a++) // 1 to 9 - "0" taken care of
68: {
69: $paramstr="testparam".$a;
70: if (isset($_REQUEST[$paramstr])) $val=ss($_REQUEST[$paramstr]);
71: else $val="";
72: $clearstr="clearparam".$a;
73: $keepstr="keeptestparam".$a;
74: if ( (isset($_REQUEST[$clearstr]))&&($_REQUEST[$clearstr]==1) )
75: { // wants cleared so do for sure
76: $val="";
77: $q.=",".$paramstr."=\"".$val."\"";
78: }
79: else if (isset($_REQUEST[$keepstr]))
80: {
81: // keep if new input is blank
82: if ($val!="") $q.=",".$paramstr."=\"".$val."\"";
83: }
84: else
85: { // otherwise update unless cleared
86: $q.=",".$paramstr."=\"".$val."\"";
87: }
88: }
89:
90: $q.=" WHERE localtestid=".ss($_REQUEST['localtestid']);
91: //echo $q;
92: //exit();
93: $NATS->DB->Query($q);
94: if ($NATS->DB->Affected_Rows()<=0) $msg="Save+Failed+or+Nothing+Changed";
95: else $msg="Changes+Saved";
96: header("Location: localtest.edit.php?localtestid=".$_REQUEST['localtestid']."&message=".$msg);
97: exit();
98: case "delete":
99: if (!isset($_REQUEST['confirmed']))
100: {
101: $back="localtest.action.php?action=delete&localtestid=".$_REQUEST['localtestid']."&confirmed=1";
102: $back=urlencode($back);
103: $url="confirm.php?action=Delete+test+and+all+historical+data&back=".$back;
104: header("Location: ".$url);
105: exit();
106: }
107: // history
108: $q="DELETE FROM fnrecord WHERE testid=\"L".ss($_REQUEST['localtestid'])."\"";
109: $NATS->DB->Query($q);
110: $hdel=$NATS->DB->Affected_Rows();
111: // test itself
112: $q="DELETE FROM fnlocaltest WHERE localtestid=".ss($_REQUEST['localtestid']);
113: $NATS->DB->Query($q);
114: $m="Deleted ".$NATS->DB->Affected_Rows()." test and ".$hdel." history items";
115: header("Location: main.php?message=".urlencode($m));
116: exit();
117:
118: default:
119: header("Location: main.php?message=Unknown+Local+Test+Action");
120: exit();
121: }
122:
123: ?>
124: