$val ) { // if( substr( $key, -3 ) == "_id" ) if ( $key == $table_id ) { $id[$key]= $val; } else { $data[$key]= $val; } } foreach( $id as $key => $val ) $arr2[$key]= $val; foreach( $data as $key => $val ) $arr2[$key]= $val; $as_array[]= $arr2; } $totalrows= count( $as_array ); // if array has no rows display msg if( $totalrows == 0 ) return "Nothing to display"; // set key and break up data struct $newkey= $page - 1; $newarray= array_chunk( $as_array, $limit ); // start table output $echo.= "\n"; // if there is a caption add it to table if( $caption ) $echo.= "\n"; $echo.= ""; // go through keys of one array row for table headers foreach( $newarray[$newkey][0] as $key => $val ) { // if( substr( $key, -3 ) != "_id" ) if ( $key != $table_id && $key != 'peer_id' ) $echo.= ""; } if( $other_func == 'slivers' ) $echo.= ""; $echo.= "\n"; // go through array row by row to output table rows foreach( $newarray[$newkey] as $assoc ) { $extraclass=""; if ($assoc['peer_id']) { $extraclass="plc-foreign"; } $echo.= ""; foreach( $assoc as $key => $val ) { // do not rely on keys order $id = $assoc[$table_id]; // if( substr( $key, -3 ) == "_id" ) if ($key == $table_id) { // $id= $val; continue; } elseif( $key == $main_field ) { $echo.= ""; } elseif ($key != 'peer_id') { $echo.= ""; } } if( $other_func == 'slivers' ) $echo.= ""; $echo.= "\n"; } // close table $echo.= "
$caption
". ucfirst( $key ) ."Slivers
$val"; if( is_array( $val ) ) { $count= 1; $tot= count( $val ); foreach( $val as $k => $v ) { $echo.= $v; if( $count != $tot ) $echo.= ", "; $count++; } } else $echo.= $val; $echo.= "view
\n"; $echo.= "
\n"; // find total number of pages $numofpages = $totalrows / $limit; // start navigation links if( $numofpages > 1 ) { // if page is not 1 display first and prev links if( $page != 1 && $page ) { $pageprev= $page - 1; $echo.= "FIRST   "; $echo.= " PREV ".$limit."   "; } else $echo.= "PREV ". $limit ." "; // if less than 30 pages display all // otherwise show 30 pages but put ... inbetween if( $numofpages < 30 ) { $npages= $numofpages; $start= 1; } else { $npages= $page + 9; if( $npages > $numofpages ) $npages= $numofpages; $start= $page - 10; if( $start < 1 ) $start= 1; if( $page != 1 ) $echo.= " ... "; } // display pages, no link if current page for( $i= $start; $i <= $npages; $i++ ) { if( $i == $page ) $echo.= $i ." "; else $echo.= "$i "; } if( ( $totalrows % $limit ) != 0 ) { $last= $numofpages + 1; if( $i == $page ) $echo.= $i ." "; else $echo.= "$i "; } else $last= $numofpages; if( $numofpages >= 30 ) { if( $page != $numofpages ) $echo.= " ... "; } if( ( $totalrows - ($limit * $page) ) > 0 ) { $pagenext= $page + 1; $echo.= "   NEXT ".$limit."   "; } else $echo.= "NEXT ". $limit; $echo.= " LAST\n"; } return $echo; } function plc_peers_option_list ($api) { // get list of peers $peers=$api->GetPeers(NULL,array('peer_id','peername')); if (count($peers)==0) { $predef=array(array("peer_id"=>"","peername"=>"All (no known peers)")); } else { $predef=array(array("peer_id"=>"","peername"=>"All peers"), array("peer_id"=>"local","peername"=>"Local only")); // show a 'foreign' button only if that makes sense if (count($peers) >= 2) { $predef [] = array("peer_id"=>"foreign","peername"=>"Foreign peers"); } } $result=""; foreach ($predef as $a) { $peer_line = "\n"; $result .= $peer_line; } if (!empty($peers)) { foreach ($peers as $a) { $peer_line = "\n"; $result .= $peer_line; } } return $result; } // function for getting the diff of multi dimention array function arr_diff( $a1, $a2 ) { $diff= array(); foreach( $a1 as $k=>$v ) { unset( $dv ); for( $x= 0; $x < count( $a2 ); $x++ ) { if( is_int( $k ) ) { if( array_search( $v, $a2 ) === false ) $dv=$v; else if( is_array( $v ) ) $dv= arr_diff( $v, $a2[$x] ); if( $dv && !in_array( $dv, $diff ) ) $diff[]=$dv; } else { if( !$a2[$k] ) $dv=$v; else if(is_array($v)) $dv=arr_diff($v,$a2[$x]); if($dv) $diff[$x]=$dv; } } } return $diff; } ?>