function send_birthday_celebration_fund_update_email_to_attendees(Celebration $celebration) { $template = file_get_contents(getcwd() . '/scripts/email_templates/fund_deducted.php'); foreach ($celebration->attendees_member_id_array as $member_id) { $mail = email_init(); $mail->addAddress(get_team_member_email_by_id($member_id)); $mail->Subject = 'Fund Deducted - Online Birthday Manager'; $first_name = get_team_member_name_by_team_member_id($member_id); $body = str_replace("{first_name}", $first_name, $template); $body = str_replace("{birthday_person}", get_team_member_name_by_team_member_id($celebration->birthday_of_member_id), $body); $body = str_replace("{team_name}", get_team_name_by_team_id($celebration->team_id), $body); $body = str_replace("{contribution}", $celebration->perhead_contribution, $body); $body = str_replace("{magic_link}", get_autologin_link(get_team_member_email_by_id($member_id)), $body); $body = str_replace("{new_fund_balance}", get_member_fund_by_team_id_and_member_id($celebration->team_id, $member_id), $body); $mail->Body = $body; $GLOBALS['enable_email'] == true ? $mail->send() : ""; } }
function post_add_celebration(Celebration $celebration) { $connection = connect(); $sql_celebration = "INSERT INTO celebrations (celebration_id, team_id, birthday_of_member_id, celebration_date, cake_amount, other_expense, perhead_contribution, total_attendees) VALUES (NULL, '" . $celebration->team_id . "', '" . $celebration->birthday_of_member_id . "', '" . $celebration->celebration_date . "', '" . $celebration->cake_amount . "', '" . $celebration->other_expense . "', '" . $celebration->perhead_contribution . "', '" . $celebration->total_attendees . "')"; $result_celebration = $connection->query($sql_celebration); $sql_get_celebration_id = "SELECT celebration_id FROM celebrations ORDER BY celebration_id DESC LIMIT 1"; $result_get_celebration_id = $connection->query($sql_get_celebration_id); $celebration_id = ""; if ($result_get_celebration_id->num_rows > 0) { while ($row = $result_get_celebration_id->fetch_assoc()) { $celebration_id = $row["celebration_id"]; } } foreach ($celebration->attendees_member_id_array as $member_id) { // Entry in celebration attendees table for all members $sql_attendees = "INSERT INTO celebration_attendees (celebration_member_key, celebration_id, member_id) VALUES (NULL, '" . $celebration_id . "', '" . $member_id . "')"; $result_attendees = $connection->query($sql_attendees); // Entry in transactions table for all members $transaction_sql = "INSERT INTO `transactions` (`transaction_id`, `transaction_amount`, `member_id`, `team_id`, `transaction_date`, `transaction_type`, `celebration_id`) VALUES (NULL, '" . $celebration->perhead_contribution . "', '" . $member_id . "', '" . $celebration->team_id . "', curdate(), 'debit', '" . $celebration_id . "' )"; $transaction_result = $connection->query($transaction_sql); // Entry in team team members table for fund balance update $current_balance = get_member_fund_by_team_id_and_member_id($celebration->team_id, $member_id); $new_balance = $current_balance - $celebration->perhead_contribution; $update_sql = "UPDATE `team_teammember` SET `fund_balance`= " . $new_balance . " WHERE `team_id`= " . $celebration->team_id . " and `member_id`= " . $member_id; $update_result = $connection->query($update_sql); } disconnect($connection); return $result_celebration == true && $result_attendees == true && $transaction_result == true && $update_result == true ? true : false; }