<!DOCTYPE html>
<html>
    
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
         <?php include("../includes/header-links.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">
        <!--[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>
    
    <body>
        <?php include '../includes/header.php'; ?>
        <div class="container-fluid">
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
                <div class="span9" id="content">
                      <!-- morris stacked chart -->
                    <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">Edit Account</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                <?php

include '../includes/connection.php';
// Create connection
// Create connection

$id=$_SESSION['id'];
$sql = "SELECT * FROM users where id='$id'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $fullname=$row['name'];
        $user_name=$row['user_name'];
        $role=$row['role'];
        $contact=$row['contact'];
        $pword=$row['password'];
    }
} else {
    echo "0 results";
}

//mysqli_close($conn)
?>
                                     <form class="form-horizontal" action="" method="POST">
                                      <fieldset>
                                       

                                        <div class="control-group">
                                          <label class="control-label" for="focusedInput">Full Name</label>
                                          <div class="controls">
                                          <?php
                                           //if($_SESSION['role']=='attendant'){
                                          //if( $permissions['view_settings'] == 1){
                                          if( $permissions['other_settings'] != 1){
                                          ?>
                                          <input class="input-xlarge focused" id="focusedInput" type="text" name="fname" value="<?php echo $fullname; ?>" readonly>

                                          <?php
                                          }else{
                                            ?>
                                          <input class="input-xlarge focused" id="focusedInput" type="text" name="fname" value="<?php echo $fullname; ?>">

                                            <?php
                                          }
                                          ?>
                                          
                                          </div>
                                        </div>
                                       
                                        <div class="control-group">
                                          <label class="control-label" for="focusedInput">Contact</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="number" name="contact" value="<?php echo $contact; ?>">
                                          </div>
                                        </div>
                                         <div class="control-group">
                                          <label class="control-label" for="focusedInput">User Name</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="text" name="uname" value="<?php echo $user_name; ?>">
                                          </div>
                                        </div>

                                        
                            <div class="control-group">
                                          <label class="control-label" for="focusedInput">Password</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="password" name="password" >
                                          </div>
                                        </div>
                                       
                                        <div class="form-actions">
                                          <button type="submit" name="edit" class="btn btn-primary">Save changes</button>
                                          <a href="poducts.php"><button type="submit" class="btn">Cancel</button></a>
                                        </div>
                                      </fieldset>
                                    </form>
                                    <?php
                                    if(isset($_POST['edit'])){
                                        $name=$_POST['fname'];
                                        $uname=$_POST['uname'];
                                        $contactt=$_POST['contact'];
                                        $pwd=md5($_POST['password']);
                                        
                                   
                                if(!empty($_POST['password'])){
                                     $sql = "UPDATE users set name='$name', user_name='$uname', contact='$contact', password='$pwd' WHERE id='$id'";
                                }
                                else{

                                $sql = "UPDATE users set name='$name', user_name='$uname', contact='$contact' WHERE id='$id'";
                                 }

                                if (mysqli_query($con, $sql)) {
                                    $id_user=$_SESSION['id'];
                                          $activity="Updated Profile from (".$fullname.", ".$user_name.", ".$contact.") to (".$name.", ".$uname.", ".$contactt.")";
                                          include '../includes/store_logs.php';
                                          $_SESSION['fullname']=$name;
                                    ?>


                                    <div class="alert alert-success">
                                        <button class="close" data-dismiss="alert">&times;</button>
                                        <strong>Success!</strong> Account Updated Successfully.
                                        <meta http-equiv="refresh" content="0;URL='myacount.php'"/>  
                                    </div>
                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success">
                                        <button class="close" data-dismiss="alert">&times;</button>
                                        <strong>Success!</strong><?php echo "Error: " . $sql . "<br>" . mysqli_error($con); ?>
                                        <meta http-equiv="refresh" content="0;URL='myacount.php'"/>  
                                    </div>
                                    <?php
                                    
                                }

                                //mysqli_close($con);

                                    }
                                    // Create connection
                                

                                    ?>

                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                        <?php
                        //if($_SESSION['role']=="Super Admin" || $_SESSION['role']=="admin"){
                        if( $permissions['other_settings'] == 1){
                            ?>
                        <div class="row-fluid">
                            <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">System Setings</div>
                            </div>
    <?php
$sql = "SELECT * FROM business where business_id='$business'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $businessname=$row['business_name'];
        $businesscontact=$row['contact'];
        $businessemail=$row['email'];
        $businessaddress=$row['location'];
    }
} else {
    echo "0 results";
}
   ?>
                            <div class="block-content collapse in">
                                <div class="span12">
                                     <form class="form-horizontal" method="POST" action="">
                                      <fieldset>
                                        
                                        <div class="control-group">
                                          <label class="control-label" for="focusedInput">Business Name</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="text" placeholder="Business Name" name="name" value="<?php echo $businessname; ?>">
                                          </div>
                                        </div>
                                        <div class="control-group">
                                          <label class="control-label" for="focusedInput">Contact</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="text" placeholder="Contact" name="contact" value="<?php echo $businesscontact; ?>">
                                          </div>
                                        </div>
                                        <div class="control-group">
                                          <label class="control-label" for="focusedInput">Email</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="email" placeholder="Email" name="email" value="<?php echo $businessemail; ?>">
                                          </div>
                                        </div>
                                        <div class="control-group">
                                          <label class="control-label" for="focusedInput">Address</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="text" placeholder="Address" name="address" value="<?php echo $businessaddress; ?>">
                                          </div>
                                        </div>
                                        
                                       
                                        <div class="form-actions">
                                          <button type="submit" name="save_settings" class="btn btn-primary">Save changes</button>
                                          <button type="reset" class="btn">Cancel</button>
                                        </div>
                                      </fieldset>
                                    </form>
