prefix . get_class($this) . "_procedures"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $sql = "CREATE TABLE " . $table_name . " ( id int(6) NOT NULL AUTO_INCREMENT, name VARCHAR(200), length int(5) DEFAULT '0' NOT NULL, public int(1) DEFAULT '1' NOT NULL, deleted int(1) DEFAULT '0' NOT NULL, UNIQUE KEY id (id) ) CHARSET utf8;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); //add default procedures // TODO MAKE ME TRANSLATABLE $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Vaktsineerimine', 'length' => 15 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Vaktsineerimine, mikrokiibiga märgistamine ja registrisse kandmine', 'length' => 30 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Emase kassi steriliseerimine', 'length' => 60 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Isase kassi kastreerimine', 'length' => 40 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Väikese emase koera steriliseerimine', 'length' => 60 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Suure emase koera steriliseerimine', 'length' => 90 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Isase koera kastreerimine', 'length' => 60 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Tervisekontrolli uuringud (vereanalüüs+ultraheli+röntgen)', 'length' => 120 ) ); $rows_affected = $wpdb->insert( $table_name, array( 'name' => 'Dermatoloogilised probleemid', 'length' => 30 ) ); } $table_name = $wpdb->prefix . get_class($this) . "_reservations"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $sql = "CREATE TABLE " . $table_name . " ( id int(6) NOT NULL AUTO_INCREMENT, name VARCHAR(200), length int(5) DEFAULT '0' NOT NULL, public int(1) DEFAULT '1' NOT NULL, PRIMARY KEY id (id) );"; $sql = "CREATE TABLE " . $table_name . " ( id INT(6) NOT NULL AUTO_INCREMENT, start_time DATETIME NOT NULL, length INT(5) NOT NULL, procedure_id INT(6) NOT NULL, client_name VARCHAR(200) NOT NULL, client_telephone VARCHAR(200) NOT NULL, client_email VARCHAR(200) NOT NULL, animal VARCHAR(200) NOT NULL, animal_age VARCHAR(200) NOT NULL, animal_sex INT(1) NOT NULL DEFAULT 0, problem VARCHAR(2000) NOT NULL, status INT(1) NOT NULL, PRIMARY KEY id (id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } add_option( get_class($this) . "_email_reservations_to", "email@example.com" ); add_option( get_class($this) . "_email_reservation_from", "email@example.com" ); add_option( get_class($this) . "_name_email_from", "Example Name" ); add_option( get_class($this) . "_day_start_time", "8:00" ); add_option( get_class($this) . "_day_end_time", "17:00" ); add_option( get_class($this) . "_reservation_time_step", "30" ); add_option( get_class($this) . "_new_reservation_email", "Tere,\r\n\r\n" . "veebilehe kaudu on tulnud uus broneering. \r\nBroneeringu andmed:" . "\r\nAlgus: {algus}\r\nPikkus: {pikkus}\r\nProtseduuri nimi: {protseduur}\r\n" . "Nimi: {nimi}\r\nTelefon: {telefon}\r\nEmail: {email}\r\nLoom: {loom}\r\n" . "Vanus: {vanus}\r\nSugu: {sugu}\r\nProbleem: {probleem}\r\n" ); add_option( get_class($this) . "_reservation_confirm_email_subject", "Broneeringu kinnitus" ); add_option( get_class($this) . "_reservation_confirm_email", "Tere {nimi},\r\n\r\n" ."Teie broneering algusajaga {algus} ja pikkusega {pikkus}minutit on kinnitatud." ); add_option( get_class($this) . "_reservation_decline_email_subject", "Broneeringu tühistus" ); add_option( get_class($this) . "_reservation_decline_email", "Tere {nimi},\r\n\r\n" ."Teie broneering algusajaga {algus} ja pikkusega {pikkus}minutit on tühistatud." ); } function uninstall() { global $wpdb; $list_of_tables_to_drop = Array( '_procedures', '_reservations' ); foreach ( $list_of_tables_to_drop as $table_name ) { $full_table_name = $wpdb->prefix . get_class($this) . $table_name; $sql = "DROP TABLE " . $full_table_name; $wpdb->query( $sql ); } } function add_pages(){ add_menu_page( 'Broneeringud', 'Broneeringud', 'manage_options', __FILE__, array( &$this, 'get_manage_reservations_page' ) ); $manage_reservations_page = add_submenu_page( __FILE__, 'Broneeringute haldamine', 'Broneeringute haldamine', 'manage_options', __FILE__, array( &$this, 'get_manage_reservations_page' ) ); $add_reservation_page = add_submenu_page( __FILE__, 'Lisa broneering', 'Lisa broneering', 'manage_options', 'get_add_reservation_page', array( &$this, 'get_add_reservation_page' ) ); add_submenu_page( __FILE__, 'Protseduuride haldamine', 'Protseduuride haldamine', 'manage_options', 'get_manage_procedures_page', array( &$this, 'get_manage_procedures_page' ) ); add_submenu_page( __FILE__, 'Seaded', 'Seaded', 'manage_options', 'get_options_page', array( &$this, 'get_options_page' ) ); add_action( 'admin_print_styles-' . $manage_reservations_page, array( &$this, 'HtkLoomakliinik_head_additions' ) ); add_action( 'admin_print_styles-' . $add_reservation_page, array( &$this, 'HtkLoomakliinik_head_additions' ) ); add_action( 'admin_print_scripts-' . $add_reservation_page, array( &$this, 'HtkLoomakliinik_head_additions' ) ); } function HtkLoomakliinik_head_additions(){ wp_enqueue_style( 'HtkLoomakliinik' ); wp_enqueue_style( 'jquery-ui' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'HtkLoomakliinik' ); wp_enqueue_script( 'jquery-ui' ); wp_enqueue_script( 'jquery-ui-datepicker-et' ); } function ajax_get_available_times(){ $response = array(); $ignore_reservation_id = ( isset( $_POST['ignore_id'] ) )? (int)$_POST['ignore_id']:false; if( isset( $_POST['date'] ) && isset( $_POST['procedure_id'] ) ){ $procedure = $this->get_procedure( (int)$_POST['procedure_id'] ); if( $procedure == false ){ $response['code'] = 0; $response['message'] = 'Procedure not found!'; }else{ $length = $procedure['length']; $date = strtotime( $_POST['date'] ); $response['code'] = 1; $response['times'] = $this->get_available_times( $date, $length, $ignore_reservation_id ); } }elseif( isset( $_POST['date'] ) && isset( $_POST['length'] ) ){ $length = (int)$_POST['length']; $date = strtotime( $_POST['date'] ); $response['code'] = 1; $response['times'] = $this->get_available_times( $date, $length, $ignore_reservation_id ); }else{ $response['code'] = 0; $response['message'] = 'Date or/and length not set!'; } echo json_encode($response); die(); } function ajax_get_month_business(){ $response = array(); if( isset( $_POST['year'] ) && isset( $_POST['month'] ) ){ $response['code'] = 1; $ignore_reservation_id = ( isset( $_POST['ignore_id'] ) )? (int)$_POST['ignore_id']:false; if( isset( $_POST['procedure_id'] ) && (int)$_POST['procedure_id'] > 0 ){ $procedure = $this->get_procedure( $_POST['procedure_id'] ); $response['days'] = $this->get_month_days_business( (int)$_POST['month'], (int)$_POST['year'], true, $procedure['length'], $ignore_reservation_id ); }elseif( isset( $_POST['length'] ) ){ $length = (int)$_POST['length']; $response['days'] = $this->get_month_days_business( (int)$_POST['month'], (int)$_POST['year'], true, $length, $ignore_reservation_id ); }else{ $response['days'] = $this->get_month_days_business( (int)$_POST['month'], (int)$_POST['year'], true, 15, $ignore_reservation_id ); // $response['days'] = $this->get_month_days_business( (int)$_POST['month'], (int)$_POST['year'] ); } }else{ $response['code'] = 0; $response['message'] = 'Year or/and month not set!'; } echo json_encode($response); die(); } function get_day_reservations( $date, $ignore_reservation_id = false ){ global $wpdb; $reservations = array(); $sql_start = date( 'Y', $date ) . '-' . date( 'm', $date ) . '-' . date( 'd', $date ); $sql_end = date( 'Y', $date ) . '-' . date( 'm', $date ) . '-' . ( date( 'd', $date ) +1 ); $table_name = $wpdb->prefix . get_class( $this ) . "_reservations"; $table_name_procedures = $wpdb->prefix . get_class( $this ) . "_procedures"; $ignore_reservation_id_sql_str = ( $ignore_reservation_id === false )?'': " AND $table_name.id <> " . (int)$ignore_reservation_id; $sql = "SELECT $table_name.id as id, $table_name.start_time as start_time, $table_name.length as length, $table_name.procedure_id as procedure_id, $table_name.client_name as client_name, $table_name.client_telephone as client_telephone, $table_name.client_email as client_email, $table_name.animal as animal, $table_name.animal_age as animal_age, $table_name.animal_sex as animal_sex, $table_name.problem as problem, $table_name.status as status, $table_name_procedures.name as procedure_name FROM $table_name, $table_name_procedures WHERE $table_name_procedures.id = $table_name.procedure_id AND $table_name.start_time > '$sql_start' AND $table_name.start_time < '$sql_end' AND $table_name.status != 2 AND $table_name.status != 3 $ignore_reservation_id_sql_str ORDER BY start_time ASC"; $rows = $wpdb->get_results( $sql, OBJECT ); foreach ($rows as $row){ $reservation = array(); $reservation['id'] = (int)$row->id; $reservation['start_time'] = strtotime( $row->start_time ); $reservation['length'] = (int)$row->length; $reservation['procedure_id'] = (int)$row->procedure_id; $reservation['client_name'] = $row->client_name; $reservation['client_telephone'] = $row->client_telephone; $reservation['client_email'] = $row->client_email; $reservation['animal'] = $row->animal; $reservation['animal_age'] = $row->animal_age; $reservation['animal_sex'] = $row->animal_sex; $reservation['problem'] = $row->problem; $reservation['status'] = (int)$row->status; $reservation['procedure_name'] = $row->procedure_name; array_push($reservations, $reservation); } return $reservations; } function get_available_times( $date, $length, $ignore_reservation_id = false ){ $taken_times = $this->get_day_reservations( $date, $ignore_reservation_id ); $available_times = $this->construct_available_times( $taken_times, $date, $length ); return $available_times; } function construct_available_times( $taken_times, $date, $length_to_find ){ $available_times = array(); $day_start = get_option( get_class($this) . '_day_start_time' ); $day_end = get_option( get_class($this) . '_day_end_time' ); $step = (int)get_option( get_class($this) . '_reservation_time_step' ); if( $step <= 0 ){ $step = 30; } $day_start_hour = split(':', $day_start); $day_start_hour = (int)$day_start_hour[0]; $day_start_minute = split(':', $day_start); $day_start_minute = (int)$day_start_hour[1]; $day_end_hour = split(':', $day_end); $day_end_hour = (int)$day_end_hour[0]; $day_end_minute = split(':', $day_end); $day_end_minute = (int)$day_end_hour[1]; $cur_time = mktime( $day_start_hour, $day_start_minute, 0, date('m', $date), date('d', $date),date('Y', $date)); $last_possible_time = mktime( $day_end_hour, $day_end_minute, 0, date('m', $date), date('d', $date),date('Y', $date)); //$last_possible_time -= $length_to_find * 60; while( $cur_time + $length_to_find * 60 <= $last_possible_time ){ $proposed_start = $cur_time; $proposed_end = $cur_time + $length_to_find*60; foreach( $taken_times as $reservation ) { if( ( $proposed_end > $reservation['start_time'] && $proposed_end <= $reservation['start_time'] + $reservation['length']*60 ) || ( $proposed_start >= $reservation['start_time'] && $proposed_end <= $reservation['start_time'] + $reservation['length']*60 ) || ( $proposed_start >= $reservation['start_time'] && $proposed_start < $reservation['start_time'] + $reservation['length']*60 ) || ( $proposed_start <= $reservation['start_time'] && $proposed_end >= $reservation['start_time'] + $reservation['length']*60 ) ){ $cur_time += $step * 60; continue 2; } } array_push( $available_times, $cur_time ); $cur_time += $step * 60; } return $available_times; } function replace_email_tags( $subject, $reservation ){ $subject = str_replace('{id}', $reservation['id'], $subject ); $subject = str_replace('{pikkus}', $reservation['length'], $subject ); $subject = str_replace('{protseduuri_id}', $reservation['procedure_id'], $subject ); $subject = str_replace('{nimi}', $reservation['client_name'], $subject ); $subject = str_replace('{telefon}', $reservation['client_telephone'], $subject ); $subject = str_replace('{email}', $reservation['client_email'], $subject ); $subject = str_replace('{loom}', $reservation['animal'], $subject ); $subject = str_replace('{vanus}', $reservation['animal_age'], $subject ); $subject = str_replace('{sugu}', $reservation['animal_sex'], $subject ); $subject = str_replace('{probleem}', $reservation['problem'], $subject ); $subject = str_replace('{protseduur}', $reservation['procedure_name'],$subject ); $start = date( 'd', $reservation['start_time'] ) . '.' . date( 'm', $reservation['start_time'] ) . '.' . date( 'Y', $reservation['start_time'] ) . ' ' . date( 'H', $reservation['start_time'] ) . ':' . date( 'i', $reservation['start_time'] ); $subject = str_replace('{algus}', $start, $subject ); return $subject; } function get_manage_reservations_page(){ if( isset ( $_POST['action'] ) && $_POST['action'] == 'edit_reservation' ){ if( isset( $_POST['id'] ) && $_POST['id'] > 0 && isset( $_POST['procedure'] ) && $_POST['procedure'] > 0 && isset( $_POST['time'] ) && isset( $_POST['name'] ) && isset( $_POST['telephone'] ) && isset( $_POST['email'] ) && isset( $_POST['animal'] ) && isset( $_POST['age'] ) && isset( $_POST['sex'] ) && isset( $_POST['problem'] ) && isset( $_POST['length'] ) ){ $procedure = $this->get_procedure( (int)$_POST['procedure'] ); if( count( $this->get_reservations_between( (int)$_POST['time'], (int)$_POST['time'] + $procedure['length']*60, $_POST['id'] ) ) == 0 ){ /*$this->add_reservation( $_POST['procedure'], $_POST['time'], $_POST['name'], $_POST['telephone'], $_POST['email'], $_POST['animal'], $_POST['age'], $_POST['sex'], $_POST['problem'], $status = 1 );*/ //send email? echo '

Broneering muudetud!

'; }else{ //warn that there is already reservations at that time echo '

Sellel ajavahemikul on juba broneering!

'; } $this->edit_reservation( $_POST['id'], $_POST['procedure'], $_POST['time'], $_POST['length'], $_POST['name'], $_POST['telephone'], $_POST['email'], $_POST['animal'], $_POST['age'], $_POST['sex'], $_POST['problem'] ); }else{ echo '

Kõik vajalikud väljad pole täidetud.

'; } }elseif( isset( $_GET['confirm'] ) && (int)isset( $_GET['confirm'] ) > 0 ){ $this->edit_reservation_status( $_GET['confirm'], 1 ); $reservation = $this->get_reservation( $_GET['confirm'] ); $subject = $this->replace_email_tags( get_option( get_class($this) . "_reservation_confirm_email_subject" ), $reservation ); $body = $this->replace_email_tags( get_option( get_class($this) . "_reservation_confirm_email" ), $reservation ); $headers = 'From: ' . get_option( get_class($this) . "_name_email_from" ) . ' <' . get_option( get_class($this) . "_email_reservation_from" ) . '>' . "\r\n\\"; wp_mail( $reservation['client_email'], $subject, $body, $headers ); echo '

Kinnitus saadetud!

'; }elseif( isset( $_GET['decline'] ) && (int)isset( $_GET['decline'] ) > 0 ){ $this->edit_reservation_status( $_GET['decline'], 2 ); $reservation = $this->get_reservation( $_GET['decline'] ); $subject = $this->replace_email_tags( get_option( get_class($this) . "_reservation_decline_email_subject" ), $reservation ); $body = $this->replace_email_tags( get_option( get_class($this) . "_reservation_decline_email" ), $reservation ); $headers = 'From: ' . get_option( get_class($this) . "_name_email_from" ) . ' <' . get_option( get_class($this) . "_email_reservation_from" ) . '>' . "\r\n\\"; wp_mail( $reservation['client_email'], $subject, $body, $headers ); echo '

Broneering tagasi lükatud ja teade saadetud!

'; }elseif( isset( $_GET['delete'] ) && (int)isset( $_GET['delete'] ) > 0 ){ $this->edit_reservation_status( $_GET['delete'], 3 ); echo '

Broneering kustutatud!

'; } $reservations = $this->get_all_reservations(0); ?>

Broneeringud Lisa uus

Kinnitamata broneeringud

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } ?>
Aeg Pikkus Protseduur Nimi Telefon Email Loom Vanus Sugu Probleem Staatus
' . date( 'd', $reservation['start_time'] ) . '.' . date( 'm', $reservation['start_time'] ) . '.' . date( 'Y', $reservation['start_time'] ) . ' ' . date( 'H', $reservation['start_time'] ) . ':' . date( 'i', $reservation['start_time'] ) . '' . $reservation['length'] . ' min' . $reservation['procedure_name'] . '' . esc_attr( $reservation['client_name'] ) . '' . esc_attr( $reservation['client_telephone'] ) . '' . esc_attr( $reservation['client_email'] ) . '' . esc_attr( $reservation['animal'] ) . '' . esc_attr( $reservation['animal_age'] ) . ''; if( $reservation['animal_sex'] == 1 ){ echo 'Emane'; }else{ echo 'Isane'; } echo '' . esc_attr( $reservation['problem'] ) . ''; if( $reservation['status'] == 0 ){ echo 'Kinnitamata'; }elseif( $reservation['status'] == 1 ){ echo 'Kinnitatud'; }elseif( $reservation['status'] == 2 ){ echo 'Tagasi lükatud'; }elseif( $reservation['status'] == 3 ){ echo 'Tühistatud'; }else{ echo 'Teadmata'; } echo '
Muuda Kinnita Lükka tagasi Kustuta
get_all_reservations(1); ?>

Kinnitatud broneeringud

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } ?>
Aeg Pikkus Protseduur Nimi Telefon Email Loom Vanus Sugu Probleem Staatus
' . date( 'd', $reservation['start_time'] ) . '.' . date( 'm', $reservation['start_time'] ) . '.' . date( 'Y', $reservation['start_time'] ) . ' ' . date( 'H', $reservation['start_time'] ) . ':' . date( 'i', $reservation['start_time'] ) . '' . $reservation['length'] . ' min' . $reservation['procedure_name'] . '' . esc_attr( $reservation['client_name'] ) . '' . esc_attr( $reservation['client_telephone'] ) . '' . esc_attr( $reservation['client_email'] ) . '' . esc_attr( $reservation['animal'] ) . '' . esc_attr( $reservation['animal_age'] ) . ''; if( $reservation['animal_sex'] == 1 ){ echo 'Emane'; }else{ echo 'Isane'; } echo '' . esc_attr( $reservation['problem'] ) . ''; if( $reservation['status'] == 0 ){ echo 'Kinnitamata'; }elseif( $reservation['status'] == 1 ){ echo 'Kinnitatud'; }elseif( $reservation['status'] == 2 ){ echo 'Tagasi lükatud'; }elseif( $reservation['status'] == 3 ){ echo 'Tühistatud'; }else{ echo 'Teadmata'; } echo '
Muuda Kinnita Lükka tagasi Kustuta
get_all_reservations(2); ?>

Tagasi lükatud broneeringud

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } ?>
Aeg Pikkus Protseduur Nimi Telefon Email Loom Vanus Sugu Probleem Staatus
' . date( 'd', $reservation['start_time'] ) . '.' . date( 'm', $reservation['start_time'] ) . '.' . date( 'Y', $reservation['start_time'] ) . ' ' . date( 'H', $reservation['start_time'] ) . ':' . date( 'i', $reservation['start_time'] ) . '' . $reservation['length'] . ' min' . $reservation['procedure_name'] . '' . esc_attr( $reservation['client_name'] ) . '' . esc_attr( $reservation['client_telephone'] ) . '' . esc_attr( $reservation['client_email'] ) . '' . esc_attr( $reservation['animal'] ) . '' . esc_attr( $reservation['animal_age'] ) . ''; if( $reservation['animal_sex'] == 1 ){ echo 'Emane'; }else{ echo 'Isane'; } echo '' . esc_attr( $reservation['problem'] ) . ''; if( $reservation['status'] == 0 ){ echo 'Kinnitamata'; }elseif( $reservation['status'] == 1 ){ echo 'Kinnitatud'; }elseif( $reservation['status'] == 2 ){ echo 'Tagasi lükatud'; }elseif( $reservation['status'] == 3 ){ echo 'Tühistatud'; }else{ echo 'Teadmata'; } echo '
Muuda Kinnita Lükka tagasi Kustuta
0 ){ echo $this->get_edit_reservation_page( $_GET['edit_reservation'] ); } ?>
get_day_reservations($date, $ignore_reservation_id); $day_start = get_option( get_class($this) . '_day_start_time' ); $day_end = get_option( get_class($this) . '_day_end_time' ); $day_start_hour = split(':', $day_start); $day_start_hour = (int)$day_start_hour[0]; $day_start_minute = split(':', $day_start); $day_start_minute = (int)$day_start_hour[1]; $day_end_hour = split(':', $day_end); $day_end_hour = (int)$day_end_hour[0]; $day_end_minute = split(':', $day_end); $day_end_minute = (int)$day_end_hour[1]; $start_time = mktime( $day_start_hour, $day_start_minute, 0, date('m', $date), date('d', $date),date('Y', $date)); $end_time = mktime( $day_end_hour, $day_end_minute, 0, date('m', $date), date('d', $date),date('Y', $date)); $total_available_time = $end_time - $start_time; //in seconds $total_available_time_left = $total_available_time; foreach ($reservations as $reservation) { $total_available_time_left -= $reservation['length']*60; } return ( 1 - (float)$total_available_time_left / (float)$total_available_time ); } function get_month_days_business( $month, $year, $ignore_not_busy = true, $length_to_fit = false, $ignore_reservation_id = false ){ $days = array(); $number_of_days = date('t', mktime(0, 0, 0, $month, 1, $year)); for( $i = 1; $i <= $number_of_days; $i++){ $day = mktime( 0, 0, 0, $month, $i, $year ); if( $length_to_fit == false ){ $busyness = $this->get_day_busyness( $day, $ignore_reservation_id ); if( $busyness >= $this->lowest_busyness_to_report && $ignore_not_busy == true ){ $days[$month][$i] = $busyness; } }else{ $available_times = $this->get_available_times($day, $length_to_fit, $ignore_reservation_id); if( count( $available_times ) == 0 ){ $days[$month][$i] = 1; }elseif( count( $available_times ) == 1 ){ $days[$month][$i] = 0.5; } } } return $days; } function get_reservations_between( $start, $end, $ignore_reservation_id = false ){ global $wpdb; $reservations = array(); $start_time = date('Y-m-d H:i:s', (int)$start); $end_time = date('Y-m-d H:i:s', (int)$end); $table_name = $wpdb->prefix . get_class( $this ) . "_reservations"; $ignore_reservation_id_sql_str = ( $ignore_reservation_id === false )?'': " AND $table_name.id <> " . (int)$ignore_reservation_id; $sql = "SELECT $table_name.id as id, $table_name.start_time as start_time, $table_name.length as length, $table_name.procedure_id as procedure_id, $table_name.client_name as client_name, $table_name.client_telephone as client_telephone, $table_name.client_email as client_email, $table_name.animal as animal, $table_name.animal_age as animal_age, $table_name.animal_sex as animal_sex, $table_name.problem as problem, $table_name.status as status FROM $table_name WHERE ( ( '$end_time' > start_time AND '$end_time' <= start_time + INTERVAL length MINUTE ) OR ( '$start_time' >= start_time AND '$end_time' <= start_time + INTERVAL length MINUTE ) OR ( '$start_time' >= start_time AND '$start_time' < start_time + INTERVAL length MINUTE ) OR ( '$start_time' <= start_time AND '$end_time' >= start_time + INTERVAL length MINUTE ) ) $ignore_reservation_id_sql_str AND $table_name.status != 2 AND $table_name.status != 3"; $rows = $wpdb->get_results( $sql, OBJECT ); foreach ($rows as $row){ $reservation = array(); $reservation['id'] = (int)$row->id; $reservation['start_time'] = strtotime( $row->start_time ); $reservation['length'] = (int)$row->length; $reservation['procedure_id'] = (int)$row->procedure_id; $reservation['client_name'] = $row->client_name; $reservation['client_telephone'] = $row->client_telephone; $reservation['client_email'] = $row->client_email; $reservation['animal'] = $row->animal; $reservation['animal_age'] = $row->animal_age; $reservation['animal_sex'] = $row->animal_sex; $reservation['problem'] = $row->problem; $reservation['status'] = (int)$row->status; array_push($reservations, $reservation); } return $reservations; } function add_reservation( $procedure_id, $time, $name, $telephone, $email, $animal, $age, $sex, $problem, $status = 0 ){ global $wpdb; $procedure = $this->get_procedure((int)$procedure_id); $start_time = date('Y-m-d H:i:s', (int)$time); $name = $wpdb->escape( $name ); $telephone = $wpdb->escape( $telephone ); $email = $wpdb->escape( $email ); $animal = $wpdb->escape( $animal ); $age = $wpdb->escape( $age ); $sex = (int)$sex; $problem = $wpdb->escape( $problem ); $status = (int)$status; $table_name = $wpdb->prefix . get_class( $this ) . "_reservations"; $insert = "INSERT INTO " . $table_name . " (start_time, length, procedure_id, client_name, client_telephone, client_email, animal, animal_age, animal_sex, problem, status ) " . "VALUES ( '" . $start_time . "', " . (int)$procedure['length'] . ", " . $procedure_id . ", '" . $name . "', '" . $telephone . "', '" . $email . "', '" . $animal . "', '" . $age . "', " . $sex . ", '" . $problem . "', " . $status . ")"; $wpdb->query( $insert ); return $wpdb->insert_id; } function ajax_add_reservation(){ $response = array(); if( isset( $_POST['procedure'] ) && $_POST['procedure'] > 0 && isset( $_POST['time'] ) && isset( $_POST['name'] ) && isset( $_POST['telephone'] ) && isset( $_POST['email'] ) && isset( $_POST['animal'] ) && isset( $_POST['age'] ) && isset( $_POST['sex'] ) && isset( $_POST['problem'] ) ){ $reservation_id = $this->add_reservation($_POST['procedure'], $_POST['time'], $_POST['name'], $_POST['telephone'], $_POST['email'], $_POST['animal'], $_POST['age'], $_POST['sex'], $_POST['problem']); $response['code'] = 1; $response['message'] = 'Broneeritud. Kinnitus saadetakse teile emailile.'; $reservation = $this->get_reservation($reservation_id); $subject = "Uus broneering"; $body = $this->replace_email_tags( get_option( get_class($this) . "_new_reservation_email" ), $reservation ); $headers = 'From: ' . get_option( get_class($this) . "_name_email_from" ) . ' <' . get_option( get_class($this) . "_email_reservation_from" ) . '>' . "\r\n\\"; wp_mail( get_option( get_class($this) . "_email_reservations_to" ), $subject, $body, $headers ); }else{ $response['code'] = 0; $response['message'] = 'Kõik vajalikud väljad ei ole täidetud.'; } echo json_encode($response); die(); } function get_add_reservation_page(){ if( isset ( $_POST['action'] ) && $_POST['action'] == 'add_new' ){ if( isset( $_POST['procedure'] ) && $_POST['procedure'] > 0 && isset( $_POST['time'] ) && isset( $_POST['name'] ) && isset( $_POST['telephone'] ) && isset( $_POST['email'] ) && isset( $_POST['animal'] ) && isset( $_POST['age'] ) && isset( $_POST['sex'] ) && isset( $_POST['problem'] )){ $procedure = $this->get_procedure( (int)$_POST['procedure'] ); if( count( $this->get_reservations_between( (int)$_POST['time'], (int)$_POST['time'] + $procedure['length']*60 ) ) == 0 ){ $this->add_reservation( $_POST['procedure'], $_POST['time'], $_POST['name'], $_POST['telephone'], $_POST['email'], $_POST['animal'], $_POST['age'], $_POST['sex'], $_POST['problem'], $status = 1 ); //send email? echo '

