//the title of this page is View Conception $pageTitle="Favorite Conceptions"; include($_SERVER['DOCUMENT_ROOT'] . "/template/header.php"); //need to see if they submitted a search $ERROR=false; $id=0; //The user must be logged in before we can do anything with favorites //Check to make sure they are if(user_logged_in() && !$doingLogout){ $username=substr($_COOKIE['sclcr'], 0, 255); } else{ //the user isn't logged in so we have to kill the page $username="unknown"; echo "
Sorry, you must be logged in to use the Favorites function. Please login to your account.
\n"; include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php"); exit(); } if( isset($_GET['id']) && isset($_GET['action']) ){ //they submitted an ID so now we try to make it a favorite $conceptID=$_GET['id']; $action=$_GET['action']; if( is_numeric($conceptID) && $conceptID>=1 && $action=="add" ){ $result=database_query("SELECT id FROM ConceptsBeta WHERE id=$conceptID LIMIT 1"); if($result && mysql_num_rows($result)==1){ //the concept is GOOD so let's add it to the person's favorites $mysqlQuery="INSERT INTO Favorites (user, conceptID, created) VALUES ('$username', $conceptID, NOW())"; $result = database_query($mysqlQuery); if($result){ //the new favorite was added echo "There was a problem adding this conception to your favorites. Please go back and try again.
\n"; echo "username: $username
\n"; echo "conceptID: $conceptID
\n"; echo "query: $mysqlQuery
\n"; } } else{ //there was no conception with that ID echo "Sorry, there is no conception with that ID. Please try again.
\n"; } } elseif( is_numeric($conceptID) && $conceptID>=1 && $action=="remove" ){ //let's make sure the concept actually exists as tied to this user $mysqlQuery="SELECT id FROM Favorites WHERE conceptID=$conceptID AND user='$username' LIMIT 1"; $result=database_query($mysqlQuery); if($result && mysql_num_rows($result)==1){ //the entry exists so let's get rid of it $mysqlQuery="DELETE FROM Favorites WHERE conceptID=$conceptID AND user='$username'"; $result=database_query($mysqlQuery); if($result){ //the remove was successful echo "The selected conception was removed from your favorites.
\n"; } else{ //the remove was NOT successful echo "Sorry, but we experienced a technical problem. The selected conception was NOT removed from your favorites. Please try again in a few moments.
\n"; } } elseif($result && mysql_num_rows($result)==0){ //the query worked but there were no rows so they are trying to remove an entry that doesn't exist echo "The conception you asked to remove isn't in your favorites. No changes were made.
\n"; } else{ //something went wrong, throw an error. echo "Sorry, there was a technical problem. No changes were made. Please try again in a few moments
\n"; } } else{ //they did not provide a legit concept ID echo "Sorry, there is a problem with the concept ID you provided. Please try it again.
\n"; echo "conceptID: $conceptID
\n"; echo "action: $action
\n"; } } /****************************************** //Now we show the list of current favorites ******************************************/ $mysqlQuery="SELECT ConceptsBeta.id, TRIM(ConceptsBeta.concept), ConceptsBeta.conception, ConceptsBeta.year, Authors.name, ConceptsBeta.contributor FROM (ConceptsBeta LEFT JOIN Keywords ON ConceptsBeta.id = Keywords.conceptID) LEFT JOIN Authors ON ConceptsBeta.id = Authors.conceptID, Favorites WHERE Favorites.user='$username' AND Favorites.conceptID=ConceptsBeta.id AND ConceptsBeta.status=1 GROUP BY ConceptsBeta.id ORDER BY ConceptsBeta.concept ASC, ConceptsBeta.year ASC LIMIT 200"; $result=database_query($mysqlQuery); if($result && mysql_num_rows($result)>=1){ echo ""; //now we create the preview string to show $previewString=substr(strip_tags($myrow[2]), 0, 220) . "..."; echo "" . ucwords($myrow[1]) . " (" . $myrow[3] . ") by " . $myrow[4]; echo " | \n"; //now we display any appropriate action icons echo " "; echo " "; echo " "; echo " "; echo " "; echo " |
$previewString |
View a bibliography of your favorites
\n"; } } elseif($result && mysql_num_rows($result)<1){ //there are no favorites to show echo "You do not have any favorites yet.
\n"; echo "When viewing a conception or in the search results click the gold star to add that conception to your favorites.
\n"; } else{ //problem getting a list of the current favorites echo "We could not access your favorites. Please try again.
\n"; } include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php"); ?>