Plugin Directory

Changeset 2895557


Ignore:
Timestamp:
04/07/2023 11:34:22 AM (3 years ago)
Author:
supportcandy
Message:

version 3.1.5

Location:
supportcandy
Files:
570 added
53 edited

Legend:

Unmodified
Added
Removed
  • supportcandy/trunk/asset/js/admin.js

    r2873748 r2895557  
    18971897    var dataform = new FormData( form );
    18981898
    1899     var visibility = {};
    1900     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    1901         function () {
    1902             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    1903             if ( ! slug) {
    1904                 return;
    1905             }
    1906             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    1907             if ( ! operator) {
    1908                 return;
    1909             }
    1910             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    1911             if ( ! operand_val_1) {
    1912                 return;
    1913             }
    1914             var filter = { operator, operand_val_1 };
    1915             if (operator === 'BETWEEN') {
    1916                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    1917                 if ( ! operand_val_2) {
    1918                     return;
    1919                 }
    1920                 filter.operand_val_2 = operand_val_2;
    1921             }
    1922             visibility[slug] = filter;
    1923         }
    1924     );
    1925     dataform.append( 'visibility', JSON.stringify( visibility ) );
     1899    dataform.append( 'visibility', JSON.stringify( wpsc_get_condition_json( 'visibility' ) ) );
    19261900
    19271901    jQuery.ajax(
     
    19741948    var dataform = new FormData( form );
    19751949
    1976     var visibility = {};
    1977     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    1978         function () {
    1979             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    1980             if ( ! slug) {
    1981                 return;
    1982             }
    1983             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    1984             if ( ! operator) {
    1985                 return;
    1986             }
    1987             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    1988             if ( ! operand_val_1) {
    1989                 return;
    1990             }
    1991             var filter = { operator, operand_val_1 };
    1992             if (operator === 'BETWEEN') {
    1993                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    1994                 if ( ! operand_val_2) {
    1995                     return;
    1996                 }
    1997                 filter.operand_val_2 = operand_val_2;
    1998             }
    1999             visibility[slug] = filter;
    2000         }
    2001     );
    2002     dataform.append( 'visibility', JSON.stringify( visibility ) );
     1950    dataform.append( 'visibility', JSON.stringify( wpsc_get_condition_json( 'visibility' ) ) );
    20031951
    20041952    jQuery.ajax(
     
    25062454    }
    25072455
    2508     var filters = {};
    2509     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    2510         function () {
    2511             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    2512             if ( ! slug) {
    2513                 return;
    2514             }
    2515             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    2516             if ( ! operator) {
    2517                 return;
    2518             }
    2519             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    2520             if ( ! operand_val_1) {
    2521                 return;
    2522             }
    2523             var filter = { operator, operand_val_1 };
    2524             if (operator === 'BETWEEN') {
    2525                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    2526                 if ( ! operand_val_2) {
    2527                     return;
    2528                 }
    2529                 filter.operand_val_2 = operand_val_2;
    2530             }
    2531             filters[slug] = filter;
    2532         }
    2533     );
    2534     if (Object.keys( filters ).length === 0) {
     2456    var filters = wpsc_get_condition_json( 'default_filters' );
     2457    if ( filters.length === 0 || ( filters.length === 1 && filters[0].length === 0 )  ) {
    25352458        alert( supportcandy.translations.req_fields_missing );
    25362459        return;
     
    25862509
    25872510    var label = jQuery( '#wpsc-atl-df-label' ).val().trim();
    2588     if ( ! label) {
     2511    if ( ! label ) {
    25892512        alert( supportcandy.translations.req_fields_missing );
    25902513        return;
    25912514    }
    25922515
    2593     if (flag) {
    2594         var filters = {};
    2595         jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    2596             function () {
    2597                 var slug = jQuery( this ).find( 'select.cf' ).first().val();
    2598                 if ( ! slug) {
    2599                     return;
    2600                 }
    2601                 var operator = jQuery( this ).find( 'select.operator' ).first().val();
    2602                 if ( ! operator) {
    2603                     return;
    2604                 }
    2605                 var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    2606                 if ( ! operand_val_1) {
    2607                     return;
    2608                 }
    2609                 var filter = { operator, operand_val_1 };
    2610                 if (operator === 'BETWEEN') {
    2611                     var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    2612                     if ( ! operand_val_2) {
    2613                         return;
    2614                     }
    2615                     filter.operand_val_2 = operand_val_2;
    2616                 }
    2617                 filters[slug] = filter;
    2618             }
    2619         );
    2620         if (Object.keys( filters ).length === 0) {
     2516    var form     = jQuery( '.wpsc-frm-edit-atl-default-filter' )[0];
     2517    var dataform = new FormData( form );
     2518
     2519    if ( flag ) {
     2520        var filters = wpsc_get_condition_json( 'default_filters' );
     2521        if ( filters.length === 0 || ( filters.length === 1 && filters[0].length === 0 )  ) {
    26212522            alert( supportcandy.translations.req_fields_missing );
    26222523            return;
    26232524        }
    2624     }
    2625 
    2626     jQuery( '.wpsc-modal-footer button' ).attr( 'disabled', true );
    2627     jQuery( el ).text( supportcandy.translations.please_wait );
    2628 
    2629     var form     = jQuery( '.wpsc-frm-edit-atl-default-filter' )[0];
    2630     var dataform = new FormData( form );
    2631     dataform.append( 'filters', JSON.stringify( filters ) );
     2525        dataform.append( 'filters', JSON.stringify( filters ) );
     2526    }
     2527
     2528    jQuery( '.wpsc-modal-footer button' ).attr( 'disabled', true );
     2529    jQuery( el ).text( supportcandy.translations.please_wait );
    26322530
    26332531    jQuery.ajax(
     
    27522650    }
    27532651
    2754     var filters = {};
    2755     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    2756         function () {
    2757             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    2758             if ( ! slug) {
    2759                 return;
    2760             }
    2761             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    2762             if ( ! operator) {
    2763                 return;
    2764             }
    2765             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    2766             if ( ! operand_val_1) {
    2767                 return;
    2768             }
    2769             var filter = { operator, operand_val_1 };
    2770             if (operator === 'BETWEEN') {
    2771                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    2772                 if ( ! operand_val_2) {
    2773                     return;
    2774                 }
    2775                 filter.operand_val_2 = operand_val_2;
    2776             }
    2777             filters[slug] = filter;
    2778         }
    2779     );
    2780     if (Object.keys( filters ).length === 0) {
     2652    var filters = wpsc_get_condition_json( 'default_filters' );
     2653    if ( filters.length === 0 || ( filters.length === 1 && filters[0].length === 0 )  ) {
    27812654        alert( supportcandy.translations.req_fields_missing );
    27822655        return;
     
    28372710    }
    28382711
    2839     if (flag) {
    2840         var filters = {};
    2841         jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    2842             function () {
    2843                 var slug = jQuery( this ).find( 'select.cf' ).first().val();
    2844                 if ( ! slug) {
    2845                     return;
    2846                 }
    2847                 var operator = jQuery( this ).find( 'select.operator' ).first().val();
    2848                 if ( ! operator) {
    2849                     return;
    2850                 }
    2851                 var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    2852                 if ( ! operand_val_1) {
    2853                     return;
    2854                 }
    2855                 var filter = { operator, operand_val_1 };
    2856                 if (operator === 'BETWEEN') {
    2857                     var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    2858                     if ( ! operand_val_2) {
    2859                         return;
    2860                     }
    2861                     filter.operand_val_2 = operand_val_2;
    2862                 }
    2863                 filters[slug] = filter;
    2864             }
    2865         );
    2866         if (Object.keys( filters ).length === 0) {
     2712    var form = jQuery( '.wpsc-frm-edit-ctl-default-filter' )[0];
     2713    var dataform = new FormData( form );
     2714
     2715    if ( flag ) {
     2716        var filters = wpsc_get_condition_json( 'default_filters' );
     2717        if ( filters.length === 0 || ( filters.length === 1 && filters[0].length === 0 )  ) {
    28672718            alert( supportcandy.translations.req_fields_missing );
    28682719            return;
    28692720        }
    2870     }
    2871 
    2872     jQuery( '.wpsc-modal-footer button' ).attr( 'disabled', true );
    2873     jQuery( el ).text( supportcandy.translations.please_wait );
    2874 
    2875     var form     = jQuery( '.wpsc-frm-edit-ctl-default-filter' )[0];
    2876     var dataform = new FormData( form );
    2877     dataform.append( 'filters', JSON.stringify( filters ) );
     2721        dataform.append( 'filters', JSON.stringify( filters ) );
     2722    }
     2723
     2724    jQuery( '.wpsc-modal-footer button' ).attr( 'disabled', true );
     2725    jQuery( el ).text( supportcandy.translations.please_wait );
    28782726
    28792727    jQuery.ajax(
     
    33273175
    33283176/**
    3329  * Get form filter oprators
    3330  */
    3331 function wpsc_tc_get_operators(el, nonce) {
    3332 
    3333     var content = jQuery( el ).closest( '.content' );
    3334     var slug    = jQuery( el ).val().trim();
    3335 
    3336     content.find( '.conditional, .wpsc-inline-loader' ).remove();
    3337     if ( ! slug) {
    3338         return;
    3339     }
    3340 
    3341     content.append( supportcandy.inline_loader );
    3342     var data = {
    3343         action: 'wpsc_tc_get_operators',
    3344         slug: slug,
    3345         _ajax_nonce: nonce
    3346     };
    3347     jQuery.post(
    3348         supportcandy.ajax_url,
    3349         data,
    3350         function (response) {
    3351             content.find( '.wpsc-inline-loader' ).remove();
    3352             content.append( response );
    3353         }
    3354     );
    3355 }
    3356 
    3357 /**
    3358  * Get email notification condition operands
    3359  */
    3360 function wpsc_tc_get_operand(el, slug, nonce) {
    3361 
    3362     var content  = jQuery( el ).closest( '.content' );
    3363     var operator = jQuery( el ).val().trim();
    3364 
    3365     content.find( '.conditional.operand, .wpsc-inline-loader' ).remove();
    3366     if ( ! operator) {
    3367         return;
    3368     }
    3369 
    3370     content.append( supportcandy.inline_loader );
    3371     var data = {
    3372         action: 'wpsc_tc_get_operand',
    3373         operator,
    3374         slug,
    3375         _ajax_nonce: nonce
    3376     };
    3377     jQuery.post(
    3378         supportcandy.ajax_url,
    3379         data,
    3380         function (response) {
    3381             content.find( '.wpsc-inline-loader' ).remove();
    3382             content.append( response );
    3383         }
    3384     );
    3385 }
    3386 
    3387 /**
    33883177 * Get edit email notification
    33893178 *
     
    34413230    }
    34423231
    3443     var conditions = {};
    3444     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    3445         function () {
    3446             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    3447             if ( ! slug) {
    3448                 return;
    3449             }
    3450             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    3451             if ( ! operator) {
    3452                 return;
    3453             }
    3454             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    3455             if ( ! operand_val_1) {
    3456                 return;
    3457             }
    3458             var filter = { operator, operand_val_1 };
    3459             if (operator === 'BETWEEN') {
    3460                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    3461                 if ( ! operand_val_2) {
    3462                     return;
    3463                 }
    3464                 filter.operand_val_2 = operand_val_2;
    3465             }
    3466             conditions[slug] = filter;
    3467         }
    3468     );
    3469     dataform.append( 'conditions', JSON.stringify( conditions ) );
     3232    dataform.append( 'conditions', JSON.stringify( wpsc_get_condition_json( 'conditions' ) ) );
    34703233
    34713234    jQuery( '.wpsc-setting-section-body' ).html( supportcandy.loader_html );
  • supportcandy/trunk/class-wpsc-installation.php

    r2887316 r2895557  
    11901190                            'custom'             => array(),
    11911191                        ),
    1192                         'relation'   => 'AND',
    11931192                        'conditions' => '',
    11941193                    ),
     
    12171216                            'custom'             => array(),
    12181217                        ),
    1219                         'relation'   => 'AND',
    12201218                        'conditions' => '',
    12211219                    ),
     
    12441242                            'custom'             => array(),
    12451243                        ),
    1246                         'relation'   => 'AND',
    12471244                        'conditions' => '',
    12481245                    ),
     
    12711268                            'custom'             => array(),
    12721269                        ),
    1273                         'relation'   => 'OR',
    1274                         'conditions' => '{"cf_status":{"operator":"=","operand_val_1":"4"}}',
     1270                        'conditions' => '[[{"slug":"status","operator":"=","operand_val_1":"4"}]]',
    12751271                    ),
    12761272                )
     
    16941690            }
    16951691
     1692            if ( version_compare( self::$current_version, '3.1.5', '<' ) ) {
     1693
     1694                // scheduled task for setting conditions upgrade.
     1695                $wpdb->insert(
     1696                    $wpdb->prefix . 'psmsc_scheduled_tasks',
     1697                    array(
     1698                        'class'     => 'WPSC_SC_Upgrade',
     1699                        'method'    => 'upgrade_setting_conditions',
     1700                        'is_manual' => 0,
     1701                    )
     1702                );
     1703
     1704                // scheduled task for saved filter conditions upgrade.
     1705                $wpdb->insert(
     1706                    $wpdb->prefix . 'psmsc_scheduled_tasks',
     1707                    array(
     1708                        'class'             => 'WPSC_SC_Upgrade',
     1709                        'method'            => 'upgrade_saved_filter_conditions',
     1710                        'is_manual'         => 1,
     1711                        'warning_text'      => 'SupportCandy - Filters database upgrade needed.',
     1712                        'warning_link_text' => 'Upgrade Now',
     1713                        'progressbar_text'  => 'Upgrading filters...',
     1714                    )
     1715                );
     1716            }
     1717
    16961718            self::set_upgrade_complete();
    16971719        }
  • supportcandy/trunk/framework/scripts.js

    r2873748 r2895557  
    10611061
    10621062/**
    1063  * Remove form filter item
    1064  */
    1065 function wpsc_remove_form_filter_item(el) {
    1066 
     1063 * Add and condition item
     1064 * @param {*} el
     1065 * @param {*} uniqueId
     1066 */
     1067function wpsc_add_and_condition( el, uniqueId ) {
     1068
     1069    var container = jQuery( el ).closest( '.wpsc-form-filter-container' ).find( '.and-container' );
     1070    container.append( jQuery( '.and-template.' + uniqueId ).html() );
     1071    container = container.find( '.and-item:last-child .or-container' );
     1072    container.append( jQuery( '.or-template.' + uniqueId ).html() );
     1073    container.find( 'select' ).selectWoo();
     1074}
     1075
     1076/**
     1077 * Add and condition item
     1078 * @param {*} el
     1079 * @param {*} uniqueId
     1080 */
     1081function wpsc_add_or_condition( el, uniqueId ) {
     1082
     1083    var container = jQuery( el ).closest( '.and-item' ).find( '.or-container' );
     1084    container.append( jQuery( '.or-template.' + uniqueId ).html() );
     1085    container.find(':last-child').find('select').selectWoo();
     1086}
     1087
     1088/**
     1089 * Remove condition item
     1090 * @param {*} el
     1091 */
     1092function wpsc_remove_condition_item( el ) {
     1093
     1094    var andItem = jQuery( el ).closest( '.and-item' );
    10671095    jQuery( el ).closest( '.wpsc-form-filter-item' ).remove();
    1068 }
    1069 
    1070 /**
    1071  * Add form filter item
    1072  */
    1073 function wpsc_add_form_filter_item() {
    1074 
    1075     jQuery( '.wpsc-form-filter-container' ).append( jQuery( '.wpsc-form-filter-snippet' ).html() );
    1076     jQuery( '.wpsc-form-filter-container' ).last().find( '.cf' ).selectWoo();
     1096    if ( andItem.find( '.or-container' ).children().length === 0 ) {
     1097        jQuery( andItem ).remove();
     1098    }
     1099}
     1100
     1101/**
     1102 * Get JSON string for the condition input of given name
     1103 * @param {*} name
     1104 */
     1105function wpsc_get_condition_json( name ) {
     1106
     1107    var conditions = [];
     1108    jQuery( '.wpsc-form-filter-container.' + name + ' .and-item' ).each(
     1109        function () {
     1110            var andCondition = [];
     1111            jQuery( this ).find( '.wpsc-form-filter-item' ).each(
     1112                function () {
     1113                    var slug = jQuery( this ).find( 'select.filter' ).first().val();
     1114                    if ( ! slug) {
     1115                        return;
     1116                    }
     1117                    var operator = jQuery( this ).find( 'select.operator' ).first().val();
     1118                    if ( ! operator) {
     1119                        return;
     1120                    }
     1121                    var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
     1122                    if ( ! operand_val_1) {
     1123                        return;
     1124                    }
     1125                    var filter = { slug, operator, operand_val_1 };
     1126                    if (operator === 'BETWEEN') {
     1127                        var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
     1128                        if ( ! operand_val_2) {
     1129                            return;
     1130                        }
     1131                        filter.operand_val_2 = operand_val_2;
     1132                    }
     1133                    andCondition.push( filter );
     1134                }
     1135            );
     1136            conditions.push( andCondition );
     1137        }
     1138    );
     1139    return conditions;
    10771140}
    10781141
     
    14201483 */
    14211484function wpsc_tl_get_custom_filter() {
     1485
    14221486    wpsc_show_modal();
    14231487    var data = {
     
    14251489        _ajax_nonce: supportcandy.nonce
    14261490    };
    1427     if (supportcandy.ticketList.filters.filterSlug == 'custom') {
     1491    if ( supportcandy.ticketList.filters.filterSlug == 'custom' ) {
    14281492        data.filters = supportcandy.ticketList.filters;
    14291493    }
     
    14481512function wpsc_tl_apply_custom_filter(el) {
    14491513
    1450     var filters = {};
    1451     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    1452         function () {
    1453             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    1454             if ( ! slug) {
    1455                 return;
    1456             }
    1457             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    1458             if ( ! operator) {
    1459                 return;
    1460             }
    1461             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    1462             if ( ! operand_val_1) {
    1463                 return;
    1464             }
    1465             var filter = { operator, operand_val_1 };
    1466             if (operator === 'BETWEEN') {
    1467                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    1468                 if ( ! operand_val_2) {
    1469                     return;
    1470                 }
    1471                 filter.operand_val_2 = operand_val_2;
    1472             }
    1473             filters[slug] = filter;
    1474         }
    1475     );
    1476     if (Object.keys( filters ).length === 0) {
     1514    var filters = wpsc_get_condition_json( 'custom_filters' );
     1515    if ( filters.length === 0 || ( filters.length === 1 && filters[0].length === 0 )  ) {
    14771516        alert( supportcandy.translations.req_fields_missing );
    14781517        return;
     
    14981537function wpsc_tl_edit_filter() {
    14991538
    1500     if (supportcandy.ticketList.filters.filterSlug == 'custom') {
     1539    if ( supportcandy.ticketList.filters.filterSlug == 'custom' ) {
    15011540        wpsc_tl_get_custom_filter();
    15021541    } else {
     
    15101549function wpsc_tl_add_saved_filter() {
    15111550
    1512     var filters = {};
    1513     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    1514         function () {
    1515             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    1516             if ( ! slug) {
    1517                 return;
    1518             }
    1519             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    1520             if ( ! operator) {
    1521                 return;
    1522             }
    1523             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    1524             if ( ! operand_val_1) {
    1525                 return;
    1526             }
    1527             var filter = { operator, operand_val_1 };
    1528             if (operator === 'BETWEEN') {
    1529                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    1530                 if ( ! operand_val_2) {
    1531                     return;
    1532                 }
    1533                 filter.operand_val_2 = operand_val_2;
    1534             }
    1535             filters[slug] = filter;
    1536         }
    1537     );
    1538     if (Object.keys( filters ).length === 0) {
     1551    var filters = wpsc_get_condition_json( 'custom_filters' );
     1552    if ( filters.length === 0 || ( filters.length === 1 && filters[0].length === 0 )  ) {
    15391553        alert( supportcandy.translations.req_fields_missing );
    15401554        return;
     
    16481662    }
    16491663
    1650     var filters = {};
    1651     jQuery( '.wpsc-form-filter-container .wpsc-form-filter-item' ).each(
    1652         function () {
    1653             var slug = jQuery( this ).find( 'select.cf' ).first().val();
    1654             if ( ! slug) {
    1655                 return;
    1656             }
    1657             var operator = jQuery( this ).find( 'select.operator' ).first().val();
    1658             if ( ! operator) {
    1659                 return;
    1660             }
    1661             var operand_val_1 = jQuery( this ).find( '.operand_val_1' ).first().val();
    1662             if ( ! operand_val_1) {
    1663                 return;
    1664             }
    1665             var filter = { operator, operand_val_1 };
    1666             if (operator === 'BETWEEN') {
    1667                 var operand_val_2 = jQuery( this ).find( '.operand_val_2' ).first().val();
    1668                 if ( ! operand_val_2) {
    1669                     return;
    1670                 }
    1671                 filter.operand_val_2 = operand_val_2;
    1672             }
    1673             filters[slug] = filter;
    1674         }
    1675     );
    1676     if (Object.keys( filters ).length === 0) {
     1664    var filters = wpsc_get_condition_json( 'custom_filters' );
     1665    if ( filters.length === 0 || ( filters.length === 1 && filters[0].length === 0 )  ) {
    16771666        alert( supportcandy.translations.req_fields_missing );
    16781667        return;
     
    16961685    ).done(
    16971686        function (res) {
    1698             supportcandy.ticketList.filters = { filterSlug: supportcandy.ticketList.filters.filterSlug };
    16991687            wpsc_close_modal();
    17001688            wpsc_get_ticket_list();
     
    17351723    jQuery( 'select.wpsc-input-filter' ).val( supportcandy.prevFilter );
    17361724    wpsc_close_modal();
     1725}
     1726
     1727/**
     1728 * Get form filter oprators
     1729 */
     1730function wpsc_tc_get_operators(el, nonce) {
     1731
     1732    var content = jQuery( el ).closest( '.content' );
     1733    var slug    = jQuery( el ).val().trim();
     1734
     1735    content.find( '.conditional, .wpsc-inline-loader' ).remove();
     1736    if ( ! slug) {
     1737        return;
     1738    }
     1739
     1740    content.append( supportcandy.inline_loader );
     1741    var data = {
     1742        action: 'wpsc_tc_get_operators',
     1743        slug: slug,
     1744        _ajax_nonce: nonce
     1745    };
     1746    jQuery.post(
     1747        supportcandy.ajax_url,
     1748        data,
     1749        function (response) {
     1750            content.find( '.wpsc-inline-loader' ).remove();
     1751            content.append( response );
     1752        }
     1753    );
     1754}
     1755
     1756/**
     1757 * Get email notification condition operands
     1758 */
     1759function wpsc_tc_get_operand(el, slug, nonce) {
     1760
     1761    var content  = jQuery( el ).closest( '.content' );
     1762    var operator = jQuery( el ).val().trim();
     1763
     1764    content.find( '.conditional.operand, .wpsc-inline-loader' ).remove();
     1765    if ( ! operator) {
     1766        return;
     1767    }
     1768
     1769    content.append( supportcandy.inline_loader );
     1770    var data = {
     1771        action: 'wpsc_tc_get_operand',
     1772        operator,
     1773        slug,
     1774        _ajax_nonce: nonce
     1775    };
     1776    jQuery.post(
     1777        supportcandy.ajax_url,
     1778        data,
     1779        function (response) {
     1780            content.find( '.wpsc-inline-loader' ).remove();
     1781            content.append( response );
     1782        }
     1783    );
    17371784}
    17381785
     
    25612608                pagination: response.pagination
    25622609            };
    2563             if (typeof supportcandy.ticketList.filters.filters != 'undefined') {
    2564                 supportcandy.ticketList.filters.filters = JSON.stringify( supportcandy.ticketList.filters.filters );
    2565             }
    25662610        }
    25672611    );
  • supportcandy/trunk/framework/style-rtl.css

    r2887316 r2895557  
    528528    display: flex;
    529529    flex-direction: column;
    530     flex-wrap: wrap;
    531     margin-bottom: 15px;
     530    padding-bottom: 15px;
    532531    box-sizing: border-box;
    533532}
     
    10391038
    10401039/* Form Filter */
    1041 .wpsc-form-filter-container {
    1042     width: 100%;
     1040.wpsc-form-filter-container,
     1041.wpsc-form-filter-container .and-item {
     1042    width: 100%;
     1043    display: flex;
     1044    flex-direction: column;
     1045    align-items: center;
     1046    gap: 15px;
     1047    border: 1px dashed #000;
     1048    border-radius: 5px;
     1049    padding: 15px;
     1050    box-sizing: border-box;
     1051}
     1052.wpsc-form-filter-container .and-container,
     1053.wpsc-form-filter-container .or-container {
     1054    width: 100%;
     1055    display: flex;
     1056    flex-direction: column;
     1057}
     1058.wpsc-form-filter-container .and-container {
     1059    gap: 15px;
     1060}
     1061.wpsc-form-filter-container .or-container {
     1062    gap: 5px;
     1063}
     1064.wpsc-form-filter-container button {
     1065    width: fit-content;
    10431066}
    10441067.wpsc-form-filter-item {
     
    15061529.wpsc-button.small {
    15071530    font-size: 12px !important;
    1508     min-height: 30px !important;
    15091531}
    15101532.wpsc-button.normal {
  • supportcandy/trunk/framework/style.css

    r2887316 r2895557  
    527527    display: flex;
    528528    flex-direction: column;
    529     flex-wrap: wrap;
    530     margin-bottom: 15px;
     529    padding-bottom: 15px;
    531530    box-sizing: border-box;
    532531}
     
    10381037
    10391038/* Form Filter */
    1040 .wpsc-form-filter-container {
    1041     width: 100%;
     1039.wpsc-form-filter-container,
     1040.wpsc-form-filter-container .and-item {
     1041    width: 100%;
     1042    display: flex;
     1043    flex-direction: column;
     1044    align-items: center;
     1045    gap: 15px;
     1046    border: 1px dashed #000;
     1047    border-radius: 5px;
     1048    padding: 15px;
     1049    box-sizing: border-box;
     1050}
     1051.wpsc-form-filter-container .and-container,
     1052.wpsc-form-filter-container .or-container {
     1053    width: 100%;
     1054    display: flex;
     1055    flex-direction: column;
     1056}
     1057.wpsc-form-filter-container .and-container {
     1058    gap: 15px;
     1059}
     1060.wpsc-form-filter-container .or-container {
     1061    gap: 5px;
     1062}
     1063.wpsc-form-filter-container button {
     1064    width: fit-content;
    10421065}
    10431066.wpsc-form-filter-item {
     
    15051528.wpsc-button.small {
    15061529    font-size: 12px !important;
    1507     min-height: 30px !important;
    15081530}
    15091531.wpsc-button.normal {
  • supportcandy/trunk/includes/admin/custom-fields/class-wpsc-cf-settings.php

    r2793251 r2895557  
    284284                array(
    285285
    286                     'ticket-form'                       => array( 'ticket', 'customer' ),
    287                     'ticket-list'                       => array( 'ticket', 'customer', 'agentonly' ),
    288                     'ticket-filter'                     => array( 'ticket', 'customer', 'agentonly' ),
    289                     'ticket-form-visibility-conditions' => array( 'ticket', 'customer' ),
    290                     'ticket-en-notification-conditions' => array( 'ticket', 'customer', 'agentonly' ),
    291                     'ticket-macro'                      => array( 'ticket', 'customer', 'agentonly' ),
     286                    'ticket-form'   => array( 'ticket', 'customer' ),
     287                    'ticket-list'   => array( 'ticket', 'customer', 'agentonly' ),
     288                    'ticket-filter' => array( 'ticket', 'customer', 'agentonly' ),
     289                    'ticket-macro'  => array( 'ticket', 'customer', 'agentonly' ),
    292290                )
    293291            );
  • supportcandy/trunk/includes/admin/custom-fields/class-wpsc-tff.php

    r2822852 r2895557  
    3636            // Remove if custom field deleted.
    3737            add_action( 'wpsc_delete_custom_field', array( __CLASS__, 'delete_custom_field' ), 10, 1 );
     38
     39            // visibility conditions filter.
     40            add_filter( 'wpsc_visibility_conditions', array( __CLASS__, 'visibility_conditions' ) );
    3841        }
    3942
     
    249252                </div>
    250253                <?php do_action( 'wpsc_get_add_new_tff', $unique_id ); ?>
    251                 <div class="wpsc-input-group">
    252                     <div class="label-container">
    253                         <label for="">
    254                             <?php esc_attr_e( 'Visibility conditions', 'supportcandy' ); ?>
    255                         </label>
    256                     </div>
    257                     <select name="relation" id="relation" style="width: fit-content; margin: 10px 0px;">
    258                         <option value="AND"><?php esc_attr_e( 'AND', 'supportcandy' ); ?></option>
    259                         <option value="OR"><?php esc_attr_e( 'OR', 'supportcandy' ); ?></option>
    260                     </select>
    261                     <div class="wpsc-form-filter-container"></div>
    262                     <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    263                         <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    264                     </button>
    265                 </div>
     254                <?php WPSC_Ticket_Conditions::print( 'visibility', 'wpsc_visibility_conditions', '', false, __( 'Visibility conditions', 'supportcandy' ) ); ?>
    266255                <input type="hidden" name="action" value="wpsc_set_add_new_tff">
    267256                <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_add_new_tff' ) ); ?>">
    268257            </form>
    269             <div class="wpsc-form-filter-snippet" style="display:none;">
    270                 <div class="wpsc-form-filter-item">
    271                     <div class="content">
    272                         <div class="item">
    273                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    274                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    275                                 <?php
    276                                 foreach ( $custom_fields as $cf ) {
    277                                     if (
    278                                         class_exists( $cf->type ) &&
    279                                         in_array( $cf->field, WPSC_CF_Settings::$allowed_modules['ticket-form-visibility-conditions'] ) &&
    280                                         $cf->type::$is_visibility_conditions ) {
    281                                         ?>
    282 
    283                                         <option value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
    284                                         <?php
    285                                     }
    286                                 }
    287                                 ?>
    288                             </select>
    289                         </div>
    290                     </div>
    291                     <div class="remove-container">
    292                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    293                     </div>
    294                 </div>
    295             </div>
    296258            <?php
    297259            $body = ob_get_clean();
     
    350312            $is_required = isset( $_POST['is-required'] ) ? intval( $_POST['is-required'] ) : 1;
    351313            $width       = isset( $_POST['width'] ) ? sanitize_text_field( wp_unslash( $_POST['width'] ) ) : 'full';
    352             $relation    = isset( $_POST['relation'] ) ? sanitize_text_field( wp_unslash( $_POST['relation'] ) ) : 'AND';
    353             $visibility  = isset( $_POST['visibility'] ) ? sanitize_text_field( wp_unslash( $_POST['visibility'] ) ) : '';
    354314            $load_after  = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__';
     315
     316            $visibility = isset( $_POST['visibility'] ) ? sanitize_text_field( wp_unslash( $_POST['visibility'] ) ) : '';
     317            if ( ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_visibility_conditions', $visibility ) ) {
     318                wp_send_json_error( 'Bad request', 400 );
     319            }
    355320
    356321            $field = apply_filters(
     
    359324                    'is-required' => $is_required,
    360325                    'width'       => $width,
    361                     'relation'    => $relation,
    362326                    'visibility'  => $visibility,
    363327                ),
     
    418382                wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
    419383            }
    420 
    421             $custom_fields = WPSC_Custom_Field::find(
    422                 array(
    423                     'items_per_page' => 0,
    424                     'meta_query'     => array(
    425                         'relation' => 'AND',
    426                         array(
    427                             'slug'    => 'field',
    428                             'compare' => 'IN',
    429                             'val'     => array( 'customer', 'ticket' ),
    430                         ),
    431                     ),
    432                 )
    433             )['results'];
    434384
    435385            $tff = get_option( 'wpsc-tff', array() );
     
    506456                do_action( 'wpsc_get_edit_tff', $field, $cf );
    507457
    508                 if ( ! ( $cf->slug == 'name' || $cf->slug == 'email' ) ) :
    509                     ?>
    510                     <div class="wpsc-input-group">
    511                         <div class="label-container">
    512                             <label for="">
    513                                 <?php esc_attr_e( 'Visibility conditions', 'supportcandy' ); ?>
    514                             </label>
    515                         </div>
    516                         <select name="relation" id="relation" style="width: fit-content; margin: 10px 0px;">
    517                             <option <?php selected( $field['relation'], 'AND' ); ?> value="AND"><?php esc_attr_e( 'AND', 'supportcandy' ); ?></option>
    518                             <option <?php selected( $field['relation'], 'OR' ); ?> value="OR"><?php esc_attr_e( 'OR', 'supportcandy' ); ?></option>
    519                         </select>
    520                         <div class="wpsc-form-filter-container">
    521                             <?php
    522                             $visibility = self::get_visibility( $field, true );
    523                             foreach ( $visibility as $slug => $filter ) :
    524                                 $cff = WPSC_Custom_Field::get_cf_by_slug( $slug );
    525                                 if ( ! $cff ) {
    526                                     continue;
    527                                 }
    528                                 ?>
    529                                 <div class="wpsc-form-filter-item">
    530                                     <div class="content">
    531                                         <div class="item">
    532                                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    533                                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    534                                                 <?php
    535                                                 foreach ( $custom_fields as $cfield ) {
    536 
    537                                                     if ( ! (
    538                                                         class_exists( $cfield->type ) &&
    539                                                         in_array( $cfield->field, WPSC_CF_Settings::$allowed_modules['ticket-form-visibility-conditions'] ) &&
    540                                                         $cfield->type::$is_visibility_conditions
    541                                                     ) ) {
    542                                                         continue;
    543                                                     }
    544                                                     $name = WPSC_Translations::get( 'wpsc-cf-name-' . $cfield->id, stripslashes( $cfield->name ) );
    545                                                     ?>
    546                                                     <option value="<?php echo esc_attr( $cfield->slug ); ?>" <?php selected( $slug, $cfield->slug ); ?>><?php echo esc_attr( $name ); ?></option>
    547                                                     <?php
    548                                                 }
    549                                                 ?>
    550                                             </select>
    551                                             <script>jQuery('.wpsc-form-filter-container').last().find('.cf').selectWoo();</script>
    552                                         </div>
    553                                         <?php
    554                                         $cff->type::get_operators( $cff, $filter );
    555                                         $cff->type::get_operands( $filter['operator'], $cff, $filter );
    556                                         ?>
    557                                     </div>
    558                                     <div class="remove-container">
    559                                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    560                                     </div>
    561                                 </div>
    562                                 <?php
    563                             endforeach
    564                             ?>
    565                         </div>
    566                         <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    567                             <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    568                         </button>
    569                     </div>
    570                     <?php
    571                 endif;
     458                if ( ! ( $cf->slug == 'name' || $cf->slug == 'email' ) ) {
     459                    WPSC_Ticket_Conditions::print( 'visibility', 'wpsc_visibility_conditions', $field['visibility'], false, __( 'Visibility conditions', 'supportcandy' ) );
     460                }
    572461                ?>
    573462                <input type="hidden" name="id" value="<?php echo esc_attr( $cf->id ); ?>">
     
    575464                <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_edit_tff' ) ); ?>">
    576465            </form>
    577             <div class="wpsc-form-filter-snippet" style="display:none;">
    578                 <div class="wpsc-form-filter-item">
    579                     <div class="content">
    580                         <div class="item">
    581                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    582                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    583                                     <?php
    584                                     foreach ( $custom_fields as $cf ) :
    585                                         if (
    586                                             class_exists( $cf->type ) &&
    587                                             in_array( $cf->field, WPSC_CF_Settings::$allowed_modules['ticket-form-visibility-conditions'] ) &&
    588                                             $cf->type::$is_visibility_conditions ) :
    589                                             ?>
    590                                             <option value="<?php echo esc_attr( $cf->slug ); ?>">
    591                                                 <?php
    592                                                 echo esc_attr( $cf->name ) ? esc_attr( WPSC_Translations::get( 'wpsc-cf-name-' . $cf->id, esc_attr( $cf->name ) ) ) : esc_attr( $cf->name );
    593                                                 ?>
    594                                             </option>
    595                                             <?php
    596                                         endif;
    597                                     endforeach;
    598                                     ?>
    599                             </select>
    600                         </div>
    601                     </div>
    602                     <div class="remove-container">
    603                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    604                     </div>
    605                 </div>
    606             </div>
    607466            <?php
    608467            $body = ob_get_clean();
     
    659518            }
    660519
     520            $visibility = isset( $_POST['visibility'] ) ? sanitize_text_field( wp_unslash( $_POST['visibility'] ) ) : '';
     521            if ( ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_visibility_conditions', $visibility ) ) {
     522                wp_send_json_error( 'Bad request', 400 );
     523            }
     524
    661525            // unset from tff so that load after should work.
    662526            unset( $tff[ $cf->slug ] );
     
    667531                    'is-required' => isset( $_POST['is-required'] ) ? intval( $_POST['is-required'] ) : 1,
    668532                    'width'       => isset( $_POST['width'] ) ? sanitize_text_field( wp_unslash( $_POST['width'] ) ) : 'full',
    669                     'relation'    => isset( $_POST['relation'] ) ? sanitize_text_field( wp_unslash( $_POST['relation'] ) ) : 'AND',
    670                     'visibility'  => isset( $_POST['visibility'] ) ? sanitize_text_field( wp_unslash( $_POST['visibility'] ) ) : '',
     533                    'visibility'  => $visibility,
    671534                ),
    672535                $cf
     
    741604        public static function get_visibility( $tff, $is_array = false ) {
    742605
    743             $visibility = html_entity_decode( $tff['visibility'] );
     606            $visibility = $tff['visibility'] ? html_entity_decode( $tff['visibility'] ) : '';
    744607            if ( $is_array ) {
    745608                return $visibility ? json_decode( $visibility, true ) : array();
     
    763626            }
    764627        }
     628
     629        /**
     630         * Filter conditions for visibility
     631         *
     632         * @param array $conditions - conditions to filter.
     633         * @return array
     634         */
     635        public static function visibility_conditions( $conditions ) {
     636
     637            foreach ( $conditions as $slug => $item ) {
     638
     639                if ( $item['type'] == 'cf' ) {
     640
     641                    $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
     642                    if (
     643                        ! $cf->type::$is_visibility_conditions ||
     644                        ! in_array( $cf->field, array( 'ticket', 'customer' ) )
     645                    ) {
     646                        unset( $conditions[ $slug ] );
     647                    }
     648                } else { // not custom field type.
     649
     650                    unset( $conditions[ $slug ] );
     651                }
     652            }
     653
     654            return $conditions;
     655        }
    765656    }
    766657endif;
  • supportcandy/trunk/includes/admin/email-notifications/class-wpsc-en-settings-tn.php

    r2822852 r2895557  
    1616
    1717        /**
    18          * Ignore ticket custom field types for email notifications
    19          *
    20          * @var array
    21          */
    22         public static $ignore_cft = array();
    23 
    24         /**
    2518         * Ignore current user recipient from these events
    2619         *
     
    5649            // clone.
    5750            add_action( 'wp_ajax_wpsc_en_clone_ticket_notification', array( __CLASS__, 'clone_ticket_notification' ) );
     51
     52            // filter conditions.
     53            add_filter( 'wpsc_en_conditions', array( __CLASS__, 'filter_conditions' ) );
    5854        }
    5955
     
    7470         */
    7571        public static function load_ignore_list() {
    76 
    77             self::$ignore_cft = apply_filters(
    78                 'wpsc_ignore_email_notification_conditions',
    79                 array(
    80                     'df_last_reply_on',
    81                     'df_last_reply_by',
    82                 )
    83             );
    8472
    8573            self::$ignore_current_user = apply_filters(
     
    301289                    'custom'             => array(),
    302290                ),
    303                 'relation'   => 'AND',
    304291                'conditions' => '',
    305292            );
     
    494481                </div>
    495482
    496                 <?php WPSC_Ticket_Conditions::print_condition_input( $et['relation'], $et['conditions'], self::$ignore_cft ); ?>
    497 
    498                 <?php do_action( 'wpsc_get_add_ticket_notification' ); ?>
     483                <?php WPSC_Ticket_Conditions::print( 'conditions', 'wpsc_en_conditions', $et['conditions'] ); ?>
     484
     485                <?php do_action( 'wpsc_get_edit_ticket_notification', $et ); ?>
    499486                <input type="hidden" name="action" value="wpsc_en_set_edit_ticket_notification">
    500487                <input type="hidden" name="template_id" value="<?php echo esc_attr( $template_id ); ?>">
     
    503490
    504491            </form>
    505 
    506             <div class="wpsc-form-filter-snippet" style="display:none;">
    507                 <?php WPSC_Ticket_Conditions::print_add_new_snippet( self::$ignore_cft ); ?>
    508             </div>
    509492
    510493            <div class="setting-footer-actions">
     
    615598            );
    616599
    617             // relation.
    618             $relation       = isset( $_POST['relation'] ) ? sanitize_text_field( wp_unslash( $_POST['relation'] ) ) : 'AND';
    619             $et['relation'] = $relation;
    620 
    621600            // conditions.
    622             $conditions       = isset( $_POST['conditions'] ) ? sanitize_text_field( wp_unslash( $_POST['conditions'] ) ) : '';
     601            $conditions = isset( $_POST['conditions'] ) ? sanitize_text_field( wp_unslash( $_POST['conditions'] ) ) : '';
     602            if ( ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_en_conditions', $conditions ) ) {
     603                wp_send_json_error( 'Bad request', 400 );
     604            }
    623605            $et['conditions'] = $conditions;
    624606
     
    828810            wp_die();
    829811        }
     812
     813        /**
     814         * Filter conditions for email templates
     815         *
     816         * @param array $conditions - all possible ticket conditions.
     817         * @return array
     818         */
     819        public static function filter_conditions( $conditions ) {
     820
     821            $ignore_list = apply_filters(
     822                'wpsc_en_conditions_ignore_list',
     823                array(
     824                    'cft'   => array( 'df_last_reply_by', 'df_last_reply_on', 'cf_woo_order', 'cf_edd_order' ), // custom field types.
     825                    'other' => array(), // other(custom) condition slug.
     826                )
     827            );
     828
     829            foreach ( $conditions as $slug => $item ) {
     830
     831                if ( $item['type'] == 'cf' ) {
     832
     833                    $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
     834                    if ( in_array( $cf->type::$slug, $ignore_list['cft'] ) ) {
     835                        unset( $conditions[ $slug ] );
     836                    }
     837                } else {
     838
     839                    if ( in_array( $slug, $ignore_list['other'] ) ) {
     840                        unset( $conditions[ $slug ] );
     841                    }
     842                }
     843            }
     844
     845            return $conditions;
     846        }
    830847    }
    831848endif;
  • supportcandy/trunk/includes/admin/ticket-list/class-wpsc-agent-ticket-list-settings.php

    r2822852 r2895557  
    493493                    </select>
    494494                </div>
    495                 <div class="wpsc-input-group">
    496                     <div class="label-container">
    497                         <label for="">
    498                             <?php esc_attr_e( 'Filters', 'supportcandy' ); ?>
    499                             <span class="required-char">*</span>
    500                         </label>
    501                     </div>
    502                     <div class="wpsc-form-filter-container"></div>
    503                     <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    504                         <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    505                     </button>
    506                 </div>
     495                <?php WPSC_Ticket_Conditions::print( 'default_filters', 'wpsc_default_filter_conditions', '', true, __( 'Filters', 'supportcandy' ) ); ?>
    507496                <div class="wpsc-input-group">
    508497                    <div class="label-container">
     
    548537                <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_add_atl_default_filter' ) ); ?>">
    549538            </form>
    550             <div class="wpsc-form-filter-snippet" style="display:none;">
    551                 <div class="wpsc-form-filter-item">
    552                     <div class="content">
    553                         <div class="item">
    554                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    555                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    556                                 <?php
    557                                 foreach ( $custom_fields as $cf ) {
    558                                     if ( $cf->type::$is_filter ) {
    559                                         ?>
    560                                         <option value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
    561                                         <?php
    562                                     }
    563                                 }
    564                                 ?>
    565                             </select>
    566                         </div>
    567                     </div>
    568                     <div class="remove-container">
    569                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    570                     </div>
    571                 </div>
    572             </div>
    573539            <?php
    574540            $body = ob_get_clean();
     
    619585
    620586            $filters = isset( $_POST['filters'] ) ? sanitize_text_field( wp_unslash( $_POST['filters'] ) ) : '';
    621             if ( ! $filters ) {
    622                 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
     587            if ( ! $filters || $filters == '[]' || ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_default_filter_conditions', $filters ) ) {
     588                wp_send_json_error( 'Bad request', 400 );
    623589            }
    624590
     
    713679                        </select>
    714680                    </div>
    715                     <div class="wpsc-input-group">
    716                         <div class="label-container">
    717                             <label for="">
    718                                 <?php esc_attr_e( 'Filters', 'supportcandy' ); ?>
    719                                 <span class="required-char">*</span>
    720                             </label>
    721                         </div>
    722                         <div class="wpsc-form-filter-container">
    723                             <?php
    724                             $filters = json_decode( html_entity_decode( $atl_filter['filters'] ), true );
    725                             if ( ! $filters ) {
    726                                 $filters = array();
    727                             }
    728                             foreach ( $filters as $slug => $filter ) :
    729                                 $cff = WPSC_Custom_Field::get_cf_by_slug( $slug );
    730                                 if ( ! $cff ) {
    731                                     continue;
    732                                 }
    733                                 ?>
    734                                 <div class="wpsc-form-filter-item">
    735                                     <div class="content">
    736                                         <div class="item">
    737                                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    738                                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    739                                                 <?php
    740                                                 foreach ( $custom_fields as $cfield ) :
    741                                                     if ( $cfield->type::$is_filter ) :
    742                                                         $selected = $slug == $cfield->slug ? 'selected="selected"' : ''
    743                                                         ?>
    744                                                         <option value="<?php echo esc_attr( $cfield->slug ); ?>" <?php echo esc_attr( $selected ); ?>><?php echo esc_attr( $cfield->name ); ?></option>
    745                                                         <?php
    746                                                     endif;
    747                                                 endforeach;
    748                                                 ?>
    749                                             </select>
    750                                             <script>jQuery('.wpsc-form-filter-container').last().find('.cf').selectWoo();</script>
    751                                         </div>
    752                                         <?php
    753                                         $cff->type::get_operators( $cff, $filter );
    754                                         $cff->type::get_operands( $filter['operator'], $cff, $filter );
    755                                         ?>
    756                                     </div>
    757                                     <div class="remove-container">
    758                                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    759                                     </div>
    760                                 </div>
    761                                 <?php
    762                             endforeach
    763                             ?>
    764                         </div>
    765                         <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    766                             <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    767                         </button>
    768                     </div>
     681                    <?php WPSC_Ticket_Conditions::print( 'default_filters', 'wpsc_default_filter_conditions', $atl_filter['filters'], true, __( 'Filters', 'supportcandy' ) ); ?>
    769682                    <div class="wpsc-input-group">
    770683                        <div class="label-container">
     
    814727                <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_edit_atl_default_filter' ) ); ?>">
    815728            </form>
    816             <div class="wpsc-form-filter-snippet" style="display:none;">
    817                 <div class="wpsc-form-filter-item">
    818                     <div class="content">
    819                         <div class="item">
    820                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    821                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    822                                 <?php
    823                                 foreach ( $custom_fields as $cf ) :
    824                                     if ( $cf->type::$is_filter ) :
    825                                         ?>
    826                                         <option value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
    827                                         <?php
    828                                     endif;
    829                                 endforeach;
    830                                 ?>
    831                             </select>
    832                         </div>
    833                     </div>
    834                     <div class="remove-container">
    835                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    836                     </div>
    837                 </div>
    838             </div>
    839729            <?php
    840730            $body = ob_get_clean();
     
    910800
    911801            $filters = isset( $_POST['filters'] ) ? sanitize_text_field( wp_unslash( $_POST['filters'] ) ) : '';
    912             if ( ! $filters ) {
    913                 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
     802            if ( ! $filters || $filters == '[]' || ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_default_filter_conditions', $filters ) ) {
     803                wp_send_json_error( 'Bad request', 400 );
    914804            }
    915805
  • supportcandy/trunk/includes/admin/ticket-list/class-wpsc-customer-ticket-list-settings.php

    r2822852 r2895557  
    492492                    </select>
    493493                </div>
    494                 <div class="wpsc-input-group">
    495                     <div class="label-container">
    496                         <label for="">
    497                             <?php esc_attr_e( 'Filters', 'supportcandy' ); ?>
    498                             <span class="required-char">*</span>
    499                         </label>
    500                     </div>
    501                     <div class="wpsc-form-filter-container"></div>
    502                     <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    503                         <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    504                     </button>
    505                 </div>
     494                <?php WPSC_Ticket_Conditions::print( 'default_filters', 'wpsc_default_filter_conditions', '', true, __( 'Filters', 'supportcandy' ) ); ?>
    506495                <div class="wpsc-input-group">
    507496                    <div class="label-container">
     
    547536                <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_add_ctl_default_filter' ) ); ?>">
    548537            </form>
    549             <div class="wpsc-form-filter-snippet" style="display:none;">
    550                 <div class="wpsc-form-filter-item">
    551                     <div class="content">
    552                         <div class="item">
    553                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    554                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    555                                 <?php
    556                                 foreach ( $custom_fields as $cf ) :
    557                                     if ( $cf->type::$is_filter ) :
    558                                         ?>
    559                                         <option value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
    560                                         <?php
    561                                     endif;
    562                                 endforeach;
    563                                 ?>
    564                             </select>
    565                         </div>
    566                     </div>
    567                     <div class="remove-container">
    568                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    569                     </div>
    570                 </div>
    571             </div>
    572538            <?php
    573539            $body = ob_get_clean();
     
    618584
    619585            $filters = isset( $_POST['filters'] ) ? sanitize_text_field( wp_unslash( $_POST['filters'] ) ) : '';
    620             if ( ! $filters ) {
    621                 wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
     586            if ( ! $filters || $filters == '[]' || ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_default_filter_conditions', $filters ) ) {
     587                wp_send_json_error( 'Bad request', 400 );
    622588            }
    623589
     
    712678                        </select>
    713679                    </div>
    714                     <div class="wpsc-input-group">
    715                         <div class="label-container">
    716                             <label for="">
    717                                 <?php esc_attr_e( 'Filters', 'supportcandy' ); ?>
    718                                 <span class="required-char">*</span>
    719                             </label>
    720                         </div>
    721                         <div class="wpsc-form-filter-container">
    722                         <?php
    723                             $filters = json_decode( html_entity_decode( $ctl_filter['filters'] ), true );
    724                         if ( ! $filters ) {
    725                             $filters = array();
    726                         }
    727                         foreach ( $filters as $slug => $filter ) :
    728                             $cff = WPSC_Custom_Field::get_cf_by_slug( $slug );
    729                             if ( ! $cff ) {
    730                                 continue;
    731                             }
    732                             ?>
    733                             <div class="wpsc-form-filter-item">
    734                                 <div class="content">
    735                                     <div class="item">
    736                                         <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    737                                             <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    738                                             <?php
    739                                             foreach ( $custom_fields as $cfield ) :
    740                                                 if ( $cfield->type::$is_filter ) :
    741                                                     ?>
    742                                                     <option value="<?php echo esc_attr( $cfield->slug ); ?>" <?php selected( $slug, $cfield->slug ); ?>><?php echo esc_attr( $cfield->name ); ?></option>
    743                                                     <?php
    744                                                 endif;
    745                                             endforeach;
    746                                             ?>
    747                                         </select>
    748                                         <script>jQuery('.wpsc-form-filter-container').last().find('.cf').selectWoo();</script>
    749                                     </div>
    750                                     <?php
    751                                     $cff->type::get_operators( $cff, $filter );
    752                                     $cff->type::get_operands( $filter['operator'], $cff, $filter );
    753                                     ?>
    754                                 </div>
    755                                 <div class="remove-container">
    756                                     <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    757                                 </div>
    758                             </div>
    759                             <?php
    760                         endforeach
    761                         ?>
    762                         </div>
    763                         <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    764                             <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    765                         </button>
    766                     </div>
     680                    <?php WPSC_Ticket_Conditions::print( 'default_filters', 'wpsc_default_filter_conditions', $ctl_filter['filters'], true, __( 'Filters', 'supportcandy' ) ); ?>
    767681                    <div class="wpsc-input-group">
    768682                        <div class="label-container">
     
    812726                <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_edit_ctl_default_filter' ) ); ?>">
    813727            </form>
    814             <div class="wpsc-form-filter-snippet" style="display:none;">
    815                 <div class="wpsc-form-filter-item">
    816                     <div class="content">
    817                         <div class="item">
    818                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    819                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    820                                 <?php
    821                                 foreach ( $custom_fields as $cf ) :
    822                                     if ( $cf->type::$is_filter ) :
    823                                         ?>
    824                                         <option value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
    825                                         <?php
    826                                     endif;
    827                                 endforeach;
    828                                 ?>
    829                             </select>
    830                         </div>
    831                     </div>
    832                     <div class="remove-container">
    833                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    834                     </div>
    835                 </div>
    836             </div>
    837728            <?php
    838729            $body = ob_get_clean();
  • supportcandy/trunk/includes/admin/ticket-list/class-wpsc-ticket-list-settings.php

    r2763565 r2895557  
    4747            // Register ready function.
    4848            add_action( 'wpsc_js_ready', array( __CLASS__, 'register_js_ready_function' ) );
     49
     50            // default filter conditions.
     51            add_filter( 'wpsc_default_filter_conditions', array( __CLASS__, 'default_filter_conditions' ) );
    4952        }
    5053
     
    220223            echo esc_attr( self::$sections[ self::$current_section ]['callback'] ) . '();' . PHP_EOL;
    221224        }
     225
     226        /**
     227         * Default filter conditions
     228         *
     229         * @param array $conditions - conditions array.
     230         * @return array
     231         */
     232        public static function default_filter_conditions( $conditions ) {
     233
     234            foreach ( $conditions as $slug => $item ) {
     235
     236                if ( $item['type'] == 'cf' ) {
     237
     238                    $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
     239                    if (
     240                        ! $cf->type::$is_filter ||
     241                        ! in_array( $cf->field, array( 'ticket', 'customer', 'agentonly' ) )
     242                    ) {
     243                        unset( $conditions[ $slug ] );
     244                    }
     245                } else { // not custom field type.
     246
     247                    unset( $conditions[ $slug ] );
     248                }
     249            }
     250
     251            return $conditions;
     252        }
    222253    }
    223254endif;
  • supportcandy/trunk/includes/admin/tickets/class-wpsc-new-ticket.php

    r2873748 r2895557  
    637637                }
    638638
    639                 $flag = $settings['relation'] == 'OR' ? false : true;
    640                 foreach ( $visibility as $key => $condition ) {
    641 
    642                     $cf = WPSC_Custom_Field::get_cf_by_slug( $key );
    643                     if ( ! $cf ) {
    644                         continue;
     639                $flag = true;
     640                foreach ( $visibility as $and_condition ) {
     641
     642                    $temp = false;
     643                    foreach ( $and_condition as $or_condition ) {
     644
     645                        if ( ! isset( WPSC_Ticket_Conditions::$conditions[ $or_condition['slug'] ] ) ) {
     646                            continue;
     647                        }
     648
     649                        $cf = WPSC_Custom_Field::get_cf_by_slug( $or_condition['slug'] );
     650                        $value = $cf->type::get_tff_value( $cf->slug, $cf );
     651                        if ( $cf->type::is_valid( $or_condition, $cf, $value ) ) {
     652                            $temp = true;
     653                            break;
     654                        }
    645655                    }
    646                     $value = $cf->type::get_tff_value( $cf->slug, $cf );
    647                     $is_valid = $cf->type::is_valid( $condition, $cf, $value );
    648                     if ( $settings['relation'] == 'OR' && $is_valid ) {
    649                         $flag = true;
    650                         break;
    651                     } elseif ( $settings['relation'] == 'AND' && ! $is_valid ) {
     656
     657                    if ( ! $temp ) {
    652658                        $flag = false;
    653659                        break;
  • supportcandy/trunk/includes/admin/tickets/class-wpsc-ticket-list.php

    r2873748 r2895557  
    116116            add_action( 'wp_ajax_wpsc_get_ticket_list', array( __CLASS__, 'layout' ) );
    117117            add_action( 'wp_ajax_nopriv_wpsc_get_ticket_list', array( __CLASS__, 'layout' ) );
     118
     119            // Conditions allowed for custom ticket filters.
     120            add_filter( 'wpsc_custom_filter_conditions', array( __CLASS__, 'custom_filter_conditions' ) );
    118121
    119122            // Get tickets ajax request.
     
    184187            self::load_tickets();
    185188            self::set_bulk_actions();
     189            $filters = self::$cookie_filters;
     190            $filters['filters'] = isset( $filters['filters'] ) ? $filters['filters'] : '[]';
     191
    186192            $response = array(
    187193                'tickets'        => self::print_tickets(),
     
    195201                    'total_items'   => self::$total_items,
    196202                ),
    197                 'filters'        => self::$cookie_filters,
     203                'filters'        => $filters,
    198204            );
    199205            wp_send_json( $response );
     
    228234
    229235            $customer_view = get_option( 'wpsc-tl-ms-customer-view', array() );
    230             self::$more_settings = $current_user->is_agent ? get_option( 'wpsc-tl-ms-agent-view' ) : get_option( 'wpsc-tl-ms-customer-view' );
     236            self::$more_settings = get_option( $current_user->is_agent ? 'wpsc-tl-ms-agent-view' : 'wpsc-tl-ms-customer-view' );
    231237
    232238            $current_user_filters = $current_user->get_tl_filters();
    233239            self::$default_filters = $current_user_filters['default'];
    234240            self::$saved_filters = $current_user_filters['saved'];
    235 
    236             if ( isset( $filters['filters'] ) ) {
    237                 if ( ! is_array( $filters['filters'] ) ) {
    238                     $filters['filters'] = json_decode( html_entity_decode( $filters['filters'] ), true );
    239                 }
    240             }
    241241
    242242            if ( ! $filters || ! self::has_filter_access( $filters ) ) {
     
    327327
    328328                if ( self::$default_flag ) {
    329                     $filters_arr = json_decode( html_entity_decode( self::$default_filters[ $slug ]['filters'] ), true );
    330                     $meta_query  = array_merge( $meta_query, self::get_meta_query( $filters_arr ) );
     329                    $meta_query = array_merge( $meta_query, WPSC_Ticket_Conditions::get_meta_query( self::$default_filters[ $slug ]['filters'] ) );
    331330                }
    332331
    333332                if ( self::$saved_flag ) {
    334                     $filters_str = self::$saved_filters[ $slug ]['filters'];
    335                     $filters_str = str_replace( '^^', '\n', $filters_str );
    336                     $filters_arr = json_decode( html_entity_decode( $filters_str ), true );
    337                     $meta_query  = array_merge( $meta_query, self::get_meta_query( $filters_arr ) );
     333                    $json_str = str_replace( PHP_EOL, '\n', self::$saved_filters[ $slug ]['filters'] );
     334                    $meta_query = array_merge( $meta_query, WPSC_Ticket_Conditions::get_meta_query( $json_str, true ) );
    338335                }
    339336
    340337                if ( $filters['filterSlug'] == 'custom' ) {
    341                     $meta_query = array_merge( $meta_query, self::get_meta_query( $filters['filters'] ) );
     338                    $meta_query = array_merge( $meta_query, WPSC_Ticket_Conditions::get_meta_query( $filters['filters'], true ) );
    342339                }
    343340            }
     
    807804        public static function print_tl_snippets() {
    808805
     806            $filters = self::$cookie_filters;
     807            $filter_json = isset( $filters['filters'] ) && $filters['filters'] ? $filters['filters'] : '[]';
     808            $filters['filters'] = $filter_json;
     809
    809810            $ticket_list_js_vars = array(
    810811                'pagination' => array(
     
    814815                    'total_items'   => self::$total_items,
    815816                ),
    816                 'filters'    => self::$cookie_filters,
     817                'filters'    => $filters,
    817818            );
    818819
     
    847848                <script>
    848849                    supportcandy.ticketList = <?php echo wp_json_encode( $ticket_list_js_vars ); ?>;
    849                     if (typeof supportcandy.ticketList.filters.filters != 'undefined') {
    850                         supportcandy.ticketList.filters.filters = JSON.stringify(supportcandy.ticketList.filters.filters);
    851                     }
    852850                    supportcandy.tl_auto_refresh = <?php echo esc_attr( $advanced_settings['auto-refresh-list-status'] ); ?>;
    853851                    if(supportcandy.tl_auto_refresh) { wpsc_tl_auto_refresh(); }
     
    888886            }
    889887
    890             if ( $filter_slug == 'custom' && $current_user->is_agent ) {
    891 
    892                 if ( ! isset( $filters['filters'] ) || ! isset( $filters['parent-filter'] ) ) {
    893                     return false;
    894                 }
    895                 $filter_items = get_option( 'wpsc-atl-filter-items' );
    896                 foreach ( $filters['filters'] as $slug => $condition ) {
    897                     if ( ! in_array( $slug, $filter_items ) ) {
    898                         return false;
    899                     }
    900                 }
    901                 return true;
    902             }
    903 
    904             if ( $filter_slug == 'custom' && ! $current_user->is_agent ) {
    905 
    906                 if ( ! isset( $filters['filters'] ) || ! isset( $filters['parent-filter'] ) ) {
    907                     return false;
    908                 }
    909                 $filter_items = get_option( 'wpsc-ctl-filter-items' );
    910                 foreach ( $filters['filters'] as $slug => $condition ) {
    911                     if ( ! in_array( $slug, $filter_items ) ) {
    912                         return false;
    913                     }
    914                 }
     888            if ( $filter_slug == 'custom' && WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_custom_filter_conditions', $filters['filters'] ) ) {
    915889                return true;
    916890            }
     
    10301004                    }
    10311005
    1032                     $filters_json = self::$default_filters[ $parent_slug ]['filters'];
    1033                     $parent_slug  = self::$default_filters[ $parent_slug ]['parent-filter'];
    1034                     $meta_query   = array_merge( $meta_query, self::get_parent_meta_query( $parent_slug ) );
    1035                     $filters_arr  = json_decode( stripslashes( $filters_json ), true );
    1036                     $meta_query   = array_merge( $meta_query, self::get_meta_query( $filters_arr ) );
     1006                    $meta_query = array_merge( $meta_query, self::get_parent_meta_query( self::$default_filters[ $parent_slug ]['parent-filter'] ) );
     1007                    $meta_query = array_merge( $meta_query, WPSC_Ticket_Conditions::get_meta_query( self::$default_filters[ $parent_slug ]['filters'] ) );
    10371008            }
    10381009
     
    10571028
    10581029            $title           = esc_attr__( 'Custom filter', 'supportcandy' );
    1059             $custom_fields   = WPSC_Custom_Field::$custom_fields;
    1060             $default_filters = $current_user->is_agent ? get_option( 'wpsc-atl-default-filters' ) : get_option( 'wpsc-atl-default-filters' );
    1061             $allowed_filters = $current_user->is_agent ? get_option( 'wpsc-atl-filter-items' ) : get_option( 'wpsc-ctl-filter-items' );
     1030            $default_filters = get_option( $current_user->is_agent ? 'wpsc-atl-default-filters' : 'wpsc-ctl-default-filters' );
    10621031            $list_items      = $current_user->get_tl_list_items();
    1063             $more_settings   = $current_user->is_agent ? get_option( 'wpsc-tl-ms-agent-view' ) : get_option( 'wpsc-tl-ms-customer-view' );
     1032            $more_settings   = get_option( $current_user->is_agent ? 'wpsc-tl-ms-agent-view' : 'wpsc-tl-ms-customer-view' );
    10641033
    10651034            // check whether filters are passed.
    10661035            $filters = isset( $_POST['filters'] ) ? map_deep( wp_unslash( $_POST['filters'] ), 'sanitize_text_field' ) : array();
     1036            $custom_filters = isset( $filters['filters'] ) && WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_custom_filter_conditions', $filters['filters'] ) ? $filters['filters'] : '';
    10671037
    10681038            ob_start();
     
    10901060                    </select>
    10911061                </div>
    1092                 <div class="wpsc-input-group">
    1093                     <div class="label-container">
    1094                         <label for="">
    1095                             <?php esc_attr_e( 'Filters', 'supportcandy' ); ?>
    1096                             <span class="required-char">*</span>
    1097                         </label>
    1098                     </div>
    1099                     <div class="wpsc-form-filter-container">
    1100                         <?php
    1101                         $meta_filters = isset( $filters['filters'] ) ? json_decode( html_entity_decode( $filters['filters'] ), true ) : array();
    1102                         foreach ( $meta_filters as $slug => $filter ) :
    1103                             $cff = WPSC_Custom_Field::get_cf_by_slug( $slug );
    1104                             if ( ! $cff ) {
    1105                                 continue;
    1106                             }
    1107                             ?>
    1108                             <div class="wpsc-form-filter-item">
    1109                                 <div class="content">
    1110                                     <div class="item">
    1111                                         <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    1112                                             <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    1113                                             <?php
    1114                                             foreach ( $custom_fields as $cfield ) :
    1115                                                 if ( $cfield->type::$is_filter && in_array( $cfield->slug, $allowed_filters ) ) :
    1116                                                     ?>
    1117                                                     <option value="<?php echo esc_attr( $cfield->slug ); ?>" <?php selected( $slug, $cfield->slug ); ?>><?php echo esc_attr( $cfield->name ); ?></option>
    1118                                                     <?php
    1119                                                 endif;
    1120                                             endforeach;
    1121                                             ?>
    1122                                         </select>
    1123                                         <script>jQuery('.wpsc-form-filter-container').last().find('.cf').selectWoo();</script>
    1124                                     </div>
    1125                                     <?php
    1126                                     $cff->type::get_operators( $cff, $filter );
    1127                                     $cff->type::get_operands( $filter['operator'], $cff, $filter );
    1128                                     ?>
    1129                                 </div>
    1130                                 <div class="remove-container">
    1131                                     <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    1132                                 </div>
    1133                             </div>
    1134                             <?php
    1135                         endforeach
    1136                         ?>
    1137                     </div>
    1138                     <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    1139                         <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    1140                     </button>
    1141                 </div>
     1062                <?php WPSC_Ticket_Conditions::print( 'custom_filters', 'wpsc_custom_filter_conditions', $custom_filters, true, __( 'Filters', 'supportcandy' ) ); ?>
    11421063                <div class="wpsc-input-group">
    11431064                    <div class="label-container">
     
    11801101                </div>
    11811102            </form>
    1182             <div class="wpsc-form-filter-snippet" style="display:none;">
    1183                 <div class="wpsc-form-filter-item">
    1184                     <div class="content">
    1185                         <div class="item">
    1186                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    1187                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    1188                                 <?php
    1189                                 foreach ( $custom_fields as $cf ) :
    1190                                     if ( in_array( $cf->slug, $allowed_filters ) ) :
    1191                                         ?>
    1192                                         <option value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
    1193                                         <?php
    1194                                     endif;
    1195                                 endforeach;
    1196                                 ?>
    1197                             </select>
    1198                         </div>
    1199                     </div>
    1200                     <div class="remove-container">
    1201                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    1202                     </div>
    1203                 </div>
    1204             </div>
    12051103            <?php
    12061104            $body = ob_get_clean();
     
    13111209            }
    13121210
    1313             $filters = isset( $_POST['filters']['filters'] ) ? sanitize_textarea_field( wp_unslash( $_POST['filters']['filters'] ) ) : '';
    1314             $filters = str_replace( '\n', '^^', $filters );
    1315             if ( ! $filters ) {
     1211            $filters = isset( $_POST['filters']['filters'] ) ? sanitize_text_field( wp_unslash( $_POST['filters']['filters'] ) ) : '';
     1212            if ( ! $filters || $filters == '[]' || ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_custom_filter_conditions', $filters ) ) {
    13161213                wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
    13171214            }
     1215
     1216            $filters = str_replace( '\n', PHP_EOL, $filters );
    13181217
    13191218            $sort_by = isset( $_POST['filters']['orderby'] ) ? sanitize_text_field( wp_unslash( $_POST['filters']['orderby'] ) ) : '';
     
    13721271
    13731272            $title           = $filters['label'];
    1374             $custom_fields   = WPSC_Custom_Field::$custom_fields;
    13751273            $default_filters = $current_user->is_agent ? get_option( 'wpsc-atl-default-filters' ) : get_option( 'wpsc-atl-default-filters' );
    1376             $allowed_filters = $current_user->is_agent ? get_option( 'wpsc-atl-filter-items' ) : get_option( 'wpsc-ctl-filter-items' );
    13771274            $list_items      = $current_user->get_tl_list_items();
    13781275            $more_settings   = $current_user->is_agent ? get_option( 'wpsc-tl-ms-agent-view' ) : get_option( 'wpsc-tl-ms-customer-view' );
     1276            $custom_filters = str_replace( PHP_EOL, '\n', $filters['filters'] );
    13791277
    13801278            ob_start();
     
    14081306                    </select>
    14091307                </div>
    1410                 <div class="wpsc-input-group">
    1411                     <div class="label-container">
    1412                         <label for="">
    1413                             <?php esc_attr_e( 'Filters', 'supportcandy' ); ?>
    1414                             <span class="required-char">*</span>
    1415                         </label>
    1416                     </div>
    1417                     <div class="wpsc-form-filter-container">
    1418                         <?php
    1419                         $filter_str   = str_replace( '^^', '\n', $filters['filters'] );
    1420                         $meta_filters = isset( $filters['filters'] ) ? json_decode( html_entity_decode( $filter_str ), true ) : array();
    1421                         foreach ( $meta_filters as $slug => $filter ) :
    1422                             $cff = WPSC_Custom_Field::get_cf_by_slug( $slug );
    1423                             if ( ! $cff ) {
    1424                                 continue;
    1425                             }
    1426                             ?>
    1427                             <div class="wpsc-form-filter-item">
    1428                                 <div class="content">
    1429                                     <div class="item">
    1430                                         <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    1431                                             <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    1432                                             <?php
    1433                                             foreach ( $custom_fields as $cfield ) :
    1434                                                 if ( $cfield->type::$is_filter ) :
    1435                                                     ?>
    1436                                                     <option value="<?php echo esc_attr( $cfield->slug ); ?>" <?php selected( $slug, $cfield->slug ); ?>><?php echo esc_attr( $cfield->name ); ?></option>
    1437                                                     <?php
    1438                                                 endif;
    1439                                             endforeach;
    1440                                             ?>
    1441                                         </select>
    1442                                         <script>jQuery('.wpsc-form-filter-container').last().find('.cf').selectWoo();</script>
    1443                                     </div>
    1444                                     <?php
    1445                                     $cff->type::get_operators( $cff, $filter );
    1446                                     $cff->type::get_operands( $filter['operator'], $cff, $filter );
    1447                                     ?>
    1448                                 </div>
    1449                                 <div class="remove-container">
    1450                                     <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    1451                                 </div>
    1452                             </div>
    1453                                 <?php
    1454                         endforeach
    1455                         ?>
    1456                     </div>
    1457                     <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    1458                         <?php esc_attr_e( 'Add new', 'supportcandy' ); ?>
    1459                     </button>
    1460                 </div>
     1308                <?php WPSC_Ticket_Conditions::print( 'custom_filters', 'wpsc_custom_filter_conditions', $custom_filters, true, __( 'Filters', 'supportcandy' ) ); ?>
    14611309                <div class="wpsc-input-group">
    14621310                    <div class="label-container">
     
    15021350                <input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_tl_set_edit_saved_filter' ) ); ?>">
    15031351            </form>
    1504             <div class="wpsc-form-filter-snippet" style="display:none;">
    1505                 <div class="wpsc-form-filter-item">
    1506                     <div class="content">
    1507                         <div class="item">
    1508                             <select class="cf" onchange="wpsc_get_ticket_filter_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operators' ) ); ?>');">
    1509                                 <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    1510                                 <?php
    1511                                 foreach ( $custom_fields as $cf ) :
    1512                                     if ( in_array( $cf->slug, $allowed_filters ) ) :
    1513                                         ?>
    1514                                         <option value="<?php echo esc_attr( $cf->slug ); ?>"><?php echo esc_attr( $cf->name ); ?></option>
    1515                                         <?php
    1516                                     endif;
    1517                                 endforeach;
    1518                                 ?>
    1519                             </select>
    1520                         </div>
    1521                     </div>
    1522                     <div class="remove-container">
    1523                         <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    1524                     </div>
    1525                 </div>
    1526             </div>
    15271352            <?php
    15281353            $body = ob_get_clean();
     
    15841409            }
    15851410
    1586             $filters = isset( $_POST['filters'] ) ? sanitize_textarea_field( wp_unslash( $_POST['filters'] ) ) : '';
    1587             $filters = str_replace( '\n', '^^', $filters );
    1588             if ( ! $filters ) {
     1411            $filters = isset( $_POST['filters'] ) ? sanitize_text_field( wp_unslash( $_POST['filters'] ) ) : '';
     1412            if ( ! $filters || $filters == '[]' || ! WPSC_Ticket_Conditions::is_valid_input_conditions( 'wpsc_custom_filter_conditions', $filters ) ) {
    15891413                wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 );
    15901414            }
     1415
     1416            $filters = str_replace( '\n', PHP_EOL, $filters );
    15911417
    15921418            $sort_by = isset( $_POST['sort-by'] ) ? sanitize_text_field( wp_unslash( $_POST['sort-by'] ) ) : '';
     
    23482174            return self::has_delete_parent_filter( $parent_slug );
    23492175        }
     2176
     2177        /**
     2178         * Allow only allowed conditions for current user for custom ticket filter
     2179         *
     2180         * @param array $conditions - conditions to filter.
     2181         * @return array
     2182         */
     2183        public static function custom_filter_conditions( $conditions ) {
     2184
     2185            $current_user = WPSC_Current_User::$current_user;
     2186            $level = $current_user->level == 'admin' ? 'agent' : $current_user->level;
     2187
     2188            foreach ( $conditions as $slug => $item ) {
     2189
     2190                if ( $item['type'] == 'cf' ) {
     2191
     2192                    $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
     2193                    if (
     2194                        ! $cf->type::$is_filter ||
     2195                        ! in_array( $cf->field, array( 'ticket', 'customer', 'agentonly' ) ) ||
     2196                        ! in_array( $level, $item['levels'] )
     2197                    ) {
     2198                        unset( $conditions[ $slug ] );
     2199                    }
     2200                } else { // not custom field type.
     2201
     2202                    unset( $conditions[ $slug ] );
     2203                }
     2204            }
     2205
     2206            return $conditions;
     2207        }
    23502208    }
    23512209
  • supportcandy/trunk/includes/class-wpsc-current-user.php

    r2890978 r2895557  
    7070         */
    7171        public $agent;
     72
     73        /**
     74         * Current user level. e.g. customer, agent or admin
     75         *
     76         * @var string
     77         */
     78        public $level;
    7279
    7380        /**
     
    145152                $this->agent    = $agent;
    146153            }
     154
     155            // set leval.
     156            if ( WPSC_Functions::is_site_admin() ) {
     157                $this->level = 'admin';
     158            } elseif ( $this->is_agent ) {
     159                $this->level = 'agent';
     160            } elseif ( $this->is_customer ) {
     161                $this->level = 'customer';
     162            } else {
     163                $this->level = 'none';
     164            }
    147165        }
    148166
     
    216234
    217235            // default filters.
    218             $default_filters = $this->is_agent ? get_option( 'wpsc-atl-default-filters' ) : get_option( 'wpsc-ctl-default-filters' );
     236            $default_filters = get_option( $this->is_agent ? 'wpsc-atl-default-filters' : 'wpsc-ctl-default-filters' );
    219237            foreach ( $default_filters as $index => $filter ) {
    220238
  • supportcandy/trunk/includes/class-wpsc-email-notifications.php

    r2887316 r2895557  
    247247
    248248            // check for conditions.
    249             if ( ! WPSC_Ticket_Conditions::is_valid_conditions( $this->ticket, $this->template['conditions'], $this->template['relation'] ) ) {
     249            if ( ! WPSC_Ticket_Conditions::is_valid( $this->template['conditions'], $this->ticket ) ) {
    250250                return false;
    251251            }
  • supportcandy/trunk/includes/class-wpsc-functions.php

    r2891695 r2895557  
    411411            $classes   .= $tff['is-required'] ? 'required ' : '';
    412412            $visibility = WPSC_TFF::get_visibility( $tff, true );
    413             $classes   .= count( $visibility ) > 0 ? 'wpsc-hidden conditional' : 'wpsc-visible';
     413            $classes   .= $visibility ? 'wpsc-hidden conditional' : 'wpsc-visible';
    414414
    415415            return $classes;
  • supportcandy/trunk/includes/class-wpsc-sc-upgrade.php

    r2887316 r2895557  
    99
    1010        /**
    11          * Update usergroups for ticket
     11         * Update attachment file paths in database
    1212         *
    1313         * @param WPSC_Scheduled_Task $task - task object.
     
    4747            }
    4848        }
     49
     50        /**
     51         * Upgrade setting conditions
     52         *
     53         * @param WPSC_Scheduled_Task $task - task object.
     54         * @version 3.1.5
     55         * @return void
     56         */
     57        public static function upgrade_setting_conditions( $task ) {
     58
     59            // Visibility conditions.
     60            $tff = get_option( 'wpsc-tff' );
     61            foreach ( $tff as $slug => $properties ) {
     62                if ( ! $properties['visibility'] ) {
     63                    continue;
     64                }
     65                $tff[ $slug ]['visibility'] = self::upgrade_condition( $properties['visibility'], $properties['relation'] );
     66            }
     67            update_option( 'wpsc-tff', $tff );
     68
     69            // Email notifications.
     70            $email_templates = get_option( 'wpsc-email-templates' );
     71            foreach ( $email_templates as $index => $properties ) {
     72                if ( ! $properties['conditions'] ) {
     73                    continue;
     74                }
     75                $email_templates[ $index ]['conditions'] = self::upgrade_condition( $properties['conditions'], $properties['relation'] );
     76            }
     77            update_option( 'wpsc-email-templates', $email_templates );
     78
     79            // Default agent filters.
     80            $atl_filters = get_option( 'wpsc-atl-default-filters' );
     81            foreach ( $atl_filters as $slug => $properties ) {
     82                if ( ! is_numeric( $slug ) ) {
     83                    continue;
     84                }
     85                $atl_filters[ $slug ]['filters'] = self::upgrade_condition( $properties['filters'], 'AND' );
     86            }
     87            update_option( 'wpsc-atl-default-filters', $atl_filters );
     88
     89            // Default customer filters.
     90            $ctl_filters = get_option( 'wpsc-ctl-default-filters' );
     91            foreach ( $ctl_filters as $slug => $properties ) {
     92                if ( ! is_numeric( $slug ) ) {
     93                    continue;
     94                }
     95                $ctl_filters[ $slug ]['filters'] = self::upgrade_condition( $properties['filters'], 'AND' );
     96            }
     97            update_option( 'wpsc-ctl-default-filters', $ctl_filters );
     98
     99            // Assigned agent rules filters.
     100            if ( class_exists( 'WPSC_AAR' ) ) {
     101                $rules = get_option( 'wpsc-aar-rules', array() );
     102                foreach ( $rules as $index => $properties ) {
     103                    $rules[ $index ]['conditions'] = self::upgrade_condition( $properties['conditions'], $properties['relation'] );
     104                }
     105                update_option( 'wpsc-aar-rules', $rules );
     106            }
     107
     108            // SLA policy filters.
     109            if ( class_exists( 'WPSC_SLA' ) ) {
     110                $policies = get_option( 'wpsc-sla-policies', array() );
     111                foreach ( $policies as $index => $properties ) {
     112                    $policies[ $index ]['conditions'] = self::upgrade_condition( $properties['conditions'], $properties['relation'] );
     113                }
     114                update_option( 'wpsc-sla-policies', $policies );
     115            }
     116
     117            WPSC_Scheduled_Task::destroy( $task );
     118        }
     119
     120        /**
     121         * Upgrade saved filter conditions for all customers
     122         *
     123         * @param WPSC_Scheduled_Task $task - task object.
     124         * @version 3.1.5
     125         * @return void
     126         */
     127        public static function upgrade_saved_filter_conditions( $task ) {
     128
     129            global $wpdb;
     130
     131            $current_page = get_transient( 'wpsc_upgrade_saved_filter_conditions_cursor' );
     132            if ( false === $current_page ) {
     133
     134                $total_items = $wpdb->get_var( "SELECT COUNT(id) FROM {$wpdb->prefix}psmsc_customers" );
     135                $total_pages = ceil( $total_items / 50 );
     136                $task->pages = $total_pages;
     137                $task->save();
     138
     139                $current_page = 0;
     140                set_transient( 'wpsc_upgrade_saved_filter_conditions_cursor', $current_page, MINUTE_IN_SECONDS * 60 * 48 );
     141            }
     142
     143            $current_page++;
     144
     145            $customers = WPSC_Customer::find(
     146                array(
     147                    'items_per_page' => 50,
     148                    'page_no'        => $current_page,
     149                    'meta_query'     => array(
     150                        'relation' => 'AND',
     151                        array(
     152                            'slug'    => 'custom_query',
     153                            'compare' => '=',
     154                            'val'     => 'c.user>0',
     155                        ),
     156                    ),
     157                )
     158            );
     159
     160            if ( $customers['total_items'] ) {
     161
     162                foreach ( $customers['results'] as $customer ) {
     163
     164                    $saved_filters = get_user_meta( $customer->user->ID, get_current_blog_id() . '-wpsc-tl-saved-filters', true );
     165                    if ( ! $saved_filters ) {
     166                        continue;
     167                    }
     168
     169                    foreach ( $saved_filters as $key => $filter ) {
     170                        $filters = self::upgrade_condition( str_replace( '^^', '\n', $filter['filters'] ), 'AND' );
     171                        $saved_filters[ $key ]['filters'] = str_replace( '\n', PHP_EOL, $filters );
     172                    }
     173                    update_user_meta( $customer->user->ID, get_current_blog_id() . '-wpsc-tl-saved-filters', $saved_filters );
     174                }
     175            }
     176
     177            if ( $current_page == $task->pages ) {
     178
     179                WPSC_Scheduled_Task::destroy( $task );
     180                delete_transient( 'wpsc_upgrade_saved_filter_conditions_cursor' );
     181
     182            } else {
     183
     184                set_transient( 'wpsc_upgrade_saved_filter_conditions_cursor', $current_page, MINUTE_IN_SECONDS * 60 * 48 );
     185                return;
     186            }
     187        }
     188
     189        /**
     190         * Upgrade and return conditions json
     191         *
     192         * @param string $conditions - conditions json string.
     193         * @param string $relation - AND or OR.
     194         * @version 3.1.5
     195         * @return string
     196         */
     197        public static function upgrade_condition( $conditions, $relation ) {
     198
     199            $conditions = json_decode( html_entity_decode( $conditions ), true );
     200            $and_conditions = array();
     201            $or_conditions = array();
     202            foreach ( $conditions as $slug => $condition ) {
     203                if ( preg_match( '/^cf_\w+$/', $slug ) ) {
     204                    $slug = str_replace( 'cf_', '', $slug );
     205                }
     206                $temp = array_merge( array( 'slug' => $slug ), $condition );
     207                if ( $relation == 'AND' ) {
     208                    $and_conditions[] = array( $temp );
     209                } else {
     210                    $or_conditions[] = $temp;
     211                }
     212            }
     213            if ( $relation == 'OR' ) {
     214                $and_conditions[] = $or_conditions;
     215            }
     216            return wp_json_encode( $and_conditions );
     217        }
    49218    }
    50219endif;
  • supportcandy/trunk/includes/class-wpsc-ticket-conditions.php

    r2798663 r2895557  
    99
    1010        /**
    11          * Conditions list
     11         * Ticket conditions
    1212         *
    1313         * @var array
     
    1616
    1717        /**
    18          * Ignore custom field types for ticket conditions
    19          *
    20          * @var array
    21          */
    22         public static $ignore_cft = array();
    23 
    24         /**
    25          * Init class
     18         * Initialize the class
     19         *
     20         * @return void
    2621         */
    2722        public static function init() {
    2823
    29             add_action( 'init', array( __CLASS__, 'load_conditions' ), 11 );
     24            add_action( 'init', array( __CLASS__, 'load_ticket_conditions' ) );
     25
    3026            add_action( 'wp_ajax_wpsc_tc_get_operators', array( __CLASS__, 'get_operators' ) );
     27            add_action( 'wp_ajax_nopriv_wpsc_tc_get_operators', array( __CLASS__, 'get_operators' ) );
     28
    3129            add_action( 'wp_ajax_wpsc_tc_get_operand', array( __CLASS__, 'get_operands' ) );
    32         }
    33 
    34         /**
    35          * Load ticket conditions
    36          *
    37          * @return void
    38          */
    39         public static function load_conditions() {
    40 
    41             $conditions = array();
    42 
    43             self::$ignore_cft = apply_filters( 'wpsc_ignore_cft_ticket_conditions', array( 'cf_woo_order' ) );
    44 
    45             // custom fields filters.
     30            add_action( 'wp_ajax_nopriv_wpsc_tc_get_operand', array( __CLASS__, 'get_operands' ) );
     31        }
     32
     33        /**
     34         * Load ticket conditions along with user permitted to utilize them
     35         *
     36         * @return void
     37         */
     38        public static function load_ticket_conditions() {
     39
     40            $agent_filters = get_option( 'wpsc-atl-filter-items', array() );
     41            $customer_filters = get_option( 'wpsc-ctl-filter-items', array() );
     42
     43            // custom fields.
    4644            foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
    4745
     
    4947                    class_exists( $cf->type ) &&
    5048                    $cf->type::$is_filter &&
    51                     in_array( $cf->field, array( 'ticket', 'agentonly', 'customer' ) ) &&
    52                     ! in_array( $cf->type::$slug, self::$ignore_cft )
     49                    in_array( $cf->field, array( 'ticket', 'agentonly', 'customer' ) )
    5350                ) ) {
    5451                    continue;
    5552                }
    5653
    57                 $conditions[ 'cf_' . $cf->slug ] = $cf->name;
    58             }
    59 
    60             // other ticket conditions than custom field.
     54                $levels = array( 'admin' );
     55
     56                if ( in_array( $cf->slug, $agent_filters ) ) {
     57                    $levels[] = 'agent';
     58                }
     59
     60                if ( in_array( $cf->slug, $customer_filters ) ) {
     61                    $levels[] = 'customer';
     62                }
     63
     64                self::$conditions[ $cf->slug ] = array(
     65                    'name'   => $cf->name,
     66                    'type'   => 'cf',
     67                    'levels' => $levels,
     68                );
     69            }
     70
     71            // custom conditions.
    6172            $other_conditions = apply_filters(
    6273                'wpsc_ticket_conditions',
     
    6778            );
    6879
    69             self::$conditions = array_merge( $conditions, $other_conditions );
     80            foreach ( $other_conditions as $slug => $name ) {
     81                self::$conditions[ $slug ] = array(
     82                    'name'   => $name,
     83                    'type'   => 'other',
     84                    'levels' => array( 'admin' ),
     85                );
     86            }
    7087        }
    7188
     
    7390         * Print condition input in the form
    7491         *
    75          * @param string  $relation - relation between conditions (AND/OR).
    76          * @param array   $conditions - conditions to preset.
    77          * @param array   $ignore_cft - ignore custom field types.
    78          * @param boolean $required - condition is required or not.
    79          * @return void
    80          */
    81         public static function print_condition_input( $relation = 'AND', $conditions = array(), $ignore_cft = array(), $required = false ) {
    82 
    83             $conditions = $conditions ? json_decode( html_entity_decode( $conditions ), true ) : array();
    84 
     92         * @param string  $name - form element name. Helpful to identify if multiple conditions need to be added.
     93         * @param string  $hook - filter hook for conditions. Uniquely identify and filter conditions available in the form.
     94         * @param string  $set_conditions - pre-defined conditions to print within input.
     95         * @param boolean $is_required - whether or not to print required character for label.
     96         * @param string  $label - whether or not to print required character for label.
     97         * @return void
     98         */
     99        public static function print( $name, $hook, $set_conditions = '', $is_required = false, $label = '' ) {
     100
     101            $label = $label ? $label : __( 'Conditions', 'supportcandy' );
     102            $conditions = apply_filters( $hook, self::$conditions );
     103            $set_conditions = $set_conditions ? json_decode( html_entity_decode( $set_conditions ), true ) : array();
     104            $unique_id = wp_unique_id( 'wpsc_' );
    85105            ?>
    86106            <div class="wpsc-input-group">
     
    88108                    <label for="">
    89109                        <?php
    90                         echo esc_attr( wpsc__( 'Conditions', 'supportcandy' ) );
    91                         if ( $required ) {
     110                        echo esc_attr( $label );
     111                        if ( $is_required ) {
    92112                            ?>
    93113                            <span class="required-char">*</span>
     
    97117                    </label>
    98118                </div>
    99                 <select name="relation" id="relation" style="width: fit-content; margin: 10px 0px;">
    100                     <option <?php selected( $relation, 'AND' ); ?> value="AND"><?php esc_attr_e( 'AND', 'supportcandy' ); ?></option>
    101                     <option <?php selected( $relation, 'OR' ); ?> value="OR"><?php esc_attr_e( 'OR', 'supportcandy' ); ?></option>
    102                 </select>
    103                 <div class="wpsc-form-filter-container">
    104                     <?php
    105                     foreach ( $conditions as $slug => $filter ) {
    106 
    107                         // check slug in conditions.
    108                         if ( ! array_key_exists( $slug, self::$conditions ) ) {
    109                             continue;
    110                         }
    111 
    112                         $flag = preg_match( '/^cf_(\w*)/', $slug, $matches );
    113                         if ( $flag ) {
    114                             $cf = WPSC_Custom_Field::get_cf_by_slug( $matches[1] );
    115                             if ( ! $cf ) {
    116                                 continue;
     119                <div class="wpsc-form-filter-container <?php echo esc_attr( $name ); ?>">
     120                    <div class="and-container">
     121                        <?php
     122                        if ( $set_conditions ) {
     123                            foreach ( $set_conditions as $and_condition ) {
     124                                ?>
     125                                <div class="and-item">
     126                                    <div class="or-container">
     127                                        <?php
     128                                        foreach ( $and_condition as $or_condition ) {
     129                                            if ( ! isset( $conditions[ $or_condition['slug'] ] ) ) {
     130                                                continue;
     131                                            }
     132                                            ?>
     133                                            <div class="wpsc-form-filter-item">
     134                                                <div class="content">
     135                                                    <div class="item">
     136                                                        <select class="filter" onchange="wpsc_tc_get_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operators' ) ); ?>');">
     137                                                            <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
     138                                                            <?php
     139                                                            foreach ( $conditions as $slug => $item ) {
     140                                                                ?>
     141                                                                <option value="<?php echo esc_attr( $slug ); ?>" <?php selected( $or_condition['slug'], $slug, true ); ?>><?php echo esc_attr( $item['name'] ); ?></option>
     142                                                                <?php
     143                                                            }
     144                                                            ?>
     145                                                        </select>
     146                                                    </div>
     147                                                    <?php
     148                                                    if ( $conditions[ $or_condition['slug'] ]['type'] == 'cf' ) {
     149                                                        $cf = WPSC_Custom_Field::get_cf_by_slug( $or_condition['slug'] );
     150                                                        $cf->type::get_operators( $cf, $or_condition );
     151                                                        $cf->type::get_operands( $or_condition['operator'], $cf, $or_condition );
     152                                                    } else {
     153                                                        self::print_operators( $or_condition['slug'], $or_condition );
     154                                                        self::print_operands( $or_condition['slug'], $or_condition['operator'], $or_condition );
     155                                                    }
     156                                                    ?>
     157                                                </div>
     158                                                <div class="remove-container">
     159                                                    <span onclick="wpsc_remove_condition_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
     160                                                </div>
     161                                            </div>
     162                                            <?php
     163                                        }
     164                                        ?>
     165                                    </div>
     166                                    <button class="wpsc-button small secondary" onclick="wpsc_add_or_condition( this, '<?php echo esc_attr( $unique_id ); ?>' );"><?php esc_html_e( '+ OR', 'supportcandy' ); ?></button>
     167                                </div>
     168                                <?php
    117169                            }
    118170                        }
    119 
    120171                        ?>
     172                    </div>
     173                    <button class="wpsc-button small secondary" onclick="wpsc_add_and_condition( this, '<?php echo esc_attr( $unique_id ); ?>' );"><?php esc_html_e( '+ AND', 'supportcandy' ); ?></button>
     174                </div>
     175                <script>jQuery( '.wpsc-form-filter-container select.filter' ).selectWoo();</script>
     176                <div style="display: none;">
     177                    <div class="and-template <?php echo esc_attr( $unique_id ); ?>">
     178                        <div class="and-item">
     179                            <div class="or-container"></div>
     180                            <button class="wpsc-button small secondary" onclick="wpsc_add_or_condition( this, '<?php echo esc_attr( $unique_id ); ?>' );"><?php esc_html_e( '+ OR', 'supportcandy' ); ?></button>
     181                        </div>
     182                    </div>
     183                    <div class="or-template <?php echo esc_attr( $unique_id ); ?>">
    121184                        <div class="wpsc-form-filter-item">
    122185                            <div class="content">
    123186                                <div class="item">
    124                                     <select class="cf" onchange="wpsc_tc_get_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operators' ) ); ?>');">
     187                                    <select class="filter" onchange="wpsc_tc_get_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operators' ) ); ?>');">
    125188                                        <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    126189                                        <?php
    127                                         foreach ( self::$conditions as $cslug => $label ) {
    128                                             $cflag = preg_match( '/^cf_(\w*)/', $cslug, $matches );
    129                                             if ( $cflag ) {
    130                                                 $ccf = WPSC_Custom_Field::get_cf_by_slug( $matches[1] );
    131                                                 if ( ! $ccf || in_array( $ccf->type::$slug, $ignore_cft ) ) {
    132                                                     continue;
    133                                                 }
    134                                             }
     190                                        foreach ( $conditions as $slug => $item ) {
    135191                                            ?>
    136                                             <option value="<?php echo esc_attr( $cslug ); ?>" <?php selected( $slug, $cslug ); ?>><?php echo esc_attr( $label ); ?></option>
     192                                            <option value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_attr( $item['name'] ); ?></option>
    137193                                            <?php
    138194                                        }
    139195                                        ?>
    140196                                    </select>
    141                                     <script>jQuery('.wpsc-form-filter-container').last().find('.cf').selectWoo();</script>
    142197                                </div>
    143                                 <?php
    144                                 if ( $flag ) {
    145                                     $cf->type::get_operators( $cf, $filter );
    146                                     $cf->type::get_operands( $filter['operator'], $cf, $filter );
    147                                 } else {
    148                                     self::print_operators( $slug, $filter );
    149                                     self::print_operand( $slug, $filter['operator'], $filter );
    150                                 }
    151                                 ?>
    152198                            </div>
    153199                            <div class="remove-container">
    154                                 <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
     200                                <span onclick="wpsc_remove_condition_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
    155201                            </div>
    156202                        </div>
    157                         <?php
    158                     }
    159                     ?>
    160                 </div>
    161                 <button class="wpsc-button small secondary wpsc-form-filter-add-btn" onclick="wpsc_add_form_filter_item();">
    162                     <?php echo esc_attr( wpsc__( 'Add new', 'supportcandy' ) ); ?>
    163                 </button>
    164             </div>
    165             <?php
    166         }
    167 
    168         /**
    169          * Print add new condition snippet
    170          *
    171          * @param array $ignore_cft - ignore custom field types.
    172          * @return void
    173          */
    174         public static function print_add_new_snippet( $ignore_cft = array() ) {
    175 
    176             ?>
    177             <div class="wpsc-form-filter-item">
    178                 <div class="content">
    179                     <div class="item">
    180                         <select class="cf" onchange="wpsc_tc_get_operators(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operators' ) ); ?>');">
    181                             <option value=""><?php esc_attr_e( 'Select field', 'supportcandy' ); ?></option>
    182                             <?php
    183                             foreach ( self::$conditions as $slug => $label ) {
    184                                 $flag = preg_match( '/^cf_(\w*)/', $slug, $matches );
    185                                 if ( $flag ) {
    186                                     $cf = WPSC_Custom_Field::get_cf_by_slug( $matches[1] );
    187                                     if ( ! $cf || in_array( $cf->type::$slug, $ignore_cft ) ) {
    188                                         continue;
    189                                     }
    190                                 }
    191                                 ?>
    192                                 <option value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_attr( $label ); ?></option>
    193                                 <?php
    194                             }
    195                             ?>
    196                         </select>
    197                         <script>jQuery('.wpsc-form-filter-container').last().find('.cf').selectWoo();</script>
    198                     </div>
    199                 </div>
    200                 <div class="remove-container">
    201                     <span onclick="wpsc_remove_form_filter_item(this)"><?php WPSC_Icons::get( 'times-circle' ); ?></span>
     203                    </div>
    202204                </div>
    203205            </div>
     
    206208
    207209        /**
    208          * Get condition operators.
     210         * Check whether or not conditions submitted by client are valid or not before inserting into the database or any further use
     211         *
     212         * @param string $hook - filter hook for conditions. Uniquely identify and filter conditions available in the form.
     213         * @param string $conditions - conditions received from the client.
     214         * @return boolean
     215         */
     216        public static function is_valid_input_conditions( $hook, $conditions ) {
     217
     218            // No conditions.
     219            if ( ! $conditions || $conditions == '[]' ) {
     220                return true;
     221            }
     222
     223            $allowed_conditions = apply_filters( $hook, self::$conditions );
     224            $conditions = json_decode( html_entity_decode( $conditions ), true );
     225
     226            foreach ( $conditions as $and_condition ) {
     227                foreach ( $and_condition as $or_condition ) {
     228                    if ( ! isset( $allowed_conditions[ $or_condition['slug'] ] ) ) {
     229                        return false;
     230                    }
     231                }
     232            }
     233
     234            return true;
     235        }
     236
     237        /**
     238         * Get condition operators ajax callback.
    209239         *
    210240         * @return void
    211241         */
    212242        public static function get_operators() {
     243
     244            $current_user = WPSC_Current_User::$current_user;
    213245
    214246            if ( check_ajax_referer( 'wpsc_tc_get_operators', '_ajax_nonce', false ) != 1 ) {
    215247                wp_send_json_error( 'Unauthorised request!', 401 );
    216             }
    217 
    218             if ( ! WPSC_Functions::is_site_admin() ) {
    219                 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
    220248            }
    221249
     
    225253            }
    226254
    227             $flag = preg_match( '/^cf_(\w*)/', $slug, $matches );
    228             if ( $flag ) {
    229 
    230                 $cf = WPSC_Custom_Field::get_cf_by_slug( $matches[1] );
    231                 if ( ! $cf ) {
    232                     wp_die();
    233                 }
     255            if ( ! in_array( $current_user->level, self::$conditions[ $slug ]['levels'] ) ) {
     256                wp_send_json_error( 'Unauthorised request!', 401 );
     257            }
     258
     259            if ( self::$conditions[ $slug ]['type'] == 'cf' ) {
     260
     261                $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
    234262                $cf->type::get_operators( $cf );
    235263
     
    243271
    244272        /**
    245          * Print operators for non-custom field conditions
     273         * Print condition operators
    246274         *
    247275         * @param string $slug - condition slug.
    248          * @param array  $filter - existing filter.
     276         * @param array  $filter - predefined condition to set operator.
    249277         * @return void
    250278         */
     
    283311
    284312        /**
    285          * Get operands for non custom field conditions
     313         * Get condition operands ajax callback.
    286314         *
    287315         * @return void
    288316         */
    289317        public static function get_operands() {
     318
     319            $current_user = WPSC_Current_User::$current_user;
    290320
    291321            if ( check_ajax_referer( 'wpsc_tc_get_operand', '_ajax_nonce', false ) != 1 ) {
    292322                wp_send_json_error( 'Unauthorised request!', 401 );
    293             }
    294 
    295             if ( ! WPSC_Functions::is_site_admin() ) {
    296                 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
    297323            }
    298324
     
    302328            }
    303329
     330            if ( ! in_array( $current_user->level, self::$conditions[ $slug ]['levels'] ) ) {
     331                wp_send_json_error( 'Unauthorised request!', 401 );
     332            }
     333
    304334            $operator = isset( $_POST['operator'] ) ? sanitize_text_field( wp_unslash( $_POST['operator'] ) ) : '';
    305335            if ( ! $operator ) {
     
    307337            }
    308338
    309             self::print_operand( $slug, $operator );
     339            if ( self::$conditions[ $slug ]['type'] == 'cf' ) {
     340
     341                $cf = WPSC_Custom_Field::get_cf_by_slug( $slug );
     342                $cf->type::get_operands( $operator, $cf );
     343
     344            } else {
     345
     346                self::print_operands( $slug, $operator );
     347            }
    310348
    311349            wp_die();
     
    313351
    314352        /**
    315          * Prit operands for non-custom field conditions
     353         * Print condition operands
    316354         *
    317355         * @param string $slug - condition slug.
    318356         * @param string $operator - operator string.
    319          * @param array  $filter - existing filter.
    320          * @return void
    321          */
    322         public static function print_operand( $slug, $operator, $filter = array() ) {
     357         * @param array  $filter - predefined condition to set operand.
     358         * @return void
     359         */
     360        public static function print_operands( $slug, $operator, $filter = array() ) {
    323361
    324362            global $wp_roles;
     
    368406
    369407        /**
    370          * Return whether conditions are valid for the ticket
    371          *
     408         * Get meta query for the given conditions
     409         *
     410         * @param string $conditions - conditions json from database.
     411         * @param string $is_user_query - check if it needs to check the permission of the filter of current user. e.g. custom filters, saved filters need to check permissions but default filters need not.
     412         * @return array
     413         */
     414        public static function get_meta_query( $conditions, $is_user_query = false ) {
     415
     416            $current_user = WPSC_Current_User::$current_user;
     417
     418            $meta_query = array();
     419            $conditions = $conditions ? json_decode( $conditions, true ) : array();
     420            if ( ! $conditions ) {
     421                return $meta_query;
     422            }
     423
     424            foreach ( $conditions as $and_condition ) {
     425
     426                $temp = array();
     427                foreach ( $and_condition as $or_condition ) {
     428
     429                    if (
     430                        ! isset( self::$conditions[ $or_condition['slug'] ] ) ||
     431                        ( $is_user_query && ! in_array( $current_user->level, self::$conditions[ $or_condition['slug'] ]['levels'] ) )
     432                    ) {
     433                        continue;
     434                    }
     435
     436                    $cf = WPSC_Custom_Field::get_cf_by_slug( $or_condition['slug'] );
     437                    $val = $cf->type::get_meta_value( $or_condition );
     438                    if ( $val === false ) {
     439                        continue;
     440                    }
     441
     442                    $temp[] = array(
     443                        'slug'    => $or_condition['slug'],
     444                        'compare' => $or_condition['operator'],
     445                        'val'     => $val,
     446                    );
     447                }
     448
     449                if ( $temp ) {
     450                    $meta_query[] = array_merge( array( 'relation' => 'OR' ), $temp );
     451                }
     452            }
     453
     454            return $meta_query;
     455        }
     456
     457        /**
     458         * Return whether or not given conditions are satisfied by the given ticket
     459         *
     460         * @param string      $conditions - conditions json from database.
    372461         * @param WPSC_Ticket $ticket - ticket object.
    373          * @param string      $conditions - conditions to check.
    374          * @param string      $relation - relation between conditions.
    375462         * @return boolean
    376463         */
    377         public static function is_valid_conditions( $ticket, $conditions, $relation ) {
    378 
    379             $conditions = $conditions ? json_decode( html_entity_decode( $conditions ), true ) : array();
     464        public static function is_valid( $conditions, $ticket ) {
     465
     466            $conditions = $conditions ? json_decode( $conditions, true ) : array();
    380467            if ( ! $conditions ) {
    381468                return true;
    382469            }
    383470
    384             $flag = $relation == 'AND' ? true : false;
    385 
    386             foreach ( $conditions as $slug => $condition ) {
    387 
    388                 if ( preg_match( '/^cf_(\w*)/', $slug, $matches ) ) {
    389 
    390                     $cf = WPSC_Custom_Field::get_cf_by_slug( $matches[1] );
    391                     if ( ! $cf ) {
     471            foreach ( $conditions as $and_condition ) {
     472
     473                $flag = false;
     474                foreach ( $and_condition as $or_condition ) {
     475
     476                    if ( ! isset( self::$conditions[ $or_condition['slug'] ] ) ) {
    392477                        continue;
    393478                    }
    394479
    395                     $is_valid = $cf->type::is_valid_ticket_condition( $condition, $cf, $ticket );
    396 
    397                 } else {
    398 
    399                     switch ( $slug ) {
    400 
    401                         case 'submitted_by':
    402                             if (
    403                                 (
    404                                     $condition['operand_val_1'] == 'agent' &&
    405                                     is_object( $ticket->agent_created )
    406                                 ) ||
    407                                 (
    408                                     $condition['operand_val_1'] == 'user' &&
    409                                     ! is_object( $ticket->agent_created )
    410                                 )
    411                             ) {
    412                                 $is_valid = true;
    413                             } else {
    414                                 $is_valid = false;
    415                             }
    416                             break;
    417 
    418                         case 'user_role':
    419                             $user_roles = $ticket->customer->user->roles;
    420                             switch ( $condition['operator'] ) {
    421 
    422                                 case '=':
    423                                     $flag = in_array( $condition['operand_val_1'], $user_roles ) ? true : false;
    424                                     break;
    425 
    426                                 case 'IN':
    427                                     $flag = false;
    428                                     foreach ( $user_roles as $id ) {
    429                                         if ( in_array( $id, $condition['operand_val_1'] ) ) {
    430                                             $flag = true;
    431                                             break;
     480                    if ( self::$conditions[ $or_condition['slug'] ]['type'] == 'cf' ) {
     481
     482                        $cf = WPSC_Custom_Field::get_cf_by_slug( $or_condition['slug'] );
     483                        $flag = $cf->type::is_valid_ticket_condition( $or_condition, $cf, $ticket );
     484
     485                    } else {
     486
     487                        switch ( $or_condition['slug'] ) {
     488
     489                            case 'submitted_by':
     490                                if (
     491                                    (
     492                                        $or_condition['operand_val_1'] == 'agent' &&
     493                                        is_object( $ticket->agent_created )
     494                                    ) ||
     495                                    (
     496                                        $or_condition['operand_val_1'] == 'user' &&
     497                                        ! is_object( $ticket->agent_created )
     498                                    )
     499                                ) {
     500                                    $flag = true;
     501                                }
     502                                break;
     503
     504                            case 'user_role':
     505                                $user_roles = $ticket->customer->user->roles;
     506                                switch ( $or_condition['operator'] ) {
     507
     508                                    case '=':
     509                                        $flag = in_array( $or_condition['operand_val_1'], $user_roles ) ? true : false;
     510                                        break;
     511
     512                                    case 'IN':
     513                                        foreach ( $user_roles as $id ) {
     514                                            if ( in_array( $id, $or_condition['operand_val_1'] ) ) {
     515                                                $flag = true;
     516                                                break;
     517                                            }
    432518                                        }
    433                                     }
    434                                     break;
    435 
    436                                 case 'NOT IN':
    437                                     foreach ( $user_roles as $id ) {
    438                                         if ( in_array( $id, $condition['operand_val_1'] ) ) {
    439                                             $flag = false;
    440                                             break;
     519                                        break;
     520
     521                                    case 'NOT IN':
     522                                        $temp = true;
     523                                        foreach ( $user_roles as $id ) {
     524                                            if ( in_array( $id, $or_condition['operand_val_1'] ) ) {
     525                                                $temp = false;
     526                                                break;
     527                                            }
    441528                                        }
    442                                     }
    443                                     break;
    444                             }
    445                             break;
    446 
    447                         default:
    448                             $is_valid = apply_filters( 'wpsc_tc_is_valid', $is_valid, $slug, $condition, $ticket );
    449                             break;
     529                                        $flag = $temp;
     530                                        break;
     531                                }
     532                                break;
     533
     534                            default:
     535                                $flag = apply_filters( 'wpsc_tc_is_valid', $flag, $slug, $or_condition, $ticket );
     536                                break;
     537                        }
    450538                    }
    451                 }
    452 
    453                 if ( $relation == 'OR' && $is_valid ) {
    454                     $flag = true;
    455                     break;
    456                 }
    457 
    458                 if ( $relation == 'AND' && ! $is_valid ) {
    459                     $flag = false;
    460                     break;
    461                 }
    462             }
    463 
    464             return $flag;
     539
     540                    // no need to check further OR conditions if this condition is TRUE.
     541                    if ( $flag ) {
     542                        break;
     543                    }
     544                }
     545
     546                // no need to check further AND conditions if this condition is FALSE.
     547                if ( ! $flag ) {
     548                    return false;
     549                }
     550            }
     551
     552            // if we make upto this point, all conditions are satisfied.
     553            return true;
    465554        }
    466555    }
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-checkbox.php

    r2873748 r2895557  
    212212
    213213            <div class="item conditional">
    214                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     214                <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' ) ); ?>');">
    215215                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    216216                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    312312
    313313                case '=':
    314                     $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])' . $val . '($|[|])\'';
     314                    $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])' . esc_sql( $val ) . '($|[|])\'';
    315315                    break;
    316316
     
    321321                        }
    322322                    }
    323                     $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     323                    $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    324324                    break;
    325325
     
    330330                        }
    331331                    }
    332                     $str = self::get_sql_slug( $cf ) . ' NOT RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     332                    $str = self::get_sql_slug( $cf ) . ' NOT RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    333333                    break;
    334334
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-date.php

    r2873748 r2895557  
    209209
    210210            <div class="item conditional">
    211                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     211                <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' ) ); ?>');">
    212212                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    213213                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    335335                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    336336                    $to   = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    337                     $str  = self::get_sql_slug( $cf ) . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     337                    $str  = self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    338338                    break;
    339339
     
    344344                        self::get_sql_slug( $cf ) . ' != \'0000-00-00 00:00:00\'',
    345345                    );
    346                     $str  = '(' . implode( ' AND ', $arr ) . ')';
     346                    $str  = '(' . implode( ' AND ', esc_sql( $arr ) ) . ')';
    347347                    break;
    348348
    349349                case '>':
    350350                    $to  = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    351                     $str = self::get_sql_slug( $cf ) . $compare . '\'' . $to . '\'';
     351                    $str = self::get_sql_slug( $cf ) . $compare . '\'' . esc_sql( $to ) . '\'';
    352352                    break;
    353353
     
    359359                        self::get_sql_slug( $cf ) . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    360360                    );
    361                     $str  = '((' . implode( ' OR ', $arr ) . ') AND ' . self::get_sql_slug( $cf ) . ' != \'0000-00-00 00:00:00\')';
     361                    $str  = '((' . implode( ' OR ', esc_sql( $arr ) ) . ') AND ' . self::get_sql_slug( $cf ) . ' != \'0000-00-00 00:00:00\')';
    362362                    break;
    363363
     
    369369                        self::get_sql_slug( $cf ) . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    370370                    );
    371                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     371                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    372372                    break;
    373373
     
    375375                    $from = WPSC_Functions::get_utc_date_str( $val['operand_val_1'] . ' 00:00:00' );
    376376                    $to   = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ' 23:59:59' );
    377                     $str  = self::get_sql_slug( $cf ) . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     377                    $str  = self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    378378                    break;
    379379
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-datetime.php

    r2873748 r2895557  
    209209
    210210            <div class="item conditional">
    211                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     211                <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' ) ); ?>');">
    212212                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    213213                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    343343                case '>=':
    344344                    $from = WPSC_Functions::get_utc_date_str( $val . ':00' );
    345                     $str  = self::get_sql_slug( $cf ) . $compare . '\'' . $from . '\'';
     345                    $str  = self::get_sql_slug( $cf ) . $compare . '\'' . esc_sql( $from ) . '\'';
    346346                    break;
    347347
     
    349349                    $from = WPSC_Functions::get_utc_date_str( $val['operand_val_1'] . ':00' );
    350350                    $to   = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ':00' );
    351                     $str  = self::get_sql_slug( $cf ) . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     351                    $str  = self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    352352                    break;
    353353
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-email.php

    r2873748 r2895557  
    212212
    213213            <div class="item conditional">
    214                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     214                <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' ) ); ?>');">
    215215                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    216216                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    325325
    326326                case '=':
    327                     $str = self::get_sql_slug( $cf ) . '=\'' . $val . '\'';
     327                    $str = self::get_sql_slug( $cf ) . '=\'' . esc_sql( $val ) . '\'';
    328328                    break;
    329329
    330330                case 'IN':
    331                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     331                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    332332                    break;
    333333
    334334                case 'NOT IN':
    335                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     335                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    336336                    break;
    337337
     
    341341                    foreach ( $val as $term ) {
    342342                        $term  = str_replace( '*', '%', trim( $term ) );
    343                         $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . $term . '%\'';
     343                        $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . esc_sql( $term ) . '%\'';
    344344                    }
    345345                    $str = '(' . implode( ' OR ', $arr ) . ')';
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-multi-select.php

    r2873748 r2895557  
    212212
    213213            <div class="item conditional">
    214                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     214                <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' ) ); ?>');">
    215215                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    216216                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    312312
    313313                case '=':
    314                     $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])' . $val . '($|[|])\'';
     314                    $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])' . esc_sql( $val ) . '($|[|])\'';
    315315                    break;
    316316
     
    321321                        }
    322322                    }
    323                     $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     323                    $str = self::get_sql_slug( $cf ) . ' RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    324324                    break;
    325325
     
    330330                        }
    331331                    }
    332                     $str = self::get_sql_slug( $cf ) . ' NOT RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     332                    $str = self::get_sql_slug( $cf ) . ' NOT RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    333333                    break;
    334334
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-number.php

    r2873748 r2895557  
    215215
    216216            <div class="item conditional">
    217                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     217                <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' ) ); ?>');">
    218218                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    219219                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    359359                case '<=':
    360360                case '>=':
    361                     $str = self::get_sql_slug( $cf ) . $compare . $val;
     361                    $str = self::get_sql_slug( $cf ) . $compare . esc_sql( $val );
    362362                    break;
    363363
    364364                case 'IN':
    365                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(' . implode( ', ', $val ) . ')';
     365                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(' . implode( ', ', esc_sql( $val ) ) . ')';
    366366                    break;
    367367
    368368                case 'NOT IN':
    369                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(' . implode( ', ', $val ) . ')';
     369                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(' . implode( ', ', esc_sql( $val ) ) . ')';
    370370                    break;
    371371
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-radio-button.php

    r2873748 r2895557  
    213213
    214214            <div class="item conditional">
    215                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     215                <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' ) ); ?>');">
    216216                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    217217                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    299299
    300300                case '=':
    301                     $str = self::get_sql_slug( $cf ) . '=\'' . $val . '\'';
     301                    $str = self::get_sql_slug( $cf ) . '=\'' . esc_sql( $val ) . '\'';
    302302                    break;
    303303
    304304                case 'IN':
    305                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     305                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    306306                    break;
    307307
    308308                case 'NOT IN':
    309                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     309                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    310310                    break;
    311311
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-single-select.php

    r2873748 r2895557  
    213213
    214214            <div class="item conditional">
    215                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     215                <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' ) ); ?>');">
    216216                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    217217                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    299299
    300300                case '=':
    301                     $str = self::get_sql_slug( $cf ) . '=\'' . $val . '\'';
     301                    $str = self::get_sql_slug( $cf ) . '=\'' . esc_sql( $val ) . '\'';
    302302                    break;
    303303
    304304                case 'IN':
    305                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     305                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    306306                    break;
    307307
    308308                case 'NOT IN':
    309                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     309                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    310310                    break;
    311311
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-text-field.php

    r2873748 r2895557  
    212212
    213213            <div class="item conditional">
    214                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     214                <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' ) ); ?>');">
    215215                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    216216                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    325325
    326326                case '=':
    327                     $str = self::get_sql_slug( $cf ) . '=\'' . $val . '\'';
     327                    $str = self::get_sql_slug( $cf ) . '=\'' . esc_sql( $val ) . '\'';
    328328                    break;
    329329
    330330                case 'IN':
    331                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     331                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    332332                    break;
    333333
    334334                case 'NOT IN':
    335                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     335                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    336336                    break;
    337337
     
    341341                    foreach ( $val as $term ) {
    342342                        $term  = str_replace( '*', '%', trim( $term ) );
    343                         $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . $term . '%\'';
     343                        $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . esc_sql( $term ) . '%\'';
    344344                    }
    345345                    $str = '(' . implode( ' OR ', $arr ) . ')';
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-textarea.php

    r2873748 r2895557  
    212212
    213213            <div class="item conditional">
    214                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     214                <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' ) ); ?>');">
    215215                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    216216                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'IN' ); ?> value="IN"><?php esc_attr_e( 'Matches', 'supportcandy' ); ?></option>
     
    306306
    307307                case 'IN':
    308                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     308                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    309309                    break;
    310310
    311311                case 'NOT IN':
    312                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     312                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    313313                    break;
    314314
     
    318318                    foreach ( $val as $term ) {
    319319                        $term  = str_replace( '*', '%', trim( $term ) );
    320                         $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . $term . '%\'';
     320                        $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . esc_sql( $term ) . '%\'';
    321321                    }
    322322                    $str = '(' . implode( ' OR ', $arr ) . ')';
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-time.php

    r2873748 r2895557  
    11741174
    11751175            <div class="item conditional">
    1176                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     1176                <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' ) ); ?>');">
    11771177                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    11781178                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    12981298
    12991299                case '=':
    1300                     $str = self::get_sql_slug( $cf ) . ' BETWEEN \'' . $val . '\' AND \'' . $val . '\'';
     1300                    $str = self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $val ) . '\' AND \'' . esc_sql( $val ) . '\'';
    13011301                    break;
    13021302
    13031303                case '<':
    1304                     $str = self::get_sql_slug( $cf ) . $compare . '\'' . $val . '\' AND ' . self::get_sql_slug( $cf ) . ' !=""';
     1304                    $str = self::get_sql_slug( $cf ) . $compare . '\'' . esc_sql( $val ) . '\' AND ' . self::get_sql_slug( $cf ) . ' !=""';
    13051305                    break;
    13061306
    13071307                case '>':
    1308                     $str = self::get_sql_slug( $cf ) . $compare . '\'' . $val . '\'';
     1308                    $str = self::get_sql_slug( $cf ) . $compare . '\'' . esc_sql( $val ) . '\'';
    13091309                    break;
    13101310
    13111311                case '<=':
    13121312                    $arr = array(
    1313                         self::get_sql_slug( $cf ) . $compare . '\'' . $val . '\'',
    1314                         self::get_sql_slug( $cf ) . ' BETWEEN \'' . $val . '\' AND \'' . $val . '\'',
     1313                        self::get_sql_slug( $cf ) . $compare . '\'' . esc_sql( $val ) . '\'',
     1314                        self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $val ) . '\' AND \'' . esc_sql( $val ) . '\'',
    13151315                    );
    13161316                    $str = '((' . implode( ' OR ', $arr ) . ') AND ' . self::get_sql_slug( $cf ) . ' != "")';
     
    13191319                case '>=':
    13201320                    $arr = array(
    1321                         self::get_sql_slug( $cf ) . $compare . '\'' . $val . '\'',
    1322                         self::get_sql_slug( $cf ) . ' BETWEEN \'' . $val . '\' AND \'' . $val . '\'',
     1321                        self::get_sql_slug( $cf ) . $compare . '\'' . esc_sql( $val ) . '\'',
     1322                        self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $val ) . '\' AND \'' . esc_sql( $val ) . '\'',
    13231323                    );
    13241324                    $str = '(' . implode( ' OR ', $arr ) . ')';
     
    13261326
    13271327                case 'BETWEEN':
    1328                     $str = self::get_sql_slug( $cf ) . ' BETWEEN \'' . $val['operand_val_1'] . '\' AND \'' . $val['operand_val_2'] . '\'';
     1328                    $str = self::get_sql_slug( $cf ) . ' BETWEEN \'' . esc_sql( $val['operand_val_1'] ) . '\' AND \'' . esc_sql( $val['operand_val_2'] ) . '\'';
    13291329                    break;
    13301330
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-cf-url.php

    r2873748 r2895557  
    212212
    213213            <div class="item conditional">
    214                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     214                <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' ) ); ?>');">
    215215                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    216216                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    325325
    326326                case '=':
    327                     $str = self::get_sql_slug( $cf ) . '=\'' . $val . '\'';
     327                    $str = self::get_sql_slug( $cf ) . '=\'' . esc_sql( $val ) . '\'';
    328328                    break;
    329329
    330330                case 'IN':
    331                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     331                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    332332                    break;
    333333
    334334                case 'NOT IN':
    335                     $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     335                    $str = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    336336                    break;
    337337
     
    341341                    foreach ( $val as $term ) {
    342342                        $term  = str_replace( '*', '%', trim( $term ) );
    343                         $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . $term . '%\'';
     343                        $arr[] = 'CONVERT(' . self::get_sql_slug( $cf ) . ' USING utf8) LIKE \'%' . esc_sql( $term ) . '%\'';
    344344                    }
    345345                    $str = '(' . implode( ' OR ', $arr ) . ')';
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-agent-created.php

    r2873748 r2895557  
    197197
    198198            <div class="item conditional">
    199                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">                   
     199                <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' ) ); ?>');">                   
    200200                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    201201                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    321321
    322322                case '=':
    323                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     323                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    324324                    break;
    325325
    326326                case 'IN':
    327                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     327                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    328328                    break;
    329329
    330330                case 'NOT IN':
    331                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     331                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    332332                    break;
    333333
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-assigned-agent.php

    r2873748 r2895557  
    215215
    216216            <div class="item conditional">
    217                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">                   
     217                <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' ) ); ?>');">                   
    218218                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    219219                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    386386                        $val = '^$';
    387387                    }
    388                     $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])' . $val . '($|[|])\'';
     388                    $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])' . esc_sql( $val ) . '($|[|])\'';
    389389                    break;
    390390
     
    395395                        }
    396396                    }
    397                     $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     397                    $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    398398                    break;
    399399
    400400                case 'NOT IN':
    401                     foreach ( $val as $index => $value ) {
     401                    foreach ( esc_sql( $val ) as $index => $value ) {
    402402                        if ( $value == '' || $value == '0' ) {
    403403                            $val[ $index ] = '^$';
    404404                        }
    405405                    }
    406                     $str = 't.' . $cf->slug . ' NOT RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     406                    $str = 't.' . $cf->slug . ' NOT RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    407407                    break;
    408408
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-browser.php

    r2763565 r2895557  
    187187
    188188            <div class="item conditional">
    189                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     189                <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' ) ); ?>');">
    190190                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    191191                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    244244
    245245                case '=':
    246                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     246                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    247247                    break;
    248248
    249249                case 'IN':
    250                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     250                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    251251                    break;
    252252
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-category.php

    r2873748 r2895557  
    194194
    195195            <div class="item conditional">
    196                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">                   
     196                <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' ) ); ?>');">                   
    197197                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    198198                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    282282
    283283                case '=':
    284                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     284                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    285285                    break;
    286286
    287287                case 'IN':
    288                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     288                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    289289                    break;
    290290
    291291                case 'NOT IN':
    292                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     292                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    293293                    break;
    294294
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-customer.php

    r2873748 r2895557  
    207207
    208208            <div class="item conditional">
    209                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     209                <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' ) ); ?>');">
    210210                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    211211                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    304304
    305305                case '=':
    306                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     306                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    307307                    break;
    308308
    309309                case 'IN':
    310                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     310                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    311311                    break;
    312312
    313313                case 'NOT IN':
    314                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     314                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    315315                    break;
    316316
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-date-closed.php

    r2763565 r2895557  
    184184
    185185            <div class="item conditional">
    186                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     186                <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' ) ); ?>');">
    187187                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    188188                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    264264                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    265265                    $to   = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    266                     $str  = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     266                    $str  = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    267267                    break;
    268268
    269269                case '<':
    270270                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    271                     $str  = 't.' . $cf->slug . $compare . '\'' . $from . '\'';
     271                    $str  = 't.' . $cf->slug . $compare . '\'' . esc_sql( $from ) . '\'';
    272272                    break;
    273273
    274274                case '>':
    275                     $to  = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    276                     $str = 't.' . $cf->slug . $compare . '\'' . $to . '\'';
     275                    $to  = WPSC_Functions::get_utc_date_str( esc_sql( $val ) . ' 23:59:59' );
     276                    $str = 't.' . $cf->slug . $compare . '\'' . esc_sql( $to ) . '\'';
    277277                    break;
    278278
     
    284284                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    285285                    );
    286                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     286                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    287287                    break;
    288288
    289289                case '>=':
    290                     $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    291                     $to   = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
     290                    $from = WPSC_Functions::get_utc_date_str( esc_sql( $val ) . ' 00:00:00' );
     291                    $to   = WPSC_Functions::get_utc_date_str( esc_sql( $val ) . ' 23:59:59' );
    292292                    $arr  = array(
    293293                        't.' . $cf->slug . $compare . '\'' . $to . '\'',
    294294                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    295295                    );
    296                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     296                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    297297                    break;
    298298
     
    307307                        $to   = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ' 23:59:59' );
    308308                    }
    309                     $str = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     309                    $str = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    310310                    break;
    311311
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-date-created.php

    r2873748 r2895557  
    190190
    191191            <div class="item conditional">
    192                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     192                <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' ) ); ?>');">
    193193                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    194194                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    270270                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    271271                    $to   = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    272                     $str  = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     272                    $str  = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    273273                    break;
    274274
    275275                case '<':
    276276                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    277                     $str  = 't.' . $cf->slug . $compare . '\'' . $from . '\'';
     277                    $str  = 't.' . $cf->slug . $compare . '\'' . esc_sql( $from ) . '\'';
    278278                    break;
    279279
    280280                case '>':
    281281                    $to  = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    282                     $str = 't.' . $cf->slug . $compare . '\'' . $to . '\'';
     282                    $str = 't.' . $cf->slug . $compare . '\'' . esc_sql( $to ) . '\'';
    283283                    break;
    284284
     
    290290                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    291291                    );
    292                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     292                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    293293                    break;
    294294
     
    300300                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    301301                    );
    302                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     302                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    303303                    break;
    304304
     
    313313                        $to   = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ' 23:59:59' );
    314314                    }
    315                     $str = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     315                    $str = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    316316                    break;
    317317
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-date-updated.php

    r2873748 r2895557  
    190190
    191191            <div class="item conditional">
    192                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     192                <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' ) ); ?>');">
    193193                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    194194                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    270270                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    271271                    $to   = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    272                     $str  = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     272                    $str  = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    273273                    break;
    274274
    275275                case '<':
    276276                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    277                     $str  = 't.' . $cf->slug . $compare . '\'' . $from . '\'';
     277                    $str  = 't.' . $cf->slug . $compare . '\'' . esc_sql( $from ) . '\'';
    278278                    break;
    279279
    280280                case '>':
    281281                    $to  = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    282                     $str = 't.' . $cf->slug . $compare . '\'' . $to . '\'';
     282                    $str = 't.' . $cf->slug . $compare . '\'' . esc_sql( $to ) . '\'';
    283283                    break;
    284284
     
    290290                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    291291                    );
    292                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     292                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    293293                    break;
    294294
     
    300300                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    301301                    );
    302                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     302                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    303303                    break;
    304304
     
    306306                    $from = WPSC_Functions::get_utc_date_str( $val['operand_val_1'] . ' 00:00:00' );
    307307                    $to   = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ' 23:59:59' );
    308                     $str  = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     308                    $str  = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    309309                    break;
    310310
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-description.php

    r2873748 r2895557  
    190190
    191191            <div class="item conditional">
    192                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     192                <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' ) ); ?>');">
    193193                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    194194                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'LIKE' ); ?> value="LIKE"><?php esc_attr_e( 'Has Words', 'supportcandy' ); ?></option>
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-id.php

    r2873748 r2895557  
    184184
    185185            <div class="item conditional">
    186                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     186                <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' ) ); ?>');">
    187187                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    188188                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    245245
    246246                case '=':
    247                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     247                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    248248                    break;
    249249
    250250                case 'IN':
    251                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     251                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    252252                    break;
    253253
    254254                case 'NOT IN':
    255                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     255                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    256256                    break;
    257257
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-last-reply-by.php

    r2763565 r2895557  
    184184
    185185            <div class="item conditional">
    186                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     186                <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' ) ); ?>');">
    187187                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    188188                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    281281
    282282                case '=':
    283                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     283                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    284284                    break;
    285285
    286286                case 'IN':
    287                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     287                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    288288                    break;
    289289
    290290                case 'NOT IN':
    291                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     291                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    292292                    break;
    293293
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-last-reply-on.php

    r2763565 r2895557  
    184184
    185185            <div class="item conditional">
    186                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     186                <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' ) ); ?>');">
    187187                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    188188                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    264264                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    265265                    $to   = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    266                     $str  = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     266                    $str  = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    267267                    break;
    268268
    269269                case '<':
    270270                    $from = WPSC_Functions::get_utc_date_str( $val . ' 00:00:00' );
    271                     $str  = 't.' . $cf->slug . $compare . '\'' . $from . '\'';
     271                    $str  = 't.' . $cf->slug . $compare . '\'' . esc_sql( $from ) . '\'';
    272272                    break;
    273273
    274274                case '>':
    275275                    $to  = WPSC_Functions::get_utc_date_str( $val . ' 23:59:59' );
    276                     $str = 't.' . $cf->slug . $compare . '\'' . $to . '\'';
     276                    $str = 't.' . $cf->slug . $compare . '\'' . esc_sql( $to ) . '\'';
    277277                    break;
    278278
     
    284284                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    285285                    );
    286                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     286                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    287287                    break;
    288288
     
    294294                        't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'',
    295295                    );
    296                     $str  = '(' . implode( ' OR ', $arr ) . ')';
     296                    $str  = '(' . implode( ' OR ', esc_sql( $arr ) ) . ')';
    297297                    break;
    298298
     
    307307                        $to   = WPSC_Functions::get_utc_date_str( $val['operand_val_2'] . ' 23:59:59' );
    308308                    }
    309                     $str = 't.' . $cf->slug . ' BETWEEN \'' . $from . '\' AND \'' . $to . '\'';
     309                    $str = 't.' . $cf->slug . ' BETWEEN \'' . esc_sql( $from ) . '\' AND \'' . esc_sql( $to ) . '\'';
    310310                    break;
    311311
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-os.php

    r2873748 r2895557  
    172172
    173173            <div class="item conditional">
    174                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     174                <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' ) ); ?>');">
    175175                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    176176                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    231231
    232232                case '=':
    233                     $str = self::get_sql_slug( $cf ) . '=\'' . $val . '\'';
     233                    $str = self::get_sql_slug( $cf ) . '=\'' . esc_sql( $val ) . '\'';
    234234                    break;
    235235
    236236                case 'IN':
    237                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     237                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    238238                    break;
    239239
    240240                case 'NOT IN':
    241                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     241                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    242242                    break;
    243243
     
    247247                    foreach ( $val as $term ) {
    248248                        $term  = str_replace( '*', '%', trim( $term ) );
    249                         $arr[] = 'CONVERT(t.' . $cf->slug . ' USING utf8) LIKE \'%' . $term . '%\'';
     249                        $arr[] = 'CONVERT(t.' . $cf->slug . ' USING utf8) LIKE \'%' . esc_sql( $term ) . '%\'';
    250250                    }
    251251                    $str = '(' . implode( ' OR ', $arr ) . ')';
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-prev-assignee.php

    r2793251 r2895557  
    205205
    206206            <div class="item conditional">
    207                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">                   
     207                <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' ) ); ?>');">                   
    208208                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    209209                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    344344
    345345                case '=':
    346                     $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])' . $val . '($|[|])\'';
     346                    $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])' . esc_sql( $val ) . '($|[|])\'';
    347347                    break;
    348348
     
    353353                        }
    354354                    }
    355                     $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     355                    $str = 't.' . $cf->slug . ' RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    356356                    break;
    357357
     
    362362                        }
    363363                    }
    364                     $str = 't.' . $cf->slug . ' NOT RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
     364                    $str = 't.' . $cf->slug . ' NOT RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
    365365                    break;
    366366
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-priority.php

    r2873748 r2895557  
    197197
    198198            <div class="item conditional">
    199                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     199                <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' ) ); ?>');">
    200200                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    201201                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    285285
    286286                case '=':
    287                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     287                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    288288                    break;
    289289
    290290                case 'IN':
    291                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     291                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    292292                    break;
    293293
    294294                case 'NOT IN':
    295                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     295                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    296296                    break;
    297297
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-source.php

    r2873748 r2895557  
    216216
    217217            <div class="item conditional">
    218                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     218                <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' ) ); ?>');">
    219219                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    220220                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    280280
    281281                case '=':
    282                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     282                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    283283                    break;
    284284
    285285                case 'IN':
    286                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     286                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    287287                    break;
    288288
    289289                case 'NOT IN':
    290                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     290                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    291291                    break;
    292292
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-status.php

    r2873748 r2895557  
    197197
    198198            <div class="item conditional">
    199                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     199                <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' ) ); ?>');">
    200200                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    201201                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    283283
    284284                case '=':
    285                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     285                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    286286                    break;
    287287
    288288                case 'IN':
    289                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', $val ) . '\')';
     289                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    290290                    break;
    291291
    292292                case 'NOT IN':
    293                     $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', $val ) . '\')';
     293                    $str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
    294294                    break;
    295295
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-subject.php

    r2873748 r2895557  
    197197
    198198            <div class="item conditional">
    199                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     199                <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' ) ); ?>');">
    200200                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    201201                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'LIKE' ); ?> value="LIKE"><?php esc_attr_e( 'Has Words', 'supportcandy' ); ?></option>
  • supportcandy/trunk/includes/custom-field-types/class-wpsc-df-user-type.php

    r2873748 r2895557  
    194194
    195195            <div class="item conditional">
    196                 <select class="operator" onchange="wpsc_get_ticket_filter_operands(this, <?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_ticket_filter_operands' ) ); ?>');">
     196                <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' ) ); ?>');">
    197197                    <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
    198198                    <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
     
    239239
    240240                case '=':
    241                     $str = 't.' . $cf->slug . '=\'' . $val . '\'';
     241                    $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
    242242                    break;
    243243
  • supportcandy/trunk/includes/models/class-wpsc-customer.php

    r2822852 r2895557  
    482482
    483483                // Invalid filter if it does not contain slug, compare and val indexes.
    484                 $slug    = isset( $filter['slug'] ) ? $filter['slug'] : false;
     484                $slug    = isset( $filter['slug'] ) ? WPSC_Functions::sanitize_sql_key( $filter['slug'] ) : false;
    485485                $compare = isset( $filter['compare'] ) ? $filter['compare'] : false;
    486486                $val     = isset( $filter['val'] ) ? $filter['val'] : false;
     
    489489                }
    490490
    491                 switch ( $compare ) {
    492 
    493                     case '<':
    494                     case '=':
    495                     case '>':
    496                     case '<=':
    497                     case '>=':
    498                         if ( self::$schema[ $slug ]['has_multiple_val'] ) {
    499                             $filter_str[] = '1=1';
     491                // custom filter.
     492                if ( $slug === 'custom_query' ) {
     493
     494                    $filter_str[] = $val;
     495
     496                } else {
     497
     498                    switch ( $compare ) {
     499
     500                        case '<':
     501                        case '=':
     502                        case '>':
     503                        case '<=':
     504                        case '>=':
     505                            if ( self::$schema[ $slug ]['has_multiple_val'] ) {
     506                                $filter_str[] = '1=1';
     507                                break;
     508                            }
     509                            $filter_str[] = 'c.' . $slug . ' ' . $compare . ' \'' . esc_sql( $val ) . '\'';
    500510                            break;
    501                         }
    502                         $filter_str[] = 'c.' . $slug . ' ' . $compare . ' \'' . $val . '\'';
    503                         break;
    504 
    505                     case 'BETWEEN':
    506                         $filter_str[] = 'c.' . $slug . ' BETWEEN \'' . $val[0] . '\' AND \'' . $val[1] . '\'';
    507                         break;
    508 
    509                     case 'IN':
    510                         if ( self::$schema[ $slug ]['has_multiple_val'] ) {
    511 
    512                             $filter_str[] = 'c.' . $slug . ' RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
    513 
    514                         } else {
    515 
    516                             $filter_str[] = 'c.' . $slug . ' IN ( \'' . implode( '\', \'', $val ) . '\' )';
    517                         }
    518                         break;
    519 
    520                     case 'NOT IN':
    521                         if ( self::$schema[ $slug ]['has_multiple_val'] ) {
    522 
    523                             $filter_str[] = 'c.' . $slug . ' NOT RLIKE \'(^|[|])(' . implode( '|', $val ) . ')($|[|])\'';
    524 
    525                         } else {
    526 
    527                             $filter_str[] = 'c.' . $slug . ' NOT IN ( \'' . implode( '\', \'', $val ) . '\' )';
    528                         }
    529                         break;
     511
     512                        case 'BETWEEN':
     513                            $filter_str[] = 'c.' . $slug . ' BETWEEN \'' . esc_sql( $val[0] ) . '\' AND \'' . esc_sql( $val[1] ) . '\'';
     514                            break;
     515
     516                        case 'IN':
     517                            if ( self::$schema[ $slug ]['has_multiple_val'] ) {
     518
     519                                $filter_str[] = 'c.' . $slug . ' RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
     520
     521                            } else {
     522
     523                                $filter_str[] = 'c.' . $slug . ' IN ( \'' . implode( '\', \'', esc_sql( $val ) ) . '\' )';
     524                            }
     525                            break;
     526
     527                        case 'NOT IN':
     528                            if ( self::$schema[ $slug ]['has_multiple_val'] ) {
     529
     530                                $filter_str[] = 'c.' . $slug . ' NOT RLIKE \'(^|[|])(' . implode( '|', esc_sql( $val ) ) . ')($|[|])\'';
     531
     532                            } else {
     533
     534                                $filter_str[] = 'c.' . $slug . ' NOT IN ( \'' . implode( '\', \'', esc_sql( $val ) ) . '\' )';
     535                            }
     536                            break;
     537                    }
    530538                }
    531539            }
  • supportcandy/trunk/includes/models/class-wpsc-ticket.php

    r2887316 r2895557  
    516516
    517517                // Invalid filter if it does not contain slug, compare and val indexes.
    518                 $slug    = isset( $filter['slug'] ) ? $filter['slug'] : false;
     518                $slug    = isset( $filter['slug'] ) ? WPSC_Functions::sanitize_sql_key( $filter['slug'] ) : false;
    519519                $compare = isset( $filter['compare'] ) ? $filter['compare'] : false;
    520520                $val     = isset( $filter['val'] ) ? $filter['val'] : false;
  • supportcandy/trunk/readme.txt

    r2889641 r2895557  
    66Tested up to: 6.2
    77Requires PHP: 7.4
    8 Stable tag: 3.1.4
     8Stable tag: 3.1.5
    99
    1010== Description ==
     
    105105
    106106== Changelog ==
     107
     108= 3.1.5 (April 07, 2023) =
     109* New: You can add multiple AND and OR conditions for all applicable places like ticket list filters, email notifications, Assign agent rules, SLA, etc.
     110* Fix: Important security fixes
    107111
    108112= 3.1.4 (March 27, 2023) =
  • supportcandy/trunk/supportcandy.php

    r2889641 r2895557  
    44 * Plugin URI: https://wordpress.org/plugins/supportcandy/
    55 * Description: Easy & Powerful support ticket system for WordPress
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: SupportCandy
    88 * Author URI: https://supportcandy.net/
     
    3131         * @var string
    3232         */
    33         public static $version = '3.1.4';
     33        public static $version = '3.1.5';
    3434
    3535        /**
Note: See TracChangeset for help on using the changeset viewer.