' . $item . ''; } 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
 Events:
 Persons:
 Nodes:
 Sites:
 Slices:
FROM (inclusive) UNTIL (inclusive)
EOF; function parse_date ($day,$month,$year) { // if everything empty -> unspecified date, return 0 if ( empty($day) && empty($month) && empty($year)) { return array ("xxx",0); } else { // fill missing fields with current value if (empty($day)) $day=date('d'); if (empty($month)) $month=date('M'); if (empty($year)) $year=date('Y'); $date=sprintf("%s %s %s",$day,$month,$year); $time=strtotime($date); return array($date,$time); } } function parse_dates () { list($from_date,$from_time) = parse_date($_GET['from_d'],$_GET['from_m'],$_GET['from_y']); list($until_date,$until_time) = parse_date($_GET['until_d'],$_GET['until_m'],$_GET['until_y']); return array($from_date,$from_time,$until_date,$until_time); } function my_is_int ($x) { return (is_numeric($x) ? intval($x) == $x : false); } function truncate ($text,$numb,$etc = "...") { if (strlen($text) > $numb) { $text = substr($text, 0, $numb); $text = $text.$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']); // 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']); } // clears unset($param['object_type']); unset($param['object_id']); unset($param['runtime']); return $param; } //plc_debug('GET',$_GET); if ( ! plc_is_admin()) { echo "
You need admin role to see this page.
"; } else if (! $_GET['type']) { echo "

Select the events to focus on :

"; // print the selection frame echo $event_form; } else { // 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; } if ($until_time != 0) { $filter['[time']=$until_time; } //////////////////////////////////////// Events $type=$_GET['type']; if ($type == 'Event') { // and the filter applied for fetching events using GetEvent $user_desc=$_GET['event']; if ( ! empty($user_desc)) { // should parse stuff like 45-90,230-3000 - some other day $filter['event_id']=intval($user_desc); } // the filter might be void here - in python we need an empty dict but that's not what we get so if (empty($filter)) { $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"); } } else { switch ($type) { case 'Person': $primary_key='person_id'; $string_key='email'; $user_input=$_GET['person']; $method="GetPersons"; $object_type='Person'; break; case 'Node': $primary_key='node_id'; $string_key='hostname'; $user_input=$_GET['node']; $method="GetNodes"; $object_type='Node'; break; case 'Site': $primary_key='site_id'; $string_key='login_base'; $user_input=$_GET['site']; $method="GetSites"; $object_type='Site'; break; case 'Slice': $primary_key='slice_id'; $string_key='name'; $user_input=$_GET['slice']; $method="GetSlices"; $object_type='Slice'; break; } $object_ids=array(); $title=sprintf('Events for type %s:',$object_type); foreach ( split(",",$user_input) as $user_desc) { # numeric if (my_is_int($user_desc)) { $obj_check = call_user_func(array($api,$method),array(intval($user_desc)),array($primary_key)); if (empty ($obj_check)) { $messages[] = "No such " . $primary_key . ": " . $user_desc; } else { $object_ids[] = $obj_check[0][$primary_key]; $title .= $user_desc . ", " ; } } else { # string $new_object_ids=call_user_func (array($api,$method), array($string_key=>$user_desc),array($primary_key,$string_key)); if (empty($new_object_ids)) { $messages[] = "No " . $string_key . " matching " . $user_desc; } else { foreach ($new_object_ids as $new_obj_id) { $object_ids[] = $new_obj_id[$primary_key]; $title .= $new_obj_id[$primary_key] . ", "; } } } } // Show messages if (!empty($messages)) { 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"); } } echo "

Back to Events"; // Print footer include 'plc_footer.php'; ?>