I would like to use this module with Ubercart's anonymous checkout for a subscription-based site.

Comments

mattcasey’s picture

Status: Active » Needs review
StatusFileSize
new4.12 KB

I added a form_alter to the module for Ubercart's checkout page

particlegirl’s picture

Hello any chance of this going to d7? I need something similar for all customers. Cheers!

particlegirl’s picture

Actually I went applied the patch manually as it wouldn't work.
and so I got this message.

Fatal error: Call to undefined function tou_i18nstrings() in /home/connecte/public_html/drupal/sites/all/modules/terms_of_use/terms_of_use.module on line 158

Cheers

Alek1983’s picture

Patch not work, I got message with error too:

Fatal error: Call to undefined function tou_i18nstrings() in /public_html/sites/all/modules/terms_of_use/terms_of_use.module on line 221

<?php

/**
 * @file
 * Adds Terms of Use to the 'user_register' form.
 *
 * This module adds Terms of Use to the registration page.
 */

/**
 * Implementation of hook_menu().
 */
function terms_of_use_menu() {
  $items = array();

  $items['admin/settings/terms_of_use'] = array(
    'description' => 'Add Terms of Use to the registration page.',
    'title' => 'Terms of Use',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('terms_of_use_admin_settings'),
    'access arguments' => array('administer site configuration'),
  );

  $items['node/autocomplete'] = array(
    'title' => 'Autocomplete node title',
    'page callback' => 'terms_of_use_autocomplete',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    'file' => 'terms_of_use.pages.inc',
  );

  $items['terms_of_use/js'] = array(
    'page callback' => 'terms_of_use_js',
    'access arguments' => array('administer site configuration'),
    'type' => MENU_CALLBACK,
    'file' => 'terms_of_use.pages.inc',
  );

  return $items;
}

/**
 * Menu callback; show settings form.
 * @see terms_of_use_admin_settings_validate()
 *
 */
function terms_of_use_admin_settings() {

  // Adding the fieldset for node specification.
  $form['terms_of_use_text'] = array(
    '#type' => 'fieldset',
    '#prefix' => '<div id="fieldset-wrapper">',
    '#suffix' => '</div>',
    //'#title' => t('Terms of Use text'),
  );
  $form['terms_of_use_text']['terms_of_use_node_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title of the post where your Terms of Use are published'),
    '#default_value' => variable_get('terms_of_use_node_title', ''),
    '#description' => t('Node <em>title</em> of the page or story (or blog entry or book page) where your Terms of Use are published.'),
    '#autocomplete_path' => 'node/autocomplete',
  );
  $form['terms_of_use_text']['terms_of_use_pick_node_id'] = array(
    '#type' => 'button',
    '#value' => t('I prefer to specify the node id'),
    '#weight' => 10,
    '#ahah' => array(
      'path' => 'terms_of_use/js',
      'wrapper' => 'fieldset-wrapper',
    ),
  );
  // Adding the fieldset for form specification.
  $form['terms_of_use_form'] = array(
    '#type' => 'fieldset',
  );
  $form['terms_of_use_form']['terms_of_use_fieldset_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Label for the fieldset'),
    '#default_value' => variable_get('terms_of_use_fieldset_name', t('Terms of Use')),
    '#description' => t('The text for the Terms of Use and the [x] checkbox are contained in a fieldset. Type here the title for that fieldset.'),
  );
  $form['terms_of_use_form']['terms_of_use_checkbox_label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label for the checkbox'),
    '#default_value' => variable_get('terms_of_use_checkbox_label', t('I agree with these terms.')),
    '#description' => t('Type here something like "I agree with these terms." or "I CERTIFY THAT I AM OVER THE AGE OF 18 YEARS OLD.", without quotes. You can use the token @link to insert a link to the Terms in this label. For example, the label can be: "I agree with the @link.", without quotes. You may want to link to the Terms if you prefer not to show the full text of the Terms in the registration form. If you use the token, the Terms will not be shown.'),
  );

  return system_settings_form($form);
}

/**
 * Validate the terms_of_use_admin_settings form.
 *
 * @see terms_of_use_admin_settings()
 */
function terms_of_use_admin_settings_validate($form, &$form_state) {
  if (isset($form_state['values']['terms_of_use_node_id'])) {
    $nid = $form_state['values']['terms_of_use_node_id'];
    if (empty($nid)) {
      form_set_error('terms_of_use_node_id', t('You must specify a node <em>nid</em>.'));
    }
    else {
      $node = node_load($nid);
      if ($node == FALSE) {
        form_set_error('terms_of_use_node_id', t('No post was published with <em>nid</em> !nid.', array('!nid' => $nid)));
      }
      else {
        variable_set('terms_of_use_node_title', $node->title);
      }
    }
  }
  elseif (!empty($form_state['values']['terms_of_use_node_title'])) {
    $node = node_load(array('title' => $form_state['values']['terms_of_use_node_title']));
    if ($node == FALSE) {
      form_set_error('terms_of_use_node_title', t('No post was published with this title.'));
    }
    else {
      variable_set('terms_of_use_node_id', $node->nid);
    }
  }
  else {
    form_set_error('terms_of_use_node_title', t('You must specify a node title.'));
  }
}

