Index: coppa.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coppa/coppa.admin.inc,v
retrieving revision 1.1
diff -u -p -r1.1 coppa.admin.inc
--- coppa.admin.inc	9 Feb 2009 19:12:26 -0000	1.1
+++ coppa.admin.inc	4 Mar 2009 21:54:45 -0000
@@ -49,11 +49,16 @@ function coppa_info() {
  */
 function coppa_sign() {
   global $user;
+
+  $form = array(
+    '#theme' => 'coppa_sign',
+  );
+
   $result = db_query("SELECT DISTINCT u.uid, u.name, c.status, pv.value, pv.fid 
-                      FROM {users} u, {coppa} c, {profile_fields} pf, profile_values pv 
+                      FROM {users} u, {coppa} c, {profile_fields} pf, {profile_values} pv 
                       WHERE c.cid=u.uid AND pv.uid = u.uid AND pf.fid = pv.fid AND pf.name = 'profile_dob' AND c.pid = %d", $user->uid);
 
-  $form['children'] = array('#tree' => true);
+  $form['children'] = array('#tree' => TRUE);
 
   $weight = 1;
   while ($r = db_fetch_object($result)) {
@@ -96,9 +101,9 @@ function coppa_sign() {
 /**
  * Submit handler for coppa_sign.
  */
-function coppa_sign_submit($form_id, $edit) {
+function coppa_sign_submit($form, &$form_state) {
   global $user;
-  foreach ($edit['children'] as $cid => $status) {
+  foreach ($form_state['values']['children'] as $cid => $status) {
     if ($status['status'] == 1) {
       $result = db_query("SELECT status FROM {coppa} WHERE pid= %d AND cid= %d", $user->pid, $cid);
       $r = db_fetch_object($result);
@@ -112,30 +117,30 @@ function coppa_sign_submit($form_id, $ed
 /**
  * Theme the COPPA sign page/form.
  */
-function theme_coppa_sign($edit) {
+function theme_coppa_sign($form) {
   $rows = array();
-  if (!isset($edit['children'])) {
-    $output = $edit['message']['#value'];
+  if (!isset($form['children'])) {
+    $output = $form['message']['#value'];
   }
   else {
     $header = array(t('User History'), t('Date of Birth'), t('COPPA Status'));
   
-    foreach (element_children($edit['children']) as $uid) {
+    foreach (element_children($form['children']) as $uid) {
       unset($row);
-      $row[] = drupal_render($edit['children'][$uid]['tracker']);
-      $row[] = drupal_render($edit['children'][$uid]['dob']);
-      unset($edit['children'][$uid]['status']['#title']);
-      $row[] = drupal_render($edit['children'][$uid]['status']);
+      $row[] = drupal_render($form['children'][$uid]['tracker']);
+      $row[] = drupal_render($form['children'][$uid]['dob']);
+      unset($form['children'][$uid]['status']['#title']);
+      $row[] = drupal_render($form['children'][$uid]['status']);
       $rows[] = $row;
     }
   
     $output = theme('table', $header, $rows, array('id' => 'coppa-sign'));
     $output .= '<br />';
-    $output .= drupal_render($edit['submit']);
+    $output .= drupal_render($form['submit']);
 
-    $output .= drupal_render($edit['form_id']);
+    $output .= drupal_render($form['form_id']);
 
-    $output .= drupal_render($edit['form_token']);
+    $output .= drupal_render($form['form_token']);
   }
   return $output;
 
@@ -147,8 +152,8 @@ function theme_coppa_sign($edit) {
 function coppa_admin_settings() {
   $roles = user_roles(TRUE);
   
-  $selected = variable_get('coppa_roles', 0);
-  $selected = unserialize($selected);
+  $selected = variable_get('coppa_roles', 'a:0:{}');
+  // $selected = unserialize($selected);
   
   $form['coppa_roles'] = array(
     '#type' => 'select',
@@ -185,18 +190,14 @@ function coppa_admin_settings() {
 }
 
 /**
- * Form submission handler for coppa_admin_settings
- */
-function coppa_admin_settings_submit($form_id, $edit) {
-  $coppa_roles = $edit['coppa_roles'];
-  variable_set('coppa_roles', serialize($coppa_roles));
-}
-
-/**
  * Form for admin/coppa/set-parents
  */
 function coppa_set_parents() {
-  $form['rows'] = array('#tree' => true);
+  $form = array(
+    '#theme' => 'coppa_set_parents',
+  );
+
+  $form['rows'] = array('#tree' => TRUE);
   
   for ($i = 0; $i < COPPA_ADD_ELEMENTS; $i++) {
     $form['rows'][$i]['parent'] = array(
@@ -223,8 +224,8 @@ function coppa_set_parents() {
 /**
  * Form validation for coppa_set_parents_submit
  */
-function coppa_set_parents_validate($form_id, $form) {
-  foreach ($form['rows'] as $rid => $row) {
+function coppa_set_parents_validate($form, &$form_state) {
+  foreach ($form_state['values']['rows'] as $rid => $row) {
     if (!empty($row['parent'])) {
       if (!empty($row['child'])) {
         // make sure both are valid usernames (is there a better way than user_load?)
@@ -275,12 +276,12 @@ function coppa_set_parents_validate($for
 /**
  * Form submission handler for coppa/set-parents
  */
-function coppa_set_parents_submit($form_id, $form) {
+function coppa_set_parents_submit($form, &$form_state) {
   
   $inserted = array();  // keep track of what we've added to avoid double inserts (we didn't check for that in validate)
   
   // form has gone through validation
-  foreach ($form['rows'] as $rid => $row) {
+  foreach ($form_state['values']['rows'] as $rid => $row) {
     if (!empty($row['child']) && !empty($row['parent'])) {
       $child = user_load(array('name' => $row['child']));
       $parent = user_load(array('name' => $row['parent']));
@@ -304,30 +305,30 @@ function coppa_set_parents_submit($form_
 /**
  * Theme for coppa_set_parents to display in tabular format
  */
-function theme_coppa_set_parents($edit) {
+function theme_coppa_set_parents($form) {
   $rows = array();
   
   $header = array(t('Parent'), t('Child'));
   
-  foreach (element_children($edit['rows']) as $r) {
+  foreach (element_children($form['rows']) as $r) {
     unset($row);
 
-    unset($edit['rows'][$r]['parent']['#title']);
-    $row[] = drupal_render($edit['rows'][$r]['parent']);
+    unset($form['rows'][$r]['parent']['#title']);
+    $row[] = drupal_render($form['rows'][$r]['parent']);
 
-    unset($edit['rows'][$r]['child']['#title']);
-    $row[] = drupal_render($edit['rows'][$r]['child']);
+    unset($form['rows'][$r]['child']['#title']);
+    $row[] = drupal_render($form['rows'][$r]['child']);
 
     $rows[] = $row;
   }
   
   $output = theme('table', $header, $rows, array('id' => 'coppa-set-parents'));
   $output .= '<br />';
-  $output .= drupal_render($edit['submit']);
+  $output .= drupal_render($form['submit']);
 
-  $output .= drupal_render($edit['form_id']);
+  $output .= drupal_render($form['form_id']);
 
-  $output .= drupal_render($edit['form_token']);
+  $output .= drupal_render($form['form_token']);
 
   return $output;
 }
@@ -336,24 +337,26 @@ function theme_coppa_set_parents($edit) 
  * form handler for coppa/manage-relationships
  */
 function coppa_manage_relationships() {
-  $form = array();
+  $form = array(
+    '#theme' => 'coppa_manage_relationships',
+  );
   $date_format = 'n j Y'; // m/d/y  
   $result = db_query("SELECT cu.uid as cid, cu.name as cname, pu.uid as pid, pu.name as pname, pv.value as dob, c.status 
                       FROM {users} cu
                       JOIN {coppa} c ON cu.uid = c.cid
                       JOIN {users} pu ON pu.uid = c.pid 
-                      LEFT JOIN profile_values pv ON pv.uid = c.cid 
-                      LEFT JOIN profile_fields pf ON pv.fid = pf.fid");
+                      LEFT JOIN {profile_values} pv ON pv.uid = c.cid 
+                      LEFT JOIN {profile_fields} pf ON pv.fid = pf.fid");
     
 
   while ($r = db_fetch_object($result)) {
     $r->dob = unserialize($r->dob);
 
     if (!isset($form[$r->pid])) {
-      $form[$r->pid] = array('#tree' => true);
+      $form[$r->pid] = array('#tree' => TRUE);
     }
     if (!isset($form[$r->pid][$r->cid])) {
-      $form[$r->pid][$r->cid] = array('#tree' => true);
+      $form[$r->pid][$r->cid] = array('#tree' => TRUE);
     }
     
     $form[$r->pid][$r->cid]['parent'] = array('#type' => 'markup', '#value' => l($r->pname, 'user/'. $r->pid));
@@ -396,9 +399,9 @@ function coppa_manage_relationships() {
 /**
  * form submission routine to remove user relationships
  */
-function coppa_manage_relationships_submit($form_id, $form) {
+function coppa_manage_relationships_submit($form, &$form_state) {
   
-  foreach ($form as $pid => $child) {
+  foreach ($form_state['values'] as $pid => $child) {
     if (is_numeric($pid)) {
       foreach ($child as $cid => $remove) {
         if ($remove['remove']) {
@@ -412,29 +415,29 @@ function coppa_manage_relationships_subm
 /**
  * theming function for coppa_manage_relationships
 */
-function theme_coppa_manage_relationships($edit) {
+function theme_coppa_manage_relationships($form) {
   $rows = array();
   
   $header = array(t('Parent'), t('Child'), t('Date of Birth'), t('COPPA Status'), t('Delete Relationship'));
 
-  foreach (element_children($edit) as $parent) {
-    foreach (element_children($edit[$parent]) as $child) {
+  foreach (element_children($form) as $parent) {
+    foreach (element_children($form[$parent]) as $child) {
       unset($row);
-      $row[] = drupal_render($edit[$parent][$child]['parent']);
-      $row[] = drupal_render($edit[$parent][$child]['child']);
-      $row[] = drupal_render($edit[$parent][$child]['dob']);
-      $row[] = drupal_render($edit[$parent][$child]['status']);
-      $row[] = drupal_render($edit[$parent][$child]['remove']);
+      $row[] = drupal_render($form[$parent][$child]['parent']);
+      $row[] = drupal_render($form[$parent][$child]['child']);
+      $row[] = drupal_render($form[$parent][$child]['dob']);
+      $row[] = drupal_render($form[$parent][$child]['status']);
+      $row[] = drupal_render($form[$parent][$child]['remove']);
       $rows[] = $row;
     }
   }
 
   $output = theme('table', $header, $rows, array('id' => 'coppa-manage-relationships'));
   $output .= '<br />';
-  $output .= drupal_render($edit['submit']);
+  $output .= drupal_render($form['submit']);
 
-  $output .= drupal_render($edit['form_id']);
+  $output .= drupal_render($form['form_id']);
 
-  $output .= drupal_render($edit['form_token']);
+  $output .= drupal_render($form['form_token']);
   return $output;  
 }
Index: coppa.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coppa/coppa.module,v
retrieving revision 1.5
diff -u -p -r1.5 coppa.module
--- coppa.module	9 Feb 2009 19:12:26 -0000	1.5
+++ coppa.module	4 Mar 2009 21:54:45 -0000
@@ -18,6 +18,13 @@ function coppa_help($path, $arg) {
 }
 
 /**
+ * Implementation of hook_perm()
+ **/
+function coppa_perm() {
+  return array('can sign coppa compliance');
+}
+
+/**
  * Implementation of hook_menu().
  */
 function coppa_menu() {
@@ -69,7 +76,7 @@ function coppa_menu() {
     'title' => 'Sign COPPA compliance',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('coppa_sign'),
-    'access arguments' => array('access content'),
+    'access arguments' => array('can sign coppa compliance'),
     'file' => 'coppa.admin.inc',
   );
 
@@ -109,14 +116,14 @@ function coppa_user($op, &$edit, &$accou
 }
 
 /**
- * returns true if the user requires coppa compliance to login (or is indeterminate)
- * returns false otherwise
+ * returns TRUE if the user requires coppa compliance to login (or is indeterminate)
+ * returns FALSE otherwise
  */
 function coppa_needed($uid) {
   $date_format = 'n j Y'; // m/d/y
   if (!empty($uid)) {
     $coppa_roles = variable_get('coppa_roles', 0);
-    $coppa_roles = unserialize($coppa_roles);
+    // $coppa_roles = unserialize($coppa_roles);
 
     if (!is_array($coppa_roles)) {
       $coppa_roles = array();
@@ -128,13 +135,13 @@ function coppa_needed($uid) {
     $user_coppa = array_intersect($user_roles, $coppa_roles); // compute the intersection of the user's roles and coppa roles
 
     if (count($user_coppa) == 0) {
-      return false; // no coppa roles set or no coppa roles for this user
+      return FALSE; // no coppa roles set or no coppa roles for this user
     }
     else {  
       $dob = coppa_get_dob($uid);
       if (empty($dob)) {
         // no dob set (or corrupt) for this user assume coppa required 
-        return true;
+        return TRUE;
       }
       else {
         $temp = date($date_format);            
@@ -149,11 +156,11 @@ function coppa_needed($uid) {
         }
         elseif ((int)$now['year'] - (int)$dob['year'] == COPPA_AGE) {
           if ((int)$now['month'] - (int)$dob['month'] > 0) {  // check month
-            return false;
+            return FALSE;
           }
           else if ((int)$now['month'] - (int)$dob['month'] == 0) {
             if ((int)$now['day'] - (int)$dob['day'] >= 0) {  // check day
-              return false;
+              return FALSE;
             }
             else {
               return !coppa_is_compliant($uid);
@@ -168,28 +175,28 @@ function coppa_needed($uid) {
   }
   else {
     // non-authenticated user
-    return false;
+    return FALSE;
   }
 }
 
 /**
- * returns true if the user is compliant
- * returns false otherwise or if no entry in the coppa table.
+ * returns TRUE if the user is compliant
+ * returns FALSE otherwise or if no entry in the coppa table.
  */
 function coppa_is_compliant($uid) {
   $result = db_query('SELECT status FROM {coppa} WHERE cid = %d', $uid);
   $r = db_fetch_array($result);
   if ($r) {
     if ($r['status'] == 0) {
-      return false;
+      return FALSE;
     }
     else {
-      return true;
+      return TRUE;
     }
   }
   else {
     // no entry in the coppa table for this user
-    return false;
+    return FALSE;
   }  
 }
 
@@ -198,7 +205,7 @@ function coppa_is_compliant($uid) {
  * if a profile_dob entry is not found for this user then an empty array is returned
  */
 function coppa_get_dob($uid) {
-  $result = db_query("SELECT pv.value FROM {profile_values} pv, profile_fields pf, users u WHERE pf.name = 'profile_dob' AND pf.fid = pv.fid AND pv.uid = u.uid AND u.uid = %d", $uid);
+  $result = db_query("SELECT pv.value FROM {profile_values} pv, {profile_fields} pf, {users} u WHERE pf.name = 'profile_dob' AND pf.fid = pv.fid AND pv.uid = u.uid AND u.uid = %d", $uid);
   $r = db_fetch_array($result);
   if ($r) {
     return unserialize($r['value']);
@@ -214,11 +221,15 @@ function coppa_get_dob($uid) {
 function coppa_theme() {
   return array(
     'coppa_sign' => array(
-      'arguments' => array('edit' => NULL),
+      'arguments' => array('form' => NULL),
       'file' => 'coppa.admin.inc',
     ),
     'coppa_set_parents' => array(
-      'arguments' => array('edit' => NULL),
+      'arguments' => array('form' => NULL),
+      'file' => 'coppa.admin.inc',
+    ),
+    'coppa_manage_relationships' => array(
+      'arguments' => array('form' => NULL),
       'file' => 'coppa.admin.inc',
     ),
   );
