Location: PHPKode > projects > The Community Wish List Server > wlserver/index.php
<?php

/*
	index.php
	This is the main program for the wish list application at Stonegoose.
*/

require_once("../config.php");

if($a=="b") { // If a==b then the user is looking at their own wish list and came from another's
	$_SESSION['currentView'] = $_SESSION['currentUser'];
	$show = $_SESSION['currentUser'];
}

if(isset($show)) {
	$_SESSION['currentView'] = $show;
} else {
	$show = $_SESSION['currentView'];
}

//	Retrieve and set the "show images" flag.
$_SESSION['imagesOff'] = $_GET['imoff'];

//	Retrieve and set the "Show Help Tips" flag
$_SESSION['showHelp'] = $_GET['sH'];

//	Create wish list and user objects based on the user key.
//	See documentation in wishlist.php class.
//	Also retrieve user name and summary (blurb)
$myList1=new WishList($_SESSION['currentView']);
$listOwner = new User($_SESSION['currentView']);
$thisUser = new User($_SESSION['currentUser']);
$userName=$myList1->name;
$blurb=$myList1->blurb;


//	If there is no HTML in the blurb, put a pretty box around it.

if ($blurb != "") {
	if (!ereg("<[^>]*>",$blurb)) {
		$blurb="<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\"><tr><td>";
		$blurb .= nl2br($blurb)."</td></tr></table>";
	}
}


//	Is it near Christmas?  If so, then make happy Christmas message.
$currDate=getdate();
$thisMonth = $currDate["mon"];
$today = $currDate["mday"];
if ( ( ($thisMonth == 12) && ($today > 21) ) || ( ($thisMonth == 1) && ($today < 7) ) ) $pcm = 1;


//	Now start printing up the page itself as an XHTML document.
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
print("<!DOCTYPE html\n");
print("PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n");
print("\t\" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\" >\n");
print("\t<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n");
print("\t\t<head>\n");
print("\t\t\t<title>$userName's Wish List at StoneGoose.com</title>\n");
print("<script language=\"JavaScript1.2\" type=\"text/javascript\" src=\"wishlist.js\"></script>\n");
print("<link rel=\"STYLESHEET\" type=\"text/css\" href=\"wishlist.css\" />");
print("\t\t</head>\n");
print("\t<body bgcolor=\"#ffffff\">\n");

//	If the user has chosen to view help tips, then add this JavaScript

if ($_SESSION['showHelp'] == 1) {
?>

<!-- This is the JavaScript which enables the tool-tips functionality -->
<script>

/*
Text Link/Image Map Tooltip Script- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, and 100's more DHTML scripts
Visit http://www.dynamicdrive.com
*/

var puMsg = new Array(15)

puMsg[1]="Click here to turn <?php ($ioff==1 ? print("on") : print("off")) ?> images in this user's wish list";
puMsg[2]="Click here to turn off these useful popup help messages";
puMsg[3]="Click here to change your login password";
puMsg[4]="Click here to log out of the Stone Goose wish list program";
puMsg[5]="Click here for a cleanly formatted version of this wish list (without images) suitable for printing";
puMsg[6]="Click here for a list of all of the items that you have claimed and who you've claimed them for";
puMsg[7]="Click here to change the list of names that shows in this popup menu";
puMsg[8]="Click here to return to your own wish list";
puMsg[9]="If you plan to purchase this item for <?php print("$userName"); ?>, click here";
puMsg[10]="Click here to make changes to this item's name, link, or description";
puMsg[11]="Click here to permanently delete this item from your wish list";
puMsg[12]="Click here when you have received this gift";
puMsg[13]="Click here to view a description of this item on the World Wide Web";
puMsg[14]="If you have decided not to purchase this item for <?php print("$userName"); ?>, click here";
puMsg[15]="If you have purchased this item for <?php print("$userName"); ?>, click here";

if (!document.layers&&!document.all&&!document.getElementById)
	event="test"

function popup(current,e,puNum){

	text=puMsg[puNum]
	if (document.all||document.getElementById){
		thetitle=text.split('<br>')
		if (thetitle.length>1){
			thetitles=''
			for (i=0;i<thetitle.length;i++)
			thetitles+=thetitle[i]
			current.title=thetitles
		}
		else
		current.title=text
	}
	else if (document.layers){
		document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
		document.tooltip.document.close()
		document.tooltip.left=e.pageX+5
		document.tooltip.top=e.pageY+5
		document.tooltip.visibility="show"
	}
}

function kill(){
	if (document.layers)
	document.tooltip.visibility="hidden"
}

</script>
<div id="tooltip" style="position:absolute;visibility:hidden"></div>

<?php
}


