<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============
$branchid = $_SESSION['LOGIN_BRANCH'];
extract($_GET);

$ffwc_info = $obj->Details_By_Cond("FFWC.STATIONS_TBL","PKID='$pk_id'");

$is_fav = "";

if($ffwc_info['IS_FAVORITE']=='Y'){
	$is_fav = "checked";
}


$old_stat_id = $ffwc_info['STATION_CODE'];
//$stat_id = $value['SID'];
$stat_name = $ffwc_info['STATION_NAME'];
$keyword = $ffwc_info['KEYWORD'];
$riv_name = $ffwc_info['RIVER_NAME'];

$district = $ffwc_info['DISTRICT'];
$mea_division = $ffwc_info['MEASUREMEMT_DIVISION'];
$mea_sub_division = $ffwc_info['MEASUREMENT_SUB_DIVISION'];
$phone = $ffwc_info['MOBILE_NO'];
$contact = $ffwc_info['PHONE_NO'];
$data_type = $ffwc_info['DATA'];
$stat_type = $ffwc_info['STATION_TYPE'];
$basin = $ffwc_info['BASIN'];
$upz = $ffwc_info['UPZILA'];
$lat = $ffwc_info['LATITUDE'];
$long = $ffwc_info['LONGITUDE'];
$rhwl = $ffwc_info['RECORDED_HIGH_WL'];
if($ffwc_info['HIGH_WL_DATE']!=""){
	$rhwl_dt = date('d-m-Y', strtotime($ffwc_info['HIGH_WL_DATE']));
}
else{
	$rhwl_dt = "";
}
$rlwl = $ffwc_info['QC_MEAN_WL'];
//$rlwl_dt = date('d-m-Y', strtotime($ffwc_info['LOW_WL_DATE']));
$dng_lvl = $ffwc_info['DANGER_LEVEL'];
$pm_dng_lvl = $ffwc_info['PRE_MONSOON_DL'];

$sts = $ffwc_info['STATION_TAGS'];

$sts_arr = explode(',',$sts);

?>
<style>
.left_th {
	text-align: right; width: 17%; padding-bottom: 10px; padding-left: 2px;
}
.left_select_th {
	text-align: right; width: 20%; padding-bottom: 5px; padding-left: 2px;
}
.right_th{
	text-align: right; width: 20%; padding-bottom: 10px; padding-left: 2px;
}
.right_select_th{
	text-align: right; width: 10%; padding-bottom: 5px; padding-left: 2px;
}
</style>
<div class="row-fluid">
	<table border="0" style="width: 100%; border-collapse: collapse;">
		<tr>
			<td colspan="6"><b><font color="#ff0000">* Numeric Value Only</font></td>
		</tr>
		<tr>
			<th class="left_th"><font color="#ff0000">*</font>Station Id: </th>
                <td style="width: 28%;">
                    <input type="text" style="width: 93%;" id="s_id" value="<?php echo $old_stat_id;?>"
					onkeyup="call_next_val_loader(event,'s_id','stat_name')"/>
					<input type="hidden" style="width: 93%;" name="data_type" id="data_type" value="WL" readonly />
					<input type="hidden" id="pk_id" value="<?php echo $pk_id; ?>"/>
				</td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th"><font color="#ff0000">*</font>Station Name: </th>
                <td style="width: 28%;">
                    <input type="text" style="width: 93%;" id="stat_name" value="<?php echo $stat_name;?>"
					onkeyup="call_next_val_loader(event,'stat_name','key_word')"/>
                </td>
			<td style="width: 10%;">&nbsp;&nbsp;&nbsp;</td>
		</tr>
        <tr>
            <th class="left_th"><font color="#ff0000">*</font>Keyword: </th>
                <td style="width: 28%;">
                    <input type="text" style="width: 93%;" id="key_word" value="<?php echo $keyword;?>"
					onkeyup="call_next_val_loader(event,'key_word','riv_name')"/>
                </td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_select_th">River Name: </th>
            <td style="width: 28%;">
				<input type="text" style="width: 93%;" id="riv_name" value="<?php echo $riv_name;?>"
				onkeyup="call_next_val_loader(event,'riv_name','basin')"/>
			</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td>
		</tr>
		<tr>
			<th class="left_th">Basin: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="basin" value="<?php echo $basin;?>" 
				onkeyup="call_next_val_loader(event,'basin','dist')"/>
			</td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th">District: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="dist" value="<?php echo $district;?>" 
				onkeyup="call_next_val_loader(event,'dist','upz')"/>
			</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td>
		</tr>
		<tr>
			<th class="left_th">Upazila: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="upz" value="<?php echo $upz;?>" 
				onkeyup="call_next_val_loader(event,'upz','latitude')"/>
			</td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th"> Latitude: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="latitude" value="<?php echo $lat;?>"  
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'latitude','longitude')"/>
			</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td>
		</tr>
		<tr>
			<th class="left_th">Longitude: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="longitude" value="<?php echo $long;?>"   
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'longitude','mea_d')"/>
			</td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th">Measurement Division: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="mea_d" value="<?php echo $mea_division;?>"   
				onkeyup="call_next_val_loader(event,'mea_d','mea_sd')"/>
			</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td>
		</tr>
		<tr>
			<th class="left_th">Measurement Sub Division: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="mea_sd" value="<?php echo $mea_sub_division;?>"   
				onkeyup="call_next_val_loader(event,'mea_sd','phone_no')"/>
			</td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th"><font color="#ff0000">*</font> Mobile No: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 93%;" id="phone_no" value="<?php echo $phone;?>"   
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'phone_no','rhwl')"/>
			</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td>
		</tr>
		<tr>
			<th class="left_th"><font color="#ff0000">*</font> QC High Water Level: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 78%;" id="rhwl" value="<?php echo $rhwl;?>"   
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'rhwl','dt_rhwl')"/> (mMSL)
			</td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th">Date of Recorded Highest Water Level: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 68%;" id="dt_rhwl" placeholder="dd-mm-yyyy" value="<?php echo $rhwl_dt;?>"
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'dt_rhwl','qcm_wl')"/> (dd-mm-yyyy)
			</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td>
		</tr>
		<tr>
			<th class="left_th"><font color="#ff0000">*</font> QC Low Water Level: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 78%;" id="qcm_wl" value="<?php echo $rlwl;?>"
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'qcm_wl','dng_wl')"/> (mMSL)
			</td>
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th"> Danger Level: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 78%;" id="dng_wl" value="<?php echo $dng_lvl;?>"
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'dng_wl','pm_dng_wl')"/> (mMSL)
			</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td>
		</tr>
		<tr>
			<th class="left_th"> Pre-Monsoon Danger Level: </th>
			<td style="width: 28%;">
				<input type="text" style="width: 78%;" id="pm_dng_wl" value="<?php echo $pm_dng_lvl;?>"
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'pm_dng_wl','updatecontact')"/> (mMSL)
			</td>
			<!-- <td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th">Favorite <input type='checkbox' style='position: relative; opacity: 1;' id='is_fav' value="<?php echo !empty($ffwc_info['IS_FAVORITE']) ? htmlspecialchars($ffwc_info['IS_FAVORITE']) : 'Y'; ?>" <?php echo $is_fav; ?>/></th>
			<td style="width: 28%;"> (check if you want to make this station favorite)</td>
			<td style="width: 4%; ">&nbsp;&nbsp;&nbsp;</td> -->
			<td style="width: 4%;">&nbsp;&nbsp;&nbsp;</td>
			<th class="right_th">Contact Info :</th>
			<td style="width: 28%;">
				<input type="text" style="width: 78%;" id="updatecontact" value="<?php echo $contact; ?>"
				onkeypress="return isNumericInput(event)"
				onkeyup="call_next_val_loader(event,'updatecontact','updatestationtag')"/>
			</td>
		</tr>
		
		<tr>
			<th class="right_th">Station Tag: </th>
			<td style="width: 28%;">
				<select id="updatestationtag" name="updatestationtag" class="chosen-select" style="width: 98%;" multiple size = 13>
					<option value="">---SELECT---</option>
					<?php
                    $table_name = "FFWC.STATION_TAGS";
                    $columns = 'ID,TAG_NAME';
                    $where_cond = "STATUS = 'A' ORDER BY ID ASC";

                    foreach($obj->View_colmn_By_Cond($table_name,$columns,$where_cond) as $stat_tag_list){
						$is_present = in_array($stat_tag_list['ID'], $sts_arr);
						$is_sts_selected = "";
						if($is_present!== false){
							$is_sts_selected = "selected";
						}
                        // echo '<option value="'.$stat_tag_list['ID'].'">'.$stat_tag_list['TAG_NAME'].'</option>';
						echo "<option value='".$stat_tag_list['ID']."' $is_sts_selected >".$stat_tag_list['TAG_NAME']."</option>";
                    }
                    ?>
				</select>
			</td>
		</tr>
	</table>
