public function get_rows($start = 0) { // Get rows to display $bip32 = new bip32(); $rows = DB::query("SELECT * FROM coin_wallets WHERE status = 'active' ORDER BY id"); // Go through rows $results = array(); foreach ($rows as $row) { $row['checkbox'] = "<center><input type=\"checkbox\" name=\"wallet_id[]\" value=\"{$row['id']}\"></center>"; $row['balance'] = $bip32->get_balance($row['id']) . ' BTC'; if ($row['address_type'] == 'multisig') { $row['address_type'] = 'Multisig - ' . $row['sigs_required'] . ' of ' . $row['sigs_total']; } else { $row['address_type'] = 'Standard'; } array_push($results, $row); } // Add total $total = DB::queryFirstField("SELECT count(*) FROM coin_wallets WHERE status = 'active'"); if ($total > 1) { // Get balance $total_balance = DB::queryFirstField("SELECT sum(amount) FROM coin_inputs WHERE is_spent = 0"); if ($total_balance == '') { $total_balance = 0; } // Set vars $vars = array('checkbox' => " ", 'id' => " ", 'display_name' => '<b>Total</b>', 'address_type' => " ", 'balance' => '<b>' . fmoney_coin($total_balance) . ' BTC</b>'); array_push($results, $vars); } // Return return $results; }
public function get_rows($start = 0) { // Initialize global $template; // Get rows to display if ($this->userid > 0) { $rows = DB::query("SELECT * FROM orders WHERE userid = %d ORDER BY date_added DESC LIMIT {$start},{$this->rows_per_page}", $this->userid); } else { $rows = DB::query("SELECT * FROM orders WHERE status = %s ORDER BY date_added DESC LIMIT {$start},{$this->rows_per_page}", $this->status); } // Go through rows $results = array(); foreach ($rows as $row) { $row['checkbox'] = "<center><input type=\"checkbox\" name=\"order_id[]\" value=\"{$row['id']}\"></center>"; $row['date_added'] = fdate($row['date_added'], true); $row['product'] = DB::queryFirstField("SELECT display_name FROM products WHERE id = %d", $row['product_id']); $row['amount'] = fmoney_coin($row['amount_btc']) . ' BTC (' . fmoney($row['amount']) . ')'; $row['status'] = ucwords($row['status']); // Get manage URL $url = $template->theme == 'public' ? SITE_URI . "/account/view_order?order_id={$row['id']}" : SITE_URI . "/admin/financial/orders_manage?order_id={$row['id']}"; $row['manage'] = "<center><a href=\"{$url}\" class=\"btn btn-primary btn-xs\">Manage</a></center>"; $username = get_user($row['userid']); $row['username'] = "******"" . SITE_URI . "/admin/user/manage2?username={$username}\">{$username}</a>"; array_push($results, $row); } // Return return $results; }
public function get_rows($start = 0) { // Get rows to display if (isset($_POST['search']) && $_POST['search'] != '') { $rows = DB::query("SELECT * FROM coin_addresses WHERE address LIKE %ss ORDER BY date_added DESC LIMIT {$start},{$this->rows_per_page}", $_POST['search']); } elseif ($this->userid > 0) { $rows = DB::query("SELECT * FROM coin_addresses WHERE userid = %d ORDER BY date_added DESC LIMIT {$start},{$this->rows_per_page}"); } else { $rows = DB::query("SELECT * FROM coin_addresses ORDER BY date_added DESC LIMIT {$start},{$this->rows_per_page}"); } // Go through rows $results = array(); foreach ($rows as $row) { // Get balance $balance = DB::queryFirstField("SELECT sum(amount) FROM coin_inputs WHERE is_spent = 0 AND address = %s", $row['address']); $row['balance'] = fmoney_coin($balance); // Set variables $row['checkbox'] = "<center><input type=\"checkbox\" name=\"input_id[]\" value=\"{$row['id']}\"></center>"; $row['address'] = "<a href=\"" . SITE_URI . "/admin/financial/addresses_view?address={$row['address']}\">{$row['address']}</a>"; $row['date_added'] = fdate($row['date_added'], true); $row['received'] = fmoney_coin($row['total_input']); array_push($results, $row); } // Return return $results; }
public function get_rows($start = 0) { // Get rows to display $rows = DB::query("SELECT * FROM products WHERE is_enabled = %d ORDER BY display_name LIMIT {$start},{$this->rows_per_page}", $this->is_enabled); // Go through rows $results = array(); foreach ($rows as $row) { $row['checkbox'] = "<center><input type=\"checkbox\" name=\"product_id[]\" value=\"{$row['id']}\"></center>"; $row['amount'] = $row['currency'] == 'fiat' ? fmoney($row['amount']) : fmoney_coin($row['amount']) . ' BTC'; array_push($results, $row); } // Return return $results; }
public function get_rows($start = 0) { // Get rows to display $rows = DB::query("SELECT * FROM coin_unauthorized_sends ORDER BY date_added DESC LIMIT {$start},{$this->rows_per_page}"); // Go through rows $results = array(); foreach ($rows as $row) { $irow = DB::queryFirstRow("SELECT * FROM coin_inputs WHERE id = %d", $row['input_id']); $username = get_user($irow['userid']); $row['date_added'] = fdate($row['date_added'], true); $row['amount'] = fmoney_coin($irow['amount']) . ' BTC'; $row['checkbox'] = "<center><input type=\"checkbox\" name=\"unauthorized_send_id[]\" value=\"{$row['id']}\"></center>"; $row['user'] = "******"" . SITE_URI . "/admin/user/manage2?username={$username}\">{$username}</a>"; $row['address'] = "<a href=\"" . SITE_URI . "/admin/financial/addresses_view?address={$irow['address']}\">{$irow['address']}</a>"; $row['viewtx'] = "<center><a href=\"" . SITE_URI . "/admin/financial/tx?txid={$row['txid']}\" class=\"btn btn-primary btn-xs\">View Tx</a></center>"; array_push($results, $row); } // Return return $results; }
public function get_rows($start = 0) { // Initailize global $template; // Get rows to display $rows = DB::query("SELECT * FROM alerts WHERE type = %s AND userid = %d ORDER BY date_added DESC LIMIT {$start},{$this->rows_per_page}", $this->type, $GLOBALS['userid']); // Go through rows $results = array(); foreach ($rows as $row) { // Get URLs $addr_url = $template->theme == 'public' ? SITE_URI . "/account/address?address={$row['address']}" : SITE_URI . "/admin/financial/addresses_view?address={$row['address']}"; // Set variables $row['checkbox'] = "<center><input type=\"checkbox\" name=\"alert_id[]\" value=\"{$row['id']}\"></center>"; $row['date_added'] = fdate($row['date_added'], true); // Type specific variables if ($this->type == 'new_user') { $user_row = DB::queryFirstRow("SELECT * FROM users WHERE id = %d", $row['reference_id']); $row['username'] = $user_row['username']; $row['email'] = $user_row['email']; } else { $input = DB::queryFirstRow("SELECT * FROM coin_inputs WHERE id = %d", $row['reference_id']); $row['username'] = get_user($input['userid']); $row['amount'] = fmoney_coin($input['amount']) . ' BTC'; $row['viewtx'] = "<center><a href=\"" . SITE_URI . "/admin/financial/tx?txid=" . $input['txid'] . "\" class=\"btn btn-primary btn-xs\">View Tx</a></center>"; if ($this->type == 'product_purchase') { $row['product'] = DB::queryFirstField("SELECT display_name FROM products WHERE id = %d", $input['product_id']); $row['manage'] = "<center><a href=\"" . SITE_URI . "/admin/financial/orders_manage?order_id=" . $input['order_id'] . "\" class=\"btn btn-primary btn-xs\">Manage</a></center>"; } elseif ($this->type == 'invoice_paid') { $irow = DB::queryFirstRow("SELECT * FROM invoices WHERE id = %d", $input['invoice_id']); $row['invoice'] = "ID# {$input['invoice_id']} (added: " . fdate($invoice['date_added']) . ")"; $row['manage'] = "<center><a href=\"" . SITE_URI . "/admin/financial/invoices_manage?invoice_id=" . $input['invoice_id'] . "\" class=\"btn btn-primary btn-xs\">Manage</a></center>"; } } //$row['address'] = "<a href=\"$addr_url\">$row[address]</a>"; $row['username'] = "******"" . SITE_URI . "/admin/user/manage2?username={$row['username']}\">{$row['username']}</a>"; array_push($results, $row); } // Return return $results; }
private function set_base_variables() { // Initialize global $config; // Define base template variables $this->assign('site_uri', SITE_URI); $this->assign('site_path', SITE_PATH); $this->assign('theme_uri', SITE_URI . '/themes/' . $this->theme); $this->assign('theme_dir', SITE_PATH . '/themes/' . $this->theme); $this->assign('route', $this->route); $this->assign('page_title', $this->page_title); $this->assign('current_year', date('Y')); $this->assign('exchange_rate', fmoney($config['exchange_rate'])); $this->assign('config', $config); // User message $user_message = ''; $msg_types = array('success', 'info', 'error'); foreach ($msg_types as $type) { if (!isset($this->user_messages[$type])) { continue; } $css_type = $type == 'error' ? 'danger' : $type; // Get icon if ($type == 'info') { $icon = 'info'; } elseif ($type == 'error') { $icon = 'ban'; } else { $icon = 'check'; } // Create HTML $user_message .= '<div class="callout callout-' . $css_type . ' text-center"><p><i class="icon fa fa-' . $icon . '"></i> '; foreach ($this->user_messages[$type] as $msg) { if ($msg == '') { continue; } $user_message .= "{$msg}<br />"; } $user_message .= "</p></div>"; } $this->assign('user_message', $user_message); // Check login //if (!defined('LOGIN')) { // define('LOGIN', false); // $GLOBALS['userid'] = 0; //} // Alerts, if admin panel if ($this->theme == 'admin' && $GLOBALS['userid'] > 0) { // Update alerts DB::query("UPDATE alerts SET is_new = 2 WHERE is_new = 1 AND userid = %d", $GLOBALS['userid']); // Get total alerts $total_alerts = DB::queryFirstField("SELECT count(*) FROM alerts WHERE is_new = 2 AND userid = %d", $GLOBALS['userid']); if ($total_alerts == '') { $total_alerts = 0; } // Get alerts $alerts = array(); $rows = DB::query("SELECT count(*) AS total, sum(amount) AS amount, type FROM alerts WHERE is_new = 2 AND userid = %d GROUP BY type ORDER BY type", $GLOBALS['userid']); foreach ($rows as $row) { // Get icon if ($row['type'] == 'new_user') { $icon = 'fa-users text-light-blue'; $name = '<b>' . $row['total'] . '</b> new users registered'; } elseif ($row['type'] == 'new_deposit') { $icon = 'fa-btc text-green'; $name = '<b>' . $row['total'] . '</b> new deposits, total <b>' . fmoney_coin($row['amount']) . ' BTC</b>'; } elseif ($row['type'] == 'product_purchase') { $icon = 'fa-shield text-red'; $name = '<b>' . $tow['total'] . '<b> product orders, total <b>' . fmoney_coin($row['amount']) . ' BTC</b>'; } elseif ($row['type'] == 'invoice_paid') { $icon = 'fa-file-pdf-o text-orange'; $name = '<b>' . $tow['total'] . '<b> invoices paid, total <b>' . fmoney_coin($row['amount']) . ' BTC</b>'; } else { continue; } // Add to alerts $vars = array('icon' => $icon, 'name' => $name); array_push($alerts, $vars); } // Template variables $this->assign('total_alerts', $total_alerts); $this->assign('alerts', $alerts); } // Set variables $this->assign('is_login', $GLOBALS['userid'] > 0 ? true : false); $this->assign('userid', $GLOBALS['userid']); // User variables, if needed if ($GLOBALS['userid'] > 0) { $user = new user($GLOBALS['userid']); $profile = $user->load(); $this->assign('user', $profile); $this->assign('username', $profile['username']); $this->assign('full_name', $profile['full_name']); $this->assign('email', $profile['email']); } }
$outputs = array($address => $balance); // Gather all unspent inputs $client = new rawtx(); $inputs = $client->gather_inputs($_POST['wallet_id'], $balance, $privkeys); // Create transaction $transaction = $client->create_transaction($_POST['wallet_id'], $inputs, $outputs); // Sign transaction $signed_tx = $client->sign_transaction($transaction, $inputs); // Send transaction $client = new transaction(); $client->send_transaction($signed_tx); // Update wallets DB::query("UPDATE coin_wallets SET status = 'inactive' WHERE id = %d", $_POST['wallet_id']); DB::query("UPDATE coin_inputs SET is_spent = 1 WHERE wallet_id = %d", $_POST['wallet_id']); // User message $balance = fmoney_coin($balance); $template->add_message("Successfully transferred your wallet to the new BIP32 keys. A total of {$balance} BTC was transferred to your new BIP32 key(s), and your new wallet ID# is {$new_wallet_id}."); } // Get wallets $first = true; $bip32_key_fields = ''; $bip32_public_key_fields = ''; $required_sigs = 0; $total_sigs = 0; $wallet_id = 0; $wallet_javascript = ''; $wallet_totals_javascript = ''; $wallet_options = ''; $rows = DB::query("SELECT * FROM coin_wallets WHERE status = 'active' ORDER BY display_name"); foreach ($rows as $row) { $wallet_id = $row['id'];
public function get_tx($txid) { // Get transaction try { $trans = $this->client->getrawtransaction($txid, 1); } catch (Exception $e) { return false; } // Check for blockhash if (isset($trans['blockhash'])) { $block = $this->client->getblock($trans['blockhash']); $trans['blocknum'] = $block['height']; } // Go through inputs $trans['inputs'] = array(); $trans['input_amount'] = 0; foreach ($trans['vin'] as $input) { // Get input transaction try { $input_trans = $this->client->getrawtransaction($input['txid'], 1); } catch (Exception $e) { return false; } // Set input vars $vars = array('txid' => $input['txid'], 'vout' => $input['vout'], 'scriptsig' => ''); // Format script sig while (strlen($input['scriptSig']['hex']) > 80) { $temp = substr($input['scriptSig']['hex'], 0, 80); $input['scriptSig']['hex'] = preg_replace("/^{$temp}/", "", $input['scriptSig']['hex']); $vars['scriptsig'] .= $temp . "<br>"; } // Get amount if (isset($input_trans['vout'][$input['vout']])) { $vars['amount'] = $input_trans['vout'][$input['vout']]['value']; $trans['input_amount'] += $vars['amount']; } // Add input array_push($trans['inputs'], $vars); } // Go through outputs $trans['outputs'] = array(); $trans['output_amount'] = 0; foreach ($trans['vout'] as $output) { $trans['output_amount'] += $output['value']; $vars = array('amount' => $output['value'], 'address' => $output['scriptPubKey']['addresses'][0], 'scriptsig' => $output['scriptPubKey']['asm']); array_push($trans['outputs'], $vars); } // Format amounts $trans['fees'] = fmoney_coin($trans['input_amount'] - $trans['output_amount']); $trans['input_amount'] = fmoney_coin($trans['input_amount']); $trans['output_amount'] = fmoney_coin($trans['output_amount']); // Return return $trans; }
<?php // Initialize global $template; // Get order if (!($row = DB::queryFirstRow("SELECT * FROM orders WHERE id = %d", $_REQUEST['order_id']))) { trigger_error("Order does not exist, ID# {$_REQUEST['order_id']}", E_USER_ERROR); } // Set variables $_POST['order_id'] = $row['id']; $row['username'] = get_user($row['userid']); $row['product_name'] = DB::queryFirstField("SELECT display_name FROM products WHERE id = %d", $row['product_id']) . ' (#' . $row['product_id'] . ')'; $row['amount'] = fmoney_coin($row['amount_btc']) . ' BTC (' . fmoney($row['amount']) . ')'; $row['date_added'] = fdate($row['date_added'], true); // Status options if ($row['status'] == 'declined') { $status_options = '<option value="approved">Approved<option value="declined" selected="selected">Declined<option value="pending">Pending'; } elseif ($row['status'] == 'pending') { $status_options = '<option value="approved">Approved<option value="declined">Declined<option value="pending" selected="selected">Pending'; } else { $status_options = '<option value="approved" selected="selected">Approved<option value="declined">Declined<option value="pending">Pending'; } // Template variables $template->assign('order', $row); $template->assign('status_options', $status_options);
$is_invoice = $row['invoice_id'] > 0 ? true : false; $username = $row['userid'] == 0 ? '-' : get_user($row['userid']); // Get order details if ($is_order === true) { $orow = DB::queryFirstRow("SELECT * FROM orders WHERE id = %d", $row['order_id']); $product_name = DB::queryFirstField("SELECT display_name FROM products WHERE id = %d", $orow['product_id']); $order_details = "<a href=\"" . SITE_URI . "/admin/financial/orders_manage?order_id={$orow['id']}\">ID# {$orow['id']} -- {$product_name}</a>"; } else { $order_details = ''; } // Get invoice details if ($is_invoice === true) { $irow = DB::queryFirstRow("SELECT * FROM invoices WHERE id = %d", $row['invoice_id']); $invoice_details = "<a href=\"" . SITE_URI . "/admin/financial/invoices_manage?invoice_id={$irow['id']}\">ID# {$irow['id']} -- " . fmoney($irow['amount']) . ' (added on ' . fdate($irow['date_added']) . ")</a>"; } else { $invoice_details = ''; } // Set vars $payment = array('is_order' => $is_order, 'is_invoice' => $is_invoice, 'username' => $username, 'date_received' => fdate($row['date_added'], true), 'amount' => fmoney_coin($row['amount']) . ' BTC ', 'order_details' => $order_details, 'invoice_details' => $invoice_details); $template->assign('payment', $payment); } // Template variables $template->assign('is_input', $is_input); $template->assign('txid', $trans['txid']); $template->assign('confirmations', $trans['confirmations']); $template->assign('blocknum', $trans['blocknum']); $template->assign('input_amount', $trans['input_amount']); $template->assign('output_amount', $trans['output_amount']); $template->assign('fees', $trans['fees']); $template->assign('inputs', $trans['inputs']); $template->assign('outputs', $trans['outputs']);
public function get_balance($wallet_id) { // Get balance $balance = DB::queryFirstField("SELECT sum(amount) FROM coin_inputs WHERE wallet_id = %d AND is_spent = 0", $wallet_id); if ($balance == '') { $balance = 0; } // Withdraw pending sends $pending_sends = DB::queryFirstField("SELECT sum(amount) FROM coin_sends WHERE wallet_id = %d AND status = 'pending'", $wallet_id); $balance -= $pending_sends; // Return return fmoney_coin($balance); }
$revenue_labels = array(); $revenue_data = array(); for ($x = 0; $x <= 10; $x++) { // Get date $date = $x == 0 ? DB::queryFirstField("SELECT date(now())") : DB::queryFirstField("SELECT date(date_sub(now(), interval {$x} day))"); list($year, $month, $day) = explode("-", $date); // Get revenuve $revenue = DB::queryFirstField("SELECT sum(amount) FROM coin_inputs WHERE date(date_added) = '{$date}'"); if ($revenue == '') { $revenue = 0; } // Add to chart data $revenue_labels[] = date('M, d', mktime(0, 0, 0, $month, $day, $year)); $revenue_data[] = fmoney_coin($revenue); } // Template variables $template->assign('funds_received', fmoney_coin($total_funds_received)); $template->assign('new_deposits', $total_new_deposits); $template->assign('new_deposits_amount', fmoney_coin($total_new_deposts_amount)); $template->assign('total_users', $total_users); $template->assign('new_users', $new_users); $template->assign('total_products', $total_products); $template->assign('total_products_amount', fmoney_coin($total_products_amount)); $template->assign('new_products', $new_products); $template->assign('new_products_amount', fmoney_coin($new_products_amount)); $template->assign('total_invoices', $total_invoices); $template->assign('total_invoices_amount', fmoney_coin($total_invoices_amount)); $template->assign('new_invoices', $new_invoices); $template->assign('new_invoices_amount', fmoney_coin($new_invoices_amount)); $template->assign('revenue_chart_labels', '"' . implode('","', $revenue_labels) . '"'); $template->assign('revenue_chart_data', implode(", ", $revenue_data));
<?php // Initialize global $template, $currency; // Get invoice if (!($row = DB::queryFirstRow("SELECT * FROM invoices WHERE id = %d", $_REQUEST['invoice_id']))) { trigger_error("Invoice does not exist, ID# {$_REQUST['invoice_id']}", E_USER_ERROR); } // Set variables $row['wallet_name'] = DB::queryFirstField("SELECT display_name FROM coin_wallets WHERE id = %d", $row['wallet_id']); $row['status'] = ucwords($row['status']); $row['date_added'] = fdate($row['date_added']); $row['date_paid'] = preg_match("/^0000/", $row['date_paid']) ? 'Unpaid' : fdate($row['date_paid']); $row['note'] = str_replace("\n", "<br />", $row['note']); $row['amount'] = fmoney($row['amount']); $row['amount_btc'] = fmoney_coin($row['amount_btc']); // Template variables $template->assign('invoice', $row);
function send_notifications($action, $id) { // Initialize global $config; // Get variables $userid = 0; if ($action == 'new_deposit' || $action == 'product_purchase' || $action == 'invoice_paid') { // Get input $row = DB::queryFirstRow("SELECT * FROM coin_inputs WHERE id = %d", $id); $wallet_name = DB::queryFirstField("SELECT display_name FROM coin_wallets WHERE id = %d", $row['wallet_id']); $userid = $row['userid']; // Set vars $vars = array('userid' => $row['userid'], 'username' => get_user($row['userid']), 'wallet_id' => $row['wallet_id'], 'wallet_name' => $wallet_name, 'product_id' => $row['product_id'], 'order_id' => $row['order_id'], 'invoice_id' => $row['invoice_id'], 'address' => $row['address'], 'txid' => $row['txid'], 'vout' => $row['vout'], 'amount' => $row['amount'], 'date_added' => fdate($row['date_added'], true)); // Product name if ($row['product_id'] > 0) { $vars['product_name'] = DB::queryFirstField("SELECT display_name FROM products WHERE id = %d", $row['product_id']); } else { $vars['product_name'] = 'N/A'; } // Invoice name if ($row['invoice_id'] > 0) { $irow = DB::queryFirstRow("SELECT * FROM invoices WHERE id = %d", $row['invoice_id']); $vars['invoice_name'] = "ID# {$row['invoice_id']} (" . fmoney_coin($row['amount_btc']) . ' BTC)'; } else { $vars['invoice_name'] = 'N/A'; } } elseif ($action == 'funds_sent') { // Get send $row = DB::queryFirstRow("SELECT * FROM coin_sends WHERE id = %d", $id); $wallet_name = DB::queryFirstField("SELECT display_name FROM coin_wallets WHERE id = %d", $row['wallet_id']); $userid = $row['userid']; // Get recipients $recipients = ''; $recip_rows = DB::query("SELECT * FROM coin_sends_addresses WHERE send_id = %d ORDER BY id", $id); foreach ($recip_rows as $recip_row) { $recipients .= $recip_row['address'] . ' - ' . $recip_row['amount'] . " BTC\n"; } // Set vars $vars = array('send_id' => $row['id'], 'wallet_id' => $row['wallet_id'], 'wallet_name' => $wallet_name, 'status' => ucwords($row['status']), 'amount' => $row['amount'], 'txid' => $row['txid'], 'date_added' => fdate($row['date_added'], true), 'recipients' => $recipients); } elseif ($action == 'invoice_created') { // Get invoice $row = DB::queryFirstRow("SELECT * FROM invoices WHERE id = %d", $id); $wallet_name = DB::queryFirstField("SELECT display_name FROM coin_wallets WHERE id = %d", $row['wallet_id']); $userid = $row['userid']; // Set vars $vars = array('invoice_id' => $row['id'], 'wallet_id' => $row['wallet_id'], 'wallet_name' => $wallet_name, 'userid' => $row['userid'], 'username' => get_user($row['userid']), 'status' => ucwords($row['status']), 'currency' => $row['currency'], 'amount' => $row['amount'], 'amount_btc' => $row['amount_btc'], 'amount_paid' => $row['amount_paid'], 'address' => $row['payment_address'], 'date_added' => fdate($row['date_added'], true), 'date_paid' => fdate($row['date_paid'], true), 'note' => $row['note'], 'process_note' => $row['process_note'], 'pay_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/' . SITE_URI . '/pay?invoice_id=' . $row['id']); } // Global variables $vars['site_name'] = $config['site_name']; $vars['company_name'] = $config['company_name']; // Go through notifications $rows = DB::query("SELECT * FROM notifications WHERE action = %s AND is_enabled = 1 ORDER BY id", $action); foreach ($rows as $row) { // Get recipients if ($row['recipient'] == 'admin') { $recipients = DB::queryFirstColumn("SELECT id FROM users WHERE group_id = 1 AND status = 'active' ORDER BY id"); } else { $recipients = array($userid); } // Format message $contents = base64_decode($row['contents']); foreach ($vars as $key => $value) { $row['subject'] = str_ireplace("~{$key}~", $value, $row['subject']); $contents = str_ireplace("~{$key}~", $value, $contents); } // Send message foreach ($recipients as $recipient) { $email = DB::queryFirstField("SELECT email FROM users WHERE id = %d", $recipient); mail($email, $row['subject'], $contents); } } }