(*) slices list has links towards the slice page with the details area closed and...
[plewww.git] / planetlab / tags / nodegroups.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 'table.php';
20 require_once 'form.php';
21
22 // -------------------- 
23 // recognized URL arguments
24 $pattern=$_GET['pattern'];
25
26 // --- decoration
27 $title="Nodegroups";
28 $tabs=array();
29 $tabs []= tab_tags();
30
31 // -------------------- 
32 $node_filter=array();
33
34
35 // fetch objs
36 $nodegroup_columns=array("nodegroup_id","groupname","tagname","value","node_ids","tag_type_id");
37
38 // server-side filtering - set pattern in $_GET for filtering on hostname
39 if ($pattern) {
40   $nodegroup_filter['groupname']=$pattern;
41   $title .= " matching " . $pattern;
42  } else {
43   $nodegroup_filter['groupname']="*";
44  }
45
46 // go
47 $nodegroups=$api->GetNodeGroups($nodegroup_filter,$nodegroup_columns);
48
49 // --------------------
50 drupal_set_title($title);
51
52 plekit_linetabs($tabs);
53
54 if ( ! $nodegroups ) {
55   drupal_set_message ('No node group found');
56   return;
57  }
58   
59 $headers=array();
60 $notes=array();
61
62 $headers['group name']='string';
63 $headers['tag name']='string';
64 $headers['tag value']='string';
65 $headers['# N']='int';
66 $notes []= '# N = number of nodes in the group';
67
68 $headers["Id"]="int";
69 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
70
71 $form=new PlekitForm(l_actions(),NULL);
72 $form->start();
73 # initial sort on groupname
74 $table=new PlekitTable("nodegroups",$headers,0,array('notes'=>$notes));
75 $table->start();
76
77 foreach ($nodegroups as $nodegroup) {
78   $table->row_start();
79   $nodegroup_id=$nodegroup['nodegroup_id'];
80   $table->cell (href(l_nodegroup($nodegroup_id),$nodegroup['groupname']));
81   // yes, a nodegroup is not a tag, but knows enough for this to work
82   $table->cell (l_tag_obj($nodegroup));
83   $table->cell ($nodegroup['value']);
84   $table->cell (count($nodegroup['node_ids']));
85   $table->cell ($nodegroup_id);
86   $table->cell ($form->checkbox_html('nodegroup_ids[]',$nodegroup_id));
87   $table->row_end();
88 }
89
90 $table->tfoot_start();
91
92 $table->row_start();
93 $table->cell($form->submit_html ("delete-nodegroups","Remove groups"),
94              array('hfill'=>true,'align'=>'right'));
95 $table->row_end();
96
97 // an inline area to add a tag type
98 $table->row_start();
99
100 // build the tagname selector
101 $relevant_tags = $api->GetTagTypes( array("category"=>'*node*'));
102 function selector_argument ($tt) { return array('display'=>$tt['tagname'],"value"=>$tt['tag_type_id']); }
103 $selectors=array_map("selector_argument",$relevant_tags);
104 $tagname_input=$form->select_html("tag_type_id",$selectors,array('label'=>"Tag Name"));
105
106
107 $table->cell($form->text_html('groupname',''));
108 $table->cell($tagname_input);
109 $table->cell($form->text_html('value',''));
110 $table->cell($form->submit_html("add-nodegroup","Add"),3);
111 $table->row_end();
112
113 $table->end();
114 $form->end();
115
116 //plekit_linetabs ($tabs,"bottom");
117
118 // Print footer
119 include 'plc_footer.php';
120
121 ?>