You are here

function om_maximenu_admin in OM Maximenu 7

Same name and namespace in other branches
  1. 8 inc/om_maximenu.admin.inc \om_maximenu_admin()
  2. 6 inc/om_maximenu.admin.inc \om_maximenu_admin()

Admin Form - Simple Editing

1 string reference to 'om_maximenu_admin'
om_maximenu_menu in ./om_maximenu.module
Implementation of hook_menu().

File

inc/om_maximenu.admin.inc, line 16
OM Maximenu Admin Configuration

Code

function om_maximenu_admin($form, &$form_state, $op = NULL) {
  global $_om_maximenu_variable;
  $maximenu = $_om_maximenu_variable;
  if (!empty($maximenu)) {
    ksort($maximenu);
  }

  // output options
  om_maximenu_admin_js();
  if ($op == NULL) {
    drupal_set_title(t('OM Maximum Edit'));
  }

  //dsm($maximenu);
  $form = array();
  $form['om_maximenus'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );

  // Existing menus and links
  $maximenu_array = array();
  if ($op == 'list') {

    // Basic Editing
    drupal_set_title(t('OM Maximenu Basic Editing'));
    $header = array(
      t('Menu'),
      t('Output'),
      t('Style'),
      t('Links'),
      '',
      '',
    );
    $rows = array();
    $style_options = array(
      '' => 'Dropdown',
      'normal' => 'Tab',
      'scrollh' => 'Tab with Horizontal Scroll',
      'scrollv' => 'Tab with Vertical Scroll',
      'roundabout' => 'Round About',
      'accordion' => 'Horizontal Accordion',
      'modal' => 'Modal Window',
    );
    if (!empty($maximenu)) {
      foreach ($maximenu as $menu_key => $menu_content) {

        // update change from tabbed to style
        $menu_content['style'] = isset($menu_content['tabbed']) ? $menu_content['tabbed'] : $menu_content['style'];
        $row = array();
        $row[] = om_string_name($menu_content['title'], FALSE);
        $row[] = om_string_name($menu_content['output'], FALSE);
        $row[] = $style_options[$menu_content['style']];
        $row[] = isset($menu_content['links']) ? count($menu_content['links']) : 0;
        $row[] = l(t('Edit'), 'admin/structure/om-maximenu/' . $menu_key . '/edit', array(
          'attributes' => array(
            'title' => t('Edit this menu.'),
          ),
        ));
        $row[] = l(t('Delete'), 'admin/structure/om-maximenu/' . $menu_key . '/delete', array(
          'attributes' => array(
            'title' => t('Delete this menu.'),
          ),
        ));
        $rows[] = array(
          'data' => $row,
        );
      }
    }
    $rows[] = array(
      'data' => array(
        'data' => l(t('Add menu'), 'admin/structure/om-maximenu/add', array(
          'attributes' => array(
            'title' => t('Add another menu.'),
          ),
        )),
        'attributes' => array(
          'colspan' => 4,
        ),
      ),
    );
    $menus = theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
    $maximenu_array[0] = array(
      '#type' => 'markup',
      '#markup' => $menus,
    );
    $form['om_maximenus'] += $maximenu_array;
  }
  else {

    // getting existing roles
    $result = db_query("SELECT rid, name, weight FROM {role} ORDER BY rid ASC");
    $roles = array();
    while ($record = $result
      ->fetchObject()) {
      $roles[$record->rid] = $record->name;
    }
    if (!empty($maximenu)) {
      if ($op == 'delete') {
        $args = arg();
        $menu_key = $args[3];
        drupal_set_title(t('Are you sure you want to delete @menu?', array(
          '@menu' => $maximenu[$menu_key]['title'],
        )));
        $maximenu_array[$menu_key]['delete'] = array(
          '#type' => 'hidden',
          '#default_value' => 1,
        );
      }

      // edit only 1 menu
      if ($op == 'edit') {
        drupal_set_title(t('OM Maximenu Edit'));
        $args = arg();
        $menu_key = $args[3];
        $this_menu[$menu_key] = isset($maximenu[$menu_key]) ? $maximenu[$menu_key] : drupal_goto('admin/structure/om-maximenu');
        $maximenu = $this_menu;
      }
      if ($op == 'edit' || $op == NULL) {
        foreach ($maximenu as $menu_key => $menu_content) {

          // counting active links
          $active_links = isset($menu_content['links']) ? count($menu_content['links']) : 0;
          $maximenu_array[$menu_key] = array(
            '#type' => 'fieldset',
            '#title' => om_string_name($menu_content['title'], FALSE),
            '#collapsible' => TRUE,
            '#collapsed' => arg(3) == 'maxedit' ? TRUE : FALSE,
            '#attributes' => array(
              'id' => 'om-maximenu-fieldset-' . om_string_name($menu_content['title']),
              'class' => array(
                'om-maximenu-fieldset',
              ),
            ),
            '#description' => $active_links != 0 ? t('Active Link/s:') . ' (' . $active_links . ')' : t('This menu will only show if you have added link/s.'),
          );

          //dsm($menu_content);
          $menu_content['menu_key'] = $menu_key;
          $menu_content['roles'] = $roles;
          $maximenu_array[$menu_key] += _om_maximenu_admin($menu_content);
        }
      }
    }
    if ($op == 'add' || $op == NULL) {
      if ($op == 'add') {
        drupal_set_title(t('OM Maximenu Add'));
      }

      // New menu and links
      // new ids relies on highest menu key id
      // adding only 1 new blank menu
      $count = !empty($maximenu) ? max(array_keys($maximenu)) + 1 : 1;
      $menu_content_new = array(
        'title' => 'New Menu',
        'skin' => 'bubble',
        'style' => '',
        'fade' => 0,
        'output' => 'block',
        'links' => array(),
        'menu_key' => $count,
        'roles' => $roles,
      );
      $maximenu_array[$count] = array(
        '#type' => 'fieldset',
        '#title' => 'New Menu',
        '#collapsible' => TRUE,
        '#collapsed' => arg(3) == 'maxedit' ? TRUE : FALSE,
        '#attributes' => array(
          'id' => 'om-maximenu-fieldset-new-menu',
          'class' => array(
            'om-maximenu-fieldset',
          ),
        ),
        '#description' => t('Change "New Menu" title to active this menu.'),
      );
      $maximenu_array[$count] += _om_maximenu_admin($menu_content_new);
    }
    $form['om_maximenus'] += $maximenu_array;
    if ($op == 'delete') {
      $form['delete'] = array(
        '#type' => 'submit',
        '#value' => t('Delete'),
      );
    }
    else {
      $form['save'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
      );
    }
    $form['cancel'] = array(
      '#type' => 'submit',
      '#value' => t('Cancel'),
    );
  }
  return $form;
}