Table = '';
$this->Definition = array();
$this->ItemActions = array(
array('Name' => T('View'), 'URL' => '?action=view&id=#Id'),
);
$this->AllowEdit = false;
if ($this->AllowEdit) $this->ItemActions[] = array('Name' => T('Delete'), 'URL' => '?action=remove&id=#Id');
}
function Show(): string
{
$Output = '';
if (array_key_exists('action', $_GET))
{
if ($_GET['action'] == 'add') $Output .= $this->AddItem();
else if ($_GET['action'] == 'view') $Output .= $this->ViewItem();
//else if ($_GET['action'] == 'edit') $Output .= $this->ModifyItem();
//else if ($_GET['action'] == 'remove') $Output .= $this->RemoveItem();
else if ($_GET['action'] == 'delete') $Output .= $this->DeleteItem();
else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL);
} else $Output .= $this->ViewList();
return $Output;
}
function ViewItem()
{
$DbResult = $this->Database->query('SELECT * FROM ('.$this->TableSQL.') AS `T` WHERE `Id`='.$_GET['id']);
if ($DbResult->num_rows > 0)
{
$DbRow = $DbResult->fetch_assoc();
$Output = T('Item').
'
';
foreach ($this->Definition as $DefIndex => $Def)
{
$Output .= ''.$Def['Title'].': | '.$this->ViewControl($Def['Type'], $DefIndex, $DbRow[$DefIndex]).' |
';
}
$Output .= ''.
'
';
} else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL);
if ($this->AllowEdit)
{
$Output .= ''.T('Add').' ';
$Output .= ''.T('Edit').' ';
$Output .= ''.T('Add').' ';
}
$Output .= ''.T('List').'
';
return $Output;
}
function ViewList()
{
$DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$this->TableSQL.') AS `T`');
$DbRow = $DbResult->fetch_row();
$PageList = GetPageList($DbRow[0]);
$Output = $PageList['Output'];
$Output .= '';
$TableColumns = array();
foreach ($this->Definition as $Index => $Def)
if ($Def['InList'])
$TableColumns[] = array('Name' => $Index, 'Title' => $Def['Title']);
if (count($this->ItemActions) > 0)
$TableColumns[] = array('Name' => '', 'Title' => 'Akce');
$Order = GetOrderTableHeader($TableColumns, 'Name', 0);
$Output .= $Order['Output'];
$DbResult = $this->Database->query('SELECT * FROM ('.$this->Table.') '.$Order['SQL'].$PageList['SQLLimit']);
while ($Item = $DbResult->fetch_assoc())
{
$Output .= '';
foreach ($this->Definition as $Index => $Def)
if ($Def['InList'])
{
if ($Def['Type'] == 'URL') $Output .= ''.$Item[$Index].' | ';
else $Output .= ''.$Item[$Index].' | ';
}
if (count($this->ItemActions) > 0)
{
$Output .= '';
foreach ($this->ItemActions as $Index => $Action)
{
$URL = $Action['URL'];
if (strpos($URL, '#Id')) $URL = str_replace('#Id', $Item['Id'], $URL);
$Output .= ''.$Action['Name'].' ';
}
$Output .= ' | ';
}
$Output .= '
';
}
$Output .= '
';
if ($this->AllowEdit) $Output .= ''.T('Add').'
';
return $Output;
}
function AddItem()
{
$Output = '';
$User = ModuleUser::Cast($this->System->GetModule('User'))->User;
if ($User->Licence(LICENCE_USER))
{
if (array_key_exists('finish', $_GET))
{
$Items = array();
foreach ($this->Definition as $Index => $Def)
{
$Items[$Index] = $_POST[$Index];
}
$this->Database->insert($this->Table, $Items);
$Output = ShowMessage(T('Item added'), MESSAGE_INFORMATION);
} else
{
$Output .= '';
}
} else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
return $Output;
}
function DeleteItem()
{
$User = ModuleUser::Cast($this->System->GetModule('User'))->User;
if ($User->Licence(LICENCE_USER))
{
$this->Database->query('DELETE FROM `'.$this->Table.'` WHERE (`User`='.$User->Id.') AND (`Id`='.($_GET['id'] * 1).')');
$Output = ShowMessage(T('Record removed'));
} else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL);
return $Output;
}
function GetControl($Type, $Name, $Value)
{
if ($Type == 'Text') $Output = '';
else if ($Type == 'Boolean') $Output = '';
else $Output = '';
return $Output;
}
function ViewControl($Type, $Name, $Value)
{
if ($Type == 'Text') $Output = $Value;
else if ($Type == 'URL') $Output = ''.$Value.'';
else if ($Type == 'Boolean') $Output = $Value;
else $Output = $Value;
return $Output;
}
}