<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
DTD for glom documents.
TODO: Make sure that all the comments list all the attributes and their meaning.
TODO: Should we specify the presence of child text nodes in the ELEMENT somehow?
-->


<!-- This is the main node of the glom document. It describes the format of the
  databases (tables) and permissions (groups), as well as connections and any
  libraries.
  database_title: The human-readable title of the database.
  translation_original_locale: What locale is considered to have been used for the human-readable titles in this document.
  format_version: The version of this document's format. Older versions of Glom cannot open documents saved in newer versions of the document format.
  is_example: Whether this is an example document. Opening an example document causes a new database (and document) to be created.
-->
    <!ELEMENT glom_document (connection?, startup_script?, table*, groups?, library_modules?) >
    <!ATTLIST glom_document
        xmlns CDATA #IMPLIED
        database_title CDATA #IMPLIED
        translation_original_locale CDATA #IMPLIED
        format_version CDATA #IMPLIED
        is_example (true|false) "false">

<!-- This describes the (PostgreSQL) connection details for the database.
     server: The hostname of the PostgreSQL server.
     user: The PostgreSQL user.
     database: The name of the database to connect to on the PostgreSQL server.
     port: The port to connect to on the PostgreSQL server.
     try_other_ports: ?
     self_hosted: Whether a local instance of PostgreSQL should be started, to serve the data that is in a glom_postgres_data directory. Deprecated in favor of hosting_mode.
     hosting_mode: Can be "postgres_central" (self hosted via a local instance of PostgreSQL), "postgres_self" (a central PostgreSQL instance is used) or "sqlite" (self-hosted via a SQLite file).
     network_shared: true if the database (and document) should be shared over the network for use by other users.
