<?php

  include("html_functions.php");



  ################## PAGE INITIALIZATION #########################

  $lgid=$_SESSION['lgid'];

  $lgpath=$_SESSION['lgpath'];

  $date=new DateTime($_SESSION['lgdate']);

  $lgyear=$date->format("Y");



  include($_SESSION['adminpath']."/dbopen.php");



  ## Get add setting

  $query="SHOW TABLES LIKE 'ootp_sql_admin';";

  $result=mysqli_query($db,$query);

  if (mysqli_num_rows($result)) 

  {

	  $query="SELECT value FROM ootp_sql_admin WHERE setting='addDisable';";

       	  $result=mysqli_query($db,$query);

	  if (mysqli_num_rows($result)) 

      	  {

		  $row=mysqli_fetch_array($result);

		  $addDisable=$row['value'];

      	  }

  }

  

  ## Removal Check

  if ($_GET['remove']==1)

  {

	  $pid=$_GET['player'];

       	  unset($_GET['player']);

       

	  $query="DELETE FROM trade_block_players WHERE player_id=$pid;";

	  mysqli_query($db,$query);

       	  $query="UPDATE players_roster_status SET trade_status=0 WHERE player_id=$pid;";

	  mysqli_query($db,$query);

  }

  

  ## Get Report Settings

  $view=$_GET['view'];

  $team_id=$_GET['team_id'];

  

  if ($team_id=="") {$team_id=$_SESSION['user_team_id'];}

	  

  ## Save Settings

  if ($team_id>0) {$action=$_POST['action'];}

  switch ($action)

  {

  case 'setTeam':

	  $notice=$_POST['teamnotice'];

     	  $notice=mysqli_real_escape_string($db,$notice);

	  $c=$_POST['c'];

     	  $fb=$_POST['1b'];

	  $sb=$_POST['2b'];

     	  $tb=$_POST['3b'];

	  $ss=$_POST['ss'];

     	  $lf=$_POST['lf'];

	  $cf=$_POST['cf'];

     	  $rf=$_POST['rf'];

	  $sp=$_POST['sp'];

     	  $rp=$_POST['rp'];

	  if ($c!=1) {$c=0;}

     	  if ($fb!=1) {$fb=0;}

	  if ($sb!=1) {$sb=0;}

     	  if ($tb!=1) {$tb=0;}

	  if ($ss!=1) {$ss=0;}

     	  if ($lf!=1) {$lf=0;}

	  if ($cf!=1) {$cf=0;}

     	  if ($rf!=1) {$rf=0;}

	  if ($sp!=1) {$sp=0;}

     	  if ($rp!=1) {$rp=0;}

	  $query="UPDATE trade_block_teams SET notice='$notice',catcher=$c,first_base=$fb,second_base=$sb,third_base=$tb,shortstop=$ss,left_field=$lf,center_field=$cf,right_field=$rf,starting_pitcher=$sp,relief_pitcher=$rp WHERE team_id=$team_id;";

     	  mysqli_query($db,$query);

	  break;

  case 'setPlayer':

	  $pid=$_POST['player'];

     	  $tid=$_POST['team'];

	  $headline=$_POST['headline'];

     	  $headline=mysqli_real_escape_string($db,$headline);

	  $notice=$_POST['playernotice'];

     	  $notice=mysqli_real_escape_string($db,$notice);

	  if ($addDisable==1)

    	  {

		  $query="SELECT trade_status FROM players_roster_status WHERE player_id=$pid;";

	  	  $result=mysqli_query($db,$query);

		  $row=mysqli_fetch_array($result);

	  	  $tstatus=$row['trade_status'];

	  }

     	  if (($addDisable!=1)||($tstatus==2))

	  {

	  	  $query="INSERT INTO trade_block_players (player_id,team_id,headline,notice,trade_status) VALUES ($pid,$tid,'$headline','$notice',2) ON DUPLICATE KEY UPDATE team_id=$tid,headline='$headline',notice='$notice',trade_status=2;";

		  mysqli_query($db,$query);

	  	  $query="UPDATE players_roster_status SET trade_status=2 WHERE player_id=$pid;";

		  mysqli_query($db,$query);

    	  }

	  else {echo "ERROR: Players may only be added to your trade block in game<br/>Return to <a href='./tradeBlockAdmin.php'>Trade Block Admin</a>.";}

     	  header("Location: ./tradeBlockAdmin.php");

	  exit;

     	  break;

  }

  

  ## Check Player Team

  $player_id=$_POST['player'];

  if ($player_id=="") {$player_id=$_GET['player'];}

  if ($player_id!="")

  {

       	  $query="SELECT organization_id FROM players WHERE player_id=$player_id;";

	  $result=mysqli_query($db,$query);

       	  $row=mysqli_fetch_array($result);

	  $pOrgId=$row['organization_id'];



	  if ($pOrgId!=$team_id) {$player_id="";}

  }

  

  if ($player_id=="") {$view="";} else {$view='player_add';}

  

  mysqli_close($db);



  # Title Bar

  $title='Team Trade Block Admin';



  page_head($title,$_SESSION['lgpath'],"","","./text_functions.js");

  echo " <div id='topbar'>\n";

  main_titlebar($lgid,$_SESSION['lgpath'],$title,$team_id);

  nav_toolbar('front_office',"Front Office");

  echo " </div>   <!-- END topbar DIV -->\n";

  echo " <div id='contentpane'>\n";



  ################## START OF PAGE CONTENT #########################

  include($_SESSION['adminpath']."/dbopen.php");

  

  switch ($view)

  {

  case 'player_add':

	  ## Get Player Info

	  $query="SELECT first_name,last_name,age,position,p.team_id,t.level,t.name as tname,t.nickname as mascot FROM players as p,teams as t WHERE p.team_id=t.team_id AND player_id=$player_id;";

	  $result=mysqli_query($db,$query);

     	  $row=mysqli_fetch_array($result);

	  $name=$row['first_name']." ".$row['last_name'];

     	  $tid=$row['team_id'];

	  $tname=$row['tname']." ".$row['mascot'];

     	  $level=get_level($row['level']);

	  $pos=get_pos($row['position'],1);

     	  $age=$row['age'];

     

	  echo " <div class='textbox' style='border:0;'><a href='./tradeBlockAdmin.php'>Back to Trade Block Admin</a></div>\n";

     

	  echo " <div class='textbox'>\n";

	  echo "  <table cellpadding=0 cellspacing=0 border=0>\n";

     	  echo "   <tr class='title2'><td colspan=2>$pos $name ($age yrs old)</td></tr>\n";

	  echo "   <tr>\n";

     	  echo "    <td valign='top'>";

	  $htmlpath=$_SESSION['htmlpath'];
      echo "<img src='".get_player_pic($lgpath,$player_id)."'>";

     	  echo "     </td>\n";

	  echo "     <td>\n";



	  $notice="";

     	  $headline="";

	  ## Get Player Settings

	  $query="SELECT * FROM trade_block_players WHERE player_id=$player_id;";

	  $result=mysqli_query($db,$query);

     	  if (mysqli_num_rows($result))

	  {

	  	  $row=mysqli_fetch_array($result);

		  $notice=$row['notice'];

	  	  $notice=stripslashes($notice);

		  $headline=$row['headline'];

	  	  $headline=stripslashes($headline);

	  }

     

	  ## Display Player Notice

	  echo "  <table cellpadding=2 cellspacing=0 border=0>\n";

     	  echo "   <tr class='headline'><td class='hsc2_l' colspan=20>Headline</td></tr>\n";

	  echo "   <tr><td colspan=20>\n";

     	  echo "    <form action='./tradeBlockAdmin.php' method='post' name='playerAdd'>\n";

	  echo "     <textarea name='headline' cols=50 rows=1 onKeyDown='limitText(this.form.headline,this.form.hcountdown,50);' onKeyUp='limitText(this.form.headline,this.form.hcountdown,50);'>$headline</textarea>\n";

     	  echo "   </td></tr>\n";

	  echo "   <tr><td colspan=8>(Maximum characters: 50)</td><td colspan=12>&nbsp;</td></tr>\n";

     	  echo "   <tr><td colspan=8>Characters Remaining:</td><td colspan=2><input readonly type='text' name='hcountdown' size=3 value=".(50-strlen($headline))."></td><td colspan=10>&nbsp;</td></tr>\n";

	  echo "   <tr class='headline'><td class='hsc2_l' colspan=20>Detailed Notice</td></tr>\n";

     	  echo "   <tr><td colspan=19>\n";

	  echo "     <textarea name='playernotice' id='playernotice' cols=80 rows=5 onKeyDown=\"limitText(this,this.form.countdown,255);\" onKeyUp=\"limitText(this,this.form.countdown,255);previewHTML('playernotice','displayAs');\" onchange=\"previewHTML('playernotice','displayAs');\">$notice</textarea>\n";

	  echo "    </td><td>\n";

	  echo "     <img src='./images/bold.png' onMouseDown=\"wrapText('playernotice','[b]','[/b]');\"><br/><img src='./images/italic.png' onMouseDown=\"wrapText('playernotice','[i]','[/i]');\"><br/><img src='./images/underline.png' onMouseDown=\"wrapText('playernotice','[u]','[/u]');\">\n";

     	  echo "   </td></tr>\n";

     	  echo "   <tr><td colspan=8>(Maximum characters: 255)</td><td colspan=12>&nbsp;</td></tr>\n";

     	  echo "   <tr><td colspan=8>Characters Remaining:</td><td colspan=2><input readonly type='text' name='countdown' size=3 value=".(255-strlen($notice))."></td><td colspan=10>&nbsp;</td></tr>\n";

	  echo "   <tr class='headline'><td class='hsc2_l' colspan=20>Preview</td></tr>\n";

	  echo "   <tr><td colspan=20>\n";

	  echo "    <div id='displayAs'>";

	  $cleanNotice=clean_bbcode(htmlspecialchars($notice));

	  echo nl2br($cleanNotice);

	  echo "</div>\n";

	  echo "   </td></tr>\n";

	  echo "   <tr>\n";

     	  echo "    <td colspan=20>\n";

	  echo "     <input type='hidden' name='action' value='setPlayer' />\n";

     	  echo "     <input type='hidden' name='player' value=$player_id />\n";

	  echo "     <input type='hidden' name='team' value=$team_id />\n";

     	  echo "     <input type='submit' name='Save' value='Save' />\n";

	  echo "    </form>\n";

     	  echo "   </td></tr>\n";

	  echo "  </table>\n";

     	  echo "    </td>\n";

	  echo "   </tr>\n";

     	  echo "  </table>\n";

	  echo " </div>\n";

     	  break;

  default:

	  ##### Get League Settings #####

	  $query="SELECT rules_rule_5,rules_min_service_days,rules_fa_minimum_years,rules_salary_arbitration_minimum_years,rules_minor_league_fa_minimum_years FROM leagues WHERE league_id=$lgid;";

     	  if ($_GET['showq']==1) {echo $query."<br/>\n";}

	  $result=mysqli_query($db,$query);

     	  $row=mysqli_fetch_array($result);

	  $rule5enable=$row['rules_rule_5'];

     	  $minService=$row['rules_min_service_days'];

	  $minFAyrs=$row['rules_fa_minimum_years'];

     	  $minARByrs=$row['rules_salary_arbitration_minimum_years'];

	  $minMLFAyrs=$row['rules_minor_league_fa_minimum_years'];

     

	  ## Get Team Settings

	  $query="SELECT * FROM trade_block_teams WHERE team_id=$team_id;";

     	  if ($_GET['showq']==1) {echo $query."<br/>\n";}

     	  $result=mysqli_query($db,$query);

	  if (mysqli_num_rows($result))

    	  {

		  $row=mysqli_fetch_array($result);

	  	  $notice=$row['notice'];

		  $notice=stripslashes($notice);

	  	  $c=$row['catcher'];

		  $fb=$row['first_base'];

	  	  $sb=$row['second_base'];

		  $tb=$row['third_base'];

	  	  $ss=$row['shortstop'];

		  $lf=$row['left_field'];

	  	  $cf=$row['center_field'];

		  $rf=$row['right_field'];

	  	  $sp=$row['starting_pitcher'];

		  $rp=$row['relief_pitcher'];

    	  }

	  else

    	  {

		  $query="INSERT INTO trade_block_teams (team_id) VALUES ($team_id);";

	  	  mysqli_query($db,$query);

	  }

     

	  ## Display Team Notice

	  echo " <div class='textbox'>\n";

     	  echo "  <table cellpadding=2 cellspacing=0 border=0>\n";

	  echo "   <tr class='title'><td colspan=20>Trade Block Settings</td></tr>\n";

     	  echo "   <tr class='headline'><td class='hsc2_l' colspan=20>General Notice</td></tr>\n";

	  echo "   <tr><td colspan=19>\n";

     	  echo "    <form action='./tradeBlockAdmin.php' method='post' name='teamAdd'>\n";

	  echo "     <textarea name='teamnotice' id='teamnotice' cols=110 rows=8 onKeyDown=\"limitText(this,'',65535);\" onKeyUp=\"limitText(this,'',65535);previewHTML('teamnotice','displayAs');\" onchange=\"previewHTML('teamnotice','displayAs');\">$notice</textarea>\n";

	  echo "    </td><td>\n";

	  echo "     <img src='./images/bold.png' onMouseDown=\"wrapText('teamnotice','[b]','[/b]');\"><br/><img src='./images/italic.png' onMouseDown=\"wrapText('teamnotice','[i]','[/i]');\"><br/><img src='./images/underline.png' onMouseDown=\"wrapText('teamnotice','[u]','[/u]');\">\n";

	  echo "   </td></tr>\n";

     	  echo "   <tr class='headline'><td class='hsc2_l' colspan=20>Preview</td></tr>\n";

	  echo "   <tr><td colspan=20>\n";

	  echo "    <div id='displayAs'>";

	  $cleanNotice=clean_bbcode(htmlspecialchars($notice));

	  echo nl2br($cleanNotice);

	  echo "</div>\n";

	  echo "   </td></tr>\n";

     	  echo "   <tr class='headline'><td class='hsc2_l' colspan=20>Team Needs</td></tr>\n";

	  echo "   <tr>\n";

     	  echo "    <td><input type='checkbox' name='c' id='c' value=1";

	  if ($c==1) {echo " checked='yes'";}

     	  echo " /></td><td><label for='c'>C</label></td>\n";

	  echo "    <td><input type='checkbox' name='1b' id='1b' value=1";

     	  if ($fb==1) {echo " checked='yes'";}

	  echo " /></td><td><label for='1b'>1B</label></td>\n";

     	  echo "    <td><input type='checkbox' name='2b' id='2b' value=1";

	  if ($sb==1) {echo " checked='yes'";}

     	  echo " /></td><td><label for='2b'>2B</label></td>\n";

	  echo "    <td><input type='checkbox' name='3b' id='3b' value=1";

     	  if ($tb==1) {echo " checked='yes'";}

	  echo " /></td><td><label for='3b'>3B</label></td>\n";

     	  echo "    <td><input type='checkbox' name='ss' id='ss' value=1";

	  if ($ss==1) {echo " checked='yes'";}

     	  echo " /></td><td><label for='ss'>SS</label></td>\n";

	  echo "    <td><input type='checkbox' name='lf' id='lf' value=1";

     	  if ($lf==1) {echo " checked='yes'";}

	  echo " /></td><td><label for='lf'>LF</label></td>\n";

     	  echo "    <td><input type='checkbox' name='cf' id='cf' value=1";

	  if ($cf==1) {echo " checked='yes'";}

     	  echo " /></td><td><label for='cf'>CF</label></td>\n";

	  echo "    <td><input type='checkbox' name='rf' id='rf' value=1";

     	  if ($rf==1) {echo " checked='yes'";}

	  echo " /></td><td><label for='rf'>RF</label></td>\n";

     	  echo "    <td><input type='checkbox' name='sp' id='sp' value=1";

	  if ($sp==1) {echo " checked='yes'";}

     	  echo " /></td><td><label for='sp'>SP</label></td>\n";

	  echo "    <td><input type='checkbox' name='rp' id='rp' value=1";

     	  if ($rp==1) {echo " checked='yes'";}

	  echo " /></td><td><label for='rp'>RP</label></td>\n";

     	  echo "   </tr>\n";

	  echo "   <tr>";

     	  echo "    <td colspan=10>";

	  if (($c==1)||($fb==1)||($sb==1)||($tb==1)||($ss==1)||($lf==1)||($cf==1)||($rf==1)||($sp==1)||($rp==1)) {echo "<a href='./tradeBlock.php?filter=need' title='Save first!'>Search For My Needs</a>";}

    	  else {echo "&nbsp;";}

	  echo "</td>\n";

	  echo "    <td colspan=10>\n";

	  echo "     <input type='hidden' name='saved' value='1' />\n";

	  echo "     <input type='hidden' name='action' value='setTeam' />\n";

	  if (($_GET['debug']==1)||($_POST['debug']==1)) {echo " <input type='hidden' name='debug' value='1' />\n";}

   	  echo "     <input type='submit' name='Save' value='Save' />\n";

	  echo "    </form>\n";

	  if (isset($_POST['saved'])&&($_POST['saved']==1)&&(file_exists('./forumTBUpdate.php')))

	  {

		  echo " <form action='./forumTBUpdate.php' method='post' name=''>\n"; 

		  if (($_GET['debug']==1)||($_POST['debug']==1)) {echo " <input type='hidden' name='debug' value='1' />\n";}

		  echo " <input type='hidden' name='team' value='$team_id' />\n"; 

		  echo " <input type='hidden' name='notice' value='".htmlentities($notice, ENT_QUOTES)."' />\n"; 

		  echo " <input type='hidden' name='c' value='$c' />\n"; 

		  echo " <input type='hidden' name='fb' value='$fb' />\n"; 

		  echo " <input type='hidden' name='sb' value='$sb' />\n"; 

		  echo " <input type='hidden' name='tb' value='$tb' />\n"; 

		  echo " <input type='hidden' name='ss' value='$ss' />\n"; 

		  echo " <input type='hidden' name='lf' value='$lf' />\n"; 

		  echo " <input type='hidden' name='cf' value='$cf' />\n"; 

		  echo " <input type='hidden' name='rf' value='$rf' />\n"; 

		  echo " <input type='hidden' name='sp' value='$sp' />\n"; 

		  echo " <input type='hidden' name='rp' value='$rp' />\n"; 

		  echo " <input type='submit' name='update' value='Update Forum' />\n"; 

		  echo " </form>\n"; 

	  }

     	  echo "   </td></tr>\n";

	  echo "  </table>\n";

     	  echo " </div>\n";

     

	  ## Get All Players In Organization

	  $query="SELECT player_id,first_name,last_name,age,position,p.team_id,p.league_id,if(p.league_id>0,t.level,100+t.level) as level,t.name as tname,t.nickname as mascot FROM players as p,teams as t WHERE p.team_id=t.team_id AND p.organization_id=$team_id ORDER BY level,league_id DESC,last_name,first_name;";

     	  $result=mysqli_query($db,$query);

	  if (mysqli_num_rows($result))

    	  {

		  $pList="";

	  	  $tList="";

		  while ($row=mysqli_fetch_array($result))

	 	  {

			  $pid=$row['player_id'];

	       		  $name=$row['first_name']." ".$row['last_name'];

              $plgid=$row['league_id'];

			  $tid=$row['team_id'];

	       		  $tname=$row['tname']." ".$row['mascot'];

			  if ($plgid<0)

              {

                  $level='INT';

                  $lvlID=100+$row['level'];

              }

              else

              {

                  $lvlID=$row['level'];

                  $level=get_level($lvlID);

              }

              $pos=get_pos($row['position'],1);

			  $age=$row['age'];

		 

			  $players[$pid]['name']=$name;

			  $players[$pid]['team_id']=$tid;

              $players[$pid]['pos']=$pos;

			  $players[$pid]['age']=$age;

              $players[$pid]['level']=$level;



			  $teams[$tid]['name']=$tname;



			  $pList.=",$pid";

	       		  $tList.=",$tid";

		  }

	  	  $pList=trim($pList,",");

		  $tList=trim($tList,",");

    	  }

	  else

    	  {

		  echo " <div class='textbox' style='border:0;>No players found</div>\n";

	  	  ##### End Page #####

		  echo "</div>   <!-- END contentpane DIV -->\n";

	  	  page_foot($lgpath);

		  exit;

    	  }

     

	  ## Ratings

     

	  ## Check TB Status

	  $bList="";

     	  $ubList="";

	  $query="SELECT prs.player_id,prs.trade_status FROM players as p,players_roster_status as prs WHERE p.player_id=prs.player_id AND prs.player_id IN ($pList) AND trade_status!=0 ORDER BY last_name,first_name;";

     	  $result=mysqli_query($db,$query);

	  if (mysqli_num_rows($result))

    	  {

		  while ($row=mysqli_fetch_array($result))

	 	  {

			  $pid=$row['player_id'];

	       		  $status=$row['trade_status'];

			  if ($status==2) {$on_block[$pid]=1;$bList.=",$pid";}

	      		  else {$on_block[$pid]=-1;$ubList.=",$pid";}

		  }

	  	  $bList=trim($bList,",");

		  $ubList=trim($ubList,",");

    	  }

     

	  ## Display Players on Block

	  if ($bList=="") {echo " <div class='textbox' style='border:0;'>No players currently on the block</div>\n";}

    	  else

	  {

	  	  ## Get Block Info

		  $query="SELECT * FROM trade_block_players WHERE player_id IN ($bList);";

	  	  $result=mysqli_query($db,$query);

		  while ($row=mysqli_fetch_array($result))

	 	  {

			  $pid=$row['player_id'];

	       		  $players[$pid]['headline']=stripslashes($row['headline']);

			  $notice=stripslashes($row['notice']);

			  $notice=clean_bbcode(htmlspecialchars($notice));

			  $notice=nl2br($notice);

			  $players[$pid]['notice']=$notice;

	 	  }

	  

		  echo " <div class='textbox'>\n";

		  echo "  <table cellpadding=0 cellspacing=0 border=0>\n";

	  	  echo "   <tr class='title2'><td>Players On The Trading Block</td></tr>\n";

		  echo "   <tr><td>\n";

	  	  echo "    <table cellpadding=2 cellspacing=0 border=0 width='935px'>\n";

		  echo "     <tr class='headline'>";

	  	  echo "<td class='hsc2_l'>Player</td>\n";

		  echo "<td class='hsc2'>Pos</td>\n";

	  	  echo "<td class='hsc2'>Age</td>\n";

		  echo "<td class='hsc2_l'>Team</td>\n";

	  	  echo "<td class='hsc2'>Level</td>\n";

		  echo "<td class='hsc2'>Headline</td>\n";

	  	  echo "<td class='hsc2'>Action</td>\n";

		  echo "</tr>\n";

	  	  $cnt=0;

		  foreach ($on_block as $pid => $val)

	 	  {

			  if ($on_block[$pid]!=1) {continue;}

              $name=$players[$pid]['name'];

			  $tid=$players[$pid]['team_id'];

              $tname=$teams[$tid]['name'];

			  $level=$players[$pid]['level'];

              $pos=$players[$pid]['pos'];

			  $age=$players[$pid]['age'];

        

			  $cls='s'.($cnt%2+1);

			  echo "     <tr class='$cls'>";

	       		  echo "<td class='".$cls."_l'><a href='$lgpath/players/player_$pid.html'>$name</a></td>";

			  echo "<td>$pos</td>";

	       		  echo "<td>$age</td>";

			  echo "<td class='".$cls."_l'><a href='$lgpath/teams/team_$tid.html'>$tname</a></td>";

	       		  echo "<td>$level</td>";

			  echo "<td>".htmlspecialchars($players[$pid]['headline'])."</td>";

	       		  if ($on_block[$pid]==1)

			  {

		    		  echo "<td><a href='./tradeBlockAdmin.php?player=$pid'>Configure</a>/<a href='./tradeBlockAdmin.php?player=$pid&remove=1'";

				  if ($addDisable==1) {echo " onclick=\"return confirm('Are you sure you\\'d like to remove $pos ".str_replace("\'","\\'",addslashes($name))." from the trade block?\\nThis action cannot be undone until the next sim.')\"";}

		    		  echo">Remove</a></td>";

			  }

	      		  elseif ($addDisable==1) {echo "<td>&nbsp;</td>\n";}

			  else {echo "<td><a href='./tradeBlockAdmin.php?player=$pid'>Add</a></td>";}

	       		  echo "</tr>\n";

			  echo "     <tr class='$cls'>";

	       		  echo "<td colspan=3>&nbsp;</td>";

			  echo "<td class='".$cls."_l' colspan=4>".$players[$pid]['notice']."</td>";

	       		  echo "</tr>\n";

			  $cnt++;

	 	  }

		  echo "     </td></tr>\n";

	  	  echo "    </table>\n";

		  echo "   </td></tr>\n";

	  	  echo "  </table>\n";

		  echo " </div>\n";

	  }

     

	  ## Display Untouchable

	  if ($ubList!="")

    	  {

		  echo " <div class='textbox'>\n";

	  	  echo "  <table cellpadding=0 cellspacing=0 border=0>\n";

		  echo "   <tr class='title2'><td>Untouchable Players</td></tr>\n";

	  	  echo "   <tr><td>\n";

		  echo "    <table cellpadding=2 cellspacing=0 border=0 width='935px' class='sortable'>\n";

	  	  echo "     <tr class='headline'>";

		  echo "<td class='hsc2_l'>Player</td>\n";

	  	  echo "<td class='hsc2'>Pos</td>\n";

		  echo "<td class='hsc2'>Age</td>\n";

	  	  echo "<td class='hsc2_l'>Team</td>\n";

		  echo "<td class='hsc2'>Level</td>\n";

	  	  echo "</tr>\n";

		  $cnt=0;

	  	  foreach ($on_block as $pid => $val)

		  {

	       		  if ($on_block[$pid]!=-1) {continue;}

			  $name=$players[$pid]['name'];

	       		  $tid=$players[$pid]['team_id'];

			  $tname=$teams[$tid]['name'];

              $level=$players[$pid]['level'];

              $pos=$players[$pid]['pos'];

	       		  $age=$players[$pid]['age'];

	       

			  $cls='s'.($cnt%2+1);

			  echo "     <tr class='$cls'>";

	       		  echo "<td class='".$cls."_l'><a href='$lgpath/players/player_$pid.html'>$name</a></td>";

			  echo "<td>$pos</td>";

	       		  echo "<td>$age</td>";

			  echo "<td class='".$cls."_l'><a href='$lgpath/teams/team_$tid.html'>$tname</a></td>";

	       		  echo "<td>$level</td>";

			  echo "</tr>\n";

	       		  $cnt++;

		  }

	  	  echo "     </td></tr>\n";

		  echo "    </table>\n";

	  	  echo "   </td></tr>\n";

		  echo "  </table>\n";

	  	  echo " </div>\n";

	  }     

     

	  ## Get All Players In Organization

	  echo " <div class='textbox'>\n";

     	  echo "  <table cellpadding=0 cellspacing=0 border=0>\n";

	  echo "   <tr class='title2'><td>All Players In System</td></tr>\n";

     	  echo "   <tr><td>\n";

	  echo "    <table cellpadding=2 cellspacing=0 border=0 width='935px' class='sortable'>\n";

     	  echo "     <tr class='headline'>";

	  echo "<td class='hsc2_l'>Player</td>\n";

     	  echo "<td class='hsc2'>Pos</td>\n";

	  echo "<td class='hsc2'>Age</td>\n";

     	  echo "<td class='hsc2_l'>Team</td>\n";

	  echo "<td class='hsc2'>Level</td>\n";

     	  echo "<td class='hsc2'>Action</td>\n";

	  echo "</tr>\n";

     	  $cnt=0;

	  foreach ($players as $pid => $val)

    	  {

		  $name=$players[$pid]['name'];

	  	  $tid=$players[$pid]['team_id'];

		  $tname=$teams[$tid]['name'];

          $level=$players[$pid]['level'];

          $lvlID=$players[$pid]['lvlID'];

          $pos=$players[$pid]['pos'];

	  	  $age=$players[$pid]['age'];



		  $cls='s'.($cnt%2+1);

	  	  echo "     <tr class='$cls'>";

		  echo "<td class='".$cls."_l'><a href='$lgpath/players/player_$pid.html'>$name</a></td>";

	  	  echo "<td>$pos</td>\n";

		  echo "<td>$age</td>\n";

	  	  echo "<td class='".$cls."_l'><a href='$lgpath/teams/team_$tid.html'>$tname</a></td>\n";

		  echo "<td sorttable_customkey='".$lvlID."'>$level</td>\n";

	  	  if ($on_block[$pid]==1)

		  {

	       		  echo "<td><a href='./tradeBlockAdmin.php?player=$pid'>Configure</a>/<a href='./tradeBlockAdmin.php?player=$pid&remove=1'";

			  if ($addDisable==1) {echo " onclick=\"return confirm('Are you sure you\\'d like to remove $pos ".str_replace("\'","\\'",addslashes($name))." from the trade block?\\nThis action cannot be undone until the next sim.')\"";}

	       		  echo ">Remove</a></td>\n";

		  }

	 	  elseif ($addDisable==1) {echo "<td>&nbsp;</td>\n";}

		  else {echo "<td><a href='./tradeBlockAdmin.php?player=$pid'>Add</a></td>\n";}

		  echo "</tr>\n";

		  $cnt++;

    	  }

	  echo "     </td></tr>\n";

     	  echo "    </table>\n";

	  echo "   </td></tr>\n";

     	  echo "  </table>\n";

	  echo " </div>\n";

     	  break;

  }

  

  mysqli_close($db);



  ################## END OF PAGE #########################

  echo " </div>   <!-- END contentpane DIV -->\n";

  page_foot($_SESSION['lgpath']);



?>

