3 // this will be trashed eventually
5 function plc_person_link ($person_id) {
6 if ( empty ($person_id)) {
9 return '<a href="/db/persons/index.php?id=' . $person_id . '">' . $person_id . '</a>';
13 function plc_node_link ($node_id) {
14 if ( empty ($node_id)) {
17 return '<a href="/db/nodes/index.php?id=' . $node_id . '">' . $node_id . '</a>';
21 // pagination function
22 function paginate( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) {
23 // get vars from call adjust them
24 $dir= strtolower( $caption );
27 $link_page= 'index.php';
29 // check for page number
30 if( empty( $_GET['page'] ) )
35 // reorder array_chunk
36 foreach( $fn_array as $arr1 ) {
39 foreach( $arr1 as $key => $val ) {
40 // if( substr( $key, -3 ) == "_id" )
41 if ( $key == $table_id ) {
48 foreach( $id as $key => $val )
51 foreach( $data as $key => $val )
57 $totalrows= count( $as_array );
59 // if array has no rows display msg
61 return "Nothing to display";
63 // set key and break up data struct
65 $newarray= array_chunk( $as_array, $limit );
68 $echo.= "<table class='list_set' border=0 cellpadding=2>\n";
70 // if there is a caption add it to table
72 $echo.= "<caption class='list_set'>$caption</caption>\n";
74 $echo.= "<thead><tr class='list_set'>";
76 // go through keys of one array row for table headers
77 foreach( $newarray[$newkey][0] as $key => $val ) {
78 // if( substr( $key, -3 ) != "_id" )
79 if ( $key != $table_id && $key != 'peer_id' )
80 $echo.= "<th class='list_set'>". ucfirst( $key ) ."</th>";
83 if( $other_func == 'slivers' )
84 $echo.= "<th>Slivers</th>";
86 $echo.= "</tr></thead><tbody>\n";
88 // go through array row by row to output table rows
89 foreach( $newarray[$newkey] as $assoc ) {
92 if ($assoc['peer_id']) {
93 $extraclass="plc-foreign";
97 $echo.= "<tr class='list_set'>";
99 foreach( $assoc as $key => $val ) {
100 // do not rely on keys order
101 $id = $assoc[$table_id];
102 // if( substr( $key, -3 ) == "_id" )
103 if ($key == $table_id) {
106 } elseif( $key == $main_field ) {
107 $echo.= "<td class='list_set $extraclass'><a href='/db/$dir/$link_page?id=$id'>$val</a></td>";
108 } elseif ($key != 'peer_id') {
109 $echo.= "<td class='list_set $extraclass'>";
110 if( is_array( $val ) ) {
113 foreach( $val as $k => $v ) {
127 if( $other_func == 'slivers' )
128 $echo.= "<td><a href='slivers.php?node=$fid&slice=$id'>view</a></td>";
134 $echo.= "</tbody></table>\n";
137 // find total number of pages
138 $numofpages = $totalrows / $limit;
140 // start navigation links
141 if( $numofpages > 1 ) {
142 // if page is not 1 display first and prev links
143 if( $page != 1 && $page ) {
144 $pageprev= $page - 1;
145 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=1\">FIRST</a> ";
146 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=$pageprev\">PREV ".$limit."</a> ";
149 $echo.= "PREV ". $limit ." ";
151 // if less than 30 pages display all
152 // otherwise show 30 pages but put ... inbetween
153 if( $numofpages < 30 ) {
154 $npages= $numofpages;
159 if( $npages > $numofpages )
160 $npages= $numofpages;
168 // display pages, no link if current page
169 for( $i= $start; $i <= $npages; $i++ ) {
173 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=$i\">$i</a> ";
177 if( ( $totalrows % $limit ) != 0 ) {
178 $last= $numofpages + 1;
182 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=$i\">$i</a> ";
187 if( $numofpages >= 30 ) {
188 if( $page != $numofpages )
192 if( ( $totalrows - ($limit * $page) ) > 0 ) {
193 $pagenext= $page + 1;
194 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=$pagenext\">NEXT ".$limit."</a> ";
197 $echo.= "NEXT ". $limit;
199 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=". intval( $last ) ."\">LAST</a>\n";
209 function plc_peers_option_list ($api) {
212 $peers=$api->GetPeers(NULL,array('peer_id','peername'));
213 if (count($peers)==0) {
214 $predef=array(array("peer_id"=>"","peername"=>"All (no known peers)"));
216 $predef=array(array("peer_id"=>"","peername"=>"All peers"),
217 array("peer_id"=>"local","peername"=>"Local only"));
218 // show a 'foreign' button only if that makes sense
219 if (count($peers) >= 2) {
220 $predef [] = array("peer_id"=>"foreign","peername"=>"Foreign peers");
225 foreach ($predef as $a) {
226 $peer_line = "<option value='" . $a['peer_id'] . "'>" . $a['peername'] . "</option>\n";
227 $result .= $peer_line;
230 if (!empty($peers)) {
231 foreach ($peers as $a) {
232 $peer_line = "<option value='" . $a['peer_id'] . "'>" . $a['peername'] . "</option>\n";
233 $result .= $peer_line;
242 // function for getting the diff of multi dimention array
243 function arr_diff( $a1, $a2 ) {
245 foreach( $a1 as $k=>$v ) {
247 for( $x= 0; $x < count( $a2 ); $x++ ) {
249 if( array_search( $v, $a2 ) === false )
251 else if( is_array( $v ) )
252 $dv= arr_diff( $v, $a2[$x] );
253 if( $dv && !in_array( $dv, $diff ) )
260 else if(is_array($v))
261 $dv=arr_diff($v,$a2[$x]);