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