blob: fa7d3c3eaae542a24a90fc18fddceeeeeaa3eb41 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2014-2015 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://eclipse.org/legal/epl-v10.html
*
* Edouard Poitras (Eclipse Foundation) - Some modifications
*******************************************************************************/
function sideDonorList($_numrows) {
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/smartconnection.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/friendsContributionsList.class.php");
$friendsContributionsList = new FriendsContributionsList();
$friendsContributionsList->selectFriendsContributionsList(0, $_numrows);
$friend = new Friend();
$contribution = new Contribution();
$fcObject = new FriendsContributions();
$count = $friendsContributionsList->getCount();
for ($i=0; $i < $count; $i++) {
$fcObject = $friendsContributionsList->getItemAt($i);
$friend = $fcObject->getFriendObject();
$contribution = $fcObject->getContributionObject();
$date = $contribution->getDateExpired();
$date = strtotime($date);
$date = strtotime("-1 year", $date);
$now = strtotime("now");
if ($date <= $now) {
$anonymous = $friend->getIsAnonymous();
if ($anonymous != 1) {
$name = $friend->getFirstName() . " " . $friend->getLastName();
$name = htmlentities($name);
}
else
$name = "Anonymous";
$benefit = $friend->getIsBenefit();
$star = '<i class="fa fa-li fa-angle-double-right"></i> ';
if ($benefit) {
$star = '<i class="fa fa-li fa-star"></i> ';
}
$amount = $contribution->getAmount();
echo "<li>" . $star . $name . "-" . "$" . $amount . "</li>";
}
}
echo "<div class=\"more\"><a href=\"donorlist.php\">Donor List</a></div>";
}
function donorListTable($_numrows, $chevron=TRUE, $striped=TRUE) {
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/smartconnection.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/friendsContributionsList.class.php");
$return_html = "";
if ($striped) $return_html .= "<table class='table table-striped'>";
else $return_html .= "<table class='table'>";
$chevron_html = '<i class="fa fa-li fa-chevron-circle-right orange" style="position: relative; left: 0px; width: 0px;"></i> ';
$friendsContributionsList = new FriendsContributionsList();
$friendsContributionsList->selectFriendsContributionsList(0, $_numrows);
$friend = new Friend();
$contribution = new Contribution();
$fcObject = new FriendsContributions();
$count = $friendsContributionsList->getCount();
for ($i=0; $i < $count; $i++) {
$fcObject = $friendsContributionsList->getItemAt($i);
$friend = $fcObject->getFriendObject();
$contribution = $fcObject->getContributionObject();
$anonymous = $friend->getIsAnonymous();
$date = $contribution->getDateExpired();
$date = strtotime($date);
$date = strtotime("-1 year", $date);
$now = strtotime("now");
if ($date <= $now) {
if ($anonymous != 1 && ($friend->getFirstName() != '' || $friend->getLastName() != '')) {
$name = $friend->getFirstName() . " " . $friend->getLastName();
$name = htmlentities($name);
} else {
$name = "Anonymous";
}
$amount = $contribution->getAmount();
if ($chevron) $return_html .= "<tr><td>$chevron_html</td><td>$name-\$$amount</td></tr>";
else $return_html .= "<tr><td>$name-\$$amount</td></tr>";
}
}
$return_html .= "</table>";
return $return_html;
}
function displayPager($_start, $_pageValue, $_pageCount, $_startParam='start', $_anchor='') {
// Build URL
$next = $_SERVER['PHP_SELF'] . '?' . $_startParam . '=' . ($_start + $_pageValue) . '' . $_anchor;
$previous = $_SERVER['PHP_SELF'] . '?' . $_startParam . '=' . ($_start - $_pageValue) . '' . $_anchor;
ob_start();
?>
<table class="pager">
<tr>
<td style="text-align:left">
<?php
if ($_start >= $_pageValue) {
?><a href="<?=$previous;?>"><< Previous Page</a><?php
}
?>&nbsp;</td>
<td style="text-align:right">
<?php
if (($_start + $_pageValue) < $_pageCount) {
?><a href="<?=$next;?>">Next Page >></a><?php
}
?>
</td>
</tr>
</table>
<?php
return ob_get_clean();
}
function displayTable($contributions) {
echo '<table class="table table-hover table-condensed" cellspacing=0>' .
'<tr class="donorHeader">' .
'<td colspan="2" width="60%">Name and Message</td>' .
'<td width="20%">Date</td>' .
'<td width="20%" align="right">Amount</td>' .
'</tr>';
// Get total number of items so we can know whether to page or not.
$friend = new Friend();
$contribution = new Contribution();
$fcObject = new FriendsContributions();
foreach ($contributions as $contribution) {
$contrib = $contribution->getContributionObject();
$friend = $contribution->getFriendObject();
$anonymous = $friend->getIsAnonymous();
if ($anonymous != 1 && ($friend->getFirstName() != '' || $friend->getLastName() != ''))
$name = $friend->getFirstName() . " " . $friend->getLastName();
else $name = "Anonymous";
$benefit = $friend->getIsBenefit();
if ($benefit != 0) $benefit = " <img width='25' src=\"images/stars.png\">";
else $benefit = "";
$amount = $contrib->getAmount();
if (strpos($amount, ".") == 0) {
$amount = $amount . ".00";
}
$comment = stripslashes(strip_tags($contrib->getMessage()));
if (strlen($comment) > 80) {
if (strpos($comment, ' ') == 0) {
$commentArray = str_split($comment, 80);
$comment = 0;
foreach ($commentArray as $value) {
$comment .= $value . " ";
}
}
}
$date = strtotime("-1 year", strtotime($contrib->getDateExpired()));
$now = strtotime("now");
if ($date <= $now) {
$date = date("Y-m-d", $date);
echo '<tr class="donorRecord">' .
'<td width="25">' . $benefit . '</td>' .
'<td width="59%"><b>' . $name . '</b><br/>' . $comment . '</td>' .
'<td>' . $date . '</td>' .
'<td align="right">$' . $amount . ' USD</td>' .
'</tr>';
}
}
echo '</table>';
}
function getGravatarURL($email, $size=80, $default='mm') {
return "https://secure.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?d=" . $default . "&s=" . $size;
}
function displayFriends($friendsContributions) {
require_once("/home/data/httpd/eclipse-php-classes/system/ldapconnection.class.php");
$ldap = new LDAPConnection();
$content = '<div class="row friend-images">';
foreach ($friendsContributions as $contributions) {
$f = $contributions->getFriendObject();
$name = ucfirst(strtolower($f->getFirstName())) . ' ' . ucfirst(strtolower($f->getLastName()));
$uid = $f->getLDAPUID();
if ($uid && $f->getEmail() != "") {
$dn = $ldap->getDNFromUID($uid);
$f->setEmail($ldap->getLDAPAttribute($dn, 'mail'));
}
$content .= '<div class="col-md-6 col-sm-8, col-xs-12">';
$content .= ' <div class="user-picture">';
$content .= ' <img class="col-xm-24" typeof="foaf:Image" src="' . getGravatarURL($f->getEmail()) . '" alt="' . $name . '" title="' . $name . '" />';
$content .= ' <span class="col-xs-24 donor-name">' . $name . '</span>';
$content .= ' </div>';
$content .= '</div>';
}
$content .= '</div>';
return $content;
}
function getFriendsCount($get_anonymous=TRUE, $get_expired=TRUE, $donation_minimum=35) {
$friends = array();
$App = new App();
$sql = "SELECT COUNT(*) FROM friends_contributions as FC
LEFT JOIN friends AS F ON FC.friend_id = F.friend_id WHERE FC.amount >= " . $App->sqlSanitize($donation_minimum);
if (!$get_anonymous) $sql .= " AND F.is_anonymous = 0";
if (!$get_expired) $sql .= " AND FC.date_expired > NOW()";
$result = $App->eclipse_sql($sql);
$row = mysql_fetch_row($result);
return $row[0];
}