From 6f26004ce994fbfde02c70a12a8615f10c610a55 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 27 Jan 2009 21:28:58 +0000 Subject: [PATCH] persons and events use plc_tables; person relifted, person_actions need work --- planetlab/css/plc_tables.css | 10 - planetlab/events/index.php | 227 +++++++++++++-------- planetlab/includes/plc_functions.php | 7 +- planetlab/includes/plc_functions_trash.php | 16 -- planetlab/includes/plc_tables.php | 28 ++- planetlab/persons/person.php | 7 + planetlab/persons/persons.php | 2 +- 7 files changed, 171 insertions(+), 126 deletions(-) diff --git a/planetlab/css/plc_tables.css b/planetlab/css/plc_tables.css index b5cc03b..2fad1f2 100644 --- a/planetlab/css/plc_tables.css +++ b/planetlab/css/plc_tables.css @@ -220,13 +220,3 @@ p.plc_filter_note { font-family: georgia; text-align: center } - - diff --git a/planetlab/events/index.php b/planetlab/events/index.php index 6899f66..5c8db26 100644 --- a/planetlab/events/index.php +++ b/planetlab/events/index.php @@ -14,10 +14,11 @@ include 'plc_header.php'; // Common functions require_once 'plc_functions.php'; -require_once 'plc_sorts.php'; +require_once 'plc_tables.php'; +require_once 'plc_minitabs.php'; // needs much memory -ini_set("memory_limit","128M"); +ini_set("memory_limit","256M"); //set default title drupal_set_title('Events'); @@ -27,7 +28,8 @@ $page_size=30; $messages = array (); -//////////////////////////////////////// +//////////////////////////////////////////////////////////// form + // defaults for day ('j'), 3-letter month ('M') or year ('Y') function the_date ($key,$dateformat) { if ($_GET[$key]) return $_GET[$key]; @@ -129,6 +131,7 @@ $until_y_dropdown_options EOF; +//////////////////////////////////////////////////////////// dates function parse_date ($day,$month,$year) { // if everything empty -> unspecified date, return 0 if ( empty($day) && empty($month) && empty($year)) { @@ -154,6 +157,7 @@ function my_is_int ($x) { return (is_numeric($x) ? intval($x) == $x : false); } +//////////////////////////////////////////////////////////// layout function truncate ($text,$numb,$etc = "...") { if (strlen($text) > $numb) { $text = substr($text, 0, $numb); @@ -162,58 +166,67 @@ function truncate ($text,$numb,$etc = "...") { return $text; } -// layout function to refine a row's content -function layout ($param){ - - // format time - $time=$param['time']; - $date= date('d M Y H:i' ,$time); - $param['time']=$date; - - // the call button - $message=htmlentities($param['message'], ENT_QUOTES); - $call=htmlentities($param['call'], ENT_QUOTES); - $detail_text=sprintf("message=<<%s>>\\n\\ncall=<<%s>>\\n\\nruntime=<<%f>>\\n",$message,$call,$param['runtime']); - $detail="%s',$call,$detail); - $param['call_name']=$detail; - unset ($param['call']); +// outline node ids and person ids with a link +function e_node ($node_id) { + if (! $node_id) return ""; + return l_node_t($node_id,$node_id); +} +function e_person ($person_id) { + if (! $person_id) return ""; + return l_person_t($person_id,$person_id); +} +// xxx broken +function e_event ($event_id) { + if (! $event_id) return ""; + return href(l_event("Event","event",$event_id),$event_id); +} - // the message button - $trunc_mess=htmlentities(truncate($param['message'],40),ENT_QUOTES); - $detail="%s',$message,$detail); - $param['message']=$detail; - - // shrink column name : event_id -> id - paginate_id used in paginate and does not show up - $param['id']=$param['event_id'] ; - // so that event_id shows up - $param['paginate_id']=$param['event_id']; unset($param['event_id']); - - //// shrink column names - $param['fault']=$param['fault_code'] ; unset($param['fault_code']); - // seem empty on all rows - probably something that I screwed when importing tony's stuff - // $param['oty']=$param['object_type'] ; unset($param['object_type']); - // $param['oid']=$param['object_id'] ; unset($param['object_id']); - $param['otys']=$param['object_types'] ; unset($param['object_types']); - $param['oids']=$param['object_ids'] ; unset($param['object_ids']); - $param['nid']=plc_node_link($param['node_id']) ; unset($param['node_id']); - $param['pid']= plc_person_link($param['person_id']) ; unset($param['person_id']); - if (array_key_exists('auth_type',$param)) { - $param['at']=$param['auth_type'] ; unset($param['auth_type']); +function e_link ($type,$id) { + $mess=$type . " " . $id; + switch ($type) { + case 'Node': return l_node_t ($id,$mess); + case 'Site': return l_site_t ($id,$mess); + case 'Person': return l_person_t ($id,$mess); + case 'Slice': return l_slice_t ($id,$mess); + case 'Role': case 'Key': case 'PCU': case 'Interface': case 'NodeGroup': + return "$mess"; + default: return "Unknown $type" . "-" . $id; } +} + +// synthesize links to the subject objects from types and ids +function e_subjects ($param) { + $types=$param['object_types']; + $ids=$param['object_ids']; + if ( ! $types) return ""; + return plc_vertical_table(array_map ("e_link",$types,$ids)); +} + +function e_issuer ($param) { + if ($param['node_id']) return e_link('Node',$param['node_id']); + if ($param['person_id']) return e_link('Person',$param['person_id']); + return '???'; +} + +function e_auth ($event) { + if (array_key_exists('auth_type',$event)) + return $event['auth_type']; + else + return ""; +} - // clears - unset($param['object_type']); - unset($param['object_id']); - unset($param['runtime']); - return $param; +function e_fault ($event) { + $f=$event['fault_code']; + if ($f==0) return "OK"; + else return $f; } -//plc_debug('GET',$_GET); +//////////////////////////////////////////////////////////// +// for convenience, add 1 day to the 'until' date as otherwise this corresponds to 0:00 +$STEP=24*60*60; if ( ! plc_is_admin()) { - echo "
You need admin role to see this page.
"; + plc_warning("You need admin role to see this page."); } else if (! $_GET['type']) { echo "

