reviewed plcdetails
[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['All Types']=array('url'=>l_tags(),'bubble'=>"All Tag Types");
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 // xxx misses in PlcDetails
67 if ($can_update) {
68 //tmp
69 // select the option corresponding with min_role_id
70   $selectors = $details->form()->role_selectors($api,"",$min_role_id);
71   $select_field = $details->form()->select_html("min_role_id",$selectors);
72   $save_i=$details->set_input_type("select");
73   $details->th_td("Min role",$select_field,"min_role_id");
74   $details->set_input_type($save_i);
75  } else {
76   $details->th_td("Min role",$min_role_id);
77  }
78 if ($can_update) 
79   $details->tr_submit('update-tag-type',"Update tag type");
80
81 $details->space();
82 $details->th_td("Used in nodes",count($node_tags));
83 $details->th_td("Used in interfaces",count($interface_tags));
84 $details->th_td("Used in slices",count($slice_tags));
85 $details->th_td("Used in slivers",count($sliver_tags));
86
87 $details->end();
88 $details->form_end();
89
90 // common options for tables below
91 $table_options=array('notes_area'=>false, 'pagesize_area'=>false, 'search_width'=>10);
92
93 // xxx could outline values corresponding to a nodegroup
94 if (count ($node_tags)) {
95   plc_section("Nodes");
96   $table=new PlcTable ("tag_nodes",array("Hostname"=>"string","value"=>"string"),0,$table_options);
97   $table->start();
98   foreach ($node_tags as $node_tag) {
99     $table->row_start();
100     $table->cell(href(l_node($node_tag['node_id']),$node_tag['hostname']));
101     $table->cell($node_tag['value']);
102     $table->row_end();
103   }
104   $table->end();
105  }
106
107 if (count ($interface_tags)) {
108   plc_section("Interfaces");
109   $table=new PlcTable ("tag_interfaces",array("IP"=>"IPAddress","value"=>"string"),0,$table_options);
110   $table->start();
111   foreach ($interface_tags as $interface_tag) {
112     $table->row_start();
113     $table->cell(href(l_interface($interface_tag['interface_id']),$interface_tag['ip']));
114     $table->cell($interface_tag['value']);
115     $table->row_end();
116   }
117   $table->end();
118  }
119
120 // grouping both kinds of slice tags 
121 // xxx don't show hostnames yet
122 $slice_tags = array_merge ($slice_tags,$sliver_tags);
123 if (count ($slice_tags)) {
124   plc_section("Slice and sliver tags");
125   $table=new PlcTable ("tag_slices",array("Slice"=>"string","value"=>"string","Node id"=>"int"),0,$table_options);
126   $table->start();
127   foreach ($slice_tags as $slice_tag) {
128     $table->row_start();
129     $table->cell(href(l_slice($slice_tag['slice_id']),$slice_tag['name']));
130     $table->cell($slice_tag['value']);
131     $node_text="all";
132     // sliver tag
133     if ($slice_tag['node_id']) 
134       $node_text=l_node($slice_tag['node_id'],$slice_tag['node_id']);
135     $table->cell($node_text);
136     $table->row_end();
137   }
138   $table->end();
139  }
140
141 // Print footer
142 include 'plc_footer.php';
143
144 ?>