6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_drupal.php';
14 drupal_set_title('Interface Setting Types');
15 include 'plc_header.php';
18 require_once 'plc_functions.php';
19 require_once 'plc_sorts.php';
22 $_person= $plc->person;
23 $_roles= $_person['role_ids'];
25 //plc_debug("person", $_person );
27 $tag_columns=array( "tag_type_id", "category", "tagname", "description", "min_role_id" );
29 // prepare dict role_id => role_name
31 $roles= $api->GetRoles();
32 global $roles_id_to_name;
33 $roles_id_to_name=array();
34 foreach ($roles as $role) {
35 $roles_id_to_name[$role['role_id']] = $role['name'];
38 // compute person's smallest role
41 foreach ($_person['role_ids'] as $role_id) {
42 if ($role_id < $person_role) {
43 $person_role=$role_id;
46 //plc_debug("person_role",$person_role);
48 // post-process results from GetTagTypes
49 // with planetlab 4.2, we've moved to php-5.2
50 // with the former 5.0 reelase, I could invoke array_map
51 // with a function that took a reference and could do side-effects
52 // Now I have to return the copy...
53 // this new way of doing things might require more memory
54 // on the other hand we should move to a schema where
55 // pagination is done in the API, so it's no big deal hopefully
56 function layout_setting_type ($setting_type) {
57 // replace role_id with name
58 global $roles_id_to_name;
59 $setting_type['min_role']=$roles_id_to_name[$setting_type['min_role_id']];
63 // if no id, display list of tag types
64 if( !$_GET['id'] && !$_GET['add'] && !$_GET['add_type'] && !$_GET['edit_type'] ) {
67 $filter = array (']min_role_id'=>$person_role,'category'=>'interface*');
68 $setting_types= $api->GetTagTypes( $filter, $tag_columns );
69 $setting_types = array_map(layout_setting_type,$setting_types);
70 sort_interface_tags ($setting_types);
74 echo "<table cellpadding=2>";
76 // if admin we need one more cells for delete links
77 if( in_array( "10", $_person['role_ids'] ) )
79 $role_header="<table><tr><th>min</th></tr><tr><th>Role</th></tr></table>";
81 echo "<th>Category</th>";
82 echo "<th>" . $role_header . "</th>";
84 echo "<th>Description</th>";
88 foreach( $setting_types as $type ) {
90 // if admin display delete links
91 if( in_array( "10", $_person['role_ids'] ) ) {
93 echo plc_delete_link_button('setting_action.php?del_type='. $type['tag_type_id'],
97 // if admin, the name is a link to edition
98 if (in_array( "10", $_person['role_ids'])) {
99 echo "<td><a href='settings.php?edit_type=". $type['tag_type_id'] . "'>" . $type['tagname'] . "</a></td>";
101 echo "<td>" . $type['tagname'] . "</td>";
103 echo "<td>" . $type['category'] . "</td>";
104 echo "<td>" . $type['min_role'] . "</td><td>" . $type['min_role_id'] . "</td><td>" . $type['description'] . "</td>";
108 if( in_array( "10", $_person['role_ids'] ) )
109 echo "<tr><td colspan=6><a href='settings.php?add_type=true'>Add a Setting Type</td></tr>";
111 echo "</tbody></table>\n";
115 echo "<p><p><a href='/db/nodes/index.php'>Back to Nodes</a>\n";
118 elseif( $_GET['add_type'] || $_GET['edit_type'] ) {
119 // if its edit get the tag info
120 if( $_GET['edit_type'] ) {
121 $type_id= intval( $_GET['edit_type'] );
122 $type= $api->GetTagTypes( array( $type_id ) );
124 $category=$type[0]['category'];
125 $name= $type[0]['tagname'];
126 $min_role_id= $type[0]['min_role_id'];
127 $description= $type[0]['description'];
131 // display form for setting types
132 echo "<form action='setting_action.php' method='post'>\n";
133 if ($_GET['edit_type']) {
134 drupal_set_title("Edit Setting Type");
136 drupal_set_title("Add Setting Type");
138 echo "<table cellpadding='5' cellspacing='5' border='0'>";
139 echo "<tr><th>Category:</th><td><input type=text name='category' size=20 value='$category'></td></tr>\n";
140 echo "<tr><th>Name:</th><td><input type=text name='name' size=20 value='$name'></td></tr>\n";
141 echo "<tr><th>Min Role:</th><td><select name='min_role_id'>\n";
143 foreach ($roles as $role) {
144 echo "<option value='" . $role['role_id'] . "'";
145 if( $min_role_id == intval($role['role_id']) ) echo " selected";
146 echo ">" . $role['name'] . "</option>\n";
148 echo "</select></td></tr>\n";
149 echo "<tr><th>Description:</th><td>";
150 echo "<textarea name='description' cols=50 rows=5>$description</textarea>\n";
152 echo "<tr><td colspan=2 align=center>";
153 if( $_GET['edit_type'] ) {
154 echo "<input type=hidden name='tag_type_id' value='$type_id'>\n";
155 echo "<input type=submit name='edit_type' value='Edit Setting Type'>\n";
157 echo "<input type=submit name='add_type' value='Add Interface Type'>\n";
164 echo "<p><a href='/db/nodes/settings.php'>Back to Setting Types</a>\n";
166 elseif( $_GET['add'] ) {
168 // get interface id from GET
169 $interface_id= intval( $_GET['add'] );
171 // get all setting types
173 $filter = array (']min_role_id'=>$person_role,'category'=>'interface*');
174 $setting_types= $api->GetTagTypes( $filter, array( "tag_type_id", "tagname" , "category") );
175 sort_interface_tags($setting_types);
177 // get interface's settings
178 $interface = $api->GetInterfaces( array( $interface_id ), array( "interface_tag_ids","ip" ) );
180 drupal_set_title("Add a setting to ". $interface[0]['ip']);
183 echo "<form action='setting_action.php' method='post'>\n";
184 echo "<input type=hidden name='interface_id' value='$interface_id'>\n";
186 echo "<table cellpadding='2'> <caption> New Setting </caption>";
188 echo "<tr><th>Select</th><td><select name='tag_type_id'><option value=''>Choose a type to add</option>\n";
190 foreach( $setting_types as $setting_type ) {
191 echo "<option value='". $setting_type['tag_type_id'] ."'>". $setting_type['category'] . ":" . $setting_type['tagname'] ."</option>\n";
194 echo "</select></td</tr>\n";
196 echo "<tr><th>Value: </th><td><input type=text name='value'></td></tr>\n";
198 echo "<tr><td colspan=2 align=center><input type=submit name='add_setting' value='Add Setting'></td></tr>\n";
204 $setting_id= intval( $_GET['id'] );
207 $setting= $api->GetInterfaceTags( array( $setting_id ));
210 $interface= $api->GetInterfaces( array( $setting[0]['interface_id'] ), array( "ip" ) );
212 drupal_set_title("Edit setting ". $setting[0]['tagname'] ." on ". $interface[0]['ip']);
214 // start form and put values in to be edited.
215 echo "<form action='setting_action.php' method='post'>\n";
216 echo "<input type=hidden name='setting_id' value='". $setting[0]['interface_tag_id'] ."'>\n";
217 echo "<input type=hidden name='interface_id' value='". $setting[0]['interface_id'] ."'>\n";
219 echo "<table cellpadding='2'> <caption> Edit Setting </caption>";
220 echo "<tr><th> Category </th> <td>" . $setting[0]['category'] . "</td></tr>";
221 echo "<tr><th> Name </th> <td>" . $setting[0]['tagname'] . "</td></tr>";
222 echo "<tr><th> Value </th> <td><input type=text name='value' value='" . $setting[0]['value'] . "'> </td></tr>";
223 echo "<tr><td colspan=2> <input type=submit value='Edit Setting' name='edit_setting'></td></tr>";
229 // back link is case-dependant
232 include 'plc_footer.php';