You are here

function _locale_string_seek in Drupal 5

Same name and namespace in other branches
  1. 4 includes/locale.inc \_locale_string_seek()

Perform a string search and display results in a table

1 call to _locale_string_seek()
locale_string_search in modules/locale/locale.module
Page handler for the string search.

File

includes/locale.inc, line 1374
Admin-related functions for locale.module.

Code

function _locale_string_seek() {

  // We have at least one criterion to match
  if ($query = _locale_string_seek_query()) {
    $join = "SELECT s.source, s.location, s.lid, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid ";
    $arguments = array();

    // Compute LIKE section
    switch ($query->searchin) {
      case 'translated':
        $where = "WHERE (t.translation LIKE '%%%s%%' AND t.translation != '')";
        $orderby = "ORDER BY t.translation";
        $arguments[] = $query->string;
        break;
      case 'untranslated':
        $where = "WHERE (s.source LIKE '%%%s%%' AND t.translation = '')";
        $orderby = "ORDER BY s.source";
        $arguments[] = $query->string;
        break;
      case 'all':
      default:
        $where = "WHERE (s.source LIKE '%%%s%%' OR t.translation LIKE '%%%s%%')";
        $orderby = '';
        $arguments[] = $query->string;
        $arguments[] = $query->string;
        break;
    }
    switch ($query->language) {

      // Force search in source strings
      case "en":
        $sql = $join . " WHERE s.source LIKE '%%%s%%' ORDER BY s.source";
        $arguments = array(
          $query->string,
        );

        // $where is not used, discard its arguments
        break;

      // Search in all languages
      case "all":
        $sql = "{$join} {$where} {$orderby}";
        break;

      // Some different language
      default:
        $sql = "{$join} {$where} AND t.locale = '%s' {$orderby}";
        $arguments[] = $query->language;
    }
    $result = pager_query($sql, 50, 0, NULL, $arguments);
    $header = array(
      t('String'),
      t('Locales'),
      array(
        'data' => t('Operations'),
        'colspan' => '2',
      ),
    );
    $arr = array();
    while ($locale = db_fetch_object($result)) {
      $arr[$locale->lid]['locales'][$locale->locale] = $locale->translation;
      $arr[$locale->lid]['location'] = $locale->location;
      $arr[$locale->lid]['source'] = $locale->source;
    }
    foreach ($arr as $lid => $value) {
      $rows[] = array(
        array(
          'data' => check_plain(truncate_utf8($value['source'], 150, FALSE, TRUE)) . '<br /><small>' . $value['location'] . '</small>',
        ),
        array(
          'data' => _locale_string_language_list($value['locales']),
          'align' => 'center',
        ),
        array(
          'data' => l(t('edit'), "admin/settings/locale/string/edit/{$lid}"),
          'class' => 'nowrap',
        ),
        array(
          'data' => l(t('delete'), "admin/settings/locale/string/delete/{$lid}"),
          'class' => 'nowrap',
        ),
      );
    }
    $request = array();
    if (count($query)) {
      foreach ($query as $key => $value) {
        $request[$key] = is_array($value) ? implode(',', $value) : $value;
      }
    }
    if (count($rows)) {
      $output .= theme('table', $header, $rows);
    }
    if ($pager = theme('pager', NULL, 50, 0, $request)) {
      $output .= $pager;
    }
  }
  return $output;
}