initial import from onelab svn codebase
[plewww.git] / planetlab / slices / update_slice.php
1 <?php
2
3 // Require login
4 require_once 'plc_login.php';
5
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api;
9
10 // Common functions
11 require_once 'plc_functions.php';
12 require_once 'plc_sorts.php';
13   
14 // find person roles
15 $_person= $plc->person;
16 $_roles= $_person['role_ids'];
17
18
19 if( !empty( $_GET['id'] ) ) {
20   $slice_id= $_GET['id'];
21   // Fetch slice information
22   $slices= $api->GetSlices( array( intval( $slice_id ) ) );
23   if( !empty( $slices ) ) {
24     $slice= $slices[0];
25   }
26 }
27
28 // Invalid slice name
29 if( !isset( $slice ) ) {
30   Header( "Location: index.php" );
31   exit();
32 }
33
34 // Defaults
35 $url_error = "";
36 $description_error = "";
37
38 if( isset( $_POST['submitted'] ) ) {
39   if( !empty($_POST['url'] ) )
40     $slice['url']= $_POST['url'];
41   else
42     $url_error= "Provide a link to a project website.";
43
44   if( !empty($_POST['desc'] ) )
45     $slice['description'] = $_POST['desc'];
46   else
47     $description_error= "Provide a short description of the slice.";
48
49   if( empty( $url_error ) && empty( $description_error ) ) {
50     // Update the slice URL and description
51     $fields= array( "description"=>$slice['description'], "url"=>$slice['url'] );
52     $api->UpdateSlice( intval( $slice_id ), $fields );
53     Header( "Location: index.php?id=$slice_id" );
54     exit();
55   }
56 }
57
58 // Print header
59 require_once 'plc_drupal.php';
60 drupal_set_title('Slices');
61 include 'plc_header.php';
62
63 $slice_name= $slice['name'];
64
65 print "<h2>Update Slice ". $slice['name'] ."</h2>";
66
67 //echo "<pre>"; print_r( $slice ); echo "</pre>";
68 $url =  $slice['url'] ;
69 $description =  $slice['description'] ;
70
71 echo <<<EOF
72
73 <p>You must provide a short description as well as a
74 link to a project website. Do <b>not</b> provide
75 bogus information; if a complaint is lodged against your slice and
76 PlanetLab Operations is unable to determine what the normal behavior
77 of your slice is, your slice may be deleted to resolve the
78 complaint.</p>
79
80 <form method="post" action="update_slice.php?id=$slice_id">
81
82 <table>
83   <tbody>
84     <tr>
85       <th>Name:</th>
86       <td>$slice_name</td>
87       <td></td>
88     </tr>
89     <tr>
90       <th>URL:</th>
91       <td><input size="50" name="url" value="$url" /></td>
92       <td><font color="red"><strong>$url_error</strong></font></td>
93     </tr>
94     <tr>
95       <th>Description:</th>
96       <td><textarea name="desc" rows="5" cols="40">$description</textarea></td>
97       <td><font color="red"><strong>$description_error</strong></font></td>
98     </tr>
99   </tbody>
100 </table>
101
102 <input type="submit" name="submitted" value="Update" />
103
104 </form>
105
106 EOF;
107
108 // Print footer
109 include 'plc_footer.php';
110
111 ?>