Changeset 434 for trunk/is/index.php


Ignore:
Timestamp:
Oct 12, 2012, 9:03:30 AM (12 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.