
FUNCTION check_if_reserved (w_rese)
This function is used to check if argument given (or part of the argument)
is an SQL reserved word.
Function returns TRUE if argument is reseved word, or FALSE as default.

FUNCTION check_auth_level(a_auth_level)
This function check if logged user has authorization to execute an action.
Allowed authorization levels are:
    LOGON, STAFF_READ, STAFF_WRITE, CUSTOMER_READ, CUSTOMER_WRITE
    INVOICE_READ, INVOICE_WRITE, PRODUCT_READ, PRODUCT_WRITE
If user is allowed to execute action this function returns TRUE. 
Default return code is FALSE.
Authorization level is acquired from   allowed   table.

FUNCTION customer_type_add(w_short_type, w_long_type)
Function is used to add customer type. 
Both arguments are written to   customer_type   table (if specified type
does not exist in table.
New customer type is retrieved from ctype_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION customer_type_update(w_short_type_old, w_short_type, w_long_type)
Function is used to update records in customer_type table if
w_short_type_old record is found in table.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION customer_type_delete(w_customer_type, should_delete)
Function is used to delete specified type record from customer_type_table.
Flag should_delete specifies:
   MARK   - sets deleted flag on record
   DELETE - realy delete specified record
   CHECK  - check if deletion is allowed   
Function returns 0 as default, and 1 if an error occoures.

FUNCTION customer_status_add(w_short_status, w_long_status)
Function is used to add customer status records in customer_status table.
Records are added only if specified record does not exist in customer_status
table.
New customer type is retrieved from cs_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION customer_status_update(w_short_status_old, w_short_status, w_long_status)
Function is used to update records in customer_status table if
w_short_status_old record exists in table.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION customer_status_delete(w_customer_status, should_delete)
Function is used to delete specified status record from customer status table.
Flag should_delete specifies:
   MARK   - sets deleted flag on record
   DELETE - realy delete specified record
   CHECK  - check if deletion is allowed   
Function returns 0 as default, and 1 if an error occoures.

FUNCTION telephone_add(w_email, telephone_no, fax_no)
Function adds telephone and fax_no into telephone table if specified records
dont already exist. Records primary key is users e-mail.
New telephone_no is retrieved from telephone_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION telephone_update(w_email, w_telephone, w_fax)
Updates telephone and fax numbers for specifed users e-mail.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION telephone_delete(w_status_no, should_delete)
Function is used to delete specified telephone record from telephone table.
Flag should_delete specifies:
   MARK   - sets deleted flag on record
   DELETE - realy delete specified record
   CHECK  - check if deletion is allowed   
Function returns 0 as default, and 1 if an error occoures.

FUNCTION order_status_add(status_txt, status_note)
Function is used to add order status records in order_status table.
Records are added only if specified record does not exist in order_status table.
New order_status_no is retrieved from order_status_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION order_status_update(w_short_status_old, w_short_status, w_long_status)
Function is used to update records in order_status table if
w_short_status_old record exists in table.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION order_status_delete(order_no, should_delete)
Function is used to delete specified status record from order_status table.
Flag should_delete specifies:
   MARK   - sets deleted flag on record
   DELETE - realy delete specified record
   CHECK  - check if deletion is allowed   
Function returns 0 as default, and 1 if an error occoures.

FUNCTION renewal_period_add(renewal_stxt, renewal_txt, renewal_date)
Function is used to add renewal period record in renewal_period table if
specified record does not exist in database.
New renewal_no is retrieved from renewal_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION renewal_period_update(renewal_no, renewal_stxt, renewal_txt)
Function is used to update renewal period record in renewal_period table if
record number is renewal_no.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION renewal_period_delete(delete_no, real_delete)
IF real_delete flag is set to MARK than this fuinction just sests deleted
flag for records whose no is delete_no.
If real_delete flag is set to DELELTE than records whose numbers are equal
to delete_no are realy deleted from database. 
Function returns 0 as default, and 1 if an error occoures.

FUNCTION address_add(w_email, street1, street_2, street_3, city, postcode
                     county, country)
Function adds customer address into address table. Address is added to table
only if customer exists in customer table and if address is unique for
specified customer.
New address_no is retrieved from address_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION address_update(w_email, street1, street_2, street_3, city, postcode
                        county, country)
Function updates address table with specified arguments for specified
customer.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION address_delete(delete_no, should_delete)
Function deletes specified record from address table if should_delete flag
is set to DELETE, or just changes deleted flag to TRUE if MARK flag is
selected.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION card_type_add(w_short_type, w_long_type)
Function adds new card type to card_type table if specified type
(w_short_type) does not already exist in database.
New card_type_no is retrieved from ct_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION card_type_update(w_short_type_old, w_short_type, w_long_type)
Function is used to update card type record in card_type table if
w_short_type_old is matched in card_type table.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION card_type_delete(delete_no, should_delete)
Function deletes specified record from card_type table if should_delete flag
is set to DELETE, or just changes deleted flag to TRUE if MARK flag is
selected.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION card_name_add(w_short_name, w_long_name)
Function adds card name to card_name table. Card is added to table only if
specified w_short_name doesn't already exist card_name table.
New card number is retrieved from card_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION card_name_update(w_short_name_old, w_short_name, w_long_name)
Updates record in card_name table if w_short_name_old is matched.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION card_name_delete(delete_no, should_delete)
Function deletes specified record from card_name table if should_delete flag
is set to DELETE, or just changes deleted flag to TRUE if MARK flag is
selected.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION payment_type_add(type_short, type_full)
Function adds payment_type to payment_type table if type_short is not
matched in table.
New payment number is retrieved from pt_no sequence.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION payment_type_update(type_no, type_short, type_full)
Updates record in payment_type table if type_no exists in payment_type table.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION payment_type_delete(delete_no, should_delete)
Function deletes specified record from card_name table if should_delete flag
is set to DELETE, or just changes deleted flag to TRUE if MARK flag is
selected.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION contactinfo_add(status_short, status_full)
Function adds status data to contactinfo table if status specified in
status_short argument does not exist in contactinfo table.
New sequence number is generated in cs_no sequence.
Function returns 0 as default, or 1 if an error occoures.

FUNCTION contactinfo_update(status_no, status_short, status_full)
Updates contactinfo table with specified arguments if status_no is matched
in contactinfo table.
Function returns 0 as default, or 1 if an error occoures.

FUNCTION contactinfo_delete(delete_no, should_delete)
Function deletes specified record from contactinfo table if should_delete flag
is set to DELETE, or just changes deleted flag to TRUE if MARK flag is
selected.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION last_action()
Updates staff table with current date and time. 
This is used for auto-logoff feature.

FUNCTION user_logon(w_user, w_pass)
Function first check if user is authorized to LOGON.
If user is authorized password is checked and if password matches user is
logged to system.
Users last access to system is updated (last_action function).
Function returns three strings concatenated with ',' (comma)

       w_name  - Users name and second name
       w_lac   - last_Access time
       a_level - Users authorization 

FUNCTION user_logoff(w_snick)
If user is allowed to LOGON, logoff procedure is started.
Function returns time elapsed from users logon.

FUNCTION customer_data_add(w_email, w_status, w_type, w_domain, w_cust_name
                           w_cust_surname, w_organization, w_contact, 
                           w_password, w_discount)
Function adds all customer data fields to customer table if customer with
specified e_mail address already does not exist in table.
Status_no is retrieved from customer_status table.
Type_no is retrieved from customer_type table.
Domain_no is retrieved from domains table.
staff_no is retrieved from staff table.
Sequence is retrieved from customer_no sequence.
Function returns 0 as default, or 1 if an error occoures.

FUNCTION customer_data_update(w_customer_no, w_email, w_status, w_type,
                              w_domain, w_cust_name, w_cust_surname,
                              w_organization, w_contact, w_password,
                              w_discount)
Function updates customers data in customer table if w_customer_no is
matched in table.
Function returns 0 as default, or 1 if an error occoures.

FUNCTION customer_data_delete(w_email, should_delete)
Function is used to delete customer records from customers table.
Allowed should_delete flags:
   MARK    - sets deleted flags on specified customer
   DELETE  - deletes specified records on specified customer
Data is marked/deleted in following tables: customer_card, telephone,
address, customer.
Function returns 0 if action is executed or 1 if an error occoures.

FUNCTION customer_card_add(w_email, w_card_name, w_card_type, w_name
                           w_expire, w_card_number)
Function is used for adding card data for specified customer (w_email).
All card data are added to customer_card table if card does not already exist
in table.
Card type is fetched from  card_type table.
Sequence used is ccard_no.
Function returns 0 as default or 1 if an error occoures.

FUNCTION customer_card_update(w_ccard_no, w_email, w_card_name, w_card_type,
                              w_name, w_expire, w_card_number)
Function updates fields for specified card (w_ccard_no) for specified user
(w_email) in customer card table.
Function returns 0 as default or 1 if an error occoures.

FUNCTION customer_card_delete(w_ccard_no, should_delete)
Function deletes specified record from customer_card table if should_delete
flag is set to DELETE, or just changes deleted flag to TRUE if MARK flag is
selected.
IF CHECK flag is selected function checks if card is allowed to be deleted.
Function returns 0 as default, and 1 if an error occoures.

FUNCTION product_data_add(w_domain, w_name, w_short_desc, w_desc)
Function adds product data to products table for specified domain.
Data is added only if w_name is not matched in products table.
Sequence used is product_no.
If everything was done correctly till this moment empty product table
is created.
Function returns 0 as default or 1 if an error occoures.

FUNCTION product_data_update(w_domain, w_name_old, w_name, w_short_desc, w_desc)
Function updates data in products table if w_name_old product exists for
domain w_domain.
Function returns 0 as default or 1 if an error occoures.

FUNCTION product_data_delete(delete_no, should_delete)
Function deletes specified record from products table if should_delete flag
is set to DELETE, or just changes deleted flag to TRUE if MARK flag is
selected. 
Data is marked/deleted in tables  product_description and products.
Function returns 0 as default, and 1 if an error occoures.


