When I was recently showing the Booking System to a customer they asked about a really handy feature. The feature request was for the ability for them to set a Sites Terms and Conditions and then have customers agree to this before it will allow them to use the site. What a great idea. So now it was time to put it into action and add the functionality to the site.

After working through it I have decided that it will need to do the following

  • The site will need to record when the terms and conditions where accepted and what they were (In case they change)
  • It will need to be able to be reset by the site admin’s in case of a change. (or per user basis)
  • It needs to be disruptive if they are not agreed to.

So with that in mind here is how I went about implementing it.

Database Changes

First up is some changes to the database. As this is a per user item there are a few additional Columns that will need to be added to the users table. The columns will be

  • accepted_terms – This is a copy of the terms that the user agreed to. This way the site terms can change, but the terms that were agreed to are able to be referenced.
  • terms_accepted – This is a true/false field that is either true the T&C’s have been accepted or false, they haven’t
  • accepted_date – Date that the terms were accepted in case they are required.

Here is the SQL

ALTER TABLE `users` 
ADD `accepted_terms` TEXT NOT NULL,  
ADD `terms_accepted` VARCHAR(1) NOT NULL,  
ADD `accepted_date` VARCHAR(50) NOT NULL

Site Settings.

Next step was to create site setting that holds the terms and conditions. Site settings are easily added in the booking system by adding a entry to the database with the name as the key and the terms and conditions as the value. (Think of the settings as a huge array). Once that part is created I added the ability to edit it to the Site Settings page.

Site Changes.

The last thing to do was to make it disruptive to users that had not agreed to them. On the main menu page I added the following code to display a simple table if the terms_accepted value in the database was false.

/* Check the database to see if the user has accepted the T&C's */
$sql = "SELECT `terms_accepted` FROM `users` WHERE `user` = '" .$_SESSION['user'] ."' LIMIT 1 ";

//Get the results.
$results = mysql_query($sql)
	or die("Error getting account information.");
$row = mysql_fetch_array($results);

// if the database value is n for no (False)
if($row['terms_accepted'] == "n") {
	//Show the table
        ?>
		<form method="post" action="submitpage.php" name="tandcaccept">
			<table align="center" width="100%">
				<thead>
					<tr>
						<th>Site Terms and Conditions.</th>
					</tr>
				</thead>
				<tr>
					<td><? /* Display the Terms and Conditions*/ ?></td>
				</tr>
				<tr>
				  <td><div align="center">
					<input name="tc_accept" type="checkbox" id="tc_accept" value="y">
					I accept these terms and conditions. <input name="Submit" type="submit" id="Submit" />
					</div></td>
				</tr>
			</table>
		</form>
	<?
} else {
	/* Normal Action */
}

And here is the code that checks and updates the database (submitpage.php)

//Collect Variable
$terms_accept = addslashes($_POST['tc_accept']);

//If the checkbox has been ticked update the database
if($terms_accept == "y") {
	$sql = "UPDATE `users` SET `terms_accepted` = '$terms_accept', `accepted_terms` = '$copyofterms', ";
	$sql .= "`accepted_date` = '" .strtotime("now") ."' WHERE  `user` = '" .$_SESSION['user'] ."' LIMIT 1 ";
	
	$results = mysql_query($sql)
		or die($error = "Error updating account");
} //Check result

Now I know this doesnt completely block the user from the site, it does however make it difficult to navigate unless they are accepted as every time they hit the main menu (Which is often) they would be presented with the Terms and Conditions Acceptance.