Changeset 434


Ignore:
Timestamp:
Oct 12, 2012, 9:03:30 AM (12 years ago)
Author:
chronos
Message:
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/form_classes.php

    r433 r434  
    8484      'LastOnline' => array('Type' => 'DateTime', 'Caption' => 'Naposledy běželo', 'Default' => ''),
    8585      'PermanentOnline' => array('Type' => 'Boolean', 'Caption' => 'Běží stále', 'Default' => '0'),
     86      'Interfaces' => array('Type' => 'TInterfaceList', 'Caption' => 'Rozhraní', 'Default' => ''),
    8687    ),
    8788  ),
     
    439440    'Filter' => '1',
    440441  ),
     442  'TInterfaceList' => array(
     443    'Type' => 'ManyToOne',
     444    'Table' => 'NetworkInterface',
     445    'Id' => 'Id',
     446    'Ref' => 'Device',
     447    'Filter' => '1',
     448  ),
    441449);
    442450
  • trunk/forms.php

    r433 r434  
    2626    );
    2727    foreach($this->Definition['Items'] as $Index => $Item)
     28    if(!array_key_exists($Item['Type'], $FormTypes) or
     29    (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    2830    {
    2931      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     
    6466    if($Context != '') $Context = $Context.'-';
    6567    foreach($this->Definition['Items'] as $Index => $Item)
     68    if(!array_key_exists($Item['Type'], $FormTypes) or
     69    (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    6670    {
    6771      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     
    154158  function LoadValuesFromDatabase($Id)
    155159  {
    156     global $Database;
     160    global $Database, $FormTypes;
    157161
    158162    $DbResult = $Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id);
    159163    $DbRow = $DbResult->fetch_array();
    160164    foreach($this->Definition['Items'] as $Index => $Item)
     165    if(!array_key_exists($Item['Type'], $FormTypes) or
     166    (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    161167    {
    162168      $this->Values[$Index] = $DbRow[$Index];
  • trunk/is/index.php

    r433 r434  
    3333    if(!array_key_exists('Action', $_SESSION)) $_SESSION['Action'] = 'list';
    3434   
    35     if($_SESSION['Action'] == 'list') $Output .= $this->ShowList();
     35    if($_SESSION['Action'] == 'list') $Output .= $this->ShowList($_SESSION['Table']);
    3636    else if($_SESSION['Action'] == 'edit') $Output .= $this->ShowEdit();
    3737    else if($_SESSION['Action'] == 'add') $Output .= $this->ShowAdd();
     
    115115  function ShowView()
    116116  {
     117    global $FormTypes;
     118   
    117119    $Form = new Form($_SESSION['Table']);
    118120    $Form->LoadValuesFromDatabase($_SESSION['Id']);
     
    126128    $Output .= '<a href="?a=delete"><img alt="Odstranit" title="Odstranit" src="'.
    127129      $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
    128     $Output .= '</div>';
    129     return($Output);
    130   }
    131  
    132   function ShowList()
     130    $Output .= '</div><br/>';
     131   
     132    // Show ManyToOne relations
     133    foreach($Form->Definition['Items'] as $Index => $Item)
     134    if((array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
     135    {
     136      $Output .= '<div style="text-align: center;">'.$Form->Definition['Title'].'</div>';
     137      $Output .= $this->ShowList($FormTypes[$Item['Type']]['Table'], '`'.$FormTypes[$Item['Type']]['Ref'].'`='.$_SESSION['Id']).'<br/>';
     138    }   
     139    return($Output);
     140  }
     141 
     142  function ShowList($Table, $Filter = '')
    133143  {   
    134144    global $Type, $FormTypes, $FormClasses;
    135145   
    136     if(array_key_exists('Table', $_SESSION))
    137       $FormClass = $FormClasses[$_SESSION['Table']];
     146    if($Table != '') $FormClass = $FormClasses[$Table];
    138147      else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
    139     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`');
     148    if($Filter != '') $Filter = ' WHERE '.$Filter;
     149    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
    140150    $DbRow = $DbResult->fetch_row();
    141151    $PageList = GetPageList($DbRow[0]);   
     
    145155   
    146156    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     157    if(!array_key_exists($FormItem['Type'], $FormTypes) or
     158      (array_key_exists($FormItem['Type'], $FormTypes) and ($FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    147159      $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
    148160    $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
     
    152164    $Output .= $Order['Output'];
    153165
    154     $Query = 'SELECT * FROM `'.$FormClass['Table'].'` '.$Order['SQL'].$PageList['SQLLimit'];
     166    $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
    155167   
    156168    $DbResult = $this->Database->query($Query);
     
    159171      $Output .= '<tr>';
    160172      foreach($FormClass['Items'] as $ItemIndex => $FormItem)
     173      if(!array_key_exists($FormItem['Type'], $FormTypes) or
     174      (array_key_exists($FormItem['Type'], $FormTypes) and ($FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
    161175      {
    162176        //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
     
    166180            $this->System->Type->RegisterType($FormItem['Type'], '',
    167181              $FormTypes[$FormItem['Type']]);
    168           $Output .= '<td>'.$this->System->Type->ExecuteTypeEvent('OneToMany', 'OnView',
     182          $Value = $this->System->Type->ExecuteTypeEvent('OneToMany', 'OnView',
    169183            array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
    170             'Type' => $FormItem['Type'])).'</td>';
    171         } else $Output .= '<td>'.$this->System->Type->ExecuteTypeEvent($FormItem['Type'], 'OnView',
    172           array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex)).'</td>';
     184            'Type' => $FormItem['Type']));
     185        } else $Value = $this->System->Type->ExecuteTypeEvent($FormItem['Type'], 'OnView',
     186          array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex));
     187        if($Value == '') $Value = '&nbsp;';
     188        $Output .= '<td>'.$Value.'</td>';
    173189      }
    174       $Output .= '<td><a href="?a=view&amp;id='.$Row['Id'].'"><img alt="Ukázat" title="Ukázat" src="'.
     190      $Output .= '<td><a href="?a=view&amp;t='.$Table.'&amp;id='.$Row['Id'].'"><img alt="Ukázat" title="Ukázat" src="'.
    175191        $this->System->Link('/images/view.png').'"/></a>'.
    176         '<a href="?a=edit&amp;id='.$Row['Id'].'"><img alt="Upravit" title="Upravit" src="'.
     192        '<a href="?a=edit&amp;t='.$Table.'&amp;id='.$Row['Id'].'"><img alt="Upravit" title="Upravit" src="'.
    177193        $this->System->Link('/images/edit.png').'"/></a>'.
    178         '<a href="?a=delete&amp;id='.$Row['Id'].'"><img alt="Smazat" title="Smazat" src="'.
     194        '<a href="?a=delete&amp;t='.$Table.'&amp;id='.$Row['Id'].'"><img alt="Smazat" title="Smazat" src="'.
    179195        $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a></td>';
    180196      $Output .= '</tr>';
Note: See TracChangeset for help on using the changeset viewer.