RESERVA GUARDADA CORRECTAMENTE
';
} else {
$appointmentSwAlert = 'Ah ocurrido algĂșn error, intĂ©ntelo de nuevo !!
';
}
if ( get_option( 'appointmentsw_changes' ) !== false ) {
update_option( 'appointmentsw_changes', 1 );
} else {
add_option( 'appointmentsw_changes', 1, null, 'no' );
}
return 1;
}
// Process CANCEL request
if ( isset ( $_REQUEST ['book_id'] ) && isset ( $_REQUEST ['user_id'] ) && isset ( $_REQUEST ['action'] ) && $_REQUEST ['action'] == 'appointmentsw-cancel' && wp_verify_nonce ( $_REQUEST ['appointmentsw-nonce'], 'appointmentsw' )) {
$book = AppointmentSw::get_book( intval( trim( $_REQUEST ['book_id'] ) ) );
$result = AppointmentSw::cancelAppointment( intval( trim( $_REQUEST ['book_id'] ) ), intval( trim( $_REQUEST ['user_id'] ) ) );
if ( $result !== null ) {
AppointmentSwNotifications::send( $book, APPOINTMENTSW_STATUS_CANCELED );
AppointmentSwNotifications::sendToAdmin( $book, APPOINTMENTSW_STATUS_CANCELED );
$appointmentSwAlert = '' . __( "Appointment canceled", APPOINTMENTSW_DOMAIN ) . '
';
} else {
$appointmentSwAlert = '' . __( "An error has occured", APPOINTMENTSW_DOMAIN ) . '
';
}
if ( get_option( 'appointmentsw_changes' ) !== false ) {
update_option( 'appointmentsw_changes', 1 );
} else {
add_option( 'appointmentsw_changes', 1, null, 'no' );
}
return 1;
}
// ADMIN
// Process ADD request
if (isset ( $_REQUEST ['slot'] ) && isset ( $_REQUEST ['user_id'] ) && isset ( $_REQUEST ['action'] ) && $_REQUEST ['action'] == 'appointmentsw-add-admin' && wp_verify_nonce ( $_REQUEST ['appointmentsw-nonce'], 'appointmentsw' )) {
$result = AppointmentSw::addAppointmentAdmin( intval( trim( $_REQUEST ['user_id'] ) ), intval( trim( $_REQUEST ['slot'] ) ) );
if ( $result !== null ) {
$book = AppointmentSw::get_book_by_slot( intval( trim( $_REQUEST ['slot'] ) ) );
AppointmentSwNotifications::send( $book, APPOINTMENTSW_STATUS_ACCEPTED );
AppointmentSwNotifications::sendToAdmin( $book, APPOINTMENTSW_STATUS_ACCEPTED );
$appointmentSwAlert = '' . __( "Appointment added", APPOINTMENTSW_DOMAIN ) . '
';
} else {
$appointmentSwAlert = '' . __( "An error has occured", APPOINTMENTSW_DOMAIN ) . '
';
}
if ( get_option( 'appointmentsw_changes' ) !== false ) {
update_option( 'appointmentsw_changes', 0 );
} else {
add_option( 'appointmentsw_changes', 0, null, 'no' );
}
return 1;
}
// Process CANCEL request
if ( isset ( $_REQUEST ['book_id'] ) && isset ( $_REQUEST ['user_id'] ) && isset ( $_REQUEST ['action'] ) && $_REQUEST ['action'] == 'appointmentsw-cancel-admin' && wp_verify_nonce ( $_REQUEST ['appointmentsw-nonce'], 'appointmentsw' )) {
$book = AppointmentSw::get_book( intval( trim( $_REQUEST ['book_id'] ) ) );
$result = AppointmentSw::cancelAppointmentAdmin( intval( trim( $_REQUEST ['book_id'] ) ), intval( trim( $_REQUEST ['user_id'] ) ) );
if ( $result !== null ) {
AppointmentSwNotifications::send( $book, APPOINTMENTSW_STATUS_CANCELED );
AppointmentSwNotifications::sendToAdmin( $book, APPOINTMENTSW_STATUS_CANCELED );
$appointmentSwAlert = '' . __( "Appointment canceled", APPOINTMENTSW_DOMAIN ) . '
';
} else {
$appointmentSwAlert = '' . __( "An error has occured", APPOINTMENTSW_DOMAIN ) . '
';
}
if ( get_option( 'appointmentsw_changes' ) !== false ) {
update_option( 'appointmentsw_changes', 0 );
} else {
add_option( 'appointmentsw_changes', 0, null, 'no' );
}
return 1;
}
// Process SAVE SETTINGS request
if ( isset ( $_REQUEST ['date'] ) && isset ( $_REQUEST ['slot'] ) && isset ( $_REQUEST ['action'] ) && $_REQUEST ['action'] == 'appointmentsw-save-settings' && wp_verify_nonce ( $_REQUEST ['appointmentsw-nonce'], 'appointmentsw' ) ) {
$slots = array();
if ( sizeof( $_REQUEST ['slot'] ) > 0 ) {
foreach ($_REQUEST ['slot'] as $key=>$value ) {
$slots[$value] = intval( trim( $value ) );
}
}
$holidays = AppointmentSw::updateHolidays( stripslashes( wp_filter_nohtml_kses( $_REQUEST ['date'] ) ), $slots );
return 1;
}
// Create new user
if ( isset ( $_REQUEST ['action'] ) && $_REQUEST ['action'] == 'appointmentsw-new-user-admin' && wp_verify_nonce ( $_REQUEST ['appointmentsw-nonce'], 'appointmentsw' )) {
$username = isset( $_REQUEST['name'] )?sanitize_title( str_replace('_','-', sanitize_user( stripslashes( wp_filter_nohtml_kses( $_REQUEST['name'] ) ) ) ) ):"";
if ( $username !== "" ) {
$password = "barberiaivan";
$email = ( isset( $_REQUEST['email'] ) && $_REQUEST['email']!=="" )?sanitize_email( $_REQUEST['email'] ):$username . "@example.com";
$user_id = username_exists( $username );
if ( !$user_id and email_exists($email) == false ) {
$user_id = wp_create_user( $username, $password, $email );
if ( ! is_wp_error( $user_id ) ) {
$appointmentSwAlert = '' . $username . __( "created correctly", APPOINTMENTSW_DOMAIN ) . '
';
} else {
$appointmentSwAlert = '' . __( "An error has occured", APPOINTMENTSW_DOMAIN ) . '
';
}
}
}
return 1;
}
}
public static function wp_enqueue_scripts ( $page ) {
// javascript
wp_register_script('appointmentsw', APPOINTMENTSW_PLUGIN_URL . '/js/scripts.js', array('jquery'),'1.0');
wp_enqueue_script('appointmentsw');
// JS
wp_register_script('asw_bootstrap', APPOINTMENTSW_PLUGIN_URL . '/bootstrap/bootstrap.min.js', array('jquery'));
wp_enqueue_script('asw_bootstrap');
// CSS
wp_register_style('asw_bootstrap', APPOINTMENTSW_PLUGIN_URL . '/bootstrap/bootstrap.min.css');
wp_enqueue_style('asw_bootstrap');
wp_localize_script( 'appointmentsw', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
public static function register_appointmentsw_settings() {
register_setting( 'appointmentsw', 'appointmentsw' );
}
/**
* Load scripts.
*/
public static function appointmentsw_enqueue_scripts() {
wp_register_style( 'appointmentsw-style', APPOINTMENTSW_PLUGIN_URL . 'css/style.css' );
wp_register_style( 'appointmentsw-style-calendar', APPOINTMENTSW_PLUGIN_URL . 'css/style-calendar.css' );
wp_enqueue_style ('appointmentsw-style');
wp_enqueue_style ('appointmentsw-style-calendar');
}
public static function admin_notices() {
if ( !empty( self::$notices ) ) {
foreach ( self::$notices as $notice ) {
echo $notice;
}
}
}
/**
* Adds the admin section.
*/
public static function admin_menu() {
$admin_page = add_menu_page(
__( 'Appointment SW' ),
__( 'Appointment SW' ),
'manage_options',
'appointmentsw',
array( __CLASS__, 'appointmentsw_settings' )
);
}
public static function appointmentsw_settings () {
?>
' . $alert . '';
}
?>
charset ) ) {
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
}
if ( ! empty( $wpdb->collate ) ) {
$charset_collate .= " COLLATE $wpdb->collate";
}
$queries = array();
$appointmentsw_table = $wpdb->prefix . 'appointmentsw_book';
if ( $wpdb->get_var( "SHOW TABLES LIKE '$appointmentsw_table'" ) != $appointmentsw_table ) {
$queries[] = "CREATE TABLE $appointmentsw_table (
book_id BIGINT(20) UNSIGNED NOT NULL auto_increment,
user_id BIGINT(20) UNSIGNED,
duration INT(10) UNSIGNED,
datetime DATETIME NOT NULL UNIQUE,
status VARCHAR(100) NOT NULL,
notified INT(2) DEFAULT 0,
PRIMARY KEY (book_id)
) $charset_collate;";
}
// Holidays table
$appointmentsw_table = $wpdb->prefix . 'appointmentsw_holidays';
if ( $wpdb->get_var( "SHOW TABLES LIKE '$appointmentsw_table'" ) != $appointmentsw_table ) {
$queries[] = "CREATE TABLE $appointmentsw_table (
holiday_id VARCHAR(100) NOT NULL,
date DATE NOT NULL,
timezone INT NOT NULL,
PRIMARY KEY (holiday_id)
) $charset_collate;";
}
if ( !empty( $queries ) ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $queries );
}
}
// Admin styles
public static function appointmentsw_login_enqueue_scripts() {
wp_register_style( 'appointmentsw-style-admin', APPOINTMENTSW_PLUGIN_URL . 'css/style-admin.css', false, '1.0.0' );
wp_enqueue_style( 'appointmentsw-style-admin' );
}
}
AppointmentSw_Plugin::init();