KevinM1 Posted July 10, 2007 Share Posted July 10, 2007 Like my last few posts, this is about the custom scripts I've been writing for a PHP-Fusion site. The scripts in question deal with editing and deleting user registrations to events listed in a 3rd party event calendar plugin. One script creates a pulldown list of registrations that the user has submitted previously (two if the user is an administrator -- one for their personal registrations, one for all member registrations). Upon selecting the registration(s) they want, the user is directed to another script, which pulls that/those registration(s) from the database. A checkbox is placed next to each record, allowing the user to select the registration(s) they wish to edit or delete. This works perfectly. My problem is this: figuring what to do if the user clicks on either the 'Edit' or 'Delete' form button when there isn't a checked registration. Right now, the script just displays a blank page (albeit with PHP-Fusion chrome), which isn't very useful. I'd like for it to keep the table of registrations on the screen so the user can select what registration(s) they want to mess with, but I don't see how that's possible without rewriting the script, which I really, really don't want to do unless absolutely necessary. And no, AJAX is not an option as I have yet to learn that technology. Here's the code for the two scripts. registration_viewer.php -- the script that generates the pulldown lists: <?php require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; if(!iMEMBER){ fallback(); } if(iADMIN){ //if ADMIN: two lists, one for the events ADMIN registered to, one for ALL events $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; $personalResult = dbquery($personalQuery); $adminQuery = "SELECT * FROM ". DB_PREFIX ."aflac"; $adminResult = dbquery($adminQuery); echo "<form method='post' action='registration_controller.php'>\n<br />\n"; echo "Your registrations: <br /><br />\n"; echo "<select name='personalEvents[]'>\n<br />\n"; echo "<option value='*'>All</option>\n<br />\n"; while($row = mysql_fetch_assoc($personalResult)){ echo "<option value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}'>{$row['ev_title']} -- ". date('M j, Y', $row['login_timestamp']) ."</option>\n<br />\n"; } echo "</select>\n"; echo "<input type='submit' name='personalSubmit' value='Go' />\n<br />\n<br /><br /><br /><br />\n"; echo "All registrations: <br /><br />\n"; echo "<select name='adminEvents[]'>\n<br />\n"; echo "<option value='*'>All</option>\n<br />\n"; while($row = mysql_fetch_assoc($adminResult)){ echo "<option value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}'>{$row['registering_agent']}: {$row['ev_title']} -- ". date('M j, Y', $row['login_timestamp']) ."</option>\n<br />\n"; } echo "</select>\n"; echo "<input type='submit' name='adminSubmit' value='Go' />\n<br />\n<br />\n</form>\n"; } if(iMEMBER && !iADMIN){ //if MEMBER && !ADMIN: one list of events MEMBER registered for $query = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; $result = dbquery($query); echo "<form method='post' action='registration_controller.php'>\n<br />\n"; echo "<select name='events[]'>\n<br />\n"; echo "<option value='*'>All</option>\n<br />\n"; while($row = mysql_fetch_assoc($result)){ echo "<option value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}'>{$row['ev_title']} -- ". date('M j, Y', $row['login_timestamp']) ."</option>\n<br />\n"; } echo "</select>\n"; echo "<input type='submit' name='submit' value='Go' />\n<br />\n</form>\n<br />\n"; } require_once "side_right.php"; require_once "footer.php"; ?> registration_controller.php -- the script that does everything else: <?php require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; if(!iMEMBER){ fallback(); } if(isset($_POST['edit'])){ //for editing registrations. only 1 registration can be edited at a time if(isset($_POST['events'])){ //MEMBER $event = explode(", ", $_POST['events'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $query = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $result = dbquery($query); $row = mysql_fetch_assoc($result); header("Location: ". BASEDIR ."registration.php?evid={$row['ev_id']}®Agent={$row['registering_agent']}&agentWritingNum={$row['agent_writing_number']}&phone={$row['phone']}&email={$row['email']}®Sales={$row['regional_sales_coordinator']}&disSales={$row['district_sales_coordinator']}"); } else if(isset($_POST['personalEvents'])){ //ADMIN $event = explode(", ", $_POST['personalEvents'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $query = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $result = dbquery($query); $row = mysql_fetch_assoc($result); header("Location: ". BASEDIR ."registration.php?evid={$row['ev_id']}®Agent={$row['registering_agent']}&agentWritingNum={$row['agent_writing_number']}&phone={$row['phone']}&email={$row['email']}®Sales={$row['regional_sales_coordinator']}&disSales={$row['district_sales_coordinator']}"); } } else if(isset($_POST['delete'])){ //for deleting events. multiple events can be deleted if(isset($_POST['events'])){ //MEMBER's personal registrations foreach($_POST['events'] as $value){ $event = explode(", ", $value); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $deleteTextQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteTextResults[] = dbquery($deleteTextQuery); $deleteAflacQuery = "DELETE FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteLoginsQuery = "DELETE FROM ". DB_PREFIX ."aw_ec_logins WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteAflacResult = dbquery($deleteAflacQuery); $deleteLoginsResult = dbquery($deleteLoginsQuery); } if($deleteAflacResult && $deleteLoginsResult){ $deleteText = "The following registration(s) have been deleted:\n<br />\n<br />\n"; $deleteText .= "<table cellspacing='0'>\n\t<tr>\n\t\t<th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; foreach($deleteTextResults as $queryResult){ while($row = mysql_fetch_assoc($queryResult)){ $deleteText .= "\n\t<tr class='regtbl1'>\n\t\t<td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } } $deleteText .= "\n</table>\n"; echo $deleteText; } } else if(isset($_POST['personalEvents'])){ //ADMIN's personal registrations foreach($_POST['personalEvents'] as $value){ $event = explode(", ", $value); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $deleteTextQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteTextResults[] = dbquery($deleteTextQuery); $deleteAflacQuery = "DELETE FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteLoginsQuery = "DELETE FROM ". DB_PREFIX ."aw_ec_logins WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteAflacResult = dbquery($deleteAflacQuery); $deleteLoginsResult = dbquery($deleteLoginsQuery); } if($deleteAflacResult && $deleteLoginsResult){ $deleteText = "The following registration(s) have been deleted:\n<br />\n<br />\n"; $deleteText .= "<table cellspacing='0'>\n\t<tr>\n\t\t<th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; foreach($deleteTextResults as $queryResult){ while($row = mysql_fetch_assoc($queryResult)){ $deleteText .= "\n\t<tr class='regtbl1'>\n\t\t<td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } } $deleteText .= "\n</table>\n"; echo $deleteText; } } else if(isset($_POST['adminEvents'])){ //ADMIN: ALL possible registrations foreach($_POST['adminEvents'] as $value){ $event = explode(", ", $value); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $deleteTextQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteTextResults[] = dbquery($deleteTextQuery); $deleteAflacQuery = "DELETE FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteLoginsQuery = "DELETE FROM ". DB_PREFIX ."aw_ec_logins WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $deleteAflacResult = dbquery($deleteAflacQuery); $deleteLoginsResult = dbquery($deleteLoginsQuery); } if($deleteAflacResult && $deleteLoginsResult){ $deleteText = "The following registration(s) have been deleted:\n<br />\n<br />\n"; $deleteText .= "<table cellspacing='0'>\n\t<tr>\n\t\t<th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; foreach($deleteTextResults as $queryResult){ while($row = mysql_fetch_assoc($queryResult)){ $deleteText .= "\n\t<tr class='regtbl1'>\n\t\t<td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } } $deleteText .= "\n</table>\n"; echo $deleteText; } } } if(isset($_POST['personalSubmit'])){ //ADMIN's personal registrations if(isset($_POST['personalEvents']) && $_POST['personalEvents'][0] == '*'){ //if ALL personal registrations are selected $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; $count = 0; while($row = mysql_fetch_assoc($personalResult)){ if($count % 2 == 0){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='personalEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } else{ echo "\n\t<tr class='regtbl2'>\n\t\t<td><input type='checkbox' name='personalEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } $count++; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } else if(isset($_POST['personalEvents']) && $_POST['personalEvents'][0] != ''){ //for singular personal registrations $event = explode(", ", $_POST['personalEvents'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; while($row = mysql_fetch_assoc($personalResult)){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='personalEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } } if(isset($_POST['submit'])){ //non-ADMIN's personal registrations if(isset($_POST['events']) && $_POST['events'][0] == '*'){ //if ALL personal registrations are selected $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '". $userdata['user_id'] ."'"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; $count = 0; while($row = mysql_fetch_assoc($personalResult)){ if($count % 2 == 0){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='events[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } else{ echo "\n\t<tr class='regtbl2'>\n\t\t<td><input type='checkbox' name='events[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } $count++; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } else if(isset($_POST['events']) && $_POST['events'][0] != ''){ //for singular personal registrations $event = explode(", ", $_POST['events'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $personalQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE user_id = '$user_id' AND ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $personalResult = dbquery($personalQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; while($row = mysql_fetch_assoc($personalResult)){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='events[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } echo "</table>\n<input type='submit' name='edit' value='Edit' /><input type='submit' name='delete' value='Delete' />\n</form>"; } } if(isset($_POST['adminSubmit'])){ //ADMIN-only: ALL possible event registrations if(isset($_POST['adminEvents']) && $_POST['adminEvents'][0] == '*'){ //if ALL registrations are selected $adminQuery = "SELECT * FROM ". DB_PREFIX ."aflac"; $adminResult = dbquery($adminQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; $count = 0; while($row = mysql_fetch_assoc($adminResult)){ if($count % 2 == 0){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='adminEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } else{ echo "\n\t<tr class='regtbl2'>\n\t\t<td><input type='checkbox' name='adminEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } $count++; } echo "</table>\n<input type='submit' name='delete' value='Delete' />\n</form>"; } else if(isset($_POST['adminEvents']) && $_POST['adminEvents'][0] != ''){ //for singular registrations $event = explode(", ", $_POST['adminEvents'][0]); $user_id = $event[0]; $ev_id = $event[1]; $login_timestamp = $event[2]; $adminQuery = "SELECT * FROM ". DB_PREFIX ."aflac WHERE ev_id = '$ev_id' AND login_timestamp = '$login_timestamp'"; $adminResult = dbquery($adminQuery); echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n"; echo "<table cellspacing='0'>\n\t<tr>\n\t\t<th></th><th>Registering Agent</th><th>Agent Writing Number</th><th>Phone Number</th><th>E-mail Address</th><th>Regional Sales Coordinator</th><th>District Sales Coordinator</th>\n\t</tr>"; while($row = mysql_fetch_assoc($adminResult)){ echo "\n\t<tr class='regtbl1'>\n\t\t<td><input type='checkbox' name='adminEvents[]' value='{$row['user_id']}, {$row['ev_id']}, {$row['login_timestamp']}' /></td><td>{$row['registering_agent']}</td><td>{$row['agent_writing_number']}</td><td>{$row['phone']}</td><td>{$row['email']}</td><td>{$row['regional_sales_coordinator']}</td><td>{$row['district_sales_coordinator']}</td>\n\t</tr>"; } echo "</table>\n<input type='submit' name='delete' value='Delete' />\n</form>"; } } require_once "side_right.php"; require_once "footer.php"; ?> Any ideas? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 10, 2007 Share Posted July 10, 2007 Why not just use JavaScript? That's pretty much what it was invented for. When either of those buttons are pressed, but before form submission takes place, loop through the checkboxes. If none are selected, either display an alert('Check something already') or silently refuse to submit. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 10, 2007 Author Share Posted July 10, 2007 Why not just use JavaScript? That's pretty much what it was invented for. When either of those buttons are pressed, but before form submission takes place, loop through the checkboxes. If none are selected, either display an alert('Check something already') or silently refuse to submit. Good idea. It's funny -- I know JavaScript (more or less, anyway), but still tend to avoid it. Must be leftover loathing from the 1990's when seemingly every site had a plethora of frames and JavaScript errors. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.