3 // this will be trashed eventually
6 function paginate_trash ( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) {
7 // get vars from call adjust them
8 $dir= strtolower( $caption );
11 $link_page= 'index.php';
13 // check for page number
14 if( empty( $_GET['page'] ) )
19 // reorder array_chunk
20 foreach( $fn_array as $arr1 ) {
23 foreach( $arr1 as $key => $val ) {
24 // if( substr( $key, -3 ) == "_id" )
25 if ( $key == $table_id ) {
32 foreach( $id as $key => $val )
35 foreach( $data as $key => $val )
41 $totalrows= count( $as_array );
43 // if array has no rows display msg
45 return "Nothing to display";
47 // set key and break up data struct
49 $newarray= array_chunk( $as_array, $limit );
52 $echo.= "<table class='list_set' border=0 cellpadding=2>\n";
54 // if there is a caption add it to table
56 $echo.= "<caption class='list_set'>$caption</caption>\n";
58 $echo.= "<thead><tr class='list_set'>";
60 // go through keys of one array row for table headers
61 foreach( $newarray[$newkey][0] as $key => $val ) {
62 // if( substr( $key, -3 ) != "_id" )
63 if ( $key != $table_id && $key != 'peer_id' )
64 $echo.= "<th class='list_set'>". ucfirst( $key ) ."</th>";
67 if( $other_func == 'slivers' )
68 $echo.= "<th>Slivers</th>";
70 $echo.= "</tr></thead><tbody>\n";
72 // go through array row by row to output table rows
73 foreach( $newarray[$newkey] as $assoc ) {
76 if ($assoc['peer_id']) {
77 $extraclass="plc-foreign";
81 $echo.= "<tr class='list_set'>";
83 foreach( $assoc as $key => $val ) {
84 // do not rely on keys order
85 $id = $assoc[$table_id];
86 // if( substr( $key, -3 ) == "_id" )
87 if ($key == $table_id) {
90 } elseif( $key == $main_field ) {
91 $echo.= "<td class='list_set $extraclass'><a href='/db/$dir/$link_page?id=$id'>$val</a></td>";
92 } elseif ($key != 'peer_id') {
93 $echo.= "<td class='list_set $extraclass'>";
94 if( is_array( $val ) ) {
97 foreach( $val as $k => $v ) {
111 if( $other_func == 'slivers' )
112 $echo.= "<td><a href='slivers.php?node=$fid&slice=$id'>view</a></td>";
118 $echo.= "</tbody></table>\n";
121 // find total number of pages
122 $numofpages = $totalrows / $limit;
124 // start navigation links
125 if( $numofpages > 1 ) {
126 // if page is not 1 display first and prev links
127 if( $page != 1 && $page ) {
128 $pageprev= $page - 1;
129 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=1\">FIRST</a> ";
130 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=$pageprev\">PREV ".$limit."</a> ";
133 $echo.= "PREV ". $limit ." ";
135 // if less than 30 pages display all
136 // otherwise show 30 pages but put ... inbetween
137 if( $numofpages < 30 ) {
138 $npages= $numofpages;
143 if( $npages > $numofpages )
144 $npages= $numofpages;
152 // display pages, no link if current page
153 for( $i= $start; $i <= $npages; $i++ ) {
157 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=$i\">$i</a> ";
161 if( ( $totalrows % $limit ) != 0 ) {
162 $last= $numofpages + 1;
166 $echo.= "<a href=\"". $_SERVER['REQUEST_URI'] ."&page=$i\">$i</a> ";
171 if( $numofpages >= 30 ) {
172 if( $page != $numofpages )
176 if( ( $totalrows - ($limit * $page) ) > 0 ) {
177 $pagenext= $page + 1;
178 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=$pagenext\">NEXT ".$limit."</a> ";
181 $echo.= "NEXT ". $limit;
183 $echo.= " <a href=\"". $_SERVER['REQUEST_URI'] ."&page=". intval( $last ) ."\">LAST</a>\n";
191 // function for getting the diff of multi dimention array
192 function arr_diff( $a1, $a2 ) {
194 foreach( $a1 as $k=>$v ) {
196 for( $x= 0; $x < count( $a2 ); $x++ ) {
198 if( array_search( $v, $a2 ) === false )
200 else if( is_array( $v ) )
201 $dv= arr_diff( $v, $a2[$x] );
202 if( $dv && !in_array( $dv, $diff ) )
209 else if(is_array($v))
210 $dv=arr_diff($v,$a2[$x]);
220 function plc_js_confirm($message) {
221 return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\"";
224 function plc_delete_link($url,$delete_message,$visible) {
225 return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" . $visible . "</a>";
228 function plc_delete_link_button($url,$delete_message,$width=15) {
229 return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" .
230 plc_delete_icon_bubble($width,"Delete this entry") .