<?php

class Default_Table

{

// member variables

var $access_count ; // count of accesses since instantiation

var $allow_empty_where = false ; // switch to allow an empty $where string in STD.LIST2.INC

var $allow_db_function = array ( ) ; // allow a field's value in a database insert/update to contain a function name

var $allow_scrolling = false ; // used inside ADD2 pattern to allow scrolling between selected rows

var $alt_language_table ; // table holding alternative language text

var $alt_language_cols ; // columns holding alternative language text

var $audit_logging ; // yes/no switch

var $checkPrimaryKey = false ; // yes/no switch

var $child_relations = array ( ) ; // child relationship specifications (optional)

var $css_files = array ( ) ; // optional CSS file names

var $csv ; // object for CSV processing

var $custom_processing_object ; // name of object containing code for custom processing

var $custom_replaces_standard = false ; // if set to TRUE in a custom method then the standard method must not be run

var $dbms_engine = '' ; // database engine (mysql, postgresql, oracle, etc)

var $dbname ; // database name as recorded in the Data Dictionary

var $dbname_server ; // database name after being switched in the CONFIG.INC file

var $dbname_old ; // refer to _switch_database() method

var $dbprefix = '' ; // prefix (for shared servers)

var $dirname ; // directory name of current script

var $dirname_dict ; // directory name where '*.dict.inc' script is located (optional)

var $download_filename ; // file to be downloaded

var $download_mode ; // 'inline' or null

var $delete_count ; // count of records deleted

var $insert_count ; // count of records inserted

var $update_count ; // count of records updated

var $unchange_count ; // count of records unchanged

var $errors = array ( ) ; // array of errors

var $expanded ; // list of tree nodes which have been expanded

var $fieldarray = array ( ) ; // array of row/field data

var $fieldspec = array ( ) ; // field specifications (see class constructor)

var $fields_not_for_trimming = array ( ) ; // array of field names which are not to be trimmed

var $field_access ; // see setFieldAccess()

var $ignore_empty_fields = false ; // YES/NO switch (see getInitialData() method)

var $initial_values ; // from MNU_INITIAL_VALUES_USER/ROLE

var $initiated_from_controller = false ; // source of object instantiation

var $inner_table ; // used in an outer-link-inner relationship

var $instruction ; // instruction to be passed to previous script

var $is_link_table = false ; // used in method _sqlAssembleWhere (many-link-many relationship)

var $javascript = array ( ) ; // optional JavaScript code

var $lastpage ; // last available page number in current query

var $link_item ; // used in _sqlAssembleWhere() in many-to-many relationships

var $lookup_data = array ( ) ; // array of lookup data (for dropdowns, radio groups)

var $lookup_css = array ( ) ; // optional css classes for $lookup_data

var $messages = array ( ) ; // array of messages

var $nameof_end_date ; // alias for 'end_date'

var $nameof_start_date ; // alias for 'start_date'

var $noedit_array ; // array of fields which cannot be updated

var $no_controller_msg = false ; // prevent page controller from creating a message concerning this object

var $no_convert_timezone = false ; // turn off all timezone conversions

var $no_csv_header = false ; // turns off creation of header row in CSV output file

var $no_display_count = false ; // yes/no switch to display count after multiple inserts or updates

var $no_duplicate_error = false ; // if TRUE do not create an error when inserting a duplicate

var $no_foreign_data = false ; // if TRUE do not call getForeignData() method

var $no_submit_on_error = false ; // if TRUE drop any SUBMIT buttons after a validation error

var $numrows ; // number of rows retrieved

var $outer_table ; // used in an outer-link-inner relationship

var $pageno ; // requested page number

var $parent_relations = array ( ) ; // parent relationship specifications (optional)

var $parent_object ; // reference to parent object (if there is one in current task)

var $child_object ; // reference to child object (if there is one in current task)

var $pdf ; // object for PDF processing

var $pdf_filename ; //

var $pdf_destination ; // I=Inline (browser), D=Download (browser), F=Filename (on server), S=String

var $picker_subdir ; // subdirectory for the File Picker

var $picker_filetypes = array ( ) ; // array of file types

var $primary_key = array ( ) ; // column(s) which form the primary key

var $report_structure ; // report structure

var $resize_array ; // used in file uploads

var $retry_on_duplicate_key ; // field name to be incremented when insert fails

var $reuse_previous_select = false ; // reuse previous SELECT in _dml_ReadBeforeUpdate()

var $rows_per_page = 0 ; // page size for multi-row forms

var $row_locks ; // FALSE, SH=shared, EX=exclusive

var $row_locks_supp ; // supplemental lock type

var $scrollarray ; // array for internal scrolling

var $scrollindex ; // index to current item in scrollarray

var $select_string ; // identifies which entries have been selected

var $skip_getdata = false ; // YES/NO switch

var $skip_validation = false ; // YES/NO switch

var $tablename ; // table name (internal)

var $transaction_level ; // transaction level

var $unbuffered_query = false ; // used in getData_serial()

var $unique_keys = array ( ) ; // unique key specifications (optional)

var $update_on_duplicate_key = false ; // switch to 'update' if insert fails

var $upload_subdir ; // subdirectory for file upoads

var $upload_filetypes = array ( ) ; // file types for uploading

var $upload_maxfilesize ; // max file size for uploading

var $wf_case_id ; // workflow case id

var $wf_context ; // workitem context

var $wf_workitem_id ; // workflow workitem id

var $wf_user_id ; // update workitem with this value, not $_SESSION['logon_user_id']

var $xsl_params = array ( ) ; // optional parameters to be passed to XSL transformation

var $zone ; // set by page controller - main/outer/middle/inner

// the following are used to construct SQL queries

var $default_orderby = null ; // default for table, may be overridden by $sql_orderby

var $default_orderby_task = null ; // default for task, may be overridden by $sql_orderby

var $sql_from ;

var $sql_groupby ;

var $sql_having ;

var $sql_no_foreign_db = false ; // if TRUE _sqlProcessJoin() method will skip tables in other databases

var $sql_orderby ; // sort field

var $prev_sql_orderby ; // previous sort field

var $sql_orderby_seq ; // 'asc' or 'desc'

var $sql_orderby_table ; // tablename qualifier for optional sort criteria

var $sql_search ; // optional search criteria from a search screen (modifiable)

var $sql_search_orig ; // original search criteria (unmodified)

var $sql_search_table ; // tablename qualifier for optional search criteria

var $sql_select ; // fields to be selected

var $sql_selection ; // selection passed down from previous task

var $sql_union ; // optional UNION clause

var $sql_where ; // additional selection criteria

var $where ; // passed from parent form

// ****************************************************************************

// class constructor

// ****************************************************************************

function Default_Table ( )

{

// save directory name of current script

//$this->dirname = dirname(__file__);

$this -> dbms_engine = '' ; // to be supplied by getFieldSpec_original()

$this -> dbprefix = '' ; // to be supplied by getFieldSpec_original()

$this -> tablename = 'default' ;

$this -> dbname = 'default' ;

// call this method to get original field specifications

// (note that they may be modified at runtime)

$this -> fieldspec = $this -> getFieldSpec_original ( ) ;

} // Default_Table

// ****************************************************************************

function array2string ( $array )

// return an array of values (for a SET/ARRAY/VARRAY datatype) as a string.

// NOTE: the format of the string is dependent upon the DBMS.

{

$DML =& $this -> _getDBMSengine ( $this -> dbname ) ;

if ( is_string ( $array ) ) {

return $array ;

} // if

$string = $DML -> array2string ( $array ) ;

return $string ;

} // array2string

// ****************************************************************************

function cascadeDelete ( $where , $parent_table = null )

// Parent record is being deleted, so remove associated records from this table.

{

$errors = array ( ) ;

$this -> delete_count = null ;

// retrieve all records which match criteria in $where

$fieldarray = $this -> getData_raw ( $where ) ;

$errors = array_merge ( $errors , $this -> errors ) ;

// now delete them one at a time

$count = 0 ;

foreach ( $fieldarray as $rowdata ) {

$rowdata [ 'rdc_no_rollup' ] = true ; // do not cause delete of child to update the parent in a callback

$rowdata = $this -> _cm_pre_cascadeDelete ( $rowdata ) ;

$rowdata = $this -> deleteRecord ( $rowdata , $parent_table ) ;

if ( ! empty ( $this -> errors ) ) {

foreach ( $this -> errors as $error ) {

$errors [ ] = " $this->tablename - $error " ;

} // foreach

break ;

} // if

$count ++;

} // foreach

unset ( $fieldarray ) ;

if ( count ( $errors ) > 0 ) {

$this -> errors = $errors ;

return false ;

} // if

// save count so that values may be accumulated

$this -> delete_count [ strtoupper ( $this -> tablename ) ] = $count ;

// $count rows were deleted

return $this -> getLanguageText ( 'sys0004' , $count , strtoupper ( $this -> tablename ) ) ;

} // cascadeDelete

// ****************************************************************************

function cascadeNullify ( $update_array , $where )

// Parent record is being deleted, so nullify foreign keys in associated records in this table.

{

$errors = array ( ) ;

// retrieve all records which match criteria in $where

$fieldarray = $this -> getData_raw ( $where ) ;

$errors = array_merge ( $errors , $this -> errors ) ;

// now update them one at a time

foreach ( $fieldarray as $rowdata ) {

$rowdata = array_merge ( $rowdata , $update_array ) ;

$rowdata = $this -> updateRecord ( $rowdata ) ;

foreach ( $this -> errors as $error ) {

$errors [ ] = " $this->tablename - $error " ;

} // foreach

} // foreach

if ( count ( $errors ) > 0 ) {

$this -> errors = $errors ;

return false ;

} // if

return true ;

} // cascadeNullify

// ****************************************************************************

function changeConfig ( $fieldarray )

// check to seein any configuration settings need to be changed.

{

$where = null ;

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_changeConfig' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_changeConfig ( $where , $fieldarray ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

// change current table configuration (optional)

$fieldarray = $this -> _cm_changeConfig ( $where , $fieldarray ) ;

} // if

return $fieldarray ;

} // changeConfig

// ****************************************************************************

function checkWorkflow ( $where )

// check workflow system to see if this task is a pending workitem.

{

$this -> errors = array ( ) ;

if ( preg_match ( '/^(workflow|audit)$/i' , $this -> dbname ) OR defined ( 'TRANSIX_NO_WORKFLOW' ) OR defined ( 'RADICORE_NO_WORKFLOW' ) ) {

// do nothing

} else {

// find out if this task/context is a workitem within a workflow instance

$this -> _examineWorkflowInstance ( $where ) ;

} // if

return $this -> errors ;

} // checkWorkflow

// ****************************************************************************

function clearEditableData ( $fieldarray )

// initialise all editable fields in $fieldarray.

{

$fieldspec = $this -> fieldspec ;

foreach ( $fieldarray as $field => $value ) {

if ( array_key_exists ( $field , $fieldspec ) ) {

if ( $field == 'curr_or_hist' ) {

// reset to 'current' dates (the default)

$fieldarray [ $field ] = 'C' ;

} elseif ( array_key_exists ( 'noedit' , $fieldspec [ $field ] ) ) {

// field is not editable, so leave it alone

} else {

// field is editable, so remove current value

$fieldarray [ $field ] = NULL ;

} // if

} else {

$fieldarray [ $field ] = NULL ;

} // if

} // foreach

$this -> fieldarray = $fieldarray ;

return $fieldarray ;

} // clearEditableData

// ****************************************************************************

function clearScrollArray ( )

// initialise the internal $scrollarray.

{

$this -> scrollarray = array ( ) ;

$this -> scrollindex = 0 ;

$this -> pageno = 0 ;

$this -> numrows = 0 ;

$this -> lastpage = 0 ;

return ;

} // clearScrollArray

// ****************************************************************************

function commit ( )

// commit this transaction

{

$errors = array ( ) ;

$this -> sql_union = null ;

if ( preg_match ( '/^(workflow|audit)$/i' , $this -> dbname ) OR defined ( 'TRANSIX_NO_WORKFLOW' ) OR defined ( 'RADICORE_NO_WORKFLOW' ) ) {

// do nothing

} else {

// if this task+context is a pending workitem then update it

$errors = $this -> _examineWorkflow ( $this -> fieldarray ) ;

} // if

$DML =& $this -> _getDBMSengine ( $this -> dbname ) ;

if ( $errors ) {

$result = $DML -> rollback ( $this -> dbname_server ) ;

} else {

if ( $result = $DML -> commit ( $this -> dbname_server ) ) {

// update has been committed, so remove any 'run_at_cancel' reference

if ( $this -> initiated_from_controller ) {

if ( isset ( $GLOBALS [ 'script_vars' ] [ 'task_id_run_at_cancel' ] ) ) {

unset ( $GLOBALS [ 'script_vars' ] [ 'task_id_run_at_cancel' ] ) ;

unset ( $GLOBALS [ 'script_vars' ] [ 'task_id_run_at_cancel_context' ] ) ;

} // if

$script_vars = updateScriptVars ( $GLOBALS [ 'script_vars' ] ) ;

} // if

} else {

$errors [ ] = $this -> getLanguageText ( 'sys0009' ) ; // 'Commit failed'

} // if

} // if

$GLOBALS [ 'transaction_has_started' ] = FALSE ;

return $errors ;

} // commit

