2018-12-01 21:50:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes;
|
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2018-12-10 11:59:02 +00:00
|
|
|
use App\User;
|
2019-07-12 03:42:01 +00:00
|
|
|
use App\Models\{CUG,Mode};
|
|
|
|
use App\Models\Frame as FrameModel;
|
2018-12-10 11:59:02 +00:00
|
|
|
|
2018-12-01 21:50:34 +00:00
|
|
|
/**
|
|
|
|
* Handles all aspects of frame
|
|
|
|
*
|
|
|
|
* Frame are constructed:
|
|
|
|
* + First line is the header, displaying TITLE/CUG TITLE|PAGE #|COST
|
|
|
|
* + Up to $frame_length for content
|
|
|
|
* + Input/Status Line
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* + Frames are stored in binary. ESC codes are stored as a single char < 32.
|
|
|
|
* + Header is on line 1.
|
|
|
|
* + Input field is on Line 24.
|
|
|
|
* + 'i' Frames are info frames, no looking for fields. (Lines 2-23)
|
|
|
|
* + 'a' Frames have active frames with responses.
|
|
|
|
* + 't' Frames terminate the session
|
|
|
|
*
|
2018-12-05 10:50:38 +00:00
|
|
|
* + Frame types:
|
|
|
|
* + 'ip' Frames are Information Provider frames - no header added. (Lines 1-23)
|
|
|
|
*
|
2018-12-01 21:50:34 +00:00
|
|
|
* To Consider
|
|
|
|
* + 'x' External frames - living in another viewdata server
|
|
|
|
*
|
|
|
|
* @package App\Classes
|
|
|
|
*/
|
2018-12-08 22:43:18 +00:00
|
|
|
abstract class Frame
|
2018-12-01 21:50:34 +00:00
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
// This holds the parser object for this frame.
|
|
|
|
protected $po = NULL;
|
|
|
|
|
|
|
|
// This holds the frame object as retrieved from the DB
|
|
|
|
protected $fo = NULL;
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
// Current field being edited
|
|
|
|
private $field_active = FALSE;
|
|
|
|
|
|
|
|
// Current input data for fields
|
|
|
|
private $field_data = [];
|
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
/*
|
2019-07-12 03:42:01 +00:00
|
|
|
// All this vars should be overridden in the child class
|
2018-12-08 22:43:18 +00:00
|
|
|
protected $frame_length = 22;
|
|
|
|
protected $frame_width = 40;
|
|
|
|
|
|
|
|
protected $header_length = 20; // 20
|
|
|
|
protected $pagenum_length = 9; // 11 (prefixed with a color, suffixed with frame)
|
|
|
|
protected $cost_length = 7; // 9 (prefixed with a color, suffixed with unit)
|
|
|
|
protected $cost_unit = 'u';
|
|
|
|
*/
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2018-12-11 12:31:44 +00:00
|
|
|
const FRAMETYPE_INFO = 'i';
|
|
|
|
const FRAMETYPE_ACTION = 'a';
|
|
|
|
const FRAMETYPE_LOGIN = 'l';
|
|
|
|
const FRAMETYPE_TERMINATE = 't';
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
// Fields that are editable
|
2019-07-12 03:42:01 +00:00
|
|
|
// @todo This needs rework.
|
2018-12-05 10:50:38 +00:00
|
|
|
private $fieldoptions = [
|
2018-12-11 12:31:44 +00:00
|
|
|
'p'=>['edit'=>TRUE,'mask'=>'*'], // Password
|
|
|
|
't'=>['edit'=>TRUE], // Text
|
2018-12-05 10:50:38 +00:00
|
|
|
];
|
|
|
|
|
2018-12-01 21:50:34 +00:00
|
|
|
// @todo Move this to the database
|
2019-07-14 12:43:31 +00:00
|
|
|
private $header = RED.SPACE.'T'.BLUE.SPACE.'E'.GREEN.SPACE.'S'.YELLOW.SPACE.'T'.MAGENTA.SPACE.'!';
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
public function __construct(FrameModel $o)
|
2018-12-01 21:50:34 +00:00
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
$this->fo = $o;
|
|
|
|
$startline = 1;
|
2018-12-05 10:50:38 +00:00
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
if ($this->fo->exists) {
|
|
|
|
if (! $this->hasFlag('ip') AND (! $this->isCUG(0) OR $this->type() !== self::FRAMETYPE_LOGIN)) {
|
|
|
|
$startline = 2;
|
2018-12-05 10:50:38 +00:00
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
} elseif ($this->isCUG(0) AND $this->type() === self::FRAMETYPE_LOGIN) {
|
|
|
|
$startline = 2;
|
|
|
|
}
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
// Our parser object
|
|
|
|
$this->po = $this->parser($startline);
|
2019-07-14 12:43:31 +00:00
|
|
|
|
|
|
|
// Set our first editable field
|
|
|
|
$this->resetCurrentField();
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
/**
|
|
|
|
* Render the frame
|
|
|
|
*
|
|
|
|
* @return null|string
|
2019-07-12 03:42:01 +00:00
|
|
|
* @throws \Exception
|
2018-12-05 10:50:38 +00:00
|
|
|
*/
|
2018-12-01 21:50:34 +00:00
|
|
|
public function __toString()
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
$output = $this->fo->cls ? CLS : HOME;
|
|
|
|
|
|
|
|
if (! $this->hasFlag('ip') AND (! $this->isCUG(0) OR $this->type() !== self::FRAMETYPE_LOGIN)) {
|
|
|
|
$output .= $this->render_header($this->header).
|
|
|
|
$this->render_page($this->fo->frame,$this->fo->index).
|
|
|
|
$this->render_cost($this->fo->cost);
|
|
|
|
|
|
|
|
} elseif ($this->isCUG(0) AND $this->type() === self::FRAMETYPE_LOGIN) {
|
|
|
|
$output .= str_repeat(DOWN,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output.(string)$this->po;
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 03:09:43 +00:00
|
|
|
/**
|
|
|
|
* Return a list of alternative versions of this frame.
|
2018-12-10 11:59:02 +00:00
|
|
|
*
|
|
|
|
* @todo: Need to adjust to not include access=0 frames unless owner
|
2018-12-06 03:09:43 +00:00
|
|
|
*/
|
2018-12-10 11:59:02 +00:00
|
|
|
public function alts(Mode $o)
|
2018-12-06 03:09:43 +00:00
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return FrameModel::where('frame',$this->fo->frame)
|
2018-12-06 03:09:43 +00:00
|
|
|
->where('index',$this->index())
|
2019-07-12 03:42:01 +00:00
|
|
|
->where('id','<>',$this->fo->id)
|
2018-12-10 11:59:02 +00:00
|
|
|
->where('mode_id',$o->id)
|
2018-12-11 12:31:44 +00:00
|
|
|
->where('access',1)
|
2018-12-06 03:09:43 +00:00
|
|
|
->limit(9);
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:19:41 +00:00
|
|
|
/**
|
|
|
|
* Return the attributes for character at position
|
|
|
|
*
|
|
|
|
* @param int $x
|
|
|
|
* @param int $y
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function attr(int $x,int $y): string
|
|
|
|
{
|
|
|
|
return $this->po->attr($x,$y);
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:09:43 +00:00
|
|
|
/**
|
|
|
|
* Frame Created Date
|
|
|
|
*/
|
|
|
|
public function created()
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->created_at;
|
2018-12-06 03:09:43 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 12:19:41 +00:00
|
|
|
/**
|
|
|
|
* Return the character at a specific position
|
|
|
|
* @param $x
|
|
|
|
* @param $y
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function char(int $x,int $y): string
|
|
|
|
{
|
|
|
|
return $this->po->char($x,$y);
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:50:34 +00:00
|
|
|
/**
|
2019-07-12 03:42:01 +00:00
|
|
|
* Return fields within the frame.
|
2018-12-01 21:50:34 +00:00
|
|
|
*/
|
2019-07-12 03:42:01 +00:00
|
|
|
public function fields()
|
|
|
|
{
|
|
|
|
return $this->po->fields;
|
|
|
|
}
|
2018-12-01 21:50:34 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-05 10:50:38 +00:00
|
|
|
* Returns the current frame.
|
|
|
|
*/
|
|
|
|
public function frame()
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function frame_length()
|
|
|
|
{
|
|
|
|
return static::$frame_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function frame_width()
|
|
|
|
{
|
|
|
|
return static::$frame_width;
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 11:59:02 +00:00
|
|
|
/**
|
|
|
|
* Get the CUG for a frame
|
|
|
|
*
|
|
|
|
* Frame CUG are derived from their frame number.
|
|
|
|
* EG: Frame 642 is a member of 642, or 64, or 6, or 0, whichever matches first.
|
|
|
|
*
|
|
|
|
* @return CUG
|
|
|
|
*/
|
|
|
|
public function getCUG()
|
|
|
|
{
|
|
|
|
$co = NULL;
|
2019-07-12 03:42:01 +00:00
|
|
|
$frame = $this->fo->frame;
|
2018-12-10 11:59:02 +00:00
|
|
|
|
|
|
|
while (! $co)
|
|
|
|
{
|
|
|
|
$co = CUG::find($frame);
|
|
|
|
|
|
|
|
if (! $co) {
|
|
|
|
$frame = substr($frame,0,strlen($frame)-1);
|
|
|
|
|
|
|
|
if (! $frame)
|
|
|
|
$frame = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $co;
|
|
|
|
}
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
/**
|
|
|
|
* Return the current field configuration
|
2019-07-14 12:43:31 +00:00
|
|
|
* Will return false if no id specified and the current field is not active
|
|
|
|
*/
|
|
|
|
public function getField(int $id=NULL)
|
|
|
|
{
|
|
|
|
if (is_null($id) AND $this->field_active === FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return $this->fields()->get(is_null($id) ? $this->field_active : $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the input for the current field
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getFieldCurrentInput()
|
|
|
|
{
|
|
|
|
return Arr::get($this->field_data,$this->field_active);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldData()
|
|
|
|
{
|
|
|
|
return $this->field_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldDataId(int $id)
|
|
|
|
{
|
|
|
|
return Arr::get($this->field_data,$id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current field ID
|
|
|
|
*
|
|
|
|
* @return bool
|
2018-12-05 10:50:38 +00:00
|
|
|
*/
|
2019-07-14 12:43:31 +00:00
|
|
|
public function getFieldId()
|
2018-12-05 10:50:38 +00:00
|
|
|
{
|
2019-07-14 12:43:31 +00:00
|
|
|
return $this->field_active;
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a specific key of the field options that passes a filter test
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* @param int $after
|
|
|
|
* @return mixed
|
2018-12-01 21:50:34 +00:00
|
|
|
*/
|
2019-07-14 12:43:31 +00:00
|
|
|
public function getFieldNextId($type='edit',$after=0)
|
2018-12-01 21:50:34 +00:00
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fields()
|
2018-12-05 10:50:38 +00:00
|
|
|
->search(function($item,$key) use ($type,$after) {
|
|
|
|
return $key >= $after AND $this->isFieldEditable($item->type);
|
|
|
|
});
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
public function getFieldPrevId($type='edit',$before=FALSE)
|
2018-12-11 12:31:44 +00:00
|
|
|
{
|
2019-07-14 12:43:31 +00:00
|
|
|
if (! $before)
|
|
|
|
$before = $this->fields()->count();
|
|
|
|
|
|
|
|
return $this->fields()
|
|
|
|
->reverse()
|
|
|
|
->search(function($item,$key) use ($type,$before) {
|
|
|
|
return $key < $before AND $this->isFieldEditable($item->type);
|
|
|
|
});
|
2018-12-11 12:31:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:50:34 +00:00
|
|
|
/**
|
|
|
|
* Return the flag for this page
|
|
|
|
*
|
|
|
|
* CLEAR: Clear Screen before rendering.
|
|
|
|
*
|
|
|
|
* @param $flag
|
|
|
|
* @return bool
|
|
|
|
*/
|
2018-12-05 10:50:38 +00:00
|
|
|
public function hasFlag($flag)
|
2018-12-01 21:50:34 +00:00
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->hasFlag($flag);
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
/**
|
|
|
|
* Return the frame DB id
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function id()
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->id;
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current frame index
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->index;
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the next index
|
|
|
|
*/
|
|
|
|
public function index_next()
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return chr(ord($this->fo->index)+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the previous index
|
|
|
|
*/
|
|
|
|
public function index_prev()
|
|
|
|
{
|
|
|
|
return $this->fo->index == 'a' ? 'a' : chr(ord($this->fo->index)-1);
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 11:59:02 +00:00
|
|
|
public function isAccessible():bool
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->access ? TRUE : FALSE;
|
2018-12-10 11:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the frame is a particular CUG
|
2019-07-12 03:42:01 +00:00
|
|
|
*
|
2018-12-10 11:59:02 +00:00
|
|
|
* @param int $cug
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isCUG(int $cug): bool
|
|
|
|
{
|
|
|
|
return ($this->getCUG()->id == $cug);
|
|
|
|
}
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
/**
|
2019-07-14 12:43:31 +00:00
|
|
|
* Determine if the current field should be masked during input
|
2018-12-05 10:50:38 +00:00
|
|
|
*
|
|
|
|
* @param string $field
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2019-07-14 12:43:31 +00:00
|
|
|
public function isFieldCurrentMask(int $id=NULL): string
|
2018-12-05 10:50:38 +00:00
|
|
|
{
|
2019-07-14 12:43:31 +00:00
|
|
|
if (! $x=$this->getField($id))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return array_get(array_get($this->fieldoptions,$x->type),'mask','');
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
/**
|
|
|
|
* Determine if a field is editable
|
|
|
|
*
|
|
|
|
* @param string $field
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isFieldEditable(string $field): bool
|
2018-12-11 12:31:44 +00:00
|
|
|
{
|
2019-07-14 12:43:31 +00:00
|
|
|
return array_get(array_get($this->fieldoptions,$field),'edit',FALSE);
|
2018-12-11 12:31:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 11:59:02 +00:00
|
|
|
/**
|
|
|
|
* Is this frame Public
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isFramePublic(): bool
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->public ? TRUE : FALSE;
|
2018-12-10 11:59:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
// @todo To implement
|
2018-12-10 11:59:02 +00:00
|
|
|
public function isOwner(User $o):bool
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
/**
|
|
|
|
* Return the Page Number
|
|
|
|
*/
|
|
|
|
public function page(bool $as_array=FALSE)
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $as_array ? ['frame'=>$this->fo->frame,'index'=>$this->fo->index] : $this->fo->page;
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the next page number.
|
|
|
|
*
|
|
|
|
* @param bool $as_array
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2019-07-12 03:42:01 +00:00
|
|
|
public function page_next(bool $as_array=FALSE)
|
2018-12-05 10:50:38 +00:00
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $as_array ? ['frame'=>$this->fo->frame,'index'=>$this->index_next()] : $this->fo->frame.$this->index_next();
|
2018-12-05 10:50:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
/**
|
|
|
|
* Load the parser
|
|
|
|
*
|
|
|
|
* @param int $startline
|
|
|
|
* @return Parser
|
|
|
|
*/
|
|
|
|
abstract protected function parser(int $startline): Parser;
|
|
|
|
|
2018-12-01 21:50:34 +00:00
|
|
|
/**
|
|
|
|
* Render the cost of the frame
|
|
|
|
*
|
|
|
|
* @param int $cost
|
|
|
|
* @return string
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
private function render_cost(int $cost)
|
|
|
|
{
|
|
|
|
if ($cost > 999)
|
|
|
|
throw new \Exception('Price too high');
|
|
|
|
|
|
|
|
if ($cost > 100)
|
2019-07-14 12:43:31 +00:00
|
|
|
$color = RED.SPACE;
|
2018-12-01 21:50:34 +00:00
|
|
|
elseif ($cost > 0)
|
2019-07-14 12:43:31 +00:00
|
|
|
$color = YELLOW.SPACE;
|
2018-12-01 21:50:34 +00:00
|
|
|
else
|
2019-07-14 12:43:31 +00:00
|
|
|
$color = GREEN.SPACE;
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
return sprintf($color.'% '.static::$cost_length.'.0f%s',$cost,static::$cost_unit);
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the Site Header
|
|
|
|
*
|
|
|
|
* @param string $header
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
|
|
|
private function render_header(string $header)
|
|
|
|
{
|
2018-12-08 22:43:18 +00:00
|
|
|
$filler = ($this->strlenv($header) < static::$header_length) ? str_repeat(' ',static::$header_length-$this->strlenv($header)) : '';
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2018-12-08 22:43:18 +00:00
|
|
|
return substr($header.$filler,0,static::$header_length+strlen($header)-$this->strlenv($header));
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the Frame Number
|
|
|
|
*
|
|
|
|
* @param int $num
|
|
|
|
* @param string $frame
|
|
|
|
* @return string
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
private function render_page(int $num,string $frame)
|
|
|
|
{
|
2019-01-02 09:56:03 +00:00
|
|
|
if ($num > (int)str_repeat(9,static::$pagenum_length))
|
2018-12-01 21:50:34 +00:00
|
|
|
throw new \Exception('Page Number too big',500);
|
|
|
|
|
|
|
|
if (strlen($frame) !== 1)
|
|
|
|
throw new \Exception('Frame invalid',500);
|
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
return WHITE.SPACE.$num.$frame.(str_repeat(' ',static::$pagenum_length-strlen($num)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the current active field to the first one
|
|
|
|
*/
|
|
|
|
public function resetCurrentField()
|
|
|
|
{
|
|
|
|
$this->field_active = $this->getFieldNextId('edit',0);
|
|
|
|
|
|
|
|
$this->resetCurrentFieldData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the current field
|
|
|
|
*/
|
|
|
|
public function resetCurrentFieldData()
|
|
|
|
{
|
|
|
|
if ($this->field_active !== FALSE AND isset($this->field_data[$this->field_active]))
|
|
|
|
unset($this->field_data[$this->field_active]);
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 12:59:22 +00:00
|
|
|
/**
|
|
|
|
* Get the route for the key press
|
|
|
|
*
|
|
|
|
* @param string $read
|
2019-07-12 03:42:01 +00:00
|
|
|
* @return string
|
|
|
|
* @throws \Exception
|
2018-12-03 12:59:22 +00:00
|
|
|
*/
|
|
|
|
public function route(string $read)
|
|
|
|
{
|
2018-12-11 12:31:44 +00:00
|
|
|
if (! preg_match('/^[0-9]$/',$read))
|
|
|
|
throw new \Exception('Routes are single digit');
|
|
|
|
|
|
|
|
// If we dont have a route record...
|
2019-07-12 03:42:01 +00:00
|
|
|
if (! $this->fo->route)
|
2018-12-11 12:31:44 +00:00
|
|
|
return '*';
|
|
|
|
|
|
|
|
$key = 'r'.$read;
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->route->{$key};
|
2018-12-03 12:59:22 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
/**
|
|
|
|
* Set the field that is current in focus for input
|
|
|
|
*
|
|
|
|
* @param int $num
|
|
|
|
*/
|
|
|
|
public function setFieldCurrent(int $num)
|
|
|
|
{
|
|
|
|
$this->po->field_active = $num;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFieldCurrentInput(string $read)
|
|
|
|
{
|
|
|
|
if ($this->field_active === FALSE)
|
|
|
|
throw new \Exception('No field active?',500);
|
|
|
|
|
|
|
|
if (! array_key_exists($this->field_active,$this->field_data))
|
|
|
|
$this->field_data[$this->field_active] = '';
|
|
|
|
|
|
|
|
$this->field_data[$this->field_active] .= $read;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the last character of the current Input field
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function setFieldCurrentInputDelete(): bool
|
|
|
|
{
|
|
|
|
if (! $this->field_data[$this->field_active])
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
$this->field_data[$this->field_active] = substr($this->field_data[$this->field_active],0,-1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the next active field
|
|
|
|
*/
|
|
|
|
public function setFieldNext()
|
|
|
|
{
|
|
|
|
$this->field_active = $this->getFieldNextId('edit',$this->field_active+1);
|
|
|
|
|
|
|
|
$this->resetCurrentFieldData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the previous active field
|
|
|
|
*/
|
|
|
|
public function setFieldPrev()
|
|
|
|
{
|
|
|
|
$this->field_active = $this->getFieldPrevId('edit',$this->field_active);
|
|
|
|
|
|
|
|
$this->resetCurrentFieldData();
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:50:34 +00:00
|
|
|
/**
|
|
|
|
* Calculate the length of text
|
|
|
|
*
|
|
|
|
* ESC characters are two chars, and need to be counted as one.
|
|
|
|
*
|
|
|
|
* @param $text
|
|
|
|
* @return int
|
|
|
|
*/
|
2019-07-12 03:42:01 +00:00
|
|
|
abstract public static function strlenv($text):int;
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
public static function testFrame()
|
2018-12-01 21:50:34 +00:00
|
|
|
{
|
|
|
|
// Simulate a DB load
|
2019-07-12 03:42:01 +00:00
|
|
|
$o = new FrameModel;
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2018-12-29 12:24:41 +00:00
|
|
|
$content = '';
|
2018-12-01 21:50:34 +00:00
|
|
|
$o->flags = ['ip'];
|
2018-12-03 12:59:22 +00:00
|
|
|
$o->type = 'a';
|
|
|
|
$o->frame = 999;
|
|
|
|
$o->index = 'a';
|
2018-12-10 11:59:02 +00:00
|
|
|
$o->access = 1;
|
2018-12-25 01:48:57 +00:00
|
|
|
$o->public = 1;
|
2018-12-13 13:02:42 +00:00
|
|
|
$o->cls = 1;
|
2018-12-01 21:50:34 +00:00
|
|
|
|
|
|
|
// Header
|
2018-12-08 22:43:18 +00:00
|
|
|
$sid = R_RED.'T'.R_BLUE.'E'.R_GREEN.'S'.R_YELLOW.'T';
|
2019-07-12 03:42:01 +00:00
|
|
|
$content .= substr($sid.'-'.str_repeat('12345678901234567890',4),0,static::$header_length+(strlen($sid)-static::strlenv($sid))).
|
2019-01-02 09:56:03 +00:00
|
|
|
R_WHITE.str_repeat('9',static::$pagenum_length).'a'.R_RED.sprintf('%07.0f',999).'u';
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2018-12-29 12:24:41 +00:00
|
|
|
$content .= R_WHITE.str_repeat('+-',static::$frame_width/2-3).' '.R_RED.'01';
|
|
|
|
$content .= R_WHITE.'Name: '.ESC.str_repeat('t',5).' |'.str_repeat('+-',static::$frame_width/2-8).'|';
|
|
|
|
$content .= R_WHITE.'Date: '.ESC.str_repeat('d',17).' |'.str_repeat('+-',static::$frame_width/2-14).'|';
|
|
|
|
$content .= R_WHITE.'Address: '.ESC.str_repeat('t',19).' |'.str_repeat('+-',static::$frame_width/2-17).'|';
|
|
|
|
$content .= R_WHITE.' : '.ESC.str_repeat('t',19).' |'.str_repeat('+-',static::$frame_width/2-17).'|';
|
|
|
|
|
|
|
|
$o->content = $content;
|
2018-12-01 21:50:34 +00:00
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
return new static($o);
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the Frame Type
|
|
|
|
*/
|
|
|
|
public function type()
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->fo->type();
|
2018-12-01 21:50:34 +00:00
|
|
|
}
|
|
|
|
}
|