| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
$condition_options = array(); |
| 7 |
|
| 8 |
$custom_fields = get_terms([ |
| 9 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 10 |
'hide_empty' => false, |
| 11 |
'orderby' => 'meta_value', |
| 12 |
'meta_key' => 'wpsc_tf_label', |
| 13 |
'order' => 'ASC', |
| 14 |
]); |
| 15 |
|
| 16 |
foreach ( $custom_fields as $field ) { |
| 17 |
|
| 18 |
$label = get_term_meta( $field->term_id, 'wpsc_tf_label', true ); |
| 19 |
$field_type = get_term_meta( $field->term_id, 'wpsc_tf_type', true ); |
| 20 |
|
| 21 |
if( $field_type == 0 ){ |
| 22 |
|
| 23 |
switch ($field->slug) { |
| 24 |
|
| 25 |
case 'ticket_category': |
| 26 |
case 'ticket_priority': |
| 27 |
case 'ticket_status': |
| 28 |
case 'assigned_agent': |
| 29 |
|
| 30 |
$condition_options[] = array( |
| 31 |
'key' => $field->term_id, |
| 32 |
'label' => $label, |
| 33 |
'has_options' => 1, |
| 34 |
); |
| 35 |
break; |
| 36 |
|
| 37 |
case 'customer_name': |
| 38 |
case 'customer_email': |
| 39 |
case 'ticket_subject': |
| 40 |
case 'ticket_description': |
| 41 |
|
| 42 |
$condition_options[] = array( |
| 43 |
'key' => $field->term_id, |
| 44 |
'label' => $label, |
| 45 |
'has_options' => 0, |
| 46 |
); |
| 47 |
break; |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
} else { |
| 52 |
|
| 53 |
switch($field_type){ |
| 54 |
|
| 55 |
case 1 : |
| 56 |
case 5 : |
| 57 |
case 7 : |
| 58 |
case 8 : |
| 59 |
case 9 : |
| 60 |
|
| 61 |
$condition_options[] = array( |
| 62 |
'key' => $field->term_id, |
| 63 |
'label' => $label, |
| 64 |
'has_options' => 0, |
| 65 |
); |
| 66 |
break; |
| 67 |
|
| 68 |
case 2: |
| 69 |
case 3: |
| 70 |
case 4: |
| 71 |
|
| 72 |
$condition_options[] = array( |
| 73 |
'key' => $field->term_id, |
| 74 |
'label' => $label, |
| 75 |
'has_options' => 1, |
| 76 |
); |
| 77 |
break; |
| 78 |
|
| 79 |
default: |
| 80 |
$condition_options = apply_filters( 'wpsc_cond_options_custom_fields', $condition_options, $field_type, $field ); |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
$condition_options[] = array( |
| 89 |
'key' => 'agent_created', |
| 90 |
'label' => __('Ticket Submitted By','supportcandy'), |
| 91 |
'has_options' => 1, |
| 92 |
); |
| 93 |
|
| 94 |
$condition_options[] = array( |
| 95 |
'key' => 'user_type', |
| 96 |
'label' => __('User Type','supportcandy'), |
| 97 |
'has_options' => 1, |
| 98 |
); |
| 99 |
|
| 100 |
$condition_options[] = array( |
| 101 |
'key' => 'user_wp_roles', |
| 102 |
'label' => __('User Roles','supportcandy'), |
| 103 |
'has_options' => 1, |
| 104 |
); |
| 105 |
|
| 106 |
$condition_options = apply_filters( 'wpsc_condition_options', $condition_options ); |
| 107 |
|
| 108 |
$conditions = $conditions ? json_decode($conditions) : array(); |
| 109 |
?> |
| 110 |
|
| 111 |
<div id="<?php echo esc_attr($id)?>" class="row" style="background-color:#CCD1D1;padding-top:30px;padding-bottom:30px;"> |
| 112 |
|
| 113 |
<div class="col-sm-12 wpsc_conditions_container"> |
| 114 |
|
| 115 |
<?php foreach ($conditions as $condition): |
| 116 |
$current_key = ''; |
| 117 |
$current_condition_index = ''; |
| 118 |
|
| 119 |
?> |
| 120 |
|
| 121 |
<div class="row wpsc_condition_element" style="margin-bottom:20px;"> |
| 122 |
|
| 123 |
<div class="col-sm-4"> |
| 124 |
|
| 125 |
<select class="wpsc_condition_field form-control" onchange="wpsc_condition_change(this)"> |
| 126 |
<option value=""><?php _e('Select Condition', 'supportcandy')?></option> |
| 127 |
<?php foreach ( $condition_options as $index => $option ) : |
| 128 |
|
| 129 |
$selected = ''; |
| 130 |
if($option['key'] == $condition->field){ |
| 131 |
$selected = 'selected="selected"'; |
| 132 |
$current_key = $condition->field; |
| 133 |
$current_condition_index = $index; |
| 134 |
} |
| 135 |
|
| 136 |
?> |
| 137 |
|
| 138 |
<option <?php echo esc_attr($selected)?> data-hasoptions="<?php echo esc_attr($option['has_options'])?>" value="<?php echo esc_attr($option['key'])?>"><?php echo esc_attr($option['label'])?></option> |
| 139 |
|
| 140 |
<?php endforeach;?> |
| 141 |
|
| 142 |
</select> |
| 143 |
|
| 144 |
</div> |
| 145 |
|
| 146 |
<div class="col-sm-3 wpsc_condition_compare_container"> |
| 147 |
|
| 148 |
<?php |
| 149 |
if($condition_options[$current_condition_index]['has_options']){ |
| 150 |
|
| 151 |
?> |
| 152 |
<select class="wpsc_condition_compare form-control"> |
| 153 |
<option <?php echo esc_attr($condition->compare) == 'match' ? 'selected="selected"' : ''?> value="match"><?php _e('Matches', 'supportcandy')?></option> |
| 154 |
<option <?php echo esc_attr($condition->compare) == 'not_match' ? 'selected="selected"' : ''?>value="not_match"><?php _e('Not Matches', 'supportcandy')?></option> |
| 155 |
</select> |
| 156 |
<?php |
| 157 |
|
| 158 |
} else { |
| 159 |
|
| 160 |
?> |
| 161 |
<select class="wpsc_condition_compare form-control"> |
| 162 |
<option <?php echo esc_attr($condition->compare) == 'contain' ? 'selected="selected"' : ''?> value="contain"><?php _e('Contains', 'supportcandy')?></option> |
| 163 |
<option <?php echo esc_attr($condition->compare) == 'match' ? 'selected="selected"' : ''?> value="match"><?php _e('Matches', 'supportcandy')?></option> |
| 164 |
<option <?php echo esc_attr($condition->compare) == 'not_match' ? 'selected="selected"' : ''?> value="not_match"><?php _e('Not Matches', 'supportcandy')?></option> |
| 165 |
|
| 166 |
</select> |
| 167 |
<?php |
| 168 |
|
| 169 |
} |
| 170 |
?> |
| 171 |
|
| 172 |
</div> |
| 173 |
|
| 174 |
<div class="col-sm-4 wpsc_condition_value_container"> |
| 175 |
|
| 176 |
<?php |
| 177 |
if($condition_options[$current_condition_index]['has_options']){ |
| 178 |
|
| 179 |
$options = $this->get_condition_options($condition->field); |
| 180 |
|
| 181 |
?> |
| 182 |
<select class="wpsc_condition_value form-control"> |
| 183 |
<?php |
| 184 |
foreach ( $options as $option ) : |
| 185 |
|
| 186 |
$selected = $option['value'] == $condition->cond_val ? 'selected="selected"' : ''; |
| 187 |
?> |
| 188 |
<option <?php echo esc_attr($selected)?> value="<?php echo str_replace('"', """, stripcslashes($option['value']))?>"><?php echo esc_attr($option['label'])?></option> |
| 189 |
<?php |
| 190 |
|
| 191 |
endforeach; |
| 192 |
?> |
| 193 |
</select> |
| 194 |
<?php |
| 195 |
|
| 196 |
} else { |
| 197 |
|
| 198 |
?> |
| 199 |
<input type="text" class="wpsc_condition_value form-control" placeholder="<?php _e('Search...','supportcandy')?>" value="<?php echo esc_attr($condition->cond_val)?>"> |
| 200 |
<?php |
| 201 |
|
| 202 |
} |
| 203 |
?> |
| 204 |
|
| 205 |
</div> |
| 206 |
|
| 207 |
<div class="col-sm-1"> |
| 208 |
<button type="button" class="btn btn-danger btn-sm" onclick="wpsc_remove_condition(this)"><i class="fas fa-times"></i></button> |
| 209 |
</div> |
| 210 |
|
| 211 |
</div> |
| 212 |
|
| 213 |
<?php endforeach;?> |
| 214 |
|
| 215 |
</div> |
| 216 |
|
| 217 |
<div class="col-sm-12" style="padding-left:30px;"> |
| 218 |
<button type="button" class="btn btn-default btn-sm" onclick="wpsc_add_new_condition('<?php echo esc_attr($id)?>')"><?php _e('Add New','supportcandy')?></button> |
| 219 |
</div> |
| 220 |
|
| 221 |
</div> |
| 222 |
|
| 223 |
<div style="display:none;" class="wpsc_condition_template"> |
| 224 |
<div class="row wpsc_condition_element" style="margin-bottom:20px;"> |
| 225 |
<div class="col-sm-4"> |
| 226 |
<select class="wpsc_condition_field form-control" onchange="wpsc_condition_change(this)"> |
| 227 |
<option value=""><?php _e('Select Condition', 'supportcandy')?></option> |
| 228 |
<?php foreach ( $condition_options as $option ) :?> |
| 229 |
<option data-hasoptions="<?php echo esc_attr($option['has_options'])?>" value="<?php echo esc_attr($option['key'])?>"><?php echo esc_attr($option['label'])?></option> |
| 230 |
<?php endforeach;?> |
| 231 |
</select> |
| 232 |
</div> |
| 233 |
<div class="col-sm-3 wpsc_condition_compare_container"></div> |
| 234 |
<div class="col-sm-4 wpsc_condition_value_container"></div> |
| 235 |
<div class="col-sm-1"> |
| 236 |
<button type="button" class="btn btn-danger btn-sm" onclick="wpsc_remove_condition(this)"><i class="fas fa-times"></i></button> |
| 237 |
</div> |
| 238 |
</div> |
| 239 |
</div> |
| 240 |
|
| 241 |
<div style="display:none;" class="wpsc_cond_compare_dd_template"> |
| 242 |
<select class="wpsc_condition_compare form-control"> |
| 243 |
<option value="match"><?php _e('Matches', 'supportcandy')?></option> |
| 244 |
<option value="not_match"><?php _e('Not Matches', 'supportcandy')?></option> |
| 245 |
</select> |
| 246 |
</div> |
| 247 |
|
| 248 |
<div style="display:none;" class="wpsc_cond_compare_tf_template"> |
| 249 |
<select class="wpsc_condition_compare form-control"> |
| 250 |
<option value="contain"><?php _e('Contains', 'supportcandy')?></option> |
| 251 |
<option value="match"><?php _e('Matches', 'supportcandy')?></option> |
| 252 |
<option value="not_match"><?php _e('Not Matches', 'supportcandy')?></option> |
| 253 |
</select> |
| 254 |
</div> |
| 255 |
|
| 256 |
<div style="display:none;" class="wpsc_cond_val_dd_template"> |
| 257 |
<select class="wpsc_condition_value form-control" name=""></select> |
| 258 |
</div> |
| 259 |
|
| 260 |
<div style="display:none;" class="wpsc_cond_val_tf_template"> |
| 261 |
<input type="text" class="wpsc_condition_value form-control" placeholder="<?php _e('Search...','supportcandy')?>" value=""> |
| 262 |
</div> |
| 263 |
|