| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_CF_Datetime' ) ) : |
| 7 |
|
| 8 |
final class WPSC_CF_Datetime { |
| 9 |
|
| 10 |
/** |
| 11 |
* Slug for this custom field type |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public static $slug = 'cf_datetime'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Set whether this custom field type is of type date |
| 19 |
* |
| 20 |
* @var boolean |
| 21 |
*/ |
| 22 |
public static $is_date = true; |
| 23 |
|
| 24 |
/** |
| 25 |
* Set whether this custom field type has applicable to date range |
| 26 |
* |
| 27 |
* @var boolean |
| 28 |
*/ |
| 29 |
public static $has_date_range = true; |
| 30 |
|
| 31 |
/** |
| 32 |
* Set whether this custom field type has multiple values |
| 33 |
* |
| 34 |
* @var boolean |
| 35 |
*/ |
| 36 |
public static $has_multiple_val = false; |
| 37 |
|
| 38 |
/** |
| 39 |
* Data type for column created in tickets table |
| 40 |
* |
| 41 |
* @var string |
| 42 |
*/ |
| 43 |
public static $data_type = 'DATETIME NULL DEFAULT NULL'; |
| 44 |
|
| 45 |
/** |
| 46 |
* Set whether this custom field type has reference to other class |
| 47 |
* |
| 48 |
* @var boolean |
| 49 |
*/ |
| 50 |
public static $has_ref = true; |
| 51 |
|
| 52 |
/** |
| 53 |
* Reference class for this custom field type so that its value(s) return with object or array of objects automatically. Empty string indicate no reference. |
| 54 |
* |
| 55 |
* @var string |
| 56 |
*/ |
| 57 |
public static $ref_class = 'datetime'; |
| 58 |
|
| 59 |
/** |
| 60 |
* Set whether this custom field field type is system default (no fields can be created from it). |
| 61 |
* |
| 62 |
* @var boolean |
| 63 |
*/ |
| 64 |
public static $is_default = false; |
| 65 |
|
| 66 |
/** |
| 67 |
* Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc. |
| 68 |
* |
| 69 |
* @var boolean |
| 70 |
*/ |
| 71 |
public static $has_extra_info = true; |
| 72 |
|
| 73 |
/** |
| 74 |
* Set whether this custom field type can accept personal info. |
| 75 |
* |
| 76 |
* @var boolean |
| 77 |
*/ |
| 78 |
public static $has_personal_info = true; |
| 79 |
|
| 80 |
/** |
| 81 |
* Set whether fields created from this custom field type is allowed in create ticket form |
| 82 |
* |
| 83 |
* @var boolean |
| 84 |
*/ |
| 85 |
public static $is_ctf = true; |
| 86 |
|
| 87 |
/** |
| 88 |
* Set whether fields created from this custom field type is allowed in ticket list |
| 89 |
* |
| 90 |
* @var boolean |
| 91 |
*/ |
| 92 |
public static $is_list = true; |
| 93 |
|
| 94 |
/** |
| 95 |
* Set whether fields created from this custom field type is allowed in ticket filter |
| 96 |
* |
| 97 |
* @var boolean |
| 98 |
*/ |
| 99 |
public static $is_filter = true; |
| 100 |
|
| 101 |
/** |
| 102 |
* Set whether fields created from this custom field type can be given character limits |
| 103 |
* |
| 104 |
* @var boolean |
| 105 |
*/ |
| 106 |
public static $has_char_limit = false; |
| 107 |
|
| 108 |
/** |
| 109 |
* Set whether fields created from this custom field type has custom options set in options table |
| 110 |
* |
| 111 |
* @var boolean |
| 112 |
*/ |
| 113 |
public static $has_options = false; |
| 114 |
|
| 115 |
/** |
| 116 |
* Set whether fields created from this custom field type can be available for ticket list sorting |
| 117 |
* |
| 118 |
* @var boolean |
| 119 |
*/ |
| 120 |
public static $is_sort = true; |
| 121 |
|
| 122 |
/** |
| 123 |
* Set whether fields created from this custom field type can be auto-filled |
| 124 |
* |
| 125 |
* @var boolean |
| 126 |
*/ |
| 127 |
public static $is_auto_fill = true; |
| 128 |
|
| 129 |
/** |
| 130 |
* Set whether fields created from this custom field type can have placeholder |
| 131 |
* |
| 132 |
* @var boolean |
| 133 |
*/ |
| 134 |
public static $is_placeholder = true; |
| 135 |
|
| 136 |
/** |
| 137 |
* Set whether fields created from this custom field type is applicable for visibility conditions in create ticket form |
| 138 |
* |
| 139 |
* @var boolean |
| 140 |
*/ |
| 141 |
public static $is_visibility_conditions = true; |
| 142 |
|
| 143 |
/** |
| 144 |
* Set whether fields created from this custom field type is applicable for macros |
| 145 |
* |
| 146 |
* @var boolean |
| 147 |
*/ |
| 148 |
public static $has_macro = true; |
| 149 |
|
| 150 |
/** |
| 151 |
* Set whether fields of this custom field type is applicalbe for search on ticket list page. |
| 152 |
* |
| 153 |
* @var boolean |
| 154 |
*/ |
| 155 |
public static $is_search = false; |
| 156 |
|
| 157 |
/** |
| 158 |
* Initialize the class |
| 159 |
* |
| 160 |
* @return void |
| 161 |
*/ |
| 162 |
public static function init() { |
| 163 |
|
| 164 |
// Get object of this class. |
| 165 |
add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) ); |
| 166 |
|
| 167 |
// Set custom field type. |
| 168 |
add_filter( 'wpsc_cf_types', array( __CLASS__, 'add_cf_type' ), 7 ); |
| 169 |
|
| 170 |
// ticket form. |
| 171 |
add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) ); |
| 172 |
add_filter( 'wpsc_create_ticket_data', array( __CLASS__, 'set_create_ticket_data' ), 10, 3 ); |
| 173 |
add_action( 'wpsc_js_clear_value_hidden_fields', array( __CLASS__, 'js_clear_value_hidden_fields' ) ); |
| 174 |
|
| 175 |
// create ticket data for rest api. |
| 176 |
add_filter( 'wpsc_rest_create_ticket', array( __CLASS__, 'set_rest_ticket_data' ), 10, 3 ); |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Load current class to reference classes |
| 181 |
* |
| 182 |
* @param array $classes - Associative array of class names indexed by its slug. |
| 183 |
* @return array |
| 184 |
*/ |
| 185 |
public static function load_ref_class( $classes ) { |
| 186 |
|
| 187 |
$classes[ self::$slug ] = array( |
| 188 |
'class' => __CLASS__, |
| 189 |
'save-key' => 'id', |
| 190 |
); |
| 191 |
return $classes; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Add custom field type to list |
| 196 |
* |
| 197 |
* @param array $cf_types - custom field types array. |
| 198 |
* @return array |
| 199 |
*/ |
| 200 |
public static function add_cf_type( $cf_types ) { |
| 201 |
|
| 202 |
$cf_types[ self::$slug ] = array( |
| 203 |
'label' => esc_attr__( 'Datetime', 'supportcandy' ), |
| 204 |
'class' => __CLASS__, |
| 205 |
); |
| 206 |
return $cf_types; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Print operators for ticket form filter |
| 211 |
* |
| 212 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 213 |
* @param array $filter - Existing filters (if any). |
| 214 |
* @return void |
| 215 |
*/ |
| 216 |
public static function get_operators( $cf, $filter = array() ) { |
| 217 |
?> |
| 218 |
|
| 219 |
<div class="item conditional"> |
| 220 |
<select class="operator" onchange="wpsc_tc_get_operand(this, '<?php echo esc_attr( $cf->slug ); ?>', '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operand' ) ); ?>');"> |
| 221 |
<option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option> |
| 222 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option> |
| 223 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '<' ); ?> value="<"><?php esc_attr_e( 'Less than', 'supportcandy' ); ?></option> |
| 224 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '<=' ); ?> value="<="><?php esc_attr_e( 'Less than or equals', 'supportcandy' ); ?></option> |
| 225 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '>' ); ?> value=">"><?php esc_attr_e( 'Greater than', 'supportcandy' ); ?></option> |
| 226 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '>=' ); ?> value=">="><?php esc_attr_e( 'Greater than or equals', 'supportcandy' ); ?></option> |
| 227 |
<option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'BETWEEN' ); ?> value="BETWEEN"><?php esc_attr_e( 'Between', 'supportcandy' ); ?></option> |
| 228 |
</select> |
| 229 |
</div> |
| 230 |
<?php |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Print operators for ticket form filter |
| 235 |
* |
| 236 |
* @param string $operator - condition operator on which operands should be returned. |
| 237 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 238 |
* @param array $filter - Exising functions (if any). |
| 239 |
* @return void |
| 240 |
*/ |
| 241 |
public static function get_operands( $operator, $cf, $filter = array() ) { |
| 242 |
|
| 243 |
$unique_id = uniqid( 'wpsc_' ); |
| 244 |
$is_between = $operator == 'BETWEEN' ? true : false; |
| 245 |
$operand_val_1 = isset( $filter['operand_val_1'] ) ? $filter['operand_val_1'] : ''; |
| 246 |
$operand_val_2 = isset( $filter['operand_val_2'] ) ? $filter['operand_val_2'] : ''; |
| 247 |
?> |
| 248 |
|
| 249 |
<div class="item conditional operand <?php echo ! $is_between ? 'single' : ''; ?>"> |
| 250 |
<input type="text" class="operand_val_1 <?php echo esc_attr( $unique_id ); ?>" placeholder="<?php echo $is_between ? esc_attr__( 'From date', 'supportcandy' ) : ''; ?>" value="<?php echo esc_attr( $operand_val_1 ); ?>"> |
| 251 |
</div> |
| 252 |
<script> |
| 253 |
jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 254 |
enableTime: true, |
| 255 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 256 |
}); |
| 257 |
</script> |
| 258 |
<?php |
| 259 |
|
| 260 |
if ( $is_between ) : |
| 261 |
?> |
| 262 |
<div class="item conditional operand"> |
| 263 |
<input type="text" class="operand_val_2 <?php echo esc_attr( $unique_id ); ?>" placeholder="<?php esc_attr_e( 'To date', 'supportcandy' ); ?>" value=""> |
| 264 |
</div> |
| 265 |
<script> |
| 266 |
jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').change(function() { |
| 267 |
var fromDate = jQuery(this).val().trim(); |
| 268 |
jQuery('.operand_val_2.<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 269 |
enableTime: true, |
| 270 |
minDate: fromDate, |
| 271 |
defaultDate: fromDate, |
| 272 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 273 |
}); |
| 274 |
}); |
| 275 |
<?php |
| 276 |
if ( $operand_val_2 ) : |
| 277 |
?> |
| 278 |
jQuery('.operand_val_2.<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 279 |
enableTime: true, |
| 280 |
minDate: '<?php echo esc_attr( $operand_val_1 ); ?>', |
| 281 |
defaultDate: '<?php echo esc_attr( $operand_val_2 ); ?>', |
| 282 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 283 |
}); |
| 284 |
<?php |
| 285 |
endif; |
| 286 |
?> |
| 287 |
</script> |
| 288 |
<?php |
| 289 |
endif; |
| 290 |
} |
| 291 |
|
| 292 |
/** |
| 293 |
* Check condition for this type |
| 294 |
* |
| 295 |
* @param array $condition - condition data. |
| 296 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 297 |
* @param mixed $value - value to compare. |
| 298 |
* @return boolean |
| 299 |
*/ |
| 300 |
public static function is_valid( $condition, $cf, $value ) { |
| 301 |
|
| 302 |
$response = false; |
| 303 |
if ( ! $value ) { |
| 304 |
return false; |
| 305 |
} |
| 306 |
$operand_1 = new DateTime( $condition['operand_val_1'] ); |
| 307 |
switch ( $condition['operator'] ) { |
| 308 |
|
| 309 |
case '=': |
| 310 |
$response = $operand_1 == $value ? true : false; |
| 311 |
break; |
| 312 |
|
| 313 |
case '<': |
| 314 |
$response = $operand_1 > $value ? true : false; |
| 315 |
break; |
| 316 |
|
| 317 |
case '>': |
| 318 |
$response = $operand_1 < $value ? true : false; |
| 319 |
break; |
| 320 |
|
| 321 |
case '<=': |
| 322 |
$response = $operand_1 >= $value ? true : false; |
| 323 |
break; |
| 324 |
|
| 325 |
case '>=': |
| 326 |
$response = $operand_1 <= $value ? true : false; |
| 327 |
break; |
| 328 |
|
| 329 |
case 'BETWEEN': |
| 330 |
$operand_2 = new DateTime( $condition['operand_val_2'] ); |
| 331 |
$response = $operand_1 <= $value && $operand_2 >= $value ? true : false; |
| 332 |
break; |
| 333 |
} |
| 334 |
return $response; |
| 335 |
} |
| 336 |
|
| 337 |
/** |
| 338 |
* Parse filter and return sql query to be merged in ticket model query builder |
| 339 |
* |
| 340 |
* @param WPSC_Custom_Field $cf - custom field of this type. |
| 341 |
* @param mixed $compare - comparison operator. |
| 342 |
* @param mixed $val - value to compare. |
| 343 |
* @return string |
| 344 |
*/ |
| 345 |
public static function parse_filter( $cf, $compare, $val ) { |
| 346 |
|
| 347 |
$str = ''; |
| 348 |
|
| 349 |
switch ( $compare ) { |
| 350 |
|
| 351 |
case '=': |
| 352 |
case '<': |
| 353 |
case '>': |
| 354 |
case '<=': |
| 355 |
case '>=': |
| 356 |
$from = WPSC_Functions::get_utc_date_str( $val . ':00' ); |
| 357 |
$str = self::get_sql_slug( $cf ) . $compare . '\'' . esc_sql( $from ) . '\''; |
| 358 |
break; |
| 359 |
|
| 360 |
case 'BETWEEN': |
| 361 |
$from = WPSC_Functions::get_utc_date_str( $val['operand_val_1'] . ':00' ); |
| 362 |
$to = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ':00' ); |
| 363 |
$str = self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\''; |
| 364 |
break; |
| 365 |
|
| 366 |
default: |
| 367 |
$str = '1=1'; |
| 368 |
} |
| 369 |
|
| 370 |
return $str; |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* Return orderby string |
| 375 |
* |
| 376 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 377 |
* @return string |
| 378 |
*/ |
| 379 |
public static function get_orderby_string( $cf ) { |
| 380 |
|
| 381 |
return self::get_sql_slug( $cf ); |
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* Check ticket condition |
| 386 |
* |
| 387 |
* @param array $condition - array with condition data. |
| 388 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 389 |
* @param WPSC_Ticket $ticket - ticket object. |
| 390 |
* @return boolean |
| 391 |
*/ |
| 392 |
public static function is_valid_ticket_condition( $condition, $cf, $ticket ) { |
| 393 |
|
| 394 |
$flag = true; |
| 395 |
$date = $ticket->{$cf->slug}; |
| 396 |
if ( ! is_object( $date ) ) { |
| 397 |
return false; |
| 398 |
} |
| 399 |
|
| 400 |
switch ( $condition['operator'] ) { |
| 401 |
|
| 402 |
case '=': |
| 403 |
$flag = $date->format( 'Y-m-d H:i' ) == $condition['operand_val_1'] ? true : false; |
| 404 |
break; |
| 405 |
|
| 406 |
case '<': |
| 407 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 408 |
$flag = $date < $operand ? true : false; |
| 409 |
break; |
| 410 |
|
| 411 |
case '>': |
| 412 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 413 |
$flag = $date > $operand ? true : false; |
| 414 |
break; |
| 415 |
|
| 416 |
case '<=': |
| 417 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 418 |
$flag = $date <= $operand ? true : false; |
| 419 |
break; |
| 420 |
|
| 421 |
case '>=': |
| 422 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 423 |
$flag = $date >= $operand ? true : false; |
| 424 |
break; |
| 425 |
|
| 426 |
case 'BETWEEN': |
| 427 |
$operand1 = new DateTime( $condition['operand_val_1'] ); |
| 428 |
$operand2 = new DateTime( $condition['operand_val_2'] ); |
| 429 |
$flag = $operand1 <= $date && $operand2 >= $date ? true : false; |
| 430 |
break; |
| 431 |
|
| 432 |
default: |
| 433 |
$flag = true; |
| 434 |
} |
| 435 |
|
| 436 |
return $flag; |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Check ticket condition |
| 441 |
* |
| 442 |
* @param array $condition - array with condition data. |
| 443 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 444 |
* @param WPSC_Ticket $customer - customer object. |
| 445 |
* @return boolean |
| 446 |
*/ |
| 447 |
public static function is_valid_customer_condition( $condition, $cf, $customer ) { |
| 448 |
|
| 449 |
$flag = true; |
| 450 |
$date = $customer->{$cf->slug}; |
| 451 |
if ( ! is_object( $date ) ) { |
| 452 |
return false; |
| 453 |
} |
| 454 |
|
| 455 |
switch ( $condition['operator'] ) { |
| 456 |
|
| 457 |
case '=': |
| 458 |
$flag = $date->format( 'Y-m-d H:i' ) == $condition['operand_val_1'] ? true : false; |
| 459 |
break; |
| 460 |
|
| 461 |
case '<': |
| 462 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 463 |
$flag = $date < $operand ? true : false; |
| 464 |
break; |
| 465 |
|
| 466 |
case '>': |
| 467 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 468 |
$flag = $date > $operand ? true : false; |
| 469 |
break; |
| 470 |
|
| 471 |
case '<=': |
| 472 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 473 |
$flag = $date <= $operand ? true : false; |
| 474 |
break; |
| 475 |
|
| 476 |
case '>=': |
| 477 |
$operand = new DateTime( $condition['operand_val_1'] ); |
| 478 |
$flag = $date >= $operand ? true : false; |
| 479 |
break; |
| 480 |
|
| 481 |
case 'BETWEEN': |
| 482 |
$operand1 = new DateTime( $condition['operand_val_1'] ); |
| 483 |
$operand2 = new DateTime( $condition['operand_val_2'] ); |
| 484 |
$flag = $operand1 <= $date && $operand2 >= $date ? true : false; |
| 485 |
break; |
| 486 |
|
| 487 |
default: |
| 488 |
$flag = true; |
| 489 |
} |
| 490 |
|
| 491 |
return $flag; |
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* Print ticket form field |
| 496 |
* |
| 497 |
* @param WPSC_Custom_Field $cf - Custom field object. |
| 498 |
* @param array $tff - Array of ticket form field settings for this field. |
| 499 |
* @return string |
| 500 |
*/ |
| 501 |
public static function print_tff( $cf, $tff ) { |
| 502 |
|
| 503 |
$unique_id = uniqid( 'wpsc_' ); |
| 504 |
$val = ''; |
| 505 |
if ( $cf->field == 'ticket' ) { |
| 506 |
$val = $cf->is_auto_fill && $cf->default_value ? $cf->default_value[0] : ''; |
| 507 |
$val = $val ? new DateTime( $val ) : ''; |
| 508 |
} else { |
| 509 |
$current_user = WPSC_Current_User::$current_user; |
| 510 |
$val = $current_user->is_customer && $current_user->customer->{$cf->slug} ? $current_user->customer->{$cf->slug} : ''; |
| 511 |
} |
| 512 |
|
| 513 |
ob_start(); |
| 514 |
?> |
| 515 |
<div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>" data-slug="<?php echo esc_attr( $cf->slug ); ?>"> |
| 516 |
<div class="wpsc-tff-label"> |
| 517 |
<span class="name"><?php echo esc_attr( $cf->name ); ?></span> |
| 518 |
<?php |
| 519 |
if ( $tff['is-required'] ) { |
| 520 |
?> |
| 521 |
<span class="required-indicator">*</span> |
| 522 |
<?php |
| 523 |
} |
| 524 |
?> |
| 525 |
</div> |
| 526 |
<span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span> |
| 527 |
<div class="wpsc-input-close-group"> |
| 528 |
<input |
| 529 |
id="<?php echo esc_attr( $unique_id ); ?>" |
| 530 |
type="text" |
| 531 |
name="<?php echo esc_attr( $cf->slug ); ?>" |
| 532 |
placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>" |
| 533 |
onchange="wpsc_check_tff_visibility()" |
| 534 |
value="<?php echo $val && is_object( $val ) ? esc_attr( $val->format( 'Y-m-d H:i' ) ) : ''; ?>" |
| 535 |
autocomplete="off"/> |
| 536 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 537 |
</div> |
| 538 |
<script> |
| 539 |
jQuery('#<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 540 |
<?php echo $cf->date_range == 'future' ? 'minDate: new Date(),' : ''; ?> |
| 541 |
<?php echo $cf->date_range == 'past' ? 'maxDate: new Date(),' : ''; ?> |
| 542 |
enableTime: true, |
| 543 |
disableMobile: true, |
| 544 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 545 |
<?php echo $cf->date_range == 'range' ? "minDate:'" . esc_attr( $cf->start_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->start_range->format( 'H:i' ) ) . "', maxDate:'" . esc_attr( $cf->end_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->end_range->format( 'H:i' ) ) . "'" : ''; ?> |
| 546 |
}); |
| 547 |
</script> |
| 548 |
</div> |
| 549 |
<?php |
| 550 |
return ob_get_clean(); |
| 551 |
} |
| 552 |
|
| 553 |
/** |
| 554 |
* Validate this type field in create ticket |
| 555 |
* |
| 556 |
* @return void |
| 557 |
*/ |
| 558 |
public static function js_validate_ticket_form() { |
| 559 |
?> |
| 560 |
|
| 561 |
case '<?php echo esc_attr( self::$slug ); ?>': |
| 562 |
var val = customField.find('input').first().val().trim(); |
| 563 |
if (customField.hasClass('required') && !val) { |
| 564 |
isValid = false; |
| 565 |
alert(supportcandy.translations.req_fields_missing); |
| 566 |
} |
| 567 |
break; |
| 568 |
<?php |
| 569 |
echo PHP_EOL; |
| 570 |
} |
| 571 |
|
| 572 |
/** |
| 573 |
* Return custom field value in $_POST |
| 574 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 575 |
* |
| 576 |
* @param string $slug - Custom field slug. |
| 577 |
* @param mixed $cf - Custom field object or false. |
| 578 |
* @return mixed |
| 579 |
*/ |
| 580 |
public static function get_tff_value( $slug, $cf = false ) { |
| 581 |
|
| 582 |
$date = isset( $_POST[ $slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $slug ] ) ) : ''; // phpcs:ignore |
| 583 |
$date = $date && preg_match( '/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/', $date ) ? $date . ':00' : ''; |
| 584 |
return $date ? new DateTime( $date ) : false; |
| 585 |
} |
| 586 |
|
| 587 |
/** |
| 588 |
* Return default value for custom field of this type |
| 589 |
* |
| 590 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 591 |
* @return mixed |
| 592 |
*/ |
| 593 |
public static function get_default_value( $cf ) { |
| 594 |
|
| 595 |
return $cf->default_value ? $cf->default_value[0] . ':00' : ''; |
| 596 |
} |
| 597 |
|
| 598 |
/** |
| 599 |
* Check and return custom field value for new ticket to be created. |
| 600 |
* This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields. |
| 601 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 602 |
* |
| 603 |
* @param array $data - Array of values to to stored in ticket in an insert function. |
| 604 |
* @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types. |
| 605 |
* @param boolean $is_my_profile - Whether it or not it is created from my-profile. This function is used by create ticket as well as my-profile. Due to customer fields handling is done same way, this flag gives apportunity to identify where it being called. |
| 606 |
* @return array |
| 607 |
*/ |
| 608 |
public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) { |
| 609 |
|
| 610 |
if ( isset( $custom_fields[ self::$slug ] ) ) { |
| 611 |
foreach ( $custom_fields[ self::$slug ] as $cf ) { |
| 612 |
$value = self::get_tff_value( $cf->slug ); |
| 613 |
if ( $cf->field == 'ticket' ) { |
| 614 |
|
| 615 |
$default_val = self::get_default_value( $cf ); |
| 616 |
$data[ $cf->slug ] = $value ? $value->format( 'Y-m-d H:i:s' ) : $default_val; |
| 617 |
|
| 618 |
} elseif ( $cf->field == 'agentonly' ) { |
| 619 |
|
| 620 |
$data[ $cf->slug ] = self::get_default_value( $cf ); |
| 621 |
|
| 622 |
} elseif ( $cf->field == 'customer' && $data['customer'] != 0 ) { |
| 623 |
|
| 624 |
$tff = get_option( 'wpsc-tff' ); |
| 625 |
if ( ! $is_my_profile && ! isset( $tff[ $cf->slug ] ) ) { |
| 626 |
continue; |
| 627 |
} |
| 628 |
$customer = new WPSC_Customer( $data['customer'] ); |
| 629 |
$prev_val = $customer->{$cf->slug} && is_object( $customer->{$cf->slug} ) ? $customer->{$cf->slug}->format( 'Y-m-d H:i:s' ) : ''; |
| 630 |
if ( $customer->{$cf->slug} != $value ) { |
| 631 |
$customer->{$cf->slug} = $value; |
| 632 |
$customer->save(); |
| 633 |
|
| 634 |
$new_val = $value && is_object( $value ) ? $value->format( 'Y-m-d H:i:s' ) : ''; |
| 635 |
|
| 636 |
// Set log for this change. |
| 637 |
WPSC_Log::insert( |
| 638 |
array( |
| 639 |
'type' => 'customer', |
| 640 |
'ref_id' => $customer->id, |
| 641 |
'modified_by' => WPSC_Current_User::$current_user->customer->id, |
| 642 |
'body' => wp_json_encode( |
| 643 |
array( |
| 644 |
'slug' => $cf->slug, |
| 645 |
'prev' => $prev_val, |
| 646 |
'new' => $new_val, |
| 647 |
) |
| 648 |
), |
| 649 |
'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ), |
| 650 |
) |
| 651 |
); |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
} |
| 656 |
return $data; |
| 657 |
} |
| 658 |
|
| 659 |
/** |
| 660 |
* Set create ticket data for rest api request |
| 661 |
* |
| 662 |
* @param array $data - create ticket data array. |
| 663 |
* @param WP_REST_Request $request - rest request object. |
| 664 |
* @param array $custom_fields - custom field objects indexed by unique custom field types. |
| 665 |
* @return array |
| 666 |
*/ |
| 667 |
public static function set_rest_ticket_data( $data, $request, $custom_fields ) { |
| 668 |
|
| 669 |
$current_user = WPSC_Current_User::$current_user; |
| 670 |
$tff = get_option( 'wpsc-tff' ); |
| 671 |
|
| 672 |
if ( isset( $custom_fields[ self::$slug ] ) ) { |
| 673 |
foreach ( $custom_fields[ self::$slug ] as $cf ) { |
| 674 |
|
| 675 |
if ( |
| 676 |
! in_array( $cf->field, array( 'ticket', 'agentonly', 'customer' ) ) || |
| 677 |
( $cf->field == 'customer' && ! isset( $tff[ $cf->slug ] ) ) |
| 678 |
) { |
| 679 |
continue; |
| 680 |
} |
| 681 |
|
| 682 |
$date = WPSC_Functions::sanitize_datetime( sanitize_text_field( $request->get_param( $cf->slug ) ) ); |
| 683 |
|
| 684 |
if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ) { |
| 685 |
|
| 686 |
$data[ $cf->slug ] = $cf->field == 'ticket' && $date ? $date : self::get_default_value( $cf ); |
| 687 |
|
| 688 |
} else { |
| 689 |
|
| 690 |
$customer = new WPSC_Customer( $data['customer'] ); |
| 691 |
$format = 'Y-m-d H:i:s'; |
| 692 |
$date = $date ? DateTime::createFromFormat( $format, $date ) : ''; |
| 693 |
$existing_val = $customer->{$cf->slug}; |
| 694 |
$existing_val = $existing_val && is_object( $existing_val ) ? $existing_val->format( $format ) : ''; |
| 695 |
|
| 696 |
if ( $date && $date->format( $format ) != $existing_val ) { |
| 697 |
|
| 698 |
$customer->{$cf->slug} = $date; |
| 699 |
$customer->save(); |
| 700 |
|
| 701 |
// Set log for this change. |
| 702 |
WPSC_Log::insert( |
| 703 |
array( |
| 704 |
'type' => 'customer', |
| 705 |
'ref_id' => $customer->id, |
| 706 |
'modified_by' => $current_user->customer->id, |
| 707 |
'body' => wp_json_encode( |
| 708 |
array( |
| 709 |
'slug' => $cf->slug, |
| 710 |
'prev' => $existing_val, |
| 711 |
'new' => $date->format( $format ), |
| 712 |
) |
| 713 |
), |
| 714 |
'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ), |
| 715 |
) |
| 716 |
); |
| 717 |
} |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
return $data; |
| 723 |
} |
| 724 |
|
| 725 |
/** |
| 726 |
* Return slug string to be used in where condition of ticket model for this type of field |
| 727 |
* |
| 728 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 729 |
* @return string |
| 730 |
*/ |
| 731 |
public static function get_sql_slug( $cf ) { |
| 732 |
|
| 733 |
$join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.'; |
| 734 |
return $join_char . $cf->slug; |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* Return val field for meta query of this type of custom field |
| 739 |
* |
| 740 |
* @param array $condition - condition data. |
| 741 |
* @return mixed |
| 742 |
*/ |
| 743 |
public static function get_meta_value( $condition ) { |
| 744 |
|
| 745 |
$operator = $condition['operator']; |
| 746 |
switch ( $operator ) { |
| 747 |
|
| 748 |
case '=': |
| 749 |
case '<': |
| 750 |
case '<=': |
| 751 |
case '>': |
| 752 |
case '>=': |
| 753 |
return $condition['operand_val_1']; |
| 754 |
|
| 755 |
case 'BETWEEN': |
| 756 |
if ( |
| 757 |
! ( isset( $condition['operand_val_1'] ) && preg_match( '/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/', $condition['operand_val_1'] ) ) || |
| 758 |
! ( isset( $condition['operand_val_2'] ) && preg_match( '/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/', $condition['operand_val_2'] ) ) |
| 759 |
) { |
| 760 |
return false; |
| 761 |
} |
| 762 |
|
| 763 |
return array( |
| 764 |
'operand_val_1' => $condition['operand_val_1'], |
| 765 |
'operand_val_2' => $condition['operand_val_2'], |
| 766 |
); |
| 767 |
} |
| 768 |
return false; |
| 769 |
} |
| 770 |
|
| 771 |
/** |
| 772 |
* Print generic input field for this type. |
| 773 |
* |
| 774 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 775 |
* @param DateTime $date - optional. Input field will be printed with given value (if given). |
| 776 |
* @return void |
| 777 |
*/ |
| 778 |
public static function print_cf_input( $cf, $date = '' ) { |
| 779 |
|
| 780 |
if ( $date && ! is_object( $date ) && $date != '0000-00-00 00:00:00' ) { |
| 781 |
$date = new DateTime( $date ); |
| 782 |
} |
| 783 |
|
| 784 |
$unique_id = uniqid( 'wpsc_' ); |
| 785 |
?> |
| 786 |
<div class="wpsc-tff wpsc-sm-12 wpsc-md-12 wpsc-lg-12 wpsc-visible wpsc-xs-12" data-cft="<?php echo esc_attr( self::$slug ); ?>"> |
| 787 |
<div class="wpsc-tff-label"> |
| 788 |
<span class="name"><?php echo esc_attr( $cf->name ); ?></span> |
| 789 |
</div> |
| 790 |
<?php |
| 791 |
$extra_info = stripslashes( $cf->extra_info ); |
| 792 |
if ( $extra_info ) { |
| 793 |
?> |
| 794 |
<span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span> |
| 795 |
<?php |
| 796 |
} |
| 797 |
?> |
| 798 |
<div class="wpsc-input-close-group"> |
| 799 |
<input |
| 800 |
id="<?php echo esc_attr( $unique_id ); ?>" |
| 801 |
type="text" |
| 802 |
name="<?php echo esc_attr( $cf->slug ); ?>" |
| 803 |
placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>" |
| 804 |
maxlength="<?php echo $cf->char_limit ? intval( $cf->char_limit ) : ''; ?>" |
| 805 |
value="<?php echo $date && is_object( $date ) ? esc_attr( $date->format( 'Y-m-d H:i' ) ) : ''; ?>" |
| 806 |
autocomplete="off"/> |
| 807 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 808 |
</div> |
| 809 |
<script> |
| 810 |
jQuery('#<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 811 |
<?php echo $cf->date_range == 'future' ? 'minDate: new Date(),' : ''; ?> |
| 812 |
<?php echo $cf->date_range == 'past' ? 'maxDate: new Date(),' : ''; ?> |
| 813 |
enableTime: true, |
| 814 |
disableMobile: true, |
| 815 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 816 |
<?php echo $cf->date_range == 'range' ? "minDate:'" . esc_attr( $cf->start_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->start_range->format( 'H:i' ) ) . "', maxDate:'" . esc_attr( $cf->end_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->end_range->format( 'H:i' ) ) . "'" : ''; ?> |
| 817 |
}); |
| 818 |
</script> |
| 819 |
</div> |
| 820 |
<?php |
| 821 |
} |
| 822 |
|
| 823 |
/** |
| 824 |
* Get value for generic field from post. |
| 825 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 826 |
* |
| 827 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 828 |
* @return string |
| 829 |
*/ |
| 830 |
public static function get_cf_input_val( $cf ) { |
| 831 |
|
| 832 |
$date = isset( $_POST[ $cf->slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore |
| 833 |
return $date && preg_match( '/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/', $date ) ? $date : ''; |
| 834 |
} |
| 835 |
|
| 836 |
/** |
| 837 |
* Print edit ticket custom field in individual ticket |
| 838 |
* |
| 839 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 840 |
* @param WPSC_Ticket $ticket - ticket object. |
| 841 |
* @return void |
| 842 |
*/ |
| 843 |
public static function print_edit_ticket_cf( $cf, $ticket ) { |
| 844 |
|
| 845 |
$unique_id = uniqid( 'wpsc_' ); |
| 846 |
?> |
| 847 |
<div class="wpsc-tff wpsc-sm-12 wpsc-md-12 wpsc-lg-12 wpsc-visible wpsc-xs-12" data-cft="<?php echo esc_attr( self::$slug ); ?>"> |
| 848 |
<div class="wpsc-tff-label"> |
| 849 |
<span class="name"><?php echo esc_attr( $cf->name ); ?></span> |
| 850 |
</div> |
| 851 |
<?php |
| 852 |
$extra_info = stripslashes( $cf->extra_info ); |
| 853 |
if ( $extra_info ) : |
| 854 |
?> |
| 855 |
<span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span> |
| 856 |
<?php |
| 857 |
endif |
| 858 |
?> |
| 859 |
<div class="wpsc-input-close-group"> |
| 860 |
<input |
| 861 |
id="<?php echo esc_attr( $unique_id ); ?>" |
| 862 |
type="text" |
| 863 |
name="<?php echo esc_attr( $cf->slug ); ?>" |
| 864 |
placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>" |
| 865 |
maxlength="<?php echo $cf->char_limit ? intval( $cf->char_limit ) : ''; ?>" |
| 866 |
value="<?php echo $ticket->{$cf->slug} && is_object( $ticket->{$cf->slug} ) ? esc_attr( $ticket->{$cf->slug}->format( 'Y-m-d H:i' ) ) : ''; ?>" |
| 867 |
autocomplete="off"/> |
| 868 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 869 |
</div> |
| 870 |
<script> |
| 871 |
jQuery('#<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 872 |
<?php echo $cf->date_range == 'future' ? 'minDate: new Date(),' : ''; ?> |
| 873 |
<?php echo $cf->date_range == 'past' ? 'maxDate: new Date(),' : ''; ?> |
| 874 |
enableTime: true, |
| 875 |
disableMobile: true, |
| 876 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 877 |
<?php echo $cf->date_range == 'range' ? "minDate:'" . esc_attr( $cf->start_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->start_range->format( 'H:i' ) ) . "', maxDate:'" . esc_attr( $cf->end_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->end_range->format( 'H:i' ) ) . "'" : ''; ?> |
| 878 |
}); |
| 879 |
</script> |
| 880 |
</div> |
| 881 |
<?php |
| 882 |
} |
| 883 |
|
| 884 |
/** |
| 885 |
* Set edit individual ticket for this custom field type. |
| 886 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 887 |
* |
| 888 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 889 |
* @param WPSC_Ticket $ticket - ticket object. |
| 890 |
* @return WPSC_Ticket |
| 891 |
*/ |
| 892 |
public static function set_edit_ticket_cf( $cf, $ticket ) { |
| 893 |
|
| 894 |
$prev = $ticket->{$cf->slug} && is_object( $ticket->{$cf->slug} ) ? $ticket->{$cf->slug}->format( 'Y-m-d' ) : ''; |
| 895 |
$new = isset( $_POST[ $cf->slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore |
| 896 |
|
| 897 |
// Exit if there is no change. |
| 898 |
if ( $prev == $new ) { |
| 899 |
return $ticket; |
| 900 |
} |
| 901 |
|
| 902 |
// Change value. |
| 903 |
$ticket->{$cf->slug} = $new ? new DateTime( $new ) : ''; |
| 904 |
$ticket->save(); |
| 905 |
|
| 906 |
return $ticket; |
| 907 |
} |
| 908 |
|
| 909 |
/** |
| 910 |
* Modify ticket field value of this custom field type using rest api |
| 911 |
* |
| 912 |
* @param WPSC_Ticket $ticket - ticket object. |
| 913 |
* @param WPSC_Custom_Field $cf - custom field. |
| 914 |
* @param mixed $value - value to be set. |
| 915 |
* @return void |
| 916 |
*/ |
| 917 |
public static function set_rest_edit_ticket_cf( $ticket, $cf, $value ) { |
| 918 |
|
| 919 |
$datetime = WPSC_Functions::sanitize_datetime( sanitize_text_field( $value ) ); |
| 920 |
if ( $ticket->{$cf->slug} != $datetime ) { |
| 921 |
$ticket->{$cf->slug} = $datetime; |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
/** |
| 926 |
* Insert log thread for this custom field type change |
| 927 |
* |
| 928 |
* @param WPSC_Custom_Field $cf - current custom field of this type. |
| 929 |
* @param WPSC_Ticket $prev - ticket object before making any changes. |
| 930 |
* @param WPSC_Ticket $new - ticket object after making changes. |
| 931 |
* @param string $current_date - date string to be stored as create time. |
| 932 |
* @param int $customer_id - current user customer id for blame. |
| 933 |
* @return void |
| 934 |
*/ |
| 935 |
public static function insert_ticket_log( $cf, $prev, $new, $current_date, $customer_id ) { |
| 936 |
|
| 937 |
// Exit if there is no change. |
| 938 |
if ( $prev->{$cf->slug} == $new->{$cf->slug} ) { |
| 939 |
return; |
| 940 |
} |
| 941 |
|
| 942 |
$prev_val = $prev->{$cf->slug} && is_object( $prev->{$cf->slug} ) ? $prev->{$cf->slug}->format( 'Y-m-d H:i:s' ) : ''; |
| 943 |
$new_val = $new->{$cf->slug} && is_object( $new->{$cf->slug} ) ? $new->{$cf->slug}->format( 'Y-m-d H:i:s' ) : ''; |
| 944 |
|
| 945 |
$thread = WPSC_Thread::insert( |
| 946 |
array( |
| 947 |
'ticket' => $prev->id, |
| 948 |
'customer' => $customer_id, |
| 949 |
'type' => 'log', |
| 950 |
'body' => wp_json_encode( |
| 951 |
array( |
| 952 |
'slug' => $cf->slug, |
| 953 |
'prev' => $prev_val, |
| 954 |
'new' => $new_val, |
| 955 |
) |
| 956 |
), |
| 957 |
'date_created' => $current_date, |
| 958 |
'date_updated' => $current_date, |
| 959 |
) |
| 960 |
); |
| 961 |
} |
| 962 |
|
| 963 |
/** |
| 964 |
* Return data for this custom field while creating duplicate ticket |
| 965 |
* |
| 966 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 967 |
* @param WPSC_Ticket $ticket - ticket object. |
| 968 |
* @return mixed |
| 969 |
*/ |
| 970 |
public static function get_duplicate_ticket_data( $cf, $ticket ) { |
| 971 |
|
| 972 |
return $ticket->{$cf->slug} && is_object( $ticket->{$cf->slug} ) ? $ticket->{$cf->slug}->format( 'Y-m-d H:i:s' ) : ''; |
| 973 |
} |
| 974 |
|
| 975 |
/** |
| 976 |
* Print edit field for this type in edit customer info |
| 977 |
* |
| 978 |
* @param WPSC_Custom_field $cf - custom field object. |
| 979 |
* @param WPSC_Customer $customer - customer object. |
| 980 |
* @param array $tff - ticket form field data. |
| 981 |
* @return string |
| 982 |
*/ |
| 983 |
public static function print_edit_customer_info( $cf, $customer, $tff ) { |
| 984 |
|
| 985 |
$unique_id = uniqid( 'wpsc_' ); |
| 986 |
$val = $customer->id && $customer->{$cf->slug} ? $customer->{$cf->slug} : ''; |
| 987 |
|
| 988 |
ob_start(); |
| 989 |
?> |
| 990 |
<div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>"> |
| 991 |
<div class="wpsc-tff-label"> |
| 992 |
<span class="name"><?php echo esc_attr( $cf->name ); ?></span> |
| 993 |
</div> |
| 994 |
<span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span> |
| 995 |
<div class="wpsc-input-close-group"> |
| 996 |
<input |
| 997 |
id="<?php echo esc_attr( $unique_id ); ?>" |
| 998 |
type="text" |
| 999 |
name="<?php echo esc_attr( $cf->slug ); ?>" |
| 1000 |
placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>" |
| 1001 |
value="<?php echo $val && is_object( $val ) ? esc_attr( $val->format( 'Y-m-d H:i' ) ) : ''; ?>" |
| 1002 |
autocomplete="off"/> |
| 1003 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 1004 |
</div> |
| 1005 |
<script> |
| 1006 |
jQuery('#<?php echo esc_attr( $unique_id ); ?>').flatpickr({ |
| 1007 |
<?php echo $cf->date_range == 'future' ? 'minDate: new Date(),' : ''; ?> |
| 1008 |
<?php echo $cf->date_range == 'past' ? 'maxDate: new Date(),' : ''; ?> |
| 1009 |
enableTime: true, |
| 1010 |
disableMobile: true, |
| 1011 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 1012 |
<?php echo $cf->date_range == 'range' ? "minDate:'" . esc_attr( $cf->start_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->start_range->format( 'H:i' ) ) . "', maxDate:'" . esc_attr( $cf->end_range->format( 'Y-m-d' ) ) . ' ' . esc_attr( $cf->end_range->format( 'H:i' ) ) . "'" : ''; ?> |
| 1013 |
}); |
| 1014 |
</script> |
| 1015 |
</div> |
| 1016 |
<?php |
| 1017 |
return ob_get_clean(); |
| 1018 |
} |
| 1019 |
|
| 1020 |
/** |
| 1021 |
* Print add new custom field setting properties |
| 1022 |
* |
| 1023 |
* @param string $field_class - Class name of the field. |
| 1024 |
* @return void |
| 1025 |
*/ |
| 1026 |
public static function get_add_new_custom_field_properties( $field_class ) { |
| 1027 |
|
| 1028 |
if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) : |
| 1029 |
?> |
| 1030 |
<div data-type="textfield" data-required="false" class="wpsc-input-group extra-info"> |
| 1031 |
<div class="label-container"> |
| 1032 |
<label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label> |
| 1033 |
</div> |
| 1034 |
<input name="extra_info" type="text" autocomplete="off" /> |
| 1035 |
</div> |
| 1036 |
<?php |
| 1037 |
endif; |
| 1038 |
|
| 1039 |
if ( in_array( 'default_value', $field_class::$allowed_properties ) ) : |
| 1040 |
?> |
| 1041 |
<div data-type="textfield" data-required="false" class="wpsc-input-group default_value"> |
| 1042 |
<div class="label-container"> |
| 1043 |
<label for=""> |
| 1044 |
<?php esc_attr_e( 'Default value', 'supportcandy' ); ?> |
| 1045 |
</label> |
| 1046 |
</div> |
| 1047 |
<div class="wpsc-input-close-group"> |
| 1048 |
<input type="text" id="wpsc-default-val-datetime" name="default_value" /> |
| 1049 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 1050 |
</div> |
| 1051 |
<script> |
| 1052 |
jQuery("#wpsc-default-val-datetime").flatpickr({ |
| 1053 |
enableTime: true, |
| 1054 |
time_24hr: true, |
| 1055 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>" |
| 1056 |
}); |
| 1057 |
</script> |
| 1058 |
</div> |
| 1059 |
<?php |
| 1060 |
endif; |
| 1061 |
|
| 1062 |
if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) : |
| 1063 |
?> |
| 1064 |
<div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill"> |
| 1065 |
<div class="label-container"> |
| 1066 |
<label for=""> |
| 1067 |
<?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?> |
| 1068 |
</label> |
| 1069 |
</div> |
| 1070 |
<select name="is_auto_fill"> |
| 1071 |
<option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1072 |
<option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1073 |
</select> |
| 1074 |
</div> |
| 1075 |
<?php |
| 1076 |
endif; |
| 1077 |
|
| 1078 |
if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) : |
| 1079 |
?> |
| 1080 |
<div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text"> |
| 1081 |
<div class="label-container"> |
| 1082 |
<label for=""> |
| 1083 |
<?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?> |
| 1084 |
</label> |
| 1085 |
</div> |
| 1086 |
<input type="text" name="placeholder_text" autocomplete="off"> |
| 1087 |
</div> |
| 1088 |
<?php |
| 1089 |
endif; |
| 1090 |
?> |
| 1091 |
|
| 1092 |
<div data-type="single-select" data-required="false" class="wpsc-input-group date_range"> |
| 1093 |
<div class="label-container"> |
| 1094 |
<label for=""><?php esc_attr_e( 'Date range', 'supportcandy' ); ?></label> |
| 1095 |
</div> |
| 1096 |
<select id="wpsc-date-range" name="date_range"> |
| 1097 |
<option value="all"><?php esc_attr_e( 'All', 'supportcandy' ); ?></option> |
| 1098 |
<option value="future"><?php esc_attr_e( 'Future', 'supportcandy' ); ?></option> |
| 1099 |
<option value="past"><?php esc_attr_e( 'Past', 'supportcandy' ); ?></option> |
| 1100 |
<option value="range"><?php esc_attr_e( 'Between', 'supportcandy' ); ?></option> |
| 1101 |
</select> |
| 1102 |
<script> |
| 1103 |
jQuery('#wpsc-date-range').change(function() { |
| 1104 |
if (jQuery(this).val() == 'range') { |
| 1105 |
jQuery('.wpsc-date-range-option').show(); |
| 1106 |
} else { |
| 1107 |
jQuery('.wpsc-date-range-option').hide(); |
| 1108 |
} |
| 1109 |
}); |
| 1110 |
</script> |
| 1111 |
</div> |
| 1112 |
|
| 1113 |
<div data-type="date-select" data-required="false" class="wpsc-input-group wpsc-date-range-option" style="display:none;"> |
| 1114 |
<div class="label-container"> |
| 1115 |
<label for=""><?php esc_attr_e( 'Date in between', 'supportcandy' ); ?></label> |
| 1116 |
</div> |
| 1117 |
<div class="wpsc-date-range"> |
| 1118 |
<div class="wpsc-input-close-group"> |
| 1119 |
<input type="text" id="from-date-range" name="from-date-range" value="" autocomplete="off"/> |
| 1120 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 1121 |
</div> |
| 1122 |
<div style="margin:5px;"></div> |
| 1123 |
<div class="wpsc-input-close-group"> |
| 1124 |
<input type="text" id="to-date-range" name="to-date-range" value="" autocomplete="off"/> |
| 1125 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 1126 |
</div> |
| 1127 |
</div> |
| 1128 |
<script> |
| 1129 |
jQuery('#from-date-range').flatpickr( { |
| 1130 |
enableTime: true, |
| 1131 |
time_24hr: true |
| 1132 |
}); |
| 1133 |
jQuery('#from-date-range').change(function() { |
| 1134 |
var fromDate = jQuery(this).val().trim(); |
| 1135 |
jQuery('#to-date-range').flatpickr( { |
| 1136 |
minDate: fromDate, |
| 1137 |
defaultDate: fromDate, |
| 1138 |
enableTime: true, |
| 1139 |
time_24hr: true |
| 1140 |
}); |
| 1141 |
}); |
| 1142 |
</script> |
| 1143 |
</div> |
| 1144 |
|
| 1145 |
<div data-type="date-format" data-required="false" class="wpsc-input-group date-format"> |
| 1146 |
<div class="label-container"> |
| 1147 |
<label for=""><?php esc_attr_e( 'Date format', 'supportcandy' ); ?></label> |
| 1148 |
</div> |
| 1149 |
<input type="text" name="date_format" autocomplete="off" /> |
| 1150 |
</div> |
| 1151 |
<?php |
| 1152 |
|
| 1153 |
if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) : |
| 1154 |
?> |
| 1155 |
<div data-type="number" data-required="false" class="wpsc-input-group tl_width"> |
| 1156 |
<div class="label-container"> |
| 1157 |
<label for=""> |
| 1158 |
<?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?> |
| 1159 |
</label> |
| 1160 |
</div> |
| 1161 |
<input type="number" name="tl_width" autocomplete="off"> |
| 1162 |
</div> |
| 1163 |
<?php |
| 1164 |
endif; |
| 1165 |
|
| 1166 |
if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) : |
| 1167 |
?> |
| 1168 |
<div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info"> |
| 1169 |
<div class="label-container"> |
| 1170 |
<label for=""> |
| 1171 |
<?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?> |
| 1172 |
</label> |
| 1173 |
</div> |
| 1174 |
<select name="is_personal_info"> |
| 1175 |
<option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1176 |
<option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1177 |
</select> |
| 1178 |
</div> |
| 1179 |
<?php |
| 1180 |
endif; |
| 1181 |
|
| 1182 |
if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) : |
| 1183 |
?> |
| 1184 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile"> |
| 1185 |
<div class="label-container"> |
| 1186 |
<label for=""> |
| 1187 |
<?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?> |
| 1188 |
</label> |
| 1189 |
</div> |
| 1190 |
<select name="allow_my_profile"> |
| 1191 |
<option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1192 |
<option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1193 |
</select> |
| 1194 |
</div> |
| 1195 |
<?php |
| 1196 |
endif; |
| 1197 |
|
| 1198 |
if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) : |
| 1199 |
?> |
| 1200 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form"> |
| 1201 |
<div class="label-container"> |
| 1202 |
<label for=""> |
| 1203 |
<?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?> |
| 1204 |
</label> |
| 1205 |
</div> |
| 1206 |
<select name="allow_ticket_form"> |
| 1207 |
<option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1208 |
<option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1209 |
</select> |
| 1210 |
</div> |
| 1211 |
<?php |
| 1212 |
endif; |
| 1213 |
} |
| 1214 |
|
| 1215 |
/** |
| 1216 |
* Print edit custom field properties |
| 1217 |
* |
| 1218 |
* @param WPSC_Custom_Fields $cf - custom field object. |
| 1219 |
* @param string $field_class - class name of field category. |
| 1220 |
* @return void |
| 1221 |
*/ |
| 1222 |
public static function get_edit_custom_field_properties( $cf, $field_class ) { |
| 1223 |
|
| 1224 |
if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) : |
| 1225 |
?> |
| 1226 |
<div data-type="textfield" data-required="false" class="wpsc-input-group extra-info"> |
| 1227 |
<div class="label-container"> |
| 1228 |
<label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label> |
| 1229 |
</div> |
| 1230 |
<input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" /> |
| 1231 |
</div> |
| 1232 |
<?php |
| 1233 |
endif; |
| 1234 |
|
| 1235 |
if ( in_array( 'default_value', $field_class::$allowed_properties ) ) : |
| 1236 |
$default_val = $cf->default_value ? $cf->default_value[0] : ''; |
| 1237 |
?> |
| 1238 |
<div data-type="textfield" data-required="false" class="wpsc-input-group default_value"> |
| 1239 |
<div class="label-container"> |
| 1240 |
<label for=""> |
| 1241 |
<?php esc_attr_e( 'Default value', 'supportcandy' ); ?> |
| 1242 |
</label> |
| 1243 |
</div> |
| 1244 |
<div class="wpsc-input-close-group"> |
| 1245 |
<input type="text" id="wpsc-default-val-datetime" name="default_value" value="<?php echo esc_attr( $default_val ); ?>" autocomplete="off"> |
| 1246 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 1247 |
</div> |
| 1248 |
<script> |
| 1249 |
jQuery("#wpsc-default-val-datetime").flatpickr({ |
| 1250 |
enableTime: true, |
| 1251 |
time_24hr: true, |
| 1252 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 1253 |
}); |
| 1254 |
</script> |
| 1255 |
</div> |
| 1256 |
<?php |
| 1257 |
endif; |
| 1258 |
|
| 1259 |
if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) : |
| 1260 |
?> |
| 1261 |
<div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill"> |
| 1262 |
<div class="label-container"> |
| 1263 |
<label for=""> |
| 1264 |
<?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?> |
| 1265 |
</label> |
| 1266 |
</div> |
| 1267 |
<select name="is_auto_fill"> |
| 1268 |
<option <?php selected( $cf->is_auto_fill, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1269 |
<option <?php selected( $cf->is_auto_fill, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1270 |
</select> |
| 1271 |
</div> |
| 1272 |
<?php |
| 1273 |
endif; |
| 1274 |
|
| 1275 |
if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) : |
| 1276 |
?> |
| 1277 |
<div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text"> |
| 1278 |
<div class="label-container"> |
| 1279 |
<label for=""> |
| 1280 |
<?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?> |
| 1281 |
</label> |
| 1282 |
</div> |
| 1283 |
<input type="text" name="placeholder_text" value="<?php echo esc_attr( $cf->placeholder_text ); ?>" autocomplete="off"> |
| 1284 |
</div> |
| 1285 |
<?php |
| 1286 |
endif; |
| 1287 |
?> |
| 1288 |
|
| 1289 |
<div data-type="single-select" data-required="false" class="wpsc-input-group date-range"> |
| 1290 |
<div class="label-container"> |
| 1291 |
<label for=""><?php esc_attr_e( 'Date range', 'supportcandy' ); ?></label> |
| 1292 |
</div> |
| 1293 |
<select id="date_range" name="date_range"> |
| 1294 |
<option <?php selected( $cf->date_range, 'all' ); ?> value="all"><?php esc_attr_e( 'All', 'supportcandy' ); ?></option> |
| 1295 |
<option <?php selected( $cf->date_range, 'future' ); ?> value="future"><?php esc_attr_e( 'Future', 'supportcandy' ); ?></option> |
| 1296 |
<option <?php selected( $cf->date_range, 'past' ); ?> value="past"><?php esc_attr_e( 'Past', 'supportcandy' ); ?></option> |
| 1297 |
<option <?php selected( $cf->date_range, 'range' ); ?> value="range"><?php esc_attr_e( 'Between', 'supportcandy' ); ?></option> |
| 1298 |
</select> |
| 1299 |
<script> |
| 1300 |
jQuery('#date_range').change(function(){ |
| 1301 |
if (jQuery(this).val() == 'range') { |
| 1302 |
jQuery('.wpsc-datetime-range-option').show(); |
| 1303 |
} else { |
| 1304 |
jQuery('.wpsc-datetime-range-option').hide(); |
| 1305 |
} |
| 1306 |
}); |
| 1307 |
</script> |
| 1308 |
</div> |
| 1309 |
|
| 1310 |
<div data-type="date-select" data-required="false" class="wpsc-input-group wpsc-datetime-range-option" style="<?php echo $cf->date_range != 'range' ? 'display:none;' : ''; ?>"> |
| 1311 |
<div class="label-container"> |
| 1312 |
<label for=""><?php esc_attr_e( 'Date in between', 'supportcandy' ); ?></label> |
| 1313 |
</div> |
| 1314 |
<div class="wpsc-date-range"> |
| 1315 |
<div class="wpsc-input-close-group"> |
| 1316 |
<input type="text" id="from-date-range" name="from-date-range" value="<?php echo $cf->start_range && is_object( $cf->start_range ) ? esc_attr( $cf->start_range->format( 'Y-m-d H:i' ) ) : ''; ?>" autocomplete="off"/> |
| 1317 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 1318 |
</div> |
| 1319 |
<div style="margin:5px;"></div> |
| 1320 |
<div class="wpsc-input-close-group"> |
| 1321 |
<input type="text" id="to-date-range" name="to-date-range" value="<?php echo $cf->end_range && is_object( $cf->end_range ) ? esc_attr( $cf->end_range->format( 'Y-m-d H:i' ) ) : ''; ?>" autocomplete="off"/> |
| 1322 |
<span onclick="wpsc_clear_date(this);"><?php WPSC_Icons::get( 'times' ); ?></span> |
| 1323 |
</div> |
| 1324 |
</div> |
| 1325 |
<script> |
| 1326 |
jQuery('#from-date-range').flatpickr({ |
| 1327 |
enableTime: true, |
| 1328 |
time_24hr: true, |
| 1329 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 1330 |
}); |
| 1331 |
jQuery('#to-date-range').flatpickr({ |
| 1332 |
enableTime: true, |
| 1333 |
time_24hr: true, |
| 1334 |
locale: "<?php echo esc_attr( WPSC_Functions::get_locale_iso() ); ?>", |
| 1335 |
}); |
| 1336 |
jQuery('#from-date-range').change(function(){ |
| 1337 |
var fromDate = jQuery(this).val().trim(); |
| 1338 |
jQuery('#to-date-range').flatpickr({ |
| 1339 |
minDate: fromDate, |
| 1340 |
defaultDate: fromDate, |
| 1341 |
enableTime: true, |
| 1342 |
time_24hr: true |
| 1343 |
}); |
| 1344 |
}); |
| 1345 |
</script> |
| 1346 |
</div> |
| 1347 |
|
| 1348 |
<div data-type="date-format" data-required="false" class="wpsc-input-group date-format"> |
| 1349 |
<div class="label-container"> |
| 1350 |
<label for=""><?php esc_attr_e( 'Date format', 'supportcandy' ); ?></label> |
| 1351 |
</div> |
| 1352 |
<input type="text" name="date_format" value="<?php echo esc_attr( $cf->date_format ); ?>" autocomplete="off" /> |
| 1353 |
</div> |
| 1354 |
<?php |
| 1355 |
|
| 1356 |
if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) : |
| 1357 |
?> |
| 1358 |
<div data-type="number" data-required="false" class="wpsc-input-group tl_width"> |
| 1359 |
<div class="label-container"> |
| 1360 |
<label for=""> |
| 1361 |
<?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?> |
| 1362 |
</label> |
| 1363 |
</div> |
| 1364 |
<input type="number" name="tl_width" value="<?php echo intval( $cf->tl_width ); ?>" autocomplete="off"> |
| 1365 |
</div> |
| 1366 |
<?php |
| 1367 |
endif; |
| 1368 |
|
| 1369 |
if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) : |
| 1370 |
?> |
| 1371 |
<div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info"> |
| 1372 |
<div class="label-container"> |
| 1373 |
<label for=""> |
| 1374 |
<?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?> |
| 1375 |
</label> |
| 1376 |
</div> |
| 1377 |
<select name="is_personal_info"> |
| 1378 |
<option <?php selected( $cf->is_personal_info, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1379 |
<option <?php selected( $cf->is_personal_info, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1380 |
</select> |
| 1381 |
</div> |
| 1382 |
<?php |
| 1383 |
endif; |
| 1384 |
|
| 1385 |
if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) : |
| 1386 |
?> |
| 1387 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile"> |
| 1388 |
<div class="label-container"> |
| 1389 |
<label for=""> |
| 1390 |
<?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?> |
| 1391 |
</label> |
| 1392 |
</div> |
| 1393 |
<select name="allow_my_profile"> |
| 1394 |
<option <?php selected( $cf->allow_my_profile, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1395 |
<option <?php selected( $cf->allow_my_profile, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1396 |
</select> |
| 1397 |
</div> |
| 1398 |
<?php |
| 1399 |
endif; |
| 1400 |
|
| 1401 |
if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) : |
| 1402 |
?> |
| 1403 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form"> |
| 1404 |
<div class="label-container"> |
| 1405 |
<label for=""> |
| 1406 |
<?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?> |
| 1407 |
</label> |
| 1408 |
</div> |
| 1409 |
<select name="allow_ticket_form"> |
| 1410 |
<option <?php selected( $cf->allow_ticket_form, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 1411 |
<option <?php selected( $cf->allow_ticket_form, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 1412 |
</select> |
| 1413 |
</div> |
| 1414 |
<?php |
| 1415 |
endif; |
| 1416 |
} |
| 1417 |
|
| 1418 |
/** |
| 1419 |
* Set custom field properties. Can be used by add/edit custom field. |
| 1420 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 1421 |
* |
| 1422 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1423 |
* @param string $field_class - class of field category. |
| 1424 |
* @return void |
| 1425 |
*/ |
| 1426 |
public static function set_cf_properties( $cf, $field_class ) { |
| 1427 |
|
| 1428 |
// extra info. |
| 1429 |
if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) { |
| 1430 |
$cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore |
| 1431 |
} |
| 1432 |
|
| 1433 |
// default value. |
| 1434 |
if ( in_array( 'default_value', $field_class::$allowed_properties ) ) { |
| 1435 |
$default_value = isset( $_POST['default_value'] ) ? sanitize_text_field( wp_unslash( $_POST['default_value'] ) ) : ''; // phpcs:ignore |
| 1436 |
$cf->default_value = $default_value ? array( $default_value ) : array(); |
| 1437 |
} |
| 1438 |
|
| 1439 |
// auto fill. |
| 1440 |
if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) { |
| 1441 |
$cf->is_auto_fill = isset( $_POST['is_auto_fill'] ) ? sanitize_text_field( wp_unslash( $_POST['is_auto_fill'] ) ) : ''; // phpcs:ignore |
| 1442 |
} |
| 1443 |
|
| 1444 |
// placeholder! |
| 1445 |
if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) { |
| 1446 |
$cf->placeholder_text = isset( $_POST['placeholder_text'] ) ? sanitize_text_field( wp_unslash( $_POST['placeholder_text'] ) ) : ''; // phpcs:ignore |
| 1447 |
} |
| 1448 |
|
| 1449 |
// date range. |
| 1450 |
$cf->date_range = isset( $_POST['date_range'] ) ? sanitize_text_field( wp_unslash( $_POST['date_range'] ) ) : 'all'; // phpcs:ignore |
| 1451 |
|
| 1452 |
// datetime in between. |
| 1453 |
$cf->start_range = isset( $_POST['from-date-range'] ) ? sanitize_text_field( wp_unslash( $_POST['from-date-range'] ) ) : ''; // phpcs:ignore |
| 1454 |
$cf->end_range = isset( $_POST['to-date-range'] ) && $cf->start_range ? sanitize_text_field( wp_unslash( $_POST['to-date-range'] ) ) : ''; // phpcs:ignore |
| 1455 |
|
| 1456 |
// date format. |
| 1457 |
$cf->date_format = isset( $_POST['date_format'] ) ? sanitize_text_field( wp_unslash( $_POST['date_format'] ) ) : ''; // phpcs:ignore |
| 1458 |
|
| 1459 |
// personal info. |
| 1460 |
if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) { |
| 1461 |
$cf->is_personal_info = isset( $_POST['is_personal_info'] ) ? intval( $_POST['is_personal_info'] ) : 0; // phpcs:ignore |
| 1462 |
} |
| 1463 |
|
| 1464 |
// my-profile. |
| 1465 |
if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) { |
| 1466 |
$cf->allow_my_profile = isset( $_POST['allow_my_profile'] ) ? intval( $_POST['allow_my_profile'] ) : 0; // phpcs:ignore |
| 1467 |
} |
| 1468 |
|
| 1469 |
// ticket form. |
| 1470 |
if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) { |
| 1471 |
$cf->allow_ticket_form = isset( $_POST['allow_ticket_form'] ) ? intval( $_POST['allow_ticket_form'] ) : 0; // phpcs:ignore |
| 1472 |
} |
| 1473 |
|
| 1474 |
// tl_width! |
| 1475 |
if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) { |
| 1476 |
$tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore |
| 1477 |
$cf->tl_width = $tl_width ? $tl_width : 100; |
| 1478 |
} |
| 1479 |
|
| 1480 |
// save! |
| 1481 |
$cf->save(); |
| 1482 |
} |
| 1483 |
|
| 1484 |
/** |
| 1485 |
* Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc. |
| 1486 |
* |
| 1487 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1488 |
* @param WPSC_Ticket $ticket - ticket object. |
| 1489 |
* @param string $module - module name. |
| 1490 |
* @return string |
| 1491 |
*/ |
| 1492 |
public static function get_ticket_field_val( $cf, $ticket, $module = '' ) { |
| 1493 |
|
| 1494 |
if ( ! is_object( $ticket->{$cf->slug} ) ) { |
| 1495 |
return ''; |
| 1496 |
} |
| 1497 |
|
| 1498 |
$gs = get_option( 'wpsc-gs-general' ); |
| 1499 |
$format = $cf->date_format ? $cf->date_format : $gs['default-date-format']; |
| 1500 |
$value = date_i18n( $format, $ticket->{$cf->slug}->getTimestamp(), false ); |
| 1501 |
|
| 1502 |
return apply_filters( 'wpsc_ticket_field_val_datetime', $value, $cf, $ticket, $module ); |
| 1503 |
} |
| 1504 |
|
| 1505 |
/** |
| 1506 |
* Print ticket value for given custom field on ticket list |
| 1507 |
* |
| 1508 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1509 |
* @param WPSC_Ticket $ticket - ticket object. |
| 1510 |
* @return void |
| 1511 |
*/ |
| 1512 |
public static function print_tl_ticket_field_val( $cf, $ticket ) { |
| 1513 |
|
| 1514 |
echo esc_attr( self::get_ticket_field_val( $cf, $ticket ) ); |
| 1515 |
} |
| 1516 |
|
| 1517 |
/** |
| 1518 |
* Print ticket value for given custom field on widget |
| 1519 |
* |
| 1520 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1521 |
* @param WPSC_Ticket $ticket - ticket object. |
| 1522 |
* @return void |
| 1523 |
*/ |
| 1524 |
public static function print_widget_ticket_field_val( $cf, $ticket ) { |
| 1525 |
|
| 1526 |
echo esc_attr( self::get_ticket_field_val( $cf, $ticket ) ); |
| 1527 |
} |
| 1528 |
|
| 1529 |
/** |
| 1530 |
* Returns printable customer value for custom field. Can be used in export tickets, replace macros etc. |
| 1531 |
* |
| 1532 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1533 |
* @param WPSC_Customer $customer - customer object. |
| 1534 |
* @return string |
| 1535 |
*/ |
| 1536 |
public static function get_customer_field_val( $cf, $customer ) { |
| 1537 |
|
| 1538 |
if ( ! is_object( $customer->{$cf->slug} ) ) { |
| 1539 |
return ''; |
| 1540 |
} |
| 1541 |
|
| 1542 |
$gs = get_option( 'wpsc-gs-general' ); |
| 1543 |
$format = $cf->date_format ? $cf->date_format : $gs['default-date-format']; |
| 1544 |
return date_i18n( $format, $customer->{$cf->slug}->getTimestamp(), false ); |
| 1545 |
} |
| 1546 |
|
| 1547 |
/** |
| 1548 |
* Print customer value for given custom field on ticket list |
| 1549 |
* |
| 1550 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1551 |
* @param WPSC_Customer $customer - customer object. |
| 1552 |
* @return void |
| 1553 |
*/ |
| 1554 |
public static function print_tl_customer_field_val( $cf, $customer ) { |
| 1555 |
|
| 1556 |
echo esc_attr( self::get_customer_field_val( $cf, $customer ) ); |
| 1557 |
} |
| 1558 |
|
| 1559 |
/** |
| 1560 |
* Print customer value for given custom field on widget |
| 1561 |
* |
| 1562 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1563 |
* @param WPSC_Customer $customer - customer object. |
| 1564 |
* @return void |
| 1565 |
*/ |
| 1566 |
public static function print_widget_customer_field_val( $cf, $customer ) { |
| 1567 |
|
| 1568 |
echo esc_attr( self::get_customer_field_val( $cf, $customer ) ); |
| 1569 |
} |
| 1570 |
|
| 1571 |
/** |
| 1572 |
* Print given value for custom field |
| 1573 |
* |
| 1574 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1575 |
* @param mixed $val - value to convert and print. |
| 1576 |
* @return void |
| 1577 |
*/ |
| 1578 |
public static function print_val( $cf, $val ) { |
| 1579 |
|
| 1580 |
if ( ! $val || $val == '0000-00-00 00:00:00' ) { |
| 1581 |
esc_attr_e( 'None', 'supportcandy' ); |
| 1582 |
return; |
| 1583 |
} |
| 1584 |
|
| 1585 |
$gs = get_option( 'wpsc-gs-general' ); |
| 1586 |
$format = $cf->date_format ? $cf->date_format : $gs['default-date-format']; |
| 1587 |
$val = is_object( $val ) ? $val : new DateTime( $val ); |
| 1588 |
echo esc_attr( date_i18n( $format, $val->getTimestamp(), false ) ); |
| 1589 |
} |
| 1590 |
|
| 1591 |
/** |
| 1592 |
* Return printable value for history log macro |
| 1593 |
* |
| 1594 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1595 |
* @param mixed $val - value to convert and return. |
| 1596 |
* @return string |
| 1597 |
*/ |
| 1598 |
public static function get_history_log_val( $cf, $val ) { |
| 1599 |
|
| 1600 |
ob_start(); |
| 1601 |
self::print_val( $cf, $val ); |
| 1602 |
return ob_get_clean(); |
| 1603 |
} |
| 1604 |
|
| 1605 |
/** |
| 1606 |
* Print dashboard activity function |
| 1607 |
* |
| 1608 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1609 |
* @param array $recent_logs - recent_logs object. |
| 1610 |
* @param array $body - body object. |
| 1611 |
* @param int $view - check if frontend. |
| 1612 |
* @return string |
| 1613 |
*/ |
| 1614 |
public static function print_activity( $cf, $recent_logs, $body, $view ) { |
| 1615 |
|
| 1616 |
$url = WPSC_Functions::get_ticket_url( $recent_logs->ticket->id, $view ); |
| 1617 |
$gs = get_option( 'wpsc-gs-general' ); |
| 1618 |
$format = $cf->date_format ? $cf->date_format : $gs['default-date-format']; |
| 1619 |
|
| 1620 |
$new_val = new DateTime( $body->new ); |
| 1621 |
if ( $body->new ) { |
| 1622 |
$log = date_i18n( $format, $new_val->getTimestamp() ); |
| 1623 |
} else { |
| 1624 |
$log = 'None'; |
| 1625 |
} |
| 1626 |
return esc_attr( $recent_logs->customer->name ) . ' updated the ' . esc_attr( $cf->name ) . ' value of <a href="' . esc_attr( $url ) . '" target="_blank">#' . esc_attr( $recent_logs->ticket->id ) . '</a> to ' . esc_attr( $log ); |
| 1627 |
} |
| 1628 |
|
| 1629 |
/** |
| 1630 |
* Return given value for custom field |
| 1631 |
* |
| 1632 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1633 |
* @param mixed $val - value to convert and print. |
| 1634 |
* @return void |
| 1635 |
*/ |
| 1636 |
public static function get_field_value( $cf, $val ) { |
| 1637 |
|
| 1638 |
if ( ! $val || $val == '0000-00-00 00:00:00' ) { |
| 1639 |
esc_attr_e( 'None', 'supportcandy' ); |
| 1640 |
return; |
| 1641 |
} |
| 1642 |
|
| 1643 |
$gs = get_option( 'wpsc-gs-general' ); |
| 1644 |
$format = $cf->date_format ? $cf->date_format : $gs['default-date-format']; |
| 1645 |
$val = is_object( $val ) ? $val : new DateTime( $val ); |
| 1646 |
return esc_attr( date_i18n( $format, $val->getTimestamp(), false ) ); |
| 1647 |
} |
| 1648 |
|
| 1649 |
/** |
| 1650 |
* Clear value of hidden fields |
| 1651 |
* |
| 1652 |
* @return void |
| 1653 |
*/ |
| 1654 |
public static function js_clear_value_hidden_fields() { |
| 1655 |
?> |
| 1656 |
case '<?php echo esc_attr( self::$slug ); ?>': |
| 1657 |
customField.find('input').first().val(''); |
| 1658 |
break; |
| 1659 |
<?php |
| 1660 |
echo PHP_EOL; |
| 1661 |
} |
| 1662 |
} |
| 1663 |
endif; |
| 1664 |
|
| 1665 |
WPSC_CF_Datetime::init(); |
| 1666 |
|