CreateForm.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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\ProxmoxCloudVps\App\UI\BackupJob\Forms;
  20. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  21. use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\ConfigurableOption;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\BackupJob\Providers\BackupJobProvider;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\BackupJob\Providers\FirewallOptionProvider;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\StartTimeValidator;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Helpers\AlertTypesConstants;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\BaseForm;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Select;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Switcher;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Text;
  31. use function ModulesGarden\Servers\ProxmoxCloudVps\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. {
  48. $backupFilesLimit = null;
  49. }
  50. if ($this->configuration()->isBackupRouting() && $backupFilesLimit)
  51. {
  52. sl("lang")->addReplacementConstant("backupFilesLimit", $backupFilesLimit);
  53. $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.'));
  54. $this->setInternalAlertMessageRaw(true);
  55. $this->setInternalAlertMessageType(AlertTypesConstants::INFO);
  56. }
  57. $this->initFields();
  58. $this->loadDataToForm();
  59. }
  60. public function getAllowedActions()
  61. {
  62. return ['create'];
  63. }
  64. private function initFields()
  65. {
  66. //starttime
  67. $field = new Text('starttime');
  68. $field->setPlaceholder("00:00");
  69. $field->addValidator(new StartTimeValidator());
  70. $this->addField($field);
  71. //dow
  72. $field = new Select('dow');
  73. $field->enableMultiple();
  74. $field->setAvailableValues([
  75. "mon" => sl("lang")->tr("mon"),
  76. "tue" => sl("lang")->tr("tue"),
  77. "wed" => sl("lang")->tr("wed"),
  78. "thu" => sl("lang")->tr("thu"),
  79. "fri" => sl("lang")->tr("fri"),
  80. "sat" => sl("lang")->tr("sat"),
  81. "sun" => sl("lang")->tr("sun")
  82. ]);
  83. $field->notEmpty();
  84. $this->addField($field);
  85. //compress
  86. $field = new Select('compress');
  87. $field->setAvailableValues([
  88. "0" => sl("lang")->tr("0"),
  89. "lzo" => sl("lang")->tr("lzo"),
  90. "gzip" => sl("lang")->tr("gzip"),
  91. "zstd" => sl("lang")->tr("zstd")
  92. ]);
  93. $field->setDefaultValue('zstd');
  94. $field->notEmpty();
  95. $this->addField($field);
  96. //mode
  97. $field = new Select('mode');
  98. $field->setAvailableValues([
  99. "snapshot" => sl("lang")->tr("snapshot"),
  100. "suspend" => sl("lang")->tr("suspend"),
  101. "stop" => sl("lang")->tr("stop")
  102. ]);
  103. $field->notEmpty();
  104. $this->addField($field);
  105. //mailto
  106. $field = new Switcher("mailto");
  107. $this->addField($field);
  108. }
  109. }