</div>

<script>
// $('.chosen-select').chosen({allow_single_deselect:true});
$('.chosen-select').chosen({
		allow_single_deselect:true,
		search_contains: true
	});  
	//resize the chosen on window resize

	$(window)
	.off('resize.chosen')
	.on('resize.chosen', function() {
		$('.chosen-select').each(function() {
			 var $this = $(this);
			 $this.next().css({'width': '98%'});
		})
	}).trigger('resize.chosen');
	//resize chosen on sidebar collapse/expand
	$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
		if(event_name != 'sidebar_collapsed') return;
		$('.chosen-select').each(function() {
			 var $this = $(this);
			 $this.next().css({'width':  '98%'});
		})
	});
</script>

<script>
$('.chosen-select-off').chosen({ allow_single_deselect: true, disable_search: true });
// resize the chosen on window resize
$(window)
  .off('resize.chosen')
  .on('resize.chosen', function() {
    $('.chosen-select-off').each(function() {
      var $this = $(this);
      $this.next().css({ 'width': '98%' });
    });
  })
  .trigger('resize.chosen');

// resize chosen on sidebar collapse/expand
$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
  if (event_name != 'sidebar_collapsed') return;
  $('.chosen-select-off').each(function() {
    var $this = $(this);
    $this.next().css({ 'width': '98%' });
  });
});
</script>

<!-- Alphanumeric Checking -->
<script>
  let inputReset = false; // Track whether input should be reset

  function isNumericInput(event) {
    const key = event.keyCode || event.which;
    const keyChar = String.fromCharCode(key);

    const regex = /[0-9]|\.|\-/; // Alphanumeric pattern

    // Only allow alphanumeric input
    if (!regex.test(keyChar)) {
      event.preventDefault();
      return false;
    }

    const input = event.target;
    const currentValue = input.value;

    if (inputReset) {
      input.value = "";
      inputReset = false;
    }

    return true;
  }
</script>
<!-- Alphanumeric Checking -->


<!--Enter Checking-->
<script>
function call_next_val_loader(e, sel_col_id, next_col_id) {
    if (e.keyCode === 13 || e.keyCode === 9 || e.keyCode === 'enter') {
		//alert(sel_col_id);
		//alert(next_col_id);
		if(next_col_id=='wl_up_btn'){
			update_ffwc_wl_station();
		}
		else{
			$("#"+next_col_id).select();
		}
    }
}
</script>
<!--Enter Checking-->

