1
0
mirror of https://github.com/fspc/Yellow-Bike-Database.git synced 2025-02-23 01:03:23 -05:00

This completes the interest survey logic.

1).  In confs, update works well, delete has an issue with on delete cascade.
2).  Saves state properly.  Now just need to create a front-end to query for volunteer organizers.
This commit is contained in:
Jonathan Rosenbaum 2015-03-06 08:27:15 +00:00
parent 433ab1a224
commit e9e3a0ef66
3 changed files with 60 additions and 32 deletions

View File

@ -67,7 +67,7 @@ $volunteer_interests = array(
"Publicizing/Outreach", "Graphic Design", "Greeter at the Front Desk", "Publicizing/Outreach", "Graphic Design", "Greeter at the Front Desk",
"Accounting/Record Keeping", "Ordering parts/supplies", "Picking up Donated Bikes/Parts", "Accounting/Record Keeping", "Ordering parts/supplies", "Picking up Donated Bikes/Parts",
"Teaching classes", "League Certified Instructor", "Pricing bikes", "Teaching classes", "League Certified Instructor", "Pricing bikes",
"Fabricating", "Open Source Programming", "Other/Contact me for general help" "Fabricating", "Open Source Programming", "Other/Contact me for general help"
); );
// Provide a comment box - true of false // Provide a comment box - true of false
@ -99,7 +99,6 @@ define("VOLUNTEER_INTEREST_COMMENTS", true);
// //
//$volunteer_interests_deletename = array("LCI"); //$volunteer_interests_deletename = array("LCI");
/*********** /***********
TRANSACTIONS TRANSACTIONS
************/ ************/

View File

