source: trunk/Modules/Admin/Admin.php

Last change on this file was 95, checked in by chronos, 2 years ago
  • Modified: Updated Common package.
  • Added: Explicit types for better type checking.
  • Fixed: Support for php 8.0.
File size: 2.4 KB
Line 
1<?php
2
3class ModuleAdmin extends Module
4{
5 function __construct($System)
6 {
7 parent::__construct($System);
8 $this->Name = 'Admin';
9 $this->Version = '1.0';
10 $this->Creator = 'Chronos';
11 $this->License = 'GNU/GPL';
12 $this->Description = 'Admin interface';
13 $this->Dependencies = array();
14 }
15
16 function DoStart(): void
17 {
18 $this->System->RegisterPage(['admin'], 'PageAdmin');
19 }
20}
21
22class PageAdmin extends Page
23{
24 function __construct(System $System)
25 {
26 parent::__construct($System);
27 }
28
29 function Show(): string
30 {
31 if (array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
32 switch ($Operation)
33 {
34 case 'Add':
35 $Output = $this->ShowAdd();
36 break;
37 case 'Delete':
38 $Output = $this->ShowDelete();
39 break;
40 case 'Edit':
41 $Output = $this->ShowEdit();
42 break;
43 case 'RebuildCache':
44 $Output = $this->ShowRebuildCache();
45 break;
46 default:
47 $Output = $this->ShowNone();
48 }
49 return $Output;
50 }
51
52 function ShowNone(): string
53 {
54 $Table = array(
55 'Header' => array('Název veličiny', 'Operace'),
56 'Rows' => array(),
57 );
58
59 $Result = $this->Database->select('Measure', '*', '1 ORDER BY Description');
60 while ($Measure = $Result->fetch_array())
61 {
62 array_push($Table['Rows'], array($Measure['Description'], MakeLink('?Operation=Edit&amp;MeasureId='.$Measure['Id'], 'Editovat').' '.MakeLink('?Operation=Delete&amp;MeasureId='.$Measure['Id'], 'Odstranit').' '.MakeLink('?Operation=RebuildCache&amp;MeasureId='.$Measure['Id'], 'Přestavět cache')));
63 }
64 $Output = '<h3>Seznam měření</h3>'.Table($Table).MakeLink('?Operation=Add', 'Přidat');
65 return $Output;
66 }
67
68 function ShowEdit(): string
69 {
70 $DbResult = $this->Database->select('Measure', '*', 'Id='.addslashes($_GET['MeasureId']));
71 $Values = array();
72 $Values = $DbResult->fetch_array();
73 return ShowEditTable('Measure', $Values);
74 }
75
76 function ShowAdd(): string
77 {
78 $Values = array();
79 return ShowEditTable('Measure', $Values);
80 }
81
82 function ShowDelete(): string
83 {
84 return '';
85 }
86
87 function ShowRebuildCache(): string
88 {
89 echo("Vytvařím novou cache...<br>");
90 $DbResult = $this->Database->select('Measure', '*', 'Id='.addslashes($_GET['MeasureId']));
91 $Measure = $DbResult->fetch_array();
92
93 $Measure->RebuildMeasureCache();
94 echo('Dokončeno<br>');
95 return '';
96 }
97}
Note: See TracBrowser for help on using the repository browser.