Changeset 1466226
- Timestamp:
- 08/02/2016 02:36:34 PM (10 years ago)
- Location:
- experitus-form
- Files:
-
- 17 added
- 2 deleted
- 8 edited
-
tags/0.2 (deleted)
-
tags/0.3 (deleted)
-
tags/0.4 (added)
-
tags/0.4/experitus-form.php (added)
-
tags/0.4/includes (added)
-
tags/0.4/includes/controllers (added)
-
tags/0.4/includes/controllers/experitus-admin-controller.php (added)
-
tags/0.4/includes/controllers/experitus-base-controller.php (added)
-
tags/0.4/includes/controllers/experitus-form-controller.php (added)
-
tags/0.4/includes/views (added)
-
tags/0.4/includes/views/_notifications.php (added)
-
tags/0.4/includes/views/admin.php (added)
-
tags/0.4/includes/views/form.php (added)
-
tags/0.4/index.php (added)
-
tags/0.4/readme.txt (added)
-
tags/0.4/web (added)
-
tags/0.4/web/experitus-admin.js (added)
-
tags/0.4/web/experitus-form.css (added)
-
tags/0.4/web/experitus-form.js (added)
-
trunk/experitus-form.php (modified) (3 diffs)
-
trunk/includes/controllers/experitus-admin-controller.php (modified) (15 diffs)
-
trunk/includes/controllers/experitus-base-controller.php (modified) (4 diffs)
-
trunk/includes/controllers/experitus-form-controller.php (modified) (10 diffs)
-
trunk/includes/views/form.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/web/experitus-form.css (modified) (2 diffs)
-
trunk/web/experitus-form.js (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
experitus-form/trunk/experitus-form.php
r1448367 r1466226 4 4 Plugin URI: 5 5 Description: This plugins integrates your WP site and Experitus account by installing an orders form 6 Version: 0. 36 Version: 0.4 7 7 Author: Experitus 8 8 */ … … 32 32 add_option( 'experitus_options_check' ); 33 33 add_option( 'experitus_block_dates' ); 34 add_option( 'experitus_countries' ); 34 35 } 35 36 register_activation_hook( __FILE__, 'add_experitus_options' ); … … 47 48 delete_option( 'experitus_options_check' ); 48 49 delete_option( 'experitus_block_dates' ); 50 delete_option( 'experitus_countries' ); 49 51 } 50 52 register_uninstall_hook( __FILE__, 'remove_experitus_options' ); -
experitus-form/trunk/includes/controllers/experitus-admin-controller.php
r1448367 r1466226 145 145 } 146 146 if (count($error_messages) == 0) { 147 $server_response = $this->make_api_request('get-request-attributes', 'GET', $input['company_alias'], array('api_key' => $input['api_key']), array('sslverify' => true) ); 147 $server_response = $this->make_api_request( 'request/get-form-data', 'GET', $input['company_alias'], array('api_key' => $input['api_key']), array('sslverify' => true) ); 148 148 149 if (is_wp_error($server_response)) { 149 $server_response = $this->make_api_request( 'get-request-attributes', 'GET', $input['company_alias'], array('api_key' => $input['api_key']), array('sslverify' => false) );150 $server_response = $this->make_api_request( 'request/get-form-data', 'GET', $input['company_alias'], array('api_key' => $input['api_key']), array('sslverify' => false) ); 150 151 if (is_wp_error($server_response)) { 151 152 $error_messages[] = $server_response->get_error_message(); … … 183 184 'error' 184 185 ); 185 return $this->options[' experitus_connection_data'];186 return $this->options['connection_data']; 186 187 } 187 188 return $input; … … 199 200 update_option( 'experitus_payments_data', $response['payments_data'] ); 200 201 update_option( 'experitus_block_dates', $response['block_dates'] ); 202 update_option( 'experitus_countries', $response['countries'] ); 201 203 update_option( 'experitus_options_check', ['outdated' => false, 'time' => time()] ); 202 204 } … … 211 213 return array( 212 214 'enable_captcha' => 0, 213 'site_key' => $this->options[' experitus_captcha_data']['site_key'],214 'secret_key' => $this->options[' experitus_captcha_data']['secret_key']215 'site_key' => $this->options['captcha_data']['site_key'], 216 'secret_key' => $this->options['captcha_data']['secret_key'] 215 217 ); 216 218 } … … 241 243 'error' 242 244 ); 243 return $this->options[' experitus_captcha_data'];245 return $this->options['captcha_data']; 244 246 } 245 247 } … … 273 275 printf( 274 276 '<input type="text" id="experitus_company_alias" name="experitus_connection_data[company_alias]" value="%s" />', 275 isset( $this->options[' experitus_connection_data']['company_alias'] ) ? esc_attr( $this->options['experitus_connection_data']['company_alias']) : ''277 isset( $this->options['connection_data']['company_alias'] ) ? esc_attr( $this->options['connection_data']['company_alias']) : '' 276 278 ); 277 279 } … … 283 285 printf( 284 286 '<input type="text" id="experitus_api_key" name="experitus_connection_data[api_key]" value="%s" />', 285 isset( $this->options[' experitus_connection_data']['api_key'] ) ? esc_attr( $this->options['experitus_connection_data']['api_key']) : ''287 isset( $this->options['connection_data']['api_key'] ) ? esc_attr( $this->options['connection_data']['api_key']) : '' 286 288 ); 287 289 } … … 293 295 printf( 294 296 '<label for="experitus_enable_captcha"><input type="checkbox" id="experitus_enable_captcha" name="experitus_captcha_data[enable_captcha]" value="1" %s /> ' . __( 'Enable Google reCAPTCHA validation.' ) . '</label>', 295 isset( $this->options[' experitus_captcha_data']['enable_captcha'] ) && $this->options['experitus_captcha_data']['enable_captcha'] ? 'checked="checked"' : ''297 isset( $this->options['captcha_data']['enable_captcha'] ) && $this->options['captcha_data']['enable_captcha'] ? 'checked="checked"' : '' 296 298 ); 297 299 } … … 303 305 printf( 304 306 '<input type="text" id="experitus_site_key" class="experitus_captcha_credentials" name="experitus_captcha_data[site_key]" value="%s" />', 305 isset( $this->options[' experitus_captcha_data']['site_key'] ) ? esc_attr( $this->options['experitus_captcha_data']['site_key']) : ''307 isset( $this->options['captcha_data']['site_key'] ) ? esc_attr( $this->options['captcha_data']['site_key']) : '' 306 308 ); 307 309 } … … 313 315 printf( 314 316 '<input type="text" id="experitus_secret_key" class="experitus_captcha_credentials" name="experitus_captcha_data[secret_key]" value="%s" />', 315 isset( $this->options[' experitus_captcha_data']['secret_key'] ) ? esc_attr( $this->options['experitus_captcha_data']['secret_key']) : ''317 isset( $this->options['captcha_data']['secret_key'] ) ? esc_attr( $this->options['captcha_data']['secret_key']) : '' 316 318 ); 317 319 } … … 321 323 */ 322 324 private function reload_form_attributes() { 323 if ( !$this->options[' experitus_connection_data'] ) {325 if ( !$this->options['connection_data'] ) { 324 326 $this->add_notification( 'error', __( 'Please connect to your Experitus account first!' ) ); 325 327 return false; 326 328 } 327 $server_response = $this->make_api_request( ' get-request-attributes' );329 $server_response = $this->make_api_request( 'request/get-form-data' ); 328 330 if (is_wp_error($server_response)) { 329 331 $this->add_notification( 'error', $server_response->get_error_message() ); … … 348 350 */ 349 351 private function if_options_outdated() { 350 if ( !$this->options[' experitus_connection_data'] || !$this->options['experitus_request_attributes'] )351 return false; 352 if ( isset( $this->options[' experitus_options_check']['outdated'] ) && $this->options['experitus_options_check']['outdated'] == true )352 if ( !$this->options['connection_data'] || !$this->options['request_attributes'] ) 353 return false; 354 if ( isset( $this->options['options_check']['outdated'] ) && $this->options['options_check']['outdated'] == true ) 353 355 return true; 354 if ( isset( $this->options[' experitus_options_check']['time'] ) && date( 'Ymd' ) == date( 'Ymd', $this->options['experitus_options_check']['time'] ) )355 return false; 356 $server_response = $this->make_api_request( ' get-request-attributes' );356 if ( isset( $this->options['options_check']['time'] ) && date( 'Ymd' ) == date( 'Ymd', $this->options['options_check']['time'] ) ) 357 return false; 358 $server_response = $this->make_api_request( 'request/get-form-data' ); 357 359 $response = json_decode($server_response['body'], true); 358 360 if ($response['result'] != 'success') { … … 361 363 } 362 364 $result = false; 363 if ( $this->options[' experitus_request_attributes'] != $response['attributes'] )365 if ( $this->options['request_attributes'] != $response['attributes'] ) 364 366 $result = true; 365 if ( $this->options[' experitus_request_items'] != $response['items'] )367 if ( $this->options['request_items'] != $response['items'] ) 366 368 $result = true; 367 if ( $this->options[' experitus_payments_data'] != $response['payments_data'] )369 if ( $this->options['payments_data'] != $response['payments_data'] ) 368 370 $result = true; 369 if ($this->options[' experitus_block_dates'] != $response['block_dates'] )371 if ($this->options['block_dates'] != $response['block_dates'] ) 370 372 $result = true; 371 373 update_option( 'experitus_options_check', ['outdated' => $result, 'time' => time()] ); … … 394 396 $this->current_tab = $_GET[ 'tab' ]; 395 397 } 396 elseif (!$this->options[' experitus_connection_data']) {398 elseif (!$this->options['connection_data']) { 397 399 $this->current_tab = 'experitus_credentials'; 398 400 } … … 402 404 403 405 //check ssl for paid 404 if ( isset( $this->options[' experitus_request_attributes']['paid'] ) && $this->options['experitus_request_attributes']['paid'] && !is_ssl()) {406 if ( isset( $this->options['request_attributes']['paid'] ) && $this->options['request_attributes']['paid'] && !is_ssl()) { 405 407 $this->add_notification( 'warning', __( 'Payments cannot be done in your booking form because of not secure connection. Please enable https protocol.' ) ); 406 408 } -
experitus-form/trunk/includes/controllers/experitus-base-controller.php
r1448367 r1466226 28 28 29 29 protected function populateOptions() { 30 $this->options['experitus_request_attributes'] = get_option('experitus_request_attributes'); 31 $this->options['experitus_connection_data'] = get_option( 'experitus_connection_data' ); 32 $this->options['experitus_request_items'] = get_option( 'experitus_request_items' ); 33 $this->options['experitus_captcha_data'] = get_option( 'experitus_captcha_data' ); 34 $this->options['experitus_ssl_verifypeer'] = get_option( 'experitus_ssl_verifypeer' ); 35 $this->options['experitus_payments_data'] = get_option( 'experitus_payments_data' ); 36 $this->options['experitus_options_check'] = get_option( 'experitus_options_check' ); 37 $this->options['experitus_block_dates'] = get_option( 'experitus_block_dates' ); 30 $this->options['request_attributes'] = get_option('experitus_request_attributes'); 31 $this->options['connection_data'] = get_option( 'experitus_connection_data' ); 32 $this->options['request_items'] = get_option( 'experitus_request_items' ); 33 $this->options['captcha_data'] = get_option( 'experitus_captcha_data' ); 34 $this->options['ssl_verifypeer'] = get_option( 'experitus_ssl_verifypeer' ); 35 $this->options['payments_data'] = get_option( 'experitus_payments_data' ); 36 $this->options['options_check'] = get_option( 'experitus_options_check' ); 37 $this->options['block_dates'] = get_option( 'experitus_block_dates' ); 38 $this->options['countries'] = get_option( 'experitus_countries' ); 38 39 } 39 40 … … 52 53 protected function get_api_url( $action, $company_alias = null ) { 53 54 if ( !$company_alias ) 54 $company_alias = $this->options[' experitus_connection_data']['company_alias'];55 $company_alias = $this->options['connection_data']['company_alias']; 55 56 return EXPERITUS_URL . 'en/' . $company_alias . '/api/' . $action . '/'; 56 57 } … … 62 63 $api_url = $this->get_api_url( $action, $company_alias ); 63 64 if ( !isset($args['sslverify']) || !$args['sslverify'] ) 64 $args['sslverify'] = (bool) $this->options[' experitus_ssl_verifypeer'];65 $args['sslverify'] = (bool) $this->options['ssl_verifypeer']; 65 66 $args['timeout'] = 10; 66 67 if ( !isset($params['api_key']) || !$params['api_key'] ) 67 $params['api_key'] = $this->options[' experitus_connection_data']['api_key'];68 $params['api_key'] = $this->options['connection_data']['api_key']; 68 69 if (strtoupper($method) == 'GET') { 69 70 $url = $api_url . '?' . http_build_query( $params ); … … 80 81 */ 81 82 public function if_captcha_enabled() { 82 return isset( $this->options[' experitus_captcha_data']['enable_captcha'] ) && $this->options['experitus_captcha_data']['enable_captcha'];83 return isset( $this->options['captcha_data']['enable_captcha'] ) && $this->options['captcha_data']['enable_captcha']; 83 84 } 84 85 -
experitus-form/trunk/includes/controllers/experitus-form-controller.php
r1448367 r1466226 26 26 27 27 //add payments 28 if ( is_ssl() && $this->options[' experitus_request_attributes']['paid'] && $this->options['experitus_payments_data'] && isset( $this->options['experitus_payments_data']['gateway'] ) ) {29 if ( $this->options[' experitus_payments_data']['gateway'] == 'paypal' ) {28 if ( is_ssl() && $this->options['payments_data'] && isset( $this->options['payments_data']['gateway'] ) ) { 29 if ( $this->options['payments_data']['gateway'] == 'paypal' ) { 30 30 $this->payment_method = 'paypal'; 31 31 } 32 elseif ( $this->options[' experitus_payments_data']['gateway'] == 'stripe' && isset( $this->options['experitus_payments_data']['stripe_public_key'] ) ) {32 elseif ( $this->options['payments_data']['gateway'] == 'stripe' && isset( $this->options['payments_data']['stripe_public_key'] ) ) { 33 33 $this->payment_method = 'stripe'; 34 34 } … … 36 36 37 37 //submitted form processing 38 if ( isset( $_POST['Request Form'] ) ) {38 if ( isset( $_POST['Request'] ) && isset( $_POST['RequestItem'] ) ) { 39 39 if ( !wp_verify_nonce( $_POST['experitus_non_ce'], 'experitus_order_request' ) ) { 40 40 wp_nonce_ays ( 'experitus_order_request' ); … … 43 43 $validation_result = $this->validate_form(); 44 44 if ( $validation_result === true ) { 45 $request_data = $this->sanitize_form($_POST['RequestForm']); 45 $request_data = $this->sanitize_form($_POST['Request']); 46 $request_data['items'][0] = $this->sanitize_form($_POST['RequestItem'][0]); 46 47 if ( $this->payment_method == 'stripe' && $_POST['stripe_token'] ) { 47 $request_data[' token'] = $_POST['stripe_token'];48 $request_data['stripe_token'] = $_POST['stripe_token']; 48 49 } 49 50 elseif ( $this->payment_method == 'paypal' ) { … … 51 52 $request_data['referrer'] = urlencode( 'http'.(is_ssl() ? 's' : '').'://'.$_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'] ); 52 53 } 53 $server_response = $this->make_api_request('add-request', 'POST', null, $request_data); 54 55 $server_response = $this->make_api_request('request/add', 'POST', null, $request_data); 54 56 55 57 if ( is_wp_error( $server_response ) ) { … … 79 81 if ( isset( $_GET['referrer_paypal'] ) && isset( $_GET['request_id'] ) ) { 80 82 $this->add_notification( 'success', __( 'Your order was successfully submited! We will contact you as soon as possible.' ) ); 81 $server_response = $this->make_api_request( ' get-request-data', 'GET', null, ['id' => $_GET['request_id']] );83 $server_response = $this->make_api_request( 'request/get', 'GET', null, ['id' => $_GET['request_id']] ); 82 84 $response = json_decode( $server_response['body'], true ); 83 if ( is_array( $response['result'] ) ) { 84 $_POST['RequestForm'] = $response['result']; 85 $_POST['RequestForm']['date'] = date('m/d/Y', $response['result']['time']); 86 $_POST['RequestForm']['time'] = date('H:i', $response['result']['time']); 85 if ( $response['result'] == 'success' ) { 86 $_POST['Request'] = $response['request']; 87 $_POST['RequestItem'][0] = $response['item']; 88 $_POST['RequestItem'][0]['date'] = date('m/d/Y', $response['item']['time']); 89 $_POST['RequestItem'][0]['time'] = date('H:i', $response['item']['time']); 87 90 } 88 91 } … … 90 93 wp_enqueue_script( 'jquery-ui-datepicker' ); 91 94 wp_enqueue_script('jquery-ui-selectmenu'); 92 if ( isset( $this->options['experitus_request_attributes']['number'] ) ) 93 wp_enqueue_script( 'jquery-ui-spinner' ); 95 wp_enqueue_script( 'jquery-ui-spinner' ); 94 96 wp_enqueue_script( 'experitus-form-scripts', plugins_url( 'web/experitus-form.js', EXPERITUS_ROOT_FILE ), array('jquery'), '1.0.0', true ); 95 97 wp_enqueue_script( 'jquery-timepicker', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.8.11/jquery.timepicker.min.js', array('jquery'), '1.0.0', true ); … … 107 109 */ 108 110 private function validate_form() { 109 $data = $_POST['RequestForm'];110 111 if ( $this->if_captcha_enabled() && !$this->validate_captcha() ) 111 112 return false; 113 $request = $_POST['Request']; 114 $item = $_POST['RequestItem']; 112 115 $errors = array(); 113 $attributes = $this->options['experitus_request_attributes'];114 116 foreach ( $this->get_required_attributes() as $required_attribute => $required_label ) { 115 if ( !isset( $data[$required_attribute] ) || !$data[$required_attribute] ) 117 $hasRequired = true; 118 if ( !isset( $request[$required_attribute] ) || !$request[$required_attribute] ) 119 $hasRequired = false; 120 if ( !$hasRequired && isset( $item[$required_attribute] ) && $item[$required_attribute] ) 121 $hasRequired = true; 122 if (!$hasRequired) 116 123 $errors[] = __( $required_label . ' field cannot be empty.' ); 117 124 } 118 if ( isset($data['email']) && $data['email'] && !is_email( $data['email'] ) ) 125 $attributes = $this->get_all_attributes(); 126 if ( isset($request['email']) && $request['email'] && !is_email( $request['email'] ) ) 119 127 $errors[] = __( $attributes['email']['label'] . ' field needs a valid email address.' ); 120 if ( isset($data['number']) && $data['number'] && !is_numeric( $data['number'] ) ) 121 $errors[] = __( $attributes['number']['label'] . ' field needs a numeric value.' ); 122 if ( isset($data['date']) && $data['date'] && !preg_match( '/\d{2}\/\d{2}\/\d{4}/',$data['date'] ) ) 128 if ( isset($request['stay_duration']) && $request['stay_duration'] && !is_numeric( $request['stay_duration'] ) ) 129 $errors[] = __( $attributes['stay_duration']['label'] . ' field needs a numeric value.' ); 130 if ( isset($request['arrival_date']) && $request['arrival_date'] && !preg_match( '/\d{2}\/\d{2}\/\d{4}/',$request['arrival_date'] ) ) 131 $errors[] = __( $attributes['arrival_date']['label'] . ' field needs a valid date in mm/dd/yyyy format.' ); 132 if ( isset($request['phone']) && $request['phone'] && !preg_match( '/([0-9\s()+-]*){5,20}/', $request['phone'] ) ) 133 $errors[] = __( $attributes['phone']['label'] . ' field needs a valid phone number' ); 134 135 if ( isset($item['inventory_id']) && $item['inventory_id'] && !is_numeric( $item['inventory_id'] ) ) 136 $errors[] = __( $attributes['inventory_id']['label'] . ' has to be chosen from a list.' ); 137 if ( isset($item['date']) && $item['date'] && !preg_match( '/\d{2}\/\d{2}\/\d{4}/',$item['date'] ) ) 123 138 $errors[] = __( $attributes['date']['label'] . ' field needs a valid date in mm/dd/yyyy format.' ); 124 if ( isset($ data['time']) && $data['time'] && !preg_match( '/\d{2}:\d{2}/',$data['time'] ) )139 if ( isset($item['time']) && $item['time'] && !preg_match( '/\d{2}:\d{2}/',$item['time'] ) ) 125 140 $errors[] = __( $attributes['time']['label'] . ' field needs a valid time in hh:mm format.' ); 126 if ( isset($data['phone']) && $data['phone'] && !preg_match( '/([0-9\s()+-]*){5,20}/', $data['phone'] ) ) 127 $errors[] = __( $attributes['phone']['label'] . ' field needs a valid phone number' ); 141 if ( isset($item['adults']) && $item['adults'] && !is_numeric( $item['adults'] ) ) 142 $errors[] = __( $attributes['adults']['label'] . ' field needs a numeric value.' ); 143 if ( isset($item['children']) && $item['children'] && !is_numeric( $item['children'] ) ) 144 $errors[] = __( $attributes['children']['label'] . ' field needs a numeric value.' ); 128 145 129 146 if ( count($errors) > 0 ) { … … 145 162 } 146 163 $params = array( 147 'secret' => $this->options[' experitus_captcha_data']['secret_key'],164 'secret' => $this->options['captcha_data']['secret_key'], 148 165 'response' => $_POST['g-recaptcha-response'] 149 166 ); … … 161 178 $sanitized = array(); 162 179 foreach ( $data as $attribute => $value ) { 163 if ( in_array( $attribute, array('total', 'paid') ) ) 164 continue; 165 elseif ( in_array( $attribute, array('email', 'number', 'date', 'time', 'phone') ) ) 180 if ( in_array( $attribute, array('email', 'inventory_id', 'adults', 'children', 'arrival_date', 'stay_duration', 'date', 'time', 'phone') ) ) 166 181 $sanitized[$attribute] = $value; 167 182 else 168 183 $sanitized[$attribute] = sanitize_text_field( $value ); 169 184 } 170 return array('RequestForm' => $sanitized); 185 return $sanitized; 186 } 187 188 189 /** 190 * Returns array of all attributes 191 */ 192 private function get_all_attributes() { 193 $attributes = []; 194 foreach ($this->options['request_attributes']['request'] as $categoryAttributes) { 195 $attributes = array_merge($attributes, $categoryAttributes); 196 } 197 array_merge($attributes, $this->options['request_attributes']['item']); 198 return $attributes; 171 199 } 172 200 … … 176 204 */ 177 205 private function get_required_attributes() { 206 $attributes = $this->get_all_attributes(); 178 207 $required = array(); 179 foreach ($ this->options['experitus_request_attributes']as $attribute => $attribute_data) {208 foreach ($attributes as $attribute => $attribute_data) { 180 209 if ($attribute_data['required']) 181 210 $required[$attribute] = $attribute_data['label']; -
experitus-form/trunk/includes/views/form.php
r1448367 r1466226 1 1 <?php function get_input_value($attribute) { 2 return isset( $_POST['RequestForm'][$attribute] ) ? $_POST['RequestForm'][$attribute] : ''; 2 if ( isset( $_POST['Request'][$attribute] ) ) 3 return $_POST['Request'][$attribute]; 4 if ( isset( $_POST['RequestItem'][0][$attribute] ) ) 5 return $_POST['RequestItem'][0][$attribute]; 6 return ''; 3 7 } ?> 4 8 … … 8 12 9 13 <div style="display: none;" id="expertus-form-data" 10 data-alias=<?= $this->options[' experitus_connection_data']['company_alias']; ?>14 data-alias=<?= $this->options['connection_data']['company_alias']; ?> 11 15 <?php if ( $this->payment_method ): ?> 12 <?= $this->payment_method == 'stripe' ? 'data-stripe-key="'.$this->options['experitus_payments_data']['stripe_public_key'].'"' : ''; ?> 13 data-pay="<?= $this->options['experitus_request_attributes']['paid'] ? 1 : 0 ?>" 14 <?= isset( $this->options['experitus_payments_data']['prices'] ) ? 'data-prices="'.htmlentities( $this->options['experitus_payments_data']['prices'], ENT_QUOTES, "UTF-8" ).'"' : '' ?> 15 <?= isset( $this->options['experitus_payments_data']['price_types'] ) ? 'data-prices-type="'.htmlentities( $this->options['experitus_payments_data']['price_types'], ENT_QUOTES, "UTF-8" ).'"' : '' ?> 16 <?= isset( $this->options['experitus_payments_data']['currencies'] ) ? 'data-currencies="'.htmlentities( $this->options['experitus_payments_data']['currencies'], ENT_QUOTES, "UTF-8" ).'"' : '' ?> 16 data-pay="1" 17 <?= isset( $this->options['payments_data']['payment_type'] ) ? 'data-payment-type="'.$this->options['payments_data']['payment_type'].'"' : '' ?> 18 <?= $this->payment_method == 'stripe' ? 'data-stripe-key="'.$this->options['payments_data']['stripe_public_key'].'"' : ''; ?> 19 <?= isset( $this->options['payments_data']['prices'] ) ? 'data-prices="'.htmlspecialchars( json_encode( $this->options['payments_data']['prices'] ) ).'"' : '' ?> 20 <?= isset( $this->options['payments_data']['price_types'] ) ? 'data-price-types="'.htmlentities( json_encode( $this->options['payments_data']['price_types'] ) ).'"' : '' ?> 21 <?= isset( $this->options['payments_data']['deposits'] ) ? 'data-deposits="'.htmlentities( json_encode( $this->options['payments_data']['deposits'] ) ).'"' : '' ?> 22 <?= isset( $this->options['payments_data']['currency'] ) ? 'data-currency="'.$this->options['payments_data']['currency'].'"' : '' ?> 23 <?php else: ?> 24 data-pay="0" 17 25 <?php endif; ?>></div> 18 26 … … 21 29 <?php wp_nonce_field( 'experitus_order_request', 'experitus_non_ce' ); ?> 22 30 23 <?php foreach( $this->options['experitus_request_attributes'] as $attribute => $data ): ?> 31 <?php foreach( $this->options['request_attributes']['request'] as $category => $categoryAttributes ): ?> 32 <?php if (!$categoryAttributes) continue; ?> 24 33 25 <?php if ( in_array( $attribute, array('total', 'paid') ) ): 26 continue; ?> 27 28 <?php elseif ( $data['hidden'] ): ?> 29 <?php if ( isset( $_GET[$attribute] ) ): ?> 30 <input value="<?php echo $_GET[$attribute]; ?>" type="hidden" id="request_form_<?php echo $attribute; ?>" name="RequestForm[<?php echo $attribute; ?>]" /> 31 <?php endif; ?> 32 33 <?php else: ?> 34 <div class="experitus_request_form_field <?= $data['required'] ? 'is-required' : ''; ?>" id="experitus_request_form_field_<?php echo $attribute; ?>"> 35 <label for="request_form_<?php echo $attribute; ?>"><?php echo $data['label']; ?></label> 34 <div class="attributes_category" id="<?= $category ?>_category"> 35 <h3> 36 <?php switch($category) { 37 case 'customer': 38 echo __( 'Customer' ); 39 break; 40 case 'accommodation': 41 echo __( 'Accommodation' ); 42 break; 43 } ?> 44 </h3> 45 46 <?php foreach ($categoryAttributes as $attribute => $data): ?> 36 47 37 <?php if ( $attribute == 'comments' ): ?> 38 <textarea id="request_form_<?php echo $attribute; ?>" name="RequestForm[<?php echo $attribute; ?>]"><?php echo get_input_value($attribute); ?></textarea> 39 40 <?php elseif ( $attribute == 'inventory_id' ): ?> 41 <select id="request_form_<?php echo $attribute; ?>" name="RequestForm[<?php echo $attribute; ?>]"> 42 <option value=""></option> 43 <?php foreach( $this->options['experitus_request_items'] as $id => $item) { ?> 44 <option value="<?php echo $id; ?>" <?php echo $id == get_input_value($attribute) ? 'selected="selected"' : ''; ?>><?php echo $item; ?></option> 45 <?php } ?> 46 </select> 47 48 <?php elseif ( $attribute == 'date' ): ?> 49 <input value="<?php echo get_input_value($attribute); ?>" type="text" id="request_form_<?php echo $attribute; ?>" name="RequestForm[<?php echo $attribute; ?>]" data-block-dates="<?php echo $this->options['experitus_block_dates'] ? $this->options['experitus_block_dates'] : ''; ?>" /> 50 48 <?php if ( isset( $data['type'] ) && $data['type'] == 'hidden_field' ): ?> 49 <?php if ( isset( $_GET[$attribute] ) ): ?> 50 <input class="request_<?php echo $attribute; ?>" value="<?php echo $_GET[$attribute]; ?>" type="hidden" id="request_<?php echo $attribute; ?>" name="Request[<?php echo $attribute; ?>]" /> 51 <?php endif; ?> 52 51 53 <?php else: ?> 52 <input value="<?php echo get_input_value($attribute); ?>" type="text" id="request_form_<?php echo $attribute; ?>" name="RequestForm[<?php echo $attribute; ?>]" /> 53 54 <div class="experitus_request_field <?= $data['required'] ? 'is-required' : ''; ?>" id="experitus_request_field_<?php echo $attribute; ?>"> 55 <?php if ( !isset( $data['type'] ) || $data['type'] != 'checkbox' ): ?> 56 <label for="request_<?php echo $attribute; ?>"><?php echo $data['label']; ?></label> 57 <?php endif; ?> 58 59 <?php if ( $attribute == 'country' ): ?> 60 <select class="request_<?php echo $attribute; ?>" id="request_<?php echo $attribute; ?>" name="Request[<?php echo $attribute; ?>]"> 61 <option value=""></option> 62 <?php foreach( $this->options['countries'] as $code => $country) { ?> 63 <option value="<?php echo $code; ?>" <?php echo $code == get_input_value($attribute) ? 'selected="selected"' : ''; ?>><?php echo $country; ?></option> 64 <?php } ?> 65 </select> 66 67 <?php elseif ( isset( $data['type'] ) && $data['type'] == 'text_area' ): ?> 68 <textarea class="request_<?php echo $attribute; ?>" id="request_<?php echo $attribute; ?>" name="Request[<?php echo $attribute; ?>]"><?php echo get_input_value($attribute); ?></textarea> 69 70 <?php elseif ( isset( $data['type'] ) && $data['type'] == 'checkbox' ): ?> 71 <input class="request_<?php echo $attribute; ?>" type="checkbox" id="request_<?php echo $attribute; ?>" name="Request[<?php echo $attribute; ?>]" <?php echo get_input_value($attribute) ? 'checked="checked"' : ''; ?> /> 72 <label for="request_<?php echo $attribute; ?>"><?php echo $data['label']; ?></label> 73 74 <?php else: ?> 75 <input class="request_<?php echo $attribute; ?>" value="<?php echo get_input_value($attribute); ?>" type="text" id="request_<?php echo $attribute; ?>" name="Request[<?php echo $attribute; ?>]" /> 76 77 <?php endif; ?> 78 79 </div> 54 80 <?php endif; ?> 55 81 56 </div> 57 <?php endif; ?> 82 <?php endforeach; ?> 83 84 </div> 85 58 86 <?php endforeach; ?> 87 88 <div class="attributes_category" id="<?= $category ?>_category"> 89 <h3><?php echo __( 'Item' ); ?></h3> 90 <?php foreach ( $this->options['request_attributes']['item'] as $attribute => $data ): ?> 91 92 <?php if ( isset( $data['type'] ) && $data['type'] == 'hidden_field' ): ?> 93 <?php if ( isset( $_GET[$attribute] ) ): ?> 94 <input class="request_item_<?php echo $attribute; ?>" value="<?php echo $_GET[$attribute]; ?>" type="hidden" id="request_item_0_<?php echo $attribute; ?>" name="RequestItem[0][<?php echo $attribute; ?>]" /> 95 <?php endif; ?> 96 97 <?php else: ?> 98 <div class="experitus_request_field <?= $data['required'] ? 'is-required' : ''; ?>" id="experitus_request_item_0_field_<?php echo $attribute; ?>"> 99 <?php if ( !isset( $data['type'] ) || $data['type'] != 'checkbox' ): ?> 100 <label for="request_item_0_<?php echo $attribute; ?>"><?php echo $data['label']; ?></label> 101 <?php endif; ?> 102 103 <?php if ( $attribute == 'comments' ): ?> 104 <textarea class="request_item_<?php echo $attribute; ?>" id="request_item_0_<?php echo $attribute; ?>" name="RequestItem[0][<?php echo $attribute; ?>]"><?php echo get_input_value($attribute); ?></textarea> 105 106 <?php elseif ( $attribute == 'inventory_id' ): ?> 107 <select class="request_item_<?php echo $attribute; ?>" id="request_item_0_<?php echo $attribute; ?>" name="RequestItem[0][<?php echo $attribute; ?>]"> 108 <option value=""></option> 109 <?php foreach( $this->options['request_items'] as $id => $item): ?> 110 <option value="<?php echo $id; ?>" <?php echo $id == get_input_value($attribute) ? 'selected="selected"' : ''; ?>><?php echo $item; ?></option> 111 <?php endforeach; ?> 112 </select> 113 114 <?php elseif ( $attribute == 'date' ): ?> 115 <input class="request_item_<?php echo $attribute; ?>" value="<?php echo get_input_value($attribute); ?>" type="text" id="request_item_0_<?php echo $attribute; ?>" name="RequestItem[0][<?php echo $attribute; ?>]" data-block-dates="<?php echo $this->options['experitus_block_dates'] ? $this->options['experitus_block_dates'] : ''; ?>" /> 116 117 <?php elseif ( isset( $data['type'] ) && $data['type'] == 'text_area' ): ?> 118 <textarea class="request_item_<?php echo $attribute; ?>" id="request_item_0_<?php echo $attribute; ?>" name="RequestItem[0][<?php echo $attribute; ?>]"><?php echo get_input_value($attribute); ?></textarea> 119 120 <?php elseif ( isset( $data['type'] ) && $data['type'] == 'checkbox' ): ?> 121 <input class="request_item_<?php echo $attribute; ?>" type="checkbox" id="request_item_0_<?php echo $attribute; ?>" name="RequestItem[0][<?php echo $attribute; ?>]" <?php echo get_input_value($attribute) ? 'checked="checked"' : ''; ?> /> 122 <label for="request_item_0_<?php echo $attribute; ?>"><?php echo $data['label']; ?></label> 123 124 <?php else: ?> 125 <input class="request_item_<?php echo $attribute; ?>" value="<?php echo get_input_value($attribute); ?>" type="text" id="request_item_0_<?php echo $attribute; ?>" name="RequestItem[0][<?php echo $attribute; ?>]" /> 126 127 <?php endif; ?> 128 </div> 129 <?php endif; ?> 130 <?php endforeach; ?> 131 </div> 59 132 60 133 <?php if ( $this->if_captcha_enabled() ): ?> 61 134 <div class="experitus_request_form_field" id="experitus_captcha_container"> 62 <div class="g-recaptcha" data-sitekey="<?php echo $this->options[' experitus_captcha_data']['site_key']; ?>"></div>135 <div class="g-recaptcha" data-sitekey="<?php echo $this->options['captcha_data']['site_key']; ?>"></div> 63 136 </div> 64 137 <?php endif; ?> -
experitus-form/trunk/readme.txt
r1448367 r1466226 4 4 Requires at least: 4.4.2 5 5 Tested up to: 4.4.2 6 Stable tag: 0. 36 Stable tag: 0.4 7 7 License: GPLv2 or later 8 8 … … 65 65 == Changelog == 66 66 67 = 0.4 Aug 02 2016 = 68 * Added new fields 69 * Added field categories 70 * Added deposit payments 71 * Added new types of additional fields 72 67 73 = 0.3 Jul 04 2016 = 68 74 * Added 'block dates' functionality -
experitus-form/trunk/web/experitus-form.css
r1445037 r1466226 1 .experitus_request_f orm_field {1 .experitus_request_field { 2 2 padding: 5px 0; 3 3 } 4 .experitus_request_f orm_field .ui-spinner {4 .experitus_request_field .ui-spinner { 5 5 display: block; 6 6 border-width: 0px; 7 7 width: 100%; 8 8 } 9 .experitus_request_f orm_field .ui-spinner input.ui-spinner-input {9 .experitus_request_field .ui-spinner input.ui-spinner-input { 10 10 margin: 0px; 11 11 } 12 .experitus_request_f orm_field select {12 .experitus_request_field select { 13 13 width: 100%; 14 14 } … … 25 25 border-left: 4px solid #cc3f44; 26 26 } 27 .experitus_request_f orm_field.has-error input,28 .experitus_request_f orm_field.has-error textarea,29 .experitus_request_f orm_field.has-error span.ui-selectmenu-button {27 .experitus_request_field.has-error input, 28 .experitus_request_field.has-error textarea, 29 .experitus_request_field.has-error span.ui-selectmenu-button { 30 30 border: 1px solid #cc3f44; 31 31 } 32 .experitus_request_f orm_field.has-error label {32 .experitus_request_field.has-error label { 33 33 color: 1px solid #cc3f44; 34 34 } 35 #experitus_request_form .attributes_category { 36 margin: 12px 0; 37 } -
experitus-form/trunk/web/experitus-form.js
r1448367 r1466226 1 1 jQuery(document).ready(function() { 2 2 var experitusForm = jQuery("#experitus_request_form"); 3 var experitusFormFields = jQuery('#experitus_request_form input[name^="Request Form["], #experitus_request_form select[name^="RequestForm["], #experitus_request_form textarea[name^="RequestForm["]');3 var experitusFormFields = jQuery('#experitus_request_form input[name^="Request"], #experitus_request_form select[name^="Request"], #experitus_request_form textarea[name^="Request"]'); 4 4 var experitusFormData = jQuery('#expertus-form-data').data(); 5 5 var experitusSubmitButton = jQuery('#experitus_request_form button[type="submit"]'); 6 var stripeHandler = StripeCheckout.configure({ 7 key: experitusFormData.stripeKey, 8 image: 'https://app.experitus.io/images/billing_logo.png', 9 locale: 'auto', 10 token: function(token) { 11 jQuery('.stripe_token').val(token.id); 12 experitusForm.unbind('submit').submit(); 13 } 14 }); 6 15 7 16 var experitusFormFns = { 8 17 checkAvailability: function() { 9 var inventoryId = jQuery(' #request_form_inventory_id').val();10 var date = jQuery(' #request_form_date').val();11 var time = jQuery(' #request_form_time').val();12 var hint = jQuery('#experitus_request_ form_field_inventory_id div.hint-block');18 var inventoryId = jQuery('.request_item_inventory_id').val(); 19 var date = jQuery('.request_item_date').val(); 20 var time = jQuery('.request_item_time').val(); 21 var hint = jQuery('#experitus_request_item_0_field_inventory_id div.hint-block'); 13 22 if (hint.length == 0) { 14 23 hint = jQuery('<div/>', { class: 'hint-block' }); 15 jQuery('#experitus_request_ form_field_inventory_id').append(hint);24 jQuery('#experitus_request_item_0_field_inventory_id').append(hint); 16 25 } 17 26 if (!inventoryId) { … … 38 47 }, 39 48 countPrice: function() { 40 var item = jQuery(' #request_form_inventory_id').val();49 var item = jQuery('.request_item_inventory_id').val(); 41 50 if (!item) { 42 return; 43 } 44 var itemPrice = experitusFormData.prices[item]; 45 if (itemPrice) { 46 var itemPriceType = experitusFormData.pricesType[item]; 47 var itemCurrency = experitusFormData.currencies[item]; 48 if (jQuery('#request_form_number') && jQuery('#request_form_number').val() && !isNaN(jQuery('#request_form_number').val())) { 49 var customersNumber = jQuery('#request_form_number').val(); 50 } else { 51 var customersNumber = 1; 52 } 53 if (!itemPriceType) { 54 experitusSubmitButton.html('Pay ' + itemCurrency['symbol'] + customersNumber * itemPrice); 55 } else { 56 experitusSubmitButton.html('Pay ' + itemCurrency['symbol'] + itemPrice); 57 } 51 return 0; 52 } 53 var price = experitusFormData.prices[item]; 54 if (price) { 55 if (experitusFormData.priceTypes[item] == 'per_person') { 56 price = price * experitusFormFns.countCustomers(); 57 } 58 if (experitusFormData.paymentType == 'deposit' && !isNaN(experitusFormData.deposits[item])) { 59 price = price * experitusFormData.deposits[item] / 100; 60 } 61 return price.toFixed(2) 58 62 } else { 63 return 0; 64 } 65 }, 66 showPrice: function() { 67 var price = experitusFormFns.countPrice(); 68 if (price) { 69 experitusSubmitButton.html('Pay ' + experitusFormData.currency + ' ' + price); 70 } 71 else { 59 72 experitusSubmitButton.html('Submit'); 60 73 } 74 }, 75 countCustomers: function() { 76 var children = parseInt(jQuery('.request_item_children').val()); 77 children = isNaN(children) ? 0 : children; 78 var adults = parseInt(jQuery('.request_item_adults').val()); 79 adults = isNaN(adults) ? 0 : adults; 80 var customers = children + adults; 81 return customers ? customers : 1; 61 82 }, 62 83 validateForm: function() { … … 70 91 }, 71 92 validateField: function(field) { 72 fieldContainer = field.closest('.experitus_request_f orm_field');93 fieldContainer = field.closest('.experitus_request_field'); 73 94 //validate required 74 95 if (fieldContainer.hasClass('is-required') && !field.val()) { … … 77 98 } 78 99 //validate email 79 if (field.is(' [name="RequestForm[email]"]')) {100 if (field.is('.request_email')) { 80 101 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; 81 102 if (!regex.test(field.val())) { … … 85 106 } 86 107 //valiate phone 87 if (field.is(' [name="RequestForm[phone]"]')) {108 if (field.is('.request_phone')) { 88 109 var regex = /^([0-9\s()+-]*){5,20}$/; 89 110 if (!regex.test(field.val())) { … … 92 113 } 93 114 } 94 //validate number 95 if (field.is(' [name="RequestForm[number]"]')) {115 //validate numbers 116 if (field.is('.request_item_adults, .request_item_children, .request_stay_duration')) { 96 117 var regex = /^[0-9]*$/; 97 if (!regex.test(field.val()) || field.val() < 1) { 98 fieldContainer.addClass('has-error'); 99 return false; 118 if (field.val()) { 119 if (!regex.test(field.val())) { 120 fieldContainer.addClass('has-error'); 121 return false; 122 } 123 if (field.is('.request_item_adults, .request_stay_duration') && field.val() < 1) { 124 fieldContainer.addClass('has-error'); 125 return false; 126 } 100 127 } 101 128 } 102 129 //validate date 103 if (field.is('[name="RequestForm[date]"]')) { 104 var regex = /^[0-9]{2}[\/][0-9]{2}[\/][0-9]{4}$/; 105 if (!regex.test(field.val())) { 106 fieldContainer.addClass('has-error'); 107 return false; 130 if (field.is('.request_item_date, .request_arrival_date')) { 131 if (field.val()) { 132 var regex = /^[0-9]{2}[\/][0-9]{2}[\/][0-9]{4}$/; 133 if (!regex.test(field.val())) { 134 fieldContainer.addClass('has-error'); 135 return false; 136 } 108 137 } 109 138 } 110 139 //validate time 111 if (field.is(' [name="RequestForm[time]"]')) {140 if (field.is('.request_item_time')) { 112 141 var regex = /^[0-9]{2}[\:][0-9]{2}$/; 113 142 if (!regex.test(field.val())) { … … 120 149 }, 121 150 pay2Stripe: function() { 122 var item = jQuery('select[name="RequestForm[inventory_id]"]').val(); 123 totalPrice = !experitusFormData.pricesType[item] ? jQuery('input[name="RequestForm[number]"]').val() * experitusFormData.prices[item] : experitusFormData.prices[item]; 124 var handler = StripeCheckout.configure({ 125 key: experitusFormData.stripeKey, 126 image: 'https://app.experitus.io/images/billing_logo.png', 127 locale: 'auto', 128 token: function(token) { 129 jQuery('.stripe_token').val(token.id); 130 experitusForm.unbind('submit').submit(); 131 } 132 }); 133 handler.open({ 151 stripeHandler.open({ 134 152 name: 'Experitus', 135 email: jQuery(' input[name="RequestForm[email]"]').val(),153 email: jQuery('.request_email').val(), 136 154 description: '', 137 currency: experitusFormData.currenc ies[item]['code'],155 currency: experitusFormData.currency, 138 156 panelLabel: 'Pay', 139 amount: totalPrice*100,140 allowRememberMe: !1157 amount: experitusFormFns.countPrice() * 100, 158 allowRememberMe: !1 141 159 }); 142 160 }, … … 159 177 160 178 161 if (jQuery('input[name="RequestForm[date]"]').length > 0) { 162 experitusFormFns.initDatePicker(jQuery('input[name="RequestForm[date]"]')); 163 } 164 if (jQuery('#request_form_time').length > 0) { 165 jQuery('#request_form_time').timepicker({ 179 if (jQuery('.request_item_date').length > 0) { 180 experitusFormFns.initDatePicker(jQuery('.request_item_date')); 181 } 182 if (jQuery('.request_arrival_date').length > 0) { 183 jQuery('.request_arrival_date').datepicker({ 184 dateFormat: 'mm/dd/yy', 185 minDate: 0 186 }); 187 } 188 if (jQuery('.request_item_time').length > 0) { 189 jQuery('.request_item_time').timepicker({ 166 190 timeFormat: 'H:i' 167 191 }); 168 192 } 169 if (jQuery(' #request_form_inventory_id').length > 0) {170 jQuery(' #request_form_inventory_id').selectmenu({193 if (jQuery('.request_item_inventory_id').length > 0) { 194 jQuery('.request_item_inventory_id').selectmenu({ 171 195 change: function() { 172 196 if (experitusFormFns.validateField(jQuery(this))) { 173 197 experitusFormFns.checkAvailability(); 174 198 if (experitusFormData.pay) { 175 experitusFormFns. countPrice();176 } 177 } 178 } 179 }); 180 jQuery(document).on('change', ' #request_form_date, #request_form_time', function() {199 experitusFormFns.showPrice(); 200 } 201 } 202 } 203 }); 204 jQuery(document).on('change', '.request_item_date, .request_item_time', function() { 181 205 if (experitusFormFns.validateField(jQuery(this))) { 182 206 experitusFormFns.checkAvailability(); … … 184 208 }); 185 209 } 186 if (jQuery('#request_form_number').length > 0) { 187 jQuery('#request_form_number').spinner({ 210 if (jQuery('.request_country').length > 0) { 211 jQuery('.request_country').selectmenu(); 212 } 213 if (jQuery('.request_item_adults').length > 0) { 214 jQuery('.request_item_adults').spinner({ 188 215 min: 1, 189 216 numberFormat: "n", 190 217 stop: function() { 191 218 if (experitusFormFns.validateField(jQuery(this))) { 192 experitusFormFns.countPrice(); 193 } 194 } 219 experitusFormFns.showPrice(); 220 } 221 } 222 }); 223 } 224 if (jQuery('.request_item_children').length > 0) { 225 jQuery('.request_item_children').spinner({ 226 min: 0, 227 numberFormat: "n", 228 stop: function() { 229 if (experitusFormFns.validateField(jQuery(this))) { 230 experitusFormFns.showPrice(); 231 } 232 } 233 }); 234 } 235 if (jQuery('.request_stay_duration').length > 0) { 236 jQuery('.request_stay_duration').spinner({ 237 min: 1, 238 numberFormat: "n" 195 239 }); 196 240 } … … 201 245 } 202 246 203 if (jQuery(this).is(' #request_form_inventory_id')) {204 experitusFormFns. countPrice();247 if (jQuery(this).is('.request_item_inventory_id')) { 248 experitusFormFns.showPrice(); 205 249 } 206 250 }); … … 212 256 } 213 257 if (experitusFormData.pay && experitusFormData.stripeKey && !jQuery('.stripe_token').val()) { 214 if (experitusFormData.prices[jQuery(' select[name="RequestForm[inventory_id]"]').val()]) {258 if (experitusFormData.prices[jQuery('.request_item_inventory_id').val()]) { 215 259 experitusFormFns.pay2Stripe(); 216 260 return false;
Note: See TracChangeset
for help on using the changeset viewer.