-- Copyright (c) 1997-now, NeoNova BV, The Netherlands. All rights Reserved.
--
-- This software is the copyrighted work of NeoNova BV.
-- Use of the software is subject to the general business terms and conditions of NeoNova BV
-- and its related transaction documents like license sheets or other written notices.#
-- Any reproduction or redistribution of the software not in accordance with the license terms
-- is expressly prohibited by law, and may result in severe civil and criminally penalties.
-- Violators will be prosecuted to the maximum extent possible.

-- Changes that should have been done in r22343 and are not overruled by later updates.

BEGIN;

CREATE TABLE phonebook (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this phonebook belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar dit telefoonboek bij hoort.

 name varchar(255) NOT NULL default '',
--HELP_EN_INFO:phonebook name
--HELP_EN_LONG:The name of this phonebook.
--HELP_NL_INFO:naam
--HELP_NL_LONG:De naam van dit telefoonboek.

 description varchar(256) NOT NULL default '',
--HELP_EN_INFO:Description
--HELP_EN_LONG:The description for this phonebook.
--HELP_NL_INFO:Omschrijving
--HELP_NL_LONG:Een omschrijving voor dit telefoonboek.

 status varchar(8) NOT NULL default 'active'
   CHECK (status IN ('active', 'deleted')),
--HELP_EN_INFO:state
--HELP_EN_LONG:Role status.
--HELP_NL_INFO:status
--HELP_NL_LONG:De status van dit telefoonboek.

 PRIMARY KEY  (id)
);

GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_id_seq TO astium;

INSERT INTO phonebook (name, company, description, status) VALUES ('empty', 1, 'empty', 'deleted');

INSERT INTO phonebook (company, name, description) values ('3', 'phonebook 1', '');
INSERT INTO phonebook (company, name, description) values ('3', 'phonebook 2', '');
INSERT INTO phonebook (company, name, description) values ('3', 'phonebook 3', '');
INSERT INTO phonebook (company, name, description) values ('3', 'phonebook 4', '');
INSERT INTO phonebook (company, name, description) values ('3', 'phonebook 5', '');

ALTER TABLE phonebook ADD CONSTRAINT phonebook_company_constraint FOREIGN KEY (company) REFERENCES company (id);

COMMIT;

BEGIN;

