brute-force changed access to $_GET['key'] to use get_array instead
[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_array($_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  }
57   
58 $headers=array();
59 $notes=array();
60
61 $headers['group name']='string';
62 $headers['tag name']='string';
63 $headers['tag value']='string';
64 $headers['# N']='int';
65 $notes []= '# N = number of nodes in the group';
66
67 $headers["Id"]="int";
68 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
69
70 $form=new PlekitForm(l_actions(),NULL);
71 $form->start();
72 # initial sort on groupname
73 $table=new PlekitTable("nodegroups",$headers,0,array('notes'=>$notes));
74 $table->start();
75
76 foreach ($nodegroups as $nodegroup) {
77   $table->row_start();
78   $nodegroup_id=$nodegroup['nodegroup_id'];
79   $table->cell (href(l_nodegroup($nodegroup_id),$nodegroup['groupname']));
80   // yes, a nodegroup is not a tag, but knows enough for this to work
81   $table->cell (l_tag_obj($nodegroup));
82   $table->cell ($nodegroup['value']);
83   $table->cell (count($nodegroup['node_ids']));
84   $table->cell ($nodegroup_id);
85   $table->cell ($form->checkbox_html('nodegroup_ids[]',$nodegroup_id));
86   $table->row_end();
87 }
88
89 $table->tfoot_start();
90
91 $table->row_start();
92 $table->cell($form->submit_html ("delete-nodegroups","Remove groups"),
93              array('hfill'=>true,'align'=>'right'));
94 $table->row_end();
95
96 // an inline area to add a tag type
97 $table->row_start();
98
99 // build the tagname selector
100 $relevant_tags = $api->GetTagTypes( array("category"=>'*node*'));
101 function selector_argument ($tt) { return array('display'=>$tt['tagname'],"value"=>$tt['tag_type_id']); }
102 $selectors=array_map("selector_argument",$relevant_tags);
103 $tagname_input=$form->select_html("tag_type_id",$selectors,array('label'=>"Tag Name"));
104
105
106 $table->cell($form->text_html('groupname',''));
107 $table->cell($tagname_input);
108 $table->cell($form->text_html('value',''));
109 $table->cell($form->submit_html("add-nodegroup","Add"),3);
110 $table->row_end();
111
112 $table->end();
113 $form->end();
114
115 //plekit_linetabs ($tabs,"bottom");
116
117 // Print footer
118 include 'plc_footer.php';
119
120 ?>