/**
 * Implementation of hook_form_form_id_alter().
 */
function terms_of_use_form_user_register_alter(&$form, $form_state) {
  // Administrative users can skip this. So admin/user/user/create won't show
  // the terms of use.
  if (user_access('administer users')) {
    return;
  }

  $fieldset_name = filter_xss(variable_get('terms_of_use_fieldset_name', t('Terms of Use')));
  $checkbox_label = filter_xss_admin(variable_get('terms_of_use_checkbox_label', t('I agree with these terms.')));

  // Adding the fieldset.
  $form['terms_of_use'] = array(
    '#type' => 'fieldset',
    '#title' => $fieldset_name,
    '#weight' => 10,
  );

  $show_terms = TRUE;

  // Getting the nid of the the Terms of Use node.
  $terms_of_use_node_id = variable_get('terms_of_use_node_id', 0);

  // If the translation module is active the node might be available in other
  // languages.
  if (module_exists('translation')) {
    $translations = translation_node_get_translations($terms_of_use_node_id);
    if (!empty($translations[$GLOBALS['language']->language])) {
      $terms_of_use_node_id = $translations[$GLOBALS['language']->language]->nid;
    }
  }
  // A nid for the desired language was found.
  if ($terms_of_use_node_id) {
    $node = node_load($terms_of_use_node_id);
    // The node could be loaded.
    if ($node->nid) {
      // Show terms on the registration for or just a link?s
      if (strpos($checkbox_label, '@link') !== FALSE) {
        $checkbox_label = str_replace('@link', l($node->title, 'node/' . $node->nid), $checkbox_label);
        $show_terms = FALSE;
      }
      // Adding the nodes body by theme_terms_of_use() to the fieldset if desired.
      if ($show_terms) {
        $node = node_prepare(node_load($terms_of_use_node_id));
        if ($node->body) {
          drupal_add_css(drupal_get_path('module', 'terms_of_use') . '/terms_of_use.css');
          $form['terms_of_use']['terms_of_use_text'] = array(
            '#value' => theme('terms_of_use', $node->body, $node),
          );
        }
        else {
          watchdog('Terms of use', 'The body field of the terms of use node was empty. Please check the the nodes content.', array(), WATCHDOG_ALERT, l('Administer terms of use', 'admin/settings/terms_of_use'));
        }
      }
    }
    else {
      watchdog('Terms of use', 'The terms of use node could not be loaded. Please check the settings and the node.', array(), WATCHDOG_ALERT, l('Administer terms of use', 'admin/settings/terms_of_use'));
    }
  }
  else {
    watchdog('Terms of use', 'No node is set to use as terms of use in the currecnt language [' . $GLOBALS['language']->language . '].', array(), WATCHDOG_NOTICE, l('Administer terms of use', 'admin/settings/terms_of_use'));
  }

  // Checkbox validate handles denoting required checkboxes for us
  if (module_exists('checkbox_validate')) {
    $asterisk = '';
  }
  else {
    $asterisk = '&nbsp;<span class="form-required" title="' . t('This field is required') . '">*</span>';
  }

  // Adding the checkbox to the fieldset.
  $form['terms_of_use']['terms_of_use'] = array(
    '#type' => 'checkbox',
    '#title' => $checkbox_label . $asterisk,
    '#required' => TRUE,
    '#element_validate' => array('_terms_of_use_validate_checkbox'),
  );

  return $form;
}

/**
 * Add to anonymous Ubercart checkout using hook_form_form_id_alter().
 */
