source: trunk/Common/Types/OneToMany.php@ 448

Last change on this file since 448 was 448, checked in by chronos, 12 years ago
  • Opraveno: NULL hodnoty ve formulářích.
File size: 1.9 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Base.php');
4
5class TypeOneToMany extends TypeBase
6{
7 function OnView($Item)
8 {
9 $Type = $this->System->Type->TypeDefinitionList[$Item['Type']];
10 if($Item['Value'] != '')
11 {
12 $DbResult = $this->System->Database->query('SELECT '.$Type['Parameters']['Name'].
13 ' AS `Name` FROM `'.$Type['Parameters']['Table'].'` WHERE `'.
14 $Type['Parameters']['Id'].'`='.$Item['Value']);
15 $DbRow = $DbResult->fetch_assoc();
16 $Output = '<a href="?t='.$Type['Parameters']['Table'].'&amp;a='.
17 'view'.'&amp;id='.$Item['Value'].'">'.$DbRow['Name'].'</a>';
18 } else $Output = '';
19 return($Output);
20 }
21
22 function OnEdit($Item)
23 {
24 $Output = '<select name="'.$Item['Name'].'">';
25 $Type = $this->System->Type->TypeDefinitionList[$Item['Type']];
26 if(array_key_exists('Condition', $Type['Parameters'])) $Where = ' WHERE '.$Type['Parameters']['Condition'];
27 else $Where = '';
28 if(array_key_exists('Null', $Item) and $Item['Null'])
29 {
30 if($Item['Value'] == NULL) $Selected = ' selected="1"'; else $Selected = '';
31 $Output .= '<option value=""'.$Selected.'></option>';
32 }
33 $DbResult = $this->System->Database->query('SELECT '.$Type['Parameters']['Name'].' AS `Name`,'.$Type['Parameters']['Id'].' AS `Id` FROM `'.$Type['Parameters']['Table'].'`'.$Where.' ORDER BY `Name`');
34 while($DbRow = $DbResult->fetch_assoc())
35 {
36 if($Item['Value'] == $DbRow['Id']) $Selected = ' selected="1"'; else $Selected = '';
37 $Output .= '<option value="'.$DbRow['Id'].'"'.$Selected.'>'.$DbRow['Id'].': '.$DbRow['Name'].'</option>';
38 }
39 $Output .= '</select>';
40 return($Output);
41 }
42
43 function OnLoad($Item)
44 {
45 if($_POST[$Item['Name']] == '') return(NULL);
46 else return($_POST[$Item['Name']]);
47 }
48
49 function OnLoadDb($Item)
50 {
51 if($Item['Value'] == '') return(NULL);
52 else return($Item['Value']);
53 }
54}
55
56?>
Note: See TracBrowser for help on using the repository browser.