Age lock categories.
This modification allows categories to be aged locked (over and under).
There is an addition to the general settings to enable, disable age locking.
In category manager when editing /creating a new category there is an addition of two new input boxes. If you have this option disabled then no need to populate the boxes.
There is an input box that takes the age lock method (n, o, u). n=no age locking, o= over age, u = under age
Another input box accepts the age to be locked.
Over age locking allows access when the individual is over the selected age.
Under age locking is allows access when the individual is under the selected age.
This modification when age locking is enabled requires that the user input a properly formatted birthday. This birthday is stored as user information. The birthday is not editable (if the user gets it wrong the first time S.O.L), the birthday is not displayed. Of course if you have SQL skills you can directly edit the dB.
This is my first pass at age locking. I hope to make some improvements as time goes on. Right now age lock setting for child categories is defaulted to the parent category. For my requirements this is acceptable behavior.
This modification is for experienced individuals. I'm sure the experienced individuals who decide to follow these poorly written instructions would have taken proper precautions to insure your sites integrity.
The line numbers reflect the line numbers of a fresh install that does not have any other modifications so the line numbers should be pretty close.
Files to be modified:
register.php, english.php, catmgr.php, udb_base.inc.php, index.php
get files from your site, make copies. Do not edit the originals.
add field to user table, run the following MySQL command.
ALTER TABLE `cpg1410_users` ADD `user_bday` VARCHAR( 10 ) NULL ;
Add three fields to the categories table
ALTER TABLE `cpg1410_categories` ADD `agelock` BOOL NOT NULL DEFAULT '0';
ALTER TABLE `cpg1410_categories` ADD `agelock_method` VARCHAR( 10 ) NOT NULL DEFAULT 'n';
ALTER TABLE `cpg1410_categories` ADD `agelock_age` VARCHAR( 10 ) NOT NULL DEFAULT '18';
INSERT INTO `cpg1410_config` ( `name` , `value` )
VALUES ('bday_required', '1');
*************** REGISTER.PHP EDITS – BEGIN *****************
edit register.php:
Find (~ line number 74): array('input', 'email', $lang_register_php['email'], 255),
Add below:
//age lock mod --Louis_Chypher@gmail.com *BEGIN
array('input', 'b_day', $lang_register_php['b_day'], 255),
//age lock mod --Louis_Chypher@gmail.com-- *END
save
find - around line 217
global $lang_register_php, $lang_register_confirm_email, $lang_continue, $lang_register_approve_email, $lang_register_activated_email, $lang_register_user_login;
replace with:
//agelock mod - begin
//global $lang_register_php, $lang_register_confirm_email, $lang_continue, $lang_register_approve_email, $lang_register_activated_email, $lang_register_user_login;
global $lang_register_php, $lang_register_confirm_email, $lang_continue, $lang_register_approve_email, $lang_register_activated_email, $lang_register_user_login, $b_day;
//agelock end
find (~ line 250):
if ($password != $password_again) $error .= '<li>' . $lang_register_php['err_password_mismatch'];
add below:
//agelock - begin
if ($CONFIG['bday_required'])
{
list($month, $day, $year) = split('[/]', $b_day);
if (!(checkdate($month,$day,$year)))
{
$error .= '<li>' . $lang_register_php['err_b_day_incorrect_format'];
}
}
//agelock - end
save
find (~ line 293):
$sql = "INSERT INTO {$CONFIG['TABLE_USERS']} ".
"(user_regdate, user_active, user_actkey, user_name, user_password, user_email, user_profile1, user_profile2, user_profile3, user_profile4, user_profile5, user_profile6) ".
"VALUES (NOW(), '$active', '$act_key', '" . addslashes($user_name) . "', '" . addslashes($encpassword) . "', '" . addslashes($email) . "', '$profile1', '$profile2', '$profile3', '$profile4', '$profile5', '$profile6')";
replace with:
/*
agelock - begin
$sql = "INSERT INTO {$CONFIG['TABLE_USERS']} ".
"(user_regdate, user_active, user_actkey, user_name, user_password, user_email, user_profile1, user_profile2, user_profile3, user_profile4, user_profile5, user_profile6) ".
"VALUES (NOW(), '$active', '$act_key', '" . addslashes($user_name) . "', '" . addslashes($encpassword) . "', '" . addslashes($email) . "', '$profile1', '$profile2', '$profile3', '$profile4', '$profile5', '$profile6')";
*/
$sql = "INSERT INTO {$CONFIG['TABLE_USERS']} ".
"(user_regdate, user_active, user_actkey, user_name, user_password, user_email, user_profile1, user_profile2, user_profile3, user_profile4, user_profile5, user_profile6,user_bday) ".
"VALUES (NOW(), '$active', '$act_key', '" . addslashes($user_name) . "', '" . addslashes($encpassword) . "', '" . addslashes($email) . "', '$profile1', '$profile2', '$profile3', '$profile4', '$profile5', '$profile6','$b_day')";
//agelock - end
save
*************** REGISTER.PHP EDITS – END *****************
*
*************** ENGLISH.PHP EDITS – BEGIN *****************
in english.php
find $lang_register_php
then find 'email' => 'Email',
(around line1509)
insert below 'email' => 'Email',
'b_day' => 'Birth date mm/dd/yyyy',
'err_b_day_incorrect_format' => 'You must enter a correctly formatted birth date date for access to this site.',
Save
Find (~ line 646):
array('Browsable batch-add interface', 'browse_batch_add', 1, 'f=index.htm&as=admin_general_browsable_batch_add&ae=admin_general_browsable_batch_add_end'),
//cpg1.4
add below:
//agelock - begin
array('Enable category age locking', 'bday_required', 1, 'f=index.htm&as=admin_general_agelock_add&ae=admin_general_agelock_add_end'),
//agelock - end
save
find (~ line 566): $lang_catmgr_php
then find (~ line 579)
'cat_desc' => 'Category description',
add below:
'agelock_method' => 'Age lock method o=over age, u=under age',
'agelock_age' => 'Age to be locked',
save
*************** ENGLISH.PHP EDITS – END *****************
*
*************** CATMGR.PHP EDITS – BEGIN *****************
in catmgr.php
find (~ line 296):
$result = cpg_db_query("SELECT cid, name, parent, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
replace with
$result = cpg_db_query("SELECT cid, name, parent, description, thumb, agelock_method, agelock_age FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cid' LIMIT 1");
save
(~ line 458) find:
<textarea name="description" rows="5" cols="40" style="width: 100%;" class="textinput">{$current_category['description']}</textarea>
</td>
</tr>
(be very certain you place this in the proper location!) add below:
<tr>
<td width="40%" class="tableb">
{$lang_catmgr_php['agelock_method']}
</td>
<td width="60%" class="tableb" valign="top">
<input type="text" style="width: 100%" name="agelock_method" value="{$current_category['agelock_method']}" class="textinput" />
</td>
</tr>
<tr>
<td width="40%" class="tableb">
{$lang_catmgr_php['agelock_age']}
</td>
<td width="60%" class="tableb" valign="top">
<input type="text" style="width: 100%" name="agelock_age" value="{$current_category['agelock_age']}" class="textinput" />
</td>
</tr>
save
find (~ line 315):
$description = addslashes($_POST['description']);
add below:
$agelock_method = trim($_POST['agelock_method']);
$agelock_age = (int)$_POST['agelock_age'];
save
find (~ line 321)
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
replace with:
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='$parent', name='$name', description='$description', thumb='$thumb', agelock_method='$agelock_method', agelock_age='$agelock_age' WHERE cid = '$cid' LIMIT 1");
save
find (~ line 323)
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb' WHERE cid = '$cid' LIMIT 1");
replace with:
cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name='$name', description='$description', thumb='$thumb', agelock_method='$agelock_method', agelock_age='$agelock_age' WHERE cid = '$cid' LIMIT 1");
save
*************** CATMGR.PHP EDITS – BEGIN *****************
*
*************** UDB_BASE.INC.PHP EDITS – BEGIN *****************
bridge\udb_base.inc.php
find (~ line 56):$sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, ug.{$f['usertbl_group_id']} AS group_id ".
replace with:$sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, u.user_bday AS bday, ug.{$f['usertbl_group_id']} AS group_id ".
save
find (~ line 60): $sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, u.{$f['usertbl_group_id']}+100 AS group_id ".
replace with: $sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, u.user_bday AS bday, u.{$f['usertbl_group_id']}+100 AS group_id ".
save
find (~ line 113):define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
add below:define('USER_BDAY', ($USER_DATA['user_bday']));
save
find (~ line 146):$USER_DATA['user_name'] = $row['username'];
add below:if ($row['user_bday']=='')
{
$USER_DATA['user_bday']= date();
}
else
{
$USER_DATA['user_bday']= $row['user_bday'];
}
save
*************** UDB_BASE.INC.PHP EDITS – END *****************
*
*************** INDEX.PHP EDITS – BEGIN *****************
Edit index.php
The line numbers are very approximate as I did some code rearrangement to facilitate readability.
Find (~ line 904)
*/?>
Insert above the “?>” and below the */:
function age_lock($agelock_method, $agelock_age)
{
if (($agelock_method=='u') || ($agelock_method=='o'))
{
$_month=date("m");
$_year=date("Y");
$_day=date("d");
$bday = explode("/",$USER_DATA['user_bday']);
if($_month>$bday[0] || ($bday[0]==$_month && $_day>=$bday[1]) )
{
$i = $_year - $bday[2];
}
else
{
$i = $_year - $bday[2] - 1;
}
if ($agelock_method=='o')
{
if($i < $agelock_age)
{ //Check to see if too young
return true;
}
else
{
return false;
}
}
if ($agelock_method=='u')
{
if($i >= $agelock_age)
{ //check to see if there too old
return true;
}
else
{return false;}
}
}
else{return false;}
}//end age_lock
save
Find (~ line 145):
$result = cpg_db_query("SELECT cid, name, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' ORDER BY $cat_sort_order");
Replace with:
//agelock - begin
//$result = cpg_db_query("SELECT cid, name, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' ORDER BY $cat_sort_order");
$result = cpg_db_query("SELECT cid, name, description, thumb, agelock_method, agelock_age FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' ORDER BY $cat_sort_order");
//agelock – end
Find (~ line number 149):
if (mysql_num_rows($result) > 0)
{
$rowset = cpg_db_fetch_rowset($result);
foreach ($rowset as $subcat)
Add below:
//agelock - begin
$age_lock_not=false;
if ($CONFIG['bday_required'])
{
$age_lock_not=age_lock($subcat['agelock_method'], $subcat['agelock_age']);
}
if (!($age_lock_not))
{
//agelock end
Save
Find :
if ($level > 1)
{
get_subcat_data($subcat['cid'], $cat_data, $album_set_array, $level -1, $ident . "</td><td><img src=\"images/spacer.gif\" width=\"20\" height=\"1\" border=\"0\" alt=\"\" /></td><td>");
}
}
}
}
Replace with:
if ($level > 1)
{
get_subcat_data($subcat['cid'], $cat_data, $album_set_array, $level -1, $ident . "</td><td><img src=\"images/spacer.gif\" width=\"20\" height=\"1\" border=\"0\" alt=\"\" /></td><td>");
}
//agelock - begin
}
//agelock - end
}//end for
}
}//end method
Save
*************** INDEX.PHP EDITS – END *****************