<?php
// $Id: ldapgroups.module,v 1.40 2009/08/25 13:23:37 miglius Exp $

/**
 * @file
 * ldapgroups integrates ldap groups with drupal roles.
 */

//////////////////////////////////////////////////////////////////////////////

define('LDAPGROUPS_DEFAULT_DN_ATTRIBUTE',      'ou');
define('LDAPGROUPS_DEFAULT_ENTRIES_ATTRIBUTE', 'memberUid');

//////////////////////////////////////////////////////////////////////////////
// Core API hooks

/**
 * Implementation of hook_menu().
 */
function ldapgroups_menu() {
  return array(
    'admin/settings/ldap/ldapgroups' => array(
      'title' => 'Groups',
      'description' => 'Configure LDAP groups to Drupal roles mapping settings.',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('ldapgroups_admin_settings'),
      'access arguments' => array('administer ldap modules'),
      'file' => 'ldapgroups.admin.inc',
    ),
    'admin/settings/ldap/ldapgroups/edit' => array(
      'title' => 'Groups',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('ldapgroups_admin_edit', 4, 5),
      'type' => MENU_CALLBACK,
      'access arguments' => array('administer ldap modules'),
      'file' => 'ldapgroups.admin.inc',
    ),
    'admin/settings/ldap/ldapgroups/reset' => array(
      'title' => 'Groups',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('ldapgroups_admin_edit', 4, 5),
      'type' => MENU_CALLBACK,
      'weight' => 1,
      'access arguments' => array('administer ldap modules'),
      'file' => 'ldapgroups.admin.inc',
    ),
  );
}

/**
 * Implements hook_user().
 */
function ldapgroups_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'login':
      require_once(drupal_get_path('module', 'ldapgroups') .'/includes/LDAPInterface.inc');
      require_once(drupal_get_path('module', 'ldapgroups') .'/ldapgroups.inc');
      ldapgroups_user_login($account);
      break;
  }
}

