';
- echo zeroBSCRM_UI2_messageHTML('warning',$msg,'','disabled warning sign','failRetrieving');
- echo '
';
-
- // grim quick hack to hide save button
- echo '';
- }
+ }
+ if ( ! $this->has_permissions_to_edit ) {
+ // user does not have a role which can edit this object type
+ $this->preCheckFail( sprintf( __( 'You do not have permission to edit this %s.', 'zero-bs-crm' ), $zbs->DAL->typeStr( $this->objTypeID ) ) );
+ return false;
- /*
- * Code added to this function will be called just after the learn menu is output
- * (where we're on an edit page)
- */
- public function post_learn_menu_output(){
+ }
+ if ( $is_malformed_obj ) {
+ // not a perms issue, so show general error
+ $this->preCheckFail( sprintf( __( 'There was an error loading this %s.', 'zero-bs-crm' ), $zbs->DAL->typeStr( $this->objTypeID ) ) );
+ return false;
+ }
+ }
- // put screen options out
- zeroBSCRM_screenOptionsPanel();
+ // load if is legit
+ return true;
+ }
- }
+ public function preCheckFail( $msg = '' ) {
- public function drawEditView(){
+ echo '
';
+ echo zeroBSCRM_UI2_messageHTML( 'warning', $msg, '', 'disabled warning sign', 'failRetrieving' );
+ echo '
';
- // run pre-checks which verify ownership etc.
- $okayToDraw = $this->preChecks();
+ // grim quick hack to hide save button
+ echo '';
+ }
- // draw if okay :)
- if ($okayToDraw) $this->drawEditViewHTML();
+ /*
+ * Code added to this function will be called just after the learn menu is output
+ * (where we're on an edit page)
+ */
+ public function post_learn_menu_output() {
- }
+ // put screen options out
+ zeroBSCRM_screenOptionsPanel();
+ }
- public function drawEditViewHTML(){
+ public function drawEditView() {
- if (empty($this->objType) || empty($this->listViewSlug) || empty($this->singular) || empty($this->plural)){
+ // run pre-checks which verify ownership etc.
+ $okayToDraw = $this->preChecks();
+ // draw if okay :)
+ if ( $okayToDraw ) {
+ $this->drawEditViewHTML();
+ }
+ }
- echo zeroBSCRM_UI2_messageHTML('warning','Error Retrieving '.$this->singular,'There has been a problem retrieving your '.$this->singular.', if this issue persists, please contact support.','disabled warning sign','zbsCantLoadData');
- return false;
+ public function drawEditViewHTML() {
- }
+ if ( empty( $this->objType ) || empty( $this->listViewSlug ) || empty( $this->singular ) || empty( $this->plural ) ) {
- // catch id's passed where no contact exists for them.
- if ($this->isGhostRecord){
+ echo zeroBSCRM_UI2_messageHTML( 'warning', 'Error Retrieving ' . $this->singular, 'There has been a problem retrieving your ' . $this->singular . ', if this issue persists, please contact support.', 'disabled warning sign', 'zbsCantLoadData' );
+ return false;
- // brutal hide, then msg #ghostrecord
- ?>
-
singular,'There does not appear to be a '.$this->singular.' with this ID.','disabled warning sign','zbsCantLoadData');
- ?>
isGhostRecord ) {
- // catch if is new record + hide zbs-nav-view
- if ($this->isNewRecord){
+ // brutal hide, then msg #ghostrecord
+ ?>
+
+ singular, 'There does not appear to be a ' . $this->singular . ' with this ID.', 'disabled warning sign', 'zbsCantLoadData' );
+ ?>
+
+ isNewRecord ) {
- global $zbs;
+ // just hide button via css. Should just stop this via learn in time
+ ?>
+
+ preChecks();
+ }
+ global $zbs;
- ?>
@@ -1337,16 +1371,16 @@ class="form-control numbersOnly zbs-dc"
id=""
class="form-control numbersOnly zbs-dc"
- placeholder=""
- value=""
+ placeholder=""
+ value=""
autocomplete=""
/>
-
@@ -1356,395 +1390,397 @@ class="form-control numbersOnly zbs-dc"
id=""
class="form-control intOnly zbs-dc"
- placeholder=""
- value=""
+ placeholder=""
+ value=""
autocomplete=""
/>
:
-
:
-
+
- settings->get('showprefix') == 0 && $fieldKey == 'prefix') {
- break;
- }
+ case 'select':
+ //don't load prefix select if prefix is hidden in settings
+ if ($zbs->settings->get('showprefix') == 0 && $fieldKey == 'prefix') {
+ break;
+ }
?>
:
-
- 0){
- if (isset($options) && is_array($options) && count($options) > 0 && $options[0] != ''){
-
- // if $default, use that
- $selectVal = '';
- if ($value !== -99 && !empty($value)){
- $selectVal = $value;
- } elseif (!empty($default))
- $selectVal = $default;
-
- //catcher
- echo ''. esc_html__('Select','zero-bs-crm').' ';
-
- foreach ($options as $opt){
-
- echo '' . esc_html( $opt ) . ' ';
-
- }
-
- } else echo ''. esc_html__('No Options','zero-bs-crm').'! ';
-
- ?>
-
-
+
+ 0){
+ if (isset($options) && is_array($options) && count($options) > 0 && $options[0] != ''){
+
+ // if $default, use that
+ $selectVal = '';
+ if ($value !== -99 && !empty($value)){
+ $selectVal = $value;
+ } elseif (!empty($default))
+ $selectVal = $default;
+
+ //catcher
+ echo ''. esc_html__('Select','zero-bs-crm').' ';
+
+ foreach ($options as $opt){
+
+ echo '' . esc_html( $opt ) . ' ';
+
+ }
+
+ } else echo ''. esc_html__('No Options','zero-bs-crm').'! ';
+
+ ?>
+
+
- settings->get('clicktocall');
+ // Click 2 call?
+ $click2call = $zbs->settings->get('clicktocall');
?>
-
- // removed from email for now zbs-text-input
+ // added zbs-text-input class 5/1/18 - this allows "linkify" automatic linking
+ // ... via js
+ // removed from email for now zbs-text-input
?>
+
-
-
+
:
-
- " id="" class="form-control zbs-watch-input zbs-dc" autocomplete="">
+ 0){
+ // if got em
+ if (isset($zbsTaxRateTable) && is_array($zbsTaxRateTable) && count($zbsTaxRateTable) > 0){
- // if $default, use that
- $selectVal = '';
- if ($value !== -99 && !empty($value)){
- $selectVal = $value;
- } elseif (!empty($default))
- $selectVal = $default;
+ // if $default, use that
+ $selectVal = '';
+ if ($value !== -99 && !empty($value)){
+ $selectVal = $value;
+ } elseif (!empty($default))
+ $selectVal = $default;
- //catcher
- echo '' . esc_html( __( 'None', 'zero-bs-crm' ) ) . ' ';
+ //catcher
+ echo '' . esc_html( __( 'None', 'zero-bs-crm' ) ) . ' ';
- foreach ($zbsTaxRateTable as $taxRate){
+ foreach ($zbsTaxRateTable as $taxRate){
- echo '' . esc_html( $taxRate['name'] . ' (' . $taxRate['rate'] . '%)' ) . ' ';
+ echo '' . esc_html( $taxRate['name'] . ' (' . $taxRate['rate'] . '%)' ) . ' ';
- }
+ }
- } else echo ''. esc_html__('No Tax Rates Defined','zero-bs-crm').'! ';
+ } else echo ''. esc_html__('No Tax Rates Defined','zero-bs-crm').'! ';
- ?>
-
-
+ ?>
+
+
-
'.$fieldKey.''.print_r(array($fieldVal,$dataArr),1).' ';
+echo '
'.$fieldKey.''.print_r(array($fieldVal,$dataArr),1).' ';
} */
- if (!empty($fieldKey) && is_array($fieldVal)){
+if (!empty($fieldKey) && is_array($fieldVal)){
- // infer a default (Added post objmodels v3.0 as a potential.)
- $default = ''; if (is_array($fieldVal) && isset($fieldVal['default'])) $default = $fieldVal['default'];
+ // infer a default (Added post objmodels v3.0 as a potential.)
+ $default = ''; if (is_array($fieldVal) && isset($fieldVal['default'])) $default = $fieldVal['default'];
- // get a value (this allows field-irrelevant global tweaks, like the addr catch below...)
- // -99 = notset
- $value = -99; if (isset($dataArr[$fieldKey])) $value = $dataArr[$fieldKey];
+ // get a value (this allows field-irrelevant global tweaks, like the addr catch below...)
+ // -99 = notset
+ $value = -99; if (isset($dataArr[$fieldKey])) $value = $dataArr[$fieldKey];
- // custom classes for inputs
- $inputClasses = isset($fieldVal['custom-field']) ? ' zbs-custom-field' : '';
+ // custom classes for inputs
+ $inputClasses = isset($fieldVal['custom-field']) ? ' zbs-custom-field' : '';
- // contacts got stuck in limbo as we upgraded db in 2 phases.
- // following catches old str and modernises to v3.0
- // make addresses their own objs 3.0+ and do away with this.
- // ... hard typed to avoid custom field collisions, hacky at best.
- switch ($fieldKey){
+ // contacts got stuck in limbo as we upgraded db in 2 phases.
+ // following catches old str and modernises to v3.0
+ // make addresses their own objs 3.0+ and do away with this.
+ // ... hard typed to avoid custom field collisions, hacky at best.
+ switch ($fieldKey){
- case 'secaddr1':
- if (isset($dataArr['secaddr_addr1'])) $value = $dataArr['secaddr_addr1'];
- break;
+ case 'secaddr1':
+ if (isset($dataArr['secaddr_addr1'])) $value = $dataArr['secaddr_addr1'];
+ break;
- case 'secaddr2':
+ case 'secaddr2':
if (isset($dataArr['secaddr_addr2'])) $value = $dataArr['secaddr_addr2'];
- break;
+ break;
- case 'seccity':
- if (isset($dataArr['secaddr_city'])) $value = $dataArr['secaddr_city'];
- break;
+ case 'seccity':
+ if (isset($dataArr['secaddr_city'])) $value = $dataArr['secaddr_city'];
+ break;
- case 'seccounty':
- if (isset($dataArr['secaddr_county'])) $value = $dataArr['secaddr_county'];
- break;
+ case 'seccounty':
+ if (isset($dataArr['secaddr_county'])) $value = $dataArr['secaddr_county'];
+ break;
- case 'seccountry':
- if (isset($dataArr['secaddr_country'])) $value = $dataArr['secaddr_country'];
- break;
+ case 'seccountry':
+ if (isset($dataArr['secaddr_country'])) $value = $dataArr['secaddr_country'];
+ break;
- case 'secpostcode':
- if (isset($dataArr['secaddr_postcode'])) $value = $dataArr['secaddr_postcode'];
- break;
- }
- global $zbs;
+ case 'secpostcode':
+ if (isset($dataArr['secaddr_postcode'])) $value = $dataArr['secaddr_postcode'];
+ break;
+ }
+ global $zbs;
- switch ($fieldVal[0]){
+ switch ($fieldVal[0]){
- case 'text':
+ case 'text':
- ?>
:
-
- :
-
+ ?> :
+
-
+
- :
-
+ ?> :
+
-
+
- :
-
+ ?> :
+
-
+
-
+ }
+ ?>
:
-
:
-
+ ?> :
+
-
+
- settings->get('showprefix') == 0 && $fieldKey == 'prefix') {
- break;
+ break;
}
- ?>
:
-
-
- 0){
- if (isset($options) && is_array($options) && count($options) > 0 && $options[0] != ''){
-
- // if $default, use that
- $selectVal = '';
- if ($value !== -99 && !empty($value)){
- $selectVal = $value;
- } elseif (!empty($default))
- $selectVal = $default;
-
- //catcher
- echo ''. esc_html__('Select','zero-bs-crm').' ';
-
- foreach ($options as $opt){
-
- echo '' . esc_html( $opt ) . ' ';
+ ?>:
+
+
+ 0){
+ if (isset($options) && is_array($options) && count($options) > 0 && $options[0] != ''){
+
+ // if $default, use that
+ $selectVal = '';
+ if ($value !== -99 && !empty($value)){
+ $selectVal = $value;
+ } elseif (!empty($default))
+ $selectVal = $default;
+
+ //catcher
+ echo ''. esc_html__('Select','zero-bs-crm').' ';
+
+ foreach ($options as $opt){
+
+ echo '' . esc_html( $opt ) . ' ';
- }
+ }
- } else echo ''. esc_html__('No Options','zero-bs-crm').'! ';
+ } else echo ''. esc_html__('No Options','zero-bs-crm').'! ';
- ?>
-
-
-
+
+
+ settings->get('clicktocall');
+ // Click 2 call?
+ $click2call = $zbs->settings->get('clicktocall');
- ?>
:
-
+ ?> :
+
-
- ' . esc_html( $value ) . ''; ?>
+
+ ' . esc_html( $value ) . ''; ?>
- '. esc_html__('SMS','zero-bs-crm').': ' . esc_html( $customerMob ) . '';
+ $customerMob = '';
+ // wh genericified
+ //if (is_array($dataArr) && isset($dataArr[$fieldKey]) && isset($dataArr['id'])) $customerMob = zeroBS_customerMobile($dataArr['id'],$dataArr);
+ if ($value !== -99) $customerMob = $value;
+
+ if (!empty($customerMob)) echo ' '. esc_html__('SMS','zero-bs-crm').': ' . esc_html( $customerMob ) . ' ';
- }
+ }
- ?>
-
+
- // removed from email for now zbs-text-input
+ // added zbs-text-input class 5/1/18 - this allows "linkify" automatic linking
+ // ... via js
+ // removed from email for now zbs-text-input
- ?>
:
-
- :
-
-
- :
+
+
+ :
-
-
- :
+
+
+ 0){
- if (isset($countries) && count($countries) > 0){
+ #if (isset($fieldVal[3]) && count($fieldVal[3]) > 0){
+ if (isset($countries) && count($countries) > 0){
- //catcher
- echo ''. esc_html__('Select','zero-bs-crm').' ';
+ //catcher
+ echo ''. esc_html__('Select','zero-bs-crm').' ';
- foreach ($countries as $countryKey => $country){
+ foreach ($countries as $countryKey => $country){
- // temporary fix for people storing "United States" but also "US"
- // needs a migration to iso country code, for now, catch the latter (only 1 user via api)
+ // temporary fix for people storing "United States" but also "US"
+ // needs a migration to iso country code, for now, catch the latter (only 1 user via api)
- echo '' . esc_html( $country ) . ' ';
+ echo '' . esc_html( $country ) . ' ';
- }
-
+ }
+
- } else echo ''. esc_html__('No Countries Loaded','zero-bs-crm').' ';
+ } else echo ''. esc_html__('No Countries Loaded','zero-bs-crm').' ';
- ?>
-
-
+
+ :
-
- :
+
+ ';
+ // we also output as input, which stops any overwriting + makes new ones for new records
+ echo ' ';
- ?>
-
+
:
-
-
+
+ :
-
-
-
:
+
+
+ 0){
- if (isset($options) && is_array($options) && count($options) > 0 && $options[0] != ''){
+ //if (isset($fieldVal[3]) && count($fieldVal[3]) > 0){
+ if (isset($options) && is_array($options) && count($options) > 0 && $options[0] != ''){
- $optIndex = 0;
+ $optIndex = 0;
- foreach ($options as $opt){
+ foreach ($options as $opt){
- echo '
' . esc_html( $opt ) . '
';
+ echo '
' . esc_html( $opt ) . '
';
- $optIndex++;
+ $optIndex++;
- }
+ }
- } else echo '
'. esc_html__('No Options','zero-bs-crm').'! ';
+ } else echo '
'. esc_html__('No Options','zero-bs-crm').'! ';
- ?>
-
-
-
+
+
+ :
-
-
- :
+
+
+ 0){
+ // if got em
+ if (isset($zbsTaxRateTable) && is_array($zbsTaxRateTable) && count($zbsTaxRateTable) > 0){
- // if $default, use that
- $selectVal = '';
- if ($value !== -99 && !empty($value)){
- $selectVal = $value;
- } elseif (!empty($default))
- $selectVal = $default;
+ // if $default, use that
+ $selectVal = '';
+ if ($value !== -99 && !empty($value)){
+ $selectVal = $value;
+ } elseif (!empty($default))
+ $selectVal = $default;
- //catcher
- echo '' . esc_html( __( 'None', 'zero-bs-crm' ) ) . ' ';
+ //catcher
+ echo '' . esc_html( __( 'None', 'zero-bs-crm' ) ) . ' ';
- foreach ($zbsTaxRateTable as $taxRate){
+ foreach ($zbsTaxRateTable as $taxRate){
- echo '' . esc_html( $taxRate['name'] . ' (' . $taxRate['rate'] . '%)' ) . ' ';
+ echo '' . esc_html( $taxRate['name'] . ' (' . $taxRate['rate'] . '%)' ) . ' ';
- }
+ }
- } else echo ''. esc_html__('No Tax Rates Defined','zero-bs-crm').'! ';
+ } else echo ''. esc_html__('No Tax Rates Defined','zero-bs-crm').'! ';
- ?>
-
-
-
+
+
+ name
- $ret = $zbsTransactionFields[$colKey][1];
+ // all fields (inc custom:)
+ if ( isset( $zbsTransactionFields ) && is_array( $zbsTransactionFields ) && isset( $zbsTransactionFields[ $colKey ] ) ) {
- }
- // all columns (any with same key will override)
- if (isset($zeroBSCRM_columns_transaction['all']) && is_array($zeroBSCRM_columns_transaction['all']) && isset($zeroBSCRM_columns_transaction['all'][$colKey])){
+ // key => name
+ $ret = $zbsTransactionFields[ $colKey ][1];
- // key => name
- $ret = $zeroBSCRM_columns_transaction['all'][$colKey][0];
+ }
+ // all columns (any with same key will override)
+ if ( isset( $zeroBSCRM_columns_transaction['all'] ) && is_array( $zeroBSCRM_columns_transaction['all'] ) && isset( $zeroBSCRM_columns_transaction['all'][ $colKey ] ) ) {
- }
+ // key => name
+ $ret = $zeroBSCRM_columns_transaction['all'][ $colKey ][0];
- return $ret;
}
+ return $ret;
+}
+
// Temp here - takes a potential transaction column + returns html
// these are mimics of js draw funcs, move into globals (eventually)
// hacky at best... (WH wrote to quickly satisfy Borge freelance)
- function zeroBS_objDraw_transactionColumnTD($colKey='',$obj=false){
+function zeroBS_objDraw_transactionColumnTD( $colKey = '', $obj = false ) {
- $ret = '';
+ $ret = '';
- if (!empty($colKey) && is_array($obj)){
+ if ( ! empty( $colKey ) && is_array( $obj ) ) {
- $linkOpen = jpcrm_esc_link('edit',$obj['id'],ZBS_TYPE_TRANSACTION);
+ $linkOpen = jpcrm_esc_link( 'edit', $obj['id'], ZBS_TYPE_TRANSACTION );
- switch ($colKey){
+ switch ( $colKey ) {
- case 'id':
- $idRef = zeroBS_objDraw_generic_id($obj);
- if (isset($obj['ref'])){
- if (!empty($idRef)) $idRef .= ' - ';
- $idRef .= $obj['ref'];
- }
- $ret = '
'. $idRef .' ';
- $ret .= !empty($obj['title']) ? '
'.$obj['title'] : '';
- break;
- case 'editlink':
- $ret = '
'. __('Edit','zero-bs-crm') . " ";
- break;
- case 'date':
+ case 'id':
+ $idRef = zeroBS_objDraw_generic_id( $obj );
+ if ( isset( $obj['ref'] ) ) {
+ if ( ! empty( $idRef ) ) {
+ $idRef .= ' - ';
+ }
+ $idRef .= $obj['ref'];
+ }
+ $ret = '
' . $idRef . ' ';
+ $ret .= ! empty( $obj['title'] ) ? '
' . $obj['title'] : '';
+ break;
+ case 'editlink':
+ $ret = '
' . __( 'Edit', 'zero-bs-crm' ) . ' ';
+ break;
+ case 'date':
if ( isset( $obj['date_date'] ) ) {
$ret = $obj['date_date'];
}
- break;
- case 'item':
- $itemStr = '';
- if (isset($obj['meta'])) $itemStr = $obj['meta']['item']; // <3.0
- if (isset($obj['title'])) $itemStr = $obj['title']; // 3.0
- $ret = '
' . $itemStr . " ";
- break;
- case 'total':
- $total = 0;
- if (isset($obj['meta'])) $total = $obj['meta']['total']; // <3.0
- if (isset($obj['total'])) $total = $obj['total']; // 3.0
- $ret = zeroBSCRM_formatCurrency($total);
- break;
- case 'status':
- $status = '';
- if (isset($obj['meta'])) $status = $obj['meta']['status']; // <3.0
- if (isset($obj['status'])) $status = $obj['status']; // 3.0
- $ret = "
" . ucfirst($status) . " ";
- break;
-
+ break;
+ case 'item':
+ $itemStr = '';
+ if ( isset( $obj['meta'] ) ) {
+ $itemStr = $obj['meta']['item']; // <3.0
}
+ if ( isset( $obj['title'] ) ) {
+ $itemStr = $obj['title']; // 3.0
+ }
+ $ret = '
' . $itemStr . ' ';
+ break;
+ case 'total':
+ $total = 0;
+ if ( isset( $obj['meta'] ) ) {
+ $total = $obj['meta']['total']; // <3.0
+ }
+ if ( isset( $obj['total'] ) ) {
+ $total = $obj['total']; // 3.0
+ }
+ $ret = zeroBSCRM_formatCurrency( $total );
+ break;
+ case 'status':
+ $status = '';
+ if ( isset( $obj['meta'] ) ) {
+ $status = $obj['meta']['status']; // <3.0
+ }
+ if ( isset( $obj['status'] ) ) {
+ $status = $obj['status']; // 3.0
+ }
+ $ret = "
" . ucfirst( $status ) . ' ';
+ break;
- // if still empty, let's try generic text
- if (empty($ret)) $ret = zeroBS_objDraw_generic_text($colKey,$obj);
-
- }
+ }
- return $ret;
+ // if still empty, let's try generic text
+ if ( empty( $ret ) ) {
+ $ret = zeroBS_objDraw_generic_text( $colKey, $obj );
+ }
}
+ return $ret;
+}
+
// Temp here
// these are mimics of js draw funcs, move into globals (eventually)
- function zeroBS_objDraw_generic_id($obj=false){
-
- $ret = '';
+function zeroBS_objDraw_generic_id( $obj = false ) {
- if (is_array($obj)){
+ $ret = '';
- if (isset($obj['id'])) $ret = '#'.$obj['id'];
- if (isset($obj['zbsid'])) $ret = '#'.$obj['zbsid'];
-
+ if ( is_array( $obj ) ) {
- }
-
- return $ret;
+ if ( isset( $obj['id'] ) ) {
+ $ret = '#' . $obj['id'];
+ }
+ if ( isset( $obj['zbsid'] ) ) {
+ $ret = '#' . $obj['zbsid'];
+ }
}
- function zeroBS_objDraw_generic_text($key='',$obj=false){
-
- $ret = '';
- if (!empty($key) && is_array($obj)){
+ return $ret;
+}
+function zeroBS_objDraw_generic_text( $key = '', $obj = false ) {
- if (isset($obj[$key])) $ret = $obj[$key];
- if (isset($obj['meta']) && is_array($obj['meta']) && isset($obj['meta'][$key])) $ret = $obj['meta'][$key];
+ $ret = '';
- }
+ if ( ! empty( $key ) && is_array( $obj ) ) {
- return $ret;
+ if ( isset( $obj[ $key ] ) ) {
+ $ret = $obj[ $key ];
+ }
+ if ( isset( $obj['meta'] ) && is_array( $obj['meta'] ) && isset( $obj['meta'][ $key ] ) ) {
+ $ret = $obj['meta'][ $key ];
+ }
}
+ return $ret;
+}
-/* ======================================================
- / Table Views (temporary)
- ====================================================== */
-
- // quick workaround to turn 29999 into 2.99.99
- // noting that the real issue here is our non delimited migration numbers :facepalm:
- function zeroBSCRM_format_migrationVersion($ver=''){
-
- // catch 3000
- $ver = str_replace( '000', '0', $ver);
-
- switch ( strlen( $ver) ){
-
- // catch x.x
- case 2:
- $migrationName = substr($ver,0,1).'.'.substr($ver,1,1);
- break;
- // catch x.x.x
- case 3:
- $migrationName = substr($ver,0,1).'.'.substr($ver,1,1).'.'.substr($ver,2);
- break;
- case 4:
-
- // if second char is 0
- if ( substr( $ver, 1, 1 ) == 0 ){
+/*
+======================================================
+ / Table Views (temporary)
+ ====================================================== */
- // e.g. 3010 = 3.0.10
- $migrationName = substr($ver,0,1).'.'.substr($ver,1,1).'.'.substr($ver,2);
+ // quick workaround to turn 29999 into 2.99.99
+ // noting that the real issue here is our non delimited migration numbers :facepalm:
+function zeroBSCRM_format_migrationVersion( $ver = '' ) {
+ // catch 3000
+ $ver = str_replace( '000', '0', $ver );
- } else {
+ switch ( strlen( $ver ) ) {
- // e.g. 3111 = 3.11.1
- $migrationName = substr($ver,0,1).'.'.substr($ver,1,2).'.'.substr($ver,3);
+ // catch x.x
+ case 2:
+ $migrationName = substr( $ver, 0, 1 ) . '.' . substr( $ver, 1, 1 );
+ break;
+ // catch x.x.x
+ case 3:
+ $migrationName = substr( $ver, 0, 1 ) . '.' . substr( $ver, 1, 1 ) . '.' . substr( $ver, 2 );
+ break;
+ case 4:
+ // if second char is 0
+ if ( substr( $ver, 1, 1 ) == 0 ) {
- }
+ // e.g. 3010 = 3.0.10
+ $migrationName = substr( $ver, 0, 1 ) . '.' . substr( $ver, 1, 1 ) . '.' . substr( $ver, 2 );
+ } else {
- break;
+ // e.g. 3111 = 3.11.1
+ $migrationName = substr( $ver, 0, 1 ) . '.' . substr( $ver, 1, 2 ) . '.' . substr( $ver, 3 );
- // catch edge case 29999
- case 5:
+ }
- // e.g. 29999 = 2.99
- $migrationName = substr($ver,0,1).'.'.substr($ver,1,2);
+ break;
- break;
+ // catch edge case 29999
+ case 5:
+ // e.g. 29999 = 2.99
+ $migrationName = substr( $ver, 0, 1 ) . '.' . substr( $ver, 1, 2 );
- //
- default:
- $migrationName = $ver;
- break;
+ break;
+ default:
+ $migrationName = $ver;
+ break;
- }
+ }
- return $migrationName;
-
- }
+ return $migrationName;
+}
diff --git a/projects/plugins/crm/includes/ZeroBSCRM.Forms.php b/projects/plugins/crm/includes/ZeroBSCRM.Forms.php
index 3c44cb84570e..bbc4114e67da 100644
--- a/projects/plugins/crm/includes/ZeroBSCRM.Forms.php
+++ b/projects/plugins/crm/includes/ZeroBSCRM.Forms.php
@@ -1,5 +1,5 @@
- 'true',
- 'style' => 'simple'
- ), $atts ) );
+ extract(
+ shortcode_atts(
+ array(
+ 'id' => 'true',
+ 'style' => 'simple',
+ ),
+ $atts
+ )
+ );
// force enquement
zeroBSCRM_forms_enqueuements();
// return the form html
- return zeroBSCRM_forms_build_form_html($atts['id'],$atts['style'],__('CRM Forms: You have not entered a style in your form shortcode','zero-bs-crm'));
-
+ return zeroBSCRM_forms_build_form_html( $atts['id'], $atts['style'], __( 'CRM Forms: You have not entered a style in your form shortcode', 'zero-bs-crm' ) );
}
-add_shortcode('jetpackcrm_form','zeroBSCRM_forms_shortcode');
-add_shortcode('zbs_form','zeroBSCRM_forms_shortcode');
+add_shortcode( 'jetpackcrm_form', 'zeroBSCRM_forms_shortcode' );
+add_shortcode( 'zbs_form', 'zeroBSCRM_forms_shortcode' );
+
+function zeroBSCRM_forms_enqueuements() {
-function zeroBSCRM_forms_enqueuements(){
+ #} Assets we need specifically here
- #} Assets we need specifically here
-
- // js
- wp_enqueue_script("jquery");
- wp_enqueue_script('zbsfrontendformsjs');
-
- // css
- wp_enqueue_style('zbsfrontendformscss');
+ // js
+ wp_enqueue_script( 'jquery' );
+ wp_enqueue_script( 'zbsfrontendformsjs' );
+ // css
+ wp_enqueue_style( 'zbsfrontendformscss' );
}
// Register Forms widget
class ZBS_Form_Widget extends WP_Widget {
-
- /**
- * Register widget with WordPress.
- */
- public function __construct() {
- parent::__construct(
- 'zbs_form_widget', // Base ID
- 'Jetpack CRM Forms', // Name
- array( 'description' => __( 'Embed a lead capture form to your website', 'zero-bs-crm' ), ) // Args
- );
- }
-
+
+ /**
+ * Register widget with WordPress.
+ */
+ public function __construct() {
+ parent::__construct(
+ 'zbs_form_widget', // Base ID
+ 'Jetpack CRM Forms', // Name
+ array( 'description' => __( 'Embed a lead capture form to your website', 'zero-bs-crm' ) ) // Args
+ );
+ }
+
/**
* Front-end display of widget.
*
@@ -117,94 +118,96 @@ public function widget( $args, $instance ) {
}
echo $args['after_widget']; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
-
- /**
- * Back-end widget form.
- *
- * @see WP_Widget::form()
- *
- * @param array $instance Previously saved values from database.
+
+ /**
+ * Back-end widget form.
+ *
+ * @see WP_Widget::form()
+ *
+ * @param array $instance Previously saved values from database.
* @return string|void
- */
- public function form( $instance ) {
- if ( isset( $instance[ 'title' ] ) ) {
- $title = $instance[ 'title' ];
- }
- else {
- $title = __( 'Contact us', 'zero-bs-crm' );
- }
- if ( isset( $instance[ 'style' ] ) ) {
- $style = $instance[ 'style' ];
- }
- else {
- $style = __( 'Simple', 'zero-bs-crm' );
- }
- if ( isset( $instance[ 'id' ] ) ) {
- $id = $instance[ 'id' ];
- }
- else {
- $id = 0;
- }
- ?>
-
-
-
-
+ */
+ public function form( $instance ) {
+ if ( isset( $instance['title'] ) ) {
+ $title = $instance['title'];
+ } else {
+ $title = __( 'Contact us', 'zero-bs-crm' );
+ }
+ if ( isset( $instance['style'] ) ) {
+ $style = $instance['style'];
+ } else {
+ $style = __( 'Simple', 'zero-bs-crm' );
+ }
+ if ( isset( $instance['id'] ) ) {
+ $id = $instance['id'];
+ } else {
+ $id = 0;
+ }
+ ?>
+
+
+
+
- Style:
-
- >
- Naked
-
- >
- Simple
-
- >
- Content
-
-
-
-
-
-
-
-
-
-
- get_field_id( 'text' ) ); ?>">Style:
+
+ >
+ Naked
+
+ >
+ Simple
+
+ >
+ Content
+
+
+
+
+
+
+
+
+
+
+ ";
@@ -213,47 +216,47 @@ function zeroBSCRM_forms_formHTMLHeader(){
echo '';
}
-
}
-add_action('wp_head', 'zeroBSCRM_forms_formHTMLHeader');
+add_action( 'wp_head', 'zeroBSCRM_forms_formHTMLHeader' );
// return html of form
-function zeroBSCRM_forms_build_form_html($formID=-1, $formStyle='content', $fallbackMessage=''){
+function zeroBSCRM_forms_build_form_html( $formID = -1, $formStyle = 'content', $fallbackMessage = '' ) {
// check form ID & style
- if ($formID > 0 && in_array($formStyle,array('naked','content','simple','cgrab'))){
+ if ( $formID > 0 && in_array( $formStyle, array( 'naked', 'content', 'simple', 'cgrab' ) ) ) {
// 'cgrab' was original 'content'
- if ($formStyle === 'cgrab') $formStyle = 'content';
+ if ( $formStyle === 'cgrab' ) {
+ $formStyle = 'content';
+ }
// retrieve Form
- $form = zeroBS_getForm($formID);
+ $form = zeroBS_getForm( $formID );
#} This checks it found something
- if (is_array($form)){
+ if ( is_array( $form ) ) {
return call_user_func( 'jpcrm_' . $formStyle . '_form_html', $formID, $form );
}
-
}
return $fallbackMessage;
}
// return HTML for ReCaptcha (if using)
-function zeroBSCRM_forms_getRecaptcha(){
+function zeroBSCRM_forms_getRecaptcha() {
#} reCaptcha addition
- $reCaptcha = zeroBSCRM_getSetting('usegcaptcha');
- $reCaptchaKey = zeroBSCRM_getSetting('gcaptchasitekey');
- if ($reCaptcha && !empty($reCaptchaKey)) return '
';
+ $reCaptcha = zeroBSCRM_getSetting( 'usegcaptcha' );
+ $reCaptchaKey = zeroBSCRM_getSetting( 'gcaptchasitekey' );
+ if ( $reCaptcha && ! empty( $reCaptchaKey ) ) {
+ return '
';
+ }
return '';
-
}
-
// v3 form HTML builder (simple style)
function jpcrm_simple_form_html( $formid = -1, $formObject = array() ) {
@@ -262,38 +265,40 @@ function jpcrm_simple_form_html( $formid = -1, $formObject = array() ) {
?>
-
-
- !
- return $obj;
+ if ( $return ) {
+ return $x;
+ }
+ // this'll never work? echo $x;
- break;
+ break;
+ default:
+ // NON str/arr... should not be using this for them>!
+ return $obj;
- }
+ break;
}
+}
/**
* Recursively strips slashes from an array.
@@ -155,37 +156,38 @@ function zeroBSCRM_stripSlashesFromArr( $value ) { // phpcs:ignore WordPress.Nam
return $value;
}
- # from http://wordpress.stackexchange.com/questions/91900/how-to-force-a-404-on-wordpress
- function zeroBSCRM_force_404() {
- status_header( 404 );
- nocache_headers();
- include get_query_template( '404' );
- die( 0 );
- }
+ # from http://wordpress.stackexchange.com/questions/91900/how-to-force-a-404-on-wordpress
+function zeroBSCRM_force_404() {
+ status_header( 404 );
+ nocache_headers();
+ include get_query_template( '404' );
+ die( 0 );
+}
// WH not sure why we need this, shuttled off into zeroBSCRM_generateHash which is cleaner.
- function zeroBSCRM_GenerateHashForPost($postID=-1,$length=20){
-
- #} Brutal hash generator, for now
- if (!empty($postID)){
-
- return zeroBSCRM_generateHash($length);
+function zeroBSCRM_GenerateHashForPost( $postID = -1, $length = 20 ) {
- }
+ #} Brutal hash generator, for now
+ if ( ! empty( $postID ) ) {
- return '';
+ return zeroBSCRM_generateHash( $length );
}
- // WH centralised, we had zeroBSCRM_GenerateHashForPost - but as moving away from CPT's not sure why
- function zeroBSCRM_generateHash($length=20){
-
- $genLen = 20; if ($genLen < $length) $genLen = $length;
- $newMD5 = wp_generate_password($genLen, false);
+ return '';
+}
- return substr($newMD5,0,$length-1);
+ // WH centralised, we had zeroBSCRM_GenerateHashForPost - but as moving away from CPT's not sure why
+function zeroBSCRM_generateHash( $length = 20 ) {
+ $genLen = 20;
+ if ( $genLen < $length ) {
+ $genLen = $length;
}
+ $newMD5 = wp_generate_password( $genLen, false );
+
+ return substr( $newMD5, 0, $length - 1 );
+}
/*
* Creates an MD5 hash of $obj, (typically an array)
@@ -194,71 +196,78 @@ function zeroBSCRM_generateHash($length=20){
* @param $obj - {anything}
* @return string - md5 of $obj, json encoded and sorted
*/
- function jpcrm_generate_hash_of_obj( $obj ){
-
- // note this will return different if sort order different
- return md5( json_encode( $obj ) );
- }
+function jpcrm_generate_hash_of_obj( $obj ) {
- function zeroBSCRM_loadCountryList(){
- #} load country list
- global $zeroBSCRM_countries;
- if(!isset($zeroBSCRM_countries)) require_once( ZEROBSCRM_INCLUDE_PATH . 'wh.countries.lib.php');
+ // note this will return different if sort order different
+ return md5( json_encode( $obj ) );
+}
- return $zeroBSCRM_countries;
+function zeroBSCRM_loadCountryList() {
+ #} load country list
+ global $zeroBSCRM_countries;
+ if ( ! isset( $zeroBSCRM_countries ) ) {
+ require_once ZEROBSCRM_INCLUDE_PATH . 'wh.countries.lib.php';
}
- function zeroBSCRM_uniqueID(){
-
+ return $zeroBSCRM_countries;
+}
+
+function zeroBSCRM_uniqueID() {
+ #} When you're wrapping a func in another, and you're guaranteed it'll return a val, can just do this:
- #} When you're wrapping a func in another, and you're guaranteed it'll return a val, can just do this:
-
- $prefix = 'ab33id_';
- ##WLREMOVE
- $prefix = 'crmt_';
- ##/WLREMOVE
-
- return uniqid($prefix);
+ $prefix = 'ab33id_';
+ ##WLREMOVE
+ $prefix = 'crmt_';
+ ##/WLREMOVE
- }
+ return uniqid( $prefix );
+}
- function zeroBSCRM_ifV($v){
- if (isset($v)) echo $v;
+function zeroBSCRM_ifV( $v ) {
+ if ( isset( $v ) ) {
+ echo $v;
}
+}
// if is array and has value v, else
- function zbs_ifAV($a=array(),$v='',$else=false){
- if (is_array($a) && isset($a[$v])) return $a[$v];
- return $else;
- }
-
- function zbs_prettyprint($array){
- echo '
';
- var_dump($array);
- echo ' ';
+function zbs_ifAV( $a = array(), $v = '', $else = false ) {
+ if ( is_array( $a ) && isset( $a[ $v ] ) ) {
+ return $a[ $v ];
}
+ return $else;
+}
+function zbs_prettyprint( $array ) {
+ echo '
';
+ var_dump( $array );
+ echo ' ';
+}
- function zeroBS_delimiterIf($delimiter,$ifStr=''){
-
- if (!empty($ifStr)) return $delimiter;
+function zeroBS_delimiterIf( $delimiter, $ifStr = '' ) {
- return '';
+ if ( ! empty( $ifStr ) ) {
+ return $delimiter;
}
+ return '';
+}
// BE INCREADIBLY CAREFUL WITH THIS FUNC, it'll recursively delete a directory
// ... safety mechanism put in - if not defined will die :)
-function zeroBSCRM_del($dir) {
+function zeroBSCRM_del( $dir ) {
- if (!defined('ZBS_OKAY_TO_PROCEED')) exit('CANNOT');
- if (file_exists($dir) && is_dir($dir)){
- $files = array_diff(scandir($dir), array('.','..'));
- if (is_array($files)) foreach ($files as $file) {
- (is_dir("$dir/$file")) ? zeroBSCRM_del("$dir/$file") : unlink("$dir/$file");
- }
- return rmdir($dir);
+ if ( ! defined( 'ZBS_OKAY_TO_PROCEED' ) ) {
+ exit( 'CANNOT' );
+ }
+ if ( file_exists( $dir ) && is_dir( $dir ) ) {
+ $files = array_diff( scandir( $dir ), array( '.', '..' ) );
+ if ( is_array( $files ) ) {
+ foreach ( $files as $file ) {
+ ( is_dir( "$dir/$file" ) ) ? zeroBSCRM_del( "$dir/$file" ) : unlink( "$dir/$file" );
+ }
+ }
+ return rmdir( $dir );
}
}
@@ -269,17 +278,17 @@ function zeroBSCRM_del($dir) {
* @param bool $also_remove_hidden_files - shall we also clear files like .htaccess?
*
*/
-function jpcrm_delete_files_from_directory( $directory_path, $also_remove_hidden_files = false ){
+function jpcrm_delete_files_from_directory( $directory_path, $also_remove_hidden_files = false ) {
- if ( !is_dir( $directory_path ) ){
+ if ( ! is_dir( $directory_path ) ) {
return false;
}
- if ( $also_remove_hidden_files ){
+ if ( $also_remove_hidden_files ) {
- $files = glob( $directory_path . '{,.}*', GLOB_BRACE);
+ $files = glob( $directory_path . '{,.}*', GLOB_BRACE );
} else {
@@ -288,228 +297,211 @@ function jpcrm_delete_files_from_directory( $directory_path, $also_remove_hidden
}
// cycle through
- foreach( $files as $file ){
-
- if ( is_file( $file ) ) {
-
- unlink( $file );
+ foreach ( $files as $file ) {
- }
+ if ( is_file( $file ) ) {
+ unlink( $file );
+
+ }
}
}
-
function zeroBSCRM_user_last_login( $user_login, $user ) {
- update_user_meta( $user->ID, 'last_login', time() );
+ update_user_meta( $user->ID, 'last_login', time() );
}
add_action( 'wp_login', 'zeroBSCRM_user_last_login', 10, 2 );
-
function zeroBSCRM_currentUser_email() {
- $current_user = wp_get_current_user();
- return $current_user->user_email;
+ $current_user = wp_get_current_user();
+ return $current_user->user_email;
}
function zeroBSCRM_currentUser_displayName() {
- $current_user = wp_get_current_user();
- return $current_user->display_name;
+ $current_user = wp_get_current_user();
+ return $current_user->display_name;
}
/**
* Retrieve users of a specific wp role
*/
-function jpcrm_wordpress_users_with_role( $role = '' ) {
+function jpcrm_wordpress_users_with_role( $role = '' ) {
// needs role
- if (empty($role)) return array();
+ if ( empty( $role ) ) {
+ return array();
+ }
// retreive & return
$args = array(
- 'role' => $role,
- 'orderby' => 'user_nicename',
- 'order' => 'ASC'
+ 'role' => $role,
+ 'orderby' => 'user_nicename',
+ 'order' => 'ASC',
);
return get_users( $args );
-
}
-
/**
* Retrieve users with one of an array of specific wp roles
*/
-function jpcrm_wordpress_users_with_role_in( $roles = array() ) {
+function jpcrm_wordpress_users_with_role_in( $roles = array() ) {
// needs to be an array of roles
- if ( !is_array($roles) ) return array();
+ if ( ! is_array( $roles ) ) {
+ return array();
+ }
// retreive & return
$args = array(
- 'role__in' => $roles,
- 'orderby' => 'user_nicename',
- 'order' => 'ASC'
+ 'role__in' => $roles,
+ 'orderby' => 'user_nicename',
+ 'order' => 'ASC',
);
return get_users( $args );
-
}
-
/**
* Display last login time
- *
*/
-
-function zeroBSCRM_wpb_lastlogin($uid ) {
- $last_login = get_user_meta( $uid, 'last_login',true);
- if($last_login == ''){
- $the_login_date = __("Never","zero-bs-crm");
- }else{
- $the_login_date = human_time_diff($last_login);
+function zeroBSCRM_wpb_lastlogin( $uid ) {
+ $last_login = get_user_meta( $uid, 'last_login', true );
+ if ( $last_login == '' ) {
+ $the_login_date = __( 'Never', 'zero-bs-crm' );
+ } else {
+ $the_login_date = human_time_diff( $last_login );
}
- return $the_login_date;
-}
-
-
+ return $the_login_date;
+}
#} Pretty up long numbers
- function zeroBSCRM_prettifyLongInts($i){
-
- if ((int)$i > 999){
- return number_format($i);
- } else {
- if (zeroBSCRM_numberOfDecimals($i) > 2) return round($i,2); else return $i;
- }
-
- }
+function zeroBSCRM_prettifyLongInts( $i ) {
- // Brutal. http://snipplr.com/view/39450/
- function zeroBSCRM_prettyAbbr($size) {
- $size = preg_replace('/[^0-9]/','',$size);
- $sizes = array("", "k", "m");
- if ($size == 0) { return('n/a'); } else {
- return (round($size/pow(1000, ($i = floor(log($size, 1000)))), 0) . $sizes[$i]); }
+ if ( (int) $i > 999 ) {
+ return number_format( $i );
+ } elseif ( zeroBSCRM_numberOfDecimals( $i ) > 2 ) {
+ return round( $i, 2 );
+ } else {
+ return $i;
}
+}
+ // Brutal. http://snipplr.com/view/39450/
+function zeroBSCRM_prettyAbbr( $size ) {
+ $size = preg_replace( '/[^0-9]/', '', $size );
+ $sizes = array( '', 'k', 'm' );
+ if ( $size == 0 ) {
+ return( 'n/a' ); } else {
+ return ( round( $size / pow( 1000, ( $i = floor( log( $size, 1000 ) ) ) ), 0 ) . $sizes[ $i ] ); }
+}
#} how many decimal points?
- function zeroBSCRM_numberOfDecimals($value)
- {
- if ((int)$value == $value)
- {
- return 0;
- }
- else if (! is_numeric($value))
- {
- return false;
- }
-
- return strlen($value) - strrpos($value, '.') - 1;
+function zeroBSCRM_numberOfDecimals( $value ) {
+ if ( (int) $value == $value ) {
+ return 0;
+ } elseif ( ! is_numeric( $value ) ) {
+ return false;
}
+ return strlen( $value ) - strrpos( $value, '.' ) - 1;
+}
- function zeroBSCRM_mtime_float(){
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
+function zeroBSCRM_mtime_float() {
+ list($usec, $sec) = explode( ' ', microtime() );
+ return ( (float) $usec + (float) $sec );
+}
#} Does its best to find the real IP for user
- function zeroBSCRM_getRealIpAddr()
- {
- $ip = false;
- #} check ip from share internet
- if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']))
- {
- $ip=$_SERVER['HTTP_CLIENT_IP'];
- }
- #} To check ip is pass from proxy
- elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']))
- {
- $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- elseif (isset($_SERVER['REMOTE_ADDR']))
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- return $ip;
- }
+function zeroBSCRM_getRealIpAddr() {
+ $ip = false;
+ #} check ip from share internet
+ if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) && ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
+ }
+ #} To check ip is pass from proxy
+ elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
+ $ip = $_SERVER['REMOTE_ADDR'];
+ }
+ return $ip;
+}
// from https://stackoverflow.com/questions/5800927/how-to-identify-server-ip-address-in-php
- function zeroBSCRM_getServerIP(){
+function zeroBSCRM_getServerIP() {
- $ip = false;
+ $ip = false;
// this method is spoofable/not safe on all hosts
// non iis
if ( ! empty( $_SERVER['SERVER_ADDR'] ) ) {
$ip = $_SERVER['SERVER_ADDR']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
}
- // iis
- if (!$ip && isset($_SERVER['LOCAL_ADDR']) && !empty($_SERVER['LOCAL_ADDR'])) $ip = $_SERVER['LOCAL_ADDR'];
-
-
- // this method uses dns
- if (!$ip){
- $host= gethostname();
- $ip = gethostbyname($host);
- }
+ // iis
+ if ( ! $ip && isset( $_SERVER['LOCAL_ADDR'] ) && ! empty( $_SERVER['LOCAL_ADDR'] ) ) {
+ $ip = $_SERVER['LOCAL_ADDR'];
+ }
- return $ip;
+ // this method uses dns
+ if ( ! $ip ) {
+ $host = gethostname();
+ $ip = gethostbyname( $host );
}
-
+ return $ip;
+}
+
// deprecated 4.0.9
- function zeroBSCRM_ip_country()
- {
-
- return '';
- /*
- $ip = zeroBSCRM_getRealIpAddr(); $ip_data = false;
- $country = "Unknown";
-
- $ip_data_in = wp_remote_get( 'http://www.geoplugin.net/json.gp?ip='.$ip, array(
- 'timeout' => 15
- )
- );
+function zeroBSCRM_ip_country() {
- if ( is_wp_error( $ip_data_in ) ) {
-
- //$error_message = $response->get_error_message();
- //echo "Something went wrong: $error_message";
+ return '';
+ /*
+ $ip = zeroBSCRM_getRealIpAddr(); $ip_data = false;
+ $country = "Unknown";
- } else {
+ $ip_data_in = wp_remote_get( 'http://www.geoplugin.net/json.gp?ip='.$ip, array(
+ 'timeout' => 15
+ )
+ );
- if (is_array($ip_data_in['body']) && isset($ip_data_in['body']) && is_string($ip_data_in['body'])){
- $ip_data = json_decode($ip_data_in['body'],true);
- $ip_data = str_replace('"', '"', $ip_data); // for PHP 5.2 see stackoverflow.com/questions/3110487/
- }
- }
-
- if (is_array($ip_data) && $ip_data && $ip_data['geoplugin_countryName'] != null) {
- $country = $ip_data['geoplugin_countryName'];
- }
-
- return $country;
- */
- }
+ if ( is_wp_error( $ip_data_in ) ) {
+ //$error_message = $response->get_error_message();
+ //echo "Something went wrong: $error_message";
- function zeroBSCRM_findAB($html,$first,$nextStr,$fallbackCloser=''){
+ } else {
- $f1 = strpos($html,$first);
- $f1end = $f1 + strlen($first);
- if ($f1){
- $f2 = strpos(substr($html,$f1end),$nextStr);
- if (!$f2){
- #use fallback closer to try
- $f2 = strpos(substr($html,$f1end),$fallbackCloser);
+ if (is_array($ip_data_in['body']) && isset($ip_data_in['body']) && is_string($ip_data_in['body'])){
+ $ip_data = json_decode($ip_data_in['body'],true);
+ $ip_data = str_replace('"', '"', $ip_data); // for PHP 5.2 see stackoverflow.com/questions/3110487/
}
- if (!$f2) $f2 = strlen(substr($html,$f1end));
- return substr($html,$f1end,$f2);
}
- #if nothing returned?
- return '';
+ if (is_array($ip_data) && $ip_data && $ip_data['geoplugin_countryName'] != null) {
+ $country = $ip_data['geoplugin_countryName'];
+ }
+
+ return $country;
+ */
+}
+
+function zeroBSCRM_findAB( $html, $first, $nextStr, $fallbackCloser = '' ) {
+
+ $f1 = strpos( $html, $first );
+ $f1end = $f1 + strlen( $first );
+ if ( $f1 ) {
+ $f2 = strpos( substr( $html, $f1end ), $nextStr );
+ if ( ! $f2 ) {
+ #use fallback closer to try
+ $f2 = strpos( substr( $html, $f1end ), $fallbackCloser );
+ }
+ if ( ! $f2 ) {
+ $f2 = strlen( substr( $html, $f1end ) );
+ }
+ return substr( $html, $f1end, $f2 );
}
+ #if nothing returned?
+ return '';
+}
/**
* Retrieve file from remote server
@@ -568,43 +560,39 @@ function zeroBSCRM_retrieveFile( $url, $filepath, $args = array() ) {
}
# http://stackoverflow.com/questions/8889025/unzip-a-file-with-php
- function zeroBSCRM_expandArchive($filepath,$expandTo){
+function zeroBSCRM_expandArchive( $filepath, $expandTo ) {
- #} REQUIRES PHP 5.2+ - this should be enabled by default
- #} But because some hosts SUCK we have to check + workaround
- if (zeroBSCRM_checkSystemFeat('zlib')){
+ #} REQUIRES PHP 5.2+ - this should be enabled by default
+ #} But because some hosts SUCK we have to check + workaround
+ if ( zeroBSCRM_checkSystemFeat( 'zlib' ) ) {
- #} All should be okay
- try {
+ #} All should be okay
+ try {
- if (file_exists($filepath) && file_exists($expandTo)){
-
- $zip = new ZipArchive;
- $res = $zip->open($filepath);
- if ($res === TRUE) {
- $zip->extractTo($expandTo);
- $zip->close();
- return true;
- }
+ if ( file_exists( $filepath ) && file_exists( $expandTo ) ) {
+ $zip = new ZipArchive();
+ $res = $zip->open( $filepath );
+ if ( $res === true ) {
+ $zip->extractTo( $expandTo );
+ $zip->close();
+ return true;
}
-
- } catch (Exception $ex){
-
-
}
+ } catch ( Exception $ex ) {
- } else {
+ }
+ } else {
- // No ZipArchive, fallback to WP's included PclZip
- // .. we used to package our own copy of this, but it was flagging as malware. See GH-1011
+ // No ZipArchive, fallback to WP's included PclZip
+ // .. we used to package our own copy of this, but it was flagging as malware. See GH-1011
- // proceed using pclzip
- if ( class_exists('PclZip')){
+ // proceed using pclzip
+ if ( class_exists( 'PclZip' ) ) {
- try {
+ try {
- if (file_exists($filepath) && file_exists($expandTo)){
+ if ( file_exists( $filepath ) && file_exists( $expandTo ) ) {
$archive = new PclZip( $filepath );
// @phan-suppress-next-line PhanParamTooMany -- PclZip functions use func_get_args.
@@ -613,37 +601,32 @@ function zeroBSCRM_expandArchive($filepath,$expandTo){
} else {
return true;
}
- }
-
- } catch (Exception $ex){
-
-
}
+ } catch ( Exception $ex ) {
}
-
}
-
- return false;
-
}
+ return false;
+}
+
/**
* Wrapper for WP's built-in get_avatar(), but forces avatar display
* whether or not "Show Avatar" WP setting is enabled.
- *
+ *
* Also adds the user display name as the alt if no alt is provided.
*/
- function jpcrm_get_avatar( $user_id, $size, $default='', $alt='', $args=array() ) {
- if ( empty( $alt) ) {
- $user = get_userdata( $user_id );
- if ($user) {
- $alt = $user->display_name;
- }
+function jpcrm_get_avatar( $user_id, $size, $default = '', $alt = '', $args = array() ) {
+ if ( empty( $alt ) ) {
+ $user = get_userdata( $user_id );
+ if ( $user ) {
+ $alt = $user->display_name;
}
- $args['force_display'] = true;
- return get_avatar( $user_id, $size, $default, $alt, $args );
}
+ $args['force_display'] = true;
+ return get_avatar( $user_id, $size, $default, $alt, $args );
+}
/**
* Inject contacts as desired
@@ -688,69 +671,70 @@ function jpcrm_inject_contacts( $contacts, $args ) {
return $contacts;
}
- function zeroBSCRM_getGravatarURLfromEmail($email='',$size=80){
+function zeroBSCRM_getGravatarURLfromEmail( $email = '', $size = 80 ) {
- // https:
- $url = '//www.gravatar.com/avatar/' . hash( 'sha256', $email );
- $url = add_query_arg( array(
+ // https:
+ $url = '//www.gravatar.com/avatar/' . hash( 'sha256', $email );
+ $url = add_query_arg(
+ array(
's' => $size,
'd' => 'mm',
- ), $url );
- return esc_url_raw( $url );
- }
+ ),
+ $url
+ );
+ return esc_url_raw( $url );
+}
/*
* Returns html to render business logo, if one is set in biz info settings
*/
- function jpcrm_business_logo_img( $max_width = '200px' ) {
+function jpcrm_business_logo_img( $max_width = '200px' ) {
- // got url?
- $logo_url = jpcrm_business_logo_url();
+ // got url?
+ $logo_url = jpcrm_business_logo_url();
- // if default, build html
- if ( !empty( $logo_url ) ){
- return '
';
- }
-
- return '';
+ // if default, build html
+ if ( ! empty( $logo_url ) ) {
+ return '
';
}
+ return '';
+}
+
/*
* Returns an URL for business logo, if one is set in biz info settings
*
* For now is semi-redundant, but centralising for later expansion
*
*/
- function jpcrm_business_logo_url( ) {
-
- // got url?
- $logo_url = zeroBSCRM_getSetting( 'invoicelogourl' );
+function jpcrm_business_logo_url() {
- // check default
- if ( !empty( $logo_url ) ){
- return $logo_url;
- }
+ // got url?
+ $logo_url = zeroBSCRM_getSetting( 'invoicelogourl' );
- return '';
+ // check default
+ if ( ! empty( $logo_url ) ) {
+ return $logo_url;
}
- function zeroBSCRM_prettyformatBytes($size, $precision = 2){
- $base = log($size, 1024);
- $suffixes = array('', 'K', 'M', 'G', 'T');
-
- return round(pow(1024, $base - floor($base)), $precision) .''. $suffixes[floor($base)];
- }
+ return '';
+}
- /*
- * Split a Camel caps string (e.g. ThisStringBecomes = This String Becomes)
- */
- function jpcrm_string_split_at_caps( $str ){
+function zeroBSCRM_prettyformatBytes( $size, $precision = 2 ) {
+ $base = log( $size, 1024 );
+ $suffixes = array( '', 'K', 'M', 'G', 'T' );
- $parts = preg_split('/(?=[A-Z])/', $str);
- return implode(' ', $parts);
+ return round( pow( 1024, $base - floor( $base ) ), $precision ) . '' . $suffixes[ floor( $base ) ];
+}
- }
+ /*
+ * Split a Camel caps string (e.g. ThisStringBecomes = This String Becomes)
+ */
+function jpcrm_string_split_at_caps( $str ) {
+ $parts = preg_split( '/(?=[A-Z])/', $str );
+ return implode( ' ', $parts );
+}
/**
* Returns send-from email + name
@@ -776,64 +760,66 @@ function zeroBSCRM_wp_retrieveSendFrom() {
);
}
-
-
#} This'll be true if wl
- function zeroBSCRM_isWL(){
-
- ##WLREMOVE
- return false;
- ##/WLREMOVE
- return true;
-
- }
+function zeroBSCRM_isWL() {
+ ##WLREMOVE
+ return false;
+ ##/WLREMOVE
+ return true;
+}
// ============= TELEMETRY SECTION
-
// https://wordpress.stackexchange.com/questions/52144/what-wordpress-api-function-lists-active-inactive-plugins
- function zeroBSCRM_allPluginListSimple() {
- $plugins = get_plugins();
- $p = array();
- if (count($plugins) > 0) {
- foreach ( $plugins as $plugin ) {
-
- $p[] = array('n' => $plugin['Name'],'v' => $plugin['Version']);
-
- }
- }
+function zeroBSCRM_allPluginListSimple() {
+ $plugins = get_plugins();
+ $p = array();
+ if ( count( $plugins ) > 0 ) {
+ foreach ( $plugins as $plugin ) {
+
+ $p[] = array(
+ 'n' => $plugin['Name'],
+ 'v' => $plugin['Version'],
+ );
- return $p;
- }
+ }
+ }
- // this ver gets ONLY active
- function zeroBSCRM_activePluginListSimple(){
- $pluginsActive = get_option('active_plugins');
- $plugins = get_plugins();
- $p = array();
- if (count($plugins) > 0) {
- foreach ( $plugins as $pluginKey => $plugin ) {
+ return $p;
+}
- if (in_array($pluginKey,$pluginsActive)) $p[] = array('n' => $plugin['Name'],'v' => $plugin['Version']);
+ // this ver gets ONLY active
+function zeroBSCRM_activePluginListSimple() {
+ $pluginsActive = get_option( 'active_plugins' );
+ $plugins = get_plugins();
+ $p = array();
+ if ( count( $plugins ) > 0 ) {
+ foreach ( $plugins as $pluginKey => $plugin ) {
+
+ if ( in_array( $pluginKey, $pluginsActive ) ) {
+ $p[] = array(
+ 'n' => $plugin['Name'],
+ 'v' => $plugin['Version'],
+ );
+ }
+ }
+ }
- }
- }
-
- return $p;
- }
+ return $p;
+}
// ============= / TELEMETRY SECTION
-
#} ZBS JSONP decode
// https://stackoverflow.com/questions/5081557/extract-jsonp-resultset-in-php
- function zeroBSCRM_jsonp_decode($jsonp, $assoc = false) { // PHP 5.3 adds depth as third parameter to json_decode
- if($jsonp[0] !== '[' && $jsonp[0] !== '{') { // we have JSONP
- $jsonp = substr($jsonp, strpos($jsonp, '('));
- }
- return json_decode(trim($jsonp,'();'), $assoc);
+function zeroBSCRM_jsonp_decode( $jsonp, $assoc = false ) {
+ // PHP 5.3 adds depth as third parameter to json_decode
+ if ( $jsonp[0] !== '[' && $jsonp[0] !== '{' ) { // we have JSONP
+ $jsonp = substr( $jsonp, strpos( $jsonp, '(' ) );
}
+ return json_decode( trim( $jsonp, '();' ), $assoc );
+}
// used by DAL2 settings
// https://stackoverflow.com/questions/6041741/fastest-way-to-check-if-a-string-is-json-in-php
@@ -847,200 +833,192 @@ function zeroBSCRM_isJson( $str ) {
}
// return placeholder img :) DAL2 friendly
- function zeroBSCRM_getDefaultContactAvatar(){
+function zeroBSCRM_getDefaultContactAvatar() {
- // hmm - how to pass an img here? when using
for html
- // for now made a quick png
- return plugins_url('/i/default-contact.png',ZBS_ROOTFILE);
-
- }
+ // hmm - how to pass an img here? when using
for html
+ // for now made a quick png
+ return plugins_url( '/i/default-contact.png', ZBS_ROOTFILE );
+}
// return logo
- function jpcrm_get_logo( $stacked=true, $color='black' ){
- $logo_url = plugins_url( '/i/icon-32.png', ZBS_ROOTFILE );
- ##WLREMOVE
- $logo_url = plugins_url( '/i/jpcrm-logo-'.($stacked?'stacked':'horizontal').'-'.$color.'.png', ZBS_ROOTFILE );
- ##/WLREMOVE
- return $logo_url;
-
- }
+function jpcrm_get_logo( $stacked = true, $color = 'black' ) {
+ $logo_url = plugins_url( '/i/icon-32.png', ZBS_ROOTFILE );
+ ##WLREMOVE
+ $logo_url = plugins_url( '/i/jpcrm-logo-' . ( $stacked ? 'stacked' : 'horizontal' ) . '-' . $color . '.png', ZBS_ROOTFILE );
+ ##/WLREMOVE
+ return $logo_url;
+}
// return placeholder img :) DAL2 friendly
- function zeroBSCRM_getDefaultContactAvatarHTML(){
+function zeroBSCRM_getDefaultContactAvatarHTML() {
- return '
';
-
- }
+ return '
';
+}
// https://stackoverflow.com/questions/2524680/check-whether-the-string-is-a-unix-timestamp
- function zeroBSCRM_isValidTimeStamp($timestamp){
- return ((string) (int) $timestamp === $timestamp)
- && ($timestamp <= PHP_INT_MAX)
- && ($timestamp >= ~PHP_INT_MAX);
- }
+function zeroBSCRM_isValidTimeStamp( $timestamp ) {
+ return ( (string) (int) $timestamp === $timestamp )
+ && ( $timestamp <= PHP_INT_MAX )
+ && ( $timestamp >= ~PHP_INT_MAX );
+}
// for use with export as per:
// because of SYLK bug in excel, we have to wrap these in "" - but fputcsv doesnt do it :/
// https://www.alunr.com/excel-csv-import-returns-an-sylk-file-format-error/
// https://stackoverflow.com/questions/2489553/forcing-fputcsv-to-use-enclosure-for-all-fields
- function zeroBSCRM_encloseArrItems($arr=array(),$encloseWith='"'){
+function zeroBSCRM_encloseArrItems( $arr = array(), $encloseWith = '"' ) {
- $endArr = $arr;
+ $endArr = $arr;
- if (is_array($arr)){
-
- $endArr = array();
- foreach ($arr as $k => $v){
- $endArr[$k] = $encloseWith.$v.$encloseWith;
- }
+ if ( is_array( $arr ) ) {
+ $endArr = array();
+ foreach ( $arr as $k => $v ) {
+ $endArr[ $k ] = $encloseWith . $v . $encloseWith;
}
-
- return $endArr;
}
+ return $endArr;
+}
+
// returns a filetype img if avail
// returns 48px from https://github.com/redbooth/free-file-icons
// ... cpp has fullsize 512px variants, but NOT to be added to core, adds bloat
- function zeroBSCRM_fileTypeImg($fileExtension=''){
-
- $fileExtension = sanitize_text_field( $fileExtension );
- if (!empty($fileExtension) && file_exists(ZEROBSCRM_PATH.'i/filetypes/'.$fileExtension.'.png')) return ZEROBSCRM_URL.'i/filetypes/'.$fileExtension.'.png';
-
- return ZEROBSCRM_URL.'i/filetypes/_blank.png';
+function zeroBSCRM_fileTypeImg( $fileExtension = '' ) {
+ $fileExtension = sanitize_text_field( $fileExtension );
+ if ( ! empty( $fileExtension ) && file_exists( ZEROBSCRM_PATH . 'i/filetypes/' . $fileExtension . '.png' ) ) {
+ return ZEROBSCRM_URL . 'i/filetypes/' . $fileExtension . '.png';
}
+ return ZEROBSCRM_URL . 'i/filetypes/_blank.png';
+}
+
// https://stackoverflow.com/questions/3797239/insert-new-item-in-array-on-any-position-in-php
/**
* @param array $array
* @param int|string $position
* @param mixed $insert
*/
- function zeroBSCRM_array_insert(&$array, $position, $insert)
- {
- if (is_int($position)) {
- array_splice($array, $position, 0, $insert);
- } else {
- $pos = array_search($position, array_keys($array));
- $array = array_merge(
- array_slice($array, 0, $pos),
- $insert,
- array_slice($array, $pos)
- );
- }
+function zeroBSCRM_array_insert( &$array, $position, $insert ) {
+ if ( is_int( $position ) ) {
+ array_splice( $array, $position, 0, $insert );
+ } else {
+ $pos = array_search( $position, array_keys( $array ) );
+ $array = array_merge(
+ array_slice( $array, 0, $pos ),
+ $insert,
+ array_slice( $array, $pos )
+ );
}
+}
// WH ver of zeroBSCRM_array_insert, specifically used for messing with menu arrs (used mc2)
- function zeroBSCRM_array_insert_ifset(&$array, $position, $insert){
-
- // check for $position legitimacy
- if (is_int($position)) {
-
- if (count($array) > $position)
- return zeroBSCRM_array_insert($array,$position,$insert);
- else {
- // just add
- $array = array_merge($array,$insert);
- return $array;
- }
-
-
- } else if (is_array($position)){
-
- // array - checks for subvalues to find position
- /*
+function zeroBSCRM_array_insert_ifset( &$array, $position, $insert ) {
- e.g. in this:
+ // check for $position legitimacy
+ if ( is_int( $position ) ) {
+ if ( count( $array ) > $position ) {
+ return zeroBSCRM_array_insert( $array, $position, $insert );
+ } else {
+ // just add
+ $array = array_merge( $array, $insert );
+ return $array;
+ }
+ } elseif ( is_array( $position ) ) {
- Array
- (
- [0] => Array
- (
- [0] => Jetpack CRM
- [1] => zbs_dash
- [2] => zerobscrm-dash
- [3] => Jetpack CRM User Dash
- )
-
- [1] => Array
- (
- [0] => Contacts
- [1] => admin_zerobs_view_customers
- [2] => manage-customers
- [3] => Contacts
- )
-
- [2] => Array
- (
- [0] => Quotes
- [1] => admin_zerobs_view_quotes
- [2] => manage-quotes
- [3] => Quotes
- )
+ // array - checks for subvalues to find position
+ /*
+ e.g. in this:
- ... if you passed $position as:
- array('1'=>'admin_zerobs_view_customers')
+ Array
+ (
+ [0] => Array
+ (
+ [0] => Jetpack CRM
+ [1] => zbs_dash
+ [2] => zerobscrm-dash
+ [3] => Jetpack CRM User Dash
+ )
- ... it'd insert before [1]
+ [1] => Array
+ (
+ [0] => Contacts
+ [1] => admin_zerobs_view_customers
+ [2] => manage-customers
+ [3] => Contacts
+ )
- */
+ [2] => Array
+ (
+ [0] => Quotes
+ [1] => admin_zerobs_view_quotes
+ [2] => manage-quotes
+ [3] => Quotes
+ )
+ ... if you passed $position as:
- // brutal
- $endPos = -1; $i = 0;
- foreach ($array as $a){
- // match position?
- foreach ($position as $k => $v){
- if ($a[$k] == $v){
+ array('1'=>'admin_zerobs_view_customers')
- // has an attr matching position
- $endPos = $i;
- }
- }
+ ... it'd insert before [1]
- $i++;
- }
+ */
- // should now have pos
- if ($endPos > -1){
+ // brutal
+ $endPos = -1;
+ $i = 0;
+ foreach ( $array as $a ) {
+ // match position?
+ foreach ( $position as $k => $v ) {
+ if ( $a[ $k ] == $v ) {
- // probs str, fallback to
- return zeroBSCRM_array_insert($array,$endPos,$insert);
+ // has an attr matching position
+ $endPos = $i;
+ }
+ }
+ ++$i;
+ }
- } else {
+ // should now have pos
+ if ( $endPos > -1 ) {
- // append
- $array = array_merge($array,$insert);
- return $array;
+ // probs str, fallback to
+ return zeroBSCRM_array_insert( $array, $endPos, $insert );
- }
+ } else {
- } else {
+ // append
+ $array = array_merge( $array, $insert );
+ return $array;
- // probs str, fallback to
- return zeroBSCRM_array_insert($array,$position,$insert);
+ }
+ } else {
- }
+ // probs str, fallback to
+ return zeroBSCRM_array_insert( $array, $position, $insert );
}
+}
// simplistic directory empty check
- function zeroBSCRM_is_dir_empty($dir) {
- if (!is_readable($dir)) return null;
- $handle = opendir($dir);
- while (false !== ($entry = readdir($handle))) {
- if ($entry !== '.' && $entry !== '..') {
- closedir($handle);
- return false;
- }
- }
- closedir($handle);
- return true;
+function zeroBSCRM_is_dir_empty( $dir ) {
+ if ( ! is_readable( $dir ) ) {
+ return null;
+ }
+ $handle = opendir( $dir );
+ while ( false !== ( $entry = readdir( $handle ) ) ) {
+ if ( $entry !== '.' && $entry !== '..' ) {
+ closedir( $handle );
+ return false;
+ }
}
+ closedir( $handle );
+ return true;
+}
/**
* Copyright © 2020 Theodore R. Smith
@@ -1053,236 +1031,238 @@ function zeroBSCRM_is_dir_empty($dir) {
* @param array $filtered Default: [., ..]
* @return array
*/
- function jpcrm_get_directories($path, $recursive = false, array $filtered = []){
- if (!is_dir($path)) {
- throw new RuntimeException("$path does not exist.");
- }
-
- $filtered += ['.', '..'];
+function jpcrm_get_directories( $path, $recursive = false, array $filtered = array() ) {
+ if ( ! is_dir( $path ) ) {
+ throw new RuntimeException( "$path does not exist." );
+ }
- $dirs = [];
- $d = dir($path);
- while (($entry = $d->read()) !== false) {
- if (is_dir("$path/$entry") && !in_array($entry, $filtered)) {
- $dirs[] = $entry;
+ $filtered += array( '.', '..' );
- if ($recursive) {
- $newDirs = getDirs("$path/$entry");
- foreach ($newDirs as $newDir) {
- $dirs[] = "$entry/$newDir";
- }
- }
- }
- }
+ $dirs = array();
+ $d = dir( $path );
+ while ( ( $entry = $d->read() ) !== false ) {
+ if ( is_dir( "$path/$entry" ) && ! in_array( $entry, $filtered ) ) {
+ $dirs[] = $entry;
- return $dirs;
+ if ( $recursive ) {
+ $newDirs = getDirs( "$path/$entry" );
+ foreach ( $newDirs as $newDir ) {
+ $dirs[] = "$entry/$newDir";
+ }
+ }
+ }
}
+ return $dirs;
+}
- /**
- * Takes an URL string and returns any $_GET parameters as an array
- */
- function jpcrm_url_get_params( $url = '' ){
-
- $components = parse_url($url);
- if ( isset( $components['query'] ) ){
+ /**
+ * Takes an URL string and returns any $_GET parameters as an array
+ */
+function jpcrm_url_get_params( $url = '' ) {
- parse_str($components['query'], $results);
- return $results;
-
- }
+ $components = parse_url( $url );
+ if ( isset( $components['query'] ) ) {
- return false;
+ parse_str( $components['query'], $results );
+ return $results;
}
-
- /**
- * Returns bool whether or not an url has params
- */
- function jpcrm_url_has_params( $url = '' ){
+ return false;
+}
+
+ /**
+ * Returns bool whether or not an url has params
+ */
+function jpcrm_url_has_params( $url = '' ) {
+
+ $components = parse_url( $url );
+ if ( isset( $components['query'] ) ) {
- $components = parse_url($url);
- if ( isset( $components['query'] ) ){
-
- parse_str($components['query'], $results);
-
- if ( count( $results ) > 0 ){
-
- return true;
+ parse_str( $components['query'], $results );
- }
- }
+ if ( count( $results ) > 0 ) {
- return false;
+ return true;
+ }
}
+ return false;
+}
/*
* This is adapted from https://github.com/dompdf/dompdf/blob/master/src/Options.php#L1147-L1159
* ... to allow us to filter out non-site-url image injections
*/
- function jpcrm_dompdf_assist_validate_remote_uri( string $uri ){
+function jpcrm_dompdf_assist_validate_remote_uri( string $uri ) {
if ( strlen( $uri ) === 0 ) {
- return [false, "The URI must not be empty."];
-
- }
-
- /*
- if ( !$this->isRemoteEnabled ) {
+ return array( false, 'The URI must not be empty.' );
- return [false, "Remote file requested, but remote file download is disabled."];
+ }
- }
- */
+ /*
+ if ( !$this->isRemoteEnabled ) {
- if ( !jpcrm_url_appears_to_match_site( $uri ) ){
+ return [false, "Remote file requested, but remote file download is disabled."];
- return [false, "Remote file requested, but remote file download is disabled."];
+ }
+ */
- }
+ if ( ! jpcrm_url_appears_to_match_site( $uri ) ) {
+ return array( false, 'Remote file requested, but remote file download is disabled.' );
- return [true, null];
}
+ return array( true, null );
+}
-/* ======================================================
- / Globally useful generic Funcs
- ====================================================== */
+/*
+======================================================
+ / Globally useful generic Funcs
+ ====================================================== */
-/* ======================================================
- unsub creation stuff - can't go in other as that's optionally included,
- // migrations sometimes need to use pre-inclusion, so here for now #notidealbutokay
- ====================================================== */
+/*
+======================================================
+ unsub creation stuff - can't go in other as that's optionally included,
+ // migrations sometimes need to use pre-inclusion, so here for now #notidealbutokay
+ ====================================================== */
// this is fired by a migration, and checked on deactivate ext
-function zeroBSCRM_unsub_checkCreatePage(){
+function zeroBSCRM_unsub_checkCreatePage() {
global $zbs;
- //check if the page exists, if not create and call it clients
+ // check if the page exists, if not create and call it clients
$pageID = zeroBSCRM_mail_getUnsubscribePage();
- if (empty($pageID) || $pageID < 1){
+ if ( empty( $pageID ) || $pageID < 1 ) {
// wh added to stop weird multi-fires (moving to migration fixed, but this is double protection)
- if (!defined('ZBS_UNSUB_PAGE_MADE')){
+ if ( ! defined( 'ZBS_UNSUB_PAGE_MADE' ) ) {
-
- //then we do not have a page for the client portal, create one, with slug clients and set as page
- //this should handle any backwards compatibility and not lose the URLs created
+ // then we do not have a page for the client portal, create one, with slug clients and set as page
+ // this should handle any backwards compatibility and not lose the URLs created
$args = array(
- 'post_name' => 'unsubscribe',
- 'post_status' => 'publish',
- 'post_title' => __('Unsubscribed','zero-bs-crm'),
+ 'post_name' => 'unsubscribe',
+ 'post_status' => 'publish',
+ 'post_title' => __( 'Unsubscribed', 'zero-bs-crm' ),
'post_content' => '[jetpackcrm_unsubscribe]',
- 'post_type' => 'page'
+ 'post_type' => 'page',
);
- $pageID = wp_insert_post($args);
- $zbs->settings->update('unsubpage', $pageID);
- define('ZBS_UNSUB_PAGE_MADE',1);
+ $pageID = wp_insert_post( $args );
+ $zbs->settings->update( 'unsubpage', $pageID );
+ define( 'ZBS_UNSUB_PAGE_MADE', 1 );
return $pageID;
}
-
- } else return $pageID;
+ } else {
+ return $pageID;
+ }
return -1;
}
// returns an active page id or -1
-function zeroBSCRM_mail_getUnsubscribePage(){
+function zeroBSCRM_mail_getUnsubscribePage() {
// what settings says it is
- $pageID = (int)zeroBSCRM_getSetting('unsubpage');
+ $pageID = (int) zeroBSCRM_getSetting( 'unsubpage' );
// is page live?
- if (!empty($pageID) || $pageID > 0) {
+ if ( ! empty( $pageID ) || $pageID > 0 ) {
- $pageStatus = get_post_status($pageID);
- // page is trashed or smt, recreate
- if ($pageStatus !== 'publish') $pageID = -1;
-
- } else $pageID = -1;
+ $pageStatus = get_post_status( $pageID );
+ // page is trashed or smt, recreate
+ if ( $pageStatus !== 'publish' ) {
+ $pageID = -1;
+ }
+ } else {
+ $pageID = -1;
+ }
return $pageID;
}
-/* ======================================================
- / unsub creation stuff
- ====================================================== */
-
+/*
+======================================================
+ / unsub creation stuff
+ ====================================================== */
-/* ======================================================
- Portal creation stuff - can't go in .Portal.php as that's optionally included,
- // migrations sometimes need to use pre-inclusion, so here for now #notidealbutokay
- ====================================================== */
+/*
+======================================================
+ Portal creation stuff - can't go in .Portal.php as that's optionally included,
+ // migrations sometimes need to use pre-inclusion, so here for now #notidealbutokay
+ ====================================================== */
// this is fired by a migration, and checked on deactivate ext
-function zeroBSCRM_portal_checkCreatePage(){
+function zeroBSCRM_portal_checkCreatePage() {
global $zbs;
- //check if the page exists, if not create and call it clients
+ // check if the page exists, if not create and call it clients
$portalPage = zeroBSCRM_portal_getPortalPage();
- if (empty($portalPage) || $portalPage < 1){
+ if ( empty( $portalPage ) || $portalPage < 1 ) {
// wh added to stop weird multi-fires (moving to migration fixed, but this is double protection)
- if (!defined('ZBS_PORTAL_PAGE_MADE')){
+ if ( ! defined( 'ZBS_PORTAL_PAGE_MADE' ) ) {
-
- //then we do not have a page for the client portal, create one, with slug clients and set as page
- //this should handle any backwards compatibility and not lose the URLs created
+ // then we do not have a page for the client portal, create one, with slug clients and set as page
+ // this should handle any backwards compatibility and not lose the URLs created
$args = array(
- 'post_name' => 'clients',
- 'post_status' => 'publish',
- 'post_title' => __('Client Portal','zero-bs-crm'),
+ 'post_name' => 'clients',
+ 'post_status' => 'publish',
+ 'post_title' => __( 'Client Portal', 'zero-bs-crm' ),
'post_content' => '[jetpackcrm_clientportal]',
- 'post_type' => 'page'
+ 'post_type' => 'page',
);
- $portalID = wp_insert_post($args);
- $zbs->settings->update('portalpage', $portalID);
- define('ZBS_PORTAL_PAGE_MADE',1);
+ $portalID = wp_insert_post( $args );
+ $zbs->settings->update( 'portalpage', $portalID );
+ define( 'ZBS_PORTAL_PAGE_MADE', 1 );
return $portalID;
}
-
- } else return $portalPage;
+ } else {
+ return $portalPage;
+ }
return -1;
}
// returns an active page id or -1
-function zeroBSCRM_portal_getPortalPage(){
+function zeroBSCRM_portal_getPortalPage() {
// what settings says it is
- $portalPage = (int)zeroBSCRM_getSetting('portalpage');
+ $portalPage = (int) zeroBSCRM_getSetting( 'portalpage' );
// is page live?
- if (!empty($portalPage) || $portalPage > 0) {
+ if ( ! empty( $portalPage ) || $portalPage > 0 ) {
- $pageStatus = get_post_status($portalPage);
- // page is trashed or smt, recreate
- if ($pageStatus !== 'publish') $portalPage = -1;
-
- } else $portalPage = -1;
+ $pageStatus = get_post_status( $portalPage );
+ // page is trashed or smt, recreate
+ if ( $pageStatus !== 'publish' ) {
+ $portalPage = -1;
+ }
+ } else {
+ $portalPage = -1;
+ }
return $portalPage;
}
-/* ======================================================
- / Portal creation stuff
- ====================================================== */
-
-
+/*
+======================================================
+ / Portal creation stuff
+ ====================================================== */
-/* ======================================================
- Link Helpers
- ====================================================== */
+/*
+======================================================
+ Link Helpers
+ ====================================================== */
// produces a portal based link to a potentially-hashed obj (inv/quo as of v3.0)
function zeroBSCRM_portal_linkObj( $obj_id = -1, $type_int = ZBS_TYPE_INVOICE ) {
global $zbs;
@@ -1300,25 +1280,25 @@ function zeroBSCRM_portal_linkObj( $obj_id = -1, $type_int = ZBS_TYPE_INVOICE )
if ( $use_hash == '1' ) {
$hash = $zbs->DAL->invoices->getInvoiceHash( $obj_id );
if ( ! empty( $hash ) ) {
- return esc_url( $portal_base_url . $invoices_endpoint . $url_separator .'zh-' . $hash );
+ return esc_url( $portal_base_url . $invoices_endpoint . $url_separator . 'zh-' . $hash );
}
}
return esc_url( $portal_base_url . $invoices_endpoint . $url_separator . $obj_id );
break;
case ZBS_TYPE_QUOTE:
- // get quotes stem
- $quotes_endpoint = $zbs->modules->portal->get_endpoint( ZBS_TYPE_QUOTE );
+ // get quotes stem
+ $quotes_endpoint = $zbs->modules->portal->get_endpoint( ZBS_TYPE_QUOTE );
// got hash?
- if ( $use_hash == "1" ) {
- $hash = $zbs->DAL->quotes->getQuoteHash($obj_id);
+ if ( $use_hash == '1' ) {
+ $hash = $zbs->DAL->quotes->getQuoteHash( $obj_id );
if ( ! empty( $hash ) ) {
- return esc_url( $portal_base_url . $quotes_endpoint . $url_separator . 'zh-' . $hash );
+ return esc_url( $portal_base_url . $quotes_endpoint . $url_separator . 'zh-' . $hash );
}
}
// otherwise just id
- return esc_url( $portal_base_url . $quotes_endpoint . $url_separator . $obj_id );
+ return esc_url( $portal_base_url . $quotes_endpoint . $url_separator . $obj_id );
break;
}
}
@@ -1327,8 +1307,8 @@ function jpcrm_get_portal_slug() {
$portal_page_id = zeroBSCRM_getSetting( 'portalpage' );
$portal_post = get_post( $portal_page_id );
$portal_permalink = $portal_post ? rtrim( _get_page_link( $portal_post ), '/' ) : '';
- $portal_slug = str_replace( home_url(), "", $portal_permalink);
-
+ $portal_slug = str_replace( home_url(), '', $portal_permalink );
+
if ( empty( $portal_slug ) ) {
$portal_slug = 'clients';
}
@@ -1337,15 +1317,15 @@ function jpcrm_get_portal_slug() {
}
function jpcrm_get_client_portal_root_url() {
- $client_portal_root_url = home_url( jpcrm_get_portal_slug() );
+ $client_portal_root_url = home_url( jpcrm_get_portal_slug() );
// The url separator should be '&' when plain permalinks are being used
$client_portal_root_url .= ( ! str_contains( $client_portal_root_url, '?' ) ) ? '/' : '&';
return $client_portal_root_url;
}
-function zeroBS_portal_link($type='dash',$objIDorHashStr=-1){
- $portalPage = zeroBSCRM_getSetting('portalpage');
+function zeroBS_portal_link( $type = 'dash', $objIDorHashStr = -1 ) {
+ $portalPage = zeroBSCRM_getSetting( 'portalpage' );
$portalLink = jpcrm_get_client_portal_root_url();
$portalSlug = jpcrm_get_portal_slug();
@@ -1358,45 +1338,47 @@ function zeroBS_portal_link($type='dash',$objIDorHashStr=-1){
break;
default:
+ // catch generic e.g. quotes invoices
- // catch generic e.g. quotes invoices
-
- $stem = $type; //'quotes';
+ $stem = $type; // 'quotes';
// if cpp, use that stem
- if (function_exists('zeroBSCRM_clientPortalgetEndpoint')) $stem = zeroBSCRM_clientPortalgetEndpoint($stem);
+ if ( function_exists( 'zeroBSCRM_clientPortalgetEndpoint' ) ) {
+ $stem = zeroBSCRM_clientPortalgetEndpoint( $stem );
+ }
// if using a str (hash) then prefix with zh- if not already
- if (is_string($objIDorHashStr)){
+ if ( is_string( $objIDorHashStr ) ) {
if ( ! str_starts_with( $objIDorHashStr, 'zh-' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
$objIDorHashStr = 'zh-' . $objIDorHashStr; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
}
}
if (
- (!is_string($objIDorHashStr) && ($objIDorHashStr == -1 || $objIDorHashStr <= 0)) // is false ID
+ ( ! is_string( $objIDorHashStr ) && ( $objIDorHashStr == -1 || $objIDorHashStr <= 0 ) ) // is false ID
||
- (is_string($objIDorHashStr) && empty($objIDorHashStr)) // is empty hash str
- )
- return home_url('/'.$portalSlug.'/'.$stem.'/');
- else
- return home_url('/'.$portalSlug.'/'.$stem.'/'.$objIDorHashStr);
+ ( is_string( $objIDorHashStr ) && empty( $objIDorHashStr ) ) // is empty hash str
+ ) {
+ return home_url( '/' . $portalSlug . '/' . $stem . '/' );
+ } else {
+ return home_url( '/' . $portalSlug . '/' . $stem . '/' . $objIDorHashStr );
+ }
break;
-
}
- return home_url('/#notfound');
+ return home_url( '/#notfound' );
}
-/* ======================================================
- / Link Helpers
- ====================================================== */
-
+/*
+======================================================
+ / Link Helpers
+ ====================================================== */
-/* ======================================================
- General WP Helpers
- ====================================================== */
+/*
+======================================================
+ General WP Helpers
+ ====================================================== */
/*
* Compares the version of WordPress running to the $version specified.
@@ -1410,22 +1392,22 @@ function jpcrm_wordpress_version( $operator = '>', $version = '4.0' ) {
return version_compare( $wp_version, $version, $operator );
}
-/* ======================================================
- / General WP Helpers
- ====================================================== */
-
-
+/*
+======================================================
+ / General WP Helpers
+ ====================================================== */
-/* ======================================================
- Security Helpers
- ====================================================== */
+/*
+======================================================
+ Security Helpers
+ ====================================================== */
/**
* Adds .htaccess and index.html files to directory
* Used to block access to those which we don't want externally accessible
* If the directory does not exist, creates it
- *
- * Adapted from Woo's ReportCSVExporter->maybe_create_directory()
+ *
+ * Adapted from Woo's ReportCSVExporter->maybe_create_directory()
* https://github.com/Automattic/woocommerce-admin/pull/6/files#diff-93130caa7eb757181d642767bfcd229f7e1124d0348d05f8db48f432df44fb62R70
*
* @param $directory_path - full path to directory
@@ -1477,65 +1459,65 @@ function jpcrm_create_and_secure_dir_from_external_access( $directory_path = '',
fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
}
- if ( ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ){
+ if ( ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
// failed to create file
$safe = false;
-
- }
+ }
}
-
}
return $safe;
-
}
-/* ======================================================
- / Security Helpers
- ====================================================== */
+/*
+======================================================
+ / Security Helpers
+ ====================================================== */
-/* ======================================================
- Dashboard Helpers
- ====================================================== */
+/*
+======================================================
+ Dashboard Helpers
+ ====================================================== */
/*
* Returns arrays of zeros (for dashboard graph prep)
*/
-function jetpackcrm_create_zeros_array($start, $end, $zbs_steps = 86400){
+function jetpackcrm_create_zeros_array( $start, $end, $zbs_steps = 86400 ) {
$filled_zeros_y = array();
$filled_zeros_m = array();
$filled_zeros_w = array();
$filled_zeros_d = array();
$the_day = $start;
- while($the_day <= $end){
- $the_year= date("Y", $the_day);
- $filled_zeros_y[$the_year] = 0;
+ while ( $the_day <= $end ) {
+ $the_year = date( 'Y', $the_day );
+ $filled_zeros_y[ $the_year ] = 0;
- $the_month = date("M y", $the_day);
- $filled_zeros_m[$the_month] = 0;
+ $the_month = date( 'M y', $the_day );
+ $filled_zeros_m[ $the_month ] = 0;
- $the_week = date("W Y", $the_day);
- $filled_zeros_w[$the_week] = 0;
+ $the_week = date( 'W Y', $the_day );
+ $filled_zeros_w[ $the_week ] = 0;
- $the_day_d = date("d M y", $the_day);
- $filled_zeros_d[$the_day_d] = 0;
+ $the_day_d = date( 'd M y', $the_day );
+ $filled_zeros_d[ $the_day_d ] = 0;
$the_day += $zbs_steps;
}
- $filled_zeros['year'] = $filled_zeros_y;
+ $filled_zeros['year'] = $filled_zeros_y;
$filled_zeros['month'] = $filled_zeros_m;
- $filled_zeros['week'] = $filled_zeros_w;
- $filled_zeros['day'] = $filled_zeros_d;
+ $filled_zeros['week'] = $filled_zeros_w;
+ $filled_zeros['day'] = $filled_zeros_d;
return $filled_zeros;
}
-/* ======================================================
- / Dashboard Helpers
- ====================================================== */
+/*
+======================================================
+ / Dashboard Helpers
+ ====================================================== */
/*
* Returns a YouTube thumbnail URL of a video
@@ -1544,20 +1526,18 @@ function jetpackcrm_create_zeros_array($start, $end, $zbs_steps = 86400){
* @param string $quality (sd|mq|hq|maxres)
* @returns string|boolean
*/
-function jpcrm_youtube_url_to_thumbnail_url( $video_url, $quality = 'mq' ){
+function jpcrm_youtube_url_to_thumbnail_url( $video_url, $quality = 'mq' ) {
$video_id = jpcrm_youtube_url_to_video_id( $video_url );
- if ( !empty( $video_id ) ){
+ if ( ! empty( $video_id ) ) {
return 'http://img.youtube.com/vi/' . $video_id . '/' . $quality . 'default.jpg';
}
return false;
-
}
-
/*
* Returns a YouTube video ID of a video
*
@@ -1566,23 +1546,22 @@ function jpcrm_youtube_url_to_thumbnail_url( $video_url, $quality = 'mq' ){
*/
function jpcrm_youtube_url_to_video_id( $video_url ) {
- $video_id = explode( "?v=", $video_url );
- if ( !isset( $video_id[1] ) ) {
- $video_id = explode( "youtu.be/", $video_url );
- }
- if ( empty($video_id[1]) ) {
- $video_id = explode("/v/", $video_url);
- }
- if ( is_array( $video_id ) ){
- $video_id = explode( "&", $video_id[1] );
- $youtube_video_id = $video_id[0];
- if ( !empty( $youtube_video_id ) ) {
- return $youtube_video_id;
- }
+ $video_id = explode( '?v=', $video_url );
+ if ( ! isset( $video_id[1] ) ) {
+ $video_id = explode( 'youtu.be/', $video_url );
+ }
+ if ( empty( $video_id[1] ) ) {
+ $video_id = explode( '/v/', $video_url );
+ }
+ if ( is_array( $video_id ) ) {
+ $video_id = explode( '&', $video_id[1] );
+ $youtube_video_id = $video_id[0];
+ if ( ! empty( $youtube_video_id ) ) {
+ return $youtube_video_id;
+ }
}
- return false;
-
+ return false;
}
/**
diff --git a/projects/plugins/crm/includes/ZeroBSCRM.IntegrationFuncs.php b/projects/plugins/crm/includes/ZeroBSCRM.IntegrationFuncs.php
index e3d03e84df32..f2291c8ee3cd 100644
--- a/projects/plugins/crm/includes/ZeroBSCRM.IntegrationFuncs.php
+++ b/projects/plugins/crm/includes/ZeroBSCRM.IntegrationFuncs.php
@@ -1,5 +1,5 @@
- 'woodyhayday2@smt.com',
-
- 'zbsc_status' => 'Lead',
- 'zbsc_prefix' => 'Mr',
- 'zbsc_fname' => 'Woody',
- 'zbsc_lname' => 'Hayday',
- 'zbsc_addr1' => 'First Addr',
- 'zbsc_addr2' => '2nd Addr',
- 'zbsc_city' => 'London',
- 'zbsc_county' => 'G London',
- 'zbsc_postcode' => 'AL1 111',
- 'zbsc_hometel' => '0123456789',
- 'zbsc_worktel' => '999',
- 'zbsc_mobtel' => '333',
- 'zbsc_notes' => 'Multi Line
- Notes
- Kick Ass',
-
- #} custom fields are set as cf(int) and so are per-install dependent, you probs don't ever want to insert these :) :D
- #'zbsc_cf1' => 'Google'
-
- ),
+ 'zbsc_email' => 'woodyhayday2@smt.com',
+
+ 'zbsc_status' => 'Lead',
+ 'zbsc_prefix' => 'Mr',
+ 'zbsc_fname' => 'Woody',
+ 'zbsc_lname' => 'Hayday',
+ 'zbsc_addr1' => 'First Addr',
+ 'zbsc_addr2' => '2nd Addr',
+ 'zbsc_city' => 'London',
+ 'zbsc_county' => 'G London',
+ 'zbsc_postcode' => 'AL1 111',
+ 'zbsc_hometel' => '0123456789',
+ 'zbsc_worktel' => '999',
+ 'zbsc_mobtel' => '333',
+ 'zbsc_notes' => 'Multi Line
+ Notes
+ Kick Ass',
+
+ #} custom fields are set as cf(int) and so are per-install dependent, you probs don't ever want to insert these :) :D
+ #'zbsc_cf1' => 'Google'
+
+ ),
'customer_date as per mike!',
- 'none',
+ 'none',
- false,
+ false,
false
- );
-
+ );
+
|
| ... note "woo" external source flag
| ... note "woodyhayday2@smt.com" - my ID within woo
@@ -122,196 +119,188 @@ function zeroBS_integrations_getCustomer($externalSource='',$externalID=''){
| ... Note: From v1.1.18 we also have fallback logs:
| --------------------------------------------------
| Fallback Logs:
- | Pass either:
- | 'none' = do nothing if user already exists
- | 'auto' = automatically create log (NOT WORKING YET)
- | OR:
- | array(
- | 'type' => 'Form Filled',#'form_filled',
- | 'shortdesc' => 'Dude filled out the form x on y',
- | 'longdesc' => ''
- | )
- |
- | (Long desc is optional)
- |
- | #} CURRENT Note Types (use first field/key e.g. "form_filled") (v1.1.18 - 20/09/16)
- |
- | 'note': { label: 'Note', ico: 'fa-sticky-note-o' },
- | 'call': { label: 'Call', ico: 'fa-phone-square' },
- | 'email': { label: 'Email', ico: 'fa-envelope-o' },
- | 'meeting': { label: 'Meeting', ico: 'fa-users' },
- | 'quote__sent': { label: 'Quote: Sent', ico: 'fa-share-square-o' },
- | 'quote__accepted': { label: 'Quote: Accepted', ico: 'fa-thumbs-o-up' },
- | 'quote__refused': { label: 'Quote: Refused', ico: 'fa-ban' },
- | 'invoice__sent': { label: 'Invoice: Sent', ico: 'fa-share-square-o' },
- | 'invoice__part_paid': { label: 'Invoice: Part Paid', ico: 'fa-money' },
- | 'invoice__paid': { label: 'Invoice: Paid', ico: 'fa-money' },
- | 'invoice__refunded': { label: 'Invoice: Refunded', ico: 'fa-money' },
- | 'transaction': { label: 'Transaction', ico: 'fa-credit-card' },
- | 'tweet': { label: 'Tweet', ico: 'fa-twitter' },
- | 'facebook_post': { label: 'Facebook Post', ico: 'fa-facebook-official' },
- | 'created': { label: 'Created', ico: 'fa-plus-circle' },
- | 'updated': { label: 'Updated', ico: 'fa-pencil-square-o' },
- | 'quote_created': { label: 'Quote Created', ico: 'fa-plus-circle' },
- | 'invoice_created': { label: 'Invoice Created', ico: 'fa-plus-circle' },
- | 'form_filled': { label: 'Form Filled', ico: 'fa-wpforms'}
+ | Pass either:
+ | 'none' = do nothing if user already exists
+ | 'auto' = automatically create log (NOT WORKING YET)
+ | OR:
+ | array(
+ | 'type' => 'Form Filled',#'form_filled',
+ | 'shortdesc' => 'Dude filled out the form x on y',
+ | 'longdesc' => ''
+ | )
+ |
+ | (Long desc is optional)
+ |
+ | #} CURRENT Note Types (use first field/key e.g. "form_filled") (v1.1.18 - 20/09/16)
+ |
+ | 'note': { label: 'Note', ico: 'fa-sticky-note-o' },
+ | 'call': { label: 'Call', ico: 'fa-phone-square' },
+ | 'email': { label: 'Email', ico: 'fa-envelope-o' },
+ | 'meeting': { label: 'Meeting', ico: 'fa-users' },
+ | 'quote__sent': { label: 'Quote: Sent', ico: 'fa-share-square-o' },
+ | 'quote__accepted': { label: 'Quote: Accepted', ico: 'fa-thumbs-o-up' },
+ | 'quote__refused': { label: 'Quote: Refused', ico: 'fa-ban' },
+ | 'invoice__sent': { label: 'Invoice: Sent', ico: 'fa-share-square-o' },
+ | 'invoice__part_paid': { label: 'Invoice: Part Paid', ico: 'fa-money' },
+ | 'invoice__paid': { label: 'Invoice: Paid', ico: 'fa-money' },
+ | 'invoice__refunded': { label: 'Invoice: Refunded', ico: 'fa-money' },
+ | 'transaction': { label: 'Transaction', ico: 'fa-credit-card' },
+ | 'tweet': { label: 'Tweet', ico: 'fa-twitter' },
+ | 'facebook_post': { label: 'Facebook Post', ico: 'fa-facebook-official' },
+ | 'created': { label: 'Created', ico: 'fa-plus-circle' },
+ | 'updated': { label: 'Updated', ico: 'fa-pencil-square-o' },
+ | 'quote_created': { label: 'Quote Created', ico: 'fa-plus-circle' },
+ | 'invoice_created': { label: 'Invoice Created', ico: 'fa-plus-circle' },
+ | 'form_filled': { label: 'Form Filled', ico: 'fa-wpforms'}
|
| --------------------------------------------------
|
|
|
- | #} RE: $extraMeta (This isn't used anywhere yet, talk to WH before using)
+ | #} RE: $extraMeta (This isn't used anywhere yet, talk to WH before using)
|
- | ... this is a key value array passable to add extra values to customers
- | ... should look like:
+ | ... this is a key value array passable to add extra values to customers
+ | ... should look like:
|
- | $extraMeta = array(
+ | $extraMeta = array(
|
- | array('key_here',12345),
- | array('another','what')
+ | array('key_here',12345),
+ | array('another','what')
|
- | )
+ | )
|
- | ... which will add the following meta to a customer:
+ | ... which will add the following meta to a customer:
|
- | zbs_customer_extra_key_here = 12345
- | zbs_customer_extra_another = what
+ | zbs_customer_extra_key_here = 12345
+ | zbs_customer_extra_another = what
|
- | ... BRUTALLY - no checking, just overwrites! (so be careful)
+ | ... BRUTALLY - no checking, just overwrites! (so be careful)
|
- | #} Re: $automatorPassthrough
+ | #} Re: $automatorPassthrough
|
- | ... adding anything here allows it to be passed through to the internal automator (which currently sets notes)
- | ... this means you can pass an array with note str overrides... e.g.
+ | ... adding anything here allows it to be passed through to the internal automator (which currently sets notes)
+ | ... this means you can pass an array with note str overrides... e.g.
|
- | array(
+ | array(
|
- | 'note_override' => array(
- |
- | 'type' => 'Form Filled',#'form_filled',
- | 'shortdesc' => 'Dude filled out the form x on y',
- | 'longdesc' => ''
+ | 'note_override' => array(
|
- | )
+ | 'type' => 'Form Filled',#'form_filled',
+ | 'shortdesc' => 'Dude filled out the form x on y',
+ | 'longdesc' => ''
|
- | )
+ | )
|
- | ... see recipes to see what's useful :)
+ | )
+ |
+ | ... see recipes to see what's useful :)
|
|=======================================
- | 27/09/16: $emailAlreadyExistsAction
- |
- | This is a flag to say what to do in this circumstance: User obj passed has an email (in $customerFields['zbsc_email']) which matches a customer in DB already
- | ... options:
- | 'update': Update customer record (and add external source) (BRUTAL override)
- | 'skip': Do nothing
- | 'notifyexit': quit + notify
- | ... this func is mostly future proofing, as there may be times we want to avoid overriding existing data from an import e.g.
+ | 27/09/16: $emailAlreadyExistsAction
+ |
+ | This is a flag to say what to do in this circumstance: User obj passed has an email (in $customerFields['zbsc_email']) which matches a customer in DB already
+ | ... options:
+ | 'update': Update customer record (and add external source) (BRUTAL override)
+ | 'skip': Do nothing
+ | 'notifyexit': quit + notify
+ | ... this func is mostly future proofing, as there may be times we want to avoid overriding existing data from an import e.g.
|
|=======================================
| ... Made this func super easy so you can just fire it when you're not sure if add or update... :) it'll deal.
|=======================================
| Returns:
- | Customer ID
- | or
- | False (boolean) (customer create/update failed)
+ | Customer ID
+ | or
+ | False (boolean) (customer create/update failed)
|=======================================
*/
-function zeroBS_integrations_addOrUpdateCustomer($externalSource='',$externalID='',$customerFields=array(), $customerDate = '', $fallbackLog='auto', $extraMeta = false, $automatorPassthroughArray = false, $emailAlreadyExistsAction = 'update',$fieldPrefix = 'zbsc_'){
+function zeroBS_integrations_addOrUpdateCustomer( $externalSource = '', $externalID = '', $customerFields = array(), $customerDate = '', $fallbackLog = 'auto', $extraMeta = false, $automatorPassthroughArray = false, $emailAlreadyExistsAction = 'update', $fieldPrefix = 'zbsc_' ) {
#} leave this true and it'll run as normal.
$usualUpdate = true;
$potentialCustomerIDfromEmail = false;
- if (!empty($externalSource) && !empty($externalID) && is_array($customerFields) && count($customerFields) > 0){
+ if ( ! empty( $externalSource ) && ! empty( $externalID ) && is_array( $customerFields ) && count( $customerFields ) > 0 ) {
- if (isset($customerFields['zbsc_email']) && !empty($customerFields['zbsc_email'])){
+ if ( isset( $customerFields['zbsc_email'] ) && ! empty( $customerFields['zbsc_email'] ) ) {
#} First check for email in cust list
- $potentialCustomerIDfromEmail = zeroBS_getCustomerIDWithEmail($customerFields['zbsc_email']);
+ $potentialCustomerIDfromEmail = zeroBS_getCustomerIDWithEmail( $customerFields['zbsc_email'] );
#} If so... act based on $emailAlreadyExistsAction param
- if (!empty($potentialCustomerIDfromEmail)){
+ if ( ! empty( $potentialCustomerIDfromEmail ) ) {
#} So we have a customer with this email...
- switch ($emailAlreadyExistsAction){
+ switch ( $emailAlreadyExistsAction ) {
- /* not built out yet...
+ /*
+ not built out yet...
case 'addextsrc':
#} Just add the external source
-
break; */
case 'update':
-
#} Just let it roll on...
$usualUpdate = true;
break;
case 'skip':
-
#} don't do nothin :)
$usualUpdate = false;
-
break;
case 'notifyexit':
-
#} Notify + exit
echo esc_html( 'Contact Add/Update Issue: A contact already exists with the email "' . $customerFields['zbsc_email'] . '" (ID: ' . $potentialCustomerIDfromEmail . '), user could not be processed!' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
exit( 0 );
break;
-
-
}
-
}
-
}
#} =========================================================================================
#} NO existing user! Proceed as before!
#} =========================================================================================
- if ($usualUpdate){
-
+ if ( $usualUpdate ) {
// if ID specifically passed, use that :)
- if (isset($customerFields['id']) && !empty($customerFields['id']) && $customerFields['id'] > 0){
+ if ( isset( $customerFields['id'] ) && ! empty( $customerFields['id'] ) && $customerFields['id'] > 0 ) {
$potentialCustomerID = $customerFields['id'];
-
+
} else {
#} Do query for ID
- $potentialCustomerID = zeroBS_getCustomerIDWithExternalSource($externalSource,$externalID);
+ $potentialCustomerID = zeroBS_getCustomerIDWithExternalSource( $externalSource, $externalID );
}
#} If ID empty, but $potentialCustomerIDfromEmail (from above) not, use $potentialCustomerIDfromEmail
- if (($potentialCustomerID === false || $potentialCustomerID == -1) && $potentialCustomerIDfromEmail !== false) $potentialCustomerID = $potentialCustomerIDfromEmail;
+ if ( ( $potentialCustomerID === false || $potentialCustomerID == -1 ) && $potentialCustomerIDfromEmail !== false ) {
+ $potentialCustomerID = $potentialCustomerIDfromEmail;
+ }
#} Default fallback log creation
$fallbackLogToPass = false;
- if (
- !isset($fallbackLog) ||
- !is_array($fallbackLog)
- ) {
+ if (
+ ! isset( $fallbackLog ) ||
+ ! is_array( $fallbackLog )
+ ) {
#} create default fallback log, unless $fallbackLog is set to 'none'
- if ($fallbackLog !== 'none'){
+ if ( $fallbackLog !== 'none' ) {
#} Autogen
#} Left this out for v1.1.18... needs thought.
- #} Do we really want to put "woo source added"? It might get added loads.
+ #} Do we really want to put "woo source added"? It might get added loads.
#} For now leave as manual...
}
-
- } elseif (is_array($fallbackLog)){
+ } elseif ( is_array( $fallbackLog ) ) {
#} Fallback log is probably set, just pass it along.
$fallbackLogToPass = $fallbackLog;
@@ -319,73 +308,74 @@ function zeroBS_integrations_addOrUpdateCustomer($externalSource='',$externalID=
}
#} Here we're passing along any automator pass through
- #} ... which will typically be overrides for creation logs or any extra params to give to internal automator.
- $automatorPassthrough = false; if (isset($automatorPassthroughArray) && is_array($automatorPassthroughArray)) $automatorPassthrough = $automatorPassthroughArray;
+ #} ... which will typically be overrides for creation logs or any extra params to give to internal automator.
+ $automatorPassthrough = false;
+ if ( isset( $automatorPassthroughArray ) && is_array( $automatorPassthroughArray ) ) {
+ $automatorPassthrough = $automatorPassthroughArray;
+ }
#} Not yet used, ask WH
// Now passing through 2.24+ $extraMeta = false;
#} Brutal add/update
#} MS - 3rd Jan 2019 - this (eventually) just calls the usual _addUpdateCustomer function
- $customerID = zeroBS_addUpdateCustomer($potentialCustomerID,$customerFields,$externalSource,$externalID, $customerDate, $fallbackLogToPass, $extraMeta, $automatorPassthrough, -1, $fieldPrefix);
+ $customerID = zeroBS_addUpdateCustomer( $potentialCustomerID, $customerFields, $externalSource, $externalID, $customerDate, $fallbackLogToPass, $extraMeta, $automatorPassthrough, -1, $fieldPrefix );
return $customerID;
-
} #} / usual update
- } else{
+ } else {
return false;
}
-
}
/*
|=======================================
- | zeroBS_integrations_addOrUpdateCompany
+ | zeroBS_integrations_addOrUpdateCompany
|=======================================
| Add's a new Company, or updates an existing Company, where their externalSource + externalID matches an existing Company (if specified)
| NOTE: This is different from zeroBS_integrations_addOrUpdateCustomer, in that the externalID must be COMPANY NAME
| This only works with specific external sources, as 'zeroBS_integrations_getCompany'
| These "externalSource"s can be flags we agree on, and add here for reference
- | 23/01/2015:
- | 'woo' = WooCommerce
- | 'pay' = Paypal
- | 'form' = Form Capture
+ | 23/01/2015:
+ | 'woo' = WooCommerce
+ | 'pay' = Paypal
+ | 'form' = Form Capture
|
| Usage:
-
+
zeroBS_integrations_addOrUpdateCompany('woo','Dell',array(
- 'zbsc_coname' => 'Dell',
+ 'zbsc_coname' => 'Dell',
- 'zbsc_status' => 'Lead',
- 'zbsc_addr1' => 'First Addr',
- 'zbsc_addr2' => '2nd Addr',
- 'zbsc_city' => 'London',
- 'zbsc_county' => 'G London',
- 'zbsc_postcode' => 'AL1 111',
- 'zbsc_hometel' => '0123456789',
- 'zbsc_worktel' => '999',
- 'zbsc_mobtel' => '333',
- 'zbsc_notes' => 'Multi Line
- Notes
- Kick Ass',
+ 'zbsc_status' => 'Lead',
+ 'zbsc_addr1' => 'First Addr',
+ 'zbsc_addr2' => '2nd Addr',
+ 'zbsc_city' => 'London',
+ 'zbsc_county' => 'G London',
+ 'zbsc_postcode' => 'AL1 111',
+ 'zbsc_hometel' => '0123456789',
+ 'zbsc_worktel' => '999',
+ 'zbsc_mobtel' => '333',
+ 'zbsc_notes' => 'Multi Line
+ Notes
+ Kick Ass',
- #} custom fields are set as cf(int) and so are per-install dependent, you probs don't ever want to insert these :) :D
- #'zbsc_cf1' => 'Google'
+ #} custom fields are set as cf(int) and so are per-install dependent, you probs don't ever want to insert these :) :D
+ #'zbsc_cf1' => 'Google'
- ),
+ ),
'customer_date as per mike!',
- 'none',
+ 'none',
- false,
+ false,
false
- );
-
+ );
+
|
| ... note "woo" external source flag
| ... note "woodyhayday2@smt.com" - my ID within woo
@@ -394,207 +384,204 @@ function zeroBS_integrations_addOrUpdateCustomer($externalSource='',$externalID=
| ... Note: From v1.1.18 we also have fallback logs:
| --------------------------------------------------
| Fallback Logs:
- | Pass either:
- | 'none' = do nothing if user already exists
- | 'auto' = automatically create log (NOT WORKING YET)
- | OR:
- | array(
- | 'type' => 'Form Filled',#'form_filled',
- | 'shortdesc' => 'Dude filled out the form x on y',
- | 'longdesc' => ''
- | )
- |
- | (Long desc is optional)
- |
- | #} CURRENT Note Types (use first field/key e.g. "form_filled") (v1.1.18 - 20/09/16)
- |
- | 'note': { label: 'Note', ico: 'fa-sticky-note-o' },
- | 'call': { label: 'Call', ico: 'fa-phone-square' },
- | 'email': { label: 'Email', ico: 'fa-envelope-o' },
- | 'meeting': { label: 'Meeting', ico: 'fa-users' },
- | 'quote__sent': { label: 'Quote: Sent', ico: 'fa-share-square-o' },
- | 'quote__accepted': { label: 'Quote: Accepted', ico: 'fa-thumbs-o-up' },
- | 'quote__refused': { label: 'Quote: Refused', ico: 'fa-ban' },
- | 'invoice__sent': { label: 'Invoice: Sent', ico: 'fa-share-square-o' },
- | 'invoice__part_paid': { label: 'Invoice: Part Paid', ico: 'fa-money' },
- | 'invoice__paid': { label: 'Invoice: Paid', ico: 'fa-money' },
- | 'invoice__refunded': { label: 'Invoice: Refunded', ico: 'fa-money' },
- | 'transaction': { label: 'Transaction', ico: 'fa-credit-card' },
- | 'tweet': { label: 'Tweet', ico: 'fa-twitter' },
- | 'facebook_post': { label: 'Facebook Post', ico: 'fa-facebook-official' },
- | 'created': { label: 'Created', ico: 'fa-plus-circle' },
- | 'updated': { label: 'Updated', ico: 'fa-pencil-square-o' },
- | 'quote_created': { label: 'Quote Created', ico: 'fa-plus-circle' },
- | 'invoice_created': { label: 'Invoice Created', ico: 'fa-plus-circle' },
- | 'form_filled': { label: 'Form Filled', ico: 'fa-wpforms'}
+ | Pass either:
+ | 'none' = do nothing if user already exists
+ | 'auto' = automatically create log (NOT WORKING YET)
+ | OR:
+ | array(
+ | 'type' => 'Form Filled',#'form_filled',
+ | 'shortdesc' => 'Dude filled out the form x on y',
+ | 'longdesc' => ''
+ | )
+ |
+ | (Long desc is optional)
+ |
+ | #} CURRENT Note Types (use first field/key e.g. "form_filled") (v1.1.18 - 20/09/16)
+ |
+ | 'note': { label: 'Note', ico: 'fa-sticky-note-o' },
+ | 'call': { label: 'Call', ico: 'fa-phone-square' },
+ | 'email': { label: 'Email', ico: 'fa-envelope-o' },
+ | 'meeting': { label: 'Meeting', ico: 'fa-users' },
+ | 'quote__sent': { label: 'Quote: Sent', ico: 'fa-share-square-o' },
+ | 'quote__accepted': { label: 'Quote: Accepted', ico: 'fa-thumbs-o-up' },
+ | 'quote__refused': { label: 'Quote: Refused', ico: 'fa-ban' },
+ | 'invoice__sent': { label: 'Invoice: Sent', ico: 'fa-share-square-o' },
+ | 'invoice__part_paid': { label: 'Invoice: Part Paid', ico: 'fa-money' },
+ | 'invoice__paid': { label: 'Invoice: Paid', ico: 'fa-money' },
+ | 'invoice__refunded': { label: 'Invoice: Refunded', ico: 'fa-money' },
+ | 'transaction': { label: 'Transaction', ico: 'fa-credit-card' },
+ | 'tweet': { label: 'Tweet', ico: 'fa-twitter' },
+ | 'facebook_post': { label: 'Facebook Post', ico: 'fa-facebook-official' },
+ | 'created': { label: 'Created', ico: 'fa-plus-circle' },
+ | 'updated': { label: 'Updated', ico: 'fa-pencil-square-o' },
+ | 'quote_created': { label: 'Quote Created', ico: 'fa-plus-circle' },
+ | 'invoice_created': { label: 'Invoice Created', ico: 'fa-plus-circle' },
+ | 'form_filled': { label: 'Form Filled', ico: 'fa-wpforms'}
|
| --------------------------------------------------
|
|
|
- | #} RE: $extraMeta (This isn't used anywhere yet, talk to WH before using)
+ | #} RE: $extraMeta (This isn't used anywhere yet, talk to WH before using)
+ |
+ | ... this is a key value array passable to add extra values to customers
+ | ... should look like:
|
- | ... this is a key value array passable to add extra values to customers
- | ... should look like:
+ | $extraMeta = array(
|
- | $extraMeta = array(
+ | array('key_here',12345),
+ | array('another','what')
|
- | array('key_here',12345),
- | array('another','what')
+ | )
|
- | )
+ | ... which will add the following meta to a customer:
|
- | ... which will add the following meta to a customer:
+ | zbs_customer_extra_key_here = 12345
+ | zbs_customer_extra_another = what
|
- | zbs_customer_extra_key_here = 12345
- | zbs_customer_extra_another = what
+ | ... BRUTALLY - no checking, just overwrites! (so be careful)
|
- | ... BRUTALLY - no checking, just overwrites! (so be careful)
+ | #} Re: $automatorPassthrough
|
- | #} Re: $automatorPassthrough
+ | ... adding anything here allows it to be passed through to the intval(var)ternal automator (which currently sets notes)
+ | ... this means you can pass an array with note str overrides... e.g.
|
- | ... adding anything here allows it to be passed through to the intval(var)ternal automator (which currently sets notes)
- | ... this means you can pass an array with note str overrides... e.g.
+ | array(
|
- | array(
+ | 'note_override' => array(
|
- | 'note_override' => array(
- |
- | 'type' => 'Form Filled',#'form_filled',
- | 'shortdesc' => 'Dude filled out the form x on y',
- | 'longdesc' => ''
+ | 'type' => 'Form Filled',#'form_filled',
+ | 'shortdesc' => 'Dude filled out the form x on y',
+ | 'longdesc' => ''
|
- | )
+ | )
|
- | )
+ | )
|
- | ... see recipes to see what's useful :)
+ | ... see recipes to see what's useful :)
|
|=======================================
- | 27/09/16: $conameAlreadyExistsAction
- |
- | This is a flag to say what to do in this circumstance: User obj passed has an email (in $companyFields['zbsc_coname']) which matches a company in DB already
- | ... options:
- | 'update': Update company record (and add external source) (BRUTAL override)
- | 'skip': Do nothing
- | 'notifyexit': quit + notify
- | ... this func is mostly future proofing, as there may be times we want to avoid overriding existing data from an import e.g.
+ | 27/09/16: $conameAlreadyExistsAction
+ |
+ | This is a flag to say what to do in this circumstance: User obj passed has an email (in $companyFields['zbsc_coname']) which matches a company in DB already
+ | ... options:
+ | 'update': Update company record (and add external source) (BRUTAL override)
+ | 'skip': Do nothing
+ | 'notifyexit': quit + notify
+ | ... this func is mostly future proofing, as there may be times we want to avoid overriding existing data from an import e.g.
|
|=======================================
| ... Made this func super easy so you can just fire it when you're not sure if add or update... :) it'll deal.
|=======================================
| Returns:
- | Company ID
- | or
- | False (boolean) (Company create/update failed)
+ | Company ID
+ | or
+ | False (boolean) (Company create/update failed)
|=======================================
*/
#} External source + (externalID = Co NAME)
function zeroBS_integrations_addOrUpdateCompany(
- $externalSource='',
- $externalID='',
- $companyFields=array(),
- $companyDate = '',
- $fallbackLog='auto',
- $extraMeta = false,
- $automatorPassthroughArray = false,
+ $externalSource = '',
+ $externalID = '',
+ $companyFields = array(),
+ $companyDate = '',
+ $fallbackLog = 'auto',
+ $extraMeta = false,
+ $automatorPassthroughArray = false,
$conameAlreadyExistsAction = 'update',
- $fieldPrefix = 'zbsc_'){
+ $fieldPrefix = 'zbsc_'
+) {
global $zbs;
#} leave this true and it'll run as normal.
$usualUpdate = true;
- if (!empty($externalSource) && !empty($externalID) && is_array($companyFields) && count($companyFields) > 0){
+ if ( ! empty( $externalSource ) && ! empty( $externalID ) && is_array( $companyFields ) && count( $companyFields ) > 0 ) {
$potentialCompanyIDfromName = false;
- $potentialCoName = '';
+ $potentialCoName = '';
// <3.0
- if (isset($companyFields[$fieldPrefix.'coname']) && !empty($companyFields[$fieldPrefix.'coname'])) $potentialCoName = $companyFields[$fieldPrefix.'coname'];
+ if ( isset( $companyFields[ $fieldPrefix . 'coname' ] ) && ! empty( $companyFields[ $fieldPrefix . 'coname' ] ) ) {
+ $potentialCoName = $companyFields[ $fieldPrefix . 'coname' ];
+ }
// 3.0
- if (isset($companyFields[$fieldPrefix.'name']) && !empty($companyFields[$fieldPrefix.'name'])) $potentialCoName = $companyFields[$fieldPrefix.'name'];
-
+ if ( isset( $companyFields[ $fieldPrefix . 'name' ] ) && ! empty( $companyFields[ $fieldPrefix . 'name' ] ) ) {
+ $potentialCoName = $companyFields[ $fieldPrefix . 'name' ];
+ }
- if ($potentialCoName !== ''){
+ if ( $potentialCoName !== '' ) {
#} First check for name in company list
- $potentialCompanyIDfromName = zeroBS_getCompanyIDWithName($potentialCoName);
+ $potentialCompanyIDfromName = zeroBS_getCompanyIDWithName( $potentialCoName );
#} If so... act based on $conameAlreadyExistsAction param
- if (!empty($potentialCompanyIDfromName)){
+ if ( ! empty( $potentialCompanyIDfromName ) ) {
#} So we have a customer with this email...
- switch ($conameAlreadyExistsAction){
+ switch ( $conameAlreadyExistsAction ) {
- /* not built out yet...
+ /*
+ not built out yet...
case 'addextsrc':
#} Just add the external source
-
break; */
case 'update':
-
#} Just let it roll on...
$usualUpdate = true;
break;
case 'skip':
-
#} don't do nothin :)
$usualUpdate = false;
-
break;
case 'notifyexit':
-
#} Notify + exit
- echo esc_html( __(jpcrm_label_company().' Add/Update Issue: A '.jpcrm_label_company().' already exists with the name "','zero-bs-crm').$potentialCoName.'" (ID: '.$potentialCompanyIDfromName.'), '.__('could not be processed!','zero-bs-crm') );
+ echo esc_html( __( jpcrm_label_company() . ' Add/Update Issue: A ' . jpcrm_label_company() . ' already exists with the name "', 'zero-bs-crm' ) . $potentialCoName . '" (ID: ' . $potentialCompanyIDfromName . '), ' . __( 'could not be processed!', 'zero-bs-crm' ) );
exit( 0 );
break;
-
-
}
-
}
-
}
#} =========================================================================================
#} NO existing user! Proceed as before!
#} =========================================================================================
- if ($usualUpdate){
+ if ( $usualUpdate ) {
#} Do query for ID
- $potentialCompanyID = zeroBS_getCompanyIDWithExternalSource($externalSource,$externalID);
+ $potentialCompanyID = zeroBS_getCompanyIDWithExternalSource( $externalSource, $externalID );
#} If ID empty, but $potentialCompanyIDfromName (from above) not, use $potentialCompanyIDfromName
- if ($potentialCompanyID === false && $potentialCompanyIDfromName !== false) $potentialCompanyID = $potentialCompanyIDfromName;
+ if ( $potentialCompanyID === false && $potentialCompanyIDfromName !== false ) {
+ $potentialCompanyID = $potentialCompanyIDfromName;
+ }
#} Default fallback log creation
$fallbackLogToPass = false;
- if (
- !isset($fallbackLog) ||
- !is_array($fallbackLog)
- ) {
+ if (
+ ! isset( $fallbackLog ) ||
+ ! is_array( $fallbackLog )
+ ) {
#} create default fallback log, unless $fallbackLog is set to 'none'
- if ($fallbackLog !== 'none'){
+ if ( $fallbackLog !== 'none' ) {
#} Autogen
#} Left this out for v1.1.18... needs thought.
- #} Do we really want to put "woo source added"? It might get added loads.
+ #} Do we really want to put "woo source added"? It might get added loads.
#} For now leave as manual...
}
-
- } elseif (is_array($fallbackLog)){
+ } elseif ( is_array( $fallbackLog ) ) {
#} Fallback log is probably set, just pass it along.
$fallbackLogToPass = $fallbackLog;
@@ -602,29 +589,30 @@ function zeroBS_integrations_addOrUpdateCompany(
}
#} Here we're passing along any automator pass through
- #} ... which will typically be overrides for creation logs or any extra params to give to internal automator.
- $automatorPassthrough = false; if (isset($automatorPassthroughArray) && is_array($automatorPassthroughArray)) $automatorPassthrough = $automatorPassthroughArray;
+ #} ... which will typically be overrides for creation logs or any extra params to give to internal automator.
+ $automatorPassthrough = false;
+ if ( isset( $automatorPassthroughArray ) && is_array( $automatorPassthroughArray ) ) {
+ $automatorPassthrough = $automatorPassthroughArray;
+ }
#} Not yet used, ask WH
$extraMeta = false;
#} Brutal add/update
- $companyID = zeroBS_addUpdateCompany($potentialCompanyID,$companyFields,$externalSource,$externalID, $companyDate, $fallbackLogToPass, $extraMeta, $automatorPassthrough,-1,$fieldPrefix);
+ $companyID = zeroBS_addUpdateCompany( $potentialCompanyID, $companyFields, $externalSource, $externalID, $companyDate, $fallbackLogToPass, $extraMeta, $automatorPassthrough, -1, $fieldPrefix );
return $companyID;
-
} #} / usual update
- } else return false;
-
-
+ } else {
+ return false;
+ }
}
-
/*
|=======================================
- | zeroBS_integrations_getCompany
+ | zeroBS_integrations_getCompany
|=======================================
| Retrieves a Company record (as usual _getCompany func) - but one that has been inserted via import from an external source
| E.g. Woo Imported, Paypal imported, whatever
@@ -635,49 +623,40 @@ function zeroBS_integrations_addOrUpdateCompany(
| zeroBS_integrations_getCompany('pay','x3da9j3d9jad2')
|=======================================
| Returns:
- | Company obj (std class)
- | or
- | False (boolean) (Company does not exist)
+ | Company obj (std class)
+ | or
+ | False (boolean) (Company does not exist)
|=======================================
| Check via: if ($coobj !== false)
|=======================================
*/
-function zeroBS_integrations_getCompany($externalSource='',$externalID=''){
+function zeroBS_integrations_getCompany( $externalSource = '', $externalID = '' ) {
#} Do query for ID
- $potentialCompanyID = zeroBS_getCompanyIDWithExternalSource($externalSource,$externalID);
+ $potentialCompanyID = zeroBS_getCompanyIDWithExternalSource( $externalSource, $externalID );
- if ($potentialCompanyID !== false){
+ if ( $potentialCompanyID !== false ) {
#} If so, pass full deets via this
- return zeroBS_getCompany($potentialCompanyID);
+ return zeroBS_getCompany( $potentialCompanyID );
}
#} If it gets here, it failed
return false;
-
}
-
-
-
-
-
-
-
-
/*
|=======================================
- | zeroBS_integrations_addOrUpdateTransaction
+ | zeroBS_integrations_addOrUpdateTransaction
|=======================================
| Add's a new Transaction, or updates an existing Transaction, where their externalSource + externalID matches an existing Transaction (if specified)
| NOTE: This is different from zeroBS_integrations_addOrUpdateCustomer, in that the externalID must be Transaction ID
| This only works with specific external sources, as 'zeroBS_integrations_getTransaction'
| Usage:
-
+
zeroBS_integrations_addOrUpdateTransaction('woo','#123456',array(
-
+
REQUIRED:
'orderid' => 'UNIQUEID',
'customer' => CustomerID,
@@ -694,7 +673,6 @@ function zeroBS_integrations_getCompany($externalSource='',$externalID=''){
'discount' => 0,
'tax_rate' => 0,
-
), array(
TAGS:
'sale','bill','chargeback','refund','echeckchargeback','cancel-rebill','uncancel-rebill' etc.
@@ -703,14 +681,14 @@ function zeroBS_integrations_getCompany($externalSource='',$externalID=''){
'date as per mike!',
- 'none',
+ 'none',
- false,
+ false,
false
- );
-
+ );
+
|
| ... note "woo" external source flag
| ... note "woodyhayday2@smt.com" - my ID within woo
@@ -719,151 +697,156 @@ function zeroBS_integrations_getCompany($externalSource='',$externalID=''){
| ... Note: From v1.1.18 we also have fallback logs:
| --------------------------------------------------
| Fallback Logs:
- | Pass either:
- | 'none' = do nothing if user already exists
- | 'auto' = automatically create log (NOT WORKING YET)
- | OR:
- | array(
- | 'type' => 'Form Filled',#'form_filled',
- | 'shortdesc' => 'Dude filled out the form x on y',
- | 'longdesc' => ''
- | )
- |
- | (Long desc is optional)
+ | Pass either:
+ | 'none' = do nothing if user already exists
+ | 'auto' = automatically create log (NOT WORKING YET)
+ | OR:
+ | array(
+ | 'type' => 'Form Filled',#'form_filled',
+ | 'shortdesc' => 'Dude filled out the form x on y',
+ | 'longdesc' => ''
+ | )
+ |
+ | (Long desc is optional)
|
| --------------------------------------------------
|
|
- | #} RE: $extraMeta
+ | #} RE: $extraMeta
|
- | ... this is a key value array passable to add extra values to customers
- | ... should look like:
+ | ... this is a key value array passable to add extra values to customers
+ | ... should look like:
|
- | $extraMeta = array(
+ | $extraMeta = array(
|
- | array('key_here',12345),
- | array('another','what')
+ | array('key_here',12345),
+ | array('another','what')
|
- | )
+ | )
|
- | ... which will add the following meta to a customer:
+ | ... which will add the following meta to a customer:
|
- | zbs_customer_extra_key_here = 12345
- | zbs_customer_extra_another = what
+ | zbs_customer_extra_key_here = 12345
+ | zbs_customer_extra_another = what
|
- | ... BRUTALLY - no checking, just overwrites! (so be careful)
+ | ... BRUTALLY - no checking, just overwrites! (so be careful)
|
| --------------------------------------------------
|
- | #} Re: $automatorPassthrough
+ | #} Re: $automatorPassthrough
|
- | ... adding anything here allows it to be passed through to the internal automator (which currently sets notes)
- | ... this means you can pass an array with note str overrides... e.g.
+ | ... adding anything here allows it to be passed through to the internal automator (which currently sets notes)
+ | ... this means you can pass an array with note str overrides... e.g.
|
- | array(
+ | array(
|
- | 'note_override' => array(
- |
- | 'type' => 'Form Filled',#'form_filled',
- | 'shortdesc' => 'Dude filled out the form x on y',
- | 'longdesc' => ''
+ | 'note_override' => array(
|
- | )
+ | 'type' => 'Form Filled',#'form_filled',
+ | 'shortdesc' => 'Dude filled out the form x on y',
+ | 'longdesc' => ''
|
- | )
+ | )
|
- | ... see recipes to see what's useful :)
+ | )
+ |
+ | ... see recipes to see what's useful :)
|
|=======================================
| Returns:
- | Transaction ID
- | or
- | False (boolean) (Transaction create/update failed)
+ | Transaction ID
+ | or
+ | False (boolean) (Transaction create/update failed)
|=======================================
*/
function zeroBS_integrations_addOrUpdateTransaction(
-
- $transactionExternalSource='', /* Req, e.g. 'str' */
- $transactionExternalID='', /* Req, e.g. 'ch_1DqSxpBy0i6Hd9AL4noH4Yhx' */
- $transactionFields=array(), /* Req: array(orderid,customer,status,total) */
- $transactionTags=array(), /* optional extra tags */
- $transactionDate = '',
- $fallbackLog='auto',
- $extraMeta = false,
+ $transactionExternalSource = '', // Required, e.g. 'str'.
+ $transactionExternalID = '', // Required, e.g. 'ch_1DqSxpBy0i6Hd9AL4noH4Yhx'.
+ $transactionFields = array(), // Required keys: orderid, customer, status, total.
+ $transactionTags = array(),
+ $transactionDate = '',
+ $fallbackLog = 'auto',
+ $extraMeta = false,
$automatorPassthroughArray = false,
$fieldPrefix = 'zbst_'
-
- ){
+) {
#} Check req.
if (
- !empty($transactionExternalSource) && !empty($transactionExternalID) && is_array($transactionFields) && count($transactionFields) > 0 &&
-
- (
- // v2
- (isset($transactionFields['orderid']) && !empty($transactionFields['orderid']))
- ||
- // v3
- (isset($transactionFields['ref']) && !empty($transactionFields['ref']))
-
- ) &&
- //isset($transactionFields['customer']) && !empty($transactionFields['customer']) &&
- isset($transactionFields['status']) && !empty($transactionFields['status']) &&
- isset($transactionFields['total']) && !empty($transactionFields['total'])
- ){
-
- #} Do query for ID
- $potentialTransactionID = zeroBS_getTransactionIDWithExternalSource($transactionExternalSource,$transactionExternalID);
+ ! empty( $transactionExternalSource ) && ! empty( $transactionExternalID ) && is_array( $transactionFields ) && count( $transactionFields ) > 0 &&
- #} Default fallback log creation
- $fallbackLogToPass = false;
- if (
- !isset($fallbackLog) ||
- !is_array($fallbackLog)
- ) {
+ (
+ // v2
+ ( isset( $transactionFields['orderid'] ) && ! empty( $transactionFields['orderid'] ) )
+ ||
+ // v3
+ ( isset( $transactionFields['ref'] ) && ! empty( $transactionFields['ref'] ) )
- #} create default fallback log, unless $fallbackLog is set to 'none'
- if ($fallbackLog !== 'none'){
+ ) &&
+ // isset($transactionFields['customer']) && !empty($transactionFields['customer']) &&
+ isset( $transactionFields['status'] ) && ! empty( $transactionFields['status'] ) &&
+ isset( $transactionFields['total'] ) && ! empty( $transactionFields['total'] )
+ ) {
- #} Autogen
- #} Left this out for v1.1.18... needs thought.
- #} Do we really want to put "woo source added"? It might get added loads.
- #} For now leave as manual...
+ #} Do query for ID
+ $potentialTransactionID = zeroBS_getTransactionIDWithExternalSource( $transactionExternalSource, $transactionExternalID );
- }
+ #} Default fallback log creation
+ $fallbackLogToPass = false;
+ if (
+ ! isset( $fallbackLog ) ||
+ ! is_array( $fallbackLog )
+ ) {
- } elseif (is_array($fallbackLog)){
+ #} create default fallback log, unless $fallbackLog is set to 'none'
+ if ( $fallbackLog !== 'none' ) {
- #} Fallback log is probably set, just pass it along.
- $fallbackLogToPass = $fallbackLog;
+ #} Autogen
+ #} Left this out for v1.1.18... needs thought.
+ #} Do we really want to put "woo source added"? It might get added loads.
+ #} For now leave as manual...
}
+ } elseif ( is_array( $fallbackLog ) ) {
- #} Here we're passing along any automator pass through
- #} ... which will typically be overrides for creation logs or any extra params to give to internal automator.
- $automatorPassthrough = false; if (isset($automatorPassthroughArray) && is_array($automatorPassthroughArray)) $automatorPassthrough = $automatorPassthroughArray;
+ #} Fallback log is probably set, just pass it along.
+ $fallbackLogToPass = $fallbackLog;
- #} Brutal add/update
- $transactionWPID = zeroBS_addUpdateTransaction($potentialTransactionID, $transactionFields, $transactionExternalSource, $transactionExternalID, $transactionDate, $transactionTags, $fallbackLogToPass, $extraMeta, $automatorPassthrough,$fieldPrefix);
+ }
+
+ #} Here we're passing along any automator pass through
+ #} ... which will typically be overrides for creation logs or any extra params to give to internal automator.
+ $automatorPassthrough = false;
+ if ( isset( $automatorPassthroughArray ) && is_array( $automatorPassthroughArray ) ) {
+ $automatorPassthrough = $automatorPassthroughArray;
+ }
- #} Update any title
- #} Not needed for transactions: if ($transactionWPID !== false) zbsCustomer_updateCompanyNameInPostTitle($companyID,false);
+ #} Brutal add/update
+ $transactionWPID = zeroBS_addUpdateTransaction( $potentialTransactionID, $transactionFields, $transactionExternalSource, $transactionExternalID, $transactionDate, $transactionTags, $fallbackLogToPass, $extraMeta, $automatorPassthrough, $fieldPrefix );
- return $transactionWPID;
+ #} Update any title
+ #} Not needed for transactions: if ($transactionWPID !== false) zbsCustomer_updateCompanyNameInPostTitle($companyID,false);
+
+ return $transactionWPID;
} else { // no source/id/fields
return false;
}
-
}
-// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
+/**
+ * Adds or updates a task via integrations.
+ *
+ * @param int $task_id Task ID.
+ * @param array $data_array Task data. Required keys: 'title', 'to', 'from'.
+ * @param array $task_reminders Task reminders. Keys: 'remind_at', 'sent' (v3+).
+ */
function zeroBS_integrations_addOrUpdateTask(
- $task_id = -1, /* Req - the task ID */
- $data_array = array(), /* Req: title,to, from */
- $task_reminders = array() /* Req: remind_at,sent (v3+) */
+ $task_id = -1,
+ $data_array = array(),
+ $task_reminders = array()
) {
#} Check req.
@@ -879,16 +862,15 @@ function zeroBS_integrations_addOrUpdateTask(
( ! empty( $data_array['start'] ) && ! empty( $data_array['end'] ) )
)
) {
- return zeroBS_addUpdateEvent( $task_id, $data_array, $task_reminders );
+ return zeroBS_addUpdateEvent( $task_id, $data_array, $task_reminders );
} else { // no source/id/fields
return false;
}
}
-
/*
|=======================================
- | zeroBS_integrations_getTransaction
+ | zeroBS_integrations_getTransaction
|=======================================
| Retrieves a transaction record (as usual _getTransaction func) - but one that has been inserted via import from an external source
| E.g. Woo Imported, Paypal imported, whatever
@@ -899,117 +881,99 @@ function zeroBS_integrations_addOrUpdateTask(
| zeroBS_integrations_getTransaction('pay','x3da9j3d9jad2')
|=======================================
| Returns:
- | transaction obj (std class)
- | or
- | False (boolean) (transaction does not exist)
+ | transaction obj (std class)
+ | or
+ | False (boolean) (transaction does not exist)
|=======================================
| Check via: if ($transobj !== false)
|=======================================
*/
-function zeroBS_integrations_getTransaction($transactionExternalSource='',$transactionExternalID=''){
+function zeroBS_integrations_getTransaction( $transactionExternalSource = '', $transactionExternalID = '' ) {
#} Do query for ID
- $potentialTransactionID = zeroBS_getTransactionIDWithExternalSource($transactionExternalSource,$transactionExternalID);
+ $potentialTransactionID = zeroBS_getTransactionIDWithExternalSource( $transactionExternalSource, $transactionExternalID );
- if ($potentialTransactionID !== false){
+ if ( $potentialTransactionID !== false ) {
#} If so, pass full deets via this
- return zeroBS_getTransaction($potentialTransactionID);
+ return zeroBS_getTransaction( $potentialTransactionID );
}
#} If it gets here, it failed
return false;
-
}
-
-
-
-
-
-
-
/*
For now a wrapper, later will allow us to seemlessly feed in customer generated cats
*/
-function zeroBS_integrations_getAllCategories($incEmpty=false){
+function zeroBS_integrations_getAllCategories( $incEmpty = false ) {
global $zbs;
- return array('zerobscrm_customertag' => $zbs->DAL->getTagsForObjType(array(
-
- 'objtypeid'=>ZBS_TYPE_CONTACT,
- 'excludeEmpty'=>!$incEmpty,
- 'withCount'=>true,
- 'ignoreowner' => true,
- // sort
- 'sortByField' => 'zbstag_name',
- 'sortOrder' => 'ASC'
-
- )));
-
+ return array(
+ 'zerobscrm_customertag' => $zbs->DAL->getTagsForObjType(
+ array(
+
+ 'objtypeid' => ZBS_TYPE_CONTACT,
+ 'excludeEmpty' => ! $incEmpty,
+ 'withCount' => true,
+ 'ignoreowner' => true,
+ // sort
+ 'sortByField' => 'zbstag_name',
+ 'sortOrder' => 'ASC',
+
+ )
+ ),
+ );
}
-
#} For now just a wrapper
-function zeroBS_integrations_searchCustomers($args=array()){
-
- if (!empty($args) && isset($args['searchPhrase'])) return zeroBS_searchCustomers($args);
+function zeroBS_integrations_searchCustomers( $args = array() ) {
- return array();
+ if ( ! empty( $args ) && isset( $args['searchPhrase'] ) ) {
+ return zeroBS_searchCustomers( $args );
+ }
+ return array();
}
-#} Add log (currently a wrapper)
+/**
+ * Adds a log entry (currently a wrapper for zeroBS_addUpdateLog).
+ *
+ * @param int $objID Object ID.
+ * @param int $logDate Log date timestamp.
+ * @param array $noteFields Note fields array. May include 'meta_assoc_id'
+ * (e.g. campaign ID for 'email sent' logs) and 'meta_assoc_src'
+ * (e.g. 'mailcamp').
+ * @param string $objType Object type, e.g. 'zerobs_customer' or a ZBS_TYPE_* constant.
+ */
function zeroBS_integrations_addLog(
+ $objID = -1,
+ $logDate = -1,
+ $noteFields = array(),
+ $objType = ''
+) {
- $objID = -1,
- /* - is add, doesn't need this:
- $logID = -1,
- */
- $logDate = -1,
-
- /*
-
- NOTE!: as of 31/05/17 WOODY started putting
- 'meta_assoc_id' in these - e.g. if it's an 'email sent' log, this meta_assoc_id will be the CAMPAIGN id
- 'meta_assoc_src' would then be mailcamp
-
- */
-
- $noteFields = array(),
-
- /*
- DB2 requires obj type,
- for now we use zerobs_customer etc. but later we will make these interchangable with TYPES e.g. ZBS_TYPE_CONTACT
- */
-
- $objType = ''
-
- ){
-
- if (!empty($objID)){
+ if ( ! empty( $objID ) ) {
#} Add fresh log:
- zeroBS_addUpdateLog($objID,-1,$logDate,$noteFields,$objType);
+ zeroBS_addUpdateLog( $objID, -1, $logDate, $noteFields, $objType );
return true;
}
return false;
-
-
}
// WH added, backward compat:
-// only works DAL2 +
-function zeroBS_integrations_getCustomFields($objTypeID=-1){
+// only works DAL2 +
+function zeroBS_integrations_getCustomFields( $objTypeID = -1 ) {
- $objTypeID = (int)$objTypeID;
+ $objTypeID = (int) $objTypeID;
- if ($objTypeID > 0){
+ if ( $objTypeID > 0 ) {
global $zbs;
@@ -1020,6 +984,7 @@ function zeroBS_integrations_getCustomFields($objTypeID=-1){
return array();
}
-/* ======================================================
- / Integration specific extension functions
- ====================================================== */
+/*
+======================================================
+ / Integration specific extension functions
+ ====================================================== */
diff --git a/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomator.php b/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomator.php
index 570dd9289f04..2d6aa68b6548 100644
--- a/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomator.php
+++ b/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomator.php
@@ -1,5 +1,5 @@
-internalAutomatorBlock) $goodToGo = false;
-
+ if ( $zbs->internalAutomatorBlock ) {
+ $goodToGo = false;
+ }
- if ($goodToGo && !empty($actionStr)){
+ if ( $goodToGo && ! empty( $actionStr ) ) {
#} Action str should be alphanumeric with periods
#} Checks if there's a global variable (work list) for this $actionStr
- $actionHolderName = 'zeroBSCRM_IA_Action_'.str_replace('.','_',$actionStr);
+ $actionHolderName = 'zeroBSCRM_IA_Action_' . str_replace( '.', '_', $actionStr );
#} Exists?
- if (isset($GLOBALS[ $actionHolderName ]) && is_array($GLOBALS[ $actionHolderName ])){
+ if ( isset( $GLOBALS[ $actionHolderName ] ) && is_array( $GLOBALS[ $actionHolderName ] ) ) {
- #} If here, has an array
- foreach ($GLOBALS[ $actionHolderName ] as $action){
+ #} If here, has an array
+ foreach ( $GLOBALS[ $actionHolderName ] as $action ) {
- if (isset($action['act']) && !empty($action['act']) && isset($action['params'])){
+ if ( isset( $action['act'] ) && ! empty( $action['act'] ) && isset( $action['params'] ) ) {
#} ['params'] not used yet... future proofing.
#} Fire any applicable
- if (function_exists($action['act'])){
+ if ( function_exists( $action['act'] ) ) {
#} call it, (and pass whatever was passed to this)
-
-
- call_user_func($action['act'],$obj);
+ call_user_func( $action['act'], $obj );
}
-
-
}
-
}
-
}
-
}
- return;
-
+ return;
}
+function zeroBSCRM_AddInternalAutomatorRecipe( $actionStr = '', $functionName = '', $paramsObj = array() ) {
-function zeroBSCRM_AddInternalAutomatorRecipe($actionStr='',$functionName='',$paramsObj=array()){
-
- if (!empty($actionStr) && !empty($functionName)){
+ if ( ! empty( $actionStr ) && ! empty( $functionName ) ) {
#} Some legacy support
- $actionStr = zeroBSCRM_InternalAutomatorLegacyActionCheck($actionStr);
+ $actionStr = zeroBSCRM_InternalAutomatorLegacyActionCheck( $actionStr );
#} Action str should be alphanumeric with periods
#} Checks if there's a global variable (work list) for this $actionStr
- $actionHolderName = 'zeroBSCRM_IA_Action_'.str_replace('.','_',$actionStr);
+ $actionHolderName = 'zeroBSCRM_IA_Action_' . str_replace( '.', '_', $actionStr );
#} Init?
- if (!isset($GLOBALS[ $actionHolderName ])) $GLOBALS[ $actionHolderName ] = array();
+ if ( ! isset( $GLOBALS[ $actionHolderName ] ) ) {
+ $GLOBALS[ $actionHolderName ] = array();
+ }
#} Append.
- array_push($GLOBALS[ $actionHolderName ],array('act'=>$functionName,'params'=>$paramsObj));
+ array_push(
+ $GLOBALS[ $actionHolderName ],
+ array(
+ 'act' => $functionName,
+ 'params' => $paramsObj,
+ )
+ );
return true;
@@ -140,10 +137,10 @@ function zeroBSCRM_AddInternalAutomatorRecipe($actionStr='',$functionName='',$pa
}
// checks for newer labels + converts
-function zeroBSCRM_InternalAutomatorLegacyActionCheck($actionStr = ''){
-
+function zeroBSCRM_InternalAutomatorLegacyActionCheck( $actionStr = '' ) {
+
#} Some legacy support
- switch ($actionStr){
+ switch ( $actionStr ) {
case 'contact.new':
$actionStr = 'customer.new';
@@ -158,9 +155,9 @@ function zeroBSCRM_InternalAutomatorLegacyActionCheck($actionStr = ''){
}
return $actionStr;
-
}
-
-/* ======================================================
+
+/*
+======================================================
/ Internal Automator
- ====================================================== */
+ ====================================================== */
diff --git a/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomatorRecipes.php b/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomatorRecipes.php
index 4aaf5d7cd031..3019696e8582 100644
--- a/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomatorRecipes.php
+++ b/projects/plugins/crm/includes/ZeroBSCRM.InternalAutomatorRecipes.php
@@ -1,5 +1,5 @@
- 0){
-
- #} Retrieve necessary info:
- $zbsNoteAgainstPostID = -1; if (is_array($obj) && isset($obj['id'])) $zbsNoteAgainstPostID = (int)$obj['id'];
- if (isset($zbsNoteAgainstPostID) && !empty($zbsNoteAgainstPostID)){
-
- #} First check if an override is passed...
- if (isset($obj['automatorpassthrough']) && is_array($obj['automatorpassthrough']) && isset($obj['automatorpassthrough']['note_override']) && is_array($obj['automatorpassthrough']['note_override']) && isset($obj['automatorpassthrough']['note_override']['type'])){
-
- #} An overriding note has been passed, just use that
-
- #} Add log
- $newLogID = zeroBS_addUpdateContactLog($zbsNoteAgainstPostID,-1,-1,$obj['automatorpassthrough']['note_override']);
-
- } else {
-
- #} No override, use default processing...
-
-
+function zeroBSCRM_IA_NewCustomerLog( $obj = array() ) {
- #} Set Deets
- $newCustomerName = ''; if (is_array($obj) && isset($obj['id']) && isset($obj['customerMeta']) && is_array($obj['customerMeta'])) $newCustomerName = zeroBS_customerName($obj['id'],$obj['customerMeta'],false,true);
- $noteShortDesc = 'Customer Created'; if (!empty($newCustomerName)) $noteShortDesc = $newCustomerName;
- $note_long_description = '';
+ # if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_customer_new' );
- // Custom short desc for external source creations
- if (isset($obj['extsource']) && !empty($obj['extsource'])){
+ if ( $autoLogThis > 0 ) {
- $uid = '';
+ #} Retrieve necessary info:
+ $zbsNoteAgainstPostID = -1;
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $zbsNoteAgainstPostID = (int) $obj['id'];
+ }
+ if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) {
- // We seem to pass either the external source array (woo)
- // ... or a string 'pay', so lets select the right one...
- if ( is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) ){
+ #} First check if an override is passed...
+ if ( isset( $obj['automatorpassthrough'] ) && is_array( $obj['automatorpassthrough'] ) && isset( $obj['automatorpassthrough']['note_override'] ) && is_array( $obj['automatorpassthrough']['note_override'] ) && isset( $obj['automatorpassthrough']['note_override']['type'] ) ) {
- $source_key = $obj['extsource']['source'];
+ #} An overriding note has been passed, just use that
- // if we have this we also have UID
- $uid = $obj['extsource']['uid'];
+ #} Add log
+ $newLogID = zeroBS_addUpdateContactLog( $zbsNoteAgainstPostID, -1, -1, $obj['automatorpassthrough']['note_override'] );
- } else {
- $source_key = $obj['extsource'];
- }
+ } else {
- switch ( $source_key ){
+ #} No override, use default processing...
- case 'pay':
+ #} Set Deets
+ $newCustomerName = '';
+ if ( is_array( $obj ) && isset( $obj['id'] ) && isset( $obj['customerMeta'] ) && is_array( $obj['customerMeta'] ) ) {
+ $newCustomerName = zeroBS_customerName( $obj['id'], $obj['customerMeta'], false, true );
+ }
+ $noteShortDesc = 'Customer Created';
+ if ( ! empty( $newCustomerName ) ) {
+ $noteShortDesc = $newCustomerName;
+ }
+ $note_long_description = '';
- $note_long_description = __( 'Created from PayPal', 'zero-bs-crm' ) . '
';
+ // Custom short desc for external source creations
+ if ( isset( $obj['extsource'] ) && ! empty( $obj['extsource'] ) ) {
- break;
+ $uid = '';
- case 'woo':
+ // We seem to pass either the external source array (woo)
+ // ... or a string 'pay', so lets select the right one...
+ if ( is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) ) {
- $note_long_description = __( 'Created from WooCommerce Order', 'zero-bs-crm' ) . '
';
+ $source_key = $obj['extsource']['source'];
- break;
+ // if we have this we also have UID
+ $uid = $obj['extsource']['uid'];
- case 'env':
+ } else {
+ $source_key = $obj['extsource'];
+ }
- $note_long_description = __( 'Created from Envato', 'zero-bs-crm' ) . '
';
+ switch ( $source_key ) {
- break;
+ case 'pay':
+ $note_long_description = __( 'Created from PayPal', 'zero-bs-crm' ) . '
';
- case 'form':
+ break;
- $note_long_description = __( 'Created from Form Capture', 'zero-bs-crm' ) . '
';
+ case 'woo':
+ $note_long_description = __( 'Created from WooCommerce Order', 'zero-bs-crm' ) . '
';
- break;
+ break;
- case 'csv':
+ case 'env':
+ $note_long_description = __( 'Created from Envato', 'zero-bs-crm' ) . '
';
- $note_long_description = __( 'Created from CSV Import', 'zero-bs-crm' ) . '
';
+ break;
- break;
+ case 'form':
+ $note_long_description = __( 'Created from Form Capture', 'zero-bs-crm' ) . '
';
- case 'gra':
+ break;
- $note_long_description = __( 'Created from Gravity Forms', 'zero-bs-crm' ) . '
';
+ case 'csv':
+ $note_long_description = __( 'Created from CSV Import', 'zero-bs-crm' ) . '
';
- break;
+ break;
- default:
+ case 'gra':
+ $note_long_description = __( 'Created from Gravity Forms', 'zero-bs-crm' ) . '
';
- // Generic fallback (shouldn't ever fire)
- $note_long_description = __( 'Created from External Source', 'zero-bs-crm' ) . '
';
+ break;
- break;
+ default:
+ // Generic fallback (shouldn't ever fire)
+ $note_long_description = __( 'Created from External Source', 'zero-bs-crm' ) . '
';
- }
-
- // allow extension override via filter (e.g. WooSync)
- $note_long_description = apply_filters( 'jpcrm_new_contact_log', $note_long_description, $source_key, $uid );
+ break;
+ }
- }
+ // allow extension override via filter (e.g. WooSync)
+ $note_long_description = apply_filters( 'jpcrm_new_contact_log', $note_long_description, $source_key, $uid );
+ }
- #} Add log
- $newLogID = zeroBS_addUpdateContactLog($zbsNoteAgainstPostID,-1,-1,array(
- 'type' => 'Created',
+ #} Add log
+ $newLogID = zeroBS_addUpdateContactLog(
+ $zbsNoteAgainstPostID,
+ -1,
+ -1,
+ array(
+ 'type' => 'Created',
'shortdesc' => $noteShortDesc,
- 'longdesc' => $note_long_description
- ));
-
- } # / end of if no override
+ 'longdesc' => $note_long_description,
+ )
+ );
- }
+ } # / end of if no override
}
-
-
}
+}
#} Adds a "created" log to users (if setting)
- function zeroBSCRM_IA_NewCompanyLog($obj=array()){
-
- # if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_company_new');
-
- if ($autoLogThis > 0){
-
- #} Retrieve necessary info:
- $zbsNoteAgainstPostID = -1; if (is_array($obj) && isset($obj['id'])) $zbsNoteAgainstPostID = (int)$obj['id'];
- if (isset($zbsNoteAgainstPostID) && !empty($zbsNoteAgainstPostID)){
+function zeroBSCRM_IA_NewCompanyLog( $obj = array() ) {
- #} First check if an override is passed...
- if (isset($obj['automatorpassthrough']) && is_array($obj['automatorpassthrough']) && isset($obj['automatorpassthrough']['note_override']) && is_array($obj['automatorpassthrough']['note_override']) && isset($obj['automatorpassthrough']['note_override']['type'])){
+ # if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_company_new' );
- #} An overriding note has been passed, just use that
+ if ( $autoLogThis > 0 ) {
- #} Add log
- $newLogID = zeroBS_addUpdateLog($zbsNoteAgainstPostID,-1,-1,$obj['automatorpassthrough']['note_override'],'zerobs_company');
-
- } else {
-
- #} No override, use default processing...
-
-
-
- #} Set Deets
- $newCompanyName = ''; if (is_array($obj) && isset($obj['id']) && isset($obj['companyMeta']) && is_array($obj['companyMeta'])) $newCompanyName = zeroBS_companyName($obj['id'],$obj['companyMeta'],false,true);
- $noteShortDesc = 'Company Created'; if (!empty($newCompanyName)) $noteShortDesc = $newCompanyName;
- $note_long_description = '';
-
- // Custom short desc for external source creations
- if (isset($obj['extsource']) && !empty($obj['extsource'])){
-
- // We seem to pass either the external source array (woo)
- // ... or a string 'pay', so lets select the right one...
- if ( is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) ){
-
- $source_key = $obj['extsource']['source'];
+ #} Retrieve necessary info:
+ $zbsNoteAgainstPostID = -1;
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $zbsNoteAgainstPostID = (int) $obj['id'];
+ }
+ if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) {
- // if we have this we also have UID
- $uid = $obj['extsource']['uid'];
+ #} First check if an override is passed...
+ if ( isset( $obj['automatorpassthrough'] ) && is_array( $obj['automatorpassthrough'] ) && isset( $obj['automatorpassthrough']['note_override'] ) && is_array( $obj['automatorpassthrough']['note_override'] ) && isset( $obj['automatorpassthrough']['note_override']['type'] ) ) {
- } else {
- $source_key = $obj['extsource'];
- }
+ #} An overriding note has been passed, just use that
- switch ( $source_key ){
+ #} Add log
+ $newLogID = zeroBS_addUpdateLog( $zbsNoteAgainstPostID, -1, -1, $obj['automatorpassthrough']['note_override'], 'zerobs_company' );
- case 'pay':
+ } else {
- $note_long_description = 'Created from PayPal
';
+ #} No override, use default processing...
- break;
+ #} Set Deets
+ $newCompanyName = '';
+ if ( is_array( $obj ) && isset( $obj['id'] ) && isset( $obj['companyMeta'] ) && is_array( $obj['companyMeta'] ) ) {
+ $newCompanyName = zeroBS_companyName( $obj['id'], $obj['companyMeta'], false, true );
+ }
+ $noteShortDesc = 'Company Created';
+ if ( ! empty( $newCompanyName ) ) {
+ $noteShortDesc = $newCompanyName;
+ }
+ $note_long_description = '';
- case 'woo':
+ // Custom short desc for external source creations
+ if ( isset( $obj['extsource'] ) && ! empty( $obj['extsource'] ) ) {
- if ( isset( $uid ) ){
- $note_long_description = sprintf( __( 'Created from WooCommerce Order #%s', 'zero-bs-crm' ), $uid ) . '
';
- } else {
- $note_long_description = __( 'Created from WooCommerce Order', 'zero-bs-crm' ) . '
';
- }
+ // We seem to pass either the external source array (woo)
+ // ... or a string 'pay', so lets select the right one...
+ if ( is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) ) {
- break;
+ $source_key = $obj['extsource']['source'];
- case 'env':
+ // if we have this we also have UID
+ $uid = $obj['extsource']['uid'];
- $note_long_description = 'Created from Envato
';
+ } else {
+ $source_key = $obj['extsource'];
+ }
- break;
+ switch ( $source_key ) {
- case 'form':
+ case 'pay':
+ $note_long_description = 'Created from PayPal
';
- $note_long_description = 'Created from Form Capture
';
+ break;
- break;
+ case 'woo':
+ if ( isset( $uid ) ) {
+ $note_long_description = sprintf( __( 'Created from WooCommerce Order #%s', 'zero-bs-crm' ), $uid ) . '
';
+ } else {
+ $note_long_description = __( 'Created from WooCommerce Order', 'zero-bs-crm' ) . '
';
+ }
- case 'csv':
+ break;
- $note_long_description = 'Created from CSV Import
';
+ case 'env':
+ $note_long_description = 'Created from Envato
';
- break;
+ break;
- default:
+ case 'form':
+ $note_long_description = 'Created from Form Capture
';
- #} Generic for now (SHOULD NEVER CALL)
- $note_long_description = 'Created from External Source
';
+ break;
- break;
+ case 'csv':
+ $note_long_description = 'Created from CSV Import
';
- }
+ break;
+ default:
+ #} Generic for now (SHOULD NEVER CALL)
+ $note_long_description = 'Created from External Source
';
- }
+ break;
+ }
+ }
- #} Add log
- $newLogID = zeroBS_addUpdateLog($zbsNoteAgainstPostID,-1,-1,array(
- 'type' => 'Created',
+ #} Add log
+ $newLogID = zeroBS_addUpdateLog(
+ $zbsNoteAgainstPostID,
+ -1,
+ -1,
+ array(
+ 'type' => 'Created',
'shortdesc' => $noteShortDesc,
- 'longdesc' => $note_long_description
- ),'zerobs_company');
+ 'longdesc' => $note_long_description,
+ ),
+ 'zerobs_company'
+ );
- } # / end of if no override
-
- }
+ } # / end of if no override
}
-
-
}
+}
#} Adds a "created" log to customer (of quotes) (if setting)
- function zeroBSCRM_IA_NewQuoteLog($obj=array()){
-
-
- # if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_quote_new');
-
- if ($autoLogThis > 0){
+function zeroBSCRM_IA_NewQuoteLog( $obj = array() ) {
- // 3.0+
- #} Retrieve necessary info:
- $noteAgainstIDs = array('contacts'=>array(),'companies'=>array());
- if (is_array($obj) && isset($obj['againstids']) && is_array($obj['againstids'])){
+ # if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_quote_new' );
- // trusting they're correctly passed...
- if (isset($obj['againstids']['contacts']) && is_array($obj['againstids']['contacts'])) $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
- if (isset($obj['againstids']['companies']) && is_array($obj['againstids']['companies'])) $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
+ if ( $autoLogThis > 0 ) {
+ // 3.0+
+ #} Retrieve necessary info:
+ $noteAgainstIDs = array(
+ 'contacts' => array(),
+ 'companies' => array(),
+ );
+ if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) {
+
+ // trusting they're correctly passed...
+ if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) {
+ $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
}
- $quoteID = ''; if (is_array($obj) && isset($obj['id'])) $quoteID = $obj['id'];
- $quoteTitle = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['title']) && !empty($obj['data']['title'])) $quoteTitle = $obj['data']['title'];
- $quoteValue = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['value']) && !empty($obj['data']['value'])) $quoteValue = zeroBSCRM_formatCurrency($obj['data']['value']);
- $extsource = ''; if (is_array($obj) && is_array($obj['extsource']) && isset($obj['extsource']['source']) && !empty($obj['extsource']['source'])) $extsource = $obj['extsource']['source'];
- $extsourceID = ''; if (is_array($obj) && is_array($obj['extsource']) && isset($obj['extsource']['uid']) && !empty($obj['extsource']['uid'])) $extsourceID = $obj['extsource']['uid'];
-
- // build str
- $note_long_description = '';
- $noteShortDesc = '';
- if (!empty($quoteID)) $noteShortDesc .= '#'.$quoteID;
- if (!empty($quoteTitle)) $noteShortDesc .= $quoteTitle;
- if (!empty($quoteValue)) $noteShortDesc .= ' ('.$quoteValue.')';
- if (!empty($extsource) && !empty($extsourceID)) $note_long_description = __('Created by','zero-bs-crm').' '.zeroBS_getExternalSourceTitle($extsource,$extsourceID);
+ if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) {
+ $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
+ }
+ }
+ $quoteID = '';
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $quoteID = $obj['id'];
+ }
+ $quoteTitle = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['title'] ) && ! empty( $obj['data']['title'] ) ) {
+ $quoteTitle = $obj['data']['title'];
+ }
+ $quoteValue = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['value'] ) && ! empty( $obj['data']['value'] ) ) {
+ $quoteValue = zeroBSCRM_formatCurrency( $obj['data']['value'] );
+ }
+ $extsource = '';
+ if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) && ! empty( $obj['extsource']['source'] ) ) {
+ $extsource = $obj['extsource']['source'];
+ }
+ $extsourceID = '';
+ if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['uid'] ) && ! empty( $obj['extsource']['uid'] ) ) {
+ $extsourceID = $obj['extsource']['uid'];
+ }
- if (is_array($noteAgainstIDs['contacts']) && count($noteAgainstIDs['contacts']) > 0) foreach ($noteAgainstIDs['contacts'] as $cID){
+ // build str
+ $note_long_description = '';
+ $noteShortDesc = '';
+ if ( ! empty( $quoteID ) ) {
+ $noteShortDesc .= '#' . $quoteID;
+ }
+ if ( ! empty( $quoteTitle ) ) {
+ $noteShortDesc .= $quoteTitle;
+ }
+ if ( ! empty( $quoteValue ) ) {
+ $noteShortDesc .= ' (' . $quoteValue . ')';
+ }
+ if ( ! empty( $extsource ) && ! empty( $extsourceID ) ) {
+ $note_long_description = __( 'Created by', 'zero-bs-crm' ) . ' ' . zeroBS_getExternalSourceTitle( $extsource, $extsourceID );
+ }
+
+ if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) {
+ foreach ( $noteAgainstIDs['contacts'] as $cID ) {
#} Add log
- $newLogID = zeroBS_addUpdateLog($cID,-1,-1,array(
- 'type' => __('Quote Created','zero-bs-crm'),
- 'shortdesc' => $noteShortDesc,
- 'longdesc' => $note_long_description
- ),'zerobs_customer');
+ $newLogID = zeroBS_addUpdateLog(
+ $cID,
+ -1,
+ -1,
+ array(
+ 'type' => __( 'Quote Created', 'zero-bs-crm' ),
+ 'shortdesc' => $noteShortDesc,
+ 'longdesc' => $note_long_description,
+ ),
+ 'zerobs_customer'
+ );
}
-
- }
-
-
+ }
}
+}
// Adds an "accepted" log to contact (of quote) (if setting)
- function zeroBSCRM_IA_AcceptedQuoteLog($obj=array()){
+function zeroBSCRM_IA_AcceptedQuoteLog( $obj = array() ) {
+ # if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_quote_accepted' );
- # if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_quote_accepted');
+ if ( $autoLogThis > 0 ) {
- if ($autoLogThis > 0){
+ global $zbs;
- global $zbs;
-
- // retrieve quote
- $quoteID = ''; if (is_array($obj) && isset($obj['id'])) $quoteID = $obj['id'];
- $quote = $zbs->DAL->quotes->getQuote($quoteID);
+ // retrieve quote
+ $quoteID = '';
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $quoteID = $obj['id'];
+ }
+ $quote = $zbs->DAL->quotes->getQuote( $quoteID );
- if ( is_array($quote) && count($quote['contact']) > 0 ){
+ if ( is_array( $quote ) && count( $quote['contact'] ) > 0 ) {
- // get signed by if passed
- $signedBy = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['signed']) && !empty($obj['data']['signed'])) $signedBy = $obj['data']['signed'];
- // could get `ip` but not really user friendly/needed
+ // get signed by if passed
+ $signedBy = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['signed'] ) && ! empty( $obj['data']['signed'] ) ) {
+ $signedBy = $obj['data']['signed'];
+ }
+ // could get `ip` but not really user friendly/needed
- // build str
- $note_long_description = '';
- $noteShortDesc = '';
- if (!empty($quoteID)) $noteShortDesc .= '#'.$quoteID;
- if (!empty($quoteTitle)) $noteShortDesc .= $quote['title'];
- if (!empty($quoteValue)) $noteShortDesc .= ' ('.zeroBSCRM_formatCurrency($quote['value']).')';
- if (!empty($signedBy)) $note_long_description = __('Signed','zero-bs-crm').' '.$signedBy;
+ // build str
+ $note_long_description = '';
+ $noteShortDesc = '';
+ if ( ! empty( $quoteID ) ) {
+ $noteShortDesc .= '#' . $quoteID;
+ }
+ if ( ! empty( $quoteTitle ) ) {
+ $noteShortDesc .= $quote['title'];
+ }
+ if ( ! empty( $quoteValue ) ) {
+ $noteShortDesc .= ' (' . zeroBSCRM_formatCurrency( $quote['value'] ) . ')';
+ }
+ if ( ! empty( $signedBy ) ) {
+ $note_long_description = __( 'Signed', 'zero-bs-crm' ) . ' ' . $signedBy;
+ }
- if (is_array($quote['contact'])) foreach ($quote['contact'] as $contact){
+ if ( is_array( $quote['contact'] ) ) {
+ foreach ( $quote['contact'] as $contact ) {
- #} Add log
- $newLogID = zeroBS_addUpdateLog($contact['id'],-1,-1,array(
- 'type' => __('Quote: Accepted','zero-bs-crm'),
+ #} Add log
+ $newLogID = zeroBS_addUpdateLog(
+ $contact['id'],
+ -1,
+ -1,
+ array(
+ 'type' => __( 'Quote: Accepted', 'zero-bs-crm' ),
'shortdesc' => $noteShortDesc,
- 'longdesc' => $note_long_description
- ),'zerobs_customer');
-
- }
+ 'longdesc' => $note_long_description,
+ ),
+ 'zerobs_customer'
+ );
}
-
+ }
}
-
-
}
-
+}
#} Adds a "created" log to customer (of quotes) (if setting)
- function zeroBSCRM_IA_NewInvoiceLog($obj=array()){
+function zeroBSCRM_IA_NewInvoiceLog( $obj = array() ) {
- # if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_invoice_new');
+ # if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_invoice_new' );
- if ($autoLogThis > 0){
-
- #} Retrieve necessary info:
- $noteAgainstIDs = array('contacts'=>array(),'companies'=>array());
- if (is_array($obj) && isset($obj['againstids']) && is_array($obj['againstids'])){
-
- // trusting they're correctly passed...
- if (isset($obj['againstids']['contacts']) && is_array($obj['againstids']['contacts'])) $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
- if (isset($obj['againstids']['companies']) && is_array($obj['againstids']['companies'])) $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
+ if ( $autoLogThis > 0 ) {
+ #} Retrieve necessary info:
+ $noteAgainstIDs = array(
+ 'contacts' => array(),
+ 'companies' => array(),
+ );
+ if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) {
+
+ // trusting they're correctly passed...
+ if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) {
+ $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
}
- $invoiceID = ''; if (is_array($obj) && isset($obj['id'])) $invoiceID = $obj['id'];
- $invoiceRef = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['id_override']) && !empty($obj['data']['id_override'])) $invoiceRef = $obj['data']['id_override'];
- $invoiceValue = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['total']) && !empty($obj['data']['total'])) $invoiceValue = zeroBSCRM_formatCurrency($obj['data']['total']);
- $extsource = ''; if (is_array($obj) && is_array($obj['extsource']) && isset($obj['extsource']['source']) && !empty($obj['extsource']['source'])) $extsource = $obj['extsource']['source'];
- $extsourceID = ''; if (is_array($obj) && is_array($obj['extsource']) && isset($obj['extsource']['uid']) && !empty($obj['extsource']['uid'])) $extsourceID = $obj['extsource']['uid'];
-
- // build str
- $note_long_description = '';
- $noteShortDesc = '';
- if (!empty($invoiceID) && empty($invoiceRef)) $noteShortDesc .= '#'.$invoiceID;
- if (!empty($invoiceRef)) $noteShortDesc .= $invoiceRef;
- if (!empty($invoiceValue)) $noteShortDesc .= ' ('.$invoiceValue.')';
- if (!empty($extsource) && !empty($extsourceID)) $note_long_description = __('Created by','zero-bs-crm').' '.zeroBS_getExternalSourceTitle($extsource,$extsourceID);
+ if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) {
+ $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
+ }
+ }
+ $invoiceID = '';
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $invoiceID = $obj['id'];
+ }
+ $invoiceRef = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['id_override'] ) && ! empty( $obj['data']['id_override'] ) ) {
+ $invoiceRef = $obj['data']['id_override'];
+ }
+ $invoiceValue = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['total'] ) && ! empty( $obj['data']['total'] ) ) {
+ $invoiceValue = zeroBSCRM_formatCurrency( $obj['data']['total'] );
+ }
+ $extsource = '';
+ if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) && ! empty( $obj['extsource']['source'] ) ) {
+ $extsource = $obj['extsource']['source'];
+ }
+ $extsourceID = '';
+ if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['uid'] ) && ! empty( $obj['extsource']['uid'] ) ) {
+ $extsourceID = $obj['extsource']['uid'];
+ }
+
+ // build str
+ $note_long_description = '';
+ $noteShortDesc = '';
+ if ( ! empty( $invoiceID ) && empty( $invoiceRef ) ) {
+ $noteShortDesc .= '#' . $invoiceID;
+ }
+ if ( ! empty( $invoiceRef ) ) {
+ $noteShortDesc .= $invoiceRef;
+ }
+ if ( ! empty( $invoiceValue ) ) {
+ $noteShortDesc .= ' (' . $invoiceValue . ')';
+ }
+ if ( ! empty( $extsource ) && ! empty( $extsourceID ) ) {
+ $note_long_description = __( 'Created by', 'zero-bs-crm' ) . ' ' . zeroBS_getExternalSourceTitle( $extsource, $extsourceID );
+ }
- if (is_array($noteAgainstIDs['contacts']) && count($noteAgainstIDs['contacts']) > 0) foreach ($noteAgainstIDs['contacts'] as $cID){
+ if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) {
+ foreach ( $noteAgainstIDs['contacts'] as $cID ) {
#} Add log
- $newLogID = zeroBS_addUpdateLog($cID,-1,-1,array(
- 'type' => __('Invoice Created','zero-bs-crm'),
- 'shortdesc' => $noteShortDesc,
- 'longdesc' => $note_long_description
- ),'zerobs_customer');
+ $newLogID = zeroBS_addUpdateLog(
+ $cID,
+ -1,
+ -1,
+ array(
+ 'type' => __( 'Invoice Created', 'zero-bs-crm' ),
+ 'shortdesc' => $noteShortDesc,
+ 'longdesc' => $note_long_description,
+ ),
+ 'zerobs_customer'
+ );
}
-
- }
-
+ }
}
+}
#} Adds a "created" log to customer (of trans) (if setting)
- function zeroBSCRM_IA_NewTransactionLog($obj=array()){
-
- $newLogID = false;
-
- #} if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_transaction_new');
+function zeroBSCRM_IA_NewTransactionLog( $obj = array() ) {
- if ($autoLogThis > 0){
+ $newLogID = false;
- #} Retrieve necessary info:
- $noteAgainstIDs = array('contacts'=>array(),'companies'=>array());
- if (is_array($obj) && isset($obj['againstids']) && is_array($obj['againstids'])){
+ #} if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_transaction_new' );
- // trusting they're correctly passed...
- if (isset($obj['againstids']['contacts']) && is_array($obj['againstids']['contacts'])) $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
- if (isset($obj['againstids']['companies']) && is_array($obj['againstids']['companies'])) $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
+ if ( $autoLogThis > 0 ) {
+ #} Retrieve necessary info:
+ $noteAgainstIDs = array(
+ 'contacts' => array(),
+ 'companies' => array(),
+ );
+ if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) {
+
+ // trusting they're correctly passed...
+ if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) {
+ $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
}
- $transactionID = ''; if (is_array($obj) && isset($obj['id'])) $transactionID = $obj['id'];
- $transactionRef = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['ref']) && !empty($obj['data']['ref'])) $transactionRef = $obj['data']['ref'];
- $transactionValue = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['total']) && !empty($obj['data']['total'])) $transactionValue = zeroBSCRM_formatCurrency($obj['data']['total']);
- $extsource = ''; if (is_array($obj) && is_array($obj['extsource']) && isset($obj['extsource']['source']) && !empty($obj['extsource']['source'])) $extsource = $obj['extsource']['source'];
- $extsourceID = ''; if (is_array($obj) && is_array($obj['extsource']) && isset($obj['extsource']['uid']) && !empty($obj['extsource']['uid'])) $extsourceID = $obj['extsource']['uid'];
-
- // build str
- $note_long_description = '';
- $noteShortDesc = '';
- if (!empty($transactionID) && empty($transactionRef)) $noteShortDesc .= '#'.$transactionID;
- if (!empty($transactionRef)) $noteShortDesc .= $transactionRef;
- if (!empty($transactionValue)) $noteShortDesc .= ' ('.$transactionValue.')';
- if (!empty($extsource) && !empty($extsourceID)) $note_long_description = __('Created by','zero-bs-crm').' '.zeroBS_getExternalSourceTitle($extsource,$extsourceID);
+ if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) {
+ $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
+ }
+ }
+ $transactionID = '';
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $transactionID = $obj['id'];
+ }
+ $transactionRef = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['ref'] ) && ! empty( $obj['data']['ref'] ) ) {
+ $transactionRef = $obj['data']['ref'];
+ }
+ $transactionValue = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['total'] ) && ! empty( $obj['data']['total'] ) ) {
+ $transactionValue = zeroBSCRM_formatCurrency( $obj['data']['total'] );
+ }
+ $extsource = '';
+ if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) && ! empty( $obj['extsource']['source'] ) ) {
+ $extsource = $obj['extsource']['source'];
+ }
+ $extsourceID = '';
+ if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['uid'] ) && ! empty( $obj['extsource']['uid'] ) ) {
+ $extsourceID = $obj['extsource']['uid'];
+ }
+
+ // build str
+ $note_long_description = '';
+ $noteShortDesc = '';
+ if ( ! empty( $transactionID ) && empty( $transactionRef ) ) {
+ $noteShortDesc .= '#' . $transactionID;
+ }
+ if ( ! empty( $transactionRef ) ) {
+ $noteShortDesc .= $transactionRef;
+ }
+ if ( ! empty( $transactionValue ) ) {
+ $noteShortDesc .= ' (' . $transactionValue . ')';
+ }
+ if ( ! empty( $extsource ) && ! empty( $extsourceID ) ) {
+ $note_long_description = __( 'Created by', 'zero-bs-crm' ) . ' ' . zeroBS_getExternalSourceTitle( $extsource, $extsourceID );
+ }
- if (is_array($noteAgainstIDs['contacts']) && count($noteAgainstIDs['contacts']) > 0) foreach ($noteAgainstIDs['contacts'] as $cID){
+ if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) {
+ foreach ( $noteAgainstIDs['contacts'] as $cID ) {
#} Add log
- $newLogID = zeroBS_addUpdateLog($cID,-1,-1,array(
- 'type' => __('Transaction Created','zero-bs-crm'),
- 'shortdesc' => $noteShortDesc,
- 'longdesc' => $note_long_description
- ),'zerobs_customer');
+ $newLogID = zeroBS_addUpdateLog(
+ $cID,
+ -1,
+ -1,
+ array(
+ 'type' => __( 'Transaction Created', 'zero-bs-crm' ),
+ 'shortdesc' => $noteShortDesc,
+ 'longdesc' => $note_long_description,
+ ),
+ 'zerobs_customer'
+ );
}
+ }
+ } // / if autolog
- } // / if autolog
-
-
- return $newLogID;
-
- }
+ return $newLogID;
+}
#} Adds a "created" log to customer (of task) (if setting)
- function zeroBSCRM_IA_NewEventLog($obj=array()){
-
- $newLogID = false;
+function zeroBSCRM_IA_NewEventLog( $obj = array() ) {
- #} if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_event_new');
+ $newLogID = false;
- #} if has id
- $zbsNoteAgainstPostID = -1; if (is_array($obj) && isset($obj['againstid']) && $obj['againstid'] > 0) $zbsNoteAgainstPostID = (int)$obj['againstid'];
+ #} if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_event_new' );
- if ($autoLogThis > 0 && isset($zbsNoteAgainstPostID) && !empty($zbsNoteAgainstPostID)){
-
- #} Retrieve necessary info:
- $noteAgainstIDs = array('contacts'=>array(),'companies'=>array());
- if (is_array($obj) && isset($obj['againstids']) && is_array($obj['againstids'])){
+ #} if has id
+ $zbsNoteAgainstPostID = -1;
+ if ( is_array( $obj ) && isset( $obj['againstid'] ) && $obj['againstid'] > 0 ) {
+ $zbsNoteAgainstPostID = (int) $obj['againstid'];
+ }
- // trusting they're correctly passed...
- if (isset($obj['againstids']['contacts']) && is_array($obj['againstids']['contacts'])) $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
- if (isset($obj['againstids']['companies']) && is_array($obj['againstids']['companies'])) $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
+ if ( $autoLogThis > 0 && isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) {
+ #} Retrieve necessary info:
+ $noteAgainstIDs = array(
+ 'contacts' => array(),
+ 'companies' => array(),
+ );
+ if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) {
+
+ // trusting they're correctly passed...
+ if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) {
+ $noteAgainstIDs['contacts'] = $obj['againstids']['contacts'];
+ }
+ if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) {
+ $noteAgainstIDs['companies'] = $obj['againstids']['companies'];
}
- $taskID = ''; if (is_array($obj) && isset($obj['id'])) $taskID = $obj['id'];
- $taskTitle = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['title']) && !empty($obj['data']['title'])) $taskTitle = $obj['data']['title'];
- $taskDescription = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['desc']) && !empty($obj['data']['desc'])) $taskDescription = $obj['data']['desc'];
- $taskStart = ''; if (is_array($obj) && is_array($obj['data']) && isset($obj['data']['start']) && !empty($obj['data']['start'])) $taskStart = zeroBSCRM_locale_utsToDatetime($obj['data']['start']);
+ }
+ $taskID = '';
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $taskID = $obj['id'];
+ }
+ $taskTitle = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['title'] ) && ! empty( $obj['data']['title'] ) ) {
+ $taskTitle = $obj['data']['title'];
+ }
+ $taskDescription = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['desc'] ) && ! empty( $obj['data']['desc'] ) ) {
+ $taskDescription = $obj['data']['desc'];
+ }
+ $taskStart = '';
+ if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['start'] ) && ! empty( $obj['data']['start'] ) ) {
+ $taskStart = zeroBSCRM_locale_utsToDatetime( $obj['data']['start'] );
+ }
- // build str
- $note_long_description = '';
- $noteShortDesc = '';
- if (!empty($taskID) && empty($taskTitle)) $noteShortDesc .= '#'.$taskID;
- if (!empty($taskTitle)) $noteShortDesc .= $taskTitle;
- if (!empty($taskDescription)) $note_long_description = $taskDescription;
- if (!empty($taskStart)) {
+ // build str
+ $note_long_description = '';
+ $noteShortDesc = '';
+ if ( ! empty( $taskID ) && empty( $taskTitle ) ) {
+ $noteShortDesc .= '#' . $taskID;
+ }
+ if ( ! empty( $taskTitle ) ) {
+ $noteShortDesc .= $taskTitle;
+ }
+ if ( ! empty( $taskDescription ) ) {
+ $note_long_description = $taskDescription;
+ }
+ if ( ! empty( $taskStart ) ) {
- // pad if filled
- if (!empty($note_long_description)) $note_long_description .= '
';
+ // pad if filled
+ if ( ! empty( $note_long_description ) ) {
+ $note_long_description .= '
';
+ }
- // add starting date
- $note_long_description .= __('Starts at ','zero-bs-crm').' '.$taskStart;
+ // add starting date
+ $note_long_description .= __( 'Starts at ', 'zero-bs-crm' ) . ' ' . $taskStart;
- }
+ }
- if (is_array($noteAgainstIDs['contacts']) && count($noteAgainstIDs['contacts']) > 0) foreach ($noteAgainstIDs['contacts'] as $cID){
+ if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) {
+ foreach ( $noteAgainstIDs['contacts'] as $cID ) {
#} Add log
- $newLogID = zeroBS_addUpdateLog($cID,-1,-1,array(
- 'type' => __('Task Created','zero-bs-crm'),
- 'shortdesc' => $noteShortDesc,
- 'longdesc' => $note_long_description
- ),'zerobs_customer');
+ $newLogID = zeroBS_addUpdateLog(
+ $cID,
+ -1,
+ -1,
+ array(
+ 'type' => __( 'Task Created', 'zero-bs-crm' ),
+ 'shortdesc' => $noteShortDesc,
+ 'longdesc' => $note_long_description,
+ ),
+ 'zerobs_customer'
+ );
}
+ }
+ }
- }
-
-
- return $newLogID;
-
- }
+ return $newLogID;
+}
/**
* Catches new logs and updates contact 'last contacted' if contact type log
@@ -642,143 +792,166 @@ function zeroBSCRM_IA_NewLogCatchContactsDB2( $obj = array() ) {
} // is log against contact
}
-
#} Adds a "created" log to customer (if setting)
- function zeroBSCRM_IA_NewClientPortalUserLog($obj=array()){
-
+function zeroBSCRM_IA_NewClientPortalUserLog( $obj = array() ) {
- # if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_clientportal_new');
+ # if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_clientportal_new' );
- if ($autoLogThis > 0){
+ if ( $autoLogThis > 0 ) {
- #} Retrieve necessary info:
- $zbsNoteAgainstPostID = -1; if (is_array($obj) && isset($obj['againstid']) && $obj['againstid'] > 0) $zbsNoteAgainstPostID = (int)$obj['againstid'];
- #TRANSITIONTOMETANO
- $userID = -1; if (is_array($obj) && isset($obj['id']) && $obj['id'] > 0) $userID = (int)$obj['id'];
- $userEmail = ''; if (is_array($obj) && isset($obj['userEmail'])) $userEmail = $obj['userEmail'];
- $noteShortDesc = ''; if (!empty($userEmail)) $noteShortDesc = __('Created with email',"zero-bs-crm").': '.$userEmail;
+ #} Retrieve necessary info:
+ $zbsNoteAgainstPostID = -1;
+ if ( is_array( $obj ) && isset( $obj['againstid'] ) && $obj['againstid'] > 0 ) {
+ $zbsNoteAgainstPostID = (int) $obj['againstid'];
+ }
+ #TRANSITIONTOMETANO
+ $userID = -1;
+ if ( is_array( $obj ) && isset( $obj['id'] ) && $obj['id'] > 0 ) {
+ $userID = (int) $obj['id'];
+ }
+ $userEmail = '';
+ if ( is_array( $obj ) && isset( $obj['userEmail'] ) ) {
+ $userEmail = $obj['userEmail'];
+ }
+ $noteShortDesc = '';
+ if ( ! empty( $userEmail ) ) {
+ $noteShortDesc = __( 'Created with email', 'zero-bs-crm' ) . ': ' . $userEmail;
+ }
- if ($userID > 0) $noteShortDesc .= ' (#'.$userID.')';
+ if ( $userID > 0 ) {
+ $noteShortDesc .= ' (#' . $userID . ')';
+ }
- if (isset($zbsNoteAgainstPostID) && !empty($zbsNoteAgainstPostID)){
+ if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) {
- #} Add log
- $newLogID = zeroBS_addUpdateContactLog($zbsNoteAgainstPostID,-1,-1,array(
- 'type' => 'Client Portal User Created',
+ #} Add log
+ $newLogID = zeroBS_addUpdateContactLog(
+ $zbsNoteAgainstPostID,
+ -1,
+ -1,
+ array(
+ 'type' => 'Client Portal User Created',
'shortdesc' => $noteShortDesc,
- 'longdesc' => ''
- ));
-
- }
+ 'longdesc' => '',
+ )
+ );
}
-
}
-
+}
#} creates customer client portal user (if setting)
- function zeroBSCRM_IA_NewCustomerClientPortal($obj=array()){
-
- # if setting
- $autoFireThis = zeroBSCRM_getSetting('portalusers');
-
- if ($autoFireThis > 0){
-
- #} Retrieve necessary info:
- $userID = -1; if (is_array($obj) && isset($obj['id']) && $obj['id'] > 0) $userID = (int)$obj['id'];
+function zeroBSCRM_IA_NewCustomerClientPortal( $obj = array() ) {
- // yup
- $okayToFire = true;
+ # if setting
+ $autoFireThis = zeroBSCRM_getSetting( 'portalusers' );
+ if ( $autoFireThis > 0 ) {
- // Specific status mode ==================================
-
- #} If using "specific statuses only"
- $statusList = zeroBSCRM_getSetting('portalusers_status');
- if (!is_array($statusList) && (empty($statusList) || $statusList == 'all')){
-
- // nothing to do
-
- } else {
-
- if (is_array($statusList)){
-
- // generate a list of "Okay" statuses that this'll check later on...
- $zbsStatusStr = zeroBSCRM_getCustomerStatuses();
- $zbsStatuses = explode(',', $zbsStatusStr);
- $okayStatuses = array();
+ #} Retrieve necessary info:
+ $userID = -1;
+ if ( is_array( $obj ) && isset( $obj['id'] ) && $obj['id'] > 0 ) {
+ $userID = (int) $obj['id'];
+ }
- // cycle through settings + copy "full str" rather than "full_str" that it'll be saved as
- foreach ($zbsStatuses as $statusStr){
+ // yup
+ $okayToFire = true;
- // permify
- $statusKey = strtolower(str_replace(' ','_',str_replace(':','_',$statusStr)));
+ // Specific status mode ==================================
- // present?
- if (in_array($statusKey, $statusList)) $okayStatuses[] = $statusStr;
+ #} If using "specific statuses only"
+ $statusList = zeroBSCRM_getSetting( 'portalusers_status' );
+ if ( ! is_array( $statusList ) && ( empty( $statusList ) || $statusList == 'all' ) ) {
- }
+ // nothing to do
- // is user's status in one of these?
- $customerStatus = ''; if (isset($obj['customerMeta']) && is_array($obj['customerMeta']) && isset($obj['customerMeta']['status'])) $customerStatus = $obj['customerMeta']['status'];
+ } elseif ( is_array( $statusList ) ) {
- // if no status, try fill from (whatever was added) to db
- if (empty($customerStatus)){
+ // generate a list of "Okay" statuses that this'll check later on...
+ $zbsStatusStr = zeroBSCRM_getCustomerStatuses();
+ $zbsStatuses = explode( ',', $zbsStatusStr );
+ $okayStatuses = array();
- $cMeta = zeroBS_getCustomerMeta($userID);
+ // cycle through settings + copy "full str" rather than "full_str" that it'll be saved as
+ foreach ( $zbsStatuses as $statusStr ) {
- if (is_array($cMeta) && isset($cMeta['status'])) $customerStatus = $cMeta['status'];
+ // permify
+ $statusKey = strtolower( str_replace( ' ', '_', str_replace( ':', '_', $statusStr ) ) );
- }
+ // present?
+ if ( in_array( $statusKey, $statusList ) ) {
+ $okayStatuses[] = $statusStr;
+ }
+ }
- // check status
- if (!empty($customerStatus) && in_array($customerStatus,$okayStatuses))
- $okayToFire = true;
- else
- $okayToFire = false; // customer status empty or not in approved list :)
+ // is user's status in one of these?
+ $customerStatus = '';
+ if ( isset( $obj['customerMeta'] ) && is_array( $obj['customerMeta'] ) && isset( $obj['customerMeta']['status'] ) ) {
+ $customerStatus = $obj['customerMeta']['status'];
+ }
- } else {
+ // if no status, try fill from (whatever was added) to db
+ if ( empty( $customerStatus ) ) {
- // non-standard val for status list, override it to all
- global $zbs;
- $zbs->settings->update('portalusers_status','all');
+ $cMeta = zeroBS_getCustomerMeta( $userID );
- // and let it fire..
+ if ( is_array( $cMeta ) && isset( $cMeta['status'] ) ) {
+ $customerStatus = $cMeta['status'];
}
+ }
+ // check status
+ if ( ! empty( $customerStatus ) && in_array( $customerStatus, $okayStatuses ) ) {
+ $okayToFire = true;
+ } else {
+ $okayToFire = false; // customer status empty or not in approved list :)
}
+ } else {
+
+ // non-standard val for status list, override it to all
+ global $zbs;
+ $zbs->settings->update( 'portalusers_status', 'all' );
- // / Specific status mode ==================================
+ // and let it fire..
- if ($okayToFire){
+ }
- // this'll check itself if already exists, so no harm in letting it (potentially) multifire
- if ($userID > 0) zeroBSCRM_createClientPortalUserFromRecord($userID);
+ // / Specific status mode ==================================
- }
+ if ( $okayToFire ) {
+ // this'll check itself if already exists, so no harm in letting it (potentially) multifire
+ if ( $userID > 0 ) {
+ zeroBSCRM_createClientPortalUserFromRecord( $userID );
+ }
}
-
}
+}
#} Compiles any segments which this contact fits in
// works for new contacts + contact edits
- function zeroBSCRM_IA_ContactSegmentCompiler($obj=array()){
+function zeroBSCRM_IA_ContactSegmentCompiler( $obj = array() ) {
- # if setting
- $autoCompileSegments = 1;
+ # if setting
+ $autoCompileSegments = 1;
- if ($autoCompileSegments > 0){
+ if ( $autoCompileSegments > 0 ) {
- #} Retrieve necessary info:
- $zbsNoteAgainstPostID = -1; if (is_array($obj) && isset($obj['id'])) $zbsNoteAgainstPostID = (int)$obj['id'];
- $contactWasInSegments = array(); if (is_array($obj) && isset($obj['prevSegments']) && is_array($obj['prevSegments'])) $contactWasInSegments = $obj['prevSegments'];
+ #} Retrieve necessary info:
+ $zbsNoteAgainstPostID = -1;
+ if ( is_array( $obj ) && isset( $obj['id'] ) ) {
+ $zbsNoteAgainstPostID = (int) $obj['id'];
+ }
+ $contactWasInSegments = array();
+ if ( is_array( $obj ) && isset( $obj['prevSegments'] ) && is_array( $obj['prevSegments'] ) ) {
+ $contactWasInSegments = $obj['prevSegments'];
+ }
- if (isset($zbsNoteAgainstPostID) && !empty($zbsNoteAgainstPostID)){
+ if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) {
global $zbs;
- $zbs->DAL->segments->compileSegmentsAffectedByContact($zbsNoteAgainstPostID,$contactWasInSegments);
+ $zbs->DAL->segments->compileSegmentsAffectedByContact( $zbsNoteAgainstPostID, $contactWasInSegments );
}
}
}
@@ -791,7 +964,7 @@ function zeroBSCRM_IA_ContactSegmentCompiler($obj=array()){
* quote.update
*
*/
- function zeroBSCRM_IA_quoteSegmentCompiler( $obj=array() ){
+function zeroBSCRM_IA_quoteSegmentCompiler( $obj = array() ) {
global $zbs;
@@ -809,7 +982,7 @@ function zeroBSCRM_IA_quoteSegmentCompiler( $obj=array() ){
* invoice.update
*
*/
- function zeroBSCRM_IA_invoiceSegmentCompiler( $obj=array() ){
+function zeroBSCRM_IA_invoiceSegmentCompiler( $obj = array() ) {
global $zbs;
@@ -827,7 +1000,7 @@ function zeroBSCRM_IA_invoiceSegmentCompiler( $obj=array() ){
* transaction.update
*
*/
- function zeroBSCRM_IA_transactionSegmentCompiler( $obj=array() ){
+function zeroBSCRM_IA_transactionSegmentCompiler( $obj = array() ) {
global $zbs;
@@ -838,223 +1011,239 @@ function zeroBSCRM_IA_transactionSegmentCompiler( $obj=array() ){
}
#} when customer status changes, portal access can be revoked/added based on status (if setting)
- function zeroBSCRM_IA_CustomerStatusChangePortalAndLog($obj=array()){
-
- # if setting
- $autoFireThis = zeroBSCRM_getSetting('portalusers');
-
- if ($autoFireThis > 0){
-
- #} Retrieve necessary info:
- $userID = -1; if (is_array($obj) && isset($obj['id']) && $obj['id'] > 0) $userID = (int)$obj['id'];
-
-
- #} If using "specific statuses only"
- $statusList = zeroBSCRM_getSetting('portalusers_status');
- if (!is_array($statusList) && (empty($statusList) || $statusList == 'all')){
-
- // nothing to do - all statuses allowed
-
- } else {
-
- if (is_array($statusList)){
-
- // generate a list of "Okay" statuses that this'll check later on...
- $zbsStatusStr = zeroBSCRM_getCustomerStatuses();
- $zbsStatuses = explode(',', $zbsStatusStr);
- $okayStatuses = array();
-
- // cycle through settings + copy "full str" rather than "full_str" that it'll be saved as
- foreach ($zbsStatuses as $statusStr){
-
- // permify
- $statusKey = strtolower(str_replace(' ','_',str_replace(':','_',$statusStr)));
+function zeroBSCRM_IA_CustomerStatusChangePortalAndLog( $obj = array() ) {
- // present?
- if (in_array($statusKey, $statusList)) $okayStatuses[] = $statusStr;
+ # if setting
+ $autoFireThis = zeroBSCRM_getSetting( 'portalusers' );
- }
+ if ( $autoFireThis > 0 ) {
- // is user's status in one of these?
- $customerStatus = ''; if (isset($obj['customerMeta']) && is_array($obj['customerMeta']) && isset($obj['customerMeta']['status'])) $customerStatus = $obj['customerMeta']['status'];
-
- // if no status, try fill from (whatever was added) to db
- if (empty($customerStatus)){
-
- $cMeta = zeroBS_getCustomerMeta($userID);
+ #} Retrieve necessary info:
+ $userID = -1;
+ if ( is_array( $obj ) && isset( $obj['id'] ) && $obj['id'] > 0 ) {
+ $userID = (int) $obj['id'];
+ }
- if (is_array($cMeta) && isset($cMeta['status'])) $customerStatus = $cMeta['status'];
+ #} If using "specific statuses only"
+ $statusList = zeroBSCRM_getSetting( 'portalusers_status' );
+ if ( ! is_array( $statusList ) && ( empty( $statusList ) || $statusList == 'all' ) ) {
- }
+ // nothing to do - all statuses allowed
- // check status
- if (!empty($customerStatus) && in_array($customerStatus,$okayStatuses)){
-
- // NEEDS account access
+ } elseif ( is_array( $statusList ) ) {
- // already got?
- $portalID = zeroBSCRM_getClientPortalUserID($userID);
+ // generate a list of "Okay" statuses that this'll check later on...
+ $zbsStatusStr = zeroBSCRM_getCustomerStatuses();
+ $zbsStatuses = explode( ',', $zbsStatusStr );
+ $okayStatuses = array();
- if (!empty($portalID) && $portalID > 0){
-
- $isDisabled = zeroBSCRM_isCustomerPortalDisabled($userID);
+ // cycle through settings + copy "full str" rather than "full_str" that it'll be saved as
+ foreach ( $zbsStatuses as $statusStr ) {
- // if disabled
- if ($isDisabled){
+ // permify
+ $statusKey = strtolower( str_replace( ' ', '_', str_replace( ':', '_', $statusStr ) ) );
+ // present?
+ if ( in_array( $statusKey, $statusList ) ) {
+ $okayStatuses[] = $statusStr;
+ }
+ }
- // already got acc, make sure enabled
- zeroBSCRM_customerPortalDisableEnable($userID,'enable');
+ // is user's status in one of these?
+ $customerStatus = '';
+ if ( isset( $obj['customerMeta'] ) && is_array( $obj['customerMeta'] ) && isset( $obj['customerMeta']['status'] ) ) {
+ $customerStatus = $obj['customerMeta']['status'];
+ }
- $noteShortDesc = __('Access enabled (by change of status to',"zero-bs-crm").' "'.$customerStatus.'"';
+ // if no status, try fill from (whatever was added) to db
+ if ( empty( $customerStatus ) ) {
- #} Add log
- $newLogID = zeroBS_addUpdateContactLog($userID,-1,-1,array(
- 'type' => 'Client Portal Access Changed',
- 'shortdesc' => $noteShortDesc,
- 'longdesc' => ''
- ));
+ $cMeta = zeroBS_getCustomerMeta( $userID );
- }
+ if ( is_array( $cMeta ) && isset( $cMeta['status'] ) ) {
+ $customerStatus = $cMeta['status'];
+ }
+ }
- } else {
+ // check status
+ if ( ! empty( $customerStatus ) && in_array( $customerStatus, $okayStatuses ) ) {
- // make acc
- if ($userID > 0) {
+ // NEEDS account access
- zeroBSCRM_createClientPortalUserFromRecord($userID);
+ // already got?
+ $portalID = zeroBSCRM_getClientPortalUserID( $userID );
- $noteShortDesc = __('Access created (by change of status to',"zero-bs-crm").' "'.$customerStatus.'"';
+ if ( ! empty( $portalID ) && $portalID > 0 ) {
- #} Add log
- $newLogID = zeroBS_addUpdateContactLog($userID,-1,-1,array(
- 'type' => 'Client Portal Access Changed',
- 'shortdesc' => $noteShortDesc,
- 'longdesc' => ''
- ));
+ $isDisabled = zeroBSCRM_isCustomerPortalDisabled( $userID );
- }
+ // if disabled
+ if ( $isDisabled ) {
- }
+ // already got acc, make sure enabled
+ zeroBSCRM_customerPortalDisableEnable( $userID, 'enable' );
- } else {
+ $noteShortDesc = __( 'Access enabled (by change of status to', 'zero-bs-crm' ) . ' "' . $customerStatus . '"';
- // SHOULD Not have account
+ #} Add log
+ $newLogID = zeroBS_addUpdateContactLog(
+ $userID,
+ -1,
+ -1,
+ array(
+ 'type' => 'Client Portal Access Changed',
+ 'shortdesc' => $noteShortDesc,
+ 'longdesc' => '',
+ )
+ );
- // already got?
- $portalID = zeroBSCRM_getClientPortalUserID($userID);
+ }
+ } else {
- if (!empty($portalID) && $portalID > 0){
-
- $isDisabled = zeroBSCRM_isCustomerPortalDisabled($userID);
+ // make acc
+ if ( $userID > 0 ) {
- // if not already disabled
- if (!$isDisabled){
+ zeroBSCRM_createClientPortalUserFromRecord( $userID );
- // disable if found
- zeroBSCRM_customerPortalDisableEnable($userID,'disable');
+ $noteShortDesc = __( 'Access created (by change of status to', 'zero-bs-crm' ) . ' "' . $customerStatus . '"';
- $noteShortDesc = __('Access disabled (by change of status to',"zero-bs-crm").' "'.$customerStatus.'"';
+ #} Add log
+ $newLogID = zeroBS_addUpdateContactLog(
+ $userID,
+ -1,
+ -1,
+ array(
+ 'type' => 'Client Portal Access Changed',
+ 'shortdesc' => $noteShortDesc,
+ 'longdesc' => '',
+ )
+ );
- #} Add log
- $newLogID = zeroBS_addUpdateContactLog($userID,-1,-1,array(
- 'type' => 'Client Portal Access Changed',
- 'shortdesc' => $noteShortDesc,
- 'longdesc' => ''
- ));
+ }
+ }
+ } else {
- }
+ // SHOULD Not have account
- }
+ // already got?
+ $portalID = zeroBSCRM_getClientPortalUserID( $userID );
+ if ( ! empty( $portalID ) && $portalID > 0 ) {
+ $isDisabled = zeroBSCRM_isCustomerPortalDisabled( $userID );
-
+ // if not already disabled
+ if ( ! $isDisabled ) {
- }
+ // disable if found
+ zeroBSCRM_customerPortalDisableEnable( $userID, 'disable' );
- } else {
+ $noteShortDesc = __( 'Access disabled (by change of status to', 'zero-bs-crm' ) . ' "' . $customerStatus . '"';
- // non-standard val for status list, override it to all
- global $zbs;
- $zbs->settings->update('portalusers_status','all');
+ #} Add log
+ $newLogID = zeroBS_addUpdateContactLog(
+ $userID,
+ -1,
+ -1,
+ array(
+ 'type' => 'Client Portal Access Changed',
+ 'shortdesc' => $noteShortDesc,
+ 'longdesc' => '',
+ )
+ );
- // and... nothing to do - all statuses allowed
+ }
}
-
}
+ } else {
+
+ // non-standard val for status list, override it to all
+ global $zbs;
+ $zbs->settings->update( 'portalusers_status', 'all' );
- // / Specific status mode ==================================
+ // and... nothing to do - all statuses allowed
- } // / if autofire on :)
+ }
- }
+ // / Specific status mode ==================================
+ } // / if autofire on :)
+}
#} Adds a "changed" log when customer status change (if setting)
- function zeroBSCRM_IA_CustomerStatusChangeAutoLog($obj=array()){
-
+function zeroBSCRM_IA_CustomerStatusChangeAutoLog( $obj = array() ) {
- # if setting
- $autoLogThis = zeroBSCRM_getSetting('autolog_customer_statuschange');
+ # if setting
+ $autoLogThis = zeroBSCRM_getSetting( 'autolog_customer_statuschange' );
- if ($autoLogThis > 0){
+ if ( $autoLogThis > 0 ) {
- #} Retrieve necessary info:
- $zbsNoteAgainstPostID = -1; if (is_array($obj) && isset($obj['againstid']) && $obj['againstid'] > 0) $zbsNoteAgainstPostID = (int)$obj['againstid'];
- #TRANSITIONTOMETANO
+ #} Retrieve necessary info:
+ $zbsNoteAgainstPostID = -1;
+ if ( is_array( $obj ) && isset( $obj['againstid'] ) && $obj['againstid'] > 0 ) {
+ $zbsNoteAgainstPostID = (int) $obj['againstid'];
+ }
+ #TRANSITIONTOMETANO
- // I nicely pass these...
- $from = ''; if (is_array($obj) && isset($obj['from']) && !empty($obj['from'])) $from = $obj['from'];
- $to = ''; if (is_array($obj) && isset($obj['to']) && !empty($obj['to'])) $to = $obj['to'];
+ // I nicely pass these...
+ $from = '';
+ if ( is_array( $obj ) && isset( $obj['from'] ) && ! empty( $obj['from'] ) ) {
+ $from = $obj['from'];
+ }
+ $to = '';
+ if ( is_array( $obj ) && isset( $obj['to'] ) && ! empty( $obj['to'] ) ) {
+ $to = $obj['to'];
+ }
- if (isset($zbsNoteAgainstPostID) && !empty($zbsNoteAgainstPostID) && isset($to) && !empty($to)){
+ if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) && isset( $to ) && ! empty( $to ) ) {
- $shortDesc = '';
- if (!empty($from))
- $shortDesc = __('From',"zero-bs-crm").' "'.$from.'" '.__('to',"zero-bs-crm").' "'.$to.'"';
- else
- $shortDesc = __('To',"zero-bs-crm").' "'.$to.'"';
+ $shortDesc = '';
+ if ( ! empty( $from ) ) {
+ $shortDesc = __( 'From', 'zero-bs-crm' ) . ' "' . $from . '" ' . __( 'to', 'zero-bs-crm' ) . ' "' . $to . '"';
+ } else {
+ $shortDesc = __( 'To', 'zero-bs-crm' ) . ' "' . $to . '"';
+ }
- #} Add log
- $newLogID = zeroBS_addUpdateContactLog($zbsNoteAgainstPostID,-1,-1,array(
- 'type' => 'Status Change',
+ #} Add log
+ $newLogID = zeroBS_addUpdateContactLog(
+ $zbsNoteAgainstPostID,
+ -1,
+ -1,
+ array(
+ 'type' => 'Status Change',
'shortdesc' => $shortDesc,
- 'longdesc' => ''
- ));
-
- }
+ 'longdesc' => '',
+ )
+ );
}
-
}
+}
+/*
+======================================================
+ / Internal Automator Recipe Functions
+ ====================================================== */
-/* ======================================================
- / Internal Automator Recipe Functions
- ====================================================== */
-
-
-
-/* ======================================================
- Internal Automator Recipe Functions - WP HOOK tieins... just middlemen here really
- ====================================================== */
+/*
+======================================================
+ Internal Automator Recipe Functions - WP HOOK tieins... just middlemen here really
+ ====================================================== */
#} Fires the hook & passes in the obj, for those who still want to use wp_hook's rather than IA Automator
- #} Fires on 'customer.new' IA
- function zeroBSCRM_IA_NewCustomerWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) {
+ #} Fires on 'customer.new' IA
+function zeroBSCRM_IA_NewCustomerWPHook( $obj = array() ) {
- do_action( 'jpcrm_after_contact_insert', $obj['id'] );
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
- // legacy, use `jpcrm_after_contact_insert` from 5.3+
- do_action( 'zbs_new_customer', $obj['id'] );
+ do_action( 'jpcrm_after_contact_insert', $obj['id'] );
- }
+ // legacy, use `jpcrm_after_contact_insert` from 5.3+
+ do_action( 'zbs_new_customer', $obj['id'] );
}
+}
/**
* Fires on 'contact.update', 'contact.email.update', and 'contact.status.update IA.
@@ -1074,22 +1263,24 @@ function zeroBSCRM_IA_EditCustomerWPHook( $obj = array() ) {
}
#} Fires on 'customer.vitals.edit' IA.
- function zeroBSCRM_IA_EditCustomerVitalsWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_edit_customer_vitals', $obj['id']);
+function zeroBSCRM_IA_EditCustomerVitalsWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_edit_customer_vitals', $obj['id'] );
}
+}
/**
* Fires on 'contact.email.update' IA. Now legacy, redirecting to zeroBSCRM_IA_EditCustomerWPHook
*
* @param array $obj An array holding contact object data.
*/
- function zeroBSCRM_IA_EditCustomerEmailWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_edit_customer_email', $obj['id']);
+function zeroBSCRM_IA_EditCustomerEmailWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_edit_customer_email', $obj['id'] );
}
+}
/**
* Fires on 'contact.delete' IA.
@@ -1109,7 +1300,7 @@ function zeroBSCRM_IA_DeleteCustomerWPHook( $obj = array() ) {
*
* @param array $obj An array holding contact object data.
*/
- function zeroBSCRM_IA_BeforeDeleteCustomerWPHook($obj=array()){
+function zeroBSCRM_IA_BeforeDeleteCustomerWPHook( $obj = array() ) {
if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
do_action( 'jpcrm_before_delete_contact', $obj );
}
@@ -1143,24 +1334,27 @@ function zeroBSCRM_IA_DeleteCompanyWPHook( $obj = array() ) {
do_action( 'zbs_delete_company', $obj['id'] );
}
}
- #} Fires on 'quote.new' IA
- function zeroBSCRM_IA_NewQuoteWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_new_quote', $obj['id']);
+ #} Fires on 'quote.new' IA
+function zeroBSCRM_IA_NewQuoteWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_new_quote', $obj['id'] );
}
- #} Fires on 'quote.accepted' IA
- function zeroBSCRM_IA_AcceptedQuoteWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('jpcrm_quote_accepted', $obj['id']);
+}
+ #} Fires on 'quote.accepted' IA
+function zeroBSCRM_IA_AcceptedQuoteWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'jpcrm_quote_accepted', $obj['id'] );
}
- #} Fires on 'quote.delete' IA
- function zeroBSCRM_IA_DeleteQuoteWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_delete_quote', $obj['id']);
+}
+ #} Fires on 'quote.delete' IA
+function zeroBSCRM_IA_DeleteQuoteWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_delete_quote', $obj['id'] );
}
+}
/**
* Fires on 'invoice.new' IA.
@@ -1197,57 +1391,64 @@ function zeroBSCRM_IA_DeleteInvoiceWPHook( $obj = array() ) {
}
}
- #} Fires on 'transaction.new' IA
- function zeroBSCRM_IA_NewTransactionWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_new_transaction', $obj['id']);
+ #} Fires on 'transaction.new' IA
+function zeroBSCRM_IA_NewTransactionWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_new_transaction', $obj['id'] );
}
- #} Fires on 'transaction.delete' IA
- function zeroBSCRM_IA_DeleteTransactionWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_delete_transaction', $obj['id']);
+}
+ #} Fires on 'transaction.delete' IA
+function zeroBSCRM_IA_DeleteTransactionWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_delete_transaction', $obj['id'] );
}
- #} Fires on 'event.new' IA
- function zeroBSCRM_IA_NewEventWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_new_event', $obj['id']);
+}
+ #} Fires on 'event.new' IA
+function zeroBSCRM_IA_NewEventWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_new_event', $obj['id'] );
}
- #} Fires on 'event.update' IA
- function zeroBSCRM_IA_UpdateEventWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_update_event', $obj['id']);
+}
+ #} Fires on 'event.update' IA
+function zeroBSCRM_IA_UpdateEventWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_update_event', $obj['id'] );
}
- #} Fires on 'event.delete' IA
- function zeroBSCRM_IA_DeleteEventWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_delete_event', $obj['id']);
+}
+ #} Fires on 'event.delete' IA
+function zeroBSCRM_IA_DeleteEventWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_delete_event', $obj['id'] );
}
- #} Fires on 'clientwpuser.new' IA
- function zeroBSCRM_IA_NewClientPortalUserHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_new_client_portal_user', $obj['id']);
+}
+ #} Fires on 'clientwpuser.new' IA
+function zeroBSCRM_IA_NewClientPortalUserHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_new_client_portal_user', $obj['id'] );
}
- #} Fires on 'form.delete' IA
- function zeroBSCRM_IA_DeleteFormWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_delete_form', $obj['id']);
+}
+ #} Fires on 'form.delete' IA
+function zeroBSCRM_IA_DeleteFormWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_delete_form', $obj['id'] );
}
- #} Fires on 'segment.delete' IA
- function zeroBSCRM_IA_DeleteSegmentWPHook($obj=array()){
-
- if (is_array($obj) && isset($obj['id']) && !empty($obj['id'])) do_action('zbs_delete_segment', $obj['id']);
+}
+ #} Fires on 'segment.delete' IA
+function zeroBSCRM_IA_DeleteSegmentWPHook( $obj = array() ) {
+ if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) {
+ do_action( 'zbs_delete_segment', $obj['id'] );
}
+}
-
-
-/* ======================================================
- / Internal Automator Recipe Functions - WP HOOK tieins
- ====================================================== */
+/*
+======================================================
+ / Internal Automator Recipe Functions - WP HOOK tieins
+ ====================================================== */
diff --git a/projects/plugins/crm/includes/ZeroBSCRM.Inventory.php b/projects/plugins/crm/includes/ZeroBSCRM.Inventory.php
index 7921895a1af2..25d157c64f05 100644
--- a/projects/plugins/crm/includes/ZeroBSCRM.Inventory.php
+++ b/projects/plugins/crm/includes/ZeroBSCRM.Inventory.php
@@ -1,5 +1,5 @@
- 0) $due = (int)$zbsInvoice['due_date'];
+ global $zbs;
- // compare (could give days difference here, but not req yet.)
- if ($due > time()){
- // not due
- return false;
- } else {
- // due
- return true;
- }
+ if ( is_array( $zbsInvoice ) ) {
- }
+ // first get due
+ $due = 0;
+ if ( isset( $zbsInvoice['due_date'] ) && $zbsInvoice['due_date'] > 0 ) {
+ $due = (int) $zbsInvoice['due_date'];
+ }
- return false;
+ // compare (could give days difference here, but not req yet.)
+ if ( $due > time() ) {
+ // not due
+ return false;
+ } else {
+ // due
+ return true;
+ }
+ }
+ return false;
}
-
-/* ======================================================
- ZBS Invoicing - REMOVE previous submit meta box + replace with custom
- ====================================================== */
+/*
+======================================================
+ ZBS Invoicing - REMOVE previous submit meta box + replace with custom
+ ====================================================== */
#} This adds our own save box
-function zeroBSCRM_replace_invoice_submit_meta_box()
-{
-
- #} remove typical submit box:
- remove_meta_box('submitdiv', 'zerobs_invoice', 'core'); // $item represents post_type
-
- #} Include/initialise custom submitbox
- require_once( ZEROBSCRM_INCLUDE_PATH . 'ZeroBSCRM.MetaBoxes.SubmitBoxes.php');
-
+function zeroBSCRM_replace_invoice_submit_meta_box() {
+
+ #} remove typical submit box:
+ remove_meta_box( 'submitdiv', 'zerobs_invoice', 'core' ); // $item represents post_type
+
+ #} Include/initialise custom submitbox
+ require_once ZEROBSCRM_INCLUDE_PATH . 'ZeroBSCRM.MetaBoxes.SubmitBoxes.php';
}
add_action( 'admin_init', 'zeroBSCRM_replace_invoice_submit_meta_box' );
#} This specifies 1 column pre-save, 2 columns post-save :)
-function zeroBSCRM_invoiceBuilderColumnCount(){
+function zeroBSCRM_invoiceBuilderColumnCount() {
- global $post;
- if (isset($post->post_status) && $post->post_status != "auto-draft") return 2;
-
- return 2;
+ global $post;
+ if ( isset( $post->post_status ) && $post->post_status != 'auto-draft' ) {
+ return 2;
+ }
+ return 2;
}
-add_filter('get_user_option_screen_layout_zerobs_invoice', 'zeroBSCRM_invoiceBuilderColumnCount' );
+add_filter( 'get_user_option_screen_layout_zerobs_invoice', 'zeroBSCRM_invoiceBuilderColumnCount' );
-
-/* ======================================================
- ZBS Invoicing - HTML GENERATOR
- ====================================================== */
+/*
+======================================================
+ ZBS Invoicing - HTML GENERATOR
+ ====================================================== */
#} Generates the HTML of an invoice based on the template in templates/invoices/invoice-pdf.html
#} if $return, it'll return, otherwise it'll echo + exit
#} --------- Notes:
-#} ... there's several ways we COULD do this,
-#} ... suggest we explore this way first, then re-discuss,
+#} ... there's several ways we COULD do this,
+#} ... suggest we explore this way first, then re-discuss,
#} ... Benefits of this inc. easy to theme ;) just create variations of invoice.html
// Note: This is primarily used to generate PDF invoice html. (dig down and see use if "zeroBSCRM_invoicing_generateInvoiceHTML($invoiceID,'pdf'")
-function zeroBSCRM_invoice_generateInvoiceHTML($invoicePostID=-1,$return=true){
+function zeroBSCRM_invoice_generateInvoiceHTML( $invoicePostID = -1, $return = true ) {
- if (!empty($invoicePostID)){
+ if ( ! empty( $invoicePostID ) ) {
- global $zbs;
- return zeroBSCRM_invoice_generateInvoiceHTML_v3( $invoicePostID, $return );
+ global $zbs;
+ return zeroBSCRM_invoice_generateInvoiceHTML_v3( $invoicePostID, $return );
- }
+ }
- #} Empty inv id
- return false;
+ #} Empty inv id
+ return false;
}
// invoice html generation 3.0+
-function zeroBSCRM_invoice_generateInvoiceHTML_v3( $invoiceID=-1, $return=true ){
+function zeroBSCRM_invoice_generateInvoiceHTML_v3( $invoiceID = -1, $return = true ) {
- global $zbs;
+ global $zbs;
- if (!empty($invoiceID)){
+ if ( ! empty( $invoiceID ) ) {
- // Discern template and retrieve
- $global_invoice_pdf_template = zeroBSCRM_getSetting('inv_pdf_template');
- if ( !empty( $global_invoice_pdf_template ) ){
- $templatedHTML = jpcrm_retrieve_template( $global_invoice_pdf_template, false );
- }
+ // Discern template and retrieve
+ $global_invoice_pdf_template = zeroBSCRM_getSetting( 'inv_pdf_template' );
+ if ( ! empty( $global_invoice_pdf_template ) ) {
+ $templatedHTML = jpcrm_retrieve_template( $global_invoice_pdf_template, false );
+ }
- // fallback to default template
- if ( !isset( $templatedHTML ) || empty( $templatedHTML ) ){
+ // fallback to default template
+ if ( ! isset( $templatedHTML ) || empty( $templatedHTML ) ) {
- // template failed as setting potentially holds out of date (removed) template
- // so use the default
- $templatedHTML = jpcrm_retrieve_template( 'invoices/invoice-pdf.html', false );
+ // template failed as setting potentially holds out of date (removed) template
+ // so use the default
+ $templatedHTML = jpcrm_retrieve_template( 'invoices/invoice-pdf.html', false );
- }
+ }
- #} Act
- if (!empty($templatedHTML)){
+ #} Act
+ if ( ! empty( $templatedHTML ) ) {
- // Over-ride the #MSGCONTENT# part
- $placeholder_templating = $zbs->get_templating();
+ // Over-ride the #MSGCONTENT# part
+ $placeholder_templating = $zbs->get_templating();
- // replace the content with our new ID ... (gets our content template info and replaces ###MSG CONTENT)
- $message_content = zeroBSCRM_mailTemplate_get(ZBSEMAIL_EMAILINVOICE);
- $message_content = $message_content->zbsmail_body;
- $templatedHTML = $placeholder_templating->replace_single_placeholder( 'msg-content', $message_content, $templatedHTML );
+ // replace the content with our new ID ... (gets our content template info and replaces ###MSG CONTENT)
+ $message_content = zeroBSCRM_mailTemplate_get( ZBSEMAIL_EMAILINVOICE );
+ $message_content = $message_content->zbsmail_body;
+ $templatedHTML = $placeholder_templating->replace_single_placeholder( 'msg-content', $message_content, $templatedHTML );
- // for v3.0 WH split out the data-retrieval from scattering amongst this func, unified here:
- // translated the below cpt way into dal / v3.0:
+ // for v3.0 WH split out the data-retrieval from scattering amongst this func, unified here:
+ // translated the below cpt way into dal / v3.0:
- // this was refactored as was duplicate code.
- // now all wired through zeroBSCRM_invoicing_generateInvoiceHTML
- $html = zeroBSCRM_invoicing_generateInvoiceHTML($invoiceID,'pdf',$templatedHTML);
+ // this was refactored as was duplicate code.
+ // now all wired through zeroBSCRM_invoicing_generateInvoiceHTML
+ $html = zeroBSCRM_invoicing_generateInvoiceHTML( $invoiceID, 'pdf', $templatedHTML );
// return
if ( ! $return ) {
@@ -150,54 +150,53 @@ function zeroBSCRM_invoice_generateInvoiceHTML_v3( $invoiceID=-1, $return=true )
// this was clunky, so split into 3.0 and <3.0 versions.
// ultimately this is much like zeroBSCRM_invoice_generateInvoiceHTML
// ... should refactor the bits that are the same
-function zeroBSCRM_invoice_generatePortalInvoiceHTML($invoicePostID=-1,$return=true){
- global $zbs;
+function zeroBSCRM_invoice_generatePortalInvoiceHTML( $invoicePostID = -1, $return = true ) {
+ global $zbs;
- if (!empty($invoicePostID)){
- return zeroBSCRM_invoice_generatePortalInvoiceHTML_v3( $invoicePostID, $return );
- }
+ if ( ! empty( $invoicePostID ) ) {
+ return zeroBSCRM_invoice_generatePortalInvoiceHTML_v3( $invoicePostID, $return );
+ }
- #} Empty inv id
- return false;
+ #} Empty inv id
+ return false;
}
-
// 3.0+
-function zeroBSCRM_invoice_generatePortalInvoiceHTML_v3($invoiceID=-1,$return=true){
+function zeroBSCRM_invoice_generatePortalInvoiceHTML_v3( $invoiceID = -1, $return = true ) {
- global $zbs;
+ global $zbs;
- if (!empty($invoiceID)){
+ if ( ! empty( $invoiceID ) ) {
- // Discern template and retrieve
- $global_invoice_portal_template = zeroBSCRM_getSetting('inv_portal_template');
- if ( !empty( $global_invoice_portal_template ) ){
- $html = jpcrm_retrieve_template( $global_invoice_portal_template, false );
- }
+ // Discern template and retrieve
+ $global_invoice_portal_template = zeroBSCRM_getSetting( 'inv_portal_template' );
+ if ( ! empty( $global_invoice_portal_template ) ) {
+ $html = jpcrm_retrieve_template( $global_invoice_portal_template, false );
+ }
- // fallback to default template
- if ( !isset( $html ) || empty( $html ) ){
+ // fallback to default template
+ if ( ! isset( $html ) || empty( $html ) ) {
- // template failed as setting potentially holds out of date (removed) template
- // so use the default
- $html = jpcrm_retrieve_template( 'invoices/portal-invoice.html', false );
+ // template failed as setting potentially holds out of date (removed) template
+ // so use the default
+ $html = jpcrm_retrieve_template( 'invoices/portal-invoice.html', false );
- }
+ }
- #} Act
- if (!empty($html)){
+ #} Act
+ if ( ! empty( $html ) ) {
- // load templating
- $placeholder_templating = $zbs->get_templating();
+ // load templating
+ $placeholder_templating = $zbs->get_templating();
- // replace the content with our new ID ... (gets our content template info and replaces ###MSG CONTENT)
- $message_content = zeroBSCRM_mailTemplate_get(ZBSEMAIL_EMAILINVOICE);
- $message_content = $message_content->zbsmail_body;
- $html = $placeholder_templating->replace_single_placeholder( 'msg-content', $message_content, $html );
+ // replace the content with our new ID ... (gets our content template info and replaces ###MSG CONTENT)
+ $message_content = zeroBSCRM_mailTemplate_get( ZBSEMAIL_EMAILINVOICE );
+ $message_content = $message_content->zbsmail_body;
+ $html = $placeholder_templating->replace_single_placeholder( 'msg-content', $message_content, $html );
- // this was refactored as was duplicate code.
- // now all wired through zeroBSCRM_invoicing_generateInvoiceHTML
- $html = zeroBSCRM_invoicing_generateInvoiceHTML($invoiceID,'portal',$html);
+ // this was refactored as was duplicate code.
+ // now all wired through zeroBSCRM_invoicing_generateInvoiceHTML
+ $html = zeroBSCRM_invoicing_generateInvoiceHTML( $invoiceID, 'portal', $html );
// return
if ( ! $return ) {
@@ -213,7 +212,7 @@ function zeroBSCRM_invoice_generatePortalInvoiceHTML_v3($invoiceID=-1,$return=tr
return false;
}
-function zbs_invoice_generate_pdf(){
+function zbs_invoice_generate_pdf() {
// download flag
if ( isset( $_POST['zbs_invoicing_download_pdf'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -296,15 +295,15 @@ function jpcrm_invoice_generate_pdf( $invoice_id = -1 ) {
// LEGACY, should now be using zeroBSCRM_invoice_generateInvoiceHTML
// still used in Client Portal Pro
-function zbs_invoice_html($invoicePostID){
+function zbs_invoice_html( $invoicePostID ) {
- $html = zeroBSCRM_invoice_generateInvoiceHTML($invoicePostID);
+ $html = zeroBSCRM_invoice_generateInvoiceHTML( $invoicePostID );
- return $html;
+ return $html;
}
#} this generates a PDF statement for a contact, either returning the filepath or a PDF download prompt
-function zeroBSCRM_invoicing_generateStatementPDF( $contactID = -1, $returnPDF = false ){
+function zeroBSCRM_invoicing_generateStatementPDF( $contactID = -1, $returnPDF = false ) {
if ( ! zeroBSCRM_permsInvoices() ) {
exit( 0 );
@@ -312,74 +311,75 @@ function zeroBSCRM_invoicing_generateStatementPDF( $contactID = -1, $returnPDF =
global $zbs;
- #} Check ID
- $contactID = (int)$contactID;
- #} If user has no perms, or id not present, die
- if (!zeroBSCRM_permsInvoices() || empty($contactID) || $contactID <= 0){
+ #} Check ID
+ $contactID = (int) $contactID;
+ #} If user has no perms, or id not present, die
+ if ( ! zeroBSCRM_permsInvoices() || empty( $contactID ) || $contactID <= 0 ) {
die( 0 );
- }
-
- $html = zeroBSCRM_invoicing_generateStatementHTML($contactID);
+ }
- // build PDF
- $dompdf = $zbs->pdf_engine();
- $dompdf->loadHtml($html,'UTF-8');
- $dompdf->render();
+ $html = zeroBSCRM_invoicing_generateStatementHTML( $contactID );
- // target dir
- $upload_dir = wp_upload_dir();
- $zbsInvoicingDir = $upload_dir['basedir'].'/invoices/';
+ // build PDF
+ $dompdf = $zbs->pdf_engine();
+ $dompdf->loadHtml( $html, 'UTF-8' );
+ $dompdf->render();
- if ( ! file_exists( $zbsInvoicingDir ) ) {
- wp_mkdir_p( $zbsInvoicingDir );
- }
- // got it?
- if ( ! file_exists( $zbsInvoicingDir ) ) {
- return false;
- }
+ // target dir
+ $upload_dir = wp_upload_dir();
+ $zbsInvoicingDir = $upload_dir['basedir'] . '/invoices/';
- // make a hash
- // here we've tried to protect against someone overriding the security,
- // but if they're inside... it's too late anyhow.
- $hash = wp_generate_password(14, false);
- if (empty($hash) || strlen($hash) < 14) $hash = md5(time().'xcsac'); // backup
-
- $statementFilename = $zbsInvoicingDir.$hash.'-'.__('statement','zero-bs-crm').'-'.$contactID.'.pdf';
+ if ( ! file_exists( $zbsInvoicingDir ) ) {
+ wp_mkdir_p( $zbsInvoicingDir );
+ }
+ // got it?
+ if ( ! file_exists( $zbsInvoicingDir ) ) {
+ return false;
+ }
- //save the pdf file on the server
- file_put_contents($statementFilename, $dompdf->output());
+ // make a hash
+ // here we've tried to protect against someone overriding the security,
+ // but if they're inside... it's too late anyhow.
+ $hash = wp_generate_password( 14, false );
+ if ( empty( $hash ) || strlen( $hash ) < 14 ) {
+ $hash = md5( time() . 'xcsac' ); // backup
+ }
- if (file_exists( $statementFilename )) {
+ $statementFilename = $zbsInvoicingDir . $hash . '-' . __( 'statement', 'zero-bs-crm' ) . '-' . $contactID . '.pdf';
- // if return pdf, return, otherwise return filepath
- if ($returnPDF){
+ // save the pdf file on the server
+ file_put_contents( $statementFilename, $dompdf->output() );
- //print the pdf file to the screen for saving
- header('Content-type: application/pdf');
- header( 'Content-Disposition: attachment; filename="' . __( 'statement', 'zero-bs-crm' ) . '-' . $contactID . '.pdf' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
- header('Content-Transfer-Encoding: binary');
- header('Content-Length: ' . filesize($statementFilename));
- header('Accept-Ranges: bytes');
- readfile($statementFilename);
+ if ( file_exists( $statementFilename ) ) {
- //delete the PDF file once it's been read (i.e. downloaded)
- unlink($statementFilename);
+ // if return pdf, return, otherwise return filepath
+ if ( $returnPDF ) {
- } else {
+ // print the pdf file to the screen for saving
+ header( 'Content-type: application/pdf' );
+ header( 'Content-Disposition: attachment; filename="' . __( 'statement', 'zero-bs-crm' ) . '-' . $contactID . '.pdf' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
+ header( 'Content-Transfer-Encoding: binary' );
+ header( 'Content-Length: ' . filesize( $statementFilename ) );
+ header( 'Accept-Ranges: bytes' );
+ readfile( $statementFilename );
- return $statementFilename;
+ // delete the PDF file once it's been read (i.e. downloaded)
+ unlink( $statementFilename );
- }
+ } else {
+ return $statementFilename;
- } // if file
+ }
+ } // if file
- return false;
+ return false;
}
-/* ======================================================
- ZBS Invoicing - STATEMENT HTML GENERATOR
- ====================================================== */
+/*
+======================================================
+ ZBS Invoicing - STATEMENT HTML GENERATOR
+ ====================================================== */
// phpcs:ignore Squiz.Commenting.FunctionComment.MissingParamTag
/**
@@ -583,7 +583,7 @@ function zeroBSCRM_invoicing_generateStatementHTML_v3( $contact_id = -1, $return
// due
if ( $invoice['due_date'] <= 0 ) {
- //no due date;
+ // no due date;
$due_date_str = __( 'No due date', 'zero-bs-crm' );
} else {
@@ -788,7 +788,7 @@ function zeroBSCRM_invoicing_generateInvoiceHTML( $invoice_id = -1, $template =
// due
if ( $invoice['due_date'] <= 0 ) {
- //no due date
+ // no due date
$due_date_str = __( 'No due date', 'zero-bs-crm' );
} else {
@@ -954,7 +954,7 @@ function zeroBSCRM_invoicing_generateInvoiceHTML( $invoice_id = -1, $template =
// == Build biz info table.
- //the business info from the settings
+ // the business info from the settings
$zbs_biz_name = zeroBSCRM_getSetting( 'businessname' );
$zbs_biz_yourname = zeroBSCRM_getSetting( 'businessyourname' );
$zbs_biz_extra = zeroBSCRM_getSetting( 'businessextra' );
@@ -1258,7 +1258,7 @@ function zeroBSCRM_invoicing_generateInvoiceHTML( $invoice_id = -1, $template =
}
// Used to generate specific part of invoice pdf: Biz table (Pay To)
-function zeroBSCRM_invoicing_generateInvPart_bizTable($args=array()){
+function zeroBSCRM_invoicing_generateInvPart_bizTable( $args = array() ) {
#} =========== LOAD ARGS ==============
$defaultArgs = array( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
@@ -1271,7 +1271,21 @@ function zeroBSCRM_invoicing_generateInvPart_bizTable($args=array()){
'template' => 'pdf', // this'll choose between the html output variants below, e.g. pdf, portal, notification
- ); foreach ($defaultArgs as $argK => $argV){ $$argK = $argV; if (is_array($args) && isset($args[$argK])) { if (is_array($args[$argK])){ $newData = $$argK; if (!is_array($newData)) $newData = array(); foreach ($args[$argK] as $subK => $subV){ $newData[$subK] = $subV; }$$argK = $newData;} else { $$argK = $args[$argK]; } } }
+ );
+ foreach ( $defaultArgs as $argK => $argV ) {
+ $$argK = $argV;
+ if ( is_array( $args ) && isset( $args[ $argK ] ) ) {
+ if ( is_array( $args[ $argK ] ) ) {
+ $newData = $$argK;
+ if ( ! is_array( $newData ) ) {
+ $newData = array();
+ } foreach ( $args[ $argK ] as $subK => $subV ) {
+ $newData[ $subK ] = $subV;
+ }$$argK = $newData;
+ } else {
+ $$argK = $args[ $argK ]; }
+ }
+ }
#} =========== / LOAD ARGS =============
$biz_info_table = '';
@@ -1381,78 +1395,72 @@ function zeroBSCRM_invoicing_generateInvPart_custTable( $inv_to = array(), $temp
$invoice_customer_info_table_html .= '
';
- //filter the whole thing if you really want to modify it
+ // filter the whole thing if you really want to modify it
$invoice_customer_info_table_html = apply_filters( 'zbs_invoice_customer_info_table', $invoice_customer_info_table_html );
return $invoice_customer_info_table_html;
}
-
-
-
-
/*
* Generates html string to output customer (contact or company) custom field lines for templating
*
* @param array $customer - a contact|company object
* @param string $template - 'pdf', 'notification', or 'portal'
-*
+*
* @return string HTML
*/
-function jpcrm_invoicing_generate_customer_custom_fields_lines( $customer, $template ){
+function jpcrm_invoicing_generate_customer_custom_fields_lines( $customer, $template ) {
- global $zbs;
+ global $zbs;
- $customer_custom_fields_html = '';
+ $customer_custom_fields_html = '';
- // retrieve custom fields to pass through
- // contact or company?
- if ( $customer['objtype'] == ZBS_TYPE_CONTACT ){
+ // retrieve custom fields to pass through
+ // contact or company?
+ if ( $customer['objtype'] == ZBS_TYPE_CONTACT ) {
- $custom_fields_to_include = zeroBSCRM_getSetting( 'contactcustomfields' );
+ $custom_fields_to_include = zeroBSCRM_getSetting( 'contactcustomfields' );
- } elseif ( $customer['objtype'] == ZBS_TYPE_COMPANY ){
+ } elseif ( $customer['objtype'] == ZBS_TYPE_COMPANY ) {
- $custom_fields_to_include = zeroBSCRM_getSetting( 'companycustomfields' );
+ $custom_fields_to_include = zeroBSCRM_getSetting( 'companycustomfields' );
- } else {
+ } else {
- // no type? ¯\_(ツ)_/¯
- return '';
+ // no type? ¯\_(ツ)_/¯
+ return '';
- }
-
-
- if ( !empty( $custom_fields_to_include ) ){
+ }
- // split the csv
- $custom_fields_to_include = array_map( 'trim', explode( ',', $custom_fields_to_include ) );
+ if ( ! empty( $custom_fields_to_include ) ) {
- // retrieve fields
- $invoice_custom_fields = $zbs->DAL->getActiveCustomFields( array( 'objtypeid' => $customer['objtype'] ) );
+ // split the csv
+ $custom_fields_to_include = array_map( 'trim', explode( ',', $custom_fields_to_include ) );
- // build custom fields string.
- // here we immitate what we expect the HTML to be, which will be errorsome if people modify heavily.
- // for now it's better than no custom fields, let's see if people have issue with this approach.
- foreach ( $invoice_custom_fields as $field_key => $field_info){
+ // retrieve fields
+ $invoice_custom_fields = $zbs->DAL->getActiveCustomFields( array( 'objtypeid' => $customer['objtype'] ) );
- // where user has set the field in settings
- if ( in_array( $field_key, $custom_fields_to_include ) ){
+ // build custom fields string.
+ // here we immitate what we expect the HTML to be, which will be errorsome if people modify heavily.
+ // for now it's better than no custom fields, let's see if people have issue with this approach.
+ foreach ( $invoice_custom_fields as $field_key => $field_info ) {
- $custom_field_str = '';
+ // where user has set the field in settings
+ if ( in_array( $field_key, $custom_fields_to_include ) ) {
- if ( isset( $customer[ $field_key ] ) && $customer[ $field_key ] ){
+ $custom_field_str = '';
- $custom_field_str = $customer[ $field_key ];
+ if ( isset( $customer[ $field_key ] ) && $customer[ $field_key ] ) {
- // catch formatted dates
- if ( isset( $customer[ $field_key . '_cfdate' ] ) ){
+ $custom_field_str = $customer[ $field_key ];
- $custom_field_str = $customer[ $field_key . '_cfdate' ];
+ // catch formatted dates
+ if ( isset( $customer[ $field_key . '_cfdate' ] ) ) {
- }
+ $custom_field_str = $customer[ $field_key . '_cfdate' ];
- }
+ }
+ }
// skip empties
if ( empty( $custom_field_str ) ) {
@@ -1478,52 +1486,51 @@ function jpcrm_invoicing_generate_customer_custom_fields_lines( $customer, $temp
return $customer_custom_fields_html;
}
-
/*
* Generates html string to output invoice custom field lines for templating
*
* @param array $invoice - an invoice object
* @param string $template - 'pdf', 'notification', or 'portal'
-*
+*
* @return string HTML
*/
-function jpcrm_invoicing_generate_invoice_custom_fields_lines( $invoice, $template ){
+function jpcrm_invoicing_generate_invoice_custom_fields_lines( $invoice, $template ) {
- global $zbs;
+ global $zbs;
- $invoice_custom_fields_html = '';
+ $invoice_custom_fields_html = '';
- // retrieve custom fields to pass through
- $custom_fields_to_include = zeroBSCRM_getSetting( 'invcustomfields' );
- if ( !empty( $custom_fields_to_include ) ){
+ // retrieve custom fields to pass through
+ $custom_fields_to_include = zeroBSCRM_getSetting( 'invcustomfields' );
+ if ( ! empty( $custom_fields_to_include ) ) {
- // split the csv
- $custom_fields_to_include = array_map( 'trim', explode( ',', $custom_fields_to_include ) );
+ // split the csv
+ $custom_fields_to_include = array_map( 'trim', explode( ',', $custom_fields_to_include ) );
- // retrieve fields
- $invoice_custom_fields = $zbs->DAL->getActiveCustomFields( array( 'objtypeid' => ZBS_TYPE_INVOICE ) );
+ // retrieve fields
+ $invoice_custom_fields = $zbs->DAL->getActiveCustomFields( array( 'objtypeid' => ZBS_TYPE_INVOICE ) );
- // build custom fields string.
- // here we immitate what we expect the HTML to be, which will be errorsome if people modify heavily.
- // for now it's better than no custom fields, let's see if people have issue with this approach.
- foreach ( $invoice_custom_fields as $field_key => $field_info){
+ // build custom fields string.
+ // here we immitate what we expect the HTML to be, which will be errorsome if people modify heavily.
+ // for now it's better than no custom fields, let's see if people have issue with this approach.
+ foreach ( $invoice_custom_fields as $field_key => $field_info ) {
- // where user has set the field in settings
- if ( in_array( $field_key, $custom_fields_to_include ) ){
+ // where user has set the field in settings
+ if ( in_array( $field_key, $custom_fields_to_include ) ) {
- $custom_field_str = '';
+ $custom_field_str = '';
- if ( $invoice[ $field_key ] ){
+ if ( $invoice[ $field_key ] ) {
- $custom_field_str = $invoice[ $field_key ];
+ $custom_field_str = $invoice[ $field_key ];
- // catch formatted dates
- if ( isset( $invoice[ $field_key . '_cfdate' ] ) ){
+ // catch formatted dates
+ if ( isset( $invoice[ $field_key . '_cfdate' ] ) ) {
- $custom_field_str = $invoice[ $field_key . '_cfdate' ];
+ $custom_field_str = $invoice[ $field_key . '_cfdate' ];
- }
- }
+ }
+ }
// skip empties
if ( empty( $custom_field_str ) ) {
@@ -1551,7 +1558,6 @@ function jpcrm_invoicing_generate_invoice_custom_fields_lines( $invoice, $templa
return $invoice_custom_fields_html;
}
-
// Used to generate specific part of invoice pdf: (Lineitem row in inv table)
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
function zeroBSCRM_invoicing_generateInvPart_lineitems( $invlines = array() ) {
diff --git a/projects/plugins/crm/includes/ZeroBSCRM.List.Columns.php b/projects/plugins/crm/includes/ZeroBSCRM.List.Columns.php
index d85c762b2e23..3d5a2c5b258a 100644
--- a/projects/plugins/crm/includes/ZeroBSCRM.List.Columns.php
+++ b/projects/plugins/crm/includes/ZeroBSCRM.List.Columns.php
@@ -1,508 +1,510 @@
- array( 'ID', false, 'basefield' ),
+ 'nameavatar' => array( __( 'Name and Avatar', 'zero-bs-crm' ) ),
+ // 'email' => array('Email','zbsDefault_column_customeremail'),
+ 'status' => array(
+ __( 'Status', 'zero-bs-crm' ),
+ false,
+ 'basefield',
+ 'editinline' => 1,
+ ),
+ 'totalvalue' => array( __( 'Total Value', 'zero-bs-crm' ) ),
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+);
+
+$zeroBSCRM_columns_customer['all'] = array(
+
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'name' => array( __( 'Name', 'zero-bs-crm' ), false, 'basefield' ),
+ 'nameavatar' => array( __( 'Name and Avatar', 'zero-bs-crm' ) ),
+ 'email' => array( __( 'Email', 'zero-bs-crm' ), false, 'basefield' ),
+ 'status' => array(
+ __( 'Status', 'zero-bs-crm' ),
+ false,
+ 'basefield',
+ 'editinline' => 1,
+ ),
+
+ 'hasquote' => array( __( 'Has Quote', 'zero-bs-crm' ) ),
+ 'hasinvoice' => array( __( 'Has Invoice', 'zero-bs-crm' ) ),
+ 'hastransaction' => array( __( 'Has Transaction', 'zero-bs-crm' ) ),
+
+ 'quotecount' => array( __( 'Quote Count', 'zero-bs-crm' ) ),
+ 'invoicecount' => array( __( 'Invoice Count', 'zero-bs-crm' ) ),
+ 'transactioncount' => array( __( 'Transaction Count', 'zero-bs-crm' ) ),
+
+ 'quotetotal' => array( __( 'Quotes Total', 'zero-bs-crm' ) ),
+ 'invoicetotal' => array( __( 'Invoices Total', 'zero-bs-crm' ) ),
+ 'transactiontotal' => array( __( 'Transactions Total', 'zero-bs-crm' ) ),
+
+ 'totalvalue' => array( __( 'Total Value', 'zero-bs-crm' ) ),
+
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+ 'lastupdated' => array( __( 'Last Updated', 'zero-bs-crm' ), false, 'basefield' ),
+ 'assigned' => array(
+ __( 'Assigned To', 'zero-bs-crm' ),
+ false,
+ 'basefield',
+ 'editinline' => 1,
+ ),
+ 'latestlog' => array( __( 'Latest Log', 'zero-bs-crm' ) ),
+ 'tagged' => array( __( 'Tagged', 'zero-bs-crm' ) ),
+ 'editlink' => array( __( 'View', 'zero-bs-crm' ) ),
+ 'editdirectlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+ 'phonelink' => array( __( 'Phone Link', 'zero-bs-crm' ) ),
+
+ 'lastcontacted' => array( __( 'Last Contacted', 'zero-bs-crm' ) ),
+
+ 'company' => array( __( 'Company', 'zero-bs-crm' ) ),
+
+);
- #{ Wh NOTE: this should all be in 1 global, messy to ahve them all separate! }
-
-
-/* ======================================================
- Hard Coded Columns for each list view (UI2.0)
- (Defaults which can be overriden by custom views)
- ====================================================== */
-
- /*
- // LABEL, column ??, grouping (in column manager)
- array('LABEL','zbsDefault_column_customerid','basefield')
-
- */
-
-
- /* ======================================================================================================
- ======================== Customers
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_customer;
-
- $zeroBSCRM_columns_customer = array();
- $zeroBSCRM_columns_customer['default'] = array(
-
-
- 'id' => array('ID',false,'basefield'),
- 'nameavatar' => array(__('Name and Avatar',"zero-bs-crm")),
- //'email' => array('Email','zbsDefault_column_customeremail'),
- 'status' => array(__('Status',"zero-bs-crm"),false,'basefield','editinline'=>1),
- 'totalvalue' => array(__('Total Value',"zero-bs-crm")),
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield')
- );
-
- $zeroBSCRM_columns_customer['all'] = array(
-
- 'id' => array('ID',false,'basefield'),
- 'name' => array(__('Name',"zero-bs-crm"),false,'basefield'),
- 'nameavatar' => array(__('Name and Avatar',"zero-bs-crm")),
- 'email' => array(__('Email',"zero-bs-crm"),false,'basefield'),
- 'status' => array(__('Status',"zero-bs-crm"),false,'basefield','editinline'=>1),
-
- 'hasquote' => array(__('Has Quote',"zero-bs-crm")),
- 'hasinvoice' => array(__('Has Invoice',"zero-bs-crm")),
- 'hastransaction' => array(__('Has Transaction',"zero-bs-crm")),
-
- 'quotecount' => array(__('Quote Count',"zero-bs-crm")),
- 'invoicecount' => array(__('Invoice Count',"zero-bs-crm")),
- 'transactioncount' => array(__('Transaction Count',"zero-bs-crm")),
-
- 'quotetotal' => array(__('Quotes Total',"zero-bs-crm")),
- 'invoicetotal' => array(__('Invoices Total',"zero-bs-crm")),
- 'transactiontotal' => array(__('Transactions Total',"zero-bs-crm")),
-
- 'totalvalue' => array(__('Total Value',"zero-bs-crm")),
-
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield'),
- 'lastupdated' => array(__('Last Updated',"zero-bs-crm"),false,'basefield'),
- 'assigned' => array(__('Assigned To',"zero-bs-crm"),false,'basefield','editinline'=>1),
- 'latestlog' => array(__('Latest Log',"zero-bs-crm")),
- 'tagged' => array(__('Tagged',"zero-bs-crm")),
- 'editlink' => array(__('View',"zero-bs-crm")),
- 'editdirectlink' => array(__('Edit',"zero-bs-crm")),
- 'phonelink' => array(__('Phone Link',"zero-bs-crm")),
-
- 'lastcontacted' => array(__('Last Contacted',"zero-bs-crm")),
-
- 'company' => array(__('Company','zero-bs-crm')),
-
- );
-
- /**
- * Corrects label for 'Company' (could be Organisation) after the settings have loaded.
- * Clunky workaround for now
- */
- add_action( 'after_zerobscrm_settings_preinit', 'jpcrm_list_columns_correct_labels', 10);
- function jpcrm_list_columns_correct_labels(){
-
- global $zeroBSCRM_columns_customer;
-
- $zeroBSCRM_columns_customer['all']['company'] = array(jpcrm_label_company());
-
- }
-
- /* ======================================================================================================
- ======================== / Customers
- ===================================================================================================== */
-
- /* ======================================================================================================
- ======================== Companies
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_company;
-
- $zeroBSCRM_columns_company = array();
- $zeroBSCRM_columns_company['default'] = array(
-
-
- 'id' => array('ID',false,'basefield'),
- 'name' => array(__('Name',"zero-bs-crm"),false,'basefield'),
- 'status' => array(__('Status',"zero-bs-crm"),false,'basefield'),
- 'contacts' => array(__('Contacts',"zero-bs-crm")),
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield'),
- 'viewlink' => array(__('View',"zero-bs-crm"))
- );
-
- $zeroBSCRM_columns_company['all'] = array(
-
-
- 'id' => array('ID',false,'basefield'),
- 'name' => array(__('Name',"zero-bs-crm"),false,'basefield'),
- 'email' => array(__('Email',"zero-bs-crm"),false,'basefield'),
- 'status' => array(__('Status',"zero-bs-crm"),false,'basefield'),
-
-
- 'hasinvoice' => array(__('Has Invoice',"zero-bs-crm")),
- 'hastransaction' => array(__('Has Transaction',"zero-bs-crm")),
-
- 'invoicecount' => array(__('Invoice Count',"zero-bs-crm")),
- 'transactioncount' => array(__('Transaction Count',"zero-bs-crm")),
-
- 'invoicetotal' => array(__('Invoices Total',"zero-bs-crm")),
- 'transactiontotal' => array(__('Transactions Total',"zero-bs-crm")),
-
- // When Company<->Quotes:
- //'hasquote' => array(__('Has Quote',"zero-bs-crm")),
- //'quotecount' => array(__('Quote Count',"zero-bs-crm")),
- //'quotetotal' => array(__('Quotes Total',"zero-bs-crm")),
-
- 'totalvalue' => array(__('Total Value',"zero-bs-crm")),
-
- 'contacts' => array(__('Contacts',"zero-bs-crm")),
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield'),
- 'lastupdated' => array(__('Last Updated',"zero-bs-crm"),false,'basefield'),
- 'viewlink' => array(__('View',"zero-bs-crm")),
- 'editlink' => array(__('Edit',"zero-bs-crm")),
- 'assigned' => array(__('Assigned To',"zero-bs-crm"),false,'basefield'),
- 'tagged' => array(__(__('Tagged',"zero-bs-crm"),"zero-bs-crm")),
- 'phonelink' => array(__('Phone Link',"zero-bs-crm")),
- // Should this be in company? (removed 04/9/18, don't think wired up) ''latestlog' => array(__('Latest Log',"zero-bs-crm")),
- // Should this be in company? (removed 04/9/18, don't think wired up) 'lastcontacted' => array(__('Last Contacted',"zero-bs-crm")),
-
- );
-
- /* ======================================================================================================
- ======================== / Companies
- ===================================================================================================== */
-
- /* ======================================================================================================
- ======================== Quotes
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_quote;
-
- $zeroBSCRM_columns_quote = array();
- $zeroBSCRM_columns_quote['default'] = array(
- 'id' => array('ID',false,'basefield'),
- 'title' => array(__('Quote Title','zero-bs-crm'),false,'basefield'),
- 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ), // phpcs:ignore WordPress.Arrays.ArrayIndentation.ItemNotAligned -- impossible to fix without fixing everything else.
- 'status' => array(__('Status','zero-bs-crm'),false,'basefield'),
- 'value' => array(__('Quote Value',"zero-bs-crm"),false,'basefield'),
- 'editlink' => array(__('Edit',"zero-bs-crm"))
-
-
- );
-
- $zeroBSCRM_columns_quote['all'] = array(
- 'id' => array('ID',false,'basefield'),
- 'title' => array(__('Quote Title','zero-bs-crm'),false,'basefield'),
- 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ), // phpcs:ignore WordPress.Arrays.ArrayIndentation.ItemNotAligned -- impossible to fix without fixing everything else.
- 'status' => array(__('Status','zero-bs-crm'),false,'basefield'),
- 'value' => array(__('Quote Value',"zero-bs-crm"),false,'basefield'),
- 'editlink' => array(__('Edit',"zero-bs-crm")),
- // not user-configurable, so disabling for now
- //'assignedobj' => array(__('Assigned To',"zero-bs-crm"),false,'basefield'),
- );
-
- /* ======================================================================================================
- ======================== / Quotes
- ===================================================================================================== */
-
-
- /* ======================================================================================================
- ======================== Invoices
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_invoice;
-
- $zeroBSCRM_columns_invoice = array();
- $zeroBSCRM_columns_invoice['default'] = array(
- 'id' => array('ID',false,'basefield'),
-
- 'ref' => array(__('Reference','zero-bs-crm'),false,'basefield'),
- 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ), // phpcs:ignore WordPress.Arrays.ArrayIndentation.ItemNotAligned -- impossible to fix without fixing everything else.
- 'status' => array(__('Status','zero-bs-crm'),false,'basefield'),
- 'value' => array(__('Value',"zero-bs-crm"),false,'basefield'),
- 'date' => array(__('Date',"zero-bs-crm"),false,'basefield'),
- 'editlink' => array(__('Edit',"zero-bs-crm"))
- );
-
- $zeroBSCRM_columns_invoice['all'] = array( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase,Generic.WhiteSpace.ScopeIndent.Incorrect
- 'id' => array('ID',false,'basefield'),
- 'ref' => array(__('Reference','zero-bs-crm'),false,'basefield'),
- 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ), // phpcs:ignore WordPress.Arrays.ArrayIndentation.ItemNotAligned -- impossible to fix without fixing everything else.
- 'status' => array(__('Status','zero-bs-crm'),false,'basefield'),
- 'value' => array(__('Value',"zero-bs-crm"),false,'basefield'),
- 'date' => array(__('Date',"zero-bs-crm"),false,'basefield'),
- 'due' => array(__('Due date',"zero-bs-crm"),false,'basefield'),
-
- 'editlink' => array(__('Edit',"zero-bs-crm")),
-
- // not user-configurable, so disabling for now
- //'assignedobj' => array(__('Assigned To',"zero-bs-crm"),false,'basefield'),
-
- );
-
-
- /* ======================================================================================================
- ======================== / Invoices
- ===================================================================================================== */
-
-
-
-/* ======================================================================================================
- ======================== Transactions
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_transaction;
-
- $zeroBSCRM_columns_transaction = array();
- $zeroBSCRM_columns_transaction['default'] = array( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
- 'id' => array('ID','zbsDefault_column_customerid','basefield'),
- 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ), // phpcs:ignore WordPress.Arrays.ArrayIndentation.ItemNotAligned -- impossible to fix without fixing everything else.
- 'status' => array(__('Status',"zero-bs-crm"),false,'basefield'),
- 'total' => array(__('Value',"zero-bs-crm"),false,'basefield'),
- 'item' => array(__('Item',"zero-bs-crm"),false,'basefield'),
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield'),
- 'editlink' => array(__('Edit Link',"zero-bs-crm"))
-
- );
-
- $zeroBSCRM_columns_transaction['all'] = array(
- 'id' => array('ID','zbsDefault_column_customerid','basefield'),
- 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ), // phpcs:ignore WordPress.Arrays.ArrayIndentation.ItemNotAligned -- impossible to fix without fixing everything else.
- 'customeremail' => array(__('Email',"zero-bs-crm")),
- 'tagged' => array(__(__('Tagged',"zero-bs-crm"),"zero-bs-crm")),
- 'status' => array(__('Status',"zero-bs-crm"),false,'basefield'),
- 'total' => array(__('Value',"zero-bs-crm"),false,'basefield'),
- 'item' => array(__('Item',"zero-bs-crm"),false,'basefield'),
-
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield'),
- 'editlink' => array(__('Edit Link',"zero-bs-crm")),
- 'external_source' => array(__('External Source',"zero-bs-crm")),
-
- // not user-configurable, so disabling for now
- //'assignedobj' => array(__('Assigned To',"zero-bs-crm"),false,'basefield'),
-
- );
-
- /* ======================================================================================================
- ======================== / Transactions
- ===================================================================================================== */
-
-
-/* ======================================================================================================
- ======================== Forms
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_form;
-
- $zeroBSCRM_columns_form = array();
- $zeroBSCRM_columns_form['default'] = array(
- 'id' => array('ID',false,'basefield'),
- 'title' => array(__('Title','zero-bs-crm'),false,'basefield'),
- 'style' => array(__('Style',"zero-bs-crm"),false,'basefield'),
- 'views' => array(__('Views',"zero-bs-crm")),
- 'conversions' => array(__('Conversions',"zero-bs-crm")),
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield'),
- 'editlink' => array(__('Edit',"zero-bs-crm"))
- );
-
- $zeroBSCRM_columns_form['all'] = array(
- 'id' => array('ID',false,'basefield'),
- 'title' => array(__('Title','zero-bs-crm'),false,'basefield'),
- 'style' => array(__('Style',"zero-bs-crm"),false,'basefield'),
- 'views' => array(__('Views',"zero-bs-crm")),
- 'conversions' => array(__('Conversions',"zero-bs-crm")),
- 'added' => array(__('Added',"zero-bs-crm"),false,'basefield'),
- 'editlink' => array(__('Edit',"zero-bs-crm"))
- );
-
- /* ======================================================================================================
- ======================== / Forms
- ===================================================================================================== */
-
- /* ======================================================================================================
- ======================== Segments
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_segment;
-
- $zeroBSCRM_columns_segment = array();
- $zeroBSCRM_columns_segment['default'] = array(
- 'id' => array('ID',false,'basefield'),
- 'name' => array(__('Name','zero-bs-crm'),false,'basefield'),
- 'audiencecount' => array(__('Contact Count','zero-bs-crm')),
- 'action' => array(__('Action','zero-bs-crm'))
- );
-
- $zeroBSCRM_columns_segment['all'] = array(
- 'id' => array('ID',false,'basefield'),
- 'name' => array(__('Name','zero-bs-crm'),false,'basefield'),
- 'audiencecount' => array(__('Contact Count','zero-bs-crm')),
- 'action' => array(__('Action','zero-bs-crm')),
- 'added' => array(__('Added','zero-bs-crm'))
-
- );
-
-
-
- /* ======================================================================================================
- ======================== / Segments
- ===================================================================================================== */
-
- /* ======================================================================================================
- ======================== Quote Templates
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_quotetemplate;
-
- $zeroBSCRM_columns_quotetemplate = array();
- $zeroBSCRM_columns_quotetemplate['default'] = array(
-
-
- 'id' => array('ID',false,'basefield'),
- 'title' => array(__('Title','zero-bs-crm'),false,'basefield'),
- 'action' => array(__('Action','zero-bs-crm'))
- );
-
- $zeroBSCRM_columns_quotetemplate['all'] = array(
-
-
- 'id' => array('ID',false,'basefield'),
- 'title' => array(__('Title','zero-bs-crm'),false,'basefield'),
- 'action' => array(__('Action','zero-bs-crm'))
-
- );
-
-
-
- /* ======================================================================================================
- ======================== / Quote Templates
- ===================================================================================================== */
-
- /* ======================================================================================================
- ======================== Tasks
- ===================================================================================================== */
-
-
- global $zeroBSCRM_columns_event;
-
- $zeroBSCRM_columns_event = array();
- $zeroBSCRM_columns_event['default'] = array(
-
-
- 'id' => array('ID',false,'basefield'),
- 'title' => array( __('Name','zero-bs-crm'), false, 'basefield' ),
- 'start' => array( __('Starting', 'zero-bs-crm' ) ),
- 'end' => array( __('Finishing', 'zero-bs-crm' ) ),
- 'status' => array( __('Status', 'zero-bs-crm' ) ),
- 'assigned' => array(__('Assigned To',"zero-bs-crm"), false, 'basefield' ),
- 'action' => array( __('Action', 'zero-bs-crm') )
- );
-
- $zeroBSCRM_columns_event['all'] = array(
-
- 'id' => array('ID',false,'basefield'),
- 'title' => array( __('Name','zero-bs-crm'), false, 'basefield' ),
- 'desc' => array( __('Description', 'zero-bs-crm' ) ),
- 'start' => array( __('Starting', 'zero-bs-crm' ) ),
- 'end' => array( __('Finishing', 'zero-bs-crm' ) ),
- 'status' => array( __('Status', 'zero-bs-crm' ) ),
- 'remind' => array( __('Reminder', 'zero-bs-crm' ) ),
- 'showcal' => array( __('Show on Cal', 'zero-bs-crm' ) ),
- //'showportal' => array( __('Show on Portal', 'zero-bs-crm' ) ),
- 'contact' => array( __('Contact', 'zero-bs-crm' ) ),
- 'company' => array( __('Company', 'zero-bs-crm' ) ),
- 'assigned' => array(__('Assigned To',"zero-bs-crm"), false, 'basefield' ),
- 'action' => array( __('Action', 'zero-bs-crm') )
-
- );
-
-
-
- /* ======================================================================================================
- ======================== / Tasks
- ===================================================================================================== */
+/**
+ * Corrects label for 'Company' (could be Organisation) after the settings have loaded.
+ * Clunky workaround for now
+ */
+add_action( 'after_zerobscrm_settings_preinit', 'jpcrm_list_columns_correct_labels', 10 );
+function jpcrm_list_columns_correct_labels() {
+
+ global $zeroBSCRM_columns_customer;
+
+ $zeroBSCRM_columns_customer['all']['company'] = array( jpcrm_label_company() );
+}
+
+/*
+======================================================================================================
+ ======================== / Customers
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Companies
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_company;
+
+$zeroBSCRM_columns_company = array();
+$zeroBSCRM_columns_company['default'] = array(
+
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'name' => array( __( 'Name', 'zero-bs-crm' ), false, 'basefield' ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+ 'contacts' => array( __( 'Contacts', 'zero-bs-crm' ) ),
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+ 'viewlink' => array( __( 'View', 'zero-bs-crm' ) ),
+);
+
+$zeroBSCRM_columns_company['all'] = array(
+
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'name' => array( __( 'Name', 'zero-bs-crm' ), false, 'basefield' ),
+ 'email' => array( __( 'Email', 'zero-bs-crm' ), false, 'basefield' ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+
+ 'hasinvoice' => array( __( 'Has Invoice', 'zero-bs-crm' ) ),
+ 'hastransaction' => array( __( 'Has Transaction', 'zero-bs-crm' ) ),
+
+ 'invoicecount' => array( __( 'Invoice Count', 'zero-bs-crm' ) ),
+ 'transactioncount' => array( __( 'Transaction Count', 'zero-bs-crm' ) ),
+
+ 'invoicetotal' => array( __( 'Invoices Total', 'zero-bs-crm' ) ),
+ 'transactiontotal' => array( __( 'Transactions Total', 'zero-bs-crm' ) ),
+
+ // When Company<->Quotes:
+ // 'hasquote' => array(__('Has Quote',"zero-bs-crm")),
+ // 'quotecount' => array(__('Quote Count',"zero-bs-crm")),
+ // 'quotetotal' => array(__('Quotes Total',"zero-bs-crm")),
+
+ 'totalvalue' => array( __( 'Total Value', 'zero-bs-crm' ) ),
+
+ 'contacts' => array( __( 'Contacts', 'zero-bs-crm' ) ),
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+ 'lastupdated' => array( __( 'Last Updated', 'zero-bs-crm' ), false, 'basefield' ),
+ 'viewlink' => array( __( 'View', 'zero-bs-crm' ) ),
+ 'editlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+ 'assigned' => array( __( 'Assigned To', 'zero-bs-crm' ), false, 'basefield' ),
+ 'tagged' => array( __( __( 'Tagged', 'zero-bs-crm' ), 'zero-bs-crm' ) ),
+ 'phonelink' => array( __( 'Phone Link', 'zero-bs-crm' ) ),
+ // Should this be in company? (removed 04/9/18, don't think wired up) ''latestlog' => array(__('Latest Log',"zero-bs-crm")),
+ // Should this be in company? (removed 04/9/18, don't think wired up) 'lastcontacted' => array(__('Last Contacted',"zero-bs-crm")),
+
+);
+
+/*
+======================================================================================================
+ ======================== / Companies
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Quotes
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_quote;
+
+$zeroBSCRM_columns_quote = array();
+$zeroBSCRM_columns_quote['default'] = array(
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Quote Title', 'zero-bs-crm' ), false, 'basefield' ),
+ 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+ 'value' => array( __( 'Quote Value', 'zero-bs-crm' ), false, 'basefield' ),
+ 'editlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+
+);
+
+$zeroBSCRM_columns_quote['all'] = array(
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Quote Title', 'zero-bs-crm' ), false, 'basefield' ),
+ 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+ 'value' => array( __( 'Quote Value', 'zero-bs-crm' ), false, 'basefield' ),
+ 'editlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+ // not user-configurable, so disabling for now
+ // 'assignedobj' => array(__('Assigned To',"zero-bs-crm"),false,'basefield'),
+);
+
+/*
+======================================================================================================
+ ======================== / Quotes
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Invoices
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_invoice;
+
+$zeroBSCRM_columns_invoice = array();
+$zeroBSCRM_columns_invoice['default'] = array(
+ 'id' => array( 'ID', false, 'basefield' ),
+
+ 'ref' => array( __( 'Reference', 'zero-bs-crm' ), false, 'basefield' ),
+ 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+ 'value' => array( __( 'Value', 'zero-bs-crm' ), false, 'basefield' ),
+ 'date' => array( __( 'Date', 'zero-bs-crm' ), false, 'basefield' ),
+ 'editlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+);
+
+$zeroBSCRM_columns_invoice['all'] = array( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'ref' => array( __( 'Reference', 'zero-bs-crm' ), false, 'basefield' ),
+ 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+ 'value' => array( __( 'Value', 'zero-bs-crm' ), false, 'basefield' ),
+ 'date' => array( __( 'Date', 'zero-bs-crm' ), false, 'basefield' ),
+ 'due' => array( __( 'Due date', 'zero-bs-crm' ), false, 'basefield' ),
+
+ 'editlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+
+ // not user-configurable, so disabling for now
+ // 'assignedobj' => array(__('Assigned To',"zero-bs-crm"),false,'basefield'),
+);
+
+/*
+======================================================================================================
+ ======================== / Invoices
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Transactions
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_transaction;
+
+$zeroBSCRM_columns_transaction = array();
+$zeroBSCRM_columns_transaction['default'] = array( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
+ 'id' => array( 'ID', 'zbsDefault_column_customerid', 'basefield' ),
+ 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+ 'total' => array( __( 'Value', 'zero-bs-crm' ), false, 'basefield' ),
+ 'item' => array( __( 'Item', 'zero-bs-crm' ), false, 'basefield' ),
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+ 'editlink' => array( __( 'Edit Link', 'zero-bs-crm' ) ),
+);
+
+$zeroBSCRM_columns_transaction['all'] = array(
+ 'id' => array( 'ID', 'zbsDefault_column_customerid', 'basefield' ),
+ 'customer' => array( __( 'Contact', 'zero-bs-crm' ) ),
+ 'customeremail' => array( __( 'Email', 'zero-bs-crm' ) ),
+ 'tagged' => array( __( __( 'Tagged', 'zero-bs-crm' ), 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ), false, 'basefield' ),
+ 'total' => array( __( 'Value', 'zero-bs-crm' ), false, 'basefield' ),
+ 'item' => array( __( 'Item', 'zero-bs-crm' ), false, 'basefield' ),
+
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+ 'editlink' => array( __( 'Edit Link', 'zero-bs-crm' ) ),
+ 'external_source' => array( __( 'External Source', 'zero-bs-crm' ) ),
+
+ // not user-configurable, so disabling for now
+ // 'assignedobj' => array(__('Assigned To',"zero-bs-crm"),false,'basefield'),
+
+);
+
+/*
+======================================================================================================
+ ======================== / Transactions
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Forms
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_form;
+
+$zeroBSCRM_columns_form = array();
+$zeroBSCRM_columns_form['default'] = array(
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Title', 'zero-bs-crm' ), false, 'basefield' ),
+ 'style' => array( __( 'Style', 'zero-bs-crm' ), false, 'basefield' ),
+ 'views' => array( __( 'Views', 'zero-bs-crm' ) ),
+ 'conversions' => array( __( 'Conversions', 'zero-bs-crm' ) ),
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+ 'editlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+);
+
+$zeroBSCRM_columns_form['all'] = array(
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Title', 'zero-bs-crm' ), false, 'basefield' ),
+ 'style' => array( __( 'Style', 'zero-bs-crm' ), false, 'basefield' ),
+ 'views' => array( __( 'Views', 'zero-bs-crm' ) ),
+ 'conversions' => array( __( 'Conversions', 'zero-bs-crm' ) ),
+ 'added' => array( __( 'Added', 'zero-bs-crm' ), false, 'basefield' ),
+ 'editlink' => array( __( 'Edit', 'zero-bs-crm' ) ),
+);
+
+/*
+======================================================================================================
+ ======================== / Forms
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Segments
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_segment;
+
+$zeroBSCRM_columns_segment = array();
+$zeroBSCRM_columns_segment['default'] = array(
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'name' => array( __( 'Name', 'zero-bs-crm' ), false, 'basefield' ),
+ 'audiencecount' => array( __( 'Contact Count', 'zero-bs-crm' ) ),
+ 'action' => array( __( 'Action', 'zero-bs-crm' ) ),
+);
+
+$zeroBSCRM_columns_segment['all'] = array(
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'name' => array( __( 'Name', 'zero-bs-crm' ), false, 'basefield' ),
+ 'audiencecount' => array( __( 'Contact Count', 'zero-bs-crm' ) ),
+ 'action' => array( __( 'Action', 'zero-bs-crm' ) ),
+ 'added' => array( __( 'Added', 'zero-bs-crm' ) ),
+
+);
+
+/*
+======================================================================================================
+ ======================== / Segments
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Quote Templates
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_quotetemplate;
+
+$zeroBSCRM_columns_quotetemplate = array();
+$zeroBSCRM_columns_quotetemplate['default'] = array(
+
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Title', 'zero-bs-crm' ), false, 'basefield' ),
+ 'action' => array( __( 'Action', 'zero-bs-crm' ) ),
+);
+
+$zeroBSCRM_columns_quotetemplate['all'] = array(
+
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Title', 'zero-bs-crm' ), false, 'basefield' ),
+ 'action' => array( __( 'Action', 'zero-bs-crm' ) ),
+
+);
+
+/*
+======================================================================================================
+ ======================== / Quote Templates
+ ===================================================================================================== */
+
+/*
+======================================================================================================
+ ======================== Tasks
+ ===================================================================================================== */
+
+global $zeroBSCRM_columns_event;
+
+$zeroBSCRM_columns_event = array();
+$zeroBSCRM_columns_event['default'] = array(
+
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Name', 'zero-bs-crm' ), false, 'basefield' ),
+ 'start' => array( __( 'Starting', 'zero-bs-crm' ) ),
+ 'end' => array( __( 'Finishing', 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ) ),
+ 'assigned' => array( __( 'Assigned To', 'zero-bs-crm' ), false, 'basefield' ),
+ 'action' => array( __( 'Action', 'zero-bs-crm' ) ),
+);
+
+$zeroBSCRM_columns_event['all'] = array(
+
+ 'id' => array( 'ID', false, 'basefield' ),
+ 'title' => array( __( 'Name', 'zero-bs-crm' ), false, 'basefield' ),
+ 'desc' => array( __( 'Description', 'zero-bs-crm' ) ),
+ 'start' => array( __( 'Starting', 'zero-bs-crm' ) ),
+ 'end' => array( __( 'Finishing', 'zero-bs-crm' ) ),
+ 'status' => array( __( 'Status', 'zero-bs-crm' ) ),
+ 'remind' => array( __( 'Reminder', 'zero-bs-crm' ) ),
+ 'showcal' => array( __( 'Show on Cal', 'zero-bs-crm' ) ),
+ // 'showportal' => array( __('Show on Portal', 'zero-bs-crm' ) ),
+ 'contact' => array( __( 'Contact', 'zero-bs-crm' ) ),
+ 'company' => array( __( 'Company', 'zero-bs-crm' ) ),
+ 'assigned' => array( __( 'Assigned To', 'zero-bs-crm' ), false, 'basefield' ),
+ 'action' => array( __( 'Action', 'zero-bs-crm' ) ),
+
+);
+
+/*
+======================================================================================================
+ ======================== / Tasks
+ ===================================================================================================== */
-// phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect, Generic.WhiteSpace.ScopeIndent.IncorrectExact
/**
* Unpacks listview settings
*/
function zeroBSCRM_unpackListViewSettings() {
- // ALL FIELD TYPES
- global $zeroBSCRM_columns_customer, $zbsCustomerFields;
- global $zeroBSCRM_columns_company, $zbsCompanyFields;
- global $zeroBSCRM_columns_quote, $zbsCustomerQuoteFields;
- global $zeroBSCRM_columns_invoice, $zbsCustomerInvoiceFields;
- global $zeroBSCRM_columns_transaction, $zbsTransactionFields;
- global $zeroBSCRM_columns_form, $zbsFormFields;
-
- $useSecondAddress = zeroBSCRM_getSetting('secondaddress');
- $second_address_label = zeroBSCRM_getSetting( 'secondaddresslabel' );
- if ( empty( $second_address_label ) ) {
- $second_address_label = __( 'Second Address', 'zero-bs-crm' );
- }
-
- // Cycle through each + add
- $mappings = array(
-
- 'zeroBSCRM_columns_customer' => 'zbsCustomerFields',
- 'zeroBSCRM_columns_company' => 'zbsCompanyFields',
- 'zeroBSCRM_columns_quote' => 'zbsCustomerQuoteFields', // not sure why naming convention lost here
- 'zeroBSCRM_columns_invoice' => 'zbsCustomerInvoiceFields', // not sure why naming convention lost here
- 'zeroBSCRM_columns_transaction' => 'zbsTransactionFields',
- 'zeroBSCRM_columns_form' => 'zbsFormFields',
-
- );
-
- foreach ($mappings as $columnsObjName => $fieldsObjName){
-
- // add all normal fields to columns (DAL2) from 2.95
- if (is_array(${$fieldsObjName}) && count(${$fieldsObjName}) > 0){
- foreach (${$fieldsObjName} as $fKey => $fDetail){
- if (!isset(${$columnsObjName}['all'][$fKey])){
-
- // some need hiding (just for api/behind scenes:)
- $hideCol = false; if (is_array($fDetail) && isset($fDetail['nocolumn']) && $fDetail['nocolumn']) $hideCol = true;
-
- if (!$hideCol){
-
- $skip = false; // skip addr 2 if off
-
- // add it
- $cfTitle = $fKey; if (is_array($fDetail) && isset($fDetail[1])) $cfTitle = $fDetail[1];
-
- // secaddr get's dealt with:
- if ( str_starts_with( $fKey, 'secaddr_' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
- $cfTitle .= ' (' . esc_html( $second_address_label ) . ')';
- if ($useSecondAddress !== 1) $skip = true;
- }
-
- if (!$skip) ${$columnsObjName}['all'][$fKey] = array($cfTitle,false,'basefield'); // note adding as basefield :)
- }
-
- }
- }
- }
-
- }
-
- // Auto-add 'edit link' to quotes invs (somehow it wasn't always adding)
- $customviews2 = zeroBSCRM_getSetting('customviews2'); $cv2Changed = false;
- if (isset($customviews2['quote']) && !array_key_exists('editlink', $customviews2['quote'])){
-
- // add it
- $customviews2['quote']['editlink'] = array(__('Edit',"zero-bs-crm"));
- $cv2Changed = true;
-
- }
- if (isset($customviews2['invoice']) && !array_key_exists('editlink', $customviews2['invoice'])){
-
- // add it
- $customviews2['invoice']['editlink'] = array(__('Edit',"zero-bs-crm"));
- $cv2Changed = true;
-
- }
- if ($cv2Changed && is_array($customviews2)){
-
- // Save setting
- global $zbs;
- return $zbs->settings->update('customviews2',$customviews2);
-
-
- }
-
-
- }
-
-// phpcs:enable Generic.WhiteSpace.ScopeIndent.Incorrect, Generic.WhiteSpace.ScopeIndent.IncorrectExact
+ // ALL FIELD TYPES
+ global $zeroBSCRM_columns_customer, $zbsCustomerFields;
+ global $zeroBSCRM_columns_company, $zbsCompanyFields;
+ global $zeroBSCRM_columns_quote, $zbsCustomerQuoteFields;
+ global $zeroBSCRM_columns_invoice, $zbsCustomerInvoiceFields;
+ global $zeroBSCRM_columns_transaction, $zbsTransactionFields;
+ global $zeroBSCRM_columns_form, $zbsFormFields;
+
+ $useSecondAddress = zeroBSCRM_getSetting( 'secondaddress' );
+ $second_address_label = zeroBSCRM_getSetting( 'secondaddresslabel' );
+ if ( empty( $second_address_label ) ) {
+ $second_address_label = __( 'Second Address', 'zero-bs-crm' );
+ }
+
+ // Cycle through each + add
+ $mappings = array(
+
+ 'zeroBSCRM_columns_customer' => 'zbsCustomerFields',
+ 'zeroBSCRM_columns_company' => 'zbsCompanyFields',
+ 'zeroBSCRM_columns_quote' => 'zbsCustomerQuoteFields', // not sure why naming convention lost here
+ 'zeroBSCRM_columns_invoice' => 'zbsCustomerInvoiceFields', // not sure why naming convention lost here
+ 'zeroBSCRM_columns_transaction' => 'zbsTransactionFields',
+ 'zeroBSCRM_columns_form' => 'zbsFormFields',
+
+ );
+
+ foreach ( $mappings as $columnsObjName => $fieldsObjName ) {
+
+ // add all normal fields to columns (DAL2) from 2.95
+ if ( is_array( ${$fieldsObjName} ) && count( ${$fieldsObjName} ) > 0 ) {
+ foreach ( ${$fieldsObjName} as $fKey => $fDetail ) {
+ if ( ! isset( ${$columnsObjName}['all'][ $fKey ] ) ) {
+
+ // some need hiding (just for api/behind scenes:)
+ $hideCol = false;
+ if ( is_array( $fDetail ) && isset( $fDetail['nocolumn'] ) && $fDetail['nocolumn'] ) {
+ $hideCol = true;
+ }
+
+ if ( ! $hideCol ) {
+
+ $skip = false; // skip addr 2 if off
+
+ // add it
+ $cfTitle = $fKey;
+ if ( is_array( $fDetail ) && isset( $fDetail[1] ) ) {
+ $cfTitle = $fDetail[1];
+ }
+
+ // secaddr get's dealt with:
+ if ( str_starts_with( $fKey, 'secaddr_' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
+ $cfTitle .= ' (' . esc_html( $second_address_label ) . ')';
+ if ( $useSecondAddress !== 1 ) {
+ $skip = true;
+ }
+ }
+
+ if ( ! $skip ) {
+ ${$columnsObjName}['all'][ $fKey ] = array( $cfTitle, false, 'basefield' ); // note adding as basefield :)
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Auto-add 'edit link' to quotes invs (somehow it wasn't always adding)
+ $customviews2 = zeroBSCRM_getSetting( 'customviews2' );
+ $cv2Changed = false;
+ if ( isset( $customviews2['quote'] ) && ! array_key_exists( 'editlink', $customviews2['quote'] ) ) {
+
+ // add it
+ $customviews2['quote']['editlink'] = array( __( 'Edit', 'zero-bs-crm' ) );
+ $cv2Changed = true;
+
+ }
+ if ( isset( $customviews2['invoice'] ) && ! array_key_exists( 'editlink', $customviews2['invoice'] ) ) {
+
+ // add it
+ $customviews2['invoice']['editlink'] = array( __( 'Edit', 'zero-bs-crm' ) );
+ $cv2Changed = true;
+
+ }
+ if ( $cv2Changed && is_array( $customviews2 ) ) {
+
+ // Save setting
+ global $zbs;
+ return $zbs->settings->update( 'customviews2', $customviews2 );
+
+ }
+}
diff --git a/projects/plugins/crm/includes/ZeroBSCRM.List.php b/projects/plugins/crm/includes/ZeroBSCRM.List.php
index aeaa6e76a851..861199e0970f 100644
--- a/projects/plugins/crm/includes/ZeroBSCRM.List.php
+++ b/projects/plugins/crm/includes/ZeroBSCRM.List.php
@@ -1,5 +1,5 @@
-objType) || empty($this->postType) || empty($this->postPage) || empty($this->singular) || empty($this->plural)){
+ if ( empty( $this->objType ) || empty( $this->postType ) || empty( $this->postPage ) || empty( $this->singular ) || empty( $this->plural ) ) {
- return 'Error.';
- }
-
- global $zbs;
+ return 'Error.';
+ }
+ global $zbs;
- #} Retrieve all passed filters (tags, etc.)
- $listViewFilters = array(); if (isset($_GET['zbs_tag'])){
+ #} Retrieve all passed filters (tags, etc.)
+ $listViewFilters = array(); if ( isset( $_GET['zbs_tag'] ) ) {
- $possibleTag = (int)sanitize_text_field($_GET['zbs_tag']);
+ $possibleTag = (int) sanitize_text_field( $_GET['zbs_tag'] );
$possibleTagObj = $zbs->DAL->getTag( $possibleTag, array( 'objtype' => $this->objTypeID ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase,WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( isset( $possibleTagObj['id'] ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
$listViewFilters['tags'] = array( $possibleTagObj ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
}
- }
- if (isset($_GET['s']) && !empty($_GET['s'])){
+ }
+ if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
- $listViewFilters['s'] = sanitize_text_field($_GET['s']);
+ $listViewFilters['s'] = sanitize_text_field( $_GET['s'] );
- }
- if (isset($_GET['quickfilters']) && !empty($_GET['quickfilters'])){
+ }
+ if ( isset( $_GET['quickfilters'] ) && ! empty( $_GET['quickfilters'] ) ) {
- // set it whether legit? what'll this do on error urls people make up?
- // v2.2+ hone this + add multi-filter
- // v2.99.5 - ALWAYS lowercase :)
+ // set it whether legit? what'll this do on error urls people make up?
+ // v2.2+ hone this + add multi-filter
+ // v2.99.5 - ALWAYS lowercase :)
$possible_quick_filters = sanitize_text_field( $_GET['quickfilters'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$listViewFilters['quickfilters'] = array( $possible_quick_filters ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
- }
-
-
- #} Paging
- $currentPage = 1; if (isset($_GET['paged'])) $currentPage = (int)sanitize_text_field($_GET['paged']);
-
- #} Sort
- $sort = false; if (isset($_GET['sort']) && !empty($_GET['sort'])) $sort = sanitize_text_field($_GET['sort']);
- $sortOrder = false; if (isset($_GET['sortdirection']) && ($_GET['sortdirection'] == 'asc' || $_GET['sortdirection'] == 'desc')) $sortOrder = sanitize_text_field($_GET['sortdirection']);
+ }
+ #} Paging
+ $currentPage = 1;
+ if ( isset( $_GET['paged'] ) ) {
+ $currentPage = (int) sanitize_text_field( $_GET['paged'] );
+ }
- # SCAFFOLDING - TO BE RE-ARRANGED :)
- #} NOTE SECOND FIELD IN THESE ARE NOW IGNORED!?!? (30/7)
+ #} Sort
+ $sort = false;
+ if ( isset( $_GET['sort'] ) && ! empty( $_GET['sort'] ) ) {
+ $sort = sanitize_text_field( $_GET['sort'] );
+ }
+ $sortOrder = false;
+ if ( isset( $_GET['sortdirection'] ) && ( $_GET['sortdirection'] == 'asc' || $_GET['sortdirection'] == 'desc' ) ) {
+ $sortOrder = sanitize_text_field( $_GET['sortdirection'] );
+ }
- #} Centralised into ZeroBSCRM.List.Columns.php 30/7/17
- $columnVar = 'zeroBSCRM_columns_'.$this->objType; //$zeroBSCRM_columns_transaction;
- $defaultColumns = $GLOBALS[ $columnVar ]['default'];
- $allColumns = $GLOBALS[ $columnVar ]['all'];
+ # SCAFFOLDING - TO BE RE-ARRANGED :)
+ #} NOTE SECOND FIELD IN THESE ARE NOW IGNORED!?!? (30/7)
+ #} Centralised into ZeroBSCRM.List.Columns.php 30/7/17
+ $columnVar = 'zeroBSCRM_columns_' . $this->objType; // $zeroBSCRM_columns_transaction;
+ $defaultColumns = $GLOBALS[ $columnVar ]['default'];
+ $allColumns = $GLOBALS[ $columnVar ]['all'];
- global $zbs;
- $usingOwnership = $zbs->settings->get('perusercustomers');
+ global $zbs;
+ $usingOwnership = $zbs->settings->get( 'perusercustomers' );
- #} Retrieve columns settings
- $customViews = $zbs->settings->get('customviews2');
+ #} Retrieve columns settings
+ $customViews = $zbs->settings->get( 'customviews2' );
- $currentColumns = false; if (isset($customViews) && isset($customViews[$this->objType])) $currentColumns = $customViews[$this->objType];
- if ($currentColumns == false) $currentColumns = $defaultColumns;
+ $currentColumns = false;
+ if ( isset( $customViews ) && isset( $customViews[ $this->objType ] ) ) {
+ $currentColumns = $customViews[ $this->objType ];
+ }
+ if ( $currentColumns == false ) {
+ $currentColumns = $defaultColumns;
+ }
// add all columns to sortables :)
if ( is_array( $currentColumns ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
@@ -199,132 +209,145 @@ public function drawListView(){
$per_page = 20;
}
- #} Refresh 2
- ?>
+ #} Refresh 2
+ ?>
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
- $col){
+
- ?>
+
- } ?>
-
+
-
-
-
+
+ $col ) {
-
-
+
+ array(),'other'=>array());
- $hasMultiColumnGroups = 0;
+ }
+ }
+ ?>
+
- foreach ($allColumns as $colKey => $col){
+
+
- if (!array_key_exists($colKey, $currentColumns)){
+
- // split em up
- if (isset($col[2]) && $col[2] == 'basefield'){
- $allColumnsSorted['basefields'][$colKey] = $col;
- $hasMultiColumnGroups = true;
- } else
- $allColumnsSorted['other'][$colKey] = $col;
+
+ array(),
+ 'other' => array(),
+ );
+ $hasMultiColumnGroups = 0;
- }
+ foreach ( $allColumns as $colKey => $col ) {
- // now we put them out sequentially
- $colGroupCount = 0;
- foreach ($allColumnsSorted as $sortGroup => $columns){
+ if ( ! array_key_exists( $colKey, $currentColumns ) ) {
- if (is_array($columns) && count($columns) > 0){
+ // split em up
+ if ( isset( $col[2] ) && $col[2] == 'basefield' ) {
+ $allColumnsSorted['basefields'][ $colKey ] = $col;
+ $hasMultiColumnGroups = true;
+ } else {
+ $allColumnsSorted['other'][ $colKey ] = $col;
+ }
+ }
+ }
- // put out a grouper + title
- echo '
';
+ // now we put them out sequentially
+ $colGroupCount = 0;
+ foreach ( $allColumnsSorted as $sortGroup => $columns ) {
- if ($hasMultiColumnGroups){
+ if ( is_array( $columns ) && count( $columns ) > 0 ) {
- // header -
+ // put out a grouper + title
+ echo '
';
- $title = ''; $extraStyles = '';
- switch ($sortGroup){
+ if ( $hasMultiColumnGroups ) {
- case 'basefields':
- $title = __('Fields','zero-bs-crm');
- break;
+ // header -
- default:
- $title = __('Extra Fields','zero-bs-crm');
- break;
- }
+ $title = '';
+ $extraStyles = '';
+ switch ( $sortGroup ) {
- if ($colGroupCount > 0) $extraStyles = 'margin-top: 1em;';
+ case 'basefields':
+ $title = __( 'Fields', 'zero-bs-crm' );
+ break;
- if (!empty($title)) echo '';
- }
+ default:
+ $title = __( 'Extra Fields', 'zero-bs-crm' );
+ break;
+ }
- echo '
';
+ if ( $colGroupCount > 0 ) {
+ $extraStyles = 'margin-top: 1em;';
+ }
- foreach ($columns as $colKey => $col){
+ if ( ! empty( $title ) ) {
+ echo '';
+ }
+ }
- if (!array_key_exists($colKey, $currentColumns)){
-
- ?>
';
- }
+ foreach ( $columns as $colKey => $col ) {
- }
+ if ( ! array_key_exists( $colKey, $currentColumns ) ) {
- echo '
';
+ ?>
+
+
';
- // if NONE output, we need to always have smt to drop to, so put empty:
- if ($colGroupCount == 0){
- echo '
';
- echo '
';
- }
+ ++$colGroupCount;
+ }
+ }
+ // if NONE output, we need to always have smt to drop to, so put empty:
+ if ( $colGroupCount == 0 ) {
+ echo '
';
+ echo '
';
+ }
+ }
+ ?>
+
- } ?>
-
-
-
-
-
+
+
+
-
-
+
+
@@ -350,7 +373,7 @@ public function drawListView(){
-
+