Ignore:
Timestamp:
May 18, 2013, 6:51:10 PM (12 years ago)
Author:
chronos
Message:
  • Opraveno: Položky nabídky ve Správě dat se opakovaně všechny načítaly z databáze pro každou skupinu.
  • Opraveno: Nyní funguje také rychlé filtrování tabulek ve Správě dat dle sloupců s typem OneToMany.
  • Upraveno: Optimalizace načítání textových názvů položek typu OneToMany. Dříve se načítaly samostatným SQL dotazem pro každý řádek zvlášť. Nyní se načítají jako jeden SELECT.
  • Přidáno: Modul TimeMeasure pro měření a zobrazování časových grafů veličin.
File:
1 edited

Legend:

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

    r533 r536  
    99  var $ParentClass = 'PagePortal';
    1010  var $MenuItems = array();
     11  var $MenuItemsLoaded = false;
    1112  var $HideMenu = false;
    1213
     
    8889      $Output .= $Form->ShowEditForm();
    8990      $Output .= '<ul class="ActionMenu">';
    90       $Output .= '<li><a href="?a=view&amp;t='.$Table.'"><img alt="Prohlížet" title="Prohlížet" src="'.
     91      $Output .= '<li><a href="?a=view&amp;t='.$Table.'&amp;i='.$Id.'"><img alt="Prohlížet" title="Prohlížet" src="'.
    9192      $this->System->Link('/images/view.png').'"/>Prohlížet</a></li>';
    9293      $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
     
    178179  }
    179180 
    180   function ShowSelect($Table, $Filter = '', $Title = '')
    181   {
    182     $this->BasicHTML = true;
    183     $this->HideMenu = true;
     181  function ShowTable($Table, $Filter = '', $Title = '', $RowActions = array())
     182  {   
    184183    if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
    185184      else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
    186     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
    187     $DbRow = $DbResult->fetch_row();
    188     $PageList = GetPageList($DbRow[0]);   
    189 
    190     $Output = '<script type="text/javascript">
    191     function set_return(id, obj)
    192     {
    193       window.opener.document.getElementById(obj).value = id;
    194     }
    195     </script>';
    196     $Output .= '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
     185
     186    // Build user filter
     187    $UserFilter = '';
     188    $Columns = array('Id' => '`Id`');
     189    if(array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
     190    {
     191      foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     192      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     193          (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     194              ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     195      {
     196        $UseType = $UseType = $FormItem['Type'];
     197        if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
     198        {
     199          if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
     200            $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
     201              $this->System->FormManager->FormTypes[$FormItem['Type']]);
     202          if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
     203          $UseType = 'OneToMany';
     204          else
     205          if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
     206          $UseType = 'Enumeration';
     207        }
     208        $FilterName = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterName',
     209          array('Name' => $ItemIndex, 'Type' => $FormItem['Type']));
     210        if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
     211          $UserFilter .= ' AND ('.$FilterName.' LIKE "%'.$_POST['Filter'.$ItemIndex].'%")';
     212      }
     213    }     
     214    if(($Filter == '') and ($UserFilter != '')) $Filter = '1 '.$UserFilter;
     215    if($Filter != '') $Filter = ' WHERE '.$Filter;
     216   
     217    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     218      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     219          (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     220              ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     221      {
     222        $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
     223        $UseType = $UseType = $FormItem['Type'];
     224        if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
     225        {
     226          if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
     227            $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
     228                $this->System->FormManager->FormTypes[$FormItem['Type']]);
     229          if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
     230            $UseType = 'OneToMany';
     231          else
     232            if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
     233            $UseType = 'Enumeration';
     234        }
     235        if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
     236          $Value = $_POST['Filter'.$ItemIndex];
     237          else $Value = '';       
     238        if($ItemIndex == 'Id') unset($Columns['Id']);
     239        $Columns[] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery',
     240          array('Value' => $Value, 'Name' => $ItemIndex,
     241              'Type' => $FormItem['Type']));
     242      }
     243     
     244    // Get total item count in database
     245    $Query = 'SELECT COUNT(*) FROM `'.$FormClass['Table'].'`';
     246    $DbResult = $this->Database->query($Query);
     247    $DbRow = $DbResult->fetch_assoc();
     248    $TotalCount = $DbRow['COUNT(*)'];
     249   
     250    // Get total filtered item count in database
     251    $Columns = implode(',', $Columns);
     252    if($UserFilter != '')
     253    {
     254      $Query = 'SELECT COUNT(*) FROM (SELECT '.$Columns.' FROM `'.$FormClass['Table'].'`) AS `TS` '.$Filter;
     255      $DbResult = $this->Database->query($Query);
     256      $DbRow = $DbResult->fetch_row();
     257      $TotalFilteredCount = $DbRow[0];
     258    } else $TotalFilteredCount = $TotalCount;
     259    $PageList = GetPageList($TotalFilteredCount);   
     260
     261    $Output = '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
    197262    $Output .= $PageList['Output'];
    198263    $Output .= '<table class="WideTable" style="font-size: small;">';
    199264   
    200     foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    201     if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    202       (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
    203       ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    204     {
    205       $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
    206     }   
    207265    $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
    208266    if(!array_key_exists('DefaultSortColumn', $FormClass))
     
    212270   
    213271    // Show search fields
    214     $UserFilter = '';
    215     if(array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
    216     {
    217       foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    218       if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    219           (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
    220               ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    221       {
    222         if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
    223           $UserFilter .= ' AND (`'.$ItemIndex.'` LIKE "%'.$_POST['Filter'.$ItemIndex].'%")';
    224       }
    225     }     
    226     $Output .= '<tr><form action="?a=select&amp;t='.$Table.'&amp;r='.$_GET['r'].'&amp;filter=1" method="post">';
     272    $Output .= '<tr><form action="?a=list&amp;t='.$Table.'&amp;filter=1" method="post">';
    227273    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    228274      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     
    236282    }
    237283    $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
    238 
    239     if(($Filter == '') and ($UserFilter != '')) $Filter = '1 '.$UserFilter;
    240     if($Filter != '') $Filter = ' WHERE '.$Filter;
    241     $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
    242    
     284   
     285    // Load and show items
     286    $Query = 'SELECT * FROM (SELECT '.$Columns.' FROM `'.$FormClass['Table'].'`) AS `TS` '.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];   
     287    $VisibleItemCount = 0;
    243288    $DbResult = $this->Database->query($Query);
    244289    while($Row = $DbResult->fetch_assoc())
     
    268313        $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
    269314          array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
    270           'Type' => $FormItem['Type']));
     315          'Type' => $FormItem['Type'], 'Filter' => $Row[$ItemIndex.'_Filter']));
    271316        if($Value == '') $Value = '&nbsp;';
    272317        $Output .= '<td>'.$Value.'</td>';
    273318      }
    274       $Output .= '<td><a href="javascript:window.close();" onclick="set_return('.$Row['Id'].',&quot;'.$_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
    275         $this->System->Link('/images/select.png').'"/></a>';
    276       $Output .= '</td></tr>';
    277     }
    278     $Output .= '</table>';
    279     $Output .= $PageList['Output'];
    280     return($Output);
    281   }
    282    
    283   function ShowList($Table, $Filter = '', $Title = '')
    284   {   
    285     if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
    286       else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
    287 
    288     // Build user filter
    289     $UserFilter = '';
    290     if(array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
    291     {
    292       foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    293       if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    294           (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
    295               ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    296       {
    297         if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
    298           $UserFilter .= ' AND (`'.$ItemIndex.'` LIKE "%'.$_POST['Filter'.$ItemIndex].'%")';
    299       }
    300     }     
    301     if(($Filter == '') and ($UserFilter != '')) $Filter = '1 '.$UserFilter;
    302     if($Filter != '') $Filter = ' WHERE '.$Filter;
    303    
    304     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
    305     $DbRow = $DbResult->fetch_row();
    306     $PageList = GetPageList($DbRow[0]);   
    307 
    308     $Output = '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
    309     $Output .= $PageList['Output'];
    310     $Output .= '<table class="WideTable" style="font-size: small;">';
    311    
    312     foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    313     if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    314       (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
    315       ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    316     {
    317       $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
    318     }   
    319     $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
    320     if(!array_key_exists('DefaultSortColumn', $FormClass))
    321       $FormClass['DefaultSortColumn'] = 'Id';
    322     $Order = GetOrderTableHeader($TableColumns, $FormClass['DefaultSortColumn'], 0);
    323     $Output .= $Order['Output'];
    324    
    325     // Show search fields
    326     $Output .= '<tr><form action="?a=list&amp;t='.$Table.'&amp;filter=1" method="post">';
    327     foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    328       if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    329           (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
    330               ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    331     {
    332       if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
    333         $Value = $_POST['Filter'.$ItemIndex];
    334         else $Value = ''; 
    335       $Output .= '<td><input type="text" name="Filter'.$ItemIndex.'" value="'.$Value.'" style="width: 100%"/></td>';   
    336     }
    337     $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
    338 
    339     // Get total item count in database
    340     $Query = 'SELECT COUNT(*) FROM `'.$FormClass['Table'].'`';
    341     $DbResult = $this->Database->query($Query);
    342     $DbRow = $DbResult->fetch_assoc();
    343     $TotalCount = $DbRow['COUNT(*)'];
    344    
    345     // Get total filtered item count in database
    346     if($UserFilter != '')
    347     {
    348       $Query = 'SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter;
    349       $DbResult = $this->Database->query($Query);
    350       $DbRow = $DbResult->fetch_assoc();
    351       $TotalFilteredCount = $DbRow['COUNT(*)'];
    352     }   
    353    
    354     // Load and show items
    355     $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];   
    356     $VisibleItemCount = 0;
    357     $DbResult = $this->Database->query($Query);
    358     while($Row = $DbResult->fetch_assoc())
    359     {
    360       $Output .= '<tr>';
    361       foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    362       if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    363       (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
    364       ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    365       {
    366         //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
    367         $UseType = $UseType = $FormItem['Type'];
    368         if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
    369         {
    370           if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
    371             $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
    372               $this->System->FormManager->FormTypes[$FormItem['Type']]);
    373           if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
    374           $UseType = 'OneToMany';
    375           else
    376           if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
    377           $UseType = 'Enumeration';
    378         }
    379         $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
    380           array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
    381           'Type' => $FormItem['Type']));
    382         $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
    383           array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
    384           'Type' => $FormItem['Type']));
    385         if($Value == '') $Value = '&nbsp;';
    386         $Output .= '<td>'.$Value.'</td>';
    387       }
    388       $Output .= '<td><a href="?a=view&amp;t='.$Table.'&amp;i='.$Row['Id'].'"><img alt="Ukázat" title="Ukázat" src="'.
    389         $this->System->Link('/images/view.png').'"/></a>'.
    390         '<a href="?a=edit&amp;t='.$Table.'&amp;i='.$Row['Id'].'"><img alt="Upravit" title="Upravit" src="'.
    391         $this->System->Link('/images/edit.png').'"/></a>'.
    392         '<a href="?a=delete&amp;t='.$Table.'&amp;i='.$Row['Id'].'"><img alt="Smazat" title="Smazat" src="'.
    393         $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
    394       if(array_key_exists('ItemActions', $FormClass))
    395       {
    396         foreach($FormClass['ItemActions'] as $Action)
    397           $Output .= '<a href="'.$this->System->Link($Action['URL']).'&amp;i='.$Row['Id'].'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
    398             $this->System->Link('/images/action.png').'"/></a>';
    399       }
    400       $Output .= '</td></tr>';
     319      $Output .= '<td>'.str_replace('#RowId', $Row['Id'], $RowActions).'</td></tr>';
    401320      $VisibleItemCount = $VisibleItemCount + 1;
    402321    }
     
    406325    $Output .= '</table>';
    407326    $Output .= $PageList['Output'];
     327    return($Output);
     328  }
     329 
     330  function ShowSelect($Table, $Filter = '', $Title = '')
     331  {
     332    $this->BasicHTML = true;
     333    $this->HideMenu = true;
     334    $RowActions = '<a href="javascript:window.close();" onclick="set_return(#RowId,&quot;'.$_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
     335      $this->System->Link('/images/select.png').'"/></a>';
     336    $Output = $this->ShowTable($Table, $Filter, $Title, $RowActions);   
     337    return($Output);
     338  }   
     339 
     340  function ShowList($Table, $Filter = '', $Title = '') 
     341  {
     342    $RowActions = '<a href="?a=view&amp;t='.$Table.'&amp;i=#RowId"><img alt="Ukázat" title="Ukázat" src="'.
     343      $this->System->Link('/images/view.png').'"/></a>'.
     344      '<a href="?a=edit&amp;t='.$Table.'&amp;i=#RowId"><img alt="Upravit" title="Upravit" src="'.
     345      $this->System->Link('/images/edit.png').'"/></a>'.
     346      '<a href="?a=delete&amp;t='.$Table.'&amp;i=#RowId"><img alt="Smazat" title="Smazat" src="'.
     347      $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
     348    if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
     349      else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
     350    if(array_key_exists('ItemActions', $FormClass))
     351    {
     352      foreach($FormClass['ItemActions'] as $Action)
     353        $RowActions .= '<a href="'.$this->System->Link($Action['URL']).'&amp;i=#RowId"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
     354          $this->System->Link('/images/action.png').'"/></a>';
     355    }   
     356    $Output = $this->ShowTable($Table, $Filter, $Title, $RowActions);
    408357    $Output .= '<ul class="ActionMenu">';
    409358    $Output .= '<li><a href="?a=add&amp;t='.$Table.'"><img alt="Přidat" title="Přidat" src="'.
     
    418367    }
    419368    $Output .= '</ul>';
    420     return($Output);
     369    return($Output);   
    421370  }
    422371 
    423372  function ShowMenuItem($Parent)
    424373  {
    425     $DbResult = $this->Database->query('SELECT `MenuItem`.`Id`, `MenuItem`.`Name`, `MenuItem`.`Parent`, `Action`.`URL` AS `URL`, `ActionIcon`.`Name` AS `IconName`  FROM `MenuItem` '.
    426       'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
    427       'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
    428       'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
    429     while($DbRow = $DbResult->fetch_assoc())
    430     {
    431       $this->MenuItems[$DbRow['Id']] = $DbRow;
     374    if($this->MenuItemsLoaded == false)
     375    {
     376      $DbResult = $this->Database->query('SELECT `MenuItem`.`Id`, `MenuItem`.`Name`, `MenuItem`.`Parent`, `Action`.`URL` AS `URL`, `ActionIcon`.`Name` AS `IconName`  FROM `MenuItem` '.
     377        'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
     378        'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
     379        'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
     380      while($DbRow = $DbResult->fetch_assoc())
     381      {
     382        $this->MenuItems[$DbRow['Id']] = $DbRow;
     383      }
     384      $this->MenuItemsLoaded = true;
    432385    }   
    433386   
Note: See TracChangeset for help on using the changeset viewer.