function eme_create_payments_table($charset, $collate) { global $wpdb; $db_version = get_option('eme_version'); $table_name = $wpdb->prefix . PAYMENTS_TBNAME; if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) { $sql = "CREATE TABLE " . $table_name . " (\n id int(11) NOT NULL auto_increment,\n creation_date_gmt datetime NOT NULL DEFAULT '0000-00-00 00:00:00', \n booking_ids text NOT NULL,\n random_id tinytext NOT NULL,\n UNIQUE KEY (id)\n ) {$charset} {$collate};"; maybe_create_table($table_name, $sql); } else { maybe_add_column($table_name, 'random_id', "alter table {$table_name} add random_id tinytext NOT NULL;"); if ($db_version < 80) { $payment_ids = $wpdb->get_col("SELECT id FROM {$table_name}"); foreach ($payment_ids as $payment_id) { $random_id = eme_payment_random_id(); $sql = $wpdb->prepare("UPDATE {$table_name} SET random_id = %s WHERE id = %d", $random_id, $payment_id); $wpdb->query($sql); } } } }
function eme_create_payment($booking_ids) { global $wpdb; $payments_table = $wpdb->prefix . PAYMENTS_TBNAME; $bookings_table = $wpdb->prefix . BOOKINGS_TBNAME; // some safety if (!$booking_ids) { return false; } $payment_id = false; $payment = array(); $payment['booking_ids'] = $booking_ids; $payment['random_id'] = eme_payment_random_id(); $payment['creation_date_gmt'] = current_time('mysql', true); if ($wpdb->insert($payments_table, $payment)) { $payment_id = $wpdb->insert_id; $booking_ids_arr = explode(",", $booking_ids); foreach ($booking_ids_arr as $booking_id) { $where = array(); $fields = array(); $where['booking_id'] = $booking_id; $fields['transfer_nbr_be97'] = eme_transfer_nbr_be97($payment_id); $wpdb->update($bookings_table, $fields, $where); } } #return $payment_id; }