Changeset 8 for base.php


Ignore:
Timestamp:
Sep 29, 2008, 2:35:42 PM (16 years ago)
Author:
george
Message:
  • Přidáno: Částečná podpora pro přihlašování uživatelů.
  • Přepracováno: Funkce pro generování formulářů podle dynamické definice namísto přímého generování podle databáze. Všechny formuláře nemají odpovídající strukturu v databázi.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r6 r8  
    11<?php
    2 include('database.php');
    3 include('common.php');
    42
    53// Include type definitions
     
    1513include('types/Hyperlink.php');
    1614
    17 function ShowList($List, $Column = '', $ColumnValue = 0)
     15function ShowList($List, $Column = '', $ColumnValue = 0, $Title = '')
    1816{
    1917  global $Database, $Types, $Config;
    2018
    21   $Output = '<div>'.$List['Title'].'</div><table class="WideTable"><tr>';
     19  if($Title == '') $Output = '<div>'.$List['Title'].'</div>';
     20    else $Output = '<div>'.$Title.'</div>';
     21  $Output .= '<table class="WideTable"><tr>';
    2222  foreach($List['Items'] as $Item)
    2323  {
     
    5252  {
    5353    $OrderDirection = array('ASC', 'DESC');
    54     $Where .= ' ORDER BY `'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];
    55   }
     54    $Order = 'ORDER BY `'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];
     55  } else $Order = '';
    5656
    5757  if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
     58  //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))';
     59  $Where .= ' '.$Order;
    5860  $DbResult = $Database->select($List['TableName'], 'COUNT(*)', $Where);
    5961  //echo($Database->LastQuery);
     
    7173        $ItemType = explode(':', $Item['Type']);
    7274        $Type = $Types[$ItemType[0]];
    73         if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
    74         if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $DbRow[$Index], $List['TableName'], $DbRow['Id']);
     75        $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     76        if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $ItemDefinition);
    7577        else $Value = $Type['CallbackView'];
    76         $Value = str_replace('%value%', $DbRow[$Index], $Value);
    7778        $Output .= '<td>'.$Value.'</td>';
    7879      }
     
    101102      {
    102103        $Type = $Types[$ItemType[0]];
    103         if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
    104         if(is_callable($Type['CallbackEdit'])) $Value = $Type['CallbackEdit']($Type, $DbRow[$Index], $List['TableName'], $DbRow['Id']);
     104        $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     105        if(is_callable($Type['CallbackEdit'])) $Value = $Type['CallbackEdit']($Type, $ItemDefinition);
    105106        else $Value = $Type['CallbackEdit'];
    106         $Value = str_replace('%value%', $DbRow[$Index], $Value);
    107         $Value = str_replace('%name%', $Index, $Value);
    108         if($Item['Required'] == 1) $Required = ' *'; else $Required = '';
     107        if($Item['Required'] == 1) $Required = '*'; else $Required = '';
    109108        $Output .= '<tr><td>'.$Item['TextBefore'].':'.$Required.'</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>';
    110109      }
     
    147146  global $Database, $Types;
    148147
    149   $Output = '<form action="?Action=AddItemFinish" method="post"><table class="WideTable">';
    150   $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>';
     148  $DefinitionItems = array();
    151149  $AfterTableOutput = '';
    152150  foreach($List['Items'] as $Index => $Item)
     
    155153    if(($ItemType[0] != 'PointerOneToMany') and ($Item['Name'] != $Column))
    156154    {
    157       $Type = $Types[$ItemType[0]];
    158       if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
    159       if(is_callable($Type['CallbackEdit'])) $Value = $Type['CallbackEdit']($Type, $Type['InitValue'], $List['TableName'], 0);
    160       else $Value = $Type['CallbackEdit'];
    161       $Value = str_replace('%value%', $Type['InitValue'], $Value);
    162       $Value = str_replace('%name%', $Index, $Value);
    163       if($Item['Required'] == 1) $Required = ' *'; else $Required = '';
    164       $Output .= '<tr><td>'.$Item['TextBefore'].':'.$Required.'</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>';
     155      if($Item['Required'] == 1) $Required = '*'; else $Required = '';
     156      $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['TableName'], 'SourceItemId' => 0);
    165157    } else
    166158    if($Item['Name'] == $Column)
    167159    {
    168       $AfterTableOutput = '<input type="hidden" name="'.$Column.'" value="'.$ColumnValue.'" />';
    169     }
    170   }
    171   $Output .= '</table>'.$AfterTableOutput.'<input type="submit" value="Přidat"></form>';
     160      $DefinitionItems[] = array('Name' => $Column, 'Type' => 'String', 'Caption' => '', 'Value' => $ColumnValue);
     161    }
     162  }
     163  $Form = new Form();
     164  $Form->Definition = array
     165  (
     166    'Title' => 'Titulek',
     167    'SubmitBuffonText' => 'Přidat',
     168    'Items' => $DefinitionItems,
     169  );
     170  $Form->OnSubmit = '?Action=AddItemFinish';
     171  $Output .= $Form->ShowEditForm().$AfterTableOutput;
    172172  if(($Column != '') and ($ColumnValue != 0))
    173173  {
     
    216216      {
    217217        $Type = $Types[$ItemType[0]];
    218         if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
    219         if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $DbRow[$Index], $List['TableName'], $DbRow['Id']);
     218        $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     219        if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $ItemDefinition);
    220220        else $Value = $Type['CallbackView'];
    221         $Value = str_replace('%value%', $DbRow[$Index], $Value);
    222221        $Output .= '<tr><td>'.$Item['TextBefore'].':</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>';
    223222      }
     
    241240      {
    242241        $SubList = $Lists[$ItemType[1]];
    243         $Output .= ShowList($SubList, $ItemType[2], $DbRow['Id']).'<br /><br />';
     242        $Output .= ShowList($SubList, $ItemType[2], $DbRow['Id'], $Item['TextBefore']).'<br /><br />';
    244243      }
    245244    }
Note: See TracChangeset for help on using the changeset viewer.