cleaned up tabs
[plewww.git] / planetlab / tags / tag.php
1 <?php
2
3 // $Id$
4
5 // Require login
6 require_once 'plc_login.php';
7
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api;
11
12 // Print header
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
15
16 // Common functions
17 require_once 'plc_functions.php';
18 require_once 'plc_minitabs.php';
19 require_once 'plc_details.php';
20 require_once 'plc_tables.php';
21 require_once 'plc_forms.php';
22
23 // -------------------- 
24 // recognized URL arguments
25 $tag_type_id=intval($_GET['id']);
26 if ( ! $tag_type_id ) { 
27   plc_error('Malformed URL - id not set'); 
28   return;
29  }
30
31 // --- decoration
32 $title="Tag Type";
33 $tabs=array();
34 $tabs []= tab_tags();
35
36 // -------------------- 
37 $tag_types= $api->GetTagTypes( array( $tag_type_id ) );
38 $tag_type=$tag_types[0];
39   
40 $tagname=$tag_type['tagname'];
41 $min_role_id= $tag_type['min_role_id'];
42 $description= $tag_type['description'];
43 $category=$tag_type['category'];
44
45 // where is it used 
46 $filter=array('tag_type_id'=>$tag_type_id);
47 $node_tags=$api->GetNodeTags($filter);
48 $interface_tags=$api->GetInterfaceTags($filter);
49 $slice_tags=$api->GetSliceTags(array_merge($filter,array("node_id"=>array())));
50 $sliver_tags=$api->GetSliceTags(array_merge($filter,array("~node_id"=>array())));
51
52 drupal_set_title("Details for tag type $tagname");
53 plc_tabs($tabs);
54
55 // ----------
56 $can_update=plc_is_admin();
57 $details=new PlcDetails ($can_update);
58
59 $details->form_start(l_actions(),array("action"=>"update-tag-type",
60                                        "tag_type_id"=>$tag_type_id));
61 $details->start();
62 $details->th_td("Name",$tagname,"tagname");
63 $details->th_td("Category",$category,"category");
64 $details->th_td("Description",$description,"description");
65
66 if ($can_update) {
67 // select the option corresponding with min_role_id
68   $selectors = $details->form()->role_selectors($api,"",$min_role_id);
69   $select_field = $details->form()->select_html("min_role_id",$selectors);
70   // xxx would need to turn role_id into role name
71   $details->th_td("Min role",$select_field,"min_role_id",array('input_type'=>'select','value'=>$min_role_id));
72  } else {
73   $details->th_td("Min role",$min_role_id);
74  }
75 if ($can_update) 
76   $details->tr_submit('update-tag-type',"Update tag type");
77
78 $details->space();
79 $details->th_td("Used in nodes",count($node_tags));
80 $details->th_td("Used in interfaces",count($interface_tags));
81 $details->th_td("Used in slices",count($slice_tags));
82 $details->th_td("Used in slivers",count($sliver_tags));
83
84 $details->end();
85 $details->form_end();
86
87 // common options for tables below
88 $table_options=array('notes_area'=>false, 'pagesize_area'=>false, 'search_width'=>10);
89
90 // xxx could outline values corresponding to a nodegroup
91 if (count ($node_tags)) {
92   plc_section("Nodes");
93   $table=new PlcTable ("tag_nodes",array("Hostname"=>"string","value"=>"string"),0,$table_options);
94   $table->start();
95   foreach ($node_tags as $node_tag) {
96     $table->row_start();
97     $table->cell(href(l_node($node_tag['node_id']),$node_tag['hostname']));
98     $table->cell($node_tag['value']);
99     $table->row_end();
100   }
101   $table->end();
102  }
103
104 if (count ($interface_tags)) {
105   plc_section("Interfaces");
106   $table=new PlcTable ("tag_interfaces",array("IP"=>"IPAddress","value"=>"string"),0,$table_options);
107   $table->start();
108   foreach ($interface_tags as $interface_tag) {
109     $table->row_start();
110     $table->cell(href(l_interface($interface_tag['interface_id']),$interface_tag['ip']));
111     $table->cell($interface_tag['value']);
112     $table->row_end();
113   }
114   $table->end();
115  }
116
117 // grouping both kinds of slice tags 
118 // xxx don't show hostnames yet
119 $slice_tags = array_merge ($slice_tags,$sliver_tags);
120 if (count ($slice_tags)) {
121   plc_section("Slice and sliver tags");
122   $table=new PlcTable ("tag_slices",array("Slice"=>"string","value"=>"string","Node id"=>"int"),0,$table_options);
123   $table->start();
124   foreach ($slice_tags as $slice_tag) {
125     $table->row_start();
126     $table->cell(href(l_slice($slice_tag['slice_id']),$slice_tag['name']));
127     $table->cell($slice_tag['value']);
128     $node_text="all";
129     // sliver tag
130     if ($slice_tag['node_id']) 
131       $node_text=l_node($slice_tag['node_id'],$slice_tag['node_id']);
132     $table->cell($node_text);
133     $table->row_end();
134   }
135   $table->end();
136  }
137
138 // Print footer
139 include 'plc_footer.php';
140
141 ?>