<?php
    foreach($feeds as $feed):
    $feedData     = json_decode($feed['json'], true);    
    $activityName = $feed['section'];
    
    // get listings photo
    if( array_key_exists('listingsNum', $feedData) ){

        $feedData['listings'] = mysql_get('listings', $feedData['listingsNum'], null, "`timezone`,`monday_open`,`monday_close`,`tuesday_open`,`tuesday_close`,`wednesday_open`,`wednesday_close`,`thursday_open`,`thursday_close`,`friday_open`,`friday_close`,`saturday_open`,`saturday_close`,`sunday_open`,`sunday_close`, `latitude`, `longitude`, `address_1`,`address_2`, `name`, `city`, `average_rating`, `checkins`, `cuisine`, `coupons`, `reviews`, `followers`, `num`");

        $feedData['listings']['recent_photo'] = "https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/landing_page/listPlaceholder.png";

        // add listings recent photos
        $imageRecords = mysql_select('photo_uploads', "`listingsNum` = ".intval($feedData['listingsNum'])." AND `for_photo` = 'photo' AND `flagged` = 0 ORDER BY `createdDate` DESC LIMIT 0,1");
        foreach($imageRecords as $photoKey => $photo){ 
          $imageFiles = getUploadRecords('photo_uploads', 'photos', $photo['num']);
            foreach($imageFiles as $file){
                $feedData['listings']['recent_photo'] = $file['thumbUrlPath3'];
            }
        }
        // add listing close time
        // $feedData['listings'] = api_addOpenCloseDetailsToListing($feedData['listings']);
    }

    $feedData['members'] = mysql_get('members', $feedData['membersNum'], null, "`facebook_picture`, `facebook_first_name`, `facebook_last_name`, `username`, `num`, `isAdmin`, `points`, `check_ins`, `following`, `followers`, `reviews`");

    $userName = $feedData['members']['facebook_first_name'];
    if(@$feedData['members']['facebook_last_name']){
        $userName .= " ".@$feedData['members']['facebook_last_name'][0].".";
    }
