X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fincludes%2Fplc_functions.php;h=9a5eff5599daf33b778b00e244a964935a5b9a9f;hb=ca6e72138a20a68200f98f4efe713d39cc2c56af;hp=a23e1ea92e676e7672d42ce4a5b666e65de90c50;hpb=1fee509dbe62c3db0a5d21264efad73963c7e635;p=plewww.git diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index a23e1ea..9a5eff5 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -3,8 +3,12 @@ // $Id$ // will trash this eventually -require_once 'plc_functions_trash.php'; + //require_once 'plc_functions_trash.php'; +// utility +function my_is_int ($x) { + return (is_numeric($x) ? intval($x) == $x : false); +} //////////////////////////////////////////////////////////// roles & other checks on global $plc function plc_is_admin () { global $plc; @@ -43,49 +47,52 @@ function href ($url,$text) { return "" . $text . ""; // l_object_add () -> the url to that object-afding page function l_actions () { return "/db/actions.php"; } +// some complex node actions are kept separate, e.g. the ones related to getbootmedium +function l_actions_download () { return "/db/nodes/node_downloads.php"; } function l_nodes () { return "/db/nodes/index.php"; } -function l_nodes_local () { return "/db/nodes/index.php?peerscope=local"; } +function l_nodes_peer ($peer_id) { return "/db/nodes/index.php?peerscope=$peer_id"; } function l_node ($node_id) { return "/db/nodes/node.php?id=$node_id"; } function l_node_t ($node_id,$text) { return href (l_node($node_id),$text); } +function l_node_obj($node) { return href(l_node($node['node_id']),$node['hostname']); } function l_node_add () { return "/db/nodes/node_add.php"; } function l_nodes_site ($site_id) { return "/db/nodes/index.php?site_id=$site_id"; } -function l_interface ($interface_id) { return "/db/nodes/interfaces.php?id=$interface_id"; } +function l_interface ($interface_id) { return "/db/nodes/interface.php?id=$interface_id"; } function l_interface_t ($interface_id,$text) { return href (l_interface($interface_id),$text); } -function l_interface_add($node_id) { return "/db/nodes/interfaces.php?node_id=$node_id"; } +function l_interface_add($node_id) { return "/db/nodes/interface.php?node_id=$node_id"; } function l_sites () { return "/db/sites/index.php"; } -function l_sites_local () { return "/db/sites/index.php?peerscope=local"; } +function l_sites_peer ($peer_id) { return "/db/sites/index.php?peerscope=$peer_id"; } function l_site ($site_id) { return "/db/sites/index.php?id=$site_id"; } function l_site_t ($site_id,$text) { return href (l_site($site_id),$text); } -function l_site_update($site_id) { return "/xxx-undefined"; } function l_slices () { return "/db/slices/index.php"; } +function l_slices_peer ($peer_id) { return "/db/slices/index.php?peerscope=$peer_id"; } function l_slice ($slice_id) { return "/db/slices/index.php?id=$slice_id"; } function l_slice_t ($slice_id,$text) { return href (l_slice($slice_id),$text); } -function l_slice_add () { return "/db/slices/add_slice.php"; } +function l_slice_add () { return "/db/slices/slice_add.php"; } function l_slices_site($site_id) { return "/db/slices/index.php?site_id=$site_id"; } // from an object -function l_slice_text ($slice) { return l_slice_t ($slice['slice_id'],$slice['name']); } +function l_slice_obj ($slice) { return l_slice_t ($slice['slice_id'],$slice['name']); } function l_sliver ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=$node_id&slice_id=$slice_id"; } function l_sliver_t ($node_id,$slice_id,$text) { return href (l_sliver($node_id,$slice_id),$text) ; } function l_persons () { return "/db/persons/index.php"; } +function l_persons_peer ($peer_id) { return "/db/persons/index.php?peerscope=$peer_id"; } function l_person ($person_id) { return "/db/persons/index.php?id=$person_id"; } function l_person_t ($person_id,$text) { return href (l_person($person_id),$text); } function l_persons_site ($site_id) { return "/db/persons/index.php?site_id=$site_id"; } function l_tags () { return "/db/tags/index.php"; } -function l_tag ($tag_type_id) { return "/db/tags/index.php"; } -function l_tag_add() { return "/db/tags/tag_form.php"; } -function l_tag_update($id) { return "/db/tags/tag_form.php&action=update-tag-type&id=$id"; } +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_nodegroups () { return "/db/tags/nodegroups.php"; } -function l_nodegroup ($nodegroup_id) { return "/db/tags/nodegroups.php?id=$nodegroup_id"; } +function l_nodegroup ($nodegroup_id) { return "/db/tags/nodegroup.php?id=$nodegroup_id"; } function l_nodegroup_t ($nodegroup_id,$text) { return href(l_nodegroup($nodegroup_id),$text); } @@ -94,6 +101,7 @@ function l_event ($type,$param,$id) { return "/db/events/index.php?type=$type&$p function l_peers() { return "/db/peers/index.php"; } function l_peer($peer_id) { return "/db/peers/index.php?id=$peer_id"; } +function l_peer_t($peer_id,$text) { return href(l_peer($peer_id),$text); } function l_comon($id_name,$id_value) { return "/db/nodes/comon.php?$id_name=$id_value"; } function l_sirius() { return "/db/sirius/index.php"; } @@ -102,6 +110,7 @@ function l_doc_plcapi() { return "/db/doc/PLCAPI.php"; } function l_doc_nmapi() { return "/db/doc/NMAPI.php"; } function l_admin() { return "/db/adminsearch.php"; } +function l_login() { return "/db/login.php"; } function l_logout() { return "/planetlab/logout.php"; } function l_sulogout() { return "/planetlab/sulogout.php"; } function l_reset_password() { return "/db/persons/reset_password.php"; } @@ -207,7 +216,7 @@ function is_reserved_network_addr($network_addr) { return false; } -//////////////////////////////////////////////////////////// peer & peerscopes +//////////////////////////////////////////////////////////// roles function plc_role_global_hash ($api) { $hash=array(); $roles=$api->GetRoles(); @@ -217,88 +226,6 @@ function plc_role_global_hash ($api) { return $hash; } -//////////////////////////////////////////////////////////// peer & peerscopes -// when shortnames are needed on peers -function plc_peer_global_hash ($api) { - $peer_columns=array('peer_id','shortname'); - $peer_filter=array(); - $peers = $api->GetPeers($peer_filter,$peer_columns); - - $peer_hash=array(); - foreach ($peers as $peer) { - $peer_hash[$peer['peer_id']]=$peer; - } -} - -function plc_peer_shortname ($peer_hash,$peer_id) { - if ( ! $peer_id ) { - return PLC_SHORTNAME; - } else { - return $peer_hash[$node['peer_id']]['shortname']; - } -} - -function plc_peer_label ($peer) { - if (! $peer) { - return "Local object on " . PLC_NAME . " (" . PLC_SHORTNAME . ")"; - } - $result= $peer['peername'] . " (" . $peer['shortname'] . ")"; - $result= href(l_peer($peer['peer_id']),$result); - return plc_foreign_text($result); -} - -// to set the background to grey on foreign objects -// return true if the peer is local -function plc_peer_block_start ($peer_hash,$peer_id) { - if ( ! $peer_id ) { - print "
"; - return true; - } else { - // set two classes, one eneraic to all foreign, and one based on the peer's shortname for finer grain tuning - printf ('
\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; - } - return array ($peer_filter,$peer_label); -} //////////////////////////////////////////////////////////// nodegroups // hash by 'tagname=value' @@ -325,39 +252,7 @@ function tabs_node($node) { return array('Node ' . $node['hostname']=>l_node($no 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)); } -//////////////////////////////////////////////////////////// presentation -// 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 'Delete this entry'; -} - -function plc_js_confirm($message) { - return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\""; -} - -function plc_delete_link($url,$delete_message,$visible) { - return "" . $visible . ""; -} - -function plc_delete_link_button($url,$delete_message,$width=15) { - return "" . plc_delete_button($width) . ""; -} - -function plc_event_button($type,$param,$id) { - return ' '; -} - -function plc_comon_button ($id_name, $id_value,$target="") { - $result=''; - $result.=' '; - return $result; -} - +//////////////////////////////////////////////////////////// html fragments function plc_vertical_table ($messages, $class="") { // pretty print the cell if ( empty( $messages) ) return ""; @@ -372,12 +267,6 @@ function plc_vertical_table ($messages, $class="") { return $formatted; } -//////////////////////////////////////////////////////////// various mappers -// could not figure how to use anonymous lambdas.. -function get_site_id ($site) { return $site['site_id'];} -function get_tagname ($tag) { return $tag['tagname'];} - -//////////////////////////////////////////////////////////// function plc_section ($text,$line=true) { if ($line) { print "
";} print "