CREATE TABLE phonebook_data_1 (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this record belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar deze gegevens bij horen.

 tag varchar(24) NOT NULL default '',
--HELP_EN_INFO:tag
--HELP_EN_LONG:Free-format tag to use for this address
--HELP_NL_INFO:label
--HELP_NL_LONG:Zelf te kiezen label voor dit adres

 name varchar(255) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:contact name
--HELP_EN_LONG:The name of the contact.
--HELP_NL_INFO:naam relatie
--HELP_NL_LONG:De naam van de contactpersoon.

 address varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact address
--HELP_EN_LONG:The address of this contact
--HELP_NL_INFO:adres relatie
--HELP_NL_LONG:Het adres van de contacpersoon.

 zipcode varchar(10) NOT NULL default '',
--HELP_EN_INFO:contact zip
--HELP_EN_LONG:The zipcode of the contact.
--HELP_NL_INFO:postcode relatie
--HELP_NL_LONG:De postcode van de contactpersoon.

 city varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact city
--HELP_EN_LONG:The city of the contact.
--HELP_NL_INFO:woonplaats relatie
--HELP_NL_LONG:De woonplaats van de contactpersoon.

 country varchar(25) NOT NULL default '',
--HELP_EN_INFO:contact country
--HELP_EN_LONG:The country of the contact.
--HELP_NL_INFO:land relatie
--HELP_NL_LONG:Het land van de contactpersoon.

 field1 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field2 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field3 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field4 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field5 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 contacttype integer NOT NULL default '1',
--HELP_EN_INFO:contact type
--HELP_EN_LONG:The type of contact. For each contact type you can assign specific ringtones to your phone and call
--HELP_EN_LONG:forwarding options. See the manual for more information about contact types.
--HELP_NL_INFO:contact type
--HELP_NL_LONG:Het type contact. Voor ieder contacttype kunnen specifieke beltonen gekozen worden en kunnen
--HELP_NL_LONG:verschillende doorschakelopties worden ingesteld. Zie de handleiding voor meer informatie.

 shortnumber varchar(16) NOT NULL default '',
--HELP_EN_INFO:shortnumber
--HELP_EN_LONG:The short number to dial to reach this contact. For example, if you enter
--HELP_EN_LONG:'45', you dial '45' from a phone.
--HELP_NL_INFO:verkort nummer
--HELP_NL_LONG:Het snelkiesnummer voor deze contactpersoon. Als u hier bijvoorbeeld '45'
--HELP_NL_LONG:invult, dan toetst u '45' op uw telefoon om de contactpersoon te bellen in plaats van het hele nummer 
--HELP_NL_LONG:te moeten toetsen. 

 customerid varchar(24) NOT NULL default '',
--HELP_EN_INFO:customer id
--HELP_EN_LONG:The ID of this customer in other databases. This is sent to the Astium Operator
--HELP_EN_LONG:Switchboard, and will be handed over to the external linkage program.
--HELP_NL_INFO:Relatienummer 
--HELP_NL_LONG:Het nummer van de relatie waaronder deze bekend is in andere databases.
--HELP_NL_LONG:Dit wordt door Astium Operator Switchboard gebruikt om door te geven aan
--HELP_NL_LONG:het externe programma dat wordt gestart als de lijn wordt opgenomen.

 number varchar(32) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:actual number
--HELP_EN_LONG:The actual number that will be dialed, when you dial the short number.
--HELP_NL_INFO:telefoonnummer
--HELP_NL_LONG:Het telefoonnummer dat wordt gedraaid als u het snelkiesnummer intoetst.

 contact1 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Primary contact
--HELP_EN_LONG:When this contact calls, connect automatically to this number.
--HELP_NL_INFO:Contactpersoon 1
--HELP_NL_LONG:Als dit bedrijf of deze persoon belt, verbindt dan met deze extensie (van zijn contactpersoon bij 
--HELP_NL_LONG:het bedrijf).

 contact2 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Secondary contact
--HELP_EN_LONG:When the primary contact does not answer, connect to this number.
--HELP_NL_INFO:Contactpersoon 2
--HELP_NL_LONG:Als de eerste contactpersoon niet antwoordt of in gesprek is, stuur
--HELP_NL_LONG:het telefoontje dan naar dit tweede nummer.

 contact3 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Tertiary contact
--HELP_EN_LONG:When the primary and secondary contacts do not respond, dial this number.
--HELP_NL_INFO:Contactpersoon 3
--HELP_NL_LONG:Als de eerste twee contactpersonen niet beschikbaar zijn, stuur
--HELP_NL_LONG:het telefoontje dan naar dit derde nummer.

 PRIMARY KEY  (id)
);

CREATE INDEX phonebook_data_1_number_index ON phonebook_data_1  (number);

GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_1 TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_1_id_seq TO astium;

COMMIT;

BEGIN;

