X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fincludes%2Fplc_functions.php;h=5db3d54104d0002c068d6d51f5a4b7fcad8e6787;hb=fd9b5dccd591a5bfe48daf1da6bbb52164fa93c9;hp=658cc86a5a35270473d5d79e881cda7163571784;hpb=25d98634e8ff1509901a8f1b44882e452b9131b7;p=plewww.git diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index 658cc86..5db3d54 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -1,6 +1,7 @@ $numb) { - $text = substr($text, 0, $numb); - $text = $text.$etc; - } - return $text; + if (strlen($text) <= $numb) return $text; + return substr($text, 0, $numb).$etc; +} +// ditto but in case the text is too lare, returns a with its 'title' set to the full value +function truncate_and_popup ($text,$numb,$etc = "...") { + if (strlen($text) <= $numb) return $text; + $display=substr($text, 0, $numb).$etc; + return sprintf("%s",$text,$display); } + // generates <(atom) class=(class)> (text) function html_atom ($atom,$text,$class="") { $html="<$atom"; @@ -417,11 +429,45 @@ function bold_html ($text) { return html_span($text,'bold'); } // shows a php variable verbatim with a heading message function plc_debug ($message,$object) { - print "
" . $message . "
";
+  print "
" . $message . "
";
   print_r ($object);
   print "
"; } +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 "
"; +} + +$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"); +} + if (! function_exists ("drupal_set_error")) { function drupal_set_error ($text) { drupal_set_message ("$text"); @@ -466,6 +512,27 @@ function plc_redirect ($url) { exit (); } +//////////////////// 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; +} + +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; +} + //////////////////// the options for an interface - suitable for plekit/form //>>> GetNetworkMethods() //[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown'] @@ -511,7 +578,7 @@ function instantiation_label ($slice) { //////////////////// toggle areas // get_arg ('show_persons',false) returns $_GET['show_persons'] if set and false otherwise -function get_arg ($name,$default,$method='get') { +function get_arg ($name,$default=NULL,$method='get') { if ($method == 'get') $var=$_GET; else $var=$_POST; if (isset ($var[$name])) return $var[$name]; else return $default; @@ -529,4 +596,10 @@ function count_english_warning ($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 (); } + + ?>