$text

\n"; @@ -388,19 +277,20 @@ function plc_error ($text) { print "
Error " . $text . "
"; } -function plc_errors ($list) { - print( "
" ); - print( "

The following errors occured:

" ); - print("
    "); - foreach( $errors as $err ) { - print( "
  • $err
  • \n" ); +function plc_errors ($errors) { + if ($errors) { + print( "
    " ); + print( "

    The following errors occured:

    " ); + print("
      "); + foreach( $errors as $error ) + print( "
    • $error
    • \n" ); + print( "
    \n" ); } - print( "
\n" ); } -function plc_warning_text ($text) { return "" . $text . "";} -function plc_warning ($text) { print plc_warning_text("Warning " . $text); } -function plc_foreign_text($text) { return "$text"; } +function plc_warning_html ($text) { return "" . $text . "";} +function plc_warning ($text) { print plc_warning_html("Warning " . $text); } +function plc_foreign_html($text) { return "$text"; } // shows a php variable verbatim with a heading message function plc_debug ($message,$object) { @@ -409,5 +299,58 @@ function plc_debug ($message,$object) { print ""; } +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_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 ' '; +} + +function plc_comon_button ($id_name, $id_value,$target="") { + $result=''; + $result.=' '; + return $result; +} + +//////////////////// +function plc_redirect ($url) { + header ("Location: " . $url); + exit (); +} ?>