| 1 | <?php |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | defined( 'ZEROBSCRM_PATH' ) || exit( 0 ); |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.new', 'zeroBSCRM_IA_NewCustomerClientPortal', array() ); |
| 25 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.new', 'zeroBSCRM_IA_NewCustomerLog', array() ); |
| 26 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.status.update', 'zeroBSCRM_IA_CustomerStatusChangePortalAndLog', array() ); |
| 27 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.status.update', 'zeroBSCRM_IA_CustomerStatusChangeAutoLog', array() ); |
| 28 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.new', 'zeroBSCRM_IA_ContactSegmentCompiler', array() ); |
| 29 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.update', 'zeroBSCRM_IA_ContactSegmentCompiler', array() ); |
| 30 | zeroBSCRM_AddInternalAutomatorRecipe( 'company.new', 'zeroBSCRM_IA_NewCompanyLog', array() ); |
| 31 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.new', 'zeroBSCRM_IA_NewQuoteLog', array() ); |
| 32 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.new', 'zeroBSCRM_IA_quoteSegmentCompiler', array() ); |
| 33 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.update', 'zeroBSCRM_IA_quoteSegmentCompiler', array() ); |
| 34 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.accepted', 'zeroBSCRM_IA_AcceptedQuoteLog', array() ); |
| 35 | zeroBSCRM_AddInternalAutomatorRecipe( 'invoice.new', 'zeroBSCRM_IA_NewInvoiceLog', array() ); |
| 36 | zeroBSCRM_AddInternalAutomatorRecipe( 'invoice.new', 'zeroBSCRM_IA_invoiceSegmentCompiler', array() ); |
| 37 | zeroBSCRM_AddInternalAutomatorRecipe( 'invoice.update', 'zeroBSCRM_IA_invoiceSegmentCompiler', array() ); |
| 38 | zeroBSCRM_AddInternalAutomatorRecipe( 'log.new', 'zeroBSCRM_IA_NewLogCatchContactsDB2', array() ); |
| 39 | zeroBSCRM_AddInternalAutomatorRecipe( 'transaction.new', 'zeroBSCRM_IA_NewTransactionLog', array() ); |
| 40 | zeroBSCRM_AddInternalAutomatorRecipe( 'transaction.new', 'zeroBSCRM_IA_transactionSegmentCompiler', array() ); |
| 41 | zeroBSCRM_AddInternalAutomatorRecipe( 'transaction.update', 'zeroBSCRM_IA_transactionSegmentCompiler', array() ); |
| 42 | zeroBSCRM_AddInternalAutomatorRecipe( 'event.new', 'zeroBSCRM_IA_NewEventLog', array() ); |
| 43 | zeroBSCRM_AddInternalAutomatorRecipe( 'clientwpuser.new', 'zeroBSCRM_IA_NewClientPortalUserLog', array() ); |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.new', 'zeroBSCRM_IA_NewCustomerWPHook', array() ); |
| 51 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.update', 'zeroBSCRM_IA_EditCustomerWPHook', array() ); |
| 52 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.status.update', 'zeroBSCRM_IA_EditCustomerWPHook', array() ); |
| 53 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.vitals.update', 'zeroBSCRM_IA_EditCustomerVitalsWPHook', array() ); |
| 54 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.email.update', 'zeroBSCRM_IA_EditCustomerEmailWPHook', array() ); |
| 55 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.delete', 'zeroBSCRM_IA_DeleteCustomerWPHook', array() ); |
| 56 | zeroBSCRM_AddInternalAutomatorRecipe( 'company.new', 'zeroBSCRM_IA_NewCompanyWPHook', array() ); |
| 57 | zeroBSCRM_AddInternalAutomatorRecipe( 'company.delete', 'zeroBSCRM_IA_DeleteCompanyWPHook', array() ); |
| 58 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.new', 'zeroBSCRM_IA_NewQuoteWPHook', array() ); |
| 59 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.accepted', 'zeroBSCRM_IA_AcceptedQuoteWPHook', array() ); |
| 60 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.update', 'zeroBSCRM_IA_EditInvoiceWPHook', array() ); |
| 61 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.status.update', 'zeroBSCRM_IA_EditInvoiceWPHook', array() ); |
| 62 | zeroBSCRM_AddInternalAutomatorRecipe( 'quote.delete', 'zeroBSCRM_IA_DeleteQuoteWPHook', array() ); |
| 63 | zeroBSCRM_AddInternalAutomatorRecipe( 'invoice.new', 'zeroBSCRM_IA_NewInvoiceWPHook', array() ); |
| 64 | zeroBSCRM_AddInternalAutomatorRecipe( 'invoice.update', 'zeroBSCRM_IA_EditInvoiceWPHook', array() ); |
| 65 | zeroBSCRM_AddInternalAutomatorRecipe( 'invoice.status.update', 'zeroBSCRM_IA_EditInvoiceWPHook', array() ); |
| 66 | zeroBSCRM_AddInternalAutomatorRecipe( 'invoice.delete', 'zeroBSCRM_IA_DeleteInvoiceWPHook', array() ); |
| 67 | zeroBSCRM_AddInternalAutomatorRecipe( 'transaction.new', 'zeroBSCRM_IA_NewTransactionWPHook', array() ); |
| 68 | zeroBSCRM_AddInternalAutomatorRecipe( 'transaction.delete', 'zeroBSCRM_IA_DeleteTransactionWPHook', array() ); |
| 69 | zeroBSCRM_AddInternalAutomatorRecipe( 'event.new', 'zeroBSCRM_IA_NewEventWPHook', array() ); |
| 70 | zeroBSCRM_AddInternalAutomatorRecipe( 'event.update', 'zeroBSCRM_IA_UpdateEventWPHook', array() ); |
| 71 | zeroBSCRM_AddInternalAutomatorRecipe( 'event.delete', 'zeroBSCRM_IA_DeleteEventWPHook', array() ); |
| 72 | zeroBSCRM_AddInternalAutomatorRecipe( 'clientwpuser.new', 'zeroBSCRM_IA_NewClientPortalUserHook', array() ); |
| 73 | zeroBSCRM_AddInternalAutomatorRecipe( 'segment.delete', 'zeroBSCRM_IA_DeleteSegmentWPHook', array() ); |
| 74 | zeroBSCRM_AddInternalAutomatorRecipe( 'contact.before.delete', 'zeroBSCRM_IA_BeforeDeleteCustomerWPHook', array() ); |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | function zeroBSCRM_IA_NewCustomerLog( $obj = array() ) { |
| 120 | |
| 121 | |
| 122 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_customer_new' ); |
| 123 | |
| 124 | if ( $autoLogThis > 0 ) { |
| 125 | |
| 126 | |
| 127 | $zbsNoteAgainstPostID = -1; |
| 128 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 129 | $zbsNoteAgainstPostID = (int) $obj['id']; |
| 130 | } |
| 131 | if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) { |
| 132 | |
| 133 | |
| 134 | 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'] ) ) { |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | $newLogID = zeroBS_addUpdateContactLog( $zbsNoteAgainstPostID, -1, -1, $obj['automatorpassthrough']['note_override'] ); |
| 140 | |
| 141 | } else { |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | $newCustomerName = ''; |
| 147 | if ( is_array( $obj ) && isset( $obj['id'] ) && isset( $obj['customerMeta'] ) && is_array( $obj['customerMeta'] ) ) { |
| 148 | $newCustomerName = zeroBS_customerName( $obj['id'], $obj['customerMeta'], false, true ); |
| 149 | } |
| 150 | $noteShortDesc = 'Customer Created'; |
| 151 | if ( ! empty( $newCustomerName ) ) { |
| 152 | $noteShortDesc = $newCustomerName; |
| 153 | } |
| 154 | $note_long_description = ''; |
| 155 | |
| 156 | |
| 157 | if ( isset( $obj['extsource'] ) && ! empty( $obj['extsource'] ) ) { |
| 158 | |
| 159 | $uid = ''; |
| 160 | |
| 161 | |
| 162 | |
| 163 | if ( is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) ) { |
| 164 | |
| 165 | $source_key = $obj['extsource']['source']; |
| 166 | |
| 167 | |
| 168 | $uid = $obj['extsource']['uid']; |
| 169 | |
| 170 | } else { |
| 171 | $source_key = $obj['extsource']; |
| 172 | } |
| 173 | |
| 174 | switch ( $source_key ) { |
| 175 | |
| 176 | case 'pay': |
| 177 | $note_long_description = __( 'Created from PayPal', 'zero-bs-crm' ) . '<i class="fa fa-paypal"></i>'; |
| 178 | |
| 179 | break; |
| 180 | |
| 181 | case 'woo': |
| 182 | $note_long_description = __( 'Created from WooCommerce Order', 'zero-bs-crm' ) . ' <i class="fa fa-shopping-cart"></i>'; |
| 183 | |
| 184 | break; |
| 185 | |
| 186 | case 'env': |
| 187 | $note_long_description = __( 'Created from Envato', 'zero-bs-crm' ) . '<i class="fa fa-envira"></i>'; |
| 188 | |
| 189 | break; |
| 190 | |
| 191 | case 'form': |
| 192 | $note_long_description = __( 'Created from Form Capture', 'zero-bs-crm' ) . '<i class="fa fa-wpforms"></i>'; |
| 193 | |
| 194 | break; |
| 195 | |
| 196 | case 'csv': |
| 197 | $note_long_description = __( 'Created from CSV Import', 'zero-bs-crm' ) . '<i class="fa fa-file-text"></i>'; |
| 198 | |
| 199 | break; |
| 200 | |
| 201 | case 'gra': |
| 202 | $note_long_description = __( 'Created from Gravity Forms', 'zero-bs-crm' ) . '<i class="fa fa-wpforms"></i>'; |
| 203 | |
| 204 | break; |
| 205 | |
| 206 | default: |
| 207 | |
| 208 | $note_long_description = __( 'Created from External Source', 'zero-bs-crm' ) . ' <i class="fa fa-users"></i>'; |
| 209 | |
| 210 | break; |
| 211 | |
| 212 | } |
| 213 | |
| 214 | |
| 215 | $note_long_description = apply_filters( 'jpcrm_new_contact_log', $note_long_description, $source_key, $uid ); |
| 216 | |
| 217 | } |
| 218 | |
| 219 | |
| 220 | $newLogID = zeroBS_addUpdateContactLog( |
| 221 | $zbsNoteAgainstPostID, |
| 222 | -1, |
| 223 | -1, |
| 224 | array( |
| 225 | 'type' => 'Created', |
| 226 | 'shortdesc' => $noteShortDesc, |
| 227 | 'longdesc' => $note_long_description, |
| 228 | ) |
| 229 | ); |
| 230 | |
| 231 | } |
| 232 | |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | function zeroBSCRM_IA_NewCompanyLog( $obj = array() ) { |
| 238 | |
| 239 | |
| 240 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_company_new' ); |
| 241 | |
| 242 | if ( $autoLogThis > 0 ) { |
| 243 | |
| 244 | |
| 245 | $zbsNoteAgainstPostID = -1; |
| 246 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 247 | $zbsNoteAgainstPostID = (int) $obj['id']; |
| 248 | } |
| 249 | if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) { |
| 250 | |
| 251 | |
| 252 | 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'] ) ) { |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | $newLogID = zeroBS_addUpdateLog( $zbsNoteAgainstPostID, -1, -1, $obj['automatorpassthrough']['note_override'], 'zerobs_company' ); |
| 258 | |
| 259 | } else { |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | $newCompanyName = ''; |
| 265 | if ( is_array( $obj ) && isset( $obj['id'] ) && isset( $obj['companyMeta'] ) && is_array( $obj['companyMeta'] ) ) { |
| 266 | $newCompanyName = zeroBS_companyName( $obj['id'], $obj['companyMeta'], false, true ); |
| 267 | } |
| 268 | $noteShortDesc = 'Company Created'; |
| 269 | if ( ! empty( $newCompanyName ) ) { |
| 270 | $noteShortDesc = $newCompanyName; |
| 271 | } |
| 272 | $note_long_description = ''; |
| 273 | |
| 274 | |
| 275 | if ( isset( $obj['extsource'] ) && ! empty( $obj['extsource'] ) ) { |
| 276 | |
| 277 | |
| 278 | |
| 279 | if ( is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) ) { |
| 280 | |
| 281 | $source_key = $obj['extsource']['source']; |
| 282 | |
| 283 | |
| 284 | $uid = $obj['extsource']['uid']; |
| 285 | |
| 286 | } else { |
| 287 | $source_key = $obj['extsource']; |
| 288 | } |
| 289 | |
| 290 | switch ( $source_key ) { |
| 291 | |
| 292 | case 'pay': |
| 293 | $note_long_description = 'Created from PayPal <i class="fa fa-paypal"></i>'; |
| 294 | |
| 295 | break; |
| 296 | |
| 297 | case 'woo': |
| 298 | if ( isset( $uid ) ) { |
| 299 | $note_long_description = sprintf( __( 'Created from WooCommerce Order #%s', 'zero-bs-crm' ), $uid ) . ' <i class="fa fa-shopping-cart"></i>'; |
| 300 | } else { |
| 301 | $note_long_description = __( 'Created from WooCommerce Order', 'zero-bs-crm' ) . ' <i class="fa fa-shopping-cart"></i>'; |
| 302 | } |
| 303 | |
| 304 | break; |
| 305 | |
| 306 | case 'env': |
| 307 | $note_long_description = 'Created from Envato <i class="fa fa-envira"></i>'; |
| 308 | |
| 309 | break; |
| 310 | |
| 311 | case 'form': |
| 312 | $note_long_description = 'Created from Form Capture <i class="fa fa-wpforms"></i>'; |
| 313 | |
| 314 | break; |
| 315 | |
| 316 | case 'csv': |
| 317 | $note_long_description = 'Created from CSV Import <i class="fa fa-file-text"></i>'; |
| 318 | |
| 319 | break; |
| 320 | |
| 321 | default: |
| 322 | |
| 323 | $note_long_description = 'Created from External Source <i class="fa fa-users"></i>'; |
| 324 | |
| 325 | break; |
| 326 | |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | |
| 331 | $newLogID = zeroBS_addUpdateLog( |
| 332 | $zbsNoteAgainstPostID, |
| 333 | -1, |
| 334 | -1, |
| 335 | array( |
| 336 | 'type' => 'Created', |
| 337 | 'shortdesc' => $noteShortDesc, |
| 338 | 'longdesc' => $note_long_description, |
| 339 | ), |
| 340 | 'zerobs_company' |
| 341 | ); |
| 342 | |
| 343 | } |
| 344 | |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | |
| 350 | function zeroBSCRM_IA_NewQuoteLog( $obj = array() ) { |
| 351 | |
| 352 | |
| 353 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_quote_new' ); |
| 354 | |
| 355 | if ( $autoLogThis > 0 ) { |
| 356 | |
| 357 | |
| 358 | |
| 359 | $noteAgainstIDs = array( |
| 360 | 'contacts' => array(), |
| 361 | 'companies' => array(), |
| 362 | ); |
| 363 | if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) { |
| 364 | |
| 365 | |
| 366 | if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) { |
| 367 | $noteAgainstIDs['contacts'] = $obj['againstids']['contacts']; |
| 368 | } |
| 369 | if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) { |
| 370 | $noteAgainstIDs['companies'] = $obj['againstids']['companies']; |
| 371 | } |
| 372 | } |
| 373 | $quoteID = ''; |
| 374 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 375 | $quoteID = $obj['id']; |
| 376 | } |
| 377 | $quoteTitle = ''; |
| 378 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['title'] ) && ! empty( $obj['data']['title'] ) ) { |
| 379 | $quoteTitle = $obj['data']['title']; |
| 380 | } |
| 381 | $quoteValue = ''; |
| 382 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['value'] ) && ! empty( $obj['data']['value'] ) ) { |
| 383 | $quoteValue = zeroBSCRM_formatCurrency( $obj['data']['value'] ); |
| 384 | } |
| 385 | $extsource = ''; |
| 386 | if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) && ! empty( $obj['extsource']['source'] ) ) { |
| 387 | $extsource = $obj['extsource']['source']; |
| 388 | } |
| 389 | $extsourceID = ''; |
| 390 | if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['uid'] ) && ! empty( $obj['extsource']['uid'] ) ) { |
| 391 | $extsourceID = $obj['extsource']['uid']; |
| 392 | } |
| 393 | |
| 394 | |
| 395 | $note_long_description = ''; |
| 396 | $noteShortDesc = ''; |
| 397 | if ( ! empty( $quoteID ) ) { |
| 398 | $noteShortDesc .= '#' . $quoteID; |
| 399 | } |
| 400 | if ( ! empty( $quoteTitle ) ) { |
| 401 | $noteShortDesc .= $quoteTitle; |
| 402 | } |
| 403 | if ( ! empty( $quoteValue ) ) { |
| 404 | $noteShortDesc .= ' (' . $quoteValue . ')'; |
| 405 | } |
| 406 | if ( ! empty( $extsource ) && ! empty( $extsourceID ) ) { |
| 407 | $note_long_description = __( 'Created by', 'zero-bs-crm' ) . ' ' . zeroBS_getExternalSourceTitle( $extsource, $extsourceID ); |
| 408 | } |
| 409 | |
| 410 | if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) { |
| 411 | foreach ( $noteAgainstIDs['contacts'] as $cID ) { |
| 412 | |
| 413 | |
| 414 | $newLogID = zeroBS_addUpdateLog( |
| 415 | $cID, |
| 416 | -1, |
| 417 | -1, |
| 418 | array( |
| 419 | 'type' => __( 'Quote Created', 'zero-bs-crm' ), |
| 420 | 'shortdesc' => $noteShortDesc, |
| 421 | 'longdesc' => $note_long_description, |
| 422 | ), |
| 423 | 'zerobs_customer' |
| 424 | ); |
| 425 | |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | |
| 432 | function zeroBSCRM_IA_AcceptedQuoteLog( $obj = array() ) { |
| 433 | |
| 434 | |
| 435 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_quote_accepted' ); |
| 436 | |
| 437 | if ( $autoLogThis > 0 ) { |
| 438 | |
| 439 | global $zbs; |
| 440 | |
| 441 | |
| 442 | $quoteID = ''; |
| 443 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 444 | $quoteID = $obj['id']; |
| 445 | } |
| 446 | $quote = $zbs->DAL->quotes->getQuote( $quoteID ); |
| 447 | |
| 448 | if ( is_array( $quote ) && count( $quote['contact'] ) > 0 ) { |
| 449 | |
| 450 | |
| 451 | $signedBy = ''; |
| 452 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['signed'] ) && ! empty( $obj['data']['signed'] ) ) { |
| 453 | $signedBy = $obj['data']['signed']; |
| 454 | } |
| 455 | |
| 456 | |
| 457 | |
| 458 | $note_long_description = ''; |
| 459 | $noteShortDesc = ''; |
| 460 | if ( ! empty( $quoteID ) ) { |
| 461 | $noteShortDesc .= '#' . $quoteID; |
| 462 | } |
| 463 | if ( ! empty( $quoteTitle ) ) { |
| 464 | $noteShortDesc .= $quote['title']; |
| 465 | } |
| 466 | if ( ! empty( $quoteValue ) ) { |
| 467 | $noteShortDesc .= ' (' . zeroBSCRM_formatCurrency( $quote['value'] ) . ')'; |
| 468 | } |
| 469 | if ( ! empty( $signedBy ) ) { |
| 470 | $note_long_description = __( 'Signed', 'zero-bs-crm' ) . ' ' . $signedBy; |
| 471 | } |
| 472 | |
| 473 | if ( is_array( $quote['contact'] ) ) { |
| 474 | foreach ( $quote['contact'] as $contact ) { |
| 475 | |
| 476 | |
| 477 | $newLogID = zeroBS_addUpdateLog( |
| 478 | $contact['id'], |
| 479 | -1, |
| 480 | -1, |
| 481 | array( |
| 482 | 'type' => __( 'Quote: Accepted', 'zero-bs-crm' ), |
| 483 | 'shortdesc' => $noteShortDesc, |
| 484 | 'longdesc' => $note_long_description, |
| 485 | ), |
| 486 | 'zerobs_customer' |
| 487 | ); |
| 488 | |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | |
| 496 | function zeroBSCRM_IA_NewInvoiceLog( $obj = array() ) { |
| 497 | |
| 498 | |
| 499 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_invoice_new' ); |
| 500 | |
| 501 | if ( $autoLogThis > 0 ) { |
| 502 | |
| 503 | |
| 504 | $noteAgainstIDs = array( |
| 505 | 'contacts' => array(), |
| 506 | 'companies' => array(), |
| 507 | ); |
| 508 | if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) { |
| 509 | |
| 510 | |
| 511 | if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) { |
| 512 | $noteAgainstIDs['contacts'] = $obj['againstids']['contacts']; |
| 513 | } |
| 514 | if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) { |
| 515 | $noteAgainstIDs['companies'] = $obj['againstids']['companies']; |
| 516 | } |
| 517 | } |
| 518 | $invoiceID = ''; |
| 519 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 520 | $invoiceID = $obj['id']; |
| 521 | } |
| 522 | $invoiceRef = ''; |
| 523 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['id_override'] ) && ! empty( $obj['data']['id_override'] ) ) { |
| 524 | $invoiceRef = $obj['data']['id_override']; |
| 525 | } |
| 526 | $invoiceValue = ''; |
| 527 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['total'] ) && ! empty( $obj['data']['total'] ) ) { |
| 528 | $invoiceValue = zeroBSCRM_formatCurrency( $obj['data']['total'] ); |
| 529 | } |
| 530 | $extsource = ''; |
| 531 | if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) && ! empty( $obj['extsource']['source'] ) ) { |
| 532 | $extsource = $obj['extsource']['source']; |
| 533 | } |
| 534 | $extsourceID = ''; |
| 535 | if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['uid'] ) && ! empty( $obj['extsource']['uid'] ) ) { |
| 536 | $extsourceID = $obj['extsource']['uid']; |
| 537 | } |
| 538 | |
| 539 | |
| 540 | $note_long_description = ''; |
| 541 | $noteShortDesc = ''; |
| 542 | if ( ! empty( $invoiceID ) && empty( $invoiceRef ) ) { |
| 543 | $noteShortDesc .= '#' . $invoiceID; |
| 544 | } |
| 545 | if ( ! empty( $invoiceRef ) ) { |
| 546 | $noteShortDesc .= $invoiceRef; |
| 547 | } |
| 548 | if ( ! empty( $invoiceValue ) ) { |
| 549 | $noteShortDesc .= ' (' . $invoiceValue . ')'; |
| 550 | } |
| 551 | if ( ! empty( $extsource ) && ! empty( $extsourceID ) ) { |
| 552 | $note_long_description = __( 'Created by', 'zero-bs-crm' ) . ' ' . zeroBS_getExternalSourceTitle( $extsource, $extsourceID ); |
| 553 | } |
| 554 | |
| 555 | if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) { |
| 556 | foreach ( $noteAgainstIDs['contacts'] as $cID ) { |
| 557 | |
| 558 | |
| 559 | $newLogID = zeroBS_addUpdateLog( |
| 560 | $cID, |
| 561 | -1, |
| 562 | -1, |
| 563 | array( |
| 564 | 'type' => __( 'Invoice Created', 'zero-bs-crm' ), |
| 565 | 'shortdesc' => $noteShortDesc, |
| 566 | 'longdesc' => $note_long_description, |
| 567 | ), |
| 568 | 'zerobs_customer' |
| 569 | ); |
| 570 | |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | |
| 577 | function zeroBSCRM_IA_NewTransactionLog( $obj = array() ) { |
| 578 | |
| 579 | $newLogID = false; |
| 580 | |
| 581 | |
| 582 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_transaction_new' ); |
| 583 | |
| 584 | if ( $autoLogThis > 0 ) { |
| 585 | |
| 586 | |
| 587 | $noteAgainstIDs = array( |
| 588 | 'contacts' => array(), |
| 589 | 'companies' => array(), |
| 590 | ); |
| 591 | if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) { |
| 592 | |
| 593 | |
| 594 | if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) { |
| 595 | $noteAgainstIDs['contacts'] = $obj['againstids']['contacts']; |
| 596 | } |
| 597 | if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) { |
| 598 | $noteAgainstIDs['companies'] = $obj['againstids']['companies']; |
| 599 | } |
| 600 | } |
| 601 | $transactionID = ''; |
| 602 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 603 | $transactionID = $obj['id']; |
| 604 | } |
| 605 | $transactionRef = ''; |
| 606 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['ref'] ) && ! empty( $obj['data']['ref'] ) ) { |
| 607 | $transactionRef = $obj['data']['ref']; |
| 608 | } |
| 609 | $transactionValue = ''; |
| 610 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['total'] ) && ! empty( $obj['data']['total'] ) ) { |
| 611 | $transactionValue = zeroBSCRM_formatCurrency( $obj['data']['total'] ); |
| 612 | } |
| 613 | $extsource = ''; |
| 614 | if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['source'] ) && ! empty( $obj['extsource']['source'] ) ) { |
| 615 | $extsource = $obj['extsource']['source']; |
| 616 | } |
| 617 | $extsourceID = ''; |
| 618 | if ( is_array( $obj ) && is_array( $obj['extsource'] ) && isset( $obj['extsource']['uid'] ) && ! empty( $obj['extsource']['uid'] ) ) { |
| 619 | $extsourceID = $obj['extsource']['uid']; |
| 620 | } |
| 621 | |
| 622 | |
| 623 | $note_long_description = ''; |
| 624 | $noteShortDesc = ''; |
| 625 | if ( ! empty( $transactionID ) && empty( $transactionRef ) ) { |
| 626 | $noteShortDesc .= '#' . $transactionID; |
| 627 | } |
| 628 | if ( ! empty( $transactionRef ) ) { |
| 629 | $noteShortDesc .= $transactionRef; |
| 630 | } |
| 631 | if ( ! empty( $transactionValue ) ) { |
| 632 | $noteShortDesc .= ' (' . $transactionValue . ')'; |
| 633 | } |
| 634 | if ( ! empty( $extsource ) && ! empty( $extsourceID ) ) { |
| 635 | $note_long_description = __( 'Created by', 'zero-bs-crm' ) . ' ' . zeroBS_getExternalSourceTitle( $extsource, $extsourceID ); |
| 636 | } |
| 637 | |
| 638 | if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) { |
| 639 | foreach ( $noteAgainstIDs['contacts'] as $cID ) { |
| 640 | |
| 641 | |
| 642 | $newLogID = zeroBS_addUpdateLog( |
| 643 | $cID, |
| 644 | -1, |
| 645 | -1, |
| 646 | array( |
| 647 | 'type' => __( 'Transaction Created', 'zero-bs-crm' ), |
| 648 | 'shortdesc' => $noteShortDesc, |
| 649 | 'longdesc' => $note_long_description, |
| 650 | ), |
| 651 | 'zerobs_customer' |
| 652 | ); |
| 653 | |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | return $newLogID; |
| 659 | } |
| 660 | |
| 661 | |
| 662 | function zeroBSCRM_IA_NewEventLog( $obj = array() ) { |
| 663 | |
| 664 | $newLogID = false; |
| 665 | |
| 666 | |
| 667 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_event_new' ); |
| 668 | |
| 669 | |
| 670 | $zbsNoteAgainstPostID = -1; |
| 671 | if ( is_array( $obj ) && isset( $obj['againstid'] ) && $obj['againstid'] > 0 ) { |
| 672 | $zbsNoteAgainstPostID = (int) $obj['againstid']; |
| 673 | } |
| 674 | |
| 675 | if ( $autoLogThis > 0 && isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) { |
| 676 | |
| 677 | |
| 678 | $noteAgainstIDs = array( |
| 679 | 'contacts' => array(), |
| 680 | 'companies' => array(), |
| 681 | ); |
| 682 | if ( is_array( $obj ) && isset( $obj['againstids'] ) && is_array( $obj['againstids'] ) ) { |
| 683 | |
| 684 | |
| 685 | if ( isset( $obj['againstids']['contacts'] ) && is_array( $obj['againstids']['contacts'] ) ) { |
| 686 | $noteAgainstIDs['contacts'] = $obj['againstids']['contacts']; |
| 687 | } |
| 688 | if ( isset( $obj['againstids']['companies'] ) && is_array( $obj['againstids']['companies'] ) ) { |
| 689 | $noteAgainstIDs['companies'] = $obj['againstids']['companies']; |
| 690 | } |
| 691 | } |
| 692 | $taskID = ''; |
| 693 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 694 | $taskID = $obj['id']; |
| 695 | } |
| 696 | $taskTitle = ''; |
| 697 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['title'] ) && ! empty( $obj['data']['title'] ) ) { |
| 698 | $taskTitle = $obj['data']['title']; |
| 699 | } |
| 700 | $taskDescription = ''; |
| 701 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['desc'] ) && ! empty( $obj['data']['desc'] ) ) { |
| 702 | $taskDescription = $obj['data']['desc']; |
| 703 | } |
| 704 | $taskStart = ''; |
| 705 | if ( is_array( $obj ) && is_array( $obj['data'] ) && isset( $obj['data']['start'] ) && ! empty( $obj['data']['start'] ) ) { |
| 706 | $taskStart = zeroBSCRM_locale_utsToDatetime( $obj['data']['start'] ); |
| 707 | } |
| 708 | |
| 709 | |
| 710 | $note_long_description = ''; |
| 711 | $noteShortDesc = ''; |
| 712 | if ( ! empty( $taskID ) && empty( $taskTitle ) ) { |
| 713 | $noteShortDesc .= '#' . $taskID; |
| 714 | } |
| 715 | if ( ! empty( $taskTitle ) ) { |
| 716 | $noteShortDesc .= $taskTitle; |
| 717 | } |
| 718 | if ( ! empty( $taskDescription ) ) { |
| 719 | $note_long_description = $taskDescription; |
| 720 | } |
| 721 | if ( ! empty( $taskStart ) ) { |
| 722 | |
| 723 | |
| 724 | if ( ! empty( $note_long_description ) ) { |
| 725 | $note_long_description .= '<br />'; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | $note_long_description .= __( 'Starts at ', 'zero-bs-crm' ) . ' ' . $taskStart; |
| 730 | |
| 731 | } |
| 732 | |
| 733 | if ( is_array( $noteAgainstIDs['contacts'] ) && count( $noteAgainstIDs['contacts'] ) > 0 ) { |
| 734 | foreach ( $noteAgainstIDs['contacts'] as $cID ) { |
| 735 | |
| 736 | |
| 737 | $newLogID = zeroBS_addUpdateLog( |
| 738 | $cID, |
| 739 | -1, |
| 740 | -1, |
| 741 | array( |
| 742 | 'type' => __( 'Task Created', 'zero-bs-crm' ), |
| 743 | 'shortdesc' => $noteShortDesc, |
| 744 | 'longdesc' => $note_long_description, |
| 745 | ), |
| 746 | 'zerobs_customer' |
| 747 | ); |
| 748 | |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | return $newLogID; |
| 754 | } |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | function zeroBSCRM_IA_NewLogCatchContactsDB2( $obj = array() ) { |
| 762 | |
| 763 | global $zbs; |
| 764 | |
| 765 | |
| 766 | |
| 767 | if ( is_array( $obj ) && isset( $obj['logagainsttype'] ) && ( $obj['logagainsttype'] === 'zerobs_customer' || $obj['logagainsttype'] === ZBS_TYPE_CONTACT ) ) { |
| 768 | |
| 769 | |
| 770 | $log_type = ''; |
| 771 | if ( is_array( $obj ) && isset( $obj['logtype'] ) ) { |
| 772 | $log_type = $obj['logtype']; |
| 773 | } |
| 774 | |
| 775 | if ( ! empty( $log_type ) && in_array( $log_type, $zbs->DAL->logs->contact_log_types, true ) ) { |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | $contact_id = -1; |
| 781 | if ( is_array( $obj ) && isset( $obj['logagainst'] ) ) { |
| 782 | $contact_id = (int) $obj['logagainst']; |
| 783 | } |
| 784 | |
| 785 | if ( ! empty( $contact_id ) && $contact_id > 0 ) { |
| 786 | |
| 787 | |
| 788 | $zbs->DAL->contacts->setContactLastContactUTS( $contact_id, time() ); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | |
| 796 | function zeroBSCRM_IA_NewClientPortalUserLog( $obj = array() ) { |
| 797 | |
| 798 | |
| 799 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_clientportal_new' ); |
| 800 | |
| 801 | if ( $autoLogThis > 0 ) { |
| 802 | |
| 803 | |
| 804 | $zbsNoteAgainstPostID = -1; |
| 805 | if ( is_array( $obj ) && isset( $obj['againstid'] ) && $obj['againstid'] > 0 ) { |
| 806 | $zbsNoteAgainstPostID = (int) $obj['againstid']; |
| 807 | } |
| 808 | |
| 809 | $userID = -1; |
| 810 | if ( is_array( $obj ) && isset( $obj['id'] ) && $obj['id'] > 0 ) { |
| 811 | $userID = (int) $obj['id']; |
| 812 | } |
| 813 | $userEmail = ''; |
| 814 | if ( is_array( $obj ) && isset( $obj['userEmail'] ) ) { |
| 815 | $userEmail = $obj['userEmail']; |
| 816 | } |
| 817 | $noteShortDesc = ''; |
| 818 | if ( ! empty( $userEmail ) ) { |
| 819 | $noteShortDesc = __( 'Created with email', 'zero-bs-crm' ) . ': ' . $userEmail; |
| 820 | } |
| 821 | |
| 822 | if ( $userID > 0 ) { |
| 823 | $noteShortDesc .= ' (#' . $userID . ')'; |
| 824 | } |
| 825 | |
| 826 | if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) { |
| 827 | |
| 828 | |
| 829 | $newLogID = zeroBS_addUpdateContactLog( |
| 830 | $zbsNoteAgainstPostID, |
| 831 | -1, |
| 832 | -1, |
| 833 | array( |
| 834 | 'type' => 'Client Portal User Created', |
| 835 | 'shortdesc' => $noteShortDesc, |
| 836 | 'longdesc' => '', |
| 837 | ) |
| 838 | ); |
| 839 | |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | |
| 845 | function zeroBSCRM_IA_NewCustomerClientPortal( $obj = array() ) { |
| 846 | |
| 847 | |
| 848 | $autoFireThis = zeroBSCRM_getSetting( 'portalusers' ); |
| 849 | |
| 850 | if ( $autoFireThis > 0 ) { |
| 851 | |
| 852 | |
| 853 | $userID = -1; |
| 854 | if ( is_array( $obj ) && isset( $obj['id'] ) && $obj['id'] > 0 ) { |
| 855 | $userID = (int) $obj['id']; |
| 856 | } |
| 857 | |
| 858 | |
| 859 | $okayToFire = true; |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | $statusList = zeroBSCRM_getSetting( 'portalusers_status' ); |
| 865 | if ( ! is_array( $statusList ) && ( empty( $statusList ) || $statusList == 'all' ) ) { |
| 866 | |
| 867 | |
| 868 | |
| 869 | } elseif ( is_array( $statusList ) ) { |
| 870 | |
| 871 | |
| 872 | $zbsStatusStr = zeroBSCRM_getCustomerStatuses(); |
| 873 | $zbsStatuses = explode( ',', $zbsStatusStr ); |
| 874 | $okayStatuses = array(); |
| 875 | |
| 876 | |
| 877 | foreach ( $zbsStatuses as $statusStr ) { |
| 878 | |
| 879 | |
| 880 | $statusKey = strtolower( str_replace( ' ', '_', str_replace( ':', '_', $statusStr ) ) ); |
| 881 | |
| 882 | |
| 883 | if ( in_array( $statusKey, $statusList ) ) { |
| 884 | $okayStatuses[] = $statusStr; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | |
| 889 | $customerStatus = ''; |
| 890 | if ( isset( $obj['customerMeta'] ) && is_array( $obj['customerMeta'] ) && isset( $obj['customerMeta']['status'] ) ) { |
| 891 | $customerStatus = $obj['customerMeta']['status']; |
| 892 | } |
| 893 | |
| 894 | |
| 895 | if ( empty( $customerStatus ) ) { |
| 896 | |
| 897 | $cMeta = zeroBS_getCustomerMeta( $userID ); |
| 898 | |
| 899 | if ( is_array( $cMeta ) && isset( $cMeta['status'] ) ) { |
| 900 | $customerStatus = $cMeta['status']; |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | |
| 905 | if ( ! empty( $customerStatus ) && in_array( $customerStatus, $okayStatuses ) ) { |
| 906 | $okayToFire = true; |
| 907 | } else { |
| 908 | $okayToFire = false; |
| 909 | } |
| 910 | } else { |
| 911 | |
| 912 | |
| 913 | global $zbs; |
| 914 | $zbs->settings->update( 'portalusers_status', 'all' ); |
| 915 | |
| 916 | |
| 917 | |
| 918 | } |
| 919 | |
| 920 | |
| 921 | |
| 922 | if ( $okayToFire ) { |
| 923 | |
| 924 | |
| 925 | if ( $userID > 0 ) { |
| 926 | zeroBSCRM_createClientPortalUserFromRecord( $userID ); |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | |
| 933 | |
| 934 | function zeroBSCRM_IA_ContactSegmentCompiler( $obj = array() ) { |
| 935 | |
| 936 | |
| 937 | $autoCompileSegments = 1; |
| 938 | |
| 939 | if ( $autoCompileSegments > 0 ) { |
| 940 | |
| 941 | |
| 942 | $zbsNoteAgainstPostID = -1; |
| 943 | if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 944 | $zbsNoteAgainstPostID = (int) $obj['id']; |
| 945 | } |
| 946 | $contactWasInSegments = array(); |
| 947 | if ( is_array( $obj ) && isset( $obj['prevSegments'] ) && is_array( $obj['prevSegments'] ) ) { |
| 948 | $contactWasInSegments = $obj['prevSegments']; |
| 949 | } |
| 950 | |
| 951 | if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) ) { |
| 952 | |
| 953 | global $zbs; |
| 954 | $zbs->DAL->segments->compileSegmentsAffectedByContact( $zbsNoteAgainstPostID, $contactWasInSegments ); |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | function zeroBSCRM_IA_quoteSegmentCompiler( $obj = array() ) { |
| 968 | |
| 969 | global $zbs; |
| 970 | |
| 971 | |
| 972 | if ( is_array( $obj ) && isset( $obj['data'] ) ) { |
| 973 | $zbs->DAL->segments->compileSegmentsAffectedByQuote( $obj['data'] ); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | function zeroBSCRM_IA_invoiceSegmentCompiler( $obj = array() ) { |
| 986 | |
| 987 | global $zbs; |
| 988 | |
| 989 | |
| 990 | if ( is_array( $obj ) && isset( $obj['data'] ) ) { |
| 991 | $zbs->DAL->segments->compileSegmentsAffectedByInvoice( $obj['data'] ); |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | function zeroBSCRM_IA_transactionSegmentCompiler( $obj = array() ) { |
| 1004 | |
| 1005 | global $zbs; |
| 1006 | |
| 1007 | |
| 1008 | if ( is_array( $obj ) && isset( $obj['data'] ) ) { |
| 1009 | $zbs->DAL->segments->compileSegmentsAffectedByTransaction( $obj['data'] ); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | |
| 1014 | function zeroBSCRM_IA_CustomerStatusChangePortalAndLog( $obj = array() ) { |
| 1015 | |
| 1016 | |
| 1017 | $autoFireThis = zeroBSCRM_getSetting( 'portalusers' ); |
| 1018 | |
| 1019 | if ( $autoFireThis > 0 ) { |
| 1020 | |
| 1021 | |
| 1022 | $userID = -1; |
| 1023 | if ( is_array( $obj ) && isset( $obj['id'] ) && $obj['id'] > 0 ) { |
| 1024 | $userID = (int) $obj['id']; |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | $statusList = zeroBSCRM_getSetting( 'portalusers_status' ); |
| 1029 | if ( ! is_array( $statusList ) && ( empty( $statusList ) || $statusList == 'all' ) ) { |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | } elseif ( is_array( $statusList ) ) { |
| 1034 | |
| 1035 | |
| 1036 | $zbsStatusStr = zeroBSCRM_getCustomerStatuses(); |
| 1037 | $zbsStatuses = explode( ',', $zbsStatusStr ); |
| 1038 | $okayStatuses = array(); |
| 1039 | |
| 1040 | |
| 1041 | foreach ( $zbsStatuses as $statusStr ) { |
| 1042 | |
| 1043 | |
| 1044 | $statusKey = strtolower( str_replace( ' ', '_', str_replace( ':', '_', $statusStr ) ) ); |
| 1045 | |
| 1046 | |
| 1047 | if ( in_array( $statusKey, $statusList ) ) { |
| 1048 | $okayStatuses[] = $statusStr; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | $customerStatus = ''; |
| 1054 | if ( isset( $obj['customerMeta'] ) && is_array( $obj['customerMeta'] ) && isset( $obj['customerMeta']['status'] ) ) { |
| 1055 | $customerStatus = $obj['customerMeta']['status']; |
| 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | if ( empty( $customerStatus ) ) { |
| 1060 | |
| 1061 | $cMeta = zeroBS_getCustomerMeta( $userID ); |
| 1062 | |
| 1063 | if ( is_array( $cMeta ) && isset( $cMeta['status'] ) ) { |
| 1064 | $customerStatus = $cMeta['status']; |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | if ( ! empty( $customerStatus ) && in_array( $customerStatus, $okayStatuses ) ) { |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | $portalID = zeroBSCRM_getClientPortalUserID( $userID ); |
| 1075 | |
| 1076 | if ( ! empty( $portalID ) && $portalID > 0 ) { |
| 1077 | |
| 1078 | $isDisabled = zeroBSCRM_isCustomerPortalDisabled( $userID ); |
| 1079 | |
| 1080 | |
| 1081 | if ( $isDisabled ) { |
| 1082 | |
| 1083 | |
| 1084 | zeroBSCRM_customerPortalDisableEnable( $userID, 'enable' ); |
| 1085 | |
| 1086 | $noteShortDesc = __( 'Access enabled (by change of status to', 'zero-bs-crm' ) . ' "' . $customerStatus . '"'; |
| 1087 | |
| 1088 | |
| 1089 | $newLogID = zeroBS_addUpdateContactLog( |
| 1090 | $userID, |
| 1091 | -1, |
| 1092 | -1, |
| 1093 | array( |
| 1094 | 'type' => 'Client Portal Access Changed', |
| 1095 | 'shortdesc' => $noteShortDesc, |
| 1096 | 'longdesc' => '', |
| 1097 | ) |
| 1098 | ); |
| 1099 | |
| 1100 | } |
| 1101 | } else { |
| 1102 | |
| 1103 | |
| 1104 | if ( $userID > 0 ) { |
| 1105 | |
| 1106 | zeroBSCRM_createClientPortalUserFromRecord( $userID ); |
| 1107 | |
| 1108 | $noteShortDesc = __( 'Access created (by change of status to', 'zero-bs-crm' ) . ' "' . $customerStatus . '"'; |
| 1109 | |
| 1110 | |
| 1111 | $newLogID = zeroBS_addUpdateContactLog( |
| 1112 | $userID, |
| 1113 | -1, |
| 1114 | -1, |
| 1115 | array( |
| 1116 | 'type' => 'Client Portal Access Changed', |
| 1117 | 'shortdesc' => $noteShortDesc, |
| 1118 | 'longdesc' => '', |
| 1119 | ) |
| 1120 | ); |
| 1121 | |
| 1122 | } |
| 1123 | } |
| 1124 | } else { |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | $portalID = zeroBSCRM_getClientPortalUserID( $userID ); |
| 1130 | |
| 1131 | if ( ! empty( $portalID ) && $portalID > 0 ) { |
| 1132 | |
| 1133 | $isDisabled = zeroBSCRM_isCustomerPortalDisabled( $userID ); |
| 1134 | |
| 1135 | |
| 1136 | if ( ! $isDisabled ) { |
| 1137 | |
| 1138 | |
| 1139 | zeroBSCRM_customerPortalDisableEnable( $userID, 'disable' ); |
| 1140 | |
| 1141 | $noteShortDesc = __( 'Access disabled (by change of status to', 'zero-bs-crm' ) . ' "' . $customerStatus . '"'; |
| 1142 | |
| 1143 | |
| 1144 | $newLogID = zeroBS_addUpdateContactLog( |
| 1145 | $userID, |
| 1146 | -1, |
| 1147 | -1, |
| 1148 | array( |
| 1149 | 'type' => 'Client Portal Access Changed', |
| 1150 | 'shortdesc' => $noteShortDesc, |
| 1151 | 'longdesc' => '', |
| 1152 | ) |
| 1153 | ); |
| 1154 | |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | } else { |
| 1159 | |
| 1160 | |
| 1161 | global $zbs; |
| 1162 | $zbs->settings->update( 'portalusers_status', 'all' ); |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | function zeroBSCRM_IA_CustomerStatusChangeAutoLog( $obj = array() ) { |
| 1175 | |
| 1176 | |
| 1177 | $autoLogThis = zeroBSCRM_getSetting( 'autolog_customer_statuschange' ); |
| 1178 | |
| 1179 | if ( $autoLogThis > 0 ) { |
| 1180 | |
| 1181 | |
| 1182 | $zbsNoteAgainstPostID = -1; |
| 1183 | if ( is_array( $obj ) && isset( $obj['againstid'] ) && $obj['againstid'] > 0 ) { |
| 1184 | $zbsNoteAgainstPostID = (int) $obj['againstid']; |
| 1185 | } |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | $from = ''; |
| 1190 | if ( is_array( $obj ) && isset( $obj['from'] ) && ! empty( $obj['from'] ) ) { |
| 1191 | $from = $obj['from']; |
| 1192 | } |
| 1193 | $to = ''; |
| 1194 | if ( is_array( $obj ) && isset( $obj['to'] ) && ! empty( $obj['to'] ) ) { |
| 1195 | $to = $obj['to']; |
| 1196 | } |
| 1197 | |
| 1198 | if ( isset( $zbsNoteAgainstPostID ) && ! empty( $zbsNoteAgainstPostID ) && isset( $to ) && ! empty( $to ) ) { |
| 1199 | |
| 1200 | $shortDesc = ''; |
| 1201 | if ( ! empty( $from ) ) { |
| 1202 | $shortDesc = __( 'From', 'zero-bs-crm' ) . ' "' . $from . '" ' . __( 'to', 'zero-bs-crm' ) . ' "' . $to . '"'; |
| 1203 | } else { |
| 1204 | $shortDesc = __( 'To', 'zero-bs-crm' ) . ' "' . $to . '"'; |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | $newLogID = zeroBS_addUpdateContactLog( |
| 1209 | $zbsNoteAgainstPostID, |
| 1210 | -1, |
| 1211 | -1, |
| 1212 | array( |
| 1213 | 'type' => 'Status Change', |
| 1214 | 'shortdesc' => $shortDesc, |
| 1215 | 'longdesc' => '', |
| 1216 | ) |
| 1217 | ); |
| 1218 | |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | function zeroBSCRM_IA_NewCustomerWPHook( $obj = array() ) { |
| 1237 | |
| 1238 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1239 | |
| 1240 | do_action( 'jpcrm_after_contact_insert', $obj['id'] ); |
| 1241 | |
| 1242 | |
| 1243 | do_action( 'zbs_new_customer', $obj['id'] ); |
| 1244 | |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | function zeroBSCRM_IA_EditCustomerWPHook( $obj = array() ) { |
| 1254 | |
| 1255 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1256 | |
| 1257 | do_action( 'jpcrm_after_contact_update', $obj['id'] ); |
| 1258 | |
| 1259 | |
| 1260 | do_action( 'zbs_edit_customer', $obj['id'] ); |
| 1261 | |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | |
| 1266 | function zeroBSCRM_IA_EditCustomerVitalsWPHook( $obj = array() ) { |
| 1267 | |
| 1268 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1269 | do_action( 'zbs_edit_customer_vitals', $obj['id'] ); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | function zeroBSCRM_IA_EditCustomerEmailWPHook( $obj = array() ) { |
| 1279 | |
| 1280 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1281 | do_action( 'zbs_edit_customer_email', $obj['id'] ); |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | function zeroBSCRM_IA_DeleteCustomerWPHook( $obj = array() ) { |
| 1291 | |
| 1292 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1293 | |
| 1294 | do_action( 'zbs_delete_customer', $obj['id'] ); |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | |
| 1302 | |
| 1303 | function zeroBSCRM_IA_BeforeDeleteCustomerWPHook( $obj = array() ) { |
| 1304 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1305 | do_action( 'jpcrm_before_delete_contact', $obj ); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | function zeroBSCRM_IA_NewCompanyWPHook( $obj = array() ) { |
| 1315 | |
| 1316 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1317 | |
| 1318 | |
| 1319 | do_action( 'zbs_new_company', $obj['id'] ); |
| 1320 | |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | function zeroBSCRM_IA_DeleteCompanyWPHook( $obj = array() ) { |
| 1330 | |
| 1331 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1332 | |
| 1333 | |
| 1334 | do_action( 'zbs_delete_company', $obj['id'] ); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | function zeroBSCRM_IA_NewQuoteWPHook( $obj = array() ) { |
| 1339 | |
| 1340 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1341 | do_action( 'zbs_new_quote', $obj['id'] ); |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | function zeroBSCRM_IA_AcceptedQuoteWPHook( $obj = array() ) { |
| 1346 | |
| 1347 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1348 | do_action( 'jpcrm_quote_accepted', $obj['id'] ); |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | function zeroBSCRM_IA_DeleteQuoteWPHook( $obj = array() ) { |
| 1353 | |
| 1354 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1355 | do_action( 'zbs_delete_quote', $obj['id'] ); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | function zeroBSCRM_IA_NewInvoiceWPHook( $obj = array() ) { |
| 1365 | |
| 1366 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1367 | do_action( 'zbs_new_invoice', $obj['id'] ); |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | function zeroBSCRM_IA_EditInvoiceWPHook( $obj = array() ) { |
| 1377 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1378 | do_action( 'zbs_new_invoice', $obj['id'] ); |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | function zeroBSCRM_IA_DeleteInvoiceWPHook( $obj = array() ) { |
| 1388 | |
| 1389 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1390 | do_action( 'zbs_delete_invoice', $obj['id'] ); |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | |
| 1395 | function zeroBSCRM_IA_NewTransactionWPHook( $obj = array() ) { |
| 1396 | |
| 1397 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1398 | do_action( 'zbs_new_transaction', $obj['id'] ); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | function zeroBSCRM_IA_DeleteTransactionWPHook( $obj = array() ) { |
| 1403 | |
| 1404 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1405 | do_action( 'zbs_delete_transaction', $obj['id'] ); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | function zeroBSCRM_IA_NewEventWPHook( $obj = array() ) { |
| 1410 | |
| 1411 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1412 | do_action( 'zbs_new_event', $obj['id'] ); |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | function zeroBSCRM_IA_UpdateEventWPHook( $obj = array() ) { |
| 1417 | |
| 1418 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1419 | do_action( 'zbs_update_event', $obj['id'] ); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | function zeroBSCRM_IA_DeleteEventWPHook( $obj = array() ) { |
| 1424 | |
| 1425 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1426 | do_action( 'zbs_delete_event', $obj['id'] ); |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | function zeroBSCRM_IA_NewClientPortalUserHook( $obj = array() ) { |
| 1431 | |
| 1432 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1433 | do_action( 'zbs_new_client_portal_user', $obj['id'] ); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | function zeroBSCRM_IA_DeleteFormWPHook( $obj = array() ) { |
| 1438 | |
| 1439 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1440 | do_action( 'zbs_delete_form', $obj['id'] ); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | function zeroBSCRM_IA_DeleteSegmentWPHook( $obj = array() ) { |
| 1445 | |
| 1446 | if ( is_array( $obj ) && isset( $obj['id'] ) && ! empty( $obj['id'] ) ) { |
| 1447 | do_action( 'zbs_delete_segment', $obj['id'] ); |
| 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |