<?php
defined('_JEXEC') or die;
function sourcerer_php_e5609b857cc6189cae999c564343fcac($src_variables){
$app = $mainframe = JFactory::getApplication();
$document = $doc = JFactory::getDocument();
$database = $db = JFactory::getDbo();
$user = 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 = "ctsadmin_jos5"; 
$passName = "T&F3WvItVi1tia&y*i*35(^3"; 
$dbName = "ctsadmin_jos5"; 
 

 
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>"; 
}  

 
  

 
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 />"; 

 
//CHOOSE TO LOGOUT USER OR HAVE USER AGREE 
$action=$_POST['submit']; 

 
//SEND USER BASED ON ACTION OF TOS 
//LOGS USER OUT 
if($action=="Get me out of here") { 

 
echo $action; 

 
//header("Location: https://www.grantcountypress.com/index.php/logout");  

 
} 

 
//LETS USER CONTINUE 
if ($action=="I agree") { 

 
$dbQuery = "UPDATE  jos_user_tos "; 
$dbQuery .= "SET agreetos=1"; 
$dbQuery .= "WHERE userid=$user->id "; 

 
//RUN UPDATE QUERY 
try { 
$conDB->query($dbQuery); 
} 

 
//CATCH ERROR 
catch (Exception $e) { 

 
//ECHO ERROR 
echo $e; 

 
} 

 
//REDIRECT USER TO SPLASH PAGE 
 header("Location: https://www.grantcountypress.com/index.php/splash-page");  

 
  

 
else { 

 
//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"]; 

 
//CHECK IF USER HAS AGREED TO TOS 
if ($tosagree==0) { 

 
//IF USER NEEDS TO AGREE, PROVIDE FORM TO FILL OUT 
echo "<h2>Terms and Conditions</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='Get me out of here' />&nbsp;&nbsp;&nbsp;<input type='submit' name='submit' value='I agree' />"; 
echo "</form>"; 

 
} 

 
//USE HAS AGREED MOVE ON 
else{ 

 
//SEND USER TO SPLASH PAGE 
//echo "user is good"; 

 
 header("Location: https://www.grantcountypress.com/index.php/splash-page");  

 
} 

 
} 

 
} 

 
} 

 
//IF USER IS NOT FOUND IN DATABASE 
else { 

 
//ADD RECORD TO DB FOR USERID 
 $dbQuery = "INSERT INTO jos_user_tos (userid,userip,userdttme) "; 
 $dbQuery .= "VALUES ($user->id,'$machIP','$dtme') "; 

 
//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"; 

 
 
}  
//RECORD NOT ADDED TO DB 
else { 
//SHOW ERROR 
    echo "Error: " . $dbQuery . "<br>" . $conDB->error; 
} 
} 

 
//CLOSE CONNECTION TO DB 
$conDB->close(); 

 
};;
return get_defined_vars();
;}