<?php

include 'load.php';

$edit_qury=mysqli_query($conn,"SELECT * FROM ormsservices WHERE ormsservices.sid='$_GET[sid]'");
$edit_resalt=mysqli_fetch_array($edit_qury);

	if(isset($_GET['sid']) && !empty($_GET['sid']))
	{
		$id = $_GET['sid'];

		$stmt_edit = $DB_con->prepare('SELECT * FROM ormsservices WHERE sid =:sid');

		$stmt_edit->execute(array(':sid'=>$id));

		$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);

		extract($edit_row);

	}

	else

	{

		header("Location: services.php");

	}	

	if(isset($_POST['update']))

	{

		$category = $_POST['category'];
		$provider = $_POST['provider'];
		$sname = $_POST['sname'];
		$scode = $_POST['scode'];
		$scomission = $_POST['scomission'];	
		$status = $_POST['status'];
		$userid = $customer;
		$addcustomer = $addbycustomer;

		if(!isset($errMSG))

		{

			$stmt = $DB_con->prepare('UPDATE ormsservices

									     SET category=:category,
										 
											 provider=:provider,
		
										     sname=:sname,
											 
											 scode=:scode,

											 scomission=:scomission,

											 status=:status,
											 
											 userid=:userid,
											 
											 addcustomer=:addcustomer

								       WHERE sid=:sid');

			$stmt->bindParam(':category',$category);	
			$stmt->bindParam(':provider',$provider);	
			$stmt->bindParam(':sname',$sname);	
			$stmt->bindParam(':scode',$scode);	
			$stmt->bindParam(':scomission',$scomission);
			$stmt->bindParam(':status',$status);
			$stmt->bindParam(':userid',$userid);
			$stmt->bindParam(':addcustomer',$addcustomer);
			$stmt->bindParam(':sid',$id);

			if($stmt->execute()){

				$successMSG = "Services Successfully Updated ...";

				header("refresh:2;services.php"); // redirects image view page after 5 seconds.

			}

			else{

				$errMSG = "Sorry Data Could Not Updated !";

			}
	
		}

	}

?>

<!DOCTYPE html>
<html lang="en">

<head>
	
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Edit Services | Sony Investment | sonyinvestments.com</title>
	<?php
	require_once 'headercss.php';
	?>
</head>

<body>

    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">
	
<?php
require_once 'header.php';
?>

        <!--**********************************
            Sidebar start
        ***********************************-->
        <div class="deznav">
            <div class="deznav-scroll">
<?php

require_once 'sidebarmenu.php';

?>
            </div>
        </div>
        <!--**********************************
            Sidebar end
        ***********************************-->
		
        <!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <!-- row -->
            <div class="container-fluid">
				<div class="row">
				<div class="col-xl-12 col-xxl-12 col-sm-12">
				<div class="alert alert-danger bg-danger text-white" role="alert">
				<strong>Alert!</strong> ඔබගේ ගිනුම තහවුරු කිරීම අසම්පුර්නයි.<a href="identity_verify.php" class="btn btn-success float-right" style="padding: 0px 3px;">සම්පුර්න කරන්න</a>
				</div>
				</div>
				</div>
                <div class="row page-titles mx-0">
                    <div class="col-sm-6 p-md-0">
                        <div class="welcome-text">
                            <h4>Edit Services</h4>
                        </div>
                    </div>
                    <div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                            <li class="breadcrumb-item active"><a href="videoclass.php">Services</a></li>
                            <li class="breadcrumb-item active"><a href="edit_videoclass.php">Edit Services</a></li>
                        </ol>
                    </div>
                </div>
				
				<div class="row">
					<div class="col-xl-12 col-xxl-12 col-sm-12">
                        <div class="card">
                            <div class="card-header">
								<h5 class="card-title">Edit Services</h5>
							</div>
							<div class="card-body">
							<?php

							if(isset($errMSG)){

							?>
			
							<div class="alert alert-danger alert-dismissible alert-alt solid fade show">
							<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i class="mdi mdi-close"></i></span></button>
							<strong>Error!</strong> <?php echo $errMSG; ?>
							</div>

							<?php

							}
	
							else if(isset($successMSG)){

							?>
			
							<div class="alert alert-success alert-dismissible alert-alt solid fade show">
							<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i class="mdi mdi-close"></i></span></button>
							<strong>Success!</strong> <?php echo $successMSG; ?>.
							</div>

							<?php

							}

							?>
                            <form method="POST" autocomplete="off" enctype="multipart/form-data">
									<div class="row">
										<div class="col-lg-4 col-md-4 col-sm-12">
											<div class="form-group">
												<label class="form-label">Category</label>
												<select name="category" class="form-control" required>
												<option value="<?php

						$id = $category; 

						$query = $DB_con->prepare('SELECT cid FROM ormscategory WHERE cid='.$id);

						$query->execute();

						$result = $query->fetch();

						echo $result['pid'];

						 ?>"><?php

						$id = $category;  

						$query = $DB_con->prepare('SELECT catename FROM ormscategory WHERE cid='.$id);

						$query->execute();

						$result = $query->fetch();

						echo $result['catename'];

						 ?></option>
					     <?php
								require_once 'dbconfig4.php';
								
								$stmt = $DB_con->prepare('SELECT * FROM ormscategory where status="Active" ORDER BY cid');

								$stmt->execute();

								if($stmt->rowCount() > 0)

								{

								while($row=$stmt->fetch(PDO::FETCH_ASSOC))

								{

								extract($row);

								?>
                        <option value="<?php echo $row['cid']; ?>"><?php echo $row['catename']; ?></option>
                        <?php } 

								}
								?>
												</select>
											</div>
										</div>
										<div class="col-lg-4 col-md-4 col-sm-12">
											<div class="form-group">
												<label class="form-label">Provider</label>
												<select name="provider" class="form-control" required>
												<option value="<?php

						$id = $provider; 

						$query = $DB_con->prepare('SELECT pid FROM ormsproviders WHERE pid='.$id);

						$query->execute();

						$result = $query->fetch();

						echo $result['pid'];

						 ?>"><?php

						$id = $provider;  

						$query = $DB_con->prepare('SELECT pname FROM ormsproviders WHERE pid='.$id);

						$query->execute();

						$result = $query->fetch();

						echo $result['pname'];

						 ?></option>
					     <?php
								require_once 'dbconfig4.php';
								
								$stmt = $DB_con->prepare('SELECT * FROM ormsproviders where status="Active" ORDER BY pid');

								$stmt->execute();

								if($stmt->rowCount() > 0)

								{

								while($row=$stmt->fetch(PDO::FETCH_ASSOC))

								{

								extract($row);

								?>
                        <option value="<?php echo $row['pid']; ?>"><?php echo $row['pname']; ?></option>
                        <?php } 

								}
								?>
												</select>
											</div>
										</div>
										<div class="col-lg-4 col-md-4 col-sm-12">
											<div class="form-group">
												<label class="form-label">Service Name</label>
												<input type="text" name="sname" class="form-control" value="<?php echo $sname; ?>" required>
											</div>
										</div>
										<div class="col-lg-4 col-md-4 col-sm-12">
											<div class="form-group">
												<label class="form-label">Service Code</label>
												<input type="text" name="scode" class="form-control" value="<?php echo $scode; ?>" required>
											</div>
										</div>
										<div class="col-lg-4 col-md-4 col-sm-12">
											<div class="form-group">
												<label class="form-label">Comission Rate</label>
												<input type="text" name="scomission" class="form-control" value="<?php echo $scomission; ?>" required>
											</div>
										</div>
										<div class="col-lg-4 col-md-4 col-sm-12">
											<div class="form-group">
												<label class="form-label">Status</label>
												<select name="status" class="form-control" required>
												<option value="Active"<?php if($status=="Active"){echo "selected";} ?>>Active</option>
												<option value="Deactive"<?php if($status=="Deactive"){echo "selected";} ?>>Deactive</option>
												</select>
											</div>
										</div>
										<div class="col-lg-12 col-md-12 col-sm-12">
											<input type="submit" name="update" class="btn btn-primary" value="Update">
											<a class="btn btn-light" href="services.php"><i class="fa fa-times"></i> Cancel</a>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
				
            </div>
        </div>
        <!--**********************************
            Content body end
        ***********************************-->



        <?php
		require_once 'footer.php';
		?>

		<!--**********************************
           Support ticket button start
        ***********************************-->

        <!--**********************************
           Support ticket button end
        ***********************************-->


    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <?php
	require_once 'footerjs.php';
	?>
    
</body>
</html>