<?php

    $limit = @$_REQUEST['limit'] ? @$_REQUEST['limit'] : 10;
    $offset = @$_REQUEST['limit'] ? @$_REQUEST['offset'] : 0;

    $reviews = mysql_select("feed", "`section` = 'reviews'  ORDER BY `action_date` DESC LIMIT $limit OFFSET $offset");
?>
<?php

    foreach($reviews as $review):
        $reviewData     = json_decode($review['json'], true);    
        
        if( array_key_exists('listingsNum', $reviewData) ){

            $reviewData['listings'] = mysql_get('listings', $reviewData['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`, `name`, `city`, `average_rating`, `checkins`, `cuisine`, `coupons`, `reviews`, `followers`, `num`");
            // add listings recent photos
            $reviewData['listings']['recent_photos'] = mysql_select('photo_uploads', "`listingsNum` = ".intval($reviewData['listingsNum'])." AND `for_photo` = 'photo' AND `flagged` = 0 ORDER BY `createdDate` DESC LIMIT 0,1");
            foreach($reviewData['listings']['recent_photos'] as $photoKey => $photo){ 
              $reviewData['listings']['recent_photos'][$photoKey]['photos'] = getUploadRecords('photo_uploads', 'photos' , $photo['num']);
            }
            // add listing close time
            // $reviewData['listings'] = api_addOpenCloseDetailsToListing($reviewData['listings']);
        }

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

        $userName = $reviewData['members']['facebook_first_name']." ".$reviewData['members']['facebook_last_name'][0];
?>
        
        <div class="feed_section stats_section clearfix">
            <div class="user_info_wrap clearfix" style="margin: 5px 0;">
                <div class="user_img">
                    <img width="30" height="30" src="<?php echo $reviewData['members.facebook_picture']; ?>">
                </div>
                <div class="comment_info">
                    <div class="user_name">
                        <span><?php echo $userName; ?>.</span>
                    </div>
                    <div class="user_action">
                        <span style="font-size: 12px;">Leaves a Tip</span>
                        <span id="time" style="color: #9b9b9b;font-size: 12px;"><?php echo shortPrettyDate($review['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/tips-small.png" alt="">
                    </span>
                    <span style="color: #5BBC2E;font-size: 12px;">20 PTS</span>
                </div>
            </div>
            <div class="sponser_image_row clearfix" style="text-align: left;">
                <div style="border-radius:5px;width:50px;height:50px;float: left;">
                    <img style="border-radius: 5px;width:100%;max-width:100%;max-height:100%;" src="<?php echo empty($reviewData['listings']['recent_photos'][0]['photos']) ? '' : $reviewData['listings']['recent_photos'][0]['photos'][0]['thumbUrlPath2']; ?>" />
                </div>
                <div class="clearfix activity_info" style="float: left;padding-top: 5px;">
                    <div class="listing_name"><?php echo $reviewData['listings']['name']; ?></div>
                    <div class="activity_images rating_images">
                        <?php $x = 1; for($x=1;$x<=$reviewData['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-grey.png"/>
                        <?php $x++; } ?>
                    </div>
                </div>
            </div>
            <div class="comment_wrap" style="margin-top: 10px;">
                <div class="comment_desc">
                    <?php echo $reviewData['tip_content']; ?>
                </div>
            </div>
        </div>
        
        <hr style="margin:0;">
<?php
    endforeach;
?>        