<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 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">Posted By</div>
                    <div class="col-sm-2" style="padding: 0">Post 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_photo">
                    <?php
                    $user_id = $this->session->userdata('user_id');
                    if ($group_photo_post) {
                        foreach ($group_photo_post as $v_photo) {
                            $file_path = 'content-library/' . $v_photo->url . '/' . $v_photo->post_details;
                            ?>
                            <div class="col-sm-12 gray text-center" >
                                <div class="col-sm-2" style="padding: 10px 0 0 0  "><a href="javascript:;" onclick="downloadAssignment('<?php echo $v_photo->post_id; ?>', '<?php echo $group_details->group_id; ?>')"> <img class="img-responsive" style="margin: 0 auto; max-height: 50px; max-width: 50px; cursor: pointer;" 
                                                                                                                                                                                                                src="<?php echo base_url() . $file_path; ?>" 
                                                                                                                                                                                                                alt="image File" ></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_photo->post_id, '/', 'Tt') . '/2'; ?>"><?php echo $v_photo->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_photo->url ?>">
                                    <?php 
                                        //echo $v_photo->person_first_name . ' ' . $v_photo->person_last_name;
                                        if(strlen($v_photo->person_first_name) && strlen($v_photo->person_last_name) < 20){
                                            echo $v_photo->person_first_name . ' ' . $v_photo->person_last_name;
                                         }
                                         else{
                                            echo substr($v_photo->person_first_name, 0, 30).' '.substr($v_photo->person_last_name, 0, 20).'...';
                                         } 
                                    ?>
                                </div>
                                <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                    <?php echo $v_photo->post_date_time; ?>
                                </div>

                                <div class="col-sm-2" style="padding: 10px 0 0 0  ">
                                    <?php
                                    $post_status = $v_photo->post_status;
                                    if ($v_photo->posted_by == $user_id || $group_details->group_created_by == $user_id) {
                                        if ($post_status != 2) {
                                            ?>
                                            <a href="#" onclick="return checkForDelete('<?php echo $v_photo->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>
            </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 + '/photo';

                            }


                        }, 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: 4}, function (data) {
                $('#view_group_photo').html(data);
            });
        });
    });
</script>