You are here

function pm_attribute_list_submit in Drupal PM (Project Management) 7

Submit function for attribute list.

1 string reference to 'pm_attribute_list_submit'
pm_attribute_list_form in ./pm.admin.inc
Defines form for attribute list.

File

./pm.admin.inc, line 173
List functions for the Project Management module.

Code

function pm_attribute_list_submit($form, &$form_state) {
  $attributes = array();
  $default_for_domain = array();
  foreach ($_POST as $key => $value) {
    $ar = explode('_', $key);
    if ($ar[0] == 'attribute') {
      if ($ar[1] == 'weight') {
        $attributes[$ar[2]]['weight'] = $value;
      }
      if ($ar[1] == 'isactive') {
        $attributes[$ar[2]]['isactive'] = $value;
      }
      if ($ar[1] == 'default') {
        $domain = str_replace('|', ' ', $ar[2]);
        $default_for_domain[$domain] = $value;
      }
    }
  }
  foreach ($attributes as $aid => $values) {
    db_update('pmattribute')
      ->fields(array(
      'isactive' => array_key_exists('isactive', $values) ? $values['isactive'] : 0,
      'weight' => $values['weight'],
    ))
      ->condition('aid', $aid, '=')
      ->execute();
  }
  foreach ($default_for_domain as $domain => $aid) {
    db_update('pmattribute')
      ->fields(array(
      'isdefault' => 0,
    ))
      ->condition('domain', $domain, '=')
      ->execute();
    db_update('pmattribute')
      ->fields(array(
      'isdefault' => 1,
    ))
      ->condition('aid', $aid, '=')
      ->execute();
  }
  drupal_set_message(t('Attributes saved'));
}