<?php include('header.php');?>

<main id="dashboard">
    <div class="container">
        <div class="row">

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

                <div class="page-title">
                    <h1><strong> Schedule Comments </strong>   </h1>
                </div>

            </div>

            <div class="col-sm-3 text-right">
                <a href="<?php echo baseUrl('addnew.php');?>" class="btn btn-lg btn-success btn-block">Add Comment</a>
                <br>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-9">
                <?php include('cron_info.php');?>
            </div>
        </div>

        <div class="row">

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

                <div class="panel panel-fb">

                    <div class="panel-body">
                        <form action="<?php echo baseUrl('schedule.php');?>" class="form-horizontal" method="post">
                            <input type="hidden" name="submit" value="filter">
                            <div class="form-inline">
                                <div class="form-group col-sm-12 col-md-5">
                                    <div class="row">
                                        <label  class="radio-inline pln" for="exampleInputEmail3">Show : </label>

                                        <label class="radio-inline">
                                            <input name="radio_queue" id="inlineRadio1" value="0" type="radio" <?php echo empty($schedules_data['filter_date'])? ' checked="checked"':'';?>>  All queues
                                        </label>
                                        <label class="radio-inline">
                                            <input name="radio_queue" id="inlineRadio2" value="1" type="radio" <?php echo !empty($schedules_data['filter_date'])? ' checked="checked"':'';?>>  Queues between
                                        </label>

                                    </div>
                                </div>
                                <div class="form-group col-sm-8 col-md-6">
                                    <div class="input-group col-sm-5 col-xs-12">
                                        <input name="datefrom" type="text" value="<?php echo !empty($schedules_data['filter_date']['date_from'])? $schedules_data['filter_date']['date_from'] : date('m/d/Y',$current_timestamp);?>" class="form-control date_picker schedule_filter">
                                        <span class="input-group-addon"><i class="fa fa-calendar fa-fw"></i></span>
                                    </div>
                                    -
                                    <div class="input-group col-sm-5 col-xs-12">
                                        <input name="dateinto" type="text" value="<?php echo !empty($schedules_data['filter_date']['date_into'])? $schedules_data['filter_date']['date_into'] : date('m/d/Y',$current_timestamp);?>" class="form-control date_picker schedule_filter">
                                        <span class="input-group-addon"><i class="fa fa-calendar fa-fw"></i></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <button class="btn btn-info btn-filter"><i class="fa fa-filter"></i> Filter</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th class="col-xs-3 col-sm-3">Page / Group</th>
                                <th class="col-xs-8 col-sm-7">Post</th>
                                <th class="col-xs-2 col-sm-2"> </th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php if(!empty($schedules_data['schedules'])) { ?>
                            <?php foreach($schedules_data['schedules'] as $schedules) { $step = 0; ?>
                                <?php if(!empty($schedules['fan_pages'])) { ?>
                                    <?php foreach($schedules['fan_pages'] as $fan_page) { ?>
                                        <?php if(!empty($fan_page['posts'])) {?>
                                            <?php foreach($fan_page['posts'] as $post) {$step++; ?>
                                                <tr data-id="<?php echo base64_encode($schedules['id'])?>">
                                                    <td class="user-page">
                                                        <img class="user-pic" src="https://graph.facebook.com/<?php echo $fan_page['id'];?>/picture" alt="">
                                                        <span class="user-name"><?php echo $fan_page['name'];?></span>
                                                        <span class="user-info">
                                                            <?php if($schedules['source_type'] == 1) {?>
                                                                <span class="user-num"><?php echo $fan_page['likes'];?> Fans</span>
                                                                <a target="_blank" href="https://facebook.com/<?php echo $fan_page['id'];?>" class="user-link"> <i class="fa fa-facebook"></i>View page </a>
                                                            <?php } else { ?>
                                                                <a target="_blank" href="https://facebook.com/<?php echo $fan_page['id'];?>" class="user-link"> <i class="fa fa-facebook"></i>View group </a>
                                                            <?php } ?>
                                                        </span>
                                                    </td>
                                                    <td class="user-post">
                                                        <img src="<?php echo $post['picture'];?>" alt="" class="post-img">
                                                        <span class="post-title"><?php echo $post['title'];?></span>
                                                        <span class="post-info">
                                                            <span class="post-comments"> <i class="fa fa-comments"></i> <?php echo $post['comments'];?> </span>
                                                            <span class="post-links"> <i class="fa fa-thumbs-up"></i> <?php echo $post['likes'];?> </span>
                                                            <span class="post-date"> <?php echo empty($post['created']) ? '' : date('m/d/Y h:i A',strtotime($post['created']));?> </span>
                                                            <a target="_blank" href="https://facebook.com/<?php echo $post['id'];?>" class="user-link"> <i class="fa fa-facebook"></i>View post </a>
                                                        </span>
                                                        <?php
                                                            $completed_txt = $post['completed'];
                                                            if($post['completed'] == 0 && !$post['can_comment'])
                                                                $completed_txt = "It is not possible to reply to comments of this post.";
                                                        ?>
                                                        <span class="post-comment"> Comments Posted: <?php echo $completed_txt;?> </span>
                                                    </td>
                                                    <td class="text-right">
                                                        <?php if($step == 1) {?>
                                                            <a id="edit_schedule" href="#" data-id="<?php echo base64_encode($schedules['id'])?>" class="btn btn-gray btn-sm btn-block">Edit</a>
                                                            <a id="delete_schedule" href="#" data-id="<?php echo base64_encode($schedules['id'])?>" class="btn btn-danger btn-sm btn-block">Delete</a>
                                                        <?php }?>
                                                    </td>
                                                </tr>
                                            <?php }?>
                                        <?php }else{$step++;?>
                                            <tr data-id="<?php echo base64_encode($schedules['id'])?>">
                                                <td class="user-page">
                                                    <img class="user-pic" src="https://graph.facebook.com/<?php echo $fan_page['id'];?>/picture" alt="">
                                                    <span class="user-name"><?php echo $fan_page['name'];?></span>
                                                        <span class="user-info">
                                                            <?php if($schedules['source_type'] == 1) {?>
                                                                <span class="user-num"><?php echo $fan_page['likes'];?> Fans</span>
                                                                <a target="_blank" href="https://facebook.com/<?php echo $fan_page['id'];?>" class="user-link"> <i class="fa fa-facebook"></i>View page </a>
                                                            <?php } else { ?>
                                                                <a target="_blank" href="https://facebook.com/<?php echo $fan_page['id'];?>" class="user-link"> <i class="fa fa-facebook"></i>View group </a>
                                                            <?php } ?>
                                                        </span>
                                                </td>
                                                <td class="user-post text-left" style="vertical-align: middle">
                                                    Post: N/A (<?php echo ($schedules['condition_type'] == 1) ? 'Latest Post' : 'Keyword Search';?>)
                                                    <span class="post-comment"> Comments Post: 0 </span>
                                                </td>
                                                <td class="text-right">
                                                    <?php if($step == 1) {?>
                                                        <a id="edit_schedule" href="#" data-id="<?php echo base64_encode($schedules['id'])?>" class="btn btn-gray btn-sm btn-block">Edit</a>
                                                        <a id="delete_schedule" href="#" data-id="<?php echo base64_encode($schedules['id'])?>" class="btn btn-danger btn-sm btn-block">Delete</a>
                                                    <?php }?>
                                                </td>
                                            </tr>
                                        <?php }?>
                                    <?php }?>
                                <?php }?>
                            <?php }?>
                        <?php }?>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <br>
        <br>
        <div class="row">
            <div class="col-sm-3">
                <a id="load_more_schedules" href="#" class="btn btn-info" data-id="<?php echo LOAD_SCHEDULE_POSTS?>">Load more...</a>
            </div>
        </div>
    </div>
</main>

<?php include('footer.php');?>
