src/Pyrite/AuditTrail.php
public static function add($objectType, $objectId = null, $action = null, $fieldName = null, $oldValue = null, $newValue = null, $userId = 0, $content = '')
    {
        global $PPHP;
        $db = $PPHP['db'];

        $ip = '127.0.0.1';
        $req = grab('request');
        if (isset($req['remote_addr'])) {
            $ip = $req['remote_addr'];
        };

        // First argument could contain named arguments
        if (is_array($objectType)) {
            if (isset($objectType['objectId']))  $objectId  = $objectType['objectId'];
            if (isset($objectType['action']))    $action    = $objectType['action'];
            if (isset($objectType['fieldName'])) $fieldName = $objectType['fieldName'];
            if (isset($objectType['oldValue']))  $oldValue  = $objectType['oldValue'];
            if (isset($objectType['newValue']))  $newValue  = $objectType['newValue'];
            if (isset($objectType['userId']))    $userId    = $objectType['userId'];
            if (isset($objectType['content']))   $content   = $objectType['content'];
            if (isset($objectType['objectType'])) {
                $objectType = $objectType['objectType'];
            } else {
                $objectType = null;
            };
        };
        if ($objectType === null && $objectId === null && $PPHP['contextType'] !== null && $PPHP['contextId'] !== null) {
            $objectType = $PPHP['contextType'];
            $objectId = $PPHP['contextId'];
        };

        if (isset($_SESSION['user']['id'])) {
            $actingUserId = $_SESSION['user']['id'];
            if ($userId === 0) {
                $userId = $actingUserId;
            };
        };

        // Enforce size limit on field values
        $oldValue = substr($oldValue, 0, 250);
        $newValue = substr($newValue, 0, 250);

        $db->exec(
            "
            INSERT INTO transactions
            (actingUserId, userId, ip, objectType, objectId, action, fieldName, oldValue, newValue, content)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            ",
            array(
                $actingUserId,
                $userId,
                $ip,
                $objectType,
                $objectId,
                $action,
                $fieldName,
                $oldValue,
                $newValue,
                $content
            )
        );
    }
public static function add($objectType, $objectId = null, $action = null, $fieldName = null, $oldValue = null, $newValue = null, $userId = 0, $content = '')
    {
        global $PPHP;
        $db = $PPHP['db'];

        $ip = '127.0.0.1';
        $req = grab('request');
        if (isset($req['remote_addr'])) {
            $ip = $req['remote_addr'];
        };

        // First argument could contain named arguments
        if (is_array($objectType)) {
            if (isset($objectType['objectId']))  $objectId  = $objectType['objectId'];
            if (isset($objectType['action']))    $action    = $objectType['action'];
            if (isset($objectType['fieldName'])) $fieldName = $objectType['fieldName'];
            if (isset($objectType['oldValue']))  $oldValue  = $objectType['oldValue'];
            if (isset($objectType['newValue']))  $newValue  = $objectType['newValue'];
            if (isset($objectType['userId']))    $userId    = $objectType['userId'];
            if (isset($objectType['content']))   $content   = $objectType['content'];
            if (isset($objectType['objectType'])) {
                $objectType = $objectType['objectType'];
            } else {
                $objectType = null;
            };
        };
        if ($objectType === null && $objectId === null && $PPHP['contextType'] !== null && $PPHP['contextId'] !== null) {
            $objectType = $PPHP['contextType'];
            $objectId = $PPHP['contextId'];
        };

        if (isset($_SESSION['user']['id'])) {
            $actingUserId = $_SESSION['user']['id'];
            if ($userId === 0) {
                $userId = $actingUserId;
            };
        };

        // Enforce size limit on field values
        $oldValue = substr($oldValue, 0, 250);
        $newValue = substr($newValue, 0, 250);

        $db->exec(
            "
            INSERT INTO transactions
            (actingUserId, userId, ip, objectType, objectId, action, fieldName, oldValue, newValue, content)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            ",
            array(
                $actingUserId,
                $userId,
                $ip,
                $objectType,
                $objectId,
                $action,
                $fieldName,
                $oldValue,
                $newValue,
                $content
            )
        );
    }
public static function add ( $ objectType , $ objectId = null , $ action = null , $ fieldName = null , $ oldValue = null , $ newValue = null , $ userId = 0 , $ content = '' ) { global $ PPHP ; $ db = $ PPHP [ 'db' ] ; $ ip = '127.0.0.1' ; $ req = grab ( 'request' ) ; if ( isset ( $ req [ 'remote_addr' ] ) ) { $ ip = $ req [ 'remote_addr' ] ; } ; // First argument could contain named arguments if ( is_array ( $ objectType ) ) { if ( isset ( $ objectType [ 'objectId' ] ) ) $ objectId = $ objectType [ 'objectId' ] ; if ( isset ( $ objectType [ 'action' ] ) ) $ action = $ objectType [ 'action' ] ; if ( isset ( $ objectType [ 'fieldName' ] ) ) $ fieldName = $ objectType [ 'fieldName' ] ; if ( isset ( $ objectType [ 'oldValue' ] ) ) $ oldValue = $ objectType [ 'oldValue' ] ; if ( isset ( $ objectType [ 'newValue' ] ) ) $ newValue = $ objectType [ 'newValue' ] ; if ( isset ( $ objectType [ 'userId' ] ) ) $ userId = $ objectType [ 'userId' ] ; if ( isset ( $ objectType [ 'content' ] ) ) $ content = $ objectType [ 'content' ] ; if ( isset ( $ objectType [ 'objectType' ] ) ) { $ objectType = $ objectType [ 'objectType' ] ; } else { $ objectType = null ; } ; } ; if ( $ objectType === null && $ objectId === null && $ PPHP [ 'contextType' ] !== null && $ PPHP [ 'contextId' ] !== null ) { $ objectType = $ PPHP [ 'contextType' ] ; $ objectId = $ PPHP [ 'contextId' ] ; } ; if ( isset ( $ _SESSION [ 'user' ] [ 'id' ] ) ) { $ actingUserId = $ _SESSION [ 'user' ] [ 'id' ] ; if ( $ userId === 0 ) { $ userId = $ actingUserId ; } ; } ; // Enforce size limit on field values $ oldValue = substr ( $ oldValue , 0 , 250 ) ; $ newValue = substr ( $ newValue , 0 , 250 ) ; $ db -> exec ( "
            INSERT INTO transactions
            (actingUserId, userId, ip, objectType, objectId, action, fieldName, oldValue, newValue, content)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            " , array ( $ actingUserId , $ userId , $ ip , $ objectType , $ objectId , $ action , $ fieldName , $ oldValue , $ newValue , $ content ) ) ; }
Add a new transaction to the audit trail

Suggested minimum set of actions:

created
modified
deleted

You can either use these positional arguments or specify a single
associative array argument with only the keys you need defined.

At least an action should be specified (i.e. 'rebooted', perhaps) and
typically also objectType and objectId.  The rest is accessory.

@param array|string    $objectType Class of object this applies to (*or args, see above)
@param string|int|null $objectId   Specific instance acted upon
@param string          $action     Type of action performed
@param string|null     $fieldName  Specific field affected
@param string|int|null $oldValue   Previous value for affected field
@param string|int|null $newValue   New value for affected field
@param string|int|null $userId     Over-ride session userId with this one
@param string|null     $content    Additional text to store in the entry

@return null
Add a new transaction to the audit trail