+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="<div";
+ if ($class) $html .= " class='$class'";
+ $html .= ">$text</div>";
+ return $html;
+}
+
+if (! function_exists ("drupal_set_error")) {
+ function drupal_set_error ($text) {
+ drupal_set_message ("<span class=error>$text</span>");
+ }
+ }
+
+//////////////////////////////////////////////////////////// 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 "<img width='$width' src='/planetlab/icons/delete.png'>";
+}
+
+function plc_bubble($text,$bubble) {
+ return "<span title='$bubble'>$text</span>";
+}
+function plc_delete_icon_bubble ($bubble,$width=15) {
+ return plc_bubble(plc_delete_icon($width),$bubble);
+}
+
+function plc_event_button($type,$param,$id) {
+ return '<a href="' . l_event($type,$param,$id) . '"> <span title="Related events"> <img src="/planetlab/icons/event.png" width=18></span></a>';
+}
+
+function plc_comon_button ($id_name, $id_value,$target="") {
+ $result='<a ';
+ if (!empty($target)) {
+ $result.='target="' . $target . '" ';
+ }
+ $result.='href="' . l_comon($id_name,$id_value) . '">';
+ $result.='<span title="Link to Comon"> <img src="/planetlab/icons/comon.png" width="18"></span></a>';
+ return $result;
+}
+
+////////////////////
+function plc_redirect ($url) {
+ header ("Location: " . $url);
+ exit ();
+}
+
+//////////////////// 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;
+}
+
+////////////////////
+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;
+}