MOT
Administration Help

Databases

Tables

Fields

Actions

MOT-SQL

Export/Import


Databases

MOT databases are just groupings of tables. The only purpose of a MOT database is to group a set of tables into a convenient collection that can be viewed together. This notion of a database allows you to put the same table in more than one database, which is really useful for certain generically useful tables (i.e. Users and People) as well as for creating different ways of viewing the same information (i.e. using both a 'Job Tracker' database for use by the IT staff and a 'Software Solutions' database for viewing by support clients).

More help is available on the following topics: Detail Sort Options, Help Text


Tables

Tables are the heart of the MOT system. Each table is a collection of fields, which can be either bits of data or links to other tables, and actions, which can be triggered either by accesses of or by changes to the table. Note that each table is wholly self sufficient in that it can be included in any number of databases.

More help is available on the following topics: Name Field, Help Text


Tables -> Name Field

The 'Name Field' option allows you to create a custom name field for a table in MOT-SQL. It is always safe just to leave this field blank.

Each table has a name field, which is the field is used to represent that table when it is linked against other tables. For instance, the name field of the Users table is the Name field, so the Users field of the Permissions table displays the name of the user linked by that field. By default, the name field is simply the field with the lowest 'Display Order' option. If you leave the 'Name Field' option blank, MOT will use this default. So, in nearly all cases, you can simply leave this option blank.

However, in a few cases, it is very handy to be able to either specify a different field than the default or to have the name field be some combination of other fields. For example, in a People table, you may have Last Name and First Name fields so that the table will properly sort the entries by Last Name. However, neither the Last Name or First Name field would serve well as a name field in this case. What you would really want would be First Name + Last Name as the name field. The Name Field option allows you to specify this behavior by writing the correct MOT-SQL phrase. In this case, the phrase would be: concat({People}.[First Name], ' ', {People}.[Last Name]) (see the help section on MOT-SQL for information on how to form MOT-SQL queries).


Tables -> Help Text

The 'Help Text' option allows you to write custom documentation for each table. The help text for the table will appear on the 'Help' page in any database to which this table belongs.


Fields

A field defines a single piece of information that can be included in a table definition. A field can either be a simple piece of data, such as a string, a number, or a date, or a link to another table. Fields are highly configurable. Be sure to read the following information on field options carefully so that you can take full advantage of MOT.

More help is available on the following topics: Type, Sort Order, Display Order, Sort by, Restrict by, Default Restrict, Blanks, List View, Detail View, Add View, Modify View, Single Link, Table, Link to, Help Text


Fields -> Type

The 'Type' whether the field will hold a piece of data or a link and, if it is a piece of data, what sort of data it will hold. A field may be any one of the following types:

  • date - A date field represents a day in the format of 'YYYY-MM-DD'.

  • time - A time field represents a time of the day, in the format of 'HH:MM:SS (A|M)P'.

  • datetime - A datetime field represents a day and a time of the day, in the format of 'YYYY-MM-DD HH:MM:SS (A|P)M'.

  • short_string - A short_string field is a string of up to 32 characters.

  • medium_string - A medium_string field is a string of up to 128 characters.

  • long_string - A long_string field is a string of up to 65535 characters. A long_string field cannnot be used to sort or restrict its table.

  • password - A password field is like a short_string field, with two exceptions: 1) MOT stores an MD5 hash of the string entered by the user instead of the string itself, and 2) MOT will mask any such entries, so that they cannot be read on the screen.

  • short_int - A short_int field is an integer between -32768 and 32767.

  • medium_int - A medium_int field is an integer between -8388608 and 8388607.

  • long_int - A long_int field is an integer between -2147483648 and 2147483647.

  • float - A float field is a floating point number with a range of -3.402823466E+38F - -1.175494351E-38, 0, -1.175494351E-38 - 3.402823466E+38F.

  • boolean - A boolean field can equal either 'yes' or 'no'.

  • url - A url field is a url of up to 128 characters. A url field is always displayed as a link to the given url.

  • email - An email field is an email address of up to 128 characters. An email field is always displayed as a mailto: link handy for sending email with a click.

  • link - A link field is a link to another table. Note that a field cannot be changed from a link to another field type or vice versa.

  • table - A table field is a link to a MOT table. It is mainly useful for the Permissions table, but resourceful users might find other uses for it.

  • database - A database field is a link to a MOT database. It is mainly useful for the Permissions table, but resourceful users might find other uses for it.


