/**
 * Get the rating star labels for translation
 *
 * @since 1.1.6
 * @package GeoDirectory_Review_Rating_Manager
 *
 * @global object $wpdb WordPress database abstraction object.
 *
 * @param  array $translation_texts Array of text strings.
 * @return array
 */
function geodir_reviewrating_db_translation($translation_texts = array())
{
    global $wpdb;
    $translation_texts = !empty($translation_texts) && is_array($translation_texts) ? $translation_texts : array();
    // Overall star labels
    $overall_labels = get_option('geodir_reviewrating_overall_rating_texts');
    if (!empty($overall_labels)) {
        foreach ($overall_labels as $label) {
            if ($label != '') {
                $translation_texts[] = stripslashes_deep($label);
            }
        }
    }
    // Rating style table
    $sql = "SELECT name, star_lables FROM `" . GEODIR_REVIEWRATING_STYLE_TABLE . "`";
    $rows = $wpdb->get_results($sql);
    if (!empty($rows)) {
        foreach ($rows as $row) {
            if (!empty($row->name)) {
                $translation_texts[] = stripslashes_deep($row->name);
            }
            if (!empty($row->star_lables)) {
                $labels = geodir_reviewrating_star_lables_to_arr($row->star_lables);
                if (!empty($labels)) {
                    foreach ($labels as $label) {
                        if ($label != '') {
                            $translation_texts[] = stripslashes_deep($label);
                        }
                    }
                }
            }
        }
    }
    // Rating category table
    $sql = "SELECT title FROM `" . GEODIR_REVIEWRATING_CATEGORY_TABLE . "`";
    $rows = $wpdb->get_results($sql);
    if (!empty($rows)) {
        foreach ($rows as $row) {
            if (!empty($row->title)) {
                $translation_texts[] = stripslashes_deep($row->title);
            }
        }
    }
    $translation_texts = !empty($translation_texts) ? array_unique($translation_texts) : $translation_texts;
    return $translation_texts;
}
/**
 * Adds rating box to admin comment edit page.
 *
 * @since 1.0.0
 * @package GeoDirectory_Review_Rating_Manager
 *
 * @global object $wpdb WordPress Database object.
 *
 * @param object $comment Comment object.
 * @return bool
 */
