| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_CF_File_Attachment_Single' ) ) : |
| 7 |
|
| 8 |
final class WPSC_CF_File_Attachment_Single { |
| 9 |
|
| 10 |
/** |
| 11 |
* Slug for this custom field type |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public static $slug = 'cf_file_attachment_single'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Set whether this custom field type is of type date |
| 19 |
* |
| 20 |
* @var boolean |
| 21 |
*/ |
| 22 |
public static $is_date = false; |
| 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 = false; |
| 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 = 'INT 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 = 'wpsc_attachment'; |
| 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 = false; |
| 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 = false; |
| 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 = false; |
| 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 = false; |
| 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 = false; |
| 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 = false; |
| 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 = true; |
| 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' ), 13 ); |
| 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 |
|
| 174 |
// create ticket data for rest api. |
| 175 |
add_filter( 'wpsc_rest_create_ticket', array( __CLASS__, 'set_rest_ticket_data' ), 10, 3 ); |
| 176 |
|
| 177 |
// Add ticket id to attachmets after create ticket. |
| 178 |
add_action( 'wpsc_create_new_ticket', array( __CLASS__, 'add_attachment_ticket_id' ), 1 ); |
| 179 |
|
| 180 |
// ticket search query. |
| 181 |
add_filter( 'wpsc_ticket_search', array( __CLASS__, 'ticket_search' ), 10, 5 ); |
| 182 |
add_filter( 'wpsc_archive_ticket_search', array( __CLASS__, 'ticket_search' ), 10, 5 ); |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Load current class to reference classes |
| 187 |
* |
| 188 |
* @param array $classes - Associative array of class names indexed by its slug. |
| 189 |
* @return array |
| 190 |
*/ |
| 191 |
public static function load_ref_class( $classes ) { |
| 192 |
|
| 193 |
$classes[ self::$slug ] = array( |
| 194 |
'class' => __CLASS__, |
| 195 |
'save-key' => 'id', |
| 196 |
); |
| 197 |
return $classes; |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Add custom field type to list |
| 202 |
* |
| 203 |
* @param array $cf_types - custom field types array. |
| 204 |
* @return array |
| 205 |
*/ |
| 206 |
public static function add_cf_type( $cf_types ) { |
| 207 |
|
| 208 |
$cf_types[ self::$slug ] = array( |
| 209 |
'label' => esc_attr__( 'File Attachment (Single)', 'supportcandy' ), |
| 210 |
'class' => __CLASS__, |
| 211 |
); |
| 212 |
return $cf_types; |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* Print ticket form field |
| 217 |
* |
| 218 |
* @param WPSC_Custom_Field $cf - Custom field object. |
| 219 |
* @param array $tff - Array of ticket form field settings for this field. |
| 220 |
* @return string |
| 221 |
*/ |
| 222 |
public static function print_tff( $cf, $tff ) { |
| 223 |
|
| 224 |
$current_user = WPSC_Current_User::$current_user; |
| 225 |
$unique_id = uniqid( 'wpsc_' ); |
| 226 |
$attachment = new WPSC_Attachment(); |
| 227 |
if ( $cf->field == 'customer' ) { |
| 228 |
$attachment = $current_user->is_customer && $current_user->customer->{$cf->slug} ? $current_user->customer->{$cf->slug} : new WPSC_Attachment(); |
| 229 |
} |
| 230 |
|
| 231 |
ob_start();?> |
| 232 |
<div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>"> |
| 233 |
<div class="wpsc-tff-label"> |
| 234 |
<span class="name"><?php echo esc_attr( $cf->name ); ?></span> |
| 235 |
<?php |
| 236 |
if ( $tff['is-required'] ) { |
| 237 |
?> |
| 238 |
<span class="required-indicator">*</span> |
| 239 |
<?php |
| 240 |
} |
| 241 |
?> |
| 242 |
</div> |
| 243 |
<span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span> |
| 244 |
<input |
| 245 |
class="<?php echo esc_attr( $unique_id ); ?>" |
| 246 |
type="file" |
| 247 |
onchange="wpsc_set_attach_single(this, '<?php echo esc_attr( $unique_id ); ?>', '<?php echo esc_attr( $cf->slug ); ?>')"/> |
| 248 |
<div class="<?php echo esc_attr( $unique_id ); ?> wpsc-editor-attachment-container"> |
| 249 |
<?php |
| 250 |
if ( $attachment->id ) { |
| 251 |
?> |
| 252 |
<div class="wpsc-editor-attachment upload-success"> |
| 253 |
<div class="attachment-label"><?php echo esc_attr( $attachment->name ); ?></div> |
| 254 |
<div |
| 255 |
class="attachment-remove" |
| 256 |
onclick="wpsc_remove_attachment(this)" |
| 257 |
data-single="true" |
| 258 |
data-uniqueid="<?php echo esc_attr( $unique_id ); ?>"> |
| 259 |
<?php WPSC_Icons::get( 'times' ); ?> |
| 260 |
</div> |
| 261 |
<input type="hidden" name="<?php echo esc_attr( $cf->slug ); ?>[]" value="<?php echo esc_attr( $attachment->id ); ?>"/> |
| 262 |
</div> |
| 263 |
<?php |
| 264 |
} |
| 265 |
?> |
| 266 |
</div> |
| 267 |
<?php |
| 268 |
if ( $attachment->id ) : |
| 269 |
?> |
| 270 |
<script>jQuery('input.<?php echo esc_attr( $unique_id ); ?>').hide();</script> |
| 271 |
<?php |
| 272 |
endif; |
| 273 |
?> |
| 274 |
</div> |
| 275 |
<?php |
| 276 |
return ob_get_clean(); |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* Validate this type field in create ticket |
| 281 |
* |
| 282 |
* @return void |
| 283 |
*/ |
| 284 |
public static function js_validate_ticket_form() { |
| 285 |
?> |
| 286 |
|
| 287 |
case '<?php echo esc_attr( self::$slug ); ?>': |
| 288 |
if (isRequired && customField.find('input[type=hidden]').length === 0) { |
| 289 |
isValid = false; |
| 290 |
} |
| 291 |
break; |
| 292 |
<?php |
| 293 |
echo PHP_EOL; |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* Return custom field value in $_POST |
| 298 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 299 |
* |
| 300 |
* @param string $slug - Custom field slug. |
| 301 |
* @param mixed $cf - Custom field object or false. |
| 302 |
* @return mixed |
| 303 |
*/ |
| 304 |
public static function get_tff_value( $slug, $cf = false ) { |
| 305 |
|
| 306 |
return isset( $_POST[ $slug ] ) && isset( $_POST[ $slug ][0] ) ? intval( $_POST[ $slug ][0] ) : 0; // phpcs:ignore |
| 307 |
} |
| 308 |
|
| 309 |
/** |
| 310 |
* Check and return custom field value for new ticket to be created. |
| 311 |
* This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields. |
| 312 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 313 |
* |
| 314 |
* @param array $data - Array of values to to stored in ticket in an insert function. |
| 315 |
* @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types. |
| 316 |
* @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. |
| 317 |
* @return array |
| 318 |
*/ |
| 319 |
public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) { |
| 320 |
|
| 321 |
if ( isset( $custom_fields[ self::$slug ] ) ) { |
| 322 |
foreach ( $custom_fields[ self::$slug ] as $cf ) { |
| 323 |
$value = self::get_tff_value( $cf->slug ); |
| 324 |
if ( $cf->field == 'ticket' ) { |
| 325 |
|
| 326 |
$data[ $cf->slug ] = ''; |
| 327 |
|
| 328 |
if ( $value ) { |
| 329 |
$attachment = new WPSC_Attachment( $value ); |
| 330 |
// Check if attachment is already active and linked to a ticket. |
| 331 |
if ( ! ( $attachment->is_active && $attachment->ticket_id ) ) { |
| 332 |
$attachment->is_active = 1; |
| 333 |
$attachment->save(); |
| 334 |
$data[ $cf->slug ] = $value; |
| 335 |
} |
| 336 |
} |
| 337 |
} elseif ( $cf->field == 'agentonly' ) { |
| 338 |
|
| 339 |
$data[ $cf->slug ] = ''; |
| 340 |
|
| 341 |
} elseif ( $cf->field == 'customer' && $data['customer'] != 0 ) { |
| 342 |
|
| 343 |
$tff = get_option( 'wpsc-tff' ); |
| 344 |
if ( ! $is_my_profile && ! isset( $tff[ $cf->slug ] ) ) { |
| 345 |
continue; |
| 346 |
} |
| 347 |
$customer = new WPSC_Customer( $data['customer'] ); |
| 348 |
$existing_val = $customer->{$cf->slug} ? $customer->{$cf->slug}->id : null; |
| 349 |
if ( $existing_val != $value ) { |
| 350 |
|
| 351 |
$new_attach_id = ''; |
| 352 |
if ( $value ) { |
| 353 |
$attachment = new WPSC_Attachment( $value ); |
| 354 |
if ( ! ( $attachment->is_active && $attachment->ticket_id ) ) { |
| 355 |
|
| 356 |
$attachment->is_active = 1; |
| 357 |
$attachment->source = 'cf'; |
| 358 |
$attachment->source_id = $cf->id; |
| 359 |
$attachment->customer_id = $customer->id; |
| 360 |
$attachment->save(); |
| 361 |
|
| 362 |
$new_attach_id = $attachment->id; |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
$customer->{$cf->slug} = $new_attach_id; |
| 367 |
$customer->save(); |
| 368 |
|
| 369 |
// Set log for this change. |
| 370 |
WPSC_Log::insert( |
| 371 |
array( |
| 372 |
'type' => 'customer', |
| 373 |
'ref_id' => $customer->id, |
| 374 |
'modified_by' => WPSC_Current_User::$current_user->customer->id, |
| 375 |
'body' => wp_json_encode( |
| 376 |
array( |
| 377 |
'slug' => $cf->slug, |
| 378 |
'prev' => $existing_val, |
| 379 |
'new' => $new_attach_id, |
| 380 |
) |
| 381 |
), |
| 382 |
'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ), |
| 383 |
) |
| 384 |
); |
| 385 |
} |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
return $data; |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Set create ticket data for rest api request |
| 394 |
* |
| 395 |
* @param array $data - create ticket data array. |
| 396 |
* @param WP_REST_Request $request - rest request object. |
| 397 |
* @param array $custom_fields - custom field objects indexed by unique custom field types. |
| 398 |
* @return array |
| 399 |
*/ |
| 400 |
public static function set_rest_ticket_data( $data, $request, $custom_fields ) { |
| 401 |
|
| 402 |
$current_user = WPSC_Current_User::$current_user; |
| 403 |
$tff = get_option( 'wpsc-tff' ); |
| 404 |
|
| 405 |
if ( isset( $custom_fields[ self::$slug ] ) ) { |
| 406 |
foreach ( $custom_fields[ self::$slug ] as $cf ) { |
| 407 |
|
| 408 |
if ( |
| 409 |
! in_array( $cf->field, array( 'ticket', 'agentonly', 'customer' ) ) || |
| 410 |
( $cf->field == 'customer' && ! isset( $tff[ $cf->slug ] ) ) |
| 411 |
) { |
| 412 |
continue; |
| 413 |
} |
| 414 |
|
| 415 |
$attachment = WPSC_Functions::sanitize_attachment( intval( $request->get_param( $cf->slug ) ) ); |
| 416 |
|
| 417 |
if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ) { |
| 418 |
|
| 419 |
if ( $cf->field == 'ticket' && $attachment ) { |
| 420 |
$attachment = new WPSC_Attachment( $attachment ); |
| 421 |
// Check if attachment is already active and linked to a ticket. |
| 422 |
if ( ! ( $attachment->is_active && $attachment->ticket_id ) ) { |
| 423 |
$attachment->is_active = 1; |
| 424 |
$attachment->save(); |
| 425 |
$data[ $cf->slug ] = $attachment->id; |
| 426 |
} |
| 427 |
} |
| 428 |
} else { |
| 429 |
|
| 430 |
$customer = new WPSC_Customer( $data['customer'] ); |
| 431 |
$existing_val = $customer->{$cf->slug}; |
| 432 |
$existing_val = $existing_val && $existing_val->id ? $existing_val->id : ''; |
| 433 |
|
| 434 |
if ( $attachment && $attachment != $existing_val ) { |
| 435 |
|
| 436 |
$attachment = new WPSC_Attachment( $attachment ); |
| 437 |
|
| 438 |
if ( ! ( $attachment->is_active && $attachment->ticket_id ) ) { |
| 439 |
|
| 440 |
$attachment->is_active = 1; |
| 441 |
$attachment->source = 'cf'; |
| 442 |
$attachment->source_id = $cf->id; |
| 443 |
$attachment->customer_id = $customer->id; |
| 444 |
$attachment->save(); |
| 445 |
|
| 446 |
$customer->{$cf->slug} = $attachment; |
| 447 |
$customer->save(); |
| 448 |
|
| 449 |
// Set log for this change. |
| 450 |
WPSC_Log::insert( |
| 451 |
array( |
| 452 |
'type' => 'customer', |
| 453 |
'ref_id' => $customer->id, |
| 454 |
'modified_by' => $current_user->customer->id, |
| 455 |
'body' => wp_json_encode( |
| 456 |
array( |
| 457 |
'slug' => $cf->slug, |
| 458 |
'prev' => $existing_val, |
| 459 |
'new' => $attachment->id, |
| 460 |
) |
| 461 |
), |
| 462 |
'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ), |
| 463 |
) |
| 464 |
); |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
return $data; |
| 472 |
} |
| 473 |
|
| 474 |
/** |
| 475 |
* Add ticket search compatibility for fields of this custom field type. |
| 476 |
* |
| 477 |
* @param array $sql - Array of sql peices that can be joined later. |
| 478 |
* @param array $filter - User filter. |
| 479 |
* @param array $custom_fields - Custom fields array applicable for search. |
| 480 |
* @param string $search - search string. |
| 481 |
* @param array $allowed_search_fields - Allowed search fields. |
| 482 |
* @return array |
| 483 |
*/ |
| 484 |
public static function ticket_search( $sql, $filter, $custom_fields, $search, $allowed_search_fields ) { |
| 485 |
|
| 486 |
if ( isset( $custom_fields[ self::$slug ] ) ) { |
| 487 |
|
| 488 |
$search_items = false; |
| 489 |
foreach ( $custom_fields[ self::$slug ] as $cf ) { |
| 490 |
if ( in_array( $cf->slug, $allowed_search_fields ) ) { |
| 491 |
if ( ! $search_items ) { |
| 492 |
$search_items = WPSC_Attachment::get_tl_search_string( $search ); |
| 493 |
if ( ! $search_items ) { |
| 494 |
break; |
| 495 |
} |
| 496 |
} |
| 497 |
$join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.'; |
| 498 |
$sql[] = $join_char . $cf->slug . ' IN(' . implode( ', ', $search_items ) . ')'; |
| 499 |
} |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
return $sql; |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* Print edit ticket custom field in individual ticket |
| 508 |
* |
| 509 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 510 |
* @param WPSC_Ticket $ticket - ticket object. |
| 511 |
* @return void |
| 512 |
*/ |
| 513 |
public static function print_edit_ticket_cf( $cf, $ticket ) { |
| 514 |
|
| 515 |
$unique_id = uniqid( 'wpsc_' ); |
| 516 |
$attachment = $ticket->{$cf->slug} ? $ticket->{$cf->slug} : new WPSC_Attachment(); |
| 517 |
?> |
| 518 |
<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 ); ?>"> |
| 519 |
<div class="wpsc-tff-label"> |
| 520 |
<span class="name"><?php echo esc_attr( $cf->name ); ?></span> |
| 521 |
</div> |
| 522 |
<?php |
| 523 |
$extra_info = stripslashes( $cf->extra_info ); |
| 524 |
if ( $extra_info ) : |
| 525 |
?> |
| 526 |
<span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span> |
| 527 |
<?php |
| 528 |
endif |
| 529 |
?> |
| 530 |
<input |
| 531 |
class="<?php echo esc_attr( $unique_id ); ?>" |
| 532 |
type="file" |
| 533 |
onchange="wpsc_set_attach_single(this, '<?php echo esc_attr( $unique_id ); ?>', '<?php echo esc_attr( $cf->slug ); ?>')"/> |
| 534 |
<div class="<?php echo esc_attr( $unique_id ); ?> wpsc-editor-attachment-container"> |
| 535 |
<?php |
| 536 |
if ( $attachment->id ) { |
| 537 |
?> |
| 538 |
<div class="wpsc-editor-attachment upload-success"> |
| 539 |
<div class="attachment-label"><?php echo esc_attr( $attachment->name ); ?></div> |
| 540 |
<div |
| 541 |
class="attachment-remove" |
| 542 |
onclick="wpsc_remove_attachment(this)" |
| 543 |
data-single="true" |
| 544 |
data-uniqueid="<?php echo esc_attr( $unique_id ); ?>"> |
| 545 |
<?php WPSC_Icons::get( 'times' ); ?> |
| 546 |
</div> |
| 547 |
<input type="hidden" name="<?php echo esc_attr( $cf->slug ); ?>[]" value="<?php echo esc_attr( $attachment->id ); ?>"/> |
| 548 |
</div> |
| 549 |
<?php |
| 550 |
} |
| 551 |
?> |
| 552 |
</div> |
| 553 |
<?php |
| 554 |
if ( $attachment->id ) : |
| 555 |
?> |
| 556 |
<script>jQuery('input.<?php echo esc_attr( $unique_id ); ?>').hide();</script> |
| 557 |
<?php |
| 558 |
endif; |
| 559 |
?> |
| 560 |
</div> |
| 561 |
<?php |
| 562 |
} |
| 563 |
|
| 564 |
/** |
| 565 |
* Set edit individual ticket for this custom field type. |
| 566 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 567 |
* |
| 568 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 569 |
* @param WPSC_Ticket $ticket - ticket object. |
| 570 |
* @return WPSC_Ticket |
| 571 |
*/ |
| 572 |
public static function set_edit_ticket_cf( $cf, $ticket ) { |
| 573 |
|
| 574 |
$prev = $ticket->{$cf->slug} ? $ticket->{$cf->slug}->id : ''; |
| 575 |
$new = isset( $_POST[ $cf->slug ] ) && isset( $_POST[ $cf->slug ][0] ) ? intval( $_POST[ $cf->slug ][0] ) : ''; // phpcs:ignore |
| 576 |
if ( $new === 0 ) { |
| 577 |
return $ticket; |
| 578 |
} |
| 579 |
|
| 580 |
// Exit if there is no change. |
| 581 |
if ( $prev == $new ) { |
| 582 |
return $ticket; |
| 583 |
} |
| 584 |
|
| 585 |
$new = new WPSC_Attachment( $new ); |
| 586 |
// Check if attachment is already active and linked to a ticket. |
| 587 |
if ( ! ( $new->is_active && $new->ticket_id ) ) { |
| 588 |
$new->is_active = 1; |
| 589 |
$new->ticket_id = $ticket->id; |
| 590 |
$new->source = 'cf'; |
| 591 |
$new->source_id = $cf->id; |
| 592 |
$new->save(); |
| 593 |
|
| 594 |
// Change value. |
| 595 |
$ticket->{$cf->slug} = $new->id; |
| 596 |
$ticket->save(); |
| 597 |
} |
| 598 |
|
| 599 |
return $ticket; |
| 600 |
} |
| 601 |
|
| 602 |
/** |
| 603 |
* Modify ticket field value of this custom field type using rest api |
| 604 |
* |
| 605 |
* @param WPSC_Ticket $ticket - ticket object. |
| 606 |
* @param WPSC_Custom_Field $cf - custom field. |
| 607 |
* @param mixed $value - value to be set. |
| 608 |
* @return void |
| 609 |
*/ |
| 610 |
public static function set_rest_edit_ticket_cf( $ticket, $cf, $value ) { |
| 611 |
|
| 612 |
$id = WPSC_Functions::sanitize_attachment( intval( $value ) ); |
| 613 |
if ( ! $id ) { |
| 614 |
return; |
| 615 |
} |
| 616 |
|
| 617 |
$attachment = new WPSC_Attachment( $id ); |
| 618 |
|
| 619 |
if ( is_object( $ticket->{$cf->slug} ) && $ticket->{$cf->slug}->id != $attachment->id ) { |
| 620 |
|
| 621 |
// Check if attachment is already active and linked to a ticket. |
| 622 |
if ( ! ( $attachment->is_active && $attachment->ticket_id ) ) { |
| 623 |
$ticket->{$cf->slug} = $attachment->id; |
| 624 |
|
| 625 |
$attachment->is_active = 1; |
| 626 |
$attachment->source = 'cf'; |
| 627 |
$attachment->source_id = $cf->id; |
| 628 |
$attachment->ticket_id = $ticket->id; |
| 629 |
$attachment->save(); |
| 630 |
} |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
/** |
| 635 |
* Insert log thread for this custom field type change |
| 636 |
* |
| 637 |
* @param WPSC_Custom_Field $cf - current custom field of this type. |
| 638 |
* @param WPSC_Ticket $prev - ticket object before making any changes. |
| 639 |
* @param WPSC_Ticket $new - ticket object after making changes. |
| 640 |
* @param string $current_date - date string to be stored as create time. |
| 641 |
* @param int $customer_id - current user customer id for blame. |
| 642 |
* @return void |
| 643 |
*/ |
| 644 |
public static function insert_ticket_log( $cf, $prev, $new, $current_date, $customer_id ) { |
| 645 |
|
| 646 |
// Exit if there is no change. |
| 647 |
if ( $prev->{$cf->slug} == $new->{$cf->slug} ) { |
| 648 |
return; |
| 649 |
} |
| 650 |
|
| 651 |
$prev_val = $prev->{$cf->slug} ? $prev->{$cf->slug}->id : ''; |
| 652 |
$new_val = $new->{$cf->slug} ? $new->{$cf->slug}->id : ''; |
| 653 |
|
| 654 |
$thread = WPSC_Thread::insert( |
| 655 |
array( |
| 656 |
'ticket' => $prev->id, |
| 657 |
'customer' => $customer_id, |
| 658 |
'type' => 'log', |
| 659 |
'body' => wp_json_encode( |
| 660 |
array( |
| 661 |
'slug' => $cf->slug, |
| 662 |
'prev' => $prev_val, |
| 663 |
'new' => $new_val, |
| 664 |
) |
| 665 |
), |
| 666 |
'date_created' => $current_date, |
| 667 |
'date_updated' => $current_date, |
| 668 |
) |
| 669 |
); |
| 670 |
} |
| 671 |
|
| 672 |
/** |
| 673 |
* Return data for this custom field while creating duplicate ticket |
| 674 |
* |
| 675 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 676 |
* @param WPSC_Ticket $ticket - ticket object. |
| 677 |
* @return mixed |
| 678 |
*/ |
| 679 |
public static function get_duplicate_ticket_data( $cf, $ticket ) { |
| 680 |
|
| 681 |
return $ticket->{$cf->slug} ? WPSC_Individual_Ticket::get_duplicate_attachment_id( $ticket->{$cf->slug}->id ) : ''; |
| 682 |
} |
| 683 |
|
| 684 |
/** |
| 685 |
* Print edit field for this type in edit customer info |
| 686 |
* |
| 687 |
* @param WPSC_Custom_field $cf - custom field object. |
| 688 |
* @param WPSC_Customer $customer - customer object. |
| 689 |
* @param array $tff - ticket form field data. |
| 690 |
* @return string |
| 691 |
*/ |
| 692 |
public static function print_edit_customer_info( $cf, $customer, $tff ) { |
| 693 |
|
| 694 |
$unique_id = uniqid( 'wpsc_' ); |
| 695 |
$attachment = $customer->id && $customer->{$cf->slug} ? $customer->{$cf->slug} : new WPSC_Attachment(); |
| 696 |
|
| 697 |
ob_start(); |
| 698 |
?> |
| 699 |
<div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>"> |
| 700 |
<div class="wpsc-tff-label"> |
| 701 |
<span class="name"><?php echo esc_attr( $cf->name ); ?></span> |
| 702 |
</div> |
| 703 |
<span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span> |
| 704 |
<input |
| 705 |
class="<?php echo esc_attr( $unique_id ); ?>" |
| 706 |
type="file" |
| 707 |
onchange="wpsc_set_attach_single(this, '<?php echo esc_attr( $unique_id ); ?>', '<?php echo esc_attr( $cf->slug ); ?>')"/> |
| 708 |
<div class="<?php echo esc_attr( $unique_id ); ?> wpsc-editor-attachment-container"> |
| 709 |
<?php |
| 710 |
if ( $attachment->id ) { |
| 711 |
?> |
| 712 |
<div class="wpsc-editor-attachment upload-success"> |
| 713 |
<div class="attachment-label"><?php echo esc_attr( $attachment->name ); ?></div> |
| 714 |
<div |
| 715 |
class="attachment-remove" |
| 716 |
onclick="wpsc_remove_attachment(this)" |
| 717 |
data-single="true" |
| 718 |
data-uniqueid="<?php echo esc_attr( $unique_id ); ?>"> |
| 719 |
<?php WPSC_Icons::get( 'times' ); ?> |
| 720 |
</div> |
| 721 |
<input type="hidden" name="<?php echo esc_attr( $cf->slug ); ?>[]" value="<?php echo esc_attr( $attachment->id ); ?>"/> |
| 722 |
</div> |
| 723 |
<?php |
| 724 |
} |
| 725 |
?> |
| 726 |
</div> |
| 727 |
<?php |
| 728 |
if ( $attachment->id ) { |
| 729 |
?> |
| 730 |
<script>jQuery('input.<?php echo esc_attr( $unique_id ); ?>').hide();</script> |
| 731 |
<?php |
| 732 |
} |
| 733 |
?> |
| 734 |
</div> |
| 735 |
<?php |
| 736 |
return ob_get_clean(); |
| 737 |
} |
| 738 |
|
| 739 |
/** |
| 740 |
* Add ticket id to attachments after create ticket |
| 741 |
* |
| 742 |
* @param WPSC_Ticket $ticket - ticket object. |
| 743 |
* @return void |
| 744 |
*/ |
| 745 |
public static function add_attachment_ticket_id( $ticket ) { |
| 746 |
|
| 747 |
foreach ( WPSC_Custom_Field::$custom_fields as $cf ) { |
| 748 |
|
| 749 |
if ( |
| 750 |
$cf->type::$slug != self::$slug || |
| 751 |
$cf->field != 'ticket' |
| 752 |
) { |
| 753 |
continue; |
| 754 |
} |
| 755 |
|
| 756 |
$attachment = $ticket->{$cf->slug}; |
| 757 |
if ( $attachment ) { |
| 758 |
$attachment->ticket_id = $ticket->id; |
| 759 |
$attachment->source = 'cf'; |
| 760 |
$attachment->source_id = $cf->id; |
| 761 |
$attachment->save(); |
| 762 |
} |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
/** |
| 767 |
* Print add new custom field setting properties |
| 768 |
* |
| 769 |
* @param string $field_class - Class name of the field. |
| 770 |
* @return void |
| 771 |
*/ |
| 772 |
public static function get_add_new_custom_field_properties( $field_class ) { |
| 773 |
|
| 774 |
if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) : |
| 775 |
?> |
| 776 |
<div data-type="textfield" data-required="false" class="wpsc-input-group extra-info"> |
| 777 |
<div class="label-container"> |
| 778 |
<label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label> |
| 779 |
</div> |
| 780 |
<input name="extra_info" type="text" autocomplete="off" /> |
| 781 |
</div> |
| 782 |
<?php |
| 783 |
endif; |
| 784 |
|
| 785 |
if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) : |
| 786 |
?> |
| 787 |
<div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info"> |
| 788 |
<div class="label-container"> |
| 789 |
<label for=""> |
| 790 |
<?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?> |
| 791 |
</label> |
| 792 |
</div> |
| 793 |
<select name="is_personal_info"> |
| 794 |
<option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 795 |
<option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 796 |
</select> |
| 797 |
</div> |
| 798 |
<?php |
| 799 |
endif; |
| 800 |
|
| 801 |
if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) : |
| 802 |
?> |
| 803 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile"> |
| 804 |
<div class="label-container"> |
| 805 |
<label for=""> |
| 806 |
<?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?> |
| 807 |
</label> |
| 808 |
</div> |
| 809 |
<select name="allow_my_profile"> |
| 810 |
<option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 811 |
<option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 812 |
</select> |
| 813 |
</div> |
| 814 |
<?php |
| 815 |
endif; |
| 816 |
|
| 817 |
if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) : |
| 818 |
?> |
| 819 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form"> |
| 820 |
<div class="label-container"> |
| 821 |
<label for=""> |
| 822 |
<?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?> |
| 823 |
</label> |
| 824 |
</div> |
| 825 |
<select name="allow_ticket_form"> |
| 826 |
<option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 827 |
<option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 828 |
</select> |
| 829 |
</div> |
| 830 |
<?php |
| 831 |
endif; |
| 832 |
} |
| 833 |
|
| 834 |
/** |
| 835 |
* Print edit custom field properties |
| 836 |
* |
| 837 |
* @param WPSC_Custom_Fields $cf - custom field object. |
| 838 |
* @param string $field_class - class name of field category. |
| 839 |
* @return void |
| 840 |
*/ |
| 841 |
public static function get_edit_custom_field_properties( $cf, $field_class ) { |
| 842 |
|
| 843 |
if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) : |
| 844 |
?> |
| 845 |
<div data-type="textfield" data-required="false" class="wpsc-input-group extra-info"> |
| 846 |
<div class="label-container"> |
| 847 |
<label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label> |
| 848 |
</div> |
| 849 |
<input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" /> |
| 850 |
</div> |
| 851 |
<?php |
| 852 |
endif; |
| 853 |
|
| 854 |
if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) : |
| 855 |
?> |
| 856 |
<div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info"> |
| 857 |
<div class="label-container"> |
| 858 |
<label for=""> |
| 859 |
<?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?> |
| 860 |
</label> |
| 861 |
</div> |
| 862 |
<select name="is_personal_info"> |
| 863 |
<option <?php selected( $cf->is_personal_info, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 864 |
<option <?php selected( $cf->is_personal_info, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 865 |
</select> |
| 866 |
</div> |
| 867 |
<?php |
| 868 |
endif; |
| 869 |
|
| 870 |
if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) : |
| 871 |
?> |
| 872 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile"> |
| 873 |
<div class="label-container"> |
| 874 |
<label for=""> |
| 875 |
<?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?> |
| 876 |
</label> |
| 877 |
</div> |
| 878 |
<select name="allow_my_profile"> |
| 879 |
<option <?php selected( $cf->allow_my_profile, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 880 |
<option <?php selected( $cf->allow_my_profile, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 881 |
</select> |
| 882 |
</div> |
| 883 |
<?php |
| 884 |
endif; |
| 885 |
|
| 886 |
if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) : |
| 887 |
?> |
| 888 |
<div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form"> |
| 889 |
<div class="label-container"> |
| 890 |
<label for=""> |
| 891 |
<?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?> |
| 892 |
</label> |
| 893 |
</div> |
| 894 |
<select name="allow_ticket_form"> |
| 895 |
<option <?php selected( $cf->allow_ticket_form, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option> |
| 896 |
<option <?php selected( $cf->allow_ticket_form, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option> |
| 897 |
</select> |
| 898 |
</div> |
| 899 |
<?php |
| 900 |
endif; |
| 901 |
} |
| 902 |
|
| 903 |
/** |
| 904 |
* Set custom field properties. Can be used by add/edit custom field. |
| 905 |
* Ignore phpcs nonce issue as we already checked where it is called from. |
| 906 |
* |
| 907 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 908 |
* @param string $field_class - class of field category. |
| 909 |
* @return void |
| 910 |
*/ |
| 911 |
public static function set_cf_properties( $cf, $field_class ) { |
| 912 |
|
| 913 |
// extra info. |
| 914 |
if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) { |
| 915 |
$cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore |
| 916 |
} |
| 917 |
|
| 918 |
// personal info. |
| 919 |
if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) { |
| 920 |
$cf->is_personal_info = isset( $_POST['is_personal_info'] ) ? intval( $_POST['is_personal_info'] ) : 0; // phpcs:ignore |
| 921 |
} |
| 922 |
|
| 923 |
// my-profile. |
| 924 |
if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) { |
| 925 |
$cf->allow_my_profile = isset( $_POST['allow_my_profile'] ) ? intval( $_POST['allow_my_profile'] ) : 0; // phpcs:ignore |
| 926 |
} |
| 927 |
|
| 928 |
// ticket form. |
| 929 |
if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) { |
| 930 |
$cf->allow_ticket_form = isset( $_POST['allow_ticket_form'] ) ? intval( $_POST['allow_ticket_form'] ) : 0; // phpcs:ignore |
| 931 |
} |
| 932 |
|
| 933 |
// save! |
| 934 |
$cf->save(); |
| 935 |
} |
| 936 |
|
| 937 |
/** |
| 938 |
* Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc. |
| 939 |
* |
| 940 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 941 |
* @param WPSC_Ticket $ticket - ticket object. |
| 942 |
* @param string $module - module name. |
| 943 |
* @return string |
| 944 |
*/ |
| 945 |
public static function get_ticket_field_val( $cf, $ticket, $module = '' ) { |
| 946 |
|
| 947 |
$attachment = $ticket->{$cf->slug}; |
| 948 |
|
| 949 |
$name = ''; |
| 950 |
if ( $attachment && $attachment->id ) { |
| 951 |
WPSC_Macros::$attachments = array_merge( WPSC_Macros::$attachments, array( $attachment ) ); |
| 952 |
|
| 953 |
if ( $module == 'email-notification' ) { |
| 954 |
$link = site_url( '/' ) . '?wpsc_attachment=' . $attachment->id . '&auth_code=' . $ticket->auth_code; |
| 955 |
$name = '<a href= ' . $link . ' >' . $attachment->name . '</a>'; |
| 956 |
} else { |
| 957 |
$name = $attachment->name; |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
return apply_filters( 'wpsc_ticket_field_val_attach_single', $name, $cf, $ticket, $module ); |
| 962 |
} |
| 963 |
|
| 964 |
/** |
| 965 |
* Print ticket value for given custom field on widget |
| 966 |
* |
| 967 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 968 |
* @param WPSC_Ticket $ticket - ticket object. |
| 969 |
* @return void |
| 970 |
*/ |
| 971 |
public static function print_widget_ticket_field_val( $cf, $ticket ) { |
| 972 |
|
| 973 |
$attachment = $ticket->{$cf->slug}; |
| 974 |
if ( ! $attachment->id ) { |
| 975 |
return; |
| 976 |
} |
| 977 |
$unique_id = uniqid( 'wpsc_' ); |
| 978 |
?> |
| 979 |
<div class="<?php echo esc_attr( $unique_id ); ?>"> |
| 980 |
<div class="wpsc-attachment-item"> |
| 981 |
<?php |
| 982 |
$download_url = site_url( '/' ) . '?wpsc_attachment=' . $attachment->id . '&auth_code=' . $ticket->auth_code; |
| 983 |
?> |
| 984 |
<a class="wpsc-link" href="<?php echo esc_url( $download_url ); ?>" target="_blank"> |
| 985 |
<span class="wpsc-attachment-name"><?php echo esc_attr( $attachment->name ); ?></span></a> |
| 986 |
</div> |
| 987 |
</div> |
| 988 |
<script>jQuery('.<?php echo esc_attr( $unique_id ); ?>').parent().addClass('fullwidth');</script> |
| 989 |
<?php |
| 990 |
} |
| 991 |
|
| 992 |
/** |
| 993 |
* Returns printable customer value for custom field. Can be used in export tickets, replace macros etc. |
| 994 |
* |
| 995 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 996 |
* @param WPSC_Customer $customer - customer object. |
| 997 |
* @return string |
| 998 |
*/ |
| 999 |
public static function get_customer_field_val( $cf, $customer ) { |
| 1000 |
|
| 1001 |
$attachment = $customer->{$cf->slug}; |
| 1002 |
return $attachment && $attachment->id ? $attachment->name : ''; |
| 1003 |
} |
| 1004 |
|
| 1005 |
/** |
| 1006 |
* Print customer value for given custom field on widget |
| 1007 |
* |
| 1008 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1009 |
* @param WPSC_Customer $customer - customer object. |
| 1010 |
* @return void |
| 1011 |
*/ |
| 1012 |
public static function print_widget_customer_field_val( $cf, $customer ) { |
| 1013 |
|
| 1014 |
$attachment = $customer->{$cf->slug}; |
| 1015 |
if ( ! is_object( $attachment ) ) { |
| 1016 |
return; |
| 1017 |
} |
| 1018 |
$unique_id = uniqid( 'wpsc_' ); |
| 1019 |
?> |
| 1020 |
<div class="<?php echo esc_attr( $unique_id ); ?>"> |
| 1021 |
<div class="wpsc-attachment-item"> |
| 1022 |
<?php |
| 1023 |
$download_url = site_url( '/' ) . '?wpsc_attachment=' . $attachment->id; |
| 1024 |
?> |
| 1025 |
<a class="wpsc-link" href="<?php echo esc_url( $download_url ); ?>" target="_blank"> |
| 1026 |
<span class="wpsc-attachment-name"><?php echo esc_attr( $attachment->name ); ?></span></a> |
| 1027 |
</div> |
| 1028 |
</div> |
| 1029 |
<script>jQuery('.<?php echo esc_attr( $unique_id ); ?>').parent().addClass('fullwidth');</script> |
| 1030 |
<?php |
| 1031 |
} |
| 1032 |
|
| 1033 |
/** |
| 1034 |
* Print given value for custom field |
| 1035 |
* |
| 1036 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1037 |
* @param mixed $val - value to convert and print. |
| 1038 |
* @return void |
| 1039 |
*/ |
| 1040 |
public static function print_val( $cf, $val ) { |
| 1041 |
|
| 1042 |
$attachment = is_object( $val ) ? $val : new WPSC_Attachment( $val ); |
| 1043 |
if ( ! $attachment->id ) { |
| 1044 |
esc_attr_e( 'None', 'supportcandy' ); |
| 1045 |
return; |
| 1046 |
} |
| 1047 |
$ticket = new WPSC_Ticket( $attachment->ticket_id ); |
| 1048 |
?> |
| 1049 |
<div class="wpsc-attachment-item"> |
| 1050 |
<?php |
| 1051 |
$download_url = site_url( '/' ) . '?wpsc_attachment=' . $attachment->id . '&auth_code=' . $ticket->auth_code; |
| 1052 |
?> |
| 1053 |
<a class="wpsc-link" href="<?php echo esc_url( $download_url ); ?>" target="_blank"> |
| 1054 |
<span class="wpsc-attachment-name"><?php echo esc_attr( $attachment->name ); ?></span> |
| 1055 |
</a> |
| 1056 |
</div> |
| 1057 |
<?php |
| 1058 |
} |
| 1059 |
|
| 1060 |
/** |
| 1061 |
* Return printable value for history log macro |
| 1062 |
* |
| 1063 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1064 |
* @param mixed $val - value to convert and return. |
| 1065 |
* @return string |
| 1066 |
*/ |
| 1067 |
public static function get_history_log_val( $cf, $val ) { |
| 1068 |
|
| 1069 |
$attachment = is_object( $val ) ? $val : new WPSC_Attachment( $val ); |
| 1070 |
return $attachment->id ? $attachment->name : esc_attr__( 'None', 'supportcandy' ); |
| 1071 |
} |
| 1072 |
|
| 1073 |
/** |
| 1074 |
* Return default value for custom field of this type |
| 1075 |
* |
| 1076 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1077 |
* @return mixed |
| 1078 |
*/ |
| 1079 |
public static function get_default_value( $cf ) { |
| 1080 |
|
| 1081 |
return ''; |
| 1082 |
} |
| 1083 |
|
| 1084 |
/** |
| 1085 |
* Print dashboard activity function |
| 1086 |
* |
| 1087 |
* @param WPSC_Custom_Field $cf - custom field object. |
| 1088 |
* @param array $recent_logs - recent_logs object. |
| 1089 |
* @param array $body - body object. |
| 1090 |
* @param int $view - check if frontend. |
| 1091 |
* @return string |
| 1092 |
*/ |
| 1093 |
public static function print_activity( $cf, $recent_logs, $body, $view ) { |
| 1094 |
|
| 1095 |
$url = WPSC_Functions::get_ticket_url( $recent_logs->ticket->id, $view ); |
| 1096 |
if ( $body->new ) { |
| 1097 |
$attachment = new WPSC_Attachment( $body->new ); |
| 1098 |
$url = site_url( '/' ) . '?wpsc_attachment=' . $attachment->id; |
| 1099 |
$link = '<a class="wpsc-link" href=" ' . esc_url( $url ) . ' " target="_blank">' . $attachment->name . '</a>'; |
| 1100 |
} else { |
| 1101 |
$link = 'None'; |
| 1102 |
} |
| 1103 |
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 ' . wp_kses_post( $link ); |
| 1104 |
} |
| 1105 |
} |
| 1106 |
endif; |
| 1107 |
|
| 1108 |
WPSC_CF_File_Attachment_Single::init(); |
| 1109 |
|