prefix . $bookings_table; $sql = "CREATE TABLE " . $table_name . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, first_name text, last_name text, job text, company text, email text, telephone text, mailinglist boolean, source tinytext, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); add_option("tsbooking_version", $tsbooking_version); } register_activation_hook(__FILE__,'tsbooking_install'); // Brandword Availability Checking function tsbooking_makebooking( $atts ) { global $wpdb; global $bookings_table; $booking_length = get_option('tsbooking_booklength') * 60; extract( shortcode_atts( array(), $atts)); // Get the list of available appointments $table_name = $wpdb->prefix . $bookings_table; $dbresult = $wpdb->get_results("SELECT time FROM $table_name WHERE first_name IS NULL OR LENGTH(first_name) = 0 ORDER BY time"); if (count($dbresult) == 0) { $result = '
';
update_option('tsbooking_booklength', 15); // Booking Length
update_option('tsbooking_email_from', 'No Reply
'; $selectedAppts = $_POST['tsbooking_appt_row']; $itemCount = count($selectedAppts); for ($pos = 0; $pos < $itemCount; ++$pos) { $wpdb->update( $table_name, array( 'first_name' => NULL, 'last_name' => NULL, 'job' => NULL, 'email' => NULL, 'company' => NULL, 'telephone' => NULL, 'source' => NULL, 'mailinglist' => "0"), array( 'id' => $selectedAppts[$pos] ) ); } echo 'Reset ' . $itemCount . ' appointment(s).'; echo '
'; $selectedAppts = $_POST['tsbooking_appt_row']; $itemCount = count($selectedAppts); if ($itemCount > 0) { $query = "DELETE FROM $table_name WHERE id IN ("; for ($pos = 0; $pos < $itemCount; ++$pos) { if ($pos != 0) $query .= ','; $query .= "'" . $selectedAppts[$pos] . "'"; } $query .= ")"; $wpdb->query($query); } echo 'Deleted ' . $itemCount . ' appointment(s).'; echo '
'; $aptsDate = $_POST['tsbooking_apptdate']; $aptsTime = $_POST['tsbooking_appttime']; $newAppt = strtotime($aptsTime . ' ' . $aptsDate); if ($newAppt) { $wpdb->insert( $table_name, array( 'time' => date("Y/m/d H:i:s", $newAppt) ) ); echo 'Added appointment at ' . date("H:i d/m/Y", $newAppt); } else { echo 'Requested appointment date not understood'; } echo '
'; update_option('tsbooking_booklength', $length); // Booking Length update_option('tsbooking_email_from', $from); // From Email Address update_option('tsbooking_email_bcc', $bcc); // Email BCC Address for confirmation emails update_option('tsbooking_email_subject', $subject); // Email subject prefix update_option('tsbooking_email_message', $message); // Email message completion echo 'Configuration Updated!'; echo '