initial import from onelab svn codebase
[plewww.git] / planetlab / slices / renew_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 // Constants
20 $week= 7 * 24 * 60 * 60; // seconds
21 $max_renewal_length= 8; // weeks from today
22 $max_expiration= mktime() + ($max_renewal_length * $week); // seconds since epoch
23 $max_expiration_date= gmstrftime("%A %b-%d-%y %T %Z", $max_expiration);
24
25 // if submitted validate input
26 if( $_POST['submitted'] ) {
27   // get post vars
28   $expire_len= $_POST['expire_len'];
29   $expires= $_POST['expires'];
30   $slice_id= intval( $_POST['id'] );
31   
32   // create empty error array
33   $error= array(  );
34   
35   // check input
36   
37   $url= $_POST['url'];
38   if( $url == '' || empty( $url ) )
39     $error['url']= "Provide a link to a project website.";
40     
41   $description= htmlspecialchars( $_POST['description'] );
42   if ( $description == '' || empty( $description ) )
43     $error['description']= "Provide a short description of the slice.";
44     
45   // if no errors update slice info 
46   if( empty( $error ) ) {
47     // set new expiration
48     
49     $expires+= ( $expire_len * $week );
50     
51     // make slice field array
52     $slice_fields= array( "url" => $url, "description" => $description, "expires" => $expires );
53     
54     // Update it!
55     $api->UpdateSlice( $slice_id, $slice_fields );
56     
57     header( "location: index.php?id=$slice_id" );
58     exit();
59     
60   }
61   
62 }
63
64 // if no id is set redirect back to slice index
65 if( !$_POST['id'] && !$_GET['id'] ) {
66   header( "location: index.php" );
67   exit();
68  }
69
70 // Print header
71 require_once 'plc_drupal.php';
72 drupal_set_title('Slice Renewal');
73 include 'plc_header.php';
74
75
76
77
78 // get id
79 if( $_GET['id'] )
80   $slice_id= intval( $_GET['id'] );
81 if( $_POST['id'] )
82   $slice_id= intval( $_POST['id'] );
83
84 // get slice info
85 $slice_info= $api->GetSlices( array( $slice_id ), array( "expires", "name", "site_id", "description", "url" ) );
86
87 echo "<h2>Slice ". $slice_info[0]['name'] ." Renewal</h2>\n";
88
89 // get site info
90 if( !empty( $slice_info[0]['site_id'] ) ) {
91   // get sliver/slice site info
92   $site_info= $api->GetSites( array( $slice_info[0]['site_id'] ), array( "max_slivers", "max_slices" ) );
93   
94   // do not allow renew if max_slices are 0
95   if( $site_info[0]['max_slices'] <= 0 ) {
96     $support= '';
97     $site_id= $slice_info[0]['site_id'];
98     
99     echo "<p>Slice creation and renewal have been temporarily disabled for your site. This may have occurred because your site's nodes have been down or unreachable for several weeks, and multiple attempts to contact your site's PI(s) and Technical Contact(s) have all failed. If so, contact your site's PI(s) and Technical Contact(s) and ask them to bring up your site's nodes. If you believe that your site's nodes are up and reachable. Visit your site's <a href='/db/sites/index.php?id=$site_id'>Site Details</a> page to find out more about your site's nodes, and how to contact your site's PI(s) and Technical Contact(s).</p>";
100
101   }
102   // else start renewal form
103   else {
104     // Calculate possible extension lengths
105     $renewal_lengths = array();
106     foreach ( array( 1 => "One more week", 2 => "Two more weeks", 4 => "One more month" ) as $weeks => $text ) {
107       if ( ( $slice_info[0]['expires'] + ( $weeks * $week ) ) < $max_expiration ) {
108         $renewal_lengths[$weeks]= "$text (". gmstrftime( "%A %b-%d-%y %T %Z", $slice_info[0]['expires'] + ( $weeks * $week ) ) .")";
109       }
110     }
111     
112         
113     if ( empty( $renewal_lengths ) ) {
114       echo "<font color='red'>Slice cannot be renewed any further into the future, try again closer to expiration date.</font> Go <a href='index.php?id=$slice_id'>back</a> to ". $slice_info[0]['name'] .".\n";
115     }
116     else {
117       // clean vars
118       $expiration_date = gmstrftime( "%A %b-%d-%y %T %Z", $slice_info[0]['expires'] );
119       
120       // display form
121       echo "<form action='/db/slices/renew_slice.php' method='post'>\n";
122       echo "<input type=hidden name='id' value='$slice_id'><input type=hidden name='expires' value='". $slice_info[0]['expires'] ."'>\n";
123     
124       echo "<p>You must provide a short description as well as a link to a project website before renewing it. Do <b>not</b> provide bogus information; if a complaint is lodged against your slice and PlanetLab Operations is unable to determine what the normal behavior of your slice is, your slice may be deleted to resolve the complaint.</p>\n";
125       
126       echo "<p><b>NOTE:</b> Slices cannot be renewed beyond $max_renewal_length weeks of today ($max_expiration_date).</p>\n";
127       
128       echo "<table cellpadding=2><tbody>\n";
129       
130       echo "<tr><th>Name:</th><td colspan=2>". $slice_info[0]['name'] ."</td></tr>\n";
131       
132       if( $error['url'] ) 
133         $url_style= " style='border: 1px solid red;'";
134       echo "<tr><th$url_style>URL: </th><td$url_style><input size=50 name='url' value='". $slice_info[0]['url'] ."' /></td><td$url_style><font color=red>". $error['url'] ."</font></td></tr>\n";
135       
136       if( $error['description'] ) 
137         $desc_style= " style='border: 1px solid red;'";
138       echo "<tr><th$desc_style>Description: </th><td$desc_style><textarea name='description' rows=5 cols=40>". $slice_info[0]['description'] ."</textarea></td><td$desc_style><font color=red>". $error['description'] ."</font></td></tr>\n";
139       
140       echo "<tr><th>Expiration Date: </th><td colspan=2>$expiration_date</td></tr>\n";
141       
142       echo "<tr><th>Renewal Length: </th><td colspan=2><select name='expire_len'>";
143       
144       // create drop down of lengths to choose
145       foreach ($renewal_lengths as $weeks => $text) {
146         echo "<option value='$weeks'";
147         if( $weeks == $expire_len )
148           echo " selected";
149         echo ">$text</option>\n";
150       }
151       
152       echo "</select></td></tr>\n<tr><td colspan=3 align=center><input type=submit value='Renew Slice' name='submitted'></td></tr>\n</tbody></table>\n";
153     
154     }
155     
156   }
157
158 }
159 else 
160   echo "No data for this slice ID.  Go <a href='index.php'>back</a> to slices.\n";
161   
162
163
164
165
166
167
168
169
170 // Print footer
171 include 'plc_footer.php';
172
173 ?>