Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 99 |
|
0.00% |
0 / 3 |
CRAP | n/a |
0 / 0 |
|
| zeroBSCRM_screenOptionsPanel | |
0.00% |
0 / 90 |
|
0.00% |
0 / 1 |
3540 | |||
| zeroBS_outputScreenOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| zeroBS_canUpdateScreenOptions | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /* |
| 3 | * Jetpack CRM |
| 4 | * https://jetpackcrm.com |
| 5 | * V2.76+ |
| 6 | * |
| 7 | * Copyright 2020 Automattic |
| 8 | * |
| 9 | * Date: 27/05/18 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ZEROBSCRM_PATH' ) || exit( 0 ); |
| 13 | |
| 14 | // outputs top of page screen options panel :) |
| 15 | // (based on rights + pagekey) |
| 16 | function zeroBSCRM_screenOptionsPanel() { |
| 17 | |
| 18 | global $zbs; |
| 19 | |
| 20 | $screenOptionsHTML = ''; |
| 21 | $options = array(); |
| 22 | $rights = true; // this is 'okay for everyone' - current_user_can('administrator')? |
| 23 | $screenOpts = $zbs->global_screen_options(); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase |
| 24 | |
| 25 | switch ( $zbs->pageKey ) { |
| 26 | |
| 27 | // contact edit |
| 28 | case 'zbs-add-edit-contact-edit': |
| 29 | $options['metaboxes'] = zeroBSCRM_getCurrentMetaboxesFlatArr(); |
| 30 | |
| 31 | break; |
| 32 | |
| 33 | // company view |
| 34 | case 'zbs-add-edit-company-view': |
| 35 | $options['tablecolumns'] = array(); |
| 36 | |
| 37 | // global $zbsTransactionFields; |
| 38 | // get existing from setting |
| 39 | $activeTransactionColumns = array( 'date', 'id', 'total', 'status' ); // default |
| 40 | // not from setting, from screenopt $allColumns = zeroBSCRM_getSetting('company_view_docs_columns'); |
| 41 | // if (isset($allColumns['transactions']) && is_array($allColumns['transactions']) && count($allColumns['transactions']) > 0) $zbsTransactionFields = $allColumns['transactions']; |
| 42 | if ( |
| 43 | isset( $screenOpts ) && is_array( $screenOpts ) |
| 44 | && isset( $screenOpts['tablecolumns'] ) && is_array( $screenOpts['tablecolumns'] ) |
| 45 | && isset( $screenOpts['tablecolumns']['transactions'] ) |
| 46 | && is_array( $screenOpts['tablecolumns']['transactions'] ) |
| 47 | && count( $screenOpts['tablecolumns']['transactions'] ) > 0 |
| 48 | ) { |
| 49 | $activeTransactionColumns = $screenOpts['tablecolumns']['transactions']; |
| 50 | } |
| 51 | |
| 52 | $options['tablecolumns']['transactions'] = $activeTransactionColumns; |
| 53 | |
| 54 | break; |
| 55 | |
| 56 | } |
| 57 | |
| 58 | // build html |
| 59 | if ( count( $options ) > 0 ) { |
| 60 | |
| 61 | // build metabox show/hide |
| 62 | if ( isset( $options['metaboxes'] ) ) { |
| 63 | |
| 64 | // get hidden list |
| 65 | $hidden = array(); |
| 66 | if ( is_array( $screenOpts ) && isset( $screenOpts['mb_hidden'] ) && is_array( $screenOpts['mb_hidden'] ) ) { |
| 67 | $hidden = $screenOpts['mb_hidden']; |
| 68 | } |
| 69 | |
| 70 | // allow rearrange? |
| 71 | // Don't use anymore :) MS UI input $rearrangeButton = '<button class="ui mini button orange" type="button" id="zbs-metabox-manager"><i class="arrows alternate icon"></i>'.__('Re-arrange','zero-bs-crm').'</button>'; |
| 72 | $rearrangeButton = ''; |
| 73 | |
| 74 | // build html list |
| 75 | $screenOptionsHTML .= '<div class="zbs-screenoptions-opt zbs-screenoptions-metaboxes"><div class="ui dividing header">' . __( 'Boxes', 'zero-bs-crm' ) . $rearrangeButton . '</div><div class="ui divided grid"><div class="row">'; |
| 76 | |
| 77 | // show lists - normal |
| 78 | if ( isset( $options['metaboxes']['normal'] ) && is_array( $options['metaboxes']['normal'] ) && count( $options['metaboxes']['normal'] ) > 0 ) { |
| 79 | |
| 80 | // for now, just doing lines $screenOptionsHTML .= '<div class="ten wide column">'; |
| 81 | $screenOptionsHTML .= '<div class="sixteen wide column"><h4 class="ui header">' . __( 'Main Column', 'zero-bs-crm' ) . '</h4>'; |
| 82 | foreach ( $options['metaboxes']['normal'] as $mbID => $mb ) { |
| 83 | |
| 84 | $mbTitle = $mbID; |
| 85 | if ( is_array( $mb ) && isset( $mb['title'] ) ) { |
| 86 | $mbTitle = $mb['title']; |
| 87 | } |
| 88 | |
| 89 | // if can hide |
| 90 | $canHide = true; |
| 91 | if ( isset( $mb['capabilities'] ) && isset( $mb['capabilities']['can_hide'] ) && $mb['capabilities']['can_hide'] == false ) { |
| 92 | $canHide = false; |
| 93 | } |
| 94 | |
| 95 | if ( $canHide ) { |
| 96 | |
| 97 | $screenOptionsHTML .= '<div class="ui checkbox zbs-metabox-checkbox"><input type="checkbox" id="zbs-mb-' . $mbID . '"'; |
| 98 | if ( ! in_array( $mbID, $hidden ) ) { |
| 99 | $screenOptionsHTML .= ' checked="checked"'; |
| 100 | } |
| 101 | $screenOptionsHTML .= ' /><label for="zbs-mb-' . $mbID . '">' . $mbTitle . '</label></div>'; |
| 102 | |
| 103 | } else { |
| 104 | |
| 105 | $screenOptionsHTML .= '<div class="ui checkbox zbs-metabox-checkbox"><input type="checkbox" id="zbs-mb-' . $mbID . '" checked="checked" disabled="disabled"><label for="zbs-mb-' . $mbID . '">' . $mbTitle . '</label></div>'; |
| 106 | |
| 107 | } |
| 108 | } |
| 109 | $screenOptionsHTML .= '</div>'; |
| 110 | |
| 111 | } |
| 112 | // show list - side |
| 113 | if ( isset( $options['metaboxes']['side'] ) && is_array( $options['metaboxes']['side'] ) && count( $options['metaboxes']['side'] ) > 0 ) { |
| 114 | |
| 115 | // for now, just doing lines $screenOptionsHTML .= '<div class="six wide column">'; |
| 116 | $screenOptionsHTML .= '<div class="sixteen wide column"><h4 class="ui header">' . __( 'Side', 'zero-bs-crm' ) . '</h4>'; |
| 117 | foreach ( $options['metaboxes']['side'] as $mbID => $mb ) { |
| 118 | |
| 119 | $mbTitle = $mbID; |
| 120 | if ( is_array( $mb ) && isset( $mb['title'] ) ) { |
| 121 | $mbTitle = $mb['title']; |
| 122 | } |
| 123 | |
| 124 | // if can hide |
| 125 | $canHide = true; |
| 126 | if ( isset( $mb['capabilities'] ) && isset( $mb['capabilities']['can_hide'] ) && $mb['capabilities']['can_hide'] == false ) { |
| 127 | $canHide = false; |
| 128 | } |
| 129 | |
| 130 | if ( $canHide ) { |
| 131 | $screenOptionsHTML .= '<div class="ui checkbox zbs-metabox-checkbox"><input type="checkbox" id="zbs-mb-' . $mbID . '"'; |
| 132 | if ( ! in_array( $mbID, $hidden ) ) { |
| 133 | $screenOptionsHTML .= ' checked="checked"'; |
| 134 | } |
| 135 | $screenOptionsHTML .= ' /><label for="zbs-mb-' . $mbID . '">' . $mbTitle . '</label></div>'; |
| 136 | } else { |
| 137 | |
| 138 | $screenOptionsHTML .= '<div class="ui checkbox zbs-metabox-checkbox"><input type="checkbox" id="zbs-mb-' . $mbID . '" checked="checked" disabled="disabled"><label for="zbs-mb-' . $mbID . '">' . $mbTitle . '</label></div>'; |
| 139 | |
| 140 | } |
| 141 | } |
| 142 | $screenOptionsHTML .= '</div>'; |
| 143 | |
| 144 | } |
| 145 | |
| 146 | $screenOptionsHTML .= '</div></div></div>'; // end row + grid + group |
| 147 | |
| 148 | } |
| 149 | |
| 150 | // build tablecolumns on/off |
| 151 | if ( isset( $options['tablecolumns'] ) && is_array( $options['tablecolumns'] ) && count( $options['tablecolumns'] ) > 0 ) { |
| 152 | |
| 153 | // build html list |
| 154 | $screenOptionsHTML .= '<div class="zbs-screenoptions-opt zbs-screenoptions-tablecolumns"><div class="ui dividing header">' . __( 'Document Table Columns', 'zero-bs-crm' ) . '</div><div class="ui divided grid"><div class="row">'; |
| 155 | |
| 156 | foreach ( $options['tablecolumns'] as $type => $selectedColumns ) { |
| 157 | |
| 158 | switch ( $type ) { |
| 159 | |
| 160 | case 'transactions': |
| 161 | // get whole list (of poss columns - list fields, then columns) |
| 162 | // these are in two types of arrays, so first, shuffle them into a kinda standardised type |
| 163 | global $zbsTransactionFields, $zeroBSCRM_columns_transaction; |
| 164 | |
| 165 | // exclusions (wh temp workaround) |
| 166 | $excludeColumnKeys = array( 'customer', 'customer_name', 'currency', 'tagged', 'added', 'tax_rate', 'customeremail' ); |
| 167 | |
| 168 | $availableColumns = array(); |
| 169 | // all fields (inc custom:) |
| 170 | if ( isset( $zbsTransactionFields ) && is_array( $zbsTransactionFields ) && count( $zbsTransactionFields ) > 0 ) { |
| 171 | foreach ( $zbsTransactionFields as $tKey => $tDeets ) { |
| 172 | |
| 173 | // key => name |
| 174 | if ( ! in_array( $tKey, $excludeColumnKeys ) ) { |
| 175 | $availableColumns[ $tKey ] = $tDeets[1]; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | // all columns (any with same key will override) |
| 180 | if ( isset( $zeroBSCRM_columns_transaction['all'] ) && is_array( $zeroBSCRM_columns_transaction['all'] ) && count( $zeroBSCRM_columns_transaction['all'] ) > 0 ) { |
| 181 | foreach ( $zeroBSCRM_columns_transaction['all'] as $tKey => $tDeets ) { |
| 182 | |
| 183 | // key => name |
| 184 | if ( ! in_array( $tKey, $excludeColumnKeys ) ) { |
| 185 | $availableColumns[ $tKey ] = $tDeets[0]; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // show list of cols |
| 191 | if ( isset( $availableColumns ) && is_array( $availableColumns ) && count( $availableColumns ) > 0 ) { |
| 192 | |
| 193 | // for now, just doing lines $screenOptionsHTML .= '<div class="ten wide column">'; |
| 194 | $screenOptionsHTML .= '<div class="sixteen wide column" id="zbs-tablecolumns-' . $type . '"><h4 class="ui header">' . __( 'Transactions Table', 'zero-bs-crm' ) . '</h4>'; |
| 195 | foreach ( $availableColumns as $colKey => $colName ) { |
| 196 | |
| 197 | $screenOptionsHTML .= '<div class="ui checkbox zbs-tablecolumn-checkbox" data-colkey="' . $colKey . '"><input type="checkbox" id="zbs-tc-' . $colKey . '"'; |
| 198 | if ( in_array( $colKey, $selectedColumns ) ) { |
| 199 | $screenOptionsHTML .= ' checked="checked"'; |
| 200 | } |
| 201 | $screenOptionsHTML .= ' /><label for="zbs-tc-' . $colKey . '">' . $colName . '</label></div>'; |
| 202 | |
| 203 | } |
| 204 | $screenOptionsHTML .= '</div>'; |
| 205 | |
| 206 | } |
| 207 | |
| 208 | break; |
| 209 | |
| 210 | } |
| 211 | } // foreach type |
| 212 | |
| 213 | $screenOptionsHTML .= '</div></div></div>'; // end row + grid |
| 214 | |
| 215 | } // if tablecolumns |
| 216 | |
| 217 | } |
| 218 | |
| 219 | if ( ! empty( $screenOptionsHTML ) ) { |
| 220 | |
| 221 | ?> |
| 222 | <div id="zbs-screen-options" class="ui segment hidden"> |
| 223 | <?php echo ( $rights ? $screenOptionsHTML : '' ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped,WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase */ ?> |
| 224 | </div> |
| 225 | <?php |
| 226 | |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | function zeroBS_outputScreenOptions() { |
| 231 | |
| 232 | global $zbs; |
| 233 | |
| 234 | $screenOpts = $zbs->global_screen_options(); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase |
| 235 | |
| 236 | ?> |
| 237 | <script type="text/javascript">var zbsPageKey = '<?php echo esc_html( $zbs->pageKey ); ?>';var zbsScreenOptions = <?php echo json_encode( $screenOpts ); ?>;</script> |
| 238 | <?php |
| 239 | } |
| 240 | |
| 241 | add_action( 'admin_footer', 'zeroBS_outputScreenOptions' ); |
| 242 | |
| 243 | function zeroBS_canUpdateScreenOptions() { |
| 244 | |
| 245 | // does this need to check if is zbs wp usr? |
| 246 | |
| 247 | $id = get_current_user_id(); |
| 248 | if ( $id > 0 ) { |
| 249 | return true; |
| 250 | } |
| 251 | |
| 252 | return false; |
| 253 | } |