<?php
// $Id$
/**
 * @file
 * Admin pages for FGCF module
 *
 * @copyright (c) 2010 Ouest Systemes Informatiques (OSInet)
 *
 * @license General Public License version 2 or later
 *
 * @author Frederic G. MARAND (fgm@osinet.fr)
 *
 */

/**
 * Implement the former hook_settings().
 *
 * @see fgcf_admin_settings_validate()
 *
 * @return array
 */
function fgcf_admin_settings() {

  $form = array();

  $mail_destination = 'fgcf_mail_destination';
  $form[$mail_destination] = array(
    '#type' => 'textfield',
    '#title' => t("Destinataire des demandes d'inscription aux formations"),
    '#default_value' => variable_get($mail_destination, variable_get('site_mail', 'support@osinet.fr')),
  );

  $flood = 'fgcf_subscribe_flood';
  $form[$flood] = array(
    '#type' => 'select',
    '#title' => t("Limite d'inscriptions"),
    '#options' => array(
      '0'  => t('Pas de limite'),
      '1'  => '1',
      '2'  => '2',
      '5'  => '5',
      '10' => '10',
    ),
    '#description' => t("Nombre maximum de demandes d'inscription toutes formations confondues, par personne et par heure"),
    '#default_value' => variable_get($flood, '10'),
  );

  $ret = system_settings_form($form);
  return $ret;
}

/**
 * Validation handler for fgcf_admin_settings().
 *
 * @param array $form
 * @param array $form_state
 *
 * @return void
 */
function fgcf_admin_settings_validate($form, &$form_state) {
  $mail_destination = 'fgcf_mail_destination';
  if (!valid_email_address($form_state['values'][$mail_destination])) {
    form_set_error($mail_destination, t('Invalid email address'));
  }
}