Ignore:
Timestamp:
Jan 13, 2020, 12:26:00 AM (5 years ago)
Author:
chronos
Message:
  • Added: NotifLog table to collect notify changes in table to be able to preset them through RSS channel.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Notify/Notify.php

    r830 r867  
    1515    $this->License = 'GNU/GPL';
    1616    $this->Description = 'Send notification messages to selected users';
    17     $this->Dependencies = array('User');
     17    $this->Dependencies = array('User', 'RSS');
    1818    $this->Checks = array();
    1919  }
     
    3939    ));
    4040    $this->System->RegisterCommandLine('notify', array($this, 'RunCheck'));
     41    $this->System->ModuleManager->Modules['RSS']->RegisterRSS(array('Title' => 'Notify log',
     42    'Channel' => 'notifylog', 'Callback' => array('ModuleNotify', 'ShowLogRSS'),
     43    'Permission' => array('Module' => 'Notify', 'Operation' => 'RSS')));
    4144  }
    4245
     
    5962    $Output = '';
    6063    $Content = '';
     64    $Title = '';
    6165
    6266    // Get output from checks
    6367    $DbResult2 = $this->Database->query('SELECT `Id`, `Name`, `SysName` FROM `NotifyCategory`');
    64     while($Category = $DbResult2->fetch_assoc())
     68    while ($Category = $DbResult2->fetch_assoc())
    6569    {
    66       if(array_key_exists($Category['SysName'], $this->Checks))
     70      if (array_key_exists($Category['SysName'], $this->Checks))
    6771      {
    68         $List = call_user_func($this->Checks[$Category['SysName']]['Callback']);
    69         if($List != '') {
     72        $Status = call_user_func($this->Checks[$Category['SysName']]['Callback']);
     73        if ($Status['Report'] != '')
     74        {
    7075          $Output .= 'Kategorie: '.$Category['Name'].":\n";
    7176          $Content .= 'Kategorie: '.$Category['Name']."<br>\n";
    72           $Content .= $List;
     77          $Content .= $Status['Report'];
    7378        }
     79        if (strlen($Title) > 0) $Title .= ', ';
     80        $Title .= $Status['ShortTitle'].':'.$Status['Count'];
    7481      }
    7582    }
     83
     84    $Time = time();
    7685
    7786    // Send content to users
     
    8190    while($User = $DbResult->fetch_assoc())
    8291    {
    83       $Time = time();
    8492      $Output .= 'User '.$User['Name'].'<br/>';
    8593
    8694      $this->Database->update('NotifyUser', '`Id`='.$User['Id'], array('LastTime' => TimeToMysqlDateTime($Time)));
    8795
    88       if(($User['Category'] == CONTACT_CATEGORY_EMAIL) and ($Content !='')) {
     96      if(($User['Category'] == CONTACT_CATEGORY_EMAIL) and ($Content != ''))
     97      {
    8998        $Mail = new Mail();
    9099        $Mail->Subject = 'Notification';
     
    102111
    103112      return($Output);
     113    }
     114
     115    if ($Content != '')
     116    {
     117      $this->Database->insert('NotifyLog', array(
     118        'Time' => TimeToMysqlDateTime($Time),
     119        'Title' => $Title,
     120        'Content' => $Content)
     121      );
    104122    }
    105123  }
     
    147165    $this->Database->query('DROP TABLE `NotifyCategory`');
    148166  }
     167
     168  function ShowLogRSS()
     169  {
     170    $this->ClearPage = true;
     171    $this->FormatHTML = false;
     172    Header('Content-Type: text/xml');
     173    $Count = 100;
     174
     175    $Output = '';
     176    $Items = array();
     177    $sql = 'SELECT Title,Content, UNIX_TIMESTAMP(`Time`) AS `Time` FROM `NotifyLog`'.
     178      ' ORDER BY `Time` DESC LIMIT '.$Count;
     179    $DbResult = $this->System->Database->query($sql);
     180    while($Line = $DbResult->fetch_assoc())
     181    {
     182      $Items[] = array
     183      (
     184        'Title' => $Line['Title'],
     185        'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/Notify.php'),
     186        'Description' => $Line['Content'],
     187        'Time' => $Line['Time'],
     188      );
     189    }
     190
     191    $RSS = new RSS();
     192    $RSS->Title = $this->System->Config['Web']['Title'].' - Záznamy upozornění';
     193    $RSS->Link = 'http://'.$this->System->Config['Web']['Host'].'/';
     194    $RSS->Description = 'Záznam upozornění '.$this->System->Config['Web']['Description'];
     195    $RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail'];
     196    $RSS->Items = $Items;
     197    return($RSS->Generate());
     198  }
    149199}
Note: See TracChangeset for help on using the changeset viewer.