<?php if(!empty($data['schedules'])) { ?>
    <?php foreach($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 = $post['is_first']; ?>
                        <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 }?>
