function mcs_uniqid($hash, $i = 1)
{
    global $wpdb;
    $sql = "SELECT hash FROM " . my_calendar_payments_table() . " WHERE hash='{$hash}'";
    if ($wpdb->get_var($sql)) {
        $hash = uniqid('E' . $i);
        mcs_uniqid($hash, $i++);
    } else {
        return $hash;
    }
}
function mcs_add_payment($post)
{
    global $wpdb;
    if (isset($post['mc-submit-payments'])) {
        $nonce = $_POST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-payments')) {
            return;
        }
        $quantity = (int) $post['quantity'];
        // admin email after submission
        $price = sprintf("%01.2f", $post['price']);
        // submitter email after submission
        $first_name = $post['first_name'];
        // subject line
        $last_name = $post['last_name'];
        $email = is_email($post['email']);
        $transaction_date = date('Y-m-d h:m:s', strtotime($post['transaction_date']));
        $uniqid = uniqid('E');
        $hash = mcs_uniqid($uniqid);
        $add = array('item_number' => 1, 'quantity' => $quantity, 'total' => $quantity, 'hash' => $hash, 'txn_id' => 'Manual Entry', 'price' => $price, 'fee' => '0.00', 'status' => 'Completed', 'transaction_date' => $transaction_date, 'first_name' => $first_name, 'last_name' => $last_name, 'payer_email' => $email);
        $formats = array('%d', '%d', '%d', '%s', '%s', '%f', '%f', '%s', '%s', '%s', '%s', '%s');
        $insert = $wpdb->insert(my_calendar_payments_table(), $add, $formats);
        if ($insert) {
            $notifications = mcs_send_notifications($first_name, $last_name, $email, $price, $hash, $quantity);
            return "<div class=\"updated\"><p><strong>" . __('New Payment Added', 'my-calendar-submissions') . "</strong></p></div>";
        } else {
            return "<div class=\"updated error\"><p><strong>" . __('New Payment was not added.', 'my-calendar-submissions') . "</strong></p></div>";
        }
    }
    return false;
}