
<input id="baseUrl" type="hidden" value="<?php echo base_url();?>">
<input id="groupUrl" type="hidden" value="<?php echo $group_url;?>">
<div class="col-sm-8">
    <div class="row ">
        <div class="col-sm-12 ">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <h3>Assignment Post</h3>
                </div>
                <div class="col-sm-6 "></div>
                <hr>
            </div>

            <div class="col-sm-12"><hr></div>
            <div id="group_assignment_view" class="col-sm-12" style="padding: 0">
                <div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;padding: 10px 0 10px 0;font-weight: bold">
                    <div class="col-sm-2" style="padding: 0">Image</div>
                    <div class="col-sm-3" style="padding: 0">Title</div>
                    <div class="col-sm-3" style="padding: 0"> By</div>
                    <div class="col-sm-2" style="padding: 0">Date</div>
                    <div class="col-sm-2" style="padding: 0">Action</div>
                </div>
                <div class="col-sm-12"><br></div>   
                <input type="hidden" name="url_id" id="url_id" value="<?php echo $group_url; ?>">
                <span class="padding-zero" id="view_group_asignment">
                    <?php
                    $user_id = $this->session->userdata('user_id');
                    if ($group_assignment_post) {
                        foreach ($group_assignment_post as $v_assignment) {
                            ?>
                            <div class="col-sm-12 gray text-center" >
                                <div class="col-sm-2" style="padding: 10px 0 0 0  "><a href="#">
                                        <?php
                                        $fileName = $v_assignment->post_file_original_name;
                                        $file_explode = explode('.', $fileName);
                                        $file_extention = $file_explode[count($file_explode) - 1];

                                        if ($file_extention == 'pdf') {
                                            ?>
                                            <a href="javascript:;" onclick="downloadAssignment('<?php echo $v_assignment->post_id; ?>', '<?php echo $group_details->group_id; ?>')"> <img src="<?php echo base_url() . 'image/assignment/pdf.png' ?>"></a>
                                            <!--<i style="color: #80c12c" class="fa fa-file-pdf-o"></i>-->
                                        <?php } else if ($file_extention == 'rar' || $file_extention == 'zip') { ?>
                                            <a href="javascript:;" onclick="downloadAssignment('<?php echo $v_assignment->post_id; ?>', '<?php echo $group_details->group_id; ?>')"> <img src="<?php echo base_url() . 'image/assignment/rar.png' ?>"></a>
                                        <?php } else if ($file_extention == 'doc' || $file_extention == 'docx') { ?>
                                            <a href="javascript:;" onclick="downloadAssignment('<?php echo $v_assignment->post_id; ?>', '<?php echo $group_details->group_id; ?>')"><img src="<?php echo base_url() . 'image/assignment/word.png' ?>"></a>

                                        <?php } else if ($file_extention == 'xls' || $file_extention == 'xlsx') { ?>
                                            <a href="javascript:;" onclick="downloadAssignment('<?php echo $v_assignment->post_id; ?>', '<?php echo $group_details->group_id; ?>')"> <img src="<?php echo base_url() . 'image/assignment/excel.png' ?>"></a>
                                        <?php } else if ($file_extention == 'pptx' || $file_extention == 'ppt') { ?>
                                            <a href="javascript:;" onclick="downloadAssignment('<?php echo $v_assignment->post_id; ?>', '<?php echo $group_details->group_id; ?>')"> <img src="<?php echo base_url() . 'image/assignment/powerpoint.png' ?>"></a>
                                        <?php } else {
                                            ?>
                                            <a href="javascript:;" onclick="downloadAssignment('<?php echo $v_assignment->post_id; ?>', '<?php echo $group_details->group_id; ?>')"> <img src="<?php echo base_url() . 'image/assignment/unknown.png' ?>"></a>
                                        <?php }
                                        ?>
                                    </a></div>
                                <div class="col-sm-3" style="padding: 10px 0 0 0  ">
                                    <a href="<?php echo base_url() . 'view-content-group/' . $this->utility_model->encode_id($v_assignment->post_id, '/', 'Tt') . '/2'; ?>"><?php echo $v_assignment->post_file_original_name; ?></a>
                                </div>
                                <div class="col-sm-3" style="padding: 10px 0 0 0; cursor: pointer; color: #80c12c;" id="viewGroup<?php echo $v_assignment->url ?>">
                                    <?php 
                                        //echo $v_assignment->person_first_name . ' ' . $v_assignment->person_last_name; 
                                        if(strlen($v_assignment->person_first_name) && strlen($v_assignment->person_last_name) < 20){
                                            echo $v_assignment->person_first_name . ' ' . $v_assignment->person_last_name;
                                         }
                                         else{
                                            echo substr($v_assignment->person_first_name, 0, 30).' '.substr($v_assignment->person_last_name, 0, 20).'...';
                                         } 
                                    ?>
                                </div>
                                <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                    <?php echo $v_assignment->post_date_time; ?>
                                </div>

                                <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                    <?php
                                    $post_status = $v_assignment->post_status;
//                            if ($post_status == 1) {
                                    ?>
                                        <!--<a href="//<?php // echo base_url() . 'make-inactive-group-post/' . $v_alert->post_id;                     ?>"><i class="fa fa-user-times" title="Inactive"></i></a>&nbsp;&nbsp;-->
                                    <?php // } else if ($post_status == 0) {   ?>
                                        <!--<a href="//<?php // echo base_url() . 'make-active-group-post/' . $v_alert->post_id;                     ?>" ><i class="fa fa-user-plus " title="Active"></i></a>&nbsp;&nbsp;-->
                                    <?php // }   ?>

                                    <?php
                                    if ($v_assignment->posted_by == $user_id || $group_details->group_created_by == $user_id) {
                                        if ($post_status != 2) {
                                            ?>
                                            <a href="#" onclick="return checkForDelete('<?php echo $v_assignment->post_id; ?>', '<?php echo $group_details->group_id; ?>')"><i class="fa fa-trash-o" title="Delete"></i></a>&nbsp;&nbsp;
                                            <?php
                                        }
                                    }
                                    ?>

                                </div>
                            </div>
                            <div class="col-sm-12"><br></div>
                                <?php
                            }
                        }
                        ?>
                </span>
                <?php echo $group_detail_assignment_pagination_link;?>
            </div>
        </div>
    </div>
