Giovanni Perego
A simple web site on some software of mine


Software - Php

Library identifiers: in library sources, names of exported identifiers always comply the following rule. Characters starting each word of the library name, are used to determine a sign that is the prefix of exported identifier. For instance, the library named "SomeLibName", will export identifiers as "SLNOpen()", "SLNClose()", "SLN_MODULE_VER", etc.




asyncjob.php 1.0 (library)


Description: Functions to handle asynchronous job tables

Functions description:
function AJDescInsert(&$db_desc, $data)
Inserts a new job descriptor, specifying its $data; returns the job id on success, FALSE on errors.


function AJDescModify(&$db_desc, $job_id, $data)
Modifies the job descriptor with id $job_id, specifying new $data; returns TRUE on success, FALSE on errors.


function AJDescRead(&$db_desc, $job_id)
Returns an associative array, with the descriptor of job with id $job_id, on success, FALSE on errors.


function AJDescReadAll(&$db_desc)
Returns an array of associative arrays, with descriptor af all jobs indexed by job id's, on success, FALSE on errors. Does not affect error codes.


function AJDescRemove(&$db_desc, $job_id)
Removes if possible the job descriptor with id $job_id; returns TRUE on success, FALSE on errors.


function AJEnqueue(&$db_desc, $data)
Enqueues a job, specifying its $data; returns the job queue-id on success, FALSE on errors.


function AJEnqueuePeriodic(&$db_desc)
Enqueues all enabled periodic job; Returns an array of job queue-id's, indexed by job periodic-id's, on success, FALSE on errors.


function AJErrorMsg()
Returns the error message of the last module function called.


function AJPeriodicInsert(&$db_desc, $data)
Inserts a periodic job, specifying its $data (the job descriptor must already exists); returns the job periodic-id on success, FALSE on errors.


function AJPeriodicModify(&$db_desc, $per_id, $data)
Modifies the periodic job with periodic-id $per_id, specifying new $data (the job descriptor must already exists); returns TRUE on success, FALSE on errors.


function AJPeriodicRead(&$db_desc, $per_id)
Returns an associative array with data of the periodic job with periodic-id $per_id on success, FALSE on errors. Does not affect error codes.


function AJPeriodicReadAll(&$db_desc)
Returns an array of associative arrays with data af all periodic jobs, indexed by job periodic-id's on success, FALSE on errors. Does not affect error codes.


function AJPeriodicRemove(&$db_desc, $per_id)
Removes the periodic job with periodic-id $per_id; returns TRUE on success, FALSE on errors.


function AJQueuedFlushEnded(&$db_desc, $ok_timeout = AJ_OK_TIMEOUT,
                            $err_timeout = AJ_ERR_TIMEOUT)

Removes ended jobs still in execution queue, if they are ended for a time greater than the specified timeout (timeouts can be different for jobs normally ended and jobs ended with errors). Returns an array of removed jobs data, indexed by job queue-id's, on success, FALSE on errors.


function AJQueuedRead(&$db_desc, $queue_id)
Returns an associative array with data of the queued job with queue-id $queue_id on success, FALSE on errors.


function AJQueuedReadAll(&$db_desc)
Returns an array of associative arrays with data af all queued jobs, indexed by job queue-id's on success, FALSE on errors.


function AJQueuedRun(&$db_desc)
Runs queued ready jobs ("Status" == AJ_READY), passing them all to AJ_SCHEDULED and executing one at the time ("Status" == AJ_RUNNING) until ended ("Status" == AJ_ENDED). Returns an array of executed jobs data, indexed by job queue-id's, on success, FALSE on errors.


function AJResult()
Returns the error code of the last module function called.






dateutil.php 1.0 (library)


Description: Functions for date and time management

Functions description:
function DUDayName($d)
Returns the name of the day number $d (0 and 7 stand for Sunday); if $d is outside the range 0..7, FALSE is returned and an error code is set.


function DUDayShortName($d)
Returns the short name of the day number $d (0 and 7 stand for Sunday); if $d is outside the range 0..7, FALSE is returned and an error code is set.


function DUDayNumOfMonth($m = 0, $y = 0)
Returns the number of days in the month $m of the year $y; if parameters are omitted, the current year and/or month are used. The year must be after 1970, otherwise FALSE is returned and an error code is set.


function DUDayNumOfYear($y = 0)
Returns the number of days of the year $y; if $y is omitted, the current year is used. The year must be after 1970, otherwise FALSE is returned and an error code is set.