function geodir_reviewrating_comment_rating_box($comment)
{
    if ($overall_star = get_option('geodir_reviewrating_overall_count')) {
        $post_type = get_post_type($comment->comment_post_ID);
        $all_postypes = geodir_get_posttypes();
        if (!in_array($post_type, $all_postypes)) {
            return false;
        }
        $overall_star_lable = get_option('geodir_reviewrating_overall_rating_texts');
        $star_color = get_option('geodir_reviewrating_overall_color');
        $overall_star_offimg = get_option('geodir_reviewrating_overall_off_img');
        $star_width = get_option('geodir_reviewrating_overall_off_img_width');
        global $comment, $wpdb, $is_geodir_loop;
        $comment_ratings = geodir_reviewrating_get_comment_rating_by_id($comment->comment_ID);
        if (!empty($comment_ratings)) {
            ?>
		<div id="gd_ratings_module">
				<div id="rating_frm" style="margin-top:15px;">
					<lable for="rating"><?php 
            _e('You can rate the area', GEODIRREVIEWRATING_TEXTDOMAIN);
            ?>
</lable>
					<div class="gd-rating-box-in clearfix">
						 <div class="gd-rating-box-in-left">
								 <div class="gd-rate-area clearfix">
										<span class="gd-ratehead"><?php 
            _e('Rate this area:', GEODIRREVIEWRATING_TEXTDOMAIN);
            ?>
</span>
											<ul class="rate-area-list">
											<?php 
            for ($star = 1; $star <= $overall_star; $star++) {
                if ($comment_ratings->overall_rating && $star <= (int) $comment_ratings->overall_rating) {
                    $active = 'active';
                } else {
                    $active = '';
                }
                $overall_star_text = isset($overall_star_lable[$star - 1]) ? esc_attr($overall_star_lable[$star - 1]) : '';
                $overall_star_text = stripslashes_deep(__($overall_star_text, GEODIRECTORY_TEXTDOMAIN));
                ?>
													<li star_rating="<?php 
                echo $star;
                ?>
" star_lable="<?php 
                echo $overall_star_text;
                ?>
"  class="gd-multirating-star <?php 
                echo $active;
                ?>
"><a><img src="<?php 
                echo $overall_star_offimg;
                ?>
" style="width:<?php 
                echo $star_width;
                ?>
px" alt="<?php 
                esc_attr_e('rating icon', GEODIRREVIEWRATING_TEXTDOMAIN);
                ?>
" /></a></li>
											<?php 
            }
            ?>
											</ul>
                                          <?php 
            $overall_star_text = isset($overall_star_lable[$comment_ratings->overall_rating - 1]) ? esc_attr($overall_star_lable[$comment_ratings->overall_rating - 1]) : '';
            $overall_star_text = stripslashes_deep(__($overall_star_text, GEODIRECTORY_TEXTDOMAIN));
            ?>
 
                                        <style>#rating_frm ul.rate-area-list li.active{background-color:<?php 
            echo $star_color;
            ?>
}</style>
											<span class="gd-rank"><?php 
            echo $comment_ratings->overall_rating ? $overall_star_text : '&nbsp;';
            ?>
</span>
											<input type="hidden" name="geodir_rating[overall]" value="<?php 
            echo $comment_ratings->overall_rating ? $comment_ratings->overall_rating : '0';
            ?>
"  />
								</div> 
					<?php 
            $post_type = get_post_type($comment->comment_post_ID);
            $post_categories = wp_get_post_terms($comment->comment_post_ID, $post_type . 'category', array('fields' => 'ids'));
            $ratings = geodir_reviewrating_rating_categories();
            $old_ratings = @unserialize($comment_ratings->ratings);
            if ($ratings) {
                ?>
					<div class="gd-rate-category clearfix">
									<span class="gd-ratehead"><?php 
                _e('Rate this area:', GEODIRREVIEWRATING_TEXTDOMAIN);
                ?>
</span>
									<div><?php 
                foreach ($ratings as $rating) {
                    //$star_lable = explode(",",$rating->star_lables);
                    $star_lable = geodir_reviewrating_star_lables_to_arr($rating->star_lables, true);
                    $rating->title = isset($rating->title) && $rating->title != '' ? __($rating->title, GEODIRECTORY_TEXTDOMAIN) : '';
                    $rating_cat = explode(",", $rating->category);
                    $showing_cat = array_intersect($rating_cat, $post_categories);
                    if (!empty($showing_cat)) {
                        if ($rating->check_text_rating_cond) {
                            ?>
															<div class="clearfix gd-rate-cat-in">
																	<span class="lable"><?php 
                            echo $rating->title;
                            ?>
</span>
																	<ul class="rate-area-list rating-<?php 
                            echo $rating->id;
                            ?>
">
																	<?php 
                            for ($star = 1; $star <= $rating->star_number; $star++) {
                                if ($old_ratings[$rating->id] && $star <= (int) $old_ratings[$rating->id]) {
                                    $active = 'active';
                                } else {
                                    $active = '';
                                }
                                $star_lable_text = isset($star_lable[$star - 1]) ? esc_attr($star_lable[$star - 1]) : '';
                                $star_lable_text = stripslashes_deep($star_lable_text);
                                ?>
																		<li star_rating="<?php 
                                echo $star;
                                ?>
" star_lable="<?php 
                                echo $star_lable_text;
                                ?>
"  class="gd-multirating-star <?php 
                                echo $active;
                                ?>
"><a><img src="<?php 
                                echo $rating->s_img_off;
                                ?>
" style="width:<?php 
                                echo $rating->s_img_width;
                                ?>
px" alt="<?php 
                                esc_attr_e('rating icon', GEODIRREVIEWRATING_TEXTDOMAIN);
                                ?>
" /></a></li>
																	<?php 
                            }
                            ?>
																	</ul>
																	<?php 
                            $star_lable_text = isset($star_lable[$old_ratings[$rating->id] - 1]) ? esc_attr($star_lable[$old_ratings[$rating->id] - 1]) : '';
                            $star_lable_text = stripslashes_deep($star_lable_text);
                            ?>
                                          <style>#rating_frm ul.rating-<?php 
                            echo $rating->id;
                            ?>
 li.active{background-color:<?php 
                            echo $rating->star_color;
                            ?>
}</style>

																	<span class="gd-rank"><?php 
                            echo $old_ratings[$rating->id] ? $star_lable_text : '&nbsp;';
                            ?>
</span>
																	<input type="hidden" name="geodir_rating[<?php 
                            echo $rating->id;
                            ?>
]" value="<?php 
                            echo $old_ratings[$rating->id] ? $old_ratings[$rating->id] : '0';
                            ?>
"  />
															</div>
						<?php 
                        } else {
                            ?>
							<div class="clearfix gd-rate-cat-in">
									<span class="lable"><?php 
                            _e($rating->title, GEODIRREVIEWRATING_TEXTDOMAIN);
                            ?>
</span>
									<select name="geodir_rating[<?php 
                            echo $rating->id;
                            ?>
]" > 
										<?php 
                            for ($star = 1; $star <= $rating->star_number; $star++) {
                                $star_lable_text = isset($star_lable[$star - 1]) ? esc_attr($star_lable[$star - 1]) : '';
                                $star_lable_text = stripslashes_deep($star_lable_text);
                                ?>
										<option value="<?php 
                                echo $star;
                                ?>
" <?php 
                                if ($old_ratings[$rating->id]) {
                                    echo 'selected="selected"';
                                }
                                ?>
  ><?php 
                                echo $star_lable_text;
                                ?>
</option>	
									<?php 
                            }
                            ?>
									</select>
							</div>
						<?php 
                        }
                    }
                    // endif
                }
                ?>
		 
					
									</div>
							 </div> 
								<?php 
            }
            ?>
     
						 </div>	 
				 </div>
				</div>
		</div>
		<?php 
        }
    }
}