<?php
if(isset($_POST['save_settings'])){
    $name=$_POST['name'];
    $email=$_POST['email'];
    $contact=$_POST['contact'];
    $address=$_POST['address'];
    

   $sql = "UPDATE  business set business_name='$name', contact='$contact',location='$address',email='$email' where business_id='$business'";

if (mysqli_query($conn, $sql)) {
$id_user=$_SESSION['id'];
  $activity="Updated Business Details from<br> <b>Business Name:</b>".$businessname."<br><b>Contact</b> ".$businesscontact."<br><b> Email:</b>".$businessemail."<br><b> Address:</b>".$businessaddress.") <p>

  to <p>
  <b>Business Name:</b>".$name."<br><b>Contact</b> ".$contact."<br><b> Email:</b>".$email."<br><b> Address:</b>".$address.")";
  include '../includes/store_logs.php';

     ?><meta http-equiv="refresh" content="0;URL='myacount.php'" /><?php
} else {
    echo "Error updating record: " . mysqli_error($conn);
}
}
?>
                                </div>
                            </div>
                        </div>
                        </div>
                        <?php } ?>
                    </div>

<?php
//if ($_SESSION['business_id']==17 && $_SESSION['role']=="admin") {
  if( $permissions['business_id'] == 17 && $permissions['other_settings'] == 1){
   
$sqlbbb =mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM branches where branch_id='$branch'"));

  
?>
<div class="block-content collapse in">
                                <div class="span12">
                                     <form class="form-horizontal" method="POST" action="">
                                      <fieldset>
                                        
                                        <div class="control-group">
                                          <label class="control-label" for="focusedInput">Contact on receipt (+256) </label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" id="focusedInput" type="text" placeholder="Contact" name="contact" value="<?php echo $sqlbbb['contact']; ?>">
                                          </div>
                                        </div>
                                       
                                        <div class="form-actions">
                                          <button type="submit" name="save_contact" class="btn btn-primary">Save changes</button>
                                          <button type="reset" class="btn">Cancel</button>
                                        </div>
                                      </fieldset>
                                    </form>
                                    </div>
                                  </div>
<?php
}
?>
<?php
if(isset($_POST['save_contact'])){
   
    $contact=$_POST['contact'];
    

   $sql = "UPDATE  branches set contact='$contact' where branch_id='$branch'";

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


     ?><meta http-equiv="refresh" content="0;URL='myacount.php'" /><?php
} else {
    echo "Error updating record: " . mysqli_error($conn);
}
}
?>
              

                     <!-- wizard -->
    
                     <!-- validation -->
       


                </div>
            </div>
            <hr>
           <?php include '../includes/footer.php'; ?>
        </div>
        <!--/.fluid-container-->
        <link href="../vendors/datepicker.css" rel="stylesheet" media="screen">
        <link href="../vendors/uniform.default.css" rel="stylesheet" media="screen">
        <link href="../vendors/chosen.min.css" rel="stylesheet" media="screen">

        <link href="../vendors/wysiwyg/bootstrap-wysihtml5.css" rel="stylesheet" media="screen">

        <script src="../vendors/jquery-1.9.1.js"></script>
        <script src="../bootstrap/js/bootstrap.min.js"></script>
        <script src="../vendors/jquery.uniform.min.js"></script>
        <script src="../vendors/chosen.jquery.min.js"></script>
        <script src="../vendors/bootstrap-datepicker.js"></script>

        <script src="../vendors/wysiwyg/wysihtml5-0.3.0.js"></script>
        <script src="../vendors/wysiwyg/bootstrap-wysihtml5.js"></script>

        <script src="../vendors/wizard/jquery.bootstrap.wizard.min.js"></script>

	<script type="text/javascript" src="../vendors/jquery-validation/dist/jquery.validate.min.js"></script>
	<script src="../assets/form-validation.js"></script>
        
	<script src="../assets/scripts.js"></script>
        <script>

	jQuery(document).ready(function() {   
	   FormValidation.init();
	});
	

        $(function() {
            $(".datepicker").datepicker();
            $(".uniform_on").uniform();
            $(".chzn-select").chosen();
            $('.textarea').wysihtml5();

            $('#rootwizard').bootstrapWizard({onTabShow: function(tab, navigation, index) {
                var $total = navigation.find('li').length;
                var $current = index+1;
                var $percent = ($current/$total) * 100;
                $('#rootwizard').find('.bar').css({width:$percent+'%'});
                // If it's the last tab then hide the last button and show the finish instead
                if($current >= $total) {
                    $('#rootwizard').find('.pager .next').hide();
                    $('#rootwizard').find('.pager .finish').show();
                    $('#rootwizard').find('.pager .finish').removeClass('disabled');
                } else {
                    $('#rootwizard').find('.pager .next').show();
                    $('#rootwizard').find('.pager .finish').hide();
                }
            }});
            $('#rootwizard .finish').click(function() {
                alert('Finished!, Starting over!');
                $('#rootwizard').find("a[href*='tab1']").trigger('click');
            });
        });
        </script>
    </body>

</html>