CreateForm.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (27.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxVps\App\UI\BackupJob\Forms;
  20. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  21. use ModulesGarden\Servers\ProxmoxVps\App\Enum\ConfigurableOption;
  22. use ModulesGarden\Servers\ProxmoxVps\App\UI\BackupJob\Providers\BackupJobProvider;
  23. use ModulesGarden\Servers\ProxmoxVps\App\UI\BackupJob\Providers\FirewallOptionProvider;
  24. use ModulesGarden\Servers\ProxmoxVps\App\UI\Validators\StartTimeValidator;
  25. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Helpers\AlertTypesConstants;
  26. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  27. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\BaseForm;
  28. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Select;
  29. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
  30. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Text;
  31. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  32. class CreateForm extends BaseForm implements ClientArea
  33. {
  34. use ProductService;
  35. public function initContent()
  36. {
  37. $this->initIds('createForm');
  38. $this->setFormType('create');
  39. $this->setProvider(new BackupJobProvider());
  40. $backupFilesLimit = $this->configuration()->getBackupMaxFiles();
  41. if ($this->isWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) &&
  42. $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) != "-1")
  43. {
  44. $backupFilesLimit = $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES);
  45. }
  46. if($backupFilesLimit == "-1"){
  47. $backupFilesLimit = null;
  48. }
  49. if ($this->configuration()->isBackupRouting() && $backupFilesLimit)
  50. {
  51. sl("lang")->addReplacementConstant("backupFilesLimit" , $backupFilesLimit);
  52. $this->setInternalAlertMessage( sl("lang")->tr('Your routing backup limit is :backupFilesLimit:. When you exceed this limit, the last backup will be replaced with a new one.'));
  53. $this->setInternalAlertMessageRaw(true);
  54. $this->setInternalAlertMessageType(AlertTypesConstants::INFO);
  55. }
  56. $this->initFields();
  57. $this->loadDataToForm();
  58. }
  59. public function getAllowedActions()
  60. {
  61. return ['create'];
  62. }
  63. private function initFields()
  64. {
  65. //starttime
  66. $field = new Text('starttime');
  67. $field->setPlaceholder("00:00");
  68. $field->addValidator(new StartTimeValidator());
  69. $this->addField($field);
  70. //dow
  71. $field = new Select('dow');
  72. $field->enableMultiple();
  73. $field->setAvailableValues([
  74. "mon" => sl("lang")->tr("mon"),
  75. "tue" => sl("lang")->tr("tue"),
  76. "wed" => sl("lang")->tr("wed"),
  77. "thu" => sl("lang")->tr("thu"),
  78. "fri" => sl("lang")->tr("fri"),
  79. "sat" => sl("lang")->tr("sat"),
  80. "sun" => sl("lang")->tr("sun")
  81. ]);
  82. $field->notEmpty();
  83. $this->addField($field);
  84. //compress
  85. $field = new Select('compress');
  86. $field->setAvailableValues([
  87. "0" => sl("lang")->tr("0"),
  88. "lzo" => sl("lang")->tr("lzo"),
  89. "gzip" => sl("lang")->tr("gzip"),
  90. "zstd" => sl("lang")->abtr("ZSTD (fast and good)")
  91. ]);
  92. $field->setDefaultValue('zstd');
  93. $field->notEmpty();
  94. $this->addField($field);
  95. //mode
  96. $field = new Select('mode');
  97. $field->setAvailableValues([
  98. "snapshot" => sl("lang")->tr("snapshot"),
  99. "suspend" => sl("lang")->tr("suspend"),
  100. "stop" => sl("lang")->tr("stop")
  101. ]);
  102. $field->notEmpty();
  103. $this->addField($field);
  104. //mailto
  105. $field = new Switcher("mailto");
  106. $this->addField($field);
  107. }
  108. }