
<?php
	session_start();
	$user_id=$_SESSION['LOGIN_USERID'];
	extract($_REQUEST);
	include("../../php_crud/my_class.php");
	$obj = new my_class();
	if($id!=''){
		$func = "update_equipment_failure";
		$button = "Update Equipment Failure";
		$failure_info = $obj->Details_By_Cond("AQUATIC.TBLPGCB_FAILURESTUDY@AQUATIC227","ID=$id AND FLAG='A'");
		$stationid = $failure_info['STATIONID'];
		//echo $stationid;
		$station_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_BASICINFOMST@AQUATIC227","NEW_ID='$stationid'");
		$upazilaid = $station_info['UPAZILACODE'];
		$districtid = $station_info['DISTRICTCODE'];
		$upazila_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_UPAZILA@AQUATIC227","ID=$upazilaid");
		$district_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_DISTRICTINFO@AQUATIC227","ID=$districtid");
		$testdatetime = date("d-m-Y",strtotime($failure_info['TESTDATETIME']));
		$occurancedate = date("d-m-Y",strtotime($failure_info['DATEANDTIMEOFFAULTE']));
	} else {
		$testdatetime = date("d-m-Y");
		$occurancedate = date("d-m-Y");
		$func = "save_equipment_failure";
		$button = "Save Equipment Failure";
		
	}
?>
<style>
	input[type="text"], textarea, select{
		width: 100%;
	}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<div class="row-fluid" id="form_data">
