<?php
	include("includes/dbconfig.php");
	$pagetitle = "Customers";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				<section class="content-header">
					<h4>Customers</h4>
					<ol class="breadcrumb">
					</ol>
				</section>

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<?php
						if($_SESSION["connectedusergroup"] == 3 || $_SESSION["connectedusergroup"] == 4 || $_SESSION["connectedusergroup"] == 1)
						{
					?>
					<div class="row">
						<div class="col-md-12">
							<div id="servererrormessage">
							</div>
						</div>
					</div>

                    <div class="row">
						<div class="col-md-12">
							<div style="">
                                <?php
                                if(isset($_POST['customer_name'])){
                                    $customer_name = trim($_POST['customer_name']);
                                    $customer_phone = trim($_POST['customer_phone']);
                                    $customer_email = trim($_POST['customer_email']);
                                    $customer_claim = trim($_POST['customer_claim']);

                                    DB::$error_handler = false;
		                            DB::$throw_exception_on_error = true;
		
                                    try
                                    {
                                       
                                        $trxnConnextn = new MeekroDB();
                                        $trxnConnextn->startTransaction();

                                        $trxnConnextn->insert
                                        ('customers', 
                                            array
                                            (
                                                'name' => $customer_name,
                                                'phone' => $customer_phone,
                                                'email' => $customer_email,
                                                'status' => 1,
                                                'claim' => $customer_claim
                                            )
                                        );


                                        $insertedrecord = $trxnConnextn->insertId();
                                        $trxnConnextn->commit();
                                    }
                                    catch(MeekroDBException $e)
		                            {
                                        $err = $err.$e->getMessage()."<br>";
                                        $err = $err.$e->getQuery()."<br>";
                                        $trxnConnextn->rollback();
                                        $errormessage = "<div class=\"alert alert-danger\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\"aria-hidden=\"true\">&times;</button>" . $err . "</div>";
                                        $server_response[] = array('issaved' => 0, 'message' => $errormessage);
                                        DB::$error_handler = 'meekrodb_error_handler';
                                        DB::$throw_exception_on_error = false;
                                        echo json_encode($server_response);
                                        exit();
                                    }
                                }
                                    
                                ?>
							</div>
						</div>
					</div>
				
					<div class="row">
						<div class="col-md-12">
							<div class="card card-primary" id="customerdetails" style="height: 500px;">
								<div class="card-body">
									
													
									
									<div>
										<div id="">
                                            <form method="post" action="createcustomer.php">
											<table class="table table-hover"  id="">
												
												<tbody>
													<tr>
														<td><b>Name</b></td><td><input type="text" name="customer_name" /></td>
													</tr>
													<tr>
														<td><b>Phone</b></td><td><input type="text" name="customer_phone"  /></td>
													</tr>
													<tr>
														<td><b>Email</b></td><td><input type="text" name="customer_email"  /></td>
													</tr>
													 <input type="hidden" name="customer_claim" value="2"														/></td>
													 
													<tr>
														<td></td><td><input type="submit" name="submit" value="Create" /></td>
													</tr>
												</tbody>
											</table>
                                            </form>
										</div>
									</div>
								</div><!-- /.card-body -->
							</div><!-- /.card -->
						</div>
						
						
					</div>
					<?php
						}
						else
						{
					?>
					<div class="alert alert-danger alert-dismissable">
						<i class="fa fa-ban-circle"></i>
						Limited Access
					</div>
					<?php
						}
					?>
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->

			 
		</div><!-- ./wrapper -->
		
		
		
		<?php include ('includes/general_footer.php')?>
		
		<script src="plugins/bert/jquery.price_format.min.js" type="text/javascript"></script>
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		<script src="plugins/bert/cashsalesregister.js" type="text/javascript"></script>
	</body>
</html>