CREATE TABLE phonebook_data_2 (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this record belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar deze gegevens bij horen.

 tag varchar(24) NOT NULL default '',
--HELP_EN_INFO:tag
--HELP_EN_LONG:Free-format tag to use for this address
--HELP_NL_INFO:label
--HELP_NL_LONG:Zelf te kiezen label voor dit adres

 name varchar(255) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:contact name
--HELP_EN_LONG:The name of the contact.
--HELP_NL_INFO:naam relatie
--HELP_NL_LONG:De naam van de contactpersoon.

 address varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact address
--HELP_EN_LONG:The address of this contact
--HELP_NL_INFO:adres relatie
--HELP_NL_LONG:Het adres van de contacpersoon.

 zipcode varchar(10) NOT NULL default '',
--HELP_EN_INFO:contact zip
--HELP_EN_LONG:The zipcode of the contact.
--HELP_NL_INFO:postcode relatie
--HELP_NL_LONG:De postcode van de contactpersoon.

 city varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact city
--HELP_EN_LONG:The city of the contact.
--HELP_NL_INFO:woonplaats relatie
--HELP_NL_LONG:De woonplaats van de contactpersoon.

 country varchar(25) NOT NULL default '',
--HELP_EN_INFO:contact country
--HELP_EN_LONG:The country of the contact.
--HELP_NL_INFO:land relatie
--HELP_NL_LONG:Het land van de contactpersoon.

 field1 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field2 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field3 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field4 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field5 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 contacttype integer NOT NULL default '1',
--HELP_EN_INFO:contact type
--HELP_EN_LONG:The type of contact. For each contact type you can assign specific ringtones to your phone and call
--HELP_EN_LONG:forwarding options. See the manual for more information about contact types.
--HELP_NL_INFO:contact type
--HELP_NL_LONG:Het type contact. Voor ieder contacttype kunnen specifieke beltonen gekozen worden en kunnen
--HELP_NL_LONG:verschillende doorschakelopties worden ingesteld. Zie de handleiding voor meer informatie.

 shortnumber varchar(16) NOT NULL default '',
--HELP_EN_INFO:shortnumber
--HELP_EN_LONG:The short number to dial to reach this contact. For example, if you enter
--HELP_EN_LONG:'45', you dial '45' from a phone.
--HELP_NL_INFO:verkort nummer
--HELP_NL_LONG:Het snelkiesnummer voor deze contactpersoon. Als u hier bijvoorbeeld '45'
--HELP_NL_LONG:invult, dan toetst u '45' op uw telefoon om de contactpersoon te bellen in plaats van het hele nummer 
--HELP_NL_LONG:te moeten toetsen. 

 customerid varchar(24) NOT NULL default '',
--HELP_EN_INFO:customer id
--HELP_EN_LONG:The ID of this customer in other databases. This is sent to the Astium Operator
--HELP_EN_LONG:Switchboard, and will be handed over to the external linkage program.
--HELP_NL_INFO:Relatienummer 
--HELP_NL_LONG:Het nummer van de relatie waaronder deze bekend is in andere databases.
--HELP_NL_LONG:Dit wordt door Astium Operator Switchboard gebruikt om door te geven aan
--HELP_NL_LONG:het externe programma dat wordt gestart als de lijn wordt opgenomen.

 number varchar(32) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:actual number
--HELP_EN_LONG:The actual number that will be dialed, when you dial the short number.
--HELP_NL_INFO:telefoonnummer
--HELP_NL_LONG:Het telefoonnummer dat wordt gedraaid als u het snelkiesnummer intoetst.

 contact1 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Primary contact
--HELP_EN_LONG:When this contact calls, connect automatically to this number.
--HELP_NL_INFO:Contactpersoon 1
--HELP_NL_LONG:Als dit bedrijf of deze persoon belt, verbindt dan met deze extensie (van zijn contactpersoon bij 
--HELP_NL_LONG:het bedrijf).

 contact2 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Secondary contact
--HELP_EN_LONG:When the primary contact does not answer, connect to this number.
--HELP_NL_INFO:Contactpersoon 2
--HELP_NL_LONG:Als de eerste contactpersoon niet antwoordt of in gesprek is, stuur
--HELP_NL_LONG:het telefoontje dan naar dit tweede nummer.

 contact3 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Tertiary contact
--HELP_EN_LONG:When the primary and secondary contacts do not respond, dial this number.
--HELP_NL_INFO:Contactpersoon 3
--HELP_NL_LONG:Als de eerste twee contactpersonen niet beschikbaar zijn, stuur
--HELP_NL_LONG:het telefoontje dan naar dit derde nummer.

 PRIMARY KEY  (id)
);

