newgroup.php3 5.71 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
# All rights reserved.
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
7
8
include("defs.php3");

9
10
11
12
13
#
# Standard Testbed Header
#
PAGEHEADER("Create a Project Group");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
14
15
16
#
# Only known and logged in users.
#
17
18
19
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
20
21

#
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Verify page arguments.
#
$optargs = OptionalPageArguments("project",    PAGEARG_PROJECT,
				 "submit",     PAGEARG_STRING,
				 "formfields", PAGEARG_ARRAY);
if (!isset($project)) {
    #
    # See what projects the uid can do this in.
    #
    $projlist = $this_user->ProjectAccessList($TB_PROJECT_MAKEGROUP);

    if (! count($projlist)) {
	USERERROR("You do not appear to be a member of any Projects in which ".
		  "you have permission to create new groups.", 1);
    }
37
}
38
39
40
41
42
43
44
45
46
47
else {
    #
    # Verify permission for specific project.
    #
    $pid = $project->pid();
    
    if (!$project->AccessCheck($this_user, $TB_PROJECT_MAKEGROUP)) {
	USERERROR("You do not have permission to create groups in ".
		  "project $pid!", 1);
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
48
49
50
}

#
51
# Spit the form out using the array of data. 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
52
# 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function SPITFORM($formfields, $errors)
{
    global $project, $pid, $projlist;
    global $TBDB_GIDLEN, $TBDB_UIDLEN;

    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
                  </tr>\n";
	}
	echo "</table><br>\n";
    }
Leigh B. Stoller's avatar
Leigh B. Stoller 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
104
105
106
107
108
109
110
111
112
    echo "<br>
          <table align=center border=1> 
          <tr>
             <td align=center colspan=2>
                 <em>(Fields marked with * are required)</em>
             </td>
          </tr>\n";

    if (isset($project)) {
	$url = CreateURL("newgroup", $project);
	echo "<form action='$url' method=post>
	      <tr>
		  <td>* Project:</td>
		  <td class=left>
		      <input name=project type=readonly value='$pid'>
		  </td>
	      </tr>\n";
    }
    else {
	$url = CreateURL("newgroup");
	echo "<form action='$url' method=post>
	      <tr>
		  <td>*Select Project:</td>";
	echo "    <td><select name=project>";

	while (list($proj) = each($projlist)) {
	    echo "<option value='$proj'>$proj </option>\n";
	}

	echo "       </select>";
	echo "    </td>
	      </tr>\n";
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    echo "<tr>
	      <td>*Group Name (no blanks, lowercase):</td>
	      <td class=left>
		  <input type=text 
			 name=\"formfields[group_id]\" 
			 value=\"" . $formfields["group_id"] . "\"
			 size=$TBDB_GIDLEN
			 maxlength=$TBDB_GIDLEN>
	      </td>
	  </tr>\n";

    echo "<tr>
	      <td>*Group Description:</td>
	      <td class=left>
		  <input type=text size=50
			 name=\"formfields[group_description]\"
			 value=\"" . $formfields["group_description"] . "\">
	      </td>
	  </tr>\n";

    echo "<tr>
	      <td>*Group Leader (Emulab userid):</td>
	      <td class=left>
		  <input type=text
			 name=\"formfields[group_leader]\"
			 value=\"" . $formfields["group_leader"] . "\"
			 size=$TBDB_UIDLEN maxlength=$TBDB_UIDLEN>
	      </td>
	  </tr>\n";

    echo "<tr>
              <td align=center colspan=2>
                  <b><input type=submit name=submit value=Submit></b>
              </td>
          </tr>\n";

    echo "</form>
          </table>\n";

    echo "<br><center>
	     Important <a href=docwrapper.php3?docname=groups.html#SECURITY'>
	     security issues</a> are discussed in the
	     <a href='docwrapper.php3?docname=groups.html'>Groups Tutorial</a>.
          </center>\n";
158
159
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
160
#
161
162
163
164
165
166
167
# Accumulate error reports for the user, e.g.
#    $errors["Key"] = "Msg";
# Required page args may need to be checked early.
$errors  = array();

#
# On first load, display a virgin form and exit.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
168
#
169
170
171
172
173
174
175
176
177
if (!isset($submit)) {
    $defaults = array();
    $defaults["group_id"]	   = "";
    $defaults["group_description"] = "";
    $defaults["group_leader"]	   = $uid;

    SPITFORM($defaults, $errors);
    PAGEFOOTER();
    return;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
178
}
179

Leigh B. Stoller's avatar
Leigh B. Stoller committed
180
#
181
182
183
184
185
186
187
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
# 
if (count($errors)) {
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
188
189
190
}

#
191
# Build up argument array to pass along.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
192
#
193
$args = array();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
194

195
196
197
if (isset($formfields["project"]) &&
    $formfields["project"] != "none" && $formfields["project"] != "") {
    $args["project"]		= $formfields["project"];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
198
}
199
200
if (isset($formfields["group_id"]) && $formfields["group_id"] != "") {
    $args["group_id"]	= $formfields["group_id"];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
201
}
202
203
204
205
206
207
if (isset($formfields["group_description"]) && 
    $formfields["group_description"] != "") {
    $args["group_description"]	= $formfields["group_description"];
}
if (isset($formfields["group_leader"]) && $formfields["group_leader"] != "") {
    $args["group_leader"]	= $formfields["group_leader"];
208
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
209

210
211
212
$group_id = $formfields["group_id"];
###STARTBUSY("Creating project group $group_id.");
echo "<br>Creating project group $group_id.<br>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
213
flush();
214

215
216
217
218
219
220
221
if (! ($newgroup = Group::Create($project, $uid, $args, $errors))) {
    # Always respit the form so that the form fields are not lost.
    # I just hate it when that happens so lets not be guilty of it ourselves.
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
222

223
###STOPBUSY();
224

225
echo "<center><h3>Done!</h3></center>\n";
226
PAGEREPLACE(CreateURL("showgroup", $newgroup));
227

228
229
230
231
#
# Standard Testbed Footer
# 
PAGEFOOTER();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
232
?>