<?php
if ($post_value) {
    $person_id = $this->session->userdata('person_id');
    $offset = $this->session->userdata('time_offset');
    ?>



    <div class="col-sm-10">

        <div class="row ">
            <div class="col-sm-12 ">

                <div class="col-sm-12">
                    <h3 class="text-left"> <?php // echo $post_value->post_file_original_name;     ?></h3>
                </div>

                <div class="col-sm-12"><hr></div>
                <?php if ($post_value->post_type == 5) { ?>
                    
                    <script src="<?php echo base_url(); ?>resource_library/js-video-player/plyr.js" type="text/javascript"></script>
                    

                    <div class="col-sm-12 padding-zero">

                        <div class="media col-sm-12 " style="font-size: 14px">
                            <div class="media-left">
                                <a href="<?php echo base_url() . $post_value->url . '/profile'; ?>">
                                    <img style="padding-left: 5px;" class="media-object" src="<?php
                                    if ($post_value->person_image) {
                                        echo base_url() . 'content-library/' . $post_value->url . '/' . $post_value->person_image_thumb;
                                    } else {
                                        echo base_url() . 'image/no_profile_picture.png';
                                    }
                                    ?>" alt="logo" width="50">
                                </a>
                            </div>
                            <div class="media-body ">

                                <h5 class="media-heading green text-justify"><?php echo $person_info->person_first_name . " " . $person_info->person_last_name; ?></h5>
                                <div class="col-sm-12">
                                    <div class="row">
                                        <video controls>
                                            <source src="<?php echo base_url() . 'content-library/' . $post_value->url . '/' . $post_value->post_details; ?>" type="video/mp4">                                                              
                                        </video>
                                    </div>
                                </div>

                            </div>

                        </div>


                    </div>
                    
                    
                <?php } else if ($post_value->post_type == 4) { ?>
                    <div class="col-sm-12 padding-zero">
                        <div class="media col-sm-12" style="font-size: 14px">
                            <div class="media-left">
                                <a href="<?php echo base_url() . $post_value->url . '/profile'; ?>">
                                    <img style="padding-left: 5px;" class="media-object" src="<?php
                                    if ($post_value->person_image) {
                                        echo base_url() . 'content-library/' . $post_value->url . '/' . $post_value->person_image_thumb;
                                    } else {
                                        echo base_url() . 'image/no_profile_picture.png';
                                    }
                                    ?>" alt="logo" width="50">
                                </a>
                            </div>
                            <div class="media-body">
                                <h5 class="media-heading green text-justify"><?php echo $person_info->person_first_name . " " . $person_info->person_last_name; ?></h5>

                                <div style="padding-left: 30px;"  id="video_player<?php echo $post_value->post_id; ?>">

                                    <img class="media-object "
                                         src="  <?php echo base_url() . $file_path; ?>" 
                                         alt="image File" width="450" height="300">                   

                                </div>

                            </div>

                            <div>
                                <hr>
                            </div>
                        </div>

                    </div>
                <?php } else if ($post_value->post_type == 1 || $post_value->post_type == 2) { ?>
                    <div class="col-sm-12 padding-zero">
                        <div class="media col-sm-12" style="font-size: 14px">
                            <div class="media-left">
                                <a href="<?php echo base_url() . $post_value->url . '/profile'; ?>">
                                    <img style="padding-left: 5px;" class="media-object" src="<?php
                                    if ($post_value->person_image) {
                                        echo base_url() . 'content-library/' . $post_value->url . '/' . $post_value->person_image_thumb;
                                    } else {
                                        echo base_url() . 'image/no_profile_picture.png';
                                    }
                                    ?>" alt="logo" width="50">
                                </a>
                            </div>
                            <div class="media-body">
                                <h5 class="media-heading green text-justify"><?php echo $person_info->person_first_name . " " . $person_info->person_last_name; ?></h5>

                                <div style="padding-left: 30px;"  id="video_player<?php echo $post_value->post_id; ?>">

                                    <?php echo $post_value->post_details; ?>            

                                </div>

                            </div>

                            <div>
                                <hr>
                            </div>
                        </div>

                    </div>

                <?php } else if ($post_value->post_type == 3) { ?>
                    <div class="col-sm-12 padding-zero">
                        <div class="media col-sm-12" style="font-size: 14px">
                            <div class="media-left">
                                <a href="<?php echo base_url() . $post_value->url . '/profile'; ?>">
                                    <img style="padding-left: 5px;" class="media-object" src="<?php
                                    if ($post_value->person_image) {
                                        echo base_url() . 'content-library/' . $post_value->url . '/' . $post_value->person_image_thumb;
                                    } else {
                                        echo base_url() . 'image/no_profile_picture.png';
                                    }
                                    ?>" alt="logo" width="50">
                                </a>
                            </div>
                            <div class="media-body">
                                <h5 class="media-heading green text-justify"><?php echo $person_info->person_first_name . " " . $person_info->person_last_name; ?></h5>
                                <div style="padding-left: 30px;"  id="video_player<?php echo $post_value->post_id; ?>">
                                    <?php
                                    $file_Name = $post_value->post_file_original_name;
                                    $file_explode = explode('.', $file_Name);
                                    $file_extention = $file_explode[count($file_explode) - 1];

                                    if ($file_extention == 'pdf') {
                                        ?>
                                        <a href="javascript:;" onclick="downloadAssignment('<?php echo $post_value->post_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 $post_value->post_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 $post_value->post_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 $post_value->post_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 $post_value->post_id; ?>')"> <img src="<?php echo base_url() . 'image/assignment/powerpoint.png' ?>"></a>

                                    <?php } ?>
                                    <?php echo $file_Name; ?>
                                </div>
                            </div>

                        </div>




                    </div>
                    <script>
                        function downloadAssignment(post_id) {


                            //alert(post_path);

                            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-assigment-file-authenticate';
                            //var message_id=messageId;
                            // alert(message_id);

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


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

                                    window.location.replace(downloadUrl);

                                }
                                // else if(xmlhttp.responseText == 'f'){
                                // alert("Your file is not found or Empty file.");
                                //}                 

                                //           else
                                //           {
                                //               alert("Download is canceled");
                                //           }

                            }, 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;

                        }
                    </script>
                <?php } ?>


            </div>
        </div>
    <?php } ?>

    <!-------------------(3) Start post User Like, Comment, library and Time Action  -------------->
    <div id="action<?php echo $post_value->post_id; ?>">
        <div class="media-bottom" style="margin-left: 75px" ><hr>
            <p class="text-justify" style="font-size: 14px;">
                <?php
                $liked_person_id1 = explode(",", $post_function[$post_value->post_id]->post_like_by);
                $liked_person_id = array_filter($liked_person_id1);
                if ($liked_person_id) {
                    echo 'read(' . count($liked_person_id) . ')';
                } else {
                    echo 'read';
                }
                ?>

                <a href="javascript:void(0)">
                    <?php
                    if ($post_value->post_comment_count == NULL) {
                        echo 'write';
                    } else {
                        echo 'write(' . $post_value->post_comment_count . ')';
                    }
                    ?>
                </a>

                <?php
                $added_library_person_id = explode(",", $post_function[$post_value->post_id]->post_add_to_my_library_by);
                echo '- library(' . count(array_filter($added_library_person_id)) . ')';
                ?>

                -<span>
                    <?php
                    $this->cf->time_format_for_read_write($post_value->post_date_time, $offset);
                    ?>
                </span>
            </p><hr>
        </div>
    </div>
    <!-------------------(3) END post User Like, Comment, library and Time Action  -------------->


    <div id="view_comment<?php echo $post_value->post_id; ?>">
        <?php
        $count_comments = 0;
        foreach ($post_comment[$post_value->post_id] as $comment_value) {
            ?>
            <div class="like_margin">
                <div class="col-sm-10 col-sm-offset-2"><hr></div>


                <!-----------------(4-a) Start Comment User Image --------------------->
                <div class="media-left">
                    <a href="<?php echo base_url() . $comment_value->url . '/profile'; ?>">
                        <img class="media-object" src="<?php
                        if ($comment_value->person_image) {
                            echo base_url() . 'content-library/' . $comment_value->url . '/' . $comment_value->person_image_thumb;
                        } else {
                            echo base_url() . 'image/no_profile_picture.png';
                        }
                        ?>" alt="logo" width="40">
                    </a>
                </div>
                <!-----------------(4-a) END Comment User Image --------------------->


                <!-----------------(4-b) Start Comment User Comments and Name --------------------->
                <div class="media-body">
                    <h5 class="media-heading green text-justify" style="font-size: 16px;">
                        <a href="<?php echo base_url() . $comment_value->url . '/profile'; ?>">
                            <?php echo $comment_value->person_first_name . ' ' . $comment_value->person_last_name; ?>
                        </a>
                    </h5>
                    <p class="text-justify" id="comment_detail<?php echo $comment_value->comment_id ?>">
                        <?php
                        if (strlen($comment_value->comment_details) > 100) {
                            $limited_string = mb_substr($comment_value->comment_details, 0, 100, 'utf-8');
                            echo $this->cf->view_emoticons($limited_string);
                            ?>
                            <a href="javascript:void(0)" style="padding-left: 10px;"
                               onclick="viewDetails('<?php echo base_url() . 'post/view_post_details/' . $comment_value->comment_id . '/comment' ?>', 'comment_detail', '<?php echo $comment_value->comment_id ?>')" >
                                more...
                            </a>
                            <?php
                        } else {
                            echo $this->cf->view_emoticons($comment_value->comment_details);
                        }
                        ?>
                    </p>
                </div>
                <!-----------------(4-b) END Comment User Comments and Name --------------------->




                <!-----------------Start View URL Details (if user Comment URL)------------------------>
                <?php
                if ($comment_url[$comment_value->comment_id]) {
                    $url_value = explode("URL: ", $comment_url[$comment_value->comment_id]->post_comment_url_info);
                    ?>
                    <div class="col-sm-10 col-sm-offset-2 text-left" style="margin: -10px 0 0 40px; ">
                        <div class="col-sm-12">
                            <h5>
                                <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                    <?php echo $url_value[2]; ?>
                                </a>
                            </h5>
                        </div>
                        <div class="col-sm-10 col-sm-offset-2" style="margin-top: -10px;">
                            <p style="font-size: 12px;">
                                <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                    <?php echo $url_value[3]; ?>
                                </a>
                            </p>
                        </div>
                        <div class="col-sm-10 col-sm-offset-2" style="margin-top: -10px;">
                            <h6>
                                <?php
                                if ($url_value[1]) {
                                    ?>
                                    <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                        <?php echo $url_value[1]; ?>
                                    </a>
                                    <?php
                                }
                                if ($url_value[4] == '') {
                                    echo '';
                                } else {
                                    echo 'BY | ';
                                    ?>
                                    <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457"><?php echo $url_value[4]; ?></a>
                                    <?php
                                }
                                ?>
                            </h6>
                        </div>
                    </div>
                <?php } ?>
                <!-----------------END View URL Details (if user Comment URL)------------------------>


                <!-----------------(4-c) Start Comments action --------------------->
                <div id="comment_like<?php echo $comment_value->comment_id; ?>">
                    <div class="media-bottom" style="margin-left: 75px" >
                        <p class="text-justify" style="font-size: 14px;">

                            <?php
                            $post_comment_like_array = explode(",", $comment_value->comment_like_by);
                            echo 'read (' . count(array_filter($post_comment_like_array)) . ')'
                            ?>

                            -<span>
                                <?php
                                $this->cf->time_format_for_read_write($comment_value->comment_date_time, $offset);
                                ?>
                            </span>
                        </p>
                    </div>
                </div>
                <!-----------------(4-c) END Comments action --------------------->



                <!------------------------------------(4-d) Start Comment Replay view----------------------------- -->
                <div id="comment_replay<?php echo $comment_value->comment_id; ?>" class="padding-zero col-sm-12" >
                    <?php
                    $replay_comment_counter = 0;
                    foreach ($comment_reply[$comment_value->comment_id] as $comment_replay_value) {
                        ?>
                        <div  class="col-sm-12"><hr></div>
                        <div class="media col-sm-10 col-sm-offset-2" style="font-size: 14px">


                            <!------------------------------------(4-d-i) Start Comment Replay User Image view----------------------------- -->

                            <div class="media-left">
                                <a href="<?php echo base_url() . $comment_replay_value->url . '/profile'; ?>">
                                    <img class="media-object " 
                                         src="<?php
                                         if ($comment_replay_value->person_image) {
                                             echo base_url() . 'content-library/' . $comment_replay_value->url . '/' . $comment_replay_value->person_image_thumb;
                                         } else {
                                             echo base_url() . 'image/no_profile_picture.png';
                                         }
                                         ?>" 
                                         alt="logo" width="30">
                                </a>
                            </div>
                            <!------------------------------------(4-d-i) END Comment Replay User Image view----------------------------- -->


                            <!------------------------------------(4-d-ii) Start Comment Reply User Name and Reply view----------------------------- -->
                            <div class="media-body">
                                <h5 class="media-heading green text-justify" style="font-size: 16px;">
                                    <a href="<?php echo base_url() . $comment_replay_value->url . '/profile'; ?>">
                                        <?php echo $comment_replay_value->person_first_name . ' ' . $comment_replay_value->person_last_name; ?>
                                    </a>
                                </h5>
                                <p class="text-justify" id="reply_comment_detail<?php echo $comment_replay_value->comment_id; ?>">
                                    <?php
                                    if (strlen($comment_replay_value->comment_details) > 80) {
                                        $limited_string = mb_substr($comment_replay_value->comment_details, 0, 80, 'utf-8');
                                        echo $this->cf->view_emoticons($limited_string);
                                        ?>
                                        <a href="javascript:void(0)" style="padding-left: 10px;"
                                           onclick="viewDetails('<?php echo base_url() . 'post/view_post_details/' . $comment_replay_value->comment_id . '/reply' ?>', 'reply_comment_detail', '<?php echo $comment_replay_value->comment_id; ?>')" >
                                            more...
                                        </a>
                                        <?php
                                    } else {
                                        echo $this->cf->view_emoticons($comment_replay_value->comment_details);
                                    }
                                    ?>
                                </p>
                            </div>
                            <!------------------------------------(4-d-ii) END Comment Reply User Name and Reply view----------------------------- -->



                            <!-----------------Start View URL Details (if user Comment Reply URL)------------------------>
                            <?php
                            if ($reply_comment_url[$comment_replay_value->comment_id]) {
                                $url_value = explode("URL: ", $reply_comment_url[$comment_replay_value->comment_id]->post_comment_url_info);
                                ?>
                                <div class="col-sm-10 col-sm-offset-2 text-left" style="margin: -10px 0 0 40px; ">
                                    <div class="col-sm-12">
                                        <h5>
                                            <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                                <?php echo $url_value[2]; ?>
                                            </a>
                                        </h5>
                                    </div>
                                    <div class="col-sm-10 col-sm-offset-2" style="margin-top: -10px;">
                                        <p style="font-size: 12px; text-align: justify;">
                                            <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                                <?php echo $url_value[3]; ?>
                                            </a>
                                        </p>
                                    </div>
                                    <div class="col-sm-10 col-sm-offset-2" style="margin-top: -10px;">
                                        <h6>
                                            <?php
                                            if ($url_value[1]) {
                                                ?>
                                                <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                                    <?php echo $url_value[1]; ?>
                                                </a>
                                                <?php
                                            }
                                            if ($url_value[4] == '') {
                                                echo '';
                                            } else {
                                                echo 'BY | ';
                                                ?>
                                                <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457"><?php echo $url_value[4]; ?></a>
                                                <?php
                                            }
                                            ?>
                                        </h6>
                                    </div>
                                </div>
                            <?php } ?>
                            <!-----------------END View URL Details (if user Comment Reply URL)------------------------>



                            <!------------------------------------(4-d-iii) Start Comment Reply User Name and Reply view----------------------------- -->
                            <div id="reply_comment_like<?php echo $comment_replay_value->comment_id ?>" class="padding-zero">
                                <div class="media-bottom" style="margin-left: 55px" >
                                    <p class="text-justify">   

                                        <?php
                                        $comment_reply_like_array = explode(",", $comment_replay_value->comment_like_by);
                                        echo 'read (' . count(array_filter($comment_reply_like_array)) . ') - ';
                                        ?>

                                        <span>
                                            <?php
                                            $this->cf->time_format_for_read_write($comment_replay_value->comment_date_time, $offset);
                                            ?>
                                        </span> 
                                    </p>
                                </div>



                                <!------------------------------------(4-d-iii-1) Start Comment Nested Reply Form----------------------------- -->

                                <div style="display: none"
                                     id="view_saaved_nested_replies<?php echo $comment_replay_value->comment_id; ?>" >
                                </div>
                                <!------------------------------------(4-d-iii-1) END Comment Nested Reply Form----------------------------- -->



                            </div>
                            <!------------------------------------(4-d-iii) END Comment Reply User Name and Reply view----------------------------- -->


                            <!------------------------------------(4-d-iv) Start view replies----------------------------- -->
                            <div id="view_nested_replies<?php echo $comment_replay_value->comment_id; ?>">

                                <?php
                                $nested_comment_counter = 0;
                                if ($total_nested_reply[$comment_replay_value->comment_id]->total_comment > 0 && $total_nested_reply[$comment_replay_value->comment_id]->total_comment != $nested_comment_counter) {
                                    ?>
                                    <div class="col-sm-12 text-left" style="margin-left: 40px;">
                                        <a href="javascript:void(0)"
                                           onclick="viewNestedReplies('<?php echo base_url() . 'super_admin_group/view_nested_replies/' . $comment_replay_value->comment_id . '/' . $nested_comment_counter; ?>', '<?php echo $comment_replay_value->comment_id; ?>')" >
                                            view replies
                                        </a>
                                    </div>
                                <?php } ?>
                            </div>
                            <!------------------------------------(4-d-iv) End view replies----------------------------- -->


                        </div>

                        <?php
                        $replay_comment_counter++;
                    }
                    if ($total_comment_reply[$comment_value->comment_id]->total_comment > $replay_comment_counter) {
                        ?>
                        <div class="col-sm-10 col-sm-offset-2 text-left" style="margin-left: 120px;">
                            <br>
                            <a href="javascript:void(0)"
                               onclick="viewMoreReply('<?php echo base_url() . 'super_admin_group/view_more_reply/' . $comment_value->comment_id . '/' . $replay_comment_counter; ?>', '<?php echo $comment_value->comment_id; ?>')" >
                                view more reply
                            </a>
                        </div>
                    <?php } ?>
                </div>
                <!---------------------------------------(4-d)END Comment Replay view----------------------------- -->


            </div>
            <?php
            $count_comments++;
        }
        ?>



        <!------------------------(4-e)View Writes Counter-------------------------------->
        <?php
