{redirect href="?pg=my_home"}

{assign var="pgLayout" value="layouts/myhome_layout2.tpl"}
{include_php file="shared_handle:acceptRejectRequests"} 
{include_php file="shared_handle:myHome"}

{assign var="hideUserBox" value="false"}
{assign var="showCompanyNews" value="true"}
{assign var="hideWLWLinks" value="true"}
{assign var="hideWidgets" value="true"}

{* getProfile is included by getStats *}
{* include_php file="shared_handle:getStats" *}

{* Now getting only Profile because getStats does TONS of unneccesary processing *}
{include_php file="shared_handle:getProfile"}

{if $smarty.request.debug}
	{display var=$competitions}
{/if}

<h1 class="underline">My Home - {$userProfile.firstName} {$userProfile.lastName} ({$userProfile.username})</h1>
<br />

{$user->firstName}, this is your personal Wellness &quot;Home&quot;.
From this page you can manage the competitions you are in, and update your wellness profile. 
Click on the 'Update Profile' button to change your Motto, and other information about yourself, or 'Account Settings' to change your password.<br />
<br />
<script language="javascript">{literal}
function goNewGraph() {
	var obj = document.getElementById('graphDropdown');
	var url;

	for (var x = 0; x < obj.options.length; x++) {
		if (obj.options[x].selected)
			url = obj.options[x].value;
	}

	graphwindow.location.replace(url);

	obj.selectedIndex = 0;
}{/literal}
</script>

<table border="0">
<tr>
	<td valign="top">
		<div id="UserProfileColumn" class="contentColumn">
			<h2 class="withBG">Your Profile</h2>
			<span class="cellHeadLarge">Age:</span><span class="cellSmall">{$userProfile.age}</span><br />
			<span class="cellHeadLarge">Start Weight:</span><span class="cellSmall">{$userProfile.initialWeight}</span><br />
			<span class="cellHeadLarge">Height:</span><span class="cellSmall">{$userProfile.heightFeet}'{$userProfile.heightInches}&quot;</span><br />
			<span class="cellHeadLarge">Start BMI:</span><span class="cellSmall">{$userProfile.startBMI}</span><br />
			<span class="cellHeadLarge">Goal Weight:</span><span class="cellSmall">{$userProfile.goalWeight}</span><br />
		<br />
                {* <form name="notUsed" style="margin:0px;">
		<select id="graphDropdown" onchange="goNewGraph();">
			<option value="">(Change Graph)</option>
			<option value="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=weight&fillPrevious=1&precision=0&totalChange=1">Change in Weight</option>
			<option value="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=weight&fillPrevious=1&precision=0" target="graphwindow">Weight</option>
			<option value="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=fat&fillPrevious=0&precision=1" target="graphwindow">Fat Intake</option>
			<option value="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=calories&fillPrevious=0&precision=1" target="graphwindow">Calorie Intake</option>
			<option value="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=carbs&fillPrevious=0&precision=1" target="graphwindow">Carb Intake</option>
			<option value="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=minutesExercise&fillPrevious=0&precision=1" target="graphwindow">Exercise Min</option>
			<option value="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=distanceExercised&fillPrevious=0&precision=1" target="graphwindow">Distance Exercised</option>
		</select>
		</form> *}
		<h2 class="withBG">Links</h2>
		<small>
		&nbsp;&middot; <a href="?pg=tips">Weight Loss Tips</a><br /> 
		&nbsp;&middot; <a href="?pg=calculators">Calculators</a><br />
		&nbsp;&middot; <a href="?pg=recipes">Recipes</a><br />
		&nbsp;&middot; <a href="?pg=nutrition">Nutrition Data</a><br />
		&nbsp;&middot; <a href="?pg=ptinfo">Customized Fitness Plan</a><br />
		&nbsp;&middot; <a href="?pg=dietitianinfo">Personal Nutrition Coach</a><br />
		</small>
                </div>
               	</td>
	<td align="center">
		<div style="margin:0px 10px;padding:5px;background-color:#FFF;border:#999 1px solid;">
		<iframe name="graphwindow" src="?pg=flashgraph-frame&compId={$compData.id}&format=small{* &type=weight&fillPrevious=1&precision=1&totalChange=0&userIds={$userProfile.id} *}" frameborder="0" width="425" height="230" scrollbars="no"></iframe></div>
		<small>
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=weight&fillPrevious=1&precision=1&totalChange=1" target="graphwindow">Change in Weight</a> |
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=weight&fillPrevious=1&precision=1" target="graphwindow">Weight</a> |
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=fat&fillPrevious=0&precision=1" target="graphwindow">Fat Intake</a> |
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=calories&fillPrevious=0&precision=1" target="graphwindow">Calorie Intake</a> |
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=carbs&fillPrevious=0&precision=1" target="graphwindow">Carb Intake</a><br />
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=water&fillPrevious=0&precision=1" target="graphwindow">Water Intake</a> |
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=minutesExercise&fillPrevious=0&precision=1" target="graphwindow">Exercise Min</a> |
			<a href="?pg=flashgraph-frame&compId={$compData.id}&format=small&userIds={$userProfile.id}&type=distanceExercised&fillPrevious=0&precision=1" target="graphwindow">Distance Exercised</a>
		</small>
