';
$Mail->AddTo($User['Value'], $User['Name']);
$Mail->AddBody(strip_tags($Content), 'text/plain');
$Mail->AddBody(''.$Content, 'text/html');
$Mail->Send();
$Output .= 'Sent email to '.$User['Value'].' ('.$User['Name'].')
';
$Output .= strip_tags(str_replace("", " ", str_replace('
', "\n", $Content)));
}
}
if ($Content != '')
{
$this->Database->insert('NotifyLog', array(
'Time' => TimeToMysqlDateTime($Time),
'Title' => $Title,
'Content' => $Content)
);
}
return $Output;
}
function RunCheck(array $Parameters): void
{
RepeatFunction(30, array($this, 'Check'));
}
function DoInstall(): void
{
$this->Database->query("INSERT INTO `NotifyCategory` (`Id`, `Name`, `SysName`) VALUES
(1, 'Dostupnost zařízení (ping)', 'NetworkReachability'),
(2, 'Dostupnost URL', 'URL'),
(3, 'Minimální úroveň signálu', 'WirelessSignal'),
(4, 'Dostupnost síťového portu', 'NetworkPort'),
(5, 'Minimální odezva', 'NetworkLatency'),
(6, 'Minimální propustnost', 'NetworkBandwidth');");
}
function ShowLogRSS(): string
{
Header('Content-Type: text/xml');
$Count = 20;
$Items = array();
$sql = 'SELECT `Id`,`Title`,`Content`, UNIX_TIMESTAMP(`Time`) AS `Time` FROM `NotifyLog`'.
' ORDER BY `Time` DESC LIMIT '.$Count;
$DbResult = $this->System->Database->query($sql);
while ($Line = $DbResult->fetch_assoc())
{
$Items[] = array
(
'Title' => $Line['Title'],
'Link' => 'https://'.$this->System->Config['Web']['Host'].$this->System->Link('/notify/?i='.$Line['Id']),
'Description' => $Line['Content'],
'Time' => $Line['Time'],
);
}
$RSS = new RSS();
$RSS->Title = $this->System->Config['Web']['Title'].' - Záznamy upozornění';
$RSS->Link = 'https://'.$this->System->Config['Web']['Host'].'/';
$RSS->Description = 'Záznam upozornění '.$this->System->Config['Web']['Description'];
$RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail'];
$RSS->Items = $Items;
return $RSS->Generate();
}
static function Cast(Module $Module): ModuleNotify
{
if ($Module instanceof ModuleNotify)
{
return $Module;
}
throw new Exception('Expected ModuleNotify type but got '.gettype($Module));
}
}
class PageNotify extends Page
{
function __construct(System $System)
{
parent::__construct($System);
$this->Title = 'Upozornění';
$this->Description = 'Upozornění';
$this->ParentClass = 'PagePortal';
}
function Show(): string
{
if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Notify', 'Show'))
return 'Nemáte oprávnění';
$Output = '';
if (!array_key_exists('i', $_GET) or !is_numeric($_GET['i'])) return 'Položka nenalezena';
$Id = $_GET['i'] * 1;
$DbResult = $this->Database->select('NotifyLog', 'Title,Content, UNIX_TIMESTAMP(`Time`) AS `Time`', 'Id='.$Id);
if ($DbResult->num_rows > 0)
{
$DbRow = $DbResult->fetch_assoc();
$Output .= ''.$DbRow['Title'].'
'.
'Čas: '.TimeToMysqlDateTime($DbRow['Time']).'
'.
''.$DbRow['Content'].'
';
} else $Output = 'Položka nenalezena';
return $Output;
}
}
class NotifyCategory extends Model
{
static function GetModelDesc(): ModelDesc
{
$Desc = new ModelDesc(self::GetClassName());
$Desc->AddString('Name');
$Desc->AddString('SysName');
return $Desc;
}
}
class NotifyUser extends Model
{
static function GetModelDesc(): ModelDesc
{
$Desc = new ModelDesc(self::GetClassName());
$Desc->AddReference('User', User::GetClassName());
$Desc->AddReference('Contact', Contact::GetClassName());
$Desc->AddInteger('Period');
return $Desc;
}
}