editsitevars.php3 4.27 KB
Newer Older
Chad Barb's avatar
 
Chad Barb committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Edit Site Variables");

#
# Only known and logged in users can do this.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Of course verify that this uid has admin privs!
#
$isadmin = ISADMIN($uid);
if (! $isadmin) {
25
    USERERROR("You do not have admin privileges to edit site variables!", 1);
Chad Barb's avatar
 
Chad Barb committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
}


if (isset($edit)) {

    $result = DBQueryFatal("SELECT name, value, defaultvalue, description ".
			   "FROM sitevariables ".
			   "WHERE name='$edit'");

    if ($row = mysql_fetch_row($result)) {
	$name         = $row[0];
	$value        = $row[1];
	$defaultvalue = $row[2];
	$description  = $row[3];
    
	echo "<center>";
	echo "<form action='editsitevars.php3' method='post'>";
	echo "<input type='hidden' name='name' value='$name'></input>";
	echo "<table><tr><th colspan=2>";
	echo "Editing site variable '<b>$name</b>':";
	echo "</th></tr><tr><td>";
	echo "<b>Description:</b></td><td>$description</font>";
	echo "</td></tr><tr><td>";
	echo "<b>Default value:</b></td><td>";
	if (0 != strcmp($defaultvalue,"")) {
	    echo "<code>$defaultvalue</code>";
	} else {
	    echo "<font color='#00B040'><i>Empty String</i></font>";	    
	}
	echo "</td></tr><tr><td>&nbsp;</td><td>";
	echo "<input type='submit' name='defaulted' value='Reset to Default Value'></input>";
	echo "</td></tr><tr><td>";
	echo "<b>New value:</b></td><td>";
	echo "<input size='60' type='text' name='value' value='$value'></input>";
	echo "</td></tr><tr><td>&nbsp;</td><td>";
	echo "<input type='submit' name='edited' value='Change to New Value'></input>";
	echo "&nbsp;";
63
	echo "<input type='submit' name='canceled' value='Cancel'></input>";
Chad Barb's avatar
 
Chad Barb committed
64
65
66
67
68
69
70
71
72
73
74
75
76
	echo "</td></tr></table>";
	echo "</form>";
	echo "</center>";

    } else {
	TBERROR("Couldn't find variable '$edit'!");
    }

    PAGEFOOTER();
    return;
}

if (isset($edited)) {
77
78
    $value = addslashes("$value");
    
Chad Barb's avatar
 
Chad Barb committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    DBQueryFatal("UPDATE sitevariables ".
		 "SET value='$value' ".
		 "WHERE name='$name'");

    echo "<h3>'$name' changed.</h3>";
    echo "<form action='editsitevars.php3' method='get'>";
    echo "<input type='submit' name='yadda' value='Return to list'></input>";
    echo "</form>";
    PAGEFOOTER();
    return;
}

if (isset($defaulted)) {
    DBQueryFatal("UPDATE sitevariables ".
		 "SET value=NULL ".
		 "WHERE name='$name'");

    echo "<h3>'$name' reset to default.</h3>";
    echo "<form action='editsitevars.php3' method='get'>";
    echo "<input type='submit' name='yadda' value='Return to list'></input>";
    echo "</form>";
    PAGEFOOTER();
    return;
}

104
105
if (isset($canceled)) {
    echo "<h3>Operation canceled.</h3>";
Chad Barb's avatar
 
Chad Barb committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    echo "<form action='editsitevars.php3' method='get'>";
    echo "<input type='submit' name='yadda' value='Return to list'></input>";
    echo "</form>";
    PAGEFOOTER();
    return;
}

$result = DBQueryFatal("SELECT name, value, defaultvalue, description ".
		       "FROM sitevariables ".
		       "ORDER BY name");

echo "<table>
      <tr>
        <th>&nbsp;Name&nbsp;</th>
        <th>&nbsp;Value&nbsp;</th>
        <th><font size='-1'>Edit</font></th>
        <th>&nbsp;Default Value&nbsp;</th>
        <th>&nbsp;Description&nbsp;</th> 
      </tr>";
 
while ($row = mysql_fetch_row($result)) {
    $name         = $row[0];
    $value        = $row[1];
    $defaultvalue = $row[2];
    $description  = $row[3];

    $cginame = urlencode($name);

    echo "<tr><td>&nbsp;<b>$name</b>&nbsp;</td>\n";

136
    echo "<td>&nbsp;";
Chad Barb's avatar
 
Chad Barb committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    if (isset($value)) {
	if (0 != strcmp($value, "")) {
	    echo "<code>$value</code>&nbsp;</td>";
	} else {
	    echo "<font color='#00B040'><i>empty string</i></font>&nbsp;</td>";	
	}
    } else {
	echo "<font color='#00B040'><i>default</i></font>&nbsp;</td>";
    }
    echo "<td align=center>";
    echo "&nbsp;<a href='editsitevars.php3?edit=$cginame'>";
    echo "<img border='0' src='greenball.gif' /></a>";
    echo "&nbsp;</td>";

    echo "<td nowrap='1'>&nbsp;";
    if (0 != strcmp($defaultvalue, "")) {
	echo "<code>$defaultvalue</code>&nbsp;</td>";
    } else {
	echo "<font color='#00B040'><i>empty string</i></font>&nbsp;</td>";	
    }

    echo "<td>&nbsp;$description&nbsp;</td></tr>\n";
}

echo "</table>";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>