Index: legal.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/legal/legal.module,v retrieving revision 1.22 diff -u -p -r1.22 legal.module --- legal.module 8 Aug 2008 22:51:47 -0000 1.22 +++ legal.module 23 Sep 2008 02:03:24 -0000 @@ -13,8 +13,8 @@ function legal_help($path, $arg) { $output .= t('When a user creates an account they are required to accept your Terms & Conditions to complete their registration.'); break; case 'admin/settings/legal': - $output .= t('Display a Terms & Conditions statement on the registration page, require visitor to accept the T&C to register. '); - $output .= t("A !page displaying your T&C will be automatically created, access to this page can be set via the !access administration page.", array('!page' => l('page', 'legal'), '!access' => l('permissions', 'admin/user/permissions'))); + $output .= t('Display a Terms & Conditions statement on the registration page, require visitor to accept the T&C to register.'); + $output .= t('A page displaying your T&C will be automatically created, access to this page can be set via the permissions administration page.', array('@page' => 'legal', '@access' => 'admin/user/permissions')); } return $output; } @@ -40,8 +40,8 @@ function legal_menu() { $items = array(); - $items['admin/settings/legal'] = array( - 'title' => 'Legal', + $items['admin/settings/legal'] = array( + 'title' => 'Legal', 'page callback' => 'drupal_get_form', 'page arguments' => array('legal_administration'), 'access arguments' => array('administer Terms and Conditions'), @@ -59,9 +59,9 @@ function legal_menu() { 'page arguments' => array('legal_login', 1, 2), 'access callback' => TRUE, 'type' => MENU_CALLBACK - ); + ); + - return $items; } @@ -78,25 +78,25 @@ function legal_theme() { } function legal_display_fields($conditions) { - + $form = array(); $accept_label = t('Accept Terms & Conditions of Use'); - + $form['current_id'] = array( '#type' => 'value', '#value' => $conditions['tc_id'], ); - + $form['current_date'] = array( '#type' => 'value', '#value' => $conditions['date'], ); - + $form['display'] = array( '#type' => 'value', '#value' => variable_get('legal_display', '0'), ); - + $form['legal'] = array( '#type' => 'fieldset', '#title' => t('Terms and Conditions of Use'), @@ -104,7 +104,7 @@ function legal_display_fields($condition ); switch (variable_get('legal_display', '0')) { - + case 1: // scroll box (CSS) case 2: // HTML $form['legal']['conditions'] = array( @@ -115,8 +115,8 @@ function legal_display_fields($condition $form['legal']['conditions'] = array( '#value' => ' ', ); - $accept_label = t('Accept !terms of Use', array('!terms' => l('Terms & Conditions', 'legal'))); - break; + $accept_label = t('Accept Terms & Conditions of Use', array('@terms' => 'legal')); + break; default: // scroll box (HTML) $form['legal']['conditions'] = array( @@ -144,7 +144,7 @@ function legal_display_fields($condition } } } - + $form['legal']['legal_accept'] = array( '#type' => 'checkbox', '#title' => $accept_label, @@ -152,26 +152,26 @@ function legal_display_fields($condition '#weight' => 50, '#required' => TRUE, ); - + return $form; } function legal_page() { - + $conditions = legal_get_conditions(); $output = ''; - + switch(variable_get('legal_display', '0')) { case 0: // Scroll Box $output = nl2br(strip_tags($conditions['conditions'])); break; case 1: // CSS Scroll Box with HTML case 2: // HTML - case 3: // Page Link + case 3: // Page Link $output = filter_xss_admin($conditions['conditions']); break; } - + return $output; } @@ -179,18 +179,18 @@ function legal_administration() { $conditions = legal_get_conditions(); $form = legal_display_fields($conditions); - + $form['conditions'] = array( '#type' => 'textarea', '#title' => t('Terms & Conditions'), '#default_value' => $conditions['conditions'], '#description' => t('Your Terms & Conditions'), '#required' => TRUE, - ); - - // overide accept checbox requirement on preview + ); + + // overide accept checbox requirement on preview $form['legal']['legal_accept']['#required'] = FALSE; - + // overide display setting $form['display'] = array( '#type' => 'radios', @@ -200,7 +200,7 @@ function legal_administration() { '#description' => t('How terms & conditions should be displayed to users.'), '#required' => TRUE, ); - + // additional checkboxes $form['extras'] = array( '#type' => 'fieldset', @@ -210,30 +210,30 @@ function legal_administration() { '#collapsed' => TRUE, '#tree' => TRUE, ); - + $extras_count = count($conditions['extras']); if ($extras_count < 5) $extras_count = 5; - + for ($counter = 1; $counter <= $extras_count; $counter++) { - + $form['extras']['extras-' . $counter] = array( '#type' => 'textfield', '#title' => t('Label'), '#default_value' => $conditions['extras']['extras-' . $counter], ); - - // overide extra checkboxes + + // overide extra checkboxes if (!empty($conditions['extras']['extras-' . $counter])) { $form['legal']['extras-' . $counter] = array( '#type' => 'checkbox', '#title' => filter_xss_admin($conditions['extras']['extras-' . $counter]), '#default_value' => 0, '#weight' => 2, - '#required' => FALSE, - ); - } + '#required' => FALSE, + ); + } } - + // notes about changes to T&C $form['changes'] = array( '#type' => 'fieldset', @@ -242,31 +242,31 @@ function legal_administration() { '#collapsible' => TRUE, '#collapsed' => TRUE, ); - + $form['changes']['changes'] = array( '#type' => 'textarea', '#title' => t('Changes'), ); - + $form['#after_build'] = array('legal_preview'); - + $form['preview'] = array( '#type' => 'button', '#value' => t('Preview'), ); - + $form['save'] = array( '#type' => 'submit', '#value' => t('Save'), ); - + return $form; } function legal_preview($form, $form_values) { switch ($form['display']['#value']) { - + case 1: // scroll box (CSS) case 2: // HTML $form['legal']['conditions'] = array( @@ -278,8 +278,8 @@ function legal_preview($form, $form_valu $form['legal']['conditions'] = array( '#value' => ' ', ); - $form['legal']['legal_accept']['#title'] = t('Accept !terms of Use', array('!terms' => l('Terms & Conditions', 'legal'))); - break; + $form['legal']['legal_accept']['#title'] = t('Accept Terms & Conditions of Use', array('@terms' => 'legal')); + break; default: // scroll box (HTML) $form['legal']['conditions'] = array( '#type' => 'textarea', @@ -294,9 +294,9 @@ function legal_preview($form, $form_valu // overide additional checkboxes in preview if (!empty($form_values['extras'])) { - + while (list ($key, $label) = each ($form_values['extras'])) { - + if (empty($label)) { unset($form['legal'][$key]); } else { @@ -304,8 +304,8 @@ function legal_preview($form, $form_valu } } - - } + + } return $form; } @@ -318,7 +318,7 @@ function legal_administration_validate($ function legal_administration_submit($form, &$form_state) { - $values = $form_state['values']; + $values = $form_state['values']; if ($form_state['clicked_button']['#value'] == t('Preview')) return; if ( variable_get('legal_display', '0') != $form_state['values']['display'] ) { @@ -331,9 +331,9 @@ function legal_administration_submit($fo db_query("INSERT INTO {legal_conditions} (tc_id, conditions, date, extras, changes) VALUES (NULL, '%s', %d, '%s', '%s')", $values['conditions'], time(), serialize($values['extras']), $values['changes']); drupal_set_message (t('Terms & Conditions have been saved.')); } - + cache_clear_all(); - return; + return; } function theme_legal_administration($form) { @@ -343,12 +343,12 @@ function theme_legal_administration($for } else { $output = '

' . t('Current Version') . '

' . t('Version ID:') . ' ' . $form['current_id']['#value'] . '
' . t('Last saved:') . ' ' . date("l jS \of F Y h:i:s A", $form['current_date']['#value']) . '

'; } - + // preview if (empty($form['legal']['conditions']['#value'])) { drupal_render($form['legal']); } else { - + $output .= '
'; $output .= '

'. t('Preview') .'

'; $form = theme('legal_display', $form); @@ -357,14 +357,14 @@ function theme_legal_administration($for } $output .= drupal_render($form); - + return $output; } function theme_legal_display($form) { if (empty($form['legal']['conditions']['#value'])) return; - + // scroll box (CSS) if ($form['display']['#value'] == 1) { $path = base_path() . drupal_get_path('module', 'legal'); @@ -379,34 +379,34 @@ function theme_legal_display($form) { function theme_legal_page($form) { if (empty($form['current_id']['#value'])) return; - + $form = theme('legal_display', $form); $output .= drupal_render($form); - + return $output; } function legal_user($op, &$edit, &$account, $category = FALSE) { global $user; - + switch ($op) { - + case 'register': - + $conditions = legal_get_conditions(); if (empty($conditions['conditions'])) return; - + $form_fields = legal_display_fields($conditions); - + // disable checkbox if: // user is already registered (administer users) // users with 'administer users' can access registration on admin/user/user/create if (!empty($user->uid)) { $form_fields['legal']['legal_accept']['#attributes'] = array('disabled' => 'disabled'); $form_fields['legal']['legal_accept']['#required'] = FALSE; - - + + reset($conditions['extras']); while (list ($key, $label) = each ($conditions['extras'])) { if (!empty($label)) { @@ -414,12 +414,12 @@ function legal_user($op, &$edit, &$accou $form_fields['legal'][$key]['#required'] = FALSE; } } - - + + } else { $form_fields['legal']['legal_accept']['#default_value'] = $edit['legal_accept']; } - + $form = theme('legal_display', $form_fields); return $form; @@ -443,24 +443,24 @@ function legal_user($op, &$edit, &$accou $signatory = db_fetch_object(db_query('SELECT * FROM {users} WHERE uid = %d LIMIT 1', $uid)); - drupal_goto('legal_accept/' . $signatory->uid . '/' . md5($signatory->name . $signatory->password . $signatory->login)); - break; - + drupal_goto('legal_accept/' . $signatory->uid . '/' . md5($signatory->name . $signatory->password . $signatory->login)); + break; + case 'form': - + $conditions = legal_get_conditions(); if (empty($conditions['conditions'])) return; - + if ($category == 'account') { - + $form_fields = legal_display_fields($conditions); - + // check latest version of T&C has been accepted $accepted = legal_version_check($account->uid, $conditions['tc_id']); - + if ($accepted == TRUE) { $form_fields['legal']['legal_accept']['#value'] = 1; - + if (!empty($conditions['extras'])) { while (list ($key, $label) = each ($conditions['extras'])) { if (!empty($label)) { @@ -469,13 +469,13 @@ function legal_user($op, &$edit, &$accou } } } - + // disable checkbox if: // user is not account owner // latest T&C has already been accepted if ($account->uid != $user->uid || $accepted == TRUE) { $form_fields['legal']['legal_accept']['#attributes'] = array('disabled' => 'disabled'); - + if (!empty($conditions['extras'])) { reset($conditions['extras']); while (list ($key, $label) = each ($conditions['extras'])) { @@ -485,11 +485,11 @@ function legal_user($op, &$edit, &$accou } } } - + // not required if user is not account owner if ($account->uid != $user->uid) { $form_fields['legal']['legal_accept']['#required'] = FALSE; - + if (!empty($conditions['extras'])) { reset($conditions['extras']); while (list ($key, $label) = each ($conditions['extras'])) { @@ -497,14 +497,14 @@ function legal_user($op, &$edit, &$accou $form_fields['legal'][$key]['#required'] = FALSE; } } - } + } } // enable account owner to accept if ($account->uid == $user->uid && $accepted != TRUE) { $form_fields['legal']['legal_accept']['#default_value'] = $edit['legal_accept']; $form_fields['legal']['legal_accept']['#required'] = TRUE; - + if (!empty($conditions['extras'])) { reset($conditions['extras']); while (list ($key, $label) = each ($conditions['extras'])) { @@ -513,10 +513,10 @@ function legal_user($op, &$edit, &$accou $form_fields['legal'][$key]['#required'] = TRUE; } } - } - + } + } - + $form = theme('legal_display', $form_fields); return $form; } @@ -540,38 +540,38 @@ function legal_user($op, &$edit, &$accou if (!empty($user->uid)) break; legal_save_accept($account->uid, $conditions['tc_id']); - break; - + break; + case 'update': - + $conditions = legal_get_conditions(); if (empty($conditions['conditions'])) return; - + $edit['legal_accept'] = NULL; $edit['conditions'] = NULL; - + foreach ($conditions['extras'] as $key => $label) { $edit[$key] = NULL; } - - if ($account->uid != $user->uid) break; - + + if ($account->uid != $user->uid) break; + // if already accepted skip data entry $accepted = legal_version_check($account->uid, $conditions['tc_id']); - + if ($accepted == TRUE) break; - + legal_save_accept($account->uid, $conditions['tc_id']); break; - + } - + return; } - -// require registered users to accept new T&C + +// require registered users to accept new T&C function legal_login($constructor, $uid, $id_hash = NULL) { - + $conditions = legal_get_conditions(); $form = legal_display_fields($conditions); @@ -595,9 +595,9 @@ function legal_login($constructor, $uid, '#value' => t('Confirm'), ); - return $form; + return $form; } - + function legal_login_validate($form, &$form_state) { $account = db_fetch_object( db_query('SELECT * FROM {users} WHERE uid = %d LIMIT 1', $form_state['values']['uid']) ); @@ -605,44 +605,44 @@ function legal_login_validate($form, &$f if ($id_hash != $form_state['values']['id_hash']) { form_set_error('legal_accept', t('User ID cannot be identified.')); - drupal_goto(); + drupal_goto(); } - return; + return; } function legal_login_submit($form, &$form_state) { - + global $user; $user = user_load(array('uid' => $form_state['values']['uid'])); legal_save_accept($user->uid, $form_state['values']['tc_id']); watchdog('legal', '%name accepted T&C version %tc_id.', array('%name' => $user->name, '%tc_id' => $form_state['values']['tc_id'])); - + // Update the user table timestamp noting user has logged in. db_query("UPDATE {users} SET login = '%d' WHERE uid = '%s'", time(), $user->uid); - + // user has new permissions, so we clear their menu cache cache_clear_all($user->uid, 'cache_menu', TRUE); - + user_module_invoke('login', $edit, $user); - $form_state['redirect'] = 'user/'. $user->uid; + $form_state['redirect'] = 'user/'. $user->uid; return; } function theme_legal_login($form) { $form = theme('legal_display', $form); - + $output .= '

' . t('To continue to use this site please read the Terms & Conditions below, and complete the form to confirm your acceptance.' ) . '

'; - + if ($form['changes']) { foreach (element_children($form['changes']) as $key) { $form['changes'][$key]['#prefix'] .= '
  • '; $form['changes'][$key]['#suffix'] .= '
  • '; } - + $form['changes']['start_list'] = array('#value' => '', '#weight' => 3); $output .= drupal_render($form['changes']); @@ -651,10 +651,10 @@ function theme_legal_login($form) { $save = drupal_render($form['save']); $output .= drupal_render($form); $output .= $save; - + return $output; } - + function legal_get_accept($uid) { $accept = db_fetch_object(db_query("SELECT * FROM {legal_accepted} WHERE uid = '%d' ORDER BY legal_id DESC LIMIT 1", $uid)); @@ -680,27 +680,27 @@ function legal_conditions_updated($new) $old = legal_get_conditions(); if ($old['conditions'] != $new['conditions']) return TRUE; - + $count = count($new['extras']); - + for ($counter = 1; $counter <= $count; $counter++) { - + if ( $old['extras']['extras-' . $counter] != $new['extras']['extras-' . $counter] ) return TRUE; } - - return FALSE; + + return FALSE; } // get all changes since user last accepted function legal_display_changes($form, $uid) { - + $last_accepted = legal_get_accept($uid); if (empty($last_accepted)) return $form; - + $results = db_query("SELECT * FROM {legal_conditions} WHERE tc_id > %d ORDER BY tc_id DESC", $last_accepted->tc_id); - + if (empty($results)) return $form; - + $form['changes'] = array( '#type' => 'fieldset', '#title' => t('Changes List'), @@ -709,15 +709,15 @@ function legal_display_changes($form, $u '#collapsed' => TRUE, '#tree' => TRUE, ); - - while ($conditions = db_fetch_object($results)) { - + + while ($conditions = db_fetch_object($results)) { + unset($changes); - + if (!empty($conditions->changes)) { - + $changes = explode("\r\n", $conditions->changes); - + foreach($changes as $change) { $form['changes'][] = array( '#value' => filter_xss_admin($change), @@ -726,9 +726,9 @@ function legal_display_changes($form, $u $is_list = TRUE; } } - + } - + if (!$is_list) $form['changes'] = NULL; return $form; @@ -739,7 +739,7 @@ function legal_version_check($uid, $curr $legal_account = legal_get_accept($uid); if ($legal_account->tc_id == $current_tc_id) return TRUE; - + // get change log messages return $log_messages; }