You are here

function shurly_edit_form in ShURLy 7

Confirmation form to edit a link

1 string reference to 'shurly_edit_form'
shurly_menu in ./shurly.module
Implements hook_menu().

File

./shurly.module, line 255
description http://www.youtube.com/watch?v=Qo7qoonzTCE

Code

function shurly_edit_form($form, &$form_state, $rid) {

  //check if we are in the "confirm" state
  if (!isset($form_state['storage']['confirm'])) {
    $shurly_link = db_query('SELECT * FROM {shurly} WHERE rid = :rid', array(
      'rid' => $rid,
    ))
      ->fetchAllAssoc('rid');
    $shurly_history = db_query('SELECT * FROM {shurly_history} WHERE rid = :rid', array(
      'rid' => $rid,
    ))
      ->fetchAll();
    $shurly_history_count = count($shurly_history);
    if ($shurly_history) {
      $form['history'] = array(
        '#prefix' => '<table>',
        '#suffix' => '</table>',
        '#tree' => TRUE,
      );
      $form['history']['header'] = array(
        '#markup' => '<thead>
        <tr>
          <th>' . t('Source') . '</th>
          <th>' . t('Changed') . '</th>
        </tr>
      </thead>',
      );
      for ($i = 0; $i < $shurly_history_count; $i++) {
        $form['history']['row_' . $i] = array(
          '#prefix' => '<tr class="' . ($i % 2 ? "odd" : "even") . '">',
          '#suffix' => '</tr>',
        );
        $form['history']['row_' . $i]['destination'] = array(
          '#prefix' => '<td>',
          '#suffix' => '</td>',
          '#markup' => l(truncate_utf8($shurly_history[$i]->destination, 30), $shurly_history[$i]->destination, array(
            'attributes' => array(
              'target' => '_blank',
            ),
          )),
        );
        $form['history']['row_' . $i]['last_date'] = array(
          '#prefix' => '<td>',
          '#suffix' => '</td>',
          '#markup' => format_date($shurly_history[$i]->last_date, 'short'),
        );
      }
    }
    $form['source'] = array(
      '#type' => 'textfield',
      '#title' => 'source',
      '#value' => $shurly_link[$rid]->source,
      '#disabled' => TRUE,
    );
    $form['destination'] = array(
      '#type' => 'textfield',
      '#title' => 'destination',
      '#value' => $shurly_link[$rid]->destination,
    );
    $form['rid'] = array(
      '#type' => 'hidden',
      '#value' => $rid,
    );
    $form['count'] = array(
      '#type' => 'hidden',
      '#value' => $shurly_link[$rid]->count,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => 'Submit',
    );
  }
  else {

    //We are in the confirm state, return a confirm
    $form = confirm_form($form, t('Are you sure you want to continue editing this short URL?'), 'form_url', t('In doing so, the count will be reset, and the current state stored in the history table. At present, this cannot be undone.'), 'Proceed', 'Cancel');
  }
  return $form;
}