<?php

  include("html_functions.php");



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

  $lgid=$_SESSION['lgid'];



  # Check Admin Table

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

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

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

  if (mysqli_num_rows($result)) 

  {

	  # Get Settings

	  $query="SELECT scope,setting,value FROM ootp_sql_admin WHERE setting LIKE '%nable'";

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

	  if (mysqli_num_rows($result))

	  {

		  while ($row=mysqli_fetch_array($result))

		  {

			  $scope=$row['scope'];

			  $setting=$row['setting'];

			  $value=$row['value'];



			  $settings[$scope][$setting]=$value;

		  }

	  }

  }



  # Get Leagues

  $query="SELECT league_id,name,abbr,parent_league_id,league_level FROM leagues ORDER BY league_id";

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

  $lgCnt=0;

  if (mysqli_num_rows($result)) 

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $league_id=$row['league_id'];

		  $leagues[$league_id]['name']=$row['name'];

		  $leagues[$league_id]['abbr']=$row['abbr'];

		  $leagues[$league_id]['parent']=$row['parent_league_id'];

		  $leagues[$league_id]['level']=$row['league_level'];

		  $leagues[$lgCnt]=$league_id;

		  $lgCnt++;

	  }

	  $lgTotCnt=count($leagues)/2;

  }



  mysqli_close($db);



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

  $title='IP Address Report - Last 30 Days';



  page_head($title,$_SESSION['lgpath']);

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

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



  if ($_SESSION['user_is_commish']!=1)

  {

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

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

	  echo "You must be a commisioner to access this page";

	

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

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

	  page_foot($_SESSION['lgpath']);

	  exit;

  }

  else

  {

	  nav_toolbar('admin','Admin Pages');

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

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

  }





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

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



  ## User Report

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

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

  echo "  <tr class='title'><td colspan=3>IP's Per User</td></tr>\n";

  echo "  <tr class='headline'><td>User ID</td><td>Username</td><td>IP Addresses</td></tr>\n";

  $query="SELECT hm.human_manager_id,first_name,last_name,ip_address,last_date FROM human_managers as hm,ootp_sql_users as osu WHERE hm.human_manager_id=osu.human_manager_id ORDER BY last_name,first_name,last_date DESC";

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

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

  if (mysqli_num_rows($result))

  {

	  $lastHMid=-1;

	  $rowcnt=0;

	  while ($row=mysqli_fetch_array($result))

	  {

		  $hmid=$row['human_manager_id'];



		  if ($hmid!=$lastHMid)

		  {

			  $rowcnt++;

			  if ($rowcnt>0) {echo "</td></tr>\n";}



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

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

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

			  echo "<td>".$row['first_name']." ".$row['last_name']."</td>";

			  echo "<td>";

		  }

		  else {echo ", ";}



		  echo "<span title='Date: ".$row['last_date']."'>".$row['ip_address']."</span>";



		  $lastHMid=$hmid;

	  }

	  if ($rowcnt>0) {echo "</td></tr>\n";}

  }

  echo " </table>\n";

  echo "</div>\n";



  ## IP Report

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

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

  echo "  <tr class='title'><td colspan=2>Users Per IP</td></tr>\n";

  echo "  <tr class='headline'><td>IP Addresses</td><td>Username</td></tr>\n";

  $query="SELECT hm.human_manager_id,first_name,last_name,ip_address,last_date FROM human_managers as hm,ootp_sql_users as osu WHERE hm.human_manager_id=osu.human_manager_id ORDER BY ip_address,last_name,first_name,last_date DESC";

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

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

  if (mysqli_num_rows($result))

  {

	  $lastIP=-1;

	  $rowcnt=0;

	  while ($row=mysqli_fetch_array($result))

	  {

		  $ip=$row['ip_address'];



		  if ($ip!=$lastIP)

		  {

			  $rowcnt++;

			  if ($rowcnt>0) {echo "</td></tr>\n";}



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

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

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

			  echo "<td>";

		  }

		  else {echo ", ";}



		  echo "<span title='ID: ".$row['human_manager_id'].", Date: ".$row['last_date']."'>".$row['first_name']." ".$row['last_name']."</a></span>";



		  $lastIP=$ip;

	  }

	  if ($rowcnt>0) {echo "</td></tr>\n";}

  }

  echo " </table>\n";

  echo "</div>\n";



  mysqli_close($db);

 

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

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

  page_foot($_SESSION['lgpath']);





?>

