require_once 'plc_config.php';
require_once 'plc_session.php';
+require_once 'plc_functions.php';
function planetlab_help($section) {
switch ($section) {
return $items;
}
+// formatting helpers
+function ul_start () { return '<ul class=menu>'; }
+function ul_end () { return '</ul>'; }
+function leaf($text) { return '<li class=leaf>' . $text . '</li>'; }
+function expanded($text) { return '<li class=expanded>' . $text . '</li>'; }
+function p($text) { return '<p>' . $text . '</p>'; }
+// fake theme to look like menu
+function menu_theme ($menu) {
+ $result = '';
+ $result .= ul_start();
+ foreach ($menu as $item) $result .= $item;
+ $result .= ul_end();
+ return $result;
+}
+
function planetlab_block($op = 'list', $delta = 0, $edit = array()) {
global $user, $plc;
$block['subject'] = t('%s login', array('%s' => variable_get('site_name', 'local')));
$block['content'] = drupal_get_form('planetlab_login_block', $form, 'planetlab_login');
- $block['content'] .= '<p><p><a href="/db/persons/reset_password.php">Forgot your password?</a></p>';
- $block['content'] .= '<p><a href="/db/persons/register.php">Create an account</a></p>';
- $block['content'] .= '<p><a href="/db/sites/register.php">File a site registration</a></p>';
+ $block['content'] .= p('');
+ $block['content'] .= p( href (l_reset_password(),"Forgot your password?") );
+ $block['content'] .= p( href(l_person_register(),"Create an account") );
+ $block['content'] .= p( href(l_site_register(),"File a site registration") );
} else {
$block['subject'] = $plc->person['email'];
$is_admin = in_array(10,$plc->person['role_ids']);
$is_tech = in_array(40,$plc->person['role_ids']);
$site_item = '';
- $site_item .= '<a href="/db/sites/">Sites</a>';
- $site_item .= '<ul>';
- $site_item .= '<li><a href="/db/sites/index.php?id='. $plc->person['site_ids'][0] .'">My Site</a></li>';
+ $site_item .= href(l_sites(),"Sites");
+ $site_item .= ul_start();
+ $site_item .= leaf( href(l_site_u(plc_my_site_id()),"My site"));
if ( $is_admin )
- $site_item .= "<li><a href='/db/sites/join_request.php'>Join Requests</a></li>";
+ $site_item .= leaf( href(l_site_pending(),"Pending Requests"));
if( $is_admin )
- $site_item .= "<li><a href='/db/sites/peers.php'>Migration Status</a></li>";
- $site_item .= "</ul>";
- $items[] = $site_item;
+ $site_item .= leaf( href(l_site_status(),"Migration Status"));
+ $site_item .= ul_end();
+ $items[] = expanded($site_item);
$user_item = '';
- $user_item .= '<a href="/db/persons/">Users</a>';
- $user_item .= '<ul>';
- $user_item .= '<li><a href="/db/persons/index.php?id='. $plc->person['person_id'] .'">My account</a></li>';
+ $user_item .= href(l_persons(),'Users');
+ $user_item .= ul_start();
+ $user_item .= leaf( href(l_person_u(plc_my_person_id()),"My account"));
if (is_pi)
- $user_item .= '<li><a href="/db/persons/index.php?site_id='. $plc->person['site_ids'][0] .'">My users</a></li>';
+ $user_item .= leaf( href( l_persons_site(plc_my_site_id()), "My users"));
if ( $plc->alt_person && $plc->alt_auth) {
$email = $plc->person['email'];
- $user_item .= "<li><a href='/db/sulogout.php'>Log out of $email </a></li>";
+ $user_item .= leaf( href( l_sulogout(),"Log out of $email"));
}
-
-
- $user_item .= '</ul>';
- $items [] = $user_item;
+ $user_item .= ul_end();
+ $items [] = expanded($user_item);
$node_item = '';
- $node_item .= '<a href="/db/nodes/">Nodes</a>';
- $node_item .= '<ul>';
- $node_item .= '<li><a href="/db/nodes/index.php?site_id='. $plc->person['site_ids'][0] .'">My Site Nodes</a></li>';
- $node_item .= "<li><a href='/db/nodes/add_node.php'>Add Node</a></li>";
+ $node_item .= href(l_nodes(),"Nodes");
+ $node_item .= ul_start();
+ $node_item .= leaf( href (l_nodes_site (plc_my_site_id()),"My Site Nodes"));
+ $node_item .= leaf( href (l_node_add(),"Add Node"));
if ( $is_admin)
- $node_item .= "<li> <a href='/db/nodes/settings.php'> Setting Types </a> </li>";
- $node_item .= '</ul>';
- $items [] = $node_item;
+ $node_item .= leaf (href(l_peers(),'Peers'));
+ $node_item .= ul_end();
+ $items [] = expanded($node_item);
$slice_item = '';
//if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) )
- $slice_item .= '<a href="/db/slices/">Slices</a>';
- $slice_item .= '<ul>';
+ $slice_item .= href(l_slices(),"Slices");
+ $slice_item .= ul_start();
if( $is_admin || $is_pi ) {
- $slice_item .= "<li><a href='/db/slices/add_slice.php'>Create Slice</a></li>";
+ $slice_item .= leaf(href(l_slice_add(),"Create Slice"));
}
if( !( $is_tech && ! $is_user && ! $is_pi && ! $is_admin ) )
- $slice_item .= '<li><a href="/db/sirius/index.php">Sirius</a></li>';
- $slice_item .= '</ul>';
- $items [] = $slice_item;
+ $slice_item .= leaf(href(l_sirius(),"Sirius"));
+ $slice_item .= ul_end();
+ $items [] = expanded($slice_item);
if( $is_admin || $is_pi ) {
$tag_item = '';
- $tag_item .= '<a href="/db/slices/tags.php?type=all">Tags</a>';
- $tag_item .= '<ul>';
- $tag_item .= "<li><a href='/db/tags/index.php?type=node'>Node Tags</a></li>";
- $tag_item .= "<li><a href='/db/tags/index.php?type=interface'>Interface Tags</a></li>";
- $tag_item .= "<li><a href='/db/tags/index.php?type=slice'>Slice Tags</a></li>";
- $tag_item .= "<li><a href='/db/tags/nodegroups.php'>Node groups (xxx)</a></li>";
- $tag_item .= '</ul>';
- $items [] = $tag_item;
+ $tag_item .= href(l_tags(),"All Tag Types");
+ $tag_item .= ul_start();
+ $tag_item .= leaf( href( l_tags_slice(),"Slice Tags"));
+ $tag_item .= leaf( href( l_tags_interface(),"Interface Tags"));
+ $tag_item .= leaf( href (l_tags_interface(),"Setting Types (dup xxx)"));
+ $tag_item .= leaf( href( l_tags_node(),"Node Tags"));
+ $tag_item .= leaf( href( l_nodegroups(),"Node groups (xxx)"));
+ $tag_item .= ul_end();
+ $items [] = expanded($tag_item);
}
-
+
+ $doc_item = '';
+ $doc_item .= href(l_about(),'About MyPLC');
+ $doc_item .= ul_start();
+ $doc_item .= leaf ( href (l_doc_plcapi(),"PLCAPI doc"));
+ $doc_item .= leaf ( href (l_doc_nmapi(),"NMAPI doc"));
+ $doc_item .= ul_end();
+ $items[] = expanded($doc_item);
if ( $is_admin )
- $items[] = l(t('Peers'),'db/peers/');
-
- if ( $is_admin )
- $items[] = l(t('Events'),'db/events/');
+ $items[] = leaf (href(l_events(),'Events'));
- $items[] = l(t('About'),'db/about.php');
-
if ($user->uid) {
// Drupal logout (destroys the session and cleans up $user)
- $items[] = l(t('Log out of %s', array('%s' => variable_get('site_name', 'local'))), 'logout');
+ // Thierry unclear when this triggers, I suspect this is obsolete
+ $items[] = leaf (l(t('Log out of %s',
+ array('%s' => variable_get('site_name', 'local'))), 'logout'));
} else {
// PlanetLab logout (just destroy the session)
- $items[] = l(t('Log out'), 'planetlab/logout');
+ $items[] = leaf ( href (l_logout(),'Log out'));
}
-
- $block['content'] = theme('item_list', $items);
+
+ //$block['content'] = theme('list_item', $items);
+ $block['content'] = menu_theme($items);
+ // plc_debug("content",$block['content']);
}
/*
drupal_goto(NULL, 'time='. time());
}
-function planetlab_user($type, &$edit, &$user, $category = NULL)
-{
+function planetlab_user($type, &$edit, &$user, $category = NULL) {
switch ($type) {
case 'logout':
if ($plc->person) {
}
}
-function planetlab_page()
-{
+function planetlab_page() {
$path = $_SERVER['DOCUMENT_ROOT'] . preg_replace('/^db\//', '/planetlab/', $_GET['q']);
// error_log("Requested " . $_GET['q'] . " -> $path");
drupal_not_found();
}
-function theme_planetlab($content)
-{
+function theme_planetlab($content) {
return $content;
}
<?php
// $Id$
- //
// Require login
require_once 'plc_login.php';
//// Print header
require_once 'plc_drupal.php';
-//set default title
-drupal_set_title('Events');
-
include 'plc_header.php';
// Common functions
require_once 'plc_functions.php';
require_once 'plc_sorts.php';
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
+// needs much memory
+ini_set("memory_limit","128M");
+
+//set default title
+drupal_set_title('Events');
// paginate unit
$page_size=30;
$messages = array ();
+////////////////////////////////////////
+// defaults for day ('j'), 3-letter month ('M') or year ('Y')
+function the_date ($key,$dateformat) {
+ if ($_GET[$key]) return $_GET[$key];
+ else return date($dateformat);
+}
+
+// fill out dates from now if not specified
+$from_d = the_date('from_d','j');
+$from_m = the_date('from_m','M');
+$from_y = the_date('from_y','Y');
+$until_d = the_date('until_d','j');
+$until_m = the_date('until_m','M');
+$until_y = the_date('until_y','Y');
+
+// create the options area from a list and the selected entry
+function dropdown_options ($array,$selected) {
+ $result="";
+ foreach ($array as $item) {
+ $result.= "<option value=" . $item;
+ if ($item == $selected) $result .= ' selected=selected';
+ $result .= '>' . $item . '</option>';
+ }
+ return $result;
+}
+
+$days=range(1,31);
+$from_d_dropdown_options=dropdown_options($days,$from_d);
+$until_d_dropdown_options=dropdown_options($days,$until_d);
+$months=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
+$from_m_dropdown_options=dropdown_options($months,$from_m);
+$until_m_dropdown_options=dropdown_options($months,$until_m);
+// only propose years ranging from now + 3 full years back
+$this_year=date('Y');
+$years=range($this_year-3,$this_year);
+$from_y_dropdown_options=dropdown_options($years,$from_y);
+$until_y_dropdown_options=dropdown_options($years,$until_y);
+
$event_form = <<< EOF
<form method=get name='F' action='/db/events/index.php' >
</td></tr>
-<tr><th>FROM</th> <th>UNTIL</th> </tr>
+<tr><th>FROM (inclusive)</th> <th>UNTIL (inclusive)</th> </tr>
<tr>
<td>
- <SELECT NAME='from_d' >
- <OPTION>
- <OPTION VALUE=' 1' >1
- <OPTION VALUE=' 2' >2
- <OPTION VALUE=' 3' >3
- <OPTION VALUE=' 4' >4
- <OPTION VALUE=' 5' >5
- <OPTION VALUE=' 6' >6
- <OPTION VALUE=' 7' >7
- <OPTION VALUE=' 8' >8
- <OPTION VALUE=' 9' >9
- <OPTION VALUE=' 10' >10
- <OPTION VALUE=' 11' >11
- <OPTION VALUE=' 12' >12
- <OPTION VALUE=' 13' >13
- <OPTION VALUE=' 14' >14
- <OPTION VALUE=' 15' >15
- <OPTION VALUE=' 16' >16
- <OPTION VALUE=' 17' >17
- <OPTION VALUE=' 18' >18
- <OPTION VALUE=' 19' >19
- <OPTION VALUE=' 20' >20
- <OPTION VALUE=' 21' >21
- <OPTION VALUE=' 22' >22
- <OPTION VALUE=' 23' >23
- <OPTION VALUE=' 24' >24
- <OPTION VALUE=' 25' >25
- <OPTION VALUE=' 26' >26
- <OPTION VALUE=' 27' >27
- <OPTION VALUE=' 28' >28
- <OPTION VALUE=' 29' >29
- <OPTION VALUE=' 30' >30
- <OPTION VALUE=' 31' >31
+ <SELECT NAME='from_d'>
+$from_d_dropdown_options
</SELECT>
-
<SELECT NAME='from_m' >
- <OPTION>
- <OPTION VALUE=' Jan' >January
- <OPTION VALUE=' Feb' >February
- <OPTION VALUE=' Mar' >March
- <OPTION VALUE=' Apr' >April
- <OPTION VALUE=' May' >May
- <OPTION VALUE=' Jun' >June
- <OPTION VALUE=' Jul' >July
- <OPTION VALUE=' Aug' >August
- <OPTION VALUE=' Sep' >September
- <OPTION VALUE=' Oct' >October
- <OPTION VALUE=' Nov' >November
- <OPTION VALUE=' Dec' >December
+$from_m_dropdown_options
</SELECT>
-
<SELECT NAME='from_y' >
- <OPTION>
- <OPTION VALUE='2006' >2006
- <OPTION VALUE='2007' >2007
- <OPTION VALUE='2008' >2008
- <OPTION VALUE='2009' >2009
- <OPTION VALUE='2010' >2010
- <OPTION VALUE='2011' >2011
+$from_y_dropdown_options
</SELECT>
-
</td>
<TD>
<SELECT NAME=' until_d' >
- <OPTION>
- <OPTION VALUE='1' >1
- <OPTION VALUE='2' >2
- <OPTION VALUE='3' >3
- <OPTION VALUE='4' >4
- <OPTION VALUE='5' >5
- <OPTION VALUE='6' >6
- <OPTION VALUE='7' >7
- <OPTION VALUE='8' >8
- <OPTION VALUE='9' >9
- <OPTION VALUE='10' >10
- <OPTION VALUE='11' >11
- <OPTION VALUE='12' >12
- <OPTION VALUE='13' >13
- <OPTION VALUE='14' >14
- <OPTION VALUE='15' >15
- <OPTION VALUE='16' >16
- <OPTION VALUE='17' >17
- <OPTION VALUE='18' >18
- <OPTION VALUE='19' >19
- <OPTION VALUE='20' >20
- <OPTION VALUE='21' >21
- <OPTION VALUE='22' >22
- <OPTION VALUE='23' >23
- <OPTION VALUE='24' >24
- <OPTION VALUE='25' >25
- <OPTION VALUE='26' >26
- <OPTION VALUE='27' >27
- <OPTION VALUE='28' >28
- <OPTION VALUE='29' >29
- <OPTION VALUE='30' >30
- <OPTION VALUE='31' >31
+$until_d_dropdown_options
</SELECT>
<SELECT NAME=' until_m' >
- <OPTION>
- <OPTION VALUE='Jan' >January
- <OPTION VALUE='Feb' >February
- <OPTION VALUE='Mar' >March
- <OPTION VALUE='Apr' >April
- <OPTION VALUE='May' >May
- <OPTION VALUE='Jun' >June
- <OPTION VALUE='Jul' >July
- <OPTION VALUE='Aug' >August
- <OPTION VALUE='Sep' >September
- <OPTION VALUE='Oct' >October
- <OPTION VALUE='Nov' >November
- <OPTION VALUE='Dec' >December
+$until_m_dropdown_options
</SELECT>
-
<SELECT NAME=' until_y' >
- <OPTION>
- <OPTION VALUE='2006' >2006
- <OPTION VALUE='2007' >2007
- <OPTION VALUE='2008' >2008
- <OPTION VALUE='2009' >2009
- <OPTION VALUE='2010' >2010
- <OPTION VALUE='2011' >2011
+$until_y_dropdown_options
</SELECT>
</td></tr>
//plc_debug('GET',$_GET);
-if ( !in_array ('10', $_roles)) {
+if ( ! plc_is_admin()) {
echo "<div class='plc-warning'> You need admin role to see this page. </div>";
- } else if (!$_GET['type']) {
-
- echo "<h2>What events would you like to consult :</h2>";
+ } else if (! $_GET['type']) {
+ echo "<h2>Select the events to focus on :</h2>";
// print the selection frame
echo $event_form;
// handle dates
list($from_date,$from_time,$until_date,$until_time) = parse_dates ();
+ // add one day to until_time - otherwise this corresponds to 0:0
+ $until_time += (24*60*60);
if ( ($from_time != 0) && ($until_time != 0) && ($from_time > $until_time) ) {
$messages[] = "Warning - wrong date selection";
}
$filter=array();
+ // sort events by time is not good enough, let's use event_id
+ $filter['-SORT']='event_id';
if ($from_time != 0) {
$filter[']time']=$from_time;
}
}
// Show messages
- if (!empty($messages)) {
- print '<div class="messages plc-warning"><ul>';
- foreach ($messages as $line) {
- print "<li> $line";
- }
- print "</ul></div>";
- }
+ if (!empty($messages))
+ foreach ($messages as $line)
+ drupal_set_message($line);
if ( ! empty ($events)) {
$events= array_map(layout,$events);
// will trash this eventually
require_once 'plc_functions_trash.php';
+//////////////////////////////////////////////////////////// roles & other checks on global $plc
+function plc_is_admin () {
+ global $plc;
+ return in_array( 10, $plc->person['role_ids']);
+}
+function plc_is_pi () {
+ global $plc;
+ return in_array( 20, $plc->person['role_ids']);
+}
+function plc_is_tech () {
+ global $plc;
+ return in_array( 40, $plc->person['role_ids']);
+}
+function plc_in_site ($site_id) {
+ global $plc;
+ return in_array( $site_id, $plc->person['site_ids']);
+}
+
+function plc_my_site_id () {
+ global $plc;
+ return $plc->person['site_ids'][0];
+}
+
+function plc_my_person_id () {
+ global $plc;
+ return $plc->person['person_id'];
+}
+
+//////////////////////////////////////////////////////////// links
+function href ($url,$text) { return "<a href='" . $url . "'>" . $text . "</a>"; }
+
+function l_nodes () { return "/db/nodes/index.php"; }
+function l_node_u ($node_id) { return "/db/nodes/node.php?id=" . $node_id; }
+function l_node ($node_id) { return href (l_node_u($node_id),$node_id); }
+function l_node2 ($node_id,$text) { return href (l_node_u($node_id),$text); }
+function l_nodes_site ($site_id) { return "/db/nodes/index.php?site_id=" . $site_id; }
+function l_node_add () { return "/db/nodes/add_node.php"; }
+
+function l_interface_u ($interface_id) { return "/db/nodes/interfaces.php?id=" . $interface_id; }
+function l_interface_add_u($node_id) { return "/db/nodes/interfaces.php?node_id=" . $node_id; }
+function l_interface ($interface_id) { return href (l_interface_u($interface_id),$interface_id); }
+function l_interface2 ($interface_id,$text) { return href (l_interface_u($interface_id),$text); }
+
+function l_sites () { return "/db/sites/index.php"; }
+function l_site_u ($site_id) { return "/db/persons/index.php?id=" . $site_id; }
+function l_site ($site_id) { return href (l_site_u($site_id),$site_id); }
+function l_site2 ($site_id,$text) { return href (l_site_u($site_id),$text); }
+
+function l_slices () { return "/db/slices/index.php"; }
+function l_slice_u ($slice_id) { return "/db/slices/index.php?id=" . $slice_id; }
+function l_slice ($slice_id) { return href (l_slice_u($slice_id),$slice_id); }
+function l_slice2 ($slice_id,$text) { return href (l_slice_u($slice_id),$text); }
+function l_slice_add () { return "/db/slices/add_slice.php"; }
+
+function l_sliver_u ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=" . $node_id. "&slice_id=" . $slice_id; }
+function l_sliver3 ($node_id,$slice_id,$text) { return href (l_sliver_u($node_id,$slice_id),$text) ; }
+
+function l_persons () { return "/db/persons/index.php"; }
+function l_persons_site ($site_id) { return "/db/persons/index.php?site_id=" . $site_id; }
+function l_person_u ($person_id) { return "/db/persons/index.php?id=" . $person_id; }
+function l_person ($person_id) { return href (l_person_u($person_id),$person_id); }
+function l_person2 ($person_id,$text) { return href (l_person_u($person_id),$text); }
+
+function l_tags () { return "/db/tags/index.php"; }
+function l_tags_node () { return "/db/tags/index.php?type=node"; }
+# xxx cleanup duplicate pages
+#function l_tags_interface () { return "/db/tags/index.php?type=interface"; }
+function l_tags_interface () { return "/db/nodes/settings.php"; }
+function l_tags_slice () { return "/db/tags/index.php?type=slice"; }
+
+function l_nodegroups () { return "/db/tags/node_groups.php"; }
+function l_nodegroup_u ($nodegroup_id) { return "/db/tags/node_groups.php?id=" . $nodegroup_id; }
+function l_nodegroup2 ($nodegroup_id,$text) { return href(l_nodegroup_u($nodegroup_id),$text); }
+
+function l_events () { return '/db/events/index.php'; }
+function l_event ($type,$param,$id) { return '/db/events/index.php?type=' . $type . '&' . $param . '=' . $id; }
+
+function l_peers() { return "/db/peers/index.php"; }
+function l_peer_u($peer_id) { return "/db/peers/index.php?id=" . $peer_id; }
+function l_comon($id_name,$id_value) { return '/db/nodes/comon.php?' . $id_name . "=" . $id_value; }
+function l_sirius() { return "/db/sirius/index.php"; }
+function l_about() { return "/db/about.php"; }
+function l_doc_plcapi() { return "/db/doc/PLCAPI.php"; }
+function l_doc_nmapi() { return "/db/doc/NMAPI.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"; }
+function l_person_register() { return "/db/persons/register.php"; }
+function l_site_register() { return "/db/sites/register.php"; }
+function l_site_pending() { return "/db/sites/join_request.php"; }
+function l_site_status() { return "/db/sites/peers.php"; }
+
//////////////////////////////////////////////////////////// validation functions
function topdomain ($hostname) {
$exploded=array_reverse(explode(".",$hostname));
return false;
}
-//////////////////////////////////////////////////////////// roles & other checks on global $plc
-function plc_is_admin () {
- global $plc;
- return in_array( 10, $plc->person['role_ids']);
-}
-function plc_is_pi () {
- global $plc;
- return in_array( 20, $plc->person['role_ids']);
-}
-function plc_is_tech () {
- global $plc;
- return in_array( 40, $plc->person['role_ids']);
-}
-function plc_in_site ($site_id) {
- global $plc;
- return in_array( $site_id, $plc->person['site_ids']);
-}
-
-function plc_my_site_id () {
- global $plc;
- return $plc->person['site_ids'][0];
-}
-
//////////////////////////////////////////////////////////// peer & peerscopes
// when shortnames are needed on peers
function plc_peer_get_hash ($api) {
return array ($peer_filter,$peer_label);
}
-//////////////////////////////////////////////////////////// links
-function href ($url,$text) { return "<a href='" . $url . "'>" . $text . "</a>"; }
-
-function l_nodes () { return "/db/nodes/index.php"; }
-function l_nodes_site ($site_id) { return "/db/nodes/index.php?site_id=" . $site_id; }
-function l_node_u ($node_id) { return "/db/nodes/node.php?id=" . $node_id; }
-function l_node ($node_id) { return href (l_node_u($node_id),$node_id); }
-function l_node2 ($node_id,$text) { return href (l_node_u($node_id),$text); }
-
-function l_interface_u ($interface_id) { return "/db/nodes/interfaces.php?id=" . $interface_id; }
-function l_interface_add_u($node_id) { return "/db/nodes/interfaces.php?node_id=" . $node_id; }
-function l_interface ($interface_id) { return href (l_interface_u($interface_id),$interface_id); }
-function l_interface2 ($interface_id,$text) { return href (l_interface_u($interface_id),$text); }
-
-function l_nodegroup_u ($nodegroup_id) { return "/db/nodes/node_groups.php?id=" . $nodegroup_id; }
-function l_nodegroup2 ($nodegroup_id,$text) { return href(l_nodegroup_u($nodegroup_id),$text); }
-
-function l_sites () { return "/db/sites/index.php"; }
-function l_site_u ($site_id) { return "/db/persons/index.php?id=" . $site_id; }
-function l_site ($site_id) { return href (l_site_u($site_id),$site_id); }
-function l_site2 ($site_id,$text) { return href (l_site_u($site_id),$text); }
-
-function l_slices () { return "/db/slices/index.php"; }
-function l_slice_u ($slice_id) { return "/db/slices/index.php?id=" . $slice_id; }
-function l_slice ($slice_id) { return href (l_slice_u($slice_id),$slice_id); }
-function l_slice2 ($slice_id,$text) { return href (l_slice_u($slice_id),$text); }
-
-function l_sliver_u ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=" . $node_id. "&slice_id=" . $slice_id; }
-function l_sliver3 ($node_id,$slice_id,$text) { return href (l_sliver_u($node_id,$slice_id),$text) ; }
-
-function l_persons () { return "/db/persons/index.php"; }
-function l_person_u ($person_id) { return "/db/persons/index.php?id=" . $person_id; }
-function l_person ($person_id) { return href (l_person_u($person_id),$person_id); }
-function l_person2 ($person_id,$text) { return href (l_person_u($person_id),$text); }
-
-function l_event ($type,$param,$id) { return '/db/events/index.php?type=' . $type . '&' . $param . '=' . $id; }
-function l_comon($id_name,$id_value) { return '/db/nodes/comon.php?' . $id_name . "=" . $id_value; }
-
-function l_logout() { return "/planetlab/logout.php"; }
-
//////////////////////////////////////////////////////////// titles
function t_site($site) { return " on site " . $site['name'] . " (" . $site['login_base'] .")"; }
function t_slice ($slice) { return " running slice " . $slice['name'] . " (" . $slice['slice_id'] . ")"; }
// table_id: <table>'s id tag
// headers: an associative array "label"=>"type"
// column_sort: the column to sort on at load-time
-// search_area : boolean
-// pagesize: the initial pagination size
-// pagesize_def: the page size when one clicks the pagesize reset button
-// max_pages: the max number of pages to display in the paginator
+// options : an associative array to override options:
+// - search_area : boolean
+// - pagesize: the initial pagination size
+// - pagesize_def: the page size when one clicks the pagesize reset button
+// - max_pages: the max number of pages to display in the paginator
function plc_table_start ($table_id, $headers, $column_sort,
- $search_area=true,$max_pages="10",$pagesize="25",$pagesize_def="999") {
+ $options=array()) {
+ $search_area= array_key_exists('search_area',$options) ? $options['search_area'] : true;
+ $max_pages= array_key_exists('max_pages',$options) ? $options['max_pages'] : 10;
+ $pagesize= array_key_exists('pagesize',$options) ? $options['pagesize'] : 25;
+ $pagesize_def= array_key_exists('pagesize_def',$options) ? $options['pagesize_def'] : 999;
+
if ($search_area) {
plc_table_search_area($table_id,$pagesize,$pagesize_def);
}
$classname.=" paginate-" . $pagesize;
print <<< EOF
<!-- instantiate paginator callback -->
-<script type"text/javascript">
+<script type="text/javascript">
function $paginator (opts) { plc_table_paginator (opts,"$table_id"); }
</script>
<br/>
if ($type == "int") $type="";
if ($type == "float") $type="";
$class="sortable";
- if ( ! empty($type)) $class .= "-" . $type;
+ if ( ! empty($type)) $class .= "-sort" . $type;
print '<th class="' . $class . ' plc_table">' . $label . "</th>\n";
}
// Common functions
require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
// if not a admin, pi, or tech then redirect to node index
// xxx does not take site into account
// Print header
require_once 'plc_drupal.php';
-drupal_set_title('Nodes');
include 'plc_header.php';
?>
if ( $success ) {
$link=l_node2($node_id,"here");
+ drupal_set_title('Node created');
print <<< EOF
-<h2>Node Created</h2>
<p>The node has been successfully added.
file $link.
EOF;
} else {
+ $sites=$api->GetSites(array(plc_my_site_id()));
+ $sitename=$sites[0]['name'];
+
+ drupal_set_title('Add a new node in site "' . $sitename . '"');
print <<< EOF
-<h2>Add A New Node</h2>
<p>This page will allow you to add a new machine to your site. This must
be done before the machine is turned on, as it will allow you to download
plc_details_end ();
+ //////////////////////////////////////////////////////////// slices
+ // display slices
+
+ print "<hr/>\n";
+ plc_table_title ("Slices");
+ if ( ! $slices ) {
+ echo "<p><span class='plc-warning'>This node is not associated to any slice.</span></p>\n";
+ } else {
+ $columns=array();
+ $columns['Peer']="string";
+ $columns['Name']="string";
+ $columns['Slivers']="string";
+ plc_table_start ("slivers",$columns,1);
+
+ foreach ($slices as $slice) {
+ plc_table_row_start($slice['name']);
+ plc_table_cell (plc_peer_shortname($peer_hash,$slice['peer_id']));
+ plc_table_cell (l_slice2 ($slice['slice_id'],$slice['name']));
+ plc_table_cell (l_sliver3 ($node_id,$slice['slice_id'],'view'));
+ plc_table_row_end();
+ }
+ plc_table_end();
+ }
+
//////////////////////////////////////////////////////////// interfaces
if ( ! $peer_id ) {
print "<hr/>\n";
plc_table_title('Interfaces');
- plc_table_start("interfaces",$columns,2,false);
+ plc_table_start("interfaces",$columns,2,array('search_area'=>false));
foreach ( $interfaces as $interface ) {
$interface_id= $interface['interface_id'];
}
- //////////////////////////////////////////////////////////// slices
- // display slices
-
- print "<hr/>\n";
- plc_table_title ("Slices");
- if ( ! $slices ) {
- echo "<p><span class='plc-warning'>This node is not associated to any slice.</span></p>\n";
- } else {
- $columns=array();
- $columns['Peer']="string";
- $columns['Name']="string";
- $columns['Slivers']="string";
- plc_table_start ("slivers",$columns,1);
-
- foreach ($slices as $slice) {
- plc_table_row_start($slice['name']);
- plc_table_cell (plc_peer_shortname($peer_hash,$slice['peer_id']));
- plc_table_cell (l_slice2 ($slice['slice_id'],$slice['name']));
- plc_table_cell (l_sliver3 ($node_id,$slice['slice_id'],'view'));
- plc_table_row_end();
- }
- plc_table_end();
- }
-
//////////////////////////////////////////////////////////// nodegroups
// display node group info
if ( ! $nodegroups ) {
print "<hr/>\n";
plc_table_title("Nodegroups");
- plc_table_start("nodegroups",$columns,0,false);
+ plc_table_start("nodegroups",$columns,0,array('search_area'=>false));
foreach( $nodegroups as $nodegroup ) {
plc_table_row_start();
<?php
+// $Id: index.php 11603 2009-01-19 16:44:53Z thierry $
+
// Require login
require_once 'plc_login.php';
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-// Print header
-require_once 'plc_drupal.php';
-drupal_set_title('All Peers');
-include 'plc_header.php';
-
-// Common functions
-require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
-
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
-
-// layout : add a comon link
-function layout_peer ($peer) {
- $peer['comon'] = plc_comon_button("peer_id",$peer['peer_id']);
- return $peer;
-}
-
-
-// if peer_host is set then set id to that peer's id.
-if( $_POST['peername'] ) {
- $peername= $_POST['peername'];
-
- $peer_info= $api->GetPeers( array( $peername ), array( "peer_id" ) );
-
- header( "location: index.php?id=". $peer_info[0]['peer_id'] );
- exit();
-
-}
-
-if( !$_GET['id'] ) {
-
- // GetPeers API call
- $peers = $api->GetPeers( NULL, array("peer_id","peername","peer_url"));
-
- $local_peer_comon = plc_comon_button("peer_id","0");
- echo "<p> See all local nodes through comon " . $local_peer_comon . " </p>";
-
- if ( empty($peers)) {
- echo "No known peer - standalone deployment";
- } else {
-
- $peers = array_map(layout_peer,$peers);
- sort_peers( $peers );
-
- echo "<div>";
- // xxx Thierry : mimicking what was done for nodes - not sure that makes sense here
- if( $peername )
- echo "<span class='plc-warning'> $peername is not a valid peer.</span>\n";
-
- echo paginate( $peers, "peer_id", "Peers", 10, "peername" );
- }
-
-} else {
- // get the peer id from the URL
- $peer_id= intval( $_GET['id'] );
-
- // make the api call to pull that peers DATA
- $peer_info= $api->GetPeers( array( $peer_id ) );
-
- // peer info
- $peername= $peer_info[0]['peername'];
- $peer_url= $peer_info[0]['peer_url'];
- // arrays of ids of peer info
- $number_nodes= sizeof($peer_info[0]['node_ids']);
- $number_slices= sizeof($peer_info[0]['slice_ids']);
- $number_persons= sizeof($peer_info[0]['person_ids']);
- $number_sites= sizeof($peer_info[0]['site_ids']);
-
- // get peer id
- $peer_id= $peer_info[0]['peer_id'];
-
- drupal_set_title("Details for Peer " . $peername);
-
- echo "<table><tbody>\n";
- echo "<tr><th>Peer name </th>";
- echo "<td> $peername </td></tr>";
- echo "<tr><th>API url </th>";
- echo "<td> $peer_url </td></tr>";
- echo "<tr><th> # nodes </th>";
- echo "<td> $number_nodes </td></tr>";
- echo "<tr><th> # slices </th>";
- echo "<td> $number_slices </td></tr>";
- echo "<tr><th> # sites </th>";
- echo "<td> $number_sites </td></tr>";
- echo "<tr><th> # persons </th>";
- echo "<td> $number_persons </td></tr>";
- echo "</tbody></table>\n";
-}
-
-echo "<br /><p><a href='index.php'>Back to peer list</a>";
-echo "</div>";
-
-
-// Print footer
-include 'plc_footer.php';
+if ($_GET['id']) require ('peer.php') ;
+else require ('peers.php');
?>
--- /dev/null
+<?php
+
+// Require login
+require_once 'plc_login.php';
+
+// Get session and API handles
+require_once 'plc_session.php';
+global $plc, $api;
+
+// Print header
+require_once 'plc_drupal.php';
+include 'plc_header.php';
+
+// Common functions
+require_once 'plc_functions.php';
+require_once 'plc_details.php';
+require_once 'plc_minitabs.php';
+
+$tabs=array();
+$tabs['Back to peers list']=l_peers();
+plc_tabs ($tabs);
+
+// --------------------
+// recognized URL arguments
+if ( $_GET['peername'] ) {
+ $peername= $_GET['peername'];
+ $peers = $api->GetPeers( array( $peername ), array( "peer_id" ) );
+ $peer_id=$peers[0]['peer_id'];
+
+ } else {
+ $peer_id=intval($_GET['id']);
+ }
+
+if ( ! $peer_id ) { plc_error('Malformed URL - id not set'); return; }
+
+// make the api call to pull that peers DATA
+$peers= $api->GetPeers( array( $peer_id ) );
+$peer = $peers[0];
+
+drupal_set_title("Details for Peer " . $peername);
+
+plc_details_start();
+plc_details_line("Peer name",$peer['peername']);
+plc_details_line("Short name",$peer['shortname']);
+plc_details_line("Hierarchical name","not implemented yet");
+plc_details_line("API URL",$peer['peer_url']);
+
+plc_details_line("Number of sites",sizeof($peer['site_ids']));
+plc_details_line("Number of nodes",sizeof($peer['node_ids']));
+plc_details_line("Number of persons",sizeof($peer['person_ids']));
+plc_details_line("Number of slices",sizeof($peer['slice_ids']));
+plc_details_end();
+
+// Print footer
+include 'plc_footer.php';
+
+?>
--- /dev/null
+<?php
+
+// Require login
+require_once 'plc_login.php';
+
+// Get session and API handles
+require_once 'plc_session.php';
+global $plc, $api;
+
+// Print header
+require_once 'plc_drupal.php';
+include 'plc_header.php';
+
+// Common functions
+require_once 'plc_functions.php';
+require_once 'plc_tables.php';
+require_once 'plc_minitabs.php';
+
+drupal_set_title('All Peers');
+
+
+// GetPeers API call
+// xxx no HRN yet
+$peers = $api->GetPeers( NULL, array("peer_id","peername","shortname","peer_url"));
+
+$tabs=array();
+$tabs['Comon for all nodes']=l_comon("peer_id","0");
+plc_tabs($tabs);
+
+if ( empty($peers)) {
+ drupal_set_message ("You seem to be running a standalone deployment");
+ } else {
+
+ $columns=array( 'Name'=>'string',
+ 'SN' =>'string',
+ 'HRN' => 'string',
+ 'URL'=>'string',
+ 'Comon'=>'string');
+
+ plc_table_start ("peers",$columns,1);
+ foreach ($peers as $peer) {
+ plc_table_row_start();
+ plc_table_cell (href(l_peer_u($peer['peer_id']),$peer['peername']));
+ plc_table_cell ($peer['shortname']);
+// xxx no HRN yet
+ plc_table_cell ('?');
+ plc_table_cell ($peer['peer_url']);
+ plc_table_cell (href(l_comon("peer_id",$peer['peer_id']),'Comon'));
+ plc_table_row_end();
+ }
+ }
+
+// Print footer
+include 'plc_footer.php';
+
+?>