function DUErrorMsg()
Returns the error message of the last module function called.


function DUIso2Ts($iso)
Returns the timestamp relative to the date string $iso, with Iso format ("YYYY-MM-DDThh:mm:ss.sTZD", where YYYY = year, MM = month, DD = day of month, hh = hour, mm = minute, ss = second, s = decimal fraction of a second, TZD = (Z | (+|-)hh:mm); the format can be truncated after any field, s and TZD are ignored); if $iso is not in the right format, the result is unpredictable. Does not affect error code.


function DUMonthName($m)
Returns the name of the month number $m; if $m is outside the range 1..12, FALSE is returned and an error code is set.


function DUMonthShortName($m)
Returns the short name of the month number $m; if $m is outside the range 1..12, FALSE is returned and an error code is set.


function DUNormalizeYear($y, $mode = DU_TODAY_CENTER,
                         $y2 = 0, $curr_yyyy = FALSE)

Returns a four digits year for the specified year $y; if $y is a two digits year, then it is normalized according to $mode (see constants section) and according to $y2 when needed. The current four digits year $curr_yyyy is calculated or it can be passed for tests.


function DUResult()
Returns the error code of the last module function called.


function DUTimerReset($name)
Resets (or creates) the timer with name $name.


function DUTimerRead($name)
Returns elapsed seconds (with microsecond resolution) since the reset of the timer named $name. If $name does not exist (it has never been reset), it resets it and returns 0.


function DUTsExplode($ts)
For the timestamp $ts, returns the corresponding associative array with indexes "Y", "M", "D", "h", "m", "s", "wd" (week day) with numerical values and "0M", "0D", "0h", "0m", "0s" with 0 padded string values. Does not affect error code.


function DUTsImplode($t)
Converts the associative array $t, with indexes "Y", "M", "D", "h", "m", "s" to the corresponding timestamp. Does not affect error code.


function DUTs2Iso($ts, $fmt = DU_ISO_DATETIME)
For the timestamp $ts, returns the corresponding string in Iso format ("YYYY-MM-DDThh:mm:ss.sTZD", where YYYY = year, MM = month, DD = day of month, hh = hour, mm = minute, ss = second, s = decimal fraction of a second, TZD = (Z | (+|-)hh:mm); s and TZD are always omitted); the format can be truncated specifying $fmt parameter and using defined constants. Does not affect error code.






dblog.php 1.0 (library)


Description: Collection of functions to log data into fixed tables of a specified database (via Odbc drivers, determined by a dsn, user and password)

Functions description:
function DLAppend($table)
Logs a tuple to the table $table of the already initialized database, with data listed by parameters following $table; no check is performed on the number of following parameters; the insert query in the table is build according to parameters specified; all parameters are automatically escaped.


function DLDone()
Closes the opened database connection.


function DLErrorMsg()
Returns the error message of the last module function called.


function DLInit($db_dsn, $user, $pwd)
Initializes the library, closing the previous database connection and opening a new one to the database Dsn $db_dsn, with user $user and password $pwd.


function DLResult()
Returns the error code of the last module function called.


function DLSelectManyRows($query)
Performs the query $query on database already initialized, returning the whole resulting tuples in an array of arrays. Use with caution, since this function could be very time and memory consuming!
If the query fails, return FALSE.






debug.php 1.0 (library)


Description: Utilities for debugging

Functions description:
function DCloseDebugWindow()
Closes the Debug window. Returns nothing.


function DMtimerReset($n = 0)
Resets the microsecond timer named $n.


function DMtimerRead($n = 0)
Returns elapsed seconds (with microsecond resolution) since the reset of microsecond timer named $n. If $n does not exist, it returns -1.


function DPrint()
Prints all parameters passed. Returns the value of the last parameter.


function DSetDebugWindow($x = D_WIN_DEF_X, $y = D_WIN_DEF_Y,
                         $width = D_WIN_DEF_WIDTH,
                         $height = D_WIN_DEF_HEIGHT,
                         $reclear = D_WIN_DEF_RECLEAR)

Sets for Debug window the position $x, $y, dimensions $width, $height, its reclear property. Return nothing.


function DShow()
Prints all parameters passed in a secondary window with title "DebugWin". Returns the value of the last parameter.






indent.php 1.0 (library)


Description: Very simple functions to indent an output

Functions description:
function ILess()
Decrease indentation of one unit, ignoring underflows; returns the new indentation string.


function IMore()
Increase indentation of one unit; returns the new indentation string.


