/scalr-2/tags/scalr-2.0.0/app/www/server/grids/aws_rds_param_groups_list.php
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
- <?php
- $response = array();
-
- // AJAX_REQUEST;
- $context = 6;
-
- try
- {
- $enable_json = true;
- include("../../src/prepend.inc.php");
-
- $req_show_all = true;
-
- if (isset($req_show_all))
- {
- if ($req_show_all == 'true')
- $_SESSION['sg_show_all'] = true;
- else
- $_SESSION['sg_show_all'] = false;
- }
-
- $Client = Client::Load($_SESSION['uid']);
-
- $AmazonRDSClient = AmazonRDS::GetInstance($Client->AWSAccessKeyID, $Client->AWSAccessKey);
-
- $AmazonRDSClient->SetRegion($_SESSION['aws_region']);
-
- // Rows
- $aws_response = $AmazonRDSClient->DescribeDBParameterGroups();
-
- $rows = (array)$aws_response->DescribeDBParameterGroupsResult->DBParameterGroups;
-
- if (!is_array($rows['DBParameterGroup']))
- $rows['DBParameterGroup'] = array($rows['DBParameterGroup']);
-
- // Get DBParameterGroups from SimpleXML Response and clean from stdClass
- $rowz = array();
- foreach ($rows['DBParameterGroup'] as $row)
- $rowz[(string)$row->DBParameterGroupName] = (array)$row;
-
- foreach ($rowz as $row)
- {
- if ($req_query)
- {
- if (!stristr($row['DBParameterGroupName'], $req_query))
- continue;
- }
-
- // Show only scalr security groups
- if (stristr($row['DBModifyInstanceSettings'], $_SESSION['sg_show_all']))
- {
- $rowz[] = $row;
- }
- }
-
- // diplay list limits
- $start = $req_start ? (int) $req_start : 0;
- $limit = $req_limit ? (int) $req_limit : 20;
-
- // cut spare limits from listview
- $response['total'] = count($rowz);
- $rowz = (count($rowz) > $limit) ? array_slice($rowz, $start, $limit) : $rowz;
-
- $response["data"] = array();
- if ($req_sort)
- {
- $nrowz = array();
- foreach ($rowz as $row)
- $nrowz[(string)$row['DBParameterGroupName']] = $row;
-
- ksort($nrowz);
-
- if ($req_dir == 'DESC')
- $rowz = array_reverse($nrowz);
- else
- $rowz = $nrowz;
- }
-
- // Rows. Create final rows array for script
- foreach ($rowz as $row)
- {
- $response["data"][] = array(
- "name" => (string)$row['DBParameterGroupName'],
- "description" => (string)$row['Description'],
- "engine" => (string)$row['Engine'],
- "id" => (string)$row['DBParameterGroupName']
- );
- }
-
- }
- catch(Exception $e)
- {
- $response = array("error" => $e->getMessage(), "data" => array());
- }
-
- print json_encode($response);
- ?>