MINI Sh3ll
<?
$plant_id = $urlparts[1] == 'add-plant' ? '0' : encrypt_decrypt('decrypt', $urlparts[1]);
$company_id = ($loginUser['usertype'] == 'ADMIN') ? "" : $loginUser['company_id'];
// $getCompanies = $objCompany->getCompanyDetailsById($company_id);
$getUsers= $objUser->getUsersByType('PADMIN',$company_id);
if($plant_id > 0){
$plant = $objPlant->getPlantDetailsById($plant_id);
}
else {
$plant =[];
}
//print '<pre>'; print_r($user); print '</pre>';
?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAUE5vHoKz_4FWHmFqqdc53OfJSwhLmNxM&callback=showPosition" loading=async defer></script>
<link href="<?=SITE_ROOT_URL?>css/select2.min.css" rel="stylesheet" />
<script src="<?=SITE_ROOT_URL?>js/select2.min.js"></script>
<div class="row">
<div class="col-md-8 offset-md-2">
<!-- Account details card-->
<div class="card card-header-actions mb-4">
<div class="card-header">Plant Information
<a class="btn btn-yellow btn-sm" href="<?=SITE_ROOT_URL.'plants/'?>">Back</a></div>
<div class="card-body">
<form id="CertForm" class="needs-validation" novalidate method="post" autocomplete="Off">
<div class="form-group">
<label class="small mb-1" for="company">Plant Name</label>
<input class="form-control form-control-sm" id="name" name="name" type="text" placeholder="Enter the name of the plant" value="<?=$plant['name']?>" required />
<div class="invalid-feedback">
Please enter the plant name
</div>
</div>
<div class="form-group">
<label class="small mb-1" for="company">Plant Code</label>
<input class="form-control form-control-sm" id="name" name="code" type="text" placeholder="Enter the code of the plant" value="<?=$plant['code']?>" required />
<div class="invalid-feedback">
Please enter the plant code
</div>
</div>
<div class="form-group">
<label class="small mb-1" for="address">Address</label>
<textarea class="form-control form-control-sm" id="address" name="address" type="text" placeholder="Enter the address" required><?=$plant['address']?></textarea>
<div class="invalid-feedback">
Please enter the plant address
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label class="small mb-1" for="city">City</label>
<input class="form-control form-control-sm" id="city" name="city" type="text" placeholder="Enter the city" value="<?=$plant['city']?>" required />
<div class="invalid-feedback">
Please enter the city
</div>
</div>
<div class="form-group col-md-4">
<label class="small mb-1" for="state">State</label>
<input class="form-control form-control-sm" id="state" name="state" type="text" placeholder="Enter the state" value="<?=$plant['state']?>" required />
<div class="invalid-feedback">
Please enter the state
</div>
</div>
<div class="form-group col-md-4">
<label class="small mb-1" for="city">Country</label>
<input class="form-control form-control-sm" id="country" name="country" type="text" placeholder="Enter the country" value="<?=$plant['country']?>" required />
<div class="invalid-feedback">
Please enter the country
</div>
</div>
</div>
<div class="form-row">
<!-- <div class="form-group col-md-6">
<label class="small mb-1" for="company_id">Company</label>
<select class="form-control form-control-sm" name="company_id" required>
<option value="">Select Company</option>
<?php
foreach($getCompanies as $c){
?>
<option value="<?=$c['id']?>" <?= ($c['id'] == $plant['company_id'] ? "selected" : "") ?>><?=$c['name']?></option>
<?
}
?>
</select>
<div class="invalid-feedback">
Please select the company
</div>
</div> -->
<div class="form-group col-md-6">
<label class="small mb-1" for="company_id">Plant Admin</label>
<select class="form-control form-control-sm" name="manager_id" required>
<option value="">Select Plant Admin</option>
<?php
foreach($getUsers as $u){
?>
<option value="<?=$u['id']?>" <?= ($u['id'] == $plant['manager_id'] ? "selected" : "") ?>><?=$u['firstname']." ".$u['lastname']?></option>
<?
}
?>
</select>
<div class="invalid-feedback">
Please select the plant admin
</div>
</div>
<div class="form-group col-md-3">
<label class="small mb-1" for="capacity">Capacity</label>
<input class="form-control form-control-sm" id="capacity" name="capacity" type="text" placeholder="Enter the capacity" value="<?=$plant['capacity']?>" required />
<div class="invalid-feedback">
Please enter the capacity
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label class="small mb-1" for="logger_details">Logger Details</label>
<input class="form-control form-control-sm" id="logger_details" name="logger_details" type="text" placeholder="Enter the logger details" value="<?=$plant['logger_details']?>" required />
<div class="invalid-feedback">
Please enter the logger details
</div>
</div>
<div class="form-group col-md-6">
<label class="small mb-1" for="inverter_details">Inverter Details</label>
<input class="form-control form-control-sm" id="inverter_details" name="inverter_details" type="text" placeholder="Enter the inverter details" value="<?=$plant['inverter_details']?>" required />
<div class="invalid-feedback">
Please enter the inverter details
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<div id="mapCanvas"></div>
<span id="maperror"></span>
</div>
<div class="form-group col-md-3">
<label class="small mb-1" for="longitude">Longitude</label>
<input class="form-control form-control-sm" id="longitude" name="longitude" type="text" placeholder="Enter the longitude" value="<?=$plant['longitude']?>" required />
<div class="invalid-feedback">
Please enter the longitude
</div>
</div>
<div class="form-group col-md-3">
<label class="small mb-1" for="latitude">Latitude</label>
<input class="form-control form-control-sm" id="latitude" name="latitude" type="text" placeholder="Enter the logger details" value="<?=$plant['latitude']?>" required />
<div class="invalid-feedback">
Please enter the latitude
</div>
</div>
</div>
<div class="text-right">
<input type="hidden" name="formtype" value="<?=$plant_id > 0 ? 'update-plant' : 'add-plant'?>" />
<button id="btnSubmit" class="btn btn-primary text-right" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var x = document.getElementById("maperror");
function showPosition(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
//var myLatLng = {lat: latitude, lng: longitude};
map = new google.maps.Map(document.getElementById('mapCanvas'), {
center: latLng,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latLng,
title: 'Ambarrukmo Plaza Yogyakarta',
map: map,
draggable: true
});
map.setCenter(latLng); //Here center the map.
marker.setPosition(latLng);
$("#geoLoc").html(lat+", "+lng);
$("#latitude").val(lat);
$("#longitude").val(lng);
google.maps.event.addListener(marker, 'dragend', function(evt){
//document.getElementById('current').innerHTML = '<p>Marker dropped: Current Lat: ' + evt.latLng.lat().toFixed(3) + ' Current Lng: ' + evt.latLng.lng().toFixed(3) + '</p>';
//document.getElementById('current').innerHTML = '';
var la = evt.latLng.lat().toFixed(7);
var ln = evt.latLng.lng().toFixed(7);
$("#geoLoc").html(la+", "+ln);
$("#latitude").val(la);
$("#longitude").val(ln);
});
google.maps.event.addListener(marker, 'dragstart', function(evt){
//document.getElementById('current').innerHTML = '<p>Loading new position...</p>';
});
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
$("#latitude").val('0');
$("#longitude").val('0');
}
function loadMap(){
var map;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
$( document ).ready(function() {
loadMap();
});
</script>
<script type="text/javascript">
$("#btnSubmit").on("click", function (e) {
var form = $("#CertForm")[0];
var isValid = form.checkValidity();
if (!isValid) {
e.preventDefault();
e.stopPropagation();
}
form.classList.add('was-validated');
//return false; // For testing only to stay on this page
});
</script>
OHA YOOOO