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 include 'plc_header.php';
17 require_once 'plc_functions.php';
18 require_once 'linetabs.php';
19 require_once 'details.php';
20 require_once 'table.php';
21 require_once 'form.php';
22 require_once 'toggle.php';
24 // --------------------
25 // recognized URL arguments
26 $tag_type_id=intval($_GET['id']);
27 if ( ! $tag_type_id ) {
28 plc_error('Malformed URL - id not set');
37 // --------------------
38 $tag_types= $api->GetTagTypes( array( $tag_type_id ) );
39 $tag_type=$tag_types[0];
41 $tagname=$tag_type['tagname'];
42 $min_role_id= $tag_type['min_role_id'];
43 $description= $tag_type['description'];
44 $category=$tag_type['category'];
47 $filter=array('tag_type_id'=>$tag_type_id);
48 $node_tags=$api->GetNodeTags($filter);
49 $interface_tags=$api->GetInterfaceTags($filter);
50 // split slice tags into 3 families, whether this applies to the whole slice, or a nodegroup, or a node
51 // using filters for this purpose does not work out very well, maybe a bug in the filter stuff
52 // anyway this is more efficient, and we compute the related node(groups) in the same pass
53 $slice_tags=$api->GetSliceTags(array_merge($filter));
56 $nodegroup_ids=array();
59 foreach ($slice_tags as $slice_tag) {
60 if ($slice_tag['node_id']) {
61 $node_ids []= $slice_tag['node_id'];
63 } else if ($slice_tag['nodegroup_id']) {
64 $nodegroup_ids []= $slice_tag['nodegroup_id'];
65 $count_nodegroup += 1;
71 $nodes=$api->GetNodes($node_ids,array('hostname','node_id'));
73 foreach ($nodes as $node) $node_hash[$node['node_id']]=$node;
74 $nodegroups=$api->GetNodeGroups($nodegroup_ids,array('groupname','nodegroup_id'));
75 $nodegroup_hash=array();
76 foreach ($nodegroups as $nodegroup) $nodegroup_hash[$nodegroup['nodegroup_id']]=$nodegroup;
79 drupal_set_title("Details for tag type $tagname");
80 plekit_linetabs($tabs);
83 $toggle = new PlekitToggle ('details','Details');
85 $can_update=plc_is_admin();
86 $details=new PlekitDetails ($can_update);
88 $details->form_start(l_actions(),array("action"=>"update-tag-type",
89 "tag_type_id"=>$tag_type_id));
91 $details->th_td("Name",$tagname,"tagname");
92 $details->th_td("Category",$category,"category",array('width'=>30));
93 $details->th_td("Description",$description,"description",array('width'=>40));
96 // select the option corresponding with min_role_id
97 $selectors = $details->form()->role_selectors($api->GetRoles(),$min_role_id);
98 $select_field = $details->form()->select_html("min_role_id",$selectors);
99 // xxx would need to turn role_id into role name
100 $details->th_td("Min role",$select_field,"min_role_id",array('input_type'=>'select','value'=>$min_role_id));
102 $details->th_td("Min role",$min_role_id);
105 $details->tr_submit('update-tag-type',"Update tag type");
108 $details->th_td("Used in nodes",count($node_tags));
109 $details->th_td("Used in interfaces",count($interface_tags));
110 $details->th_td("Used in slices/node",$count_node);
111 $details->th_td("Used in slices/nodegroup",$count_nodegroup);
112 $details->th_td("Used in slices",$count_slice);
115 $details->form_end();
118 // common options for tables below
119 $table_options=array('notes_area'=>false, 'pagesize_area'=>false, 'search_width'=>10);
121 // xxx could outline values corresponding to a nodegroup
122 if (count ($node_tags)) {
123 $toggle=new PlekitToggle('tag_nodes',"Nodes");
125 $table=new PlekitTable ("tag_nodes",array("Hostname"=>"string","value"=>"string"),0,$table_options);
127 foreach ($node_tags as $node_tag) {
129 $table->cell(href(l_node($node_tag['node_id']),$node_tag['hostname']));
130 $table->cell($node_tag['value']);
137 if (count ($interface_tags)) {
138 $toggle=new PlekitToggle('tag_interfaces',"Interfaces");
140 $table=new PlekitTable ("tag_interfaces",array("IP"=>"IPAddress","value"=>"string"),0,$table_options);
142 foreach ($interface_tags as $interface_tag) {
144 $table->cell(href(l_interface($interface_tag['interface_id']),$interface_tag['ip']));
145 $table->cell($interface_tag['value']);
152 if (count ($slice_tags)) {
153 $toggle=new PlekitToggle('tag_slices',"Slice tags");
156 $headers["slice"]='string';
157 $headers["value"]='string';
158 $headers["node"]='string';
159 $headers["nodegroup"]='string';
160 $table=new PlekitTable ("tag_slices",$headers,0,$table_options);
162 foreach ($slice_tags as $slice_tag) {
164 $table->cell(href(l_slice($slice_tag['slice_id']),$slice_tag['name']));
165 $table->cell($slice_tag['value']);
168 if ($slice_tag['node_id']) {
169 $node_id=$slice_tag['node_id'];
170 $node=$node_hash[$node_id];
171 $node_text=l_node_obj($node);
173 $table->cell($node_text);
175 $nodegroup_text="all";
176 if ($slice_tag['nodegroup_id']) {
177 $nodegroup_id=$slice_tag['nodegroup_id'];
178 $nodegroup=$nodegroup_hash[$nodegroup_id];
179 $nodegroup_text=l_nodegroup_obj($nodegroup);
181 $table->cell($nodegroup_text);
189 //plekit_linetabs ($tabs,"bottom");
192 include 'plc_footer.php';