</td>
	<td valign="top" width="100%" style="padding:5px;background-color:#FFF;border:#999 1px solid;">
		<h2><i>"{$userProfile.personalSaying|default:"Your personal motto goes here."|replace:'"':''}"</i></h2>
		</td>
</tr>
</table>
<br />
{if $smarty.request.hideComps neq "1"}
<table width="100%"><tr><td valign="top">
{* ********************************* COMPETITIONS I AM IN ********************************** *}
<h2 class="withBG">
	<div class="topRight hideShow">
		<a href="javascript:toggle('inComps', '', 'showHide');"><img id="inComps_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div> 
	Competitions I Am In</h2>
Here are the competitions you have signed up to participate in. If you have an ID of a competition you would like to join, enter it below.<br />
<div id="inComps" style="display:block;">	
	<div style="margin:10px;padding:5px;background-color:#FFF;border:#999 1px solid;">
	<table cellspacing="0" cellpadding="1" align="center">
	<tr>
		<td class="underline2"><span>&nbsp;<b>ID</b></span></td>
		<td class="underline2"><span>&nbsp;<b>Title</b></span></td>
		{*
		<td class="underline2"><span>&nbsp;<b>Type</b></span></td>
		*}
		<td class="underline2"><span>&nbsp;<b>Style</b></span></td>
		{* <td class="underline2"><span>&nbsp;<b>Rank</b></span></td> *}
		{* <td class="underline2" nowrap><span>&nbsp;<b>Time Remaining</b></span></td> *}
		<td class="underline2" nowrap><span>&nbsp;<b>Ends</b></span></td>
		{* <td class="underline2" nowrap><span>&nbsp;<b>Prize</b></span></td> *}
	</tr>
	{* Set up the warning period... 7 days from now (604800 = 7 days in seconds) *}
	{math assign="endsSoon" equation="x + y" x=$smarty.now y="604800"}
	{foreach from=$competitions item="comp"}
	<tr>
		<td nowrap="nowrap"><span><small>&nbsp;<a href="?pg=competition&cid={$comp.id}">{$comp.id}</a> &nbsp;</small></span></td>
		<td nowrap="nowrap"><span><small>&nbsp;<a href="?pg=competition&cid={$comp.id}">{$comp.title|truncate:35:"..."}</a> &nbsp;</small></span></td>
		{*
		<td nowrap="nowrap"><span><small>&nbsp;{$comp.type|niceText}</small> &nbsp;</span></td>
		*}
		<td nowrap="nowrap"><span><small>&nbsp;{if $comp.style eq "Group-vs-Group"}Team{else}Individual{/if}</small> &nbsp;</span></td>
		{* <td nowrap="nowrap"><span><small>&nbsp;{if $comp.rank ne "N/A"}{$comp.rank}/{$comp.rankOutOf}{else}N/A{/if}</small> &nbsp;</span></td> *}
		{* <td nowrap><span><small{if $comp.endDate lt $smarty.now} style="font-weight:bold;"{elseif $comp.endDate lt $endsSoon} style="color:#C00;font-weight:bold;"{/if}>&nbsp;{$comp.timeLeft}</small> &nbsp;</span></td> *}
		<td nowrap="nowrap"><span><small{if $comp.endDate lt $smarty.now} style="font-weight:bold;"{elseif $comp.endDate lt $endsSoon} style="color:#C00;font-weight:bold;"{/if}>&nbsp;{$comp.endDate|date_format2:"D n/j/y"}</small> &nbsp;</span></td>
		{* <td nowrap="nowrap" align="right"><span><small>&nbsp;{if not $comp.potAmount and $comp.potDescription}(Special){else}{math assign="fontSizeFactor" equation="x / y" x=$comp.potAmount y="100"}{math assign="fontSize" equation="x + y" x="11" y=$fontSizeFactor|number_format:"0"}<span style="font-size:{$fontSize}px;">${$comp.potAmount|number_format:"0"}</span>{/if}</small> &nbsp;</span></td> *}
	</tr>
	{foreachelse}
	<tr>
		<td colspan="6"><span><small>You have not joined any competitions.</small></span></td>
	</tr>
	{/foreach}
	</table>
	</div>
	<span style="margin-left:65px;"><small>(NOTE: <b>Bold Date</b> = Ended, <span style="color:#C00;"><b>Red Date</b></span> = Ends Soon)</small></span>

	<div style="text-align:right;">
	<form name="joinCompForm" method="post" style="margin:4px;">
		<input type="hidden" name="pg" value="competition/join" />
		<input type="hidden" name="no_expire" value="true" />
		<b>Competition ID#</b> <input type="text" class="textInput" name="cid"> <a href="javascript:document.joinCompForm.submit();" class="button">Join</a><br />
	</form>
	-<i>or</i>- see a list of all <a href="?pg=availableCompetitions">Available Competitions</a>!
	</div>
