Changeset 8


Ignore:
Timestamp:
May 9, 2008, 10:39:00 AM (17 years ago)
Author:
george
Message:

Přidáno: Oprávnění pro čtení a zápis k rolím a operacím.
Přidáno: Zobrazení matice oprávnění.
Přidáno: Uživatelské menu s proměnným obsahem podle role uživatele.
Upraveno: Rozdělení importu na import z mangosu a import ze staré databáze.

Location:
branches/2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2/database.php

    r5 r8  
    99  var $LastQuery = '';
    1010 
     11  function query($Query)
     12  {
     13    $this->LastQuery = $Query;
     14    return(parent::query($Query)); 
     15  }
     16
    1117  function select($Table, $What = '*', $Condition = 1)
    1218  {
  • branches/2/frontend.php

    r7 r8  
    3434  function Login()
    3535  {
     36    $Output = $this->System->Modules['User']->Login($_POST['Username'], $_POST['Password']);
     37    $this->System->Modules['User']->Check();
     38    return($Output);
     39  }
     40
     41  function Logout()
     42  {
     43    $Output = $this->System->Modules['User']->Logout();
     44    $this->System->Modules['User']->Check();
     45    return($Output);
     46  }
     47
     48  function ShowText($TranslationGroupId)
     49  {
    3650   
    37     return($this->System->Modules['User']->Login($_POST['Username'], $_POST['Password']));
    38   }
    39 
    40   function Logout()
    41   {
    42    
    43     return($this->System->Modules['User']->Logout());
    44   }
    45 
    46   function TranslationGroupEdit($TranslationGroupId)
    47   {
    48     $Output = '<strong>Překlad textů:</strong><br /><table class="TranslationTable">';
    49     foreach($this->System->Modules['Translation']->GetTextList($TranslationGroupId) as $GroupItem)
    50     {
    51       $Output .= '<tr><th>'.$GroupItem['Name'].'</th><td>'.$GroupItem['Text'].'</td><td><div><textarea name="GroupItem'.$GroupItem['Id'].'">'.$GroupItem['Text'].'</textarea></div></td></tr>';
    52     }
    53     $Output .= '</table>';
     51    $TextList = $this->System->Modules['Translation']->GetMultipleText($TranslationGroupId, $_GET['Index']);
     52    if(count($TextList) == 0)
     53    {
     54      // Edit new text
     55      $Output = '<strong>Překlad textů:</strong><table class="TranslationTable">';
     56      foreach($this->System->Modules['Translation']->GetTextList($TranslationGroupId) as $GroupItem)
     57      {
     58        $Output .= '<tr><th>'.$GroupItem['Name'].'</th><td>'.$GroupItem['Text'].'</td><td><div><textarea name="GroupItem'.$GroupItem['Id'].'">'.$GroupItem['Text'].'</textarea></div></td></tr>';
     59      }
     60      $Output .= '</table>';
     61    }
     62    else if(count($TextList) == 1)
     63    {
     64      // Show only one
     65      $Output = '<strong>Zobrazení textu:</strong><table class="TranslationTable">';
     66      foreach($this->System->Modules['Translation']->GetTextList($TranslationGroupId) as $GroupItem)
     67      {
     68        $Output .= '<tr><th>'.$GroupItem['Name'].'</th><td>'.$GroupItem['Text'].'</td><td>'.$GroupItem['Text'].'</td></tr>';
     69      }
     70      $Output .= '</table>';
     71    } else
     72    {
     73      // Show multiple possibilites
     74      $Output = '<strong>Více překladů jednoho textu:</strong><table class="TranslationTable">'.
     75       '<tr><th>ID</th><th>Titulek</th></tr>';
     76      foreach($TextList as $Text)
     77      {
     78        $Output .= '<tr><td>'.$Text['Index'].'</td><td><a href="?Action=ShowText&amp;GroupId='.$Text['Id'].'">'.$Text['Text'].'</a></td></tr>';
     79      }
     80      $Output .= '</table>';
     81    }
    5482    return($Output);
    5583  }
     
    5987    $ItemPerPage = 30;
    6088    if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
    61     $Output = '<strong>Seznam textů:</strong><br/>';
     89    $Output = '<strong>Seznam textů:</strong><table>'.
     90    '<tr><th>ID</th><th>Titulek</th><th>Překladů</th></tr>';
    6291    foreach($this->System->Modules['Translation']->GetTextGroupList($GroupId, 1, 1, $Page, $ItemPerPage) as $Translation)
    6392    {
    6493      if(strlen($Translation['Text']) > 30) $Translation['Text'] = substr($Translation['Text'], 0, 30).'...';
    65       $Output .= $Translation['Index'].'. <a href="?Action=TranslationGroupEdit&amp;GroupId='.$Translation['Id'].'">'.$Translation['Text'].'</a><br />';
    66     }
    67     $Output .= $this->System->PagesList('?Action=TextGroupList&amp;GroupId='.$GroupId.'&amp;Page=', $Page, $this->System->Modules['Translation']->GetTextGroupListCount($GroupId, 1, 1), $ItemPerPage);
     94      $Output .= '<tr><td>'.$Translation['Index'].'</td><td><a href="?Action=ShowText&amp;GroupId='.$Translation['Id'].'&amp;Index='.$Translation['Index'].'">'.$Translation['Text'].'</a></td><td>'.($Translation['TextCount'] - 1).'</td></tr>';
     95    }
     96    $Output .= '</table>'.$this->System->PagesList('?Action=TextGroupList&amp;GroupId='.$GroupId.'&amp;Page=', $Page, $this->System->Modules['Translation']->GetTextGroupListCount($GroupId, 1, 1), $ItemPerPage);
    6897    return($Output);
    6998  }
     
    71100  function TranslationGroupList()
    72101  {
    73     $Output = '<strong>Seznam skupin:</strong><br/>';
     102    $Output = '<strong>Seznam skupin:</strong><table>'.
     103    '<tr><th>Skupina textů</th><th>Počet textů</th></tr>';
    74104    foreach($this->System->Modules['Translation']->GetTranslationGroupList() as $Group)
    75105    {
    76       $Output .= '<a href="?Action=TextGroupList&amp;GroupId='.$Group['Id'].'">'.$Group['Name'].'</a><br />';
     106      $Output .= '<tr><td><a href="?Action=TextGroupList&amp;GroupId='.$Group['Id'].'">'.$Group['Name'].'</a></td><td>'.$Group['TextCount'].'</td></tr>';
    77107    }
    78108    return($Output);
     
    84114    '<a href="?">Uvodní stránka</a><br />'.
    85115    '<a href="?Action=TranslationGroupList">Seznam skupin</a><br />'.
    86     '<a href="?Action=MangosImport">Import z MaNGOSu</a><br />'.
    87116    '<br />';
    88117    return($Output);
     
    92121  {
    93122    $Output = 'Uživatel: '.$this->System->Modules['User']->User['Name'].' ';
    94     if($this->System->Modules['User']->User['Id'] == 0) $Output .= '<a href="?Action=LoginDialog">Přihlásit</a>';
     123    if($this->System->Modules['User']->User['Id'] == 1) $Output .= '<a href="?Action=LoginDialog">Přihlásit</a>';
    95124      else $Output .= '<a href="?Action=Logout">Odhlásit</a>';
    96125   
    97126    return($Output.'<br />');
    98127  }
    99 
     128 
     129  function UserMenu()
     130  {
     131    $Output = '<strong>Uživatelské menu</strong><br />';
     132    $Permission = &$this->System->Modules['User']->User['Permission'];
     133    if($Permission[9]['Read']) $Output .= '<a href="?Action=PermissionMatrix">Tabulka oprávnění</a><br />';
     134    if($Permission[4]['Read']) $Output .= '<a href="?Action=UserOptions">Nastavení účtu</a><br />';
     135    if($Permission[2]['Read']) $Output .= '<a href="?Action=UserTextList">Přeložené texty</a><br />';
     136    if($Permission[3]['Read']) $Output .= '<a href="?Action=UserNewText">Nový překlad</a><br />';
     137    if($Permission[5]['Read']) $Output .= '<a href="?Action=Import">Import</a><br />';
     138    return($Output.'<br />');
     139  }
     140
     141  function UserOptions()
     142  {
     143    $Output = '';
     144    return($Output);
     145  }
     146
     147  function PermissionMatrix()
     148  {
     149     $Output = '<table>';
     150     $Matrix = $this->System->Modules['User']->PermissionMatrix();
     151     $ShowHeader = 1;
     152     foreach($Matrix as $RowIndex => $Row)
     153     {
     154       if($ShowHeader == 1)
     155       {
     156         $Output .= '<tr><th>&nbsp;</th>';
     157         foreach($Row as $ColumnIndex => $Column)
     158           $Output .= '<th>'.$ColumnIndex.'</th>';
     159         $Output .= '</tr>';
     160         $ShowHeader = 0;
     161       }
     162       $Output .= '<tr><th>'.$RowIndex.'</th>';
     163       foreach($Row as $ColumnIndex => $Column)
     164         $Output .= '<td>'.$Column.'</td>';
     165       $Output .= '</tr>';
     166     }
     167     $Output .= '</table>';
     168     return($Output);
     169  }
     170
     171  function UserTextList($GroupId)
     172  {
     173    $ItemPerPage = 30;
     174    if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
     175    $Output = '<strong>Seznam vašich textů:</strong><br/>';
     176    foreach($this->System->Modules['Translation']->GetTextGroupList($GroupId, $this->System->Modules['User']->User['Id'], 1, $Page, $ItemPerPage) as $Translation)
     177    {
     178      if(strlen($Translation['Text']) > 30) $Translation['Text'] = substr($Translation['Text'], 0, 30).'...';
     179      $Output .= $Translation['Index'].'. <a href="?Action=TranslationGroupEdit&amp;GroupId='.$Translation['Id'].'">'.$Translation['Text'].'</a><br />';
     180    }
     181    $Output .= $this->System->PagesList('?Action=TextGroupList&amp;GroupId='.$GroupId.'&amp;Page=', $Page, $this->System->Modules['Translation']->GetTextGroupListCount($GroupId, 1, 1), $ItemPerPage);
     182    return($Output);
     183  }
     184 
     185  function Import()
     186  {
     187    return('<a href="?Action=ImportMangos">Import z Mangosu</a><br />'.
     188    '<a href="?Action=ImportOldSystem">Import ze starého systému</a><br />');
     189  }
    100190
    101191  function Output()
     
    114204        $Output = $this->Logout();
    115205        break;
    116       case 'TranslationGroupEdit':
    117         $Output = $this->TranslationGroupEdit($_GET['GroupId']);
     206      case 'ShowText':
     207        $Output = $this->ShowText($_GET['GroupId']);
    118208        break;
    119209      case 'TextGroupList':
     
    123213        $Output = $this->TranslationGroupList();
    124214        break;
    125       case 'MangosImport':
    126         $Output = $this->System->Modules['MangosImport']->FullImport();
     215      case 'PermissionMatrix':
     216        $Output = $this->PermissionMatrix();
     217        break;
     218      case 'UserOptions':
     219        $Output = $this->UserOptions();
     220        break;
     221      case 'UserTextList':
     222        $Output = $this->UserTextList();
     223        break;
     224      case 'Import':
     225        $Output = $this->Import();
     226        break;
     227      case 'ImportMangos':
     228        $Output = $this->System->Modules['MangosImport']->ImportFromMangos();
     229        break;
     230      case 'ImportOldSystem':
     231        $Output = $this->System->Modules['MangosImport']->ImportOldMangos();
    127232        break;
    128233    }
    129234    else $Output = '';
    130     return($this->Header().'<table class="MainLayout"><tr><td id="LeftPanel">'.$this->User().$this->Menu().'</td><td>'.$Output.'</td></tr></table>'.$this->Footer());
     235    return($this->Header().'<table class="MainLayout"><tr><td id="LeftPanel">'.$this->User().$this->Menu().$this->UserMenu().'</td><td class="MainLayoutTd">'.$Output.'</td></tr></table>'.$this->Footer());
    131236  } 
    132237}
  • branches/2/mangos_import.php

    r5 r8  
    33class MangosImport extends Module
    44{
    5   function FullImport()
     5  function ImportFromMangos()
    66  {
    77    $Output = '';
     
    4444    return($Output);
    4545  }
     46
     47  function ImportOldSystem()
     48  {
     49  }
    4650}
    4751
  • branches/2/style.css

    r7 r8  
    2424}
    2525
     26table
     27{
     28  border-width: 1px;
     29  border-style: solid;
     30  border-color: black;
     31  border-spacing: 0px;
     32}
     33
     34table td
     35{
     36  border-width: 1px;
     37  border-style: solid;
     38  border-color: black;
     39  padding: 2px 5px 2px 5px;
     40}
     41
     42table th
     43{
     44  border-width: 1px;
     45  border-style: solid;
     46  border-color: black;
     47  padding: 2px 5px 2px 5px;
     48}
     49
    2650textarea
    2751{
     
    3761}
    3862
    39 .MainLayout td
     63.MainLayoutTd
    4064{
     65  border: 0;
    4166  vertical-align: top;
    4267}
     
    4469.MainLayout #LeftPanel
    4570{
     71  border: 0;
    4672  width: 200px;
     73  vertical-align: top;
    4774}
  • branches/2/translation.php

    r6 r8  
    66  {
    77    $Result = array();
    8     $DbResult = $this->Database->select('TranslationGroup', '*');
     8    $DbResult = $this->Database->query('SELECT `TranslationGroup`.*, (SELECT COUNT(*) FROM `TextGroup` WHERE `TextGroup`.`Group` = `TranslationGroup`.`Id`) AS `TextCount` FROM `TranslationGroup`');
    99    while($DbRow = $DbResult->fetch_array())
    1010    {
     
    4444  {
    4545    $Result = array();
    46     $DbResult = $this->Database->query('SELECT `TextGroup`.*, (SELECT `Text` FROM `Text` WHERE `Text`.`TranslationGroup` = `TextGroup`.`Id` LIMIT 1) as `Text` FROM `TextGroup` WHERE `TextGroup`.`Group`='.$GroupId.' AND `TextGroup`.`User`='.$UserId.' AND `TextGroup`.`Language`='.$Language.' LIMIT '.($Page * $ItemPerPage).','.$ItemPerPage);
     46    $DbResult = $this->Database->query('SELECT `TextGroup`.*, (SELECT `Text` FROM `Text` WHERE `Text`.`TranslationGroup` = `TextGroup`.`Id` LIMIT 1) as `Text`, (SELECT COUNT(`TextGroup2`.`User`) FROM `TextGroup` AS `TextGroup2` WHERE `TextGroup2`.`Id` = `TextGroup`.`Id`) as `TextCount` FROM `TextGroup` WHERE `TextGroup`.`Group`='.$GroupId.' AND `TextGroup`.`User`='.$UserId.' AND `TextGroup`.`Language`='.$Language.' LIMIT '.($Page * $ItemPerPage).','.$ItemPerPage);
    4747    //echo($this->Database->LastQuery);
    4848    if($DbResult->num_rows > 0)
     
    6262    return($DbRow[0]);
    6363  }
     64
     65  function GetMultipleText($GroupId, $Index)
     66  {
     67    $Result = array();
     68    $DbResult = $this->Database->query('SELECT `TextGroup`.*, (SELECT `Text` FROM `Text` WHERE `Text`.`TranslationGroup` = `TextGroup`.`Id` LIMIT 1) as `Text` FROM `TextGroup` WHERE `TextGroup`.`Group`='.$GroupId.' AND `TextGroup`.`Index` = '.$Index.' AND `TextGroup`.`Language` != 1');
     69    //echo($this->Database->LastQuery);
     70    if($DbResult->num_rows > 0)
     71    while($DbRow = $DbResult->fetch_array())
     72    {
     73      $Result[] = $DbRow;
     74    }
     75    return($Result);
     76  }
    6477}
    6578
  • branches/2/user.php

    r7 r8  
    1616class User extends Module
    1717{
    18   var $Roles = array('Člen', 'Uživatel', 'Administrator');
     18  var $Roles = array();
    1919  var $User = array();
     20  var $DefaultRole = 2;
    2021 
    2122  function Check()
    2223  {
    2324    $SID = session_id();
     25
    2426    // Lookup user record
    2527    $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
     
    2830      // Refresh time of last access
    2931      $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('Time' => 'NOW()'));
    30     } else $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => 0, 'Time' => 'NOW()', 'IpAddress' => (gethostbyaddr(GetRemoteAddress()).' '.GetRemoteAddress()))); 
     32    } else $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => 1, 'Time' => 'NOW()', 'IpAddress' => (gethostbyaddr(GetRemoteAddress()).' '.GetRemoteAddress()))); 
    3133
    3234    // Odeber neaktivní uživatele
     
    3840    if($Row['User'] != 0)
    3941    {
    40       $Query = $this->Database->select('User', '*', "Id='".$Row['User']."'");
     42      $Query = $this->Database->select('User', '*', "Id=".$Row['User']."");
    4143      $this->User = $Query->fetch_array();
    4244      $Result = USER_LOGGED;
    4345    } else {
    44       $this->User = array('FullName' => 'Návštěvník', 'Id' => 0, 'Name' => 'Anonym');
     46      $Query = $this->Database->select('User', '*', "Id=1");
     47      $this->User = $Query->fetch_array();
    4548      $Result = USER_NOT_LOGGED;
    4649    }
     50    $this->LoadPermission($this->User['Role']);
     51
     52    // Role and permission
     53    $this->LoadRoles();
     54   
    4755  }
    4856
     
    5967      else
    6068      {
    61         $this->Database->insert('User', array('Name' => addslashes($Nick), 'FullName' => addslashes($FullName), 'Password' => addslashes($Password), 'Email' => htmlspecialchars($Email), 'Permission' => 1));
     69        $this->Database->insert('User', array('Name' => addslashes($Nick), 'FullName' => addslashes($FullName), 'Password' => addslashes($Password), 'Email' => htmlspecialchars($Email), 'Role' => $this->DefaultRole));
    6270        $Result = USER_REGISTRATED;
    6371      }
     
    8997  {
    9098    $SID = session_id();
    91     $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => 0));
     99    $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => 1));
    92100    return(USER_LOGGED_OUT);
     101  }
     102
     103  function LoadRoles()
     104  {
     105    $this->Roles = array();
     106    $DbResult = $this->Database->select('UserRole', '*');
     107    while($DbRow = $DbResult->fetch_array())
     108      $this->Roles[] = $DbRow;
     109  }
     110
     111  function LoadPermission($Role)
     112  {
     113    $this->User['Permission'] = array();
     114    $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description` FROM `UserRolePermission` JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` WHERE `UserRolePermission`.`Role` = '.$Role);
     115    if($DbResult->num_rows > 0)
     116    while($DbRow = $DbResult->fetch_array())
     117      $this->User['Permission'][$DbRow['Operation']] = $DbRow;
     118  }
     119
     120  function PermissionMatrix()
     121  {
     122    $Result = array();
     123    $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description`, `UserRole`.`Title` FROM `UserRolePermission` LEFT JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` LEFT JOIN `UserRole` ON `UserRole`.`Id` = `UserRolePermission`.`Role`');
     124    while($DbRow = $DbResult->fetch_array())
     125    {
     126      $Value = '';
     127      if($DbRow['Read']) $Value .= 'R';
     128      if($DbRow['Write']) $Value .= 'W';
     129      $Result[$DbRow['Description']][$DbRow['Title']] = $Value;
     130    }   
     131    return($Result);
    93132  }
    94133}
Note: See TracChangeset for help on using the changeset viewer.