record origin url
[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     plc_redirect( l_slice($slice_id));
58     
59   }
60   
61 }
62
63 // if no id is set redirect back to slice index
64 if( !$_POST['id'] && !$_GET['id'] ) {
65   plc_redirect( l_slices());
66  }
67
68 // Print header
69 require_once 'plc_drupal.php';
70 drupal_set_title('Slice Renewal');
71 include 'plc_header.php';
72
73
74
75
76 // get id
77 if( $_GET['id'] )
78   $slice_id= intval( $_GET['id'] );
79 if( $_POST['id'] )
80   $slice_id= intval( $_POST['id'] );
81
82 // get slice info
83 $slice_info= $api->GetSlices( array( $slice_id ), array( "expires", "name", "site_id", "description", "url" ) );
84
85 echo "<h2>Slice ". $slice_info[0]['name'] ." Renewal</h2>\n";
86
87 // get site info
88 if( !empty( $slice_info[0]['site_id'] ) ) {
89   // get sliver/slice site info
90   $site_info= $api->GetSites( array( $slice_info[0]['site_id'] ), array( "max_slivers", "max_slices" ) );
91   
92   // do not allow renew if max_slices are 0
93   if( $site_info[0]['max_slices'] <= 0 ) {
94     $support= '';
95     $site_id= $slice_info[0]['site_id'];
96     
97     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>";
98
99   }
100   // else start renewal form
101   else {
102     // Calculate possible extension lengths
103     $renewal_lengths = array();
104     foreach ( array( 1 => "One more week", 2 => "Two more weeks", 4 => "One more month" ) as $weeks => $text ) {
105       if ( ( $slice_info[0]['expires'] + ( $weeks * $week ) ) < $max_expiration ) {
106         $renewal_lengths[$weeks]= "$text (". gmstrftime( "%A %b-%d-%y %T %Z", $slice_info[0]['expires'] + ( $weeks * $week ) ) .")";
107       }
108     }
109     
110         
111     if ( empty( $renewal_lengths ) ) {
112       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";
113     }
114     else {
115       // clean vars
116       $expiration_date = gmstrftime( "%A %b-%d-%y %T %Z", $slice_info[0]['expires'] );
117       
118       // display form
119       echo "<form action='/db/slices/renew_slice.php' method='post'>\n";
120       echo "<input type=hidden name='id' value='$slice_id'><input type=hidden name='expires' value='". $slice_info[0]['expires'] ."'>\n";
121     
122       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";
123       
124       echo "<p><b>NOTE:</b> Slices cannot be renewed beyond $max_renewal_length weeks of today ($max_expiration_date).</p>\n";
125       
126       echo "<table cellpadding=2><tbody>\n";
127       
128       echo "<tr><th>Name:</th><td colspan=2>". $slice_info[0]['name'] ."</td></tr>\n";
129       
130       if( $error['url'] ) 
131         $url_style= " style='border: 1px solid red;'";
132       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";
133       
134       if( $error['description'] ) 
135         $desc_style= " style='border: 1px solid red;'";
136       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";
137       
138       echo "<tr><th>Expiration Date: </th><td colspan=2>$expiration_date</td></tr>\n";
139       
140       echo "<tr><th>Renewal Length: </th><td colspan=2><select name='expire_len'>";
141       
142       // create drop down of lengths to choose
143       foreach ($renewal_lengths as $weeks => $text) {
144         echo "<option value='$weeks'";
145         if( $weeks == $expire_len )
146           echo " selected";
147         echo ">$text</option>\n";
148       }
149       
150       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";
151     
152     }
153     
154   }
155
156 }
157 else 
158   echo "No data for this slice ID.  Go <a href='index.php'>back</a> to slices.\n";
159   
160
161
162
163
164
165
166
167
168 // Print footer
169 include 'plc_footer.php';
170
171 ?>