UpdateForm.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\Validators\StartTimeValidator;
  24. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Helpers\AlertTypesConstants;
  25. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  26. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\BaseForm;
  27. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Hidden;
  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 UpdateForm extends BaseForm implements ClientArea
  33. {
  34. use ProductService;
  35. public function initContent()
  36. {
  37. $this->initIds('updateForm');
  38. $this->setFormType('update');
  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. }else if($this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) == "-1"){
  46. $backupFilesLimit = null;
  47. }
  48. if ($this->configuration()->isBackupRouting() && $backupFilesLimit)
  49. {
  50. sl("lang")->addReplacementConstant("backupFilesLimit" , $backupFilesLimit);
  51. $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.'));
  52. $this->setInternalAlertMessageRaw(true);
  53. $this->setInternalAlertMessageType(AlertTypesConstants::INFO);
  54. }
  55. else
  56. {
  57. $this->setInternalAlertMessage('confirmUpdate');
  58. $this->setInternalAlertMessageType(AlertTypesConstants::INFO);
  59. }
  60. $this->initFields();
  61. $this->loadDataToForm();
  62. }
  63. public function getAllowedActions()
  64. {
  65. return ['update'];
  66. }
  67. private function initFields()
  68. {
  69. //backupScheduleId
  70. $this->addField(new Hidden("backupScheduleId"));
  71. //displayId
  72. $this->addField(new Hidden("displayId"));
  73. //starttime
  74. $field = new Text('starttime');
  75. $field->setPlaceholder("00:00");
  76. $field->addValidator(new StartTimeValidator());
  77. $this->addField($field);
  78. //dow
  79. $field = new Select('dow');
  80. $field->enableMultiple();
  81. $field->setAvailableValues([
  82. "mon" => sl("lang")->tr("mon"),
  83. "tue" => sl("lang")->tr("tue"),
  84. "wed" => sl("lang")->tr("wed"),
  85. "thu" => sl("lang")->tr("thu"),
  86. "fri" => sl("lang")->tr("fri"),
  87. "sat" => sl("lang")->tr("sat"),
  88. "sun" => sl("lang")->tr("sun")
  89. ]);
  90. $field->notEmpty();
  91. $this->addField($field);
  92. //compress
  93. $field = new Select('compress');
  94. $field->setAvailableValues([
  95. "0" => sl("lang")->tr("0"),
  96. "lzo" => sl("lang")->tr("lzo"),
  97. "gzip" => sl("lang")->tr("gzip"),
  98. "zstd" => sl("lang")->abtr("ZSTD (fast and good)")
  99. ]);
  100. $field->setDefaultValue('zstd');
  101. $field->notEmpty();
  102. $this->addField($field);
  103. //mode
  104. $field = new Select('mode');
  105. $field->setAvailableValues([
  106. "snapshot" => sl("lang")->tr("snapshot"),
  107. "suspend" => sl("lang")->tr("suspend"),
  108. "stop" => sl("lang")->tr("stop")
  109. ]);
  110. $field->notEmpty();
  111. $this->addField($field);
  112. //mailto
  113. $field = new Switcher("mailto");
  114. $this->addField($field);
  115. }
  116. }