<?php require_once(APPPATH.'/views/header.php'); ?>
<body>
    <div id="wrapper">
    <?php require_once(APPPATH.'/views/menu_user.php'); ?>
        <div id="page-wrapper">
            <div class="container-fluid">
                <fieldset class="admin-border">
                    <fieldset class="scheduler-border">
                    <legend class="scheduler-border"><?php echo $title;?></legend>
                        <div class="row">
                        <form id="my_set" action="<?php echo base_url();?>adm/arhiva/iesire" method="POST" enctype="multipart/form-data">
                            
                            <div class="col-lg-4 col-md-6 col-sm-8 col-xs-12">
                                <label>Scaneaza codul (*)</label><br />
                                <input class="form-control" type="number" id="cod"  name="cod" placeholder="Cod">
                                <span id="error_doc" class="text-danger"></span>
                            </div>
                            <div class="clearfix"></div><br/>
                            <div class="col-lg-4 col-md-6 col-sm-8 col-xs-12">
                                <label>Document (*)</label><br />
                                <select class="form-control" id="document" name="document">
                                    <?=(isset($select_docs) && $select_docs)? $select_docs:'';?>
                                </select>
                            </div>
                            <div class="clearfix"></div><br/>
                            <div class="col-lg-4 col-md-6 col-sm-8 col-xs-12">
                                <label>Client (*) <a id="new_client" class="btn btn-primary"><i class="fa fa-plus"></i></a></label><br />
                                <select class="form-control" id="client" name="client">
                                    <?=(isset($select_client) && $select_client)? $select_client:'';?>
                                </select>
                            </div>
                            <div class="clearfix"></div><br/>
                            <div class="col-lg-4 col-md-6 col-sm-8 col-xs-12">
                                <label>Observatii</label><br />
                                <textarea class="form-control" type="text" id="observatii"  name="observatii"  placeholder="Observatii"></textarea>
                            </div>
                            <div class="clearfix"></div><br/>
                            <div class="col-lg-4 col-md-6 col-sm-8 col-xs-12">
                                <label>Status</label><br />
                                <select disabled=true class="form-control" id="status" name="status">
                                    <?=(isset($select_status) && $select_status)? $select_status:'';?>
                                </select>
                            </div>
                            <div class="clearfix"></div><br/>
                            <div class="col-lg-4 col-md-6 col-sm-8 col-xs-12">
                            <button id="save_btn" type="submit" class="btn btn-primary">Adauga</button>
                            </div><br />
                            </form>
                        </div>
                    <br/>
                    </fieldset>
                </fieldset>
            </div>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <div id="gif" class="modal fade loading-gif">
        <div class="modal-dialog">
            <div>
                <img src="<?=base_url()?>img/loading.gif">
            </div>
        </div>
    </div>
    <div id="modal_new_client" class="modal fade">
       <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                   <h4 class="modal-title text-center"><?='Adauga client nou';?></h4>
               </div>
               <form id="myFormClient" action="<?php echo base_url();?>adm/arhiva/newClient" method="POST" enctype="multipart/form-data">
                  <div id="content" class="modal-body"> 
      
                  <label>Denumire (*)</label>
                  <input type="text" name="client_denumire" id="client_denumire" class="form-control form-modal" placeholder="Denumire" />
                  <div class="clearfix"></div><br/>
                  <label>Responsabil (*)</label>
                  <input type="text" name="client_responsabil" id="client_responsabil" class="form-control form-modal" placeholder="Responsabil" />
                  <div class="clearfix"></div><br/>
                  <label>E-mail (*)</label>
                  <input type="text" name="client_email" id="client_email" class="form-control form-modal" placeholder="Email" />
                  <div class="clearfix"></div><br/>
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-default" data-dismiss="modal"><?='Inchide';?></button>
                     <input type='submit' class="btn btn-primary" id='sub' name='sub' value="Adauga">
                 </div>
               </form>
            </div>
        </div>
    </div>
    <!-- /#wrapper -->
<?php require_once(APPPATH.'/views/footer.php'); ?> 
<script>
            
        $(document).ready(function(){
            $("#cod").focus();

            $("#new_client").click(function() {
                $('#modal_new_client').modal('show');
            });

            $("#cod").change(function() {
                var cod = $("#cod").val();
                var c_data  =   {ajax:'1', cod:cod};
                            $.ajax({
                                url : "<?php echo base_url();?>adm/arhiva/check",
                                type:"POST",
                                data: c_data,
                                success: function(data, textStatus, jqXHR)
                                {
                                    var info = JSON.parse(data);
                                    if(info[0])
                                    {
                                        $("#document").val(info[0]);
                                        $("#error_doc").html('');
                                    }
                                    else
                                    {
                                        $("#error_doc").html(info[1]);
                                    }
                                },
                                error: function (jqXHR, textStatus, errorThrown)
                                {  
                                }
                            });
                
            });

            $("#myFormClient").validate({
                    // validation rules
                    rules: {
                        client_denumire: "required",
                        client_responsabil: "required",
                        client_email:{
                                required: true,
                                email: true
                            }
                    },
                    // Specify validation error messages
                    messages: {
                        client_denumire: "Completeaza denumire client",
                        client_responsabil: "Completeaza nume responsabil client",
                        client_email: "Completeaza adresa de email"                    
                    },
                    submitHandler: function(form) {
                        var c_data  =   {   ajax:'1', 
                                            de:$("#client_denumire").val(),
                                            re:$("#client_responsabil").val(), 
                                            em:$("#client_email").val()
                                        };
                        $.ajax({
                                url : "<?php echo base_url();?>adm/arhiva/newClient",
                                type:"POST",
                                data: c_data,
                                success: function(data, textStatus, jqXHR)
                                {
                                    var info = JSON.parse(data);
                                    if(info[0])
                                    {
                                        $("#client").html(info[0]);
                                        $(".form-modal").val('');
                                        $('#modal_new_client').modal('hide');
                                    }
                                },
                                error: function (jqXHR, textStatus, errorThrown)
                                {  
                                }
                        });
                    }
            });

            $("#my_set").validate({
                    // validation rules
                    rules: {
                        client: {min:1},
                        document: {min:1}
                    },
                    // Specify validation error messages
                    messages: {
                        client: "Selecteaza un client",
                        document: "Selecteaza un document"                        
                    },
                    submitHandler: function(form) {
                      form.submit();
                    }
            });
        });

</script>     
</body>
</html>