/** * Insert all the old values from appointments */ private function migrateOldFormValues($ids) { global $wpdb; $table_name = 'ea_appointments'; $models = new EADBModels(); $apps = $models->get_all_rows($table_name); $chunks = array_chunk($apps, 100); $rows = array(); $keys = array('email', 'name', 'phone', 'description'); $table_name = $wpdb->prefix . 'ea_fields'; foreach ($chunks as $chunk) { // helpers $values = array(); $place_holders = array(); $query = "INSERT INTO {$table_name} (app_id, field_id, value) VALUES "; // all appointments foreach ($chunk as $app) { // set insert for every key email, name, phone, description foreach ($keys as $key) { array_push($values, $app->id, $ids[$key], $app->{$key}); $place_holders[] = "('%d', '%d', '%s')"; } } $query .= implode(', ', $place_holders); $wpdb->query($wpdb->prepare("{$query} ", $values)); } }
/** * */ private function get_options($type) { if (!$this->generate_next_option) { return; } $dbmod = new EADBModels(); $rows = $dbmod->get_all_rows("ea_{$type}"); // If there is only one result if (count($rows) == 1) { $price = !empty($rows[0]->price) ? " data-price='{$rows[0]->price}'" : ''; echo "<option value='{$rows[0]->id}' selected='selected'{$price}>{$rows[0]->name}</option>"; return; } echo "<option value='' selected='selected'>-</option>"; foreach ($rows as $row) { $price = !empty($row->price) ? " data-price='{$row->price}'" : ''; echo "<option value='{$row->id}'{$price}>{$row->name}</option>"; } // just to have all options //$this->generate_next_option = false; }
/** * Send email notification */ public static function send_notification($data) { $emails = self::get_option_value('pending.email', ''); if ($emails == '') { return; } $dbmodels = new EADBModels(); $app_id = $data['id']; $data = $dbmodels->get_appintment_by_id($app_id); $meta = $dbmodels->get_all_rows('ea_meta_fields', array(), array('position' => 'ASC')); ob_start(); require EA_SRC_DIR . 'templates/mail.notification.tpl.php'; $mail_content = ob_get_clean(); $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($emails, __('New Reservation #', 'easy-appointments') . $app_id, $mail_content, $headers); }
/** * Send email notification for admin */ public static function send_notification($data) { $emails = self::get_option_value('pending.email', ''); if ($emails == '') { return; } $dbmodels = new EADBModels(); $app_id = $data['id']; $data = $dbmodels->get_appintment_by_id($app_id); $meta = $dbmodels->get_all_rows('ea_meta_fields', array(), array('position' => 'ASC')); $params = array(); $time_format = get_option('time_format'); $date_format = get_option('date_format'); foreach ($data as $key => $value) { if ($key == 'start' || $key == 'end') { $value = date($time_format, strtotime("{$data['date']} {$value}")); } if ($key == 'date') { $value = date($date_format, strtotime("{$value} {$data['start']}")); } $params["#{$key}#"] = $value; $data[$key] = $value; } $subject_template = EALogic::get_option_value('pending.subject.email', 'Notification : #id#'); $send_from = EALogic::get_option_value('send.from.email', ''); $subject = str_replace(array_keys($params), array_values($params), $subject_template); ob_start(); require EA_SRC_DIR . 'templates/mail.notification.tpl.php'; $mail_content = ob_get_clean(); $headers = array('Content-Type: text/html; charset=UTF-8'); if (!empty($send_from)) { $headers[] = 'From: ' . $send_from; } wp_mail($emails, $subject, $mail_content, $headers); }