

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

       <ol class="breadcrumb">
            <li><a href="#">نظام  المهام</a></li>
            <li><a href="tasksController.php?do=show"> المهام </a></li>
            <li class="active">تعديل  </li>
        </ol>

        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading" style="padding:5px 15px 15px">
                <h3 class="panel-title" style="display: inline-block;"> عرض       </h3>
                <a href="{$youtubes[198]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
                <a href="tasksController.php" class="hidden-print"><input type="button"  id="submit" style="margin-left: 12px" class="btn btn-primary pull-left " value="إضافة جديد"/></a>
            </div>
            
            <hr/>
            <div class="panel-body">

                <form class="form-inline hidden-print " action="savedailyController.php?do=show" method="post">
                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata" id="fromdate"   data-date-format="yyyy-mm-dd"  >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata"  id="todate"   data-date-format="yyyy-mm-dd"  >
                    </div>
                    <div class="form-group" style="min-width: 219px;">
                        <label class="sr-only">العملاء</label>
                        <input type="text" class="searchdata wdt100" id="select2client" data-placeholder="اختر " />
                    </div>
                    {if $usergroupid eq 0}
                    <div class="form-group" style="min-width: 219px;">
                        <label class="sr-only">المستخدمين</label>
                        <input type="text" class="searchdata wdt100" id="select2user" data-placeholder="اختر " />
                    </div>
                    <div class="form-group" style="min-width: 219px;">
                        <label class="sr-only">المواظفين</label>
                        <input type="text" class="searchdata wdt100" id="select2user2" data-placeholder="اختر " />
                    </div>
                    {/if}
                    <div class="form-group" style="min-width: 219px;">
                        <label class="sr-only">انواع المهام</label>
                        <input type="text" class="searchdata wdt100" id="select2types" data-placeholder="اختر " />
                    </div>
                    <div class="form-group" style="min-width: 219px;">
                        <label class="sr-only">حالات المهمه </label>
                        <select   id="taskcaseid" data-placeholder="اختر " class="select2 searchdata">
                                <option value="" ></option>
                                <option value="0" >الكل</option>
                                {foreach $taskscases as $taskcase}
                                <option value="{$taskcase->id}" {if $taskcase->id eq 1 } selected {/if}>{$taskcase->taskcase}</option>
                                {/foreach}
                        </select>
                    </div>
                     <input type="hidden" id="usergroupidshow" value="{$usergroupid}">
                </form>

            </div>

            <div class="clearfix"></div>
            <hr/>
            <ul class="nav nav-tabs">
            <li id="li0" >
              <a   class="tabetaskscases"  data-id="0" data-toggle="tab">الكل</a>
            </li> 
            {foreach $taskscases as $taskcase}
            <li id="li{$taskcase->id}" {if $taskcase->id eq 1 }class="active" {/if}>
              <a   class="tabetaskscases"  data-id="{$taskcase->id}" data-toggle="tab">{$taskcase->taskcase}</a>
            </li> 
            {/foreach}
          </ul>
            <table class="table table-bordered border-primary" id="getajaxdata">
                <thead>
                    <tr>
                        <th >رقم</th>
                        <th >العميل</th>
                        <th >الموظف</th>
                        <th >نوع المهمه</th>
                        <th >تاريخ التنفيذ</th>
                        <th >عنوان المهمه</th>
                        <th >حالة المهمه</th>
                        <th >تاريخ الاضافه</th>
                        <th >المستخدم</th>
                        <th >اضافه تعليق</th>
                        <th >تعديل الحاله</th>
                        <th >تفاصيل</th>
                        <th >تعديل</th>
                        <th >حذف</th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>

        </div>
    </div>
