<?php
	include(''. $config['LocalPath'] . '/includes/.sql_con.php');

if(isset($_POST['new_job_name'])){

	$edit_job_name=$_POST['new_job_name'];
	$edit_job_sop=$_POST['new_job_sop'];
	$edit_job_id=$_POST['edit_job_id'];
	$edit_job_time=$_POST['new_job_time'];

		$update_job = "UPDATE `JOB` SET `JOB_NAME`='$edit_job_name', `SOP_URL`='$edit_job_sop', `COMPLETE_TIME`='$edit_job_time' WHERE `JOB_ID`='$edit_job_id'";
			mysql_query($update_job)or die ('Update Failed</br>'.mysql_error());
}
//else{
if(isset($_POST['current_job_id'])){
        $posted_job_id=$_POST['current_job_id'];
	echo $posted_job_id;	
		$get_job_info = mysql_query("SELECT JOB_NAME, SOP_URL, COMPLETE_TIME FROM JOB WHERE JOB_ID='$posted_job_id'");
			while ($rowinfo=mysql_fetch_array($get_job_info)){
					$posted_job_name=$rowinfo['JOB_NAME'];
					$posted_job_sop=$rowinfo['SOP_URL'];
					$posted_job_time=$rowinfo['COMPLETE_TIME'];
			}

?>

<div class="row">
	<div class="col-lg-5 col-lg-offset-3 col-md-5 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-5 col-xs-offset-3">
		<div class="card card-mini">
			<div class="card-header">
				<div class="card-title"><b><center>Edit Job</center></b></div>
			</div>
		<div class="card-body">

			<form class="form form-horizontal" method="post" id="form">
				<div class="form-group">
					<label class="col-md-3 control-label"><b>Job Name</b></label>
					<div class="col-md-5">
						<input type="text" name="new_job_name" class="form-control" Value="<?php echo $posted_job_name;?>">
					</div>
				</div>
		<div class="form-group">
			<div class="col-md-3">
				<label class="control-label"><b>SOP URL</b></label>
			</div>
			<div class="col-md-5">
				<input type="text"  name="new_job_sop" class="form-control" Value="<?php echo $posted_job_sop;?>">
				<input type="hidden" name="edit_job_id" value="<?php echo $posted_job_id;?>"/>
			</div>
		</div>

                <div class="form-group">
                        <div class="col-md-3">
                                <label class="control-label"><b>Estimated Time to Complete</b></label>
                        </div>
                        <div class="col-md-3">
				<div class="input-group">
                                <input type="text"  name="new_job_time" class="form-control" Value="<?php echo $posted_job_time;?>">
                                        <span class="input-group-addon">Mins</span>
				</div>
                        </div>
                </div>
		<!--<div class="form-group">
			<label class="col-md-3 control-label">Type</label>
			<div class="col-md-9">
				<div class="radio radio-inline">
					<input type="radio" name="radio4" id="radio10" value="option10">
					<label for="radio10">
					Global
					</label>
				</div>
				<div class="radio radio-inline">
					<input type="radio" name="radio4" id="radio11" value="option11" checked>
					<label for="radio11">
					Local
					</label>
				</div>
			</div>
		</div>-->
<div class="form-footer">
	<div class="form-group">
		<div class="col-md-5 col-md-offset-3">
			<center>	<button type="submit" class="btn btn-primary">Edit Job</button>
		</div>
	</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php 
}
else{
?>
<div class="row">
	<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
		<div class="card card-mini">
      <div class="card-header">
        <div class="card-title"><b><center>Active Jobs</center></b></div>
        <ul class="card-action">
          <li>
            <a href="#" onClick="MyFunction();">
              <i class="fa fa-refresh"></i>
            </a>
		<script>
			function MyFunction() {
				location.reload();
			}
		</script>
          </li>
        </ul>
      </div>
      <div class="card-body no-padding table-responsive">
        <table class="table card-table">
          <thead>
            <tr>
              <th><b>Job Name</b></th>
              <th><b>SOP URL</b></th>
	      <th><b>Time To Complete</b></th>
	      <th><b>Edit Job</b></th>
            </tr>
          </thead>
          <tbody>
<?php


$job_list_result = mysql_query('SELECT JOB_ID , JOB_NAME, SOP_URL, COMPLETE_TIME FROM JOB');

while ($row=mysql_fetch_array($job_list_result)){
        $current_job_id=$row['JOB_ID'];
        $job_name=$row['JOB_NAME'];
	$job_sop=$row['SOP_URL'];
	$job_complete_time=$row['COMPLETE_TIME'];
        


?>
            <tr>
              <td><?php echo $job_name;?></td>
              <td><a href="<?php echo $job_sop;?>"><?php echo $job_sop;?></a></td>
	      <td><?php if ($job_complete_time == ''){
				echo " Not Set";
			}
			else{
				echo "$job_complete_time Mins";
			}
		?></td>
              <td><form  method="post"><input type="hidden" name="current_job_id" value="<?php echo $current_job_id;?>"><input type="hidden" name="job_name" value="<?php echo $job_name;?>" />
		<input type="hidden" name="job_sop" value="<?php echo $job_sop?>" /><button type="Submit" class="btn btn-primary">Edit Job</button></form></td>
            </tr>
<?php
}
?>
	<tr>
		<td colspan='3' align='center'><a href="addjob.php"><button class="btn btn-primary">Add A Job</button></td>
	</tr>
          </tbody>
        </table>
      </div>
    </div>

	</div>
</div>	
<?php 
}
?>
