Skip navigation
Help

uc_order.admin.inc

  1. drupal
    1. 6 ubercart/uc_order/uc_order.admin.inc
    2. 7 ubercart/uc_order/uc_order.admin.inc

Order administration menu items.

Functions & methods

NameDescription
theme_uc_order_edit_formFormats the uc_order_edit_form().
theme_uc_order_state_tableThemes the order state table in the order workflow settings.
theme_uc_order_status_tableThemes the order status table in the order workflow settings.
uc_order_address_bookDisplays a form to select a previously entered address.
uc_order_address_book_formPresents previously entered addresses as selectable options.
uc_order_add_line_item_formForm to add a line item to an order.
uc_order_add_line_item_form_submitForm submission handler for uc_order_add_line_item_form().
uc_order_add_line_item_form_validateValidates new line item data.
uc_order_create_formCreates a new order and redirect to its edit screen.
uc_order_create_form_create_submitForm submission handler for customer search.
uc_order_create_form_create_validateForm validation handler for customer search.
uc_order_create_form_customerAjax callback: updates the customer selection fields.
uc_order_create_form_customer_searchAjax callback: updates the customer search results.
uc_order_create_for_userCreates a new order for the specified customer, ready for editing.
uc_order_customersRedirects to the customers listing page.
uc_order_delete_confirm_formConfirmation form to delete an order.
uc_order_delete_confirm_form_submitForm submission handler for uc_order_delete_confirm_form().
uc_order_edit_formDisplays the order edit screen, constructed via hook_uc_order_pane().
uc_order_edit_form_deleteHandles order delete button action.
uc_order_edit_form_submitForm submission handler for uc_order_edit_form().
uc_order_edit_form_validatePrevents order edits from colliding.
uc_order_historyReturns the sortable table listing of a customer's orders.
uc_order_logDisplays a log of changes made to an order.
uc_order_mail_invoice_formSets recipients of an invoice, then mails it.
uc_order_mail_invoice_form_submitForm submission handler for uc_order_mail_invoice_form().
uc_order_mail_invoice_form_validateOnly mail invoices to valid email addresses.
uc_order_ordersRedirects to the orders listing page.
uc_order_select_customerPresents the customer search results and let one of them be chosen.
uc_order_select_customer_formForm to choose a customer from a list.
uc_order_settings_formGenerates the settings form for orders.
uc_order_status_create_formPresents the form to create a custom order status.
uc_order_status_create_form_submitForm submission handler for uc_order_status_create_form_submit().
uc_order_status_create_form_validateEnsures the new status id is unique and has no spaces.
uc_order_workflow_formDisplays the order workflow form for order state and status customization.
uc_order_workflow_form_submitForm submission handler for uc_order_workflow_form().

File

