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


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

	$new_device_servid=$_POST['servid'];
	$new_device_custid=$_POST['custid'];
	$new_device_servname=$_POST['servname'];
	$new_asset_type=$_POST['asset_type'];

if($new_asset_type==0){
echo "You must select a Asset Type";
}
else{
		$insert_device ="INSERT INTO `ASSET` (SERVICE_ID, CUSTOMER_ID, SERVICE_NAME, ASSET_TYPE_ID) VALUES ('$new_device_servid' , '$new_device_custid', '$new_device_servname', '$new_asset_type')";
			mysql_query($insert_device)or die ('Add Failed</br>'.mysql_error());
}
}
?>

<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>Add Asset</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>Asset ID</b></label>
					<div class="col-md-5">
						<input type="text" name="servid" class="form-control" placeholder="AS123456">
					</div>
				</div>
		<div class="form-group">
			<div class="col-md-3">
				<label class="control-label"><b>Customer ID</b></label>
			</div>
			<div class="col-md-5">
				<input type="text"  name="custid" class="form-control" placeholder="123456">
			</div>
		</div>
		<div class="form-group">
			<label class="col-md-3 control-label"><b>Asset Name</b></label>
			<div class="col-md-5">
					<input type="text" name="servname" class="form-control" placeholder="Device.hostirian.com">
			</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-group">
			<label class="col-md-3 control-label"><b>Asset Type</b></label>
			<div class="col-md-5">
				<div class="input-group">
					<select class="select2" name="asset_type">
					<option value="0">Please Selet Asset Type</option>
							<?php 
						$asset_type_fetch=mysql_query("SELECT ID, TYPE FROM ASSET_TYPE");

						while ($assetrow = mysql_fetch_array($asset_type_fetch)){
							$asset_type= $assetrow['TYPE'];
						        $asset_type_id = $assetrow['ID'];
        						?>
							<option value="<?php echo $asset_type_id;?>"><?php echo $asset_type;?></option>
						<?php
						}
						?>


					</select>
				</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">Add Asset</button>
			<button type="button" class="btn btn-default" onclick="resetForm()">Clear</button> </center>
				<script>
					function resetForm() {
						document.getElementById("form").reset();
					}
				</script>
		</div>
	</div>
</div>
</form>
</div>
</div>
</div>
</div>
<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 Assets</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>Service ID</b></th>
              <th><b>Customer ID</b></th>
	      <th><b>Device Name</b></th>
	      <th><b>Asset Type</b></th>
            </tr>
          </thead>
          <tbody>
<?php


$tasks_result = mysql_query('SELECT a.SERVICE_ID as asset_service_id, a.CUSTOMER_ID as asset_customer_id, a.SERVICE_NAME as asset_service_name, t.TYPE as asset_type  FROM ASSET AS a INNER JOIN ASSET_TYPE as t on a.ASSET_TYPE_ID=t.ID');

while ($row=mysql_fetch_array($tasks_result)){
        $service_id=$row['asset_service_id'];
        $customer_id=$row['asset_customer_id'];
	$service_name=$row['asset_service_name'];
	$asset_type_id=$row['asset_type'];
        


?>
            <tr>
              <td><?php echo $service_id;?></td>
              <td><?php echo $customer_id;?></td>
              <td><?php echo $service_name;?></td>
	      <td><?php echo $asset_type_id;?></td>
            </tr>
<?php
}
?>
          </tbody>
        </table>
      </div>
    </div>

	</div>
</div>	
