You are here

function freelinking_page_form in Freelinking 5

Same name and namespace in other branches
  1. 6 freelinking.module \freelinking_page_form()
  2. 6.2 freelinking.module \freelinking_page_form()
1 string reference to 'freelinking_page_form'
freelinking_page in ./freelinking.module

File

./freelinking.module, line 54

Code

function freelinking_page_form($admin = TRUE) {
  if ($admin) {
    $form['options'] = array(
      '#type' => 'fieldset',
      '#title' => t('Update options'),
      '#prefix' => '<div class="container-inline">',
      '#suffix' => '</div>',
    );
    $options = array(
      'delete' => t('Delete'),
      'delete-all' => t('Delete All'),
    );
    $form['options']['operation'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => 'delete',
    );
    $form['options']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
    );
    $header = array(
      array(
        'data' => theme('table_select_header_cell'),
      ),
      array(
        'data' => t('Phrase'),
        'field' => 'phrase',
        'sort' => 'asc',
      ),
      array(
        'data' => t('Target'),
        'field' => 'path',
      ),
    );
  }
  else {
    $header = array(
      array(
        'data' => t('Phrase'),
        'field' => 'phrase',
        'sort' => 'asc',
      ),
      array(
        'data' => t('Target'),
        'field' => 'path',
      ),
    );
  }
  $query = "SELECT hash, phrase, path FROM {freelinking}" . tablesort_sql($header);
  $result = pager_query($query, 50);
  while ($freelink = db_fetch_object($result)) {

    // looping through phrase, target pairs
    $hash = $freelink->hash;
    $links[$hash] = '';
    $form['phrase'][$hash] = array(
      '#value' => urldecode($freelink->phrase),
    );
    $fltargetnid = _freelinking_exists($freelink->phrase);
    $freelink = _freelinking_make_link($freelink->phrase);
    if ($fltargetnid) {
      $link = l(t('see this content'), drupal_get_path_alias('node/' . $fltargetnid));
    }
    else {

      // content not found, show link to create
      $link = '<a href="' . url($freelink['path'], $freelink['args']) . '">' . t('create this content') . '</a>';
    }
    $form['target'][$hash] = array(
      '#value' => $link,
    );
  }
  if ($admin) {
    $form['links'] = array(
      '#type' => 'checkboxes',
      '#options' => $links,
    );
  }
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}