You are here

function globallink_menu_dashboard_form in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink_menu/globallink_menu_send.inc \globallink_menu_dashboard_form()
  2. 7.6 globallink_menu/globallink_menu_send.inc \globallink_menu_dashboard_form()

Builds form to create a menu submission.

1 string reference to 'globallink_menu_dashboard_form'
globallink_menu_dashboard in globallink_menu/globallink_menu_send.inc
Builds forms on menu send dashboard.

File

globallink_menu/globallink_menu_send.inc, line 286

Code

function globallink_menu_dashboard_form() {
  module_load_include('inc', 'globallink_menu', 'globallink_menu');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_send_translations');
  $module_path = drupal_get_path('module', 'globallink');
  drupal_add_js($module_path . '/js/globallink_send_translations.js');
  drupal_add_js(array(
    'globallinkSendTranslations' => array(
      'selectAll' => base_path() . globallink_get_root_menu('create-submission/select_all_js'),
      'selectedPath' => base_path() . globallink_get_root_menu('create-submission/select_id_js'),
      'selectedType' => GLOBALLINK_ENTITY_TYPE_MENU,
      'sessionKey' => 'mids',
    ),
  ), 'setting');
  drupal_add_css($module_path . '/css/globallink.css');
  $form = array();
  $default_checked = array();
  if (isset($_SESSION['mids'])) {
    $default_checked = $_SESSION['mids'];
  }
  $languages = globallink_get_mapped_drupal_locales(FALSE);
  if (isset($languages) && count($languages) > 1) {
    $target_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
    $source_lang_arr = globallink_get_mapped_locales_with_drupal_desc(FALSE);
    $count = 0;
    $types = array_keys(menu_get_menus());
    if (!empty($_SESSION['globallink_selected_menu_types'])) {
      $types = $_SESSION['globallink_selected_menu_types'];
    }
    $default_language = language_default();
    $default = $default_language->language;
    if (!empty($_SESSION['globallink_selected_menu_language'])) {
      $default = $_SESSION['globallink_selected_menu_language'];
    }
    $link_title = '';
    if (!empty($_SESSION['globallink_selected_menu_title'])) {
      $link_title = $_SESSION['globallink_selected_menu_title'];
    }
    unset($target_lang_arr[globallink_get_locale_code($default)]);
    $t_count = 0;
    foreach ($target_lang_arr as $key => $value) {
      $t_count++;
      if ($t_count % 2 === 0) {
        $target_lang_arr[$key] = '&nbsp;&nbsp;' . $value . '<BR/>';
      }
      else {
        $target_lang_arr[$key] = '&nbsp;&nbsp;' . $value . '&nbsp;&nbsp;&nbsp;&nbsp;';
      }
    }

    // Menu loading starts here
    $menu_names = array_keys(menu_get_menus(TRUE));
    $search_menu_types = array();
    if ($types != '') {
      foreach ($types as $t) {
        if ($t != '') {
          $search_menu_types[] = $t;
        }
        else {
          $search_menu_types = $menu_names;
          break;
        }
      }
    }
    else {
      $search_menu_types = $menu_names;
    }
    $menu_types = menu_get_menus(TRUE);
    $page_count = TPT_PAGER_LIMIT;
    if (isset($_SESSION['globallink_menu_page_count'])) {
      $page_count = $_SESSION['globallink_menu_page_count'][0];
    }
    $header = array(
      GLOBALLINK_ENTITY_TYPE_MENU => array(
        'field' => 'ml.menu_name',
        'data' => t('Menu Name'),
      ),
      'link' => array(
        'field' => 'ml.link_title',
        'data' => t('Link Title'),
      ),
      'lang' => t('Language'),
      'active' => t('In Active Submission'),
      'preview' => t('Preview'),
    );
    $query = db_select('menu_links', 'ml')
      ->fields('ml')
      ->condition('menu_name', $search_menu_types, 'IN')
      ->condition('language', $default, '=')
      ->extend('PagerDefault')
      ->limit($page_count)
      ->extend('TableSort');
    if ($link_title != '') {
      $query
        ->condition('link_title', '%' . $link_title . '%', 'LIKE');
    }
    $sort_order = isset($_GET['order']) ? $_GET['order'] : '';
    if ($sort_order == '') {
      $query
        ->orderBy('mlid', 'DESC');
    }
    else {
      $query
        ->orderByHeader($header);
    }
    $results = $query
      ->execute();
    $rows = array();
    foreach ($results as $item) {
      $count++;
      $active = '';
      $active_arr = globallink_menu_get_active_submission_by_id($item->mlid);
      if (!empty($active_arr)) {
        foreach ($active_arr as $active_row) {
          $l_title = globallink_format_display_string($active_row->submission);
          $l_href = 'admin/globallink-translations/workbench/all/' . $active_row->submission_rid . '/' . $active_row->target_lang_code;
          $l_options = array();
          $active .= l($l_title, $l_href, $l_options) . '&nbsp;&nbsp;- &nbsp;&nbsp;' . $active_row->sub_target_lang_name . ' <BR/> ';
        }
      }
      $rows[$item->mlid] = array(
        GLOBALLINK_ENTITY_TYPE_MENU => $menu_types[$item->menu_name],
        'link' => l($item->link_title, $item->link_path),
        'lang' => $languages[$item->language],
        'active' => $active,
        'preview' => globallink_menu_make_preview_link('Preview', $item->mlid),
      );
    }
    $cart_count = get_cart_count();
    globallink_add_cart_form_elements($form, $header, $rows, $default_checked, $cart_count);
    if ($count > 0) {
      $form['pager'] = array(
        '#markup' => theme('pager'),
      );
    }
  }

  // Very important
  form_load_include($form_state, 'inc', 'globallink', 'globallink_send_translations');
  return $form;
}