CREATE OR REPLACE PACKAGE cout_system_configuration IS

  /**
    -- Package containing the common utility system configuration routines used by the Access Manager application
    -- #version $Revision: $
    -- #author Andy Hardy
  */

  /*
  $Header: $  Logfile, Revision, Date, Author
  
  $Modtime: $  Date and time of last modification
  
  $History: $
  */

  /** Default date format for stored configuration items*/
  g_date_format CONSTANT VARCHAR2(80) := 'DD/MM/YYYY HH24:MI:SS';

  /** Add a date configuration item
  #param p_parameter The name of the configuration item
  #param p_value The value to be given to the configuration item
  #param p_description The description of the configuration item
  */
  PROCEDURE add_configuration_item_date(p_parameter   IN system_configuration.parameter%TYPE
                                       ,p_value       IN DATE
                                       ,p_description IN system_configuration.description%TYPE := NULL);
  /** Add a non-date configuration item
  #param p_parameter The name of the configuration item
  #param p_value The value to be given to the configuration item
  #param p_description The description of the configuration item
  */
  PROCEDURE add_configuration_item(p_parameter   IN system_configuration.parameter%TYPE
                                  ,p_value       IN system_configuration.VALUE%TYPE DEFAULT NULL
                                  ,p_description IN system_configuration.description%TYPE := NULL);

  /** Get a date configuration item
  #param p_parameter The name of the configuration item to be retrieved
  #return Value of the configuration item as a date
  */
  FUNCTION get_configuration_item_date(p_parameter IN system_configuration.parameter%TYPE)
    RETURN DATE;
  /** Get a configuration item
  #param p_parameter The name of the configuration item to be retrieved
  #return Value of the configuration item
  */
  FUNCTION get_configuration_item(p_parameter IN system_configuration.parameter%TYPE)
    RETURN system_configuration.VALUE%TYPE;

END cout_system_configuration;
/
CREATE OR REPLACE PACKAGE BODY cout_system_configuration IS

  -- Author  : HARDYA
  -- Created : 25/08/2004 14:22:59
  -- Purpose : Enter default system configuration details into the SYSTEM_CONFIGURATION table

  /*
  $Header: $  Logfile, Revision, Date, Author
  
  25/08/2004: $  Date and time of last checkin
  $Modtime: $  Date and time of last modification
  
  $History: $
  */

  PROCEDURE add_configuration_item(p_parameter   IN system_configuration.parameter%TYPE
                                  ,p_value       IN system_configuration.VALUE%TYPE DEFAULT NULL
                                  ,p_description IN system_configuration.description%TYPE := NULL) IS
  BEGIN
    INSERT INTO system_configuration
      (parameter
      ,VALUE
      ,description)
    VALUES
      (upper(p_parameter)
      ,p_value
      ,p_description);
  EXCEPTION
    WHEN dup_val_on_index THEN
      UPDATE system_configuration
         SET VALUE = p_value
       WHERE parameter = p_parameter;
  END add_configuration_item;

  PROCEDURE add_configuration_item_date(p_parameter   IN system_configuration.parameter%TYPE
                                       ,p_value       IN DATE
                                       ,p_description IN system_configuration.description%TYPE := NULL) IS
  BEGIN
    add_configuration_item(p_parameter   => p_parameter
                          ,p_value       => to_char(p_value
                                                   ,g_date_format)
                          ,p_description => p_description);
  END add_configuration_item_date;

  FUNCTION get_configuration_item(p_parameter IN system_configuration.parameter%TYPE)
    RETURN system_configuration.VALUE%TYPE IS
    l_value system_configuration.VALUE%TYPE;
  BEGIN
    SELECT VALUE
      INTO l_value
      FROM system_configuration
     WHERE parameter = upper(p_parameter);
    RETURN l_value;
  EXCEPTION
    WHEN no_data_found THEN
      RETURN NULL;
  END get_configuration_item;

  FUNCTION get_configuration_item_date(p_parameter IN system_configuration.parameter%TYPE)
    RETURN DATE IS
    l_value system_configuration.VALUE%TYPE;
  BEGIN
    l_value := get_configuration_item(p_parameter);
    RETURN to_date(l_value
                  ,g_date_format);
  
  END get_configuration_item_date;

END cout_system_configuration;
/
