Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

A Flexible Method of Storing Control Data

By Tony Marston
2006-08-29


Implementation

Although I have previous implemented this design in a different language this article shows my latest implementation in PHP using my own development framework.

Changing the table structure
The first step is to update the internal table definition by replacing the physical database structure with the theoretical structure. The "physical" structure, as exported from the Data Dictionary, is as follows:





    $fieldspec['record_id']                 = array('type' => 'string',
'size' => 16,
'pkey' => 'y',
'required' => 'y',
'uppercase' => 'y');

$fieldspec['field_id'] = array('type' => 'string',
'size' => 32,
'pkey' => 'y',
'required' => 'y',
'uppercase' => 'y');

$fieldspec['field_value'] = array('type' => 'string',
'size' => 255);

This structure can be replaced at runtime with
the following code:

    function _cm_changeConfig ($where, $fieldarray)
// Change the table configuration for the duration of this instance.
{
// default language code
$fieldspec['default_language'] = array('type' => 'string',
'size' => 5,
'required' => 'y',
'lowercase' => 'y',
'control' => 'dropdown',
'optionlist' => 'language_code');

// how often must the user change his password?
$fieldspec['pswd_change'] = array('type' => 'string',
'size' => 2,
'required' => 'y',
'uppercase' => 'y',
'control' => 'radiogroup',
'optionlist' => 'pswd_change',
'align_hv' => 'vertical');
// change password after 'n' logons
$fieldspec['pswd_count'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y');
// change password after 'n' days
$fieldspec['pswd_days'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y');
// an invalid password can be tried 'n' times after which the user_id will be disabled
$fieldspec['pswd_retries'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y');
// issue a "password will expire in N days/logons" warning
$fieldspec['pswd_warning'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y');
// specify the format of user passwords
$fieldspec['pswd_format_minlen'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y',
'required' => 'y',
'minvalue' => 1);
$fieldspec['pswd_format_upper'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y');
$fieldspec['pswd_format_lower'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y');
$fieldspec['pswd_format_digits'] = array('type' => 'integer',
'size' => 3,
'unsigned' => 'y');
// are passwords to be encrypted on the database?
$fieldspec['pswd_encrypt'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N');
// are passwords to be visible in the update/enquiry screens?
$fieldspec['pswd_hidden'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N');

// define lockout times between which system is unavailable
$fieldspec['shutdown_start'] = array('type' => 'time',
'size' => 5);
$fieldspec['shutdown_end'] = array('type' => 'time',
'size' => 5);
$fieldspec['shutdown_warning'] = array('type' => 'time',
'size' => 5);

$day_names = getLanguageArray('day_names_short');

$fieldspec['shutdown_monday'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N',
'control' => 'checkbox',
'label' => $day_names['mon'],
'align_lr' => 'left');

$fieldspec['shutdown_tuesday'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N',
'control' => 'checkbox',
'label' => $day_names['tue'],
'align_lr' => 'left');
$fieldspec['shutdown_wednesday'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N',
'control' => 'checkbox',
'label' => $day_names['wed'],
'align_lr' => 'left');
$fieldspec['shutdown_thursday'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N',
'control' => 'checkbox',
'label' => $day_names['thu'],
'align_lr' => 'left');
$fieldspec['shutdown_friday'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N',
'control' => 'checkbox',
'label' => $day_names['fri'],
'align_lr' => 'left');
$fieldspec['shutdown_saturday'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N',
'control' => 'checkbox',
'label' => $day_names['sat'],
'align_lr' => 'left');
$fieldspec['shutdown_sunday'] = array('type' => 'boolean',
'true' => 'Y',
'false' => 'N',
'control' => 'checkbox',
'label' => $day_names['sun'],
'align_lr' => 'left');

$this->fieldspec = $fieldspec;

return $fieldarray;

} // _cm_changeConfig

This amended structure identifies the following:


  • What fields need to be displayed on the screen.
  • How each field should be displayed (i.e. which HTML control to use).
  • How the user input for each field should be validated.


Tutorial Pages:
» Introduction
» A flexible approach
» Implementation
» From database to screen
» From screen to database
» Summary


 | Bookmark
Related Tutorials:
» Installing MySQL on Windows
» Implementing High Availability in MySQL
» Stored Procedures are EVIL
» MySQL Database Handling in PHP
» Exploring MySQL CURDATE and NOW. The Same But Different.
» Creating a PostgreSQL and MySQL driver