</div>
</td><td valign="top" style="margin-left:10px;">
{* ********************************* COMPETITIONS I HAVE STARTED ********************************** *}
{if $user->inGroupName('coordinators')}
<form name="requestsForm" action="index.php" method="post" style="margin:0px;">
<input type="hidden" name="pg" value="{$page.name}">
<input type="hidden" name="no_expire" value="true">
<input type="hidden" name="acceptReject" value="">

<h2 class="withBG">
	<div class="topRight hideShow">
		<a href="javascript:toggle('myComps', '', 'showHide');"><img id="myComps_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div> 
	Competitions I Have Started</h2>

<div id="myComps" style="display:block;">
{if $myCompetitions|@count gt 0}
	<div style="margin:0px;padding:5px;background-color:#FFF;border:#999 1px solid;">
	<table cellspacing="0" cellpadding="1" align="center">
	<tr>
		<td class="underline2" nowrap><span>&nbsp;<b>ID</b> &nbsp;</span></td>
		<td class="underline2" nowrap><span>&nbsp;<b>Title</b> &nbsp;</span></td>
		<td class="underline2" nowrap><span>&nbsp;<b>Type</b> &nbsp;</span></td>
		<td class="underline2" nowrap><span>&nbsp;<b>People wanting to join</b> &nbsp;</span></td>
	</tr>
	{foreach from=$myCompetitions item="comp"}
	<tr>
		<td valign="top"><span>&nbsp;<small><a href="?pg=competition&cid={$comp.id}">{$comp.id}</a></small></span></td>
		<td valign="top" nowrap="nowrap" style="overflow:hidden;"><span>&nbsp;<small><a href="?pg=competition&cid={$comp.id}">{$comp.title}</a></small></span></td>
		<td valign="top" nowrap="nowrap">&nbsp;<span><small>{$comp.type}</small></td>
		<td valign="top" style="border-left:1px solid #000;"><span>{if $comp.requests|@count}{assign var="isRequests" value="true"}{/if}{foreach from=$comp.requests item="request"}<div class="hangingIndent"><input type="checkbox" name="request[{$comp.id}][]" value="{$request.id}"><small>({$request.dateAdded|date_format2:"n/j/y"}) {$request.name} &lt;{mailto address=$request.email encode="javascript"}&gt;: &quot;<i>{$request.comment|strip_tags}</i>&quot;</small></div>{foreachelse}&nbsp;None right now.{/foreach}</span></td>
	</tr>
	{/foreach}
	{if $isRequests}
	<tr>
		<td colspan="4" align="center">
			<span><br /><a href="javascript://" onclick="acceptReject.value='accept';requestsForm.submit();return false;" class="button">Accept Selected</a>
			<a href="javascript://" onclick="acceptReject.value='reject';requestsForm.submit();return false;" class="button">Reject Selected</a><small><br /><br /></small></span></td>
	</tr>
	{/if}
	</table>
	</div>
{else}
	<div class="underline2">&nbsp;</div>
	<small>&nbsp; &nbsp; You have not created any competitions.</small>
{/if}
{/if}
</div>
<br />
</form>