// ****************************************************************************

function convertTimeZone ( $fieldarray , $fieldspec )

// convert any datetime fields from client timezone to server timezone.

{

if ( isset ( $_SESSION [ 'display_timezone_party' ] ) AND is_True ( $_SESSION [ 'display_timezone_party' ] ) ) {

if ( ! empty ( $fieldarray [ 'party_timezone' ] ) ) {

$timezone_client = $fieldarray [ 'party_timezone' ] ; // timezone of data's party

} else {

$timezone_client = $_SESSION [ 'timezone_client' ] ; // timezone of logon user

} // if

} else {

$timezone_client = $_SESSION [ 'timezone_client' ] ; // timezone of logon user

} // if

if ( empty ( $_SESSION [ 'timezone_server' ] ) OR empty ( $timezone_client ) ) {

return $fieldarray ; // nothing to do

} // if

$dateobj =& RDCsingleton :: getInstance ( 'date_class' ) ;

foreach ( $fieldspec as $field => $spec ) {

if ( ! empty ( $fieldarray [ $field ] ) ) {

if ( preg_match ( '/^(datetime|timestamp)$/i' , $spec [ 'type' ] ) ) {

if ( ! isset ( $spec [ 'noedit' ] ) AND ! isset ( $spec [ 'nodisplay' ] ) ) {

$datetime = $dateobj -> getInternalDateTime ( $fieldarray [ $field ] , $spec ) ;

if ( $datetime === false ) {

$this -> errors [ $field ] = $dateobj -> errors ;

} // if

$fieldarray [ $field ] = convertTZ ( $datetime ,

$timezone_client ,

$_SESSION [ 'timezone_server' ] ) ;

} // if

} elseif ( preg_match ( '/^(date)$/i' , $spec [ 'type' ] ) ) {

if ( ! isset ( $spec [ 'noedit' ] ) AND ! isset ( $spec [ 'nodisplay' ] ) ) {

$date = $dateobj -> getInternalDate ( $fieldarray [ $field ] , $spec ) ;

if ( $date === false ) {

$this -> errors [ $field ] = $dateobj -> errors ;

} // if

$fieldarray [ $field ] = convertTZdate ( $date ,

'12:00:00' ,

$timezone_client ,

$_SESSION [ 'timezone_server' ] ) ;

} // if

} // if

} // if

} // foreach

return $fieldarray ;

} // convertTimeZone

// ****************************************************************************

function currentOrHistoric ( $string , $start_date = 'start_date' , $end_date = 'end_date' )

// convert the string 'current/historic/future' into a date range.

// NOTE: defaults to fields named START_DATE and END_DATE, but this may be changed.

{

if ( empty ( $start_date ) ) {

$start_date = 'start_date' ;

} // if

if ( empty ( $end_date ) ) {

$end_date = 'end_date' ;

} // if

// convert search string into an indexed array

$search = where2array ( $string , false , false ) ;

if ( isset ( $search [ 'curr_or_hist' ] ) ) {

// replace Current/Historic/Future with a range of dates

$search1 = stripOperators ( $search ) ;

// check that $start_date and $end_date exist in this table

if ( ! array_key_exists ( $start_date , $this -> fieldspec ) OR ! array_key_exists ( $end_date , $this -> fieldspec ) ) {

$search1 [ 'curr_or_hist' ] = 'invalid' ;

} else {

$today = getTimeStamp ( 'date' ) ;

switch ( $search1 [ 'curr_or_hist' ] ) {

case 'C' :

// search for records with CURRENT dates

$search [ $start_date ] = "<=' $today 23:59:59'" ;

$search [ $end_date ] = ">=' $today 00:00:00'" ;

break ;

case 'H' :

// search for records with HISTORIC dates

$search [ $end_date ] = "<' $today 00:00:00'" ;

break ;

case 'F' :

// search for records with FUTURE dates

$search [ $start_date ] = ">' $today 23:59:59'" ;

default :

;

} // switch

} // if

// rebuild search string without 'curr_or_hist' flag

unset ( $search [ 'curr_or_hist' ] ) ;

$string = array2where ( $search ) ;

} // if

return $string ;

} // currentOrHistoric

// ****************************************************************************

function customButton ( $fieldarray , $button , $postarray , $row = null )

// user pressed a custom button.

{

if ( $this -> errors ) {

return $this -> getFieldArray ( ) ; // object has unresolved errors, so do nothing

} // if

// filter out any data which does not belong in this table

$postarray = getPostArray ( $postarray , $this -> fieldspec ) ;

if ( ! is_long ( key ( $fieldarray ) ) ) {

$fieldarray = array ( $fieldarray ) ; // ensure it is indexed by row

} // if

if ( $this -> rows_per_page == 1 ) {

// this is the only row

$row = 0 ;

$fieldarray = array_update_associative ( $fieldarray [ $row ] , $postarray , $this -> fieldspec ) ;

$output = $this -> _cm_customButton ( $fieldarray , $button ) ;

} else {

// this is one of many rows

if ( empty ( $row ) ) $row = 1 ; // default

$row = $row - 1 ; // screen rows start at #1 while database rows start at zero

if ( array_key_exists ( $row , $fieldarray ) ) {

$fieldarray = array_update_indexed ( $fieldarray , $postarray , $this -> fieldspec ) ;

$output = $this -> _cm_customButton ( $fieldarray [ $row ] , $button ) ;

} // if

} // if

reset ( $output ) ;

if ( is_long ( key ( $output ) ) ) {

// output is indexed, so replace entire array

$this -> fieldarray = $output ;

} else {

// output is associative, so replace single row

if ( $this -> rows_per_page == 1 ) {

$this -> fieldarray = array ( $row => $output ) ;

} else {

$this -> fieldarray [ $row ] = $output ;

} // if

} // if

// see if any additional data is required or needs to be changed

$this -> fieldarray = $this -> getExtraData ( $this -> fieldarray ) ;

if ( count ( $this -> fieldarray ) == 1 ) {

if ( empty ( $this -> fieldarray [ key ( $this -> fieldarray ) ] ) ) {

$this -> fieldarray = array ( ) ; // contains a single empty element, so clear it out

} // if

} // if

return $this -> getFieldArray ( ) ;

} // customButton

// ****************************************************************************

function deleteMultiple ( $fieldarray )

// delete multiple records using data in $fieldarray.

{

$errors = array ( ) ;

$this -> no_display_count = false ;

$count = 0 ;

if ( isset ( $GLOBALS [ 'batch' ] ) AND is_True ( $GLOBALS [ 'batch' ] ) ) {

// check to see if this task is a pending workitem

$errors = $this -> checkWorkflow ( $fieldarray [ 0 ] ) ;

if ( $errors ) {

return $fieldarray ;

} // if

} // if

if ( empty ( $this -> errors ) ) {

// perform any additional custom pre-processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_pre_deleteMultiple' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_pre_deleteMultiple ( $fieldarray ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_pre_deleteMultiple ( $fieldarray ) ;

} // if

} // if

if ( ! $this -> errors ) {

// delete each row one by one

foreach ( $fieldarray as $rownum => $row ) {

$row = $this -> deleteRecord ( $row ) ;

if ( ! empty ( $this -> errors ) ) {

// accumulate all errors

//$errors = array_merge($errors, $this->errors);

$errors [ $rownum ] = $this -> errors ;

} else {

$count = $count + $this -> numrows ;

} // if

} // foreach

if ( empty ( $this -> errors ) ) {

// perform any additional custom post-processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_post_deleteMultiple' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_post_deleteMultiple ( $fieldarray ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_post_deleteMultiple ( $fieldarray ) ;

} // if

} // if

} // if

if ( is_True ( $this -> no_display_count ) ) {

// do not display record count

} else {

// '$count records were deleted from $tablename'

$this -> messages [ ] = $this -> getLanguageText ( 'sys0004' , $count , strtoupper ( $this -> tablename ) ) ;

} // if

$this -> errors = $errors ;

$this -> numrows = $count ;

return $fieldarray ;

} // deleteMultiple

// ****************************************************************************

function deleteRecord ( $fieldarray , $parent_table = null )

// delete the record specified in $fieldarray.

// ($parent_table is only used in a cascade delete)

{

$this -> errors = array ( ) ; // initialise

if ( empty ( $fieldarray ) ) {

return $fieldarray ; // nothing to delete

} // if

if ( is_string ( $fieldarray ) ) {

// convert from string to array

$fieldarray = where2array ( $fieldarray ) ;

} // if

// shift all field names to lower case

$fieldarray = array_change_key_case ( $fieldarray , CASE_LOWER ) ;

if ( ! $this -> skip_getdata ) {

// check that full primary key (or candidate key) has been supplied

list ( $where , $errors ) = isPkeyComplete ( $fieldarray , $this -> getPkeyNames ( ) , $this -> unique_keys ) ;

if ( ! empty ( $errors ) ) {

$this -> errors = $errors ;

} // if

if ( empty ( $this -> errors ) ) {

// obtain copy of original record from database

$where = array2where ( $fieldarray , $this -> getPkeyNames ( ) , $this ) ;

$originaldata = $this -> _dml_ReadBeforeUpdate ( $where ) ;

if ( $this -> numrows == 0 ) {

return $fieldarray ; // there is nothing to delete

} elseif ( $this -> numrows == 1 ) {

// use only 1st row in $originaldata

$originaldata = $originaldata [ 0 ] ;

// insert non-key values for inclusion in audit log

$fieldarray = array_merge ( $fieldarray , $originaldata ) ;

if ( ! empty ( $this -> unique_keys ) ) {

// rebuild $where from pkey in case candidate key was used

$where = array2where ( $fieldarray , $this -> getPkeyNames ( ) , $this ) ;

} // if

} else {

// more than 1 record found - key is not unique

$this -> errors [ ] = $this -> getLanguageText ( 'sys0113' ) ;

} // if

} // if

} // if

// check that this record can be deleted

$numrows = $this -> numrows ;

if ( empty ( $this -> errors ) ) {

$fieldarray = $this -> validateDelete ( $fieldarray , $parent_table ) ;

} // if

if ( empty ( $this -> errors ) ) {

// perform any custom pre-delete processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_pre_deleteRecord' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_pre_deleteRecord ( $fieldarray ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_pre_deleteRecord ( $fieldarray ) ;

} // if

} // if

if ( empty ( $this -> errors ) ) {

// delete any tables related to the specified record

$this -> deleteRelations ( $fieldarray ) ;

} // if

$this -> numrows = $numrows ;

if ( empty ( $this -> errors ) AND $this -> numrows > 0 ) {

// delete the specified record

$this -> _dml_deleteRecord ( $fieldarray ) ;

} // if

if ( empty ( $this -> errors ) ) {

// perform any custom post-delete processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_post_deleteRecord' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_post_deleteRecord ( $fieldarray ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_post_deleteRecord ( $fieldarray ) ;

} // if

} // if

return $fieldarray ;

} // deleteRecord

// ****************************************************************************

function deleteRelations ( $fieldarray )

// delete any child records whch are linked to the current record.

