'admin/ecsettings/ec_terms', 'title' => t('Terms & Conditions'), 'description' => t('Specify the Terms & Conditions that will be presented to a user during the checkout process.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('ec_terms_details'), 'access' => user_access('administer ec_terms'), 'type' => MENU_NORMAL_ITEM, ); } else { } return $items; } /** * Implementation of hook_perm(). */ function ec_terms_perm() { return array('administer ec_terms'); } // Generate settings form. function ec_terms_details() { $form['ec_terms']['switch'] = array( '#type' => 'select', '#title' => t('Require user to agree to terms and conditions?'), '#options' => array('Y' => t('Yes'), 'N' => t('No')), '#default_value' => (variable_get('ec_terms_switch', true) ? 'Y' : 'N'), '#required' => true, ); $form['ec_terms']['how'] = array( '#type' => 'select', '#title' => t('When to present terms'), '#description' => t('Choose whether to present terms on the review page or on a separate screen'), '#options' => array('page' => t('Separate screen'), 'review' => t('Checkout review')), '#default_value' => variable_get('ec_terms_page', 'page'), '#required' => true, ); $form['ec_terms']['name'] = array( '#type' => 'textfield', '#title' => t('Title of Terms & Conditions'), '#description' => t('Examples: terms, refund policy, return policy, etc'), '#default_value' => variable_get('ec_terms_title', t('Terms & Conditions')), ); $form['ec_terms']['text'] = array( '#type' => 'textarea', '#title' => t('Terms'), '#description' => t('These will be displayed during the checkout process. HTML Accepted'), '#cols' => 60, '#rows' => 15, '#default_value' => variable_get('ec_terms', ''), ); $form['ec_terms']['fail'] = array( '#type' => 'textfield', '#title' => t('Failure text'), '#description' => t('The message to be displayed if agreement is required but the checkbox is not checked.'), '#default_value' => variable_get('ec_terms_fail', t('Accept our terms and conditions in order to continue')), ); $form['ec_terms']['confirmation'] = array( '#type' => 'textfield', '#title' => t('Confirmation text'), '#description' => t('Example: !example', array('!example' => t('I agree to the above terms and conditions'))), '#default_value' => variable_get('ec_terms_confirmation', t('I agree to the above terms and conditions')), ); return system_settings_form($form); } function ec_terms_details_validate($form_id, $form_values) { if ($form_values['switch'] == 'Y') { if ($form_values['text'] == '') { form_set_error('ec_terms][text', t('You must provide some terms for the user to agree to.')); } if ($form_values['name'] == '') { form_set_error('ec_terms][name', t('You must provide a title for your terms')); } if ($form_values['fail'] == '') { form_set_error('ec_terms][fail', t('You must provide some failure text.')); } } } function ec_terms_details_submit($form_id, $form_values) { variable_set('ec_terms', $form_values['text']); variable_set('ec_terms_switch', ($form_values['switch'] == 'Y')); variable_set('ec_terms_page', $form_values['how']); variable_set('ec_terms_title', $form_values['name']); variable_set('ec_terms_confirmation', $form_values['confirmation']); variable_set('ec_terms_fail', $form_values['fail']); if ($form_values['switch'] == 'Y'){ drupal_set_message(t('ec_terms will be required during checkout')); } else { drupal_set_message(t('ec_terms will not be required during checkout (no checkbox will be presented)')); } if ($form_values['how'] == 'page') { drupal_set_message(t('ec_terms will be a separate screen during checkout.')); } else { drupal_set_message(t('ec_terms will be shown on the review screen')); } if ($form_values['name'] !== '') { drupal_set_message(t('ec_terms will be titled %title', array('%title' => $form_values['name']))); } } /** * Implementation of hook_checkoutapi(). */ function ec_terms_checkoutapi(&$txn, $op, $arg3 = NULL, $arg4 = NULL){ $ec_terms_string = variable_get('ec_terms', ''); $ec_terms = filter_xss($ec_terms_string, $allowed_tags = array('a', 'em', 'strong', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'div')); $ec_terms_title = check_plain(variable_get('ec_terms_title', t('Terms & Conditions'))); $ec_terms_page = variable_get('ec_terms_page', 'page'); $ec_terms_switch = variable_get('ec_terms_switch', true); $ec_terms_fail = variable_get('ec_terms_fail', t('Accept our !terms_title in order to continue', array('!terms_title' => $ec_terms_title))); $output = ''; switch ($op) { case 'form': if ($ec_terms_page == 'page') { //drupal_set_title(variable_get('ec_terms_title', '')); $form = _present_ec_terms($ec_terms, $ec_terms_title); $form['submit'] = array( '#type' => 'submit', '#value' => t('Checkout'), ); return $form; } break; case 'validate': if ($ec_terms_switch && (!$txn->ec_terms_agree)) { form_set_error('error', $ec_terms_fail); } break; case 'save': if ($txn->ec_terms !== 0) { $txn->screen++; } break; case 'review': if ($ec_terms_page == 'review'){ $form = _present_ec_terms($ec_terms, $ec_terms_title); return $form; } break; case 'review_validate': if ($ec_terms_page == 'review' && $ec_terms_switch && !$txn->ec_terms_agree) { form_set_error('error', $ec_terms_fail); } break; case 'review_save': $txn->screen++; break; } } function theme_ec_terms_review_form(&$form) { // Build the ec_terms data form. $details = drupal_render_form('ec_terms', $form); // Render it in a box to match other checkout review items. $output = theme('box', variable_get('ec_terms_title', t('Terms & Conditions')), $details); return $output; } function _present_ec_terms($ec_terms, $ec_terms_title) { $form['text'] = array( '#type' => 'markup', '#prefix' => '