<!doctype html>
<html lang="en">

<head>
	<title>[[*longtitle]] | [[++site_name]]</title>
	<base href="[[!++site_url]]">
	<meta charset="[[++modx_charset]]">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="keywords" content="[[*introtext]]">
	<meta name="description" content="[[*description]]">
	<link rel="icon" href="client-assets/images/favicon.ico?v=2" type="image/x-icon"> [[!Profile]]
	
	<script type="text/javascript">
    	window.dataLayer = window.dataLayer || [];
    
    	function gtag() {
    		dataLayer.push(arguments);
    	}
    	gtag('js', new Date());
    	gtag('set', {
    		'user_id': '[[+modx.user.id]]'
    	}); // Set the user ID using signed-in user_id.
    	gtag('config', 'UA-133963301-1');
	</script>
	
	<link href="https://cdn.jsdelivr.net/npm/simple-datatables@latest/dist/style.css" rel="stylesheet" />
	<link href="client-assets/css/dashboard-2021.css" rel="stylesheet" />
	<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js" crossorigin="anonymous"></script>
	<link href="https://cdn.datatables.net/1.10.20/css/dataTables.bootstrap4.min.css" rel="stylesheet" crossorigin="anonymous" />
	<script src="client-assets/js/skycons.js"></script>
	<style>
    	.btn-append {
    		color: #495057;
    		background-color: #e9ecef;
    		border: 1px solid #ced4da;
    	}
    	.footer {
    		position: absolute;
    		bottom: 0;
    		width: 100%;
    		height: 60px;
    		line-height: 60px;
    	}
	</style>
</head>

<body class="sb-nav-fixed" id="page-top"> 
    [[!Personalize?
        &yesChunk=`navHeaderLogged`
        &noChunk=`navHeader`
        &allowedGroups=`basicClients,bacicAdmin,companyClients,companyManagers`
    ]]
    
	<div id="layoutSidenav">
	    <div id="layoutSidenav_nav">
    		<!-- Sidebar -->
    		[[Wayfinder?
    		    &startId=`2` 
        		&displayStart=`0` 
        		&startitemTpl=`startitemTpl` 
        		&selfClass=`show` 
        		&level=`2`
        		&outerTpl=`outer`
        		    &outerClass=`sb-sidenav accordion sb-sidenav-dark`
        		&rowTpl=`row`
        		    &rowClass=`nav-link`
        		&parentRowTpl=`parentRow`
        		    &parentClass=`nav-link collapsed`
        		&innerTpl=`inner`
        		    &innerClass=`collapse`
        		&innerRowTpl=`secondInner`
        		    &innerRowClass=`nav-link`
    		]]
        </div>
		
		<div id="layoutSidenav_content">
			<main>

				<div class="container-fluid px-4">
				    <h1 class="mt-4">[[*pagetitle]]</h1>

					<ol class="breadcrumb mb-4"> [[$dash-breadcrumbs]] </ol>
					
					<div class="row">
					    <div class="container-fluid">
    <div class="grid-form">
        <!---->
        <div class="grid-form1">
            <h3>Plant Analysis</h3>
            <p>Variables used in Plant Analysis recommendation programs.</p>
            <div class="tab-content">
            <!-- Company Product list here -->    
            
            <?php
error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    $result    = null;
    $modx_user = $modx->user->get('id');
    
    /* Database connection */
    //$con = mysqli_connect("localhost", "root", "R3M0T31", "cropmonitor");
    $con = mysqli_connect("localhost", "cropmonitor", "brvnCcaEYxlPCS3", "cropmonitor");
    
    /* Check Database Connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    /* Image Insert for Plant Identification */
    if(isset($_POST["insert"]))  
        {  
            $file = addslashes(file_get_contents($_FILES["image"]["tmp_name"]));  
            $query = "INSERT INTO plant_images(name) VALUES ('$file')";  
            if(mysqli_query($con, $query))  
                {  
                    echo '<script>alert("Image saved")</script>';  
                }  
        }  
?>