Select the events to focus on :

"; @@ -222,21 +235,25 @@ if ( ! plc_is_admin()) { } else { + $tabs=array(); + $tabs['Back to events form']=l_events(); + plc_tabs($tabs); + // 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"; + $until_time += $STEP; + if ( ($from_time != 0) && ($until_time != $STEP) && ($from_time > $until_time) ) { + $messages[] = "Warning - is after "; } $filter=array(); // sort events by time is not good enough, let's use event_id - $filter['-SORT']='event_id'; + $filter['-SORT']='-event_id'; if ($from_time != 0) { $filter[']time']=$from_time; } - if ($until_time != 0) { + if ($until_time != $STEP) { $filter['[time']=$until_time; } @@ -255,26 +272,14 @@ if ( ! plc_is_admin()) { $filter[']time']=0; } $events = $api->GetEvents($filter); - if (empty($events)) { - $messages[] = "No event found - user input was [" . $user_desc . "]"; - } else { - $title="Events matching " . ($user_desc ? $user_desc : "everything"); - if ($from_time != 0) - $title .= " From " . $from_date; - if ($until_time != 0) - $title .= " Until " . $until_date; - drupal_set_title ($title); - } - - // Show messages - if (!empty($messages)) - foreach ($messages as $line) - drupal_set_message($line); - - if ( ! empty ($events)) { - $events= array_map(layout,$events); - echo paginate( $events, "paginate_id", "Events", $page_size, "event_id"); - } + $title="Events matching " . ($user_desc ? $user_desc : "everything"); + if ($from_time != 0) + $title .= " From " . $from_date; + if ($until_time != $STEP) + $title .= " Until " . $until_date; + + // see actual display of $title and $events below + } else { switch ($type) { @@ -336,25 +341,71 @@ if ( ! plc_is_admin()) { } } } - - // Show messages - if (!empty($messages)) { - print '
    '; - foreach ($messages as $line) { - print "
  • $line"; - } - print "
"; - } - - drupal_set_title($title); - $events = $api->GetEventObjects(array('object_id'=>$object_ids,'object_type'=>$object_type)); - $events=array_map(layout,$events); - echo paginate( $events, "paginate_id", "--------" . $type . " EVENTS---------", $page_size, "hostname"); + $event_objs = $api->GetEventObjects(array('object_id'=>$object_ids,'object_type'=>$object_type),array('event_id')); + // get set of event_ids + $event_ids = array_map ( create_function ('$eo','return $eo["event_id"];') , $event_objs); + + $events = $api->GetEvents (array('event_id'=>$event_ids)); + + // see actual display of $title and $events below + + } + + drupal_set_title ($title); + // Show messages + if (!empty($messages)) + foreach ($messages as $line) + drupal_set_message($line); + + $columns=array( + "Id"=>"int", + "Time"=>"EnglishDateTime", + "Method"=>"string", + "Message"=>"string", + "Subjects"=>"string", + "Issuer"=>"string", + "Auth"=>"string", + "R"=>"string", + "D"=>"none", + ); + + $table_options=array('notes'=>array("The R column shows the call result value, a.k.a. fault_code", + "Click the button in the D(etails) columns to get more details", + ), + 'max_pages'=>20); + plc_table_start("events",$columns,"0r",$table_options); + foreach ($events as $event) { + + // the call button + $message = htmlentities($event['message'], ENT_QUOTES); + $call = htmlentities($event['call'], ENT_QUOTES); + $text = sprintf("message=<<%s>>\\n\\ncall=<<%s>>\\n\\nruntime=<<%f>>\\n",$message,$call,$event['runtime']); + $method = "%s',$call,$method); + + // the message button + $trunc_mess=htmlentities(truncate($event['message'],40),ENT_QUOTES); + $message="%s',$message,$message); + + $message=truncate($event['message'],40); + plc_table_row_start($event['event_id']); + plc_table_cell(e_event($event['event_id'])); + plc_table_cell(date('M/d/Y H:i', $event['time'])); + plc_table_cell($event['call_name']); + plc_table_cell($message); + plc_table_cell(e_subjects($event)); + plc_table_cell(e_issuer($event)); + plc_table_cell(e_auth($event)); + plc_table_cell(e_fault($event)); + plc_table_cell($details); + plc_table_row_end(); } + plc_table_end($table_options); } -echo "

