8576a96c64742e5707ecbd18685c66bfce0f89e4
[plewww.git] / planetlab / nodes / setting_action.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 // Common functions
13 require_once 'plc_functions.php';
14 require_once 'plc_sorts.php';
15
16 // find person roles
17 $_person= $plc->person;
18 $_roles= $_person['role_ids'];
19
20 //plc_debug('GET',$_GET);
21 //plc_debug('POST',$_POST);
22
23 // tag type updates
24 if( $_POST['edit_type'] ) {
25   $setting_type_id= intval( $_POST['interface_tag_type_id'] );
26   $setting_type = array ('category' => $_POST['category'],
27                          'name' => $_POST['name'],
28                          'min_role_id' => intval( $_POST['min_role_id'] ),
29                          'description' => $_POST['description']);
30   
31   // Update it!
32   $api->UpdateTagType( $setting_type_id, $setting_type );
33   $api_error=$api->error();
34   if (!empty($api_error)) {
35     print "<div class='plc-error'>" . $api_error . "</div>";
36   }
37   
38   // xxx check the destination page
39   header( "location: settings.php" );
40   exit();
41 }
42
43 // tag type adds
44 if( $_POST['add_type'] ) {
45   $setting_type = array ('category' => $_POST['category'],
46                          'name' => $_POST['name'],
47                          'min_role_id' => intval( $_POST['min_role_id'] ),
48                          'description' => $_POST['description']);
49   // add it!!
50   $api->AddTagType( $setting_type );
51
52   // xxx check the destination page
53   header( "location: settings.php" );
54   exit();
55 }
56   
57
58 // tag deletion
59 if( $_GET['rem_id'] ) {
60   // get the id of the tag to remove from GET
61   $setting_id= intval( $_GET['rem_id'] );
62
63   // get interface_id 
64   $setting= $api->GetInterfaceTags( array( $setting_id ), array( "interface_id" ) );
65   $interface_id= $setting[0]['interface_id'];
66   
67   // delete the tag
68   $api->DeleteInterfaceTag( $setting_id );
69
70   header( "location: interfaces.php?id=$interface_id" );
71   exit();
72 }
73
74 // tag adds
75 if( $_POST['add_setting'] ) {
76   // get the interface_id, tag_type_id, and value from POST
77   $interface_id= intval( $_POST['interface_id'] );
78   $interface_tag_type_id= intval( $_POST['interface_tag_type_id'] );
79   $value= $_POST['value'];
80
81   // add it!
82   $api->AddInterfaceTag( $interface_id, $interface_tag_type_id, $value );
83
84   header( "location: interfaces.php?id=$interface_id" );
85   exit();
86 }
87
88 // tag updates
89 if( $_POST['edit_setting'] ) {
90   // get the id of the setting to update and the value from POST
91   $setting_id= intval( $_POST['setting_id'] );
92   $value= $_POST['value'];
93   $interface_id= $_POST['interface_id'];
94
95   // update it!
96   $api->UpdateInterfaceTag($setting_id, $value );
97
98   header( "location: interfaces.php?id=$interface_id" );
99   exit();
100 }
101
102 // Settings -------------------------------------------------
103
104 // TAG TYPES ---------------------------------------------------
105   
106 // delete tag types
107 if( $_GET['del_type'] ) {
108   // get vars
109   $type_id= intval( $_GET['del_type'] );
110
111   // delete it!
112   $api->DeleteTagType( $type_id );
113   
114   // xxx check the destination page
115   header( "location: settings.php" );
116   exit();
117 }
118   
119 /*
120 // Print footer
121 include 'plc_footer.php';
122 */
123
124 ?>