Broneering lisatud!

'; }else{ //warn that there is already reservations at that time echo '

Sellel ajavahemikul on juba broneering!

'; } }else{ echo '

Kõik vajalikud väljad pole täidetud.

'; } } $public_procedures = $this->get_all_public_procedures(); ?>

Lisa uus broneering

>
>
>
>
>

get_all_public_procedures(); $reservation = $this->get_reservation($reservation_id); ?>

Muuda broneeringut

onchange="getAvailableTimes(jQuery('#datepicker').val(), jQuery('#datepicker'));updateMonthBusiness();">
>
>
>
>
/>

prefix . get_class( $this ) . "_reservations"; $table_name_procedures = $wpdb->prefix . get_class( $this ) . "_procedures"; $status_sql_str = ( $status === false )?'': " AND $table_name.status = " . (int)$status; $sql = "SELECT $table_name.id as id, $table_name.start_time as start_time, $table_name.length as length, $table_name.procedure_id as procedure_id, $table_name.client_name as client_name, $table_name.client_telephone as client_telephone, $table_name.client_email as client_email, $table_name.animal as animal, $table_name.animal_age as animal_age, $table_name.animal_sex as animal_sex, $table_name.problem as problem, $table_name.status as status, $table_name_procedures.name as procedure_name FROM $table_name, $table_name_procedures WHERE $table_name_procedures.id = $table_name.procedure_id AND $table_name.status != 3 $status_sql_str ORDER BY start_time DESC"; $rows = $wpdb->get_results( $sql, OBJECT ); foreach ($rows as $row){ $reservation = array(); $reservation['id'] = (int)$row->id; $reservation['start_time'] = strtotime( $row->start_time ); $reservation['length'] = (int)$row->length; $reservation['procedure_id'] = (int)$row->procedure_id; $reservation['client_name'] = $row->client_name; $reservation['client_telephone'] = $row->client_telephone; $reservation['client_email'] = $row->client_email; $reservation['animal'] = $row->animal; $reservation['animal_age'] = $row->animal_age; $reservation['animal_sex'] = $row->animal_sex; $reservation['problem'] = $row->problem; $reservation['status'] = (int)$row->status; $reservation['procedure_name'] = $row->procedure_name; array_push($reservations, $reservation); } return $reservations; } function get_reservation( $reservation_id ){ global $wpdb; $reservation_id = (int)$reservation_id; $reservations = array(); $table_name = $wpdb->prefix . get_class( $this ) . "_reservations"; $table_name_procedures = $wpdb->prefix . get_class( $this ) . "_procedures"; $sql = "SELECT $table_name.id as id, $table_name.start_time as start_time, $table_name.length as length, $table_name.procedure_id as procedure_id, $table_name.client_name as client_name, $table_name.client_telephone as client_telephone, $table_name.client_email as client_email, $table_name.animal as animal, $table_name.animal_age as animal_age, $table_name.animal_sex as animal_sex, $table_name.problem as problem, $table_name.status as status, $table_name_procedures.name as procedure_name FROM $table_name, $table_name_procedures WHERE $table_name_procedures.id = $table_name.procedure_id AND $table_name.id = $reservation_id ORDER BY start_time ASC"; if ( $row = $wpdb->get_row( $sql ) ){ $reservation = array(); $reservation['id'] = (int)$row->id; $reservation['start_time'] = strtotime( $row->start_time ); $reservation['length'] = (int)$row->length; $reservation['procedure_id'] = (int)$row->procedure_id; $reservation['client_name'] = $row->client_name; $reservation['client_telephone'] = $row->client_telephone; $reservation['client_email'] = $row->client_email; $reservation['animal'] = $row->animal; $reservation['animal_age'] = $row->animal_age; $reservation['animal_sex'] = $row->animal_sex; $reservation['problem'] = $row->problem; $reservation['status'] = (int)$row->status; $reservation['procedure_name'] = $row->procedure_name; return $reservation; } return false; } function get_manage_procedures_page(){ if( isset ( $_POST['action'] ) && $_POST['action'] == 'save_edit' ){ if( isset( $_POST['id'] ) && isset( $_POST['name'] ) && isset( $_POST['length'] ) && isset( $_POST['public'] ) ){ $this->edit_procedure($_POST['id'], $_POST['name'], $_POST['length'], $_POST['public']); } }else if( isset ( $_POST['action'] ) && $_POST['action'] == 'add_new' ){ if( isset( $_POST['name'] ) && isset( $_POST['length'] ) && isset( $_POST['public'] ) ){ $this->add_procedure($_POST['name'], $_POST['length'], $_POST['public']); } }else if( isset ( $_REQUEST['action'] ) && $_REQUEST['action'] == 'delete' && isset( $_REQUEST['id'] ) ){ $this->delete_procedure($_REQUEST['id']); echo '

Kustutatud

'; } echo '

Protseduuride haldamine

'; echo '
'; echo '
'; echo '
'; $procedures = $this->get_all_procedures(); echo ''; echo ''; foreach ($procedures as $procedure) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
Protseduuri nimi Pikkus Avalikult
nähtav
' . $procedure['name'] . '' . $procedure['length'] . ' min' . (($procedure['public'])?'Jah':'Ei') . 'MuudaKustuta
'; echo '
'; echo '
'; if( isset ( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' && isset( $_REQUEST['id'] ) ){ //edit form $procedure = $this->get_procedure($_REQUEST['id']); ?>

Muuda

Lisa uus

'; echo '
'; } function get_options_page(){ if( isset ( $_POST['action'] ) && $_POST['action'] == 'save_options' ){ $email_to = $_POST['email_to']; update_option( get_class($this) . '_email_reservations_to', $email_to ); $new_reservation_email = $_POST['new_reservation_email']; update_option( get_class($this) . '_new_reservation_email', $new_reservation_email ); $email_from = $_POST['email_from']; update_option( get_class($this) . '_email_reservation_from', $email_from ); $name_email_from = $_POST['name_email_from']; update_option( get_class($this) . '_name_email_from', $name_email_from ); $day_start_time = $_POST['day_start_time']; update_option( get_class($this) . '_day_start_time', $day_start_time ); $day_end_time = $_POST['day_end_time']; update_option( get_class($this) . '_day_end_time', $day_end_time ); $reservation_time_step = $_POST['reservation_time_step']; update_option( get_class($this) . '_reservation_time_step', $reservation_time_step ); $reservation_confirm_email_subject = $_POST['confirm_email_subject']; update_option( get_class($this) . '_reservation_confirm_email_subject', $reservation_confirm_email_subject ); $reservation_confirm_email = $_POST['confirm_email']; update_option( get_class($this) . '_reservation_confirm_email', $reservation_confirm_email ); $reservation_decline_email_subject = $_POST['decline_email_subject']; update_option( get_class($this) . '_reservation_decline_email_subject', $reservation_decline_email_subject ); $reservation_decline_email = $_POST['decline_email']; update_option( get_class($this) . '_reservation_decline_email', $reservation_decline_email ); } ?>

Seaded

Broneeringu korral saada teade aadressile: " maxlength="200">

Sisu:


Broneeringu staatuse muutmise korral saadetakse teade aadressilt: " maxlength="200">

Broneeringu staatuse muutmise korral saadetav teade saadetakse nime alt: " maxlength="200">


Varaseim lubatud broneeringu aeg(TT:MM): " maxlength="5">

Broneeringute lõpu aeg(TT:MM): " maxlength="5">

Broneeringu aja pakkumise samm(minutites): " maxlength="5">


Kinnituskirja pealkiri: " >

Kinnituskirja sisu:


Tühistuskirja pealkiri: " >

Tühistuskirja sisu:

Emaili pealkirja ja sisu võimalikud muutujad: {id}, {algus}, {pikkus}, {protseduuri_id}, {nimi}, {telefon}, {email}, {loom}, {vanus}, {sugu}, {probleem}, {protseduur}

prefix . get_class( $this ) . "_procedures"; $sql = "SELECT $table_name.id as id, $table_name.name as name, $table_name.length as length, $table_name.public as public FROM $table_name WHERE $table_name.deleted = 0 ORDER BY name ASC"; $rows = $wpdb->get_results( $sql, OBJECT ); foreach ($rows as $row){ $procedure = array(); $procedure['id'] = (int)$row->id; $procedure['name'] = $row->name; $procedure['length'] = (int)$row->length; $procedure['public'] = (int)$row->public; array_push($procedures, $procedure); } return $procedures; } function get_all_public_procedures(){ global $wpdb; $procedures = array(); $table_name = $wpdb->prefix . get_class( $this ) . "_procedures"; $sql = "SELECT $table_name.id as id, $table_name.name as name, $table_name.length as length, $table_name.public as public FROM $table_name WHERE $table_name.deleted = 0 AND $table_name.public = 1 ORDER BY name ASC"; $rows = $wpdb->get_results( $sql, OBJECT ); foreach ($rows as $row){ $procedure = array(); $procedure['id'] = (int)$row->id; $procedure['name'] = $row->name; $procedure['length'] = (int)$row->length; $procedure['public'] = (int)$row->public; array_push($procedures, $procedure); } return $procedures; } function get_procedure( $id ){ global $wpdb; $id = (int)$id; $table_name = $wpdb->prefix . get_class( $this ) . "_procedures"; $sql = "SELECT $table_name.id as id, $table_name.name as name, $table_name.length as length, $table_name.public as public FROM $table_name WHERE $table_name.id = $id LIMIT 1"; if ( $row = $wpdb->get_row( $sql ) ){ $procedure = array(); $procedure['id'] = (int)$row->id; $procedure['name'] = $row->name; $procedure['length'] = (int)$row->length; $procedure['public'] = (int)$row->public; return $procedure; } return false; } function add_procedure( $name, $length, $public ){ global $wpdb; $name = $wpdb->escape( $name ); $length = $wpdb->escape( $length ); $public = (int)$public; $table_name = $wpdb->prefix . get_class( $this ) . "_procedures"; $insert = "INSERT INTO " . $table_name . " (name, length, public) " . "VALUES ( '" . $name . "', '" . $length . "', " . $public . ")"; $wpdb->query( $insert ); } function edit_procedure( $id, $name, $length, $public ){ global $wpdb; $id = (int)$id; $name = $wpdb->escape( $name ); $length = $wpdb->escape( $length ); $public = (int)$public; $table_name = $wpdb->prefix . get_class( $this ) . "_procedures"; $update = "UPDATE $table_name SET name='$name', length='$length', public=$public WHERE id=$id"; $wpdb->query( $update ); } function edit_reservation( $reservation_id, $procedure_id, $time, $length, $name, $telephone, $email, $animal, $age, $sex, $problem, $status = 0 ){ global $wpdb; $reservation_id = (int)$reservation_id; $procedure_id = (int)$procedure_id; $start_time = date('Y-m-d H:i:s', (int)$time); $length = (int)$length; $name = $wpdb->escape( $name ); $telephone = $wpdb->escape( $telephone ); $email = $wpdb->escape( $email ); $animal = $wpdb->escape( $animal ); $age = $wpdb->escape( $age ); $sex = (int)$sex; $problem = $wpdb->escape( $problem ); $status = (int)$status; $table_name = $wpdb->prefix . get_class( $this ) . "_reservations"; $update = "UPDATE $table_name SET start_time='$start_time', length=$length, procedure_id=$procedure_id, client_name='$name', client_telephone='$telephone', client_email='$email', animal='$animal', animal_age='$age', animal_sex=$sex, problem='$problem', status='$status' WHERE id=$reservation_id"; $wpdb->query( $update ); } function edit_reservation_status( $reservation_id, $status ){ global $wpdb; $reservation_id = (int)$reservation_id; $status = (int)$status; $table_name = $wpdb->prefix . get_class( $this ) . "_reservations"; $update = "UPDATE $table_name SET status='$status' WHERE id=$reservation_id"; $wpdb->query( $update ); } function delete_procedure( $id ){ /*actually wont delete from database, in fear of breaking old reservations, that may * depend on this procedure. */ global $wpdb; $id = (int)$id; $table_name = $wpdb->prefix . get_class( $this ) . "_procedures"; $update = "UPDATE $table_name SET deleted=1 WHERE id=$id"; $wpdb->query( $update ); } function get_widget_body( $id, $instance ){ $public_procedures = $this->get_all_public_procedures(); ?>

get_field_id('body') .'>'; echo ''; echo $HtkLoomakliinik->get_widget_body( $this->id, $instance); echo '
'; # After the widget echo $after_widget; } function form($instance) { } function update($new_instance, $old_instance) { // processes widget options to be saved return $new_instance; } } //Actions and Filters if ( isset( $HtkLoomakliinik ) ) { global $HtkLoomakliinik; register_activation_hook( __FILE__, array(&$HtkLoomakliinik, 'install') ); register_deactivation_hook( __FILE__, array(&$HtkLoomakliinik, 'uninstall') ); //Actions add_action( 'widgets_init', create_function('', 'return register_widget("HtkLoomakliinik_Widget");') ); add_action( 'admin_menu', array( &$HtkLoomakliinik, 'add_pages' ) ); add_action( 'wp_ajax_get_available_times', array( &$HtkLoomakliinik, 'ajax_get_available_times' ) ); add_action( 'wp_ajax_nopriv_get_available_times', array( &$HtkLoomakliinik, 'ajax_get_available_times' ) ); add_action( 'wp_ajax_get_month_business', array( &$HtkLoomakliinik, 'ajax_get_month_business' ) ); add_action( 'wp_ajax_nopriv_get_month_business', array( &$HtkLoomakliinik, 'ajax_get_month_business' ) ); add_action( 'wp_ajax_nopriv_add_reservation', array( &$HtkLoomakliinik, 'ajax_add_reservation' ) ); add_action( 'wp_ajax_add_reservation', array( &$HtkLoomakliinik, 'ajax_add_reservation' ) ); //incase user is logged in and wants to add from frontend add_action( 'wp_head', array( &$HtkLoomakliinik, 'HtkLoomakliinik_head_additions' ), 0 ); wp_register_style('HtkLoomakliinik', plugin_dir_url( __FILE__ ) . '/css/style.css', array()); wp_register_style( 'jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/smoothness/jquery-ui.css' ); wp_deregister_script( 'jquery-ui' ); wp_register_script( 'jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js'); wp_register_script( 'jquery-ui-datepicker-et', 'http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-et.js'); wp_register_script( 'HtkLoomakliinik', plugin_dir_url( __FILE__ ) . '/js/main.js', array('jquery')); } ?>