function IReset()
Resets indentation to zero and returns the new indentation string.


function IInd()
Return current indentation string.






odbc.php 1.0 (abstract type)


Description: Functions to create accesses to databases using Open DataBase Connectivity layer

Functions description:
function ODBCAffectedRows(&$desc)
Returns the number of affected rows in the last query (it can be a select or any other query). It does not modify the error code, on errors returns 0.


function ODBCDone(&$desc)
Closes the opened database connection.


function ODBCErrorMsg()
Returns the error message of the last module function called.


function ODBCExtErrorMsg()
Returns the extended error messages (in Html format) of the last module function called.


function ODBCInit(&$desc)
Initializes a persistent connection with the database descripted in the associative array $desc; the array must have keys "Dsn", "User", "Pwd"; $desc is modified inserting the DB handle "_Handle". Returns TRUE if succeded, otherwise FALSE and error code and error message are set.


function ODBCQuery(&$desc, $query)
Performs the generic query $query (without returning values), on the database descripted in the associative array $desc. If the query fails, return FALSE and error code and error message are set.


function ODBCResult()
Returns the error code of the last module function called.


function ODBCSelect(&$desc, $query, $mode, $array_type = ODBC_STD)
Performs the query $query on the database descripted in the associative array $desc, according to $mode, returning a tuple for each call in an array; this can have numeric indexes (default) or the names of the requested fields ($array_type = ODBC_ASS; ODBC_FLAT is treated as ODBC_STD). $desc is modified inserting the result handle "_Result".
The first call must be with $mode set to ODBC_FIRST, next ones with $mode set to ODBC_NEXT ($query is ignored); after the last result the select must be closed with $mode set to $ODBC_CLOSE. If the query fails, return FALSE and error code and error message are set.


function ODBCSelectManyRows(&$desc, $query, $array_type = ODBC_STD)
Performs the query $query on the database descripted in the associative array $desc, returning the all the resulting tuples in an array of arrays for $array_type = ODBC_STD (indexes are numeric), in an array of associative arrays for $array_type = ODBC_ASS (internal indexes are the names of the requested fields), in a simple flat array for $array_type = ODBC_FLAT (with n fields in the query, first tuple have numeric indexes 0..n, second tuple (n + 1)..(2 * n), etc.). Use with caution, since this function could be very time and memory consuming! If the query fails, return FALSE and error code and error message are set.


function ODBCSelectOneRow(&$desc, $query, $array_type = ODBC_STD)
Performs the query $query on the database descripted in the associative array $desc, returning only the first resulting tuple in an array; this can have numeric indexes (default) or the names of the requested fields ($array_type = ODBC_ASS; ODBC_FLAT is treated as ODBC_STD). If the query fails, return FALSE and error code and error message are set.






odbccfg.php 1.0 (library)


Description: Functions to work with a configuration table, shaped as Windows Ini files, in a DB accessed via Odbc module

Functions description:
function OCDeleteSection(&$cfg_desc, $sec)
Deletes, if exist, all the variables in the section $sec; returns FALSE on DB errors, otherwise TRUE.


function OCDeleteVar(&$cfg_desc, $sec, $var)
Deletes, if exists, the variable with name $var, in the section $sec; returns FALSE on DB errors, otherwise TRUE.


function OCDone(&$desc)
Closes the reference to specified database. Return nothing.


function OCInit(&$desc, &$db_desc)
Initializes the descriptor $desc refererring to the database descriptor $db_desc and setting default values if not already set in $desc. Returns nothing.


function OCReadSection(&$cfg_desc, $sec, $ass = OC_ASS)
Reads all the variables in the section $sec and returns them as an array; if $ass is OC_STD the array returned is defined as:
  array(0 => array(0 => "Var1", 1 => Value1),
        1 => array(0 => "Var2", 1 => Value2),
        ...);
if $ass is OC_ASS (default), the array returned is defined as:
  array("Var1" => Value1,
        "Var2" => Value2,
        ...).
Returns FALSE on DB errors.


function OCReadSections(&$cfg_desc, $ass = TRUE)
Reads all the variables in all the sections and returns them as an array; if $ass is OC_STD the array returned is defined as:
  array(0 => array(0 => "Var1", 1 => Value1, 2 => "SectionX"),
        1 => array(0 => "Var2", 1 => Value2, 2 => "SectionX"),
        ...);
