ConsoleButton.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Vms\Buttons;
  20. use ModulesGarden\ProxmoxAddon\App\Models\VmModel;
  21. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Vms\Modals\MigrateModal;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\BuildUrl;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Buttons\ButtonDataTableModalAction;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataProviders\Providers\QueryDataProvider;
  27. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
  28. class ConsoleButton extends ButtonDataTableModalAction implements ClientArea
  29. {
  30. protected $icon = 'lu-zmdi lu-zmdi-desktop-windows';
  31. public function initContent()
  32. {
  33. $this->initIds('consoleButton');
  34. $this->setDisableByColumnValue("vmid", 0);
  35. }
  36. public function afterInitContent()
  37. {
  38. $query = VmModel::select("id")
  39. ->ofHostingId($this->getWhmcsParamByKey('serviceid'))
  40. ->notTemplate()
  41. ->getQuery();
  42. $dataProv = new QueryDataProvider();
  43. $dataProv->setData($query);
  44. $vmid = $dataProv->getData()->getRecords()->first()->id;
  45. $consoleUrl = isAdmin() ? BuildUrl::getUrl('console', 'novnc', ['vm'=> $vmid]) : 'clientarea.php?action=productdetails&id=' . $this->getWhmcsParamByKey('serviceid') . '&vm=' . $vmid . '&modop=custom&a=management&mg-page=console&mg-action=novnc';
  46. $this->setConsoleUrl($consoleUrl);
  47. logModuleCall(
  48. 'proxmoxCloud',
  49. __FUNCTION__,
  50. $this->actionButtons,
  51. 'Debug',
  52. $dataProv->getData()->getRecords()
  53. );
  54. }
  55. public function setConsoleUrl($url)
  56. {
  57. $this->addHtmlAttribute('onclick', "window.open('{$url}', '', 'width=900,height=700'); return false;");
  58. return $this;
  59. }
  60. }