{* ********************************* INCENTIVES PROGRAM ********************************** *}
<h2 class="withBG">
	<div class="topRight hideShow">
		<a href="javascript:toggle('myIncentives', '', 'showHide');"><img id="myIncentives_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div> 
	My Incentives Program</h2>

<div id="myIncentives" style="display:block;">
        <div style="margin:0px;padding:5px;background-color:#FFF;border:#999 1px solid;">
	
	{include_php file="shared_handle:company/participationPoints"}

	{if $scores|@count gt 0}
	<h3>Participation Points</h3>
        <table id="surveyContainer" width="100%">
           <thead>
               <tr><td width="100%"><u> Category </u></td><td><u> Points </u></td><td nowrap><u> Total </u></td></tr>
           </thead>
           <tbody>
           {foreach from=$scores item="score" key="category" name="loopScores"}<tr><td nowrap>
		<small>{$category|niceText}</small></td><td align="right"><small>{$score}</small></td>
		{if $smarty.foreach.loopScores.first}<td rowspan="999" align="center"><em>{$participationPointsEarned|default:0}</em></td>{/if}</tr>
           {foreachelse}
		None found.</td><td colspan="2">&nbsp;</td></tr>
           {/foreach}
           </tbody>
        </table>
	<div class="underline"></div>
	<br />
	{/if}

	<h3>Survey Points</h3>
        <table id="surveyContainer" width="100%">
           {include_php file="shared_handle:company/surveyList"}
           <thead>
               <tr><td width="100%"><u> Survey Name </u></td><td><u> Available </u></td><td nowrap><u> Total </u></td></tr>
           </thead>
           <tbody>
           {foreach from=$surveys item=item name="loopSurveys"}<tr><td nowrap>
		{if $item.dateAvailable gt 0}
		<small>{$item.surveyName}</small></td><td align="center"><small>{if $item.frequency eq "Once"}Taken{elseif (($item.dateAvailable - $smarty.now) < 43000)}{$item.dateAvailable|date_format2:"g:i A"}{else}{$item.dateAvailable|date_format2:"m/d/y"}{/if}</small></td>
		{else}
		<small><a href="javascript://" onclick="openSurvey({$item.id});">{$item.surveyName}</a></small></td><td align="center"><small>Now</small></td>
		{/if}{if $smarty.foreach.loopSurveys.first}<td rowspan="999" align="center"><em>{$surveyPointsEarned|default:0}</em></td>{/if}</tr>
                {foreachelse}
		None found.</td><td colspan="2">&nbsp;</td></tr>
               {/foreach}
           </tbody>
        </table>
	<div class="underline"></div>
	<span><small><a href="javascript://" onclick="viewSurveys();">View My Survey History</a></small></span>
	
	<br /><br />
	<div align="right"><b>Your total points: </b><span style="font-size:18px;font-weight:bold;border:1px solid gray;padding:3px;">{$surveyPointsEarned+$participationPointsEarned}</span></div>

        </div>
</div>
</td></tr></table>
{/if}