{

$this -> errors = array ( ) ;

if ( empty ( $this -> child_relations ) ) {

return ;

} // if

// process contents of $child_relations array

foreach ( $this -> child_relations as $reldata ) {

$tblchild = $reldata [ 'child' ] ;

switch ( strtoupper ( $reldata [ 'type' ] ) ) {

case 'NULLIFY' :

case 'NUL' :

// set foreign key(s) to null

$where = NULL ;

$update_array = array ( ) ;

foreach ( $reldata [ 'fields' ] as $fldparent => $fldchild ) {

//if (strlen($fldchild) < 1) {

// // 'Name of child field missing in relationship with $tblchild'

// $this->errors[] = $this->getLanguageText('sys0110', strtoupper($tblchild));

// break;

//} // if

if ( ! empty ( $fldchild ) ) {

if ( empty ( $where ) ) {

$where = " $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} else {

$where .= " AND $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} // if

} // if

$update_array [ $fldchild ] = NULL ;

} // foreach

if ( empty ( $where ) ) {

// 'Name of child field missing in relationship with $tblchild'

$this -> errors [ ] = $this -> getLanguageText ( 'sys0110' , strtoupper ( $tblchild ) ) ;

break ;

} else {

// instantiate an object for this table

if ( array_key_exists ( 'subsys_dir' , $reldata ) ) {

// get path to current subsystem directory

$dir = dirname ( $this -> dirname ) ;

// switch to other subsystem directory

$dir = dirname ( $dir ) . '/' . $reldata [ 'subsys_dir' ] . '/' ;

} else {

$dir = NULL ;

} // if

if ( ! class_exists ( $tblchild ) ) {

require_once $dir . "classes/ $tblchild .class.inc" ;

} // if

$childobject = new $tblchild ;

if ( ! empty ( $this -> dbname_old ) AND $this -> dbname_old == $childobject -> dbname ) {

// name of parent database has been switched, so switch the child name as well

$childobject -> dbname_old = $childobject -> dbname ;

$childobject -> dbname = $this -> dbname ;

} // if

$childobject -> audit_logging = $this -> audit_logging ;

$childobject -> sql_no_foreign_db = $this -> sql_no_foreign_db ;

// now use this object to delete child records

if ( ! $childobject -> cascadeNullify ( $update_array , $where ) ) {

$this -> errors = array_merge ( $childobject -> getErrors ( ) , $this -> errors ) ;

} // if

unset ( $childobject ) ;

} // if

break ;

case 'DELETE' ;

case 'DEL' :

case 'CASCADE' :

case 'CAS' :

// delete all related rows

$where = NULL ;

foreach ( $reldata [ 'fields' ] as $fldparent => $fldchild ) {

//if (strlen($fldchild) < 1) {

// // 'Name of child field missing in relationship with $tblchild'

// $this->errors[] = $this->getLanguageText('sys0110', strtoupper($tblchild));

// break;

//} // if

if ( ! empty ( $fldchild ) ) {

if ( empty ( $where ) ) {

$where = " $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} else {

$where .= " AND $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} // if

} // if

} // foreach

if ( empty ( $where ) ) {

// 'Name of child field missing in relationship with $tblchild'

$this -> errors [ ] = $this -> getLanguageText ( 'sys0110' , strtoupper ( $tblchild ) ) ;

break ;

} else {

// instantiate an object for this table

if ( array_key_exists ( 'subsys_dir' , $reldata ) ) {

// get path to current subsystem directory

$dir = dirname ( $this -> dirname ) ;

// switch to other subsystem directory

$dir = dirname ( $dir ) . '/' . $reldata [ 'subsys_dir' ] . '/' ;

} else {

$dir = NULL ;

} // if

if ( ! class_exists ( $tblchild ) ) {

require_once $dir . "classes/ $tblchild .class.inc" ;

} // if

$childobject = new $tblchild ;

if ( ! empty ( $this -> dbname_old ) AND $this -> dbname_old == $childobject -> dbname ) {

// name of parent database has been switched, so switch the child name as well

$childobject -> dbname_old = $childobject -> dbname ;

$childobject -> dbname = $this -> dbname ;

} // if

$childobject -> audit_logging = $this -> audit_logging ;

$childobject -> sql_no_foreign_db = $this -> sql_no_foreign_db ;

// check for 'order by' clause

if ( isset ( $reldata [ 'orderby' ] ) ) {

$childobject -> default_orderby = $reldata [ 'orderby' ] ;

} // if

// now use this object to delete child records

if ( ! $msg = $childobject -> cascadeDelete ( $where , $this -> tablename ) ) {

$this -> errors = array_merge ( $childobject -> getErrors ( ) , $this -> errors ) ;

} else {

if ( ! empty ( $childobject -> delete_count ) AND is_array ( $childobject -> delete_count ) ) {

foreach ( $childobject -> delete_count as $table => $count ) {

if ( isset ( $this -> delete_count [ $table ] ) ) {

$this -> delete_count [ $table ] += $count ;

} else {

$this -> delete_count [ $table ] = $count ;

} // if

} // foreach

} // if

} // if

unset ( $childobject ) ;

} // if

break ;

case 'RESTRICTED' :

case 'RES' :

case 'IGN' :

// do nothing

break ;

case 'DEX' :

case 'NUX' :

// do nothing as it will be handled by a foreign key constraint

break ;

default :

// 'Unknown relation type: $type'

$this -> errors [ ] = $this -> getLanguageText ( 'sys0010' , $reldata [ 'type' ] ) ;

} // switch

} // foreach

return ;

} // deleteRelations

// ****************************************************************************

function deleteScrollItem ( $index )

// delete the specified item from $scrollarray, then return the details of the

// next available item.

{

if ( $index > count ( $this -> scrollarray ) ) {

// index is too high, so do not delete

$index = count ( $this -> scrollarray ) ;

} elseif ( $index < 1 ) {

// index is too low, so do not delete

$index = 1 ;

} else {

// index is valid, so remove indicated item

unset ( $this -> scrollarray [ $index ] ) ;

// resequence the array after removing this item

$array [ 0 ] = 'dummy' ;

foreach ( $this -> scrollarray as $entry ) {

$array [ ] = $entry ;

} // foreach

unset ( $array [ 0 ] ) ;

$this -> scrollarray = $array ;

if ( $index > count ( $this -> scrollarray ) ) {

// index is too high, so do not delete

$index = count ( $this -> scrollarray ) ;

} // if

} // if

// replace $where with details from the next available entry in scrollarray

if ( is_array ( $this -> scrollarray [ $index ] ) ) {

$where = array2where ( $this -> scrollarray [ $index ] ) ;

} else {

$where = $this -> scrollarray [ $index ] ;

} // if

// set values to be used by scrolling logic

$this -> scrollindex = $index ;

$this -> pageno = $index ;

$this -> lastpage = count ( $this -> scrollarray ) ;

return $where ;

} // deletetScrollItem

// ****************************************************************************

function deleteSelection ( $selection )

// delete/update a selection of records in one operation.

{

$this -> errors = array ( ) ;

if ( empty ( $selection ) ) {

// 'Nothing has been selected yet.'

$this -> errors [ ] = scriptPrevious ( $this -> getLanguageText ( 'sys0081' ) ) ;

return ;

} // if

// call custom method for specific processing

$msg = $this -> _cm_deleteSelection ( $selection ) ;

return $msg ;

} // deleteSelection

// ****************************************************************************

function eraseRecord ( $fieldarray )

// delete the record, and ALL its children, specified in $fieldarray.

{

$this -> errors = array ( ) ;

if ( is_string ( $fieldarray ) ) {

// convert from string to array

$fieldarray = where2array ( $fieldarray , false , false ) ;

} // if

// strip any operators from the value portion of the array

$fieldarray = stripOperators ( $fieldarray ) ;

// check that full primary key has been supplied

list ( $where , $errors ) = isPkeyComplete ( $fieldarray , $this -> getPkeyNames ( ) ) ;

if ( ! empty ( $errors ) ) {

$this -> errors = $errors ;

} // if

if ( empty ( $this -> errors ) ) {

// get field specifications for this database table

$fieldspec = $this -> fieldspec ;

// remove any non-database fields from input array

foreach ( $fieldarray as $field => $fieldvalue ) {

// check that $field exists in $fieldspec array

if ( ! array_key_exists ( $field , $fieldspec ) ) {

// it does not (like the SUBMIT button, for example), so remove it

unset ( $fieldarray [ $field ] ) ;

} // if

} // foreach

} // if

// perform any custom pre-erase processing

if ( empty ( $this -> errors ) ) {

$fieldarray = $this -> _cm_pre_eraseRecord ( $fieldarray ) ;

} // if

// delete any tables related to the specified record

if ( empty ( $this -> errors ) ) {

$this -> eraseRelations ( $fieldarray ) ;

} // if

// delete the specified record

if ( empty ( $this -> errors ) ) {

$this -> _dml_deleteRecord ( $fieldarray ) ;

} // if

// perform any custom post-delete processing

if ( empty ( $this -> errors ) ) {

$fieldarray = $this -> _cm_post_eraseRecord ( $fieldarray ) ;

} // if

return $fieldarray ;

} // eraseRecord

// ****************************************************************************

function eraseRelations ( $fieldarray )

// erase any child records whch are linked to the current record.

// this is done by treating every relationship type as CASCADE DELETE

{

$this -> errors = array ( ) ;

if ( empty ( $this -> child_relations ) OR empty ( $fieldarray ) ) {

return ;

} // if

// process contents of $child_relations array

foreach ( $this -> child_relations as $reldata ) {

$tblchild = $reldata [ 'child' ] ;

if ( array_key_exists ( 'subsys_dir' , $reldata ) ) {

// do not erase from a database in another subsystem

} else {

switch ( strtoupper ( $reldata [ 'type' ] ) ) {

case 'DEX' :

case 'NUX' :

// do nothing as it will be handled by a foreign key constraint

break ;

case 'IGN' :

// ignore this relationship

break ;

case 'NULLIFY' :

case 'NUL' :

// set foreign key(s) to null

$where = NULL ;

$update_array = array ( ) ;

foreach ( $reldata [ 'fields' ] as $fldparent => $fldchild ) {

if ( strlen ( $fldchild ) < 1 ) {

// 'Name of child field missing in relationship with $tblchild'

$this -> errors [ ] = $this -> getLanguageText ( 'sys0110' , strtoupper ( $tblchild ) ) ;

break ;

} // if

if ( empty ( $where ) ) {

$where = " $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} else {

$where .= " AND $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} // if

$update_array [ $fldchild ] = NULL ;

} // foreach

// instantiate an object for this table

if ( array_key_exists ( 'subsys_dir' , $reldata ) ) {

// get path to current subsystem directory

$dir = dirname ( $this -> dirname ) ;

// switch to other subsystem directory

$dir = dirname ( $dir ) . '/' . $reldata [ 'subsys_dir' ] . '/' ;

} else {

$dir = NULL ;

} // if

if ( ! class_exists ( $tblchild ) ) {

require_once $dir . "classes/ $tblchild .class.inc" ;

} // if

$childobject = new $tblchild ;

// now use this object to delete child records

if ( ! $childobject -> cascadeNullify ( $update_array , $where ) ) {

$this -> errors = array_merge ( $childobject -> getErrors ( ) , $this -> errors ) ;

} // if

unset ( $childobject ) ;

break ;

case 'DELETE' :

case 'DEL' :

case 'CASCADE' :

case 'CAS' :

case 'RESTRICTED' :

case 'RES' :

// erase all related rows

$where = NULL ;

foreach ( $reldata [ 'fields' ] as $fldparent => $fldchild ) {

if ( strlen ( $fldchild ) < 1 ) {

// 'Name of child field missing in relationship with $tblchild'

$this -> errors [ ] = $this -> getLanguageText ( 'sys0110' , strtoupper ( $tblchild ) ) ;

break ;

} // if

if ( empty ( $where ) ) {

$where = " $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} else {

$where .= " AND $fldchild ='" . addslashes ( $fieldarray [ $fldparent ] ) . "'" ;

} // if

} // foreach

// instantiate an object for this table

if ( array_key_exists ( 'subsys_dir' , $reldata ) ) {

// get path to current subsystem directory

$dir = dirname ( $this -> dirname ) ;

// switch to other subsystem directory

$dir = dirname ( $dir ) . '/' . $reldata [ 'subsys_dir' ] . '/' ;

} else {

$dir = NULL ;

} // if

if ( ! class_exists ( $tblchild ) ) {

require_once $dir . "classes/ $tblchild .class.inc" ;

} // if

$childobject = new $tblchild ;

// check for 'order by' clause

if ( isset ( $reldata [ 'orderby' ] ) ) {

$childobject -> default_orderby = $reldata [ 'orderby' ] ;

} // if

// pass down the current audit logging switch

$childobject -> audit_logging = $this -> audit_logging ;

$childdata = $childobject -> getData_raw ( $where ) ;

foreach ( $childdata as $childrow ) {

// now use this object to delete each child record one at a time

$childobject -> eraseRecord ( $childrow ) ;

if ( $childobject -> getErrors ( ) ) {

$this -> errors = array_merge ( $childobject -> getErrors ( ) , $this -> errors ) ;

} // if

} // foreach

unset ( $childobject ) ;

break ;

default :

// 'Unknown relation type: $type'

$this -> errors [ ] = $this -> getLanguageText ( 'sys0010' , $reldata [ 'type' ] ) ;

} // switch

} // if

} // foreach

if ( count ( $this -> errors ) > 0 ) {

return false ;

} // if

return true ;

} // eraseRelations

// ****************************************************************************

function executeQuery ( $query )

// execute one or more pre-defined queries.

// $query may be a string (single query) or an array (multiple queries).

{

$DML =& $this -> _getDBMSengine ( $this -> dbname ) ;

$DML -> setRowLocks ( $this -> row_locks ) ;

if ( is_array ( $query ) ) {

$temp = $query ;

$temp = array_map ( "trim" , $temp ) ;

} else {

$query = trim ( $query ) ;

// split string into an array of individual queries

$pattern = "/

( # start group

[^';]+ # match as much as possible which doesn't include ' or ;

| # or

'[^']*' # a single quoted string

)* # end group, repeated

/six" ;

preg_match_all ( $pattern , $query , $regs ) ;

$temp = $regs [ 0 ] ;

} // if

$query_array = array ( ) ;

foreach ( $temp as $entry ) {

// ensure each entry ends with ';'

$entry = trim ( $entry ) ;

if ( ! empty ( $entry ) ) {

if ( substr ( $entry , - 1 , 1 ) != ';' ) {

$entry .= ';' ;

} // if

$query_array [ ] = $entry ;

} // if

} // foreach

$result = $DML -> multiQuery ( $this -> dbname_server , $this -> tablename , $query_array ) ;

return $result ;

} // executeQuery

// ****************************************************************************

function fetchRow ( $resource )

// Fetch the next row from a resource created in the getData_serial() method.

{

$this -> errors = array ( ) ;

if ( $this -> skip_getdata ) {

if ( empty ( $this -> fieldarray ) ) {

$row = false ;

} else {

$row = array_shift ( $this -> fieldarray ) ;

$row = $this -> _cm_post_fetchRow ( $row ) ;

} // if

return $row ;

} // if

$DML =& $this -> _getDBMSengine ( $this -> dbname ) ;

$row = $DML -> fetchRow ( $this -> dbname_server , $resource ) ;

if ( $row ) {

// perform any custom post-retrieve processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_post_fetchRow' ) ) {

$row = $this -> custom_processing_object -> _cm_post_fetchRow ( $row ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

if ( $row ) {

$row = $this -> _cm_post_fetchRow ( $row ) ;

} // if

} // if

if ( empty ( $row ) ) {

// this row has been cancelled, so read another one

$row = $this -> fetchRow ( $resource ) ;

} // if

} // if

return $row ;

} // fetchRow

// ****************************************************************************

function fetchRowChild ( $row )

// See if there is are any child records associated with the current row.

// (for example, a node in a tree structure may have child nodes)

// Any child rows are returned one at a time.

// Note that each child row may also have its own children.

{

$this -> errors = array ( ) ;

if ( empty ( $row ) ) return FALSE ;

$keys = array ( ) ;

// get names of SENIOR and JUNIOR keys

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_getNodeKeys' ) ) {

$keys = $this -> custom_processing_object -> _cm_getNodeKeys ( $keys ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

if ( $row ) {

$keys = $this -> _cm_getNodeKeys ( $keys ) ;

} // if

} // if

$snr_id = $keys [ 'snr_id' ] ;

$jnr_id = $keys [ 'jnr_id' ] ;

$resources =& $this -> resource_array ;

if ( ! is_array ( $resources ) ) {

$resources = array ( ) ;

} // if

if ( empty ( $resources ) ) {

// create a new resource

$where = " $snr_id ='{ $row [ $jnr_id ]}'" ;

$resource = $this -> getData_serial ( $where ) ;

} else {

$resource = array_pop ( $resources ) ;

} // if

$resources [ ] =& $resource ;

$row = $this -> fetchRow ( $resource ) ; // read a single row

if ( empty ( $row ) ) {

$null = array_pop ( $resources ) ; // this resource has been exhausted

while ( ! empty ( $resources ) ) {

$resource = array_pop ( $resources ) ;

$row = $this -> fetchRow ( $resource ) ; // read a single row

if ( ! empty ( $row ) ) {

$resources [ ] =& $resource ; // resource not exhausted yet, so put it back

// create a new resource for possible children

$where = " $snr_id ='{ $row [ $jnr_id ]}'" ;

$child_resource = $this -> getData_serial ( $where ) ;

$resources [ ] = $child_resource ;

break ;

} // if

} // while

} else {

$where = " $snr_id ='{ $row [ $jnr_id ]}'" ;

$child_resource = $this -> getData_serial ( $where ) ;

$resources [ ] = $child_resource ;

} // if

if ( ! empty ( $row ) AND ! empty ( $row [ 'level' ] ) ) {

$row [ 'level' ] = count ( $resources ) ;

} // if

return $row ;

} // fetchRowChild

// ****************************************************************************

function filePickerSelect ( $selection )

// Deal with selection from a filepicker screen.

{

$selection = $this -> _cm_filePickerSelect ( $selection ) ;

return $selection ;

} // filePickerSelect

// ****************************************************************************

function fileUpload ( $input_name , $temp_file )

// Specify file name to be used for the upload.

{

$this -> errors = array ( ) ;

$fieldarray = where2array ( $this -> where ) ;

$output_name = $this -> _cm_fileUpload ( $input_name , $temp_file , $fieldarray ) ;

return $this -> upload_subdir . '/' . $output_name ;

} // fileUpload

// ****************************************************************************

function formatData ( $fieldarray , & $css_array )

// format values retrieved from the database before they are shown to the user.

// (such as changing dates from 'CCYY-MM-DD' to 'dd Mmm CCYY'

// NOTE: $css_array is passed BY REFERENCE as it may be altered.

{

if ( empty ( $fieldarray ) ) return $fieldarray ;

$dateobj =& RDCsingleton :: getInstance ( 'date_class' ) ;

if ( ! empty ( $fieldarray [ 'party_timezone' ] ) ) {

if ( ! isset ( $_SESSION [ 'display_timezone_party' ] ) OR $_SESSION [ 'display_timezone_party' ] === false ) {

$this -> messages [ ] = getLanguageText ( 'sys0238' ) ; // "DateTimes shown in User's timezone"

} else {

$this -> messages [ ] = getLanguageText ( 'sys0239' ) ; // "DateTimes shown in Party's timezone"

} // if

} // if

foreach ( $fieldarray as $fieldname => $fieldvalue ) {

// only deal with fields defined in $fieldspec

if ( isset ( $this -> fieldspec [ $fieldname ] ) ) {

// get specifications for current field

$fieldspec = $this -> fieldspec [ $fieldname ] ;

if ( ! isset ( $fieldspec [ 'type' ] ) ) {

$fieldspec [ 'type' ] = 'string' ; // set default type

} // if

if ( $GLOBALS [ 'mode' ] == 'search' ) {

if ( preg_match ( '/^(is not null|is null)$/i' , trim ( $fieldvalue ) , $regs ) ) {

$fieldvalue = strtoupper ( $regs [ 0 ] ) ;

$fieldspec [ 'type' ] = 'string' ;

$operator = '' ;

} elseif ( preg_match ( "/^(<>|<=|<|>=|>|!=|=)/" , $fieldvalue , $regs ) ) {

$operator = $regs [ 0 ] ;

// strip operator from front of string

$fieldvalue = substr ( $fieldvalue , strlen ( $operator ) ) ;

if ( substr ( $fieldvalue , 0 , 1 ) == "'" ) {

// remove leading quote

$fieldvalue = substr ( $fieldvalue , 1 ) ;

} // if

if ( substr ( $fieldvalue , - 1 ) == "'" ) {

// remove trailing quote

$fieldvalue = substr ( $fieldvalue , 0 , - 1 ) ;

} // if

} else {

$operator = '=' ;

} // if

} else {

$operator = '=' ;

} // if

switch ( strtolower ( $fieldspec [ 'type' ] ) ) {

case 'string' :

if ( isset ( $fieldspec [ 'control' ] ) AND $fieldspec [ 'control' ] == 'multidrop' ) {

list ( $operator , $value , $delimiter ) = extractOperatorValue ( $fieldvalue ) ;

if ( trim ( $operator ) == 'IN' ) {

// turn this string into an array

$value = trim ( $value , '()' ) ;

$array = explode ( ',' , $value ) ;

foreach ( $array as $key => $entry ) {

if ( substr ( $entry , 0 , 1 ) == "'" ) {

// remove leading quote

$entry = substr ( $entry , 1 ) ;

} // if

if ( substr ( $entry , - 1 , 1 ) == "'" ) {

// remove leading quote

$entry = substr ( $entry , 0 , strlen ( $entry ) - 1 ) ;

} // if

$array [ $key ] = $entry ;

} // foreach

$fieldvalue = $array ;

$operator = '=' ;

} // if

} // if

break ;

case 'set' :

case 'array' :

if ( ! is_array ( $fieldvalue ) ) {

// convert string into an array

if ( strlen ( $fieldvalue ) > 0 ) {

// note: postgresql uses '{}' to enclose the array

$fieldvalue = explode ( ',' , trim ( $fieldvalue , '{}' ) ) ;

} else {

$fieldvalue = array ( ) ;

} // if

} // if

break ;

case 'boolean' :

if ( is_bool ( $fieldvalue ) or strlen ( $fieldvalue ) > 0 ) {

$boolean = $this -> getLanguageArray ( 'boolean' ) ;

// set boolean fields to either TRUE or FALSE

if ( is_True ( $fieldvalue ) ) {

if ( isset ( $fieldspec [ 'true' ] ) ) {

$fieldvalue = $fieldspec [ 'true' ] ;

} elseif ( isset ( $boolean [ 'true' ] ) ) {

$fieldvalue = $boolean [ 'true' ] ;

} // if

} else {

if ( isset ( $fieldspec [ 'false' ] ) ) {

$fieldvalue = $fieldspec [ 'false' ] ;

} elseif ( isset ( $boolean [ 'false' ] ) ) {

$fieldvalue = $boolean [ 'false' ] ;

} // if

} // if

} else {

// value has not defined yet

if ( $GLOBALS [ 'mode' ] != 'search' ) {

if ( isset ( $fieldspec [ 'default' ] ) ) {

// default value has been defined, so use it

$fieldvalue = $fieldspec [ 'default' ] ;

} // if

} else {

// leave as undefined

} // if

} // if

break ;

case 'date' :

if ( isset ( $fieldspec [ 'infinityisnull' ] ) and substr ( $fieldvalue , 0 , 10 ) == '9999-12-31' ) {

// this date is shown to the user as empty

$fieldvalue = '' ;

} else {

if ( $GLOBALS [ 'mode' ] == 'search' and strpos ( $fieldvalue , '%' ) ) {

// this is already in LIKE format for a search screen. so leave it alone

// (apart from removing trailing '%' which will be replaced later)

$fieldvalue = rtrim ( $fieldvalue , '%' ) ;

} elseif ( ! empty ( $fieldvalue ) ) {

if ( $this -> no_convert_timezone === FALSE AND isset ( $_SESSION [ 'timezone_server' ] ) ) {

$date = $dateobj -> getInternalDate ( $fieldvalue ) ;

if ( $date === false ) {

$this -> errors [ $fieldname ] = $dateobj -> errors ;

return $fieldarray ;

} // if

if ( isset ( $_SESSION [ 'display_timezone_party' ] ) AND is_True ( $_SESSION [ 'display_timezone_party' ] ) ) {

if ( ! empty ( $fieldarray [ 'party_timezone' ] ) ) {

$timezone_client = $fieldarray [ 'party_timezone' ] ; // timezone of data's party

} else {

$timezone_client = $_SESSION [ 'timezone_client' ] ; // timezone of logon user

} // if

} else {

$timezone_client = $_SESSION [ 'timezone_client' ] ; // timezone of logon user

} // if

$fieldvalue = convertTZdate ( $date , '12:00:00' , $_SESSION [ 'timezone_server' ] , $timezone_client ) ;

} // if

// convert date from internal to external format

if ( $date = $dateobj -> getExternalDate ( $fieldvalue , $_SESSION [ 'date_format_output' ] ) ) {

$fieldvalue = $date ;

} else {

// date cannot be converted, so leave as is

} // if

} // if

} // if

break ;

case 'datetime' :

case 'timestamp' :

if ( isset ( $fieldspec [ 'infinityisnull' ] ) and substr ( $fieldvalue , 0 , 10 ) == '9999-12-31' ) {

// this date is shown to the user as empty

$fieldvalue = '' ;

} else {

if ( ! empty ( $fieldvalue ) ) {

if ( $this -> no_convert_timezone === FALSE AND isset ( $_SESSION [ 'timezone_server' ] ) ) {

$datetime = $dateobj -> getInternalDateTime ( $fieldvalue , $fieldspec ) ;

if ( $datetime === false ) {

$this -> errors [ $fieldname ] = $dateobj -> errors ;

return $fieldarray ;

} // if

if ( isset ( $_SESSION [ 'display_timezone_party' ] ) AND is_True ( $_SESSION [ 'display_timezone_party' ] ) ) {

if ( ! empty ( $fieldarray [ 'party_timezone' ] ) ) {

$timezone_client = $fieldarray [ 'party_timezone' ] ; // timezone of data's party

} else {

$timezone_client = $_SESSION [ 'timezone_client' ] ; // timezone of logon user

} // if

} else {

$timezone_client = $_SESSION [ 'timezone_client' ] ; // timezone of logon user

} // if

$fieldvalue = convertTZ ( $datetime , $_SESSION [ 'timezone_server' ] , $timezone_client ) ;

} // if

// look for a time portion (ends with '99:99' or '99:99:99')

if ( preg_match ( '/([0-9]{2}:[0-9]{2}){1}(:[0-9]{2})?$/' , $fieldvalue , $regs ) ) {

$time = $regs [ 0 ] ;

$date = substr ( $fieldvalue , 0 , - strlen ( $time ) ) ;

} else {

$date = $fieldvalue ;

$time = null ;

} // if

// convert date from internal to external format

if ( $date = $dateobj -> getExternalDate ( $date , $_SESSION [ 'date_format_output' ] ) ) {

$fieldvalue = trim ( $date ) . ' ' . substr ( trim ( $time ) , 0 , 8 ) ;

} else {

// date cannot be converted, so leave as is

} // if

} // if

} // if

break ;

case 'time' :

if ( isset ( $fieldspec [ 'size' ] ) and $fieldspec [ 'size' ] == 5 ) {

// exclude the seconds portion of the time

$fieldvalue = substr ( $fieldarray [ $fieldname ] , 0 , 5 ) ;

} // if

break ;

case 'integer' :

if ( $fieldvalue == 0 AND isset ( $fieldspec [ 'blank_when_zero' ] ) ) {

if ( $operator == '=' ) {

$fieldvalue = '' ; // value is zero, so display blank

} // if

} // if

break ;

case 'double' :

case 'float' :

case 'real' :

if ( ! empty ( $fieldvalue ) ) {

if ( is_numeric ( $fieldvalue ) ) {

$float = sprintf ( '%F' , $fieldvalue ) ;

$float = rtrim ( $float , '0' ) ; // remove trailing zeroes after decimal point

$float = rtrim ( $float , '.' ) ; // remove decimal point if it is the last character

if ( strlen ( $float ) > 18 ) {

$fieldvalue = ( double ) $fieldvalue ; // number is too long, so display in scientific notation

} else {

$fieldvalue = $float ; // display as decimal number

} // if

} // if

} // if

break ;

case 'decimal' :

case 'numeric' :

if ( isset ( $fieldspec [ 'scale' ] ) ) {

$decimal_places = $fieldspec [ 'scale' ] ;

} else {

$decimal_places = 0 ;

} // if

if ( $fieldvalue == 0 AND isset ( $fieldspec [ 'blank_when_zero' ] ) ) {

if ( $operator == '=' ) {

$fieldvalue = '' ; // value is zero, so display blank

} // if

} else {

// remove any thousands separators

// this screws up -> $fieldvalue = number_unformat($fieldvalue);

// format number according to current locale settings

$strip_trailing_zero =& $fieldspec [ 'strip_trailing_zero' ] ;

$fieldvalue = formatNumber ( $fieldvalue , $decimal_places , $strip_trailing_zero ) ;

} // if

break ;

default :

;

} // switch

if ( preg_match ( '/^(csv|pdf)/i' , strtolower ( $GLOBALS [ 'mode' ] ) ) ) {

if ( isset ( $fieldspec [ 'optionlist' ] ) ) {

if ( empty ( $fieldvalue ) ) {

$fieldvalue = null ;

} else {

// convert value into corresponding entry(s) from optionlist

if ( isset ( $this -> lookup_data [ $fieldspec [ 'optionlist' ] ] ) ) {

$lookup = $this -> lookup_data [ $fieldspec [ 'optionlist' ] ] ;

if ( ! empty ( $lookup ) ) {

if ( is_array ( $fieldvalue ) ) {

// convert array into a comma separated string

$string = '' ;

foreach ( $fieldvalue as $key ) {

$string .= $lookup [ $key ] . ',' ;

} // foreach

$fieldvalue = rtrim ( $string , ',' ) ;

} else {

if ( array_key_exists ( $fieldvalue , $lookup ) ) {

$fieldvalue = $lookup [ $fieldvalue ] ;

} // if

} // if

} // if

} // if

} // if

} elseif ( isset ( $fieldspec [ 'foreign_field' ] ) ) {

if ( isset ( $fieldarray [ $fieldspec [ 'foreign_field' ] ] ) ) {

$fieldvalue = $fieldarray [ $fieldspec [ 'foreign_field' ] ] ;

} // if

} // if

} // if

if ( isset ( $fieldspec [ 'password' ] ) ) {

if ( isset ( $fieldspec [ 'hash' ] ) ) {

if ( preg_match ( '/(sha1|md5)/i' , $fieldspec [ 'hash' ] ) ) {

// for this hash type do not output anything

$fieldvalue = '' ;

} // if

} // if

} // if

// put changed value back into array

if ( $GLOBALS [ 'mode' ] == 'search' AND $operator != '=' ) {

$fieldarray [ $fieldname ] = $operator . $fieldvalue ;

} else {

$fieldarray [ $fieldname ] = $fieldvalue ;

} // if

} else {

// not in $this->fieldspec, so cannot be formatted

$fieldarray [ $fieldname ] = $fieldvalue ;

} // if

} // foreach

// perform any custom formatting

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_formatData' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_formatData ( $fieldarray , $css_array ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_formatData ( $fieldarray , $css_array ) ;

} // if

return $fieldarray ;

} // formatData

// ****************************************************************************

function free_result ( $resource )

// free a resource created by getData_serial()

{

$result = $this -> _dml_free_result ( $resource ) ;

return $result ;

} // free_result

// ****************************************************************************

function & getChildData ( )

// return $fieldarray from the child object (if there is one).

// NOTE: output is passed by reference.

{

if ( ! is_object ( $this -> child_object ) ) {

return FALSE ;

} elseif ( ! method_exists ( $this -> child_object , 'getFieldArray' ) ) {

return FALSE ;

} // if

$child_data =& $this -> child_object -> getFieldArray ( ) ;

return $child_data ;

} // getChildData

// ****************************************************************************

function getClassName ( )

// return the name of this class, but without any numeric suffix.

// Example: table 'mnu_tran' may have subtypes (aliases) of 'mnu_tran_s01'

// and 'mnu_tran_jnr'. These will return the following:

// 'mnu_task' -> 'mnu_task'

// 'mnu_task_s01' -> 'mnu_task'

// 'mnu_task_jnr' -> 'mnu_task_jnr'

{

$tablename = removeTableSuffix ( get_class ( $this ) ) ;

return strtolower ( $tablename ) ;

} // getClassName

// ****************************************************************************

function getColumnNames ( $where = null )

// obtain list of column names which will be output with this SQL statement.

// (this is used in 'std.output4.inc')

{

$this -> rows_per_page = 1 ;

$this -> fieldspec = $this -> getFieldSpec_original ( ) ;

$fieldarray = array ( ) ;

$fieldspec = array ( ) ;

$this -> lookup_data [ 'selected' ] = $this -> getLanguageArray ( 'selected' ) ;;

$data = $this -> getData ( $where ) ;

if ( empty ( $data ) ) return $data ;

$fieldarray = $data [ 0 ] ;

// initial value for each column is 'selected'

foreach ( $fieldarray as $fieldname => & $fieldvalue ) {

$fieldvalue = 'Y' ;

} // foreach

// modify list of column names and their default values

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_getColumnNames' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_getColumnNames ( $fieldarray ) ;

} // if

} // if

if ( $this -> errors ) return ;

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_getColumnNames ( $fieldarray ) ;

if ( $this -> errors ) return ;

} // if

