/main/images.php

https://gitlab.com/franheit_krya/digitalocean-dashboard · PHP · 92 lines · 92 code · 0 blank · 0 comment · 5 complexity · eca5863bfaf04d3a2c2cd5eed1599823 MD5 · raw file

  1. <?php require_once '../main/header.php'; ?>
  2. <div class="container-fluid">
  3. <div class="row">
  4. <?php require_once '../main/sidebar.php'; ?>
  5. <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main do-images">
  6. <table id="digitaloceantable" class="table table-hover">
  7. <thead>
  8. <tr>
  9. <th>ID</th>
  10. <th>Name</th>
  11. <th>Type</th>
  12. <th>Distribution</th>
  13. <th>Slug</th>
  14. <th>Public</th>
  15. <th>Regions</th>
  16. <th>Min&nbsp;Disk&nbsp;Size</th>
  17. <th>Created</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. <?php
  22. $endpoint = "https://api.digitalocean.com/v2/images?private=true";
  23. $headers[] = "Content-type: application/json";
  24. $headers[] = "Authorization: Bearer $DO_API_TOKEN";
  25. $curl = curl_init();
  26. curl_setopt_array($curl, [
  27. CURLOPT_HTTPHEADER => $headers,
  28. CURLOPT_RETURNTRANSFER => true,
  29. CURLOPT_URL => $endpoint,
  30. ]);
  31. $response = curl_exec($curl);
  32. $decoderesponse = json_decode($response, true);
  33. foreach ($decoderesponse['images'] as $image) {
  34. $id = $image['id'];
  35. $name = $image['name'];
  36. $type = $image['type'];
  37. $distribution = $image['distribution'];
  38. $slug = $image['slug'];
  39. $public = $image['public'];
  40. $regions = $image['regions'];
  41. $min_disk_size = $image['min_disk_size'];
  42. $created_at = $image['created_at'];
  43. echo "<tr><td>" . $id . "</td>";
  44. echo "<td>" . $name . "</td>";
  45. echo "<td>" . $type . "</td>";
  46. echo "<td>" . $distribution . "</td>";
  47. echo "<td>" . $slug . "</td>";
  48. echo "<td>";
  49. if ($public == true) {
  50. echo "Public";
  51. } else {
  52. echo "Private";
  53. }
  54. echo "</td>";
  55. echo "<td>" . $regions[0] . "</td>";
  56. echo "<td>" . $min_disk_size . "GB</td>";
  57. echo "<td>" . $created_at . "</td></tr>";
  58. }
  59. ?>
  60. </tbody>
  61. </table>
  62. <script type="text/javascript">
  63. $(document).ready(function() {
  64. $('#digitaloceantable').DataTable({
  65. "aaSorting": [],
  66. "oLanguage": {
  67. "sInfo": 'Showing _START_ to _END_ of _TOTAL_ Images.',
  68. "sInfoEmpty": 'No Images yet.',
  69. "sInfoFiltered": 'filtered from _MAX_ total Images',
  70. "sZeroRecords": 'No Images Found',
  71. "sLengthMenu": 'Show _MENU_ Images',
  72. "sEmptyTable": "No Images found currently.",
  73. }
  74. });
  75. });
  76. </script>
  77. <?php if ($DO_API_DEVELOPER_MODE == true): ?>
  78. <div class="collapse" id="collapseDeveloperMode">
  79. <div class="well">
  80. <?php
  81. echo "<pre>";
  82. print_r(json_decode($response, 1));
  83. echo "</pre>";
  84. ?>
  85. </div>
  86. </div>
  87. <?php endif; ?>
  88. </div>
  89. </div>
  90. </div>
  91. </body>
  92. </html>