@ -3,11 +3,11 @@
require_once('Connections/YBDB.php'); require_once('Connections/YBDB.php');
require_once('Connections/database_functions.php'); require_once('Connections/database_functions.php');
/*
require_once('php-console/src/PhpConsole/__autoload.php'); /*require_once('php-console/src/PhpConsole/__autoload.php');
$handler = PhpConsole\Handler::getInstance(); $handler = PhpConsole\Handler::getInstance();
$handler->start(); $handler->start();*/
*/
$waiver = WAIVER; $waiver = WAIVER;
$email_list = EMAIL_LIST; $email_list = EMAIL_LIST;
@ -116,22 +116,23 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error()); $Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
// Are there any interests in the datatbase? // Are there any interests in the datatbase?
$sql = "SELECT option_name FROM options;"; $interests = [];
$sql = "SELECT option_name, option_name_id FROM options;";
$query = mysql_query($sql, $YBDB) or die(mysql_error()); $query = mysql_query($sql, $YBDB) or die(mysql_error());
while ($result = mysql_fetch_assoc($query)) { while ($result = mysql_fetch_assoc($query)) {
$interests[] = $result["option_name"]; $interests[$result["option_name"]] = $result["option_name_id"];
} }
$interests = array_combine($interests,$interests);
if ($volunteer_interest_form && !isset($volunteer_interests_changename)) { if ($volunteer_interest_form && !isset($volunteer_interests_changename)) {
// populate database with user defined interests if they do not exist // populate database with user defined interests if they do not exist
$volunteer_interest = array_combine($volunteer_interests,$volunteer_interests); $volunteer_interest = array_combine($volunteer_interests,$volunteer_interests);
$c = 0;
foreach ($volunteer_interest as $interest) { foreach ($volunteer_interest as $interest) {
// Insert new interest // Insert new interest
if ( !$interests[$interest] ) { if ( is_null($interests[$interest]) ) {
$query = "INSERT INTO options (option_name) VALUES ('" . $interest . "');"; $query = "INSERT INTO options (option_name) VALUES('" . $interest . "');";
$result = mysql_query($query, $YBDB) or die(mysql_error()); $result = mysql_query($query, $YBDB) or die(mysql_error());
} }
} }
@ -142,7 +143,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
if( isset($volunteer_interests_changename) ) { if( isset($volunteer_interests_changename) ) {
foreach ($volunteer_interests_changename as $key => $interest) { foreach ($volunteer_interests_changename as $key => $interest) {
$sql = "UPDATE options SET option_name='" . $interest . $sql = "UPDATE options SET option_name='" . $interest .
"' WHERE option_name='" . $interests[$key] . "';"; "' WHERE option_name='" . $key . "';";
$query = mysql_query($sql, $YBDB) or die(mysql_error()); $query = mysql_query($sql, $YBDB) or die(mysql_error());
} }
} else if( isset($volunteer_interests_deletename) ) { } else if( isset($volunteer_interests_deletename) ) {
@ -160,16 +161,29 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
} }
} }
foreach ($interests as $interest) { // Find out if any selections are in the database,
// to decide whether an INSERT or DELETE needs to be done
$sql = "SELECT selection FROM selections;";
$query = mysql_query($sql, $YBDB) or die(mysql_error());
$selections = [];
while ($result = mysql_fetch_assoc($query)) {
$selections[$result["selection"]] = $result["selection"];
}
if($interest_checked[$interest]) { foreach ($interests as $selection => $interest_id) {
$sql = "UPDATE options SET option_value=1 WHERE option_name='" . $interests[$interest] . "';"; if ( is_null($selections[$interest_id]) ) { //INSERT
$query = mysql_query($sql, $YBDB) or die(mysql_error()); if( !is_null($interest_checked[$selection]) ) {
} else { $sql = "INSERT INTO selections (contact_id, selection, selection_value)
$sql = "UPDATE options SET option_value=0 WHERE option_name='" . $interests[$interest] . "';"; VALUES (" . $_POST['contact_id'] . ",'" . $interest_id . "',1);";
$query = mysql_query($sql, $YBDB) or die(mysql_error()); $result = mysql_query($sql, $YBDB) or die(mysql_error());
}
} else { //DELETE
if( is_null($interest_checked[$selection]) ) {
$sql = "DELETE FROM selections WHERE selection=" . $interest_id .
" AND contact_id=" . $_POST['contact_id'] . ";";
$query = mysql_query($sql, $YBDB) or die(mysql_error());
}
} }
} }
@ -289,6 +303,14 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
<table> <table>
<tr><td>&nbsp;</td></tr> <tr><td>&nbsp;</td></tr>
<?php <?php
$sql = " SELECT options.option_name AS selection FROM selections, options
WHERE selections.selection=options.option_name_id;";
$query = mysql_query($sql, $YBDB) or die(mysql_error());
$selections = [];
while ($result = mysql_fetch_assoc($query)) {
$selections[$result["selection"]] = $result["selection"];
}
$columns = 3; $columns = 3;
$c = 0; $c = 0;
$rows = 0; $rows = 0;
@ -298,9 +320,16 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1);
for($i = $rows - $columns; $i < $rows; $i++) { for($i = $rows - $columns; $i < $rows; $i++) {
if($volunteer_interests[$i]) { if($volunteer_interests[$i]) {
echo "<td><input name='interest_checkboxes[]' class='interest_checkboxes'
value='$volunteer_interests[$i]' type='checkbox'>" . if($volunteer_interests[$i] === $selections[$volunteer_interests[$i]]) {
$volunteer_interests[$i] . "</td>"; echo "<td><input name='interest_checkboxes[]' class='interest_checkboxes'
value='$volunteer_interests[$i]' type='checkbox' checked>" .
$volunteer_interests[$i] . "</td>";
} else {
echo "<td><input name='interest_checkboxes[]' class='interest_checkboxes'
value='$volunteer_interests[$i]' type='checkbox'>" .
$volunteer_interests[$i] . "</td>";
}
} }
} }
echo "</tr>"; echo "</tr>";

View File

@ -200,17 +200,17 @@ ALTER TABLE transaction_log MODIFY description text(2048) DEFAULT NULL;
-- --
CREATE TABLE IF NOT EXISTS options ( CREATE TABLE IF NOT EXISTS options (
option_name_id int(10) unsigned NOT NULL AUTO_INCREMENT, option_name_id int(10) unsigned NOT NULL AUTO_INCREMENT,
option_name varchar(64) NOT NULL, option_name varchar(64) NOT NULL UNIQUE,
PRIMARY KEY (option_name_id) PRIMARY KEY (option_name_id)
); ) DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
-- selections -- selections
-- stores the volunteer interest selections made by people -- stores the volunteer interest selections made by people
-- --
CREATE TABLE IF NOT EXISTS selections ( CREATE TABLE IF NOT EXISTS selections (
contact_id int(10) unsigned, contact_id int(10) unsigned,
selection int(10) unsigned, selection int(10) unsigned UNIQUE,
selection_value int(10) unsigned, selection_value text,
FOREIGN KEY (contact_id) REFERENCES contacts (contact_id) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (contact_id) REFERENCES contacts (contact_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (selection) REFERENCES options (option_name_id) ON DELETE CASCADE ON UPDATE CASCADE FOREIGN KEY (selection) REFERENCES options (option_name_id) ON DELETE CASCADE ON UPDATE CASCADE
); ) DEFAULT CHARSET=latin1;