ksort ( $fieldarray ) ;

foreach ( $fieldarray as $fieldname => & $fieldvalue ) {

// each field has a 'Yes/No' dropdown with an initial value

if ( is_True ( $fieldvalue ) ) {

$fieldvalue = 'Y' ;

} else {

$fieldvalue = 'N' ;

} // if

$fieldspec [ $fieldname ] = array ( 'type' => 'string' ,

'control' => 'dropdown' ,

'optionlist' => 'selected' ) ;

// add this column to the screen structure

$GLOBALS [ 'screen_structure' ] [ 'main' ] [ 'fields' ] [ ] = array ( $fieldname => $fieldname , 'colspan' => 3 ) ;

} // foreach

// add controls for LIMIT and OFFSET

$fieldspec [ 'rdc_limit' ] = array ( 'type' => 'integer' , 'minvalue' => 0 , 'maxvalue' => 4294967295 , 'required' => 'y' ) ;

$fieldspec [ 'rdc_offset' ] = array ( 'type' => 'integer' , 'minvalue' => 0 , 'maxvalue' => 4294967295 , 'required' => 'y' ) ;

$fieldarray [ 'rdc_limit' ] = 1000 ;

$fieldarray [ 'rdc_offset' ] = 0 ;

// append fields for LIMIT and OFFSET

