'fieldset',
'#title' => t('Admin settings'),
'#summary callback' => 'summarize_form',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['admin']['uc_order_number_displayed'] = array(
'#type' => 'select',
'#title' => t('Number of orders on overview screen'),
'#options' => drupal_map_assoc(range(10, 100, 10)),
'#summary' => t('Displaying @orders orders at a time on the admin overview', array('@orders' => variable_get('uc_order_number_displayed', 30))),
'#default_value' => variable_get('uc_order_number_displayed', 30),
);
$form['admin']['uc_order_logging'] = array(
'#type' => 'checkbox',
'#title' => t('Enable order logging'),
'#summary callback' => 'summarize_checkbox',
'#summary arguments' => array(
t('Order logging is enabled.'),
t('Order logging is disabled.'),
),
'#default_value' => variable_get('uc_order_logging', TRUE),
);
$form['admin']['uc_order_capitalize_addresses'] = array(
'#type' => 'checkbox',
'#title' => t('Capitalize address on order screens'),
'#summary callback' => 'summarize_checkbox',
'#summary arguments' => array(
t('Addresses on order view pages are capitalized.'),
t('Addresses on order view pages are not capitalized.'),
),
'#default_value' => variable_get('uc_order_capitalize_addresses', TRUE),
);
$form['customer'] = array(
'#type' => 'fieldset',
'#title' => t('Customer settings'),
'#summary callback' => 'summarize_form',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['customer']['uc_cust_view_order_invoices'] = array(
'#type' => 'checkbox',
'#title' => t('Allow customers to view order invoices from their order history.'),
'#description' => t('Enabling this feature allows pop-up invoices to be opened when a particular order is being viewed.'),
'#summary callback' => 'summarize_checkbox',
'#summary arguments' => array(
t('Customers are allowed to view order invoices from their accounts.'),
t('Customers are not allowed to view order invoices from their accounts.'),
),
'#default_value' => variable_get('uc_cust_view_order_invoices', TRUE),
);
$form['customer']['uc_cust_order_invoice_template'] = array(
'#type' => 'select',
'#title' => t('On-site invoice template'),
'#description' => t('Select the invoice template to use when invoices are viewed on the site. This is separate from the template used to e-mail invoices to customers which is configured through Conditional actions.', array('!url' => url(CA_UI_PATH))),
'#options' => uc_order_template_options(),
'#summary' => t('You are using the %template order invoice template.', array('%template' => variable_get('uc_cust_order_invoice_template', 'customer'))),
'#default_value' => variable_get('uc_cust_order_invoice_template', 'customer'),
);
return system_settings_form($form);
}
/**
* Summarize the order status settings.
*
* @param $form
* The form passed from the summarizer
* @param $states
* An array of order statuses
* @return
* An array of summary information
*
* This function summarizes the order statuses that have been defined. It is
* organized under a parent node specifying that the following settings are
* order statuses.
*/
function _uc_order_states_summarize($form, $states) {
$statuses = $items = array();
foreach ($states as $state) {
$items[] = t('@state', array('@state' => $state['title']));
}
$statuses[] = array(
'data' => t('The following order statuses have been defined:'),
'children' => $items,
);
return $statuses;
}
/**
* Display the order workflow form for order state and status customization.
*
* @ingroup forms
* @see uc_order_workflow_form_submit()
*/
function uc_order_workflow_form() {
$states = uc_order_state_list();
$statuses = uc_order_status_list();
$form['order_states'] = array(
'#type' => 'fieldset',
'#title' => t('Order states'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#summary callback' => 'summarize_null',
'#theme' => 'uc_order_state_table',
'#tree' => TRUE,
);
foreach ($states as $state) {
$form['order_states'][$state['id']]['#summary callback'] = 'summarize_form';
$form['order_states'][$state['id']]['title'] = array(
'#value' => $state['title'],
);
// Create the select box for specifying a default status per order state.
$options = array();
foreach ($statuses as $status) {
if ($status['state'] == $state['id']) {
$options[$status['id']] = $status['title'];
}
}
if (empty($options)) {
$form['order_states'][$state['id']]['default'] = array(
'#value' => t('- N/A -'),
);
}
else {
$form['order_states'][$state['id']]['default'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => uc_order_state_default($state['id']),
);
}
}
$form['order_statuses'] = array(
'#type' => 'fieldset',
'#title' => t('Order statuses'),
'#collapsible' => FALSE,
'#summary callback' => '_uc_order_states_summarize',
'#summary arguments' => array($states),
'#theme' => 'uc_order_status_table',
'#tree' => TRUE,
);
// Build the state option array for the order status table.
$options = array();
foreach ($states as $state) {
$options[$state['id']] = $state['title'];
}
foreach ($statuses as $status) {
$form['order_statuses'][$status['id']]['id'] = array(
'#value' => $status['id'],
);
$form['order_statuses'][$status['id']]['title'] = array(
'#type' => 'textfield',
'#default_value' => $status['title'],
'#size' => 32,
'#required' => TRUE,
);
$form['order_statuses'][$status['id']]['weight'] = array(
'#type' => 'weight',
'#delta' => 20,
'#default_value' => $status['weight'],
);
if ($status['locked']) {
$form['order_statuses'][$status['id']]['state'] = array(
'#value' => uc_order_state_data($status['state'], 'title'),
);
$form['order_statuses'][$status['id']]['locked'] = array(
'#type' => 'hidden',
'#value' => TRUE,
);
}
else {
$form['order_statuses'][$status['id']]['state'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $status['state'],
);
$form['order_statuses'][$status['id']]['remove'] = array(
'#type' => 'checkbox',
);
}
}
$form['order_statuses']['create'] = array(
'#type' => 'submit',
'#value' => t('Create new status'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit changes'),
);
return $form;
}
/**
* @see uc_order_workflow_form()
*/
function uc_order_workflow_form_submit($form, &$form_state) {
foreach ($form_state['values']['order_states'] as $key => $value) {
variable_set('uc_state_'. $key .'_default', $value['default']);
}
foreach ($form_state['values']['order_statuses'] as $key => $value) {
if ($value['locked'] != TRUE && $value['remove'] == TRUE) {
db_query("DELETE FROM {uc_order_statuses} WHERE order_status_id = '%s'", $key);
drupal_set_message(t('Order status %status removed.', array('%status' => $key)));
}
else {
if ($value['locked'] == TRUE) {
db_query("UPDATE {uc_order_statuses} SET title = '%s', weight = %d "
."WHERE order_status_id = '%s'", $value['title'],
$value['weight'], $key);
}
else {
db_query("UPDATE {uc_order_statuses} SET title = '%s', state = '%s', "
."weight = %d WHERE order_status_id = '%s'", $value['title'],
$value['state'], $value['weight'], $key);
}
}
}
switch ($form_state['values']['op']) {
case t('Submit changes'):
drupal_set_message(t('Order workflow information saved.'));
break;
case t('Create new status'):
$form_state['redirect'] = 'admin/store/settings/orders/edit/workflow/create';
}
}
/**
* Settings for the order panes.
*
* @ingroup forms
*/
function uc_order_panes_form() {
$panes = _order_pane_list();
foreach ($panes as $pane) {
foreach ($pane['show'] as $view) {
$form['panes'][$view][$pane['id']]['title'] = array(
'#value' => $pane['title'],
);
$form['panes'][$view][$pane['id']]['uc_order_pane_'. $pane['id'] .'_show_'. $view] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('uc_order_pane_'. $pane['id'] .'_show_'. $view, $pane['enabled']),
);
$form['panes'][$view][$pane['id']]['uc_order_pane_'. $pane['id'] .'_enabled'] = &$form['panes'][$view][$pane['id']]['uc_order_pane_'. $pane['id'] .'_show_'. $view];
$form['panes'][$view][$pane['id']]['uc_order_pane_'. $pane['id'] .'_weight_'. $view] = array(
'#type' => 'weight',
'#default_value' => variable_get('uc_order_pane_'. $pane['id'] .'_weight_'. $view, $pane['weight']),
);
$form['panes'][$view][$pane['id']]['uc_order_pane_'. $pane['id'] .'_weight'] = &$form['panes'][$view][$pane['id']]['uc_order_pane_'. $pane['id'] .'_weight_'. $view];
$form['panes'][$view][$pane['id']]['weight'] = variable_get('uc_order_pane_'. $pane['id'] .'_weight_'. $view, $pane['weight']);
}
}
$titles = _get_order_screen_titles();
foreach ($form['panes'] as $view => $data) {
if (!is_array($form['panes'][$view])) {
continue;
}
uasort($form['panes'][$view], 'uc_weight_sort');
foreach ($data as $pane => $info) {
unset($form['panes'][$view][$pane]['weight']);
}
$fieldset = array(
'#theme' => 'uc_pane_sort_table',
'#pane_prefix' => 'uc_order_pane',
'#type' => 'fieldset',
'#title' => t('Order panes on !screen screen', array('!screen' => $titles[$view])),
'#summary callback' => '_uc_order_panes_summarize',
'#summary arguments' => array($data, $titles[$view], $view),
);
$form['panes'][$view] = array_merge($fieldset, $form['panes'][$view]);
$form['panes']['#summary callback'] = 'summarize_form';
}
return system_settings_form($form);
}
/**
* Present the form to create a custom order status.
*
* @ingroup forms
* @see
* uc_order_status_create_form_validate()
* uc_order_status_create_form_submit()
*/
function uc_order_status_create_form() {
$form['status_id'] = array(
'#type' => 'textfield',
'#title' => t('Order status ID'),
'#description' => t('Must be a unique ID with no spaces.'),
'#summary callback' => 'summarize_null',
'#size' => 32,
'#maxlength' => 32,
'#required' => TRUE,
);
$form['status_title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('The order status title displayed to users.'),
'#summary callback' => 'summarize_null',
'#size' => 32,
'#maxlength' => 48,
'#required' => TRUE,
);
// Build the state option array for the order status table.
$options = array();
foreach (uc_order_state_list() as $state) {
$options[$state['id']] = $state['title'];
}
$form['status_state'] = array(
'#type' => 'select',
'#title' => t('Order state'),
'#description' => t('Set which order state this status is for.'),
'#summary callback' => 'summarize_null',
'#options' => $options,
'#default_value' => 'post_checkout',
);
$form['status_weight'] = array(
'#type' => 'weight',
'#title' => t('List position'),
'#delta' => 20,
'#default_value' => 0,
);
$form['create'] = array(
'#type' => 'submit',
'#value' => t('Create'),
);
$form['cancel'] = array(
'#value' => l(t('Cancel'), 'admin/store/settings/orders/edit/workflow'),
);
return $form;
}
/**
* Ensure the new status id is unique and has no spaces.
*
* @see uc_order_status_create_form()
*/
function uc_order_status_create_form_validate($form, &$form_state) {
$new_status = strtolower(trim($form_state['values']['status_id']));
if (strpos($new_status, ' ') !== FALSE || $new_status == 'all') {
form_set_error('status_id', t('You have entered an invalid status ID.'));
}
$statuses = uc_order_status_list();
foreach ($statuses as $status) {
if ($new_status == $status['id']) {
form_set_error('status_id', t('This ID is already in use. Please specify a unique ID.'));
}
}
}
/**
* @see uc_order_status_create_form()
*/
function uc_order_status_create_form_submit($form, &$form_state) {
db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, "
."weight, locked) VALUES ('%s', '%s', '%s', %d, 0)",
$form_state['values']['status_id'], $form_state['values']['status_title'],
$form_state['values']['status_state'], $form_state['values']['status_weight']);
drupal_set_message(t('Custom order status created.'));
$form_state['redirect'] = 'admin/store/settings/orders/edit/workflow';
}
/**
* Display the main order admin screen, an overview of all received orders.
*/
function uc_order_admin($sql = NULL, $args = NULL, $search = FALSE) {
$header = array(
array('data' => t('Actions')),
array('data' => t('Order ID'), 'field' => 'o.order_id', 'sort' => 'desc'),
array('data' => t('Customer')),
array('data' => t('Total'), 'align' => 'center', 'field' => 'o.order_total'),
array('data' => t('Purchase date'), 'align' => 'center', 'field' => 'o.created'),
array('data' => t('Status'), 'field' => 'os.title'),
);
if (is_null($sql)) {
$args = array();
$show_status = 1;
if (arg(3) == 'sort' && !is_null(arg(4))) {
$_SESSION['sort_status'] = arg(4);
$where = "WHERE o.order_status = '%s'";
$args[] = arg(4);
}
else {
if (isset($_SESSION['sort_status']) && !is_null($_SESSION['sort_status'])) {
$where = "WHERE o.order_status = '%s'";
$args[] = $_SESSION['sort_status'];
}
else {
$where = 'WHERE o.order_status IN '. uc_order_status_list('general', TRUE);
}
}
if ($_SESSION['sort_status'] == 'all') {
$where = '';
}
$sql = 'SELECT o.order_id, o.uid, o.billing_first_name, o.billing_last_name, o.order_total, '
.'o.order_status, o.created, os.title FROM {uc_orders} o LEFT JOIN {uc_order_statuses} os '
.'ON o.order_status = os.order_status_id '. $where . tablesort_sql($header);
}
$address = variable_get('uc_customer_list_address', 'billing');
if ($address == 'shipping') {
$sql = str_replace('billing', 'delivery', $sql);
}
else {
$address = 'billing';
}
$context = array(
'revision' => 'themed-original',
'type' => 'amount',
);
$result = pager_query($sql, variable_get('uc_order_number_displayed', 30), 0, NULL, $args);
while ($order = db_fetch_object($result)) {
if ($address == 'shipping') {
$order_name = $order->delivery_first_name .' '. $order->delivery_last_name;
}
else {
$order_name = $order->billing_first_name .' '. $order->billing_last_name;
}
if (trim($order_name) == '') {
if ($order->uid !== 0) {
$account = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $order->uid));
}
if (empty($account)) {
$order_name = t('User: none');
}
else {
$order_name = t('User: !name', array('!name' => $account));
}
}
$rows[] = array(
'data' => array(
array('data' => uc_order_actions($order, TRUE), 'nowrap' => 'nowrap'),
array('data' => $order->order_id),
array('data' => check_plain($order_name), 'nowrap' => 'nowrap'),
array('data' => uc_price($order->order_total, $context), 'align' => 'right', 'nowrap' => 'true'),
array('data' => format_date($order->created, 'custom', variable_get('uc_date_format_default', 'm/d/Y')), 'align' => 'center'),
array('data' => $order->title),
),
'id' => 'order-'. $order->order_id,
);
}
drupal_add_js(array(
'ucURL' => array(
'adminOrders' => url('admin/store/orders/'),
),
), 'setting');
drupal_add_js(drupal_get_path('module', 'uc_order') .'/uc_order.js');
if ($search === FALSE) {
$output = '
'. drupal_get_form('uc_order_select_form') .'
'
.'
'. drupal_get_form('uc_order_admin_sort_form') .'
';
}
$output .= theme('table', $header, $rows, array('class' => 'uc-orders-table'));
$output .= theme('pager', NULL, variable_get('uc_order_number_displayed', 30), 0);
return $output;
}
/**
* Create the order status select box on the order overview screen.
*
* @ingroup forms
* @see uc_order_admin_sort_form_submit()
*/
function uc_order_admin_sort_form() {
$options = array('-1' => t('Active orders'));
foreach (uc_order_status_list() as $status) {
$options[$status['id']] = $status['title'];
}
$options['all'] = t('All orders');
if (!isset($_SESSION['sort_status']) || is_null($_SESSION['sort_status'])) {
$default_status = -1;
}
else {
$default_status = $_SESSION['sort_status'];
}
$form['status'] = array(
'#type' => 'select',
'#title' => t('View by status'),
'#options' => $options,
'#default_value' => $default_status,
'#attributes' => array('onchange' => 'this.form.submit();')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'View',
'#attributes' => array('style' => 'display: none;')
);
return $form;
}
/**
* @see uc_order_admin_sort_form()
*/
function uc_order_admin_sort_form_submit($form, &$form_state) {
if ($form_state['values']['status'] == '-1') {
unset($_SESSION['sort_status']);
drupal_goto('admin/store/orders');
}
else {
$_SESSION['sort_status'] = $form_state['values']['status'];
drupal_goto('admin/store/orders/sort/'. $form_state['values']['status']);
}
}
/**
* Create the textfield box to select an order by ID on the order overview screen.
*
* @ingroup forms
* @see uc_order_select_form_submit()
*/
function uc_order_select_form() {
$form['order_id'] = array(
'#type' => 'textfield',
'#title' => t('View order'),
'#size' => 10,
'#maxlength' => 10
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('View'),
'#attributes' => array('style' => 'display: none;')
);
return $form;
}
/**
* @see uc_order_select_form()
*/
function uc_order_select_form_submit($form, &$form_state) {
if (uc_order_exists($form_state['values']['order_id'])) {
drupal_goto('admin/store/orders/'. $form_state['values']['order_id']);
}
}
/**
* Create a new order and redirect to its edit screen.
*/
function uc_order_create() {
drupal_add_js(array('ucURL' => array('adminOrders' => url('admin/store/orders/'))), 'setting');
drupal_add_js(drupal_get_path('module', 'uc_order') .'/uc_order.js');
$output = '
'
. uc_store_get_icon('file:order_view') .' '
. t('Search for an existing customer.') .'
';
$output .= '
'
. uc_store_get_icon('file:menu_customers_small') .' '
. t('Create a new customer.') .'
';
$output .= ' '
. drupal_get_form('uc_order_create_form');
return $output;
}
/**
* Select a customer to whom to assign a new order.
*
* @ingroup forms
* @see uc_order_create_form_submit()
*/
function uc_order_create_form() {
$form['customer'] = array(
'#type' => 'fieldset',
'#title' => t('New order customer'),
'#description' => t('Use the buttons above to have these fields filled in or just submit the form with the fields blank to create a blank order.'),
'#collapsible' => FALSE,
);
$form['customer']['uid'] = array(
'#type' => 'hidden',
'#default_value' => 0,
);
$form['customer']['text']['uid_text'] = array(
'#type' => 'textfield',
'#title' => t('Customer number'),
'#default_value' => 0,
'#maxlength' => 10,
'#size' => 10,
'#disabled' => TRUE,
);
$form['customer']['primary_email'] = array(
'#type' => 'hidden',
'#default_value' => '',
);
$form['customer']['text']['primary_email_text'] = array(
'#type' => 'textfield',
'#title' => t('Primary e-mail'),
'#default_value' => '',
'#maxlength' => 64,
'#size' => 32,
'#disabled' => TRUE,
);
$form['create'] = array(
'#type' => 'submit',
'#value' => t('Create order'),
);
return $form;
}
/**
* @see uc_order_create_form()
*/
function uc_order_create_form_submit($form, &$form_state) {
global $user;
$order = uc_order_new($form_state['values']['uid'], 'post_checkout');
uc_order_comment_save($order->order_id, $user->uid, t('Order created by the administration.'), 'admin');
$form_state['redirect'] = 'admin/store/orders/'. $order->order_id .'/edit';
}
/**
* Display a search form to browse all received orders.
*/
function uc_order_usearch() {
$output = drupal_get_form('uc_order_search_form');
if (arg(4) == 'results') {
$output .= '
'. t('Search returned the following results:') .'
';
$billing_first_name = strtolower(str_replace('*', '%', check_plain(arg(5))));
$billing_last_name = strtolower(str_replace('*', '%', check_plain(arg(6))));
$billing_company = strtolower(str_replace('*', '%', check_plain(arg(7))));
$shipping_first_name = strtolower(str_replace('*', '%', check_plain(arg(8))));
$shipping_last_name = strtolower(str_replace('*', '%', check_plain(arg(9))));
$shipping_company = strtolower(str_replace('*', '%', check_plain(arg(10))));
$start_date = check_plain(arg(11));
$end_date = check_plain(arg(12));
$args = array();
if ($billing_first_name !== '0' && $billing_first_name !== '%') {
$where .= " AND LOWER(o.billing_first_name) LIKE '%s'";
$args[] = $billing_first_name;
}
if ($billing_last_name !== '0' && $billing_last_name !== '%') {
$where .= " AND LOWER(o.billing_last_name) LIKE '%s'";
$args[] = $billing_last_name;
}
if ($billing_company !== '0' && $billing_company !== '%') {
$where .= " AND LOWER(o.billing_company) LIKE '%s'";
$args[] = $billing_company;
}
if ($shipping_first_name !== '0' && $shipping_first_name !== '%') {
$where .= " AND LOWER(o.delivery_first_name) LIKE '%s'";
$args[] = $shipping_first_name;
}
if ($shipping_last_name !== '0' && $shipping_last_name !== '%') {
$where .= " AND LOWER(o.delivery_last_name) LIKE '%s'";
$args[] = $shipping_last_name;
}
if ($shipping_company !== '0' && $shipping_company !== '%') {
$where .= " AND LOWER(o.delivery_company) LIKE '%s'";
$args[] = $shipping_company;
}
if ($start_date !== '0') {
$where .= " AND o.created >= %d";
$args[] = $start_date;
}
if ($end_date !== '0') {
$where .= " AND o.created <= %d";
$args[] = $end_date;
}
$sql = 'SELECT o.order_id, o.billing_first_name, o.billing_last_name, o.order_total, '
.'o.order_status, o.created, os.title FROM {uc_orders} o LEFT JOIN {uc_order_statuses} os '
.'ON o.order_status = os.order_status_id WHERE o.order_status NOT IN '. uc_order_status_list('specific', TRUE)
. $where .' ORDER BY o.created DESC';
$output .= uc_order_admin($sql, $args, TRUE);
}
return $output;
}
/**
* Display a form to select a previously entered address.
*
* @see uc_order_address_book_form()
*/
function uc_order_address_book() {
$uid = intval($_POST['uid']);
$type = $_POST['type'];
$func = $_POST['func'];
print drupal_get_form('uc_order_address_book_form', $uid, $type, $func);
exit();
}
/**
* Present previously entered addresses as selectable options.
*
* @ingroup forms
* @see uc_order_address_book()
*/
function uc_order_address_book_form($form_state, $uid = 0, $type = 'billing', $func = '') {
$select = uc_select_address($uid, $type, $func);
if ($uid == 0) {
$form['desc'] = array('#value' => ' '. t('You must select a customer before address information is available. ') .' ');
}
elseif (is_null($select)) {
$form['desc'] = array('#value' => ' '. t('No addresses found for customer.') .' ');
}
else {
$form['addresses'] = uc_select_address($uid, $type, $func, t('Select an address'));
$form['addresses']['#prefix'] = '
';
$form['addresses']['#suffix'] = '
';
}
$form['close'] = array(
'#type' => 'button',
'#value' => t('Close'),
'#attributes' => array('onclick' => "return close_address_select('#". $type ."_address_select');"),
);
return $form;
}
/**
* Present the customer search results and let one of them be chosen.
*
* @see uc_order_select_customer_form()
*/
function uc_order_select_customer($email = NULL) {
$options = NULL;
// Return the search results and let them pick one!
if (arg(4) == 'search') {
$first_name = strtolower(str_replace('*', '%', $_POST['first_name']));
$last_name = strtolower(str_replace('*', '%', $_POST['last_name']));
$email = strtolower(str_replace('*', '%', $_POST['email']));
if ($first_name && $first_name !== '%') {
$where .= " AND LOWER(o.billing_first_name) LIKE '". db_escape_string($first_name) ."'";
}
if ($last_name && $last_name !== '%') {
$where .= " AND LOWER(o.billing_last_name) LIKE '". db_escape_string($last_name) ."'";
}
if ($email && $email !== '%') {
$where .= " AND (LOWER(o.primary_email) LIKE '". db_escape_string($email) ."' OR LOWER(u.mail) LIKE '"
. db_escape_string($email) ."')";
}
$query = "SELECT DISTINCT u.uid, u.mail, o.billing_first_name, "
."o.billing_last_name FROM {users} AS u LEFT JOIN {uc_orders} "
."AS o ON u.uid = o.uid WHERE u.uid > 0 AND (o.order_status "
."IS NULL OR o.order_status IN ". uc_order_status_list('general', TRUE) .")". $where
." ORDER BY o.billing_last_name ASC";
$result = db_query($query);
$options = array();
while ($user = db_fetch_object($result)) {
if (empty($user->billing_first_name) && empty($user->billing_last_name)) {
$name = '';
}
else {
$name = $user->billing_last_name .', '. $user->billing_first_name .' ';
}
$options[$user->uid .':'. $user->mail] = $name .'('. $user->mail .')';
}
if (count($options) == 0) {
$output .= '
'. t('Search returned no results.') .'
';
$options = NULL;
}
else {
$output .= '
'. t('Search returned the following:') .'
';
}
}
// Check to see if the e-mail address for a new user is unique.
if (arg(5) == 'check') {
$email = $_POST['email'];
if (!valid_email_address($email)) {
$output .= t('Invalid e-mail address.') .' ';
}
$result = db_query("SELECT uid, mail FROM {users} WHERE mail = '%s'", $email);
if ($user = db_fetch_object($result)) {
$output .= t('An account already exists for that e-mail.') .'
';
}
}
$output .= drupal_get_form('uc_order_select_customer_form', $options);
print $output;
exit();
}
/**
* Form to choose a customer from a list.
*
* @ingroup forms
* @see uc_order_select_customer()
*/
function uc_order_select_customer_form($form_state, $options = NULL) {
if (is_null(arg(4))) {
$form['desc'] = array(
'#value' => '
'. t('Search for a customer based on these fields.')
.' '. t('Use * as a wildcard to match any character.') .' '
.'('. t('Leave a field empty to ignore it in the search.')
.')