(*) slices list has links towards the slice page with the details area closed and...
[plewww.git] / planetlab / tags / tags.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="Tag Types";
28 $tabs=array();
29 $tabs []= tab_tags();
30 $tabs []= tab_nodes_local();
31 $tabs []= tab_slices();
32
33 // -------------------- 
34 drupal_set_title($title);
35 plekit_linetabs($tabs);
36
37 $tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "min_role_id" );
38
39 $tag_type_filter=NULL;
40 if ($pattern) 
41   $tag_type_filter['category']=$pattern;
42
43 // get types
44 $tag_types= $api->GetTagTypes($tag_type_filter, $tag_type_columns);
45   
46 $headers=array();
47 $notes=array();
48 // delete button
49 $headers['Name']="string";
50 $headers['Description']="string";
51 $headers['Category']="string";
52 $headers['MR']="string";
53 $notes []= "MR: Min Role, needed to manage this tag";
54
55 // xxx ref count would be helpful but seem too expensive to compute at this stage 
56 // the individual tag page show those ref counts per type
57
58 $headers["Id"]="int";
59 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
60
61 $form=new PlekitForm(l_actions(),NULL);
62 $form->start();
63
64 $table = new PlekitTable("tags",$headers,0,array('notes'=>$notes));
65 $table->start();
66
67 $roles_hash=plc_role_global_hash($api);
68
69 $description_width=40;
70
71 foreach( $tag_types as $tag_type ) {
72   $role_name=$roles_hash[$tag_type['min_role_id']];
73
74   $table->row_start();
75   $tag_type_id=$tag_type['tag_type_id'];
76   $table->cell(href(l_tag($tag_type_id),$tag_type['tagname']));
77   $table->cell(wordwrap($tag_type['description'],$description_width,"<br/>"));
78   $table->cell($tag_type['category']);
79   $table->cell($role_name);
80   // ref count
81   //  if (plc_is_admin())     $table->cell('xxx');
82   $table->cell($tag_type_id);
83   if (plc_is_admin()) 
84     $table->cell ($form->checkbox_html('tag_type_ids[]',$tag_type_id));
85   $table->row_end();
86 }
87
88 if (plc_is_admin()) {
89   $table->tfoot_start();
90
91   $table->row_start();
92   $table->cell($form->submit_html ("delete-tag-types","Remove tags"),
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 role selector
100   $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids));
101   function selector_argument ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); }
102   $selectors=array_map("selector_argument",$relevant_roles);
103   $role_input=$form->select_html("min_role_id",$selectors,array('label'=>"Role"));
104
105   $table->cell($form->text_html('tagname',''));
106   $table->cell($form->textarea_html('description','',$description_width,2));
107   $table->cell($form->text_html('category',''));
108   $table->cell($role_input);
109   $table->cell($form->submit_html("add-tag-type","Add"),2);
110   $table->row_end();
111  }
112
113 $table->end();
114 $form->end();
115
116 //plekit_linetabs ($tabs,"bottom");
117
118 // Print footer
119 include 'plc_footer.php';
120
121 ?>