function ca_admin in Ubercart 6.2
Display the administration page that lets you add and modify predicates.
File
- ca/
ca.admin.inc, line 11 - Conditional actions overview UI.
Code
function ca_admin($groupby = 'trigger') {
drupal_add_css(drupal_get_path('module', 'ca') . '/ca.css');
// Load all the module defined predicates into a temporary array.
$temp = module_invoke_all('ca_predicate');
drupal_alter('ca_predicate', $temp);
// Assign a default weight if need be.
foreach ($temp as $key => $value) {
$temp[$key]['#pid'] = $key;
if (!isset($value['#weight'])) {
$temp[$key]['#weight'] = 0;
}
}
// Load and loop through all the database stored predicates.
$result = db_query("SELECT * FROM {ca_predicates}");
while ($predicate = db_fetch_array($result)) {
// Prepare the database data into a predicate.
$predicate = ca_prepare_db_predicate($predicate);
// Overrides the module defined predicate if it's been modified by a user.
$temp[$predicate['#pid']] = $predicate;
}
usort($temp, 'ca_weight_sort');
// Copy the temporary array of predicates into a keyed array.
$predicates = array();
foreach ($temp as $predicate) {
$predicates[$predicate['#pid']] = $predicate;
}
// Load up the trigger data so we can display them by title.
$triggers = module_invoke_all('ca_trigger');
// Build the header for the predicate tables based on the grouping type.
if ($groupby == 'trigger') {
$header = array(
array(
'data' => t('Title'),
'class' => 'col-title',
),
t('Class'),
t('Status'),
t('Weight'),
t('Operations'),
);
$table_class = 'ca-predicate-trigger';
$table_label = '<strong>' . t('Trigger') . ':</strong> ';
}
elseif ($groupby == 'class') {
$header = array(
array(
'data' => t('Title'),
'class' => 'col-title',
),
t('Trigger'),
t('Status'),
t('Weight'),
t('Operations'),
);
$table_class = 'ca-predicate-class';
$table_label = '<strong>' . t('Class') . ':</strong> ';
}
$rows = array();
foreach ($predicates as $key => $value) {
// Build the basic operation links for each predicate.
$ops = array(
l(t('edit'), CA_UI_PATH . '/' . $key . '/edit'),
);
// Add the reset link if a module defined predicate has been modified.
if (!is_numeric($key) && isset($value['#modified'])) {
$ops[] = l(t('reset'), CA_UI_PATH . '/' . $key . '/reset');
}
// Add a delete link if displaying a custom predicate.
if (is_numeric($key)) {
$ops[] = l(t('delete'), CA_UI_PATH . '/' . $key . '/delete');
}
// Add the predicate's row to the table based on the grouping type.
if ($groupby == 'trigger') {
$tables[$triggers[$value['#trigger']]['#title']]['rows'][] = array(
check_plain($value['#title']),
strpos($value['#class'], 'custom') === 0 ? check_plain(substr($value['#class'], 7)) : $value['#class'],
$value['#status'] == 0 ? t('Disabled') : t('Enabled'),
array(
'data' => $value['#weight'],
'class' => 'ca-predicate-table-weight',
),
array(
'data' => implode(' ', $ops),
'class' => 'ca-predicate-table-ops',
),
);
}
elseif ($groupby == 'class') {
$class = strpos($value['#class'], 'custom') === 0 ? check_plain(substr($value['#class'], 7)) : $value['#class'];
$tables[$class]['rows'][] = array(
check_plain($value['#title']),
check_plain($triggers[$value['#trigger']]['#title']),
$value['#status'] == 0 ? t('Disabled') : t('Enabled'),
array(
'data' => $value['#weight'],
'class' => 'ca-predicate-table-weight',
),
array(
'data' => implode(' ', $ops),
'class' => 'ca-predicate-table-ops',
),
);
}
}
// Put the tables in alphabetical order.
ksort($tables);
// Add the tables for each trigger to the output.
$output = '';
foreach ($tables as $key => $value) {
// Accommodate empty class names.
if (empty($key)) {
$key = t('- None -');
}
$output .= theme('table', $header, $value['rows'], array(
'class' => $table_class,
), $table_label . check_plain($key));
}
$output .= l(t('Add a predicate'), CA_UI_PATH . '/add');
return $output;
}