CREATE INDEX phonebook_data_2_number_index ON phonebook_data_2  (number);

GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_2 TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_2_id_seq TO astium;

COMMIT;

BEGIN;

CREATE TABLE phonebook_data_3 (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this record belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar deze gegevens bij horen.

 tag varchar(24) NOT NULL default '',
--HELP_EN_INFO:tag
--HELP_EN_LONG:Free-format tag to use for this address
--HELP_NL_INFO:label
--HELP_NL_LONG:Zelf te kiezen label voor dit adres

 name varchar(255) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:contact name
--HELP_EN_LONG:The name of the contact.
--HELP_NL_INFO:naam relatie
--HELP_NL_LONG:De naam van de contactpersoon.

 address varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact address
--HELP_EN_LONG:The address of this contact
--HELP_NL_INFO:adres relatie
--HELP_NL_LONG:Het adres van de contacpersoon.

 zipcode varchar(10) NOT NULL default '',
--HELP_EN_INFO:contact zip
--HELP_EN_LONG:The zipcode of the contact.
--HELP_NL_INFO:postcode relatie
--HELP_NL_LONG:De postcode van de contactpersoon.

 city varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact city
--HELP_EN_LONG:The city of the contact.
--HELP_NL_INFO:woonplaats relatie
--HELP_NL_LONG:De woonplaats van de contactpersoon.

 country varchar(25) NOT NULL default '',
--HELP_EN_INFO:contact country
--HELP_EN_LONG:The country of the contact.
--HELP_NL_INFO:land relatie
--HELP_NL_LONG:Het land van de contactpersoon.

 field1 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field2 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field3 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field4 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field5 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 contacttype integer NOT NULL default '1',
--HELP_EN_INFO:contact type
--HELP_EN_LONG:The type of contact. For each contact type you can assign specific ringtones to your phone and call
--HELP_EN_LONG:forwarding options. See the manual for more information about contact types.
--HELP_NL_INFO:contact type
--HELP_NL_LONG:Het type contact. Voor ieder contacttype kunnen specifieke beltonen gekozen worden en kunnen
--HELP_NL_LONG:verschillende doorschakelopties worden ingesteld. Zie de handleiding voor meer informatie.

 shortnumber varchar(16) NOT NULL default '',
--HELP_EN_INFO:shortnumber
--HELP_EN_LONG:The short number to dial to reach this contact. For example, if you enter
--HELP_EN_LONG:'45', you dial '45' from a phone.
--HELP_NL_INFO:verkort nummer
--HELP_NL_LONG:Het snelkiesnummer voor deze contactpersoon. Als u hier bijvoorbeeld '45'
--HELP_NL_LONG:invult, dan toetst u '45' op uw telefoon om de contactpersoon te bellen in plaats van het hele nummer 
--HELP_NL_LONG:te moeten toetsen. 

 customerid varchar(24) NOT NULL default '',
--HELP_EN_INFO:customer id
--HELP_EN_LONG:The ID of this customer in other databases. This is sent to the Astium Operator
--HELP_EN_LONG:Switchboard, and will be handed over to the external linkage program.
--HELP_NL_INFO:Relatienummer 
--HELP_NL_LONG:Het nummer van de relatie waaronder deze bekend is in andere databases.
--HELP_NL_LONG:Dit wordt door Astium Operator Switchboard gebruikt om door te geven aan
--HELP_NL_LONG:het externe programma dat wordt gestart als de lijn wordt opgenomen.

 number varchar(32) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:actual number
--HELP_EN_LONG:The actual number that will be dialed, when you dial the short number.
--HELP_NL_INFO:telefoonnummer
--HELP_NL_LONG:Het telefoonnummer dat wordt gedraaid als u het snelkiesnummer intoetst.

 contact1 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Primary contact
--HELP_EN_LONG:When this contact calls, connect automatically to this number.
--HELP_NL_INFO:Contactpersoon 1
--HELP_NL_LONG:Als dit bedrijf of deze persoon belt, verbindt dan met deze extensie (van zijn contactpersoon bij 
--HELP_NL_LONG:het bedrijf).

 contact2 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Secondary contact
--HELP_EN_LONG:When the primary contact does not answer, connect to this number.
--HELP_NL_INFO:Contactpersoon 2
--HELP_NL_LONG:Als de eerste contactpersoon niet antwoordt of in gesprek is, stuur
--HELP_NL_LONG:het telefoontje dan naar dit tweede nummer.

 contact3 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Tertiary contact
--HELP_EN_LONG:When the primary and secondary contacts do not respond, dial this number.
--HELP_NL_INFO:Contactpersoon 3
--HELP_NL_LONG:Als de eerste twee contactpersonen niet beschikbaar zijn, stuur
--HELP_NL_LONG:het telefoontje dan naar dit derde nummer.

 PRIMARY KEY  (id)
);