$col_count = count ( $GLOBALS [ 'screen_structure' ] [ 'main' ] [ 'fields' ] ) + 1 ;

$GLOBALS [ 'screen_structure' ] [ 'main' ] [ 'fields' ] [ $col_count ] [ ] = array ( 'label' => 'rdc_limit' , ) ;

$GLOBALS [ 'screen_structure' ] [ 'main' ] [ 'fields' ] [ $col_count ] [ ] = array ( 'field' => 'rdc_limit' ) ;

$GLOBALS [ 'screen_structure' ] [ 'main' ] [ 'fields' ] [ $col_count ] [ ] = array ( 'label' => 'rdc_offset' ) ;

$GLOBALS [ 'screen_structure' ] [ 'main' ] [ 'fields' ] [ $col_count ] [ ] = array ( 'field' => 'rdc_offset' ) ;

$this -> rows_per_page = 0 ; // allow multiple rows to be returned on the next call to getData()

$this -> fieldspec = $fieldspec ;

$this -> fieldarray = $fieldarray ;

return $fieldarray ;

} // getColumnNames

// ****************************************************************************

function getCount ( $where = null )

// get count of records that satisfy selection criteria in $where.

{

if ( strlen ( trim ( $where ) ) > 0 ) {

$count = $this -> _dml_getCount ( $where ) ;

return $count ;

} else {

return 0 ;

} // if

} // getCount

// ****************************************************************************

function getData ( $where = null )

// get data from this table using optional 'where' criteria.

// this is formatted before being displayed to the user.

{

$this -> errors = array ( ) ; // initialise

$data_raw = array ( ) ;

// if (!empty($this->sql_where)) {

// // remove anything in $this->sql_where which is duplicated in $where

// $this->sql_where = filterWhere1Where2($where, $this->sql_where, $this->tablename);

// } // if

$this -> where = $where ; // save

if ( is_null ( $this -> pageno ) ) {

$this -> pageno = 1 ; //default

} // if

// convert $where from string to an associative array

$where_array = where2array ( $where , $this -> pageno ) ;

if ( ! empty ( $where_array [ 'rdc_table_name' ] ) ) {

$where_array = convert_parent_id_to_child_id ( $where_array , $this -> tablename , $this -> parent_relations ) ;

$where = array2where ( $where_array ) ;

} // if

// make this data available if passed down by parent object

if ( empty ( $this -> fieldarray ) ) {

$fieldarray = array ( ) ;

} else {

if ( is_string ( key ( $this -> fieldarray ) ) ) {

$fieldarray = $this -> fieldarray ;

} else {

$fieldarray = array_shift ( $this -> fieldarray ) ;

} // if

} // if

if ( $this -> initiated_from_controller ) {

// replace with original unmodified version

$this -> sql_search = $this -> sql_search_orig ;

} // if

// perform any custom pre-retrieve processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_pre_getData' ) ) {

$where = $this -> custom_processing_object -> _cm_pre_getData ( $where , $where_array , $fieldarray ) ;

} // if

} // if

if ( $this -> errors ) return ;

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$where = $this -> _cm_pre_getData ( $where , $where_array , $fieldarray ) ;

if ( $this -> errors ) return ;

} // if

if ( $this -> where != $where ) {

// $where has been modified, so update $where_array

$this -> where = $where ;

$where_array = where2array ( $where , $this -> pageno ) ;

} // if

if ( $this -> checkPrimaryKey AND ! $this -> allow_empty_where ) {

// check that full primary key (or candidate key) has been supplied

list ( $where1 , $errors1 ) = isPkeyComplete ( $where_array , $this -> getPkeyNames ( ) , $this -> unique_keys , $this ) ;

if ( ! empty ( $errors1 ) ) {

$this -> errors = $errors1 ;

return ;

} // if

$this -> checkPrimaryKey = false ;

} // if

