ckp
[plewww.git] / planetlab / tags / tag_set.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
21   // get slice id from GET
22   $slice_id= intval( $_GET['add'] );
23   
24   // get all tag types 
25   $tag_types= $api->GetTagTypes( $tag_type_filter , array( "tag_type_id", "tagname" ) );
26   
27   foreach( $tag_types as $tag_type ) {
28     $all_tags[$tag_type['tag_type_id']]= $tag_type['tagname'];
29   }
30   
31   // get slice's tag types
32   $slice_info= $api->GetSlices( array( $slice_id ), array( "slice_tag_ids" ) );
33   $tag_info= $api->GetSliceTags( $slice_info[0]['slice_tag_ids'], array( "tag_type_id", "tagname" ) );
34   
35   foreach( $tag_info as $info ) {
36     $slice_tag_types[$info['tag_type_id']]= $info['tagname'];
37   }
38
39
40     $tag_types= $all_tags;
41   
42   // start form
43   echo "<form action='tag_action.php' method='post'>\n";
44   echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
45   
46   echo "<select name='tag_type_id'><option value=''>Choose a type to add</option>\n";
47   
48   foreach( $tag_types as $key => $val ) {
49     echo "<option value='". $key ."'>". $val ."</option>\n";
50   
51   }
52   echo "</select>\n";
53   
54   echo "<p><strong>Value: </strong><input type=text name='value'>\n";
55   
56   echo "<p><input type=submit name='add_tag' value='Add Tag'>\n";
57   echo "<input type=hidden name='slice_id' value='$slice_id'>\n";
58   echo "</form>\n";
59   
60 }
61 else {
62   $tag_id= intval( $_GET['id'] );
63   
64   // get tag
65   $slice_tag= $api->GetSliceTags( array( $tag_id ), array( "slice_id", "slice_tag_id", "tag_type_id", "value", "description", "min_role_id" ) );
66   
67   // get type info 
68   $tag_type= $api->GetTagTypes( array( $slice_tag[0]['tag_type_id'] ), array( "tag_type_id", "tagname", "description" ) );
69   
70   // slice info
71   $slice_info= $api->GetSlices( array( $slice_tag[0]['slice_id'] ), array( "name" ) );
72   
73   // start form and put values in to be edited.
74   echo "<form action='tag_action.php' method='post'>\n";
75   echo "<h2>Edit ". $slice_info[0]['name'] ." tag: ". $tag_type[0]['tagname'] ."</h2>\n";
76   
77   echo $slice_tag[0]['description'] ."<br />\n";
78   echo "<strong>Value:</strong> <input type=text name=value value='". $slice_tag[0]['value'] ."'><br /><br />\n";
79   
80   echo "<input type=submit value='Edit Tag' name='edit_tag'>\n";
81   echo "<input type=hidden name='slice_id' value='". $slice_tag[0]['slice_id'] ."'>\n";
82   echo "<input type=hidden name='tag_id' value='". $tag_id ."'>\n";
83   echo "</form>\n";
84   
85 }
86
87 // Print footer
88 include 'plc_footer.php';
89
90 ?>