//  Is the user looking at their own wish list?
//	$sgwluk = Stone Goose Wish List User Key -- the cookie on the user's computer
//	$sgwlsk = "Show Key" -- user key of the owner of the wish list being viewed currently
if ( $_SESSION['currentUser'] == $_SESSION['currentView'] ) $thisUser = 1; else $thisUser = 0;


//  Get the name of the current user
$thisUserName=getUserInfo($_SESSION['currentUser']);


//  Begin generating the HTML page


//	THIS LINE CONTAINS THE VERSION NUMBER!!
print("<p><span class=\"body_headline\">Stonegoose.com Community Wishlist Server</span><br /><span class=\"body_note\">(v. ");
include("version.php");
print(" - <a href=\"changelog.php\">changelog</a>)</span><br /><hr>\n");


print("<span class=\"body_main\">\n");
print("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n");
print("\t<tr>\n");
print("\t\t<td width=\"50%\">");
print("<p><b>Welcome, $thisUserName</b><br />");
//	Print any update messages that are called for
if ($_GET['uu'] == 1) {
    print("<span class=\"body_update\">Your user information has been updated</span><br />\n");
}
if ($_GET['pwm'] == 1) {
	print("<span class=\"body_update\">Your password has been changed</span><br />\n");
}

if ($_GET['sm'] == 1) {
	print("<span class=\"body_update\">Your thank you note was sent</span><br />\n");
}

if ($_GET['sm'] == 2) {
	print("<span class=\"body_update\">No thank you e-mail was sent</span><br />\n");
}


print("</td>\n");
print("\t\t<td width=\"50%\" align=\"right\">");
print("<font size=\"-1\">");
print("(<a href=\"index.php?sH=" . ($sH == 1 ? "0" : "1") . "\"" . ($showHelp==1 ? " onMouseOver=\"popup(this,event,2)\"; onMouseOut=\"kill()\">" : ">") . "Help tips " . ($sH == 1 ? "off" : "on") . "</a>)&nbsp;");
print("(<a href=\"index.php?imoff=" . ($ioff == 1 ? "0" : "1") . "\"" . ($showHelp==1 ? " onMouseOver=\"popup(this,event,1)\"; onMouseOut=\"kill()\">" : ">") . "Images " . ($ioff == 1 ? "on" : "off") . "</a>)<br>");
print("&nbsp;(<a href=\"chgpasswd.php\"" .($showHelp==1 ? " onMouseOver=\"popup(this,event,3)\"; onMouseOut=\"kill()\">" : ">") . "Change your password</a>)&nbsp");
print("(<a href=\"logout.php\"" . ($showHelp==1 ? " onMouseOver=\"popup(this,event,4)\"; onMouseOut=\"kill()\">" : ">") . "Log Out</a>)</td>\n");
print("</font>");
print("</td>\n\t</tr>\n</table>");

//	If it's near Christmas, display the Christmas message
if ( ($pcm == 1) && ($sgwlsk == $sgwluk) ) {
	print("<br><center><table border=\"1\" cellpadding=\"1\" cellspacing=\"0\"><tr><td align=\"center\"><font color=\"#00cc00\"><b>Merry Christmas!</b></font><br>Don't forget to click &quot;Received&quot; for presents that you have received from your list!</td></tr></table></center>");
}


//	GENERATE RECIPIENT LIST DROP-DOWN BOX
$family=getOtherUsers($_SESSION['currentUser']);
?>
<form action="index.php" method="post" name="form">
<p>Select the name of the user whose list you'd like to see</p>
<select name="show">
<?php
	for ($i=0;$i<count($family);$i++)
	{
		$theKey=$family[$i]["personKey"];
		$theName=$family[$i]["userName"];
    $theBDay=$family[$i]["bDay"];
		print("<option value=\"$theKey\"");
		if ( $_SESSION['currentView'] == $theKey ) print ("selected");
		print(">$theName ($theBDay)</option>\n");
	}
