[insert_php]
define(‘DONOTCACHEPAGE’, true);
function get_the_user_ip() {
if ( ! empty( $_SERVER[‘HTTP_CLIENT_IP’] ) ) {
//check ip from share internet
$ip = $_SERVER[‘HTTP_CLIENT_IP’];
} elseif ( ! empty( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
} else {
$ip = $_SERVER[‘REMOTE_ADDR’];
}
return $ip;
}
$current_user = wp_get_current_user();
// Create connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
$i = 0;
$approvedids = array();
if(isset($_POST[‘approve’])) {
if (!empty($_POST[‘checklist’]) && is_array($_POST[‘checklist’])) {
foreach($_POST[‘checklist’] as $approvedid) {
//echo “id ” . $approvedid . “
“;
$sql = “UPDATE aylus_VolunteerHours SET approved=1” .
“, approvalip = ‘” . get_the_user_ip() .
“‘, approvaluserid = ‘” . $current_user->ID .
“‘, approvalusername = ‘” . $current_user->user_login .
“‘, approvaluseremail = ‘” . $current_user->user_email .
“‘ WHERE approved is null and id=” . $approvedid;
//echo $sql . “
“;
$conn->query($sql);
$approvedids[$i++] = $approvedid;
}
}
}
echo ‘
Pending Requests
‘;
$sql = “SELECT id, name, eventdate, branch, requestemail, hours, description FROM aylus_VolunteerHours where approved is null order by id”;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo ‘
‘;
} else {
echo “
No request pending approval.
“;
}
$start_year = date(‘Y’);
$stop_year = 2015;
while ($start_year >= $stop_year)
{
echo ‘
‘;
echo ‘
Approved Hours between May 1st, ‘ . $start_year . ‘ and Apr 30th, ‘ . ($start_year + 1) . ‘
‘;
$sql = “SELECT id, subid, name, eventdate, branch, requestemail, hours, category, shortdescription, description, submitterip, userid, username, useremail, approved, approvalnotes, approvalip, approvaluserid, approvalusername, approvaluseremail FROM aylus_VolunteerHours where approved = 1 and hours > 0 and eventdate >= ‘” . $start_year . “-05-01 00:00:00’ and eventdate < '" . ($start_year + 1) . "-05-01 00:00:00' order by LOWER(name), eventdate";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo ‘
echo ‘
Name | Hours | Event Date | Branch | Submitter Email | Approved by | Description |
---|---|---|---|---|---|---|
‘ . $name . ‘ | ‘ . ‘Total: ‘ . $total_hours. ‘ | |||||
‘ . $name . ‘ | ‘ . ‘Total: ‘ . $total_hours. ‘ | |||||
‘ . $row_name . ‘ | ‘ . $row[“hours”] . ‘ | ‘ . date(“m/d/Y”, strtotime($row[“eventdate”])) . ‘ | ‘ . $row[“branch”] . ‘ | ‘ . $row[“requestemail”] . ‘ | ‘ . $row[“approvalusername”] . ‘ | ‘ . $row[“description”] . ‘ |
‘ . $row_name . ‘ | ‘ . $row[“hours”] . ‘ | ‘ . date(“m/d/Y”, strtotime($row[“eventdate”])) . ‘ | ‘ . $row[“branch”] . ‘ | ‘ . $row[“requestemail”] . ‘ | ‘ . $row[“approvalusername”] . ‘ | ‘ . $row[“description”] . ‘ |
‘ . $name . ‘ | ‘ . ‘Total: ‘ . $total_hours. ‘ | |||||
‘ . $name . ‘ | ‘ . ‘Total: ‘ . $total_hours. ‘ |
‘;
echo ‘
‘;
} else {
echo “
No request approved.
“;
}
$start_year–;
}
$conn->close();
[/insert_php]