UpdateForm.php 4.7 KB

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