From d895b852a6e160496ffc760d46d3719a3d62ff86 Mon Sep 17 00:00:00 2001 From: Nathan Kinkade Date: Sun, 3 Feb 2008 23:23:24 +0000 Subject: Initial checkin of nutridb.org and basic subversion directory structure --- nutrient_chooser.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 nutrient_chooser.php (limited to 'nutrient_chooser.php') diff --git a/nutrient_chooser.php b/nutrient_chooser.php new file mode 100644 index 0000000..875801d --- /dev/null +++ b/nutrient_chooser.php @@ -0,0 +1,80 @@ +_rootUri}/"); + exit; +} + +# the user clicked "Save Changes" so we'll remove all of their previous nutrients +# and add the ones submitted with the form +if ( isset($_POST['setNutrients']) ) { + $status = "true"; + $sql = sprintf (" + DELETE FROM userNutrients + WHERE user = '%s' + ", + $_SESSION['user']['id'] + ); + $db->Modify($sql); + if ( $db->_error ) { + $status = "false"; + } else { + if ( ! empty($_POST['nutrient']) ) { + foreach ( $_POST['nutrient'] as $nutrient ) { + $sql = sprintf (" + INSERT INTO userNutrients(user, nutrient) + VALUES ('%s','%s') + ", + $_SESSION['user']['id'], + $nutrient + ); + $db->Modify($sql); + if ( $db->_error ) { + $status = "false"; + } + } + } + } + if ( $status == "true" ) { + $_SESSION['systemMsg'] = "Your nutrient list was updated successfully."; + } else { + $_SESSION['systemMsg'] = "There were errors saving your nutrient list."; + } + # redirect the user back to this same page with a GET request + header("Location: {$config->_rootUri}/nutrient_chooser.php"); + exit; +} + +# grab the current nutrient list from the database and assign list to template +$sql = sprintf (" + SELECT nutrientDefs.nutr_no, nutrientDefs.nutrdesc, + userNutrients.nutrient AS myNutrient + FROM nutrientDefs LEFT JOIN userNutrients + ON nutrientDefs.nutr_no = userNutrients.nutrient AND userNutrients.user = '%s' + ORDER BY COALESCE(myNutrient, '999999'), nutrientDefs.sr_order + ", + $_SESSION['user']['id'] +); +$db->Select($sql); +$smarty->assign("nutrients", $db->_rows); + +# grab the various parts. these sections are not printed to the screen +# but rather dumped into smarty variables that will simply be printed +# in the template, so the order doesn't matter here at the moment +require("header.php"); +require("sidebar_left.php"); +require("sidebar_right.php"); +require("footer.php"); + +$smarty->display("nutrient_chooser.tpl"); + +?> -- cgit v1.2.3