<?php
/*
 * dani - irontect
* */
    require_once ('../../../../../wp-load.php');
    global $bp, $wpdb;
    
    ob_end_clean();
    ob_clean();
    $invitedSend = $wpdb->get_row('select * from wp_jet_events_members where event_id = "' . $_POST['eventId'] . '" and user_id = "' . $_POST['idInvited'] . '"');
    
    if (!$invitedSend) {
        
        $defaults = array(
                        'user_id'       => $_POST['idInvited'],
                        'event_id'      => $_POST['eventId'],
                        'inviter_id'    => $bp->loggedin_user->id,
                        'date_modified' => gmdate( "Y-m-d H:i:s" ),
                        'is_confirmed'  => 0,
                        'is_confirmed'  => 0
        );
        
        $args = wp_parse_args( $args, $defaults );
        extract( $args, EXTR_SKIP );
        
        $notifications = array(
                        'user_id'           => $_POST['idInvited'],
                        'item_id'           => $_POST['eventId'],
                        'component_name'    => 'jes_events',
                        'secondary_item_id' => '0',
                        'component_action'  => 'jes_event_invite',
                        'date_notified'     => date('Y-m-d H:i:s'),
                        'is_new'            => '1'
        );
        
        $wpdb->insert( 'wp_bp_notifications' , $notifications );
        add_user_meta( $_POST['idInvited'], 'notification_events_invite', 'yes');
        
        if ( !$user_id || !$event_id )
            return false;
            
        if ( !events_is_user_member( $user_id, $event_id ) && !events_check_user_has_invite( $user_id, $event_id ) ) {
            
            $invite                = new JES_Events_Member;
            $invite->event_id      = $event_id;
            $invite->user_id       = $user_id;
            $invite->date_modified = $date_modified;
            $invite->inviter_id    = $inviter_id;
            $invite->is_confirmed  = $is_confirmed;
            $invite->invite_sent   = '1';
            
            if ( !$invite->save() )
                return false;
            
            do_action( 'events_invite_user', $args );
        }
        
        return true;
    
    }
?>