Error\n"; 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 "

This Concept was Added to Your Favorites

\n"; } else{ //the new favorite failed echo "

Error

\n"; 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 "

Error

\n"; 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 "

Success

\n"; echo "

The selected conception was removed from your favorites.

\n"; } else{ //the remove was NOT successful echo "

Error

\n"; 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 "

Error

\n"; 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 "

Error

\n"; 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 "

Error

\n"; 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 "

Your Favorites

\n"; while($myrow=mysql_fetch_row($result)){ //show the results echo "
\n"; //now we actually output the conception entries 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 "Read this conception in a new window "; echo "Visualize a Concept Web! "; echo "Email this conception "; echo "Print this conception "; echo "Remove this conception from your Favorites "; echo "
$previewString
\n"; echo "
\n"; //add this entry to the bibliography and year array $CONCEPT_ID_ARRAY[]=$myrow[0]; } $conceptIDList=implode(",", $CONCEPT_ID_ARRAY); if($conceptIDList){ echo "

View a bibliography of your favorites

\n"; } } elseif($result && mysql_num_rows($result)<1){ //there are no favorites to show echo "

Your Favorites

\n"; 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 "

Error

\n"; echo "

We could not access your favorites. Please try again.

\n"; } include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php"); ?>