source: trunk/Packages/FormManager/Types/OneToMany.php

Last change on this file was 8, checked in by chronos, 19 months ago
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
File size: 3.5 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Base.php');
4
5class TypeOneToMany extends TypeBase
6{
7 public array $EditActions;
8
9 function OnView(array $Item): ?string
10 {
11 $Type = $this->FormManager->Type->TypeDefinitionList[$Item['Type']];
12 if ($Item['Value'] != '')
13 {
14 $Output = '<a href="?t='.$Type['Parameters']['Table'].'&amp;a='.
15 'view'.'&amp;i='.$Item['Value'].'">'.$Item['Filter'].'</a>';
16 } else $Output = '';
17 return $Output;
18 }
19
20 function OnEdit(array $Item): string
21 {
22 $Output = '<select name="'.$Item['Name'].'" id="'.$Item['Name'].'">';
23 $Type = $this->FormManager->Type->TypeDefinitionList[$Item['Type']];
24 if (array_key_exists('Condition', $Type['Parameters'])) $Where = ' WHERE '.$Type['Parameters']['Condition'];
25 else $Where = '';
26 if (array_key_exists('Null', $Item) and $Item['Null'])
27 {
28 if ($Item['Value'] == NULL) $Selected = ' selected="1"'; else $Selected = '';
29 $Output .= '<option value=""'.$Selected.'></option>';
30 }
31 if (array_key_exists('View', $Type['Parameters'])) $Table = $Type['Parameters']['View'];
32 else $Table = $Type['Parameters']['Table'];
33 $DbResult = $this->Database->query('SELECT '.$Type['Parameters']['Name'].' AS `Name`,'.$Type['Parameters']['Id'].' AS `Id` FROM '.$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['Name'].'</option>';
38 }
39 $Output .= '</select>';
40 if ($this->FormManager->ShowRelation)
41 {
42 $URL = '';
43 if (array_key_exists('OnPreset', $Item))
44 {
45 $Preset = call_user_func($Item['OnPreset'], $Item['Values']);
46 $URL = str_replace('&', '&amp;', '&'.http_build_query($Preset));
47 }
48 $Output .= '<img src="'.$this->FormManager->Root.'/images/add.png" alf="Přidat" language="javascript" '.
49 'onclick="return popupwindow(&quot;'.$this->FormManager->Root.'/is/?a=addsub&amp;t='.$Table.'&amp;r='.$Item['Name'].'&amp;rt='.$Item['Type'].$URL.'&quot;,&quot;test&quot;);" style="cursor:hand;cursor:pointer"/>';
50 $Output .= '<img src="'.$this->FormManager->Root.'/images/select.png" alf="Vybrat" language="javascript" '.
51 'onclick="return popupwindow(&quot;'.$this->FormManager->Root.'/is/?a=select&amp;t='.$Table.'&amp;r='.$Item['Name'].'&quot;,&quot;test&quot;);" style="cursor:hand;cursor:pointer"/>';
52 }
53 return $Output;
54 }
55
56 function OnLoad(array $Item): ?string
57 {
58 if ($_POST[$Item['Name']] == '') return NULL;
59 else return $_POST[$Item['Name']];
60 }
61
62 function OnLoadDb(array $Item): ?string
63 {
64 if ($Item['Value'] == '') return NULL;
65 else return $Item['Value'];
66 }
67
68 function OnFilterName(array $Item): string
69 {
70 return '`'.$Item['Name'].'_Filter`';
71 }
72
73 function OnFilterNameQuery(array $Item): string
74 {
75 $Type = $this->FormManager->Type->TypeDefinitionList[$Item['Type']];
76 //if ($Item['Value'] != '')
77 //{
78 if (array_key_exists('View', $Type['Parameters'])) $Table = $Type['Parameters']['View'];
79 else $Table = $Type['Parameters']['Table'];
80 $Output = '`'.$Item['Name'].'`, (SELECT '.$Type['Parameters']['Name'].''.
81 ' AS `Name` FROM '.$Table.' WHERE `'.
82 $Type['Parameters']['Id'].'`=`TX`.`'.$Item['Name'].'`) AS `'.$Item['Name'].'_Filter`';
83 //} else $Output = '`'.$Item['Name'].'`, `'.$Item['Name'].'` AS `'.$Item['Name'].'_Filter`';
84 return $Output;
85 }
86}
Note: See TracBrowser for help on using the repository browser.