source: branches/php/Base/HTML/Controller.php@ 112

Last change on this file since 112 was 112, checked in by chronos, 11 years ago
  • Odstraněno: Ukončovací PHP značka ze všech souborů.
File size: 4.1 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../System.php');
4
5class Controller extends Object
6{
7 var $DefaultAction;
8 var $Name;
9 var $ActionMap = array();
10 var $FilterColumn = '';
11 var $FilterId = 0;
12
13 function __construct($System)
14 {
15 parent::__construct($System);
16 $this->ActionMap = array(
17 'View' => 'View',
18 'Delete' => 'Delete',
19 'Edit' => 'Edit',
20 'Add' => 'Add',
21 'List' => 'ItemList',
22 'ListPanel' => 'ListPanel',
23 );
24 }
25
26 function Edit()
27 {
28 $Output = '';
29 if(array_key_exists('Mode', $_GET)) $Mode = $_GET['Mode'];
30 else $Mode = '';
31 if($Mode == 'Store')
32 {
33 $this->System->Navigation->UnsetParameter('Mode');
34 $ClassName = $this->Name.'EditWebObject';
35 $Item = new $ClassName($this->System);
36 $Item->Save();
37 $Output .= $this->View();
38 } else
39 {
40 $ClassName = $this->Name.'EditWebObject';
41 $Item = new $ClassName($this->System);
42 $Item->LoadFromDatabase($_GET['Id']);
43 $Output .= $this->System->HTML->Panel($this->System->Localization->Translate($this->Name.'Edit'),
44 $Item->Show());
45 }
46 return($Output);
47 }
48
49 function Add()
50 {
51 $Output = '';
52 if(array_key_exists('Mode', $_GET)) $Mode = $_GET['Mode'];
53 else $Mode = '';
54 if($Mode == 'Store')
55 {
56 $this->System->Navigation->UnsetParameter('Mode');
57 $ClassName = $this->Name.'AddWebObject';
58 $Item = new $ClassName($this->System);
59 $_GET['Id'] = $Item->Add();
60 $Output .= $this->View();
61 } else
62 {
63 $ClassName = $this->Name.'AddWebObject';
64 $Item = new $ClassName($this->System);
65 $Output .= $this->System->HTML->Panel($this->System->Localization->Translate($this->Name.'Add'),
66 $Item->Show());
67 }
68 return($Output);
69 }
70
71 function View()
72 {
73 $Output = '';
74 $ClassName = $this->Name.'ViewWebObject';
75 $Item = new $ClassName($this->System);
76 try {
77 $Item->LoadFromDatabase($_GET['Id']);
78 $Output .= $this->System->HTML->Panel($this->System->Localization->Translate($this->Name.'View'),
79 $Item->Show());
80 } catch (ExceptionNotFound $E)
81 {
82 $Output .= $this->System->Output->SystemMessage($this->System->Localization->Translate('ItemNotFound'));
83 }
84 return($Output);
85 }
86
87 function ItemList()
88 {
89 $Output = $this->System->HTML->Panel($this->System->Localization->Translate($this->Name.'List'),
90 $this->ListPanel(), '<a href="'.$this->System->Navigation->MakeLink($this->Name, 'List', array('Mode' => '')).'">'.$this->System->Localization->Translate('View').'</a>'.
91 ' <a href="'.$this->System->Navigation->MakeLink($this->Name, 'List', array('Mode' => 'Manage')).'">'.$this->System->Localization->Translate('Manage').'</a>'.
92 ' <a href="'.$this->System->Navigation->MakeLink($this->Name, 'Add').'">'.$this->System->Localization->Translate('Add').'</a>',
93 $this->Name);
94 return($Output);
95 }
96
97 function ListPanel()
98 {
99 if(array_key_exists('FilterColumn', $_GET) and array_key_exists('Panel', $_GET))
100 {
101 $this->FilterColumn = $_GET['FilterColumn'];
102 }
103 if(array_key_exists('Id', $_GET))
104 $this->FilterId = $_GET['Id'];
105 if(array_key_exists('Mode', $_GET)) $Mode = $_GET['Mode'];
106 else $Mode = '';
107 $ClassName = $this->Name.'ListWebObject';
108 $List = new $ClassName($this->System, $this->FilterColumn, $this->FilterId, $Mode);
109 $List->Module = $this->Name;
110 $List->LoadFromDatabase();
111 $Output = $List->Show();
112 return($Output);
113 }
114
115 function Delete()
116 {
117 $Output = '';
118 $this->System->Database->delete($this->Name, 'Id='.$_GET['Id']);
119 $Output .= $this->System->Output->SystemMessage($this->System->Localization->Translate('ItemDeleted'));
120 $Output .= $this->ItemList();
121 return($Output);
122 }
123
124 function Show()
125 {
126 if(!array_key_exists('A', $_GET)) $_GET['A'] = $this->DefaultAction;
127 $Action = $_GET['A'];
128
129 foreach($this->ActionMap as $ActionIndex => $ActionMethod)
130 {
131 if($Action == $ActionIndex)
132 {
133 $Output = $this->$ActionMethod();
134 break;
135 }
136 }
137 if(!isset($Output)) $Output = 'Action '.$_GET['A'].' not found';
138 return($Output);
139 }
140}
Note: See TracBrowser for help on using the repository browser.