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 'plc_sorts.php';
15 $_person= $plc->person;
16 $_roles= $_person['role_ids'];
18 // redirect if no site id is set add instead
22 $site_id= $_GET['id'];
26 // if form not submitted get data from API
27 if( $_POST['submitted'] ) {
29 $name= $_POST['name'];
30 $abbrev_name= $_POST['abbrev_name'];
32 $login_base= $_POST['login_base'];
33 $latitude= $_POST['latitude'];
34 $longitude= $_POST['longitude'];
35 //$max_slivers= $_POST['max_slivers'];
36 $max_slices= $_POST['max_slices'];
40 $error['name']= "<font color=red>Name can not be blank.</font>";
42 if( $abbrev_name == "" )
43 $error['abbrev_name']= "<font color=red>Abbreviated Name can not be blank.</font>";
45 if( $login_base == "" )
46 $error['login_base']= "<font color=red>Login Base can not be blank.</font>";
48 if( $url == "" || $url == "http://" )
49 $error['url']= "<font color=red>URL can not be blank.</font>";
51 if( !is_numeric( $latitude ) )
52 $error['latitude']= "<font color=red>Latitude must be a number.</font>";
54 if( !is_numeric( $longitude ) )
55 $error['longitude']= "<font color=red>Longitude must be a number.</font>";
57 if( !is_numeric( $max_slices ) )
58 $error['max_slices']= "<font color=red>Max Slices must be a number.</font>";
61 // if no errors add/update site
63 $fields= array( "name" => $name, "url" => $url, "longitude" => floatval( $longitude ), "login_base" => $login_base, "latitude" => floatval( $latitude ), "is_public" => true, "abbreviated_name" => $abbrev_name, "max_slices" => 0 );
64 $api->AddSite( $fields );
65 //echo "<pre>"; print_r( $fields ); echo "</pre>";
68 if( $do == 'Update' ) {
69 $fields= array( "name" => $name, "url" => $url, "longitude" => floatval( $longitude ), "login_base" => $login_base, "latitude" => floatval( $latitude ), "is_public" => true, "abbreviated_name" => $abbrev_name, "max_slices" => intval( $max_slices ) );
70 $api->UpdateSite( intval( $site_id ), $fields );
71 // Thierry aug 31 07 - redirect to the site's details page
72 plc_redirect(l_site($site_id));
77 // if its an update get site info$max_slices &&
78 if( $do == 'Update' && empty( $error ) ) {
80 $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "url", "longitude", "latitude", "login_base", "max_slices", "abbreviated_name" ) );
82 // var names to api return
83 $name= $site_info[0]['name'];
84 $abbrev_name= $site_info[0]['abbreviated_name'];
85 $url= $site_info[0]['url'];
86 $login_base= $site_info[0]['login_base'];
87 $latitude= $site_info[0]['latitude'];
88 $longitude= $site_info[0]['longitude'];
89 //$max_slivers= $site_info[0]['max_slivers'];
90 $max_slices= $site_info[0]['max_slices'];
95 require_once 'plc_drupal.php';
96 drupal_set_title('Sites');
97 include 'plc_header.php';
101 $name_err= " style='border: 1px solid red;'";
103 if( $error['abbrev_name'] )
104 $abbrev_err= " style='border: 1px solid red;'";
106 if( $error['login_base'] )
107 $base_err= " style='border: 1px solid red;'";
110 $url_err= " style='border: 1px solid red;'";
112 if( $error['latitude'] )
113 $lat_err= " style='border: 1px solid red;'";
115 if( $error['longitude'] )
116 $long_err= " style='border: 1px solid red;'";
118 if( $error['max_slices'] )
119 $max_err= " style='border: 1px solid red;'";
122 echo "<form action='update_site.php?id=$site_id' method='post'>\n";
123 echo "<h2>$do $name</h2>\n";
125 echo "<table><tbody>\n";
126 // Thierry - displays name under double quotes - some site names have single quotes, none have double quotes as of now
127 echo "<tr><th>Name: </th><td> <input type=text $name_err name='name' value=\"$name\" size=40></td><td>". $error['name'] ."</td></tr>\n";
128 echo "<tr><th>Abbreviated Name: </th><td> <input type=text $abbrev_err name='abbrev_name' value='$abbrev_name' size=40></td><td>". $error['abbrev_name'] ."</td></tr>\n";
129 echo "<tr><th>Login Base: </th><td> <input type=text $base_err name='login_base' value='$login_base' size=40></td><td>". $error['login_base'] ."</td></tr>\n";
130 echo "<tr><th>URL: </th><td> <input type=text $url_err name='url' value='$url' size=40></td><td>". $error['url'] ."</td></tr>\n";
131 echo "<tr><th>Latitude/Longitude: </th><td> <input type=text $lat_err name='latitude' value='$latitude' size=10> / <input type=text $long_err name='longitude' value='$longitude' size=10></td><td>". $error['latitude'] ." ". $error['longitude'] ."</td></tr>\n";
133 if( in_array( 10, $_roles ) ) {
134 echo "<tr><th>Max Slices: </th><td> <input type=text $max_err name='max_slices' value='$max_slices'"; if( !in_array( '10', $_roles ) ) echo " disabled"; echo " size=10></td><td>". $error['max_slices'] ."</td></tr>\n";
137 echo "<tr><td colspan=3><input type=hidden name='max_slices' value='$max_slices'></td></tr>\n";
139 echo "<tr><td></td><td colspan=2><input type=submit name='submitted' value='$do Site'></td></tr>\n";
140 echo "</tbody></table><br />\n";
142 echo "<p><a href='index.php?id=$site_id'>Back to Site</a>\n";
148 include 'plc_footer.php';