<?php
-// $Id$
+// install the default timezone as defined in php.ini
+date_default_timezone_set(ini_get('date.timezone'));
# note: this needs to be consistent with the value in Monitor/monitor/wrapper/plc.py
global $PENDING_CONSORTIUM_ID;
function l_register_node () { return "/registerwizard/index.php"; }
function l_pcu_add () { return "/registerwizard/index.php/register/stage1_addpcu"; }
function l_pcu ($pcu_id) { return "/db/sites/pcu.php?id=$pcu_id"; }
+function l_pcu_href ($pcu_id, $text) { return href(l_pcu($pcu_id), $text); }
function l_nodes () { return "/db/nodes/index.php"; }
function l_nodes_peer ($peer_id) { return "/db/nodes/index.php?peerscope=$peer_id"; }
function l_tags () { return "/db/tags/index.php"; }
function l_tag ($tag_type_id) { return "/db/tags/index.php?id=$tag_type_id"; }
function l_tag_obj ($tag) { return href(l_tag($tag['tag_type_id']),$tag['tagname']); }
+function l_tag_roles ($tag_type_id) { return "/db/tags/index.php?id=$tag_type_id&show_details=0&show_roles=1"; }
function l_nodegroups () { return "/db/tags/nodegroups.php"; }
function l_nodegroup ($nodegroup_id) { return "/db/tags/nodegroup.php?id=$nodegroup_id"; }
return $exploded[0];
}
-// with php-5.3 on f12, ereg is marked deprecated, using PCRE instead
-// looks unused
-function is_valid_email_addr ($email) {
- if (preg_match("/^.+@.+\\..+$/", $email) ) {
- return true;
- } else {
- return false;
- }
-}
-
-// looks unused
-function is_valid_url ($url) {
- if (preg_match("/^(http|https):\/\/.+\..+$/", strtolower($url) ) ) {
- return true;
- } else {
- return false;
- }
-}
+//// with php-5.3 on f12, ereg is marked deprecated, using PCRE instead
+//// looks unused
+// function is_valid_email_addr ($email) {
+// if (preg_match("/^.+@.+\\..+$/", $email) ) {
+// return true;
+// } else {
+// return false;
+// }
+//}
+//
+//// looks unused
+//function is_valid_url ($url) {
+// if (preg_match("/^(http|https):\/\/.+\..+$/", strtolower($url) ) ) {
+// return true;
+// } else {
+// return false;
+// }
+//}
function is_valid_ip ($ip) {
if (preg_match("/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/", $ip ) ) {
return $formatted;
}
-//////////
+////////// just return a truncated text
function truncate ($text,$numb,$etc = "...") {
- if (strlen($text) > $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 <span> 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("<span title='%s'>%s</span>",$text,$display);
}
+
// generates <(atom) class=(class)> (text) </(atom)>
function html_atom ($atom,$text,$class="") {
$html="<$atom";
// shows a php variable verbatim with a heading message
function plc_debug ($message,$object) {
- print "<br>" . $message . "<pre>";
+ print "<br />" . $message . "<pre>";
print_r ($object);
print "</pre>";
}
+function plc_debug_txt ($message,$txt) {
+ print "<br />" . $message . "<pre>";
+ $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 "</pre>";
+}
+
+$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 ("<span class=error>$text</span>");
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']
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 (); }
+
+
?>