function terms_of_use_form_uc_cart_checkout_form_alter(&$form, $form_state) {
  // Administrative users can skip this. So admin/user/user/create won't show
  // the terms of use.
  if (user_access('administer users')) {
    return;
  }

    $fieldset_name = filter_xss(tou_i18nstrings(
    'fieldset_name',
    variable_get('terms_of_use_fieldset_name', t('Terms of Use'))
  ));
  $checkbox_label = filter_xss_admin(tou_i18nstrings(
    'checkbox_label',
    variable_get('terms_of_use_checkbox_label', t('I agree with these terms.'))
  ));

  // Adding the fieldset.
  $form['terms_of_use'] = array(
    '#type' => 'fieldset',
    '#title' => $fieldset_name,
  );
  $show_terms = TRUE;

  // Getting the nid of the the Terms of Use node.
  $terms_of_use_node_id = variable_get('terms_of_use_node_id', 0);

  // If the translation module is active the node might be available in other
  // languages.
  if (module_exists('translation')) {
    $translations = translation_node_get_translations($terms_of_use_node_id);
    if (!empty($translations[$GLOBALS['language']->language])) {
      $terms_of_use_node_id = $translations[$GLOBALS['language']->language]->nid;
    }
  }
  // A nid for the desired language was found.
  if ($terms_of_use_node_id) {
    $node = node_load($terms_of_use_node_id);
    // The node could be loaded.
    if ($node->nid) {
      // Show terms on the registration for or just a link?s
      if (strpos($checkbox_label, '@link') !== FALSE) {
        $checkbox_label = str_replace('@link', l($node->title, 'node/' . $node->nid), $checkbox_label);
        $show_terms = FALSE;
      }
      // Adding the nodes body by theme_terms_of_use() to the fieldset if desired.
      if ($show_terms) {
        $node = node_prepare(node_load($terms_of_use_node_id));
        if ($node->body) {
          drupal_add_css(drupal_get_path('module', 'terms_of_use') . '/terms_of_use.css');
          $form['terms_of_use']['terms_of_use_text'] = array(
                  '#value' => theme('terms_of_use', $node->body, $node),
          );
        }
        else {
          watchdog('Terms of use', 'The body field of the terms of use node was empty. Please check the the nodes content.', array(), WATCHDOG_ALERT, l('Administer terms of use', 'admin/settings/terms_of_use'));
        }
      }
    }
    else {
      watchdog('Terms of use', 'The terms of use node could not be loaded. Please check the settings and the node.', array(), WATCHDOG_ALERT, l('Administer terms of use', 'admin/settings/terms_of_use'));
    }
  }
  else {
    watchdog('Terms of use', 'No node is set to use as terms of use in the currecnt language [' . $GLOBALS['language']->language . '].', array(), WATCHDOG_NOTICE, l('Administer terms of use', 'admin/settings/terms_of_use'));
  }

  // Checkbox validate handles denoting required checkboxes for us
  if (module_exists('checkbox_validate')) {
    $asterisk = '';
  }
  else {
    $asterisk = '&nbsp;<span class="form-required" title="' . t('This field is required') . '">*</span>';
  }

  // Adding the checkbox to the fieldset.
  $form['terms_of_use']['terms_of_use'] = array(
    '#type' => 'checkbox',
    '#title' => $checkbox_label . $asterisk,
    '#required' => TRUE,
    '#element_validate' => array('_terms_of_use_validate_checkbox'),
  );

  return $form;
}

/**
 * Validation callback; verify that checkbox is checked.
 */
function _terms_of_use_validate_checkbox($form, &$form_state) {
  $value = $form_state['values']['terms_of_use'];
  if ($value == 0) {
    form_set_error('terms_of_use', t('You must agree with the !terms to get an account.', array('!terms' => filter_xss(variable_get('terms_of_use_fieldset_name', t('Terms of Use'))))));
  }
}

/**
 * Implementation of hook_theme().
 */
function terms_of_use_theme() {
  return array(
    'terms_of_use' => array(
      'arguments' => array('terms' => NULL, 'node' => NULL),
    ),
  );
}

/**
 * Output the terms of use.
 *
 * @param $terms
 *  The terms of service, already formatted.
 * @param $node
 *  The $node object, in case we need it.
 * @return
 *  HTML output.
 * @ingroup themeable
 */
function theme_terms_of_use($terms, $node = NULL) {
  $output = '<div id="terms-of-use" class="content clear-block">';
  $output .= $terms;
  $output .= '</div>';

  return $output;
}
mattcasey’s picture

The dev code changed, the function was in the version from February 25th. I don't have an environment for patching right now but if you look at what I did, I just copied the form_alter() function above it, changing the function name to match the new form id (form_uc_cart_checkout). Remember to flush your cache after adding it.

Alek1983’s picture

Thank you very much, but still not working at all.

jasonawant’s picture

Version: 6.x-1.x-dev » 6.x-1.3
StatusFileSize
new3.67 KB

Hi,

I've quickly updated this patch for 6.x-1.3.

I removed the two calls to filter_xss(tou_i18nstrings when getting the variables, which I think was causing the error.

I've also changed the check

if (user_access('administer users')) {
    return;
  }

to

  global $user;
  // Only present the terms of use pane on the checkout form if user is anonymous.
  if ($user->uid != 0) {
    return;
  }

Jason.

kars-t’s picture

Status: Needs review » Closed (won't fix)