MailtoSwitchButton.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Buttons;
  20. use MGProvision\Proxmox\v2\models\BackupSchedule;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  23. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  24. use ModulesGarden\Servers\ProxmoxVps\Core\UI\ResponseTemplates\DataJsonResponse;
  25. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Buttons\ButtonSwitchAjax;
  26. use ModulesGarden\Servers\ProxmoxVps\App\Enum\ConfigurableOption;
  27. class MailtoSwitchButton extends ButtonSwitchAjax implements ClientArea
  28. {
  29. use ProductService;
  30. use ApiService;
  31. protected $switchColumn = 'mailto';
  32. protected $refreshActionIds = 'dackupJobDataTable';
  33. public function returnAjaxData()
  34. {
  35. try
  36. {
  37. $data = json_decode(base64_decode($this->getRequestValue('actionElementId')), true);
  38. $storage = $this->configuration()->getBackupStorage() ? $this->configuration()->getBackupStorage() : "local";
  39. $routing = 1;
  40. $maxFiles = $this->configuration()->getBackupMaxFiles();
  41. if($this->isWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES) && $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)!="-1"){
  42. $maxFiles = $this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES);
  43. }else if($this->getWhmcsConfigOption(ConfigurableOption::BACKUPS_FILES)=="-1"){
  44. $maxFiles = null;
  45. }
  46. $backupSchedule = new BackupSchedule();
  47. $backupSchedule->setApi($this->api());
  48. $backupSchedule->setAttributes([
  49. "id" => $data['backupScheduleId'],
  50. "vmid" => $this->vm()->getVmid(),
  51. "storage" => $storage,
  52. "remove" => $routing,
  53. "maxfiles" => $maxFiles,
  54. "starttime" => $data['starttime'],
  55. "dow" => $data['dow'],
  56. "mode" => $data['mode'],
  57. "compress" => $data['compress'],
  58. "mailto" => $this->getRequestValue("value") == "on" ? $this->getWhmcsParamByKey('clientsdetails')['email'] : null,
  59. ]);
  60. $backupSchedule->update();
  61. }
  62. catch (\Exception $exc)
  63. {
  64. return (new DataJsonResponse())->setStatusError()->setMessage($exc->getMessage())->setCallBackFunction($this->callBackFunction)->addRefreshTargetId($this->refreshActionIds);
  65. }
  66. return (new DataJsonResponse())->setMessageAndTranslate('changesSaved')
  67. ->setCallBackFunction('pmOnBackupJobChanged');
  68. }
  69. /**
  70. *
  71. */
  72. protected function afterInitContent()
  73. {
  74. //Why?
  75. }
  76. }