ubercart/uc_order/uc_order.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Order administration menu items.
  5. */
  6. /**
  7. * Redirects to the customers listing page.
  8. */
  9. function uc_order_customers() {
  10. drupal_goto('admin/store/customers/view');
  11. }
  12. /**
  13. * Redirects to the orders listing page.
  14. */
  15. function uc_order_orders() {
  16. drupal_goto('admin/store/orders/view');
  17. }
  18. /**
  19. * Generates the settings form for orders.
  20. *
  21. * @ingroup forms
  22. */
  23. function uc_order_settings_form($form, &$form_state) {
  24. $form['invoice']['uc_cust_order_invoice_template'] = array(
  25. '#type' => 'select',
  26. '#title' => t('On-site invoice template'),
  27. '#description' => t('Select the invoice template to use when invoices are viewed on the site.'),
  28. '#options' => uc_order_template_options(),
  29. '#default_value' => variable_get('uc_cust_order_invoice_template', 'customer'),
  30. );
  31. if (module_exists('uc_cart')) {
  32. $form['invoice']['uc_cust_order_invoice_template']['#description'] .= '<br />' . t('This is separate from the template used to e-mail invoices to customers which is configured through <a href="!url">Rules</a>.', array('!url' => url('admin/store/settings/checkout/rules')));
  33. }
  34. return system_settings_form($form);
  35. }
  36. /**
  37. * Displays the order workflow form for order state and status customization.
  38. *
  39. * @see uc_order_workflow_form_submit()
  40. * @see theme_uc_order_state_table()
  41. * @see theme_uc_order_status_table()
  42. *
  43. * @ingroup forms
  44. */
  45. function uc_order_workflow_form($form, &$form_state) {
  46. $states = uc_order_state_list();
  47. $statuses = uc_order_status_list();
  48. $form['order_states'] = array(
  49. '#type' => 'fieldset',
  50. '#title' => t('Order states'),
  51. '#collapsible' => TRUE,
  52. '#collapsed' => TRUE,
  53. '#theme' => 'uc_order_state_table',
  54. '#tree' => TRUE,
  55. );
  56. foreach ($states as $state_id => $state) {
  57. $form['order_states'][$state_id]['title'] = array(
  58. '#markup' => $state['title'],
  59. );
  60. // Create the select box for specifying a default status per order state.
  61. $options = array();
  62. foreach ($statuses as $status) {
  63. if ($status['state'] == $state_id) {
  64. $options[$status['id']] = $status['title'];
  65. }
  66. }
  67. if (empty($options)) {
  68. $form['order_states'][$state_id]['default'] = array(
  69. '#markup' => t('- N/A -'),
  70. );
  71. }
  72. else {
  73. $form['order_states'][$state_id]['default'] = array(
  74. '#type' => 'select',
  75. '#options' => $options,
  76. '#default_value' => uc_order_state_default($state_id),
  77. );
  78. }
  79. }
  80. $form['order_statuses'] = array(
  81. '#type' => 'fieldset',
  82. '#title' => t('Order statuses'),
  83. '#collapsible' => FALSE,
  84. '#theme' => 'uc_order_status_table',
  85. '#tree' => TRUE,
  86. );
  87. // Build the state option array for the order status table.
  88. $options = array();
  89. foreach ($states as $state_id => $state) {
  90. $options[$state_id] = $state['title'];
  91. }
  92. foreach ($statuses as $status) {
  93. $form['order_statuses'][$status['id']]['id'] = array(
  94. '#markup' => $status['id'],
  95. );
  96. $form['order_statuses'][$status['id']]['title'] = array(
  97. '#type' => 'textfield',
  98. '#default_value' => $status['title'],
  99. '#size' => 32,
  100. '#required' => TRUE,
  101. );
  102. $form['order_statuses'][$status['id']]['weight'] = array(
  103. '#type' => 'weight',
  104. '#delta' => 20,
  105. '#default_value' => $status['weight'],
  106. );
  107. $form['order_statuses'][$status['id']]['locked'] = array(
  108. '#type' => 'value',
  109. '#value' => $status['locked'],
  110. );
  111. if ($status['locked']) {
  112. $form['order_statuses'][$status['id']]['state'] = array(
  113. '#markup' => uc_order_state_data($status['state'], 'title'),
  114. );
  115. }
  116. else {
  117. $form['order_statuses'][$status['id']]['state'] = array(
  118. '#type' => 'select',
  119. '#options' => $options,
  120. '#default_value' => $status['state'],
  121. );
  122. $form['order_statuses'][$status['id']]['remove'] = array(
  123. '#type' => 'checkbox',
  124. );
  125. }
  126. }
  127. $form['actions'] = array('#type' => 'actions');
  128. $form['actions']['submit'] = array(
  129. '#type' => 'submit',
  130. '#value' => t('Submit changes'),
  131. );
  132. return $form;
  133. }
  134. /**
  135. * Form submission handler for uc_order_workflow_form().
  136. *
  137. * @see uc_order_workflow_form()
  138. */
  139. function uc_order_workflow_form_submit($form, &$form_state) {
  140. foreach ($form_state['values']['order_states'] as $key => $value) {
  141. variable_set('uc_state_' . $key . '_default', $value['default']);
  142. }
  143. foreach ($form_state['values']['order_statuses'] as $key => $value) {
  144. if ($value['locked'] != TRUE && $value['remove'] == TRUE) {
  145. db_delete('uc_order_statuses')
  146. ->condition('order_status_id', $key)
  147. ->execute();
  148. drupal_set_message(t('Order status %status removed.', array('%status' => $key)));
  149. }
  150. else {
  151. $fields = array(
  152. 'title' => $value['title'],
  153. 'weight' => $value['weight'],
  154. );
  155. // The state cannot be changed if the status is locked.
  156. if ($value['locked'] == FALSE) {
  157. $fields['state'] = $value['state'];
  158. }
  159. $query = db_update('uc_order_statuses')
  160. ->fields($fields)
  161. ->condition('order_status_id', $key)
  162. ->execute();
  163. }
  164. }
  165. drupal_set_message(t('Order workflow information saved.'));
  166. }
  167. /**
  168. * Themes the order state table in the order workflow settings.
  169. *
  170. * @see uc_order_workflow_form()
  171. *
  172. * @ingroup themeable
  173. */
  174. function theme_uc_order_state_table($variables) {
  175. $form = $variables['form'];
  176. $header = array(t('State'), t('Default order status'));
  177. foreach (element_children($form) as $state_id) {
  178. $rows[] = array(
  179. drupal_render($form[$state_id]['title']),
  180. drupal_render($form[$state_id]['default']),
  181. );
  182. }
  183. return theme('table', array('header' => $header, 'rows' => $rows));
  184. }
  185. /**
  186. * Themes the order status table in the order workflow settings.
  187. *
  188. * @see uc_order_workflow_form()
  189. *
  190. * @ingroup themeable
  191. */
  192. function theme_uc_order_status_table($variables) {
  193. $form = $variables['form'];
  194. $header = array(t('ID'), t('Title'), t('List position'), t('State'), t('Remove'));
  195. foreach (element_children($form) as $state_id) {
  196. $rows[] = array(
  197. drupal_render($form[$state_id]['id']),
  198. drupal_render($form[$state_id]['title']),
  199. drupal_render($form[$state_id]['weight']),
  200. drupal_render($form[$state_id]['state']),
  201. array('data' => drupal_render($form[$state_id]['remove']), 'align' => 'center'),
  202. );
  203. }
  204. return theme('table', array('header' => $header, 'rows' => $rows));
  205. }
  206. /**
  207. * Presents the form to create a custom order status.
  208. *
  209. * @see uc_order_status_create_form_validate()
  210. * @see uc_order_status_create_form_submit()
  211. *
  212. * @ingroup forms
  213. */
  214. function uc_order_status_create_form($form, &$form_state) {
  215. $form['status_id'] = array(
  216. '#type' => 'textfield',
  217. '#title' => t('Order status ID'),
  218. '#description' => t('Must be a unique ID with no spaces.'),
  219. '#size' => 32,
  220. '#maxlength' => 32,
  221. '#required' => TRUE,
  222. );
  223. $form['status_title'] = array(
  224. '#type' => 'textfield',
  225. '#title' => t('Title'),
  226. '#description' => t('The order status title displayed to users.'),
  227. '#size' => 32,
  228. '#maxlength' => 48,
  229. '#required' => TRUE,
  230. );
  231. // Build the state option array for the order status table.
  232. $options = array();
  233. foreach (uc_order_state_list() as $state) {
  234. $options[$state['id']] = $state['title'];
  235. }
  236. $form['status_state'] = array(
  237. '#type' => 'select',
  238. '#title' => t('Order state'),
  239. '#description' => t('Set which order state this status is for.'),
  240. '#options' => $options,
  241. '#default_value' => 'post_checkout',
  242. );
  243. $form['status_weight'] = array(
  244. '#type' => 'weight',
  245. '#title' => t('List position'),
  246. '#delta' => 20,
  247. '#default_value' => 0,
  248. );
  249. $form['actions'] = array('#type' => 'actions');
  250. $form['actions']['create'] = array(
  251. '#type' => 'submit',
  252. '#value' => t('Create'),
  253. );
  254. $form['actions']['cancel'] = array(
  255. '#markup' => l(t('Cancel'), 'admin/store/settings/orders/workflow'),
  256. );
  257. return $form;
  258. }
  259. /**
  260. * Ensures the new status id is unique and has no spaces.
  261. *
  262. * @see uc_order_status_create_form()
  263. * @see uc_order_status_create_form_submit()
  264. */
  265. function uc_order_status_create_form_validate($form, &$form_state) {
  266. $new_status = strtolower(trim($form_state['values']['status_id']));
  267. if (strpos($new_status, ' ') !== FALSE || $new_status == 'all') {
  268. form_set_error('status_id', t('You have entered an invalid status ID.'));
  269. }
  270. $statuses = uc_order_status_list();
  271. foreach ($statuses as $status) {
  272. if ($new_status == $status['id']) {
  273. form_set_error('status_id', t('This ID is already in use. Please specify a unique ID.'));
  274. }
  275. }
  276. }
  277. /**
  278. * Form submission handler for uc_order_status_create_form_submit().
  279. *
  280. * @see uc_order_status_create_form()
  281. * @see uc_order_status_create_form_validate()
  282. */
  283. function uc_order_status_create_form_submit($form, &$form_state) {
  284. db_insert('uc_order_statuses')
  285. ->fields(array(
  286. 'order_status_id' => $form_state['values']['status_id'],
  287. 'title' => $form_state['values']['status_title'],
  288. 'state' => $form_state['values']['status_state'],
  289. 'weight' => $form_state['values']['status_weight'],
  290. 'locked' => 0,
  291. ))
  292. ->execute();
  293. drupal_set_message(t('Custom order status created.'));
  294. $form_state['redirect'] = 'admin/store/settings/orders/workflow';
  295. }
  296. /**
  297. * Creates a new order and redirect to its edit screen.
  298. *
  299. * @see uc_order_create_form_create_validate()
  300. * @see uc_order_create_form_create_submit()
  301. *
  302. * @ingroup forms
  303. */
  304. function uc_order_create_form($form, &$form_state) {
  305. $form['customer_type'] = array(
  306. '#type' => 'radios',
  307. '#options' => array(
  308. 'search' => t('Search for an existing customer.'),
  309. 'create' => t('Create a new customer account.'),
  310. 'none' => t('No customer account required.'),
  311. ),
  312. '#required' => TRUE,
  313. '#default_value' => 'search',
  314. '#ajax' => array(
  315. 'callback' => 'uc_order_create_form_customer',
  316. 'wrapper' => 'uc-order-customer',
  317. 'progress' => array('type' => 'throbber'),
  318. ),
  319. );
  320. $form['customer'] = array(
  321. '#prefix' => '<div id="uc-order-customer">',
  322. '#suffix' => '</div>',
  323. '#tree' => TRUE,
  324. );
  325. // Create form elements needed for customer search.
  326. // Shown only when the 'Search for an existing customer.' radio is selected.
  327. if (!isset($form_state['values']['customer_type']) ||
  328. $form_state['values']['customer_type'] == 'search') {
  329. // Container for customer search fields.
  330. $form['customer'] += array(
  331. '#type' => 'fieldset',
  332. '#title' => t('Customer search'),
  333. '#description' => t('Enter full or partial information in one or more of the following fields, then press the "Search" button. Search results will match all the provided information.'),
  334. );
  335. // Customer first name.
  336. $form['customer']['first_name'] = array(
  337. '#type' => 'textfield',
  338. '#title' => t('First name'),
  339. '#size' => 24,
  340. '#maxlength' => 32,
  341. );
  342. // Customer last name.
  343. $form['customer']['last_name'] = array(
  344. '#type' => 'textfield',
  345. '#title' => t('Last name'),
  346. '#size' => 24,
  347. '#maxlength' => 32,
  348. );
  349. // Customer e-mail address.
  350. $form['customer']['email'] = array(
  351. '#type' => 'textfield',
  352. '#title' => t('E-mail'),
  353. '#size' => 24,
  354. '#maxlength' => 96,
  355. );
  356. // Customer username.
  357. $form['customer']['username'] = array(
  358. '#type' => 'textfield',
  359. '#title' => t('Username'),
  360. '#size' => 24,
  361. '#maxlength' => 96,
  362. );
  363. $form['customer']['search'] = array(
  364. '#type' => 'button',
  365. '#value' => t('Search'),
  366. '#ajax' => array(
  367. 'callback' => 'uc_order_create_form_customer_search',
  368. 'wrapper' => 'uc-order-customer-results',
  369. 'progress' => array('type' => 'throbber'),
  370. ),
  371. );
  372. $form['customer']['uid'] = array(
  373. '#prefix' => '<div id="uc-order-customer-results">',
  374. '#suffix' => '</div>',
  375. );
  376. // Search for existing customer by e-mail address.
  377. if (isset($form_state['values']['customer']['email'])) {
  378. $query = db_select('users', 'u')->distinct();
  379. $query->leftJoin('uc_orders', 'o', 'u.uid = o.uid');
  380. $query->fields('u', array('uid', 'name', 'mail'))
  381. ->fields('o', array('billing_first_name', 'billing_last_name'))
  382. ->condition('u.uid', 0, '>')
  383. ->condition(db_or()
  384. ->isNull('o.billing_first_name')
  385. ->condition('o.billing_first_name', db_like(trim($form_state['values']['customer']['first_name'])) . '%', 'LIKE')
  386. )
  387. ->condition(db_or()
  388. ->isNull('o.billing_last_name')
  389. ->condition('o.billing_last_name', db_like(trim($form_state['values']['customer']['last_name'])) . '%', 'LIKE')
  390. )
  391. ->condition(db_or()
  392. ->condition('o.primary_email', db_like(trim($form_state['values']['customer']['email'])) . '%', 'LIKE')
  393. ->condition('u.mail', db_like(trim($form_state['values']['customer']['email'])) . '%', 'LIKE')
  394. )
  395. ->condition('u.name', db_like(trim($form_state['values']['customer']['username'])) . '%', 'LIKE')
  396. ->orderBy('o.created', 'DESC')
  397. ->range(0, $limit = 11);
  398. $result = $query->execute();
  399. $options = array();
  400. foreach ($result as $user) {
  401. $name = '';
  402. if (!empty($user->billing_first_name) && !empty($user->billing_last_name)) {
  403. $name = $user->billing_first_name . ' ' . $user->billing_last_name . ' ';
  404. }
  405. // Options formated as "First Last <email@example.com> (username)".
  406. $options[$user->uid] = $name . '&lt;' . $user->mail . '&gt;' . ' (' . $user->name . ')';
  407. }
  408. $max = FALSE;
  409. if (count($options) == $limit) {
  410. array_pop($options);
  411. $max = TRUE;
  412. }
  413. if (!empty($options)) {
  414. // Display search results.
  415. $form['customer']['uid'] += array(
  416. '#type' => 'radios',
  417. '#title' => t('Select customer'),
  418. '#description' => $max ? t('More than !limit results found. Refine your search to find other customers.', array('!limit' => $limit - 1)) : '',
  419. '#options' => $options,
  420. '#default_value' => key($options),
  421. );
  422. }
  423. else {
  424. // No search results found.
  425. $form['customer']['uid'] += array(
  426. '#markup' => '<p>' . t('Search returned no results.') . '</p>',
  427. );
  428. }
  429. }
  430. }
  431. // Create form elements needed for new customer creation.
  432. // Shown only when the 'Create a new customer account.' radio is selected.
  433. elseif ($form_state['values']['customer_type'] == 'create') {
  434. // Container for new customer information.
  435. $form['customer'] += array(
  436. '#type' => 'fieldset',
  437. '#title' => t('New customer details'),
  438. );
  439. // Customer e-mail address.
  440. $form['customer']['email'] = array(
  441. '#type' => 'textfield',
  442. '#title' => t('Customer e-mail address'),
  443. '#size' => 24,
  444. '#maxlength' => 96,
  445. );
  446. // Option to notify customer.
  447. $form['customer']['sendmail'] = array(
  448. '#type' => 'checkbox',
  449. '#title' => t('E-mail account details to customer.'),
  450. );
  451. }
  452. $form['actions'] = array('#type' => 'actions');
  453. $form['actions']['submit'] = array(
  454. '#type' => 'submit',
  455. '#value' => t('Create order'),
  456. '#validate' => array('uc_order_create_form_create_validate'),
  457. '#submit' => array('uc_order_create_form_create_submit'),
  458. );
  459. return $form;
  460. }
  461. /**
  462. * Ajax callback: updates the customer selection fields.
  463. */
  464. function uc_order_create_form_customer($form, &$form_state) {
  465. return $form['customer'];
  466. }
  467. /**
  468. * Ajax callback: updates the customer search results.
  469. */
  470. function uc_order_create_form_customer_search($form, &$form_state) {
  471. return $form['customer']['uid'];
  472. }
  473. /**
  474. * Form validation handler for customer search.
  475. *
  476. * @see uc_order_create_form()
  477. *
  478. * @ingroup forms
  479. */
  480. function uc_order_create_form_create_validate($form, &$form_state) {
  481. switch ($form_state['values']['customer_type']) {
  482. case 'search':
  483. if (empty($form_state['values']['customer']['uid'])) {
  484. form_set_error('customer][uid', t('Please select a customer.'));
  485. }
  486. break;
  487. case 'create':
  488. $email = trim($form_state['values']['customer']['email']);
  489. if (!valid_email_address($email)) {
  490. form_set_error('customer][mail', t('Invalid e-mail address.'));
  491. }
  492. $uid = db_query('SELECT uid FROM {users} WHERE mail LIKE :mail', array(':mail' => $email))->fetchField();
  493. if ($uid) {
  494. form_set_error('customer][mail', t('An account already exists for that e-mail.'));
  495. }
  496. break;
  497. }
  498. }
  499. /**
  500. * Form submission handler for customer search.
  501. *
  502. * @see uc_order_create_form()
  503. *
  504. * @ingroup forms
  505. */
  506. function uc_order_create_form_create_submit($form, &$form_state) {
  507. global $user;
  508. switch ($form_state['values']['customer_type']) {
  509. case 'search':
  510. $uid = $form_state['values']['customer']['uid'];
  511. break;
  512. case 'create':
  513. // Create new account.
  514. $email = trim($form_state['values']['customer']['email']);
  515. $fields = array(
  516. 'name' => uc_store_email_to_username($email),
  517. 'mail' => $email,
  518. 'pass' => user_password(),
  519. 'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0,
  520. );
  521. $account = user_save(NULL, $fields);
  522. $uid = $account->uid;
  523. if ($form_state['values']['customer']['sendmail']) {
  524. // Manually set the password so it appears in the e-mail.
  525. $account->password = $fields['pass'];
  526. drupal_mail('user', 'register_admin_created', $email, uc_store_mail_recipient_language($email), array('account' => $account), uc_store_email_from());
  527. drupal_set_message(t('A welcome message has been e-mailed to the new user.'));
  528. }
  529. break;
  530. default:
  531. $uid = 0;
  532. }
  533. $order = uc_order_new($uid, 'post_checkout');
  534. uc_order_comment_save($order->order_id, $user->uid, t('Order created by the administration.'), 'admin');
  535. $form_state['redirect'] = 'admin/store/orders/' . $order->order_id . '/edit';
  536. }
  537. /**
  538. * Creates a new order for the specified customer, ready for editing.
  539. */
  540. function uc_order_create_for_user($account) {
  541. global $user;
  542. $order = uc_order_new($account->uid, 'post_checkout');
  543. uc_order_comment_save($order->order_id, $user->uid, t('Order created by the administration.'), 'admin');
  544. drupal_goto('admin/store/orders/' . $order->order_id . '/edit');
  545. }
  546. /**
  547. * Displays a form to select a previously entered address.
  548. *
  549. * @see uc_order_address_book_form()
  550. */
  551. function uc_order_address_book() {
  552. $uid = intval($_POST['uid']);
  553. $type = $_POST['type'];
  554. $func = $_POST['func'];
  555. $form = drupal_get_form('uc_order_address_book_form', $uid, $type, $func);
  556. print drupal_render($form);
  557. exit();
  558. }
  559. /**
  560. * Presents previously entered addresses as selectable options.
  561. *
  562. * @see uc_order_address_book()
  563. *
  564. * @ingroup forms
  565. */
  566. function uc_order_address_book_form($form, &$form_state, $uid = 0, $type = 'billing', $func = '') {
  567. $select = uc_select_address($uid, $type, $func);
  568. if ($uid == 0) {
  569. $form['desc'] = array('#markup' => '<br />' . t('You must select a customer before address<br />information is available.<br />') . '<br />');
  570. }
  571. elseif (is_null($select)) {
  572. $form['desc'] = array('#markup' => '<br />' . t('No addresses found for customer.') . '<br />');
  573. }
  574. else {
  575. $form['addresses'] = uc_select_address($uid, $type, $func, t('Select an address'));
  576. $form['addresses']['#prefix'] = '<div style="float: left; margin-right: 1em;">';
  577. $form['addresses']['#suffix'] = '</div>';
  578. }
  579. $form['close'] = array(
  580. '#type' => 'button',
  581. '#value' => t('Close'),
  582. '#attributes' => array('onclick' => "return close_address_select('#" . $type . "_address_select');"),
  583. );
  584. return $form;
  585. }
  586. /**
  587. * Presents the customer search results and let one of them be chosen.
  588. *
  589. * @see uc_order_select_customer_form()
  590. */
  591. function uc_order_select_customer($email = NULL) {
  592. $build = array();
  593. $options = NULL;
  594. // Return the search results and let them pick one!
  595. if (arg(4) == 'search') {
  596. $first_name = str_replace('*', '%', db_like($_POST['first_name']));
  597. $last_name = str_replace('*', '%', db_like($_POST['last_name']));
  598. $email = str_replace('*', '%', db_like($_POST['email']));
  599. $query = db_select('users', 'u')->distinct();
  600. $query->leftJoin('uc_orders', 'o', 'u.uid = o.uid');
  601. $query->fields('u', array('uid', 'mail'))
  602. ->fields('o', array('billing_first_name', 'billing_last_name'))
  603. ->condition('u.uid', 0, '>')
  604. ->orderBy('o.billing_last_name');
  605. if ($first_name && $first_name !== '%') {
  606. $query->condition('o.billing_first_name', $first_name, 'LIKE');
  607. }
  608. if ($last_name && $last_name !== '%') {
  609. $query->condition('o.billing_last_name', $last_name, 'LIKE');
  610. }
  611. if ($email && $email !== '%') {
  612. $query->condition(db_or()
  613. ->condition('o.primary_email', $email, 'LIKE')
  614. ->condition('u.mail', $email, 'LIKE')
  615. );
  616. }
  617. $result = $query->execute();
  618. $options = array();
  619. foreach ($result as $user) {
  620. if (empty($user->billing_first_name) && empty($user->billing_last_name)) {
  621. $name = '';
  622. }
  623. else {
  624. $name = $user->billing_last_name . ', ' . $user->billing_first_name . ' ';
  625. }
  626. $options[$user->uid . ':' . $user->mail] = $name . '(' . $user->mail . ')';
  627. }
  628. if (count($options) == 0) {
  629. $build['description'] = array('#markup' => '<p>' . t('Search returned no results.') . '</p>');
  630. $options = NULL;
  631. }
  632. else {
  633. $build['description'] = array('<p>' . t('Search returned the following:') . '</p>');
  634. }
  635. }
  636. // Check to see if the e-mail address for a new user is unique.
  637. if (arg(5) == 'check') {
  638. $email = check_plain($_POST['email']);
  639. $build['email'] = array('#markup' => '');
  640. if (!valid_email_address($email)) {
  641. $build['email']['#markup'] .= t('Invalid e-mail address.') . '<br />';
  642. }
  643. $result = db_query("SELECT uid, mail FROM {users} WHERE mail = :mail", array(':mail' => $email));
  644. if ($user = $result->fetchObject()) {
  645. $build['email']['#markup'] .= t('An account already exists for that e-mail.') . '<br /><br />';
  646. $build['email']['#markup'] .= '<b>' . t('Use this account now?') . '</b><br />'
  647. . t('User @uid - @mail', array('@uid' => $user->uid, '@mail' => $user->mail)) . ' <input type="button" '
  648. . 'onclick="select_existing_customer(' . $user->uid . ', \''
  649. . $user->mail . '\');" value="' . t('Apply') . '" /><br /><br /><hr /><br/>';
  650. }
  651. else {
  652. $name = uc_store_email_to_username($email);
  653. $fields = array(
  654. 'name' => $name,
  655. 'mail' => $email,
  656. 'pass' => user_password(6),
  657. 'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0,
  658. );
  659. $account = user_save('', $fields);
  660. if ($_POST['sendmail'] == 'true') {
  661. // Manually set the password so it appears in the e-mail.
  662. $account->password = $fields['pass'];
  663. // Send the e-mail through the user module.
  664. drupal_mail('user', 'register_admin_created', $email, uc_store_mail_recipient_language($email), array('account' => $account), uc_store_email_from());
  665. $build['email']['#markup'] .= t('Account details sent to e-mail provided.<br /><br /><strong>Username:</strong> @username<br /><strong>Password:</strong> @password', array('@username' => $fields['name'], '@password' => $fields['pass'])) . '<br /><br />';
  666. }
  667. $build['result'] = array(
  668. '#markup' => '<strong>' . t('Use this account now?') . '</strong><br />'
  669. . t('User @uid - @mail', array('@uid' => $account->uid, '@mail' => $account->mail)) . ' <input type="button" '
  670. . 'onclick="select_existing_customer(' . $account->uid . ', \''
  671. . $account->mail . '\');" value="' . t('Apply') . '" /><br /><br /><hr /><br/>',
  672. );
  673. }
  674. }
  675. $build['customer_select_form'] = drupal_get_form('uc_order_select_customer_form', $options);
  676. print drupal_render($build);
  677. exit();
  678. }
  679. /**
  680. * Form to choose a customer from a list.
  681. *
  682. * @see uc_order_select_customer()
  683. *
  684. * @ingroup forms
  685. */
  686. function uc_order_select_customer_form($form, &$form_state, $options = NULL) {
  687. if (is_null(arg(4))) {
  688. $form['desc'] = array(
  689. '#markup' => '<div>' . t('Search for a customer based on these fields.')
  690. . '<br />' . t('Use * as a wildcard to match any character.') . '<br />'
  691. . '(<em>' . t('Leave a field empty to ignore it in the search.')
  692. . '</em>)</div>',
  693. );
  694. $form['first_name'] = array(
  695. '#type' => 'textfield',
  696. '#title' => t('First name'),
  697. '#size' => 24,
  698. '#maxlength' => 32,
  699. );
  700. $form['last_name'] = array(
  701. '#type' => 'textfield',
  702. '#title' => t('Last name'),
  703. '#size' => 24,
  704. '#maxlength' => 32,
  705. );
  706. $form['email'] = array(
  707. '#type' => 'textfield',
  708. '#title' => t('E-mail'),
  709. '#size' => 24,
  710. '#maxlength' => 96,
  711. );
  712. }
  713. elseif (arg(4) == 'search' && !is_null($options)) {
  714. $form['cust_select'] = array(
  715. '#type' => 'select',
  716. '#title' => t('Select a customer'),
  717. '#size' => 7,
  718. '#options' => $options,
  719. '#default_value' => key($options),
  720. '#attributes' => array('ondblclick' => 'return select_customer_search();'),
  721. );
  722. }
  723. elseif (arg(4) == 'new') {
  724. $form['desc'] = array(
  725. '#markup' => '<div>' . t('Enter an e-mail address for the new customer.') . '</div>',
  726. );
  727. $form['email'] = array(
  728. '#type' => 'textfield',
  729. '#title' => t('E-mail'),
  730. '#size' => 24,
  731. '#maxlength' => 96,
  732. );
  733. }
  734. $form['actions'] = array('#type' => 'actions');
  735. if (is_null(arg(4))) {
  736. $form['actions']['search'] = array(
  737. '#type' => 'submit',
  738. '#value' => t('Search'),
  739. '#attributes' => array('onclick' => 'return load_customer_search_results();'),
  740. );
  741. }
  742. elseif (arg(4) == 'search') {
  743. if (!is_null($options)) {
  744. $form['actions']['select'] = array(
  745. '#type' => 'submit',
  746. '#value' => t('Select'),
  747. '#attributes' => array('onclick' => 'return select_customer_search();'),
  748. );
  749. }
  750. $form['actions']['back'] = array(
  751. '#type' => 'submit',
  752. '#value' => t('Back'),
  753. '#attributes' => array('onclick' => 'return load_customer_search();'),
  754. );
  755. }
  756. elseif (arg(4) == 'new') {
  757. $form['sendmail'] = array(
  758. '#type' => 'checkbox',
  759. '#title' => t('E-mail customer account details.'),
  760. );
  761. $form['actions']['submit'] = array(
  762. '#type' => 'submit',
  763. '#value' => t('Submit'),
  764. '#attributes' => array('onclick' => 'return check_new_customer_address();'),
  765. );
  766. }
  767. $form['actions']['close'] = array(
  768. '#type' => 'submit',
  769. '#value' => t('Close'),
  770. '#attributes' => array('onclick' => 'return close_customer_select();'),
  771. );
  772. return $form;
  773. }
  774. /**
  775. * Returns the sortable table listing of a customer's orders.
  776. *
  777. * This function is deprecated; this listing is now provided by Views.
  778. *
  779. * @param $uid
  780. * The user ID whose orders you wish to list.
  781. */
  782. function uc_order_history($user) {
  783. drupal_set_title(t('My order history'));
  784. $header = array(
  785. array('data' => t('Date'), 'field' => 'o.created', 'sort' => 'desc'),
  786. array('data' => t('Order #'), 'field' => 'o.order_id'),
  787. array('data' => t('Status'), 'field' => 'os.title'),
  788. array('data' => t('Products'), 'field' => 'products'),
  789. array('data' => t('Total'), 'field' => 'o.order_total'),
  790. );
  791. $rows = array();
  792. $query = db_select('uc_orders', 'o');
  793. $o_order_id = $query->addField('o', 'order_id');
  794. $o_created = $query->addField('o', 'created');
  795. $o_status = $query->addField('o', 'order_status');
  796. $o_total = $query->addField('o', 'order_total');
  797. $o_uid = $query->addField('o', 'uid');
  798. $query->condition($o_uid, $user->uid)
  799. ->condition($o_status, uc_order_status_list('general', TRUE), 'IN');
  800. $count_query = $query->countQuery();
  801. $query = $query->extend('PagerDefault')->extend('TableSort');
  802. $os = $query->leftJoin('uc_order_statuses', 'os', 'o.order_status = os.order_status_id');
  803. $op = $query->leftJoin('uc_order_products', 'op', 'o.order_id = op.order_id');
  804. $os_title = $query->addField('os', 'title');
  805. $op_products = $query->addExpression('SUM(op.qty)', 'products');
  806. $query->groupBy('o.order_id')
  807. ->groupBy('o.created')
  808. ->groupBy('os.title')
  809. ->groupBy('o.order_total')
  810. ->groupBy('o.order_status')
  811. ->groupBy('o.uid')
  812. ->orderByHeader($header)
  813. ->limit(20);
  814. $query->setCountQuery($count_query);
  815. $result = $query->execute();
  816. // Build a table based on the customer's orders.
  817. foreach ($result as $order) {
  818. $link = l($order->order_id, 'user/' . $user->uid . '/orders/' . $order->order_id);
  819. if (user_access('view all orders')) {
  820. $link .= '<span class="order-admin-icons">' . uc_order_actions($order, TRUE) . '</span>';
  821. }
  822. $rows[] = array(
  823. array('data' => format_date($order->created, 'uc_store')),
  824. array('data' => $link),
  825. array('data' => check_plain($order->title)),
  826. array('data' => (!is_null($order->products) ? $order->products : 0), 'align' => 'center'),
  827. array('data' => array('#theme' => 'uc_price', '#price' => $order->order_total), 'align' => 'right'),
  828. );
  829. }
  830. $build = array();
  831. $build['orders'] = array(
  832. '#theme' => 'table',
  833. '#header' => $header,
  834. '#rows' => $rows,
  835. '#attributes' => array('class' => array('uc-order-history')),
  836. '#empty' => t('No orders available.'),
  837. );
  838. $build['pager'] = array(
  839. '#theme' => 'pager',
  840. '#element' => 0,
  841. '#weight' => 5,
  842. );
  843. return $build;
  844. }
  845. /**
  846. * Displays the order edit screen, constructed via hook_uc_order_pane().
  847. *
  848. * @see uc_order_edit_form_validate()
  849. * @see uc_order_edit_form_submit()
  850. * @see theme_uc_order_edit_form()
  851. * @see uc_order_edit_form_delete()
  852. *
  853. * @ingroup forms
  854. */
  855. function uc_order_edit_form($form, &$form_state, $order) {
  856. if (isset($form_state['order'])) {
  857. $order = $form_state['order'];
  858. }
  859. else {
  860. $form_state['order'] = $order;
  861. }
  862. $form['#order'] = $order;
  863. $form['order_id'] = array('#type' => 'hidden', '#value' => $order->order_id);
  864. $form['order_uid'] = array('#type' => 'hidden', '#value' => $order->uid);
  865. $modified = isset($form_state['values']['order_modified']) ? $form_state['values']['order_modified'] : $order->modified;
  866. $form['order_modified'] = array('#type' => 'hidden', '#value' => $modified);
  867. $panes = _uc_order_pane_list('edit');
  868. foreach ($panes as $id => $pane) {
  869. if (in_array('edit', $pane['show'])) {
  870. $func = $pane['callback'];
  871. if (function_exists($func)) {
  872. $func('edit-form', $order, $form, $form_state);
  873. }
  874. }
  875. }
  876. $form['actions'] = array('#type' => 'actions');
  877. $form['actions']['submit-changes'] = array(
  878. '#type' => 'submit',
  879. '#value' => t('Submit changes'),
  880. '#attributes' => array('class' => array('save-button')),
  881. );
  882. if (uc_order_can_delete($order)) {
  883. $form['actions']['delete'] = array(
  884. '#type' => 'submit',
  885. '#value' => t('Delete'),
  886. '#submit' => array('uc_order_edit_form_delete'),
  887. );
  888. }
  889. field_attach_form('uc_order', $order, $form, $form_state);
  890. form_load_include($form_state, 'inc', 'uc_store', 'includes/uc_ajax_attach');
  891. $form['#process'][] = 'uc_ajax_process_form';
  892. return $form;
  893. }
  894. /**
  895. * Prevents order edits from colliding.
  896. *
  897. * @see uc_order_edit_form()
  898. * @see uc_order_edit_form_submit()
  899. * @see theme_uc_order_edit_form()
  900. */
  901. function uc_order_edit_form_validate($form, &$form_state) {
  902. $order = uc_order_load($form_state['values']['order_id']);
  903. if ($form_state['values']['order_modified'] != $order->modified) {
  904. form_set_error('order_modified', t('This order has been modified by another user, changes cannot be saved.'));
  905. }
  906. entity_form_field_validate('uc_order', $form, $form_state);
  907. // Build list of changes to be applied.
  908. $panes = _uc_order_pane_list();
  909. foreach ($panes as $id => $pane) {
  910. if (in_array('edit', $pane['show'])) {
  911. $func = $pane['callback'];
  912. if (function_exists($func)) {
  913. if (($changes = $func('edit-process', $order, $form, $form_state)) != NULL) {
  914. foreach ($changes as $key => $value) {
  915. $form_state['order']->$key = $value;
  916. }
  917. }
  918. }
  919. }
  920. }
  921. }
  922. /**
  923. * Form submission handler for uc_order_edit_form().
  924. *
  925. * @see uc_order_edit_form()
  926. * @see uc_order_edit_form_validate()
  927. * @see theme_uc_order_edit_form()
  928. */
  929. function uc_order_edit_form_submit($form, &$form_state) {
  930. $order = uc_order_load($form_state['values']['order_id']);
  931. $log = array();
  932. foreach ($form_state['order'] as $key => $value) {
  933. if (!isset($order->$key) || $order->$key !== $value) {
  934. if (!is_array($value)) {
  935. $log[$key] = array('old' => $order->$key, 'new' => $value);
  936. }
  937. $order->$key = $value;
  938. }
  939. }
  940. if (module_exists('uc_stock')) {
  941. $qtys = array();
  942. foreach ($order->products as $product) {
  943. $qtys[$product->order_product_id] = $product->qty;
  944. }
  945. }
  946. $order->products = array();
  947. if (isset($form_state['values']['products']) && is_array($form_state['values']['products'])) {
  948. foreach ($form_state['values']['products'] as $product) {
  949. if (!isset($product['remove']) && intval($product['qty']) > 0) {
  950. $product['data'] = unserialize($product['data']);
  951. $product = (object) $product;
  952. $order->products[] = $product;
  953. if (module_exists('uc_stock')) {
  954. $temp = $product->qty;
  955. $product->qty = $product->qty - $qtys[$product->order_product_id];
  956. uc_stock_adjust_product_stock($product, 0, $order);
  957. $product->qty = $temp;
  958. }
  959. }
  960. else {
  961. $log['remove_' . $product['nid']] = $product['title'] . ' removed from order.';
  962. }
  963. }
  964. }
  965. // Load line items again, since some may have been updated by the form.
  966. $order->line_items = uc_order_load_line_items($order);
  967. uc_order_log_changes($order->order_id, $log);
  968. field_attach_submit('uc_order', $order, $form, $form_state);
  969. uc_order_save($order);
  970. drupal_set_message(t('Order changes saved.'));
  971. }
  972. /**
  973. * Formats the uc_order_edit_form().
  974. *
  975. * @see uc_order_edit_form()
  976. * @see uc_order_edit_form_validate()
  977. * @see uc_order_edit_form_submit()
  978. *
  979. * @ingroup themeable
  980. */
  981. function theme_uc_order_edit_form($variables) {
  982. $form = $variables['form'];
  983. $output = '';
  984. $panes = _uc_order_pane_list();
  985. foreach ($panes as $id => $pane) {
  986. if (in_array('edit', $pane['show'])) {
  987. $func = $pane['callback'];
  988. if (function_exists($func) && ($contents = $func('edit-theme', $form['#order'], $form)) != NULL) {
  989. $output .= '<div class="order-pane ' . $pane['class'] . '" id="order-pane-' . $id . '">';
  990. $title = isset($pane['display title']) ? $pane['display title'] : $pane['title'];
  991. if ($title) {
  992. $output .= '<div class="order-pane-title">' . $title . ':' . '</div>';
  993. }
  994. $output .= $contents . '</div>';
  995. }
  996. }
  997. }
  998. $last = '<div class="order-pane abs-left">' . drupal_render($form['order_id']) . drupal_render($form['order_modified'])
  999. . drupal_render($form['form_id']) . drupal_render($form['form_token'])
  1000. . drupal_render($form['form_build_id'])
  1001. . drupal_render($form['actions'])
  1002. . '</div>';
  1003. $output .= drupal_render_children($form) . $last;
  1004. return $output;
  1005. }
  1006. /**
  1007. * Handles order delete button action.
  1008. *
  1009. * @see uc_order_edit_form()
  1010. */
  1011. function uc_order_edit_form_delete($form, &$form_state) {
  1012. $form_state['redirect'] = 'admin/store/orders/' . $form_state['values']['order_id'] . '/delete';
  1013. }
  1014. /**
  1015. * Form to add a line item to an order.
  1016. *
  1017. * @see uc_order_add_line_item_form_validate()
  1018. * @see uc_order_add_line_item_submit()
  1019. */
  1020. function uc_order_add_line_item_form($form, &$form_state, $order, $line_item_id) {
  1021. $func = _uc_line_item_data($line_item_id, 'callback');
  1022. if (!function_exists($func) || ($form = $func('form', $order->order_id)) == NULL) {
  1023. $form['title'] = array(
  1024. '#type' => 'textfield',
  1025. '#title' => t('Line item title'),
  1026. '#description' => t('Display title of the line item.'),
  1027. '#size' => 32,
  1028. '#maxlength' => 128,
  1029. '#default_value' => _uc_line_item_data($line_item_id, 'title'),
  1030. );
  1031. $form['amount'] = array(
  1032. '#type' => 'uc_price',
  1033. '#title' => t('Line item amount'),
  1034. '#allow_negative' => TRUE,
  1035. );
  1036. }
  1037. $form['order_id'] = array(
  1038. '#type' => 'hidden',
  1039. '#value' => $order->order_id,
  1040. );
  1041. $form['line_item_id'] = array(
  1042. '#type' => 'hidden',
  1043. '#value' => $line_item_id,
  1044. );
  1045. $form['actions'] = array('#type' => 'actions');
  1046. $form['actions']['submit'] = array(
  1047. '#type' => 'submit',
  1048. '#value' => t('Add line item'),
  1049. '#suffix' => l(t('Cancel'), 'admin/store/orders/' . $order->order_id . '/edit'),
  1050. );
  1051. return $form;
  1052. }
  1053. /**
  1054. * Validates new line item data.
  1055. *
  1056. * @see uc_order_add_line_item_form()
  1057. */
  1058. function uc_order_add_line_item_form_validate($form, &$form_state) {
  1059. $func = _uc_line_item_data($form_state['values']['line_item_id'], 'callback');
  1060. if (function_exists($func) && ($form = $func('form', $form_state['values']['order_id'])) != NULL) {
  1061. $func('validate', $form, $form_state);
  1062. }
  1063. }
  1064. /**
  1065. * Form submission handler for uc_order_add_line_item_form().
  1066. *
  1067. * @see uc_order_add_line_item_form()
  1068. */
  1069. function uc_order_add_line_item_form_submit($form, &$form_state) {
  1070. $func = _uc_line_item_data($form_state['values']['line_item_id'], 'callback');
  1071. if (function_exists($func) && ($form = $func('form', $form_state['values']['order_id'])) != NULL) {
  1072. $func('submit', $form, $form_state);
  1073. }
  1074. else {
  1075. uc_order_line_item_add($form_state['values']['order_id'], $form_state['values']['line_item_id'], $form_state['values']['title'], $form_state['values']['amount']);
  1076. drupal_set_message(t('Line item added to order.'));
  1077. }
  1078. $form_state['redirect'] = 'admin/store/orders/' . $form_state['values']['order_id'] . '/edit';
  1079. }
  1080. /**
  1081. * Sets recipients of an invoice, then mails it.
  1082. *
  1083. * @see uc_order_mail_invoice_form_validate()
  1084. * @see uc_order_mail_invoice_form_submit()
  1085. *
  1086. * @ingroup forms
  1087. */
  1088. function uc_order_mail_invoice_form($form, &$form_state, $order) {
  1089. $form['order_id'] = array(
  1090. '#type' => 'hidden',
  1091. '#value' => $order->order_id,
  1092. );
  1093. $form['email'] = array(
  1094. '#type' => 'textfield',
  1095. '#title' => t('Recipient e-mail address'),
  1096. '#default_value' => $order->primary_email,
  1097. );
  1098. $form['actions'] = array('#type' => 'actions');
  1099. $form['actions']['submit'] = array(
  1100. '#type' => 'submit',
  1101. '#value' => t('Mail invoice'),
  1102. );
  1103. return $form;
  1104. }
  1105. /**
  1106. * Only mail invoices to valid email addresses.
  1107. *
  1108. * @see uc_order_mail_invoice_form()
  1109. */
  1110. function uc_order_mail_invoice_form_validate($form, &$form_state) {
  1111. $recipient = check_plain($form_state['values']['email']);
  1112. if (empty($recipient) || !valid_email_address($recipient)) {
  1113. form_set_error('email', t('Invalid e-mail address.'));
  1114. }
  1115. }
  1116. /**
  1117. * Form submission handler for uc_order_mail_invoice_form().
  1118. *
  1119. * @see uc_order_mail_invoice_form()
  1120. */
  1121. function uc_order_mail_invoice_form_submit($form, &$form_state) {
  1122. $order = uc_order_load($form_state['values']['order_id']);
  1123. $recipient = check_plain($form_state['values']['email']);
  1124. $params = array('order' => $order);
  1125. $sent = drupal_mail('uc_order', 'invoice', $recipient, uc_store_mail_recipient_language($recipient), $params, uc_store_email_from());
  1126. if (!$sent) {
  1127. drupal_set_message(t('E-mail failed.'));
  1128. }
  1129. else {
  1130. $message = t('Invoice e-mailed to @email.', array('@email' => $recipient));
  1131. drupal_set_message($message);
  1132. uc_order_log_changes($order->order_id, array($message));
  1133. }
  1134. }
  1135. /**
  1136. * Displays a log of changes made to an order.
  1137. */
  1138. function uc_order_log($order) {
  1139. $result = db_query("SELECT * FROM {uc_order_log} WHERE order_id = :id ORDER BY order_log_id DESC", array(':id' => $order->order_id));
  1140. $header = array(t('Time'), t('User'), t('Changes'));
  1141. $rows = array();
  1142. foreach ($result as $change) {
  1143. $rows[] = array(
  1144. format_date($change->created, 'short'),
  1145. theme('uc_uid', array('uid' => $change->uid)),
  1146. $change->changes,
  1147. );
  1148. }
  1149. $build['log'] = array(
  1150. '#theme' => 'table',
  1151. '#header' => $header,
  1152. '#rows' => $rows,
  1153. '#empty' => t('No changes have been logged for this order.'),
  1154. );
  1155. return $build;
  1156. }
  1157. /**
  1158. * Confirmation form to delete an order.
  1159. *
  1160. * @see uc_order_delete_confirm_form_submit()
  1161. *
  1162. * @ingroup forms
  1163. */
  1164. function uc_order_delete_confirm_form($form, &$form_state, $order) {
  1165. if (!uc_order_can_delete($order)) {
  1166. drupal_set_message(t('It is not possible to delete order @id.', array('@id' => $order->order_id)));
  1167. drupal_goto('admin/store/orders');
  1168. }
  1169. $form['order_id'] = array(
  1170. '#type' => 'value',
  1171. '#value' => $order->order_id,
  1172. );
  1173. return confirm_form($form, t('Are you sure you want to delete order @order_id?', array('@order_id' => $order->order_id)), 'admin/store/orders', NULL, t('Delete'));
  1174. }
  1175. /**
  1176. * Form submission handler for uc_order_delete_confirm_form().
  1177. *
  1178. * @see uc_order_delete_confirm_form()
  1179. */
  1180. function uc_order_delete_confirm_form_submit($form, &$form_state) {
  1181. // Delete the specified order.
  1182. uc_order_delete($form_state['values']['order_id']);
  1183. // Display a message to the user and return to the order admin page.
  1184. drupal_set_message(t('Order @order_id completely removed from the database.', array('@order_id' => $form_state['values']['order_id'])));
  1185. $form_state['redirect'] = 'admin/store/orders';
  1186. }