if $ass is OC_ASS (default), the array returned is defined as:
  array("Section1" => array("Var1" => Value1,
                            "Var2" => Value2,
                            ...),
        "Section2" => array(...),
        ...).
Returns FALSE on DB errors.


function OCReadVar(&$cfg_desc, $sec, $var, $default = FALSE)
Reads the variable with name $var, in the section $sec; if the variable does not exist, it is returned the default value $default. Returns FALSE on DB errors.


function OCSectionExists(&$cfg_desc, $sec)
Checks if exists at least one variable in the section $sec. Returns FALSE on DB errors.


function OCVarExists(&$cfg_desc, $sec, $var)
Checks if the variable with name $var, in the section $sec exists. Returns FALSE on DB errors.


function OCWriteVar(&$cfg_desc, $sec, $var, $val)
Writes the value $val in the variable with name $var, in the section $sec; if the variable does not exist, it is created. Returns FALSE on DB errors, otherwise TRUE.






odbccfgutil.php 1.0 (library)


Description: Utility functions based on OdbcCfg module

Functions description:
function OCUUnlock(&$cfg_desc, $var)
Clear the lock on variable $var in section "Locks" (see $OCU_lock_sec_name) of the configuration descriptor $cfg_desc. Returns nothing.


function OCUTsl(&$cfg_desc, $var, $timeout = OCU_NO_TIMEOUT)
Test and set lock; works using the configuration descriptor $cfg_desc, on the boolean value (0/1) of the variable $var in section "Locks" (see $OCU_lock_sec_name). Returns TRUE on lock acquired, FALSE if $timeout is specified (in seconds with microseconds resolution) and it is expired (lock not acquired); it does not return if $timeout is not specified.






odbcperm.php 1.0 (library)


Description: Functions to check permissions on forms, views and form controls, stored in a DB accessed via Odbc module

Functions description:
function OPControlPerm($cfg_desc, $control_num = 1, $view_num = 1)
Returns the permission already read for the previously specified script, relative to the control $control_num of the view $view_num.


function OPDone(&$desc)
Closes the reference to specified database. Return nothing.


function OPInit(&$desc, &$db_desc)
Initializes the descriptor $desc refererring to the database descriptor $db_desc and setting default values if not already set in $desc. Returns nothing.


function OPFormPerm($cfg_desc)
Returns the permission already read for the previously specified script, relative to the main form.


function OPReadScriptPerm(&$cfg_desc, $path, $username)
Returns permissions of the path $path, for the username $username. Returns FALSE on DB errors.


function OPViewPerm($cfg_desc, $view_num = 1)
Returns the permission already read for the previously specified script, relative to the view $view_num.






tbl.php 1.0 (abstract type)


Description: Functions to create Html tables

Functions description:
function TBLCell(&$desc, $elem = " ")
Returns, for the table with descriptor $desc, the printable string for a single cell containing $elem, handling opening and closing of the relative row.


function TBLDone(&$desc)
Returns, for the table with the descriptor $desc, the string for the closure.


function TBLEmpty(&$desc, $elem = "")
Returns, for the table with descriptor $desc, the printable string for a empty row (without cell background); the optional $elem is spanned over all columns.


function TBLErrorMsg()
Returns the error message of the last module function called.


function TBLInit(&$desc, $attr_set = array())
Initializes a table descripted in the associative array $desc; the array can have the keys names listed in Notes. If keys are not found, then $desc is modified inserting these keys with default values. All tags not recognized are ignored.
The optional parameter $attr_set is an array with elements describing alternative attributes for interlacing rows; these elements are associative arrays too; keys names can be all those tags listed in Notes that begin with "Col".
Returns table header; sets error code always to TBL_NO_ERROR.


function TBLNextSet(&$desc, $n)
Sets the next alternative attribute set to be used for interlacing rows; returns FALSE on errors or an empty string (so, it can be used during table printing). $n can be 0 to refer to attribute set provided with the original descriptor; greater values refer to alternate sets. $n is always normalized to valid values.


function TBLResult()
Returns the error code of the last module function called.


function TBLRow(&$desc)
Returns, for the table with descriptor $desc, the printable string for a row; row cells can be passed as variable arguments list, after $desc. If the first one after $desc is an array, then its elements will be used as cell data; otherwise every parameter found will be put into cells. If values are not enough, remaining are left empty (with a " "); exceeding values are ignored.


function TBLTitle(&$desc, $title = "")
Returns, for the table with descriptor $desc, the printable string for a title row; the optional $title is spanned over all columns.





About me



Software