ConsoleButton.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\Servers\ProxmoxCloudVps\App\UI\Vms\Modals\MigrateModal;
  21. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Buttons\ButtonDataTableModalAction;
  24. class ConsoleButton extends ButtonDataTableModalAction implements ClientArea
  25. {
  26. protected $icon = 'lu-zmdi lu-zmdi-desktop-windows';
  27. public function initContent()
  28. {
  29. $this->initIds('consoleButton');
  30. $this->setDisableByColumnValue("vmid", 0);
  31. $url = "clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=console&mg-action=novnc";
  32. // $url = "window.open('" . $target . "', '', 'width=900,height=700'); return false;";
  33. // $url ="clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=vm";
  34. $this->setRawUrl($url)
  35. ->setRedirectParams(['vm' => ':id']);
  36. }
  37. public function afterInitContent()
  38. {
  39. $this->htmlAttributes['@click.middle'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
  40. $this->htmlAttributes['@click'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
  41. logModuleCall(
  42. 'proxmoxCloud',
  43. __FUNCTION__,
  44. $this->parseCustomParams(),
  45. 'Debug',
  46. $this->htmlAttributes
  47. );
  48. }
  49. public function setRawUrl($url)
  50. {
  51. $this->rawUrl = $url;
  52. return $this;
  53. }
  54. protected function parseCustomParams()
  55. {
  56. if (count($this->redirectParams) === 0 && $this->rawUrl === null)
  57. {
  58. return '{}';
  59. }
  60. return $this->parseListTOJsString($this->redirectParams);
  61. }
  62. protected function parseListTOJsString($params)
  63. {
  64. $jsString = '{';
  65. if ($this->rawUrl !== null)
  66. {
  67. $params['rawUrl'] = $this->rawUrl;
  68. }
  69. foreach ($params as $key => $value)
  70. {
  71. $jsString .= ' ' . str_replace('-', '__', $key) . ': ' . (is_array($value) ? ($this->parseListTOJsString($value) . ',') : ("'" . (string) $value) . "',");
  72. }
  73. $jsString = trim($jsString, ',') . ' } ';
  74. return $jsString;
  75. }
  76. public function setRedirectParams($paramsList)
  77. {
  78. $this->redirectParams = $paramsList;
  79. $this->updateHtmlAttributesByRedirectParams();
  80. return $this;
  81. }
  82. protected function updateHtmlAttributesByRedirectParams()
  83. {
  84. foreach ($this->redirectParams as $key => $value)
  85. {
  86. $this->updateHtmlAttribute($key, $value);
  87. }
  88. }
  89. protected function updateHtmlAttribute($key, $value)
  90. {
  91. if (strpos($value, ':') === 0)
  92. {
  93. $this->addHtmlAttribute(':data-' . $key , 'dataRow.' . trim($value, ':'));
  94. }
  95. }
  96. }