Ignore:
Timestamp:
Jun 12, 2009, 8:56:03 PM (15 years ago)
Author:
george
Message:
  • Opraveno: Obnovena funkčnost formulářové položky typu PointerOneToOne a možnost volby databáze serveru.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/types/PointerOneToOne.php

    r11 r22  
    33class TypePointerOneToOne extends TypeBase
    44{
    5   function GetTablePointerName($Type, $Item)
    6   {
    7     global $Database;
    8 
    9     //print_r($Item);
    10     $Columns = '';
    11     $List = GetListDefinition($Type['Parameters'][0]);
    12     $TargetTable = $List['TableName'];
    13     //echo($TargetTable.'<');
    14     //print_r($List);
    15     foreach($List['Items'] as $Index => $ListItem)
    16     {
    17       //echo('ListItem');
    18       //print_r($ListItem);
    19       $Type = GetTypeDefinition($ListItem['Type']);
    20       if($ListItem['VisibleInPointer'] == 1)
    21       {
    22         if($Type['ParentType'] == TypePointerOneToOneId)
    23         {
    24           //print_r($Type);
    25           $DbResult = $Database->select(array('Database' => $List['Database'], 'Table' => $List['TableName'], 'Condition' => $List['IdName'].'='.$Item['Value']));
    26           $DbRow = $DbResult->fetch_assoc();
    27           $DefinitionItem = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'], 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
    28           $SubTarget = $this->GetTablePointerName($Type, $DefinitionItem);
    29           $Columns .= '"'.$SubTarget['Name'].' ",';
    30         } else $Columns .= '`'.$ListItem['Name'].'`," ",';
    31       }
    32     }
    33     $Columns = substr($Columns, 0, -1);
    34     if($Columns == '') $Columns = '`'.$List['IdName'].'` AS `Name`, `'.$List['IdName'].'`';
    35       else $Columns = 'CONCAT('.$Columns.') AS `Name`, `'.$List['IdName'].'`';
    36     $DbResult = $Database->select(array('Database' => $List['Database'], 'Table' => $TargetTable, 'Columns' => $Columns, 'Condition' => $List['IdName'].'='.$Item['Value']));
    37     //echo($Database->LastQuery);
    38     if($DbResult->num_rows > 0)
    39     {
    40       return($DbResult->fetch_assoc());
    41     } else return('');
    42   }
    43 
    44   function GetTablePointerNameList($Type, $Item)
    45   {
    46     global $Database;
    47 
    48     $Columns = '';
    49     $List = GetListDefinition($Type['Parameters'][0]);
    50     $TargetTable = $List['TableName'];
    51     foreach($List['Items'] as $ListItem)
    52       if($ListItem['VisibleInPointer'] == 1) $Columns .= '`'.$ListItem['Name'].'`," ",';
    53     $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, `'.$List['IdName'].'`';
    54     $DbResult = $Database->select(array('Database' => $List['Database'], 'Table' => $TargetTable, 'Columns' => $Columns));
    55     //echo($Database->LastQuery);
    56     if($DbResult->num_rows > 0)
    57     {
    58 
    59       $Result = array(array('Name' => 'Žádný', 'Id' => 0));
    60       while($DbRow = $DbResult->fetch_assoc())
    61         $Result[] = $DbRow;
    62       return($Result);
    63     } else return(array());
    64   }
    65 
    665  function OnView($Item)
    676  {
    68     global $Database;
     7    global $Database, $TypeDefinitionList;
    698
    70     $Type = GetTypeDefinition($Item['Type']);
     9    $Type = $TypeDefinitionList[$Item['Type']];
     10    $DbResult = $Database->query('SELECT '.$Type['Parameters']['Name'].' AS Name FROM `'.$Type['Parameters']['Table'].'` WHERE `'.$Type['Parameters']['Id'].'`='.$Item['Value']);
     11    $DbRow = $DbResult->fetch_assoc();
     12    $Output = $DbRow['Name'];
     13   
     14/*    $Type = GetTypeDefinition($Item['Type']);
    7115    $List = GetListDefinition($Type['Parameters'][0]);
    7216    $TargetTable = $Type['Parameters'][0];
     
    7418    if($TargetName != '') $Output = '<a href="?Action=ViewItem&amp;Table='.$TargetTable.'&amp;Item='.$TargetName[$List['IdName']].'">'.$TargetName['Name'].'</a>';
    7519    else $Output = '';
     20    */
    7621    return($Output);
    7722  }
     
    7924  function OnEdit($Item)
    8025  {
    81     global $Database, $Types;
     26    global $Database, $TypeDefinitionList;
    8227
    83     $Type = $Types[$Item['Type']];
    84     $List = GetListDefinition($Type['Parameters'][0]);
    8528    $Output = '<select name="'.$Item['Name'].'">';
    86     $TargetNameList = $this->GetTablePointerNameList($Type, $Item);
    87     //echo($Database->LastQuery);
    88     foreach($TargetNameList as $TargetName)
     29    $Type = $TypeDefinitionList[$Item['Type']];
     30    $DbResult = $Database->query('SELECT '.$Type['Parameters']['Name'].' AS Name,'.$Type['Parameters']['Id'].' AS Id FROM `'.$Type['Parameters']['Table'].'`');
     31    while($DbRow = $DbResult->fetch_assoc())
    8932    {
    90       if($Item['Value'] == $TargetName[$List['IdName']]) $Selected = ' selected="1"'; else $Selected = '';
    91       $Output .= '<option value="'.$TargetName[$List['IdName']].'"'.$Selected.'>'.$TargetName['Name'].'</option>';
     33      if($Item['Value'] == $DbRow['Id']) $Selected = ' selected="1"'; else $Selected = '';
     34      $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Name'].'</option>';
    9235    }
    9336    $Output .= '</select>';
Note: See TracChangeset for help on using the changeset viewer.