?>
    <?php if($activityName == "reviews"): ?>
    <div class="feed_section clearfix">
        <div class="user_info_wrap clearfix">
            <div class="user_img">
                <img width="30" height="30" src="<?php echo $feedData['members']['facebook_picture']; ?>">
            </div>
            <div class="comment_info">
                <div class="user_name">
                    <span><?php echo $userName; ?></span>
                </div>
                <div class="user_action">
                    <span class="user_action_txt">Leaves a Tip</span>
                    <span class="time"><?php echo shortPrettyDate($feed['action_date']); ?></span>
                </div>
            </div>
            <div class="feed_points">
                <span class="tip_icon" style="margin-right: 5px;">
                    <img style="vertical-align:middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/tips-small.png" alt="">
                </span>
                <span>20</span>
            </div>
        </div>
        <div class="sponser_image_row clearfix" style="text-align: left;">
            <div style="float: left;">
                <img style="border-radius: 5px;width:50px;" src="<?php echo $feedData['listings']['recent_photo']; ?>" />
            </div>
            <div class="clearfix activity_info" style="float: left;padding-top: 5px;">
                <div class="listing_name"><?php echo $feedData['listings']['name']; ?></div>
                <div class="activity_images">
                    <?php $x = 1; for($x=1;$x<=$feedData['listings']['average_rating'];$x++){ ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small-yellow.png"/>
                    <?php } while($x<=5) { ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small.png"/>
                    <?php $x++; } ?>
                </div>
            </div>
        </div>
        <div class="comment_wrap" style="margin-top: 10px;">
            <div class="comment_desc">
                <?php echo $feedData['tip_content']; ?>
            </div>
        </div>
    </div>
    <hr style="margin:0;width: 100%;border: 3px solid #ddd;">
    <?php endif; ?>
    <?php if($activityName == 'user_badges'):

        $feedData['badges'] = mysql_get('badges', $feedData['badgesNum'], null, "`badge_name`, `badge_description`, `points`, `badge_type`");

        $feedData['badges']['completed_image'] = getUploadRecords('badges', 'completed_image', $feedData['badgesNum']);
        $feedData['badges']['gif_badge'] = getUploadRecords('badges', 'gif_badge', $feedData['badgesNum']);
        if(count($feedData['badges']['gif_badge'])){
            $badgeImage = $feedData['badges']['gif_badge'][0]['urlPath'];
        }else{
            $badgeImage = $feedData['badges']['completed_image'][0]['urlPath'];
        } 

    ?>
    <div class="feed_section clearfix">
        <div class="user_info_wrap clearfix">
            <div class="user_img">
                <img width="30" height="30" src="<?php echo $feedData['members']['facebook_picture']; ?>">
            </div>
            <div class="comment_info">
                <div class="user_name">
                    <span><?php echo $userName; ?></span>
                </div>
                <div class="user_action">
                    <span class="user_action_txt">Unlocks an achievement</span>
                    <span class="time"><?php echo shortPrettyDate($feed['action_date']); ?></span>
                </div>
            </div>
        <div class="feed_points">
          <span class="badge_icon" style="font-size: 11px;color: #666;margin-right: 5px;">
            <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/badge-small.png">
          </span>
          <span>100</span>
        </div>
      </div>
      <div class="sponser_image_row clearfix" style="text-align: left;">
        <div style="float: left;">
            <img style="width:50px;" src="<?php echo $badgeImage; ?>" />
        </div>
        <div class="clearfix activity_info" style="float: left;padding-top: 5px;">
          <div class="badge_name"><?php echo $feedData['badges']['badge_name']; ?></div>
          <div class="badge_desc comment_desc">
            <?php echo $feedData['badges']['badge_description']; ?>
          </div>
        </div>
      </div>
    </div>
    <hr style="margin:0;width: 100%;border: 3px solid #ddd;">
    <?php endif; ?>
    <?php if($activityName == 'user_follows'): ?>
        <div class="feed_section clearfix">
            <div class="user_info_wrap clearfix">
                <div class="user_img">
                    <img width="30" height="30" src="<?php echo $feedData['members']['facebook_picture']; ?>">
                </div>
                <div class="comment_info">
                    <div class="user_name">
                        <span><?php echo $userName; ?></span>
                    </div>
                     <div class="user_action">
                        <span class="user_action_txt">Follows</span>
                        <span class="time"><?php echo shortPrettyDate($feed['action_date']); ?></span>
                    </div>
                </div>
                <div class="points" style="float: right;">
                    <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/follow-user-small.png"/>
                </div>
            </div>
            <div class="sponser_image_row clearfix" style="text-align: left;">
                <div style="float: left;">
                    <img style="border-radius:50%;width:50px;" src="<?php echo $feedData['user_following.facebook_picture']; ?>" />
                </div>
                <div class="clearfix activity_info" style="float: left;padding-top: 5px;">
                    <?php $followingUserName = $feedData['user_following.facebook_first_name']." ".@$feedData['user_following.facebook_last_name'][0]; ?>
                    <div class="following_name"><?php echo $followingUserName; ?></div>
                    <div class="activity_images">
                        <span>
                            <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/follow-user-small.png"/>
                            <?php echo $feedData['user_following.followers']; ?>
                        </span>
                        <span>
                            <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/tips-small.png">
                            <?php echo $feedData['user_following.reviews']; ?>
                        </span>
                        <span>
                            <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/checkin-small.png">
                            <?php echo $feedData['user_following.check_ins']; ?>
                        </span>
                    </div>
                </div>
            </div>
        </div>
        <hr style="margin:0;width: 100%;border: 3px solid #ddd;">
    <?php endif; ?>
    <?php if($activityName == 'listings_follows'): ?>
    <div class="feed_section clearfix">
        <div class="user_info_wrap clearfix">
            <div class="user_img">
                <img width="30" height="30" src="<?php echo $feedData['members']['facebook_picture']; ?>">
            </div>
            <div class="comment_info">
                <div class="user_name">
                    <span><?php echo $userName; ?></span>
                </div>
                <div class="user_action">
                    <span class="user_action_txt">Follows</span>
                    <span class="time"><?php echo shortPrettyDate($feed['action_date']); ?></span>
                </div>
            </div>
            <div class="points" style="float: right;">
                <span class="tip_icon" style="margin-right: 5px;">
                    <img style="vertical-align:middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/follow-place-small.png" alt="">
                </span>
            </div>
        </div>
        <div class="sponser_image_row clearfix" style="text-align: left;">
            <div style="float: left;">
                <img style="border-radius: 5px;width:50px;" src="<?php echo $feedData['listings']['recent_photo'] ?>" />
            </div>
            <div class="clearfix activity_info" style="float: left;padding-top: 5px;">
                <div class="listing_name"><?php echo $feedData['listings']['name']; ?></div>
                <div class="activity_images">
                    <div >
                        <?php $x = 1; for($x=1;$x<=4;$x++){ ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small-yellow.png"/>
                        <?php } while($x<=5) { ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small.png"/>
                        <?php $x++; } ?>
                    </div>
                    <span>
                        <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/follow-user-small.png"/>
                        <?php echo $feedData['listings']['followers']; ?>
                    </span>
                    <span>
                        <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/tips-small.png">
                        <?php echo $feedData['listings']['reviews']; ?>
                    </span>
                    <span>
                        <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/checkin-small.png">
                        <?php echo $feedData['listings']['checkins']; ?>
                    </span>
                </div>
            </div>
        </div>
    </div>
    <hr style="margin:0;width: 100%;border: 3px solid #ddd;">
    <?php endif; ?>
    <?php if($activityName == 'ratings'): ?>
    <div class="feed_section clearfix">
        <div class="user_info_wrap clearfix">
            <div class="user_img">
                <img width="30" height="30" src="<?php echo $feedData['members']['facebook_picture']; ?>">
            </div>
            <div class="comment_info">
                <div class="user_name">
                    <span><?php echo $userName; ?></span>
                </div>
                <div class="user_action">
                    <span class="user_action_txt">Rates</span>
                    <span class="time"><?php echo shortPrettyDate($feed['action_date']); ?></span>
                </div>
            </div>
            <div class="feed_points">
                <span class="tip_icon" style="margin-right: 5px;">
                    <img style="vertical-align:middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small.png" alt="">
                </span>
                <span>15</span>
            </div>
        </div>
        <div class="sponser_image_row clearfix" style="text-align: left;">
            <div style="float: left;">
                <img style="border-radius: 5px;width:50px;" src="<?php echo $feedData['listings']['recent_photo']; ?>" />
            </div>
            <div class="clearfix activity_info" style="float: left;padding-top: 5px;">
                <div class="listing_name"><?php echo $feedData['listings']['name']; ?></div>
                <div class="activity_images">
                    <?php $x = 1; for($x=1;$x<=$feedData['rating'];$x++){ ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small-yellow.png"/>
                    <?php } while($x<=5) { ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small.png"/>
                    <?php $x++; } ?>
                </div>
            </div>
        </div>
    </div>
    <hr style="margin:0;width: 100%;border: 3px solid #ddd;">
    <?php endif; ?>
    <?php if($activityName == 'foodie_experience'): ?>
        <div class="feed_section clearfix">
            <div class="user_info_wrap clearfix">
                <div class="user_img">
                    <img width="30" height="30" src="<?php echo $feedData['members']['facebook_picture']; ?>">
                </div>
                <div class="comment_info">
                    <div class="user_name">
                        <span><?php echo $userName; ?></span>
                    </div>
                    <div class="user_action">
                        <span class="user_action_txt">Takes a survey</span>
                        <span class="time"><?php echo shortPrettyDate($feed['action_date']); ?></span>
                    </div>
                </div>
                <div class="feed_points">
                    <img  style="vertical-align:middle;"src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/emoji-happy-small.png"/>
                    <span>20</span>
                </div>
            </div>
            <div class="sponser_image_row clearfix" style="text-align: left;">
                <div style="float: left;">
                    <img style="border-radius: 5px;width:50px;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/FoodieExp3x.png" />
                </div>
                <div class="activity_info clearfix" style="float: left;padding-top: 5px;">
                    <div class="badge_name">Halal Experience</div>
                    <div class="badge_desc comment_desc">
                        <?php echo $feedData['listings']['name'] ?>
                    </div>
                </div>
            </div>
        </div>
        <hr style="margin:0;width: 100%;border: 3px solid #ddd;">
    <?php endif; ?>
    <?php if($activityName == 'check_ins'): ?>
        <div class="feed_section clearfix">
            <div class="user_info_wrap clearfix">
                <div class="user_img">
                    <img width="30" height="30" src="<?php echo @$feedData['members']['facebook_picture']; ?>">
                </div>
                <div class="comment_info">
                    <div class="user_name">
                        <span><?php echo $userName; ?></span>
                    </div>
                    <div class="user_action">
                        <span class="user_action_txt">Checks in</span>
                        <span class="time"><?php echo shortPrettyDate($feed['action_date']); ?></span>
                    </div>
                </div>
                <div class="feed_points">
                    <span class="check_in_icon" style="margin-right: 5px;">
                        <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/checkin-small.png">
                    </span>
                    <span>10</span>
                </div>
            </div>
            <div class="sponser_image_row clearfix" style="text-align: left;">
                <div style="float: left;">
                    <img style="border-radius: 5px;width:50px;" src="<?php echo $feedData['listings']['recent_photo']; ?>" />
                </div>

                <div class="activity_info" style="float: left;padding-top: 5px;">
                    <div class="listing_name"><?php echo $feedData['listings']['name']; ?></div>
                    <div class="activity_images">
                        <?php $x = 1; for($x=1;$x<=$feedData['listings']['average_rating'];$x++){ ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small-yellow.png"/>
                    <?php } while($x<=5) { ?>
                        <img src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/rating-small.png"/>
                    <?php $x++; } ?>
                    </div>
                </div>
            </div>
            <div class="comment_wrap" style="margin-top: 10px;">
                <?php
                    $dotImage = "green";

                    $address = "";
                    if(!empty($feedData['listings']['address_1']))
                        $address = $feedData['listings']['address_1'];
                    if(!empty($feedData['listings']['address_2']))
                        $address .= ", ".$feedData['listings']['address_2'];
                    if(!empty($feedData['listings']['city']))                                        
                        $address .= ", ".$feedData['listings']['city'];  
                                       
                ?>
                <div class="map_top_content">
                    <span>
                        <img width="8px" style="margin-right: 5px;" src="https://s3-us-west-1.amazonaws.com/urban-halal/static_assets/landing_page/<?php echo $dotImage; ?>_dot.png" alt="">&nbsp;&nbsp;
                        <?php echo trim($address, ", "); ?>
                    </span>
                </div>
                <div class="checked_in_map" id="feed_map_<?php echo $feedData['num']; ?>"></div>
                <?php if($feedData['listings']['latitude']): ?>
                <script type="text/javascript">
                    function initialize() {
                       var latlng = new google.maps.LatLng(<?php echo $feedData['listings']['latitude']; ?>, <?php echo $feedData['listings']['longitude']; ?>);
                        var map = new google.maps.Map(document.getElementById('feed_map_<?php echo $feedData['num']; ?>'), {
                          center: latlng,
                          zoom: 12
                        });
                        var marker = new google.maps.Marker({
                          map: map,
                          position: latlng,
                          draggable: false,
                          anchorPoint: new google.maps.Point(0, -29)
                       });
                    }
                    initialize();
                </script>
                <?php endif; ?>
            </div>
        </div>
        <hr style="margin:0;width: 100%;border: 3px solid #ddd;">
    <?php endif; ?>
<?php endforeach; ?>