Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.56 KB | None | 0 0
  1. <?php
  2.     function getInfo($number) {
  3.         $path = 'http://localhost/project/api.php?number=' . $number;
  4.  
  5.         $curl = curl_init();
  6.         curl_setopt($curl, CURLOPT_URL, $path);
  7.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  8.         curl_setopt($curl, CURLOPT_HEADER, false);
  9.         $result = curl_exec($curl);
  10.         curl_close($curl);
  11.        
  12.         $result = json_decode($result, true);
  13.         return $result;
  14.     }
  15.  
  16.     function prevDay($date) {
  17.         $daysOfMonth = array(31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  18.         $day = (int)substr($date, 0, 2);
  19.         $month = (int)substr($date, 3, 2);
  20.         $year = (int)substr($date, 6, 4);
  21.        
  22.         if ($day > 1) {
  23.             --$day;
  24.         } else if ($month > 1) {
  25.             --$month;
  26.             $day = $daysOfMonth[$month - 1];
  27.         } else {
  28.             --$year;
  29.             $day = 31;
  30.             $month = 12;
  31.         }
  32.        
  33.         if ($day < 10) {
  34.             $day = '0' . $day;
  35.         }
  36.  
  37.         if ($month < 10) {
  38.             $month = '0' . $month;
  39.         }
  40.  
  41.         return $day . '/' . $month . '/' . $year;
  42.     }
  43.    
  44.     $number = isset($_GET['number']) ? $_GET['number'] : '';
  45.     $path = 'http://localhost/project/dashboard.php?number=' . $number;
  46.     $page = isset($_GET['page']) ? $_GET['page'] : 1;
  47.    
  48.     $info = getInfo($number);
  49.     $names = array('Transaction ID', 'Transaction Type', 'Phone Type', 'City', 'Region', 'Start Time UTC', 'Start Time Local',
  50.                    'Connect Duration', 'IVR Duration');
  51. ?>
  52.  
  53. <!DOCTYPE html>
  54.  
  55. <html>
  56.     <head>
  57.         <title>Dashboard Page</title>
  58.        
  59.         <link rel='stylesheet' href='style.css' />
  60.         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  61.         <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  62.         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  63.  
  64.         <script type='text/javascript'>
  65.             $(document).ready(function() {
  66.                 var names = ['Transaction ID', 'Transaction Type', 'Phone Type', 'City', 'Region', 'Start Time UTC', 'Start Time Local',
  67.                              'Connect Duration', 'IVR Duration'];
  68.                
  69.                 $('.option input[type=checkbox]').prop('checked', true);
  70.  
  71.                 for (let i = 0; i < names.length; ++i) {
  72.                     $('.option #' + i).change(function() {
  73.                         $('table.info tr').each(function(index) {
  74.                             $(this).children(':nth-child(' + (i + 1) + ')').toggle();
  75.                         })
  76.                     });
  77.                 }
  78.             });
  79.         </script>
  80.     </head>
  81.  
  82.     <body>
  83.         <div class='wrap'>
  84.             <div class='navbar'>
  85.                 <img src='...' alt='logo' />
  86.                 <span class='datetime'><?php echo $number ?></span>
  87.             </div>
  88.            
  89.             <div class='container'>
  90.                 <svg width='1025' height='200' style='font-family:"Lucida Grande", "Lucida Sans Unicode",
  91.                 Arial, Helvetica, sans-serif;font-size:12px; background-color: white; display: block; margin: 10px auto;'>
  92.                
  93.                     <?php
  94.                         $dates = array();
  95.                         $currDate = '';
  96.  
  97.                         foreach (array_reverse($info) as $row) {
  98.                             $day = substr($row[6], 8, 2);
  99.                             $month = substr($row[6], 5, 2);
  100.                             $year = substr($row[6], 0, 4);
  101.                             $key = $day . '/' . $month . '/' . $year;
  102.                            
  103.                             if ($currDate == '') {
  104.                                 $currDate = $key;
  105.                             }
  106.  
  107.                             if (array_key_exists($key, $dates)) {
  108.                                 $dates[$key] += 1;
  109.                             } else {
  110.                                 $dates[$key] = 1;
  111.                             }
  112.                         }
  113.                        
  114.                         for ($i = 9; $i >= 0; --$i) {
  115.                             echo '<text x="' . ($i * 100 + 30) . '" y="200" fill="black">' . $currDate . '</text>';
  116.                             echo '<circle cx="' . ($i * 100 + 60) . '" cy= "' . ((7 - $dates[$currDate]) * 25 - 5) . '" r="5" fill="red" />';
  117.                             $prevDate = prevDay($currDate);
  118.  
  119.                             if ($i > 0) {
  120.                                 echo '<line x1="'. ($i * 100 + 60) . '" y1="' . ((7 - $dates[$currDate]) * 25 - 5) . '" x2="' .
  121.                                 (($i - 1) * 100 + 60) . '" y2="' . ((7 - $dates[$prevDate]) * 25 - 5) . '" stroke="orange" stroke-width="3" />';
  122.                             }
  123.  
  124.                             $currDate = $prevDate;
  125.                         }
  126.                        
  127.                         for ($i = 0; $i <= 6; $i += 2) {
  128.                             echo '<text x="0" y="' . (7 - $i) * 25 . '" fill="black">' . $i . '</text>';
  129.                             echo '<line x1="10" y1="' . ((7 - $i) * 25 - 5) . '" x2="1025" y2="' . ((7 - $i) * 25 - 5) . '"
  130.                            style="stroke:rgb(100,50,50); stroke-width:2" />';
  131.                         }
  132.                     ?>
  133.                 </svg>
  134.                 <span class='calls'>Total calls: <?php echo count($info); ?></span>
  135.  
  136.                 <div class="dropdown">
  137.                     <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
  138.                         Display
  139.                         <span class="caret"></span>
  140.                     </button>
  141.                     <ul class="dropdown-menu">
  142.                     <?php
  143.                         for ($i = 0; $i < count($names); ++$i) {
  144.                             echo '<li><a href="#"><div class="form-check option">';
  145.                             echo '<input class="form-check-input" type="checkbox" value="' . $names[$i] . '" id="' . $i . '">';
  146.                             echo '<label class="form-check-label" for="' . $i . '">' . $names[$i] . '</label>';
  147.                             echo '</div></li></a>';
  148.                         }
  149.                     ?>
  150.                     </ul>
  151.                 </div>
  152.  
  153.                 <table class='table table-striped info'>
  154.                     <thead>
  155.                         <tr>
  156.                             <?php
  157.                                 foreach ($names as $elem) {
  158.                                     echo '<th scope="col">' . $elem . '</th>';
  159.                                 }
  160.                             ?>
  161.                         </tr>
  162.                     </thead>
  163.                     <tbody>
  164.                         <?php
  165.                             $lenPerPage = 4;
  166.  
  167.                             for ($i = $lenPerPage * ($page - 1); $i < min($lenPerPage * $page, count($info)); ++$i) {
  168.                                 $row = $info[$i];
  169.                                 echo '<tr>';
  170.                                
  171.                                 foreach ($row as $elem) {
  172.                                     echo '<td>' . $elem . '</td>';
  173.                                 }
  174.  
  175.                                 echo '</tr>';
  176.                             }
  177.                         ?>
  178.                     </tbody>
  179.                 </table>
  180.  
  181.                 <nav id='pagination' aria-label="Page navigation example">
  182.                     <ul class="pagination">
  183.                         <li class="page-item <?php if ($page == 1) { echo 'disabled'; } ?>">
  184.                             <a class="page-link" href='<?php echo $path . '&page=' . ($page - 1) ?>' aria-label="Previous">
  185.                                 <span aria-hidden="true">&laquo;</span>
  186.                                 <span class="sr-only">Previous</span>
  187.                             </a>
  188.                         </li>
  189.                         <li class="page-item <?php if ($lenPerPage * $page >= count($info)) { echo 'disabled'; } ?>">
  190.                             <a class="page-link" href='<?php echo $path . '&page=' . ($page + 1) ?>' aria-label="Next">
  191.                                 <span aria-hidden="true">&raquo;</span>
  192.                                 <span class="sr-only">Next</span>
  193.                             </a>
  194.                         </li>
  195.                     </ul>
  196.                 </nav>
  197.             </div>
  198.            
  199.             <div class='footer'>
  200.             </div>
  201.         </div>
  202.     </body>
  203. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement