function get_distri_logo($distribution)
{
    $distri = lhg_get_distribution_array();
    $distri_name = lhg_get_distri_name($distribution);
    $logo = $distri[$distri_name]["logo"];
    #fallback:
    if ($logo == "") {
        $logo = "/wp-content/plugins/lhg-hardware-profile-manager/images/unknown-logo.png";
    }
    #print "D: $distribution, LOGO: $logo <br>";
    return $logo;
}
function lhg_points_from_hwscans($start_timestamp, $end_timestamp)
{
    global $lhg_price_db;
    # 1 look if donation target is set in history DB
    $sql = "SELECT distribution FROM `lhgscansessions` WHERE scandate >= \"" . $start_timestamp . "\" AND scandate < \"" . $end_timestamp . "\" ";
    $results = $lhg_price_db->get_results($sql);
    $distri_array = lhg_get_distribution_array();
    $donation_targets = array();
    $points = array();
    foreach ($results as $result) {
        # get distribution id string
        $distri = lhg_get_distri_name($result->distribution);
        #error_log("SCans: $distri -> $donation_target");
        # to whom to contribute the donation points for this distribution?
        $donation_target = $distri_array[$distri]["donation_target"];
        if ($donation_target > 0) {
            # donate some karma points for each scan
            $points[$donation_target] += 20;
        }
    }
    return $points;
    #return array($donation_targets, $points);
}
function lhg_hardware_scans_points_shortcode($attr)
{
    global $lang;
    global $donation;
    $start = $attr['start'];
    $end = $attr['end'];
    $start_timestamp = strtotime($start);
    $end_timestamp = strtotime($enddate);
    if ($start == "") {
        $start_timestamp = cp_StartOfQuarter();
    }
    if ($end == "") {
        $end_timestamp = time();
    }
    #
    $total_points = 0;
    # collects all points collected in this time frame
    $donation_points = array();
    # collects all points per donation target in this time frame
    #
    # donation points by hardware scans
    #
    $points_scan = lhg_points_from_hwscans($start_timestamp, $end_timestamp);
    foreach ($points_scan as $key => $points) {
        #error_log("Pts: $points -> $key");
        $total_points += $points;
        $donation_points[$key] += $points;
    }
    # sort by points
    arsort($points_scan);
    $distri = lhg_get_distribution_array();
    $logo = $distri[$distri_name]["logo"];
    foreach ($points_scan as $key => $points) {
        $distri_name = lhg_get_distri_name($donation[$key]["Name"]);
        $logo = $distri[$distri_name]["logo"];
        $url = $distri[$distri_name]["url"];
        $scan_output .= '<div class="donations-short-user-list">
                        		<div class="donations-short-user-list-avatar">' . '<a href="' . $url . '">' . "<img src=\"" . $logo . "\" width=45px></a>\n                                        </div>\n\n                                        " . '<div class="donations-short-user-list-text">
                                        	<center> <a href="' . $url . '">' . $donation[$key]["Name"] . "</a><br><b>{$points} points</b>\n                                        \t</center>\n                                        </div>\n\n                                </div>";
    }
    return $scan_output;
}