?>
</select>
<input type="submit" value="Get their wish list!"><br />
<?php
	print("<span class=\"optiontext\"><a href=\"updateuserlist.php\"" .($showHelp==1 ? " onMouseOver=\"popup(this,event,7)\"; onMouseOut=\"kill()\">" : ">") . "Edit Recipient List</a></span>");
?>
</form>


<?php
//	GREETINGS TO THE USER
print("<table width=\"100%\" border=\"0\">\n");
print("<tr>\n");
print("<td valign=\"top\">\n");
if ( $thisUser == 1)
{
	print("<b>This list belongs to you</b><br />\n");
    $userString = $currentUser->userName;
}
else
{
	print("<b>This list belongs to $myList1->name</b>");
	print(" (<a href=\"index.php?a=b\"" .($showHelp==1 ? " onMouseOver=\"popup(this,event,8)\"; onMouseOut=\"kill()\">" : ">") . "Back to your own list</a>)</p>\n");
    print("<br /><b>$myList1->fName's birthday is $myList1->bDay</b><br />");
}


//	PRINT THE ADDRESS BOX
print("<div class=\"address_box\">");
print("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
if (($thisUser==1) || ($listOwner->showAddress == 'y')) {
	print("<tr>\n");
	print("<td align=\"right\" valign=\"top\"><b>Address:&nbsp;</b></td>\n");
	print("<td valign=\"top\" align=\"left\">\n");
	if ($listOwner->address1) { 
		print($listOwner->address1."<br />\n");
	}
	if ($listOwner->address2) { 
		print($listOwner->address2."<br />\n"); 
	}
    print($listOwner->city.", ".$listOwner->state."&nbsp;&nbsp;".$listOwner->postalCode."<br />\n");
	print("</tr>\n<tr>\n");
	print("<td valign=\"top\" align=\"right\"><b>Phone Number:&nbsp;</b></td><td valign=\"top\">".$listOwner->phone."</td>");
	print("</tr>\n<tr>\n");
	print("<td valign=\"top\" align=\"right\"><b>E-mail Address:&nbsp;</b></td><td><a href=\"mailto:$listOwner->eMail\">$listOwner->eMail</a></span></td>");
	print("</tr>\n</table>\n");
    if ($thisUser==1) {
        print("<br />Other users can".($listOwner->showAddress=='n' ? " not " : " ")." see your contact information<br>");
        print("<span class=\"optiontext\"><a href=\"updatereg.php\">Edit your contact information</a></span>\n");
    }
}
print("</div>");


//	OPTION FOR PRINTER-FRIENDLY VERSION AND SHOPPING LIST
print("<p><a href=\"friendlylist.php\"" .($showHelp==1 ? " onMouseOver=\"popup(this,event,5)\"; onMouseOut=\"kill()\">" : ">") . "Printer-friendly version</a></p>\n");
print("<p><a href=\"shoppinglist.php\"" .($showHelp==1 ? " onMouseOver=\"popup(this,event,6)\"; onMouseOut=\"kill()\">" : ">") . "Print Your Shopping List</a></p>\n");


//  DISPLAY "SPECIAL NOTES" FIELD
if (($blurb != "") or ($thisUser == 1)) {
    print("<p><b>Notes:</b><br />\n");
    print("$blurb<br />\n");
    if ($thisUser == 1) {
        print("<span class=\"optiontext\"><a href=\"editnotes.php\">Edit your notefield</a></span>\n");
    }
}
print ("</p>\n");


//	ADD ITEMS TO LIST HERE
if ( $thisUser == 1) {
	print("<p><b>Add Stuff to your Wish List!</b></p>\n");
	addItemForm();
	if (isset($amdevtoken)) {
		print("<b>Or <a href=\"importawl.php\">Click Here</a> to import your Amazon wish list (beta)</b><br />");
	}
}
else print("&nbsp;");


//	PRINT UP THE WISH LIST
print("<p>Number of items: $myList1->numGifts</p>\n");
print("<center>\n");

printList($myList1,$_SESSION['currentUser'],$_SESSION['currentView'],0,$imoff);

print("</center>\n");

print("</td>\n");

print("</tr>\n");
print("</table>\n");
include("pagemaker.php");
print("\t</body>\n");
print("</html>\n");
?>
Return current item: The Community Wish List Server