Index: validateage.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/validateage/validateage.install,v
retrieving revision 1.1
diff -u -p -r1.1 validateage.install
--- validateage.install	21 Jan 2009 01:19:16 -0000	1.1
+++ validateage.install	6 Jul 2010 00:40:11 -0000
@@ -56,6 +56,23 @@ function validateage_schema() {
  */
 function validateage_uninstall() {
   drupal_uninstall_schema('validateage');
+  _variable_del_all('validateage_');
+}
+
+/**
+ * Utility function that is an altered version of variable_del, it will delete
+ * a set of variables set by a module.
+ *
+ * @global <type> $conf
+ * @param string $name The variables' namespace for which to delete
+ */
+function _variable_del_all($name) {
+  global $conf;
+
+  db_query("DELETE FROM {variable} WHERE name LIKE '%s%%'", $name);
+  cache_clear_all('variables', 'cache');
+
+  unset($conf[$name]);
 }
 
 /**
Index: validateage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/validateage/validateage.module,v
retrieving revision 1.6.2.5
diff -u -p -r1.6.2.5 validateage.module
--- validateage.module	1 Feb 2010 23:06:33 -0000	1.6.2.5
+++ validateage.module	6 Jul 2010 00:40:11 -0000
@@ -4,20 +4,18 @@
 /**
  * @file
  * This is the main module file
- * 
+ *
  * This module requires that a user's stated age during registration is at least that set by the administrator.
  */
 
 /**
  * Implementation of hook_init()
  *
- * If validate age for all pages is selected then we check cookie 
+ * If validate age for all pages is selected then we check cookie
  *
  */
- //  
 function validateage_init() {
   if (variable_get('validateage_age_pages', 0) && arg(0)!='validateage' && !variable_get('site_offline', 0)) {
-    
     if ($_COOKIE['validateage']>variable_get('validateage_age', '18')) {
       return;
     }
@@ -26,15 +24,14 @@ function validateage_init() {
       foreach ($items as $bot) {
         if (strpos($_SERVER['HTTP_USER_AGENT'], $bot)) {
           if (variable_get('validateage_age_search_engines_log', 0)) {
-            watchdog('validateage', t('!bot bot detected', array('!bot' => $bot))); 
+            watchdog('validateage', t('!bot bot detected', array('!bot' => $bot)));
           }
           return;
         }
       }
     }
-
-   // not a bot or a validated user
-   drupal_goto('validateage', drupal_get_destination());
+    // not a bot or a validated user
+    drupal_goto('validateage', drupal_get_destination());
   }
   return;
 }
@@ -70,31 +67,72 @@ function validateage_perm() {
 
 /*
  * Implementation of hook_menu()
- */
+*/
 function validateage_menu() {
+  $path = drupal_get_path('module', 'validateage');
   $items = array();
   $items['admin/user/validateage'] = array(
-      'title' => t('Minimum Registration Age'),
-      'description' => t('Set the minimum age for user registration'),
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('validateage_admin'),
-      'access arguments' => array('administer age validation'),
-      'type' => MENU_NORMAL_ITEM,
-     );
+    'title' => t('Minimum Registration Age'),
+    'description' => t('Set the minimum age for user registration'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('validateage_admin'),
+    'access arguments' => array('administer age validation'),
+    'type' => MENU_NORMAL_ITEM,
+  );
   $items['validateage'] = array(
-      'title' => t('Please Enter Your Age'),
-      'description' => t('!site is an age restricted site', array('!site' => variable_get('site_name', ''))),
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('validateage_age_form'),
-      'access arguments' => array('access content'),
-      'type' => MENU_CALLBACK,
-     );
+    'title' => variable_get('validateage_page_title', t('Please Enter Your Age')),
+    'description' => t('!site is an age restricted site', array('!site' => variable_get('site_name', ''))),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('validateage_age_form'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['validateage/autocomplete-node'] = array(
+    'page callback' => 'validateage_autocomplete_node',
+    'type' => MENU_CALLBACK,
+    'file' => 'validateage_autocomplete_node.inc',
+    'file path' => $path,
+    'access arguments' => array('administer age validation'),
+  );
+  $items['admin/user/validateage/callback/%'] = array(
+    'type' => MENU_CALLBACK,
+    'page callback' => 'validateage_buttonlabels_callback',
+    'page arguments' => array(4),
+    'access callback' => TRUE,
+  );
   return $items;
 }
+/**
+ * Callback function for use with the ahah form elements menu callbacks
+ *
+ * @param string $arg form wrapper to process
+ */
+function validateage_buttonlabels_callback($arg) {
+  $form_state = array('storage' => NULL, 'submitted' => FALSE);
+  $form_build_id = $_POST['form_build_id'];
+  $form = form_get_cache($form_build_id, $form_state);
+
+  $args = $form['#parameters'];
+  $form_id = array_shift($args);
+  $form_state['post'] = $form['#post'] = $_POST;
+  $form['#programmed'] = $form['#redirect'] = FALSE;
+
+  drupal_process_form($form_id, $form, $form_state);
+  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
+
+  $textfields = $form[$arg];
+  // clear out the messages so we don't see multiple on final submission
+  drupal_get_messages();
+  $output = drupal_render($textfields);
+
+  // Final rendering callback.
+  print drupal_json(array('status' => TRUE, 'data' => $output));
+  exit();
+}
 
 /*
  * Implementation of hook_user
- */
+*/
 function validateage_user($op, &$edit, &$account, $category = NULL) {
   global $user;
   if (variable_get('validateage_age_registration', 0)) {
@@ -159,7 +197,7 @@ function validateage_user($op, &$edit, &
         elseif (_validateage_check_birthday($birthday)) {
           drupal_set_message(t('Happy Birthday!'));
         }
-      break;
+        break;
     }
   }
 }
@@ -167,8 +205,14 @@ function validateage_user($op, &$edit, &
 /*
  * This function defines the settings on the admin page
  */
-function validateage_admin() {
-  $form['validateage_age'] = array(
+function validateage_admin(&$form_state) {
+  drupal_add_js('misc/autocomplete.js'); // load up the autocomplete.js since the ahah call later may not load it
+  /* General Settings */
+  $form['general'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('General Settings')
+  );
+  $form['general']['validateage_age'] = array(
     '#type' => 'textfield',
     '#title' => t('Age'),
     '#default_value' => variable_get('validateage_age', '18'),
@@ -177,6 +221,21 @@ function validateage_admin() {
     '#description' => t('The minimum age required to register for the site.'),
     '#element_validate' => array('validateage_is_number'),
   );
+  $form['general']['validateage_age_message'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Validate Age Message'),
+    '#default_value' => variable_get('validateage_age_message', 'You must be at least @age to enter @site'),
+    '#description' => t('The message displayed if the user is underage.'),
+    '#size' => 120,
+  );
+  $form['general']['validateage_age_years'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Cookie Expiry'),
+    '#default_value' => variable_get('validateage_age_years', 10),
+    '#description' => t('The number of years until expiry of cookie for age validation on pages'),
+  );
+
+  /* Registration Options */
   $form['registration'] = array(
     '#type' => 'fieldset',
     '#title' => t('Registration Options')
@@ -187,20 +246,19 @@ function validateage_admin() {
     '#default_value' => variable_get('validateage_age_registration', 0),
     '#description' => t('Enable age validation for users on registration'),
   );
-
-  // allow admins to choose whether to use an existing profile module field for birthday 
+  // allow admins to choose whether to use an existing profile module field for birthday
   // or have it stored by validateage
   if (module_exists('profile')) {
     // Get fields from the profile.module of the type 'date'.
     $options = array();
     $result = db_query("SELECT fid, name FROM {profile_fields} WHERE type = 'date'");
-  
+
     while ($field = db_fetch_object($result)) {
       $options[$field->fid] = $field->name;
     }
-  
+
     $options = array('independent input field') + $options;
-  
+
     $form['registration']['validateage_field_id'] = array(
       '#type' => 'select',
       '#title' => t('Date of birth source'),
@@ -218,6 +276,7 @@ function validateage_admin() {
     '#description' => t('The message displayed if the user is underage.'),
   );
 
+  /* Page Options */
   $form['pages'] = array(
     '#type' => 'fieldset',
     '#title' => t('Page Options')
@@ -228,19 +287,75 @@ function validateage_admin() {
     '#default_value' => variable_get('validateage_age_pages', 0),
     '#description' => t('Enable age validation for any page on this site'),
   );
-  $form['pages']['validateage_age_message'] = array(
+  $form['pages']['validateage_page_title'] = array(
     '#type' => 'textfield',
-    '#title' => t('Validate Age Message'),
-    '#default_value' => variable_get('validateage_age_message', 'You must be at least @age to enter @site'),
-    '#description' => t('The message displayed if the user is underage.'),
-    '#size' => 120,
+    '#title' => t('Page Title'),
+    '#description' => t('The title to use for the age validation page, if unspecified the default title of "%s" will be used.', array('%s' => t('Please Enter Your Age'))),
+    '#default_value' => variable_get('validateage_page_title', ''),
   );
-  $form['pages']['validateage_age_years'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Cookie Expiry'),
-    '#default_value' => variable_get('validateage_age_years', 10),
-    '#description' => t('The number of years until expiry of cookie for age validation on pages'),
+  $form['pages']['validateage_node_use'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use a node for the age validation page'),
+    '#default_value' => variable_get('validateage_node_use', 0),
+    '#description' => t('If checked you can specify a node to show on the age validation page.'),
+    '#ahah' => array(
+      'path' => 'admin/user/validateage/callback/nodedetails',
+      'wrapper' => 'nodedetails',
+      'effect' => 'fade',
+    )
+  );
+  $form['pages']['nodedetails'] = array(
+    '#prefix' => '<div id="nodedetails">',
+    '#suffix' => '</div>',
+    '#type' => 'fieldset',
+    '#title' => t('Node Details'),
+    '#attributes' => (variable_get('validateage_node_use', 0) === 1) ? array() : array('style' => 'display:none;')
+  );
+  if (variable_get('validateage_node_use', 0) === 1) {
+    $temp = $form['pages']['nodedetails'];
+    $temp['validateage_node_nid'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Node to show in the age validation page'),
+      '#autocomplete_path' => 'validateage/autocomplete-node',
+      '#description' => t('Type the title or the node ID of the node you would like to use in the age validation page and select it from the dropdown.'),
+      '#default_value' => (is_numeric(variable_get('validateage_node_nid', ''))) ? _validateage_nid2str(variable_get('validateage_node_nid', '')) : '',
+    );
+    if ($form_state['values']) $form['nodedetails'] = $temp;
+    else $form['pages']['nodedetails'] = $temp;
+  }
+  $form['pages']['validateage_buttons_use'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use buttons for the age validation'),
+    '#default_value' => variable_get('validateage_buttons_use', 0),
+    '#description' => t('If checked user will see two buttons ("Agree" & "Disagree") instead of a date widget.  Note that the true birthdate of the user will not be collected when using this option.'),
+    '#ahah' => array(
+      'path' => 'admin/user/validateage/callback/buttonlabels',
+      'wrapper' => 'buttonlabels',
+      'effect' => 'fade',
+    )
+  );
+  $form['pages']['buttonlabels'] = array(
+    '#prefix' => '<div id="buttonlabels">',
+    '#suffix' => '</div>',
+    '#type' => 'fieldset',
+    '#title' => t('Button Labels'),
+    '#attributes' => (variable_get('validateage_buttons_use', 0) === 1) ? array() : array('style' => 'display:none;')
   );
+  if (variable_get('validateage_buttons_use', 0) === 1) {
+    $temp = $form['pages']['buttonlabels'];
+    $temp['validateage_buttons_text_agree'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Text to use for the "Agree" button'),
+      '#default_value' => variable_get('validate_age_buttons_text_agree', t('Agree'))
+    );
+    $temp['validateage_buttons_text_disagree'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Text to use for the "Disagree" button'),
+      '#default_value' => variable_get('validate_age_buttons_text_disagree', t('Disagree'))
+    );
+    if ($form_state['values']) $form['buttonlabels'] = $temp;
+    else $form['pages']['buttonlabels'] = $temp;
+  }
   $form['pages']['validateage_age_search_engines'] = array(
     '#type' => 'checkbox',
     '#title' => t('Allow Search Engines'),
@@ -260,10 +375,22 @@ function validateage_admin() {
     '#default_value' => variable_get('validateage_age_search_engines_log', 0),
     '#description' => t('Log search engine activity. Note: only bother ticking this if you allow search engines past the page validation.'),
   );
+  // add in an extra submission function to do some string alterations
+  $form['#submit'][] = 'validateage_admin_submit';
   return system_settings_form($form);
 }
 
 /**
+ * Runs additional processing on the form values upon submission
+ *
+ * @param array $form original form array
+ * @param array $form_state holds the values from the form upon submission
+ */
+function validateage_admin_submit($form, &$form_state) {
+  if (isset($form_state['values']['validateage_node_nid'])) $form_state['values']['validateage_node_nid'] = _validateage_str2nid($form_state['values']['validateage_node_nid']);
+}
+
+/**
  *
  */
 function validateage_admin_profile_visibility(&$form) {
@@ -315,7 +442,7 @@ function validateage_birthday_update($ui
   db_query($query, $args);
 }
 
-/*
+/**
  * This function gets a user's age
  */
 function _validateage_get_age($birthday) {
@@ -349,15 +476,45 @@ function _validateage_check_birthday($bi
  * Content of the age validation page.  Note that there is a page.tpl file to accompany this in order to avoid showing content to unvalidated users.  See README.txt
  */
 function validateage_age_form() {
-  $form['validateage_dob'] = array(
-    '#type' => 'date',
-    '#title' => t('Date of Birth'),
-    '#description' => t(variable_get('validateage_age_message', 'You must be at least @age to enter @site'), array('@age' => variable_get('validateage_age', 18), '@site' => variable_get('sitename', ''))),
-  );
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => 'Submit'
-  );
+  // if a node is going to be used in the page, load it up and display here
+  if (variable_get('validateage_node_use', 0) === 1) {
+    $form['node'] = array(
+      '#type' => 'markup',
+      '#value' => is_numeric(variable_get('validateage_node_nid', '')) ? node_view(node_load(1)) : ''
+    );
+  }
+  // if buttons are not being used show the standard date widget
+  if (variable_get('validateage_buttons_use', 0) === 0) {
+    $form['validateage_dob'] = array(
+      '#type' => 'date',
+      '#title' => t('Date of Birth'),
+      '#description' => t(variable_get('validateage_age_message', 'You must be at least @age to enter @site'), array('@age' => variable_get('validateage_age', 18), '@site' => variable_get('site_name', ''))),
+    );
+    $form['submit'] = array(
+      '#type' => 'submit',
+      '#value' => t('Submit')
+    );
+  }
+  // use agree/disagree buttons instead of a widget
+  else {
+    $form['validateage_dob'] = array(
+      '#type' => 'date',
+      '#title' => t('Date of Birth'),
+      '#default_value' => array('year' => date("Y") - variable_get('validateage_age', 18), 'month' => date("n"), 'day' => date("j") - 1),
+      '#description' => t(variable_get('validateage_age_message', 'You must be at least @age to enter @site'), array('@age' => variable_get('validateage_age', 18), '@site' => variable_get('sitename', ''))),
+      '#attributes' => array('style' => 'display:none;'),
+      '#prefix' => '<div style="display:none;">',
+      '#suffix' => '</div>'
+    );
+    $form['submit'] = array(
+      '#type' => 'submit',
+      '#value' => variable_get('validate_age_buttons_text_agree', t('Agree'))
+    );
+    $form['disagree'] = array(
+      '#type' => 'submit',
+      '#value' => variable_get('validate_age_buttons_text_disagree', t('Disagree'))
+    );
+  }
   return $form;
 }
 
@@ -385,8 +542,8 @@ function validateage_age_form_submit($fo
  * This function returns an array of the default search engine bots
  */
 function validateage_get_botlist() {
-  $botlist = array(   
-    "Teoma",                   
+  $botlist = array(
+    "Teoma",
     "alexa",
     "froogle",
     "inktomi",
@@ -413,3 +570,31 @@ function validateage_get_botlist() {
   );
   return $botlist;
 }
+
+/**
+ * Utility function to convert the string in node fields into a simple node id
+ *
+ * @param string $str
+ *   (required) the string to process
+ *
+ * @return integer $nid
+ *   the node's id
+ */
+function _validateage_str2nid($str) {
+  return $nid = substr($str, (strrpos($str, '[') + 1), -1);
+}
+
+/**
+ * Utility function to convert a node id into the format of 'Title [nid]'
+ *
+ * @param integer $nid
+ *   (required) the nid to process
+ *
+ * @return string $str
+ *   the formatted string in form of 'Title [nid]'
+ */
+function _validateage_nid2str($nid) {
+  $arr = db_fetch_array(db_query("SELECT title FROM {node} WHERE nid = %d LIMIT 1", $nid));
+  $title = $arr['title'];
+  return $str = $title . ' [' . $nid . ']';
+}
Index: validateage_autocomplete_node.inc
===================================================================
RCS file: validateage_autocomplete_node.inc
diff -N validateage_autocomplete_node.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ validateage_autocomplete_node.inc	6 Jul 2010 00:40:11 -0000
@@ -0,0 +1,16 @@
+<?php
+// $Id: $
+/**
+ * Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing nodes.
+ */
+function validateage_autocomplete_node($string) {
+  $matches = array();
+  $result = db_query(db_rewrite_sql("SELECT nid, title FROM {node} WHERE status = 1 AND nid LIKE '%s%%' OR LOWER(title) LIKE '%%%s%%'"), strtolower($string), strtolower($string), 0, 10);
+  while ($node = db_fetch_object($result)) {
+    $title = check_plain($node->title);
+    $nid = $node->nid;
+    $display = $title . ' [' . $nid . ']';
+    $matches[$display] = $display;
+  }
+  drupal_json($matches);
+}
