3 function plc_person_link ($person_id) {
4 if ( empty ($person_id)) {
7 return '<a href="/db/persons/index.php?id=' . $person_id . '">' . $person_id . '</a>';
11 function plc_node_link ($node_id) {
12 if ( empty ($node_id)) {
15 return '<a href="/db/nodes/index.php?id=' . $node_id . '">' . $node_id . '</a>';
19 // pagination function
20 function paginate( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) {
21 // get vars from call adjust them
22 $dir= strtolower( $caption );
25 $link_page= 'index.php';
27 // check for page number
28 if( empty( $_GET['page'] ) )
33 // reorder array_chunk
34 foreach( $fn_array as $arr1 ) {
37 foreach( $arr1 as $key => $val ) {
38 // if( substr( $key, -3 ) == "_id" )
39 if ( $key == $table_id ) {
46 foreach( $id as $key => $val )
49 foreach( $data as $key => $val )
55 $totalrows= count( $as_array );
57 // if array has no rows display msg
59 return "Nothing to display";
61 // set key and break up data struct
63 $newarray= array_chunk( $as_array, $limit );
66 $echo.= "<table class='list_set' border=0 cellpadding=2>\n";
68 // if there is a caption add it to table
70 $echo.= "<caption class='list_set'>$caption</caption>\n";
72 $echo.= "<thead><tr class='list_set'>";
74 // go through keys of one array row for table headers
75 foreach( $newarray[$newkey][0] as $key => $val ) {
76 // if( substr( $key, -3 ) != "_id" )
77 if ( $key != $table_id && $key != 'peer_id' )
78 $echo.= "<th class='list_set'>". ucfirst( $key ) ."</th>";
81 if( $other_func == 'slivers' )
82 $echo.= "<th>Slivers</th>";
84 $echo.= "</tr></thead><tbody>\n";
86 // go through array row by row to output table rows
87 foreach( $newarray[$newkey] as $assoc ) {
90 if ($assoc['peer_id']) {
91 $extraclass="plc-foreign";
95 $echo.= "<tr class='list_set'>";
97 foreach( $assoc as $key => $val ) {
98 // do not rely on keys order
99 $id = $assoc[$table_id];
100 // if( substr( $key, -3 ) == "_id" )
101 if ($key == $table_id) {
104 } elseif( $key == $main_field ) {
105 $echo.= "<td class='list_set $extraclass'><a href='/db/$dir/$link_page?id=$id'>$val</a></td>";
106 } elseif ($key != 'peer_id') {
107 $echo.= "<td class='list_set $extraclass'>";
108 if( is_array( $val ) ) {
111 foreach( $val as $k => $v ) {
125 if( $other_func == 'slivers' )
126 $echo.= "<td><a href='slivers.php?node=$fid&slice=$id'>view</a></td>";
132 $echo.= "</tbody></table>\n";
135 // find total number of pages
136 $numofpages = $totalrows / $limit;
138 // start navigation links
139 if( $numofpages > 1 ) {
140 // if page is not 1 display first and prev links
141 if( $page != 1 && $page ) {
142 $pageprev= $page - 1;
143 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=1\">FIRST</a> ";
144 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=$pageprev\">PREV ".$limit."</a> ";
147 $echo.= "PREV ". $limit ." ";
149 // if less than 30 pages display all
150 // otherwise show 30 pages but put ... inbetween
151 if( $numofpages < 30 ) {
152 $npages= $numofpages;
157 if( $npages > $numofpages )
158 $npages= $numofpages;
166 // display pages, no link if current page
167 for( $i= $start; $i <= $npages; $i++ ) {
171 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=$i\">$i</a> ";
175 if( ( $totalrows % $limit ) != 0 ) {
176 $last= $numofpages + 1;
180 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=$i\">$i</a> ";
185 if( $numofpages >= 30 ) {
186 if( $page != $numofpages )
190 if( ( $totalrows - ($limit * $page) ) > 0 ) {
191 $pagenext= $page + 1;
192 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=$pagenext\">NEXT ".$limit."</a> ";
195 $echo.= "NEXT ". $limit;
197 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=". intval( $last ) ."\">LAST</a>\n";
205 // function for getting the diff of multi dimention array
206 function arr_diff( $a1, $a2 ) {
208 foreach( $a1 as $k=>$v ) {
210 for( $x= 0; $x < count( $a2 ); $x++ ) {
212 if( array_search( $v, $a2 ) === false )
214 else if( is_array( $v ) )
215 $dv= arr_diff( $v, $a2[$x] );
216 if( $dv && !in_array( $dv, $diff ) )
223 else if(is_array($v))
224 $dv=arr_diff($v,$a2[$x]);
234 function is_valid_email_addr($email)
236 if( ereg("^.+@.+\\..+$", $email) )
242 function is_valid_url($url)
244 if( ereg("^(http|https)://.+\..+$", strtolower($url) ) )
250 function is_valid_ip($ip)
252 if( ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $ip ) )
254 // it's at least in the right format, now check to see if
255 // each part is equal to less than 255
256 $parts= explode( '.', $ip );
257 $count= count($parts);
259 for( $i= 0; $i < $count; $i++ )
261 if( intval($parts[$i]) > 255 )
272 function is_valid_network_addr($network_addr,$mask)
274 $lNetwork= ip2long($network_addr);
275 $lMask= ip2long($mask);
277 // are they the correct format?
278 if( $lNetwork == -1 || $lMask == -1 )
281 // is network address valid for the mask?
282 if( ($lNetwork & $lMask) != $lNetwork )
289 // returns whether or not a network address is in the reserved space
290 // in the case of a invalid network address, false will be returned.
291 function is_reserved_network_addr($network_addr)
293 $lNetwork= ip2long($network_addr);
295 if( $lNetwork == -1 )
298 // does the network address fall in a reserved block?
299 $reserved_ips = array (
300 array('10.0.0.0','10.255.255.255'),
301 array('172.16.0.0','172.31.0.0'),
302 array('192.168.0.0','192.168.255.0')
304 foreach ($reserved_ips as $r)
306 $min = ip2long($r[0]);
307 $max = ip2long($r[1]);
309 if (($lNetwork >= $min) && ($lNetwork <= $max))
316 // builds a table from an array of strings, with the given class
317 function plc_make_table ($class, $messages) {
318 // pretty print the cell
320 if (! empty ($messages)) {
321 $formatted="<table class='" . $class . "'>";
322 foreach ($messages as $message) {
323 $formatted .= "<tr><td>" . $message . "</td></tr>";
325 $formatted .= "</table>";
330 // shows a php variable verbatim with a heading message
331 function plc_debug($message,$object) {
332 print "<br>" . $message . "<pre>";
337 // attempt to normalize the delete buttons and confirmations
338 function plc_delete_button($width=15) {
339 return '<span title="Delete this entry"><img width=' . $width . ' alt="Delete this entry" src="/planetlab/includes/delete.png"></span>';
342 function plc_js_confirm($message) {
343 return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\"";
346 function plc_delete_link($url,$delete_message,$visible) {
347 return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" . $visible . "</a>";
350 function plc_delete_link_button($url,$delete_message,$width=15) {
351 return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" . plc_delete_button($width) . "</a>";
354 function plc_event_button($type,$param,$id) {
355 return '<a href="/db/events/index.php?type=' . $type . '&' . $param . '=' . $id . '"> <span title="Related events"> <img src="/planetlab/includes/event.png" width=18></span></a>';
358 function plc_comon_button ($field, $value,$target="") {
360 if (!empty($target)) {
361 $result.='target="' . $target . '" ';
363 $result.='href="/db/nodes/comon.php?' . $field . "=" . $value . '">';
364 $result.='<span title="Link to Comon"> <img src="/planetlab/includes/comon.png" width="18"></span></a>';
368 function plc_peers_option_list ($api) {
371 $peers=$api->GetPeers(NULL,array('peer_id','peername'));
372 if (count($peers)==0) {
373 $predef=array(array("peer_id"=>"","peername"=>"All (no known peers)"));
375 $predef=array(array("peer_id"=>"","peername"=>"All peers"),
376 array("peer_id"=>"local","peername"=>"Local only"));
377 // show a 'foreign' button only if that makes sense
378 if (count($peers) >= 2) {
379 $predef [] = array("peer_id"=>"foreign","peername"=>"Foreign peers");
384 foreach ($predef as $a) {
385 $peer_line = "<option value='" . $a['peer_id'] . "'>" . $a['peername'] . "</option>\n";
386 $result .= $peer_line;
389 if (!empty($peers)) {
390 foreach ($peers as $a) {
391 $peer_line = "<option value='" . $a['peer_id'] . "'>" . $a['peername'] . "</option>\n";
392 $result .= $peer_line;