[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);
}
$hasError = false;
$i = 0;
$approvedids = array();
if(isset($_POST[‘approve’])) {
if (!empty($_POST[‘checklist’]) && is_array($_POST[‘checklist’])) {
foreach($_POST[‘checklist’] as $approvedid) {
$shortdescriptionarray = $_POST[‘shortdescription’];
if (isset($shortdescriptionarray[$approvedid])) {
$shortdescription = trim($shortdescriptionarray[$approvedid]);
if ($shortdescription !== ”) {
//echo “id ” . $approvedid . ” summary ” . $shortdescriptionarray[$approvedid] . “
“;
$sql = “UPDATE aylus_HonorPoints SET approved=1, shortdescription = ‘” . $shortdescriptionarray[$approvedid] .
“‘, 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;
}
else
{
$hasError = true;
}
}
}
}
}
if ($hasError)
{
echo ‘
Please enter the event summary upon approval.
‘;
}
echo ‘
Pending Requests
‘;
$sql = “SELECT id, name, eventdate, branch, requestemail, points, description FROM aylus_HonorPoints where approved is null order by id”;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo ‘
‘;
} else {
echo “
No request pending approval.
“;
}
echo ‘
‘;
echo ‘
Approved Requests
‘;
$sql = “SELECT id, subid, name, eventdate, branch, requestemail, points, category, shortdescription, description, submitterip, userid, username, useremail, approved, approvalnotes, approvalip, approvaluserid, approvalusername, approvaluseremail FROM aylus_HonorPoints where approved = 1 order by eventdate”;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo ‘
echo ‘
Name | Event Date | Branch | Submitter Email | Points | Approved by | Event Summary | Description |
---|---|---|---|---|---|---|---|
‘ . $row[“name”] . ‘ | ‘ . date(“m/d/Y”, strtotime($row[“eventdate”])) . ‘ | ‘ . $row[“branch”] . ‘ | ‘ . $row[“requestemail”] . ‘ | ‘ . $row[“points”] . ‘ | ‘ . $row[“approvalusername”] . ‘ | ‘ . $row[“shortdescription”] . ‘ | ‘ . $row[“description”] . ‘ |
‘;
echo ‘
‘;
} else {
echo “
No request approved.
“;
}
$conn->close();
[/insert_php]