function simple_package_tracking_order_tracking_numbers_view in Simple Package Tracking 7
3 calls to simple_package_tracking_order_tracking_numbers_view()
File
- ./
simple_package_tracking.module, line 824
Code
function simple_package_tracking_order_tracking_numbers_view($order, $view_mode, $confirmed_delete_id = -1, $confirmed_action_id = -1, &$click = NULL) {
$query = db_select('tracking_numbers', 'n')
->fields('n', array(
'tracking_id',
'tracking_number',
'tracking_carrier',
'tracking_url',
'tracking_note',
))
->condition('order_id', $order->order_id, '=')
->execute();
$rows = array();
$nums = array();
// for duplicate test
$unique = 1;
// for duplicate test
$click_message = FALSE;
while ($tracking = $query
->fetchObject()) {
$row = array();
$row[] = $tracking->tracking_carrier != NULL ? $tracking->tracking_carrier : t('Other');
if ($tracking->tracking_number != '') {
$row[] = l($tracking->tracking_number, $tracking->tracking_url, array(
'attributes' => array(
'target' => '_blank',
),
));
$nums[] = $tracking->tracking_number;
$click_message = TRUE;
}
else {
$row[] = t('No tracking available');
$nums[] = 'ignore' . $unique++;
}
$row[] = $tracking->tracking_note;
if (user_access('administer commerce_order entities')) {
drupal_add_library('system', 'drupal.ajax');
if ($tracking->tracking_id == $confirmed_delete_id) {
// This item has been clicked once for deletion on a second click
$row[] = '<div>' . t('Do you really want to delete this number?') . '<br />' . l(t('Yes, delete for real!'), 'simple_package_tracking_number_delete_callback/' . $order->order_id . '/' . $tracking->tracking_id . '/nojs/', array(
'attributes' => array(
'class' => array(
'use-ajax',
'tracking-delete-confirm',
),
),
)) . '<br />' . t('(If not, simply ignore this question.)') . '</div>';
}
else {
// This item has NOT been clicked once for deletion, so go to a confirmation message
$row[] = '<div>' . l(t('Delete'), 'simple_package_tracking_number_delete_confirm_callback/' . $order->order_id . '/' . $tracking->tracking_id . '/nojs/', array(
'attributes' => array(
'class' => array(
'use-ajax',
'tracking-delete-confirm',
),
),
)) . '</div>';
}
if ($tracking->tracking_id == $confirmed_action_id) {
// This item has been clicked once to redo actions on a second click
$row[] = '<div>' . t('Do you really want to repeat the actions for this number?') . '<br />' . l(t('Yes, redo the actions.'), 'simple_package_tracking_number_action_callback/' . $order->order_id . '/' . $tracking->tracking_id . '/nojs/', array(
'attributes' => array(
'class' => array(
'use-ajax',
'tracking-delete-confirm',
),
),
)) . '<br />' . t('(If not, simply ignore this question.)') . '</div>';
}
else {
// This item has NOT been clicked once for redo actions, so go to a confirmation message
$row[] = '<div>' . l(t('Redo actions'), 'simple_package_tracking_number_action_confirm_callback/' . $order->order_id . '/' . $tracking->tracking_id . '/nojs/', array(
'attributes' => array(
'class' => array(
'use-ajax',
'tracking-delete-confirm',
),
),
)) . '</div>';
}
}
$rows[] = $row;
}
$n = count($rows);
if ($n === 0) {
// If you want a message when no tracking is available, comment out
// the following 'return NULL;' line and un-comment the next two lines.
return NULL;
//$row = array('No tracking information is available yet');
//$rows = array($row);
}
if ($view_mode != 'customer') {
// Mark duplicates
$dups = array();
for ($i = 0; $i < $n; ++$i) {
for ($j = 0; $j < $n; ++$j) {
if ($i == $j) {
continue;
}
//if (strcmp($rows[$i][1], $rows[$j][1]) == 0) {
if (strcmp($nums[$i], $nums[$j]) == 0) {
$dups[] = $i;
break;
}
}
}
foreach ($dups as $d) {
$rows[$d][1] .= ' <b>(' . t('duplicate') . ')</b>';
}
}
$headers = array();
$output = theme('table', array(
'header' => $headers,
'rows' => $rows,
));
if (!is_null($click)) {
$click = $click_message;
}
return $output;
}