<?php
require_once("header.php");
require_once("menu.php");


if(isset($_REQUEST['edit']))
{
    $team_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_team_id($team_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
    $update_team['id'] = $_POST['id'];
    $update_team['team_name'] = $_POST['team_name'];
    $update_team['position'] = $_POST['position'];
	$update_team['team_email'] = $_POST['team_email'];
	$update_team['team_contact_no'] = $_POST['team_contact_no'];
    $update_team['team_telephone'] = $_POST['team_telephone'];
	$update_team['team_details'] = $_POST['team_details'];
	$update_team['linkedin'] = $_POST['linkedin'];
	
        
        if(!empty($_FILES['team_profile']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/team/';      
            $tempname = $_FILES['team_profile']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['team_profile']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_team['team_profile'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_team['team_profile'] =$_POST['team_profile1'];
        }
     
    $ex = $obj->update_team($update_team);
    echo '<script>window.location="team.php"</script>';
}

if(isset($_POST['submit']))
{
	$team_info['team_name'] = $_POST['team_name'];
    $team_info['position'] = $_POST['position'];
    $team_info['team_email'] = $_POST['team_email'];
	$team_info['team_contact_no'] = $_POST['team_contact_no'];
	$team_info['team_telephone'] = $_POST['team_telephone'];
	$team_info['team_details'] = $_POST['team_details'];
	$team_info['linkedin'] = $_POST['linkedin'];
	$server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/team/';
        
        if(!empty($_FILES['team_profile']['name']))
        {            
            $tempname = $_FILES['team_profile']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['team_profile']['name'];
            move_uploaded_file($tempname,$upload_name);
            $team_info['team_profile'] = $server_url."/".$upload_name;
        }
	
	
    $ex = $obj->insert_team($team_info);
    echo '<script>window.location="team.php"</script>';
}

?>

<div id="layoutSidenav_content">
<main class="mt-4">
    <div class="container-fluid">
        
        <div class="card mb-4">
            <div class="card-header">
                <i class="fas fa-check-square mr-1"></i>Add Team Member Details
                <a href="team.php" class="btn btn-primary btn-sm float-right">Back</a>
            </div>
            <div class="card-body">
                <form method="post" name="frm" id="frm" enctype="multipart/form-data">
                   <input type="hidden" name="id" value="<?php echo $team_id;?>">
                    
                    
					
					<div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control" name="team_name" required value="<?php echo $row['team_name'];?>">
                    </div>
					<div class="form-group">
                        <label>Position</label>
                        <input type="text" class="form-control" name="position" required value="<?php echo $row['position'];?>">
                    </div>
					<div class="form-group">
                        <label>Email</label>
                        <input type="text" class="form-control" name="team_email" required value="<?php echo $row['team_email'];?>">
                    </div>
					<div class="form-group">
                        <label>Mobile No</label>
                        <input type="text" class="form-control" name="team_contact_no" required value="<?php echo $row['team_contact_no'];?>">
                    </div>
					<div class="form-group">
                        <label>Telephone No</label>
                        <input type="text" class="form-control" name="team_telephone" required value="<?php echo $row['team_telephone'];?>">
                    </div>
					<div class="form-group">
                        <label>Member Details</label>
                        <textarea id="w3review" name="team_details" rows="6" cols="50" class="tinymce"><?php echo $row['team_details'];?></textarea>
				   </div>
				   	<div class="form-group">
                        <label>LinkedIn</label>
                        <input type="text" class="form-control" name="linkedin" required value="<?php echo $row['linkedin'];?>">
                    </div>
					
					
					
					<div class="form-group">
                        <label>Profile </label><br>
						
                       <input type="file" class="" name="team_profile" value="<?php echo $row['team_profile'];?>">
                       <input type="hidden" name="team_profile1" value="<?php echo $row['team_profile'];?>">
                       <img src="<?php echo $row['team_profile'];?>"  style="width: 100px;">
                     </div>
					 
					
					
                    <?php if(isset($_REQUEST['edit']))
                    { ?> 
                        <button type="submit" class="btn btn-primary" name="update">Update</button>
                    <?php } 
                    else
                    { ?>
                        <button type="submit" class="btn btn-primary" name="submit">Submit</button>
                    <?php } ?>
                </form> 
            </div>
        </div>
    </div>
</main>

<script>
    var url = "team.php";
</script>

<?php require_once("footer.php");?>

