Changeset 887 for trunk/Modules/IS/IS.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/IS/IS.php
r873 r887 5 5 class PageIS extends Page 6 6 { 7 var $FullTitle = 'Správa dat'; 8 var $ShortTitle = 'Správa dat'; 9 var $ParentClass = 'PagePortal'; 10 var $MenuItems; 11 var $HideMenu; 12 var $ShowActionName; 7 public array $MenuItems; 8 public bool $HideMenu; 9 public bool $ShowActionName; 13 10 14 11 function __construct($System) 15 12 { 16 13 parent::__construct($System); 14 $this->FullTitle = 'Správa dat'; 15 $this->ShortTitle = 'Správa dat'; 16 $this->ParentClass = 'PagePortal'; 17 17 18 $this->MenuItems = array(); 18 19 $this->HideMenu = false; … … 20 21 } 21 22 22 function Show() 23 { 24 if (! $this->System->User->CheckPermission('IS', 'Manage'))23 function Show(): string 24 { 25 if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('IS', 'Manage')) 25 26 return 'Nemáte oprávnění'; 26 27 $this->System->FormManager->ShowRelation = true; … … 78 79 } 79 80 80 function Dashboard() 81 function Dashboard(): string 81 82 { 82 83 $Output = '<strong>Nástěnka:</strong><br/>'; 83 foreach ( $this->System->ModuleManager->Modules['IS']->DashboardItems as $Item)84 foreach (ModuleIS::Cast($this->System->GetModule('IS'))->DashboardItems as $Item) 84 85 { 85 86 if (is_string($Item['Callback'][0])) … … 93 94 } 94 95 95 function ShowFavoriteAdd( $Table, $ItemId)96 { 97 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.$this-> System->User->User['Id'].')');96 function ShowFavoriteAdd(string $Table, string $ItemId): string 97 { 98 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.$this->ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')'); 98 99 if ($DbResult->num_rows > 0) 99 100 { … … 101 102 } else 102 103 { 103 $this->Database->insert('MenuItemFavorite', array('MenuItem' => ($_GET['i'] * 1), 'User' => $this->System->User->User['Id']));104 $this->Database->insert('MenuItemFavorite', array('MenuItem' => ($_GET['i'] * 1), 'User' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'])); 104 105 $Output = $this->SystemMessage('Oblíbené', 'Přidáno do oblíbených'); 105 106 } … … 108 109 } 109 110 110 function ShowFavoriteDel( $Table, $ItemId)111 { 112 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='. $this->System->User->User['Id'].')');111 function ShowFavoriteDel(string $Table, string $ItemId): string 112 { 113 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')'); 113 114 if ($DbResult->num_rows > 0) 114 115 { … … 124 125 } 125 126 126 function LogChange( $Form, $Action, $NewId, $OldId)127 function LogChange(Form $Form, string $Action, string $NewId, string $OldId): void 127 128 { 128 129 $Values = $Form->Definition['Table'].' (Id: '.$OldId.' => '.$NewId.'):'."\n"; … … 152 153 } 153 154 } 154 $this->System->ModuleManager->Modules['Log']->NewRecord('IS', $Action, $Values);155 } 156 157 function ShowEdit( $Table, $Id)155 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('IS', $Action, $Values); 156 } 157 158 function ShowEdit(string $Table, string $Id): string 158 159 { 159 160 $Output = ''; 160 161 if (!array_key_exists($Table, $this->System->FormManager->Classes)) 161 162 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena'); 162 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))163 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write')) 163 164 return $this->SystemMessage('Oprávnění', 'Nemáte oprávnění'); 164 165 if (array_key_exists('o', $_GET)) … … 226 227 } 227 228 228 function ShowDelete( $Table, $Id)229 function ShowDelete(string $Table, string $Id): string 229 230 { 230 231 $Output = ''; … … 232 233 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena'); 233 234 $FormClass = $this->System->FormManager->Classes[$Table]; 234 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))235 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write')) 235 236 return 'Nemáte oprávnění'; 236 237 $DbResult = $this->Database->select($Table, '*', '`Id`='.$Id); … … 266 267 } 267 268 268 function ShowAdd( $Table, $Actions = array())269 function ShowAdd(string $Table, array $Actions = array()): string 269 270 { 270 271 $Output = ''; 271 272 if (!array_key_exists($Table, $this->System->FormManager->Classes)) 272 273 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena'); 273 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))274 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write')) 274 275 return 'Nemáte oprávnění'; 275 276 if (array_key_exists('o', $_GET)) … … 315 316 316 317 //$this->Database->update($Table, 'Id='.$Id, 317 // array('UserCreate' => $this->System->User->User['Id'],318 // array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'], 318 319 // 'TimeCreate' => 'NOW()')); 319 320 } catch (Exception $E) … … 357 358 } 358 359 359 function ShowAddSub( $Table, $Filter = '', $Title = '')360 { 361 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))360 function ShowAddSub(string $Table, string $Filter = '', string $Title = ''): string 361 { 362 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write')) 362 363 return 'Nemáte oprávnění'; 363 364 $this->BasicHTML = true; … … 367 368 } 368 369 369 function ShowTabs( $Tabs, $QueryParamName, $TabContent)370 function ShowTabs(array $Tabs, string $QueryParamName, string $TabContent): string 370 371 { 371 372 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); … … 388 389 } 389 390 390 function ShowView( $Table, $Id, $WithoutActions = false)391 function ShowView(string $Table, string $Id, bool $WithoutActions = false): string 391 392 { 392 393 if (!array_key_exists($Table, $this->System->FormManager->Classes)) 393 394 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena'); 394 395 $FormClass = $this->System->FormManager->Classes[$Table]; 395 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Read'))396 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read')) 396 397 return 'Nemáte oprávnění'; 397 398 … … 473 474 } 474 475 475 function ShowTable( $Table, $Filter = '', $Title = '', $RowActions = array(), $ExcludeColumn = '')476 function ShowTable(string $Table, string $Filter = '', string $Title = '', string $RowActions = '', string $ExcludeColumn = ''): string 476 477 { 477 478 if (!array_key_exists($Table, $this->System->FormManager->Classes)) … … 673 674 } 674 675 675 function ShowSelect( $Table, $Filter = '', $Title = '')676 { 677 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Read'))676 function ShowSelect(string $Table, string $Filter = '', string $Title = ''): string 677 { 678 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read')) 678 679 return 'Nemáte oprávnění'; 679 680 $this->BasicHTML = true; … … 686 687 } 687 688 688 function ShowMapSelect( $Table, $Filter = '', $Title = '')689 { 690 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))689 function ShowMapSelect(string $Table, string $Filter = '', string $Title = ''): string 690 { 691 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write')) 691 692 return 'Nemáte oprávnění'; 692 693 $Map = new MapOpenStreetMaps($this->System); … … 701 702 } 702 703 703 function ShowList( $Table, $Filter = '', $Title = '', $ExcludeColumn = '', $ExcludeValue = '')704 function ShowList(string $Table, string $Filter = '', string $Title = '', string $ExcludeColumn = '', string $ExcludeValue = ''): string 704 705 { 705 706 $Output = ''; 706 if (defined('NEW_PERMISSION') and ! $this->System->User->CheckPermission($this->TableToModule($Table), 'Read'))707 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read')) 707 708 return 'Nemáte oprávnění'; 708 709 if (!array_key_exists($Table, $this->System->FormManager->Classes)) … … 738 739 if (array_key_exists('mi', $_GET)) 739 740 { 740 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['mi'] * 1).') AND (`User`='. $this->System->User->User['Id'].')');741 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['mi'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')'); 741 742 if ($DbResult->num_rows > 0) 742 743 { … … 761 762 } 762 763 763 function ShowFavorites() 764 function ShowFavorites(): string 764 765 { 765 766 $this->MenuItems = array(); … … 768 769 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '. 769 770 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '. 770 'WHERE `MenuItemFavorite`.`User`='. $this->System->User->User['Id'].' '.771 'WHERE `MenuItemFavorite`.`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].' '. 771 772 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`'); 772 773 while ($DbRow = $DbResult->fetch_assoc()) … … 778 779 } 779 780 780 function ShowMenu() 781 function ShowMenu(): string 781 782 { 782 783 $this->MenuItems = array(); … … 794 795 } 795 796 796 function ShowMenuItem( $Parent, $All = false)797 function ShowMenuItem(string $Parent, bool $All = false): string 797 798 { 798 799 $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">'; … … 810 811 if ($MenuItem['IconName'] != '') $Image = '<img src="'.$this->System->Link('/images/favicons/'.$MenuItem['IconName']).'"/> '; 811 812 else $Image = '<img src="'.$this->System->Link('/images/favicons/'.$Icon).'"/> '; 812 //if ( $this->System->User->CheckPermission($this->TableToModule($Table), 'Write') or !defined('NEW_PERMISSION'))813 //if (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write') or !defined('NEW_PERMISSION')) 813 814 $Output .= '<li>'.$Image.$LinkTitle.'</li>'; 814 815 if ($All == false) $Output .= $this->ShowMenuItem($MenuItem['Id']); … … 819 820 } 820 821 821 function TableToModule( $Table)822 function TableToModule(string $Table): string 822 823 { 823 824 $DbResult = $this->Database->query('SELECT (SELECT `Name` FROM `Module` '. … … 830 831 } 831 832 832 function ShowAction( $Name, $Target, $Icon, $Confirm = '')833 function ShowAction(string $Name, string $Target, string $Icon, string $Confirm = ''): string 833 834 { 834 835 $Output = '<img alt="'.$Name.'" title="'.$Name.'" src="'. … … 846 847 var $DashboardItems; 847 848 848 function __construct( $System)849 function __construct(System $System) 849 850 { 850 851 parent::__construct($System); … … 855 856 $this->License = 'GNU/GPLv3'; 856 857 $this->Description = 'User interface for generic information system'; 857 $this->Dependencies = array( );858 $this->Dependencies = array('User'); 858 859 859 860 $this->DashboardItems = array(); 860 861 } 861 862 862 function DoInstall() 863 { 864 } 865 866 function DoUninstall() 867 { 868 } 869 870 function DoStart() 871 { 872 $this->System->RegisterPage( 'is', 'PageIS');863 function DoInstall(): void 864 { 865 } 866 867 function DoUninstall(): void 868 { 869 } 870 871 function DoStart(): void 872 { 873 $this->System->RegisterPage(['is'], 'PageIS'); 873 874 $this->System->FormManager->RegisterClass('MenuItem', array( 874 875 'Title' => 'Položky nabídky', … … 914 915 } 915 916 916 function DoStop() 917 { 918 } 919 920 function RegisterDashboardItem( $Name, $Callback)917 function DoStop(): void 918 { 919 } 920 921 function RegisterDashboardItem(string $Name, callable $Callback): void 921 922 { 922 923 $this->DashboardItems[$Name] = array('Callback' => $Callback); 923 924 } 924 925 925 function UnregisterDashboardItem( $Name)926 function UnregisterDashboardItem(string $Name): void 926 927 { 927 928 unset($this->DashboardItems[$Name]); 928 929 } 930 931 static function Cast(AppModule $AppModule): ModuleIS 932 { 933 if ($AppModule instanceof ModuleIS) 934 { 935 return $AppModule; 936 } 937 throw new Exception('Expected ModuleIS type but '.gettype($AppModule)); 938 } 929 939 }
Note:
See TracChangeset
for help on using the changeset viewer.