Ignore:
Timestamp:
Apr 23, 2013, 7:12:53 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Výběr relací mezi tabulkami pomocí zobrazení samostatného okna s výběrovou tabulkou ve správě dat.
  • Přidáno: Možnost generovat jen základní HTML část stránky bez hlavičky a patičky.
File:
1 edited

Legend:

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

    r528 r529  
    99  var $ParentClass = 'PagePortal';
    1010  var $MenuItems = array();
     11  var $HideMenu = false;
    1112
    1213  function Show()
     
    2223    {
    2324      $this->MenuItems[$DbRow['Id']] = $DbRow;
    24     }
    25    
    26     $Output = '<table style="width: 100%"><tr><td style="width: 20%; vertical-align: top;">';
    27     $Output .= '<strong>Nabídka:</strong><br/>'.$this->ShowMenuItem('');
    28     $Output .= '</td><td style="width: 80%; vertical-align: top;">';
     25    }   
    2926   
    3027    if(array_key_exists('t', $_GET)) $_SESSION['Table'] = $_GET['t'];
    3128    if(array_key_exists('a', $_GET)) $_SESSION['Action'] = $_GET['a'];
    3229    if(array_key_exists('id', $_GET)) $_SESSION['Id'] = $_GET['id'];
    33        
     30    if(array_key_exists('r', $_GET)) $_SESSION['Ref'] = $_GET['r'];
     31   
    3432    if(!array_key_exists('Action', $_SESSION)) $_SESSION['Action'] = 'list';
    3533    if(!array_key_exists('Id', $_SESSION) or !array_key_exists('Table', $_SESSION) or
     
    3836      $_SESSION['Action'] = '';
    3937      $_SESSION['Table'] = '';
    40     }
    41    
    42     if($_SESSION['Action'] == 'list') $Output .= $this->ShowList($_SESSION['Table']);
    43     else if($_SESSION['Action'] == 'edit') $Output .= $this->ShowEdit($_SESSION['Table'], $_SESSION['Id']);
    44     else if($_SESSION['Action'] == 'add') $Output .= $this->ShowAdd($_SESSION['Table']);
    45     else if($_SESSION['Action'] == 'view') $Output .= $this->ShowView($_SESSION['Table'], $_SESSION['Id']);
    46     else if($_SESSION['Action'] == 'delete') $Output .= $this->ShowDelete($_SESSION['Table'], $_SESSION['Id']);
    47     $Output .= '</td></tr></table>';
     38      $_SESSION['Ref'] = '';
     39    }
     40   
     41    if($_SESSION['Action'] == 'list') $Content = $this->ShowList($_SESSION['Table']);
     42    else if($_SESSION['Action'] == 'select') $Content = $this->ShowSelect($_SESSION['Table']);
     43    else if($_SESSION['Action'] == 'edit') $Content = $this->ShowEdit($_SESSION['Table'], $_SESSION['Id']);
     44    else if($_SESSION['Action'] == 'add') $Content = $this->ShowAdd($_SESSION['Table']);
     45    else if($_SESSION['Action'] == 'view') $Content = $this->ShowView($_SESSION['Table'], $_SESSION['Id']);
     46    else if($_SESSION['Action'] == 'delete') $Content = $this->ShowDelete($_SESSION['Table'], $_SESSION['Id']);
     47    else $Content = '';
     48    if($this->HideMenu == false)
     49    {
     50      $Output = '<table style="width: 100%"><tr><td style="width: 20%; vertical-align: top;">';
     51      $Output .= '<strong>Nabídka:</strong><br/>'.$this->ShowMenuItem('');
     52      $Output .= '</td><td style="width: 80%; vertical-align: top;">';
     53      $Output .= $Content;
     54      $Output .= '</td></tr></table>';
     55    } else $Output = $Content;
    4856   
    4957    return($Output);
     
    7078      $Form->SetClass($Table);
    7179      $Form->LoadValuesFromDatabase($Id);
    72       $Form->OnSubmit = '?a=edit&amp;o=save';
     80      $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;o=save';
    7381      $Output .= $Form->ShowEditForm();
    7482      $Output .= '<ul class="ActionMenu">';
    75       $Output .= '<li><a href="?a=view"><img alt="Prohlížet" title="Prohlížet" src="'.
     83      $Output .= '<li><a href="?a=view&amp;t='.$Table.'"><img alt="Prohlížet" title="Prohlížet" src="'.
    7684      $this->System->Link('/images/view.png').'"/>Prohlížet</a></li>';
    77       $Output .= '<li><a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
     85      $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
    7886        $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
    79       $Output .= '<li><a href="?a=delete" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
     87      $Output .= '<li><a href="?a=delete&amp;t='.$Table.'" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
    8088        $this->System->Link('/images/delete.png').'"/>Odstranit</a></li>';
    8189      $Output .= '</ul>';
     
    118126      $Form = new Form($this->System->FormManager);
    119127      $Form->SetClass($Table);
    120       $Form->OnSubmit = '?a=add&amp;o=save';
     128      $Form->OnSubmit = '?a=add&amp;t='.$Table.'&amp;o=save';
    121129      $Output .= $Form->ShowEditForm();
    122130      $Output .= '<ul class="ActionMenu">';
    123       $Output .= '<li><a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
     131      $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
    124132        $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
    125133      $Output .= '</ul>';
     
    166174  }
    167175 
    168   function ShowList($Table, $Filter = '', $Title = '')
    169   {   
     176  function ShowSelect($Table, $Filter = '', $Title = '')
     177  {
     178    $this->BasicHTML = true;
     179    $this->HideMenu = true;
    170180    if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
    171181      else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
     
    174184    $PageList = GetPageList($DbRow[0]);   
    175185
    176     $Output = '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
     186    $Output = '<script type="text/javascript">
     187    function set_return(id, obj)
     188    {
     189      window.opener.document.getElementById(obj).value = id;
     190    }
     191    </script>';
     192    $Output .= '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
    177193    $Output .= $PageList['Output'];
    178194    $Output .= '<table class="WideTable" style="font-size: small;">';
     
    204220      }
    205221    }     
    206     $Output .= '<tr><form action="?a=list&amp;filter=1" method="post">';
     222    $Output .= '<tr><form action="?a=select&amp;filter=1" method="post">';
    207223    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    208224      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     
    252268        $Output .= '<td>'.$Value.'</td>';
    253269      }
     270      $Output .= '<td><a href="javascript:window.close();" onclick="set_return('.$Row['Id'].',&quot;'.$_SESSION['Ref'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
     271        $this->System->Link('/images/select.png').'"/></a>';
     272      $Output .= '</td></tr>';
     273    }
     274    $Output .= '</table>';
     275    $Output .= $PageList['Output'];
     276    return($Output);
     277  }
     278   
     279  function ShowList($Table, $Filter = '', $Title = '')
     280  {   
     281    if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
     282      else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
     283
     284    // Build user filter
     285    $UserFilter = '';
     286    if(array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
     287    {
     288      foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     289      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     290          (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     291              ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     292      {
     293        if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
     294          $UserFilter .= ' AND (`'.$ItemIndex.'` LIKE "%'.$_POST['Filter'.$ItemIndex].'%")';
     295      }
     296    }     
     297    if(($Filter == '') and ($UserFilter != '')) $Filter = '1 '.$UserFilter;
     298    if($Filter != '') $Filter = ' WHERE '.$Filter;
     299   
     300    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
     301    $DbRow = $DbResult->fetch_row();
     302    $PageList = GetPageList($DbRow[0]);   
     303
     304    $Output = '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
     305    $Output .= $PageList['Output'];
     306    $Output .= '<table class="WideTable" style="font-size: small;">';
     307   
     308    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     309    if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     310      (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     311      ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     312    {
     313      $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
     314    }   
     315    $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
     316    if(!array_key_exists('DefaultSortColumn', $FormClass))
     317      $FormClass['DefaultSortColumn'] = 'Id';
     318    $Order = GetOrderTableHeader($TableColumns, $FormClass['DefaultSortColumn'], 0);
     319    $Output .= $Order['Output'];
     320   
     321    // Show search fields
     322    $Output .= '<tr><form action="?a=list&amp;filter=1" method="post">';
     323    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     324      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     325          (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     326              ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     327    {
     328      if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
     329        $Value = $_POST['Filter'.$ItemIndex];
     330        else $Value = ''; 
     331      $Output .= '<td><input type="text" name="Filter'.$ItemIndex.'" value="'.$Value.'" style="width: 100%"/></td>';   
     332    }
     333    $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
     334
     335    $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
     336   
     337    $DbResult = $this->Database->query($Query);
     338    while($Row = $DbResult->fetch_assoc())
     339    {
     340      $Output .= '<tr>';
     341      foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     342      if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
     343      (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
     344      ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     345      {
     346        //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
     347        $UseType = $UseType = $FormItem['Type'];
     348        if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
     349        {
     350          if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
     351            $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
     352              $this->System->FormManager->FormTypes[$FormItem['Type']]);
     353          if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
     354          $UseType = 'OneToMany';
     355          else
     356          if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
     357          $UseType = 'Enumeration';
     358        }
     359        $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
     360          array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
     361          'Type' => $FormItem['Type']));
     362        $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
     363          array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
     364          'Type' => $FormItem['Type']));
     365        if($Value == '') $Value = '&nbsp;';
     366        $Output .= '<td>'.$Value.'</td>';
     367      }
    254368      $Output .= '<td><a href="?a=view&amp;t='.$Table.'&amp;id='.$Row['Id'].'"><img alt="Ukázat" title="Ukázat" src="'.
    255369        $this->System->Link('/images/view.png').'"/></a>'.
Note: See TracChangeset for help on using the changeset viewer.