/**
  * Top Rated Profiles block (Leaders)
  */
 function getBlockCode_Leaders()
 {
     global $site;
     global $max_voting_mark;
     global $index_progressbar_w;
     global $getBlockCode_TopRated_db_num;
     global $max_thumb_height;
     global $max_thumb_width;
     global $oTemplConfig;
     // most rated profiles
     // $rate_max = get_max_votes_profile();
     $oVoting = new BxTemplVotingView('profile', 0, 0);
     $iIdMonth = $oVoting->getTopVotedItem(30, '`Profiles`', '`ID`', "AND `Profiles`.`Status` = 'Active'");
     $iIdWeek = $oVoting->getTopVotedItem(7, '`Profiles`', '`ID`', "AND `Profiles`.`Status` = 'Active' AND `ID`<>{$iIdMonth}");
     $iIdDay = $oVoting->getTopVotedItem(1, '`Profiles`', '`ID`', "AND `Profiles`.`Status` = 'Active' AND `ID`<>{$iIdMonth} AND `ID`<>{$iIdWeek}");
     $oVotingMonth = new BxTemplVotingView('profile', $iIdMonth);
     $oVotingWeek = new BxTemplVotingView('profile', $iIdWeek);
     $oVotingDay = new BxTemplVotingView('profile', $iIdDay);
     $rate_memb_month = getProfileInfo($iIdMonth);
     //db_arr( "SELECT Headline, NickName, ID, Pic_0_addon FROM Profiles WHERE `ID` = '$iIdMonth' LIMIT 1" );
     $rate_memb_week = getProfileInfo($iIdWeek);
     //db_arr( "SELECT Headline, NickName, ID, Pic_0_addon FROM Profiles WHERE `ID` = '$iIdWeek' LIMIT 1" );
     $rate_memb_day = getProfileInfo($iIdDay);
     //db_arr( "SELECT Headline, NickName, ID, Pic_0_addon FROM Profiles WHERE `ID` = '$iIdDay' LIMIT 1" );
     //$rate_memb_month  = db_arr( "SELECT Headline, NickName, Member, COUNT(*) AS `count`, SUM(Mark)/COUNT(*) AS mark, ID, Pic_0_addon  FROM `Votes` INNER JOIN Profiles ON (ID = Member) WHERE Status = 'Active' AND TO_DAYS(NOW()) - TO_DAYS(`Date`) <= 30 GROUP BY Member ORDER BY Mark DESC,`count` DESC LIMIT 1" );
     //$rate_memb_week   = db_arr( "SELECT Headline, NickName, Member, COUNT(*) AS `count`, SUM(Mark)/COUNT(*) AS mark, ID, Pic_0_addon  FROM `Votes` INNER JOIN Profiles ON (ID = Member) WHERE Status = 'Active' AND TO_DAYS(NOW()) - TO_DAYS(`Date`) <= 7 GROUP BY Member ORDER BY Mark DESC,`count` DESC LIMIT 1" );
     $ret = '';
     //#####################################################################
     $ret .= '<div class="clear_both"></div>';
     $ret .= '<div id="prof_of_month">';
     $ret .= '<div class="top_rated_head">';
     $ret .= _t("_Month");
     $ret .= '</div>';
     if (0 < $rate_memb_month['ID']) {
         $ret .= get_member_thumbnail($rate_memb_month['ID'], 'none');
         $ret .= '<div class="rate_block_position">';
         $ret .= $oVotingMonth->getSmallVoting(0);
         $ret .= '</div>';
     } else {
         $ret .= '<div class="top_prof_not_avail">';
         $ret .= '<div class="no_result">';
         $ret .= '<div>';
         $ret .= _t("_no_top_month");
         $ret .= '</div>';
         $ret .= '</div>';
         $ret .= '</div>';
     }
     $ret .= '<div class="clear_both"></div></div>';
     //#####################################################################
     $ret .= '<div id="prof_of_week">';
     $ret .= '<div class="top_rated_head">';
     $ret .= _t("_Week");
     $ret .= '</div>';
     if (0 < $rate_memb_week['ID']) {
         $ret .= get_member_thumbnail($rate_memb_week['ID'], 'none');
         $ret .= '<div class="rate_block_position">';
         $ret .= $oVotingWeek->getSmallVoting(0);
         $ret .= '</div>';
     } else {
         $ret .= '<div class="top_prof_not_avail">';
         $ret .= '<div class="no_result">';
         $ret .= '<div>';
         $ret .= _t("_no_top_week");
         $ret .= '</div>';
         $ret .= '</div>';
         $ret .= '</div>';
     }
     $ret .= '<div class="clear_both"></div></div>';
     //#####################################################################
     $ret .= '<div id="prof_of_day">';
     $ret .= '<div class="top_rated_head">';
     $ret .= _t("_Day");
     $ret .= '</div>';
     if (0 < $rate_memb_day['ID']) {
         $ret .= get_member_thumbnail($rate_memb_day['ID'], 'none');
         $ret .= '<div class="rate_block_position">';
         $ret .= $oVotingDay->getSmallVoting(0);
         $ret .= '</div>';
     } else {
         $ret .= '<div class="top_prof_not_avail">';
         $ret .= '<div class="no_result">';
         $ret .= '<div>';
         $ret .= _t("_no_top_day");
         $ret .= '</div>';
         $ret .= '</div>';
         $ret .= '</div>';
     }
     $ret .= '<div class="clear_both"></div></div>';
     $ret .= '<div class="clear_both"></div>';
     return $ret;
 }
    /**
     * Top Rated Profiles block (Leaders)
     */
    function getBlockCode_Leaders()
    {
        $sLeaders = $sLeaderValues = '';
        $aPreferSex = array();
        $sPeriodTypesMale = getParam('leaders_male_types');
        $sPeriodTypesFemale = getParam('leaders_female_types');
        if ($sPeriodTypesMale == '' || $sPeriodTypesFemale == '') {
            return;
        }
        $sCurrentMode = !empty($_GET['leaders_mode']) && ($_GET['leaders_mode'] == 'all' || $_GET['leaders_mode'] == 'male' || $_GET['leaders_mode'] == 'female') ? $_GET['leaders_mode'] : 'all';
        $aDBTopMenu = array();
        foreach (array('all', 'male', 'female') as $sEachMode) {
            switch ($sEachMode) {
                case 'all':
                    if ($sCurrentMode == $sEachMode) {
                        $aPreferSex[] = 'male';
                        $aPreferSex[] = 'female';
                    }
                    $sModeTitle = _t('_All');
                    break;
                case 'male':
                    if ($sCurrentMode == $sEachMode) {
                        $aPreferSex[] = 'male';
                    }
                    $sModeTitle = _t('_By Male');
                    break;
                case 'female':
                    if ($sCurrentMode == $sEachMode) {
                        $aPreferSex[] = 'female';
                    }
                    $sModeTitle = _t('_By Female');
                    break;
            }
            $aDBTopMenu[$sModeTitle] = array('href' => BX_DOL_URL_ROOT . "index.php?leaders_mode={$sEachMode}", 'dynamic' => true, 'active' => $sEachMode == $sCurrentMode);
        }
        $aPeriodTypesMale = explode(',', $sPeriodTypesMale);
        $aPeriodTypesFemale = explode(',', $sPeriodTypesFemale);
        $oVoting = new BxTemplVotingView('profile', 0, 0);
        $aLeadersList = array();
        $aPeriodTypes = array();
        $iIDYear = $iIDMonth = $iIDWeek = $iIDDay = 0;
        foreach ($aPreferSex as $sSex) {
            $aPeriodTypes[$sSex] = $sSex == 'male' ? $aPeriodTypesMale : $aPeriodTypesFemale;
            foreach ($aPeriodTypes[$sSex] as $sPeriodType) {
                switch ($sPeriodType) {
                    case 'year':
                        $iIDYear = $oVoting->getTopVotedItem(365, '`Profiles`', '`ID`', "AND `Profiles`.`Status` = 'Active' AND `Profiles`.`Sex` = '{$sSex}'");
                        $aLeadersList[$sSex]['year'] = $iIDYear;
                        break;
                    case 'month':
                        $sYearAddon = $iIDYear ? "AND `ID`<>'{$iIDYear}'" : '';
                        $iIDMonth = $oVoting->getTopVotedItem(30, '`Profiles`', '`ID`', "AND `Profiles`.`Status` = 'Active' {$sYearAddon} AND `Profiles`.`Sex` = '{$sSex}'");
                        $aLeadersList[$sSex]['month'] = $iIDMonth;
                        break;
                    case 'week':
                        $sYearAddon = $iIDYear ? "AND `ID`<>'{$iIDYear}'" : '';
                        $sMonthAddon = $iIDMonth ? "AND `ID`<>'{$iIDMonth}'" : '';
                        $iIDWeek = $oVoting->getTopVotedItem(7, '`Profiles`', '`ID`', "AND `Profiles`.`Status` = 'Active' {$sYearAddon} {$sMonthAddon} AND `Profiles`.`Sex` = '{$sSex}'");
                        $aLeadersList[$sSex]['week'] = $iIDWeek;
                        break;
                    case 'day':
                        $sYearAddon = $iIDYear ? "AND `ID`<>'{$iIDYear}'" : '';
                        $sMonthAddon = $iIDMonth ? "AND `ID`<>'{$iIDMonth}'" : '';
                        $sWeekAddon = $iIDWeek ? "AND `ID`<>'{$iIDWeek}'" : '';
                        $iIDDay = $oVoting->getTopVotedItem(1, '`Profiles`', '`ID`', "AND `Profiles`.`Status` = 'Active' {$sYearAddon} {$sMonthAddon} {$sWeekAddon} AND `Profiles`.`Sex` = '{$sSex}'");
                        $aLeadersList[$sSex]['day'] = $iIDDay;
                        break;
                }
            }
            $sLeaderValues .= $this->genLeaderPack($aLeadersList[$sSex], $sSex);
        }
        $sLeaders = <<<EOF
<div class="clear_both"></div>
\t{$sLeaderValues}
<div class="clear_both"></div>
EOF;
        $sLeaderMembers = $GLOBALS['oFunctions']->centerContent($sLeaders, '.featured_block_1');
        return array($sLeaderMembers, $aDBTopMenu);
    }