1d04d10e68928a88ae850fab21637581a0e6c20d
[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   plc_redirect ("settings.php");
40 }
41
42 // tag type adds
43 if( $_POST['add_type'] ) {
44   $setting_type = array ('category' => $_POST['category'],
45                          'name' => $_POST['name'],
46                          'min_role_id' => intval( $_POST['min_role_id'] ),
47                          'description' => $_POST['description']);
48   // add it!!
49   $api->AddTagType( $setting_type );
50
51   // xxx check the destination page
52   plc_redirect ("settings.php");
53 }
54   
55
56 // tag deletion
57 if( $_GET['rem_id'] ) {
58   // get the id of the tag to remove from GET
59   $setting_id= intval( $_GET['rem_id'] );
60
61   // get interface_id 
62   $setting= $api->GetInterfaceTags( array( $setting_id ), array( "interface_id" ) );
63   $interface_id= $setting[0]['interface_id'];
64   
65   // delete the tag
66   $api->DeleteInterfaceTag( $setting_id );
67
68   plc_redirect (l_interface($interface_id));
69 }
70
71 // tag adds
72 if( $_POST['add_setting'] ) {
73   // get the interface_id, tag_type_id, and value from POST
74   $interface_id= intval( $_POST['interface_id'] );
75   $interface_tag_type_id= intval( $_POST['interface_tag_type_id'] );
76   $value= $_POST['value'];
77
78   // add it!
79   $api->AddInterfaceTag( $interface_id, $interface_tag_type_id, $value );
80
81   plc_redirect (l_interface($interface_id));
82 }
83
84 // tag updates
85 if( $_POST['edit_setting'] ) {
86   // get the id of the setting to update and the value from POST
87   $setting_id= intval( $_POST['setting_id'] );
88   $value= $_POST['value'];
89   $interface_id= $_POST['interface_id'];
90
91   // update it!
92   $api->UpdateInterfaceTag($setting_id, $value );
93
94   plc_redirect (l_interface($interface_id));
95 }
96
97 // Settings -------------------------------------------------
98
99 // TAG TYPES ---------------------------------------------------
100   
101 // delete tag types
102 if( $_GET['del_type'] ) {
103   // get vars
104   $type_id= intval( $_GET['del_type'] );
105
106   // delete it!
107   $api->DeleteTagType( $type_id );
108   
109   // xxx check the destination page
110   plc_redirect ("settings.php" );
111 }
112   
113 /*
114 // Print footer
115 include 'plc_footer.php';
116 */
117
118 ?>