if ( $this -> skip_getdata ) {

// use data already loaded in

if ( is_int ( key ( $this -> fieldarray ) ) ) {

// already indexed by row

$data_raw = $this -> fieldarray ;

} else {

if ( empty ( $this -> fieldarray ) ) {

$data_raw = array ( ) ;

} else {

// associative array, so make it row zero

$data_raw [ 0 ] = $this -> fieldarray ;

} // if

} // if

$this -> numrows = count ( $data_raw ) ;

if ( empty ( $this -> scrollarray ) ) {

// set record/page counts from contents of $this->fieldarray

if ( $this -> numrows == 0 ) {

$this -> lastpage = 0 ;

$this -> pageno = 0 ;

} else {

if ( $this -> rows_per_page > 0 ) {

$this -> lastpage = ceil ( $this -> numrows / $this -> rows_per_page ) ;

} else {

$this -> lastpage = $this -> numrows ;

} // if

if ( $this -> pageno < 1 ) {

$this -> pageno = 1 ;

} elseif ( $this -> pageno > $this -> lastpage ) {

$this -> pageno = $this -> lastpage ;

} // if

} // if

} // if

} else {

// assemble the $where string from its component parts

$where_str = $this -> _sqlAssembleWhere ( $where , $where_array ) ;

// get the data from the database

$data_raw = $this -> _dml_getData ( $where_str ) ;

} // if

if ( ! empty ( $this -> select_string ) ) {

$data_raw = $this -> setSelectedRows ( $this -> select_string , $data_raw ) ;

} // if

if ( $this -> initiated_from_controller ) {

if ( isset ( $GLOBALS [ 'script_vars' ] [ 'task_id_run_at_end' ] ) ) {

if ( $this -> rows_per_page > 1

OR ( $this -> rows_per_page = 1 AND $this -> numrows > 1 ) ) {

// too many rows selected, so turn this option off

unset ( $GLOBALS [ 'script_vars' ] [ 'task_id_run_at_end' ] ) ;

unset ( $GLOBALS [ 'script_vars' ] [ 'task_id_run_at_end_context' ] ) ;

} else {

// set context for this option

$GLOBALS [ 'script_vars' ] [ 'task_id_run_at_end_context' ] = $where ;

} // if

} // if

} // if

if ( $GLOBALS [ 'mode' ] != 'insert' ) {

// clear 'nodisplay' option which may have been by previous iteration

foreach ( $this -> fieldspec as $field => $spec ) {

if ( array_key_exists ( 'autoinsert' , $spec ) or array_key_exists ( 'autoupdate' , $spec ) ) {

unset ( $this -> fieldspec [ $field ] [ 'nodisplay' ] ) ;

} // if

} // foreach

} // if

// $entry = getEntryPoint($this);

// if (strtolower($entry) == 'getdata') {

if ( isset ( $this -> instruction ) ) {

$data_raw = $this -> _processInstruction ( $data_raw ) ;

} // if

// perform any custom post-retrieve processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_post_getData' ) ) {

$data_raw = $this -> custom_processing_object -> _cm_post_getData ( $data_raw , $where ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$data_raw = $this -> _cm_post_getData ( $data_raw , $where ) ;

} // if

$this -> where = $where ;

// } // if

$this -> fieldarray = $data_raw ;

return $this -> fieldarray ;

} // getData

// ****************************************************************************

function getData_raw ( $where = null )

// get data from this table using optional 'where' criteria.

// this is returned raw (as read from the database with any formatting).

{

$this -> errors = array ( ) ;

// convert $where from string to an associative array

$where_array = where2array ( $where ) ;

if ( isset ( $this -> fieldspec [ 'rdcaccount_id' ] ) ) {

// this table is split by account, so account_id must be supplied in WHERE string

if ( ! isset ( $where_array [ 'rdcaccount_id' ] ) ) {

$account_id =& $_SESSION [ 'rdcaccount_id' ] ;

if ( empty ( $account_id ) AND preg_match ( '/(mnu_user|mnu_account)/i' , $this -> tablename ) ) {

// no account id supplied, so read everything on these tables only

} else {

if ( empty ( $account_id ) OR $account_id == 1 ) {

$account_id_string = " $this->tablename .rdcaccount_id='1'" ;

} else {

$account_id_string = " $this->tablename .rdcaccount_id IN ('1', ' $account_id ')" ;

} // if

if ( empty ( $this -> sql_where ) ) {

$this -> sql_where = $account_id_string ;

} else {

if ( substr_count ( $this -> sql_where , $account_id_string ) == 0 ) {

$this -> sql_where .= " AND $account_id_string " ;

} // if

} // if

} // if

} // if

} // if

if ( ! empty ( $this -> sql_where ) ) {

if ( preg_match ( '/^(OR )/i' , $this -> sql_where ) ) {

// begins with 'OR ', so do not append using ' AND '

$where .= ' ' . $this -> sql_where ;

} else {

if ( empty ( $where ) ) {

$where = $this -> sql_where ;

} else {

$where = " $where AND $this->sql_where " ;

} // if

} // if

} // if

if ( ! empty ( $this -> sql_search ) ) {

// turn 'current/historic/future' into a range of dates

$this -> sql_search = $this -> currentOrHistoric ( $this -> sql_search , $this -> nameof_start_date , $this -> nameof_end_date ) ;

if ( ! empty ( $this -> sql_search ) ) {

if ( empty ( $where ) ) {

$where = $this -> sql_search ;

} else {

$where = " $where AND $this->sql_search " ;

} // if

} // if

} // if

// if (!empty($this->sql_from)) {

// $alias_array = extractAliasNames($this->sql_select);

// // anything in WHERE which has an alias name will be moved to HAVING

// $having_array = where2array($this->sql_having, false, false);

// $where = qualifyWhere($where, $this->tablename, $this->fieldspec, $this->sql_from, $this->sql_search_table, $alias_array, $having_array);

// } // if

$data_raw = $this -> _dml_getData ( $where , TRUE ) ;

return $data_raw ;

} // getData_raw

// ****************************************************************************

function getData_serial ( $where = null , $rdc_limit = null , $rdc_offset = null , $unbuffered = false )

// get data from this table using optional 'where' criteria.

// this does not return the records one page at a time but allows a serial

// read via the fetchRow() method of all records for processing in another way,

// such as exporting to CSV.

{

$this -> errors = array ( ) ; // initialise

$this -> where = $where ; // save

// convert $where from string to an associative array

$where_array = where2array ( $where , $this -> pageno ) ;

if ( $this -> initiated_from_controller AND ! empty ( $this -> sql_search_orig ) ) {

// replace with original unmodified version

$this -> sql_search = $this -> sql_search_orig ;

} // if

// perform any custom pre-retrieve processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_pre_getData' ) ) {

$where = $this -> custom_processing_object -> _cm_pre_getData ( $where , $where_array , $this -> fieldarray ) ;

} // if

} // if

if ( $this -> errors ) return ;

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$where = $this -> _cm_pre_getData ( $where , $where_array ) ;

if ( $this -> errors ) return ;

} // if

if ( $this -> where != $where ) {

// $where has been modified, so update $where_array

$this -> where = $where ;

$where_array = where2array ( $where , $this -> pageno ) ;

} // if

if ( $this -> checkPrimaryKey ) {

// check that full primary key (or candidate key) has been supplied

list ( $where1 , $errors1 ) = isPkeyComplete ( $where_array , $this -> getPkeyNames ( ) , $this -> unique_keys ) ;

if ( ! empty ( $errors1 ) ) {

$this -> errors = $errors1 ;

return ;

} // if

$this -> checkPrimaryKey = false ;

} // if

if ( $this -> skip_getdata ) {

// do not populate $this->fieldarray from the database

if ( is_int ( key ( $this -> fieldarray ) ) ) {

// already indexed by row

$data_raw = $this -> fieldarray ;

} else {

// associative array, so make it row zero

$data_raw [ 0 ] = $this -> fieldarray ;

} // if

$this -> fieldarray = $data_raw ;

$this -> numrows = count ( $data_raw ) ;

$resource = null ;

} else {

// assemble the $where string from its component parts

$where_str = $this -> _sqlAssembleWhere ( $where , $where_array ) ;

// get the result from the database

$resource = $this -> _dml_getData_serial ( $where_str , $rdc_limit , $rdc_offset , $this -> unbuffered_query ) ;

} // if

// Note: individual records are obtained using the fetchRow() method

return $resource ;

} // getData_serial

// ****************************************************************************

function getDBname ( )

// return the database name for this table.

{

return strtolower ( $this -> dbname ) ;

} // getDBname

// ****************************************************************************

function getEnum ( $fieldname )

// get the contents of an ENUM field and return it as an array.

{

$array = $this -> _dml_getEnum ( $fieldname ) ;

return $array ;

} // getEnum

// ****************************************************************************

function getErrors ( )

// return array of error messages

{

$errors = $this -> errors ;

$this -> errors = array ( ) ;

if ( ! is_array ( $errors ) ) {

// convert string into an array

$errors = ( array ) $errors ;

} // if

return $errors ;

} // getErrors

// ****************************************************************************

function getExpanded ( )

// get array of tree nodes which have been expanded

{

$expanded = $this -> expanded ;

$this -> expanded = array ( ) ;

return $expanded ;

} // getExpanded

// ****************************************************************************

function getExtraData ( $input , $where = null )

// get additional data for this table, such as lookup lists.

{

//$this->errors = array();

// $input may be an array or a string

if ( empty ( $input ) ) {

$fieldarray [ 0 ] = array ( ) ;

$key = 0 ;

$where = null ;

} elseif ( is_string ( $input ) ) {

// convert from string to associative array

$fieldarray [ 0 ] = where2array ( $input ) ;

$key = 0 ;

$where = $input ;

} else {

reset ( $input ) ; // fix for version 4.4.1

if ( is_string ( key ( $input ) ) ) {

// associative array, so set it to row zero

$fieldarray [ 0 ] = $input ;

$key = 0 ;

} else {

// indexed by row, so use it as-is

$fieldarray = $input ;

$key = key ( $input ) ;

} // if

// convert first row in $fieldarray to a string

//$where = array2where($fieldarray[$key]);

} // if

if ( is_True ( $this -> no_foreign_data ) ) {

// skip this next bit

} else {

// retrieve data from foreign (parent) tables for each row

foreach ( $fieldarray as $rownum => $rowdata ) {

$fieldarray [ $rownum ] = $this -> getForeignData ( $rowdata ) ;

} // foreach

} // if

// perform custom processing (such as obtaining lookup lists) on FIRST record only

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_getExtraData' ) ) {

$fieldarray [ $key ] = $this -> custom_processing_object -> _cm_getExtraData ( $where , $fieldarray [ $key ] ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray [ $key ] = $this -> _cm_getExtraData ( $where , $fieldarray [ $key ] ) ;

} // if

$fieldarray [ $key ] = array_change_key_case ( $fieldarray [ $key ] , CASE_LOWER ) ;

// change current table configuration (optional)

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_changeConfig' ) ) {

$fieldarray [ $key ] = $this -> custom_processing_object -> _cm_changeConfig ( $where , $fieldarray [ $key ] ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

// change current table configuration (optional)

$fieldarray [ $key ] = $this -> _cm_changeConfig ( $where , $fieldarray [ $key ] ) ;

} // if

$pattern_id = getPatternId ( ) ;

if ( preg_match ( '/MULTI4/i' , $pattern_id ) AND ! empty ( $this -> initial_values ) ) {

foreach ( $fieldarray as $rownum => $rowdata ) {

// insert any initial values obtained from MNU_INITIAL_VALUE_ROLE/USER table

foreach ( $this -> initial_values as $key1 => $value1 ) {

if ( empty ( $rowdata [ $key1 ] ) ) {

// current value is empty, so overwrite with initial value

$rowdata [ $key1 ] = $value1 ;

} // if

} // foreach

$fieldarray [ $rownum ] = $rowdata ;

} // foreach

} // if

// store updated $fieldarray within this object

$this -> fieldarray = $fieldarray ;

return $this -> getFieldArray ( ) ;

} // getExtraData

// ****************************************************************************

function getFieldArray ( )

// return array of data that currently resides within this object

// (usually stuff which was retrieved from the database).

{

if ( empty ( $this -> fieldarray ) ) {

return array ( ) ;

} // if

reset ( $this -> fieldarray ) ;

if ( $this -> rows_per_page == 1 ) {

// return an associative array (one row only)

if ( is_long ( key ( $this -> fieldarray ) ) ) {

return $this -> fieldarray [ 0 ] ; // convert indexed to associative

} else {

return $this -> fieldarray ;

} // if

} else {

// return an indexed array (one or more rows)

if ( is_long ( key ( $this -> fieldarray ) ) ) {

return $this -> fieldarray ;

} else {

return array ( $this -> fieldarray ) ; // convert associative to indexed

} // if

} // if

} // getFieldArray

// ****************************************************************************

function getFieldSpec ( )

// return array of field specifications (which may be adjusted by $this->field_access).

{

if ( ! empty ( $this -> field_access ) ) {

// include specified access_type in $fieldspec array

foreach ( $this -> field_access as $field_id => $access_type ) {

if ( array_key_exists ( $field_id , $this -> fieldspec ) ) {

$this -> fieldspec [ $field_id ] [ $access_type ] = 'y' ;

} // if

} // foreach

} // if

return $this -> fieldspec ;

} // getFieldSpec

// ****************************************************************************

function getFieldSpec_original ( )

// set the specifications for this database table.

