ConsoleButton.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. class ConsoleButton extends ButtonDataTableModalAction implements ClientArea
  28. {
  29. protected $icon = 'lu-zmdi lu-zmdi-desktop-windows';
  30. public function initContent()
  31. {
  32. $this->initIds('consoleButton');
  33. $this->setDisableByColumnValue("vmid", 0);
  34. }
  35. public function afterInitContent()
  36. {
  37. $query = VmModel::select("id")
  38. ->ofHostingId($this->getWhmcsParamByKey('serviceid'))
  39. ->notTemplate()
  40. ->getQuery();
  41. $dataProv = new QueryDataProvider();
  42. $dataProv->setData($query);
  43. $vmid = $dataProv->getData()->getRecords()->first()->id;
  44. $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';
  45. $this->setConsoleUrl($consoleUrl);
  46. logModuleCall(
  47. 'proxmoxCloud',
  48. __FUNCTION__,
  49. $this->actionButtons,
  50. 'Debug',
  51. $dataProv->getData()->getRecords()
  52. );
  53. }
  54. public function setConsoleUrl($url)
  55. {
  56. $this->addHtmlAttribute('onclick', "window.open('{$url}', '', 'width=900,height=700'); return false;");
  57. return $this;
  58. }
  59. }