Fields -> Sort Order

The 'Sort Order' option determines the order in which the rows of the table are sorted by default. Tables entries are sorted according to the fields with the lower sort orders first.

The 'Sort Order' option is ignored if the 'Sort by' option is set to no. In other words, only fields marked as 'Sort by' are used to sort the table.


Fields -> Display Order

The 'Display Order' option determines the order in which the fields are displayed. Fields with lower display order values are displayed first.


Fields -> Sort by

The 'Sort by' option determines two things: 1) whether the field should be used to sort the table by default (whether MOt should pay attention to the 'Sort Order' option) and 2) whether the user should have the option of sorting the table by this field first (whether the field appears on the 'Sort by' list of the sort options box.


Fields -> Restrict by

The 'Restrict by' option determines whether the user will be able to restrict the table to certain rows depending on the value of this field. In other words, this option determins whether this field has its own line in the sort options table.


Fields -> Default Restrict

if the 'Default Restrict' option is not blank, MOT will ony display entries in which the value of the field in question is equal to the value of this option. Note that setting a value for the 'Default Restrict' option while also setting the 'Restrict by' option to 'no' has the effect of locking the user into a restricted set of fields, since she will not be able to change the restriction.


Fields -> Blanks

The 'Blanks' option determines whether the given field can contain a blank value.


Fields -> List View

The 'List View' field determines whether the field in question will appear in the list view of its table.


Fields -> Detail View

The 'Detail View' field determines whether the field in question will appear in the detail view of its table.


Fields -> Add View

The 'Add View' field determines whether the field in question will appear in the add entry screen of its table.


Fields -> Modify View

The 'Modify View' field determines whether the field in question will appear in the modify entry screen of its table.


Fields -> Single Link

The 'Single Link' option is only relevant for link fields (fields with a type of 'link'). A single link field is limited to a single link to its linked table.


Fields -> Table

The 'Table' option determines which table this field belongs to. Normally, you can ignore this option, since it is automagically set to the current table by default.


Fields -> Link to

The 'Link to' option is only relevant for link fields. The 'Link to' option determines which table this field links to.


Fields -> Help Text

The 'Help Text' option allows you to write custom documentation for each field. The help text for the table will appear on the 'Help' page underneath the appropriate table in any database to which the table belongs.


Actions

Actions are custom scripts which are automatically fired by specified database actions (adds, modifications, etc.). They are immensely helpful for implementing things like email notification and timestamping.

Since action scripts must be written in php, you have to know php to take advantage of them. You will also probably want to know some SQL (MOT-SQL, actually) to do anything very interesting.

More help is available on the following topics: Action Name, Function Name, File Name, Timing, Trigger, Table, Useful Functions


Actions -> Action Name

The 'Action Name' option is mainly just used for identification purposes. However, it is also as the link text for list and detail triggers (see below).


Actions -> Function Name

The 'Function Name' option tells MOT which function to run when the action is triggered. The function should be declared in the following form:

Function function_name($action_type, $when, $table_id, $row_id) { ... }

Actions -> File Name

The 'File Name' options tells MOT in which file it can find the specified function. To find the correct file, MOT looks in the actions/ subdirectory for a file named [File Name].php3. So if an action has a 'File Name' option of job_tracker, MOT looks for the function in a file called 'actions/job_tracker.php3'.

To prevent different databases from bumping into one another, I recommend that you put all of the actions for a given database in a file named after your database (i.e. actions for the 'Job Tracker' database should go in the job_tracker.php3 file).


Actions -> Timing

The 'Timing' option determines when the action will be run, in relation to the trigger. For instance, an action with a timing of 'before' and a trigger of 'add' will be run before each addition to the table.

See the 'Trigger' option documentation for further notes on the effect of the 'Timing' option.


Actions -> Trigger

The 'Trigger' options determines what even will trigger the action. Each trigger type corresponds to a different MOT screen (add, modify, delete, list, detail). An action can perform different functions depending on its trigger type and timing:

  • For add, modify, and delete triggers, the actions is always after the user has submitted the reuqested change. The timing determines whether the action fires before or after the requested change actually goes through. For these triggers, an action that fires before the event and returns a value of 'false' will prevent the specified action from happening. For example, there is a 'Protect Admin' action that fires before additions and modification to the Users table and prevents an addition or modification from happening if a non-admin is trying to give himself admin privileges.

  • For list and detail triggers, you should only assign before triggers. If the before trigger returns true, then a link, bearing the name of the trigger, will appear at the top of the page in question. Clicking on that link will fire off the same trigger as an after trigger. For example, the 'Job Tracker' database contains a close_job action on the the detail view. When triggered with a timing of before, this action returns true if the given entry has a 'Close Date' equal to zero (meaning that the job has not yet been closed). When triggered with a timing of after, the action sets the current entry 'Close Date' field to the current time.


Actions -> Table

The 'Table' option determines which table the action is attached to. You can normally ignore this option, since it will be set to the current table by default.


Actions -> Useful Functions

There are a number of useful php function you should know about if you are going to build your own action scripts:

action_get_new_vals($table_id) { ... }

Get an array containing the values to be submitted to the database. This function is only relevant for actions triggered before additions or modifications.

action_publish_field($table_id, $field_name, $new_val) { ... }

Change the submission value of field $field_name in table $table_id to $new_val. Note that this function only has an effect on the database if the function is triggered before the addition or modification. If you want to change a value in the database at any other time, you will have to use a mot-sql query.

action_publish_all_fields($table_id, $new_vals)

Replace the list of values to be submitted to the database with $new_vals. This function is usually best used in conjuction with the action_get_new_vals.

mot_query($query) { ... }

Perform a MOT-SQL query. See the MOT-SQL documentation below for more details. To access the results of the query, use the sql_* commands (sql_fetchrow, sql_fetcharray, etc) found in sql.php3.

sql_date($time) { ... }

Return $time (as returned by the php time() function) in a format suitable to be inserted into a sql database.


MOT-SQL

MOT-SQL allows you to access your MOT databases by running ordinary sql queries through a preprocessor that translates your MOT table and field names (i.e. 'Users' and 'Admin') into their actual sql representations.

The MOT-SQL preprocessor uses the following constructs:

  • {} - To insert a MOT table into your query, surround the table name in {}s.

  • [] - To insert a MOT field into your query, surround the field name in []s. Note that every MOT field name must be immediately preceded by a MOT table name and a period (i.e. select {Users}.[Name] from {Users}). To select the row id from any table, use the [id] field.

  • <> - To join a MOT table to one of its links, follow the table name by the link name, with the link name surrounded in <>s (i.e. select {People}.[email] from {Jobs} where {Jobs}.[id]). To join a chain of links, with each link joining to the previous link, simply append the links to one another (i.e. select {People}.[email] from {Jobs} <Users> <Personal Info> where {Jobs}.[id]).

    To join several links to a single table, use a comma as the first character after the < (i.e. select {Jobs}.[Summary], {People}.[Email], {Users}.[Name] from {Jobs} <,Users>).

Note that, due to my currently crappy implementation, each table can only be joined into a query once. So, you cannot, for example, include two different links to the same table in a single query.


Export/Import

MOT supports exporting and importing database schemas, so you can share any particularly nifty databases that you create. MOT uses a homebrew xml format to save the databases and its own, completely php-based xml parser to load them, so there is no need to recompile php.

For the most part, you can remain blissfully ignorant of the xml format, since MOT can create the export file for the database schema. If you want to include data in your exported database, however, you will have to manually add in the correct <query ... ></query>tags.

More help is available on the following topics: Query Tag


Local Administrator
based on Ministry of Truth v 2.0.a4 by Hal Roberts