{

if ( empty ( $this -> fieldspec ) ) {

// first time only - look for changes in engine, prefix or database name

list ( $dbname , $this -> dbprefix , $this -> dbms_engine ) = findDBConfig ( $this -> dbname ) ;

$this -> dbname_server = $this -> dbprefix . $dbname ;

} // if

if ( is_bool ( $this -> audit_logging ) OR ! empty ( $this -> audit_logging ) ) {

$save_audit_logging = $this -> audit_logging ;

} else {

$save_audit_logging = null ;

} // if

$fieldspec = array ( ) ;

$this -> primary_key = array ( ) ;

$this -> unique_keys = array ( ) ;

$this -> child_relations = array ( ) ;

$this -> parent_relations = array ( ) ;

$this -> audit_logging = FALSE ;

$this -> default_orderby = '' ;

$this -> alt_language_table = '' ;

$this -> alt_language_cols = '' ;

$this -> nameof_start_date = '' ;

$this -> nameof_end_date = '' ;

$tablename = $this -> getTableName ( ) ;

if ( $tablename != 'default' ) {

// include table specifications generated by Data Dictionary

if ( ! empty ( $this -> dirname_dict ) ) {

require ( $this -> dirname_dict . '/' . $tablename . '.dict.inc' ) ;

} else {

require ( $this -> dirname . '/' . $tablename . '.dict.inc' ) ;

} // if

if ( is_bool ( $save_audit_logging ) OR ! empty ( $save_audit_logging ) ) {

$this -> audit_logging = $save_audit_logging ;

} // if

} // if

if ( ! empty ( $_SESSION [ 'date_format_output' ] ) ) {

$dateobj =& RDCsingleton :: getInstance ( 'date_class' ) ;

foreach ( $fieldspec as $field => $spec ) {

if ( preg_match ( '/date/i' , $spec [ 'type' ] , $regs ) ) {

$date_length = $dateobj -> getDateLength ( $_SESSION [ 'date_format_output' ] , $spec [ 'type' ] ) ;

$fieldspec [ $field ] [ 'size' ] = $date_length ;

} // if

} // foreach

} // if

if ( defined ( 'TRANSIX_NO_AUDIT' ) OR defined ( 'NO_AUDIT_LOGGING' ) ) {

$this -> audit_logging = false ;

} // if

//if (empty($this->custom_processing_object)) {

if ( $this -> dbname != 'default' ) {

$this -> _getCustomProcessingObject ( ) ;

} // if

return $fieldspec ;

} // getFieldSpec_original

// ****************************************************************************

function getForeignData ( $fieldarray )

// Retrieve data from foreign (parent) database tables.

// (parent tables are identified in $this->parent_relations)

{

if ( empty ( $fieldarray ) ) {

return $fieldarray ;

} // if

// perform custom processing before standard processing

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_getForeignData' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_getForeignData ( $fieldarray ) ;

} // if

} // if

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_getForeignData ( $fieldarray ) ;

} // if

$fieldarray = array_change_key_case ( $fieldarray , CASE_LOWER ) ;

foreach ( $this -> parent_relations as $reldata ) {

if ( isset ( $reldata [ 'parent_field' ] ) ) {

// may be more than one parent_field, so turn it into an array of separate field names

list ( $parent_fields , $alias_array ) = extractFieldNamesIndexed ( $reldata [ 'parent_field' ] ) ;

$ix = 0 ; // set to first entry

if ( ! empty ( $fieldarray [ $parent_fields [ $ix ] ] ) ) {

// parent field is already there, so do nothing

} else {

// construct WHERE clause to read from parent table

$where_array = array ( ) ;

foreach ( $reldata [ 'fields' ] as $fldchild => $fldparent ) {

if ( strlen ( $fldchild ) < 1 ) {

// 'Name of child field missing in relationship with $tblchild'

$this -> errors [ ] = $this -> getLanguageText ( 'sys0110' , strtoupper ( $tblchild ) ) ;

break ;

} // if

if ( ! isset ( $fieldarray [ $fldchild ] ) or strlen ( $fieldarray [ $fldchild ] ) == 0 ) {

// foreign key field is missing, so stop further processing

$where_array = array ( ) ;

break ;

} // if

if ( preg_match ( '/^(IS NULL|IS NOT NULL)$/i' , trim ( $fieldarray [ $fldchild ] ) ) ) {

if ( $GLOBALS [ 'mode' ] != 'search' ) {

// does not contain a proper value, so do not attempt to read

$fieldarray [ $fldchild ] = null ;

} // if

$where_array = array ( ) ;

break ;

} // if

$where_array [ $fldparent ] = $fieldarray [ $fldchild ] ;

} // foreach

if ( empty ( $where_array ) ) {

// $where is empty, so set foreign field(s) to empty

foreach ( $parent_fields as $ix => $parent_field ) {

if ( ! isset ( $this -> fieldspec [ $parent_field ] ) ) {

// field is not is current $fieldspec array, so it can be initialised

$fieldarray [ $parent_field ] = null ;

} // if

} // foreach

} else {

$where = array2where ( $where_array , false , false , true ) ;

$tblparent = $reldata [ 'parent' ] ;

// instantiate an object for this table

if ( array_key_exists ( 'subsys_dir' , $reldata ) ) {

$save_cwd = getcwd ( ) ;

// switch to other directory so that any includes() within the class

// are relative to that directory and not the current directory

$dir = dirname ( $this -> dirname ) ; // path to current subsystem directory

$dir = dirname ( $dir ) . '/' . $reldata [ 'subsys_dir' ] . '/' ; // switch to other subsystem directory

chdir ( $dir ) ;

} else {

$save_cwd = NULL ;

} // if

if ( ! class_exists ( $tblparent ) ) {

require_once "classes/ $tblparent .class.inc" ;

} // end

$parentobj = new $tblparent ;

$parentobj -> sql_select = $reldata [ 'parent_field' ] ;

$parent_data = $parentobj -> getData ( $where ) ;

unset ( $parentobj ) ;

if ( ! empty ( $parent_data ) ) {

// copy specified parent field(s) into $fieldarray

foreach ( $parent_fields as $ix => $parent_field ) {

if ( empty ( $fieldarray [ $parent_field ] ) ) {

// field is currently empty, so replace it with parent value

if ( array_key_exists ( $parent_field , $parent_data [ 0 ] ) ) {

$fieldarray [ $parent_field ] = $parent_data [ 0 ] [ $parent_field ] ;

} else {

// original name not found, so look for an alias

list ( $original , $alias ) = getFieldAlias3 ( $alias_array [ $ix ] ) ;

if ( $original != $alias ) {

$fieldarray [ $parent_field ] = $parent_data [ 0 ] [ $original ] ;

} // if

} // if

} // if

} // foreach

} else {

if ( $GLOBALS [ 'mode' ] == 'search' ) {

// key may be incomplete, so leave it alone

} else {

// not found, so set foreign key(s) to empty

//foreach ($reldata['fields'] as $fldchild => $fldparent) {

// if (in_array($fldchild, $this->primary_key)) {

// // part of primary key, so leave it alone

// } else {

// // not part of primary key, so empty it

// $fieldarray[$fldchild] = null;

// } // f

//} // foreach

} // if

} // if

if ( ! empty ( $save_cwd ) ) {

// switch back to the original working directory

chdir ( $save_cwd ) ;

} // if

} // if

} // if

} // if

} // foreach

return $fieldarray ;

} // getForeignData

// ****************************************************************************

function getInitialData ( $where )

// get initial data for new records in this table.

{

$this -> errors = array ( ) ;

$this -> numrows = 0 ;

if ( ! empty ( $where ) ) {

if ( is_array ( $where ) ) {

$fieldarray = $where ;

} else {

// convert 'where' string to an associative array

$fieldarray = where2array ( $where ) ;

foreach ( $fieldarray as $fieldname => $fieldvalue ) {

if ( ! is_string ( $fieldname ) ) {

// this is a numeric index, not a valid field name, so remove it

unset ( $fieldarray [ $fieldname ] ) ;

} else {

if ( preg_match ( '/^(IS NULL|IS NOT NULL|NOT IN|IN[ ]?\()/i' , trim ( $fieldvalue ) ) ) {

// not a valid value, so remove it

unset ( $fieldarray [ $fieldname ] ) ;

} elseif ( array_key_exists ( $fieldname , $this -> fieldspec ) ) {

if ( ! empty ( $fieldvalue ) ) {

// do not allow any items in $where criteria to be changed

$this -> fieldspec [ $fieldname ] [ 'noedit' ] = 'y' ;

} // if

} // if

} // if

} // foreach

} // if

} else {

$fieldarray = array ( ) ;

} // if

if ( ! empty ( $this -> initial_values ) ) {

// insert any initial values obtained from MNU_INITIAL_VALUE_ROLE/USER table

foreach ( $this -> initial_values as $key => $value ) {

if ( empty ( $fieldarray [ $key ] ) ) {

// current value is empty, so overwrite with initial value

$fieldarray [ $key ] = $value ;

} // if

} // foreach

} // if

if ( is_True ( $this -> allow_scrolling ) ) {

$save_pageno = $this -> pageno ;

$save_lastpage = $this -> lastpage ;

} // if

// perform any custom processing (optional)

$this -> sqlSelectInit ( ) ;

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_getInitialData' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_getInitialData ( $fieldarray ) ;

} // if

} // if

if ( $this -> errors ) return $fieldarray ;

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

$fieldarray = $this -> _cm_getInitialData ( $fieldarray ) ;

} // if

if ( $this -> errors ) return $fieldarray ;

if ( is_True ( $this -> allow_scrolling ) ) {

$this -> pageno = $save_pageno ;

$this -> lastpage = $save_lastpage ;

} // if

$fieldarray = array_change_key_case ( $fieldarray , CASE_LOWER ) ;

if ( isset ( $this -> fieldspec [ 'rdcaccount_id' ] ) ) {

if ( empty ( $_SESSION [ 'rdcaccount_id' ] ) ) {

if ( preg_match ( '/(mnu_user|mnu_account)/i' , $this -> tablename ) ) {

// do nothing on this table

} else {

// use the 'sharing' id

$fieldarray [ 'rdcaccount_id' ] = 1 ;

} // if

} else {

if ( isset ( $fieldarray [ 'rdcaccount_id' ] ) AND $fieldarray [ 'rdcaccount_id' ] != $_SESSION [ 'rdcaccount_id' ] ) {

// "User's account (X) is not compatible with record's account (Y)";

$this -> errors [ 'rdcaccount_id' ] = getLanguageText ( 'sys0232' , $_SESSION [ 'rdcaccount_id' ] , $fieldarray [ 'rdcaccount_id' ] ) ;

return $fieldarray ;

} else {

// always use this user's account_id

$fieldarray [ 'rdcaccount_id' ] = $_SESSION [ 'rdcaccount_id' ] ;

} // if

} // if

} // if

// do not display autoinsert/autoupdate fields on input screens

foreach ( $this -> fieldspec as $field => $spec ) {

if ( array_key_exists ( 'auto_increment' , $spec ) OR array_key_exists ( 'autoinsert' , $spec ) OR array_key_exists ( 'autoupdate' , $spec ) ) {

$this -> fieldspec [ $field ] [ 'nodisplay' ] = 'y' ;

} // if

} // foreach

reset ( $fieldarray ) ; // fix to enable key($fieldarray) to work

if ( ! empty ( $fieldarray ) and ! is_string ( key ( $fieldarray ) ) ) {

// this has multiple rows, so ignore

} else {

// shift all field names to lower case

$fieldarray = array_change_key_case ( $fieldarray , CASE_LOWER ) ;

if ( is_True ( $this -> ignore_empty_fields ) ) {

// do not insert any missing fields

$this -> ignore_empty_fields = false ;

} else {

// insert values for any missing fields

foreach ( $this -> fieldspec as $fieldname => $spec ) {

if ( isset ( $spec [ 'nondb' ] ) ) {

// this is a non-database field, so ignore it

} else {

if ( ! isset ( $fieldarray [ $fieldname ] ) OR strlen ( $fieldarray [ $fieldname ] ) < 1 ) {

if ( isset ( $spec [ 'default' ] ) AND strlen ( $spec [ 'default' ] ) > 0 AND ! preg_match ( '/(date|time|datetime)/i' , $spec [ 'type' ] ) ) {

if ( array_key_exists ( 'auto_increment' , $spec ) OR array_key_exists ( 'autoinsert' , $spec ) OR array_key_exists ( 'autoupdate' , $spec ) OR $fieldname == 'rdcaccount_id' ) {

// value will be inserted later

$fieldarray [ $fieldname ] = NULL ;

} else {

// default value exists, so load it

$fieldarray [ $fieldname ] = $spec [ 'default' ] ;

} // if

} else {

// load an empty value so the field will appear in the XML output

$fieldarray [ $fieldname ] = NULL ;

} // if

} // if

} // if

} // foreach

} // if

} // if

