4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_functions.php';
12 require_once 'details.php';
13 require_once 'table.php';
14 require_once 'toggle.php';
16 //plc_debug('POST',$_POST);
18 // if not a PI or admin then redirect to slice index
19 $has_privileges = plc_is_admin() || plc_is_pi();
20 if ( ! $has_privileges ) {
21 drupal_set_error("Insufficient privilege to add a slice");
22 header( "index.php" );
26 // find out which site the slice should be added to
27 // without site_id set in GET, we use the first site that this user is in
28 if (isset($_GET['site_id'])) {
29 $site_id=intval($_GET['site_id']);
30 } else if (isset ($_POST['site_id'])) {
31 $site_id=intval($_POST['site_id']);
33 $site_id=plc_my_site_id();
36 //////////////////// action
37 if ( $_POST['add-slice'] ) {
40 $instantiation= $_POST['instantiation'];
41 $name= $_POST['name'];
42 $description= $_POST['description'];
43 $person_ids = $_POST['person_ids'];
47 $sites=$api->GetSites(array('site_id'=>$site_id));
49 drupal_set_error("Cannot find site_id $site_id");
53 $base=$site['login_base'] . '_';
56 if( $name == $base ) {
57 drupal_set_error("You must enter a name for your slice");
59 } else if (strpos($name,$base) != 0) {
60 drupal_set_error("Slice name $name should begin with $base");
63 // make sure slice name doesnt exist
64 $slices = $api->GetSlices( array( $name ), array( "slice_id" ) );
65 if ( count($slices) != 0) {
66 drupal_set_error("Slice name $name already in use, please choose another");
71 if ( ($url == "http://") || ( $url=="" ) ) {
72 drupal_set_error("You must enter a URL for your slice's info");
76 if( $description == "" ) {
77 drupal_set_error("Your must enter a description for you slice.");
81 // if no errors then add
83 $fields= array( "url" => $url,
84 "instantiation" => $instantiation,
86 "description" => $description );
88 $slice_id= $api->AddSlice( $fields );
91 drupal_set_error("Could not create slice $name " . $api->error() );
94 drupal_set_message ("Slice $slice_id created");
99 foreach ($person_ids as $person_id) {
100 $person_id=intval($person_id);
101 if ($api->AddPersonToSlice($person_id,$slice_id) != 1) {
102 drupal_set_error("Could not add person $person_id in slice :" . $api->error());
109 drupal_set_message ("Added $counter person(s)");
111 drupal_set_error ("Could not add all selected persons, only $counter were added");
113 plc_redirect(l_slice($slice_id) );
118 //////////////////// still here : either it's a blank form or something was wrong
121 require_once 'plc_drupal.php';
122 include 'plc_header.php';
124 $sites=$api->GetSites(array($site_id));
126 $sitename=$site['name'];
127 if ( ! $_POST['name'])
128 $base= $site['login_base'] ."_";
130 // propose to add all 'reachable' persons
131 $site_person_ids=$site['person_ids'];
132 $persons=$api->GetPersons($site_person_ids,array('email','enabled','first_name','last_name','person_id'));
134 drupal_set_title('Create slice in site "' . $sitename . '"');
137 $url = $_POST['url'];
138 if( !$url ) $url= "http://";
140 // check for errors and set error styles
142 $name_error= " class='plc-warning'";
145 $url_error= " class='plc-warning'";
147 if( $error['description'] )
148 $desc_error= " class='plc-warning'";
151 // add javaScript code
153 <script type='text/javascript'>
154 function update(str1) {
155 var temp= new Array()
156 temp= str1.split('->');
157 var c= ( temp[1] + '_' )
158 document.getElementById('textbox').value = c;
164 <div class='slice_add'>
165 <p>You must provide a short description of the new slice
166 as well as a link to a project website before creating it.
168 Do <strong>not</strong> provide bogus information; if a complaint
169 is lodged against your slice and your PlanetLab Operations Center
170 is unable to determine what the normal behavior of your slice is,
171 your slice may be deleted to resolve the complaint.
173 <p><strong>NOTE</strong>:
174 All PlanetLab users are <strong>strongly</strong> encouraged to join the PlanetLab
175 <a href='https://lists.planet-lab.org/mailman/listinfo/users'>Users</a>
176 mailing list. Most questions about running software on PlanetLab can be answered by
177 posting to this list.
178 <br/>Site administrators often use this list to post announcements about service outages.
179 New software releases and available services are announced here as well.
184 $details = new PlekitDetails(TRUE);
186 $form_variables = array('site_id'=>plc_my_site_id());
187 $form = $details -> form_start("/db/slices/slice_add.php",$form_variables);
188 print $form->hidden_html("site_id",$site_id);
192 // is the user on several sites ?
193 if (plc_is_admin () || count (plc_my_site_ids()) > 1) {
194 // site selector - not implemented yet
195 //// // displays a site select list for admins and multi-site users
196 //// if( count( $_person['site_ids'] ) > 1 || in_array( 10, $_roles ) ) {
197 //// // get sites depending on role and sites associated.
198 //// if( in_array( 10, $_roles ) )
199 //// $site_info= $api->GetSites( NULL, array( "name", "site_id", "login_base" ) );
200 //// elseif( count( $_person['site_ids'] ) > 1 )
201 //// $site_info= $api->GetSites( $_person['site_ids'], array( "name", "site_id", "login_base" ) );
203 //// echo "<tr><th>Site: </th><td><select onchange='update(this[selectedIndex].text)' name='site_id'>\n";
205 //// foreach( $site_info as $site ) {
206 //// echo "<option value=". $site['site_id'];
207 //// if( $site['site_id'] == $_person['site_ids'][0] )
208 //// echo " selected";
209 //// echo ">". $site['name'] ."->". $site['login_base'] ."</option>\n";
212 //// echo "</select></td><td></td></tr>\n";
216 $details->th_td("Name",$name ? $name : $base, "name");
217 $details->th_td("URL",$url,"url");
218 $details->th_td("Description",$description,"description",
219 array('input_type'=>'textarea',
220 'width'=>50,'height'=>5));
221 $selectors=array(array('display'=>"PLC",'value'=>'plc-instantiated'),
222 array('display'=>"Delegated",'value'=>'delegated'),
223 array('display'=>"None",'value'=>'not-instantiated'));
225 $instanciation_select = $form->select_html ("instantiation", $selectors);
226 $details->th_td("Instanciation",$instanciation_select,"instantiation",
227 array('input_type'=>'select', 'value'=>$instantiation));
233 <div class='slice_add'>
234 <p>There are three possible "instantiation" states for a slice.</p>
236 <li> <strong>PLC</strong> creates a slice with default settings. </li>
237 <li><strong>Delegated</strong> creates a ticket to use on each node. </li>
238 <li><strong>None</strong> allows you to reserve a slice name; you may instantiate the slice later.</li>
244 $title = count($persons) . " people can be added in slice";
245 $toggle=new PlekitToggle ('persons',$title,
246 array('visible'=>get_arg('show_persons',true)));
250 $headers['email']='string';
251 $headers['first']='string';
252 $headers['last']='string';
253 $headers['+']='none';
254 $table = new PlekitTable ('persons_in_slice',$headers,0);
256 foreach ($persons as $person) {
258 $table->cell($person['email']);
259 $table->cell($person['first_name']);
260 $table->cell($person['last_name']);
261 $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
268 $add_button = $form->submit_html ("add-slice","Create Slice");
269 print ("<div id='slice_add_button'> $add_button </div>");
274 include 'plc_footer.php';