more inline updates & cleaned up tags
[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 'plc_minitabs.php';
19 require_once 'plc_tables.php';
20 require_once 'plc_forms.php';
21
22 // -------------------- 
23 // recognized URL arguments
24 $pattern=$_GET['pattern'];
25
26 // --- decoration
27 $title="Tag Types";
28 $tabs=array();
29 $tabs['Tag Types']=array('url'=>l_tags(),'bubble'=>"Create a new tag type");
30 $tabs['All Nodes']=array('url'=>l_nodes(),'bubble'=>"Nodes from all peers");
31 $tabs['Local Nodes']=array('url'=>l_nodes(),'values'=>array('peerscope'=>'local'),'bubble'=>"All local nodes");
32 //$tabs['Interfaces']=l_interfaces();
33 $tabs['All Slices']=array('url'=>l_slices(),'bubble'=>"Slices from all peers");
34
35 // -------------------- 
36 drupal_set_title($title);
37 plc_tabs($tabs);
38
39 $tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "min_role_id" );
40
41 $tag_type_filter=NULL;
42 if ($pattern) 
43   $tag_type_filter['category']=$pattern;
44
45 // get types
46 $tag_types= $api->GetTagTypes($tag_type_filter, $tag_type_columns);
47   
48 $headers=array();
49 // delete button
50 $headers['Name']="string";
51 $headers['Description']="string";
52 $headers['Category']="string";
53 $headers['Min role']="string";
54 $headers["Id"]="int";
55 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
56
57 $form=new PlcForm(l_actions(),NULL);
58 $form->start();
59
60 $table = new PlcTable("tags",$headers,0);
61 $table->start();
62
63 $roles_hash=plc_role_global_hash($api);
64
65 $description_width=40;
66
67 foreach( $tag_types as $tag_type ) {
68   $role_name=$roles_hash[$tag_type['min_role_id']];
69
70   $table->row_start();
71   $tag_type_id=$tag_type['tag_type_id'];
72   $table->cell(href(l_tag($tag_type_id),$tag_type['tagname']));
73   $table->cell(wordwrap($tag_type['description'],$description_width,"<br/>"));
74   $table->cell($tag_type['category']);
75   $table->cell($role_name);
76   $table->cell($tag_type_id);
77   if (plc_is_admin()) 
78     $table->cell ($form->checkbox_html('tag_type_ids[]',$tag_type_id));
79   $table->row_end();
80 }
81
82 if (plc_is_admin()) {
83   $table->tfoot_start();
84
85   $table->row_start();
86   $table->cell($form->submit_html ("delete-tag-types","Remove tags"),
87                $table->columns(),"right");
88   $table->row_end();
89
90   // an inline area to add a tag type
91   $table->row_start();
92   
93   // build the role selector
94   $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids));
95   function selector_argument ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); }
96   $selectors=array_map("selector_argument",$relevant_roles);
97   $role_input=$form->select_html("min_role_id",$selectors,"Role");
98
99   $table->cell($form->text_html('tagname','',''));
100   $table->cell($form->textarea_html('description','',$description_width,2));
101   $table->cell($form->text_html('category','',''));
102   $table->cell($role_input);
103   $table->cell($form->submit_html("add-tag-type","Add Type"),2);
104   $table->row_end();
105  }
106
107 $table->end();
108 $form->end();
109
110 // Print footer
111 include 'plc_footer.php';
112
113 ?>