You are here

function menu_position_rules_form_submit in Menu Position 6

Same name and namespace in other branches
  1. 7.2 menu_position.admin.inc \menu_position_rules_form_submit()
  2. 7 menu_position.admin.inc \menu_position_rules_form_submit()

Handles form submission for menu_position_rules_form().

File

./menu_position.admin.inc, line 245
Provides infrequently used functions and hooks for menu_position.

Code

function menu_position_rules_form_submit($form, &$form_state) {
  foreach ($form_state['values']['rules'] as $rid => $rule) {
    $fields = array(
      'enabled' => $rule['enabled'],
      'weight' => $rule['weight'],
    );
    $db_rule = db_fetch_object(db_query('SELECT * FROM {menu_position_rules} WHERE rid = %d', $rid));
    if (!$rule['enabled']) {

      // If the rule has been disabled, remove the menu link.
      menu_link_delete($db_rule->mlid);
    }
    elseif (!$db_rule->enabled) {

      // If the rule has been enabled, add a menu link.
      $fields['mlid'] = menu_position_add_menu_link($rid, $db_rule->plid, $db_rule->admin_title);
    }
    $sql = 'UPDATE {menu_position_rules} SET ' . implode(' = %d, ', array_keys($fields)) . ' = %d WHERE rid = %d';
    $fields['rid'] = $rid;
    db_query($sql, array_values($fields));
  }
  drupal_set_message(t('The new rules ordering has been applied.'));
}