broker cleanup
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
7 changed files
with
1224 additions
and
2118 deletions
| ... | @@ -21,8 +21,8 @@ if (isset($_GET['current_tab'])) { | ... | @@ -21,8 +21,8 @@ if (isset($_GET['current_tab'])) { |
| 21 | $currentTab = 'ace_body_shop'; | 21 | $currentTab = 'ace_body_shop'; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | $bodyShopURL = home_url('/broker-landing-page/ace?current_tab=ace_body_shop'); | 24 | $bodyShopURL = home_url('/ace?current_tab=ace_body_shop'); |
| 25 | $propertyContractorURL = home_url('/broker-landing-page/ace?current_tab=ace_property_contractor'); | 25 | $propertyContractorURL = home_url('/ace?current_tab=ace_property_contractor'); |
| 26 | 26 | ||
| 27 | ?> | 27 | ?> |
| 28 | 28 | ... | ... |
| ... | @@ -5,7 +5,8 @@ error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED); | ... | @@ -5,7 +5,8 @@ error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED); |
| 5 | @ini_set( 'max_execution_time', '300' ); | 5 | @ini_set( 'max_execution_time', '300' ); |
| 6 | require_once __DIR__ . '/vendor/autoload.php'; | 6 | require_once __DIR__ . '/vendor/autoload.php'; |
| 7 | require_once 'simple_html_dom.php'; | 7 | require_once 'simple_html_dom.php'; |
| 8 | 8 | require_once 'inc/users.php'; | |
| 9 | require_once 'inc/learn.php'; | ||
| 9 | 10 | ||
| 10 | add_action('wp_enqueue_scripts', 'theme_broker_enqueue_scripts'); | 11 | add_action('wp_enqueue_scripts', 'theme_broker_enqueue_scripts'); |
| 11 | function theme_broker_enqueue_scripts() | 12 | function theme_broker_enqueue_scripts() |
| ... | @@ -385,76 +386,6 @@ function send_headers() | ... | @@ -385,76 +386,6 @@ function send_headers() |
| 385 | } | 386 | } |
| 386 | 387 | ||
| 387 | add_action('template_redirect', 'send_headers'); | 388 | add_action('template_redirect', 'send_headers'); |
| 388 | /** | ||
| 389 | * Add login authentication function to use either username or email address | ||
| 390 | */ | ||
| 391 | //add_action('wp_authenticate', 'my_front_end_login_fail', 1, 2); | ||
| 392 | //add_action('wp_login_failed', 'my_front_end_login_fail', 1, 1); | ||
| 393 | |||
| 394 | function my_front_end_login_fail($user, $pwd = '') | ||
| 395 | { | ||
| 396 | |||
| 397 | // reasons to stop here | ||
| 398 | // $user is not empty | ||
| 399 | // $user is not a wp-error object | ||
| 400 | // $pwd is not empty | ||
| 401 | if (!empty($user) && !empty($pwd) && !is_wp_error($user)) { | ||
| 402 | return false; | ||
| 403 | } | ||
| 404 | |||
| 405 | // if a referer is set, use it. else setup the standard login file | ||
| 406 | $referrer = (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] | ||
| 407 | : home_url('wp-login.php'); // take the safe one, use home_url() | ||
| 408 | |||
| 409 | /* | ||
| 410 | * since PHP5 we can parse an url | ||
| 411 | * @see http://php.net/manual/en/function.parse-url.php | ||
| 412 | * | ||
| 413 | * parse_url( 'http://www.example.com/wp-login.php?login=failed&foo=bar' ) gives us something like that: | ||
| 414 | * | ||
| 415 | * array ( | ||
| 416 | * 'scheme' => 'http' | ||
| 417 | * 'host' => 'www.example.com' | ||
| 418 | * 'path' => '/wp-login.php' | ||
| 419 | * 'query' => 'login=failed&foo=bar' | ||
| 420 | * ) | ||
| 421 | */ | ||
| 422 | |||
| 423 | $parsed_url = parse_url($referrer); | ||
| 424 | |||
| 425 | /* | ||
| 426 | * Another fine function is parse_str() | ||
| 427 | * @see: http://php.net/manual/en/function.parse-str.php | ||
| 428 | * | ||
| 429 | * parse( 'login=failed&foo=bar', $query ); results in | ||
| 430 | * array( | ||
| 431 | * 'login' => 'failed' | ||
| 432 | * 'foo' => 'bar' | ||
| 433 | * ) | ||
| 434 | * | ||
| 435 | */ | ||
| 436 | parse_str($parsed_url['query'], $query); | ||
| 437 | |||
| 438 | // if there's a valid referrer, and it's not the default log-in screen | ||
| 439 | if (!strstr($parsed_url['path'], 'wp-login') && !strstr($parsed_url['path'], 'wp-admin')) { | ||
| 440 | |||
| 441 | // already has the failed don't appened it again | ||
| 442 | $redirect_to = $referrer; | ||
| 443 | |||
| 444 | if (!isset($query['login']) || 'failed' !== $query['login']) { | ||
| 445 | // add the failed | ||
| 446 | // but never ever use a simple string concaternation | ||
| 447 | // what will result if the referer is 'example.com?foo=bar'? | ||
| 448 | // it will result in 'example.com?foo=bar?login=failed' OUTCH! | ||
| 449 | $redirect_to = add_query_arg(['login' => 'failed_empty'], $referrer); | ||
| 450 | } | ||
| 451 | |||
| 452 | // you don't want to redirect to google or somewhere else, you want to redirect to your | ||
| 453 | // own domain. so use wp_safe_redirect() | ||
| 454 | wp_safe_redirect($redirect_to); | ||
| 455 | exit; | ||
| 456 | } | ||
| 457 | } | ||
| 458 | 389 | ||
| 459 | /** | 390 | /** |
| 460 | * Redirect always homepage after logout | 391 | * Redirect always homepage after logout |
| ... | @@ -576,422 +507,6 @@ function remove_lostpassword_text($text) | ... | @@ -576,422 +507,6 @@ function remove_lostpassword_text($text) |
| 576 | add_filter('gettext', 'remove_lostpassword_text'); | 507 | add_filter('gettext', 'remove_lostpassword_text'); |
| 577 | 508 | ||
| 578 | 509 | ||
| 579 | /** | ||
| 580 | * Add custom user profile fields | ||
| 581 | */ | ||
| 582 | |||
| 583 | add_action('show_user_profile', 'add_custom_fields'); | ||
| 584 | add_action('edit_user_profile', 'add_custom_fields'); | ||
| 585 | add_action("user_new_form", "add_custom_fields"); | ||
| 586 | |||
| 587 | define('WPSL_MARKER_URI', dirname(get_bloginfo('template_url')) . '/commonwell-corp/images/'); | ||
| 588 | |||
| 589 | |||
| 590 | function add_custom_fields($user) | ||
| 591 | { | ||
| 592 | $brokerList = getBrokerageList(); | ||
| 593 | $userBrokerId = esc_attr(get_the_author_meta('broker_id', $user->ID)); | ||
| 594 | ?> | ||
| 595 | <div class="broker-group"> | ||
| 596 | <h3>Broker</h3> | ||
| 597 | <table class="form-table form-broker_id"> | ||
| 598 | <tr class="form-field"> | ||
| 599 | <th><label for="broker_id">Brokerage <span class="description">(required)</span></label></th> | ||
| 600 | <td> | ||
| 601 | <input type="text" style="position: absolute; opacity: 0; z-index: -1;" /> | ||
| 602 | <select name="broker_id" id="broker_id"> | ||
| 603 | <option value="">Select Broker</option> | ||
| 604 | <?php foreach ($brokerList as $broker): ?> | ||
| 605 | <?php | ||
| 606 | $isSelected = $userBrokerId === $broker['broker_id'] ? 'selected="selected"' : ''; | ||
| 607 | ?> | ||
| 608 | <option value="<?php echo $broker['broker_id']; ?>" <?php echo $isSelected; ?>><?php echo $broker['brokerage']; ?></option> | ||
| 609 | <?php endforeach;?> | ||
| 610 | </select> | ||
| 611 | </td> | ||
| 612 | </tr> | ||
| 613 | </table> | ||
| 614 | </div> | ||
| 615 | <?php | ||
| 616 | } | ||
| 617 | |||
| 618 | /** | ||
| 619 | * Save additional profile field | ||
| 620 | */ | ||
| 621 | |||
| 622 | add_action('personal_options_update', 'save_custom_fields'); | ||
| 623 | add_action('edit_user_profile_update', 'save_custom_fields'); | ||
| 624 | add_action('user_register', 'save_custom_fields'); | ||
| 625 | |||
| 626 | function save_custom_fields($user_id) | ||
| 627 | { | ||
| 628 | # again do this only if you can | ||
| 629 | if (!current_user_can('administrator', $user_id)) { | ||
| 630 | return false; | ||
| 631 | } | ||
| 632 | |||
| 633 | $brokerList = getBrokerageList(); | ||
| 634 | $brokerage = false; | ||
| 635 | foreach ($brokerList as $broker) { | ||
| 636 | if ($_POST['broker_id'] == $broker['broker_id']) { | ||
| 637 | $brokerage = $broker['brokerage']; | ||
| 638 | } | ||
| 639 | } | ||
| 640 | |||
| 641 | if ($brokerage) { | ||
| 642 | update_user_meta($user_id, 'brokerage', sanitize_text_field($brokerage)); | ||
| 643 | } | ||
| 644 | |||
| 645 | update_user_meta($user_id, 'broker_id', sanitize_text_field($_POST['broker_id'])); | ||
| 646 | } | ||
| 647 | |||
| 648 | |||
| 649 | add_action('admin_footer-user-new.php', 'addUAMField'); | ||
| 650 | /** | ||
| 651 | * Add UAM field into a user registration form | ||
| 652 | * | ||
| 653 | * @param $user | ||
| 654 | */ | ||
| 655 | function addUAMField($user) | ||
| 656 | { | ||
| 657 | try { | ||
| 658 | global $userAccessManager, $wpdb; | ||
| 659 | $aUamUserGroups = $userAccessManager->getAccessHandler()->getUserGroups(); | ||
| 660 | } catch(Throwable $e) { | ||
| 661 | error_log($e->getMessage()); | ||
| 662 | return; | ||
| 663 | } | ||
| 664 | |||
| 665 | ?> | ||
| 666 | <h3><?php echo TXT_UAM_GROUPS; ?></h3> | ||
| 667 | <table class="form-table"> | ||
| 668 | <tbody> | ||
| 669 | <tr> | ||
| 670 | <th> | ||
| 671 | <label for="usergroups"><?php echo TXT_UAM_SET_UP_USERGROUPS; ?></label> | ||
| 672 | </th> | ||
| 673 | <td> | ||
| 674 | <input type="hidden" name="uam_update_groups" value="true" /> | ||
| 675 | <ul class="uam_group_selection"> | ||
| 676 | <?php | ||
| 677 | if ( | ||
| 678 | !isset($sGroupsFormName) | ||
| 679 | || $sGroupsFormName === null | ||
| 680 | ) { | ||
| 681 | $sGroupsFormName = 'uam_usergroups'; | ||
| 682 | } | ||
| 683 | |||
| 684 | foreach ($aUamUserGroups as $oUamUserGroup) { | ||
| 685 | $sAddition = ''; | ||
| 686 | $sAttributes = ''; | ||
| 687 | |||
| 688 | ?> | ||
| 689 | <li> | ||
| 690 | <input type="checkbox" id="<?php echo $sGroupsFormName; ?>-<?php echo $oUamUserGroup->getId(); ?>" <?php echo $sAttributes; ?> value="<?php echo $oUamUserGroup->getId(); ?>" name="<?php echo $sGroupsFormName; ?>[]" data-name="<?php echo strtolower($oUamUserGroup->getGroupName()); ?>" /> | ||
| 691 | <label for="<?php echo $sGroupsFormName; ?>-<?php echo $oUamUserGroup->getId(); ?>" class="selectit" style="display:inline;"> | ||
| 692 | <?php echo $oUamUserGroup->getGroupName() . $sAddition; ?> | ||
| 693 | </label> | ||
| 694 | <a class="uam_group_info_link">(<?php echo TXT_UAM_INFO; ?>)</a> | ||
| 695 | <!-- Tool tip content--> | ||
| 696 | <div class="tooltip"> | ||
| 697 | <ul class="uam_group_info"> | ||
| 698 | <?php | ||
| 699 | global $userAccessManager; | ||
| 700 | |||
| 701 | foreach ($userAccessManager->getAccessHandler()->getAllObjectTypes() as $sCurObjectType) { | ||
| 702 | if (isset($aUserGroups[$oUamUserGroup->getId()])) { | ||
| 703 | $aRecursiveMembership = $aUserGroups[$oUamUserGroup->getId()]->getRecursiveMembershipForObjectType( | ||
| 704 | $sObjectType, | ||
| 705 | $iObjectId, | ||
| 706 | $sCurObjectType | ||
| 707 | ); | ||
| 708 | |||
| 709 | if (count($aRecursiveMembership) > 0) { | ||
| 710 | ?> | ||
| 711 | <li class="uam_group_info_head"> | ||
| 712 | <?php echo constant( | ||
| 713 | 'TXT_UAM_GROUP_MEMBERSHIP_BY_' . strtoupper($sCurObjectType) | ||
| 714 | ); ?>: | ||
| 715 | <ul> | ||
| 716 | <?php | ||
| 717 | foreach ($aRecursiveMembership as $oObject) { | ||
| 718 | ?> | ||
| 719 | <li class="recusiveTree"><?php echo walkPath( | ||
| 720 | $oObject, | ||
| 721 | $sCurObjectType | ||
| 722 | ); ?></li> | ||
| 723 | <?php | ||
| 724 | } | ||
| 725 | ?> | ||
| 726 | </ul> | ||
| 727 | </li> | ||
| 728 | <?php | ||
| 729 | } | ||
| 730 | } | ||
| 731 | } | ||
| 732 | ?> | ||
| 733 | <li class="uam_group_info_head"><?php echo TXT_UAM_GROUP_INFO; ?>: | ||
| 734 | <ul> | ||
| 735 | <li><?php echo TXT_UAM_READ_ACCESS; ?>: | ||
| 736 | <?php | ||
| 737 | if ($oUamUserGroup->getReadAccess() == "all") { | ||
| 738 | echo TXT_UAM_ALL; | ||
| 739 | } elseif ($oUamUserGroup->getReadAccess() == "group") { | ||
| 740 | echo TXT_UAM_ONLY_GROUP_USERS; | ||
| 741 | } | ||
| 742 | ?> | ||
| 743 | </li> | ||
| 744 | <li><?php echo TXT_UAM_WRITE_ACCESS; ?>: | ||
| 745 | <?php | ||
| 746 | if ($oUamUserGroup->getWriteAccess() == "all") { | ||
| 747 | echo TXT_UAM_ALL; | ||
| 748 | } elseif ($oUamUserGroup->getWriteAccess() == "group") { | ||
| 749 | echo TXT_UAM_ONLY_GROUP_USERS; | ||
| 750 | } | ||
| 751 | ?> | ||
| 752 | </li> | ||
| 753 | <li> | ||
| 754 | <?php echo TXT_UAM_GROUP_ROLE; ?>: <?php | ||
| 755 | if ($oUamUserGroup->getObjectsFromType('role')) { | ||
| 756 | $sOut = ''; | ||
| 757 | |||
| 758 | foreach ($oUamUserGroup->getObjectsFromType( | ||
| 759 | 'role' | ||
| 760 | ) as $sKey => $sRole) { | ||
| 761 | $sOut .= trim($sKey) . ', '; | ||
| 762 | } | ||
| 763 | |||
| 764 | echo rtrim($sOut, ', '); | ||
| 765 | } else { | ||
| 766 | echo TXT_UAM_NONE; | ||
| 767 | } | ||
| 768 | ?> | ||
| 769 | </li> | ||
| 770 | </ul> | ||
| 771 | </li> | ||
| 772 | </ul> | ||
| 773 | </div> | ||
| 774 | </li> | ||
| 775 | <?php | ||
| 776 | } | ||
| 777 | ?> | ||
| 778 | </ul> | ||
| 779 | </td> | ||
| 780 | </tr> | ||
| 781 | </tbody> | ||
| 782 | </table> | ||
| 783 | <?php | ||
| 784 | } | ||
| 785 | |||
| 786 | add_action('user_register', 'saveUAMField'); | ||
| 787 | |||
| 788 | /** | ||
| 789 | * Save the UAM field value | ||
| 790 | * | ||
| 791 | * @return bool | ||
| 792 | */ | ||
| 793 | function saveUAMField($user_id) | ||
| 794 | { | ||
| 795 | try { | ||
| 796 | |||
| 797 | # again do this only if you can | ||
| 798 | if (!current_user_can('administrator', $user_id)) { | ||
| 799 | return false; | ||
| 800 | } | ||
| 801 | |||
| 802 | global $userAccessManager; | ||
| 803 | $uamAccessHandler = $userAccessManager->getAccessHandler(); | ||
| 804 | $aUserGroups = null; | ||
| 805 | |||
| 806 | $aFormData = array(); | ||
| 807 | |||
| 808 | if (isset($_POST['uam_update_groups'])) { | ||
| 809 | $aFormData = $_POST; | ||
| 810 | } elseif (isset($_GET['uam_update_groups'])) { | ||
| 811 | $aFormData = $_GET; | ||
| 812 | } | ||
| 813 | |||
| 814 | if (isset($aFormData['uam_update_groups'])) { | ||
| 815 | if ($aUserGroups === null) { | ||
| 816 | $aUserGroups = isset($aFormData['uam_user_groups']) ? $aFormData['uam_user_groups'] : array(); | ||
| 817 | } | ||
| 818 | |||
| 819 | foreach ($aUserGroups as $key => $value) { | ||
| 820 | if (isset($aUserGroups[$key]['id'])) { | ||
| 821 | $uamUserGroups = $uamAccessHandler->getUserGroups(); | ||
| 822 | $uamUserGroup = $uamUserGroups[$key]; | ||
| 823 | $uamUserGroup->addObject('_user_', $user_id); | ||
| 824 | $uamUserGroup->save(); | ||
| 825 | } | ||
| 826 | } | ||
| 827 | } | ||
| 828 | |||
| 829 | } catch(Throwable $e) { | ||
| 830 | error_log("saveUAMField Error " . $e->getMessage() . ", for user_id = " . $user_id . " while updating group(s) " . $_REQUEST['uam_update_groups']); | ||
| 831 | } | ||
| 832 | } | ||
| 833 | |||
| 834 | |||
| 835 | /** | ||
| 836 | * Remove roles | ||
| 837 | * | ||
| 838 | * Author, Editor, Contributor | ||
| 839 | * | ||
| 840 | */ | ||
| 841 | $wp_roles = new WP_Roles(); | ||
| 842 | $wp_roles->remove_role("author"); | ||
| 843 | $wp_roles->remove_role("editor"); | ||
| 844 | $wp_roles->remove_role("contributor"); | ||
| 845 | |||
| 846 | /** | ||
| 847 | * Admin init function | ||
| 848 | */ | ||
| 849 | |||
| 850 | add_action('admin_footer-user-new.php', 'setUserProfileLogicNewUser'); | ||
| 851 | add_action('admin_footer-user-edit.php', 'setUserProfileLogicEditUser'); | ||
| 852 | |||
| 853 | function setUserProfileLogicNewUser($hook) | ||
| 854 | { | ||
| 855 | ?> | ||
| 856 | <script> | ||
| 857 | (function($) { | ||
| 858 | var addNewUserForm = $('#createuser'); | ||
| 859 | var roleSelectBox = $('#role'); | ||
| 860 | var brokerIdSelectBox = $('#broker_id'); | ||
| 861 | var brokerIdFormField = $('.form-broker_id .form-field'); | ||
| 862 | var brokerCheckbox = $('.uam_group_selection input[type="checkbox"][id="uam_usergroups-1"]'); | ||
| 863 | var brokerGroup = $('.broker-group'); | ||
| 864 | |||
| 865 | // Role select | ||
| 866 | roleSelectBox.on( | ||
| 867 | 'change', | ||
| 868 | function(e) { | ||
| 869 | var userRole = e.target.value; | ||
| 870 | // If broker is selected | ||
| 871 | // Check "Broker" user group | ||
| 872 | if (userRole === 'subscriber') { | ||
| 873 | brokerCheckbox[0].checked = true; | ||
| 874 | brokerGroup.slideDown(100); | ||
| 875 | |||
| 876 | } else { | ||
| 877 | brokerCheckbox[0].checked = false; | ||
| 878 | brokerGroup.slideUp(100); | ||
| 879 | brokerIdSelectBox[0].selectedIndex = 0; | ||
| 880 | |||
| 881 | brokerIdFormField.removeClass('form-required'); | ||
| 882 | brokerIdFormField.removeClass('form-invalid'); | ||
| 883 | } | ||
| 884 | } | ||
| 885 | ).trigger('change'); | ||
| 886 | |||
| 887 | // Organization | ||
| 888 | brokerIdSelectBox.on('change', function() { | ||
| 889 | var userRole = roleSelectBox.val(); | ||
| 890 | // If Broker is selected, org is empty | ||
| 891 | // Show error message | ||
| 892 | if (userRole === 'subscriber') { | ||
| 893 | if (brokerIdSelectBox[0].selectedIndex !== 0) { | ||
| 894 | brokerIdFormField.removeClass('form-required'); | ||
| 895 | brokerIdFormField.removeClass('form-invalid'); | ||
| 896 | } | ||
| 897 | } | ||
| 898 | }); | ||
| 899 | |||
| 900 | addNewUserForm.on('submit', function(e) { | ||
| 901 | var userRole = roleSelectBox.val(); | ||
| 902 | |||
| 903 | // If Broker is selected, org is empty | ||
| 904 | // Show error message | ||
| 905 | if (userRole === 'subscriber') { | ||
| 906 | if (brokerIdSelectBox[0].selectedIndex == 0) { | ||
| 907 | brokerIdFormField.addClass('form-required'); | ||
| 908 | } else { | ||
| 909 | brokerIdFormField.removeClass('form-required'); | ||
| 910 | brokerIdFormField.removeClass('form-invalid'); | ||
| 911 | } | ||
| 912 | } else { | ||
| 913 | brokerIdFormField.removeClass('form-required'); | ||
| 914 | brokerIdFormField.removeClass('form-invalid'); | ||
| 915 | } | ||
| 916 | }); | ||
| 917 | |||
| 918 | })(jQuery); | ||
| 919 | </script> | ||
| 920 | <?php | ||
| 921 | } | ||
| 922 | |||
| 923 | function setUserProfileLogicEditUser($hook) | ||
| 924 | { | ||
| 925 | ?> | ||
| 926 | <script> | ||
| 927 | (function($) { | ||
| 928 | var addEditUserForm = $('#your-profile'); | ||
| 929 | var roleSelectBox = $('#role'); | ||
| 930 | var brokerCheckbox = $('.uam_group_selection input[type="checkbox"][id="uam_usergroups-1"]'); | ||
| 931 | var brokerIdFormField = $('.form-broker_id .form-field'); | ||
| 932 | var brokerGroup = $('.broker-group'); | ||
| 933 | var brokerSelectBox = $('#broker_id'); | ||
| 934 | |||
| 935 | roleSelectBox.on( | ||
| 936 | 'change', | ||
| 937 | function(e) { | ||
| 938 | var targetValue = e.target.value; | ||
| 939 | // If broker is selected | ||
| 940 | // Check "Broker" user group | ||
| 941 | if (targetValue === 'subscriber') { | ||
| 942 | brokerCheckbox[0].checked = true; | ||
| 943 | brokerGroup.slideDown(100); | ||
| 944 | } else { | ||
| 945 | brokerCheckbox[0].checked = false; | ||
| 946 | brokerGroup.slideUp(100); | ||
| 947 | brokerSelectBox[0].selectedIndex = 0; | ||
| 948 | |||
| 949 | brokerIdFormField.removeClass('form-required'); | ||
| 950 | brokerIdFormField.removeClass('form-invalid'); | ||
| 951 | } | ||
| 952 | } | ||
| 953 | ).trigger('change'); | ||
| 954 | |||
| 955 | // Organization | ||
| 956 | brokerSelectBox.on('change', function() { | ||
| 957 | var userRole = roleSelectBox.val(); | ||
| 958 | // If Broker is selected, org is empty | ||
| 959 | // Show error message | ||
| 960 | if (userRole === 'subscriber') { | ||
| 961 | if (brokerSelectBox[0].selectedIndex !== 0) { | ||
| 962 | brokerIdFormField.removeClass('form-required'); | ||
| 963 | brokerIdFormField.removeClass('form-invalid'); | ||
| 964 | } | ||
| 965 | } | ||
| 966 | }); | ||
| 967 | |||
| 968 | addEditUserForm.on('submit', function(e) { | ||
| 969 | var userRole = roleSelectBox.val(); | ||
| 970 | |||
| 971 | // If Broker is selected, org is empty | ||
| 972 | // Show error message | ||
| 973 | if (userRole === 'subscriber') { | ||
| 974 | if (brokerSelectBox[0].selectedIndex == 0) { | ||
| 975 | brokerIdFormField.addClass('form-required'); | ||
| 976 | brokerIdFormField.addClass('form-invalid'); | ||
| 977 | return false; | ||
| 978 | |||
| 979 | } else { | ||
| 980 | brokerIdFormField.removeClass('form-required'); | ||
| 981 | brokerIdFormField.removeClass('form-invalid'); | ||
| 982 | return true; | ||
| 983 | } | ||
| 984 | } else { | ||
| 985 | brokerIdFormField.removeClass('form-required'); | ||
| 986 | brokerIdFormField.removeClass('form-invalid'); | ||
| 987 | return true; | ||
| 988 | } | ||
| 989 | |||
| 990 | }); | ||
| 991 | })(jQuery); | ||
| 992 | </script> | ||
| 993 | <?php | ||
| 994 | } | ||
| 995 | 510 | ||
| 996 | add_action('init', 'handle_preflight'); | 511 | add_action('init', 'handle_preflight'); |
| 997 | function handle_preflight() | 512 | function handle_preflight() |
| ... | @@ -1018,225 +533,6 @@ add_role( | ... | @@ -1018,225 +533,6 @@ add_role( |
| 1018 | ) | 533 | ) |
| 1019 | ); | 534 | ); |
| 1020 | 535 | ||
| 1021 | add_action('show_user_profile', 'addCommonwellStaffInfo'); | ||
| 1022 | add_action('edit_user_profile', 'addCommonwellStaffInfo'); | ||
| 1023 | |||
| 1024 | function addCommonwellStaffInfo($user) | ||
| 1025 | { | ||
| 1026 | $user_id = $_GET['user_id']; | ||
| 1027 | if (user_can($user_id, 'cwl_staff')) { | ||
| 1028 | |||
| 1029 | $CommonwellTitle = get_user_meta($user_id, 'Commonwelltitle', true); | ||
| 1030 | $CommonwellPersonalizedMesssage = get_user_meta($user_id, 'CommonwellPersonalizedMesssage', true); | ||
| 1031 | $CommonwellTel = get_user_meta($user_id, 'CommonwellTel', true); | ||
| 1032 | $VideoLink = get_user_meta($user_id, 'VideoLink', true); | ||
| 1033 | ?> | ||
| 1034 | <h3>Commonwell Staff</h3> | ||
| 1035 | |||
| 1036 | <table class="form-table"> | ||
| 1037 | <tr> | ||
| 1038 | <th><label for="organization_profile">Commonwell Title</label></th> | ||
| 1039 | <td><input id="Commonwelltitle" type="text" name="Commonwelltitle" value="<?php echo $CommonwellTitle; ?>" class="regular-text" /></td> | ||
| 1040 | </tr> | ||
| 1041 | <tr> | ||
| 1042 | <th><label for="organization_profile">Personalized Messsage</label></th> | ||
| 1043 | <td><textarea id="CommonwellPersonalizedMesssage" name="CommonwellPersonalizedMesssage" /> | ||
| 1044 | <?php echo $CommonwellPersonalizedMesssage; ?> | ||
| 1045 | </textarea></td> | ||
| 1046 | </tr> | ||
| 1047 | <tr> | ||
| 1048 | <th><label for="organization_profile">Phone</label></th> | ||
| 1049 | <td><input type='tel' id="CommonwellTel" name="CommonwellTel" class="regular-text" pattern='[\+]\d{1}[\(]\d{3}[\)-]\d{3}[\-]\d{4} [\ext]\d{3}' value=" <?php echo $CommonwellTel; ?>" title='Phone Number (Format: +9(999)-999-9999 ext 999)'> | ||
| 1050 | (Format: +9(999)-999-9999 ext 999) | ||
| 1051 | </td> | ||
| 1052 | </tr> | ||
| 1053 | <tr> | ||
| 1054 | <th><label for="organization_profile">Video Link</label></th> | ||
| 1055 | <td><input id="VideoLink" type="text" name="VideoLink" value="<?php echo $VideoLink; ?>" class="regular-text" /></td> | ||
| 1056 | </tr> | ||
| 1057 | </table> | ||
| 1058 | <?php | ||
| 1059 | } | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | /** | ||
| 1063 | * Save additional profile field | ||
| 1064 | */ | ||
| 1065 | |||
| 1066 | add_action('personal_options_update', 'saveCommonwellStaffInfo'); | ||
| 1067 | add_action('edit_user_profile_update', 'saveCommonwellStaffInfo'); | ||
| 1068 | function saveCommonwellStaffInfo($user_id) | ||
| 1069 | { | ||
| 1070 | update_user_meta($user_id, 'Commonwelltitle', sanitize_text_field($_POST['Commonwelltitle'])); | ||
| 1071 | update_user_meta( | ||
| 1072 | $user_id, | ||
| 1073 | 'CommonwellPersonalizedMesssage', | ||
| 1074 | sanitize_text_field($_POST['CommonwellPersonalizedMesssage']) | ||
| 1075 | ); | ||
| 1076 | update_user_meta($user_id, 'CommonwellTel', sanitize_text_field($_POST['CommonwellTel'])); | ||
| 1077 | update_user_meta($user_id, 'VideoLink', sanitize_text_field($_POST['VideoLink'])); | ||
| 1078 | } | ||
| 1079 | |||
| 1080 | add_action('show_user_profile', 'my_show_extra_profile_fields'); | ||
| 1081 | add_action('edit_user_profile', 'my_show_extra_profile_fields'); | ||
| 1082 | |||
| 1083 | function my_show_extra_profile_fields($user) | ||
| 1084 | { | ||
| 1085 | |||
| 1086 | $user_id = $_GET['user_id']; | ||
| 1087 | if (user_can($user_id, 'cwl_staff')) { | ||
| 1088 | include_once $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-config.php'; | ||
| 1089 | |||
| 1090 | global $wpdb; | ||
| 1091 | |||
| 1092 | $query = get_option('broker_list') ? unserialize(get_option('broker_list')) : []; | ||
| 1093 | |||
| 1094 | foreach ($query as $key => $row) { | ||
| 1095 | |||
| 1096 | $brokers[$row['id']]['id'] = $row['id']; | ||
| 1097 | $brokers[$row['id']]['broker_id'] = $row['broker_id']; | ||
| 1098 | $brokers[$row['id']]['name'] = $row['brokerage']; | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | $brokersSelected = 'select broker_id from wp_broker_staff where staff_id =' . $user_id; | ||
| 1102 | |||
| 1103 | foreach ($wpdb->get_results($brokersSelected) as $row) { | ||
| 1104 | |||
| 1105 | $brokersPicked[] = $row->broker_id; | ||
| 1106 | unset($brokers[$row->broker_id]); | ||
| 1107 | } | ||
| 1108 | ; | ||
| 1109 | |||
| 1110 | $brokersLeft = $brokers; | ||
| 1111 | |||
| 1112 | ?> | ||
| 1113 | |||
| 1114 | |||
| 1115 | <table class="form-table"> | ||
| 1116 | |||
| 1117 | <form> | ||
| 1118 | <fieldset> | ||
| 1119 | <tr> | ||
| 1120 | |||
| 1121 | |||
| 1122 | <th><label>Brokers Served</label></th> | ||
| 1123 | |||
| 1124 | </tr> | ||
| 1125 | <tr> | ||
| 1126 | <td width="30%" align="center"> | ||
| 1127 | YOUR LIST | ||
| 1128 | <select style="width:100%;" name="brokerselected[]" id="select-to" multiple="multiple" size="5"> | ||
| 1129 | <?php | ||
| 1130 | |||
| 1131 | foreach ($query as $key => $row) { | ||
| 1132 | //error_log(print_r($brokerPicked,true)); | ||
| 1133 | if (in_array($row['broker_id'], $brokersPicked)) { | ||
| 1134 | |||
| 1135 | ?> | ||
| 1136 | <option selected="selected" value="<?php echo $row['broker_id']; ?>"><?php echo $row['brokerage']; ?></option> | ||
| 1137 | |||
| 1138 | |||
| 1139 | |||
| 1140 | <?php } | ||
| 1141 | }?> | ||
| 1142 | </select> | ||
| 1143 | </td> | ||
| 1144 | <td width="20%"> | ||
| 1145 | |||
| 1146 | |||
| 1147 | <a href="JavaScript:void(0);" style="float:left;" id="btn-remove">Remove »</a> | ||
| 1148 | |||
| 1149 | <a href="JavaScript:void(0);" style="float:right;" id="btn-add">« Add </a> | ||
| 1150 | </td> | ||
| 1151 | <td width="30%" align="center"> | ||
| 1152 | BROKERS | ||
| 1153 | <select style="width:100%;" name="selectfrom" id="select-from" multiple size="5"> | ||
| 1154 | <?php foreach ($brokersLeft as $brokerLeft) {?> | ||
| 1155 | |||
| 1156 | <option value="<?php echo $brokerLeft['broker_id']; ?>"><?php echo $brokerLeft['name']; ?></option> | ||
| 1157 | <?php }?> | ||
| 1158 | |||
| 1159 | </select> | ||
| 1160 | <td> | ||
| 1161 | |||
| 1162 | </tr> | ||
| 1163 | |||
| 1164 | </fieldset> | ||
| 1165 | </form> | ||
| 1166 | |||
| 1167 | </td> | ||
| 1168 | </tr> | ||
| 1169 | |||
| 1170 | </table> | ||
| 1171 | <script> | ||
| 1172 | jQuery(document).ready( | ||
| 1173 | function($) { | ||
| 1174 | |||
| 1175 | $('#btn-add').click( | ||
| 1176 | function() { | ||
| 1177 | $('#select-from option:selected').each( | ||
| 1178 | function() { | ||
| 1179 | $('#select-to').append("<option selected='selected' value='" + $(this).val() + "'>" + $(this).text() + "</option>"); | ||
| 1180 | $(this).remove(); | ||
| 1181 | } | ||
| 1182 | ); | ||
| 1183 | } | ||
| 1184 | ); | ||
| 1185 | $('#btn-remove').click( | ||
| 1186 | function() { | ||
| 1187 | $('#select-to option:selected').each( | ||
| 1188 | function() { | ||
| 1189 | $('#select-from').append("<option value='" + $(this).val() + "'>" + $(this).text() + "</option>"); | ||
| 1190 | $(this).remove(); | ||
| 1191 | } | ||
| 1192 | ); | ||
| 1193 | } | ||
| 1194 | ); | ||
| 1195 | |||
| 1196 | $(document).on( | ||
| 1197 | 'submit', '#your-profile', | ||
| 1198 | function() { | ||
| 1199 | $('#select-to option').each( | ||
| 1200 | function() { | ||
| 1201 | $(this).attr("selected", 1); | ||
| 1202 | } | ||
| 1203 | ); | ||
| 1204 | } | ||
| 1205 | ); | ||
| 1206 | |||
| 1207 | } | ||
| 1208 | ); | ||
| 1209 | </script> | ||
| 1210 | |||
| 1211 | <?php } | ||
| 1212 | } | ||
| 1213 | |||
| 1214 | add_action('personal_options_update', 'my_save_extra_profile_fields'); | ||
| 1215 | add_action('edit_user_profile_update', 'my_save_extra_profile_fields'); | ||
| 1216 | |||
| 1217 | function my_save_extra_profile_fields() | ||
| 1218 | { | ||
| 1219 | |||
| 1220 | global $wpdb; | ||
| 1221 | global $user_id; | ||
| 1222 | |||
| 1223 | $wpdb->delete( | ||
| 1224 | 'wp_broker_staff', | ||
| 1225 | array('staff_id' => $user_id) | ||
| 1226 | ); | ||
| 1227 | |||
| 1228 | foreach ($_POST['brokerselected'] as $brokerselected) { | ||
| 1229 | //error_log($brokerselected); | ||
| 1230 | |||
| 1231 | $wpdb->insert( | ||
| 1232 | 'wp_broker_staff', | ||
| 1233 | array( | ||
| 1234 | 'staff_id' => $user_id, | ||
| 1235 | 'broker_id' => $brokerselected, | ||
| 1236 | ) | ||
| 1237 | ); | ||
| 1238 | } | ||
| 1239 | } | ||
| 1240 | 536 | ||
| 1241 | // Our custom post type function | 537 | // Our custom post type function |
| 1242 | function create_posttype() | 538 | function create_posttype() |
| ... | @@ -1317,79 +613,7 @@ function ja_theme_setup() | ... | @@ -1317,79 +613,7 @@ function ja_theme_setup() |
| 1317 | { | 613 | { |
| 1318 | add_theme_support('post-thumbnails', array('post', 'notifications')); | 614 | add_theme_support('post-thumbnails', array('post', 'notifications')); |
| 1319 | } | 615 | } |
| 1320 | function custom_post_type() | ||
| 1321 | { | ||
| 1322 | |||
| 1323 | // Set UI labels for Custom Post Type | ||
| 1324 | $labelsNewsandEvents = array( | ||
| 1325 | 'name' => _x('News', 'Post Type General Name', 'commonwell-corp'), | ||
| 1326 | 'singular_name' => _x('News', 'Post Type Singular Name', 'commonwell-corp'), | ||
| 1327 | 'menu_name' => __('Notifications', 'commonwell-corp'), | ||
| 1328 | 'parent_item_colon' => __('Parent News ', 'commonwell-corp'), | ||
| 1329 | 'all_items' => __('All News', 'commonwell-corp'), | ||
| 1330 | 'view_item' => __('View News', 'commonwell-corp'), | ||
| 1331 | 'add_new_item' => __('Add New News', 'commonwell-corp'), | ||
| 1332 | 'add_new' => __('Add New', 'commonwell-corp'), | ||
| 1333 | 'edit_item' => __('Edit News', 'commonwell-corp'), | ||
| 1334 | 'update_item' => __('Update News', 'commonwell-corp'), | ||
| 1335 | 'search_items' => __('Search News', 'commonwell-corp'), | ||
| 1336 | 'not_found' => __('Not Found', 'commonwell-corp'), | ||
| 1337 | 'not_found_in_trash' => __('Not found in Trash', 'commonwell-corp'), | ||
| 1338 | ); | ||
| 1339 | |||
| 1340 | // Set other options for Custom Post Type | ||
| 1341 | |||
| 1342 | $labelsNewsandEvents = array( | ||
| 1343 | 'label' => __('news', 'twentythirteen'), | ||
| 1344 | 'description' => __('notification news and reviews', 'twentythirteen'), | ||
| 1345 | 'labels' => $labels, | ||
| 1346 | // Features this CPT supports in Post Editor | ||
| 1347 | 'supports' => array( | ||
| 1348 | 'title', | ||
| 1349 | 'editor', | ||
| 1350 | 'excerpt', | ||
| 1351 | 'author', | ||
| 1352 | 'thumbnail', | ||
| 1353 | 'comments', | ||
| 1354 | 'revisions', | ||
| 1355 | 'custom-fields', | ||
| 1356 | ), | ||
| 1357 | // You can associate this CPT with a taxonomy or custom taxonomy. | ||
| 1358 | 'taxonomies' => array('genres'), | ||
| 1359 | /* A hierarchical CPT is like Pages and can have | ||
| 1360 | * Parent and child items. A non-hierarchical CPT | ||
| 1361 | * is like Posts. | ||
| 1362 | */ | ||
| 1363 | 'hierarchical' => false, | ||
| 1364 | 'public' => true, | ||
| 1365 | 'show_ui' => true, | ||
| 1366 | 'show_in_menu' => true, | ||
| 1367 | 'show_in_nav_menus' => true, | ||
| 1368 | 'show_in_admin_bar' => true, | ||
| 1369 | 'menu_position' => 5, | ||
| 1370 | 'can_export' => true, | ||
| 1371 | 'has_archive' => true, | ||
| 1372 | 'exclude_from_search' => false, | ||
| 1373 | 'publicly_queryable' => true, | ||
| 1374 | 'capability_type' => 'post', | ||
| 1375 | ); | ||
| 1376 | |||
| 1377 | // Registering your Custom Post Type | ||
| 1378 | register_post_type('new_and_events', $args); | ||
| 1379 | } | ||
| 1380 | |||
| 1381 | global $post; | ||
| 1382 | |||
| 1383 | if ($post->type == 'Notifications') { | ||
| 1384 | get_template_part(get_bloginfo('template_url') . '/broker_pages.php'); | ||
| 1385 | error_log('tre'); | ||
| 1386 | } | ||
| 1387 | /* Hook into the 'init' action so that the function | ||
| 1388 | * Containing our post type registration is not | ||
| 1389 | * unnecessarily executed. | ||
| 1390 | */ | ||
| 1391 | 616 | ||
| 1392 | add_action('init', 'custom_post_type', 0); | ||
| 1393 | 617 | ||
| 1394 | function clean_custom_menus() | 618 | function clean_custom_menus() |
| 1395 | { | 619 | { |
| ... | @@ -1510,7 +734,7 @@ function clean_custom_moblie_menus() | ... | @@ -1510,7 +734,7 @@ function clean_custom_moblie_menus() |
| 1510 | <span class="icon-bar"></span> | 734 | <span class="icon-bar"></span> |
| 1511 | <span class="icon-bar"></span> | 735 | <span class="icon-bar"></span> |
| 1512 | </button> | 736 | </button> |
| 1513 | <a href="' . get_option('home') . '/broker-landing-page/"> | 737 | <a href="' . get_option('home') .'"> |
| 1514 | <img id="mobile-logo" src="' . get_bloginfo('template_url') . '/images/Commonwell-logo.svg" alt="Commonwell Mutual Insurance Group logo" /> | 738 | <img id="mobile-logo" src="' . get_bloginfo('template_url') . '/images/Commonwell-logo.svg" alt="Commonwell Mutual Insurance Group logo" /> |
| 1515 | </a> | 739 | </a> |
| 1516 | <button onClick="showSearch();" type="button" class="search_icon_button" ><i class="search_icon material-icons"></i></button> | 740 | <button onClick="showSearch();" type="button" class="search_icon_button" ><i class="search_icon material-icons"></i></button> |
| ... | @@ -1748,38 +972,6 @@ function NewsText() | ... | @@ -1748,38 +972,6 @@ function NewsText() |
| 1748 | } | 972 | } |
| 1749 | 973 | ||
| 1750 | 974 | ||
| 1751 | add_shortcode("ImpactNews", "ImpactNews"); | ||
| 1752 | function ImpactNews() | ||
| 1753 | { | ||
| 1754 | $custom_args = array( | ||
| 1755 | 'post_type' => 'new_and_events', | ||
| 1756 | 'posts_per_page' => 10, | ||
| 1757 | 'paged' => 1, | ||
| 1758 | 'meta_query' => array( | ||
| 1759 | 'relation' => 'AND', | ||
| 1760 | array( | ||
| 1761 | 'key' => 'type', | ||
| 1762 | 'value' => 'Impact', | ||
| 1763 | 'compare' => '=', | ||
| 1764 | ), | ||
| 1765 | ) | ||
| 1766 | ); | ||
| 1767 | |||
| 1768 | $custom_query = new WP_Query($custom_args); | ||
| 1769 | |||
| 1770 | if ($custom_query->have_posts()): | ||
| 1771 | $news = '<div class="impact-news"><h3>(UPCOMING PROGRAM DATES)</h3><hr>'; | ||
| 1772 | while ($custom_query->have_posts()): $custom_query->the_post(); | ||
| 1773 | $id = get_the_ID(); | ||
| 1774 | $post = get_post($id); | ||
| 1775 | $news .= '<h4>'.$post->post_title.'</h4><p>'. $post->post_content.'</p><hr>' ; | ||
| 1776 | |||
| 1777 | endwhile; | ||
| 1778 | $newspost = $news.'</div>'; | ||
| 1779 | endif; | ||
| 1780 | |||
| 1781 | return $newspost; | ||
| 1782 | } | ||
| 1783 | 975 | ||
| 1784 | add_shortcode("WaveButton", "WaveButton"); | 976 | add_shortcode("WaveButton", "WaveButton"); |
| 1785 | function WaveButton() | 977 | function WaveButton() |
| ... | @@ -2111,111 +1303,6 @@ function disable_emojis_remove_dns_prefetch($urls, $relation_type) | ... | @@ -2111,111 +1303,6 @@ function disable_emojis_remove_dns_prefetch($urls, $relation_type) |
| 2111 | } | 1303 | } |
| 2112 | 1304 | ||
| 2113 | 1305 | ||
| 2114 | function broker_override_fields($broker_override_id) | ||
| 2115 | { | ||
| 2116 | $brokerList = getBrokerageList(); | ||
| 2117 | $userBrokerId = $broker_override_id; | ||
| 2118 | ?> | ||
| 2119 | |||
| 2120 | <select name="broker_override_id" class="broker_override_id"> | ||
| 2121 | <option value="">Select Broker</option> | ||
| 2122 | <?php foreach ($brokerList as $broker): ?> | ||
| 2123 | <?php | ||
| 2124 | $isSelected = $userBrokerId === $broker['brokerage'] ? 'selected="selected"' : ''; | ||
| 2125 | ?> | ||
| 2126 | <option value="<?php echo $broker['brokerage']; ?>" <?php echo $isSelected; ?>><?php echo $broker['brokerage']; ?></option> | ||
| 2127 | <?php endforeach;?> | ||
| 2128 | </select> | ||
| 2129 | |||
| 2130 | <?php | ||
| 2131 | } | ||
| 2132 | |||
| 2133 | function matchBrokerageFromList($post_title) | ||
| 2134 | { | ||
| 2135 | $brokerList = get_option('broker_list') ? unserialize(get_option('broker_list')) : []; | ||
| 2136 | $searchword = $post_title; | ||
| 2137 | $matches = array(); | ||
| 2138 | |||
| 2139 | foreach ($brokerList as $k => $v) { | ||
| 2140 | |||
| 2141 | $brokerage = substr($v['brokerage'], 0, strrpos($v['brokerage'], '-')); | ||
| 2142 | |||
| 2143 | if (strpos($searchword, $brokerage) !== false) { | ||
| 2144 | $matches[$k] = $v['brokerage']; | ||
| 2145 | } | ||
| 2146 | } | ||
| 2147 | |||
| 2148 | return $matches; | ||
| 2149 | } | ||
| 2150 | |||
| 2151 | function getRecipientWithBrokerId($Brokerage) | ||
| 2152 | { | ||
| 2153 | $available_brokers = get_users( | ||
| 2154 | array( | ||
| 2155 | |||
| 2156 | 'meta_query' => array( | ||
| 2157 | array( | ||
| 2158 | 'key' => 'brokerage', | ||
| 2159 | 'value' => $Brokerage, | ||
| 2160 | 'compare' => '==', | ||
| 2161 | ), | ||
| 2162 | |||
| 2163 | ), | ||
| 2164 | ) | ||
| 2165 | ); | ||
| 2166 | |||
| 2167 | ob_start(); | ||
| 2168 | ?> | ||
| 2169 | <select name="lead_recipien_id" class="lead_recipien_id"> | ||
| 2170 | <option value="">Select Recipient</option> | ||
| 2171 | <?php foreach ($available_brokers as $broker): ?> | ||
| 2172 | <?php | ||
| 2173 | $isSelected = ""; | ||
| 2174 | ?> | ||
| 2175 | <option value="<?php echo $broker->ID; ?>"><?php echo $broker->user_email; ?></option> | ||
| 2176 | <?php endforeach;?> | ||
| 2177 | </select> | ||
| 2178 | |||
| 2179 | |||
| 2180 | <?php | ||
| 2181 | } | ||
| 2182 | |||
| 2183 | add_action('wp_ajax_get_recipients', 'ajax_get_Recipien_With_BrokerId'); | ||
| 2184 | add_action('wp_ajax_nopriv_get_recipients', 'ajax_get_Recipien_With_BrokerId'); | ||
| 2185 | function ajax_get_Recipien_With_BrokerId() | ||
| 2186 | { | ||
| 2187 | |||
| 2188 | $broker_override_id = $_POST['broker_override_id']; | ||
| 2189 | $available_brokers = get_users( | ||
| 2190 | array( | ||
| 2191 | |||
| 2192 | 'meta_query' => array( | ||
| 2193 | array( | ||
| 2194 | 'key' => 'brokerage', | ||
| 2195 | 'value' => $broker_override_id, | ||
| 2196 | 'compare' => '==', | ||
| 2197 | ), | ||
| 2198 | |||
| 2199 | ), | ||
| 2200 | ) | ||
| 2201 | ); | ||
| 2202 | |||
| 2203 | ?> | ||
| 2204 | <select name="lead_recipien_id" class="lead_recipien_id"> | ||
| 2205 | <option value="">Select Recipient</option> | ||
| 2206 | <?php foreach ($available_brokers as $broker): ?> | ||
| 2207 | <?php | ||
| 2208 | $isSelected = ""; | ||
| 2209 | ?> | ||
| 2210 | <option value="<?php echo $broker->ID; ?>"><?php echo $broker->user_email; ?></option> | ||
| 2211 | <?php endforeach;?> | ||
| 2212 | </select> | ||
| 2213 | |||
| 2214 | |||
| 2215 | <?php $output = ob_get_clean(); | ||
| 2216 | wp_send_json_success($output); | ||
| 2217 | die(); | ||
| 2218 | } | ||
| 2219 | 1306 | ||
| 2220 | add_shortcode('add_hr', 'add_hr_shortcode'); | 1307 | add_shortcode('add_hr', 'add_hr_shortcode'); |
| 2221 | 1308 | ||
| ... | @@ -2244,640 +1331,6 @@ function remove_custom_cookie_admin() | ... | @@ -2244,640 +1331,6 @@ function remove_custom_cookie_admin() |
| 2244 | 1331 | ||
| 2245 | 1332 | ||
| 2246 | 1333 | ||
| 2247 | |||
| 2248 | function badgeos_send_achievements_email_custom( $user_id, $achievement_id, $this_trigger, $site_id, $args, $entry_id ) { | ||
| 2249 | |||
| 2250 | global $wpdb; | ||
| 2251 | |||
| 2252 | |||
| 2253 | $badgeos_settings = ( $exists = badgeos_utilities::get_option( 'badgeos_settings' ) ) ? $exists : array(); | ||
| 2254 | $achievement_post_type = badgeos_utilities::get_post_type( $achievement_id ); | ||
| 2255 | $achievement_type = $badgeos_settings['achievement_main_post_type']; | ||
| 2256 | $post_obj = get_page_by_path( $achievement_post_type, OBJECT, $achievement_type ); | ||
| 2257 | |||
| 2258 | $parent_post_type = ''; | ||
| 2259 | if( $post_obj ) { | ||
| 2260 | $parent_post_type = $post_obj->post_type; | ||
| 2261 | } | ||
| 2262 | if ( trim( $achievement_type ) == trim( $parent_post_type ) ) { | ||
| 2263 | |||
| 2264 | $badgeos_admin_tools = ( $exists = badgeos_utilities::get_option( 'badgeos_admin_tools' ) ) ? $exists : array(); | ||
| 2265 | |||
| 2266 | $email_cc_list = badgeos_bcc_cc_emails( $badgeos_admin_tools, 'email_achievement_cc_list', 'cc' ); | ||
| 2267 | $email_bcc_list = badgeos_bcc_cc_emails( $badgeos_admin_tools, 'email_achievement_bcc_list', 'bcc' ); | ||
| 2268 | |||
| 2269 | if( ! isset( $badgeos_admin_tools['email_disable_earned_achievement_email'] ) || $badgeos_admin_tools['email_disable_earned_achievement_email'] == 'no' ) { | ||
| 2270 | |||
| 2271 | $results = $wpdb->get_results( "select * from ".$wpdb->prefix."badgeos_achievements where entry_id='".$entry_id."'", 'ARRAY_A' ); | ||
| 2272 | if( count( $results ) > 0 ) { | ||
| 2273 | $record = $results[ 0 ]; | ||
| 2274 | $achievement_type = $record[ 'post_type' ]; | ||
| 2275 | $type_title = $post_obj->post_title; | ||
| 2276 | $step_type = trim( $badgeos_settings['achievement_step_post_type'] ); | ||
| 2277 | $issue_date = $record[ 'date_earned' ]; | ||
| 2278 | $rec_type = $record[ 'rec_type' ]; | ||
| 2279 | $rec_date_earned = $record['date_earned']; | ||
| 2280 | $date_format = badgeos_utilities::get_option( 'date_format', true ); | ||
| 2281 | $time_format = badgeos_utilities::get_option( 'time_format', true ); | ||
| 2282 | if( get_post_meta( $achievement_id, '_open_badge_enable_baking', true ) ) { | ||
| 2283 | $evidence_page_id = get_option( 'badgeos_evidence_url' ); | ||
| 2284 | $badgeos_evidence_url = get_permalink( $evidence_page_id ); | ||
| 2285 | $badgeos_evidence_url = add_query_arg( 'bg', $record[ 'ID' ], $badgeos_evidence_url ); | ||
| 2286 | $badgeos_evidence_url = add_query_arg( 'eid', $record[ 'entry_id' ], $badgeos_evidence_url ); | ||
| 2287 | $badgeos_evidence_url = add_query_arg( 'uid', $record[ 'user_id' ], $badgeos_evidence_url ); | ||
| 2288 | } | ||
| 2289 | |||
| 2290 | if( ! empty( $achievement_type ) && trim( $achievement_type ) != $step_type ) { | ||
| 2291 | $email_subject = $badgeos_admin_tools['email_achievement_subject']; | ||
| 2292 | if( empty( $email_subject ) ) { | ||
| 2293 | $email_subject = __( 'Congratulation for earning an achievement', 'badgeos' ); | ||
| 2294 | } | ||
| 2295 | |||
| 2296 | $email_content = $badgeos_admin_tools['email_achievement_content']; | ||
| 2297 | |||
| 2298 | $from_title = get_bloginfo( 'name' ); | ||
| 2299 | $from_email = get_bloginfo( 'admin_email' ); | ||
| 2300 | |||
| 2301 | if( !empty( $badgeos_admin_tools['email_general_from_name'] ) ) { | ||
| 2302 | $from_title = $badgeos_admin_tools['email_general_from_name']; | ||
| 2303 | } | ||
| 2304 | |||
| 2305 | if( !empty( $badgeos_admin_tools['email_general_from_email'] ) ) { | ||
| 2306 | $from_title = $badgeos_admin_tools['email_general_from_email']; | ||
| 2307 | } | ||
| 2308 | |||
| 2309 | $achievement_title = $record[ 'achievement_title' ]; | ||
| 2310 | $points = $record[ 'points' ]; | ||
| 2311 | $achievement_image = badgeos_get_achievement_post_thumbnail( $achievement_id, 'full' ); | ||
| 2312 | |||
| 2313 | $user_to_title = ''; | ||
| 2314 | $user_email = ''; | ||
| 2315 | $to_user_id = $record[ 'user_id']; | ||
| 2316 | $user_to = get_user_by( 'ID', $record[ 'user_id'] ); | ||
| 2317 | if( $user_to ) { | ||
| 2318 | $user_to_title = $user_to->display_name; | ||
| 2319 | $user_email = $user_to->user_email; | ||
| 2320 | } | ||
| 2321 | |||
| 2322 | $headers[] = 'From: '.$from_title.' <'.$from_email.'>'; | ||
| 2323 | $headers[] = 'Content-Type: text/html; charset=UTF-8'; | ||
| 2324 | if( is_array( $email_cc_list ) && count( $email_cc_list ) > 0 ) { | ||
| 2325 | foreach( $email_cc_list as $cc_id ) { | ||
| 2326 | if( !empty( $cc_id ) ) { | ||
| 2327 | $headers[] = 'Cc: '.$cc_id; | ||
| 2328 | } | ||
| 2329 | } | ||
| 2330 | } | ||
| 2331 | |||
| 2332 | if( is_array( $email_bcc_list ) && count( $email_bcc_list ) > 0 ) { | ||
| 2333 | foreach( $email_bcc_list as $bcc_id ) { | ||
| 2334 | if( !empty( $bcc_id ) ) { | ||
| 2335 | $headers[] = 'Bcc: '.$bcc_id; | ||
| 2336 | } | ||
| 2337 | } | ||
| 2338 | } | ||
| 2339 | |||
| 2340 | $email_subject = str_replace('[achievement_type]', $type_title, $email_subject ); | ||
| 2341 | $email_subject = str_replace('[achievement_title]', $achievement_title, $email_subject ); | ||
| 2342 | $email_subject = str_replace('[points]', $points, $email_subject ); | ||
| 2343 | $email_subject = str_replace('[user_email]', $user_email, $email_subject ); | ||
| 2344 | $email_subject = str_replace('[user_name]', $user_to_title, $email_subject ); | ||
| 2345 | |||
| 2346 | ob_start(); | ||
| 2347 | |||
| 2348 | $email_content = stripslashes( html_entity_decode( $email_content ) ); | ||
| 2349 | $email_content = str_replace("\'","'", $email_content); | ||
| 2350 | $email_content = str_replace('\"','"', $email_content); | ||
| 2351 | |||
| 2352 | $email_content = str_replace('[achievement_type]', $type_title, $email_content ); | ||
| 2353 | $email_content = str_replace('[achievement_title]', $achievement_title, $email_content ); | ||
| 2354 | $email_content = str_replace('[date_earned]', date( $date_format.' '.$time_format, strtotime($record['date_earned']) ), $email_content ); | ||
| 2355 | $email_content = str_replace('[achievement_link]', get_permalink($achievement_id), $email_content ); | ||
| 2356 | $email_content = str_replace('[points]', $points, $email_content ); | ||
| 2357 | $email_content = str_replace('[user_email]', $user_email, $email_content ); | ||
| 2358 | $email_content = str_replace('[user_name]', $user_to_title."<p> </p>", $email_content ); | ||
| 2359 | $email_content = str_replace('[achievement_image]', "<p> </p>".$achievement_image."<p> </p>", $email_content ); | ||
| 2360 | $email_content = str_replace('[user_profile_link]', get_edit_profile_url( $to_user_id ), $email_content ); | ||
| 2361 | $email_content = str_replace('[evidence]', badgeos_include_evidence_in_email( $achievement_id, $issue_date, $rec_type, $badgeos_evidence_url, $rec_date_earned ), $email_content); | ||
| 2362 | |||
| 2363 | ?> | ||
| 2364 | <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;"> | ||
| 2365 | <tr> | ||
| 2366 | <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;"> | ||
| 2367 | <?php echo $email_content; ?> | ||
| 2368 | </td> | ||
| 2369 | </tr> | ||
| 2370 | </table> | ||
| 2371 | <?php | ||
| 2372 | |||
| 2373 | |||
| 2374 | $message = ob_get_contents(); | ||
| 2375 | ob_end_clean(); | ||
| 2376 | if( ! empty( $user_email ) ) { | ||
| 2377 | |||
| 2378 | |||
| 2379 | wp_mail( $user_email, strip_tags( $email_subject ), $message, $headers ); | ||
| 2380 | } | ||
| 2381 | } | ||
| 2382 | } | ||
| 2383 | } | ||
| 2384 | } | ||
| 2385 | |||
| 2386 | } | ||
| 2387 | |||
| 2388 | |||
| 2389 | add_action( 'badgeos_award_achievement', 'badgeos_send_achievements_email_custom', 10, 6 ); | ||
| 2390 | |||
| 2391 | |||
| 2392 | function remove_badgeos_can_notify_user( $user_login, $user ) { | ||
| 2393 | update_user_meta($user->ID, '_badgeos_can_notify_user', ''); | ||
| 2394 | } | ||
| 2395 | |||
| 2396 | add_action('wp_login', 'remove_badgeos_can_notify_user', 10, 2 ); | ||
| 2397 | |||
| 2398 | |||
| 2399 | |||
| 2400 | |||
| 2401 | add_shortcode('textbooks', 'textbooks_shortcode'); | ||
| 2402 | |||
| 2403 | function textbooks_shortcode() | ||
| 2404 | { | ||
| 2405 | ob_start(); | ||
| 2406 | global $wpdb; | ||
| 2407 | $results = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."usermeta where meta_key LIKE '%learndash_group_users%' and user_id =".get_current_user_id()); | ||
| 2408 | |||
| 2409 | foreach( $results as $result){ | ||
| 2410 | $sfwd_groups = get_post_meta($result->meta_value , '_groups', true ); | ||
| 2411 | if(!empty($sfwd_groups['groups_group_materials']) ){ | ||
| 2412 | echo '<h4 style="font-size:1rem;">'.get_the_title($result->meta_value).'</h4>'; | ||
| 2413 | echo '<div class="material">'.$sfwd_groups['groups_group_materials'].'</div>'; | ||
| 2414 | } | ||
| 2415 | } | ||
| 2416 | |||
| 2417 | |||
| 2418 | $enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false); | ||
| 2419 | foreach($enrolled_courses as $enrolled_course){ | ||
| 2420 | $lesson_materials=""; | ||
| 2421 | $sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true ); | ||
| 2422 | $course_steps = get_post_meta($enrolled_course , 'ld_course_steps', true ); | ||
| 2423 | $course_steps = $course_steps['steps']['h']['sfwd-lessons']; | ||
| 2424 | foreach($course_steps as $key => $course_step){ | ||
| 2425 | $sfwd_lessons = get_post_meta($key , '_sfwd-lessons', true ); | ||
| 2426 | $lesson_materials .= $sfwd_lessons['sfwd-lessons_lesson_materials']; | ||
| 2427 | } | ||
| 2428 | if(!empty($sfwd_course['sfwd-courses_course_materials']) || !empty($lesson_materials) ){ | ||
| 2429 | echo '<h4 style="font-size:1rem;">'.str_replace("Private:","",get_the_title($enrolled_course )).'</h4>'; | ||
| 2430 | echo '<div class="material">'.$sfwd_course['sfwd-courses_course_materials'].$lesson_materials.'</div>'; | ||
| 2431 | } | ||
| 2432 | } | ||
| 2433 | ?> | ||
| 2434 | |||
| 2435 | <?php | ||
| 2436 | |||
| 2437 | return ob_get_clean(); | ||
| 2438 | } | ||
| 2439 | |||
| 2440 | |||
| 2441 | |||
| 2442 | add_shortcode('badges', 'badges_shortcode'); | ||
| 2443 | |||
| 2444 | function badges_shortcode() | ||
| 2445 | { | ||
| 2446 | ob_start(); | ||
| 2447 | //learndash_groups_to_course(get_current_user_id()); | ||
| 2448 | global $wpdb; | ||
| 2449 | $results = $wpdb->get_results("SELECT ID, date_earned, achievement_title FROM ".$wpdb->prefix."badgeos_achievements where post_type='badges' and user_id =".get_current_user_id()); | ||
| 2450 | echo '<div class="badges">'; | ||
| 2451 | foreach( $results as $result){ | ||
| 2452 | $thumbnail_id = get_post_meta($result->ID, '_thumbnail_id', true ); | ||
| 2453 | echo '<div class="badge_container" data-title="'.str_replace(":","_",str_replace(" ","-",get_the_title($result->ID))).'">'.wp_get_attachment_image($thumbnail_id, array('300', '200'), "", array( "class" => "img-responsive" ) ).'</div>'; | ||
| 2454 | } | ||
| 2455 | echo '</div>'; | ||
| 2456 | echo '<p class="has-text-align-center">Click to download your certificate</p>'; | ||
| 2457 | |||
| 2458 | echo '<div class="cert">'; | ||
| 2459 | |||
| 2460 | |||
| 2461 | |||
| 2462 | $enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false); | ||
| 2463 | foreach($enrolled_courses as $enrolled_course){ | ||
| 2464 | if($enrolled_course == 45591){ | ||
| 2465 | continue; | ||
| 2466 | } | ||
| 2467 | $cert = learndash_get_course_certificate_link($enrolled_course, get_current_user_id()); | ||
| 2468 | if(!empty($cert)){ | ||
| 2469 | $sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true ); | ||
| 2470 | $thumbnail_id = get_post_meta($sfwd_course['sfwd-courses_certificate'], '_thumbnail_id', true ); | ||
| 2471 | echo '<div class="badge_container cert"><a target="_blank" class="cert_link" href="'.$cert.'">' | ||
| 2472 | .wp_get_attachment_image($thumbnail_id, array('200', '100'), "", array( "class" => "img-responsive" ) ).' </a><br><strong>'. date( 'F, d, Y', get_user_meta(get_current_user_id(), 'course_completed_'.$enrolled_course, true )).'</strong></div>'; | ||
| 2473 | |||
| 2474 | } | ||
| 2475 | } | ||
| 2476 | echo '</div>'; | ||
| 2477 | ?> | ||
| 2478 | |||
| 2479 | <?php | ||
| 2480 | |||
| 2481 | return ob_get_clean(); | ||
| 2482 | } | ||
| 2483 | |||
| 2484 | |||
| 2485 | function learndash_groups_to_course($user_id) | ||
| 2486 | { | ||
| 2487 | |||
| 2488 | |||
| 2489 | global $user_ID, $blog_id, $wpdb; | ||
| 2490 | |||
| 2491 | |||
| 2492 | $results = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."usermeta where meta_key LIKE '%learndash_group_users%' and user_id =".$user_id); | ||
| 2493 | |||
| 2494 | foreach( $results as $result){ | ||
| 2495 | if($result->meta_value== 45728){ | ||
| 2496 | continue; | ||
| 2497 | } | ||
| 2498 | ld_update_group_access( $user_id, $result->meta_value, false); | ||
| 2499 | |||
| 2500 | $sfwd_groups = get_post_meta($result->meta_value , '_groups', true ); | ||
| 2501 | $group_course_id = get_post_meta($result->meta_value, 'ld_auto_enroll_group_course_ids', true ); | ||
| 2502 | |||
| 2503 | if($group_course_id[0] !==""){ | ||
| 2504 | if(!get_user_meta($user_id,'course_completed_'.$group_course_id[0],true )){ | ||
| 2505 | sci_learndash_mark_course_complete($group_course_id[0],$user_id); | ||
| 2506 | if($access_from = get_user_meta($user_id,'course_'.$group_course_id[0].'_access_from',true )){ | ||
| 2507 | update_user_meta( $user_id, 'course_completed_'.$group_course_id[0], $access_from); | ||
| 2508 | } | ||
| 2509 | } | ||
| 2510 | } | ||
| 2511 | } | ||
| 2512 | } | ||
| 2513 | |||
| 2514 | |||
| 2515 | |||
| 2516 | /** | ||
| 2517 | * Mark learndash course as complete. | ||
| 2518 | * | ||
| 2519 | * @param int $id Course ID. | ||
| 2520 | * @param int $user_id User ID. | ||
| 2521 | */ | ||
| 2522 | function sci_learndash_mark_course_complete($id, $user_id) | ||
| 2523 | { | ||
| 2524 | |||
| 2525 | |||
| 2526 | |||
| 2527 | //retreive current course progress | ||
| 2528 | $user_progress['course'][$id] = learndash_user_get_course_progress($user_id, $id, 'legacy'); | ||
| 2529 | |||
| 2530 | if (isset($user_progress['course'][$id]['lessons'])) { | ||
| 2531 | |||
| 2532 | //update lessons progress to complete | ||
| 2533 | $lesson_array = $user_progress['course'][$id]['lessons']; | ||
| 2534 | $lessons = array_flip($lesson_array); | ||
| 2535 | $lessons = array_fill_keys(array_keys($lesson_array), 1); | ||
| 2536 | $user_progress['course'][$id]['lessons'] = $lessons; | ||
| 2537 | |||
| 2538 | } | ||
| 2539 | |||
| 2540 | |||
| 2541 | //update topics progress to complete | ||
| 2542 | if (isset($user_progress['course'][$id]['topics'])) { | ||
| 2543 | foreach($user_progress['course'][$id]['topics'] as $ldtopic_key => $ldtopic){ | ||
| 2544 | if(count($ldtopic) > 0){ | ||
| 2545 | $new_ldtopic = array_flip($ldtopic); | ||
| 2546 | $new_ldtopic = array_fill_keys(array_keys($ldtopic), 1); | ||
| 2547 | $user_progress['course'][$id]['topics'][$ldtopic_key] = $new_ldtopic; | ||
| 2548 | } | ||
| 2549 | } | ||
| 2550 | |||
| 2551 | } | ||
| 2552 | |||
| 2553 | //update quiz progress to complete | ||
| 2554 | if (isset($user_progress['quiz'][$id])) { | ||
| 2555 | $quiz_array = $user_progress['course'][$id]['quiz']; | ||
| 2556 | $quiz = array_flip($quiz_array); | ||
| 2557 | $quiz = array_fill_keys(array_keys($quiz_array), 1); | ||
| 2558 | $user_progress['course'][$id]['quiz'] = $quiz; | ||
| 2559 | }else{ | ||
| 2560 | $quiz_list = []; | ||
| 2561 | if ( isset($user_progress['course'][$id]['lessons']) && count($user_progress['course'][$id]['lessons']) > 0 ) { | ||
| 2562 | $ld_lesson_keys = array_keys($user_progress['course'][$id]['lessons']); | ||
| 2563 | foreach($ld_lesson_keys as $course_lesson_id){ | ||
| 2564 | $topic_quizzes = learndash_get_lesson_quiz_list( $course_lesson_id ); | ||
| 2565 | if (!empty($topic_quizzes)){ | ||
| 2566 | foreach ($topic_quizzes as $topic_quiz) { | ||
| 2567 | $quiz_list[$topic_quiz['post']->ID] = 1; | ||
| 2568 | } | ||
| 2569 | } | ||
| 2570 | } | ||
| 2571 | } | ||
| 2572 | if (!empty($quiz_list)){ | ||
| 2573 | $user_progress['quiz'][$id] = $quiz_list; | ||
| 2574 | } | ||
| 2575 | } | ||
| 2576 | |||
| 2577 | $processed_course_ids = []; | ||
| 2578 | |||
| 2579 | if ((isset($user_progress['course'])) && (!empty($user_progress['course']))) { | ||
| 2580 | |||
| 2581 | $usermeta = get_user_meta($user_id, '_sfwd-course_progress', true); | ||
| 2582 | $course_progress = empty($usermeta) ? [] : $usermeta; | ||
| 2583 | |||
| 2584 | $course_changed = false; // Simple flag to let us know we changed the quiz data so we can save it back to user meta. | ||
| 2585 | |||
| 2586 | foreach ($user_progress['course'] as $course_id => $course_data_new) { | ||
| 2587 | |||
| 2588 | $processed_course_ids[intval($course_id)] = intval($course_id); | ||
| 2589 | |||
| 2590 | if (isset($course_progress[$course_id])) { | ||
| 2591 | $course_data_old = $course_progress[$course_id]; | ||
| 2592 | } else { | ||
| 2593 | $course_data_old = []; | ||
| 2594 | } | ||
| 2595 | |||
| 2596 | $course_data_new = learndash_course_item_to_activity_sync($user_id, $course_id, $course_data_new, | ||
| 2597 | $course_data_old); | ||
| 2598 | |||
| 2599 | $course_progress[$course_id] = $course_data_new; | ||
| 2600 | |||
| 2601 | $course_changed = true; | ||
| 2602 | } | ||
| 2603 | |||
| 2604 | if (true === $course_changed) { | ||
| 2605 | update_user_meta($user_id, '_sfwd-course_progress', $course_progress); | ||
| 2606 | } | ||
| 2607 | } | ||
| 2608 | |||
| 2609 | |||
| 2610 | if ((isset($user_progress['quiz'])) && (!empty($user_progress['quiz']))) { | ||
| 2611 | |||
| 2612 | $usermeta = get_user_meta($user_id, '_sfwd-quizzes', true); | ||
| 2613 | $quizz_progress = empty($usermeta) ? [] : $usermeta; | ||
| 2614 | $quiz_changed = false; // Simple flag to let us know we changed the quiz data so we can save it back to user meta. | ||
| 2615 | |||
| 2616 | foreach ($user_progress['quiz'] as $course_id => $course_quiz_set) { | ||
| 2617 | foreach ($course_quiz_set as $quiz_id => $quiz_new_status) { | ||
| 2618 | $quiz_meta = get_post_meta($quiz_id, '_sfwd-quiz', true); | ||
| 2619 | |||
| 2620 | if (!empty($quiz_meta)) { | ||
| 2621 | $quiz_old_status = !learndash_is_quiz_notcomplete($user_id, [$quiz_id => 1], false, $course_id); | ||
| 2622 | |||
| 2623 | // For Quiz if the admin marks a qiz complete we don't attempt to update an existing attempt for the user quiz. | ||
| 2624 | // Instead we add a new entry. LD doesn't care as it will take the complete one for calculations where needed. | ||
| 2625 | if ((bool)true === (bool)$quiz_new_status) { | ||
| 2626 | if ((bool)true !== (bool)$quiz_old_status) { | ||
| 2627 | |||
| 2628 | if (isset($quiz_meta['sfwd-quiz_lesson'])) { | ||
| 2629 | $lesson_id = absint($quiz_meta['sfwd-quiz_lesson']); | ||
| 2630 | } else { | ||
| 2631 | $lesson_id = 0; | ||
| 2632 | } | ||
| 2633 | |||
| 2634 | if (isset($quiz_meta['sfwd-quiz_topic'])) { | ||
| 2635 | $topic_id = absint($quiz_meta['sfwd-quiz_topic']); | ||
| 2636 | } else { | ||
| 2637 | $topic_id = 0; | ||
| 2638 | } | ||
| 2639 | |||
| 2640 | // If the admin is marking the quiz complete AND the quiz is NOT already complete... | ||
| 2641 | // Then we add the minimal quiz data to the user profile. | ||
| 2642 | $quizdata = [ | ||
| 2643 | 'quiz' => $quiz_id, | ||
| 2644 | 'score' => 0, | ||
| 2645 | 'count' => 0, | ||
| 2646 | 'question_show_count' => 0, | ||
| 2647 | 'pass' => true, | ||
| 2648 | 'rank' => '-', | ||
| 2649 | 'time' => time(), | ||
| 2650 | 'pro_quizid' => absint($quiz_meta['sfwd-quiz_quiz_pro']), | ||
| 2651 | 'course' => $course_id, | ||
| 2652 | 'lesson' => $lesson_id, | ||
| 2653 | 'topic' => $topic_id, | ||
| 2654 | 'points' => 0, | ||
| 2655 | 'total_points' => 0, | ||
| 2656 | 'percentage' => 0, | ||
| 2657 | 'timespent' => 0, | ||
| 2658 | 'has_graded' => false, | ||
| 2659 | 'statistic_ref_id' => 0, | ||
| 2660 | 'm_edit_by' => get_current_user_id(), // Manual Edit By ID. | ||
| 2661 | 'm_edit_time' => time(), // Manual Edit timestamp. | ||
| 2662 | ]; | ||
| 2663 | |||
| 2664 | $quizz_progress[] = $quizdata; | ||
| 2665 | |||
| 2666 | if (true === $quizdata['pass']) { | ||
| 2667 | $quizdata_pass = true; | ||
| 2668 | } else { | ||
| 2669 | $quizdata_pass = false; | ||
| 2670 | } | ||
| 2671 | |||
| 2672 | // Then we add the quiz entry to the activity database. | ||
| 2673 | learndash_update_user_activity( | ||
| 2674 | [ | ||
| 2675 | 'course_id' => $course_id, | ||
| 2676 | 'user_id' => $user_id, | ||
| 2677 | 'post_id' => $quiz_id, | ||
| 2678 | 'activity_type' => 'quiz', | ||
| 2679 | 'activity_action' => 'insert', | ||
| 2680 | 'activity_status' => $quizdata_pass, | ||
| 2681 | 'activity_started' => $quizdata['time'], | ||
| 2682 | 'activity_completed' => $quizdata['time'], | ||
| 2683 | 'activity_meta' => $quizdata, | ||
| 2684 | ] | ||
| 2685 | ); | ||
| 2686 | |||
| 2687 | $quiz_changed = true; | ||
| 2688 | |||
| 2689 | if ((isset($quizdata['course'])) && (!empty($quizdata['course']))) { | ||
| 2690 | $quizdata['course'] = get_post($quizdata['course']); | ||
| 2691 | } | ||
| 2692 | |||
| 2693 | if ((isset($quizdata['lesson'])) && (!empty($quizdata['lesson']))) { | ||
| 2694 | $quizdata['lesson'] = get_post($quizdata['lesson']); | ||
| 2695 | } | ||
| 2696 | |||
| 2697 | if ((isset($quizdata['topic'])) && (!empty($quizdata['topic']))) { | ||
| 2698 | $quizdata['topic'] = get_post($quizdata['topic']); | ||
| 2699 | } | ||
| 2700 | |||
| 2701 | /** | ||
| 2702 | * Fires after the quiz is marked as complete. | ||
| 2703 | * | ||
| 2704 | * @param arrat $quizdata An array of quiz data. | ||
| 2705 | * @param WP_User $user WP_User object. | ||
| 2706 | */ | ||
| 2707 | do_action('learndash_quiz_completed', $quizdata, get_user_by('ID', $user_id)); | ||
| 2708 | |||
| 2709 | } | ||
| 2710 | } elseif (true !== $quiz_new_status) { | ||
| 2711 | // If we are unsetting a quiz ( changing from complete to incomplete). We need to do some complicated things... | ||
| 2712 | if (true === $quiz_old_status) { | ||
| 2713 | |||
| 2714 | if (!empty($quizz_progress)) { | ||
| 2715 | foreach ($quizz_progress as $quiz_idx => $quiz_item) { | ||
| 2716 | |||
| 2717 | if (($quiz_item['quiz'] == $quiz_id) && (true === $quiz_item['pass'])) { | ||
| 2718 | $quizz_progress[$quiz_idx]['pass'] = false; | ||
| 2719 | |||
| 2720 | // We need to update the activity database records for this quiz_id | ||
| 2721 | $activity_query_args = [ | ||
| 2722 | 'post_ids' => $quiz_id, | ||
| 2723 | 'user_ids' => $user_id, | ||
| 2724 | 'activity_type' => 'quiz', | ||
| 2725 | ]; | ||
| 2726 | $quiz_activity = learndash_reports_get_activity($activity_query_args); | ||
| 2727 | if ((isset($quiz_activity['results'])) && (!empty($quiz_activity['results']))) { | ||
| 2728 | foreach ($quiz_activity['results'] as $result) { | ||
| 2729 | if ((isset($result->activity_meta['pass'])) && (true === $result->activity_meta['pass'])) { | ||
| 2730 | |||
| 2731 | // If the activity meta 'pass' element is set to true we want to update it to false. | ||
| 2732 | learndash_update_user_activity_meta($result->activity_id, 'pass', | ||
| 2733 | false); | ||
| 2734 | |||
| 2735 | // Also we need to update the 'activity_status' for this record | ||
| 2736 | learndash_update_user_activity( | ||
| 2737 | [ | ||
| 2738 | 'activity_id' => $result->activity_id, | ||
| 2739 | 'course_id' => $course_id, | ||
| 2740 | 'user_id' => $user_id, | ||
| 2741 | 'post_id' => $quiz_id, | ||
| 2742 | 'activity_type' => 'quiz', | ||
| 2743 | 'activity_action' => 'update', | ||
| 2744 | 'activity_status' => false, | ||
| 2745 | ] | ||
| 2746 | ); | ||
| 2747 | } | ||
| 2748 | } | ||
| 2749 | } | ||
| 2750 | |||
| 2751 | $quiz_changed = true; | ||
| 2752 | } | ||
| 2753 | |||
| 2754 | /** | ||
| 2755 | * Remove the quiz lock. | ||
| 2756 | * | ||
| 2757 | * @since 2.3.1 | ||
| 2758 | */ | ||
| 2759 | if ((isset($quiz_item['pro_quizid'])) && (!empty($quiz_item['pro_quizid']))) { | ||
| 2760 | learndash_remove_user_quiz_locks($user_id, $quiz_item['quiz']); | ||
| 2761 | } | ||
| 2762 | } | ||
| 2763 | } | ||
| 2764 | } | ||
| 2765 | } | ||
| 2766 | |||
| 2767 | $processed_course_ids[intval($course_id)] = intval($course_id); | ||
| 2768 | } | ||
| 2769 | } | ||
| 2770 | } | ||
| 2771 | |||
| 2772 | if (true === $quiz_changed) { | ||
| 2773 | update_user_meta($user_id, '_sfwd-quizzes', $quizz_progress); | ||
| 2774 | } | ||
| 2775 | } | ||
| 2776 | |||
| 2777 | if (!empty($processed_course_ids)) { | ||
| 2778 | foreach (array_unique($processed_course_ids) as $course_id) { | ||
| 2779 | learndash_process_mark_complete($user_id, $course_id); | ||
| 2780 | learndash_update_group_course_user_progress($course_id, $user_id); | ||
| 2781 | } | ||
| 2782 | } | ||
| 2783 | |||
| 2784 | } | ||
| 2785 | |||
| 2786 | |||
| 2787 | add_shortcode('dash_user_info', 'dash_user_info_shortcode'); | ||
| 2788 | |||
| 2789 | function dash_user_info_shortcode() | ||
| 2790 | { | ||
| 2791 | global $current_user; | ||
| 2792 | get_currentuserinfo(); | ||
| 2793 | echo'<div class="dash_user_info">'; | ||
| 2794 | echo get_avatar( $current_user->ID, 180 ); | ||
| 2795 | echo '<p>'.$current_user->first_name.' '.$current_user->last_name.'</p>'; | ||
| 2796 | echo "</div>"; | ||
| 2797 | ob_start();?> | ||
| 2798 | |||
| 2799 | <?php | ||
| 2800 | |||
| 2801 | return ob_get_clean(); | ||
| 2802 | } | ||
| 2803 | |||
| 2804 | |||
| 2805 | function the_bread() { | ||
| 2806 | if(!is_admin()){ | ||
| 2807 | $ingredients = array( | ||
| 2808 | 'separator' => '>', | ||
| 2809 | 'offset' => -3, | ||
| 2810 | 'length' => 3, | ||
| 2811 | ); | ||
| 2812 | |||
| 2813 | $flour = $_SERVER['REQUEST_URI']; | ||
| 2814 | |||
| 2815 | if ( str_contains( $flour, '?' ) ) | ||
| 2816 | $flour = substr( $flour, 0, strpos( $flour, '?' ) ); | ||
| 2817 | |||
| 2818 | $flour = ( str_ends_with( $flour, '/' ) ? explode( '/', substr( $flour, 1, -1 ) ) : explode( '/', substr( $flour, 1 ) ) ); | ||
| 2819 | |||
| 2820 | $crumbs = []; | ||
| 2821 | |||
| 2822 | foreach ( $flour as $crumb ) { | ||
| 2823 | |||
| 2824 | $slug = esc_html( $crumb ); | ||
| 2825 | |||
| 2826 | $url = esc_url( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . substr( implode( '/', $flour ), 0, strpos( implode( '/', $flour ), $crumb ) ) . $crumb. '/' ); | ||
| 2827 | |||
| 2828 | array_push( $crumbs, ( object ) | ||
| 2829 | [ | ||
| 2830 | 'slug' => $slug, | ||
| 2831 | 'url' => $url, | ||
| 2832 | ] | ||
| 2833 | ); | ||
| 2834 | |||
| 2835 | }; | ||
| 2836 | |||
| 2837 | $offset = ( empty( $ingredients['offset'] ) ? 0 : $ingredients['offset'] ); | ||
| 2838 | $length = ( empty( $ingredients['length'] ) ? null : $ingredients['length'] ); | ||
| 2839 | |||
| 2840 | $crumbs = array_slice( $crumbs, $offset, $length ); | ||
| 2841 | |||
| 2842 | echo '<ul class="bread">'; | ||
| 2843 | |||
| 2844 | $i = 0; | ||
| 2845 | if ( is_singular( 'sfwd-lessons' ) ) { | ||
| 2846 | echo '<li class="crumb" itemprop="itemListElement"> | ||
| 2847 | <a itemprop="item" href="https://thecommonwell.ca/broker-landing-page/learning-2/"> | ||
| 2848 | <span itemprop="name">Broker Learning</span> | ||
| 2849 | </a> | ||
| 2850 | <meta itemprop="position" content="1"> | ||
| 2851 | </li>><li class="crumb" itemprop="itemListElement"> | ||
| 2852 | <a itemprop="item" href="https://thecommonwell.ca/broker-landing-page/learning-2/marketing-masters/"> | ||
| 2853 | <span itemprop="name">Marketing Masters</span> | ||
| 2854 | </a> | ||
| 2855 | <meta itemprop="position" content="2"> | ||
| 2856 | </li>>'; | ||
| 2857 | } | ||
| 2858 | foreach ( $crumbs as $crumb ) { | ||
| 2859 | $i++; | ||
| 2860 | |||
| 2861 | echo '<li class="crumb" itemprop="itemListElement"> | ||
| 2862 | <a itemprop="item" href="' . $crumb->url . '"> | ||
| 2863 | <span itemprop="name">' . ( url_to_postid( $crumb->url ) ? get_the_title( url_to_postid( $crumb->url ) ) : ucfirst( str_replace( '-', ' ', $crumb->slug ) ) ) . '</span> | ||
| 2864 | </a> | ||
| 2865 | <meta itemprop="position" content="' . $i . '"> | ||
| 2866 | </li>'; | ||
| 2867 | |||
| 2868 | if ( $i !== sizeof( $crumbs ) && ! empty( $ingredients['separator'] ) ) | ||
| 2869 | echo $ingredients['separator']; | ||
| 2870 | |||
| 2871 | }; | ||
| 2872 | |||
| 2873 | echo '</ul>'; | ||
| 2874 | } | ||
| 2875 | |||
| 2876 | }; | ||
| 2877 | |||
| 2878 | add_shortcode( 'breadcrumbs', 'the_bread' ); | ||
| 2879 | |||
| 2880 | |||
| 2881 | if (!function_exists('str_contains')) { | 1334 | if (!function_exists('str_contains')) { |
| 2882 | function str_contains(string $haystack, string $needle): bool | 1335 | function str_contains(string $haystack, string $needle): bool |
| 2883 | { | 1336 | { |
| ... | @@ -3065,9 +1518,7 @@ add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' ); | ... | @@ -3065,9 +1518,7 @@ add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' ); |
| 3065 | add_filter( 'use_widgets_block_editor', '__return_false' ); | 1518 | add_filter( 'use_widgets_block_editor', '__return_false' ); |
| 3066 | 1519 | ||
| 3067 | 1520 | ||
| 3068 | add_filter( 'login_redirect', function( $url, $query, $user ) { | 1521 | |
| 3069 | return '/broker-landing-page'; | ||
| 3070 | }, 10, 3 ); | ||
| 3071 | 1522 | ||
| 3072 | 1523 | ||
| 3073 | 1524 | ... | ... |
| ... | @@ -82,7 +82,7 @@ | ... | @@ -82,7 +82,7 @@ |
| 82 | <div class="row"> | 82 | <div class="row"> |
| 83 | <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"> | 83 | <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"> |
| 84 | <div id="page-logo"> | 84 | <div id="page-logo"> |
| 85 | <a href="<?php bloginfo('url') ?>/broker-landing-page/" title="<?php bloginfo('name') ?> - <?php bloginfo('description') ?>"> | 85 | <a href="<?php bloginfo('url') ?>" title="<?php bloginfo('name') ?> - <?php bloginfo('description') ?>"> |
| 86 | <img id="otherpage-logo" src="<?php bloginfo('template_directory') ?>/images/Commonwell-logo.svg" alt="Commonwell Mutual Insurance Group logo" /> | 86 | <img id="otherpage-logo" src="<?php bloginfo('template_directory') ?>/images/Commonwell-logo.svg" alt="Commonwell Mutual Insurance Group logo" /> |
| 87 | </a> | 87 | </a> |
| 88 | </div> | 88 | </div> | ... | ... |
| 1 | <?php | ||
| 2 | |||
| 3 | function badgeos_send_achievements_email_custom( $user_id, $achievement_id, $this_trigger, $site_id, $args, $entry_id ) { | ||
| 4 | |||
| 5 | global $wpdb; | ||
| 6 | |||
| 7 | |||
| 8 | $badgeos_settings = ( $exists = badgeos_utilities::get_option( 'badgeos_settings' ) ) ? $exists : array(); | ||
| 9 | $achievement_post_type = badgeos_utilities::get_post_type( $achievement_id ); | ||
| 10 | $achievement_type = $badgeos_settings['achievement_main_post_type']; | ||
| 11 | $post_obj = get_page_by_path( $achievement_post_type, OBJECT, $achievement_type ); | ||
| 12 | |||
| 13 | $parent_post_type = ''; | ||
| 14 | if( $post_obj ) { | ||
| 15 | $parent_post_type = $post_obj->post_type; | ||
| 16 | } | ||
| 17 | if ( trim( $achievement_type ) == trim( $parent_post_type ) ) { | ||
| 18 | |||
| 19 | $badgeos_admin_tools = ( $exists = badgeos_utilities::get_option( 'badgeos_admin_tools' ) ) ? $exists : array(); | ||
| 20 | |||
| 21 | $email_cc_list = badgeos_bcc_cc_emails( $badgeos_admin_tools, 'email_achievement_cc_list', 'cc' ); | ||
| 22 | $email_bcc_list = badgeos_bcc_cc_emails( $badgeos_admin_tools, 'email_achievement_bcc_list', 'bcc' ); | ||
| 23 | |||
| 24 | if( ! isset( $badgeos_admin_tools['email_disable_earned_achievement_email'] ) || $badgeos_admin_tools['email_disable_earned_achievement_email'] == 'no' ) { | ||
| 25 | |||
| 26 | $results = $wpdb->get_results( "select * from ".$wpdb->prefix."badgeos_achievements where entry_id='".$entry_id."'", 'ARRAY_A' ); | ||
| 27 | if( count( $results ) > 0 ) { | ||
| 28 | $record = $results[ 0 ]; | ||
| 29 | $achievement_type = $record[ 'post_type' ]; | ||
| 30 | $type_title = $post_obj->post_title; | ||
| 31 | $step_type = trim( $badgeos_settings['achievement_step_post_type'] ); | ||
| 32 | $issue_date = $record[ 'date_earned' ]; | ||
| 33 | $rec_type = $record[ 'rec_type' ]; | ||
| 34 | $rec_date_earned = $record['date_earned']; | ||
| 35 | $date_format = badgeos_utilities::get_option( 'date_format', true ); | ||
| 36 | $time_format = badgeos_utilities::get_option( 'time_format', true ); | ||
| 37 | if( get_post_meta( $achievement_id, '_open_badge_enable_baking', true ) ) { | ||
| 38 | $evidence_page_id = get_option( 'badgeos_evidence_url' ); | ||
| 39 | $badgeos_evidence_url = get_permalink( $evidence_page_id ); | ||
| 40 | $badgeos_evidence_url = add_query_arg( 'bg', $record[ 'ID' ], $badgeos_evidence_url ); | ||
| 41 | $badgeos_evidence_url = add_query_arg( 'eid', $record[ 'entry_id' ], $badgeos_evidence_url ); | ||
| 42 | $badgeos_evidence_url = add_query_arg( 'uid', $record[ 'user_id' ], $badgeos_evidence_url ); | ||
| 43 | } | ||
| 44 | |||
| 45 | if( ! empty( $achievement_type ) && trim( $achievement_type ) != $step_type ) { | ||
| 46 | $email_subject = $badgeos_admin_tools['email_achievement_subject']; | ||
| 47 | if( empty( $email_subject ) ) { | ||
| 48 | $email_subject = __( 'Congratulation for earning an achievement', 'badgeos' ); | ||
| 49 | } | ||
| 50 | |||
| 51 | $email_content = $badgeos_admin_tools['email_achievement_content']; | ||
| 52 | |||
| 53 | $from_title = get_bloginfo( 'name' ); | ||
| 54 | $from_email = get_bloginfo( 'admin_email' ); | ||
| 55 | |||
| 56 | if( !empty( $badgeos_admin_tools['email_general_from_name'] ) ) { | ||
| 57 | $from_title = $badgeos_admin_tools['email_general_from_name']; | ||
| 58 | } | ||
| 59 | |||
| 60 | if( !empty( $badgeos_admin_tools['email_general_from_email'] ) ) { | ||
| 61 | $from_title = $badgeos_admin_tools['email_general_from_email']; | ||
| 62 | } | ||
| 63 | |||
| 64 | $achievement_title = $record[ 'achievement_title' ]; | ||
| 65 | $points = $record[ 'points' ]; | ||
| 66 | $achievement_image = badgeos_get_achievement_post_thumbnail( $achievement_id, 'full' ); | ||
| 67 | |||
| 68 | $user_to_title = ''; | ||
| 69 | $user_email = ''; | ||
| 70 | $to_user_id = $record[ 'user_id']; | ||
| 71 | $user_to = get_user_by( 'ID', $record[ 'user_id'] ); | ||
| 72 | if( $user_to ) { | ||
| 73 | $user_to_title = $user_to->display_name; | ||
| 74 | $user_email = $user_to->user_email; | ||
| 75 | } | ||
| 76 | |||
| 77 | $headers[] = 'From: '.$from_title.' <'.$from_email.'>'; | ||
| 78 | $headers[] = 'Content-Type: text/html; charset=UTF-8'; | ||
| 79 | if( is_array( $email_cc_list ) && count( $email_cc_list ) > 0 ) { | ||
| 80 | foreach( $email_cc_list as $cc_id ) { | ||
| 81 | if( !empty( $cc_id ) ) { | ||
| 82 | $headers[] = 'Cc: '.$cc_id; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | if( is_array( $email_bcc_list ) && count( $email_bcc_list ) > 0 ) { | ||
| 88 | foreach( $email_bcc_list as $bcc_id ) { | ||
| 89 | if( !empty( $bcc_id ) ) { | ||
| 90 | $headers[] = 'Bcc: '.$bcc_id; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | $email_subject = str_replace('[achievement_type]', $type_title, $email_subject ); | ||
| 96 | $email_subject = str_replace('[achievement_title]', $achievement_title, $email_subject ); | ||
| 97 | $email_subject = str_replace('[points]', $points, $email_subject ); | ||
| 98 | $email_subject = str_replace('[user_email]', $user_email, $email_subject ); | ||
| 99 | $email_subject = str_replace('[user_name]', $user_to_title, $email_subject ); | ||
| 100 | |||
| 101 | ob_start(); | ||
| 102 | |||
| 103 | $email_content = stripslashes( html_entity_decode( $email_content ) ); | ||
| 104 | $email_content = str_replace("\'","'", $email_content); | ||
| 105 | $email_content = str_replace('\"','"', $email_content); | ||
| 106 | |||
| 107 | $email_content = str_replace('[achievement_type]', $type_title, $email_content ); | ||
| 108 | $email_content = str_replace('[achievement_title]', $achievement_title, $email_content ); | ||
| 109 | $email_content = str_replace('[date_earned]', date( $date_format.' '.$time_format, strtotime($record['date_earned']) ), $email_content ); | ||
| 110 | $email_content = str_replace('[achievement_link]', get_permalink($achievement_id), $email_content ); | ||
| 111 | $email_content = str_replace('[points]', $points, $email_content ); | ||
| 112 | $email_content = str_replace('[user_email]', $user_email, $email_content ); | ||
| 113 | $email_content = str_replace('[user_name]', $user_to_title."<p> </p>", $email_content ); | ||
| 114 | $email_content = str_replace('[achievement_image]', "<p> </p>".$achievement_image."<p> </p>", $email_content ); | ||
| 115 | $email_content = str_replace('[user_profile_link]', get_edit_profile_url( $to_user_id ), $email_content ); | ||
| 116 | $email_content = str_replace('[evidence]', badgeos_include_evidence_in_email( $achievement_id, $issue_date, $rec_type, $badgeos_evidence_url, $rec_date_earned ), $email_content); | ||
| 117 | |||
| 118 | ?> | ||
| 119 | <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;"> | ||
| 120 | <tr> | ||
| 121 | <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;"> | ||
| 122 | <?php echo $email_content; ?> | ||
| 123 | </td> | ||
| 124 | </tr> | ||
| 125 | </table> | ||
| 126 | <?php | ||
| 127 | |||
| 128 | |||
| 129 | $message = ob_get_contents(); | ||
| 130 | ob_end_clean(); | ||
| 131 | if( ! empty( $user_email ) ) { | ||
| 132 | |||
| 133 | |||
| 134 | wp_mail( $user_email, strip_tags( $email_subject ), $message, $headers ); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | add_action( 'badgeos_award_achievement', 'badgeos_send_achievements_email_custom', 10, 6 ); | ||
| 145 | |||
| 146 | |||
| 147 | function remove_badgeos_can_notify_user( $user_login, $user ) { | ||
| 148 | update_user_meta($user->ID, '_badgeos_can_notify_user', ''); | ||
| 149 | } | ||
| 150 | |||
| 151 | add_action('wp_login', 'remove_badgeos_can_notify_user', 10, 2 ); | ||
| 152 | |||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | add_shortcode('textbooks', 'textbooks_shortcode'); | ||
| 157 | |||
| 158 | function textbooks_shortcode() | ||
| 159 | { | ||
| 160 | ob_start(); | ||
| 161 | global $wpdb; | ||
| 162 | $results = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."usermeta where meta_key LIKE '%learndash_group_users%' and user_id =".get_current_user_id()); | ||
| 163 | |||
| 164 | foreach( $results as $result){ | ||
| 165 | $sfwd_groups = get_post_meta($result->meta_value , '_groups', true ); | ||
| 166 | if(!empty($sfwd_groups['groups_group_materials']) ){ | ||
| 167 | echo '<h4 style="font-size:1rem;">'.get_the_title($result->meta_value).'</h4>'; | ||
| 168 | echo '<div class="material">'.$sfwd_groups['groups_group_materials'].'</div>'; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | |||
| 173 | $enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false); | ||
| 174 | foreach($enrolled_courses as $enrolled_course){ | ||
| 175 | $lesson_materials=""; | ||
| 176 | $sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true ); | ||
| 177 | $course_steps = get_post_meta($enrolled_course , 'ld_course_steps', true ); | ||
| 178 | $course_steps = $course_steps['steps']['h']['sfwd-lessons']; | ||
| 179 | foreach($course_steps as $key => $course_step){ | ||
| 180 | $sfwd_lessons = get_post_meta($key , '_sfwd-lessons', true ); | ||
| 181 | $lesson_materials .= $sfwd_lessons['sfwd-lessons_lesson_materials']; | ||
| 182 | } | ||
| 183 | if(!empty($sfwd_course['sfwd-courses_course_materials']) || !empty($lesson_materials) ){ | ||
| 184 | echo '<h4 style="font-size:1rem;">'.str_replace("Private:","",get_the_title($enrolled_course )).'</h4>'; | ||
| 185 | echo '<div class="material">'.$sfwd_course['sfwd-courses_course_materials'].$lesson_materials.'</div>'; | ||
| 186 | } | ||
| 187 | } | ||
| 188 | ?> | ||
| 189 | |||
| 190 | <?php | ||
| 191 | |||
| 192 | return ob_get_clean(); | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | add_shortcode('badges', 'badges_shortcode'); | ||
| 198 | |||
| 199 | function badges_shortcode() | ||
| 200 | { | ||
| 201 | ob_start(); | ||
| 202 | //learndash_groups_to_course(get_current_user_id()); | ||
| 203 | global $wpdb; | ||
| 204 | $results = $wpdb->get_results("SELECT ID, date_earned, achievement_title FROM ".$wpdb->prefix."badgeos_achievements where post_type='badges' and user_id =".get_current_user_id()); | ||
| 205 | echo '<div class="badges">'; | ||
| 206 | foreach( $results as $result){ | ||
| 207 | $thumbnail_id = get_post_meta($result->ID, '_thumbnail_id', true ); | ||
| 208 | echo '<div class="badge_container" data-title="'.str_replace(":","_",str_replace(" ","-",get_the_title($result->ID))).'">'.wp_get_attachment_image($thumbnail_id, array('300', '200'), "", array( "class" => "img-responsive" ) ).'</div>'; | ||
| 209 | } | ||
| 210 | echo '</div>'; | ||
| 211 | echo '<p class="has-text-align-center">Click to download your certificate</p>'; | ||
| 212 | |||
| 213 | echo '<div class="cert">'; | ||
| 214 | |||
| 215 | |||
| 216 | |||
| 217 | $enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false); | ||
| 218 | foreach($enrolled_courses as $enrolled_course){ | ||
| 219 | if($enrolled_course == 45591){ | ||
| 220 | continue; | ||
| 221 | } | ||
| 222 | $cert = learndash_get_course_certificate_link($enrolled_course, get_current_user_id()); | ||
| 223 | if(!empty($cert)){ | ||
| 224 | $sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true ); | ||
| 225 | $thumbnail_id = get_post_meta($sfwd_course['sfwd-courses_certificate'], '_thumbnail_id', true ); | ||
| 226 | echo '<div class="badge_container cert"><a target="_blank" class="cert_link" href="'.$cert.'">' | ||
| 227 | .wp_get_attachment_image($thumbnail_id, array('200', '100'), "", array( "class" => "img-responsive" ) ).' </a><br><strong>'. date( 'F, d, Y', get_user_meta(get_current_user_id(), 'course_completed_'.$enrolled_course, true )).'</strong></div>'; | ||
| 228 | |||
| 229 | } | ||
| 230 | } | ||
| 231 | echo '</div>'; | ||
| 232 | ?> | ||
| 233 | |||
| 234 | <?php | ||
| 235 | |||
| 236 | return ob_get_clean(); | ||
| 237 | } | ||
| 238 | |||
| 239 | |||
| 240 | function learndash_groups_to_course($user_id) | ||
| 241 | { | ||
| 242 | |||
| 243 | |||
| 244 | global $user_ID, $blog_id, $wpdb; | ||
| 245 | |||
| 246 | |||
| 247 | $results = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."usermeta where meta_key LIKE '%learndash_group_users%' and user_id =".$user_id); | ||
| 248 | |||
| 249 | foreach( $results as $result){ | ||
| 250 | if($result->meta_value== 45728){ | ||
| 251 | continue; | ||
| 252 | } | ||
| 253 | ld_update_group_access( $user_id, $result->meta_value, false); | ||
| 254 | |||
| 255 | $sfwd_groups = get_post_meta($result->meta_value , '_groups', true ); | ||
| 256 | $group_course_id = get_post_meta($result->meta_value, 'ld_auto_enroll_group_course_ids', true ); | ||
| 257 | |||
| 258 | if($group_course_id[0] !==""){ | ||
| 259 | if(!get_user_meta($user_id,'course_completed_'.$group_course_id[0],true )){ | ||
| 260 | sci_learndash_mark_course_complete($group_course_id[0],$user_id); | ||
| 261 | if($access_from = get_user_meta($user_id,'course_'.$group_course_id[0].'_access_from',true )){ | ||
| 262 | update_user_meta( $user_id, 'course_completed_'.$group_course_id[0], $access_from); | ||
| 263 | } | ||
| 264 | } | ||
| 265 | } | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 269 | |||
| 270 | |||
| 271 | /** | ||
| 272 | * Mark learndash course as complete. | ||
| 273 | * | ||
| 274 | * @param int $id Course ID. | ||
| 275 | * @param int $user_id User ID. | ||
| 276 | */ | ||
| 277 | function sci_learndash_mark_course_complete($id, $user_id) | ||
| 278 | { | ||
| 279 | |||
| 280 | |||
| 281 | |||
| 282 | //retreive current course progress | ||
| 283 | $user_progress['course'][$id] = learndash_user_get_course_progress($user_id, $id, 'legacy'); | ||
| 284 | |||
| 285 | if (isset($user_progress['course'][$id]['lessons'])) { | ||
| 286 | |||
| 287 | //update lessons progress to complete | ||
| 288 | $lesson_array = $user_progress['course'][$id]['lessons']; | ||
| 289 | $lessons = array_flip($lesson_array); | ||
| 290 | $lessons = array_fill_keys(array_keys($lesson_array), 1); | ||
| 291 | $user_progress['course'][$id]['lessons'] = $lessons; | ||
| 292 | |||
| 293 | } | ||
| 294 | |||
| 295 | |||
| 296 | //update topics progress to complete | ||
| 297 | if (isset($user_progress['course'][$id]['topics'])) { | ||
| 298 | foreach($user_progress['course'][$id]['topics'] as $ldtopic_key => $ldtopic){ | ||
| 299 | if(count($ldtopic) > 0){ | ||
| 300 | $new_ldtopic = array_flip($ldtopic); | ||
| 301 | $new_ldtopic = array_fill_keys(array_keys($ldtopic), 1); | ||
| 302 | $user_progress['course'][$id]['topics'][$ldtopic_key] = $new_ldtopic; | ||
| 303 | } | ||
| 304 | } | ||
| 305 | |||
| 306 | } | ||
| 307 | |||
| 308 | //update quiz progress to complete | ||
| 309 | if (isset($user_progress['quiz'][$id])) { | ||
| 310 | $quiz_array = $user_progress['course'][$id]['quiz']; | ||
| 311 | $quiz = array_flip($quiz_array); | ||
| 312 | $quiz = array_fill_keys(array_keys($quiz_array), 1); | ||
| 313 | $user_progress['course'][$id]['quiz'] = $quiz; | ||
| 314 | }else{ | ||
| 315 | $quiz_list = []; | ||
| 316 | if ( isset($user_progress['course'][$id]['lessons']) && count($user_progress['course'][$id]['lessons']) > 0 ) { | ||
| 317 | $ld_lesson_keys = array_keys($user_progress['course'][$id]['lessons']); | ||
| 318 | foreach($ld_lesson_keys as $course_lesson_id){ | ||
| 319 | $topic_quizzes = learndash_get_lesson_quiz_list( $course_lesson_id ); | ||
| 320 | if (!empty($topic_quizzes)){ | ||
| 321 | foreach ($topic_quizzes as $topic_quiz) { | ||
| 322 | $quiz_list[$topic_quiz['post']->ID] = 1; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | } | ||
| 326 | } | ||
| 327 | if (!empty($quiz_list)){ | ||
| 328 | $user_progress['quiz'][$id] = $quiz_list; | ||
| 329 | } | ||
| 330 | } | ||
| 331 | |||
| 332 | $processed_course_ids = []; | ||
| 333 | |||
| 334 | if ((isset($user_progress['course'])) && (!empty($user_progress['course']))) { | ||
| 335 | |||
| 336 | $usermeta = get_user_meta($user_id, '_sfwd-course_progress', true); | ||
| 337 | $course_progress = empty($usermeta) ? [] : $usermeta; | ||
| 338 | |||
| 339 | $course_changed = false; // Simple flag to let us know we changed the quiz data so we can save it back to user meta. | ||
| 340 | |||
| 341 | foreach ($user_progress['course'] as $course_id => $course_data_new) { | ||
| 342 | |||
| 343 | $processed_course_ids[intval($course_id)] = intval($course_id); | ||
| 344 | |||
| 345 | if (isset($course_progress[$course_id])) { | ||
| 346 | $course_data_old = $course_progress[$course_id]; | ||
| 347 | } else { | ||
| 348 | $course_data_old = []; | ||
| 349 | } | ||
| 350 | |||
| 351 | $course_data_new = learndash_course_item_to_activity_sync($user_id, $course_id, $course_data_new, | ||
| 352 | $course_data_old); | ||
| 353 | |||
| 354 | $course_progress[$course_id] = $course_data_new; | ||
| 355 | |||
| 356 | $course_changed = true; | ||
| 357 | } | ||
| 358 | |||
| 359 | if (true === $course_changed) { | ||
| 360 | update_user_meta($user_id, '_sfwd-course_progress', $course_progress); | ||
| 361 | } | ||
| 362 | } | ||
| 363 | |||
| 364 | |||
| 365 | if ((isset($user_progress['quiz'])) && (!empty($user_progress['quiz']))) { | ||
| 366 | |||
| 367 | $usermeta = get_user_meta($user_id, '_sfwd-quizzes', true); | ||
| 368 | $quizz_progress = empty($usermeta) ? [] : $usermeta; | ||
| 369 | $quiz_changed = false; // Simple flag to let us know we changed the quiz data so we can save it back to user meta. | ||
| 370 | |||
| 371 | foreach ($user_progress['quiz'] as $course_id => $course_quiz_set) { | ||
| 372 | foreach ($course_quiz_set as $quiz_id => $quiz_new_status) { | ||
| 373 | $quiz_meta = get_post_meta($quiz_id, '_sfwd-quiz', true); | ||
| 374 | |||
| 375 | if (!empty($quiz_meta)) { | ||
| 376 | $quiz_old_status = !learndash_is_quiz_notcomplete($user_id, [$quiz_id => 1], false, $course_id); | ||
| 377 | |||
| 378 | // For Quiz if the admin marks a qiz complete we don't attempt to update an existing attempt for the user quiz. | ||
| 379 | // Instead we add a new entry. LD doesn't care as it will take the complete one for calculations where needed. | ||
| 380 | if ((bool)true === (bool)$quiz_new_status) { | ||
| 381 | if ((bool)true !== (bool)$quiz_old_status) { | ||
| 382 | |||
| 383 | if (isset($quiz_meta['sfwd-quiz_lesson'])) { | ||
| 384 | $lesson_id = absint($quiz_meta['sfwd-quiz_lesson']); | ||
| 385 | } else { | ||
| 386 | $lesson_id = 0; | ||
| 387 | } | ||
| 388 | |||
| 389 | if (isset($quiz_meta['sfwd-quiz_topic'])) { | ||
| 390 | $topic_id = absint($quiz_meta['sfwd-quiz_topic']); | ||
| 391 | } else { | ||
| 392 | $topic_id = 0; | ||
| 393 | } | ||
| 394 | |||
| 395 | // If the admin is marking the quiz complete AND the quiz is NOT already complete... | ||
| 396 | // Then we add the minimal quiz data to the user profile. | ||
| 397 | $quizdata = [ | ||
| 398 | 'quiz' => $quiz_id, | ||
| 399 | 'score' => 0, | ||
| 400 | 'count' => 0, | ||
| 401 | 'question_show_count' => 0, | ||
| 402 | 'pass' => true, | ||
| 403 | 'rank' => '-', | ||
| 404 | 'time' => time(), | ||
| 405 | 'pro_quizid' => absint($quiz_meta['sfwd-quiz_quiz_pro']), | ||
| 406 | 'course' => $course_id, | ||
| 407 | 'lesson' => $lesson_id, | ||
| 408 | 'topic' => $topic_id, | ||
| 409 | 'points' => 0, | ||
| 410 | 'total_points' => 0, | ||
| 411 | 'percentage' => 0, | ||
| 412 | 'timespent' => 0, | ||
| 413 | 'has_graded' => false, | ||
| 414 | 'statistic_ref_id' => 0, | ||
| 415 | 'm_edit_by' => get_current_user_id(), // Manual Edit By ID. | ||
| 416 | 'm_edit_time' => time(), // Manual Edit timestamp. | ||
| 417 | ]; | ||
| 418 | |||
| 419 | $quizz_progress[] = $quizdata; | ||
| 420 | |||
| 421 | if (true === $quizdata['pass']) { | ||
| 422 | $quizdata_pass = true; | ||
| 423 | } else { | ||
| 424 | $quizdata_pass = false; | ||
| 425 | } | ||
| 426 | |||
| 427 | // Then we add the quiz entry to the activity database. | ||
| 428 | learndash_update_user_activity( | ||
| 429 | [ | ||
| 430 | 'course_id' => $course_id, | ||
| 431 | 'user_id' => $user_id, | ||
| 432 | 'post_id' => $quiz_id, | ||
| 433 | 'activity_type' => 'quiz', | ||
| 434 | 'activity_action' => 'insert', | ||
| 435 | 'activity_status' => $quizdata_pass, | ||
| 436 | 'activity_started' => $quizdata['time'], | ||
| 437 | 'activity_completed' => $quizdata['time'], | ||
| 438 | 'activity_meta' => $quizdata, | ||
| 439 | ] | ||
| 440 | ); | ||
| 441 | |||
| 442 | $quiz_changed = true; | ||
| 443 | |||
| 444 | if ((isset($quizdata['course'])) && (!empty($quizdata['course']))) { | ||
| 445 | $quizdata['course'] = get_post($quizdata['course']); | ||
| 446 | } | ||
| 447 | |||
| 448 | if ((isset($quizdata['lesson'])) && (!empty($quizdata['lesson']))) { | ||
| 449 | $quizdata['lesson'] = get_post($quizdata['lesson']); | ||
| 450 | } | ||
| 451 | |||
| 452 | if ((isset($quizdata['topic'])) && (!empty($quizdata['topic']))) { | ||
| 453 | $quizdata['topic'] = get_post($quizdata['topic']); | ||
| 454 | } | ||
| 455 | |||
| 456 | /** | ||
| 457 | * Fires after the quiz is marked as complete. | ||
| 458 | * | ||
| 459 | * @param arrat $quizdata An array of quiz data. | ||
| 460 | * @param WP_User $user WP_User object. | ||
| 461 | */ | ||
| 462 | do_action('learndash_quiz_completed', $quizdata, get_user_by('ID', $user_id)); | ||
| 463 | |||
| 464 | } | ||
| 465 | } elseif (true !== $quiz_new_status) { | ||
| 466 | // If we are unsetting a quiz ( changing from complete to incomplete). We need to do some complicated things... | ||
| 467 | if (true === $quiz_old_status) { | ||
| 468 | |||
| 469 | if (!empty($quizz_progress)) { | ||
| 470 | foreach ($quizz_progress as $quiz_idx => $quiz_item) { | ||
| 471 | |||
| 472 | if (($quiz_item['quiz'] == $quiz_id) && (true === $quiz_item['pass'])) { | ||
| 473 | $quizz_progress[$quiz_idx]['pass'] = false; | ||
| 474 | |||
| 475 | // We need to update the activity database records for this quiz_id | ||
| 476 | $activity_query_args = [ | ||
| 477 | 'post_ids' => $quiz_id, | ||
| 478 | 'user_ids' => $user_id, | ||
| 479 | 'activity_type' => 'quiz', | ||
| 480 | ]; | ||
| 481 | $quiz_activity = learndash_reports_get_activity($activity_query_args); | ||
| 482 | if ((isset($quiz_activity['results'])) && (!empty($quiz_activity['results']))) { | ||
| 483 | foreach ($quiz_activity['results'] as $result) { | ||
| 484 | if ((isset($result->activity_meta['pass'])) && (true === $result->activity_meta['pass'])) { | ||
| 485 | |||
| 486 | // If the activity meta 'pass' element is set to true we want to update it to false. | ||
| 487 | learndash_update_user_activity_meta($result->activity_id, 'pass', | ||
| 488 | false); | ||
| 489 | |||
| 490 | // Also we need to update the 'activity_status' for this record | ||
| 491 | learndash_update_user_activity( | ||
| 492 | [ | ||
| 493 | 'activity_id' => $result->activity_id, | ||
| 494 | 'course_id' => $course_id, | ||
| 495 | 'user_id' => $user_id, | ||
| 496 | 'post_id' => $quiz_id, | ||
| 497 | 'activity_type' => 'quiz', | ||
| 498 | 'activity_action' => 'update', | ||
| 499 | 'activity_status' => false, | ||
| 500 | ] | ||
| 501 | ); | ||
| 502 | } | ||
| 503 | } | ||
| 504 | } | ||
| 505 | |||
| 506 | $quiz_changed = true; | ||
| 507 | } | ||
| 508 | |||
| 509 | /** | ||
| 510 | * Remove the quiz lock. | ||
| 511 | * | ||
| 512 | * @since 2.3.1 | ||
| 513 | */ | ||
| 514 | if ((isset($quiz_item['pro_quizid'])) && (!empty($quiz_item['pro_quizid']))) { | ||
| 515 | learndash_remove_user_quiz_locks($user_id, $quiz_item['quiz']); | ||
| 516 | } | ||
| 517 | } | ||
| 518 | } | ||
| 519 | } | ||
| 520 | } | ||
| 521 | |||
| 522 | $processed_course_ids[intval($course_id)] = intval($course_id); | ||
| 523 | } | ||
| 524 | } | ||
| 525 | } | ||
| 526 | |||
| 527 | if (true === $quiz_changed) { | ||
| 528 | update_user_meta($user_id, '_sfwd-quizzes', $quizz_progress); | ||
| 529 | } | ||
| 530 | } | ||
| 531 | |||
| 532 | if (!empty($processed_course_ids)) { | ||
| 533 | foreach (array_unique($processed_course_ids) as $course_id) { | ||
| 534 | learndash_process_mark_complete($user_id, $course_id); | ||
| 535 | learndash_update_group_course_user_progress($course_id, $user_id); | ||
| 536 | } | ||
| 537 | } | ||
| 538 | |||
| 539 | } | ||
| 540 | |||
| 541 | |||
| 542 | add_shortcode('dash_user_info', 'dash_user_info_shortcode'); | ||
| 543 | |||
| 544 | function dash_user_info_shortcode() | ||
| 545 | { | ||
| 546 | global $current_user; | ||
| 547 | get_currentuserinfo(); | ||
| 548 | echo'<div class="dash_user_info">'; | ||
| 549 | echo get_avatar( $current_user->ID, 180 ); | ||
| 550 | echo '<p>'.$current_user->first_name.' '.$current_user->last_name.'</p>'; | ||
| 551 | echo "</div>"; | ||
| 552 | ob_start();?> | ||
| 553 | |||
| 554 | <?php | ||
| 555 | |||
| 556 | return ob_get_clean(); | ||
| 557 | } | ||
| 558 | |||
| 559 | |||
| 560 | function the_bread() { | ||
| 561 | if(!is_admin()){ | ||
| 562 | $ingredients = array( | ||
| 563 | 'separator' => '>', | ||
| 564 | 'offset' => -3, | ||
| 565 | 'length' => 3, | ||
| 566 | ); | ||
| 567 | |||
| 568 | $flour = $_SERVER['REQUEST_URI']; | ||
| 569 | |||
| 570 | if ( str_contains( $flour, '?' ) ) | ||
| 571 | $flour = substr( $flour, 0, strpos( $flour, '?' ) ); | ||
| 572 | |||
| 573 | $flour = ( str_ends_with( $flour, '/' ) ? explode( '/', substr( $flour, 1, -1 ) ) : explode( '/', substr( $flour, 1 ) ) ); | ||
| 574 | |||
| 575 | $crumbs = []; | ||
| 576 | |||
| 577 | foreach ( $flour as $crumb ) { | ||
| 578 | |||
| 579 | $slug = esc_html( $crumb ); | ||
| 580 | |||
| 581 | $url = esc_url( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . substr( implode( '/', $flour ), 0, strpos( implode( '/', $flour ), $crumb ) ) . $crumb. '/' ); | ||
| 582 | |||
| 583 | array_push( $crumbs, ( object ) | ||
| 584 | [ | ||
| 585 | 'slug' => $slug, | ||
| 586 | 'url' => $url, | ||
| 587 | ] | ||
| 588 | ); | ||
| 589 | |||
| 590 | }; | ||
| 591 | |||
| 592 | $offset = ( empty( $ingredients['offset'] ) ? 0 : $ingredients['offset'] ); | ||
| 593 | $length = ( empty( $ingredients['length'] ) ? null : $ingredients['length'] ); | ||
| 594 | |||
| 595 | $crumbs = array_slice( $crumbs, $offset, $length ); | ||
| 596 | |||
| 597 | echo '<ul class="bread">'; | ||
| 598 | |||
| 599 | $i = 0; | ||
| 600 | if ( is_singular( 'sfwd-lessons' ) ) { | ||
| 601 | echo '<li class="crumb" itemprop="itemListElement"> | ||
| 602 | <a itemprop="item" href="https://thecommonwell.ca/learning-2/"> | ||
| 603 | <span itemprop="name">Broker Learning</span> | ||
| 604 | </a> | ||
| 605 | <meta itemprop="position" content="1"> | ||
| 606 | </li>><li class="crumb" itemprop="itemListElement"> | ||
| 607 | <a itemprop="item" href="https://thecommonwell.ca/learning-2/marketing-masters/"> | ||
| 608 | <span itemprop="name">Marketing Masters</span> | ||
| 609 | </a> | ||
| 610 | <meta itemprop="position" content="2"> | ||
| 611 | </li>>'; | ||
| 612 | } | ||
| 613 | foreach ( $crumbs as $crumb ) { | ||
| 614 | $i++; | ||
| 615 | |||
| 616 | echo '<li class="crumb" itemprop="itemListElement"> | ||
| 617 | <a itemprop="item" href="' . $crumb->url . '"> | ||
| 618 | <span itemprop="name">' . ( url_to_postid( $crumb->url ) ? get_the_title( url_to_postid( $crumb->url ) ) : ucfirst( str_replace( '-', ' ', $crumb->slug ) ) ) . '</span> | ||
| 619 | </a> | ||
| 620 | <meta itemprop="position" content="' . $i . '"> | ||
| 621 | </li>'; | ||
| 622 | |||
| 623 | if ( $i !== sizeof( $crumbs ) && ! empty( $ingredients['separator'] ) ) | ||
| 624 | echo $ingredients['separator']; | ||
| 625 | |||
| 626 | }; | ||
| 627 | |||
| 628 | echo '</ul>'; | ||
| 629 | } | ||
| 630 | |||
| 631 | }; | ||
| 632 | |||
| 633 | add_shortcode( 'breadcrumbs', 'the_bread' ); |
| 1 | <?php | ||
| 2 | |||
| 3 | if( function_exists('acf_add_options_page') ) { | ||
| 4 | |||
| 5 | acf_add_options_page(array( | ||
| 6 | 'page_title' => 'Payment Options', | ||
| 7 | 'menu_title' => 'Payment Options', | ||
| 8 | 'menu_slug' => 'payment-options', | ||
| 9 | 'capability' => 'edit_posts', | ||
| 10 | 'redirect' => false | ||
| 11 | )); | ||
| 12 | |||
| 13 | } | ||
| 14 | |||
| 15 | add_action( 'admin_menu', 'rudr_submenu' ); | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | add_action('wpcf7_init', 'networking_setup'); | ||
| 20 | |||
| 21 | function networking_setup() | ||
| 22 | { | ||
| 23 | wpcf7_add_form_tag('bambora_checkout', 'bambora_checkout'); | ||
| 24 | |||
| 25 | } | ||
| 26 | |||
| 27 | function bambora_checkout($tag) | ||
| 28 | { | ||
| 29 | |||
| 30 | $bambora = ' <div id="bambora" class="container"> | ||
| 31 | <div class="row"> <div class="form-group col-lg-12 has-feedback" id="card-number-bootstrap">Card Number *<div id="card-number" class="form-control"></div><label class="help-block" for="card-number" id="card-number-error"></label> </div></div> | ||
| 32 | <div class="row"> <div class="form-group col-md-12 col-lg-6 has-feedback" id="card-cvv-bootstrap">CVV *<div id="card-cvv" class="form-control"></div><label class="help-block" for="card-cvv" id="card-cvv-error"></label> </div> | ||
| 33 | <div class="form-group col-md-12 col-lg-6 has-feedback" id="card-expiry-bootstrap">Expiry Date *<div id="card-expiry" class="form-control"></div><label class="help-block" for="card-expiry" id="card-expiry-error"></label> </div> | ||
| 34 | <div class="payment"><button id="pay-button" type="submit" class="btn btn-primary disabled" disabled="true">SUBMIT</button> </div> </div></div> | ||
| 35 | <br><div class="row"> <div class="col-lg-12 text-center"> <div id="feedback"></div></div></div><div class="overlay"><div style="width:400px;margin:auto;text-align: center;"> <img class="load" src="../wp-content/themes/commonwell-corp/images/loading.svg"/><br><h2>Processing...</h2></div></div>'; | ||
| 36 | |||
| 37 | return $bambora; | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | add_action('wp_ajax_submited', 'submited'); | ||
| 44 | add_action('wp_ajax_nopriv_submited', 'submited'); | ||
| 45 | |||
| 46 | |||
| 47 | function submited() | ||
| 48 | { | ||
| 49 | $new_post = array( | ||
| 50 | 'post_title' => $_POST['policy_number'].'_'.date('Y-m-d H:i:s'), | ||
| 51 | 'post_content' => '', | ||
| 52 | 'post_status' => 'publish', | ||
| 53 | 'post_type' => 'invoices', | ||
| 54 | 'post_category' => array(0) | ||
| 55 | ); | ||
| 56 | |||
| 57 | $post_id = wp_insert_post($new_post); | ||
| 58 | update_post_meta($post_id, 'approved_declined','submited'); | ||
| 59 | update_post_meta($post_id, 'policy_holders_name',$_POST['policy_holders_name'] ); | ||
| 60 | update_post_meta($post_id, 'card_holder',$_POST['card_holder'] ); | ||
| 61 | update_post_meta($post_id, 'policy_number',$_POST['policy_number'] ); | ||
| 62 | update_post_meta($post_id, 'payment_amount',$_POST['payment_amount'] ); | ||
| 63 | update_post_meta($post_id, 'user_email',$_POST['user_email'] ); | ||
| 64 | update_post_meta($post_id, 'user_phone',$_POST['user_phone'] ); | ||
| 65 | $return = array( | ||
| 66 | 'ID' => $post_id | ||
| 67 | ); | ||
| 68 | wp_send_json_success($return); | ||
| 69 | exit; | ||
| 70 | |||
| 71 | } | ||
| 72 | |||
| 73 | add_action('wpcf7_before_send_mail', 'send_payment_information', 10, 1); | ||
| 74 | |||
| 75 | function send_payment_information($contact_form) | ||
| 76 | { | ||
| 77 | |||
| 78 | $form_id = $contact_form->id(); | ||
| 79 | if ($form_id == 65254) | ||
| 80 | { | ||
| 81 | $wpcf7 = WPCF7_ContactForm::get_current(); | ||
| 82 | $submission = WPCF7_Submission::get_instance(); | ||
| 83 | $data = $submission->get_posted_data(); | ||
| 84 | save_payment_data($data); | ||
| 85 | send_payment_email($data); | ||
| 86 | |||
| 87 | |||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | function save_payment_data($data) | ||
| 93 | { | ||
| 94 | |||
| 95 | $post_id = $data['postId']; | ||
| 96 | if(empty($post_id)){ | ||
| 97 | |||
| 98 | $new_post = array( | ||
| 99 | 'post_title' => $data['policy_number'].'_'.date('Y-m-d H:i:s'), | ||
| 100 | 'post_content' => '', | ||
| 101 | 'post_status' => 'publish', | ||
| 102 | 'post_type' => 'invoices', | ||
| 103 | 'post_category' => array(0) | ||
| 104 | ); | ||
| 105 | $post_id = wp_insert_post($new_post); | ||
| 106 | update_post_meta($post_id, 'policy_holders_name',$data['policy_holders_name'] ); | ||
| 107 | update_post_meta($post_id, 'card_holder',$data['card_holder'] ); | ||
| 108 | update_post_meta($post_id, 'policy_number',$data['policy_number'] ); | ||
| 109 | update_post_meta($post_id, 'payment_amount',$data['payment_amount'] ); | ||
| 110 | update_post_meta($post_id, 'user_email',$data['user_email'] ); | ||
| 111 | update_post_meta($post_id, 'user_phone',$data['user_phone'] ); | ||
| 112 | update_post_meta($post_id, 'payment_amount',$data['payment_amount'] ); | ||
| 113 | |||
| 114 | } | ||
| 115 | |||
| 116 | update_post_meta($post_id, 'approved_declined','approved' ); | ||
| 117 | update_post_meta($post_id, 'payment_confirmed',$data['payment_confirmed'] ); | ||
| 118 | update_post_meta($post_id, 'transId',$data['transId'] ); | ||
| 119 | update_post_meta($post_id, 'response_message', 'Approved'); | ||
| 120 | |||
| 121 | } | ||
| 122 | |||
| 123 | |||
| 124 | |||
| 125 | |||
| 126 | function send_payment_email($data) | ||
| 127 | { | ||
| 128 | if(!empty($data['user_email'])){ | ||
| 129 | $currency = 'CAD'; | ||
| 130 | $locale = 'en_CA'; | ||
| 131 | |||
| 132 | $fmt = new \NumberFormatter( $locale, \NumberFormatter::CURRENCY ); | ||
| 133 | |||
| 134 | $to = $data['user_email']; | ||
| 135 | $subject = 'Payment Confirmation'; | ||
| 136 | $headers = array('Content-Type: text/html; charset=UTF-8', 'From: noreply@thecommonwell.ca <noreply@thecommonwell.ca>'); | ||
| 137 | $body =' | ||
| 138 | <style>.bold{font-weight:bold;}</style> | ||
| 139 | <h2>Your transaction has been approved</h2> | ||
| 140 | <table> | ||
| 141 | <tr><td class="bold">Policyholder’s Name</td><td>'.$data['policy_holders_name'].'</td></tr> | ||
| 142 | <tr><td class="bold">Policy Number</td><td>'.$data['policy_number'].'</td></tr> | ||
| 143 | <tr><td class="bold">Authorization Number</td><td>'.$data['transId'].'</td></tr> | ||
| 144 | <tr><td class="bold">Amount Paid</td><td>'.$fmt->formatCurrency($data['payment_amount'], $currency).'</td></tr> | ||
| 145 | <tr><td class="bold">Date</td><td>'. get_the_date( 'Y-m-d g:i a', $data['postId'] ).'</td></tr> | ||
| 146 | </table>'; | ||
| 147 | |||
| 148 | wp_mail($to, $subject, $body, $headers); | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | |||
| 153 | add_action('wp_ajax_submit_declined', 'submit_declined'); | ||
| 154 | add_action('wp_ajax_nopriv_submit_declined', 'submit_declined'); | ||
| 155 | |||
| 156 | function submit_declined() | ||
| 157 | { | ||
| 158 | $post_id = $_POST['postId']; | ||
| 159 | if(empty($post_id)){ | ||
| 160 | |||
| 161 | $new_post = array( | ||
| 162 | 'post_title' => $data['policy_number'].'_'.date('Y-m-d H:i:s'), | ||
| 163 | 'post_content' => '', | ||
| 164 | 'post_status' => 'publish', | ||
| 165 | 'post_type' => 'invoices', | ||
| 166 | 'post_category' => array(0) | ||
| 167 | ); | ||
| 168 | $post_id = wp_insert_post($new_post); | ||
| 169 | update_post_meta($post_id, 'policy_holders_name',$_POST['policy_holders_name'] ); | ||
| 170 | update_post_meta($post_id, 'card_holder',$_POST['card_holder'] ); | ||
| 171 | update_post_meta($post_id, 'policy_number',$_POST['policy_number'] ); | ||
| 172 | update_post_meta($post_id, 'payment_amount',$_POST['payment_amount'] ); | ||
| 173 | update_post_meta($post_id, 'user_email',$_POST['user_email'] ); | ||
| 174 | update_post_meta($post_id, 'user_phone',$_POST['user_phone'] ); | ||
| 175 | update_post_meta($post_id, 'payment_amount',$_POST['payment_amount'] ); | ||
| 176 | |||
| 177 | } | ||
| 178 | update_post_meta($post_id, 'transId',$_POST['transId'] ); | ||
| 179 | update_post_meta($post_id, 'approved_declined','declined'); | ||
| 180 | update_post_meta($post_id, 'response_message',$_POST['response_message'] ); | ||
| 181 | send_payment_declined($_POST); | ||
| 182 | wp_send_json_success(); | ||
| 183 | exit; | ||
| 184 | |||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | function send_payment_declined($data) | ||
| 189 | { | ||
| 190 | if(!empty($data['user_email'])){ | ||
| 191 | $currency = 'CAD'; | ||
| 192 | $locale = 'en_CA'; | ||
| 193 | |||
| 194 | $fmt = new \NumberFormatter( $locale, \NumberFormatter::CURRENCY ); | ||
| 195 | |||
| 196 | $to = $data['user_email']; | ||
| 197 | $subject = 'Payment Declined'; | ||
| 198 | $headers = array('Content-Type: text/html; charset=UTF-8', 'From: noreply@thecommonwell.ca <noreply@thecommonwell.ca>'); | ||
| 199 | $body =' | ||
| 200 | <style>.bold{font-weight:bold;}</style> | ||
| 201 | <h2>Your transaction has been declined</h2> | ||
| 202 | <p>The following transaction has been declined. Please try again later. If the problem persists please call our billing department at 1-844-267-7577.<p> | ||
| 203 | <table> | ||
| 204 | <tr><td class="bold">Policyholder’s Name</td><td>'.$data['policy_holders_name'].'</td></tr> | ||
| 205 | <tr><td class="bold">Policy Number</td><td>'.$data['policy_number'].'</td></tr> | ||
| 206 | <tr><td class="bold">Amount</td><td>'.$fmt->formatCurrency($data['payment_amount'], $currency).'</td></tr> | ||
| 207 | <tr><td class="bold">Date</td><td>'. get_the_date( 'Y-m-d g:i a', $data['postId'] ).'</td></tr> | ||
| 208 | </table>'; | ||
| 209 | |||
| 210 | wp_mail($to, $subject, $body, $headers); | ||
| 211 | |||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | function get_oauth_token() | ||
| 216 | { | ||
| 217 | |||
| 218 | $curl = curl_init(); | ||
| 219 | |||
| 220 | curl_setopt_array($curl, array( | ||
| 221 | CURLOPT_URL => getenv('external_payment_token'), | ||
| 222 | CURLOPT_RETURNTRANSFER => true, | ||
| 223 | CURLOPT_ENCODING => '', | ||
| 224 | CURLOPT_MAXREDIRS => 10, | ||
| 225 | CURLOPT_TIMEOUT => 3, | ||
| 226 | CURLOPT_CONNECTTIMEOUT => 1, | ||
| 227 | CURLOPT_FOLLOWLOCATION => true, | ||
| 228 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
| 229 | CURLOPT_CUSTOMREQUEST => 'POST', | ||
| 230 | CURLOPT_POSTFIELDS =>'{ | ||
| 231 | "client_id": "'.getenv('external_payment_client_id').'", | ||
| 232 | "client_secret": "'.getenv('external_payment_client_secret').'", | ||
| 233 | "audience": "'.getenv('external_payment_audience').'", | ||
| 234 | "grant_type": "client_credentials" | ||
| 235 | }', | ||
| 236 | CURLOPT_HTTPHEADER => array( | ||
| 237 | 'Content-Type: application/json', | ||
| 238 | 'Cookie: did=s%3Av0%3Ac0a3ada0-4f00-11ed-976f-adb722eaf863.QGVoTtXe6a3%2Fy3972nHfTp%2FYiqbnA1BVT0X1%2F3lhHhg; did_compat=s%3Av0%3Ac0a3ada0-4f00-11ed-976f-adb722eaf863.QGVoTtXe6a3%2Fy3972nHfTp%2FYiqbnA1BVT0X1%2F3lhHhg' | ||
| 239 | ), | ||
| 240 | )); | ||
| 241 | |||
| 242 | $response = curl_exec($curl); | ||
| 243 | error_log(print_r($response, true)); | ||
| 244 | curl_close($curl); | ||
| 245 | $data_obj = json_decode($response); | ||
| 246 | |||
| 247 | update_option( 'payment_service_access_token', $data_obj->{"access_token"}, true ); | ||
| 248 | return $response; | ||
| 249 | } | ||
| 250 | |||
| 251 | |||
| 252 | function send_confirm_payment($data) | ||
| 253 | { | ||
| 254 | |||
| 255 | |||
| 256 | error_log('send_confirm_payment Guidewire'); | ||
| 257 | $curl = curl_init(); | ||
| 258 | $access_token = get_option( 'payment_service_access_token' ); | ||
| 259 | curl_setopt_array($curl, array( | ||
| 260 | CURLOPT_URL => getenv('external_payment'), | ||
| 261 | CURLOPT_RETURNTRANSFER => true, | ||
| 262 | CURLOPT_ENCODING => '', | ||
| 263 | CURLOPT_MAXREDIRS => 10, | ||
| 264 | CURLOPT_TIMEOUT => 3, | ||
| 265 | CURLOPT_CONNECTTIMEOUT => 1, | ||
| 266 | CURLOPT_FOLLOWLOCATION => true, | ||
| 267 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
| 268 | CURLOPT_CUSTOMREQUEST => 'POST', | ||
| 269 | CURLOPT_POSTFIELDS =>'{ | ||
| 270 | "requestUID" : "'.$data['transId'].'", | ||
| 271 | "requestApplicationName" : "Tenzing", | ||
| 272 | "policyNumber" : "'.$data['policy_number'].'", | ||
| 273 | "amount": "'.$data['payment_amount'].'", | ||
| 274 | "paymentDate": "'.date('Y-m-d H:i:s').'", | ||
| 275 | "paymentReceivedDate": "'.date('Y-m-d H:i:s').'", | ||
| 276 | "paymentMethod": "singlecreditcard_tcw", | ||
| 277 | "receiptType": "DIRECTBILLMONEYDETAILS", | ||
| 278 | "customerName" :"'.$data['policy_holders_name'].'" | ||
| 279 | }', | ||
| 280 | CURLOPT_HTTPHEADER => array( | ||
| 281 | 'Content-Type: application/json', | ||
| 282 | 'Authorization: Bearer '.$access_token.'' | ||
| 283 | ), | ||
| 284 | )); | ||
| 285 | |||
| 286 | $response = curl_exec($curl); | ||
| 287 | |||
| 288 | curl_close($curl); | ||
| 289 | error_log(print_r($response, true)); | ||
| 290 | $data_obj = json_decode($response); | ||
| 291 | $paymentId = $data_obj->{"paymentId"}; | ||
| 292 | if(!empty($data_obj->{"paymentId"})){ | ||
| 293 | update_post_meta($data['postId'], 'sent_confirm', true ); | ||
| 294 | update_post_meta($data['postId'], 'response_paymentId', $paymentId ); | ||
| 295 | update_post_meta($data['postId'], 'sent_confirm_response', $response ); | ||
| 296 | }else if($data_obj->{"error"} == 'Unauthorized'){ | ||
| 297 | get_oauth_token(); | ||
| 298 | send_confirm_payment($data); | ||
| 299 | }else{ | ||
| 300 | error_log('curl send_confirm_payment fail'); | ||
| 301 | send_confirm_payment_fail($data); | ||
| 302 | } | ||
| 303 | |||
| 304 | |||
| 305 | |||
| 306 | } | ||
| 307 | |||
| 308 | |||
| 309 | function send_confirm_payment_fail($data) | ||
| 310 | { | ||
| 311 | error_log('mail send_confirm_payment fail'); | ||
| 312 | $currency = 'CAD'; | ||
| 313 | $locale = 'en_CA'; | ||
| 314 | |||
| 315 | $fmt = new \NumberFormatter( $locale, \NumberFormatter::CURRENCY ); | ||
| 316 | |||
| 317 | $to = get_field('send_confirm_payment_fail', 'option'); | ||
| 318 | $subject = 'Failed Guidewire Call'; | ||
| 319 | $headers = array('Content-Type: text/html; charset=UTF-8', 'From: noreply@thecommonwell.ca <noreply@thecommonwell.ca>'); | ||
| 320 | $body =' | ||
| 321 | <style>.bold{font-weight:bold;}</style> | ||
| 322 | <h2>Failed to send transaction to Guidewire</h2> | ||
| 323 | <table> | ||
| 324 | <tr><td class="bold">Trans ID</td><td>'.$data['transId'].'</td></tr> | ||
| 325 | <tr><td class="bold">Policyholder’s Name</td><td>'.$data['policy_holders_name'].'</td></tr> | ||
| 326 | <tr><td class="bold">Policy Number</td><td>'.$data['policy_number'].'</td></tr> | ||
| 327 | <tr><td class="bold">Authorization Number</td><td>'.$data['transId'].'</td></tr> | ||
| 328 | <tr><td class="bold">Amount Paid</td><td>'.$fmt->formatCurrency($data['payment_amount'], $currency).'</td></tr> | ||
| 329 | <tr><td class="bold">Date</td><td>'. get_the_date( 'Y-m-d g:i a', $data['postId'] ).'</td></tr> | ||
| 330 | </table>'; | ||
| 331 | |||
| 332 | wp_mail($to, $subject, $body, $headers); | ||
| 333 | |||
| 334 | } | ||
| 335 | |||
| 336 | add_shortcode( 'payment_form', 'payment_form' ); | ||
| 337 | |||
| 338 | function payment_form() | ||
| 339 | { | ||
| 340 | if(is_admin()){ | ||
| 341 | return false; | ||
| 342 | } | ||
| 343 | |||
| 344 | ob_start(); | ||
| 345 | if(ip_visitor_country() == "CA" | ||
| 346 | || ip_visitor_country() == "US" | ||
| 347 | || ip_visitor_country() == "Unknown" | ||
| 348 | ){ | ||
| 349 | |||
| 350 | if(get_field('payment_on', 'option') == 'true'){ | ||
| 351 | ?> | ||
| 352 | <?php echo do_shortcode('[contact-form-7 id="65254" title="Payment" html_id="GeneratedTable_wrapper" ]');?> | ||
| 353 | |||
| 354 | |||
| 355 | <?php | ||
| 356 | }else{ | ||
| 357 | ?> | ||
| 358 | <div class="pay-closed alert alert-danger" style="color:#68696D;" role="alert"><?php the_field('payment_closed', 'option'); ?></div> | ||
| 359 | <?php echo do_shortcode('[contact-form-7 id="65254" title="Payment" html_id="GeneratedTable_wrapper" ]'); | ||
| 360 | } | ||
| 361 | }else{ | ||
| 362 | ?><div class="pay-closed alert alert-danger" style="color:#68696D;" role="alert"><?php the_field('payment_location_closed', 'option'); ?></div><?php | ||
| 363 | } | ||
| 364 | |||
| 365 | $output = ob_get_clean(); | ||
| 366 | |||
| 367 | return $output; | ||
| 368 | } | ||
| 369 | |||
| 370 | |||
| 371 | function rudr_submenu(){ | ||
| 372 | |||
| 373 | add_submenu_page( | ||
| 374 | 'options-general.php', // parent page slug | ||
| 375 | 'Payment Report', | ||
| 376 | 'Payment Report', | ||
| 377 | 'manage_options', | ||
| 378 | 'payment_report', | ||
| 379 | 'payment_report', | ||
| 380 | 4 // menu position | ||
| 381 | ); | ||
| 382 | } | ||
| 383 | |||
| 384 | |||
| 385 | |||
| 386 | |||
| 387 | |||
| 388 | //add_shortcode( 'payment_report', 'payment_report' ); | ||
| 389 | |||
| 390 | add_action( 'admin_enqueue_scripts', 'enqueue_custom_admin' ); | ||
| 391 | |||
| 392 | function enqueue_custom_admin(){ | ||
| 393 | wp_enqueue_script( 'customcheckout', get_stylesheet_directory_uri().'/scripts/customcheckout.js', array(), '0.0.24', true ); | ||
| 394 | wp_enqueue_style('datatables', '//cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css', [], "0.0.1"); | ||
| 395 | wp_enqueue_script('datatables', '//cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js',['jquery'], '0.0.1',true ); | ||
| 396 | wp_enqueue_script('dataTables_buttons', '//cdn.datatables.net/buttons/2.3.2/js/dataTables.buttons.min.js',['jquery'], '0.0.1',true ); | ||
| 397 | wp_enqueue_script('dataTables_buttons_html5', '//cdn.datatables.net/buttons/2.3.2/js/buttons.html5.min.js',['jquery'], '0.0.1',true ); | ||
| 398 | } | ||
| 399 | |||
| 400 | function payment_report() | ||
| 401 | { | ||
| 402 | |||
| 403 | |||
| 404 | if(is_admin()){ | ||
| 405 | // return false; | ||
| 406 | } | ||
| 407 | |||
| 408 | $args = array( | ||
| 409 | 'post_type' => 'invoices', | ||
| 410 | 'post_status' => 'publish', | ||
| 411 | 'posts_per_page' => -1, | ||
| 412 | |||
| 413 | ); | ||
| 414 | $content = "<style> | ||
| 415 | .dataTables_wrapper { | ||
| 416 | position: relative; | ||
| 417 | clear: both; | ||
| 418 | width: 100%; | ||
| 419 | margin-top:40px; | ||
| 420 | overflow:scroll; | ||
| 421 | background-color:#fff; | ||
| 422 | padding:10px; | ||
| 423 | } | ||
| 424 | |||
| 425 | div.dataTables_wrapper div.dataTables_filter { | ||
| 426 | margin-top:20px; | ||
| 427 | text-align: right; | ||
| 428 | width: 95%; | ||
| 429 | float: left; | ||
| 430 | } | ||
| 431 | .status-dropdown{ | ||
| 432 | width:200px; | ||
| 433 | float:left; | ||
| 434 | } | ||
| 435 | </style>"; | ||
| 436 | $posts = new WP_Query( $args ); | ||
| 437 | |||
| 438 | if ( $posts->have_posts() ) : | ||
| 439 | $content .= '<select class="form-control status-dropdown"><option value="">All</option><option value="submited">submited</option> <option value="approved">approved</option> <option value="declined">declined</option></select>'; | ||
| 440 | $content .= '<table id="payments">'; | ||
| 441 | $content .= '<thead><tr> | ||
| 442 | <th>Trans ID</th> | ||
| 443 | <th>Status</th> | ||
| 444 | <th>Date</th> | ||
| 445 | <th>Policyholder\'s Name</th> | ||
| 446 | <th>Policy Number</th> | ||
| 447 | <th>Payment Amount</th> | ||
| 448 | <th>Email Address</th> | ||
| 449 | <th>Phone Number</th> | ||
| 450 | <th>Payment Confirmed</th> | ||
| 451 | <th>Response Message</th> | ||
| 452 | <th>Guidewire Response</th> | ||
| 453 | </tr></thead>'; | ||
| 454 | while ( $posts->have_posts() ) :$posts->the_post(); | ||
| 455 | $post_id = get_the_ID(); | ||
| 456 | $post_date = get_the_date( 'Y-m-d H:i:s' ); | ||
| 457 | $content .= '<tr>'; | ||
| 458 | $content .= '<td>' . get_post_meta( $post_id , 'transId',true ). '</td>'; | ||
| 459 | $content .= '<td>' . get_post_meta( $post_id , 'approved_declined',true ). '</td>'; | ||
| 460 | $content .= '<td>'.$post_date.'</td>'; | ||
| 461 | $content .= '<td>' . get_post_meta( $post_id , 'policy_holders_name',true ). '</td>'; | ||
| 462 | $content .= '<td>' . get_post_meta( $post_id , 'policy_number',true ). '</td>'; | ||
| 463 | $content .= '<td>' . get_post_meta( $post_id , 'payment_amount',true ). '</td>'; | ||
| 464 | $content .= '<td>' . get_post_meta( $post_id , 'user_email',true ). '</td>'; | ||
| 465 | $content .= '<td>' . get_post_meta( $post_id , 'user_phone',true ). '</td>'; | ||
| 466 | $content .= '<td>' . get_post_meta( $post_id , 'payment_confirmed',true ). '</td>'; | ||
| 467 | $content .= '<td>' . get_post_meta( $post_id , 'response_message' ,true ). '</td>'; | ||
| 468 | $content .= '<td>' . get_post_meta( $post_id , 'sent_confirm_response' ,true ). '</td>'; | ||
| 469 | $content .= '</tr>'; | ||
| 470 | endwhile; | ||
| 471 | $content .= '</table>'; | ||
| 472 | echo $content; | ||
| 473 | endif; | ||
| 474 | } | ||
| 475 | |||
| 476 | //add_action('init','clean_up_invoices'); | ||
| 477 | |||
| 478 | |||
| 479 | function clean_up_invoices() | ||
| 480 | { | ||
| 481 | global $wpdb; | ||
| 482 | $wpdb->query(" | ||
| 483 | delete | ||
| 484 | p,pm | ||
| 485 | from wp_posts p | ||
| 486 | join wp_postmeta pm on pm.post_id = p.id | ||
| 487 | where p.post_type = 'invoices' | ||
| 488 | and p.post_date < now() - INTERVAL 90 DAY | ||
| 489 | "); | ||
| 490 | } | ||
| 491 | |||
| 492 | function ip_visitor_country() | ||
| 493 | { | ||
| 494 | |||
| 495 | $client = @$_SERVER['HTTP_CLIENT_IP']; | ||
| 496 | $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; | ||
| 497 | $remote = $_SERVER['REMOTE_ADDR']; | ||
| 498 | $country = "Unknown"; | ||
| 499 | |||
| 500 | if(filter_var($client, FILTER_VALIDATE_IP)) | ||
| 501 | { | ||
| 502 | $ip = $client; | ||
| 503 | } | ||
| 504 | elseif(filter_var($forward, FILTER_VALIDATE_IP)) | ||
| 505 | { | ||
| 506 | $ip = $forward; | ||
| 507 | } | ||
| 508 | else | ||
| 509 | { | ||
| 510 | $ip = $remote; | ||
| 511 | } | ||
| 512 | $ch = curl_init(); | ||
| 513 | curl_setopt($ch, CURLOPT_URL, "http://www.geoplugin.net/json.gp?ip=".$ip); | ||
| 514 | curl_setopt($ch, CURLOPT_HEADER, 0); | ||
| 515 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | ||
| 516 | $ip_data_in = curl_exec($ch); // string | ||
| 517 | curl_close($ch); | ||
| 518 | |||
| 519 | $ip_data = json_decode($ip_data_in,true); | ||
| 520 | $ip_data = str_replace('"', '"', $ip_data); // for PHP 5.2 see stackoverflow.com/questions/3110487/ | ||
| 521 | |||
| 522 | if($ip_data && $ip_data['geoplugin_countryCode'] != null) { | ||
| 523 | $country = $ip_data['geoplugin_countryCode']; | ||
| 524 | } | ||
| 525 | |||
| 526 | return $country; | ||
| 527 | } | ||
| 528 | |||
| 529 | |||
| 530 | |||
| 531 | add_action("init","get_post_pram"); | ||
| 532 | |||
| 533 | function get_post_pram(){ | ||
| 534 | if(isset($_POST) && isset($_POST['trnApproved']) && !empty($_POST['ref3'])){ | ||
| 535 | error_log(print_r($_POST, true)); | ||
| 536 | if($_POST['trnApproved'] == '1'){ | ||
| 537 | $id = $_POST['ref3']; | ||
| 538 | if(get_post_meta($id , 'approved_declined', true) != 'approved'){ | ||
| 539 | update_post_meta($id, 'approved_declined', 'approved'); | ||
| 540 | update_post_meta($id, 'payment_confirmed',$_POST['trnApproved'] ); | ||
| 541 | update_post_meta($id, 'transId',$_POST['trnId'] ); | ||
| 542 | update_post_meta($id, 'response_message', 'Approved'); | ||
| 543 | } | ||
| 544 | |||
| 545 | $data = array('transId'=> $_POST['trnId'], 'policy_holders_name'=> $_POST['ref2'], 'policy_number'=> $_POST['ref1'], 'payment_amount'=> $_POST['trnAmount'],'postId'=> $_POST['ref3']); | ||
| 546 | send_confirm_payment($data); | ||
| 547 | |||
| 548 | }elseif($_POST['trnApproved'] == '0'){ | ||
| 549 | $id = $_POST['ref3']; | ||
| 550 | if(get_post_meta($id , 'approved_declined', true) != 'declined'){ | ||
| 551 | update_post_meta($id, 'approved_declined','declined'); | ||
| 552 | update_post_meta($id, 'transId',$_POST['trnId'] ); | ||
| 553 | update_post_meta($id, 'response_message',$_POST['response_message']); | ||
| 554 | } | ||
| 555 | } | ||
| 556 | |||
| 557 | } | ||
| 558 | } | ||
| 559 | |||
| 560 | ?> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | <?php | ||
| 2 | |||
| 3 | /** | ||
| 4 | * Add custom user profile fields | ||
| 5 | */ | ||
| 6 | |||
| 7 | add_action('show_user_profile', 'add_custom_fields'); | ||
| 8 | add_action('edit_user_profile', 'add_custom_fields'); | ||
| 9 | add_action("user_new_form", "add_custom_fields"); | ||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | function add_custom_fields($user) | ||
| 14 | { | ||
| 15 | $brokerList = getBrokerageList(); | ||
| 16 | $userBrokerId = esc_attr(get_the_author_meta('broker_id', $user->ID)); | ||
| 17 | ?> | ||
| 18 | <div class="broker-group"> | ||
| 19 | <h3>Broker</h3> | ||
| 20 | <table class="form-table form-broker_id"> | ||
| 21 | <tr class="form-field"> | ||
| 22 | <th><label for="broker_id">Brokerage <span class="description">(required)</span></label></th> | ||
| 23 | <td> | ||
| 24 | <input type="text" style="position: absolute; opacity: 0; z-index: -1;" /> | ||
| 25 | <select name="broker_id" id="broker_id"> | ||
| 26 | <option value="">Select Broker</option> | ||
| 27 | <?php foreach ($brokerList as $broker): ?> | ||
| 28 | <?php | ||
| 29 | $isSelected = $userBrokerId === $broker['broker_id'] ? 'selected="selected"' : ''; | ||
| 30 | ?> | ||
| 31 | <option value="<?php echo $broker['broker_id']; ?>" <?php echo $isSelected; ?>><?php echo $broker['brokerage']; ?></option> | ||
| 32 | <?php endforeach;?> | ||
| 33 | </select> | ||
| 34 | </td> | ||
| 35 | </tr> | ||
| 36 | </table> | ||
| 37 | </div> | ||
| 38 | <?php | ||
| 39 | } | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Save additional profile field | ||
| 43 | */ | ||
| 44 | |||
| 45 | add_action('personal_options_update', 'save_custom_fields'); | ||
| 46 | add_action('edit_user_profile_update', 'save_custom_fields'); | ||
| 47 | add_action('user_register', 'save_custom_fields'); | ||
| 48 | |||
| 49 | function save_custom_fields($user_id) | ||
| 50 | { | ||
| 51 | # again do this only if you can | ||
| 52 | if (!current_user_can('administrator', $user_id)) { | ||
| 53 | return false; | ||
| 54 | } | ||
| 55 | |||
| 56 | $brokerList = getBrokerageList(); | ||
| 57 | $brokerage = false; | ||
| 58 | foreach ($brokerList as $broker) { | ||
| 59 | if ($_POST['broker_id'] == $broker['broker_id']) { | ||
| 60 | $brokerage = $broker['brokerage']; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | if ($brokerage) { | ||
| 65 | update_user_meta($user_id, 'brokerage', sanitize_text_field($brokerage)); | ||
| 66 | } | ||
| 67 | |||
| 68 | update_user_meta($user_id, 'broker_id', sanitize_text_field($_POST['broker_id'])); | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | add_action('admin_footer-user-new.php', 'addUAMField'); | ||
| 73 | /** | ||
| 74 | * Add UAM field into a user registration form | ||
| 75 | * | ||
| 76 | * @param $user | ||
| 77 | */ | ||
| 78 | function addUAMField($user) | ||
| 79 | { | ||
| 80 | try { | ||
| 81 | global $userAccessManager, $wpdb; | ||
| 82 | $aUamUserGroups = $userAccessManager->getAccessHandler()->getUserGroups(); | ||
| 83 | } catch(Throwable $e) { | ||
| 84 | error_log($e->getMessage()); | ||
| 85 | return; | ||
| 86 | } | ||
| 87 | |||
| 88 | ?> | ||
| 89 | <h3><?php echo TXT_UAM_GROUPS; ?></h3> | ||
| 90 | <table class="form-table"> | ||
| 91 | <tbody> | ||
| 92 | <tr> | ||
| 93 | <th> | ||
| 94 | <label for="usergroups"><?php echo TXT_UAM_SET_UP_USERGROUPS; ?></label> | ||
| 95 | </th> | ||
| 96 | <td> | ||
| 97 | <input type="hidden" name="uam_update_groups" value="true" /> | ||
| 98 | <ul class="uam_group_selection"> | ||
| 99 | <?php | ||
| 100 | if ( | ||
| 101 | !isset($sGroupsFormName) | ||
| 102 | || $sGroupsFormName === null | ||
| 103 | ) { | ||
| 104 | $sGroupsFormName = 'uam_usergroups'; | ||
| 105 | } | ||
| 106 | |||
| 107 | foreach ($aUamUserGroups as $oUamUserGroup) { | ||
| 108 | $sAddition = ''; | ||
| 109 | $sAttributes = ''; | ||
| 110 | |||
| 111 | ?> | ||
| 112 | <li> | ||
| 113 | <input type="checkbox" id="<?php echo $sGroupsFormName; ?>-<?php echo $oUamUserGroup->getId(); ?>" <?php echo $sAttributes; ?> value="<?php echo $oUamUserGroup->getId(); ?>" name="<?php echo $sGroupsFormName; ?>[]" data-name="<?php echo strtolower($oUamUserGroup->getGroupName()); ?>" /> | ||
| 114 | <label for="<?php echo $sGroupsFormName; ?>-<?php echo $oUamUserGroup->getId(); ?>" class="selectit" style="display:inline;"> | ||
| 115 | <?php echo $oUamUserGroup->getGroupName() . $sAddition; ?> | ||
| 116 | </label> | ||
| 117 | <a class="uam_group_info_link">(<?php echo TXT_UAM_INFO; ?>)</a> | ||
| 118 | <!-- Tool tip content--> | ||
| 119 | <div class="tooltip"> | ||
| 120 | <ul class="uam_group_info"> | ||
| 121 | <?php | ||
| 122 | global $userAccessManager; | ||
| 123 | |||
| 124 | foreach ($userAccessManager->getAccessHandler()->getAllObjectTypes() as $sCurObjectType) { | ||
| 125 | if (isset($aUserGroups[$oUamUserGroup->getId()])) { | ||
| 126 | $aRecursiveMembership = $aUserGroups[$oUamUserGroup->getId()]->getRecursiveMembershipForObjectType( | ||
| 127 | $sObjectType, | ||
| 128 | $iObjectId, | ||
| 129 | $sCurObjectType | ||
| 130 | ); | ||
| 131 | |||
| 132 | if (count($aRecursiveMembership) > 0) { | ||
| 133 | ?> | ||
| 134 | <li class="uam_group_info_head"> | ||
| 135 | <?php echo constant( | ||
| 136 | 'TXT_UAM_GROUP_MEMBERSHIP_BY_' . strtoupper($sCurObjectType) | ||
| 137 | ); ?>: | ||
| 138 | <ul> | ||
| 139 | <?php | ||
| 140 | foreach ($aRecursiveMembership as $oObject) { | ||
| 141 | ?> | ||
| 142 | <li class="recusiveTree"><?php echo walkPath( | ||
| 143 | $oObject, | ||
| 144 | $sCurObjectType | ||
| 145 | ); ?></li> | ||
| 146 | <?php | ||
| 147 | } | ||
| 148 | ?> | ||
| 149 | </ul> | ||
| 150 | </li> | ||
| 151 | <?php | ||
| 152 | } | ||
| 153 | } | ||
| 154 | } | ||
| 155 | ?> | ||
| 156 | <li class="uam_group_info_head"><?php echo TXT_UAM_GROUP_INFO; ?>: | ||
| 157 | <ul> | ||
| 158 | <li><?php echo TXT_UAM_READ_ACCESS; ?>: | ||
| 159 | <?php | ||
| 160 | if ($oUamUserGroup->getReadAccess() == "all") { | ||
| 161 | echo TXT_UAM_ALL; | ||
| 162 | } elseif ($oUamUserGroup->getReadAccess() == "group") { | ||
| 163 | echo TXT_UAM_ONLY_GROUP_USERS; | ||
| 164 | } | ||
| 165 | ?> | ||
| 166 | </li> | ||
| 167 | <li><?php echo TXT_UAM_WRITE_ACCESS; ?>: | ||
| 168 | <?php | ||
| 169 | if ($oUamUserGroup->getWriteAccess() == "all") { | ||
| 170 | echo TXT_UAM_ALL; | ||
| 171 | } elseif ($oUamUserGroup->getWriteAccess() == "group") { | ||
| 172 | echo TXT_UAM_ONLY_GROUP_USERS; | ||
| 173 | } | ||
| 174 | ?> | ||
| 175 | </li> | ||
| 176 | <li> | ||
| 177 | <?php echo TXT_UAM_GROUP_ROLE; ?>: <?php | ||
| 178 | if ($oUamUserGroup->getObjectsFromType('role')) { | ||
| 179 | $sOut = ''; | ||
| 180 | |||
| 181 | foreach ($oUamUserGroup->getObjectsFromType( | ||
| 182 | 'role' | ||
| 183 | ) as $sKey => $sRole) { | ||
| 184 | $sOut .= trim($sKey) . ', '; | ||
| 185 | } | ||
| 186 | |||
| 187 | echo rtrim($sOut, ', '); | ||
| 188 | } else { | ||
| 189 | echo TXT_UAM_NONE; | ||
| 190 | } | ||
| 191 | ?> | ||
| 192 | </li> | ||
| 193 | </ul> | ||
| 194 | </li> | ||
| 195 | </ul> | ||
| 196 | </div> | ||
| 197 | </li> | ||
| 198 | <?php | ||
| 199 | } | ||
| 200 | ?> | ||
| 201 | </ul> | ||
| 202 | </td> | ||
| 203 | </tr> | ||
| 204 | </tbody> | ||
| 205 | </table> | ||
| 206 | <?php | ||
| 207 | } | ||
| 208 | |||
| 209 | add_action('user_register', 'saveUAMField'); | ||
| 210 | |||
| 211 | /** | ||
| 212 | * Save the UAM field value | ||
| 213 | * | ||
| 214 | * @return bool | ||
| 215 | */ | ||
| 216 | function saveUAMField($user_id) | ||
| 217 | { | ||
| 218 | try { | ||
| 219 | |||
| 220 | # again do this only if you can | ||
| 221 | if (!current_user_can('administrator', $user_id)) { | ||
| 222 | return false; | ||
| 223 | } | ||
| 224 | |||
| 225 | global $userAccessManager; | ||
| 226 | $uamAccessHandler = $userAccessManager->getAccessHandler(); | ||
| 227 | $aUserGroups = null; | ||
| 228 | |||
| 229 | $aFormData = array(); | ||
| 230 | |||
| 231 | if (isset($_POST['uam_update_groups'])) { | ||
| 232 | $aFormData = $_POST; | ||
| 233 | } elseif (isset($_GET['uam_update_groups'])) { | ||
| 234 | $aFormData = $_GET; | ||
| 235 | } | ||
| 236 | |||
| 237 | if (isset($aFormData['uam_update_groups'])) { | ||
| 238 | if ($aUserGroups === null) { | ||
| 239 | $aUserGroups = isset($aFormData['uam_user_groups']) ? $aFormData['uam_user_groups'] : array(); | ||
| 240 | } | ||
| 241 | |||
| 242 | foreach ($aUserGroups as $key => $value) { | ||
| 243 | if (isset($aUserGroups[$key]['id'])) { | ||
| 244 | $uamUserGroups = $uamAccessHandler->getUserGroups(); | ||
| 245 | $uamUserGroup = $uamUserGroups[$key]; | ||
| 246 | $uamUserGroup->addObject('_user_', $user_id); | ||
| 247 | $uamUserGroup->save(); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | } catch(Throwable $e) { | ||
| 253 | error_log("saveUAMField Error " . $e->getMessage() . ", for user_id = " . $user_id . " while updating group(s) " . $_REQUEST['uam_update_groups']); | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | |||
| 258 | /** | ||
| 259 | * Remove roles | ||
| 260 | * | ||
| 261 | * Author, Editor, Contributor | ||
| 262 | * | ||
| 263 | */ | ||
| 264 | $wp_roles = new WP_Roles(); | ||
| 265 | $wp_roles->remove_role("author"); | ||
| 266 | $wp_roles->remove_role("editor"); | ||
| 267 | $wp_roles->remove_role("contributor"); | ||
| 268 | |||
| 269 | /** | ||
| 270 | * Admin init function | ||
| 271 | */ | ||
| 272 | |||
| 273 | add_action('admin_footer-user-new.php', 'setUserProfileLogicNewUser'); | ||
| 274 | add_action('admin_footer-user-edit.php', 'setUserProfileLogicEditUser'); | ||
| 275 | |||
| 276 | function setUserProfileLogicNewUser($hook) | ||
| 277 | { | ||
| 278 | ?> | ||
| 279 | <script> | ||
| 280 | (function($) { | ||
| 281 | var addNewUserForm = $('#createuser'); | ||
| 282 | var roleSelectBox = $('#role'); | ||
| 283 | var brokerIdSelectBox = $('#broker_id'); | ||
| 284 | var brokerIdFormField = $('.form-broker_id .form-field'); | ||
| 285 | var brokerCheckbox = $('.uam_group_selection input[type="checkbox"][id="uam_usergroups-1"]'); | ||
| 286 | var brokerGroup = $('.broker-group'); | ||
| 287 | |||
| 288 | // Role select | ||
| 289 | roleSelectBox.on( | ||
| 290 | 'change', | ||
| 291 | function(e) { | ||
| 292 | var userRole = e.target.value; | ||
| 293 | // If broker is selected | ||
| 294 | // Check "Broker" user group | ||
| 295 | if (userRole === 'subscriber') { | ||
| 296 | brokerCheckbox[0].checked = true; | ||
| 297 | brokerGroup.slideDown(100); | ||
| 298 | |||
| 299 | } else { | ||
| 300 | brokerCheckbox[0].checked = false; | ||
| 301 | brokerGroup.slideUp(100); | ||
| 302 | brokerIdSelectBox[0].selectedIndex = 0; | ||
| 303 | |||
| 304 | brokerIdFormField.removeClass('form-required'); | ||
| 305 | brokerIdFormField.removeClass('form-invalid'); | ||
| 306 | } | ||
| 307 | } | ||
| 308 | ).trigger('change'); | ||
| 309 | |||
| 310 | // Organization | ||
| 311 | brokerIdSelectBox.on('change', function() { | ||
| 312 | var userRole = roleSelectBox.val(); | ||
| 313 | // If Broker is selected, org is empty | ||
| 314 | // Show error message | ||
| 315 | if (userRole === 'subscriber') { | ||
| 316 | if (brokerIdSelectBox[0].selectedIndex !== 0) { | ||
| 317 | brokerIdFormField.removeClass('form-required'); | ||
| 318 | brokerIdFormField.removeClass('form-invalid'); | ||
| 319 | } | ||
| 320 | } | ||
| 321 | }); | ||
| 322 | |||
| 323 | addNewUserForm.on('submit', function(e) { | ||
| 324 | var userRole = roleSelectBox.val(); | ||
| 325 | |||
| 326 | // If Broker is selected, org is empty | ||
| 327 | // Show error message | ||
| 328 | if (userRole === 'subscriber') { | ||
| 329 | if (brokerIdSelectBox[0].selectedIndex == 0) { | ||
| 330 | brokerIdFormField.addClass('form-required'); | ||
| 331 | } else { | ||
| 332 | brokerIdFormField.removeClass('form-required'); | ||
| 333 | brokerIdFormField.removeClass('form-invalid'); | ||
| 334 | } | ||
| 335 | } else { | ||
| 336 | brokerIdFormField.removeClass('form-required'); | ||
| 337 | brokerIdFormField.removeClass('form-invalid'); | ||
| 338 | } | ||
| 339 | }); | ||
| 340 | |||
| 341 | })(jQuery); | ||
| 342 | </script> | ||
| 343 | <?php | ||
| 344 | } | ||
| 345 | |||
| 346 | function setUserProfileLogicEditUser($hook) | ||
| 347 | { | ||
| 348 | ?> | ||
| 349 | <script> | ||
| 350 | (function($) { | ||
| 351 | var addEditUserForm = $('#your-profile'); | ||
| 352 | var roleSelectBox = $('#role'); | ||
| 353 | var brokerCheckbox = $('.uam_group_selection input[type="checkbox"][id="uam_usergroups-1"]'); | ||
| 354 | var brokerIdFormField = $('.form-broker_id .form-field'); | ||
| 355 | var brokerGroup = $('.broker-group'); | ||
| 356 | var brokerSelectBox = $('#broker_id'); | ||
| 357 | |||
| 358 | roleSelectBox.on( | ||
| 359 | 'change', | ||
| 360 | function(e) { | ||
| 361 | var targetValue = e.target.value; | ||
| 362 | // If broker is selected | ||
| 363 | // Check "Broker" user group | ||
| 364 | if (targetValue === 'subscriber') { | ||
| 365 | brokerCheckbox[0].checked = true; | ||
| 366 | brokerGroup.slideDown(100); | ||
| 367 | } else { | ||
| 368 | brokerCheckbox[0].checked = false; | ||
| 369 | brokerGroup.slideUp(100); | ||
| 370 | brokerSelectBox[0].selectedIndex = 0; | ||
| 371 | |||
| 372 | brokerIdFormField.removeClass('form-required'); | ||
| 373 | brokerIdFormField.removeClass('form-invalid'); | ||
| 374 | } | ||
| 375 | } | ||
| 376 | ).trigger('change'); | ||
| 377 | |||
| 378 | // Organization | ||
| 379 | brokerSelectBox.on('change', function() { | ||
| 380 | var userRole = roleSelectBox.val(); | ||
| 381 | // If Broker is selected, org is empty | ||
| 382 | // Show error message | ||
| 383 | if (userRole === 'subscriber') { | ||
| 384 | if (brokerSelectBox[0].selectedIndex !== 0) { | ||
| 385 | brokerIdFormField.removeClass('form-required'); | ||
| 386 | brokerIdFormField.removeClass('form-invalid'); | ||
| 387 | } | ||
| 388 | } | ||
| 389 | }); | ||
| 390 | |||
| 391 | addEditUserForm.on('submit', function(e) { | ||
| 392 | var userRole = roleSelectBox.val(); | ||
| 393 | |||
| 394 | // If Broker is selected, org is empty | ||
| 395 | // Show error message | ||
| 396 | if (userRole === 'subscriber') { | ||
| 397 | if (brokerSelectBox[0].selectedIndex == 0) { | ||
| 398 | brokerIdFormField.addClass('form-required'); | ||
| 399 | brokerIdFormField.addClass('form-invalid'); | ||
| 400 | return false; | ||
| 401 | |||
| 402 | } else { | ||
| 403 | brokerIdFormField.removeClass('form-required'); | ||
| 404 | brokerIdFormField.removeClass('form-invalid'); | ||
| 405 | return true; | ||
| 406 | } | ||
| 407 | } else { | ||
| 408 | brokerIdFormField.removeClass('form-required'); | ||
| 409 | brokerIdFormField.removeClass('form-invalid'); | ||
| 410 | return true; | ||
| 411 | } | ||
| 412 | |||
| 413 | }); | ||
| 414 | })(jQuery); | ||
| 415 | </script> | ||
| 416 | <?php | ||
| 417 | } | ||
| 418 | |||
| 419 | |||
| 420 | |||
| 421 | |||
| 422 | |||
| 423 | add_action('show_user_profile', 'my_show_extra_profile_fields'); | ||
| 424 | add_action('edit_user_profile', 'my_show_extra_profile_fields'); | ||
| 425 | |||
| 426 | function my_show_extra_profile_fields($user) | ||
| 427 | { | ||
| 428 | |||
| 429 | $user_id = $_GET['user_id']; | ||
| 430 | if (user_can($user_id, 'cwl_staff')) { | ||
| 431 | include_once $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-config.php'; | ||
| 432 | |||
| 433 | global $wpdb; | ||
| 434 | |||
| 435 | $query = get_option('broker_list') ? unserialize(get_option('broker_list')) : []; | ||
| 436 | |||
| 437 | foreach ($query as $key => $row) { | ||
| 438 | |||
| 439 | $brokers[$row['id']]['id'] = $row['id']; | ||
| 440 | $brokers[$row['id']]['broker_id'] = $row['broker_id']; | ||
| 441 | $brokers[$row['id']]['name'] = $row['brokerage']; | ||
| 442 | } | ||
| 443 | |||
| 444 | $brokersSelected = 'select broker_id from wp_broker_staff where staff_id =' . $user_id; | ||
| 445 | |||
| 446 | foreach ($wpdb->get_results($brokersSelected) as $row) { | ||
| 447 | |||
| 448 | $brokersPicked[] = $row->broker_id; | ||
| 449 | unset($brokers[$row->broker_id]); | ||
| 450 | } | ||
| 451 | ; | ||
| 452 | |||
| 453 | $brokersLeft = $brokers; | ||
| 454 | |||
| 455 | ?> | ||
| 456 | |||
| 457 | |||
| 458 | <table class="form-table"> | ||
| 459 | |||
| 460 | <form> | ||
| 461 | <fieldset> | ||
| 462 | <tr> | ||
| 463 | |||
| 464 | |||
| 465 | <th><label>Brokers Served</label></th> | ||
| 466 | |||
| 467 | </tr> | ||
| 468 | <tr> | ||
| 469 | <td width="30%" align="center"> | ||
| 470 | YOUR LIST | ||
| 471 | <select style="width:100%;" name="brokerselected[]" id="select-to" multiple="multiple" size="5"> | ||
| 472 | <?php | ||
| 473 | |||
| 474 | foreach ($query as $key => $row) { | ||
| 475 | //error_log(print_r($brokerPicked,true)); | ||
| 476 | if (in_array($row['broker_id'], $brokersPicked)) { | ||
| 477 | |||
| 478 | ?> | ||
| 479 | <option selected="selected" value="<?php echo $row['broker_id']; ?>"><?php echo $row['brokerage']; ?></option> | ||
| 480 | |||
| 481 | |||
| 482 | |||
| 483 | <?php } | ||
| 484 | }?> | ||
| 485 | </select> | ||
| 486 | </td> | ||
| 487 | <td width="20%"> | ||
| 488 | |||
| 489 | |||
| 490 | <a href="JavaScript:void(0);" style="float:left;" id="btn-remove">Remove »</a> | ||
| 491 | |||
| 492 | <a href="JavaScript:void(0);" style="float:right;" id="btn-add">« Add </a> | ||
| 493 | </td> | ||
| 494 | <td width="30%" align="center"> | ||
| 495 | BROKERS | ||
| 496 | <select style="width:100%;" name="selectfrom" id="select-from" multiple size="5"> | ||
| 497 | <?php foreach ($brokersLeft as $brokerLeft) {?> | ||
| 498 | |||
| 499 | <option value="<?php echo $brokerLeft['broker_id']; ?>"><?php echo $brokerLeft['name']; ?></option> | ||
| 500 | <?php }?> | ||
| 501 | |||
| 502 | </select> | ||
| 503 | <td> | ||
| 504 | |||
| 505 | </tr> | ||
| 506 | |||
| 507 | </fieldset> | ||
| 508 | </form> | ||
| 509 | |||
| 510 | </td> | ||
| 511 | </tr> | ||
| 512 | |||
| 513 | </table> | ||
| 514 | <script> | ||
| 515 | jQuery(document).ready( | ||
| 516 | function($) { | ||
| 517 | |||
| 518 | $('#btn-add').click( | ||
| 519 | function() { | ||
| 520 | $('#select-from option:selected').each( | ||
| 521 | function() { | ||
| 522 | $('#select-to').append("<option selected='selected' value='" + $(this).val() + "'>" + $(this).text() + "</option>"); | ||
| 523 | $(this).remove(); | ||
| 524 | } | ||
| 525 | ); | ||
| 526 | } | ||
| 527 | ); | ||
| 528 | $('#btn-remove').click( | ||
| 529 | function() { | ||
| 530 | $('#select-to option:selected').each( | ||
| 531 | function() { | ||
| 532 | $('#select-from').append("<option value='" + $(this).val() + "'>" + $(this).text() + "</option>"); | ||
| 533 | $(this).remove(); | ||
| 534 | } | ||
| 535 | ); | ||
| 536 | } | ||
| 537 | ); | ||
| 538 | |||
| 539 | $(document).on( | ||
| 540 | 'submit', '#your-profile', | ||
| 541 | function() { | ||
| 542 | $('#select-to option').each( | ||
| 543 | function() { | ||
| 544 | $(this).attr("selected", 1); | ||
| 545 | } | ||
| 546 | ); | ||
| 547 | } | ||
| 548 | ); | ||
| 549 | |||
| 550 | } | ||
| 551 | ); | ||
| 552 | </script> | ||
| 553 | |||
| 554 | <?php } | ||
| 555 | } | ||
| 556 | |||
| 557 | add_action('personal_options_update', 'my_save_extra_profile_fields'); | ||
| 558 | add_action('edit_user_profile_update', 'my_save_extra_profile_fields'); | ||
| 559 | |||
| 560 | function my_save_extra_profile_fields() | ||
| 561 | { | ||
| 562 | |||
| 563 | global $wpdb; | ||
| 564 | global $user_id; | ||
| 565 | |||
| 566 | $wpdb->delete( | ||
| 567 | 'wp_broker_staff', | ||
| 568 | array('staff_id' => $user_id) | ||
| 569 | ); | ||
| 570 | |||
| 571 | foreach ($_POST['brokerselected'] as $brokerselected) { | ||
| 572 | //error_log($brokerselected); | ||
| 573 | |||
| 574 | $wpdb->insert( | ||
| 575 | 'wp_broker_staff', | ||
| 576 | array( | ||
| 577 | 'staff_id' => $user_id, | ||
| 578 | 'broker_id' => $brokerselected, | ||
| 579 | ) | ||
| 580 | ); | ||
| 581 | } | ||
| 582 | } |
| ... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
| 10 | <div id="container"> | 10 | <div id="container"> |
| 11 | <?php if (is_user_logged_in()): | 11 | <?php if (is_user_logged_in()): |
| 12 | ?> | 12 | ?> |
| 13 | <script>window.location.replace("<?php echo site_url('/broker-landing-page'); ?>");</script> | 13 | <script>window.location.replace("<?php echo site_url(); ?>");</script> |
| 14 | <?php global $current_user; | 14 | <?php global $current_user; |
| 15 | get_currentuserinfo(); | 15 | get_currentuserinfo(); |
| 16 | ?> | 16 | ?> |
| ... | @@ -50,7 +50,7 @@ if ($children) {?> | ... | @@ -50,7 +50,7 @@ if ($children) {?> |
| 50 | <p><a href="<?php echo wp_logout_url(home_url()); ?>" title="Logout">>> Member Logout</a></p> | 50 | <p><a href="<?php echo wp_logout_url(home_url()); ?>" title="Logout">>> Member Logout</a></p> |
| 51 | <?php else: ?> | 51 | <?php else: ?> |
| 52 | <h2>Broker Login</h2> | 52 | <h2>Broker Login</h2> |
| 53 | <?php $args = array('redirect' => site_url('/broker-landing-page')); | 53 | <?php $args = array('redirect' => site_url()); |
| 54 | 54 | ||
| 55 | if (isset($_GET['action'])): ?> | 55 | if (isset($_GET['action'])): ?> |
| 56 | <div class="success"> | 56 | <div class="success"> | ... | ... |
-
Please register or sign in to post a comment