+ //
+ // Save reference (and prepare next) on write transaction.
+ //
+ function save($type, $id, $reference)
+ {
+ update_reference($type, $id, $reference); // store in refs table
+ if ($reference == $this->get_next($type)) { // if reference was not changed from default
+ $next = $this->_increment($reference); // increment default
+ save_next_reference($type, $next);
+ }
+ }
+ //
+ // Restore previous reference (if possible) after voiding transaction.
+ //
+ function restore_last($type, $id)
+ {
+ $reference = get_reference($type, $id);
+ $prev = $this->_increment($this->get_next($type), true); //decrement
+ if ($reference==$prev) {
+ save_next_reference($type, $prev);
+ }
+ }
+ //-----------------------------------------------------------------------
+ //
+ // Increments (or decrements if $back==true) reference template
+ //
+ function _increment($reference, $back=false)