";
- return true;
- } else {
- // set two classes, one eneraic to all foreign, and one based on the peer's shortname for finer grain tuning
- printf ('
";
+ }
+ $formatted .= "";
+ return $formatted;
+}
+function plc_itemize ($messages, $class="") {
+ if ( empty( $messages) ) return "";
+ $formatted = "";
+ $formatted .= "
";
+ return $formatted;
}
-function plc_peer_block_end () {
- print "
\n";
-}
-
-// interpret standard syntax for peerscope
-function plc_peer_info ($api,$peerscope) {
- switch ($peerscope) {
- case '':
- $peer_filter=array();
- $peer_label="all peers";
- break;
- case 'local':
- $peer_filter=array("peer_id"=>NULL);
- $peer_label=PLC_SHORTNAME;
- break;
- case 'foreign':
- $peer_filter=array("~peer_id"=>NULL);
- $peer_label="foreign peers";
- break;
- default:
- if (is_int ($peerscope)) {
- $peer_id=intval($peerscope);
- $peers=$api->GetPeers(array("peer_id"=>$peer_id));
- } else {
- $peers=$api->GetPeers(array("shortname"=>$peerscope));
- }
- if ($peers) {
- $peer=$peers[0];
- $peer_id=$peer['peer_id'];
- $peer_filter=array("peer_id"=>$peer_id);
- $peer_label='peer "' . $peer['shortname'] . '"';
- } else {
- $peer_filter=array();
- $peer_label="[no such peer " . $peerscope . "]";
- }
- break;
+//////////
+// should use the same channel as the php errors..
+function plc_error_html ($text) { return "
" . $text . "
"; }
+function plc_error ($text) { print plc_error_html ("Error " . $text); }
+
+function plc_errors ($errors) {
+ if ($errors) {
+ print( "
" );
+ print( "
The following errors occured:
" );
+ print("
");
+ foreach( $errors as $error )
+ print( "- $error
\n" );
+ print( "
\n" );
}
- return array ($peer_filter,$peer_label);
}
-//////////////////////////////////////////////////////////// titles
-function t_site($site) { return " on site " . $site['name'] . " (" . $site['login_base'] .")"; }
-function t_slice ($slice) { return " running slice " . $slice['name'] . " (" . $slice['slice_id'] . ")"; }
+function plc_warning_html ($text) { return "
" . $text . "";}
+function plc_warning ($text) { print plc_warning_html("Warning " . $text); }
+function plc_foreign_html($text) { return "
$text"; }
-//////////////////////////////////////////////////////////// nav tabs
-function tabs_node($node) { return array('Node ' . $node['hostname']=>l_node($node_id)); }
-function tabs_site($site) { return array('Site ' . $site['name']=>l_site($site_id)); }
-function tabs_slice($slice) { return array('Slice ' . $slice['name']=>l_slice($slice_id)); }
+// shows a php variable verbatim with a heading message
+function plc_debug ($message,$object) {
+ print "
" . $message . "
";
+ print_r ($object);
+ print "
";
+}
-//////////////////////////////////////////////////////////// presentation
+function truncate ($text,$numb,$etc = "...") {
+ if (strlen($text) > $numb) {
+ $text = substr($text, 0, $numb);
+ $text = $text.$etc;
+ }
+ return $text;
+}
+function html_div ($text,$class="") {
+ $html="
$text");
+ }
+ }
+
+//////////////////////////////////////////////////////////// sort out for obsolete / trash
// builds a table from an array of strings, with the given class
// attempt to normalize the delete buttons and confirmations
-function plc_delete_button($width=15) {
- return '
';
+function plc_delete_icon($width=15) {
+ return "
";
}
-function plc_js_confirm($message) {
- return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\"";
+function plc_add_icon($width=15) {
+ return "
";
}
-function plc_delete_link($url,$delete_message,$visible) {
- return "
" . $visible . "";
+function plc_bubble($text,$bubble) {
+ return "
$text";
}
-
-function plc_delete_link_button($url,$delete_message,$width=15) {
- return "
" . plc_delete_button($width) . "";
+function plc_delete_icon_bubble ($bubble,$width=15) {
+ return plc_bubble(plc_delete_icon($width),$bubble);
}
function plc_event_button($type,$param,$id) {
@@ -300,48 +407,65 @@ function plc_comon_button ($id_name, $id_value,$target="") {
return $result;
}
-function plc_vertical_table ($messages, $class="") {
- // pretty print the cell
- if ( empty( $messages) ) return "";
- $formatted = "";
- $formatted .= "
";
- return $formatted;
-}
-
-////////////////////////////////////////////////////////////
-function plc_error ($text) {
- // should use the same channel as the php errors..
- print "
Error " . $text . "
";
+////////////////////
+function plc_redirect ($url) {
+ header ("Location: " . $url);
+ exit ();
}
-function plc_errors ($list) {
- print( "
" );
- print( "
The following errors occured:
" );
- print("
");
- foreach( $errors as $err ) {
- print( "- $err
\n" );
+//////////////////// the options for an interface - suitable for plekit/form
+//>>> GetNetworkMethods()
+//[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown']
+function interface_method_selectors ($api, $method, $primary) {
+ if ($primary) {
+ $builtin_methods=array("static"=>"Static",
+ "dhcp"=>"DHCP");
+ } else {
+ $builtin_methods=array("static"=>"Static",
+ "dhcp"=>"DHCP",
+ "proxy"=>"Proxy",
+ "tap"=>"TUN/TAP",
+ "ipmi"=>"IPMI");
+ }
+ $selectors=array();
+ foreach ($builtin_methods as $value=>$display) {
+ $selector=array('display'=>$display, 'value'=>$value);
+ if ($value == $method) $selector['selected']=true;
+ $selectors []= $selector;
}
- print( "
\n" );
+ return $selectors;
}
-function plc_warning_div ($text) {
- return "
" . $text . "
";
+////////////////////
+function instantiation_label ($slice) {
+ $instantiation_labels = array ('not-instantiated'=>'NOT',
+ 'plc-instantiated'=>'PLC',
+ 'delegated' => 'DEL',
+ 'nm-controller' => 'NM');
+ $result=$instantiation_labels[$slice['instantiation']];
+ if (!$result) $result = $slice['instantiation'];
+ if (!$result) $result = '??';
+ return $result;
}
-function plc_warning ($text) {
- print plc_warning_div("Warning " . $text);
+
+//////////////////// toggle areas
+// get_arg ('show_persons',false) returns $_GET['show_persons'] if set and false otherwise
+function get_arg ($name,$default,$method='get') {
+ if ($method == 'get') $var=$_GET; else $var=$_POST;
+ if (isset ($var[$name])) return $var[$name];
+ else return $default;
}
-// shows a php variable verbatim with a heading message
-function plc_debug ($message,$object) {
- print "
" . $message . "
";
- print_r ($object);
- print "
";
+//////////////////// number of ...
+function count_english ($objs,$name) {
+ $count=count($objs);
+ if ($count == 0) return 'No ' . $name;
+ else if ($count == 1) return 'One ' . $name;
+ else return $count . ' ' . $name . 's';
+}
+function count_english_warning ($objs, $name) {
+ $x=count_english ($objs,$name);
+ if (count ($objs) == 0) $x=plc_warning_html($x . ' !!');
+ return $x;
}
-
?>