-->
    <!ELEMENT connection EMPTY >
    <!ATTLIST connection
        server CDATA "localhost"
        user CDATA #IMPLIED
        database CDATA #REQUIRED
	port CDATA #REQUIRED
	try_other_ports (true|false) "true"
        self_hosted (true|false) "false"
        hosting_mode CDATA #IMPLIED
        network_shared (true|false) "false">

    <!ELEMENT startup_script (#PCDATA)>
    <!ATTLIST startup_script>

<!-- group(s) and table_privs are the permissions for each table.
      However, these are just initial permissions for examples. The real permissions are
      always in the database.
-->
    <!ELEMENT groups (group*)>
    <!ATTLIST groups>

<!-- The group node specifies a group of users and lists the permissions for that group for each table.
      However, these are just initial permissions for examples. The real permissions are
      always in the database.
     name: The name of this group of users.
     developer: Whether users in this group may use the developer features in Glom to change the database.
-->
    <!ELEMENT group (table_privs*)>
    <!ATTLIST group
        name CDATA #REQUIRED
        developer (true|false) "false">

<!-- table_privs are the permissions for each table for a group.
     However, these are just initial permissions for examples. The real permissions are
     always in the database.
     priv_view: Whether users in the group may view records in this table.
     priv_edit: Whether users in the group may edit records in this table.
     priv_create: Whether users in the group may create new records in this table.
     priv_delete: Whether users in the group may delete records in this table.
-->
    <!ELEMENT table_privs EMPTY>
    <!ATTLIST table_privs
        table_name CDATA #REQUIRED
        priv_view (true|false) "true"
        priv_edit (true|false) "true"
        priv_create (true|false) "true"
        priv_delete (true|false) "true">


<!-- The table node describes the structure for a database - what fields there
  are, how the fields should be displayed, translations into other
  languages, relationships between tables/fields, and reports for each table.
  name: The internal name of the table. Not to be seen by normal operators.
  title: The  human-visble title. This may be translated in the trans_set child node.
  hidden: Whether the table is hidden.
  overview_x and overview_y attributes are positions on the Relationships Overview picture.
  default: can specify that the table should be opened when the file is opened. Only one table should have default=true.
  example_rows: deprecated in 1.6 (and support removed in 1.10) - use the child node instead.
-->
    <!ELEMENT table (example_rows?, trans_set?, title_singular?, fields+, relationships?, data_layouts+, reports?, print_layouts?)>
    <!ATTLIST table
        name CDATA #REQUIRED
        title CDATA #IMPLIED
        hidden (true|false) "false"
        overview_x CDATA #IMPLIED
        overview_y CDATA #IMPLIED
        default (true|false) "false">

<!-- example_rows are comma separated lists of data (in the child text node) to load into the table
     when it is first created. -->
    <!ELEMENT example_rows (example_row*)>

    <!ELEMENT example_row (value*)>

    <!ELEMENT value (#PCDATA)>
    <!ATTLIST value
        column CDATA #REQUIRED>

<!-- relationships describe connections between databases. -->

    <!ELEMENT relationships (relationship*)>

    <!ELEMENT relationship (trans_set?)>
    <!ATTLIST relationship
        name CDATA #REQUIRED
        title CDATA #IMPLIED
        key CDATA #REQUIRED
        other_table CDATA #REQUIRED
        other_key CDATA #IMPLIED
        auto_create CDATA #IMPLIED
        allow_edit (true|false) "false">

<!-- fields define what type of data the database stores. There are different types of
  fields - numbers, strings, images, etc. The primary_key option is set to true when this field is
  the primary sort key of the data.
  name: The internal name of the table. Not to be seen by normal operators.
  title: The  human-visble title. This may be translated in the trans_set child node.
  primary_key: Whether this field is the primary key for its table.
  unique: Whether the values in this field should be unique in this table, meaning that it should not appear in this field in any other record in this table.
  auto_increment: Whether the value in this field should be automatically filled in when creating a new record, by incrementing a number.
  allow_edit: Whether users should be allowed to edit the value in this field.
  default_value: New records will have this value in this field when they are first created.
  calculation: deprecated - use the child node instead.
-->
    <!ELEMENT fields (field*)>

    <!ELEMENT field (calculation?, field_lookup?, formatting?, trans_set?)>
    <!ATTLIST field
        name CDATA #REQUIRED
        type CDATA #IMPLIED
        title CDATA #IMPLIED
        primary_key (true|false) "false"
        unique (true|false) "true"
        auto_increment (true|false) "true"
        allow_edit (true|false) "false"
        default_value CDATA #IMPLIED
        calculation CDATA #IMPLIED>

<!-- field_lookups specify that a value should be take from a related field when the associated ID changes.
     relationship: The name of the relationship from which to look up a value.
     field: The name of the field in the related table from which to look up a value.
-->
    <!ELEMENT field_lookup EMPTY>
    <!ATTLIST field_lookup
        relationship CDATA #REQUIRED
        field CDATA #REQUIRED>

<!-- formatting is the formatting of a field. Most of the options are for multiline text or numbers,
  since normal text boxes are relatively simple. The choices_* options are for defining the custom choice
  boxes. -->

    <!ELEMENT formatting (custom_choice_list*, choices_related_extra_layout?)>
    <!ATTLIST formatting
        format_thousands_separator (true|false) "true"
        format_text_multiline (true|false) "true"
        format_text_multiline_height_lines CDATA #IMPLIED
        format_decimal_places CDATA #IMPLIED
        choices_related (true|false) "true"
        choices_related_relationship CDATA #IMPLIED
        choices_related_field CDATA #IMPLIED
        choices_related_second CDATA #IMPLIED
        choices_related_show_all (true|false) #IMPLIED
        choices_custom (true|false) "false"
        format_decimal_places_restricted (true|false) "false"
        format_currency_symbol CDATA #IMPLIED
        format_use_alt_negative_color (true|false) "false"
        font CDATA #IMPLIED
        color_fg CDATA #IMPLIED
        color_bg CDATA #IMPLIED
        alignment_horizontal CDATA #IMPLIED>

<!-- A custom_choice is a drop down menu that can be selected (for example, Mrs., Mr., Ms., etc) from
  a set of options. -->

    <!ELEMENT custom_choice_list (custom_choice*)>
    <!ATTLIST custom_choice_list>

    <!ELEMENT custom_choice EMPTY>
    <!ATTLIST custom_choice
        value CDATA #REQUIRED>

 <!ELEMENT choices_related_extra_layout (data_layout_groups)>

<!-- The calculation node specifies python code that should be used to
     calculate a value for this field. They python code is in a child text node. -->
    <!ELEMENT calculation (#PCDATA)>
    <!ATTLIST calculation>

<!-- data layouts specify the arrangement of layout items.
  The name of the data_layout is usually either "list" or "details".-->

    <!ELEMENT data_layouts (data_layout*) >

    <!ELEMENT data_layout (data_layout_groups)>
    <!ATTLIST data_layout
        name CDATA #REQUIRED
        parent_table CDATA #IMPLIED>

    <!ELEMENT data_layout_groups (data_layout_group*)>
    <!ATTLIST data_layout_groups>

<!-- A data_layout_group is is a list of layout items. It can contain sub-groups. -->

    <!-- TODO: The comma separator specifies a fixed child node sequence, but we don't want to enforce that. -->
    <!ELEMENT data_layout_group (trans_set?, (data_layout_group | data_layout_item | data_layout_portal | data_layout_calendar_portal | data_layout_item_groupby | data_layout_button | data_layout_notebook | data_layout_item_header | data_layout_text)*)>
    <!ATTLIST data_layout_group
        name CDATA #IMPLIED
        title CDATA #IMPLIED
        sequence CDATA #IMPLIED
        columns_count CDATA #IMPLIED>

<!-- A data_layout_notebook is the tabbed display of tables in the details view. -->

    <!ELEMENT data_layout_notebook (trans_set?, data_layout_group*, data_layout_portal*)>
    <!ATTLIST data_layout_notebook
        name CDATA #REQUIRED
        columns_count CDATA #IMPLIED
        sequence CDATA #IMPLIED
        title CDATA #IMPLIED>

<!-- A data_layout_item_groupby is a data_layout_group that sorts -->

    <!ELEMENT data_layout_item_groupby (trans_set?, groupby?, sortby?, (data_layout_group |  data_layout_item | data_layout_portal | data_layout_calendar_portal | data_layout_button | data_layout_item_groupby |  secondary_fields | data_layout_item_summary | data_layout_item_verticalgroup)*)>
    <!ATTLIST data_layout_item_groupby
        name CDATA #IMPLIED
        title CDATA #IMPLIED
        sequence CDATA #IMPLIED
        columns_count CDATA #IMPLIED
        border_width CDATA #IMPLIED>

<!-- data_layout_text and text are for displaying text. -->

    <!ELEMENT data_layout_text (text?, formatting?, position?)>
    <!ATTLIST data_layout_text
        sequence CDATA #IMPLIED>

    <!ELEMENT text EMPTY>
    <!ATTLIST text
        title CDATA #REQUIRED>

<!-- sortby describes what a data_layout_item_groupby sorts by. -->

    <!ELEMENT sortby (data_layout_item*)>
    <!ATTLIST sortby>

<!-- data_layout_item_verticalgroup is in used in reporsts to display a vertical group of fields. -->

    <!ELEMENT data_layout_item_verticalgroup (data_layout_item*)>
    <!ATTLIST data_layout_item_verticalgroup
        name CDATA #IMPLIED
        columns_count CDATA #IMPLIED
        sequence CDATA #IMPLIED>

<!-- data_layout_item_summary and data_layout_item_fieldsummary summarize other
  fields. A good example of this is the total price in example_smallbusiness.glom. -->

    <!ELEMENT data_layout_item_summary (data_layout_item_fieldsummary*)>

    <!ELEMENT data_layout_item_fieldsummary (formatting?)>
    <!ATTLIST data_layout_item_fieldsummary
        name CDATA #REQUIRED
        editable (true|false) "false"
        use_default_formatting (true|false) "true"
        sequence CDATA #IMPLIED
        summarytype CDATA #REQUIRED>

<!-- groupby is used to determine how data_layout_item_groupby items group. -->

    <!ELEMENT groupby (title_custom?, formatting?)>
    <!ATTLIST groupby
        name CDATA #REQUIRED
        editable (true|false) "false"
        use_default_formatting (true|false) "true"
        relationship CDATA #IMPLIED>

<!-- secondary fields are additional fields to display. -->

    <!ELEMENT secondary_fields (data_layout_group*)>
    <!ATTLIST secondary_fields>


<!-- trans_set and trans are used for translating. They describe a set of alternatives
  for different languages - for a good sample, see example_film_manager.glom. -->

    <!ELEMENT trans_set (trans*)>
    <!ATTLIST trans_set>

    <!ELEMENT trans EMPTY>
    <!ATTLIST trans
        loc CDATA #REQUIRED
        val CDATA #REQUIRED>

<!-- A data_layout_item is the display of a single field in the layout. -->

    <!ELEMENT data_layout_item (title_custom?, formatting?, position?)>
    <!ATTLIST data_layout_item
        name CDATA #REQUIRED
        relationship CDATA #IMPLIED
        group CDATA #IMPLIED
        sequence CDATA #IMPLIED
        editable CDATA #IMPLIED
        use_default_formatting (true|false) "true"
	column_width CDATA #IMPLIED
        related_relationship CDATA #IMPLIED
        sort_ascending (true|false) "false">

<!-- A data_layout_item_header is the initial part of a report. -->

    <!ELEMENT data_layout_item_header (data_layout_item*)>
    <!ATTLIST data_layout_item_header
        name CDATA #IMPLIED
        columns_count CDATA #IMPLIED
        sequence CDATA #IMPLIED>

<!-- data_layout_button is a button on the layout. -->

    <!ELEMENT data_layout_button (script?, formatting?)>
    <!ATTLIST data_layout_button
        title CDATA #REQUIRED
        sequence CDATA #IMPLIED
        script CDATA #IMPLIED>

<!-- A script node is used to embed python code into the custom button. -->

    <!ELEMENT script (#PCDATA)>
    <!ATTLIST script>

<!-- A title_custom is used instead of the field's usual title. -->

    <!ELEMENT title_custom (trans_set?)>
    <!ATTLIST title_custom
        title CDATA #IMPLIED
        use_custom (true|false) "true">

<!-- A title_singular is used for the singular form where the standard title would be the plural form. -->

    <!ELEMENT title_singular (trans_set?)>
    <!ATTLIST title_singular
        title CDATA #IMPLIED>


<!-- A data_layout_portal shows related records -->

    <!ELEMENT data_layout_portal (position?, portal_navigation_relationship?, data_layout_item*) >
    <!ATTLIST data_layout_portal
        name CDATA #IMPLIED
        relationship CDATA #REQUIRED
        sequence CDATA #IMPLIED
        hide CDATA #IMPLIED
        columns_count CDATA #IMPLIED
        portal_rows_count_min CDATA #IMPLIED
        portal_rows_count_max CDATA #IMPLIED
        line_color CDATA #IMPLIED
        column_line_color CDATA #IMPLIED
        row_height CDATA #IMPLIED
        row_line_width CDATA #IMPLIED>

    <!ELEMENT data_layout_calendar_portal (portal_navigation_relationship?, data_layout_item*) >
    <!ATTLIST data_layout_calendar_portal
        name CDATA #IMPLIED
        relationship CDATA #REQUIRED
        date_field CDATA #REQUIRED
        sequence CDATA #IMPLIED
        hide CDATA #IMPLIED
        columns_count CDATA #IMPLIED>
 
<!-- The position of a layout item on a print layouts. -->
    <!ELEMENT position EMPTY>
    <!ATTLIST position
        x CDATA #REQUIRED
        y CDATA #REQUIRED
        width CDATA #REQUIRED
        height CDATA #REQUIRED>

<!-- portal_navigation_relationship determines what happens when the user
     activates a row in a related records portal.
     portal_navigation_relationship: "automatic", "specific" or "none".
     relationship: If portal_navigation_relationship is "specific" then this is
     the relationship to which to navigate.
     related_relationship: If portal_navigation_relationship is "specific" then
     this may be a related (to relationship) relationship to which to navigate. -->

    <!ELEMENT portal_navigation_relationship EMPTY>
    <!ATTLIST portal_navigation_relationship
        navigation_type CDATA #IMPLIED
        relationship CDATA #IMPLIED
        related_relationship CDATA #IMPLIED>

<!-- reports and data reports make short sheets of important information that
  distill a larger database. data_report(s) is the old interface; use reports if you are
  writing a new XML document. -->

    <!ELEMENT data_reports (data_report*)>

    <!ELEMENT data_report (data_layout_groups*)>
    <!ATTLIST data_report
        name CDATA #REQUIRED
        title CDATA #REQUIRED>

    <!ELEMENT reports (report*)>
    <!ATTLIST reports>

    <!ELEMENT report (data_layout_groups*, trans_set?)>
    <!ATTLIST report
        name CDATA #REQUIRED
        title CDATA #IMPLIED
        show_table_title (true|false) "false">

<!-- print layouts are for perfectly-positioned printing of single record details. -->
    <!ELEMENT print_layouts (print_layout*)>

    <!ELEMENT print_layout (page_setup?, data_layout_groups, horizontal_rule?, vertical_rule?, trans_set?)>
    <!ATTLIST print_layout
        name CDATA #REQUIRED
        title CDATA #IMPLIED
        parent_table CDATA #IMPLIED
        show_table_title (true|false) "false"
        show_grid (true|false) "false"
        show_rules (true|false) "false"
        show_outlines (true|false) "false"
        page_count CDATA #IMPLIED>
        
    <!ELEMENT page_setup (#PCDATA)>
    <!ATTLIST page_setup>

    <!ELEMENT print_layout_groups (print_layout_group*)>
    <!ATTLIST print_layout_groups>

    <!ELEMENT horizontal_rule EMPTY>
    <!ATTLIST horizontal_rule
        position CDATA #REQUIRED>

    <!ELEMENT vertical_rule EMPTY>
    <!ATTLIST vertical_rule
        position CDATA #REQUIRED>

<!-- The library_modules node contains python code that may be used in scripts and
     calculations via the python import keyword. -->

    <!ELEMENT library_modules (module*)>
    <!ATTLIST library_modules>

<!-- library_module nodes contain python code that may be used in scripts and
     calculations via the python import keyword. The source code is in the
     child text node.
     name: The name of the module, to be used with the python import command.
     script: Deprecated in Glom 1.12. The code of the python module. -->
    <!ELEMENT module (#PCDATA)>
    <!ATTLIST module
        name CDATA #REQUIRED>
