ConsoleButton.php 2.5 KB

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