more inline updates & cleaned up tags
[plewww.git] / planetlab / slices / slice_add.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 //print_r( $_person );
19
20 // if not a PI or admin then redirect to slice index
21 if( !in_array( '10', $_roles ) && !in_array( '20', $_roles ) )
22   header( "index.php" );
23
24 if( !$_POST['name'] ) {
25   // get default site base
26   $site_info= $api->GetSites( array( $_person['site_ids'][0] ), array( "login_base" ) );
27   $base= $site_info[0]['login_base'] ."_";
28 }
29
30 // add it
31 if( $_POST['add'] ) {
32   // get post vars
33   $url= $_POST['url'];
34   $instantiation= $_POST['instantiation'];
35   $name= $_POST['name'];
36   $description= $_POST['description'];
37
38   // validate input
39   if( $name == $base )
40     $error['name']= "<font color=red>You must enter a name for your slice.</font>";
41   else {
42     $slice_name= $name;
43     // make sure slice name doesnt exist
44     $slice_info= $api->GetSlices( array( $slice_name ), array( "slice_id" ) );
45     
46     if( !empty( $slice_info ) ) {
47       $error['name']= "<font color=red>Slice name already in use.  Please choose another.</font>";
48       $name= "";
49     }
50     
51   }
52   
53   if( $url == "http://" || "" )
54     $error['url']= "<font color=red>You must enter a URL for your slice's info.</font>";
55       
56   if( $description == "" )
57     $error['description']= "<font color=red>Your must enter a description for you slice.</font>";
58   
59   // if no errors then add
60   if( !$error ) {
61     $fields= array( "url" => $url, "instantiation" => $instantiation, "name" => $slice_name, "description" => $description );
62     echo "added: <pre>"; print_r( $fields ); echo "</pre>\n";
63     // add it!
64     $slice_new_id= $api->AddSlice( $fields );
65
66     if( $slice_new_id ) {
67       plc_redirect( "index.php?id=$slice_new_id" );
68       exit();
69     } else {
70       $error['api']= $api->error();
71     }
72   }
73
74 }
75
76 // Print header
77 require_once 'plc_drupal.php';
78 drupal_set_title('Slices');
79 include 'plc_header.php';
80
81
82 if( !$url )  
83   $url= "http://";
84
85 // check for errors and set error styles
86 if( $error['name'] )
87   $name_error= " class='plc-warning'";
88   
89 if( $error['url'] )
90   $url_error= " class='plc-warning'";
91   
92 if( $error['description'] )
93   $desc_error= " class='plc-warning'";
94
95
96 // add javaScript code
97 echo "<script type='text/javascript'>
98       function update(str1) {
99         var temp= new Array()
100         temp= str1.split('->');
101         var c= ( temp[1] + '_' )
102         document.getElementById('textbox').value = c;
103       }
104 </script>\n";
105
106
107 // start form
108 echo "<form action='slice_add.php' method=post>\n";
109
110 if( $error['api'] )
111   echo "<font class='plc-warning'>". $error['api'] ."</font>\n";
112
113 echo "<h2>Create Slice</h2>\n";
114
115 echo "<p>You must provide a short description of the new slice as well as a link to a project website before creating it. Do <strong>not</strong> 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.\n";
116 echo "<p>There are three possible \"instantiation\" states for a slice. <strong>PLC</strong> creates a slice with default settings. <strong>Delegated</strong> creates a ticket to use on each node. <strong>None</strong> allows you to reserve a slice name; you may instantiate the slice later.\n";
117 echo "<p><strong>NOTE</strong>: All PlanetLab users are <strong>strongly</strong> encouraged to join the PlanetLab <a href='https://lists.planet-lab.org/mailman/listinfo/users'>Users</a> mailing list. Most questions about running software on PlanetLab can be answered by posting to this list. Site administrators often use this list to post announcements about service outages. New software releases and available services are announced here as well.\n";
118
119 echo "<p><table><tbody>\n";
120
121 // displays a site select list for admins and multi-site users
122 if( count( $_person['site_ids'] ) > 1 || in_array( 10, $_roles ) ) {
123   // get sites depending on role and sites associated.
124   if( in_array( 10, $_roles ) )
125     $site_info= $api->GetSites( NULL, array( "name", "site_id", "login_base" ) );
126   elseif( count( $_person['site_ids'] ) > 1 )
127     $site_info= $api->GetSites( $_person['site_ids'], array( "name", "site_id", "login_base" ) );
128
129   echo "<tr><th>Site: </th><td><select onchange='update(this[selectedIndex].text)' name='site_id'>\n";
130
131   sort_sites( $site_info );
132   foreach( $site_info as $site ) {
133     echo "<option value=". $site['site_id'];
134     if( $site['site_id'] == $_person['site_ids'][0] )
135       echo " selected";
136     echo ">". $site['name'] ."->". $site['login_base'] ."</option>\n";
137   }
138
139   echo "</select></td><td></td></tr>\n";
140
141 }
142
143 echo "<tr><th$name_error>Name: </th><td><input type=text id='textbox' name='name' size=40 value='";
144 if( $name ) 
145   echo $name;
146 else
147   echo $base;
148 echo "'></td><td>". $error['name'] ."</td></tr>\n";
149 echo "<tr><th$url_error>URL: </th><td> <input type=text name='url' size=50 value='$url'></td><td>". $error['url'] ."</td></tr>\n";
150 echo "<tr><th$desc_error>Description: </th><td> <textarea name='description' rows=5 cols=45>$description</textarea></td><td>". $error['description'] ."</td></tr>\n";
151 echo "<tr><th>Instantiation: </th><td> <select name='instantiation'>\n";
152 echo "<option value='plc-instantiated'"; if( $instantiation == 'plc-instantiated' ) echo " selected"; echo ">PLC</option>\n";
153 echo "<option value='delegated'"; if( $instantiation == 'delegated' ) echo " selected"; echo ">Delegated</option>\n";
154 echo "<option value='not-instantiated'"; if( $instantiation == 'not-instantiated' ) echo " selected"; echo ">None</option>\n";
155 echo "</select></td><td></td></tr>\n";
156
157 echo "</tbody></table>\n";
158
159 echo "<p><input type=submit name='add' value='Add Slice'>\n";
160
161 echo "</form>\n";
162
163
164
165
166 // Print footer
167 include 'plc_footer.php';
168
169 ?>