update
[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 'linetabs.php';
19 require_once 'details.php';
20 require_once 'table.php';
21 require_once 'form.php';
22 require_once 'toggle.php';
23
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'); 
29   return;
30  }
31
32 // --- decoration
33 $title="Tag Type";
34 $tabs=array();
35 $tabs []= tab_tags();
36
37 // -------------------- 
38 $tag_types= $api->GetTagTypes( array( $tag_type_id ) );
39 $tag_type=$tag_types[0];
40   
41 $tagname=$tag_type['tagname'];
42 $min_role_id= $tag_type['min_role_id'];
43 $description= $tag_type['description'];
44 $category=$tag_type['category'];
45
46 // where is it used 
47 $filter=array('tag_type_id'=>$tag_type_id);
48 $node_tags=$api->GetNodeTags($filter);
49 $interface_tags=$api->GetInterfaceTags($filter);
50 $slice_tags=$api->GetSliceTags(array_merge($filter,array("node_id"=>array())));
51 $sliver_tags=$api->GetSliceTags(array_merge($filter,array("~node_id"=>array())));
52
53 drupal_set_title("Details for tag type $tagname");
54 plekit_linetabs($tabs);
55
56 // ----------
57 $can_update=plc_is_admin();
58 $details=new PlekitDetails ($can_update);
59
60 $details->form_start(l_actions(),array("action"=>"update-tag-type",
61                                        "tag_type_id"=>$tag_type_id));
62 $details->start();
63 $details->th_td("Name",$tagname,"tagname");
64 $details->th_td("Category",$category,"category");
65 $details->th_td("Description",$description,"description");
66
67 if ($can_update) {
68 // select the option corresponding with min_role_id
69   $selectors = $details->form()->role_selectors($api,"",$min_role_id);
70   $select_field = $details->form()->select_html("min_role_id",$selectors);
71   // xxx would need to turn role_id into role name
72   $details->th_td("Min role",$select_field,"min_role_id",array('input_type'=>'select','value'=>$min_role_id));
73  } else {
74   $details->th_td("Min role",$min_role_id);
75  }
76 if ($can_update) 
77   $details->tr_submit('update-tag-type',"Update tag type");
78
79 $details->space();
80 $details->th_td("Used in nodes",count($node_tags));
81 $details->th_td("Used in interfaces",count($interface_tags));
82 $details->th_td("Used in slices",count($slice_tags));
83 $details->th_td("Used in slivers",count($sliver_tags));
84
85 $details->end();
86 $details->form_end();
87
88 // common options for tables below
89 $table_options=array('notes_area'=>false, 'pagesize_area'=>false, 'search_width'=>10);
90
91 // xxx could outline values corresponding to a nodegroup
92 if (count ($node_tags)) {
93   $toggle=new PlekitToggle('tag_nodes',"Nodes");
94   $toggle->start();
95   $table=new PlekitTable ("tag_nodes",array("Hostname"=>"string","value"=>"string"),0,$table_options);
96   $table->start();
97   foreach ($node_tags as $node_tag) {
98     $table->row_start();
99     $table->cell(href(l_node($node_tag['node_id']),$node_tag['hostname']));
100     $table->cell($node_tag['value']);
101     $table->row_end();
102   }
103   $table->end();
104   $toggle->end();
105  }
106
107 if (count ($interface_tags)) {
108   $toggle=new PlekitToggle('tag_interfaces',"Interfaces");
109   $toggle->start();
110   $table=new PlekitTable ("tag_interfaces",array("IP"=>"IPAddress","value"=>"string"),0,$table_options);
111   $table->start();
112   foreach ($interface_tags as $interface_tag) {
113     $table->row_start();
114     $table->cell(href(l_interface($interface_tag['interface_id']),$interface_tag['ip']));
115     $table->cell($interface_tag['value']);
116     $table->row_end();
117   }
118   $table->end();
119   $toggle->end();
120  }
121
122 // grouping both kinds of slice tags 
123 // xxx don't show hostnames yet
124 $slice_tags = array_merge ($slice_tags,$sliver_tags);
125 if (count ($slice_tags)) {
126   $toggle=new PlekitToggle('tag_slices',"Slice and sliver tags");
127   $toggle->start();
128   $table=new PlekitTable ("tag_slices",array("Slice"=>"string","value"=>"string","Node id"=>"int"),0,$table_options);
129   $table->start();
130   foreach ($slice_tags as $slice_tag) {
131     $table->row_start();
132     $table->cell(href(l_slice($slice_tag['slice_id']),$slice_tag['name']));
133     $table->cell($slice_tag['value']);
134     $node_text="all";
135     // sliver tag
136     if ($slice_tag['node_id']) 
137       $node_text=l_node($slice_tag['node_id'],$slice_tag['node_id']);
138     $table->cell($node_text);
139     $table->row_end();
140   }
141   $table->end();
142   $toggle->end();
143  }
144
145 //plekit_linetabs ($tabs,"bottom");
146
147 // Print footer
148 include 'plc_footer.php';
149
150 ?>