section ? $edit->section : $_GET['section']; switch (strtoupper($section)) { case 'OVERVIEW': $form = store_transaction_overview_form($edit); break; case 'ADDRESSES': $form = store_transaction_addresses_form($edit); break; case 'ITEMS': $form = store_transaction_item_form($edit); break; default: $form = array_merge(store_transaction_overview_form($edit), store_transaction_addresses_form($edit), store_transaction_item_form($edit)); } if ($edit->uid && is_numeric($edit->uid)) { $edit->uid = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $edit->uid)); } if (!empty($edit->txnid)) { $form['txnid'] = array( '#type' => 'value', '#value' => $edit->txnid, ); $form[] = array( '#type' => 'submit', '#value' => t('Update transaction') ); $form[] = array( '#type' => 'submit', '#value' => t('Delete'), ); } else { $form[] = array( '#type' => 'submit', '#value' => t('Create new transaction'), ); } $form['section'] = array( '#type' => 'value', '#value' => $section, ); return $form; } function store_transaction_form_validate($form_id, $form_values) { store_transaction_validate($form_values); } function store_transaction_validate(&$edit) { $edit['section'] = $edit['section'] ? strtoupper($edit['section']) : 'ALL'; switch ($edit['section']) { case 'OVERVIEW': store_transaction_validate_overview($edit); break; case 'ADDRESSES': store_transaction_validate_addresses($edit); break; case 'ITEMS': store_transaction_validate_item($edit); break; default: store_transaction_validate_overview($edit); store_transaction_validate_addresses($edit); store_transaction_validate_item($edit); } store_invoke_ec_transactionapi($edit, 'validate', strtoupper($edit['section'])); return ((form_get_errors()) ? FALSE : TRUE); } function store_transaction_form_submit($form_id, $form_values) { if ($form_values['op'] == t('Delete')) { $dest = drupal_get_destination(); unset($_REQUEST['destination'], $_REQUEST['edit']['destination']); return array('admin/store/transaction/delete/'. $form_values['txnid'], $dest); } else { store_transaction_save((object)$form_values); return 'admin/store/transaction'; } } // ------------------------------------------------------------------------- // Transaction items form function store_transaction_edit_items($txnid, $nid = NULL) { if (!is_numeric($txnid) || !($t = store_transaction_load($txnid))) { return drupal_not_found(); } if (is_null($nid) || !is_numeric($nid)) { return drupal_get_form('store_transaction_add_items_form', $t); } else { $p = NULL; foreach (array_keys($t->items) as $k) { $p =& $t->items[$k]; if ($p->nid == $nid) { break; } } if (is_null($p)) { return drupal_not_found(); } return drupal_get_form('store_transaction_edit_items_form', $t, $p); } } /** * Displays the form for editing a product already attached to a transaction. * * @todo: add hooks to this form for recurring etc * * @param $t Transaction * @param $p Product * @return HTML form for editing the given product as part of the given transaction. */ function store_transaction_edit_items_form(&$t, &$p) { $form['txnid'] = array( '#type' => 'value', '#value' => $t->txnid ); $form['nid'] = array( '#type' => 'value', '#value' => $p->nid ); $form['vid'] = array( '#type' => 'value', '#value' => $p->vid ); $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $p->title, '#size' => 30, '#maxlength' => 128, ); $form['qty'] = array( '#type' => 'textfield', '#title' => t('Quantity'), '#default_value' => $p->qty, '#size' => 15, '#maxlength' => 15, ); $form['data'] = array( '#type' => 'hidden', '#value' => $p->data, ); $interval = drupal_map_assoc(range(0, 31)); $interval[0] = '--'; $unit = array(0 => t('-please choose-'), 'D' => t('Day(s)'), 'W' => t('Week(s)'), 'M' => t('Month(s)'), 'Y' => t('Year(s)')); $form[] = array('#type' => 'submit', '#value' => t('Update'), '#weight' => 2); return $form; } function store_transaction_edit_items_form_submit($form_id, &$form_values) { product_transaction_save_product((object)$form_values); // Deleting the cache store_transaction_cache($form_values['txnid'], NULL, TRUE); // Fix up Gross $t = store_transaction_load($form_values['txnid']); $t->gross = store_transaction_calc_gross($t); db_query('UPDATE {ec_transaction} SET gross = %f WHERE txnid = %d', $t->gross, $t->txnid); } function store_transaction_items($txnid) { $html = store_quicklist_header(); $header = array( array('data' => t('nid'), 'field' => 'p.nid'), array('data' => t('sku'), 'field' => 'p.sku'), array('data' => t('title'), 'field' => 'stp.title', 'sort' => 'asc'), array('data' => t('qty'), 'field' => 'stp.qty'), array('data' => t('type'), 'field' => 'p.ptype') ); if ($count = db_result(db_query('SELECT COUNT(p.nid) FROM {ec_transaction_product} as stp, {ec_product} as p WHERE stp.vid = p.vid AND stp.txnid = %d', $txnid))) { $sql = 'SELECT * FROM {ec_transaction_product} as stp, {ec_product} as p WHERE stp.vid = p.vid AND stp.txnid = %d'. tablesort_sql($header); } else { $sql = 'SELECT * FROM {ec_transaction_product} as stp WHERE stp.txnid = %d'. tablesort_sql($header); } $result = pager_query($sql, 50, 0, NULL, $txnid); $num_items = 0; while ($data = db_fetch_object($result)) { ++$num_items; $qty += $data->qty; $rows[] = array($data->nid, check_plain($data->sku), l($data->title, "node/$data->nid", array('target' => '_blank')), $data->qty, $data->ptype); } $r[] = array(array('data' => 'Unique items:', 'align' => 'right'), array('data' => "$num_items")); $r[] = array(array('data' => 'Total quantity:', 'align' => 'right'), array('data' => "$qty")); $table = theme('table', NULL, $r, array('border' => 0)); $rows[] = array(array('data' => $table, 'colspan' => 5, 'align' => 'right')); $pager = theme('pager', NULL, 50, 0); if (!empty($pager)) { $rows[] = array(array('data' => $pager, 'colspan' => 5)); } echo $html; if (!empty($rows)) { echo theme('table', $header, $rows); } else { echo '
'. t('There are no transactions to view. You can manually add transactions, however.', array('!add_transaction' => 'admin/store/transaction/add')) .'
'; } echo '