Adding form to MySQLTable output. refs #981
Showing
1 changed file
with
45 additions
and
6 deletions
| 1 | <?php | 1 | <?php |
| 2 | namespace Tz\WordPress\Tools\MySQLTable; | 2 | namespace Tz\WordPress\Tools\MySQLTable; |
| 3 | 3 | ||
| 4 | function array2table($arr,$width = "100%") | 4 | function array2table($arr, $width = "100%", $with_form = true) { |
| 5 | { | ||
| 6 | $count = count($arr); | 5 | $count = count($arr); |
| 7 | if($count > 0){ | 6 | if (!$count) echo ''; |
| 7 | |||
| 8 | reset($arr); | 8 | reset($arr); |
| 9 | $num = count(current($arr)); | 9 | $num = count(current($arr)); |
| 10 | echo "<table border=\"0\"cellpadding=\"5\" cellspacing=\"0\" width=\"$width\" class=\"cbv-report-list\">\n"; | 10 | |
| 11 | if ($with_form) { | ||
| 12 | echo <<<HTML | ||
| 13 | |||
| 14 | <form id="report-form" action="http://cbv/wp-admin/admin.php?page=report_manager&action=run_action&report_id={$_GET['report_id']}&action_to_run=change_user_status" method="post"> | ||
| 15 | |||
| 16 | <div style="margin-bottom: 20px"> | ||
| 17 | |||
| 18 | <label for="action-list"><h4 style="margin-bottom: 5px">With Selected:</h4></label> | ||
| 19 | <select id="action-list"> | ||
| 20 | <option value="change_user_status">Change User Status</option> | ||
| 21 | <option value="change_user_role">Change User Role</option> | ||
| 22 | <option value="add_ce_hours">Add Continuing Education Hours</option> | ||
| 23 | <option value="send_notification">Send Notification</option> | ||
| 24 | <option value="create_invoice">Create an Invoice / Credit Note</option> | ||
| 25 | </select> | ||
| 26 | |||
| 27 | <input type="submit" value="Go" /> | ||
| 28 | |||
| 29 | </div> | ||
| 30 | HTML; | ||
| 31 | } | ||
| 32 | |||
| 33 | echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"$width\" class=\"cbv-report-list\">\n"; | ||
| 11 | echo "<thead>\n"; | 34 | echo "<thead>\n"; |
| 12 | echo "<tr>\n"; | 35 | echo "<tr>\n"; |
| 36 | |||
| 37 | if ($with_form) { | ||
| 38 | echo '<th style ="min-width: 30px"><input type="checkbox" checked="checked" name="selector" id="selector" /></th>'; | ||
| 39 | } | ||
| 40 | |||
| 13 | foreach(current($arr) as $key => $value){ | 41 | foreach(current($arr) as $key => $value){ |
| 14 | echo "<th valign='bottom'>"; | 42 | echo "<th valign='bottom'>"; |
| 15 | echo $key." "; | 43 | echo $key." "; |
| ... | @@ -18,12 +46,17 @@ function array2table($arr,$width = "100%") | ... | @@ -18,12 +46,17 @@ function array2table($arr,$width = "100%") |
| 18 | echo "</tr>\n"; | 46 | echo "</tr>\n"; |
| 19 | echo "</thead>\n"; | 47 | echo "</thead>\n"; |
| 20 | echo "<tbody>\n"; | 48 | echo "<tbody>\n"; |
| 49 | |||
| 21 | $wi = 0; | 50 | $wi = 0; |
| 22 | while ($curr_row = current($arr)) { | 51 | while ($curr_row = current($arr)) { |
| 23 | $rclass = ($wi%2) ? "odd" : ""; | 52 | $rclass = ($wi%2) ? "odd" : ""; |
| 24 | echo "<tr class='".$rclass."'>\n"; | 53 | echo "<tr class='".$rclass."'>\n"; |
| 25 | $col = 1; | 54 | $col = 1; |
| 26 | // Are you fucking kidding me with this shit, Kevin??? | 55 | |
| 56 | if ($with_form) { | ||
| 57 | echo '<td style="min-width: 30px"><input type="checkbox" checked="checked" name="records[' . $curr_row['ID'] . ']" value="1" /></td>'; | ||
| 58 | } | ||
| 59 | |||
| 27 | while (false !== ($curr_field = current($curr_row))) { | 60 | while (false !== ($curr_field = current($curr_row))) { |
| 28 | echo "<td>"; | 61 | echo "<td>"; |
| 29 | echo $curr_field." "; | 62 | echo $curr_field." "; |
| ... | @@ -31,18 +64,24 @@ function array2table($arr,$width = "100%") | ... | @@ -31,18 +64,24 @@ function array2table($arr,$width = "100%") |
| 31 | next($curr_row); | 64 | next($curr_row); |
| 32 | $col++; | 65 | $col++; |
| 33 | } | 66 | } |
| 67 | |||
| 34 | while($col <= $num){ | 68 | while($col <= $num){ |
| 35 | echo "<td> </td>\n"; | 69 | echo "<td> </td>\n"; |
| 36 | $col++; | 70 | $col++; |
| 37 | } | 71 | } |
| 72 | |||
| 38 | echo "</tr>\n"; | 73 | echo "</tr>\n"; |
| 39 | $wi++; | 74 | $wi++; |
| 40 | next($arr); | 75 | next($arr); |
| 41 | } | 76 | } |
| 77 | |||
| 42 | echo "</tbody>\n"; | 78 | echo "</tbody>\n"; |
| 43 | echo "</table>\n"; | 79 | echo "</table>\n"; |
| 80 | |||
| 81 | if ($with_form) { | ||
| 82 | echo '</form>'; | ||
| 44 | } | 83 | } |
| 45 | } | 84 | } |
| 46 | 85 | ||
| 47 | function CSVExport($arr) { | 86 | function CSVExport($arr) { |
| 48 | $out = ""; | 87 | $out = ""; | ... | ... |
-
Please register or sign in to post a comment