| Server IP : 3.96.16.70 / Your IP : 216.73.216.15 Web Server : Apache System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/registration.mining4life.org/wp-content/plugins/m4l_plugin/ |
Upload File : |
<?php
require_once(get_stylesheet_directory() . '/vendor/autoload.php');
use Postmark\PostmarkClient;
use Postmark\Models\PostmarkException;
function countTables( $include_empty_tables ) {
global $wpdb;
// Initialize all tables 1–HEFL_NUM_TABLES with 0 people
$tables = [];
for ( $t = 1; $t <= HEFL_NUM_TABLES; $t++ ) {
$tables[$t] = ['num_people' => 0];
}
// Single query: get all guests with inattendance=yes, fetch their tablenumber
$sql = $wpdb->prepare(
"
SELECT pm_table.meta_value AS table_number, COUNT(*) AS guest_count
FROM {$wpdb->posts} p
INNER JOIN {$wpdb->postmeta} pm_in
ON p.ID = pm_in.post_id
AND pm_in.meta_key = %s
AND pm_in.meta_value = %s
INNER JOIN {$wpdb->postmeta} pm_table
ON p.ID = pm_table.post_id
AND pm_table.meta_key = %s
WHERE p.post_type = %s
AND p.post_status = %s
GROUP BY pm_table.meta_value
",
'guest_inattendance', 'yes', 'guest_tablenumber', 'guest', 'publish'
);
$results = $wpdb->get_results( $sql );
// Fill in counts
foreach ( $results as $row ) {
$table_num = intval( $row->table_number );
if ( $table_num >= 1 && $table_num <= HEFL_NUM_TABLES ) {
$tables[$table_num]['num_people'] = intval( $row->guest_count );
}
}
// Optionally remove empty tables
if ( ! $include_empty_tables ) {
foreach ( $tables as $key => $val ) {
if ( $val['num_people'] === 0 ) {
unset( $tables[$key]);
}
}
}
return $tables;
}
function countTablesEverybody( $include_empty_tables ) {
global $wpdb;
// Initialize all tables 1–HEFL_NUM_TABLES with 0 people
$tables = [];
for ( $t = 1; $t <= HEFL_NUM_TABLES; $t++ ) {
$tables[$t] = ['num_people' => 0];
}
// Single query: get all guests, grouped by table number
$sql = $wpdb->prepare(
"
SELECT pm_table.meta_value AS table_number, COUNT(*) AS guest_count
FROM {$wpdb->posts} p
INNER JOIN {$wpdb->postmeta} pm_table
ON p.ID = pm_table.post_id
AND pm_table.meta_key = %s
WHERE p.post_type = %s
AND p.post_status = %s
GROUP BY pm_table.meta_value
",
'guest_tablenumber', 'guest', 'publish'
);
$results = $wpdb->get_results( $sql );
// Fill in counts
foreach ( $results as $row ) {
$table_num = intval( $row->table_number );
if ( $table_num >= 1 && $table_num <= HEFL_NUM_TABLES ) {
$tables[$table_num]['num_people'] = intval( $row->guest_count );
}
}
// Optionally remove empty tables
if ( ! $include_empty_tables ) {
foreach ( $tables as $key => $val ) {
if ( $val['num_people'] === 0 ) {
unset( $tables[$key]);
}
}
}
return $tables;
}
function sendReceipt($postID, $to_email, $transID) {
global $wpdb;
// Get the post & the guest_email postmeta
$post = get_post($postID);
//$to = get_post_meta($post->ID, 'guest_email', true);
$to = $to_email;
$firstname = get_post_meta($post->ID, 'guest_firstname', true);
// Get the transaction
$response = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->wp_hefl_cctrans WHERE id = %s", $transID), ARRAY_A );
try {
$client = new PostmarkClient(POSTMARK_CLIENT_API);
$sendResult = $client->sendEmailWithTemplate(
"receipt@mining4life.org", // Sender
$to, // Recipient
POSTMARK_BUYINRECEIPT_TEMPLATE_ID, // Template ID
[ // Template Variables
"firstname" => ucfirst($firstname),
"transID" => $response[0]['result_transactionid'],
"transDate" => $response[0]['result_settlementbatchdate'],
"buyInType" => $response[0]['description'],
"buyInValue" => $response[0]['amount']
]
);
} catch(PostmarkException $ex){
// If client is able to communicate with the API in a timely fashion,
// but the message data is invalid, or there's a server error,
// a PostmarkException can be thrown.
$postError = $ex->httpStatusCode . '<br>';
$postError .= $ex->message . '<br>';
$postError .= $ex->postmarkApiErrorCode;
exit(json_encode($postError));
} catch(Exception $generalException){
// A general exception is thrown if the API
// was unreachable or times out.
$postError = $generalException->getMessage();
exit(json_encode($postError));
}
}
function generateMembershipForm($postID) {
$options = get_option('hefl_registration_options');
$guest_table = get_post_meta($postID, 'guest_table', true);
$guest_name = get_post_meta($postID, 'guest_firstname', true) . " " . get_post_meta($postID, 'guest_lastname', true);;
$guest_phonenumber = get_post_meta($postID, 'guest_phonenumber', true);
$guest_email = get_post_meta($postID, 'guest_email', true);
$guest_membershipdate = get_post_meta($postID, 'guest_membershipdate', true);
$guest_signature = get_post_meta($postID, 'guest_signature', true);
$im = new Imagick();
$im->readImageBlob($guest_signature);
if ( $im->getImageWidth() > 540 ) {
$im->resizeImage(540, 0, imagick::FILTER_LANCZOS, 1);
}
$im->setImageFormat("png24");
$im->writeImage(get_home_path() . "pdf/" . $postID . ".png");
$output = '<table style="width: 540px;">
<tr>
<td style="width: 150px;">Table</td>
<td>'.$guest_table.'</td>
</tr>
<tr>
<td style="width: 150px;">Member Name</td>
<td>'.$guest_name.'</td>
</tr>
<tr>
<td style="width: 150px;">Telephone</td>
<td>'.$guest_phonenumber.'</td>
</tr>
<tr>
<td style="width: 150px;">Email Address</td>
<td>'.$guest_email.'</td>
</tr>
<tr>
<td style="width: 150px;">Date</td>
<td>'.$guest_membershipdate.'</td>
</tr>
</table>
<table tyle="width: 540px;">
<tr>
<td>
<p><strong>MEMBERSHIP STATEMENT:</strong> Mining4lLife is a corporation without share capital incorporated under Part II of the <em>Canada Not-for-profit Corporations Act</em> to raise funds for various charitable organizations. Membership in Mining4Life offers the opportunity to participate in any Mining4Life events, including the event held on ' . date('F j, Y', strtotime($options['hefl_event_date'])) . '. Net proceeds from this event will be donated to the Hospital for Sick Children, BC Children\'s Hospital and Plan International Canada.</p>
<p><strong>APPLICATION FOR MEMBERSHIP:</strong> I hereby apply for membership for Mining4Life. I support its charitable objectives and agree to the following: 1) I shall abide by its articles of incorporation, bylaws, rules and regulations. 2) The board of directors shall have full authority to: (a) remove me from any event if, in the board\'s reasonable determination, I am considered to be compromising the fairness or integrity of the event in any way. 3) Mining4Life is not liable and assumes no responsibility for the acts or omissions of any member or for any disputes regarding the rules at any event. 4) In consideration of Mining4Life\'s acceptance of my application for membership, I hereby, for myself, my heirs, executors, administrators and assigns, forever release, discharge and hold harmless Mining4Life, its directors, volunteers, representatives and agents from any claim or liability arising out of or relating to any event sponsored by Mining4Life. 5) I confirm my resignation as a member of Mining4Life effective ' . date('F j, Y', strtotime('December 31')) . '.</p>
</td>
</tr>
<tr>
<td>
<img src="'.get_home_path().'pdf/'.$postID.'.png" border="0" />
</td>
</tr>
</table>';
return $output;
}
function canDelete($postID) {
$post = get_post($postID);
$guest_inattendance = get_post_meta($post->ID, 'guest_inattendance', true);
if ($guest_inattendance == "yes") {
return false;
} else {
return true;
}
}
?>