CREATE INDEX phonebook_data_3_number_index ON phonebook_data_3  (number);

GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_3 TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_3_id_seq TO astium;

COMMIT;

BEGIN;

CREATE TABLE phonebook_data_4 (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this record belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar deze gegevens bij horen.

 tag varchar(24) NOT NULL default '',
--HELP_EN_INFO:tag
--HELP_EN_LONG:Free-format tag to use for this address
--HELP_NL_INFO:label
--HELP_NL_LONG:Zelf te kiezen label voor dit adres

 name varchar(255) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:contact name
--HELP_EN_LONG:The name of the contact.
--HELP_NL_INFO:naam relatie
--HELP_NL_LONG:De naam van de contactpersoon.

 address varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact address
--HELP_EN_LONG:The address of this contact
--HELP_NL_INFO:adres relatie
--HELP_NL_LONG:Het adres van de contacpersoon.

 zipcode varchar(10) NOT NULL default '',
--HELP_EN_INFO:contact zip
--HELP_EN_LONG:The zipcode of the contact.
--HELP_NL_INFO:postcode relatie
--HELP_NL_LONG:De postcode van de contactpersoon.

 city varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact city
--HELP_EN_LONG:The city of the contact.
--HELP_NL_INFO:woonplaats relatie
--HELP_NL_LONG:De woonplaats van de contactpersoon.

 country varchar(25) NOT NULL default '',
--HELP_EN_INFO:contact country
--HELP_EN_LONG:The country of the contact.
--HELP_NL_INFO:land relatie
--HELP_NL_LONG:Het land van de contactpersoon.

 field1 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field2 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field3 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field4 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field5 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 contacttype integer NOT NULL default '1',
--HELP_EN_INFO:contact type
--HELP_EN_LONG:The type of contact. For each contact type you can assign specific ringtones to your phone and call
--HELP_EN_LONG:forwarding options. See the manual for more information about contact types.
--HELP_NL_INFO:contact type
--HELP_NL_LONG:Het type contact. Voor ieder contacttype kunnen specifieke beltonen gekozen worden en kunnen
--HELP_NL_LONG:verschillende doorschakelopties worden ingesteld. Zie de handleiding voor meer informatie.

 shortnumber varchar(16) NOT NULL default '',
--HELP_EN_INFO:shortnumber
--HELP_EN_LONG:The short number to dial to reach this contact. For example, if you enter
--HELP_EN_LONG:'45', you dial '45' from a phone.
--HELP_NL_INFO:verkort nummer
--HELP_NL_LONG:Het snelkiesnummer voor deze contactpersoon. Als u hier bijvoorbeeld '45'
--HELP_NL_LONG:invult, dan toetst u '45' op uw telefoon om de contactpersoon te bellen in plaats van het hele nummer 
--HELP_NL_LONG:te moeten toetsen. 

 customerid varchar(24) NOT NULL default '',
--HELP_EN_INFO:customer id
--HELP_EN_LONG:The ID of this customer in other databases. This is sent to the Astium Operator
--HELP_EN_LONG:Switchboard, and will be handed over to the external linkage program.
--HELP_NL_INFO:Relatienummer 
--HELP_NL_LONG:Het nummer van de relatie waaronder deze bekend is in andere databases.
--HELP_NL_LONG:Dit wordt door Astium Operator Switchboard gebruikt om door te geven aan
--HELP_NL_LONG:het externe programma dat wordt gestart als de lijn wordt opgenomen.

 number varchar(32) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:actual number
--HELP_EN_LONG:The actual number that will be dialed, when you dial the short number.
--HELP_NL_INFO:telefoonnummer
--HELP_NL_LONG:Het telefoonnummer dat wordt gedraaid als u het snelkiesnummer intoetst.

 contact1 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Primary contact
--HELP_EN_LONG:When this contact calls, connect automatically to this number.
--HELP_NL_INFO:Contactpersoon 1
--HELP_NL_LONG:Als dit bedrijf of deze persoon belt, verbindt dan met deze extensie (van zijn contactpersoon bij 
--HELP_NL_LONG:het bedrijf).

 contact2 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Secondary contact
--HELP_EN_LONG:When the primary contact does not answer, connect to this number.
--HELP_NL_INFO:Contactpersoon 2
--HELP_NL_LONG:Als de eerste contactpersoon niet antwoordt of in gesprek is, stuur
--HELP_NL_LONG:het telefoontje dan naar dit tweede nummer.

 contact3 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Tertiary contact
--HELP_EN_LONG:When the primary and secondary contacts do not respond, dial this number.
--HELP_NL_INFO:Contactpersoon 3
--HELP_NL_LONG:Als de eerste twee contactpersonen niet beschikbaar zijn, stuur
--HELP_NL_LONG:het telefoontje dan naar dit derde nummer.

 PRIMARY KEY  (id)
);