<div class="container-fluid">
    <div class="row">
        <div class="form-group col-4">
            <select id="plant" class="form-control">
                <option value="" selected="selected">Select Plant Type</option>
                    <?php
                        $sql = "SELECT DISTINCT `plant_type` FROM `plant_specifications` WHERE `modx_user_id` = " . $modx_user . " ORDER BY `plant_type` ASC; ";
                        $resultset = mysqli_query($con, $sql) or die("database error:". mysqli_error($con));
                        while( $rows = mysqli_fetch_assoc($resultset) ) {
                    ?>
                <option value="<?php echo $rows["plant_type"]; ?>" "><?php echo $rows["plant_type"]; ?></option>
                <?php $plant = $rows["plant_type"]; } ?>
            </select>
        </div>
    </div>
    
    
    <div class="row" id="show_product"></div>
    
    
    
    <hr>
    <div class="row">
        <div class="col">
            <div class="row">
                <p>Nutrient Requirements</p>
            </div>
            <div class="row">
                <div class="col border border-success">
                    <!-- Show Selected Plant Data Script -->
                    <script type="text/javascript">
                        $(document).ready(function(){
                            // code to get all records from table via select box
                            $("#plant").change(function() {
                                var plant = $(this).find(":selected").val();
                                    $.ajax({
                                        url: '[[~89]]',
                                        type: "POST",
                                        data: 'empid='+ plant,
                                        success: function(data) {
                                            $('#show_product').html(data);
                                    }
                                });
                            })
                        });
                    </script>
                </div>
            </div>
        </div>
    </div>
        
</div>



<!-- Update Values Script -->
<script type="text/javascript">
    function showEdit(editableObj) {
        $(editableObj).css("background", "#97e499");
    }
    function updateDatabase(editableObj, column, id) {
        $(editableObj).css("background", "#FDFDFD");
        $.ajax({
            url: "[[~57]]",
            type: "POST",
            data: 'column=' + column + '&editval=' + editableObj.innerHTML + '&id=' + id,
            success: function (data) {
                $(editableObj).css("background", "white");
            }
        });
    }
</script>

<!-- Image Insert Script -->
<script>  
 $(document).ready(function(){  
      $('#insert').click(function(){  
           var image_name = $('#image').val();  
           if(image_name == '')  
           {  
                alert("Please Select Image");  
                return false;  
           }  
           else  
           {  
                var extension = $('#image').val().split('.').pop().toLowerCase();  
                if(jQuery.inArray(extension, ['gif','png','jpg','jpeg']) == -1)  
                {  
                     alert('Invalid Image File');  
                     $('#image').val('');  
                     return false;  
                }  
           }  
      });  
 });  
 </script>
 ?>
                
            </div>
        </div>
    </div>
</div>
					</div>

				</div>

			</main>
			
			<footer class="py-4 bg-light mt-auto">
                <div class="container-fluid px-4">
                    <div class="d-flex align-items-center justify-content-between small">
                        <div class="text-muted">[[SimpleCopyright? &startYear=`2003`]]. All Rights Reserved <a href="[[~1]]"></a></div>
                        <div>
                            <a href="[[~39~]]">Privacy Policy</a>
                            &middot;
                            <a href="[[~39~]]">Terms &amp; Conditions</a>
                        </div>
                    </div>
                </div>
            </footer>
            
		</div>

	</div>

	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
	<script>
    	/*!
            * Start Bootstrap - SB Admin v7.0.3 (https://startbootstrap.com/template/sb-admin)
            * Copyright 2013-2021 Start Bootstrap
            * Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-sb-admin/blob/master/LICENSE)
            */
            // 
        // Scripts
        // 
        
        window.addEventListener('DOMContentLoaded', event => {
        
            // Toggle the side navigation
            const sidebarToggle = document.body.querySelector('#sidebarToggle');
            if (sidebarToggle) {
                // Uncomment Below to persist sidebar toggle between refreshes
                // if (localStorage.getItem('sb|sidebar-toggle') === 'true') {
                //     document.body.classList.toggle('sb-sidenav-toggled');
                // }
                sidebarToggle.addEventListener('click', event => {
                    event.preventDefault();
                    document.body.classList.toggle('sb-sidenav-toggled');
                    localStorage.setItem('sb|sidebar-toggle', document.body.classList.contains('sb-sidenav-toggled'));
                });
            }
        
        });

	</script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
	<script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" crossorigin="anonymous"></script>
</body>
</html>