include "includes/dbConnNew.php";
$recid = $_REQUEST["recid"];
if($_REQUEST["comp"] == "y"){
$compMessage ="Thanks for complimenting the chef!" ;
}
if($_REQUEST["rate"] == "y"){
$compMessage ="Thanks for rating the chef!" ;
}
if($_REQUEST["comp"] == "y" && $_REQUEST["rate"] == "y"){
$compMessage ="Thanks for complimenting the chef!" ;
}
//*********************************************************
//* vote for a recipe
//*********************************************************
if( $_POST["theAction"] == "vote"){
//check if user is logged in
if( ! $_SESSION['loggedIn'] ){
header("Location: logonFridge.php");
exit ;
}else{
//see if user voted for this recipe already today
$today = date("Y-m-d") ;
$sqlUser = "select * from votes where (USER_ID = '" . $_SESSION["sessionUserID"] . "') and (DATE_ADDED = '$today') and (RECIPE_ID = '" . $_REQUEST["recid"] . "')";
$resultUser = mysql_query($sqlUser) or die(mysql_error());
if($myrowUser=MySQL_fetch_array($resultUser)){
//user has already voted for this recipe today - don't record the vote - show message
$voteMessage = "You've already voted for this recipe today. Please try again tomorrow.";
}else{
//this is the first time the user has voted for this recipe today - DO record the vote - show message
$sqlInsert = "INSERT INTO votes (USER_ID, DATE_ADDED, RECIPE_ID, IP_ADDRESS) values ('" . $_SESSION["sessionUserID"] . "', '$today', '" . $_REQUEST["recid"] . "', '$logged_string')";
$resultInsert = mysql_query($sqlInsert) or die(mysql_error());
$voteMessage = "Thanks for voting! Remember you can vote for all of your favorite recipes!";
}
}
}
//***********************************************************
//* end of voting for a recipe
//***********************************************************
// add to mycookbook
if($_REQUEST["act"] == "y" && $recid > " " && $_SESSION["sessionUserID"] > " "){
$sql = "select * from cookbook where (Recipe_ID='$recid' and User_ID = '" . $_SESSION["sessionUserID"] . "')";
$result = mysql_query($sql) or die(mysql_error());
if($myrow=MySQL_fetch_array($result)){
$added = "The recipe was added to your Cookbook." ;
} else {
$sqlR = "INSERT INTO cookbook (User_ID, Recipe_ID) VALUES ('" . $_SESSION['sessionUserID'] . "', '$recid')";
mysql_query($sqlR);
$added = "The recipe was added to your Cookbook." ;
}
}
if($_REQUEST["act"] == "y" && $recid > " " && !$_SESSION["sessionUserID"]){
$added = "Please login or register to add this recipe to your Cookbook." ;
}
$sqlrp = "select * from recipes where (ID='$recid')";
$resultrp = mysql_query($sqlrp) or die(mysql_error());
if($myrowrp=MySQL_fetch_array($resultrp)){
$photo = $myrowrp["Photo"];
$Recipe_Name = $myrowrp["Recipe_Name"];
$User_ID = $myrowrp["User_ID"];
$winner = $myrowrp["winner"];
if(($myrowrp["Prep_Time_Hours"] > " ") && ($myrowrp["Prep_Time_Minutes"] > " ")){
$prepTime = $myrowrp["Prep_Time_Hours"]. ":". $myrowrp["Prep_Time_Minutes"] ;
}
if($myrowrp["Prep_Time_Hours"] > " " && $myrowrp["Prep_Time_Minutes"] < " "){
$prepTime = $myrowrp["Prep_Time_Hours"] . ":00" ;
}
if($myrowrp["Prep_Time_Hours"] < " " && $myrowrp["Prep_Time_Minutes"] > " "){
$prepTime = $myrowrp["Prep_Time_Minutes"] . "min" ;
}
if($myrowrp["Total_Time_Hours"] < " " && $myrowrp["Total_Time_Minutes"] > " "){
$totTime = $myrowrp["Total_Time_Minutes"] . "min" ;
}
if($myrowrp["Total_Time_Hours"] > " " && $myrowrp["Total_Time_Minutes"] > " "){
$totTime = $myrowrp["Total_Time_Hours"] . ":" . $myrowrp["Total_Time_Minutes"] ;
}
if($myrowrp["Total_Time_Hours"] > " " && $myrowrp["Total_Time_Minutes"] < " "){
$totTime = $myrowrp["Total_Time_Hours"] . ":00" ;
}
}
//get the user who submitted this
$submitBy = "A Yadahome user";
$sqlU = "select * from users where (ID = '$User_ID') ";
$resultU = mysql_query($sqlU) or die(mysql_error());
if($myrowU=MySQL_fetch_array($resultU)){
$submitBy = $myrowU["First_Name"];
if( ($myrowU["State_Reside"] > " ") && ($myrowU["City"] > " ")){ $submitBy .= " of " . $myrowU["City"] . ", " . $myrowU["State_Reside"]; }
if( ($myrowU["City"] > " ") && ($myrowU["State_Reside"] <= " ") ){ $submitBy .= " of " . $myrowU["City"]; }
if( ($myrowU["City"] <= " ") && ($myrowU["State_Reside"] > " ") ){ $submitBy .= " of " . $myrowU["State_Reside"]; }
}
$rating = 3;
//get recipe rating $recid
$sqlr = "select round(avg(Rating)) as Rating from ratings where For_Recipe_ID = '$recid'";
$resultr = mysql_query($sqlr) or die(mysql_error());
if($myrowr=MySQL_fetch_array($resultr)){
$rating = $myrowr["Rating"];
if($rating < 1){ $rating = 1;}
if($rating > 5){ $rating = 5;}
if($myrowr["Rating"] == 0){$rating = 3;}
}
//*******************************
?>
Recipe for = $Recipe_Name ?>
include 'beforeEndHead.php'; ?>
echo $rating; ?>
include('savingsCenter.php') ?>
include "googAna.php"; ?>