</div>


<script>
    function checkForDelete(post_id, group_id) {
        swal({
            title: "",
            text: "Are you sure you want to Delete this Group Member?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#8CC73F',
            confirmButtonText: 'Yes',
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        var xmlhttp4 = false;
                        try {
                            xmlhttp4 = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (e) {
                            try {
                                xmlhttp4 = new ActiveXObject("Microsoft.XMLHTTP");
                            } catch (E) {
                                xmlhttp4 = false;
                            }
                        }
                        if (!xmlhttp4 && typeof XMLHttpRequest != 'undefined') {
                            xmlhttp4 = new XMLHttpRequest();
                        }



                        var url = '<?php echo base_url(); ?>' + 'remove-fornt-group-media-file-backend';
                        //   alert(post_id);
                        // var group_id=document.getElementById("group_id").value;
                        var url_name = document.getElementById("url_id").value;

                        var formdata = new FormData();
                        formdata.append("post_id", post_id);
                        formdata.append("group_id", group_id);

                        xmlhttp4.addEventListener("load", function () {
                            //  alert( xmlhttp4.responseText);
                            if (xmlhttp4.responseText == 1) {
                                swal('you can not delete this group.');

                            } else {
                                window.location = '<?php echo base_url(); ?>' + 'group/' + url_name + '/assignment';

                            }


                        }, false);
                        xmlhttp4.addEventListener("error", function () {
                            alert("not upload");
                        }, false);
                        xmlhttp4.addEventListener("abort", function () {
                            alert("Aborted");
                        }, false);

                        xmlhttp4.open("POST", url);
                        xmlhttp4.send(formdata);
                    }
                });
    }
    function downloadAssignment(post_id, group_id) {

        var xmlhttp = false;
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            xmlhttp = new XMLHttpRequest();
        }
        var url = '<?php echo base_url(); ?>' + 'download-fornt-end-assigment-file-authenticate';

        var formdata = new FormData();
        formdata.append("post_id", post_id);
        formdata.append("group_id", group_id);


        xmlhttp.addEventListener("load", function () {
            //  alert( xmlhttp.responseText);
            var downloadUrl = '<?php echo base_url(); ?>' + 'download-assignment-file-fornt-end-group/' + post_id;
            if (xmlhttp.responseText == 1) {

                window.location.replace(downloadUrl);

            }


        }, false);
        xmlhttp.addEventListener("error", function () {
            alert("not sent");
        }, false);
        xmlhttp.addEventListener("abort", function () {
            alert("Aborted");
        }, false);

        xmlhttp.open("POST", url);
        xmlhttp.send(formdata);


        return true;

    }

    $(document).ready(function () {
        var ajaxGroupUrl = '<?php echo base_url('group/ajax-group-post'); ?>';
        $(document).on('click', 'div[id^="viewGroup"]', function () {
            var url = this.id.replace('viewGroup', '');
            var groupUrl = $('#url_id').val();

            $.post(ajaxGroupUrl, {person_url: url, group_url: groupUrl, type: 3}, function (data) {
                $('#view_group_asignment').html(data);
            });
        });
    });
</script>
<script src="<?php echo base_url('front_end_resource/course/course_view.js'); ?>" type="text/javascript"></script>