function sa_data_entry() { global $wpdb, $rep_table, $bill_table, $cat_table, $vote_table, $val_table; //Check if this is a form submission if (isset($_POST["type"])) { $type = sa_process_form(); } else { $type = "rep"; //Default to representative screen } ?> <div class="sawatch-admin-pane"> <h1> SA Data Entry </h1> <nav class="main-menu"> <ul> <li id="rep" onclick="updatePane(this.id)">Representative</li> <li id="bill" onclick="updatePane(this.id)">Bill</li> <li id="vote" onclick="updatePane(this.id)">Votes</li> <li id="cat" onclick="updatePane(this.id)">Budget Categories</li> <li id="val" onclick="updatePane(this.id)">Budget Values</li> </ul> </nav> <div id="rep-data" <?php if ($type != "rep") { echo 'style="display:none;"'; } ?> > <form action="" method="post"> <div class="form-add"> <h3>Representative Input</h3> First name:<br> <input type="text" name="firstname"><br> Last name:<br> <input type="text" name="lastname"><br> Student ID (for email):<br> <input type="text" name="student_id"><br> Class Year:<br> <input type="number" name="classyear"><br> Position:<br> <input type="radio" name="position" value="pres" checked>President<br> <input type="radio" name="position" value="vp">Vice President<br> <input type="radio" name="position" value="senator">Senator<br> <input type="radio" name="position" value="classpres">Class President<br> Bio:<br> <textarea type="text" name="bio"></textarea><br> Picture URL:<br> <input type="text" name="picture_url"><br> <input type="submit" name="add" value="Submit"> <input type="hidden" name="type" value="rep"> <!-- Used when processing form --> </div> <div class="form-remove"> <h3>Representative Removal</h3> <?php //Load all representatives $results = $wpdb->get_results("SELECT rep_id, firstname, lastname FROM {$rep_table};", OBJECT); echo '<select name="rep_id">'; foreach ($results as $rep) { echo "<option value=" . $rep->rep_id . "> " . $rep->firstname . " " . $rep->lastname . "</option>"; } echo "</select><br>"; ?> <input type="checkbox" name="deleteDep" value=1>Delete all votes associated with this representative<br> <input type="submit" name="remove" value="Submit"> </div> </form> </div> <div id="bill-data" <?php if ($type != "bill") { echo 'style="display:none;"'; } ?> > <form action="" method="post"> <div class="form-add"> <h3>Bill Input</h3> Bill Name:<br> <input type="text" name="name"><br> Vote Date:<br> <input type="date" name="vote_date"><br> Description:<br> <textarea type="text" name="description"></textarea><br> Result:<br> <input type="radio" name="result" value="pass" checked>Passed<br> <input type="radio" name="result" value="withdrawn">Withdrawn<br> <input type="radio" name="result" value="fail">Failed<br> <input type="radio" name="result" value="tabled">Tabled<br> <input type="submit" name="add" value="Submit"> <input type="hidden" name="type" value="bill"> <!-- Used when processing form --> </div> <div class="form-remove"> <h3>Bill Removal</h3> <?php //Load all bills $results = $wpdb->get_results("SELECT bill_id, name, vote_date FROM {$bill_table};", OBJECT); echo '<select name="bill_id">'; foreach ($results as $bill) { echo "<option value=" . $bill->bill_id . "> " . $bill->name . " " . "</option>"; } echo "</select><br>"; ?> <input type="checkbox" name="deleteDep" value=1>Delete all votes associated with this bill<br> <input type="submit" name="remove" value="Submit"> </div> </form> </div> <div id="vote-data" <?php if ($type != "vote") { echo 'style="display:none;"'; } ?> > <form action="" method="post"> <div class="form-add"> <h3>Votes Input</h3> Representative:<br> <?php $results = $wpdb->get_results("SELECT rep_id, firstname, lastname FROM {$rep_table};", OBJECT); echo '<select name="rep">'; foreach ($results as $rep) { echo "<option value=" . $rep->rep_id . "> " . $rep->firstname . " " . $rep->lastname . "</option>"; } echo "</select><br>"; ?> Bill Name:<br> <?php $results = $wpdb->get_results("SELECT bill_id, name FROM {$bill_table};", OBJECT); echo '<select name="bill">'; foreach ($results as $bill) { echo "<option value=" . $bill->bill_id . "> " . $bill->name . "</option>"; } echo "</select><br>"; ?> Result:<br> <input type="radio" name="vote" value="sponsor" checked>Sponsored (Aye)<br> <input type="radio" name="vote" value="aye">Aye<br> <input type="radio" name="vote" value="nay">Nay<br> <input type="radio" name="vote" value="abstain">Abstain<br> <input type="submit" name="add" value="Submit"> <input type="hidden" name="type" value="vote"> <!-- Used when processing form --> </div> <div class="form-remove"> <h3>Vote Removal</h3> <?php //Load all votes $results = $wpdb->get_results("SELECT vote_id, rep_id, bill_id FROM {$vote_table};", OBJECT); echo '<select name="vote_id">'; foreach ($results as $vote) { //TODO: refactor, use joins for god's sake $rep = $wpdb->get_results("SELECT firstname, lastname FROM {$rep_table} WHERE rep_id=" . $vote->rep_id . ";", OBJECT); $bill = $wpdb->get_results("SELECT name FROM {$bill_table} WHERE bill_id=" . $vote->bill_id . ";", OBJECT); echo "<option value=" . $vote->vote_id . "> " . $rep[0]->firstname . " " . $rep[0]->lastname . ", " . $bill[0]->name . "</option>"; } echo "</select><br>"; ?> <input type="submit" name="remove" value="Submit"> </div> </form> </div> <div id="cat-data" <?php if ($type != "cat") { echo 'style="display:none;"'; } ?> > <form action="" method="post"> <div class="form-add"> <h3>Budget Category Input</h3> Budget Category Name:<br> <input type="text" name="name"><br> Category Description:<br> <textarea type="text" name="description"></textarea><br> <input type="submit" name="add" value="Submit"> <input type="hidden" name="type" value="cat"> <!-- Used when processing form --> </div> <div class="form-remove"> <h3>Category Removal</h3> <?php //Load all categories $results = $wpdb->get_results("SELECT budget_id, name FROM {$cat_table};", OBJECT); echo '<select name="budget_id">'; foreach ($results as $cat) { echo "<option value=" . $cat->budget_id . "> " . $cat->name . " " . "</option>"; } echo "</select><br>"; ?> <input type="checkbox" name="deleteDep" value=1>Delete all values associated with this budget category<br> <input type="submit" name="remove" value="Submit"> </div> </form> </div> <div id="val-data" <?php if ($type != "val") { echo 'style="display:none;"'; } ?> > <form action="" method="post"> <div class="form-add"> <h3>Budget Value Input</h3> Budget Category Name:<br> <?php $results = $wpdb->get_results("SELECT budget_id, name FROM {$cat_table};", OBJECT); echo '<select name="cat">'; foreach ($results as $cat) { echo "<option value=" . $cat->budget_id . "> " . $cat->name . "</option>"; } echo "</select><br>"; ?> Date:<br> <input type="date" name="date"><br> Amount:<br> <input type="number" step="0.01" name="amount"><br> <input type="submit" name="add" value="Submit"> <input type="hidden" name="type" value="val"> <!-- Used when processing form --> </div> <div class="form-remove"> <h3>Budget Value Removal</h3> <?php //Load all categories $results = $wpdb->get_results("SELECT budget_value_id, budget_id, date FROM {$val_table};", OBJECT); echo '<select name="val_id">'; foreach ($results as $cat) { //TODO: lrn 2 sql pls $category = $wpdb->get_results("SELECT name FROM {$cat_table} WHERE budget_id=" . $cat->budget_id . ";", OBJECT); echo "<option value=" . $cat->budget_value_id . "> " . $category[0]->name . ", " . $cat->date . "</option>"; } echo "</select><br>"; ?> <input type="submit" name="remove" value="Submit"> </div> </form> </div> </div> <?php }
function sa_data_entry() { sa_process_form(); //TODO: Reload same section the form was submitted from ?> <div class="sawatch-admin-pane"> <h1> SA Data Entry </h1> <nav class="main-menu"> <ul> <li id="rep" onclick="updatePane(this.id)">Representative</li> <li id="bill" onclick="updatePane(this.id)">Bill</li> <li id="vote" onclick="updatePane(this.id)">Votes</li> <li id="cat" onclick="updatePane(this.id)">Budget Categories</li> <li id="val" onclick="updatePane(this.id)">Budget Values</li> </ul> </nav> <div id="rep-data"> <p>Representative Input</p> <form action="" method="post"> First name:<br> <input type="text" name="firstname"><br> Last name:<br> <input type="text" name="lastname"><br> Class Year:<br> <input type="text" name="classyear"><br> Position:<br> <input type="radio" name="position" value="pres" checked>President<br> <input type="radio" name="position" value="vp">Vice President<br> <input type="radio" name="position" value="senator">Senator<br> Bio:<br> <textarea type="text" name="bio"></textarea><br> Picture URL:<br> <input type="text" name="picture_url"><br> <input type="submit" value="Submit"> <input type="hidden" name="type" value="rep"> <!-- Used when processing form --> </form> </div> <div id="bill-data" style="display:none;"> <p>Bill Input</p> <form action="" method="post"> Bill Name:<br> <input type="text" name="name"><br> Vote Date:<br> <input type="date" name="vote_date"><br> Description:<br> <textarea type="text" name="description"></textarea><br> Result:<br> <input type="radio" name="result" value="pass" checked>Passed<br> <input type="radio" name="result" value="fail">Failed<br> <input type="radio" name="result" value="tabled">Tabled<br> <input type="submit" value="Submit"> <input type="hidden" name="type" value="bill"> <!-- Used when processing form --> </form> </div> <div id="vote-data" style="display:none;"> <p>Votes Input</p> <form action="" method="post"> Representative First Name:<br> <input type="text" name="firstname"><br> Representative Last Name:<br> <input type="text" name="lastname"><br> Bill Name:<br> <textarea type="text" name="bill_name"></textarea><br> Result:<br> <input type="radio" name="vote" value="aye" checked>Aye<br> <input type="radio" name="vote" value="nay">Nay<br> <input type="radio" name="vote" value="abstain">Abstain<br> <input type="submit" value="Submit"> <input type="hidden" name="type" value="vote"> <!-- Used when processing form --> </form> </div> <div id="cat-data" style="display:none;"> <p>Budget Category Input</p> <form action="" method="post"> Budget Category Name:<br> <input type="text" name="name"><br> Category Description:<br> <textarea type="text" name="description"></textarea><br> <input type="submit" value="Submit"> <input type="hidden" name="type" value="cat"> <!-- Used when processing form --> </form> </div> <div id="val-data" style="display:none;"> <p>Budget Value Input</p> <form action="" method="post"> Budget Category Name:<br> <input type="text" name="cat_name"><br> Date:<br> <input type="date" name="date"><br> Amount:<br> <input type="text" name="amount"><br> <input type="submit" value="Submit"> <input type="hidden" name="type" value="val"> <!-- Used when processing form --> </form> </div> </div> <?php }