CREATE INDEX phonebook_data_4_number_index ON phonebook_data_4  (number);

GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_4 TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_4_id_seq TO astium;

COMMIT;

BEGIN;

CREATE TABLE phonebook_data_5 (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this record belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar deze gegevens bij horen.

 tag varchar(24) NOT NULL default '',
--HELP_EN_INFO:tag
--HELP_EN_LONG:Free-format tag to use for this address
--HELP_NL_INFO:label
--HELP_NL_LONG:Zelf te kiezen label voor dit adres

 name varchar(255) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:contact name
--HELP_EN_LONG:The name of the contact.
--HELP_NL_INFO:naam relatie
--HELP_NL_LONG:De naam van de contactpersoon.

 address varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact address
--HELP_EN_LONG:The address of this contact
--HELP_NL_INFO:adres relatie
--HELP_NL_LONG:Het adres van de contacpersoon.

 zipcode varchar(10) NOT NULL default '',
--HELP_EN_INFO:contact zip
--HELP_EN_LONG:The zipcode of the contact.
--HELP_NL_INFO:postcode relatie
--HELP_NL_LONG:De postcode van de contactpersoon.

 city varchar(50) NOT NULL default '',
--HELP_EN_INFO:contact city
--HELP_EN_LONG:The city of the contact.
--HELP_NL_INFO:woonplaats relatie
--HELP_NL_LONG:De woonplaats van de contactpersoon.

 country varchar(25) NOT NULL default '',
--HELP_EN_INFO:contact country
--HELP_EN_LONG:The country of the contact.
--HELP_NL_INFO:land relatie
--HELP_NL_LONG:Het land van de contactpersoon.

 field1 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field2 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field3 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field4 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 field5 text NOT NULL default '',
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 contacttype integer NOT NULL default '1',
--HELP_EN_INFO:contact type
--HELP_EN_LONG:The type of contact. For each contact type you can assign specific ringtones to your phone and call
--HELP_EN_LONG:forwarding options. See the manual for more information about contact types.
--HELP_NL_INFO:contact type
--HELP_NL_LONG:Het type contact. Voor ieder contacttype kunnen specifieke beltonen gekozen worden en kunnen
--HELP_NL_LONG:verschillende doorschakelopties worden ingesteld. Zie de handleiding voor meer informatie.

 shortnumber varchar(16) NOT NULL default '',
--HELP_EN_INFO:shortnumber
--HELP_EN_LONG:The short number to dial to reach this contact. For example, if you enter
--HELP_EN_LONG:'45', you dial '45' from a phone.
--HELP_NL_INFO:verkort nummer
--HELP_NL_LONG:Het snelkiesnummer voor deze contactpersoon. Als u hier bijvoorbeeld '45'
--HELP_NL_LONG:invult, dan toetst u '45' op uw telefoon om de contactpersoon te bellen in plaats van het hele nummer 
--HELP_NL_LONG:te moeten toetsen. 

 customerid varchar(24) NOT NULL default '',
--HELP_EN_INFO:customer id
--HELP_EN_LONG:The ID of this customer in other databases. This is sent to the Astium Operator
--HELP_EN_LONG:Switchboard, and will be handed over to the external linkage program.
--HELP_NL_INFO:Relatienummer 
--HELP_NL_LONG:Het nummer van de relatie waaronder deze bekend is in andere databases.
--HELP_NL_LONG:Dit wordt door Astium Operator Switchboard gebruikt om door te geven aan
--HELP_NL_LONG:het externe programma dat wordt gestart als de lijn wordt opgenomen.

 number varchar(32) NOT NULL default '',
--GENERATE:phoneconfig:phone:
--HELP_EN_INFO:actual number
--HELP_EN_LONG:The actual number that will be dialed, when you dial the short number.
--HELP_NL_INFO:telefoonnummer
--HELP_NL_LONG:Het telefoonnummer dat wordt gedraaid als u het snelkiesnummer intoetst.

 contact1 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Primary contact
--HELP_EN_LONG:When this contact calls, connect automatically to this number.
--HELP_NL_INFO:Contactpersoon 1
--HELP_NL_LONG:Als dit bedrijf of deze persoon belt, verbindt dan met deze extensie (van zijn contactpersoon bij 
--HELP_NL_LONG:het bedrijf).

 contact2 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Secondary contact
--HELP_EN_LONG:When the primary contact does not answer, connect to this number.
--HELP_NL_INFO:Contactpersoon 2
--HELP_NL_LONG:Als de eerste contactpersoon niet antwoordt of in gesprek is, stuur
--HELP_NL_LONG:het telefoontje dan naar dit tweede nummer.

 contact3 varchar(15) NOT NULL default '',
--HELP_EN_INFO:Tertiary contact
--HELP_EN_LONG:When the primary and secondary contacts do not respond, dial this number.
--HELP_NL_INFO:Contactpersoon 3
--HELP_NL_LONG:Als de eerste twee contactpersonen niet beschikbaar zijn, stuur
--HELP_NL_LONG:het telefoontje dan naar dit derde nummer.

 PRIMARY KEY  (id)
);

CREATE INDEX phonebook_data_5_number_index ON phonebook_data_5  (number);

GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_5 TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phonebook_data_5_id_seq TO astium;

COMMIT;

ALTER TABLE fastdial_contact DROP COLUMN descr_prompt;
ALTER TABLE fastdial_company DROP COLUMN descr_prompt;

ALTER TABLE fastdial_contact ADD COLUMN customerid varchar(24);
UPDATE fastdial_contact SET customerid = '' WHERE customerid IS NULL;
ALTER TABLE fastdial_contact ALTER COLUMN customerid SET DEFAULT '';
ALTER TABLE fastdial_contact ALTER COLUMN customerid SET NOT NULL;

ALTER TABLE fastdial_company DROP COLUMN pin;
