Changeset 11 for base.php


Ignore:
Timestamp:
Oct 13, 2008, 8:05:21 AM (16 years ago)
Author:
george
Message:
  • Opraveno: Mazání položek nyní položku neodstraňuje z databáze, ale pouze ji označí za smazanou. Sloupce DeletionTime se nastaví na aktuální čas a položka nadále nebude zobrazována ve výpisech.
  • Opraveno: Načítání položek formuláře nyní prováděno přes událost OnLoad pro každý typ samostatně. Tímto také opraveno načítání hodnoty typu Boolean(checkbox) a Date(comboboxy datumu).
  • Opraveno: Správné zpracování typů nejenom podle id, ale také podle jména.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r10 r11  
    3232  $Output .= '<th>Akce</th></tr>';
    3333
    34   $Where = '';
     34  $Where = ' AND (t1.DeletionTime IS NULL)';
    3535
    3636  if(($Column != '') and ($ColumnValue != 0))
     
    6969  $TotalItemCount = $DbRow[0];
    7070
    71   $DbResult = $Database->query('SELECT t1.* FROM `'.$List['TableName'].'` AS t1 LEFT JOIN `'.$List['TableName'].'` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE t2.ItemId IS NULL'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
     71  $DbResult = $Database->query('SELECT t1.* FROM `'.$List['TableName'].'` AS t1 LEFT JOIN `'.$List['TableName'].'` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL)'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
    7272  //echo($Database->LastQuery.'<br>');
    7373  while($DbRow = $DbResult->fetch_array())
     
    199199  global $Database, $Types, $System;
    200200
    201   $Values = array();
    202   foreach($List['Items'] as $Index => $Item)
    203   {
    204     if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
    205     {
    206       $Values[$Index] = $_POST[$Index];
    207     }
    208   }
     201  $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
     202  while($DbRow = $DbResult->fetch_array())
     203  {
     204    $DefinitionItems = array();
     205    foreach($List['Items'] as $Index => $Item)
     206    {
     207      if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
     208      {
     209        $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     210      }
     211    }
     212  }
     213  $Form = new Form();
     214  $Form->Definition = array
     215  (
     216    'Title' => 'Titulek',
     217    'SubmitBuffonText' => 'Uložit',
     218    'Items' => $DefinitionItems,
     219  );
     220  $Form->LoadValuesFromForm();
     221
    209222  $DbResult = $Database->select($List['TableName'], 'ItemId', 'Id='.$Id);
    210223  $DbRow = $DbResult->fetch_assoc();
    211   $Values['ItemId'] = $DbRow['ItemId'];
    212   $Values['Author'] = $System->Modules['User']->User['Id'];
    213   $Values['CreationTime'] = 'NOW()';
    214   $Values['ValidTimeFrom'] = 'NOW()';
    215   $Database->insert($List['TableName'], $Values);
     224  $Form->Values['ItemId'] = $DbRow['ItemId'];
     225  $Form->Values['Author'] = $System->Modules['User']->User['Id'];
     226  $Form->Values['CreationTime'] = 'NOW()';
     227  $Form->Values['ValidTimeFrom'] = 'NOW()';
     228  $Database->insert($List['TableName'], $Form->Values);
    216229  //echo($Database->LastQuery);
    217230  $Output = 'Změny uloženy.';
    218   $Output .= ShowViewItem($List, $Id);
     231  $Output .= ShowViewItem($List, $Database->insert_id);
     232  $Form->Values['Column'] = $_POST['Column'];
     233  ExecuteListEvent($List['TableName'], 'OnEdit', $Form->Values);
    219234  return($Output);
    220235}
     
    264279  global $Database, $Types, $System;
    265280
    266   $Values = array();
    267   foreach($List['Items'] as $Index => $Item)
    268   {
    269     if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
    270     {
    271       $Values[$Index] = $_POST[$Index];
    272     }
    273   }
    274   $Values['Author'] = $System->Modules['User']->User['Id'];
    275   $Values['CreationTime'] = 'NOW()';
    276   $Values['ValidTimeFrom'] = 'NOW()';
     281  $DefinitionItems = array();
     282  $AfterTableOutput = '';
     283  foreach($List['Items'] as $Item)
     284  {
     285    //echo($Item['Name'].',');
     286    if(($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
     287    {
     288      if($Item['Required'] == 1) $Required = '*'; else $Required = '';
     289      $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['TableName'], 'SourceItemId' => 0);
     290    } else
     291    if($Item['Name'] == $Column)
     292    {
     293      $DefinitionItems[] = array('Name' => $Column, 'Type' => 'Hidden', 'Caption' => '', 'Value' => $ColumnValue);
     294    }
     295  }
     296  $DefinitionItems[] = array('Name' => 'Column', 'Type' => 'Hidden', 'Caption' => '', 'Value' => $Column);
     297
     298  $Form = new Form();
     299  $Form->Definition = array
     300  (
     301    'Title' => 'Titulek',
     302    'SubmitBuffonText' => 'Přidat',
     303    'Items' => $DefinitionItems,
     304  );
     305  $Form->LoadValuesFromForm();
     306  $Form->Values['Author'] = $System->Modules['User']->User['Id'];
     307  $Form->Values['CreationTime'] = 'NOW()';
     308  $Form->Values['ValidTimeFrom'] = 'NOW()';
    277309  $DbResult = $Database->select($List['TableName'], 'MAX(ItemId)');
    278310  $DbRow = $DbResult->fetch_row();
    279311  $AutoincrementId = $DbRow[0];
    280   $Values['ItemId'] = $AutoincrementId + 1;
    281   $Database->insert($List['TableName'], $Values);
     312  $Form->Values['ItemId'] = $AutoincrementId + 1;
     313  $Database->insert($List['TableName'], $Form->Values);
    282314  //echo($Database->LastQuery);
    283315  $Output = 'Položka přidána';
    284316  $Output .= ShowViewItem($List, $Database->insert_id);
    285   $Values['Column'] = $_POST['Column'];
    286   ExecuteListEvent($List['TableName'], 'OnAdd', $Values);
     317  $Form->Values['Column'] = $_POST['Column'];
     318  ExecuteListEvent($List['TableName'], 'OnAdd', $Form->Values);
    287319  return($Output);
    288320}
     
    336368function ShowDeleteItem($List, $Id)
    337369{
    338   global $Database;
    339 
    340   $Database->delete($List['TableName'], 'Id='.$Id);
     370  global $Database, $Lists;
     371
     372  $Database->update($List['TableName'], 'Id='.$Id, array('DeletionTime' => 'NOW()'));
    341373  $Output = 'Položka smazána.';
     374  $Output .= ShowList($Lists[$_SESSION['Table']], $Lists[$_SESSION['Column']], $Lists[$_SESSION['ColumnValue']]).'<br /><br />';
    342375  return($Output);
    343376}
     
    431464function LoadTypeDefinition()
    432465{
    433   global $Database, $Types;
     466  global $Database, $Types, $TypeNames;
    434467
    435468  $Types = array();
     469  $TypeNames = array();
    436470  $DbResult = $Database->select('SystemType', '*');
    437471  while($DbRow = $DbResult->fetch_assoc())
     
    440474    $DbRow['BaseType'] = $DbRow['Name'];
    441475    $Types[$DbRow['Id']] = $DbRow;
     476    $TypeNames[$DbRow['Name']] = $DbRow['Id'];
    442477  }
    443478
     
    474509}
    475510
     511function ModifyAllTables($Query)
     512{
     513  global $Database;
     514
     515  $DbResult = $Database->select('SystemList', '*');
     516  while($DbRow = $DbResult->fetch_assoc())
     517  {
     518    $Database->query($Query);
     519  }
     520}
     521
    476522?>
Note: See TracChangeset for help on using the changeset viewer.