productressources.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. use WHMCS\Application;
  3. use WHMCS\Config\Setting;
  4. use WHMCS\Exception\ProgramExit;
  5. use WHMCS\Product\Product;
  6. use WHMCS\Session;
  7. use WHMCS\User\Client;
  8. use WHMCS\Database\Capsule;
  9. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
  10. use ModulesGarden\Servers\ProxmoxCloudVps\Packages\WhmcsService\Service;
  11. require("../../init.php");
  12. /*
  13. *** USAGE SAMPLES ***
  14. <script language="javascript" src="feeds/productsinfo.php?pid=1&get=name"></script>
  15. <script language="javascript" src="feeds/productsinfo.php?pid=1&get=description"></script>
  16. <script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly&currency=1"></script>
  17. <script language="javascript" src="feeds/productsinfo.php?pid=1&get=orderurl&carttpl=web20cart"></script>
  18. */
  19. $whmcs = App::self();
  20. $pid = (int) $whmcs->get_req_var('pid');
  21. $id = (int) $whmcs->get_req_var('id');
  22. $get = $whmcs->get_req_var('get');
  23. $language = $whmcs->get_req_var('language') ?: null;
  24. $data = array();
  25. $name = $description = '';
  26. // Verify user input for pid exists, is greater than 0, and as is a valid id
  27. if ($pid > 0) {
  28. $data = Capsule::table('tblproducts')
  29. ->where('id', '=', $pid)
  30. ->first();
  31. $pid = (int) $data->id;
  32. // If there is a user logged in, we will use the client language
  33. if (((int) $userId = Session::get('userid'))) {
  34. $language = Client::find($userId, array('language'))->language ?: null;
  35. }
  36. $name = Product::getProductName($pid, $data->name, $language);
  37. $description = Product::getProductDescription($pid, $data->description, $language);
  38. }
  39. // Verify that the pid is not less than 1 to in order to continue.
  40. if ($pid < 1) {
  41. widgetOutput('Product ID Not Found');
  42. }
  43. $configOptionsGroupID = Capsule::table('tblproductconfiglinks')
  44. ->where('pid', '=', $pid)
  45. ->select('gid')
  46. ->first();
  47. $configOptions = Capsule::table('tblproductconfigoptions')
  48. ->where('gid', '=', $configOptionsGroupID->gid)
  49. ->select('optionname','qtyminimum')
  50. ->get();
  51. $service = new Service($id);
  52. $ressource = new ResourceManager();
  53. print_r($ressource);
  54. widgetOutput($ressource->vcpus()->getUsed());
  55. function widgetOutput($value) {
  56. echo "document.write('".addslashes($value)."');";
  57. throw new ProgramExit();
  58. }