</div>
<div class="modal fade" id="mtasksdetail" tabindex="-1" role="dialog" aria-labelledby="mtasksdetailLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="mtasksdetailLabel">تفاصيل المهمه</h5>
        <button type="button" style="float:left;    margin-top: -24px;" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" id="tasksdetails">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">اغلاق</button>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="mchangetaskcase" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">تعديل حالة المهمه</h5>
        <button type="button" style="float:left;    margin-top: -24px;" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" id="changetaskcase">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">اغلاق</button>
        <button type="button" class="btn btn-primary formajax" >تعديل الحاله </button>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="maddcommentajax" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">اضافة تعليق</h5>
        <button type="button" style="float:left;    margin-top: -24px;" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" id="addcommentajax">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">اغلاق</button>
        <button type="button" class="btn btn-primary faddcommentajax" >حفظ التعليق </button>
      </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);
            }
        });

        $("#select2user").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.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);
            }
        });


        $("#select2user2").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.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);
            }
        });


        $("#select2types").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2types",
                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);
            }
        });
        

         fetch_data($('#fromdate').val(), $('#todate').val(), $('#select2client').val(), $('#select2user').val(), $('#taskcaseid').val(), $('#select2user2').val(), $('#select2types').val(),$('#usergroupidshow').val());
        function fetch_data(fromdate = '', todate = '', data1 = '', data2 = '', data3 = '', data4 = '', data5 = '', data6 = '')
        {

            var dataTable = $('#getajaxdata').DataTable({
                "lengthMenu": [[20, 40, 60, 80, 100, -1], [20, 40, 60, 80, 100, "All"]],
                dom: 'Bfrtip',
                buttons: [
                    {
                        extend: 'copyHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'csvHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'print',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'excelHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'pdfHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    'colvis'
                ],
                "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
                "order": [[7, "asc"]],
                "displayLength": 20,
                "ajax": {
                    url: 'tasksController.php?do=showajax',
                    type: "POST",
                    data: {
                        fromdate: fromdate,
                        todate: todate,
                        data1: data1,
                        data2: data2,
                        data3: data3,
                        data4: data4,
                        data5: data5,
                        data6: data6,
                    }
                },
                "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                    if (aData[1] == "الكميه")
                    {
                        $('td', nRow).css('background-color', '#c4f378');
                    }
                },

            });

        }


        $('.searchdata').change(function () {
            var fromdate = $('#fromdate').val();
            var todate = $('#todate').val();
            var data1 = $('#select2client').val();
            var data2 = $('#select2user').val();
            var data3 = $('#taskcaseid').val();
            var data4 = $('#select2user2').val();
            var data5 = $('#select2types').val();
            var data6 = $('#usergroupidshow').val();

            $('#getajaxdata').DataTable().destroy();
            fetch_data(fromdate, todate, data1, data2, data3, data4, data5, data6);

        });

        $('body').on('click', '.tabetaskscases', function () {
            var id = $(this).attr('data-id');
            $('#taskcaseid').val(id).trigger('change');
        }); 


        $('body').on('click', '.tasksdetails', function () {
            var id = $(this).attr('data-id');
            $.post('tasksController.php?do=detail', {id: id}, function (result) {
                $('#tasksdetails').html(result);
                $('#mtasksdetail').modal('show');
            });
        });

        $('body').on('click', '.changetaskcase', function () {
            var id = $(this).attr('data-id');
            $.post('tasksController.php?do=changetaskcase', {id: id}, function (result) {
                $('#changetaskcase').html(result);
                $('#mchangetaskcase').modal('show');
                 $('select.select2').select2({width:'100%'});
            });
        });

        $('body').on('click', '.addcommentajax', function () {
            var id = $(this).attr('data-id');
            $.post('tasksController.php?do=addcommentajax', {id: id}, function (result) {
                $('#addcommentajax').html(result);
                $('#maddcommentajax').modal('show');
            });
        });


        $('body').on('click', '.formajax', function () {
            if ($("#formajax").valid() === true) {
                $('.formajax').prop("disabled", true);
                $('.formajax').css("background", "red");
                var id = $("#cid").val();
                var taskcaseid = $("#ctaskcaseid").val();
                var taskcasecomment = $("#ctaskcasecomment").val();
                $.post('tasksController.php?do=savetaskcase', {id: id, taskcaseid: taskcaseid, taskcasecomment: taskcasecomment}, function (result) {
                    if (result == 1) {
                        $('#changetaskcase').html('تم التعديل بنجاح');
                        $('#mchangetaskcase').modal('hide');
                    }else{
                        $('#changetaskcase').html('حدثا خطأ اثناء التنفيذ'); 
                       $('#mchangetaskcase').modal('hide');
                    }
                    $('#getajaxdata').DataTable().destroy();
                    fetch_data($('#fromdate').val(), $('#todate').val(), $('#select2client').val(), $('#select2user').val(), $('#taskcaseid').val());
               
                });

            } else {
                $('.formajax').prop("disabled", false);
            }
        });


        $('body').on('click', '.faddcommentajax', function () {
            if ($("#faddcommentajax").valid() === true) {
                $('.faddcommentajax').prop("disabled", true);
                $('.faddcommentajax').css("background", "red");
                var id = $("#ccid").val();
                var taskcomment = $("#ctaskcomment").val();
                $.post('tasksController.php?do=savecomment', {id: id, taskcomment: taskcomment}, function (result) {
                    if (result == 1) {
                        $('#addcommentajax').html('تم اضافة التعليق بنجاح');
                        $('#maddcommentajax').modal('hide');
                    }else{
                       $('#addcommentajax').html('حدثا خطأ اثناء التنفيذ'); 
                       $('#maddcommentajax').modal('hide');
                    }
               
                });

            } else {
                $('.faddcommentajax').prop("disabled", false);
            }
        });


        $('body').on('click', '.removetask', function () {
            var id = $(this).attr('data-id');
            if (confirm('هل انت متاكد من الحذف ؟')) {
                var thisis = $(this);
                $.post('tasksController.php?do=del', {id: id}, function (data) {
                    if (data == 1) {
                        thisis.parent().parent().remove();
                    }else{
                       alert('حدث خطأ أثناء التنفيذ');
                    }
                    $('#getajaxdata').DataTable().destroy();
                    fetch_data($('#fromdate').val(), $('#todate').val(), $('#select2client').val(), $('#select2user').val(), $('#taskcaseid').val());
                });
            } else {
                 alert('لماذا ضغطت إلغاء؟ يجب أن تكون قد أكدت');
            }
        });






      

    });







</script>
{/literal}
