Guest User

Untitled

a guest
Mar 9th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.18 KB | None | 0 0
  1. <?php
  2.  
  3.     $ser = "localhost";
  4.     $user = "root";
  5.     $pass = "";
  6.     $db = "machineschedule";
  7.  
  8.     $con = mysqli_connect($ser, $user, $pass, $db) or die( "connection failed" );
  9.  
  10.     $sql = "SELECT `status`, `startingtime` , `endingtime` FROM `machine2` ORDER BY `startingtime`";
  11.     $result = mysqli_query( $con, $sql );  
  12.  
  13.     if(mysqli_num_rows($result) == 0)
  14.     {
  15.         echo "<script> location.href='http://localhost/machineschedule/nodata.php'; </script>";
  16.     }
  17.  
  18.     mysqli_close($con);
  19.  
  20.     // echo date( 'Y-m-d H:i:s' );
  21.  
  22.     function printDiv($time , $status='' , $laststatus='',$tsClass='')
  23.     {
  24. ?>
  25.         <div class='timestamp <?=$tsClass; ?>'>
  26.            
  27.             <span class='time'>
  28.                 <?= date( 'H:i:s' , strtotime($time));?>
  29.             </span>
  30.  
  31.             <?php
  32.             if( simpleStatus($status) != simpleStatus($laststatus) )
  33.             {
  34.             ?>
  35.                 <span class='vertical-line'></span>
  36.             <?php
  37.             }
  38.             ?>
  39.  
  40.  
  41.             <div class='line <?= $status; ?>'></div>
  42.         </div>
  43. <?php
  44.     }
  45.  
  46.     function newContainer($time)
  47.     {
  48.         //closing last container div
  49. ?>
  50.         </div>
  51.         <div class="date-title"><?= date('d-m-Y', strtotime($time)); ?></div>
  52.         <div class="container">
  53.            
  54. <?php
  55.     }
  56.  
  57.     function continueNewContainer($time,$status)
  58.     {
  59.         //closing last container div
  60. ?>
  61.  
  62.         </div>
  63.         <div class="date-title"><?= date('d-m-Y', strtotime($time)); ?></div>
  64.         <div class="container">
  65.         <div class='timestamp start-arrow'>
  66.         <div class='line <?= $status; ?>'></div>
  67.         </div>
  68.            
  69. <?php
  70.     }
  71.  
  72.     function simpleStatus($status)
  73.     {
  74.         if($status == "working")
  75.         {
  76.             return "working";
  77.         }
  78.         return "off";
  79.     }
  80.  
  81. ?>
  82.  
  83. <link rel="stylesheet" href="./css/main.css" />
  84. <meta name="viewport" content="width=device-width, initial-scale=1">
  85.  
  86.     <?php
  87.     $row = mysqli_fetch_array( $result );
  88.  
  89.     newContainer($row['startingtime']);
  90.  
  91.  
  92.     printDiv( $row['startingtime'], simpleStatus($row['status']) );
  93.     $endtimetemp = $row['endingtime'];
  94.     $laststatus = $row['status'];
  95.  
  96.     while( $row = mysqli_fetch_array( $result ) )
  97.     {
  98.         if( strtotime($row['startingtime']) != strtotime( $endtimetemp ) )
  99.         {
  100.             printDiv( $endtimetemp , 'no-data' ,$laststatus);
  101.             if( date('d-m-Y', strtotime($endtimetemp)) != date('d-m-Y', strtotime($row['startingtime'])) )
  102.             {
  103.                 newContainer($row['startingtime']);
  104.             }
  105.         }
  106.         if( date('d-m-Y', strtotime($row['startingtime'])) != date('d-m-Y', strtotime($row['endingtime'])) )
  107.         {  
  108.             printDiv( $row['startingtime'], $row['status'] , $laststatus,'force-line' );
  109.             continueNewContainer( $row['endingtime'], $row['status'] );
  110.         }
  111.  
  112.         else
  113.         {
  114.             printDiv( $row['startingtime'], $row['status'], $laststatus );
  115.         }
  116.  
  117.         $endstatustemp = $row['status'];
  118.         $endtimetemp = $row['endingtime'];
  119.     }
  120.  
  121.     printDiv( $endtimetemp );
  122.  
  123.     $con = mysqli_connect($ser, $user, $pass, $db) or die( "connection failed" );
  124.  
  125.     $sql1 = "SELECT `status`, `startingtime` , `endingtime` FROM `machine2` ORDER BY `startingtime`";
  126.     $result = mysqli_query( $con, $sql1 );  
  127.    
  128.     if(mysqli_num_rows($result) == 0)
  129.     {
  130.         echo "<script> location.href='http://localhost/machineschedule/nodata.php'; </script>";
  131.     }
  132.     mysqli_close($con);
  133.  
  134.  
  135.     ?>
  136. </div>
  137.  
  138.  
  139. <table class="data-table">
  140.         <thead>
  141.             <tr>
  142.                 <th>Status</th>
  143.                 <th>Starting Time</th>
  144.                 <th>Ending Time</th>
  145.             </tr>
  146.         </thead>
  147.         <tbody>
  148.             <?php while($row = mysqli_fetch_array($result)){?>
  149.             <tr <?php echo "class=".$row['status']." ";   ?>>
  150.                 <td><?php echo $row["status"]; ?></td>
  151.                 <td><?php echo $row["startingtime"]; ?></td>
  152.                 <td><?php echo $row["endingtime"]; ?></td>
  153.             </tr>
  154.             <?php } ?>
  155.         </tbody>
  156.     </table>
Add Comment
Please, Sign In to add comment