<?php
defined('_JEXEC') or die;
function regularlabs_php_77508e7b635e5b1021248be90ca0291a($src_variables){
$app = $mainframe = RegularLabs\Library\Condition\Php::getApplication();
$document = $doc = RegularLabs\Library\Condition\Php::getDocument();
$database = $db = JFactory::getDbo();
$user = JFactory::getApplication()->getIdentity() ?: JFactory::getUser();
$Itemid = $app->input->getInt('Itemid');
if (is_array($src_variables)) {foreach ($src_variables as $src_key => $src_value) {${$src_key} = $src_value;}}
$dbServer = "localhost"; 
$nameUser = "gcpadmin_2019"; 
$passName = "T&F3WvItVi1tia&y*i*35(^3"; 
$dbName = "gcpadmin_2019"; 

 
date_default_timezone_set('America/New_York'); 

 
$machIP = gethostbyaddr($_SERVER['REMOTE_ADDR']); 
$user = JFactory::getUser(); 
$dtme = date(DATE_ATOM, time()); 

 
  

 
if ($user->guest) { 
//echo "<p>You must login to see the content.</p>"; 
header("Location: https://grantcountypress.com/index.php/login"); 

 
} 

 
  

 
else { 
//echo "<p>You are logged in, you can see the content.</p>"; 

 
 
//CREATE CONNECTION TO DATABASE 
try { 
$conDB = new mysqli($dbServer,$nameUser,$passName,$dbName); 
} 

 
//IF CONNECTION FAILS, PROVIDE ERROR MESSAGE AND DIE 
catch(Exception $e){ 
die( print_r( $e->getMessage() ) ); 
} 

 
//VALIDATE DB CONNECTION 
if ($conDB->connect_error) { 
die("Connection Failed: " . $conDB->connect_error); 
} 
//echo "Connected Successfully <br />"; 

 
//GET UPDATED TERMS OF SERVICE DATE 
$dbQuery = "SELECT * "; 
$dbQuery .= "FROM jos_content "; 
$dbQuery .= "WHERE asset_id = 1256"; 

 
//RUN QUERY 
$results = $conDB->query($dbQuery); 

 
//SEE HOW MANY ROWS WERE FOUND 
if ($results->num_rows > 0 ) { 

 
//GET DETAILS OF RECORD 
while($rows = $results->fetch_assoc()) { 

 
//ASSIGN FIELD TO VARIABLE FOR TOS MODIFIED DATE 
$tosdate = $rows["modified"]; 

 
  

 
} 

 
} 

 
//echo $tosdate; 

 
//CHOOSE TO LOGOUT USER OR HAVE USER AGREE 
$action=$_POST['submit']; 

 
//SEND USER BASED ON ACTION OF TOS 
//LOGS USER OUT 
if($action=="I do not agree") { 

 
echo $action; 

 
header("Location: https://grantcountypress.com/index.php/logout"); 

 
} 

 
//LETS USER CONTINUE 
if ($action=="I agree") { 

 
$dbQuery = "UPDATE jos_user_tos "; 
$dbQuery .= "SET agreetos=1,userip='$machIP' "; 
$dbQuery .= "WHERE userid=$user->id "; 

 
echo $dbQuery; 

 
 
//RUN UPDATE QUERY 
try { 
$conDB->query($dbQuery); 
} 

 
//CATCH ERROR 
catch (Exception $e) { 

 
//ECHO ERROR 
die( print_r( $e->getMessage() ) ); 

 
} 

 
//REDIRECT USER TO SPLASH PAGE 
 header("Location: https://www.grantcountypress.com/index.php/splash-page"); 

 
} 

 
//CHECK IF USER RECORD EXISTS 

 
//CREATE QUERY TO SELECT RECORD 
$dbQuery = "SELECT * "; 
$dbQuery .= "FROM jos_user_tos "; 
$dbQuery .= "WHERE userid=$user->id "; 

 
//RUN QUERY 
$results = $conDB->query($dbQuery); 

 
//SEE HOW MANY ROWS WERE FOUND 
if ($results->num_rows > 0 ) { 

 
//GET DETAILS OF RECORD 
while($rows = $results->fetch_assoc()) { 

 
//ASSIGN FIELD TO VARIABLE TO CHECK IF USER HAS AGREED TO TOS 
$tosagree = $rows["agreetos"]; 

 
//SAVE DATE USER AGREED TO COMPARE TO LAST UPDATE 
$useragree = $rows["userdttme"]; 

 
//CHECK IF USER HAS AGREED TO TOS 
if ($tosagree==0) { 

 
//IF USER NEEDS TO AGREE, PROVIDE FORM TO FILL OUT 
echo "<h2>Updated Terms of Service</h2>"; 

 
echo "Grant County Press has recently updated the terms of service. You must agree to these terms in order to continuing to use this site. If you do not agree, your access to material will be limited. <a href='/index.php/terms-of-service' target='_blank'>Click here to read the updated terms of service.</a>"; 

 
echo "<form action='' method='post' enctype='multipart/form-data'>"; 
echo "<input type='hidden' name='action' value='submit'>"; 

 
echo "<input type='submit' name='submit' value='I do not agree' />&nbsp;&nbsp;&nbsp;<input type='submit' name='submit' value='I agree' />"; 
echo "</form>"; 

 
} 

 
//USER HAS AGREED MOVE ON 
else{ 

 
  

 
$ua = strtotime($useragree); 
$ta = strtotime($tosdate)-14400; 

 
  

 
  

 
//CHECK TO SEE IF USER AGREED TO UPDATED TERMS OR PREVIOUS 

 
if ($ua > $ta) { 

 
//SEND USER TO SPLASH PAGE 
//echo "user is good"; 

 
header("Location: https://grantcountypress.com/index.php/splash-page"); 

 
} 

 
else { 

 
//IF USER NEEDS TO AGREE, PROVIDE FORM TO FILL OUT 
echo "<h2>Updated Terms of Service</h2>"; 

 
echo "Grant County Press has recently updated the terms of service. You must agree to these terms in order to continuing to use this site. If you do not agree, your access to material will be limited. <a href='/index.php/terms-of-service' target='_blank'>Click here to read the updated terms of service.</a>"; 

 
echo "<form action='' method='post' enctype='multipart/form-data'>"; 
echo "<input type='hidden' name='action' value='submit'>"; 

 
echo "<input type='submit' name='submit' value='I do not agree' />&nbsp;&nbsp;&nbsp;<input type='submit' name='submit' value='I agree' />"; 
echo "</form>"; 

 
} 

 
} 

 
} 

 
} 

 
//IF USER IS NOT FOUND IN DATABASE 
else { 

 
//ADD RECORD TO DB FOR USERID 
$dbQuery = "INSERT INTO jos_user_tos (userid,userip) "; 
$dbQuery .= "VALUES ($user->id,'$machIP') "; 

 
//RUN QUERY TO ADD RECORD 
if ($conDB->query($dbQuery) === TRUE) { 
 //RECORD HAS ADDED SUCCESSFULLY SHOW FORM TO AGREE TO TOS 
 //echo "New record created successfully"; 

 
//IF USER NEEDS TO AGREE, PROVIDE FORM TO FILL OUT 
echo "<h2>Updated Terms of Service</h2>"; 

 
echo "Grant County Press has recently updated the terms of service. You must agree to these terms in order to continuing to use this site. If you do not agree, your access to material will be limited. <a href='/index.php/terms-of-service' target='_blank'>Click here to read the updated terms of service.</a>"; 

 
echo "<form action='' method='post' enctype='multipart/form-data'>"; 
echo "<input type='hidden' name='action' value='submit'>"; 

 
echo "<input type='submit' name='submit' value='I do not agree' />&nbsp;&nbsp;&nbsp;<input type='submit' name='submit' value='I agree' />"; 
echo "</form>"; 

 
 
}  
//RECORD NOT ADDED TO DB 
else { 
//SHOW ERROR 
 echo "Error: " . $dbQuery . "<br>" . $conDB->error; 
} 
} 

 
//CLOSE CONNECTION TO DB 
$conDB->close(); 

 
};;
return get_defined_vars();
;}