

<div class="row">
    <div class="container">

         <ol class="breadcrumb">
          <li><a href="#">مشاريع خارجيه</a></li>
            <li><a href="executors.php?do=show"> اضافة منفذين للمشروع </a></li>
            <li class="active">تعديل  </li>
        </ol>


        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">تعديل  </h3>
            </div>
            <div class="panel-body">


                {literal}
                <form class="form-horizontal"  action="executors.php?do=update"   method="post"  enctype="multipart/form-data" >
                    {/literal}

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">العملاء</label>
                        <div class="col-lg-4">
                            <input type="text" name="executorsclientid" required="required" class="wdt100" id="select2client" data-placeholder="اختر " />
                              <input type="hidden" id="clientid" value="{$client.clientid}">
                            <input type="hidden" id="clienttext" value="{$client.clientname}">
                         </div>
                    </div>
                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">الفواتير </label>
                        <div class="col-lg-4">
                            <input type="text" name="executorssellid" required="required" class="wdt100" id="select2sellbill" data-placeholder="اختر " />
                            <input type="hidden" id="executorssellid" value="{$sellbill.sellbillid}">
                            <input type="hidden" id="selltext" value="{$sellbill.sellbillid} / {$sellbill.datestarting}">
                         </div>
                    </div>

                     <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">المواظفين</label>
                        <div class="col-lg-4">
                            <input type="text" name="executorsuserids" multiple required="required" class="wdt100" id="select2user" data-placeholder="اختر " />
                            {foreach $users as $user}
                            <input type="hidden" class="alluser" data-id="{$user.userid}" data-text="{$user.employeename}">
                            {/foreach}
                         </div>
                    </div>



                     
                  

                    <div class="form-group">
                        <input type="hidden" name="id" value="{$executors->id}">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="submit" class="btn btn-primary pull-left" >تعديل </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{literal}
<script type="text/javascript">


    $(document).ready(function () {
        var formatResult;
        formatResult = function (data) {
            return  data.text;
        }


        $("#select2client").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2client",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });

       $('#select2client').select2('data', {id: $('#clientid').val(), text: $('#clienttext').val()});
        
         $("#select2user").select2({
            placeholder: "إسم  المشروع",
            multiple: true,
            quietMillis: 100,
            ajax: {
                url: "executors.php?do=select2user",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });

        var countuser = Number($('#countuser').val());
        var myarray = [];
        $('.alluser').each(function(i, e){
           myarray.push({id: $(this).attr('data-id'), text: $(this).attr('data-text')});
        });
        $('#select2user').select2('data', myarray);
        
        $("#select2sellbill").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "executors.php?do=select2sellbill",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                     var select2client = Number($('#select2client').val());
                     if (!select2client) {
                        alert('يجب اختيار العميل اولا');
                        return false;
                     }
                    return {
                        searchTerm: term,
                        clientid: select2client,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });
        $('#select2sellbill').select2('data', {id: $('#executorssellid').val(), text: $('#selltext').val()});
       




    });
</script>
{/literal}


