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