Changeset 353 for trunk


Ignore:
Timestamp:
Jan 18, 2012, 8:48:26 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Soubor pro zobrazení výpisu záznamu operací uživatelů přidružen k modulu Log.
Location:
trunk
Files:
1 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Model.php

    r343 r353  
    11<?php
    22
     3define('PropertyDate', 'Date');
     4define('PropertyTime', 'Time');
    35define('PropertyDateTime', 'DateTime');
    46define('PropertyText', 'Text');
     
    3234  {
    3335    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDateTime);
     36  }
     37 
     38  function AddPropertyDate($Name)
     39  {
     40    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyDate);
     41  }
     42 
     43  function AddPropertyTime($Name)
     44  {
     45    $this->Properties[] = array('Name' => $Name, 'Type' => PropertyTime);
    3446  }
    3547 
     
    8597      if($Property['Type'] == PropertyDateTime)
    8698        $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,';
     99      else if($Property['Type'] == PropertyDate)
     100        $Query .= '`'.$Property['Name'].'` DATE NOT NULL,';
     101      else if($Property['Type'] == PropertyTime)
     102        $Query .= '`'.$Property['Name'].'` TIME NOT NULL,';
    87103      else if($Property['Type'] == PropertyString)
    88104        $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,';
     
    90106        $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,';
    91107      else if($Property['Type'] == PropertyInteger)
     108        $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,';
     109      else if($Property['Type'] == PropertyBoolean)
    92110        $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,';
    93111      else if($Property['Type'] == PropertyFloat)
  • trunk/Modules/Log/Log.php

    r348 r353  
    11<?php
     2
     3include_once('Common/rss_generator.php');
     4
     5class LogShow extends Page
     6{
     7  var $FullTitle = 'Zobrazení záznamu operací';
     8  var $ShortTitle = 'Záznam operací';
     9  var $RowPerPage = 20;
     10
     11  function Show()
     12  {
     13    if(count($this->System->PathItems) > 1)
     14    {
     15      if($this->System->PathItems[1] == 'rss') return($this->ShowRSS());
     16        else return(PAGE_NOT_FOUND);
     17    } else return($this->ShowList());
     18  }
     19 
     20  function ShowRSS()
     21  {
     22    $this->SimplePage = true;
     23    $this->FormatHTML = false;
     24   
     25    if(!$this->System->Models['User']->CheckPermission('Log', 'Show')) return('Nemáte oprávnění');
     26    $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(Time), Log.*, `User`.`Name` as UserName FROM `Log` LEFT JOIN `User` ON `User`.`Id` = `Log`.`User` ORDER BY Time DESC LIMIT 0, 50');
     27    while($Row = $DbResult->fetch_assoc())
     28    {
     29      $Info = $Row['UserName'].': '.$Row['Module'].' '.$Row['Operation'].' '.$Row['Value'];
     30      $Items[] = array
     31      (
     32        'Title' => $Info,
     33        'Link' => 'http://'.$this->System->Config['Web']['Host'].'/',
     34        'Description' => $Info,
     35        'Time' => $Row['UNIX_TIMESTAMP(Time)'],
     36      );
     37    }
     38    return(GenerateRSS(array(
     39      'Title' => $this->System->Config['Web']['Title'].' - Záznamy operací',
     40      'Link' => 'http://'.$this->System->Config['Web']['Host'].'/',
     41      'Description' => 'Záznamy operací',
     42      'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
     43      'Items' => $Items)));
     44  }
     45 
     46  function ShowList()
     47  {
     48    if(!$this->System->Models['User']->CheckPermission('Log', 'Show')) return('Nemáte oprávnění');
     49    $DbResult = $this->Database->select('Log', 'COUNT(*)');
     50    $RowTotal = $DbResult->fetch_array();
     51    $PageMax = $RowTotal[0];
     52    if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
     53
     54    $Output = '<div align="center"><table class="WideTable" style="font-size: small;">';
     55    $Output .= '<tr><th>Čas</th><th>Uživatel</th><th>Modul</th><th>Operace</th><th>Hodnota</th></tr>';
     56    $DbResult = $this->Database->query('SELECT Log.*, `User`.`Name` as UserName FROM `Log` LEFT JOIN `User` ON `User`.`Id` = `Log`.`User` ORDER BY Time DESC LIMIT '.$Page * $this->RowPerPage.','.$this->RowPerPage);
     57    while($DbRow = $DbResult->fetch_assoc())
     58    {
     59      $Output .= '<tr><td>'.$DbRow['Time'].'</td><td>'.$DbRow['UserName'].'</td><td>'.$DbRow['Module'].'</td><td>'.$DbRow['Operation'].'</td><td>'.$DbRow['Value'].'</td></tr>';
     60    }
     61    $Output .= '</table>';
     62    $Output .= PagesList('?Page=', $Page, $PageMax, $this->RowPerPage);
     63    $Output .= '</div>';
     64    return($Output);
     65  }
     66}
     67
     68class Log extends Model
     69{
     70  function __construct($Database, $System)
     71  {
     72    parent::__construct($Database, $System);
     73    $this->Name = 'Log';
     74    $this->AddPropertyDateTime('Time');
     75    $this->AddPropertyOneToMany('User', 'User');
     76    $this->AddPropertyString('Module');
     77    $this->AddPropertyString('Operation');   
     78    $this->AddPropertyString('Value');   
     79  }
     80}
    281
    382class ModuleLog extends Module
     
    1291    $this->Description = 'Logging of user operations';
    1392    $this->Dependencies = array('User');
    14     $this->Models = array();
     93    $this->Models = array('Log');
     94  }
     95 
     96  function Init()
     97  {
     98    $this->System->Pages['log'] = 'LogShow';
    1599  }
    16100
  • trunk/Modules/News/NewsPage.php

    r350 r353  
    11<?php
     2
     3include_once('Common/rss_generator.php');
    24
    35class NewsPage extends Page
     
    255257    Header('Content-Type: text/xml');
    256258
    257 include_once('rss_generator.php');
    258 
    259 $NewsCount = 15;
    260 
    261 $Items = array();
    262 $Category = '';
    263 $CategoryOption = '';
    264 $CategoryOptionURL = '';
    265 $CategoryName = '';
    266 
    267 // Prepare WHERE condition
    268 if(array_key_exists('select', $_GET))
    269 {
    270   $Where = '';
    271   $Parts = explode('-', $_GET['select']);
    272   foreach($Parts as $Part)
    273   {
    274     $Where .= 'OR (category='.($Part * 1).')';
    275   }
    276   $Where = substr($Where, 2);
    277 } else $Where = 1;
    278 
    279 // Get category names
    280 $Categories = array();
    281 $DbResult = $Database->select('NewsCategory', '*');
    282 while($Category = $DbResult->fetch_array())
    283 {
    284   $Categories[$Category['Id']] = $Category['Caption'];
     259    $NewsCount = 15;
     260
     261    $Items = array();
     262    $Category = '';
     263    $CategoryOption = '';
     264    $CategoryOptionURL = '';
     265    $CategoryName = '';
     266
     267    // Prepare WHERE condition
     268    if(array_key_exists('select', $_GET))
     269    {
     270      $Where = '';
     271      $Parts = explode('-', $_GET['select']);
     272      foreach($Parts as $Part)
     273      {
     274        $Where .= 'OR (category='.($Part * 1).')';
     275      }
     276      $Where = substr($Where, 2);
     277    } else $Where = 1;
     278
     279    // Get category names
     280    $Categories = array();
     281    $DbResult = $this->Database->select('NewsCategory', '*');
     282    while($Category = $DbResult->fetch_array())
     283    {
     284      $Categories[$Category['Id']] = $Category['Caption'];
     285    }
     286
     287    // Update news from discussion forum
     288    /*
     289    $ForumCategory = 4;   
     290    $Database->select_db('forum');
     291    $DbResult = $Database->query('SELECT posts.post_time, posts_text.post_subject, posts_text.post_text, users.username, topics.topic_title FROM posts JOIN posts_text ON posts.post_id = posts_text.post_id JOIN users ON users.user_id = posts.poster_id JOIN topics ON topics.topic_id= posts.topic_id ORDER BY post_time DESC LIMIT '.$NewsCount);
     292    $Index = 0;
     293    //echo(DB_NumRows().',');
     294    while($Row = $DbResult->fetch_array())
     295    {
     296      $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
     297      $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']);
     298      $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
     299      $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
     300      $Index = $Index + 1;   
     301     
     302      $Title = $Row['topic_title'].'-'.$Row['post_subject'];
     303      $Content = $Row['post_text'];
     304      $Date = date('Y-m-d H:i:s', $Row['post_time']);
     305      $Author = $Row['username'];
     306      $Database->select_db('is');
     307      //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
     308      $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
     309      if($DbResult2->num_rows == 0) //echo('.'); else echo('x');
     310        $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));
     311        //echo($Date); 
     312      $Database->select_db('forum');
     313    }
     314    $Database->select_db('is');
     315    */
     316
     317    // Get news from database by selected categories
     318    $UploadedFilesFolder = 'uploads/';
     319    $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
     320    while($Row = $DbResult->fetch_assoc())
     321    {
     322      $EnclosuresText = '';
     323      if($Row['Enclosure'] != '')
     324      {
     325        $EnclosuresText .= '<br />Přílohy: ';
     326        $Enclosures = explode(';', $Row['Enclosure']);
     327        foreach($Enclosures as $Enclosure)
     328        {
     329          if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
     330        }
     331      }
     332      if($Row['Name'] == '') $Author = $Row['Author'];
     333        else $Author = $Row['Name'];
     334      $Items[] = array(
     335        'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],
     336        'Link' => 'http://'.$this->System->Config['Web']['Host'].'/aktuality/index.php?category='.$Row['Category'],
     337        'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,
     338        'Time' => $Row['UNIX_TIMESTAMP(Date)'],
     339      );
     340    }
     341
     342    return(GenerateRSS(array(
     343      'Title' => $this->System->Config['Web']['Title'].' - Aktuality',
     344      'Link' => 'http://'.$this->System->Config['Web']['Host'].'/',
     345      'Description' => 'Aktuality komunitní počítačové sítě ZděchovNET',
     346      'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
     347      'Items' => $Items)));     
     348  } 
    285349}
    286350
    287 // Update news from discussion forum
    288 /*
    289 $ForumCategory = 4;   
    290 $Database->select_db('forum');
    291 $DbResult = $Database->query('SELECT posts.post_time, posts_text.post_subject, posts_text.post_text, users.username, topics.topic_title FROM posts JOIN posts_text ON posts.post_id = posts_text.post_id JOIN users ON users.user_id = posts.poster_id JOIN topics ON topics.topic_id= posts.topic_id ORDER BY post_time DESC LIMIT '.$NewsCount);
    292 $Index = 0;
    293 //echo(DB_NumRows().',');
    294 while($Row = $DbResult->fetch_array())
    295 {
    296   $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
    297   $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']);
    298   $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
    299   $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
    300   $Index = $Index + 1;   
    301  
    302   $Title = $Row['topic_title'].'-'.$Row['post_subject'];
    303   $Content = $Row['post_text'];
    304   $Date = date('Y-m-d H:i:s', $Row['post_time']);
    305   $Author = $Row['username'];
    306   $Database->select_db('is');
    307   //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
    308   $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
    309   if($DbResult2->num_rows == 0) //echo('.'); else echo('x');
    310     $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));
    311     //echo($Date); 
    312   $Database->select_db('forum');
    313 }
    314 $Database->select_db('is');
    315 */
    316 
    317 // Get news from database by selected categories
    318 $UploadedFilesFolder = 'uploads/';
    319 $DbResult = $Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
    320 while($Row = $DbResult->fetch_assoc())
    321 {
    322   $EnclosuresText = '';
    323   if($Row['Enclosure'] != '')
    324   {
    325     $EnclosuresText .= '<br />Přílohy: ';
    326     $Enclosures = explode(';', $Row['Enclosure']);
    327     foreach($Enclosures as $Enclosure)
    328     {
    329       if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
    330     }
    331   }
    332   if($Row['Name'] == '') $Author = $Row['Author'];
    333     else $Author = $Row['Name'];
    334   $Items[] = array(
    335     'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],
    336     'Link' => 'http://centrala.zdechov.net/aktuality/index.php?category='.$Row['Category'],
    337     'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,
    338     'Time' => $Row['UNIX_TIMESTAMP(Date)'],
    339   );
    340 }
    341 
    342 return(GenerateRSS(array(
    343   'Title' => $Config['Web']['Title'].' - Aktuality',
    344   'Link' => 'http://'.$Config['Web']['Host'].'/',
    345   'Description' => 'Aktuality komunitní počítačové sítě ZděchovNET',
    346   'WebmasterEmail' => $Config['Web']['AdminEmail'],
    347   'Items' => $Items)));
    348      
    349   }
    350  
    351 }
    352 
    353351?>
Note: See TracChangeset for help on using the changeset viewer.