Changeset 895 for trunk/Modules


Ignore:
Timestamp:
Jan 12, 2021, 10:29:50 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Setup is now AppModule and it is installed and stated as first module.
  • Modified: Improved modular system.
Location:
trunk/Modules
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Network/Network.php

    r894 r895  
    184184        'API' => array('Type' => 'TDeviceAPIType', 'Caption' => 'API', 'Default' => '', 'Null' => true),
    185185        'Logs' => array('Type' => 'TDeviceLogList', 'Caption' => 'Záznamy', 'Default' => ''),
     186        'InboundNATPriority' => array('Type' => 'Integer', 'Caption' => 'Priorita příchozího NATu', 'Default' => '1'),
    186187      ),
    187188      'AfterInsert' => array($this, 'AfterInsertNetworkDevice'),
  • trunk/Modules/Network/NetworkModels.php

    r894 r895  
    3232    $Desc->AddString('LoginPassword');
    3333    $Desc->AddReference('API', DeviceAPIType::GetClassName());
     34    $Desc->AddInteger('InboundNATPriority');
    3435    return $Desc;
    3536  }
  • trunk/Modules/Portal/Portal.php

    r893 r895  
    1414    $this->Description = 'Community portal.';
    1515    $this->Dependencies = array('News', 'User');
     16  }
     17
     18  function GetModels(): array
     19  {
     20    return array(Panel::GetClassName(), PanelColumn::GetClassName());
     21  }
     22
     23  function DoInstall(): void
     24  {
     25   /* $this->Database->query("INSERT INTO `PanelColumn` (`Id`, `Width`) VALUES
     26    (1, ''),
     27    (2, ''),
     28    (3, '70%');");
     29    $this->Database->query("INSERT INTO `Panel` (`Id`, `Module`, `Parameters`, `Order`, `PanelColumn`) VALUES
     30    (1, 'ActionGroup', 1, 2, 1),
     31    (2, 'ActionGroup', 4, 1, 2),
     32    (3, 'ActionGroup', 5, 2, 2),
     33    (4, 'ActionGroup', 6, 3, 2),
     34    (5, 'ActionGroup', 2, 4, 2),
     35    (6, 'ActionGroup', 3, 5, 2),
     36    (7, 'NewsGroupList', '', 2, 3),
     37    (8, 'Webcam', '', 3, 1),
     38    (9, 'UserOptions', '', 1, 3),
     39    (10, 'ActionGroup', 9, 1, 1),
     40    (11, 'Meteo', '', 4, 1);");*/
    1641  }
    1742
     
    3560    ));
    3661    ModuleUser::Cast($this->System->GetModule('User'))->UserPanel[] = array('PagePortal', 'UserPanel');
     62  }
     63}
     64
     65class PanelColumn extends Model
     66{
     67  static function GetDesc(): ModelDesc
     68  {
     69    $Desc = new ModelDesc(self::GetClassName());
     70    $Desc->AddString('Width');
     71    return $Desc;
     72  }
     73}
     74
     75class Panel extends Model
     76{
     77  static function GetDesc(): ModelDesc
     78  {
     79    $Desc = new ModelDesc(self::GetClassName());
     80    $Desc->AddString('Module');
     81    $Desc->AddString('Parameters');
     82    $Desc->AddInteger('Order');
     83    $Desc->AddInteger('PanelColumn');
     84    return $Desc;
    3785  }
    3886}
     
    216264
    217265        $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
    218         $DbResult = $this->Database->update('Member', 'Id='.$User->User['Member'],
     266        $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` '.
     267          'WHERE `User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']);
     268        $CustomerUserRel = $DbResult->fetch_assoc();
     269        $CustomerId = $CustomerUserRel['Member'];
     270
     271        $DbResult = $this->Database->update('Member', 'Id='.$CustomerId,
    219272           array('FamilyMemberCount' => $Form->Values['FamilyMemberCount']));
    220         $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$User->User['Member']);
     273        $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$CustomerId);
    221274        $Member = $DbResult->fetch_assoc();
    222275        $DbResult = $this->Database->update('Subject', 'Id='.$Member['Subject'],
     
    231284          'Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, '.
    232285          'Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
    233           'ON Subject.Id = Member.Subject WHERE Member.Id='.$User->User['Member']);
     286          'ON Subject.Id = Member.Subject WHERE Member.Id='.$CustomerId);
    234287        $DbRow = $DbResult->fetch_array();
    235288        foreach ($Form->Definition['Items'] as $Index => $Item)
  • trunk/Modules/Subject/Subject.php

    r894 r895  
    133133  function GetModels(): array
    134134  {
    135     return array(Country::GetClassName(), Subject::GetClassName(), ContactCategory::GetClassName(),
     135    return array(Subject::GetClassName(), ContactCategory::GetClassName(),
    136136      Contact::GetClassName());
    137137  }
     
    166166}
    167167
    168 class Country extends Model
    169 {
    170   static function GetDesc(): ModelDesc
    171   {
    172     $Desc = new ModelDesc(self::GetClassName());
    173     $Desc->AddString('Name');
    174     return $Desc;
    175   }
    176 }
    177 
    178168class Contact extends Model
    179169{
  • trunk/Modules/System/System.php

    r894 r895  
    11<?php
     2
     3include_once(dirname(__FILE__).'/SystemModels.php');
    24
    35class PageModules extends Page
     
    109111    $this->Description = 'Base system module';
    110112    $this->Dependencies = array();
     113    $this->SystemModule = true;
    111114  }
    112115
     
    115118    return array(UnitOfMeasure::GetClassName(), ActionIcon::GetClassName(), ActionGroup::GetClassName(),
    116119      ActionType::GetClassName(), Action::GetClassName(), Language::GetClassName(), Country::GetClassName());
     120  }
     121
     122  function DoBeforeInstall(): void
     123  {
     124    $this->Manager->OnInstallModel = array($this, 'InstallModel');
     125    $this->Manager->OnUninstallModel = array($this, 'UninstallModel');
     126  }
     127
     128  function DoAfterUninstall(): void
     129  {
     130    $this->Manager->OnInstallModel = null;
     131    $this->Manager->OnUninstallModel = null;
    117132  }
    118133
     
    184199  function DoStart(): void
    185200  {
     201    $this->Manager->OnInstallModel = array($this, 'InstallModel');
     202    $this->Manager->OnUninstallModel = array($this, 'UninstallModel');
     203
    186204    $this->System->RegisterPage(['module'], 'PageModules');
    187205    $this->System->FormManager->RegisterClass('Action', array(
     
    404422    //$this->Manager->OnModuleChange = array($this, 'ModuleChange');
    405423    //$this->LoadFromDatabase();
     424  }
     425
     426  function InstallModel(ModelDesc $ModelDesc)
     427  {
     428    $Query = "CREATE TABLE IF NOT EXISTS `".$ModelDesc->Name."` (\n";
     429    $Query .= '  `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n";
     430    foreach ($ModelDesc->Columns as $Column)
     431    {
     432      $Query .= "  `".$Column->Name."` ";
     433      if ($Column->Type == ModelColumnType::Integer) $Query .= 'int(11)';
     434      else if ($Column->Type == ModelColumnType::String) $Query .= 'varchar(255)';
     435      else if ($Column->Type == ModelColumnType::Float) $Query .= 'varchar(255)';
     436      else if ($Column->Type == ModelColumnType::Text) $Query .= 'text';
     437      else if ($Column->Type == ModelColumnType::DateTime) $Query .= 'datetime';
     438      else if ($Column->Type == ModelColumnType::Reference) $Query .= 'int(11)';
     439      else if ($Column->Type == ModelColumnType::Boolean) $Query .= 'tinyint(1)';
     440      else if ($Column->Type == ModelColumnType::Date) $Query .= 'date';
     441      else if ($Column->Type == ModelColumnType::BigInt) $Query .= 'bigint(20)';
     442      else if ($Column->Type == ModelColumnType::Enum)
     443      {
     444        $Query .= 'enum("'.implode('", "', $Column->States).'")';
     445      }
     446
     447      if ($Column->Nullable) $Query .= '';
     448        else $Query .= ' NOT NULL';
     449
     450      $Query .= ' COLLATE utf8_general_ci';
     451
     452      if ($Column->HasDefault)
     453      {
     454        if ($Column->Default == null)
     455          $Query .= ' DEFAULT NULL';
     456        else $Query .= ' DEFAULT '.$Column->GetDefault();
     457      }
     458      $Query .= ",\n";
     459    }
     460    $Query .= '  PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`)';
     461    foreach ($ModelDesc->Columns as $Column)
     462    {
     463      if ($Column->Type == ModelColumnType::Reference)
     464        $Query .= ','."\n".'  KEY `'.$Column->Name.'` (`'.$Column->Name.'`)';
     465      else if ($Column->Unique)
     466        $Query .= ','."\n".'  UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)';
     467    }
     468    $Query .= "\n";
     469
     470    if ($ModelDesc->Memory) $Engine = 'MEMORY';
     471      else $Engine = 'InnoDB';
     472    $Query .= ') ENGINE='.$Engine.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;';
     473    $I = 1;
     474    foreach ($ModelDesc->Columns as $Column)
     475    {
     476      if ($Column->Type == ModelColumnType::Reference)
     477        $Query .= "ALTER TABLE `".$ModelDesc->Name."` ".
     478        "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);";
     479      $I++;
     480    }
     481    $this->Database->query($Query);
     482  }
     483
     484  function UninstallModel(ModelDesc $ModelDesc)
     485  {
     486    $this->Database->query('DROP TABLE IF EXISTS `'.$ModelDesc->Name.'`');
    406487  }
    407488
     
    544625  }
    545626}
    546 
    547 class UnitOfMeasure extends Model
    548 {
    549   static function GetDesc(): ModelDesc
    550   {
    551     $Desc = new ModelDesc(self::GetClassName());
    552     $Desc->AddString('Name');
    553     $Desc->AddString('Unit');
    554     return $Desc;
    555   }
    556 }
    557 
    558 class Action extends Model
    559 {
    560   static function GetDesc(): ModelDesc
    561   {
    562     $Desc = new ModelDesc(self::GetClassName());
    563     $Desc->AddString('Title');
    564     $Desc->AddString('URL');
    565     $Desc->AddReference('Icon', ActionIcon::GetClassName());
    566     $Desc->AddReference('Type', ActionType::GetClassName());
    567     $Desc->AddReference('Group', ActionGroup::GetClassName());
    568     $Desc->AddReference('PermissionOperation', PermissionOperation::GetClassName());
    569     $Desc->AddBoolean('Enable');
    570     return $Desc;
    571   }
    572 }
    573 
    574 class ActionIcon extends Model
    575 {
    576   static function GetDesc(): ModelDesc
    577   {
    578     $Desc = new ModelDesc(self::GetClassName());
    579     $Desc->AddString('Name');
    580     return $Desc;
    581   }
    582 }
    583 
    584 class ActionGroup extends Model
    585 {
    586   static function GetDesc(): ModelDesc
    587   {
    588     $Desc = new ModelDesc(self::GetClassName());
    589     $Desc->AddString('Name');
    590     return $Desc;
    591   }
    592 }
    593 
    594 class ActionType extends Model
    595 {
    596   static function GetDesc(): ModelDesc
    597   {
    598     $Desc = new ModelDesc(self::GetClassName());
    599     $Desc->AddString('Name');
    600     return $Desc;
    601   }
    602 }
    603 
    604 class Language extends Model
    605 {
    606   static function GetDesc(): ModelDesc
    607   {
    608     $Desc = new ModelDesc(self::GetClassName());
    609     $Desc->AddString('Name');
    610     return $Desc;
    611   }
    612 }
    613 
    614 class Country extends Model
    615 {
    616   static function GetDesc(): ModelDesc
    617   {
    618     $Desc = new ModelDesc(self::GetClassName());
    619     $Desc->AddString('Name');
    620     return $Desc;
    621   }
    622 }
    623 
  • trunk/Modules/User/User.php

    r894 r895  
    2929  }
    3030
     31  function DoInstall(): void
     32  {
     33    $this->Database->insert('PermissionGroup', array('Id' => 1, 'Description' => 'Ostatní'));
     34    $this->Database->insert('PermissionGroup', array('Id' => 2, 'Description' => 'Registrovaní uživatelé'));
     35    $this->Database->insert('PermissionGroup', array('Id' => 3, 'Description' => 'Zákazníci'));
     36    $this->Database->insert('PermissionGroup', array('Id' => 4, 'Description' => 'Správci sítě'));
     37    $this->Database->insert('PermissionGroup', array('Id' => 5, 'Description' => 'Systémoví správci'));
     38  }
     39
    3140  function DoStart(): void
    3241  {
     
    181190    $Output = 'Uživatelů: '.$DbRow['0'].'<br/>';
    182191    return $Output;
    183   }
    184 
    185   function DoStop(): void
    186   {
    187192  }
    188193
  • trunk/Modules/User/UserModel.php

    r894 r895  
    7575    $Desc->AddString('Salt');
    7676    $Desc->AddString('Email');
    77     $Desc->AddString('LastIpAddress');
    78     $Desc->AddString('LastLoginTime');
     77    $Column = $Desc->AddString('LastIpAddress');
     78    $Column->HasDefault = true;
     79    $Column->Nullable = true;
     80    $Column = $Desc->AddDateTime('LastLoginTime');
     81    $Column->Nullable = true;
     82    $Column->HasDefault = true;
    7983    $Desc->AddDateTime('RegistrationTime');
    8084    $Desc->AddBoolean('Locked');
    81     $Desc->AddString('InitPassword');
     85    $Column = $Desc->AddString('InitPassword');
     86    $Column->Nullable = true;
     87    $Column->HasDefault = true;
    8288    return $Desc;
    8389  }
     
    118124    if ($Row['User'] != '')
    119125    {
    120       $Query = $this->Database->query('SELECT `User`.*, `UserCustomerRel`.`Customer` AS `Member` FROM `User` '.
    121         ' LEFT JOIN `UserCustomerRel` ON `UserCustomerRel`.`User`=`User`.`Id` WHERE `User`.`Id`='.$Row['User']);
     126      $Query = $this->Database->query('SELECT `User`.* FROM `User` WHERE `User`.`Id`='.$Row['User']);
    122127      $this->User = $Query->fetch_assoc();
    123128      $Result = USER_LOGGED;
     
    500505  {
    501506    $Desc = new ModelDesc(self::GetClassName());
    502     $Desc->AddReference('Module', Module::GetClassName());
     507    //$Desc->AddReference('Module', Module::GetClassName());
    503508    $Desc->AddString('Operation');
    504509    $Desc->AddString('Item');
  • trunk/Modules/User/UserPage.php

    r887 r895  
    2121  function ShowContacts(): string
    2222  {
     23    if (!$this->System->ModuleManager->ModuleRunning('Subject')) return '';
     24
    2325    $Query = 'SELECT `Contact`.`Value`, `Contact`.`Description`, (SELECT `Name` FROM `ContactCategory` WHERE `ContactCategory`.`Id` = `Contact`.`Category`) AS `Category` '.
    2426      'FROM `Contact` WHERE `User` = '.
     
    3941    $Order = GetOrderTableHeader('Contacts', $TableColumns, 'Value', 0);
    4042    $Output .= $Order['Output'];
    41 
    4243    $Query = $Query.' '.$Order['SQL'].$PageList['SQLLimit'];
    43 
    4444    $DbResult = $this->Database->query($Query);
    4545    while ($Contact = $DbResult->fetch_assoc())
     
    4949      '<td>'.$Contact['Value'].'</td>'.
    5050      '<td>'.$Contact['Description'].'</td>'.
    51       '</tr>';
     51        '</tr>';
    5252    }
    5353    $Output .= '</table>';
  • trunk/Modules/Wiki/Wiki.php

    r894 r895  
    4646  static function GetDesc(): ModelDesc
    4747  {
    48     $Desc = new ModelDesc('WikiPage');
     48    $Desc = new ModelDesc(self::GetClassName());
    4949    $Desc->AddString('Name');
    5050    $Desc->AddString('NormalizedName');
Note: See TracChangeset for help on using the changeset viewer.