<?php
// if ($_SESSION['add'] == 'Y') {
    ?>
        <form action="" id="equipmentFailureForm" method="post">    
			<div class="row-fluid">
				<div class="row-fluid">
					<legend>Equipment Failure Study</legend> 	
				</div>
				<input type="hidden" name="id" value="<?php echo $id;?>">
				<div class="row-fluid">
					<table style="width: 100%; margin-top: -10px;">
						<tr>
							<td style="padding-left: 10px; padding-bottom: 10px;"><b>Device Sl No:</b></td>
							<td>
								<input style="width: 90%;" type="text" name="device_sl_no" id="device_sl_no" class="form-control" placeholder="Device Sl No." readonly value="<?php echo $station_info['DEVICESLNO'];?>" />
							</td>
							<td style="padding-left: 10px; padding-bottom: 10px;">
								<b>
								<a href="#modal_device_list" data-toggle="modal" data-target="#modal_device_list" onclick="load_device_info()" style="border-bottom: 1px solid blue; color: blue;">
									Pick</a>
								</b>
							</td>
							<td>
								<input style="width: 90%;" type="text" name="pick_no" id="pick_no" class="form-control" readonly value="<?php echo $station_info['ID'];?>" />
							</td>
						</tr>
						<tr>
							<td style="padding-left: 10px; padding-bottom: 10px;"><b>New ID:</b></td>
							<td>
								<input style="width: 90%;" type="text" name="new_id" id="new_id" class="form-control" placeholder="" readonly value="<?php echo $station_info['NEW_ID'];?>" />
							</td>
							<td style="padding-left: 10px; padding-bottom: 10px;"><b>Old ID:</b></td>
							<td>
								<input style="width: 90%;" type="text" name="old_id" id="old_id" class="form-control" placeholder="" readonly value="<?php echo $station_info['OLD_ID'];?>" />
							</td>
						</tr>
						<tr>
							<td style="padding-left: 10px; padding-bottom: 10px;"><b>Upazila:</b></td>
							<td>
								<input style="width: 90%;" type="text" name="upazila" id="upazila" class="form-control" placeholder="" readonly value="<?php echo $upazila_info['UPAZILANAME']; ?>" />
							</td>
							<td style="padding-left: 10px; padding-bottom: 10px;"><b>District:</b></td>
							<td>
								<input style="width: 90%;" type="text" name="district" id="district" class="form-control" placeholder="" readonly value="<?php echo $district_info['DISTRICTNAME']; ?>" />
							</td>
						</tr>
					</table>
				</div>
                
				
				<div class="row-fluid">
					<div class="span4">	
						<div class="control-group">
							<label class="control-label" for="form-field-1">Device Name<font color="#FF0000">*</font></label>
							<div class="controls">
								<select id="device_name" name="device_name" class="form_control" >
									<option value="">SELECT DEVICE</option>
									<?php
										$table_name = "AQUATIC.TBLGWH_DEVICENAME@AQUATIC227";
										$where_cond = "FLAG='A' ORDER BY ID ASC";
										$row = $obj->View_all_data_row_column_By_Cond($table_name,' * ',$where_cond);
										foreach($row AS $index=>$value){?>
											<option value="<?php echo $value['ID']; ?>" <?php if($value['ID']==$failure_info['DEVICEID']){echo "selected";} ?>><?php echo $value['DEVICENAME'];?></option>
										<?php }
									?>
								</select>
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Test By (Geologist)<font color="#FF0000">*</font>
							</label>

							<div class="controls">
								<input type="text" name="test_by" id="test_by" class="form-control" placeholder="Test by (Geologist)" value="<?php echo $failure_info['TESTBY']; ?>" >
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Test Date and Time<font color="#FF0000">*</font>
							</label>

							<div class="controls">
								<input type="text" name="test_date" id="test_date" class="form-control date-picker" data-date-format="dd-mm-yyyy" placeholder="Test Date and Time" value="<?php echo $testdatetime; ?>">
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Note Details
							</label>

							<div class="controls">
								<textarea name="note_detail" id="note_detail" class="form-control" placeholder="Note Details"><?php echo $failure_info['NOTEDETAILS']; ?></textarea>
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Year of Maintenance</label>
								
							<div class="controls">
								<select id="year_maintenance" name="year_maintenance" >
									<option value="">--SELECT YEAR--</option>
									<option value="2000" <?php if($failure_info['YEAROFMANUFACTURE']=='2000'){ echo "selected";}?>>2000</option>
									<option value="2001" <?php if($failure_info['YEAROFMANUFACTURE']=='2001'){ echo "selected";}?>>2001</option>
									<option value="2002" <?php if($failure_info['YEAROFMANUFACTURE']=='2002'){ echo "selected";}?>>2002</option>
									<option value="2003" <?php if($failure_info['YEAROFMANUFACTURE']=='2003'){ echo "selected";}?>>2003</option>
									<option value="2004" <?php if($failure_info['YEAROFMANUFACTURE']=='2004'){ echo "selected";}?>>2004</option>
									<option value="2005" <?php if($failure_info['YEAROFMANUFACTURE']=='2005'){ echo "selected";}?>>2005</option>
									<option value="2006" <?php if($failure_info['YEAROFMANUFACTURE']=='2006'){ echo "selected";}?>>2006</option>
									<option value="2007" <?php if($failure_info['YEAROFMANUFACTURE']=='2007'){ echo "selected";}?>>2007</option>
									<option value="2008" <?php if($failure_info['YEAROFMANUFACTURE']=='2008'){ echo "selected";}?>>2008</option>
									<option value="2009" <?php if($failure_info['YEAROFMANUFACTURE']=='2009'){ echo "selected";}?>>2009</option>
									<option value="2010" <?php if($failure_info['YEAROFMANUFACTURE']=='2010'){ echo "selected";}?>>2010</option>
									<option value="2011" <?php if($failure_info['YEAROFMANUFACTURE']=='2011'){ echo "selected";}?>>2011</option>
									<option value="2012" <?php if($failure_info['YEAROFMANUFACTURE']=='2012'){ echo "selected";}?>>2012</option>
									<option value="2013" <?php if($failure_info['YEAROFMANUFACTURE']=='2013'){ echo "selected";}?>>2013</option>
									<option value="2014" <?php if($failure_info['YEAROFMANUFACTURE']=='2014'){ echo "selected";}?>>2014</option>
									<option value="2015" <?php if($failure_info['YEAROFMANUFACTURE']=='2015'){ echo "selected";}?>>2015</option>
									<option value="2016" <?php if($failure_info['YEAROFMANUFACTURE']=='2016'){ echo "selected";}?>>2016</option>
									<option value="2017" <?php if($failure_info['YEAROFMANUFACTURE']=='2017'){ echo "selected";}?>>2017</option>
									<option value="2018" <?php if($failure_info['YEAROFMANUFACTURE']=='2018'){ echo "selected";}?>>2018</option>
									<option value="2019" <?php if($failure_info['YEAROFMANUFACTURE']=='2019'){ echo "selected";}?>>2019</option>
									<option value="2020" <?php if($failure_info['YEAROFMANUFACTURE']=='2020'){ echo "selected";}?>>2020</option>
									<option value="2021" <?php if($failure_info['YEAROFMANUFACTURE']=='2021'){ echo "selected";}?>>2021</option>
								</select>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Year of Commissioning
							</label>

							<div class="controls">
								<select id="year_commission" name="year_commission" >
									<option value="">--SELECT YEAR--</option>
									<option value="2000" <?php if($failure_info['YEAROFCOMMISSIONING']=='2000'){ echo "selected";}?>>2000</option>
									<option value="2001" <?php if($failure_info['YEAROFCOMMISSIONING']=='2001'){ echo "selected";}?>>2001</option>
									<option value="2002" <?php if($failure_info['YEAROFCOMMISSIONING']=='2002'){ echo "selected";}?>>2002</option>
									<option value="2003" <?php if($failure_info['YEAROFCOMMISSIONING']=='2003'){ echo "selected";}?>>2003</option>
									<option value="2004" <?php if($failure_info['YEAROFCOMMISSIONING']=='2004'){ echo "selected";}?>>2004</option>
									<option value="2005" <?php if($failure_info['YEAROFCOMMISSIONING']=='2005'){ echo "selected";}?>>2005</option>
									<option value="2006" <?php if($failure_info['YEAROFCOMMISSIONING']=='2006'){ echo "selected";}?>>2006</option>
									<option value="2007" <?php if($failure_info['YEAROFCOMMISSIONING']=='2007'){ echo "selected";}?>>2007</option>
									<option value="2008" <?php if($failure_info['YEAROFCOMMISSIONING']=='2008'){ echo "selected";}?>>2008</option>
									<option value="2009" <?php if($failure_info['YEAROFCOMMISSIONING']=='2009'){ echo "selected";}?>>2009</option>
									<option value="2010" <?php if($failure_info['YEAROFCOMMISSIONING']=='2010'){ echo "selected";}?>>2010</option>
									<option value="2011" <?php if($failure_info['YEAROFCOMMISSIONING']=='2011'){ echo "selected";}?>>2011</option>
									<option value="2012" <?php if($failure_info['YEAROFCOMMISSIONING']=='2012'){ echo "selected";}?>>2012</option>
									<option value="2013" <?php if($failure_info['YEAROFCOMMISSIONING']=='2013'){ echo "selected";}?>>2013</option>
									<option value="2014" <?php if($failure_info['YEAROFCOMMISSIONING']=='2014'){ echo "selected";}?>>2014</option>
									<option value="2015" <?php if($failure_info['YEAROFCOMMISSIONING']=='2015'){ echo "selected";}?>>2015</option>
									<option value="2016" <?php if($failure_info['YEAROFCOMMISSIONING']=='2016'){ echo "selected";}?>>2016</option>
									<option value="2017" <?php if($failure_info['YEAROFCOMMISSIONING']=='2017'){ echo "selected";}?>>2017</option>
									<option value="2018" <?php if($failure_info['YEAROFCOMMISSIONING']=='2018'){ echo "selected";}?>>2018</option>
									<option value="2019" <?php if($failure_info['YEAROFCOMMISSIONING']=='2019'){ echo "selected";}?>>2019</option>
									<option value="2020" <?php if($failure_info['YEAROFCOMMISSIONING']=='2020'){ echo "selected";}?>>2020</option>
									<option value="2021" <?php if($failure_info['YEAROFCOMMISSIONING']=='2021'){ echo "selected";}?>>2021</option>
								</select>
							</div> 
						</div>
					</div>
					<div class="span4">	
						<div class="control-group">
							<label class="control-label" for="form-field-1">Date and Time of Occurance/Discovery of fault

							<div class="controls">
								<input type="text" name="occurance_date" id="occurance_date" class="form-control date-picker" data-date-format="dd-mm-yyyy" placeholder="dd-mm-yyyy" value="<?php echo $occurancedate; ?>">
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Information Received in BWDB
							</label>

							<div class="controls">
								<input type="text" name="info_receive" id="info_receive" class="form-control" placeholder="Information Received in BWDB" value="<?php echo $failure_info['INFORMATIONRECEIVED']; ?>" />
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Fault Discovery During
							</label>

							<div class="controls">
								<input type="text" name="fault_discover" id="fault_discover" class="form-control" placeholder="Fault Discovery During" value="<?php echo $failure_info['FAULTDISCOVERED']; ?>" />
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Present Condition of Equipment
							</label>

							<div class="controls">
								<textarea name="present_condition" id="present_condition" class="form-control" placeholder="Present Condition of Equipment"><?php echo $failure_info['PRESENTCONDOFEQUIP']; ?></textarea>
							</div> 
						</div>
						<div class="control-group">
							<label class="control-label" for="form-field-1">Details of Previous Maintenance
							</label>

							<div class="controls">
								<textarea name="prev_maintenance" rows="5" id="prev_maintenance" class="form-control" placeholder="Details of Previous Maintenance"><?php echo $failure_info['DETAILOFPREVMAINTENANCE']; ?></textarea>
							</div> 
						</div>
					</div>
					<div class="span4">
						<div class="control-group">
							<label class="control-label" for="form-field-1">Details of Previous Failure
							</label>

							<div class="controls">
								<textarea name="prev_failure" id="prev_failure" class="form-control" placeholder="Details of Previous Failure"><?php echo $failure_info['DETAILOFPREVFAULT']; ?></textarea>
							</div> 
						</div>
					</div>
					<div class="span4">
						<div class="control-group">
							<label class="control-label" for="form-field-1">Sequence of events/Description of fault
							</label>

							<div class="controls">
								<textarea name="seq_events" id="seq_events" class="form-control" placeholder="Sequence of events/Description of fault"><?php echo $failure_info['PRESENTCONDOFEQUIP']; ?></textarea>
							</div> 
						</div>
					</div>
					<div class="span4">
						<div class="control-group">
							<label class="control-label" for="form-field-1">Details of Tests Done After
							</label>

							<div class="controls">
								<textarea name="details_test" id="details_test" class="form-control" placeholder="Details of Tests Done After"><?php echo $failure_info['DETAILOFTESTDONE']; ?></textarea>
							</div> 
						</div>
					</div>
					<div class="span4">
						<div class="control-group">
							<label class="control-label" for="form-field-1">Conclusions/Recommendations
							</label>

							<div class="controls">
								<textarea name="conclusion" id="conclusion" class="form-control" placeholder="Conclusions/Recommendations"><?php echo $failure_info['CONCLUSION']; ?></textarea>
							</div> 
						</div>
					</div>
					<div class="span4">
						<div class="control-group">
							<label class="control-label" for="form-field-1">Status<font color="#FF0000">*</font></label>
							<div class="controls">
								<select name="status" id="status" class="form-control">
									<option value="A" <?php if($failure_info['FLAG']=='A'){echo "selected";}?>>Active</option>
									<option value="I" <?php if($failure_info['FLAG']=='I'){echo "selected";}?>>Inactive</option>
								</select>
							</div> 
						</div>
					</div>
                </div>
				
				<div class="row-fluid">
                    <div class="span5">
                    </div>

                    <div class="span4">

                        <div class="control-group">
                            <label class="control-label" for="form-field-1">&nbsp;</label>

                            <div class="controls">
                                
        
                                    <?php echo '<button class="btn btn-small btn-success" type="button" onclick="'.$func.'('.$id.')">
										<i class="fa fa-check-circle"></i>
										'.$button.'
									</button>';
									?>
                                

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn btn-small btn-danger" type="reset" id="btn_reset">
                                    <i class="icon-undo bigger-100"></i>
                                    Reset
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
		</form>
<?php //} ?>		
</div>

<script>
	$('.date-picker').datepicker().next().on(ace.click_event, function(){
     	$(this).prev().focus();
    });	
</script>