Back to Events"; // Print footer include 'plc_footer.php'; diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index f30b77d..fa28702 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -54,7 +54,7 @@ function l_interface_t ($interface_id,$text) { function l_interface_add($node_id) { return "/db/nodes/interfaces.php?node_id=" . $node_id; } function l_sites () { return "/db/sites/index.php"; } -function l_site ($site_id) { return "/db/persons/index.php?id=" . $site_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_slices () { return "/db/slices/index.php"; } @@ -330,8 +330,11 @@ function plc_errors ($list) { print( "\n" ); } +function plc_warning_div ($text) { + return "

" . $text . "
"; +} function plc_warning ($text) { - print "
Warning " . $text . "
"; + print plc_warning_div("Warning " . $text); } // shows a php variable verbatim with a heading message diff --git a/planetlab/includes/plc_functions_trash.php b/planetlab/includes/plc_functions_trash.php index 3fe1200..b4c18dd 100644 --- a/planetlab/includes/plc_functions_trash.php +++ b/planetlab/includes/plc_functions_trash.php @@ -2,22 +2,6 @@ // this will be trashed eventually -function plc_person_link ($person_id) { - if ( empty ($person_id)) { - return ""; - } else { - return '' . $person_id . ''; - } - } - -function plc_node_link ($node_id) { - if ( empty ($node_id)) { - return ""; - } else { - return '' . $node_id . ''; - } - } - // pagination function function paginate( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) { // get vars from call adjust them diff --git a/planetlab/includes/plc_tables.php b/planetlab/includes/plc_tables.php index 6fc1835..d41c15e 100644 --- a/planetlab/includes/plc_tables.php +++ b/planetlab/includes/plc_tables.php @@ -21,6 +21,7 @@ function plc_table_cell($cell) { // options : an associative array to override options (should be passed to both _stsart and _end) // - search_area : boolean (default true) // - notes_area : boolean (default true) +// - notes : an array of additional notes // - 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 @@ -39,7 +40,7 @@ function plc_table_end ($options) { plc_table_foot(); $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true; if ($notes_area) - plc_table_notes(); + plc_table_notes($options); } //////////////////// @@ -98,12 +99,16 @@ class="plc_table sortable-onload-$column_sort rowstyle-alt colstyle-alt no-arrow EOF; foreach ($headers as $label => $type) { - if ($type == "string") $type=""; - if ($type == "int") $type=""; - if ($type == "float") $type=""; - $class="sortable"; - if ( ! empty($type)) $class .= "-sort" . $type; - print '' . $label . "\n"; + if ($type == "none" ) { + $class=""; + } else { + if ($type == "string") $type=""; + if ($type == "int") $type=""; + if ($type == "float") $type=""; + $class="sortable"; + if ( ! empty($type)) $class .= "-sort" . $type; + } + printf ('%s',$class,$label); } print <<< EOF @@ -124,14 +129,19 @@ EOF; } //////////////////////////////////////// -function plc_table_notes () { +function plc_table_notes ($options) { print <<< EOF

Notes: Enter & or | in the search area to alternate between AND and OR search modes
Hold down the shift key to select multiple columns to sort -

EOF; + if (array_key_exists('notes',$options)) { + foreach ($options['notes'] as $line) { + print "
" . $line . "\n"; + } + } + print "

"; } //////////////////////////////////////// diff --git a/planetlab/persons/person.php b/planetlab/persons/person.php index 25ef6cd..de845e6 100644 --- a/planetlab/persons/person.php +++ b/planetlab/persons/person.php @@ -102,7 +102,14 @@ if (empty($persons)) { plc_tabs($tabs); + if ($privileges && ! $enabled ) + drupal_set_message ("$first_name $last_name is not enabled yet, please use the 'Enable' button below"); + + $enabled_text="Enabled"; + if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled"); + plc_details_start(); + plc_details_line("Enabled",$enabled_text); plc_details_line("First Name",$first_name); plc_details_line("Last Name",$last_name); plc_details_line("Title",$title); diff --git a/planetlab/persons/persons.php b/planetlab/persons/persons.php index dc8fbb5..89cd015 100644 --- a/planetlab/persons/persons.php +++ b/planetlab/persons/persons.php @@ -64,7 +64,7 @@ function person_status ($person) { // fetch persons -$person_columns=array('person_id','first_name','last_name','email','roles','peer_id','key_ids','site_ids'); +$person_columns=array('person_id','first_name','last_name','email','roles','peer_id','key_ids','site_ids','enabled'); // PIs and admins can see users not yet enabled $privileges=plc_is_admin() || plc_is_pi(); if ( ! $privileges ) -- 2.45.2