$this -> fieldarray = $fieldarray ;

return $fieldarray ;

} // getInitialData

// ****************************************************************************

function getInitialDataMultiple ( $where )

// get initial data for new records in this table.

// this is called before insertMultiple(), so there is no user dialog.

{

$this -> errors = array ( ) ;

$this -> numrows = 0 ;

if ( ! empty ( $where ) ) {

if ( is_array ( $where ) ) {

$fieldarray = $where ;

} else {

// convert 'where' string to an array which is indexed by row number

$array1 = splitWhereByRow ( $where ) ;

// convert 'where' for each row into an associative array

foreach ( $array1 as $rownum => $rowdata ) {

$fieldarray [ ] = where2array ( $rowdata ) ;

} // foreach

} // if

} else {

$fieldarray = array ( ) ;

} // if

// perform any custom processing (optional)

if ( is_object ( $this -> custom_processing_object ) ) {

if ( method_exists ( $this -> custom_processing_object , '_cm_getInitialDataMultiple' ) ) {

$fieldarray = $this -> custom_processing_object -> _cm_getInitialDataMultiple ( $fieldarray ) ;

} // if

} // if

if ( $this -> errors ) return $fieldarray ;

if ( $this -> custom_replaces_standard ) {

$this -> custom_replaces_standard = false ;

} else {

// perform any custom processing (optional)

$fieldarray = $this -> _cm_getInitialDataMultiple ( $fieldarray ) ;

} // if

if ( $this -> errors ) return $fieldarray ;

$fieldarray = array_change_key_case ( $fieldarray , CASE_LOWER ) ;

$this -> fieldarray = $fieldarray ;

return $fieldarray ;

} // getInitialDataMultiple

// ****************************************************************************

function getInstruction ( )

// return an optional instruction to the previous script.

{

return $this -> instruction ;

} // getInstruction

// ****************************************************************************

function getLanguageArray ( $id )

// get named array from the language file.

{

$classdir = $GLOBALS [ 'classdir' ] ; // save

$cwd = getcwd ( ) ;

if ( ! empty ( $this -> dirname ) AND $cwd != dirname ( $this -> dirname ) ) {

// switch to correct directory for retrieving message text

$GLOBALS [ 'classdir' ] = dirname ( $this -> dirname ) ;

chdir ( $GLOBALS [ 'classdir' ] ) ;

} // if

// call the function in the standard library

$string = getLanguageArray ( $id ) ;

$GLOBALS [ 'classdir' ] = $classdir ; // restore

chdir ( $cwd ) ;

return $string ;

} // getLanguageArray

// ****************************************************************************

function getLanguageEntries ( $rows , $parent_data , $fieldlist )

// ensure that $rows contains an entry for each supported language on MNU_LANGUAGE.

{

if ( ! empty ( $rows ) ) {

return $rows ; // some records already there, so do nothing

} // if

// convert $fieldlist from string to array

$fieldlist = explode ( ',' , $fieldlist ) ;

// edit data passed down from parent record

foreach ( $parent_data as $fieldname => $fieldvalue ) {

// remove unwanted columns

if ( ! array_key_exists ( $fieldname , $this -> fieldspec ) ) {

// field does not exist in this table, so remove it

unset ( $parent_data [ $fieldname ] ) ;

} elseif ( array_key_exists ( 'pkey' , $this -> fieldspec [ $fieldname ] ) ) {

// leave the primary key

} elseif ( $this -> fieldspec [ $fieldname ] [ 'type' ] != 'string' ) {

// not a string field, so remove it

unset ( $parent_data [ $fieldname ] ) ;

} elseif ( array_key_exists ( 'autoinsert' , $this -> fieldspec [ $fieldname ] ) ) {

unset ( $parent_data [ $fieldname ] ) ;

} elseif ( array_key_exists ( 'autoupdate' , $this -> fieldspec [ $fieldname ] ) ) {

unset ( $parent_data [ $fieldname ] ) ;

} // if

} // foreach

$where = array2where ( $parent_data , $this -> getPkeyNames ( ) , $this ) ;

// obtain list of supported languages

$language_array = $_SESSION [ 'supported_languages' ] ;

if ( ! empty ( $_SESSION [ 'default_language' ] ) ) {

// remove default language as this is not an alternative

unset ( $language_array [ $_SESSION [ 'default_language' ] ] ) ;

} // if

// eliminate languages which already have an entry on this table

foreach ( $rows as $rownum => $rowdata ) {

if ( array_key_exists ( $rowdata [ 'language_id' ] , $language_array ) ) {

unset ( $language_array [ $rowdata [ 'language_id' ] ] ) ;

} // if

} // foreach

// create entries for languages which are missing

foreach ( $language_array as $language_id => $language_code ) {

$fieldarray = $parent_data ;

$fieldarray [ 'language_id' ] = $language_id ;

//$new_data[] = $fieldarray;

$newdata = $this -> insertOrUpdate ( $fieldarray ) ;

if ( $this -> errors ) {

$result = $this -> rollback ( ) ;

return false ;

} // if

$rows [ ] = $newdata ;

} // foreach

return $rows ;

} // getLanguageEntries

// ****************************************************************************

function getLanguageText ( $id , $arg1 = null , $arg2 = null , $arg3 = null , $arg4 = null , $arg5 = null )

// get text from the language file and include up to 5 arguments.

{

$classdir = $GLOBALS [ 'classdir' ] ; // save

$cwd = getcwd ( ) ;

if ( ! empty ( $this -> dirname ) AND $cwd != dirname ( $this -> dirname ) ) {

// switch to correct directory for retrieving message text

$GLOBALS [ 'classdir' ] = dirname ( $this -> dirname ) ;

chdir ( $GLOBALS [ 'classdir' ] ) ;

} // if

// call the function in the standard library

$string = getLanguageText ( $id , $arg1 , $arg2 , $arg3 , $arg4 , $arg5 ) ;

$GLOBALS [ 'classdir' ] = $classdir ; // restore

chdir ( $cwd ) ;

return $string ;

} // getLanguageText

// ****************************************************************************

function getLastIndex ( )

// return the last index number for $this->scrollArray.

{

return count ( $this -> scrollarray ) ;

} // getLastIndex

// ****************************************************************************

function getLastPage ( )

// return the last page number for retrieved rows.

{

return ( int ) $this -> lastpage ;

} // getLastPage

// ****************************************************************************

function getLookupData ( )

// get data to be used in lookups (dropdowns, radio buttons, etc).

// this is populated in getExtraData().

{

if ( ! empty ( $this -> lookup_data ) ) {

$data = $this -> lookup_data ;

} else {

$data = array ( ) ;

} // if

if ( ! empty ( $this -> lookup_css ) ) {

$css = $this -> lookup_css ;

} else {

$css = array ( ) ;

} // if

return array ( $data , $css ) ;

} // getLookupData

// ****************************************************************************

function getMessages ( )

// return any messages which are not errors.

{

$messages = ( array ) $this -> messages ;

$this -> messages = array ( ) ;

return $messages ;

} // getMessages

// ****************************************************************************

function getNodeData ( $expanded , $where = null )

// retrieve requested tree structure from the database.

// $expanded may be a list of nodes which are to be expanded, or the word

// 'ALL' to sigify that all possible nodes should be expanded.

// $where identifies the start point of a tree structure

{

if ( empty ( $where ) ) {

$wherearray = null ;

} else {

// turn $where string into an associative array

$wherearray = where2array ( $where ) ;

} // if

if ( isset ( $this -> instruction ) ) {

// save this until AFTER the call to _cm_getNodeData

$instruction = $this -> instruction ;

unset ( $this -> instruction ) ;

} // if

if ( empty ( $expanded ) ) {

$expanded = array ( ) ;

} // if

$rows_per_page = $this -> rows_per_page ; // save

$pageno = empty ( $this -> pageno ) ? 1 : $this -> pageno ;

// pass control to custom method

$fieldarray = $this -> _cm_getNodeData ( $expanded , $where , $wherearray ) ;

$this -> rows_per_page = $rows_per_page ; // restore

$this -> lastpage = ceil ( $this -> numrows / $this -> rows_per_page ) ;

if ( $pageno > $this -> lastpage ) {

$this -> pageno = $this -> lastpage ;

} else {

$this -> pageno = $pageno ;

} // if

if ( isset ( $instruction ) ) {

// process an instructions from a child script

$this -> instruction = $instruction ;

$fieldarray = $this -> _processInstruction ( $fieldarray ) ;

} // if

$this -> fieldarray = $fieldarray ;

$this -> where = $where ; // save this for any child forms

return $fieldarray ;

} // getNodeData

// ****************************************************************************

function getNumRows ( )

// return the number of rows retrived for the current page.

{

return ( int ) $this -> numrows ;

} // getNumRows

// ****************************************************************************

function getOrderBy ( )

// return current sort order (to be used in sql SELECT statement).

{

// allow sort order to be customised

$orderby = $this -> _cm_getOrderBy ( $this -> sql_orderby ) ;

if ( empty ( $orderby ) ) {

$orderby = $this -> default_orderby_task ;

} // if

if ( empty ( $orderby ) ) {

$orderby = $this -> default_orderby ;

} // if

if ( empty ( $orderby ) ) {

$this -> sql_orderby_seq = null ;

} else {

if ( ! empty ( $this -> sql_from ) ) {

$orderby = qualifyOrderby ( $orderby , $this -> tablename , $this -> fieldspec , $this -> sql_select , $this -> sql_from ) ;

} // if

$this -> sql_orderby_seq = $this -> getOrderBySeq ( $orderby , $this -> sql_orderby_seq ) ;

} // if

return $orderby ;

} // getOrderBy

// ****************************************************************************

function getOrderBySeq ( & $orderby = null , $orderby_seq = null )

// return sort sequence ('asc' or 'desc').

// NOTE: $orderby is passed by reference as it may be modified

{

if ( empty ( $orderby ) ) {

$orderby_seq = null ;

} else {

// find out if any sort sequence has been specified on any first field

$array = explode ( ',' , $orderby ) ;

// look for any trailing 'asc' or 'desc'

$pattern = '/( asc| ascending| desc| descending)$/i' ;

$found = false ;

foreach ( $array as $sortfield ) {

if ( preg_match ( $pattern , $sortfield , $regs ) ) {

$found = true ;

if ( count ( $array ) == 1 ) {

// only one field, so remove sequence from fieldname

$orderby = substr ( $orderby , 0 , - strlen ( $regs [ 0 ] ) ) ;

$orderby_seq = trim ( $regs [ 0 ] ) ;

} else {

// more than one field, so remove separate sequence

$orderby_seq = null ;

} // if

} // if

} // foreach

if ( $found == false AND empty ( $orderby_seq ) ) {

$orderby_seq = 'asc' ;

} // if

} // if

return $orderby_seq ;

} // getOrderBySeq

// ****************************************************************************

function getPageNo ( )

// get current page number to be retrieved for a multi-page display.

{

if ( is_null ( $this -> pageno ) ) {

if ( $this -> lastpage > 0 ) {

$this -> pageno = 1 ; // default to first page

} // if

} // if

return ( int ) $this -> pageno ;

} // getPageNo

// ****************************************************************************

function & getParentData ( )

// return $fieldarray from the parent object.

// NOTE: output is passed by reference.

{

if ( ! is_object ( $this -> parent_object ) ) {

return FALSE ;

} elseif ( ! method_exists ( $this -> parent_object , 'getFieldArray' ) ) {

return FALSE ;

} // if

$parent_data = $this -> parent_object -> getFieldArray ( ) ;

return $parent_data ;

} // getParentData

// ****************************************************************************

function getPkeyArray ( $fieldarray = null , $next_task = null )

// return the list of primary key values for the last selection of data

// which was retrieved from this table (or the passed array).

{

// get name(s) of field(s) which form the primary key

$pkeynames = $this -> getPkeyNames ( ) ;

if ( ! empty ( $next_task ) AND ! preg_match ( '/^(audit)/i' , $next_task [ 'task_id' ] ) ) {

// obtain any custom adjustments to this array

$task_id = $next_task [ 'task_id' ] ;

$pattern_id = $next_task [ 'pattern_id' ] ;

$pkeynames = $this -> _cm_getPkeyNames ( $pkeynames , $task_id , $pattern_id ) ;

if ( empty ( $pkeynames ) ) {

// "Primary key has not been defined for table 'x'"

$this -> errors [ ] = getLanguageText ( 'sys0198' , $this -> tablename ) ;

return false ;

} // if

} // if

if ( empty ( $fieldarray ) ) {

$fieldarray = $this -> fieldarray ;

} // if

reset ( $fieldarray ) ; // fix for version 4.4.1

if ( ! is_array ( $fieldarray [ key ( $fieldarray ) ] ) ) {

// array is one level deep - convert to 2 