5 require_once 'plc_login.php';
7 // Get session and API handles
8 require_once 'plc_session.php';
12 require_once 'plc_drupal.php';
13 include 'plc_header.php';
16 require_once 'plc_functions.php';
17 require_once 'plc_sorts.php';
20 ini_set("memory_limit","128M");
23 drupal_set_title('Events');
30 ////////////////////////////////////////
31 // defaults for day ('j'), 3-letter month ('M') or year ('Y')
32 function the_date ($key,$dateformat) {
33 if ($_GET[$key]) return $_GET[$key];
34 else return date($dateformat);
37 // fill out dates from now if not specified
38 $from_d = the_date('from_d','j');
39 $from_m = the_date('from_m','M');
40 $from_y = the_date('from_y','Y');
41 $until_d = the_date('until_d','j');
42 $until_m = the_date('until_m','M');
43 $until_y = the_date('until_y','Y');
45 // create the options area from a list and the selected entry
46 function dropdown_options ($array,$selected) {
48 foreach ($array as $item) {
49 $result.= "<option value=" . $item;
50 if ($item == $selected) $result .= ' selected=selected';
51 $result .= '>' . $item . '</option>';
57 $from_d_dropdown_options=dropdown_options($days,$from_d);
58 $until_d_dropdown_options=dropdown_options($days,$until_d);
59 $months=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
60 $from_m_dropdown_options=dropdown_options($months,$from_m);
61 $until_m_dropdown_options=dropdown_options($months,$until_m);
62 // only propose years ranging from now + 3 full years back
64 $years=range($this_year-3,$this_year);
65 $from_y_dropdown_options=dropdown_options($years,$from_y);
66 $until_y_dropdown_options=dropdown_options($years,$until_y);
69 <form method=get name='F' action='/db/events/index.php' >
71 <table align='bottom'>
74 <input type='radio' name='type' id='events' value='Event' checked='checked'> Events:
76 <input type='text' onSelect="submit();" onFocus='events.checked=true' name='event' size=20>
78 <input type='radio' name='type' id='persons' value='Person'> Persons:
80 <input type='text' onSelect="submit();" onFocus='persons.checked=true' name='person' size=20>
82 <input type='radio' name='type' id='nodes' value='Node'> Nodes:
84 <input type='text' onSelect="submit();" onFocus='nodes.checked=true' name='node' size=20>
86 <input type='radio' name='type' id='sites' value='Site'> Sites:
88 <input type='text' onSelect="submit();" onFocus='sites.checked=true' name='site' size=20>
90 <input type='radio' name='type' id='slices' value='Slice'> Slices:
92 <input type='text' onSelect="submit();" onFocus='slices.checked=true' name='slice' size=20>
97 <tr><th>FROM (inclusive)</th> <th>UNTIL (inclusive)</th> </tr>
101 <SELECT NAME='from_d'>
102 $from_d_dropdown_options
104 <SELECT NAME='from_m' >
105 $from_m_dropdown_options
107 <SELECT NAME='from_y' >
108 $from_y_dropdown_options
113 <SELECT NAME=' until_d' >
114 $until_d_dropdown_options
116 <SELECT NAME=' until_m' >
117 $until_m_dropdown_options
119 <SELECT NAME=' until_y' >
120 $until_y_dropdown_options
125 <input type='submit' align='middle' value='Show Events'>
132 function parse_date ($day,$month,$year) {
133 // if everything empty -> unspecified date, return 0
134 if ( empty($day) && empty($month) && empty($year)) {
135 return array ("xxx",0);
137 // fill missing fields with current value
138 if (empty($day)) $day=date('d');
139 if (empty($month)) $month=date('M');
140 if (empty($year)) $year=date('Y');
141 $date=sprintf("%s %s %s",$day,$month,$year);
142 $time=strtotime($date);
143 return array($date,$time);
147 function parse_dates () {
148 list($from_date,$from_time) = parse_date($_GET['from_d'],$_GET['from_m'],$_GET['from_y']);
149 list($until_date,$until_time) = parse_date($_GET['until_d'],$_GET['until_m'],$_GET['until_y']);
150 return array($from_date,$from_time,$until_date,$until_time);
153 function my_is_int ($x) {
154 return (is_numeric($x) ? intval($x) == $x : false);
157 function truncate ($text,$numb,$etc = "...") {
158 if (strlen($text) > $numb) {
159 $text = substr($text, 0, $numb);
165 // layout function to refine a row's content
166 function layout ($param){
169 $time=$param['time'];
170 $date= date('d M Y H:i' ,$time);
171 $param['time']=$date;
174 $message=htmlentities($param['message'], ENT_QUOTES);
175 $call=htmlentities($param['call'], ENT_QUOTES);
176 $detail_text=sprintf("message=<<%s>>\\n\\ncall=<<%s>>\\n\\nruntime=<<%f>>\\n",$message,$call,$param['runtime']);
177 $detail="<input type=button name='call' value='" . $param['call_name'] ."' onclick='alert(\"" . $detail_text . "\")'";
178 $detail=sprintf('<span title="%s">%s</span>',$call,$detail);
179 $param['call_name']=$detail;
180 unset ($param['call']);
182 // the message button
183 $trunc_mess=htmlentities(truncate($param['message'],40),ENT_QUOTES);
184 $detail="<input type=button name='message' value='" . $trunc_mess ."' onclick='alert(\"" . $detail_text . "\")'";
185 $detail=sprintf('<span title="%s">%s</span>',$message,$detail);
186 $param['message']=$detail;
188 // shrink column name : event_id -> id - paginate_id used in paginate and does not show up
189 $param['<span title="event_id">id</span>']=$param['event_id'] ;
190 // so that event_id shows up
191 $param['paginate_id']=$param['event_id']; unset($param['event_id']);
193 //// shrink column names
194 $param['<span title="fault_code">fault</span>']=$param['fault_code'] ; unset($param['fault_code']);
195 // seem empty on all rows - probably something that I screwed when importing tony's stuff
196 // $param['<span title="object_type">oty</span>']=$param['object_type'] ; unset($param['object_type']);
197 // $param['<span title="object_id">oid</span>']=$param['object_id'] ; unset($param['object_id']);
198 $param['<span title="object_types">otys</span>']=$param['object_types'] ; unset($param['object_types']);
199 $param['<span title="object_ids">oids</span>']=$param['object_ids'] ; unset($param['object_ids']);
200 $param['<span title="node_id">nid</span>']=plc_node_link($param['node_id']) ; unset($param['node_id']);
201 $param['<span title="person_id">pid</span>']= plc_person_link($param['person_id']) ; unset($param['person_id']);
202 if (array_key_exists('auth_type',$param)) {
203 $param['<span title="auth_type">at</span>']=$param['auth_type'] ; unset($param['auth_type']);
207 unset($param['object_type']);
208 unset($param['object_id']);
209 unset($param['runtime']);
213 //plc_debug('GET',$_GET);
215 if ( ! plc_is_admin()) {
216 echo "<div class='plc-warning'> You need admin role to see this page. </div>";
218 } else if (! $_GET['type']) {
219 echo "<h2>Select the events to focus on :</h2>";
220 // print the selection frame
226 list($from_date,$from_time,$until_date,$until_time) = parse_dates ();
227 // add one day to until_time - otherwise this corresponds to 0:0
228 $until_time += (24*60*60);
229 if ( ($from_time != 0) && ($until_time != 0) && ($from_time > $until_time) ) {
230 $messages[] = "Warning - wrong date selection";
234 // sort events by time is not good enough, let's use event_id
235 $filter['-SORT']='event_id';
236 if ($from_time != 0) {
237 $filter[']time']=$from_time;
239 if ($until_time != 0) {
240 $filter['[time']=$until_time;
243 //////////////////////////////////////// Events
245 if ($type == 'Event') {
247 // and the filter applied for fetching events using GetEvent
248 $user_desc=$_GET['event'];
249 if ( ! empty($user_desc)) {
250 // should parse stuff like 45-90,230-3000 - some other day
251 $filter['event_id']=intval($user_desc);
253 // the filter might be void here - in python we need an empty dict but that's not what we get so
254 if (empty($filter)) {
257 $events = $api->GetEvents($filter);
258 if (empty($events)) {
259 $messages[] = "No event found - user input was [" . $user_desc . "]";
261 $title="Events matching " . ($user_desc ? $user_desc : "everything");
263 $title .= " From " . $from_date;
264 if ($until_time != 0)
265 $title .= " Until " . $until_date;
266 drupal_set_title ($title);
270 if (!empty($messages))
271 foreach ($messages as $line)
272 drupal_set_message($line);
274 if ( ! empty ($events)) {
275 $events= array_map(layout,$events);
276 echo paginate( $events, "paginate_id", "Events", $page_size, "event_id");
282 $primary_key='person_id';
284 $user_input=$_GET['person'];
285 $method="GetPersons";
286 $object_type='Person';
290 $primary_key='node_id';
291 $string_key='hostname';
292 $user_input=$_GET['node'];
298 $primary_key='site_id';
299 $string_key='login_base';
300 $user_input=$_GET['site'];
306 $primary_key='slice_id';
308 $user_input=$_GET['slice'];
310 $object_type='Slice';
315 $title=sprintf('Events for type %s:',$object_type);
316 foreach ( split(",",$user_input) as $user_desc) {
318 if (my_is_int($user_desc)) {
319 $obj_check = call_user_func(array($api,$method),array(intval($user_desc)),array($primary_key));
320 if (empty ($obj_check)) {
321 $messages[] = "No such " . $primary_key . ": " . $user_desc;
323 $object_ids[] = $obj_check[0][$primary_key];
324 $title .= $user_desc . ", " ;
328 $new_object_ids=call_user_func (array($api,$method), array($string_key=>$user_desc),array($primary_key,$string_key));
329 if (empty($new_object_ids)) {
330 $messages[] = "No " . $string_key . " matching " . $user_desc;
332 foreach ($new_object_ids as $new_obj_id) {
333 $object_ids[] = $new_obj_id[$primary_key];
334 $title .= $new_obj_id[$primary_key] . ", ";
341 if (!empty($messages)) {
342 print '<div class="messages plc-warning"><ul>';
343 foreach ($messages as $line) {
349 drupal_set_title($title);
350 $events = $api->GetEventObjects(array('object_id'=>$object_ids,'object_type'=>$object_type));
352 $events=array_map(layout,$events);
353 echo paginate( $events, "paginate_id", "--------" . $type . " EVENTS---------", $page_size, "hostname");
357 echo "<br /><p><a href='/db/events/index.php'>Back to Events</a>";
360 include 'plc_footer.php';