function lhg_return_donation_results($startdate, $enddate) { # ToDo: Currently, provided time frame is ignored # ongoing quarter is always used list($list_guid, $list_points) = cp_getAllQuarterlyPoints_transverse($startdate, $enddate); #error_log("Start: $startdate End: $enddate"); #print "Userpoints: "; #var_dump($list_points); #print "<br>"; $i = 0; foreach ($list_guid as $guid) { # Skip anonymously submitted posts if ($uid != 12378) { //$user = get_userdata($uid); //$name = $user->first_name." ".$user->last_name; $points = $list_points[$i]; //donates to # target has to be extracted from transverse database! #$donation_target = get_user_meta($uid,'user_donation_target',true); # checking for latest change global $lhg_price_db; $sql = "SELECT * FROM `lhgtransverse_users` WHERE id = \"" . $guid . "\" "; $results = $lhg_price_db->get_results($sql); $timestamp_de = $results[0]->donation_target_date_de; $timestamp_com = $results[0]->donation_target_date_com; if ($timestamp_de > $timestamp_com) { $donation_target = $results[0]->donation_target_de; } else { $donation_target = $results[0]->donation_target_com; } #error_log("TSde/com: $timestamp_de/$timestamp_com -> Target: $donation_target"); # sum up points, default = LHG: if ($donation_target == "") { $donation_target = 1; } if ($donation_target == 0) { $donation_target = 1; } $donation_target_sum[$donation_target] += $points; $donation_target_users[$donation_target] += 1; } $i++; } return array($donation_target_sum, $donation_target_users); #return array($donation_target_sum, $dnoation_targets); }
function lhg_donation_history($attr) { global $lang; global $donation; $start = $attr['start']; $end = $attr['end']; list($endyear, $endmonth) = explode("-", $end); $enddate = "1-" . (intval($endmonth) + 1) . "-" . $endyear; $start_timestamp = strtotime($start); $end_timestamp = strtotime($enddate); # $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 # # donations to distribution was introduced after 09-2016 # skip output otherwise if ($end_timestamp > strtotime("1-10-2016")) { $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"]; $scan_output .= '<div class="donations-short-user-list"> <div class="donations-short-user-list-avatar">' . "<img src=\"" . $logo . "\" width=45px>\n </div>\n\n " . '<div class="donations-short-user-list-text"> <center>' . $donation[$key]["Name"] . "<br><b>" . round($points / $total_points * 100) . "%</b> ({$points} points)\n \t</center>\n </div>\n\n </div>"; } # # donation points collected by users list($list_guid, $list_points_guid) = cp_getAllQuarterlyPoints_transverse($start_timestamp, $end_timestamp); #print_r("LGUID: $list_guid"); $i = 0; if (sizeof($list_guid) > 0) { foreach ($list_guid as $guid) { $user_tmp = lhg_get_userdata_guid($guid); $user = $user_tmp[0]; if ($user !== false) { #var_dump($user); #print sizeof($uid)."<p>"; $user_nicename = $user->user_nicename; $points = $list_points_guid[$i]; # get user's avatar $avatar = $user->avatar; # repair URL if linking to .de avatar on .com server if (strpos($avatar, "src='/avatars/") > 0) { $avatar = str_replace("src='/avatars/", "src='http://www.linux-hardware-guide.de/avatars/", $avatar); } $wpuid_de = $user->wpuid_de; $wpuid_com = $user->wpuid; $user_language_txt = $user->language; $user_language_flag = lhg_show_flag_by_lang($user_language_txt); $total_karma = $user->karma_com + $user->karma_de; //$num_com * 3 + $num_art * 50; if ($lang == "de") { $uid = $user->wpuid_de; } if ($lang == "com") { $uid = $user->wpuid; } //registration date #$regdate = date("d. M Y", strtotime(get_userdata( $uid ) -> user_registered ) ); //donates to # TODO: # to be updated, because we need the donation target at the end of the given time frame $donation_target = lhg_get_donation_target_by_date($guid, $end_timestamp); $total_points += $points; $donation_points[$donation_target] += $points; #$output .="User: $user_nicename -> Points: $points -> $donation_target <br>"; ## show user info ## $user_list .= '<div class="donations-short-user-list"> <div class="donations-short-user-list-avatar">'; # TODO: localized hardware profile should be linked. Not US version # linked avatar to user page if on local server # link avatar to guser page, if user present on other servers if ($lang == "de") { if ($user->wpuid_de != 0) { $user_list .= '<a href="/hardware-profile/user' . $user->wpuid_de . '" class="recent-comments">'; $close0 = 1; # remember that link has to be closed } else { $user_list .= '<a href="/hardware-profile/guser' . $guid . '" class="recent-comments">'; $close0 = 1; } } if ($lang != "de") { if ($user->wpuid != 0) { $user_list .= '<a href="/hardware-profile/user' . $user->wpuid . '" class="recent-comments">'; $close0 = 1; # remember that link has to be closed } else { $user_list .= '<a href="/hardware-profile/guser' . $guid . '" class="recent-comments">'; $close0 = 1; # remember that link has to be closed } } $user_list .= ' <div class="userlist-avatar">' . $avatar . ' </div> '; if ($close0 == 1) { $user_list .= '</a></div>'; } $user_list .= '<div class="donations-short-user-list-text"><center>'; # show link to user page if on local server # link to guser page, if user present on other servers if ($lang == "de") { if ($user->wpuid_de != 0) { $user_list .= ' <a href="/hardware-profile/user' . $user->wpuid_de . '" class="recent-comments">'; $close1 = 1; # remember that link has to be closed } else { $user_list .= ' <a href="/hardware-profile/guser' . $guid . '" class="recent-comments">'; $close1 = 1; } } if ($lang != "de") { if ($user->wpuid != 0) { $user_list .= ' <a href="/hardware-profile/user' . $user->wpuid . '" class="recent-comments">'; $close1 = 1; } else { $user_list .= ' <a href="/hardware-profile/guser' . $guid . '" class="recent-comments">'; $close1 = 1; } } $user_list .= "" . $user_nicename . ""; if ($close1 == 1) { $user_list .= '</a>'; } $user_list .= "<br>{$points} Points\n to<br>" . $donation[$donation_target]["Name"] . "\n\n </center> </div>"; $user_list .= "</div>"; } $i++; } } #print "Scan results:"; #var_dump($scans_donation_target); #$iendmonth= (int)$endmonth; $output .= "<h2>Donations from " . date("d M Y", $start_timestamp) . " to " . date("d M Y", $end_timestamp) . ":</h2>\n Collected Points: <b>{$total_points}</b><br>\n "; foreach ($donation_points as $key => $donation_point) { if ($donation_point > 0) { $output .= "Donations to " . $donation[$key]["Name"] . ": <b>" . round($donation_point / $total_points * 100) . "%</b> ({$donation_point} points)<br>"; } } $output .= "<br>Users that collected and donated points:<br>\n " . $user_list . ""; # donations to distribution was introduced after 09-2016 # skip output otherwise if ($end_timestamp > strtotime("1-10-2016")) { $output .= '<br clear=all>Hardware scan results:<br>' . $scan_output . "<br clear=all>"; } return $output; }