2 // $Id: index.php 1166 2008-01-29 09:32:26Z amine $
6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_drupal.php';
15 drupal_set_title('Events');
17 include 'plc_header.php';
20 require_once 'plc_functions.php';
21 require_once 'plc_sorts.php';
24 $_person= $plc->person;
25 $_roles= $_person['role_ids'];
33 <form method=get name='F' action='/db/events/index.php' >
35 <table align='bottom'>
38 <input type='radio' name='type' id='events' value='Event' checked='checked'> Events:
40 <input type='text' onSelect="submit();" onFocus='events.checked=true' name='event' size=20>
42 <input type='radio' name='type' id='persons' value='Person'> Persons:
44 <input type='text' onSelect="submit();" onFocus='persons.checked=true' name='person' size=20>
46 <input type='radio' name='type' id='nodes' value='Node'> Nodes:
48 <input type='text' onSelect="submit();" onFocus='nodes.checked=true' name='node' size=20>
50 <input type='radio' name='type' id='sites' value='Site'> Sites:
52 <input type='text' onSelect="submit();" onFocus='sites.checked=true' name='site' size=20>
54 <input type='radio' name='type' id='slices' value='Slice'> Slices:
56 <input type='text' onSelect="submit();" onFocus='slices.checked=true' name='slice' size=20>
61 <tr><th>FROM</th> <th>UNTIL</th> </tr>
65 <SELECT NAME='from_d' >
76 <OPTION VALUE=' 10' >10
77 <OPTION VALUE=' 11' >11
78 <OPTION VALUE=' 12' >12
79 <OPTION VALUE=' 13' >13
80 <OPTION VALUE=' 14' >14
81 <OPTION VALUE=' 15' >15
82 <OPTION VALUE=' 16' >16
83 <OPTION VALUE=' 17' >17
84 <OPTION VALUE=' 18' >18
85 <OPTION VALUE=' 19' >19
86 <OPTION VALUE=' 20' >20
87 <OPTION VALUE=' 21' >21
88 <OPTION VALUE=' 22' >22
89 <OPTION VALUE=' 23' >23
90 <OPTION VALUE=' 24' >24
91 <OPTION VALUE=' 25' >25
92 <OPTION VALUE=' 26' >26
93 <OPTION VALUE=' 27' >27
94 <OPTION VALUE=' 28' >28
95 <OPTION VALUE=' 29' >29
96 <OPTION VALUE=' 30' >30
97 <OPTION VALUE=' 31' >31
100 <SELECT NAME='from_m' >
102 <OPTION VALUE=' Jan' >January
103 <OPTION VALUE=' Feb' >February
104 <OPTION VALUE=' Mar' >March
105 <OPTION VALUE=' Apr' >April
106 <OPTION VALUE=' May' >May
107 <OPTION VALUE=' Jun' >June
108 <OPTION VALUE=' Jul' >July
109 <OPTION VALUE=' Aug' >August
110 <OPTION VALUE=' Sep' >September
111 <OPTION VALUE=' Oct' >October
112 <OPTION VALUE=' Nov' >November
113 <OPTION VALUE=' Dec' >December
116 <SELECT NAME='from_y' >
118 <OPTION VALUE='2006' >2006
119 <OPTION VALUE='2007' >2007
120 <OPTION VALUE='2008' >2008
121 <OPTION VALUE='2009' >2009
122 <OPTION VALUE='2010' >2010
123 <OPTION VALUE='2011' >2011
129 <SELECT NAME=' until_d' >
140 <OPTION VALUE='10' >10
141 <OPTION VALUE='11' >11
142 <OPTION VALUE='12' >12
143 <OPTION VALUE='13' >13
144 <OPTION VALUE='14' >14
145 <OPTION VALUE='15' >15
146 <OPTION VALUE='16' >16
147 <OPTION VALUE='17' >17
148 <OPTION VALUE='18' >18
149 <OPTION VALUE='19' >19
150 <OPTION VALUE='20' >20
151 <OPTION VALUE='21' >21
152 <OPTION VALUE='22' >22
153 <OPTION VALUE='23' >23
154 <OPTION VALUE='24' >24
155 <OPTION VALUE='25' >25
156 <OPTION VALUE='26' >26
157 <OPTION VALUE='27' >27
158 <OPTION VALUE='28' >28
159 <OPTION VALUE='29' >29
160 <OPTION VALUE='30' >30
161 <OPTION VALUE='31' >31
163 <SELECT NAME=' until_m' >
165 <OPTION VALUE='Jan' >January
166 <OPTION VALUE='Feb' >February
167 <OPTION VALUE='Mar' >March
168 <OPTION VALUE='Apr' >April
169 <OPTION VALUE='May' >May
170 <OPTION VALUE='Jun' >June
171 <OPTION VALUE='Jul' >July
172 <OPTION VALUE='Aug' >August
173 <OPTION VALUE='Sep' >September
174 <OPTION VALUE='Oct' >October
175 <OPTION VALUE='Nov' >November
176 <OPTION VALUE='Dec' >December
179 <SELECT NAME=' until_y' >
181 <OPTION VALUE='2006' >2006
182 <OPTION VALUE='2007' >2007
183 <OPTION VALUE='2008' >2008
184 <OPTION VALUE='2009' >2009
185 <OPTION VALUE='2010' >2010
186 <OPTION VALUE='2011' >2011
191 <input type='submit' align='middle' value='Show Events'>
198 function parse_date ($day,$month,$year) {
199 // if everything empty -> unspecified date, return 0
200 if ( empty($day) && empty($month) && empty($year)) {
201 return array ("xxx",0);
203 // fill missing fields with current value
204 if (empty($day)) $day=date('d');
205 if (empty($month)) $month=date('M');
206 if (empty($year)) $year=date('Y');
207 $date=sprintf("%s %s %s",$day,$month,$year);
208 $time=strtotime($date);
209 return array($date,$time);
213 function parse_dates () {
214 list($from_date,$from_time) = parse_date($_GET['from_d'],$_GET['from_m'],$_GET['from_y']);
215 list($until_date,$until_time) = parse_date($_GET['until_d'],$_GET['until_m'],$_GET['until_y']);
216 return array($from_date,$from_time,$until_date,$until_time);
219 function my_is_int ($x) {
220 return (is_numeric($x) ? intval($x) == $x : false);
223 function truncate ($text,$numb,$etc = "...") {
224 if (strlen($text) > $numb) {
225 $text = substr($text, 0, $numb);
231 // layout function to refine a row's content
232 function layout ($param){
235 $time=$param['time'];
236 $date= date('d M Y H:i' ,$time);
237 $param['time']=$date;
240 $message=htmlentities($param['message'], ENT_QUOTES);
241 $call=htmlentities($param['call'], ENT_QUOTES);
242 $detail_text=sprintf("message=<<%s>>\\n\\ncall=<<%s>>\\n\\nruntime=<<%f>>\\n",$message,$call,$param['runtime']);
243 $detail="<input type=button name='call' value='" . $param['call_name'] ."' onclick='alert(\"" . $detail_text . "\")'";
244 $detail=sprintf('<span title="%s">%s</span>',$call,$detail);
245 $param['call_name']=$detail;
246 unset ($param['call']);
248 // the message button
249 $trunc_mess=htmlentities(truncate($param['message'],40),ENT_QUOTES);
250 $detail="<input type=button name='message' value='" . $trunc_mess ."' onclick='alert(\"" . $detail_text . "\")'";
251 $detail=sprintf('<span title="%s">%s</span>',$message,$detail);
252 $param['message']=$detail;
254 // shrink column name : event_id -> id - paginate_id used in paginate and does not show up
255 $param['<span title="event_id">id</span>']=$param['event_id'] ;
256 // so that event_id shows up
257 $param['paginate_id']=$param['event_id']; unset($param['event_id']);
259 //// shrink column names
260 $param['<span title="fault_code">fault</span>']=$param['fault_code'] ; unset($param['fault_code']);
261 // seem empty on all rows - probably something that I screwed when importing tony's stuff
262 // $param['<span title="object_type">oty</span>']=$param['object_type'] ; unset($param['object_type']);
263 // $param['<span title="object_id">oid</span>']=$param['object_id'] ; unset($param['object_id']);
264 $param['<span title="object_types">otys</span>']=$param['object_types'] ; unset($param['object_types']);
265 $param['<span title="object_ids">oids</span>']=$param['object_ids'] ; unset($param['object_ids']);
266 $param['<span title="node_id">nid</span>']=plc_node_link($param['node_id']) ; unset($param['node_id']);
267 $param['<span title="person_id">pid</span>']= plc_person_link($param['person_id']) ; unset($param['person_id']);
268 if (array_key_exists('auth_type',$param)) {
269 $param['<span title="auth_type">at</span>']=$param['auth_type'] ; unset($param['auth_type']);
273 unset($param['object_type']);
274 unset($param['object_id']);
275 unset($param['runtime']);
279 //plc_debug('GET',$_GET);
281 if ( !in_array ('10', $_roles)) {
282 echo "<div class='plc-warning'> You need admin role to see this page. </div>";
284 } else if (!$_GET['type']) {
286 echo "<h2>What events would you like to consult :</h2>";
287 // print the selection frame
292 // // xxx this of any use at all ?
293 // drupal_set_html_head('<script type="text/javascript" src="/planetlab/includes/js/bsn.Ajax.js"></script>
294 // <script type="text/javascript" src="/planetlab/includes/js/bsn.DOM.js"></script>
295 // <script type="text/javascript" src="/planetlab/includes/js/bsn.AutoSuggest.js"></script>');
298 list($from_date,$from_time,$until_date,$until_time) = parse_dates ();
299 if ( ($from_time != 0) && ($until_time != 0) && ($from_time > $until_time) ) {
300 $messages[] = "Warning - wrong date selection";
304 if ($from_time != 0) {
305 $filter[']time']=$from_time;
307 if ($until_time != 0) {
308 $filter['[time']=$until_time;
311 //////////////////////////////////////// Events
313 if ($type == 'Event') {
315 // and the filter applied for fetching events using GetEvent
316 $user_desc=$_GET['event'];
317 if ( ! empty($user_desc)) {
318 // should parse stuff like 45-90,230-3000 - some other day
319 $filter['event_id']=intval($user_desc);
321 // the filter might be void here - in python we need an empty dict but that's not what we get so
322 if (empty($filter)) {
325 $events = $api->GetEvents($filter);
326 if (empty($events)) {
327 $messages[] = "No event found - user input was [" . $user_desc . "]";
329 $title="Events matching " . ($user_desc ? $user_desc : "everything");
331 $title .= " From " . $from_date;
332 if ($until_time != 0)
333 $title .= " Until " . $until_date;
334 drupal_set_title ($title);
338 if (!empty($messages)) {
339 print '<div class="messages plc-warning"><ul>';
340 foreach ($messages as $line) {
346 if ( ! empty ($events)) {
347 $events= array_map(layout,$events);
348 echo paginate( $events, "paginate_id", "Events", $page_size, "event_id");
354 $primary_key='person_id';
356 $user_input=$_GET['person'];
357 $method="GetPersons";
358 $object_type='Person';
362 $primary_key='node_id';
363 $string_key='hostname';
364 $user_input=$_GET['node'];
370 $primary_key='site_id';
371 $string_key='login_base';
372 $user_input=$_GET['site'];
378 $primary_key='slice_id';
380 $user_input=$_GET['slice'];
382 $object_type='Slice';
387 $title=sprintf('Events for type %s:',$object_type);
388 foreach ( split(",",$user_input) as $user_desc) {
390 if (my_is_int($user_desc)) {
391 $obj_check = call_user_func(array($api,$method),array(intval($user_desc)),array($primary_key));
392 if (empty ($obj_check)) {
393 $messages[] = "No such " . $primary_key . ": " . $user_desc;
395 $object_ids[] = $obj_check[0][$primary_key];
396 $title .= $user_desc . ", " ;
400 $new_object_ids=call_user_func (array($api,$method), array($string_key=>$user_desc),array($primary_key,$string_key));
401 if (empty($new_object_ids)) {
402 $messages[] = "No " . $string_key . " matching " . $user_desc;
404 foreach ($new_object_ids as $new_obj_id) {
405 $object_ids[] = $new_obj_id[$primary_key];
406 $title .= $new_obj_id[$primary_key] . ", ";
413 if (!empty($messages)) {
414 print '<div class="messages plc-warning"><ul>';
415 foreach ($messages as $line) {
421 drupal_set_title($title);
422 $events = $api->GetEventObjects(array('object_id'=>$object_ids,'object_type'=>$object_type));
424 $events=array_map(layout,$events);
425 echo paginate( $events, "paginate_id", "--------" . $type . " EVENTS---------", $page_size, "hostname");
429 echo "<br /><p><a href='/db/events/index.php'>Back to Events</a>";
432 include 'plc_footer.php';