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_message ("Slice $slice_id created");
96 foreach ($person_ids as $person_id) {
97 $person_id=intval($person_id);
98 if ($api->AddPersonToSlice($person_id,$slice_id) != 1) {
99 drupal_set_error("Could not add person $person_id in slice :" . $api->error());
106 drupal_set_message ("Added $counter person(s)");
108 drupal_set_error ("Could not add all selected persons, only $counter were added");
110 plc_redirect(l_slice($slice_id) );
112 drupal_set_error("Could not create slice $name " . $api->error() );
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 // is there a need to consider several sites ?
152 $multiple_sites=false;
153 $site_columns=array('name','login_base','site_id');
154 if (plc_is_admin ()) {
155 $multiple_sites=true;
157 } else if (count (plc_my_site_ids()) > 1) {
158 $multiple_sites=true;
159 $filter=plc_my_site_ids();
162 if ($multiple_sites) {
163 print "<div id='add_slice_in_site'>";
164 $other_sites=$api->GetSites($filter,$site_columns);
166 foreach ($other_sites as $other_site) {
167 $selector=array('display'=>$other_site['name'],
168 'value'=>$other_site['site_id']);
169 if ($other_site['site_id']==$other_site_id) $selector['selected']='selected';
170 $selectors []= $selector;
173 $site_form = new PleKitForm (l_slice_add(),array(),'get');
175 print $site_form->label_html('site_id','Or choose some other site');
176 print $site_form->select_html('site_id',$selectors,array('autosubmit'=>true,
177 'id'=>'add_slice_choose_site'));
183 <div class='slice_add'>
184 <p>You must provide a short description of the new slice
185 as well as a link to a project website before creating it.
187 Do <strong>not</strong> provide bogus information; if a complaint
188 is lodged against your slice and your PlanetLab Operations Center
189 is unable to determine what the normal behavior of your slice is,
190 your slice may be deleted to resolve the complaint.
192 <p><strong>NOTE</strong>:
193 All PlanetLab users are <strong>strongly</strong> encouraged to join the PlanetLab
194 <a href='https://lists.planet-lab.org/mailman/listinfo/users'>Users</a>
195 mailing list. Most questions about running software on PlanetLab can be answered by
196 posting to this list.
197 <br/>Site administrators often use this list to post announcements about service outages.
198 New software releases and available services are announced here as well.
203 $details = new PlekitDetails(TRUE);
205 $form_variables = array('site_id'=>plc_my_site_id());
206 $form = $details -> form_start("/db/slices/slice_add.php",$form_variables);
207 print $form->hidden_html("site_id",$site_id);
211 $running=count($site['slice_ids']);
212 $max=$site['max_slices'];
213 $allocated = " $running running / $max max";
214 if ($running >= $max) $allocated = plc_warning_html($allocated);
215 $details->th_td("Allocated slices",$allocated);
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';