<?php include_once "./Configs.php"; ?>
<!DOCTYPE html>
<html lang="en">
<?php
if(isset($_GET['edit']) ){
$titulo="Edit project";      
$sql="SELECT * FROM amr_projects WHERE id='".$_GET['edit']."' ORDER BY creacion DESC LIMIT 1;"; 
$ejecutarquery=mysqli_query($link,$sql); 
if(mysqli_num_rows($ejecutarquery)>0){
    $row=mysqli_fetch_assoc($ejecutarquery);
}else{
    $titulo.= " - Id not found! Create a new one instead";
}    
}else{
$titulo="New project";    
}
include_once "./Head.php"; ?>
    <!-- body start AQUI va el theme mode-->
<?php 
if($usuario["layout"] == 'horizontal'){
?>    
    <body class="loading" data-layout-mode="horizontal" data-layout='{"mode": "<?php echo $usuario["theme"]; ?>", "width": "fluid", "menuPosition": "fixed", "topbar": {"color": "dark"}, "showRightSidebarOnPageLoad": false}'>    
<?php 
}else{
?>    
    <body class="loading" data-layout='{"mode": "<?php echo $usuario["theme"]; ?>", "width": "fluid", "menuPosition": "fixed", "sidebar": { "color": "<?php echo $usuario["theme"]; ?>", "size": "default", "showuser": true}, "topbar": {"color": "light"}, "showRightSidebarOnPageLoad": true}'>
<?php 
}
?>    
        <div id="wrapper">
<?php  include_once "./Header.php"; ?>
<?php  include_once "./Menu.php"; ?>
            <div class="content-page">
                <div class="content">

                    <!-- Start Content-->
                    <div class="container-fluid">

                        <!-- start page title -->
<div class="row">
    <div class="col-12">
        <div class="page-title-box page-title-box-alt">
            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Adminto</a></li>
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
                    <li class="breadcrumb-item active">Editable</li>
                </ol>
            </div>
            <h4 class="page-title"><?php echo $titulo; ?></h4>
            <p><?php if(isset($warning) ){echo $warning;} ?></p>
        </div>
    </div>
</div>     
<!-- end page title --> 
                        
                                                                  
                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-body">
                                        <!--<h5 class="mt-0">New product</h5>-->
                                        <p class="sub-header">Fill in the form and click the "Create" button.</p>
                                        <form method="post" enctype="multipart/form-data"> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-floating mb-3">
                                                        <input type="hidden" name="idcambiar" value="<?php if(isset($_GET["edit"]) ){echo $_GET['edit'];}?>">
                                                        <input type="text" class="form-control" id="floatingPassword" placeholder="Name" name="nombre" required value='<?php if(isset($row['nombre']) ){echo $row['nombre'];}?>'>
                                                        <label for="floatingPassword">Name</label>
                                                    </div>
                                                    <div class="form-floating mb-3">
                                                        <textarea class="form-control" placeholder="description" id="floatingTextarea2"
                                                                    style="height: 100px" name="descripcion" required><?php if(isset($row['descripcion']) ){echo $row['descripcion'];}?></textarea>
                                                        <label for="floatingTextarea2">Description</label>
                                                    </div>
                                                    <div class="form-floating mb-3">
                                                        <select class="form-select" id="floatingSelect" aria-label="Floating label select example" name="estatus" required>
                                                            <option value="Draft">Draft</option>
                                                            <option value="In progress">In progress</option>
                                                            <option value="Completed">Completed</option>
                                                            <option value="Cancelled">Cancelled</option>
                                                        </select>
                                                        <label for="floatingSelect">Status</label>
                                                        <?php if(isset($row['estatus']) ){echo '<script>jQuery(document).ready(function ($) { setTimeout(function() { $("select[name=estatus]").val("'.$row['estatus'].'");  }, 1000); });</script>';}?>
                                                    </div>
                                                </div>
                                                <div class="col-lg-6">
                                                    <div class="form-floating mb-3">
                                                        <p class="mb-1 fw-bold text-muted mt-3 mt-md-0">Assign to a contact or company</p>
                                                        <p class="text-muted font-13">
                                                            * You can choose multiple options
                                                        </p>
                                                        <select class="form-control select2-multiple" data-toggle="select2" data-width="100%" multiple="multiple" data-placeholder="Choose ..." name="asignado[]" required><!--Al ser obligatorio, necesita escoger uno y al escoger NINGUNO lo deshecha y borra todos-->
                                                            <option value="NINGUNO">None</option>
                                                            <?php echo AsignarContEmpr();?>
                                                        </select>                                                    
                                                    </div>
                                                    <div class="d-grid">
                                                        <button type="submit" name="botonnuevo" class="btn btn-success waves-effect waves-light" value="proyecto"><?php if(isset($_GET['edit']) ){echo "Update";}else{echo "Create";}?></button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div> <!-- end card-body -->
                                </div> <!-- end card -->    
                                
        <!-- Selectize o multiple select -->
        <script src="./assets/libs/select2/js/select2.min.js"></script>
        <script>
            jQuery(document).ready(function($) {
                $('select.select2-multiple').select2();//necesitas ejecutar esto para inicializar la libreria
                
                /*carga el select de la bdd/**/
                <?php if(isset($_GET['edit']) ){ echo asignJS($_GET['edit']); } ?>    
            });
        </script>   
                            </div> <!-- end col -->
                        </div> <!-- end row -->

                                
                    </div> <!-- container -->

                </div> <!-- content -->
<?php  include_once "./Footer.php"; ?>
        <!-- Table Editable plugin-->
        <script src="./assets/libs/jquery-tabledit/jquery.tabledit.min.js"></script>
        <!-- Table editable init-->
        <!--<script src="./assets/js/pages/tabledit.init.js"></script>-->


        <!-- third party js - Para las tablas que hacen el PDF-->
        <script src="./assets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="./assets/libs/datatables.net-bs5/js/dataTables.bootstrap5.min.js"></script>
        <script src="./assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
        <script src="./assets/libs/datatables.net-responsive-bs5/js/responsive.bootstrap5.min.js"></script>
        <script src="./assets/libs/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
        <script src="./assets/libs/datatables.net-buttons-bs5/js/buttons.bootstrap5.min.js"></script>
        <script src="./assets/libs/datatables.net-buttons/js/buttons.html5.min.js"></script>
        <script src="./assets/libs/datatables.net-buttons/js/buttons.flash.min.js"></script>
        <script src="./assets/libs/datatables.net-buttons/js/buttons.print.min.js"></script>
        <script src="./assets/libs/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
        <script src="./assets/libs/datatables.net-select/js/dataTables.select.min.js"></script>
        <script src="./assets/libs/pdfmake/build/pdfmake.min.js"></script>
        <script src="./assets/libs/pdfmake/build/vfs_fonts.js"></script>
        <!-- third party js ends -->
        <!-- Datatables init -->
        <script src="./assets/js/pages/datatables.init.js"></script>
                
                
            </div>
        </div>        
    </body>
</html>