<?php

/**
 * Implementation of hook_help().
 */
function login_destination_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Force users to certain page(s) upon login.');
  }
}

/**
 * Implementation of hook_form_alter().
 */
function login_destination_form_alter($form_id, &$form) {
  if ($form_id == 'user_login_block' || $form_id == 'user_login') {
    $form['#action'] = login_destination_get_destination();
  }
}

function login_destination_get_destination() {
  // customize the path as desired. 
  // $path = 'myproject';
  $path = variable_get('login_destination', 'user');
  return url($_GET['q'], "destination=$path");
}

// Implementation of hook_settings()
function login_destination_settings() {
  $form['login_destination'] = array(
    '#type' => 'textfield', 
    '#title' => t('Login Destination'), 
    '#description' => t('This page is displayed after the user logs in. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.'),
    '#default_value' => variable_get('login_destination', 'user'),
  );
  return $form;
}
