Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 267
0.00% covered (danger)
0.00%
0 / 16
CRAP
0.00% covered (danger)
0.00%
0 / 1
Details_Endpoint
0.00% covered (danger)
0.00%
0 / 266
0.00% covered (danger)
0.00%
0 / 16
18090
0.00% covered (danger)
0.00%
0 / 1
 register_endpoint
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 render_admin_notice
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 save_details
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
132
 get_value
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
210
 render_text_field
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
 render_price_field
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
 render_numeric_field
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
 render_date_field
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
30
 render_select_field
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
156
 render_telephone_field
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
182
 render_email_field
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
30
 render_text_area_field
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
 render_country_list_field
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
132
 render_radio_field
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
182
 render_checkbox_field
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
182
 render_field_by_type
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 1
240
1<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
2namespace Automattic\JetpackCRM;
3
4defined( 'ZEROBSCRM_PATH' ) || exit( 0 );
5
6/**
7 * Details endpoint
8 */
9class Details_Endpoint extends Client_Portal_Endpoint {
10
11    public static function register_endpoint( $endpoints, $client_portal ) { // phpcs:ignore Squiz.Commenting.FunctionComment.Missing
12        $new_endpoint = new Details_Endpoint( $client_portal );
13
14        $new_endpoint->portal                       = $client_portal;
15        $new_endpoint->slug                         = 'details';
16        $new_endpoint->name                         = __( 'Your Details', 'zero-bs-crm' );
17        $new_endpoint->hide_from_menu               = false;
18        $new_endpoint->menu_order                   = 1;
19        $new_endpoint->icon                         = 'fa-user';
20        $new_endpoint->template_name                = 'details.php';
21        $new_endpoint->add_rewrite_endpoint         = true;
22        $new_endpoint->should_check_user_permission = true;
23
24        $endpoints[] = $new_endpoint;
25        return $endpoints;
26    }
27
28    public function render_admin_notice() { // phpcs:ignore Squiz.Commenting.FunctionComment.Missing
29        $admin_message = __( 'This is the Client Portal contact details page. This will show the contact their details and allow them change information in the fields below. You can hide fields from this page in Settings → Client Portal → Fields.', 'zero-bs-crm' );
30        $this->portal->render->portal_viewing_as_admin_banner( $admin_message );
31    }
32
33    // Functions that were in the template file
34    public function save_details() { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle
35        if (
36            $_POST['save'] == 1
37            && isset( $_POST['_wpnonce'] )
38            && wp_verify_nonce( $_POST['_wpnonce'], 'jpcrm-update-client-details' )
39        ) {
40            $uid   = get_current_user_id();
41            $uinfo = get_userdata( $uid );
42            $cID   = zeroBS_getCustomerIDWithEmail( $uinfo->user_email );
43
44            // added !empty check - because if logged in as admin, saved deets, it made a new contact for them
45            if ( (int) $_POST['customer_id'] == $cID && ! empty( $cID ) ) {
46
47                // handle the password fields, if set.
48                if ( isset( $_POST['password'] ) && ! empty( $_POST['password'] ) && isset( $_POST['password2'] ) && ! empty( $_POST['password2'] ) ) {
49
50                    if ( $_POST['password'] != $_POST['password2'] ) {
51                        echo "<div class='zbs_alert danger'>" . esc_html__( 'Passwords do not match', 'zero-bs-crm' ) . '</div>';
52                    } else {
53                        // update password
54                        wp_set_password( sanitize_text_field( $_POST['password'] ), $uid );
55
56                        // log password change
57                        zeroBS_addUpdateLog(
58                            $cID,
59                            -1,
60                            -1,
61                            array(
62                                'type'      => __( 'Password updated via Client Portal', 'zero-bs-crm' ),
63                                'shortdesc' => __( 'Contact changed their password via the Client Portal', 'zero-bs-crm' ),
64                                'longdesc'  => '',
65                            ),
66                            'zerobs_customer'
67                        );
68
69                        // display message
70                        echo "<div class='zbs_alert'>" . esc_html__( 'Password updated.', 'zero-bs-crm' ) . '</div>';
71                        // update any details as well
72                        $this->portal->jpcrm_portal_update_details_from_post( $cID );
73                    }
74                } else {
75                    // update any details as well
76                    $this->portal->jpcrm_portal_update_details_from_post( $cID );
77                }
78
79                do_action( 'jpcrm_client_portal_after_save_details' );
80            }
81        }
82    }
83
84    function get_value( $fieldK, $zbsCustomer ) {
85        // get a value (this allows field-irrelevant global tweaks, like the addr catch below...)
86        $value = '';
87        if ( isset( $zbsCustomer[ $fieldK ] ) ) {
88            $value = $zbsCustomer[ $fieldK ];
89        }
90
91        // #backward-compatibility
92        // contacts got stuck in limbo as we upgraded db in 2 phases.
93        // following catches old str and modernises to v3.0
94        // make addresses their own objs 3.0+ and do away with this.
95        // ... hard typed to avoid custom field collisions, hacky at best.
96        switch ( $fieldK ) {
97
98            case 'secaddr1':
99                if ( isset( $zbsCustomer['secaddr_addr1'] ) ) {
100                    $value = $zbsCustomer['secaddr_addr1'];
101                }
102                break;
103
104            case 'secaddr2':
105                if ( isset( $zbsCustomer['secaddr_addr2'] ) ) {
106                    $value = $zbsCustomer['secaddr_addr2'];
107                }
108                break;
109
110            case 'seccity':
111                if ( isset( $zbsCustomer['secaddr_city'] ) ) {
112                    $value = $zbsCustomer['secaddr_city'];
113                }
114                break;
115
116            case 'seccounty':
117                if ( isset( $zbsCustomer['secaddr_county'] ) ) {
118                    $value = $zbsCustomer['secaddr_county'];
119                }
120                break;
121
122            case 'seccountry':
123                if ( isset( $zbsCustomer['secaddr_country'] ) ) {
124                    $value = $zbsCustomer['secaddr_country'];
125                }
126                break;
127
128            case 'secpostcode':
129                if ( isset( $zbsCustomer['secaddr_postcode'] ) ) {
130                    $value = $zbsCustomer['secaddr_postcode'];
131                }
132                break;
133        }
134
135        return $value;
136    }
137
138    function render_text_field( $fieldK, $fieldV, $value ) {
139        $extra_attributes = '';
140        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
141            $extra_attributes .= ' readonly disabled ';
142        }
143        ?>
144        <p>
145            <label class='label' for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
146            <input <?php echo esc_attr( $extra_attributes ); ?> type="text" name="zbsc_<?php echo esc_attr( $fieldK ); ?>" id="<?php echo esc_attr( $fieldK ); ?>" class="form-control widetext" placeholder="<?php echo esc_attr( isset( $fieldV[2] ) ? $fieldV[2] : '' ); ?>" value="<?php echo ! empty( $value ) ? esc_attr( $value ) : ''; ?>" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); /* phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase */ ?>" />
147        </p>
148        <?php
149    }
150
151    function render_price_field( $fieldK, $fieldV, $value ) {
152        $extra_attributes = '';
153        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
154            $extra_attributes .= ' readonly disabled ';
155        }
156        ?>
157        <p>
158            <label for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
159            <?php echo esc_html( zeroBSCRM_getCurrencyChr() ); ?> <input <?php echo esc_attr( $extra_attributes ); ?> style="width: 130px;display: inline-block;;" type="text" name="zbsc_<?php echo esc_attr( $fieldK ); ?>" id="<?php echo esc_attr( $fieldK ); ?>" class="form-control  numbersOnly" placeholder="<?php echo esc_attr( isset( $fieldV[2] ) ? $fieldV[2] : '' ); ?>" value="<?php echo ! empty( $value ) ? esc_attr( $value ) : ''; ?>" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); /* phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase */ ?>" />
160        </p>
161        <?php
162    }
163
164    /**
165     * Renders the HTML of a numeric field identified by $field_key with value $value.
166     *
167     * @param string $field_key The key associated with this field, used (for example) in the input name.
168     * @param object $field_settings Row from the meta table that needs to be updated.
169     * @param object $value Row from the meta table that needs to be updated.
170     *
171     * @return void
172     */
173    private function render_numeric_field( $field_key, $field_settings, $value ) {
174        $extra_attributes = '';
175        if ( isset( $field_settings['read_only'] ) && $field_settings['read_only'] ) {
176            $extra_attributes .= ' readonly disabled ';
177        }
178        ?>
179        <p>
180            <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo esc_html( $field_settings[1] ); ?>:</label>
181            <input <?php echo esc_attr( $extra_attributes ); ?> style="width: 130px;display: inline-block;;" type="text" name="zbsc_<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" class="form-control  numbersOnly" placeholder="<?php echo isset( $field_settings[2] ) ? esc_attr( $field_settings[2] ) : ''; ?>" value="<?php echo ! empty( $value ) ? esc_attr( $value ) : ''; ?>" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); ?>" />
182        </p>
183        <?php
184    }
185
186    function render_date_field( $field_key, $field_value, $value ) {
187        $extra_attributes = '';
188        if ( isset( $field_value['read_only'] ) && $field_value['read_only'] ) {
189            $extra_attributes .= ' readonly disabled';
190        }
191        $date_value = '';
192        if ( ! empty( $value ) && $value !== -99 ) {
193            $date_value = jpcrm_uts_to_date_str( $value, 'Y-m-d', true );
194        }
195        ?>
196            <p>
197                <label class='label' for="<?php echo esc_attr( $field_key ); ?>">
198                    <?php esc_html_e( $field_value[1], 'zero-bs-crm' ); ?>:
199                </label>
200                <input<?php echo esc_attr( $extra_attributes ); ?> type="date" name="zbsc_<?php echo esc_attr( $field_key ); ?>" id="zbsc_<?php echo esc_attr( $field_key ); ?>" placeholder="yyyy-mm-dd" value="<?php echo esc_attr( $date_value ); ?>"/>
201            </p>
202        <?php
203    }
204
205    function render_select_field( $fieldK, $fieldV, $value ) {
206        $extra_attributes = '';
207        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
208            $extra_attributes .= ' readonly disabled ';
209        }
210        ?>
211        <p>
212            <label class='label' for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
213            <select <?php echo esc_attr( $extra_attributes ); ?> name="zbsc_<?php echo esc_attr( $fieldK ); ?>" id="<?php echo esc_attr( $fieldK ); ?>" class="form-control zbs-watch-input" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); /* phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase */ ?>">
214                <?php
215                // pre DAL 2 = $fieldV[3], DAL2 = $fieldV[2]
216                $options = array();
217                if ( isset( $fieldV[3] ) && is_array( $fieldV[3] ) ) {
218                    $options = $fieldV[3];
219                } else {
220                    // DAL2 these don't seem to be auto-decompiled?
221                    // doing here for quick fix, maybe fix up the chain later.
222                    if ( isset( $fieldV[2] ) ) {
223                        $options = explode( ',', $fieldV[2] );
224                    }
225                }
226
227                if ( isset( $options ) && count( $options ) > 0 ) {
228
229                    // catcher
230                    echo '<option value="" disabled="disabled"';
231                    if ( empty( $value ) ) {
232                        echo ' selected="selected"';
233                    }
234                    echo '>' . esc_html__( 'Select', 'zero-bs-crm' ) . '</option>';
235
236                    foreach ( $options as $opt ) {
237
238                        echo '<option value="' . esc_attr( $opt ) . '"';
239                        if ( isset( $value ) && strtolower( $value ) == strtolower( $opt ) ) {
240                            echo ' selected="selected"';
241                        }
242                        // __ here so that things like country lists can be translated
243                        echo '>' . esc_html( __( $opt, 'zero-bs-crm' ) ) . '</option>';
244
245                    }
246                } else {
247                    echo '<option value="">' . esc_html__( 'No Options', 'zero-bs-crm' ) . '!</option>';
248                }
249
250                ?>
251            </select>
252            <input type="hidden" name="zbsc_<?php echo esc_attr( $fieldK ); ?>_dirtyflag" id="zbsc_<?php echo esc_attr( $fieldK ); ?>_dirtyflag" value="0" />
253        </p>
254        <?php
255    }
256
257    function render_telephone_field( $fieldK, $fieldV, $value, $zbsCustomer ) {
258        $extra_attributes = '';
259        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
260            $extra_attributes .= ' readonly disabled ';
261        }
262
263        $click2call = 0;
264        ?>
265        <p>
266        <label for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
267        <input <?php echo esc_attr( $extra_attributes ); ?> type="text" name="zbsc_<?php echo esc_attr( $fieldK ); ?>" id="<?php echo esc_attr( $fieldK ); ?>" class="form-control zbs-tel" placeholder="<?php echo esc_attr( isset( $fieldV[2] ) ? $fieldV[2] : '' ); ?>" value="<?php echo ! empty( $value ) ? esc_attr( $value ) : ''; ?>" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); /* phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase */ ?>" />
268        <?php
269        if ( $click2call == '1' && isset( $zbsCustomer[ $fieldK ] ) && ! empty( $zbsCustomer[ $fieldK ] ) ) {
270            echo '<a href="' . esc_attr( zeroBSCRM_clickToCallPrefix() . $zbsCustomer[ $fieldK ] ) . '" class="button"><i class="fa fa-phone"></i> ' . esc_html( $zbsCustomer[ $fieldK ] ) . '</a>';}
271        ?>
272        <?php
273        if ( $fieldK == 'mobtel' ) {
274
275            $sms_class = 'send-sms-none';
276            $sms_class = apply_filters( 'zbs_twilio_sms', $sms_class );
277            do_action( 'zbs_twilio_nonce' );
278
279            $customerMob = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
280            if ( is_array( $zbsCustomer ) && isset( $zbsCustomer[ $fieldK ] ) && ! empty( $zbsCustomer['id'] ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
281                $customerMob = zeroBS_customerMobile( $zbsCustomer['id'], $zbsCustomer ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
282            }
283
284            if ( ! empty( $customerMob ) ) {
285                echo '<a class="' . esc_attr( $sms_class ) . ' button" data-smsnum="' . esc_attr( $customerMob ) . '"><i class="mobile alternate icon"></i> ' . esc_html__( 'SMS', 'zero-bs-crm' ) . ': ' . esc_html( $customerMob ) . '</a>';
286            }
287        }
288
289        ?>
290        </p>
291        <?php
292    }
293
294    function render_email_field( $fieldK, $fieldV, $value ) {
295        $extra_attributes = '';
296        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
297            $extra_attributes .= ' readonly disabled ';
298        }
299
300        ?>
301        <p>
302        <label for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
303        <div class="<?php echo esc_attr( $fieldK ); ?>">
304            <input <?php echo esc_attr( $extra_attributes ); ?> type="text" name="zbsc_<?php echo esc_attr( $fieldK ); ?>" id="<?php echo esc_attr( $fieldK ); ?>" class="form-control zbs-email" placeholder="<?php echo esc_attr( isset( $fieldV[2] ) ? $fieldV[2] : '' ); ?>" value="<?php echo ! empty( $value ) ? esc_attr( $value ) : ''; ?>" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); /* phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase */ ?>" />
305        </div>
306        </p>
307        <?php
308    }
309
310    /**
311     * Renders the HTML of a textarea identified by $field_key with value $value.
312     *
313     * @param string $field_key The key associated with this field, used (for example) in the input name.
314     * @param object $field_settings Row from the meta table that needs to be updated.
315     * @param object $value Row from the meta table that needs to be updated.
316     *
317     * @return void
318     */
319    private function render_text_area_field( $field_key, $field_settings, $value ) {
320        $extra_attributes = '';
321        if ( isset( $field_settings['read_only'] ) && $field_settings['read_only'] ) {
322            $extra_attributes .= ' readonly disabled ';
323        }
324        ?>
325        <p>
326        <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo esc_html( $field_settings[1] ); ?>:</label>
327        <textarea <?php echo esc_attr( $extra_attributes ); ?> name="zbsc_<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" class="form-control" placeholder="<?php echo isset( $field_settings[2] ) ? esc_attr( $field_settings[2] ) : ''; ?>" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); ?>"><?php echo ! empty( $value ) ? esc_attr( $value ) : ''; ?></textarea>
328        </p>
329        <?php
330    }
331
332    function render_country_list_field( $fieldK, $fieldV, $value, $showCountryFields ) {
333        $extra_attributes = '';
334        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
335            $extra_attributes .= ' readonly disabled ';
336        }
337
338        $countries = zeroBSCRM_loadCountryList();
339
340        if ( $showCountryFields == '1' ) {
341
342            ?>
343            <p>
344            <label for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
345            <select <?php echo esc_attr( $extra_attributes ); ?> name="zbsc_<?php echo esc_attr( $fieldK ); ?>" id="<?php echo esc_attr( $fieldK ); ?>" class="form-control" autocomplete="<?php echo esc_attr( jpcrm_disable_browser_autocomplete() ); /* phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase */ ?>">
346                <?php
347
348                if ( isset( $countries ) && count( $countries ) > 0 ) {
349
350                    // catcher
351                    echo '<option value="" disabled="disabled"';
352                    if ( empty( $value ) ) {
353                        echo ' selected="selected"';
354                    }
355                    echo '>' . esc_html__( 'Select', 'zero-bs-crm' ) . '</option>';
356
357                    foreach ( $countries as $countryKey => $country ) {
358
359                        // temporary fix for people storing "United States" but also "US"
360                        // needs a migration to iso country code, for now, catch the latter (only 1 user via api)
361
362                        echo '<option value="' . esc_attr( $country ) . '"';
363                        if ( isset( $value ) && (
364                                strtolower( $value ) == strtolower( $country )
365                                ||
366                                strtolower( $value ) == strtolower( $countryKey )
367                            ) ) {
368                            echo ' selected="selected"';
369                        }
370                        echo '>' . esc_html( $country ) . '</option>';
371
372                    }
373                } else {
374                    echo '<option value="">' . esc_html__( 'No Countries Loaded', 'zero-bs-crm' ) . '!</option>';
375                }
376
377                ?>
378            </select>
379            </p>
380            <?php
381
382        }
383    }
384
385    function render_radio_field( $fieldK, $fieldV, $value, $postPrefix ) {
386        $extra_attributes = '';
387        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
388            $extra_attributes .= ' readonly disabled ';
389        }
390
391        ?>
392        <p>
393        <label for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
394        <div class="zbs-field-radio-wrap">
395            <?php
396
397            // pre DAL 2 = $fieldV[3], DAL2 = $fieldV[2]
398            $options = false;
399            if ( isset( $fieldV[3] ) && is_array( $fieldV[3] ) ) {
400                $options = $fieldV[3];
401            } else {
402                // DAL2 these don't seem to be auto-decompiled?
403                // doing here for quick fix, maybe fix up the chain later.
404                if ( isset( $fieldV[2] ) ) {
405                    $options = explode( ',', $fieldV[2] );
406                }
407            }
408
409            if ( isset( $options ) && is_array( $options ) && count( $options ) > 0 && $options[0] != '' ) {
410
411                $optIndex = 0;
412
413                foreach ( $options as $opt ) {
414                    // <label><input type="radio" name="group1" id="x" /> <span>Label text x</span></label>
415                    echo '<div class="zbs-radio">';
416                    echo '<label for="' . esc_attr( $fieldK ) . '-' . esc_attr( $optIndex ) . '"><input ' . esc_attr( $extra_attributes ) . ' type="radio" name="' . esc_attr( $postPrefix . $fieldK ) . '" id="' . esc_attr( $fieldK ) . '-' . esc_attr( $optIndex ) . '" value="' . esc_attr( $opt ) . '"';
417                    if ( isset( $value ) && $value == $opt ) {
418                        echo ' checked="checked"';
419                    }
420                    echo ' /> <span>' . esc_html( $opt ) . '</span></label></div>';
421
422                    ++$optIndex;
423                }
424            } else {
425                echo '-';
426            }
427
428            ?>
429        </div>
430        </p>
431        <?php
432    }
433
434    function render_checkbox_field( $fieldK, $fieldV, $value, $postPrefix ) {
435        $extra_attributes = apply_filters( 'jpcrm_client_portal_detail_field_extra_attributes', $fieldK, $fieldV );
436        if ( isset( $fieldV['read_only'] ) && $fieldV['read_only'] ) {
437            $extra_attributes .= ' readonly disabled ';
438        }
439        ?>
440        <p>
441        <label for="<?php echo esc_attr( $fieldK ); ?>"><?php esc_html_e( $fieldV[1], 'zero-bs-crm' ); ?>:</label>
442        <div class="zbs-field-checkbox-wrap">
443            <?php
444
445            // pre DAL 2 = $fieldV[3], DAL2 = $fieldV[2]
446            $options = false;
447            if ( isset( $fieldV[3] ) && is_array( $fieldV[3] ) ) {
448                $options = $fieldV[3];
449            } else {
450                // DAL2 these don't seem to be auto-decompiled?
451                // doing here for quick fix, maybe fix up the chain later.
452                if ( isset( $fieldV[2] ) ) {
453                    $options = explode( ',', $fieldV[2] );
454                }
455            }
456
457            // split fields (multi select)
458            $dataOpts = array();
459            if ( ! empty( $value ) ) {
460                $dataOpts = explode( ',', $value );
461            }
462
463            if ( isset( $options ) && is_array( $options ) && count( $options ) > 0 && $options[0] != '' ) {
464
465                $optIndex = 0;
466
467                foreach ( $options as $opt ) {
468                    echo '<div class="zbs-cf-checkbox">';
469                    echo '<label for="' . esc_attr( $fieldK ) . '-' . esc_attr( $optIndex ) . '"><input ' . esc_attr( $extra_attributes ) . ' type="checkbox" name="' . esc_attr( $postPrefix . $fieldK ) . '-' . esc_attr( $optIndex ) . '" id="' . esc_attr( $fieldK ) . '-' . esc_attr( $optIndex ) . '" value="' . esc_attr( $opt ) . '"';
470                    if ( in_array( $opt, $dataOpts ) ) {
471                        echo ' checked="checked"';
472                    }
473                    echo ' /> <span>' . esc_html( $opt ) . '</span></label></div>';
474
475                    ++$optIndex;
476
477                }
478            } else {
479                echo '-';
480            }
481
482            ?>
483        </div>
484        </p>
485        <?php
486    }
487
488    function render_field_by_type( $type, $fieldK, $fieldV, $value, $postPrefix, $showCountryFields, $zbsCustomer ) {
489        switch ( $type ) {
490            case 'text':
491                $this->render_text_field( $fieldK, $fieldV, $value );
492                break;
493            case 'price':
494                $this->render_price_field( $fieldK, $fieldV, $value );
495                break;
496            case 'date':
497                $this->render_date_field( $fieldK, $fieldV, $value );
498                break;
499
500            case 'select':
501                $this->render_select_field( $fieldK, $fieldV, $value );
502                break;
503
504            case 'tel':
505                $this->render_telephone_field( $fieldK, $fieldV, $value, $zbsCustomer );
506                break;
507
508            case 'email':
509                $this->render_email_field( $fieldK, $fieldV, $value );
510                break;
511
512            case 'textarea':
513                $this->render_text_area_field( $fieldK, $fieldV, $value );
514                break;
515
516            // Added 1.1.19
517            case 'selectcountry':
518                $this->render_country_list_field( $fieldK, $fieldV, $value, $showCountryFields );
519                break;
520
521            // 2.98.5 added autonumber, checkbox, radio
522            case 'autonumber':
523                // NOT SHOWN on portal :)
524                break;
525
526            // radio
527            case 'radio':
528                $this->render_radio_field( $fieldK, $fieldV, $value, $postPrefix );
529                break;
530
531            case 'checkbox':
532                $this->render_checkbox_field( $fieldK, $fieldV, $value, $postPrefix );
533                break;
534
535            case 'numberint':
536            case 'numberfloat':
537                $this->render_numeric_field( $fieldK, $fieldV, $value ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
538                break;
539
540            default:
541                do_action( 'jpcrm_client_portal_detail_render_field_by_type', $type, $fieldK, $fieldV, $value, $postPrefix, $showCountryFields, $zbsCustomer );
542                break;
543        }
544    }
545}