<?php

  include("html_functions.php");

  

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

  {

	  header('Location: '.$_SERVER['HTTP_REFERER']);

  }



  # Initialize variables

  $settings['scoutsOn']=0;

  $playersPerRun=3000;



  # Get admin settings

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

  $query="SELECT setting,value FROM ootp_sql_admin WHERE scope='ALL' AND module='admin';";

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $setting=$row['setting'];

		  $settings[$setting]=$row['value'];

	  }

  }

  $scoutsOn=$settings['scoutsOn'];

  $trackSplits=$settings['trackSplits'];



  # Get current date

  if (!isset($_SESSION['lgdate']))

  {

	  $query="SELECT leagues.current_date as lgdate FROM leagues LIMIT 1";

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

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

	  $row=mysqli_fetch_array($result);

	  $_SESSION['lgdate']=$row['lgdate'];

  }

  $lgdate=$_SESSION['lgdate'];



  ##### Check if dev table exists #####

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

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

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

  if (!mysqli_num_rows($result)) 

  {

     ##### Initialize Development Table #####

     $query="CREATE TABLE IF NOT EXISTS players_development (player_id INT, dev_date DATE, rating VARCHAR(80), old_value SMALLINT, new_value SMALLINT, PRIMARY KEY (player_id, dev_date, rating));";

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

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

  }



  ##### Check if old ratings table exists #####

  $query="SHOW TABLES LIKE 'players_%_old';";

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

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

  if ((!mysqli_num_rows($result))||(mysqli_num_rows($result)<3))

  {

	  $query="CREATE TABLE players_batting_old AS (SELECT pb.*,running_ratings_speed,running_ratings_stealing,running_ratings_baserunning FROM players_batting as pb,(SELECT player_id,running_ratings_speed,running_ratings_stealing,running_ratings_baserunning FROM players WHERE hidden=0 AND retired=0) as p WHERE p.player_id=pb.player_id)";

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

	  mysqli_query($db,$query);

	  $query="CREATE TABLE players_pitching_old AS (SELECT * FROM players_pitching)";

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

	  mysqli_query($db,$query);

	  $query="CREATE TABLE players_fielding_old AS (SELECT * FROM players_fielding)";

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

	  mysqli_query($db,$query);

	

	  # Save off date

	  $scope='ALL';

	  $module='admin';

	  $setting='devrun';

	

	  if (isset($_GET['devLgID']))

	  {

		  $query="INSERT INTO ootp_sql_admin (scope, module, setting, identifier, value) VALUES (";

		  $query.="'$scope', '$module', '$setting', '".$_GET['devLgID']."', '$lgdate'";

		  $query.=") ON DUPLICATE KEY UPDATE value='$lgdate';";

	  }

	  else

	  {

		  $query="INSERT INTO ootp_sql_admin (scope, module, setting, value) VALUES (";

		  $query.="'$scope', '$module', '$setting', '$lgdate'";

		  $query.=") ON DUPLICATE KEY UPDATE value='$lgdate';";

	  }

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

	  mysqli_query($db,$query);

	

	  $_SESSION['devrun']=1;

	

	  mysqli_close($db);



	  header('Location: '.$_SERVER['HTTP_REFERER']);

	  exit;

  }





  ###########################################################

  # Development

  ###########################################################



  ##### Get Max Player ID

  $query="SELECT MAX(player_id) as maxPID FROM players WHERE hidden=0 AND retired=0";

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

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

  $row=mysqli_fetch_array($result);

  $maxPID=$row['maxPID'];

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

  $maxPID=$maxPID-($maxPID%$playersPerRun)+$playersPerRun;

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



  mysqli_close($db);



  $i=0;

  while ($endPID<$maxPID)

  {

	  $updText="";



	  $endPID=$endPID+$playersPerRun;

	  $startPID=$endPID-$playersPerRun+1;



	  if ($_GET['showq']==1) {echo "Running Loop player_id's from $startPID to $endPID<br/><br/>\n";}



  ##### Batting Ratings

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



  if ($trackSplits==1)

  {

	  $scoutArray=Array('batting_ratings_overall_contact', 'batting_ratings_overall_gap', 'batting_ratings_overall_eye', 'batting_ratings_overall_strikeouts', 'batting_ratings_overall_power', 'batting_ratings_vsr_contact', 'batting_ratings_vsr_gap', 'batting_ratings_vsr_eye', 'batting_ratings_vsr_strikeouts', 'batting_ratings_vsr_power', 'batting_ratings_vsl_contact', 'batting_ratings_vsl_gap', 'batting_ratings_vsl_eye', 'batting_ratings_vsl_strikeouts', 'batting_ratings_vsl_power', 'batting_ratings_talent_contact', 'batting_ratings_talent_gap', 'batting_ratings_talent_eye', 'batting_ratings_talent_strikeouts', 'batting_ratings_talent_power', 'batting_ratings_misc_bunt', 'batting_ratings_misc_bunt_for_hit');

  }

  else

  {

	  $scoutArray=Array('batting_ratings_overall_contact', 'batting_ratings_overall_gap', 'batting_ratings_overall_eye', 'batting_ratings_overall_strikeouts', 'batting_ratings_overall_power', 'batting_ratings_talent_contact', 'batting_ratings_talent_gap', 'batting_ratings_talent_eye', 'batting_ratings_talent_strikeouts', 'batting_ratings_talent_power', 'batting_ratings_misc_bunt', 'batting_ratings_misc_bunt_for_hit');

  }



  ## Start query with calculation

  $query="SELECT pcur.player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Add to query

	  $query.=",";

	  $query.="pcur.$ratLbl as new_$ratLbl";

	  $query.=",";

	  $query.="(pcur.$ratLbl-pold.$ratLbl)";

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  # Include current ratings table

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  if ($scoutsOn==1) {$query.="players_batting_scouted";}

  else 

  {

	  $query.="(SELECT pb.* FROM (SELECT * FROM players_batting WHERE player_id>=$startPID AND player_id<=$endPID) as pb,(SELECT player_id,league_id FROM players WHERE player_id>=$startPID AND player_id<=$endPID AND retired=0 AND hidden=0) as p WHERE p.player_id=pb.player_id";

	  if (isset($_GET['devLgID'])) {$query.=" AND p.league_id=".$_GET['devLgID'];}

	  $query.=") as players_batting";

  }

  $query.=") as pcur";

  # Include old ratings table

  $query.=",";

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM players_batting_old";

  $query.=" WHERE player_id>=$startPID AND player_id<=$endPID) as pold";

  $query.=" WHERE pcur.player_id=pold.player_id";

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

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $pid=$row['player_id'];

		  foreach ($scoutArray as $key => $ratLbl)

		  {

			  if ($row[$ratLbl]==0) {continue;}

			  else 

			  {

				  $newLbl='new_'.$ratLbl;

				  $updText.="INSERT IGNORE INTO players_development (player_id,dev_date,rating,old_value,new_value) VALUES ($pid,'$lgdate','$ratLbl',".($row[$newLbl]-$row[$ratLbl]).",".$row[$newLbl].");\n";

			  }

		  }



	  }

  }



  mysqli_close($db);



  ##### Running Ratings

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



  $scoutArray=Array('running_ratings_speed','running_ratings_stealing','running_ratings_baserunning');



  ## Start query with calculation

  $query="SELECT pcur.player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Add to query

	  $query.=",";

	  $query.="pcur.$ratLbl as new_$ratLbl";

	  $query.=",";

	  $query.="(pcur.$ratLbl-pold.$ratLbl)";

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  # Include current ratings table

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  if ($scoutsOn==1) {$query.="players_batting_scouted";}

  else 

  {

	  $query.="(SELECT player_id,running_ratings_speed,running_ratings_stealing,running_ratings_baserunning FROM players WHERE player_id>=$startPID AND player_id<=$endPID AND retired=0 AND hidden=0";

	  if (isset($_GET['devLgID'])) {$query.=" AND p.league_id=".$_GET['devLgID'];}

	  $query.=") as players";

  }

  $query.=") as pcur";

  # Include old ratings table

  $query.=",";

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM players_batting_old";

  $query.=" WHERE player_id>=$startPID AND player_id<=$endPID) as pold";

  $query.=" WHERE pcur.player_id=pold.player_id";

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

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $pid=$row['player_id'];

		  foreach ($scoutArray as $key => $ratLbl)

		  {

			  if ($row[$ratLbl]==0) {continue;}

			  else 

			  {

				  $newLbl='new_'.$ratLbl;

				  $updText.="INSERT IGNORE INTO players_development (player_id,dev_date,rating,old_value,new_value) VALUES ($pid,'$lgdate','$ratLbl',".($row[$newLbl]-$row[$ratLbl]).",".$row[$newLbl].");\n";

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

			  }

		  }



	  }

  }



  mysqli_close($db);



  ##### Pitching Ratings

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

  if ($trackSplits==1)

  {

	  $scoutArray=Array('pitching_ratings_overall_stuff', 'pitching_ratings_overall_control', 'pitching_ratings_overall_movement', 'pitching_ratings_overall_wild_pitch', 'pitching_ratings_vsr_stuff', 'pitching_ratings_vsr_control', 'pitching_ratings_vsr_movement', 'pitching_ratings_vsl_stuff', 'pitching_ratings_vsl_control', 'pitching_ratings_vsl_movement', 'pitching_ratings_talent_stuff', 'pitching_ratings_talent_control', 'pitching_ratings_talent_movement', 'pitching_ratings_pitches_fastball', 'pitching_ratings_pitches_slider', 'pitching_ratings_pitches_curveball', 'pitching_ratings_pitches_screwball', 'pitching_ratings_pitches_forkball', 'pitching_ratings_pitches_changeup', 'pitching_ratings_pitches_sinker', 'pitching_ratings_pitches_splitter', 'pitching_ratings_pitches_knuckleball', 'pitching_ratings_pitches_cutter', 'pitching_ratings_pitches_circlechange', 'pitching_ratings_pitches_knucklecurve', 'pitching_ratings_pitches_talent_fastball', 'pitching_ratings_pitches_talent_slider', 'pitching_ratings_pitches_talent_curveball', 'pitching_ratings_pitches_talent_screwball', 'pitching_ratings_pitches_talent_forkball', 'pitching_ratings_pitches_talent_changeup', 'pitching_ratings_pitches_talent_sinker', 'pitching_ratings_pitches_talent_splitter', 'pitching_ratings_pitches_talent_knuckleball', 'pitching_ratings_pitches_talent_cutter', 'pitching_ratings_pitches_talent_circlechange', 'pitching_ratings_pitches_talent_knucklecurve', 'pitching_ratings_misc_velocity', 'pitching_ratings_misc_stamina', 'pitching_ratings_misc_ground_fly', 'pitching_ratings_misc_hold');

  }

  else

  {

	  $scoutArray=Array('pitching_ratings_overall_stuff', 'pitching_ratings_overall_control', 'pitching_ratings_overall_movement', 'pitching_ratings_overall_wild_pitch', 'pitching_ratings_talent_stuff', 'pitching_ratings_talent_control', 'pitching_ratings_talent_movement', 'pitching_ratings_pitches_fastball', 'pitching_ratings_pitches_slider', 'pitching_ratings_pitches_curveball', 'pitching_ratings_pitches_screwball', 'pitching_ratings_pitches_forkball', 'pitching_ratings_pitches_changeup', 'pitching_ratings_pitches_sinker', 'pitching_ratings_pitches_splitter', 'pitching_ratings_pitches_knuckleball', 'pitching_ratings_pitches_cutter', 'pitching_ratings_pitches_circlechange', 'pitching_ratings_pitches_knucklecurve', 'pitching_ratings_pitches_talent_fastball', 'pitching_ratings_pitches_talent_slider', 'pitching_ratings_pitches_talent_curveball', 'pitching_ratings_pitches_talent_screwball', 'pitching_ratings_pitches_talent_forkball', 'pitching_ratings_pitches_talent_changeup', 'pitching_ratings_pitches_talent_sinker', 'pitching_ratings_pitches_talent_splitter', 'pitching_ratings_pitches_talent_knuckleball', 'pitching_ratings_pitches_talent_cutter', 'pitching_ratings_pitches_talent_circlechange', 'pitching_ratings_pitches_talent_knucklecurve', 'pitching_ratings_misc_velocity', 'pitching_ratings_misc_stamina', 'pitching_ratings_misc_ground_fly', 'pitching_ratings_misc_hold');

  }



  ## Start query with calculation

  $query="SELECT pcur.player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Add to query

	  $query.=",";

	  $query.="pcur.$ratLbl as new_$ratLbl";

	  $query.=",";

	  $query.="(pcur.$ratLbl-pold.$ratLbl)";

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  # Include current ratings table

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  if ($scoutsOn==1) {$query.="players_pitching_scouted";}

  else 

  {

	  $query.="(SELECT pb.* FROM (SELECT * FROM players_pitching WHERE player_id>=$startPID AND player_id<=$endPID) as pb,(SELECT player_id,league_id FROM players WHERE player_id>=$startPID AND player_id<=$endPID AND retired=0 AND hidden=0) as p WHERE p.player_id=pb.player_id";

	  if (isset($_GET['devLgID'])) {$query.=" AND p.league_id=".$_GET['devLgID'];}

	  $query.=") as players_pitching";

  }

  $query.=") as pcur";

  # Include old ratings table

  $query.=",";

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM players_pitching_old";

  $query.=" WHERE player_id>=$startPID AND player_id<=$endPID) as pold";

  $query.=" WHERE pcur.player_id=pold.player_id";

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

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $pid=$row['player_id'];

		  foreach ($scoutArray as $key => $ratLbl)

		  {

			  if ($row[$ratLbl]==0) {continue;}

			  else 

			  {

				  $newLbl='new_'.$ratLbl;

				  $updText.="INSERT IGNORE INTO players_development (player_id,dev_date,rating,old_value,new_value) VALUES ($pid,'$lgdate','$ratLbl',".($row[$newLbl]-$row[$ratLbl]).",".$row[$newLbl].");\n";

			  }

		  }



	  }

  }



  mysqli_close($db);



  ##### Fielding Ratings

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



  $scoutArray=Array('fielding_ratings_infield_range', 'fielding_ratings_infield_arm', 'fielding_ratings_turn_doubleplay', 'fielding_ratings_outfield_range', 'fielding_ratings_outfield_arm', 'fielding_ratings_catcher_arm', 'fielding_ratings_catcher_ability', 'fielding_ratings_infield_error', 'fielding_ratings_outfield_error', 'fielding_rating_pos1', 'fielding_rating_pos2', 'fielding_rating_pos3', 'fielding_rating_pos4', 'fielding_rating_pos5', 'fielding_rating_pos6', 'fielding_rating_pos7', 'fielding_rating_pos8', 'fielding_rating_pos9');

  

  ## Start query with calculation

  $query="SELECT pcur.player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Add to query

	  $query.=",";

	  $query.="pcur.$ratLbl as new_$ratLbl";

	  $query.=",";

	  $query.="(pcur.$ratLbl-pold.$ratLbl)";

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  # Include current ratings table

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM ";

  if ($scoutsOn==1) {$query.="players_fielding_scouted";}

  else 

  {

	  $query.="(SELECT pb.* FROM (SELECT * FROM players_fielding WHERE player_id>=$startPID AND player_id<=$endPID) as pb,(SELECT player_id,league_id FROM players WHERE player_id>=$startPID AND player_id<=$endPID AND retired=0 AND hidden=0) as p WHERE p.player_id=pb.player_id";

	  if (isset($_GET['devLgID'])) {$query.=" AND p.league_id=".$_GET['devLgID'];}

	  $query.=") as players_fielding";

  }

  $query.=") as pcur";

  # Include old ratings table

  $query.=",";

  $query.="(SELECT player_id";

  foreach ($scoutArray as $key => $ratLbl)

  {

	  # Get scale

	  $ratScale=get_scale($ratLbl);

	  $scale=$settings[$ratScale];

	

	  # Add to query

	  $query.=",";

	  $query.=ratings_query($ratLbl,$scale,"",0);

	  $query.=" as $ratLbl";

  }

  $query.=" FROM players_fielding_old";

  $query.=" WHERE player_id>=$startPID AND player_id<=$endPID) as pold";

  $query.=" WHERE pcur.player_id=pold.player_id";

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

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

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

  if (mysqli_num_rows($result))

  {

	  while ($row=mysqli_fetch_array($result))

	  {

		  $pid=$row['player_id'];

		  foreach ($scoutArray as $key => $ratLbl)

		  {

			  if ($row[$ratLbl]==0) {continue;}

			  else 

			  {

				  $newLbl='new_'.$ratLbl;

				  $updText.="INSERT IGNORE INTO players_development (player_id,dev_date,rating,old_value,new_value) VALUES ($pid,'$lgdate','$ratLbl',".($row[$newLbl]-$row[$ratLbl]).",".$row[$newLbl].");\n";

			  }

		  }



	  }

  }



  mysqli_close($db);



  ##### Run queries into DB

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



  if ($updText!="")

  {

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

       	  $updText=trim($updText);

	  $e=explode("\n",$updText);

	  if ($_GET['showq']==1) {echo "Loading ".count($e)." development changes<br/><br/>\n";}

       	  foreach ($e as $key => $query)

	  {

		  mysqli_query($db,$query);

		  $err=mysqli_error($db);

	    	  if ($err!="") {echo $err."<br />\n";}

	  }

  }





  mysqli_close($db);



    }   // End While Loop



  ## Save off ratings into old tables (only if scouts off, if scouts are on, then they get saved off when scouted)

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



  if ($scoutsOn==0)

  {

	  $query="DROP TABLE IF EXISTS players_batting_old;";

	  mysqli_query($db,$query);

	  $query="DROP TABLE IF EXISTS players_pitching_old;";

	  mysqli_query($db,$query);

	  $query="DROP TABLE IF EXISTS players_fielding_old;";

	  mysqli_query($db,$query);



	  $query="CREATE TABLE players_batting_old AS (SELECT pb.*,running_ratings_speed,running_ratings_stealing,running_ratings_baserunning FROM players_batting as pb,(SELECT player_id,running_ratings_speed,running_ratings_stealing,running_ratings_baserunning FROM players WHERE hidden=0 AND retired=0) as p WHERE p.player_id=pb.player_id)";

	  mysqli_query($db,$query);

	  $query="CREATE TABLE players_pitching_old AS (SELECT * FROM players_pitching)";

	  mysqli_query($db,$query);

	  $query="CREATE TABLE players_fielding_old AS (SELECT * FROM players_fielding)";

	  mysqli_query($db,$query);

  }



  # Save off date

  $scope='ALL';

  $module='admin';

  $setting='devrun';



  if (isset($_GET['devLgID']))

  {

	  $query="INSERT INTO ootp_sql_admin (scope, module, setting, identifier, value) VALUES (";

	  $query.="'$scope', '$module', '$setting', '".$_GET['devLgID']."', '$lgdate'";

	  $query.=") ON DUPLICATE KEY UPDATE value='$lgdate';";

  }

  else

  {

	  $query="INSERT INTO ootp_sql_admin (scope, module, setting, value) VALUES (";

	  $query.="'$scope', '$module', '$setting', '$lgdate'";

	  $query.=") ON DUPLICATE KEY UPDATE value='$lgdate';";

  }

  mysqli_query($db,$query);



  $_SESSION['devrun']=1;



  mysqli_close($db);



  header('Location: '.$_SERVER['HTTP_REFERER']);



?>

