function lhg_donation_table_shortcode_singe_language($attr)
{
    global $region;
    global $top_users;
    global $donation;
    global $txt_cp_title;
    global $txt_cp_karma;
    global $txt_cp_points;
    global $txt_cp_donates_to;
    global $txt_cp_longtext;
    global $txt_cp_language;
    # before we create the table we update the data in the transverse DB
    lhg_update_karma_values('quarterly');
    # How many users to show for ongoing quarter
    $max_users_to_show = 10;
    $langurl = lhg_get_lang_url_from_region($region);
    #extract($args, EXTR_SKIP);
    #echo $before_widget;
    //$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
    #$output .='<i class="icon-trophy menucolor"></i>&nbsp;'.$txt_cp_title;
    #if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
    //set default values
    #if($instance['num'] == '' || $instance['num'] == 0) { $instance['num'] = 1; }
    #if($instance['text'] == '') { $instance['text'] = '%user% (%points%)';}
    # Show table of top users of ongoing Quarter
    list($list_uid, $list_points) = cp_getAllQuarterlyPoints();
    #list($list_guid, $list_points_guid) = cp_getAllQuarterlyPoints_transverse();
    #print "<br>Users:";
    #var_dump($list_uid);
    $i = 0;
    if (sizeof($list_uid) > 0) {
        $output .= '<table id="quarterly-points-table">
                <tr id="quarterly-points-header-row">
                  <td class="qrtly-1" id="quarterly-points-1">Quarterly Points</td>
                  <td class="qrtly-2" id="quarterly-points-2"></td>
                  <td class="qrtly-3" id="quarterly-points-3">Username</td>
                  <td class="qrtly-4" id="quarterly-points-3">Details</td>
                  <td class="qrtly-5" id="quarterly-points-3">Total Karma</td>
                </tr>
                ';
    }
    if (sizeof($list_uid) > 0) {
        foreach ($list_uid as $uid) {
            # skip deleted users
            # skip anonymously added posts, i.e. user = user-submitted-posts
            $user = get_userdata($uid);
            if ($user !== false) {
                if ($uid != 12378) {
                    #var_dump($user);
                    #print sizeof($uid)."<p>";
                    $name = $user->first_name . " " . $user->last_name;
                    $points = $list_points[$i];
                    $avatar = get_avatar($uid, 40);
                    $user_language_txt = lhg_get_locale_from_id($uid);
                    $user_language_flag = lhg_show_flag_by_lang($user_language_txt);
                    $total_karma = cp_getPoints($uid);
                    //$num_com * 3 + $num_art * 50;
                    //registration date
                    $regdate = date("d. M Y", strtotime(get_userdata($uid)->user_registered));
                    //donates to
                    $donation_target = get_user_meta($uid, 'user_donation_target', true);
                    if ($donation_target == "") {
                        $donation_target = 1;
                    }
                    //print_r($y);
                    //if ($langurl != "") $langurl = "/".$langurl;
                    #print "Name: ".$user->user_nicename." ($uid) - $points<br>";
                    $output .= '<tr>

<td class="qrtly-1" >
	    <div class="userlist-place-quarter">' . $points . ' ' . $txt_cp_points . '
    	    </div>
</td>


<td class="quartery-points-avatar qrtly-2">
<a href="./hardware-profile/user' . $uid . '" class="recent-comments">
    <div class="userlist-avatar">' . $avatar . '
    </div>
</a>
</td>


<td class="qrtly-3">
          <div class="userlist-displayname">
		<a href="./hardware-profile/user' . $uid . '" class="recent-comments">
	            	' . $user->nickname . '
                </a>

          </div>
</td>


<td class="qrtly-4">
    <div class="quarterly-points-userlist-details">
      ' . $txt_cp_donates_to . ': ' . $donation[$donation_target]["Name"] . '<br>
      ' . $txt_cp_language . ': ' . $user_language_flag . '
    </div>
</td>

<td class="qrtly-5">
          <div class="quartly-points-totalpoints">
	     ' . $total_karma . ' ' . $txt_cp_points . '<br>
          </div>
</td>


</tr>';
                }
            }
            $i++;
            if ($i > $max_users_to_show) {
                break;
            }
        }
    }
    if (sizeof($list_uid) > 0) {
        $output .= "</table>";
    }
    return $output;
}
function lhg_update_karma_values($type)
{
    global $lang;
    global $lhg_price_db;
    list($list_uid, $list_points) = cp_getAllQuarterlyPoints();
    $i = 0;
    if (sizeof($list_uid) > 0) {
        foreach ($list_uid as $uid) {
            #error_log("CP UID return: $uid");
            $user = get_userdata($uid);
            if ($user !== false) {
                if ($uid != 12378) {
                    $name = $user->nickname;
                    #$user->first_name." ".$user->last_name;
                    $username = $user->user_login;
                    $points = $list_points[$i];
                    $avatar = get_avatar($uid, 40);
                    $user_language_txt = lhg_get_locale_from_id($uid);
                    $user_language_flag = lhg_show_flag_by_lang($user_language_txt);
                    $total_karma = cp_getPoints($uid);
                    //$num_com * 3 + $num_art * 50;
                    $donation_target = get_user_meta($uid, 'user_donation_target', true);
                    if ($lang != "de") {
                        $user_language = get_user_meta($uid, 'user_language', true);
                    }
                    error_log("User {$username} -> quarterly_karma: {$points}");
                    # check if user exists
                    if ($lang != "de") {
                        $sql = "SELECT id, karma_com, karma_quarterly_com, donation_target_com, user_nicename, language, username_com, emails FROM `lhgtransverse_users` WHERE emails = \"" . $user->user_email . "\" ";
                    } else {
                        $sql = "SELECT id, karma_de, karma_quarterly_de, donation_target_de, user_nicename, username_de, emails  FROM `lhgtransverse_users` WHERE emails = \"" . $user->user_email . "\" ";
                    }
                    $result = $lhg_price_db->get_results($sql);
                    #error_log( "UID: $uid");
                    #error_log("GUID: ".$result[0] ->id);
                    #var_dump($result);
                    #print "<br>";
                    if ($result[0]->id == "") {
                        # user not yet in priceDB, add
                        $guid = lhg_add_user_to_pricedb($uid);
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("karma_com", $guid, $total_karma);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("karma_quarterly_com", $guid, $points);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("donation_target_com", $guid, $donation_target);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("language", $guid, $user_language);
                        }
                        if ($lang != "de") {
                            lhg_update_userdb_by_guid("username_com", $guid, $username);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("karma_de", $guid, $total_karma);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("karma_quarterly_de", $guid, $points);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("donation_target_de", $guid, $donation_target);
                        }
                        if ($lang == "de") {
                            lhg_update_userdb_by_guid("username_de", $guid, $username);
                        }
                        #error_log("A: $uid - $guid - ".$result->id);
                        lhg_update_userdb_by_guid("user_nicename", $guid, $name);
                        lhg_update_userdb_by_guid("avatar", $guid, $avatar);
                    } else {
                        # user in priceDB, check if update necessary
                        if ($lang != "de" && $total_karma != $result[0]->karma_com) {
                            lhg_update_userdb_by_guid("karma_com", $result[0]->id, $total_karma);
                        }
                        if ($lang != "de" && $points != $result[0]->karma_quarterly_com) {
                            lhg_update_userdb_by_guid("karma_quarterly_com", $result[0]->id, $points);
                        }
                        if ($lang != "de" && $donation_target != $result[0]->donation_target_com) {
                            lhg_update_userdb_by_guid("donation_target_com", $result[0]->id, $donation_target);
                        }
                        if ($lang != "de" && $user_language != $result[0]->language) {
                            lhg_update_userdb_by_guid("language", $result[0]->id, $user_language);
                        }
                        if ($lang != "de" && $username != $result[0]->username_com) {
                            lhg_update_userdb_by_guid("username_com", $result[0]->id, $username);
                        }
                        if ($lang == "de" && $total_karma != $result[0]->karma_de) {
                            lhg_update_userdb_by_guid("karma_de", $result[0]->id, $total_karma);
                        }
                        if ($lang == "de" && $points != $result[0]->karma_quarterly_de) {
                            lhg_update_userdb_by_guid("karma_quarterly_de", $result[0]->id, $points);
                        }
                        if ($lang == "de" && $donation_target != $result[0]->donation_target_de) {
                            lhg_update_userdb_by_guid("donation_target_de", $result[0]->id, $donation_target);
                        }
                        if ($lang == "de" && $username != $result[0]->username_com) {
                            lhg_update_userdb_by_guid("username_de", $result[0]->id, $username);
                        }
                        if ($name != $result[0]->user_nicename) {
                            lhg_update_userdb_by_guid("user_nicename", $result[0]->id, $name);
                        }
                        if ($avatar != $result[0]->avatar) {
                            lhg_update_userdb_by_guid("avatar", $result[0]->id, $avatar);
                        }
                        if ($user->user_email != $result[0]->emails) {
                            lhg_update_userdb_by_guid("emails", $result[0]->id, $user->user_email);
                        }
                        # check if user was already set for other language
                        if ($lang == "de" && $uid != $result[0]->wpuid_de) {
                            lhg_update_userdb_by_guid("wpuid_de", $result[0]->id, $uid);
                        }
                        if ($lang != "de" && $uid != $result[0]->wpuid) {
                            lhg_update_userdb_by_guid("wpuid", $result[0]->id, $uid);
                        }
                        #error_log("NAME: $name");
                        #error_log("B Points: $points vs. ".$result[0]->karma_quarterly_com);
                    }
                }
            }
            $i++;
            // points array counter
        }
    }
}
    function widget($args, $instance)
    {
        global $region;
        global $top_users;
        global $donation;
        global $txt_cp_title;
        global $txt_cp_karma;
        global $txt_cp_points;
        global $txt_cp_donates_to;
        global $txt_cp_longtext;
        global $txt_cp_language;
        # How many users to show for ongoing quarter
        $max_users_to_show = 5;
        $langurl = lhg_get_lang_url_from_region($region);
        extract($args, EXTR_SKIP);
        echo $before_widget;
        //$title = empty($instance['title']) ? '&nbsp;' : apply_filters('widget_title', $instance['title']);
        $title = '<i class="icon-trophy menucolor"></i>&nbsp;' . $txt_cp_title;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        //set default values
        if ($instance['num'] == '' || $instance['num'] == 0) {
            $instance['num'] = 1;
        }
        if ($instance['text'] == '') {
            $instance['text'] = '%user% (%points%)';
        }
        # Show table of top users of ongoing Quarter
        list($list_uid, $list_points) = cp_getAllQuarterlyPoints();
        #print "<br>Users:";
        #var_dump($list_uid);
        $i = 0;
        if (sizeof($list_uid) > 0) {
            print '<table id="quarterly-points-table">
                <tr id="quarterly-points-header-row">
                  <td class="qrtly-1" id="quarterly-points-1">Quarterly Points</td>
                  <td class="qrtly-2" id="quarterly-points-2"></td>
                  <td class="qrtly-3" id="quarterly-points-3">Username</td>
                  <td class="qrtly-4" id="quarterly-points-3">Details</td>
                  <td class="qrtly-5" id="quarterly-points-3">Total Points</td>
                </tr>
                ';
        }
        if (sizeof($list_uid) > 0) {
            foreach ($list_uid as $uid) {
                $user = get_userdata($uid);
                $name = $user->first_name . " " . $user->last_name;
                $points = $list_points[$i];
                $avatar = get_avatar($uid, 40);
                $user_language_txt = lhg_get_locale_from_id($uid);
                $user_language_flag = lhg_show_flag_by_lang($user_language_txt);
                $total_karma = cp_getPoints($uid);
                //$num_com * 3 + $num_art * 50;
                //registration date
                $regdate = date("d. M Y", strtotime(get_userdata($uid)->user_registered));
                //donates to
                $donation_target = get_user_meta($uid, 'user_donation_target', true);
                if ($donation_target == "") {
                    $donation_target = 1;
                }
                //print_r($y);
                //if ($langurl != "") $langurl = "/".$langurl;
                #print "Name: ".$user->user_nicename." ($uid) - $points<br>";
                echo '<tr>

<td class="qrtly-1" >
	    <div class="userlist-place-quarter">' . $points . ' ' . $txt_cp_points . '
    	    </div>
</td>


<td class="quartery-points-avatar qrtly-2">
<a href="./hardware-profile/user' . $uid . '" class="recent-comments">
    <div class="userlist-avatar">' . $avatar . '
    </div>
</a>
</td>


<td class="qrtly-3">
          <div class="userlist-displayname">
		<a href="./hardware-profile/user' . $uid . '" class="recent-comments">';
                echo $user->user_nicename . '
                </a>

          </div>
</td>


<td class="qrtly-4">
    <div class="quarterly-points-userlist-details">
      ' . $txt_cp_donates_to . ': ' . $donation[$donation_target]["Name"] . '<br>
      ' . $txt_cp_language . ': ' . $user_language_flag . '
    </div>
</td>

<td class="qrtly-5">
          <div class="quartly-points-totalpoints">
	      ' . $txt_cp_karma . ': ' . $total_karma . ' ' . $txt_cp_points . '<br>
          </div>
</td>

';
                print "</tr>";
                $i++;
                if ($i > $max_users_to_show - 1) {
                    break;
                }
            }
        }
        if (sizeof($list_uid) > 0) {
            print "</table>";
        }
        /*
        
        		$top = cp_getAllPoints($instance['num'],get_option('cp_topfilter'));
        		do_action('cp_topUsersWidget_before');
        		echo apply_filters('cp_topUsersWidget_before','<div class="userlist-all"><ul class="bwp-rc-ulist">');
        		$line = str_replace('%style%', $instance['style'], $line);
        		foreach($top as $x=>$y){
                                $i++;
                                $uid = $y['id'];
        			$user = get_userdata($y['id']);
                                $name = $user->first_name." ".$user->last_name;
        			$string = str_replace('%string%', '', $instance['text']);
        			$string = str_replace('%string%',$string,$line);
        			$string = apply_filters('cp_displayUserInfo',$string,$y,$x+1);
        
                                //Flag
        		        $user_language_txt = lhg_get_locale_from_id ( $uid );
                		$user_language_flag= lhg_show_flag_by_lang ( $user_language_txt );
        
                                //registration date
                                $regdate = date("d. M Y", strtotime(get_userdata( $uid ) -> user_registered ) );
        
                                //donates to
        			$donation_target = get_user_meta($uid,'user_donation_target',true);
                                if ($donation_target == "") $donation_target = 1;
        
                                $avatar = get_avatar($uid, 40);
                                //print_r($y);
                                //if ($langurl != "") $langurl = "/".$langurl;
        
        global $txt_cp_karma;
        global $txt_cp_points;
        global $txt_cp_donates_to;
        global $txt_cp_longtext;
        global $txt_cp_language;
        
                                echo '
        <a href="./hardware-profile/user'.$uid.'" class="recent-comments">
          <div class="comment-box">
        
            <div class="userlist-avatar">'.
              $avatar.'
            </div>
        
            <div class="userlist-name">
                  <div class="userlist-place">'.
                    $i.'.
                  </div>
                  <div class="userlist-displayname">';
                    //if ($name == " ") {
                    	echo $y['display_name'];
                    //}else{
                    //    echo $name;
                    //};
                    echo '
                  </div>
        
                <!-- div class="userlist-flag">'.
                  $user_language_flag.'
                </div -->
        
            </div>
        
        
            <div class="userlist-details">
              '.$txt_cp_karma.': '.$y['points'].' '.$txt_cp_points.'<br>
              '.$txt_cp_donates_to.': '.$donation[$donation_target]["Name"].'<br>
              '.$txt_cp_language.': '.$user_language_flag.'
            </div>
        
          </div>
        </a>';
        //      Registered since: '.$regdate.'<br>
        
        
        
        
                        $top_users[$i]["ID"]=$uid;
                        $top_users[$i]["Karma"]=$y['points'];
        	        $top_users[$i]["DisplayName"]=$y['display_name'];
        
                                // echo $string;
        		}
        		echo apply_filters('cp_topUsersWidget_after','</ul></div>');
        
        $topvotes = lhg_voted_donation();
        $most_voted = lhg_most_voted ($topvotes);
        $most_voted_percent = lhg_most_voted_percent ($topvotes);
        
        //$most_voted = 2;
        
                // echo "TV: $topvotes";
        */
        global $donation_total;
        /*
        Former donation code
        echo '
        
        <div class="userlist-chart">'.$txt_cp_longtext.': <b>'. $donation_total.' &euro;</b>
          '.do_shortcode('[highchart-quarterly]
        ');
        */
        echo 'Donations:<br>' . do_shortcode('[highchart_quarterly]');
        $startQrt = cp_StartOfQuarter();
        $endQrt = cp_EndOfQuarter();
        #print "Range: ".date('jS \of F Y h:i:s A',$startQrt)." to ".date('jS \of F Y h:i:s A',$endQrt);
        //   Currently, '.$most_voted_percent.'% of all users vote for "'.$donation[$most_voted]["Name"].'".
        //$topvo
        // echo '</div>';
        //end of userlist all
        do_action('cp_topUsersWidget_after');
        echo $after_widget;
    }