<?php
session_start();
error_reporting(0);
@ini_set('display_errors', 0);
$id_user=$_SESSION['id'];
$branch=$_SESSION['branch_id'];
$business=$_SESSION['business_id'];
?>
<!DOCTYPE html>
<html>
    
    <head>
        <?php include("../includes/header-links.php");
           
$permissions = mysqli_fetch_array(mysqli_query($con,"SELECT * FROM  
  permissions,users WHERE  permissions.role_id = users.role 
  AND users.id='$id_user' AND users.business_id ='$business' AND users.branch_id ='$branch'"));

if($permissions['view_logs'] != 1){
?>
<script>window.location="../main/dashboard.php"</script>
<?php
}
?>
        <!-- Bootstrap -->
        <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
        <link href="../assets/styles.css" rel="stylesheet" media="screen">
        <link href="../assets/DT_bootstrap.css" rel="stylesheet" media="screen">
        <link rel="stylesheet" href="../data-table-css/bootstrap-table.css">
    <link rel="stylesheet" href="../data-table-css/bootstrap-editable.css">
        <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendors/flot/excanvas.min.js"></script><![endif]-->
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script src="../vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    </head>
    </head>
    
    <body>
        <?php include '../includes/header.php'; ?>
        <div class="container-fluid">
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
                <div class="span10" id="content">

                     <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">Activity Logs</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                   
                                   <?php
include '../includes/connection.php';
                                   // Create connection
$sql = mysqli_query($con,"SELECT id, (select name from users where id=logs.user_id) as name, activity, date_time FROM logs where branch_id='$branch' order by id DESC");
//$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($sql) > 0) {
    // output data of each row
    


                                   ?>
                                    
                                    <div id="toolbar">
                                        <select class="form-control">
                                                <option value="">Export Basic</option>
                                                <option value="all">Export All</option>
                                                <option value="selected">Export Selected</option>
                                            </select>
                                    </div>
                                    <table  id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="false" data-show-pagination-switch="true" data-show-refresh="false" data-key-events="true" data-show-toggle="false" data-resizable="false" data-cookie="true"
                                        data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" data-export-options='{"fileName": "Testing_filename"}'>
                                        <thead>
                                            <tr>
                                                <th>S/NO</th>
                                                <th width="20%">User Name</th>
                                                <th>Activity</th>
                                                <th width="20%">Date/Time</th>
                                                

                                            </tr>
                                        </thead>
                                        <tbody>
                                        
                                        <?php
										$no = 0;
										while($row = mysqli_fetch_assoc($sql)) {
										$no++;
												?>
										<tr class="gradeU">
                                                <td><?php echo $no; ?></td>
                                                <td><?php echo $row['name']; ?></td>
                                                <td><?php echo $row['activity']; ?></td>
                                                <td class="center"><?php echo $row['date_time']; ?></td>
                                                
                                             
                                            </tr>
                                            
                                            <?php


  }
} else {
    echo "0 results";
}

mysqli_close($con);


                                        ?>
                                            
                                        </tbody>
                                    </table>
                                    
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>
                </div>
            </div>
            <hr>
            <?php include '../includes/footer.php'; ?>
        </div>
        <!--/.fluid-container-->

        <script src="vendors/jquery-1.9.1.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <script src="vendors/datatables/js/jquery.dataTables.min.js"></script>


        <script src="assets/scripts.js"></script>
        <script src="assets/DT_bootstrap.js"></script>
        <script>
        $(function() {
            
        });
        </script>
   

<?php


if(isset($_POST['add'])){
	include 'connection.php';
$product_name=$_POST['name'];
$quantity=$_POST['quantity'];
$unit=$_POST['unit'];
	// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO products (product_name, quantity, price)
VALUES ('$product_name', '$quantity', '$unit')";

if (mysqli_query($conn, $sql)) {


    $id_user=$_SESSION['id'];
  $activity="Added a new product ".$product_name;
  include 'store_logs.php';
	?>


    <meta http-equiv="refresh" content="0;URL='savepurchase.php?product=<?php echo $product_name; ?>&quantity=<?php echo $quantity; ?>&price=<?php echo $unit; ?>'" />  
    <?php
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
}

?>
  <script src="../vendors/jquery-1.9.1.js"></script>
        <script src="../bootstrap/js/bootstrap.min.js"></script>
        <script src="../vendors/datatables/js/jquery.dataTables.min.js"></script>
<script src="../data-table-js/bootstrap-table.js"></script>
    <script src="../data-table-js/tableExport.js"></script>
    <script src="../data-table-js/data-table-active.js"></script>
    <script src="../data-table-js/bootstrap-table-editable.js"></script>
    <script src="../data-table-js/bootstrap-editable.js"></script>
    <script src="../data-table-js/bootstrap-table-resizable.js"></script>
    <script src="../data-table-js/colResizable-1.5.source.js"></script>
    <script src="../data-table-js/bootstrap-table-export.js"></script>

        <script src="../assets/scripts.js"></script>
        <script src="../assets/DT_bootstrap.js"></script>
        <script>
        $(function() {
            
        });
        </script>
  </body>
</html>
