PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/scalr-2/tags/scalr-2.0.0/app/www/server/grids/aws_rds_param_groups_list.php

http://scalr.googlecode.com/
PHP | 97 lines | 69 code | 21 blank | 7 comment | 10 complexity | 32602fa7ff655f5729b9650cf8345085 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, GPL-3.0
  1. <?php
  2. $response = array();
  3. // AJAX_REQUEST;
  4. $context = 6;
  5. try
  6. {
  7. $enable_json = true;
  8. include("../../src/prepend.inc.php");
  9. $req_show_all = true;
  10. if (isset($req_show_all))
  11. {
  12. if ($req_show_all == 'true')
  13. $_SESSION['sg_show_all'] = true;
  14. else
  15. $_SESSION['sg_show_all'] = false;
  16. }
  17. $Client = Client::Load($_SESSION['uid']);
  18. $AmazonRDSClient = AmazonRDS::GetInstance($Client->AWSAccessKeyID, $Client->AWSAccessKey);
  19. $AmazonRDSClient->SetRegion($_SESSION['aws_region']);
  20. // Rows
  21. $aws_response = $AmazonRDSClient->DescribeDBParameterGroups();
  22. $rows = (array)$aws_response->DescribeDBParameterGroupsResult->DBParameterGroups;
  23. if (!is_array($rows['DBParameterGroup']))
  24. $rows['DBParameterGroup'] = array($rows['DBParameterGroup']);
  25. // Get DBParameterGroups from SimpleXML Response and clean from stdClass
  26. $rowz = array();
  27. foreach ($rows['DBParameterGroup'] as $row)
  28. $rowz[(string)$row->DBParameterGroupName] = (array)$row;
  29. foreach ($rowz as $row)
  30. {
  31. if ($req_query)
  32. {
  33. if (!stristr($row['DBParameterGroupName'], $req_query))
  34. continue;
  35. }
  36. // Show only scalr security groups
  37. if (stristr($row['DBModifyInstanceSettings'], $_SESSION['sg_show_all']))
  38. {
  39. $rowz[] = $row;
  40. }
  41. }
  42. // diplay list limits
  43. $start = $req_start ? (int) $req_start : 0;
  44. $limit = $req_limit ? (int) $req_limit : 20;
  45. // cut spare limits from listview
  46. $response['total'] = count($rowz);
  47. $rowz = (count($rowz) > $limit) ? array_slice($rowz, $start, $limit) : $rowz;
  48. $response["data"] = array();
  49. if ($req_sort)
  50. {
  51. $nrowz = array();
  52. foreach ($rowz as $row)
  53. $nrowz[(string)$row['DBParameterGroupName']] = $row;
  54. ksort($nrowz);
  55. if ($req_dir == 'DESC')
  56. $rowz = array_reverse($nrowz);
  57. else
  58. $rowz = $nrowz;
  59. }
  60. // Rows. Create final rows array for script
  61. foreach ($rowz as $row)
  62. {
  63. $response["data"][] = array(
  64. "name" => (string)$row['DBParameterGroupName'],
  65. "description" => (string)$row['Description'],
  66. "engine" => (string)$row['Engine'],
  67. "id" => (string)$row['DBParameterGroupName']
  68. );
  69. }
  70. }
  71. catch(Exception $e)
  72. {
  73. $response = array("error" => $e->getMessage(), "data" => array());
  74. }
  75. print json_encode($response);
  76. ?>