X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=planetlab%2Fincludes%2Fplc_functions.php;h=d40de74ab558556ecb4fd7c94aa3aedc3f2eb152;hb=9d5da0d9968a075070eb8c5b75d8267d082bec31;hp=3809c766d7cf6cd8f31c3ff780281cd5bb9ff6da;hpb=34b0377def5a2f3789df20e63b32099baba7df66;p=plewww.git diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index 3809c76..d40de74 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -1,276 +1,269 @@ ' . $person_id . ''; - } - } - -function plc_node_link ($node_id) { - if ( empty ($node_id)) { - return ""; - } else { - return '' . $node_id . ''; - } - } - -// pagination function -function paginate( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) { - // get vars from call adjust them - $dir= strtolower( $caption ); - $echo= ""; - - $link_page= 'index.php'; - - // check for page number - if( empty( $_GET['page'] ) ) - $page= 1; - else - $page= $_GET['page']; - - // reorder array_chunk - foreach( $fn_array as $arr1 ) { - unset( $arr2 ); - - foreach( $arr1 as $key => $val ) { -// if( substr( $key, -3 ) == "_id" ) - if ( $key == $table_id ) { - $id[$key]= $val; - } else { - $data[$key]= $val; - } - } - - foreach( $id as $key => $val ) - $arr2[$key]= $val; - - foreach( $data as $key => $val ) - $arr2[$key]= $val; - - $as_array[]= $arr2; - } - - $totalrows= count( $as_array ); - - // if array has no rows display msg - if( $totalrows == 0 ) - return "Nothing to display"; - - // set key and break up data struct - $newkey= $page - 1; - $newarray= array_chunk( $as_array, $limit ); - - // start table output - $echo.= "
". ucfirst( $key ) ." | "; - } - - if( $other_func == 'slivers' ) - $echo.= "Slivers | "; - - $echo.= "|
---|---|---|
$val | "; - } elseif ($key != 'peer_id') { - $echo.= ""; - if( is_array( $val ) ) { - $count= 1; - $tot= count( $val ); - foreach( $val as $k => $v ) { - $echo.= $v; - if( $count != $tot ) - $echo.= ", "; - $count++; - } - } - else - $echo.= $val; - $echo.= " | "; - } - - } - - if( $other_func == 'slivers' ) - $echo.= "view | "; - - $echo.= "
" . $message . " |
The following errors occured:
" ); + print(""; +function plc_debug ($message,$object) { + print "
" . $message . ""; print_r ($object); print ""; } -// attempt to normalize the delete buttons and confirmations -function plc_delete_button($width=15) { - return ''; +function plc_debug_txt ($message,$txt) { + print "
" . $message . ""; + $txt=str_replace(" ","<SPC>",$txt); + $txt=str_replace("\t","<TAB>",$txt); + $txt=str_replace("\n","<LF>",$txt); + $txt=str_replace("\r","<CR>",$txt); + print $txt . "<EOF>"; + print ""; } -function plc_js_confirm($message) { - return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\""; +$plc_prof_start=0.; +$plc_prof_time=0.; +$plc_prof_counter=0; +function plc_debug_prof_start () { + global $plc_prof_counter, $plc_prof_start, $plc_prof_time; + $plc_prof_counter=0; + plc_debug(strftime("[0] %T (start)") ,"heating up"); + $plc_prof_time=microtime(true); + $plc_prof_start=$plc_prof_time; +} +function plc_debug_prof ($message,$object) { + global $plc_prof_counter, $plc_prof_start, $plc_prof_time; + $plc_prof_counter+=1; + $now=microtime(true); + $timelabel=strftime("%T"); + $prof_message=sprintf("[%d] %s (%2.3f s -- %2.3f s) ",$plc_prof_counter,$timelabel, + ($now-$plc_prof_time),($now-$plc_prof_start)); + plc_debug($prof_message.$message,$object); + $plc_prof_time=$now; +} +function plc_debug_prof_end () { + plc_debug_prof ("end","cooling down"); } -function plc_delete_link($url,$delete_message,$visible) { - return "" . $visible . ""; +if (! function_exists ("drupal_set_error")) { + function drupal_set_error ($text) { + drupal_set_message ("$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_icon($width=15) { + return ""; } -function plc_delete_link_button($url,$delete_message,$width=15) { - return "" . plc_delete_button($width) . ""; +function plc_add_icon($width=15) { + return ""; +} + +function plc_bubble($text,$bubble) { + return "$text"; +} +function plc_delete_icon_bubble ($bubble,$width=15) { + return plc_bubble(plc_delete_icon($width),$bubble); } function plc_event_button($type,$param,$id) { - return ' '; + return ' '; } -function plc_comon_button ($field, $value,$target="") { +function plc_comon_button ($id_name, $id_value,$target="") { $result=''; - $result.=' '; + $result.='href="' . l_comon($id_name,$id_value) . '">'; + $result.=' '; return $result; } -function plc_peers_option_list ($api) { +//////////////////// +function plc_redirect ($url) { + header ("Location: " . $url); + exit (); +} - // get list of peers - $peers=$api->GetPeers(NULL,array('peer_id','peername')); - if (count($peers)==0) { - $predef=array(array("peer_id"=>"","peername"=>"All (no known peers)")); - } else { - $predef=array(array("peer_id"=>"","peername"=>"All peers"), - array("peer_id"=>"local","peername"=>"Local only")); - // show a 'foreign' button only if that makes sense - if (count($peers) >= 2) { - $predef [] = array("peer_id"=>"foreign","peername"=>"Foreign peers"); - } - } - - $result=""; - foreach ($predef as $a) { - $peer_line = "\n"; - $result .= $peer_line; - } +//////////////////// the options for an nodetype - suitable for plekit/form +global $builtin_node_types; +$builtin_node_types = array ( "regular" => "Regular/Shared", + "reservable" => "Reservable (requires to get leases)"); +function node_type_display ($api, $node_type) { + global $builtin_node_types; + $val=$builtin_node_types[$node_type]; + if ( ! $val) $val="??undefined??"; + return $val; +} - if (!empty($peers)) { - foreach ($peers as $a) { - $peer_line = "\n"; - $result .= $peer_line; - } - } +function node_type_selectors ($api,$node_type) { + global $builtin_node_types; + foreach ($builtin_node_types as $value=>$display) { + $selector=array('display'=>$display, 'value'=>$value); + if ($value == $node_type) $selector['selected']=true; + $selectors []= $selector; + } + return $selectors; +} - return $result; +//////////////////// 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; + } + return $selectors; } +// displays bandwidth with kbps Mbps Gbps as needed +function pretty_bandwidth ($bw) { + if ($bw < 1000) return $bw; + if ($bw < 1000000) return strval($bw/1000) . " kbps"; + if ($bw < 1000000000) return strval($bw/1000000) . " Mbps"; + else return strval($bw/1000000000) . " Gbps"; +} + +//////////////////// +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; +} + +//////////////////// 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; +} + +//////////////////// 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; +} + +//////////////////// outlining reservable nodes +function reservable_mark () { return "-R-";} +function reservable_legend () { return "reservable nodes are marked with " . reservable_mark (); } + + ?>