//                                        echo $total_comment[$post_value->post_id]->total_comment .'---'. $count_comments;
        if ($total_comment[$post_value->post_id]->total_comment > $count_comments) {
            ?>
            <div class="col-sm-10 col-sm-offset-2 text-left" style="margin-left: 120px;">
                <br>
                <a href="javascript:void(0)"
                   onclick="viewWrites('<?php echo base_url() . 'super_admin_group/view_writes/' . $post_value->post_id . '/' . $count_comments; ?>', '<?php echo $post_value->post_id; ?>')" >
                    view writes
                </a>
            </div>
        <?php } ?>
        <!------------------------(4-e)View Writes Counter-------------------------------->


    </div>
    <script>
        function viewDetails(url, htmlID, ID) {
            serverPage = url;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
//            alert(xmlhttp.responseText);
                    documentID(htmlID + ID).innerHTML = xmlhttp.responseText;
                }
            };
            xmlhttp.send(null);
        }

        function viewNestedReplies(url, ID) {
            serverPage = url;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
//            alert(xmlhttp.responseText);
                    documentID('view_nested_replies' + ID).style.display = 'block';
                    documentID('view_nested_replies' + ID).innerHTML = xmlhttp.responseText;
                }
            };
            xmlhttp.send(null);
        }

        function viewMoreReply(url, ID) {
            serverPage = url;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
//            alert(xmlhttp.responseText);
                    documentID('comment_replay' + ID).innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.send(null);
        }

        function viewWrites(url, ID) {
            serverPage = url;
            xmlhttp.open("GET", serverPage);
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
//            alert(xmlhttp.responseText);
                    documentID('view_comment' + ID).innerHTML = xmlhttp.responseText;
                }
            };
            xmlhttp.send(null);
        }
    </script>
    