Changeset 415 for trunk


Ignore:
Timestamp:
Oct 7, 2012, 8:37:15 PM (12 years ago)
Author:
chronos
Message:
  • Upraveno: Optimalizace kontroly oprávnění operací.
  • Upraveno: Načítání skupin odkazů na hlavní stránce.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        66postfixadmin
        77backup
         8.project
         9.buildpath
         10.settings
  • trunk/finance/spotreba.php

    r409 r415  
    1414    $Output = 'Spotřeba zařízení jednotlivých segmentů:<div align="center"><table class="WideTable"><tr><th>Jméno segmentu</th><th>Spotřeba [W]</th><th>Cena [Kč/měsíc]</th></tr>';
    1515    $CelkovaSpotreba = 0;
    16     $DbResult = $this->Database->query("SELECT * FROM NetworkSegment");
     16    $DbResult = $this->Database->query('SELECT * FROM NetworkSegment');
    1717    while($Segment = $DbResult->fetch_array())
    1818    {
    19       $DbResult2 = $this->Database->query("SELECT SUM(Consumption) FROM Product WHERE Segment=".$Segment['Id']." AND Used=1");
     19      $DbResult2 = $this->Database->query('SELECT SUM(Consumption) FROM Product WHERE Segment='.$Segment['Id'].' AND Used=1');
    2020      $Row2 = $DbResult2->fetch_array();
    2121      $CelkovaSpotreba = $CelkovaSpotreba + $Row2[0];
    22       $Output .= '<tr><td>'.$Row['Name'].'</td><td align="right">'.$Row2[0].'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($Row2[0]).'</td></tr>';
     22      $Output .= '<tr><td>'.$Segment['Name'].'</td><td align="right">'.$Row2[0].'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($Row2[0]).'</td></tr>';
    2323    }
    2424    $Output .= '<tr style="font-weight: Bold;"><td><strong>Celkem</strong></td><td align="right">'.$CelkovaSpotreba.'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($CelkovaSpotreba).'</td></tr>';
  • trunk/finance/user_state.php

    r413 r415  
    2222      if(!$this->System->Modules['User']->CheckPermission('Finance', 'DisplaySubjectState')) return('Nemáte oprávnění');
    2323      $UserId = $this->System->Modules['User']->User['Id'];
    24       $DbResult = $this->Database->query('SELECT * FROM Subject WHERE Id=(SELECT Subject FROM Member WHERE Id=(SELECT Customer FROM UserCustomerRel WHERE User='.$UserId.'))');
     24      $DbResult = $this->Database->query('SELECT * FROM Subject WHERE Id=(SELECT Subject FROM Member WHERE Id=(SELECT Customer FROM UserCustomerRel WHERE User='.$UserId.' LIMIT 1))');
    2525      $Subject = $DbResult->fetch_assoc();
    2626    }
  • trunk/index.php

    r305 r415  
    99  var $ShortTitle = '';
    1010 
    11   function ShowLinks($GroupId)
    12   {
    13     global $Database;
    14    
    15     $DbResult = $Database->query('SELECT * FROM `HyperlinkGroup` WHERE `Id`='.$GroupId);
    16     $HyperlinkGroup = $DbResult->fetch_assoc();
    17 
     11  function ShowLinks($HyperlinkGroup)
     12  {
    1813    $Output = '';
    19     $DbResult = $Database->query('SELECT * FROM `Hyperlink` WHERE (`Group`='.$GroupId.') AND (`Enable` = 1)');
     14    $DbResult = $this->Database->query('SELECT * FROM `Hyperlink` WHERE (`Group`='.$HyperlinkGroup['Id'].') AND (`Enable` = 1)');
    2015    while($HyperLink = $DbResult->fetch_assoc())
    2116    {
    2217      if($HyperLink['IconFile'] == '') $HyperLink['IconFile'] = 'clear.png';
    2318        if(substr($HyperLink['URL'], 0, 4) != 'http') $HyperLink['URL'] = $this->System->Config['Web']['RootFolder'].$HyperLink['URL'];
    24         if(($HyperLink['PermissionModule'] == '') or (($HyperLink['PermissionModule'] != '') and $this->System->Modules['User']->CheckPermission($HyperLink['PermissionModule'], $HyperLink['PermissionOperation'])))       
     19        if(($HyperLink['PermissionModule'] == '') or (($HyperLink['PermissionModule'] != '') and $this->System->Modules['User']->Models['User']->CheckPermission($HyperLink['PermissionModule'], $HyperLink['PermissionOperation'])))       
    2520        $Output .= '<img alt="'.$HyperLink['Name'].'" src="images/favicons/'.$HyperLink['IconFile'].'" width="16" height="16" /> <a href="'.$HyperLink['URL'].'">'.$HyperLink['Name'].'</a><br />';
    2621    }
     
    6358    if($this->System->Modules['User']->CheckPermission('Finance', 'DisplaySubjectState'))
    6459    {
    65       $DbResult = $this->Database->select('Subject', 'Money', 'Id=(SELECT Subject FROM Member WHERE Id=(SELECT Member FROM User WHERE Id='.$this->System->Modules['User']->User['Id'].'))');
     60      $DbResult = $this->Database->select('MemberPayment', 'Cash', 'Member=(SELECT Customer FROM UserCustomerRel WHERE Id='.$this->System->Modules['User']->User['Id'].')');
    6661      if($DbResult->num_rows > 0)
    6762      {
    6863        $DbRow = $DbResult->fetch_assoc();
    69         $Output2 .= ' &nbsp;  &nbsp; <img alt="" src="images/favicons/money.png" width="16" height="16" /> '.$DbRow['Money'].' Kč';
     64        $Output2 .= ' &nbsp;  &nbsp; <img alt="" src="images/favicons/money.png" width="16" height="16" /> '.$DbRow['Cash'].' Kč';
    7065      }
    7166    }
     
    273268    $Database->select_db($Config['Database']['Database']);
    274269
     270    $DbResult = $Database->query('SELECT * FROM `HyperlinkGroup`');
     271    while($DbRow = $DbResult->fetch_assoc())
     272      $HyperlinkGroups[$DbRow['Id']] = $DbRow;
     273
    275274    // Show pannels
    276275    //if(IsInternetAddr()) echo('Internet'); else echo('LAN');
    277     //$Output .= $this->InfoBar();
     276    $Output .= $this->InfoBar();
    278277    $Output .= '<table id="MainTable"><tr>';
    279278    $DbResult = $Database->select('PanelColumn', '*');
     
    283282        else $Width = '';
    284283      $Output .= '<td valign="top"'.$Width.'>';
    285       $DbResult2 = $Database->query('SELECT * FROM  `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`');
     284      $DbResult2 = $Database->query('SELECT * FROM `Panel` WHERE `PanelColumn`='.$PanelColumn['Id'].' ORDER BY `Order`');
    286285      while($Panel = $DbResult2->fetch_assoc())
    287286      {
    288         if($Panel['Module'] == 'HyperlinkGroup') $Output .= $this->ShowLinks($Panel['Parameters']);
     287        if($Panel['Module'] == 'HyperlinkGroup') $Output .= $this->ShowLinks($HyperlinkGroups[$Panel['Parameters']]);
    289288        else if($Panel['Module'] == 'OnlineHostList') $Output .= $this->Panel('Online počítače', $this->OnlineHostList());
    290289        else if($Panel['Module'] == 'UserOptions')
  • trunk/sql/updates/409.sql

    r409 r415  
    66CHANGE `pos` `Pos` INT( 11 ) NOT NULL DEFAULT '0',
    77CHANGE `first` `First` INT( 11 ) NOT NULL DEFAULT '0',
    8 CHANGE `last` `Last` INT( 11 ) NOT NULL DEFAULT '0'
     8CHANGE `last` `Last` INT( 11 ) NOT NULL DEFAULT '0';
    99
    1010
  • trunk/sql/updates/410.sql

    r410 r415  
    99
    1010ALTER TABLE `UserCustomerRel`
    11   ADD CONSTRAINT `usercustomerrel_ibfk_2` FOREIGN KEY (`User`) REFERENCES `user` (`Id`),
    12   ADD CONSTRAINT `usercustomerrel_ibfk_1` FOREIGN KEY (`Customer`) REFERENCES `member` (`Id`);
     11  ADD CONSTRAINT `usercustomerrel_ibfk_2` FOREIGN KEY (`User`) REFERENCES `User` (`Id`),
     12  ADD CONSTRAINT `usercustomerrel_ibfk_1` FOREIGN KEY (`Customer`) REFERENCES `Member` (`Id`);
    1313
    1414INSERT INTO `UserCustomerRel` (SELECT NULL as Id, Member as Customer, Id AS User FROM User WHERE Member IS NOT NULL);
  • trunk/user.php

    r410 r415  
    3434  var $AnonymousUserId = 98;
    3535  var $OnlineStateTimeout = 600; // in seconds
     36  var $PermissionCache = array();
    3637
    3738  function Check()
     
    5253    if($Row['User'] != $this->AnonymousUserId)
    5354    {
    54       $Query = $this->Database->query('SELECT *, UserCustomerRel.Customer AS Member FROM User JOIN UserCustomerRel ON UserCustomerRel.User=User.Id WHERE User.Id='.$Row['User']);     
     55      $Query = $this->Database->query('SELECT User.*, UserCustomerRel.Customer AS Member FROM User JOIN UserCustomerRel ON UserCustomerRel.User=User.Id WHERE User.Id='.$Row['User']);     
    5556      $this->User = $Query->fetch_assoc();
    5657      $Result = USER_LOGGED;
     
    208209  function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0)
    209210  {
    210         $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
    211     if($DbResult->num_rows > 0)
    212     {
    213       $DbRow = $DbResult->fetch_array();
    214       $OperationId = $DbRow['Id'];
    215 
     211    // First try to check cache
     212    if(in_array(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache))
     213    {
     214      $OperationId = array_search(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache);
     215      $PermissionExists = is_numeric($OperationId);
     216    } else
     217    {   
     218      // If no permission combination exists in cache, do new check of database items
     219      $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
     220      if($DbResult->num_rows > 0)
     221      {
     222        $DbRow = $DbResult->fetch_array();
     223        $OperationId = $DbRow['Id'];
     224        $this->PermissionCache[$DbRow['Id']] = array($Module, $Operation, $ItemType, $ItemType);       
     225        $PermissionExists = true;
     226      } else
     227      {         
     228        $this->PermissionCache[$DbRow['Id'].'_'] = array($Module, $Operation, $ItemType, $ItemType);       
     229        $PermissionExists = false;
     230      }
     231    }
     232
     233    if($PermissionExists)
     234    {
    216235      // Check user-operation relation
    217236      $DbResult = $this->Database->select('PermissionUserAssignment', '*', '`User`="'.$this->User['Id'].'" AND `AssignedOperation`="'.$OperationId.'"');
     
    219238
    220239      // Check user-group relation
    221       $DbResult = $this->Database->select('PermissionUserAssignment', 'AssignedGroup', '`User`="'.$this->User['Id'].'" AND `AssignedGroup` IS NOT NULL');
     240      $DbResult = $this->Database->select('PermissionUserAssignment', 'AssignedGroup', '`User`="'.$this->User['Id'].'"');
    222241      while($DbRow = $DbResult->fetch_array())
    223242      {
    224          if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
     243       if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
    225244      }
    226245      return(false);
Note: See TracChangeset for help on using the changeset viewer.