MailtoSwitchButton.php 3.7 KB

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