コード例 #1
0
 /**
  * run all 
  */
 function run($recurrence = 'daily')
 {
     // loop
     foreach ($this->schedules[$recurrence] as $callback) {
         // event_callback
         $event_callback = $recurrence . '_' . $callback;
         // daily_[callback]
         // trigger
         if (method_exists($this, $event_callback)) {
             // run
             call_user_func(array($this, $event_callback));
             // log executed
             $current_date = mgm_get_current_datetime('Y-m-d H:i:s');
             // with time part #1023 issue
             // last run set in events
             $this->events[$recurrence][$callback] = $current_date['timestamp'];
         }
     }
     // update option
     $this->save();
 }
コード例 #2
0
 function get_earnings($date_start, $date_end, $member_type)
 {
     // global
     global $wpdb;
     $data = array();
     $curr_date = mgm_get_current_datetime();
     $current_date = $curr_date['timestamp'];
     // preparing query based on dates
     if (!empty($date_start) && !empty($date_end)) {
         /*			$date_end=str_replace('/','-',$date_end);
         			$end_date  = date('Y-m-d', strtotime( $date_end));
         			
         			$date_start=str_replace('/','-',$date_start);	
         			$start_date  = date('Y-m-d',  strtotime( $date_start));	
         */
         //issue #1311
         $sformat = mgm_get_date_format('date_format_short');
         $start_date = mgm_format_inputdate_to_mysql($date_start, $sformat);
         $end_date = mgm_format_inputdate_to_mysql($date_end, $sformat);
         $start_date .= ' 00:00:00';
         $end_date .= ' 23:59:59';
         //Issue #733
         //$condition =" WHERE transaction_dt BETWEEN  '$start_date' AND  '$end_date'";
         $condition = " AND status_text = 'Last payment was successful' AND transaction_dt BETWEEN  '{$start_date}' AND  '{$end_date}'";
     } else {
         //setting the default end date
         if (empty($date_end)) {
             $date_end = $end_date = date('Y-m-d', $current_date);
             $end_date .= ' 23:59:59';
         }
         //setting the default start date
         if (empty($date_start)) {
             $date_start = $start_date = date('Y-m-d', strtotime("{$end_date} - 3 months"));
             $start_date .= ' 00:00:00';
         }
         //$condition =" WHERE transaction_dt BETWEEN  '$start_date' AND  '$end_date'";
         $condition = " AND status_text = 'Last payment was successful' AND transaction_dt BETWEEN  '{$start_date}' AND  '{$end_date}'";
         //Issue #733
         //$condition =" ORDER BY  `transaction_dt` DESC LIMIT 10";
         //$condition = " AND status_text = 'Last payment was successful' ORDER BY  `transaction_dt` DESC LIMIT 10";
     }
     // sql
     $sql = "SELECT * FROM `" . TBL_MGM_TRANSACTION . "` WHERE 1 {$condition}";
     // mgm_log($sql);
     // row
     $rows = $wpdb->get_results($sql);
     // reset data
     $subscription = array();
     $purchase = array();
     $d = array();
     // looping the results
     foreach ($rows as $row) {
         $row->data = json_decode($row->data, true);
         extract($row->data);
         // Storing subscription data to array
         if (trim($row->payment_type) == 'subscription_purchase') {
             $dt = strtok($row->transaction_dt, " ");
             if (isset($subscription[$dt])) {
                 if ($membership_type == $member_type || $member_type == 'all') {
                     $subscription[$dt]['date'] = $dt;
                     //issue #1311
                     if ($trial_on) {
                         $subscription[$dt]['cost'] += $trial_cost;
                     } else {
                         $subscription[$dt]['cost'] += $cost;
                     }
                     //$subscription[$dt]['cost'] +=$cost;
                     $subscription[$dt]['count']++;
                 }
             } else {
                 if ($membership_type == $member_type || $member_type == 'all') {
                     $d[] = $dt;
                     $subscription[$dt]['date'] = $dt;
                     //issue #1311
                     if ($trial_on) {
                         $subscription[$dt]['cost'] += $trial_cost;
                     } else {
                         $subscription[$dt]['cost'] += $cost;
                     }
                     //$subscription[$dt]['cost'] =$cost;
                     $subscription[$dt]['count'] = 1;
                 }
             }
         }
         // Storing pay per post data to array
         if (trim($row->payment_type) == 'post_purchase') {
             $dt = strtok($row->transaction_dt, " ");
             if (isset($purchase[$dt])) {
                 // validating membership type
                 if ($membership_type == $member_type || $member_type == 'all') {
                     $purchase[$dt]['date'] = $dt;
                     $purchase[$dt]['cost'] += $cost;
                     $purchase[$dt]['count']++;
                 }
             } else {
                 // validating membership type
                 if ($membership_type == $member_type || $member_type == 'all') {
                     $d[] = $dt;
                     $purchase[$dt]['date'] = $dt;
                     $purchase[$dt]['cost'] = $cost;
                     $purchase[$dt]['count'] = 1;
                 }
             }
         }
     }
     //getting recurring earnings and dates
     $recurring_data = $this->recurring_earnings($date_start, $date_end, $member_type);
     $d = array_unique($d);
     $md = array_merge($d, $recurring_data['dates']);
     $d = array_unique($md);
     sort($d);
     $recurring = $recurring_data['recurring'];
     $dcount = count($d);
     $data[0]['date_start'] = $date_start;
     $data[0]['date_end'] = $date_end;
     $data[0]['member_type'] = $member_type;
     // Migrating the pay per post,recurring and subscription data to array
     for ($i = 0; $i < $dcount; $i++) {
         $udt = $d[$i];
         if (!empty($udt)) {
             $data[$i]['date'] = $udt;
             if (array_key_exists($udt, $purchase)) {
                 $data[$i]['purchase'] = $purchase[$udt]['cost'];
             } else {
                 $data[$i]['purchase'] = 0;
             }
             if (array_key_exists($udt, $subscription)) {
                 $data[$i]['subscription'] = $subscription[$udt]['cost'];
             } else {
                 $data[$i]['subscription'] = 0;
             }
             if (isset($recurring) && array_key_exists($udt, $recurring)) {
                 $data[$i]['recurring'] = $recurring[$udt]['cost'];
             } else {
                 $data[$i]['recurring'] = 0;
             }
         }
     }
     return $data;
 }
コード例 #3
0
 function purchase_export()
 {
     global $wpdb;
     // data
     $data = array();
     // filter
     $sql_filter = $data['search_field_name'] = $data['search_field_value'] = '';
     $search_field_name = mgm_post_var('search_field_name');
     // check
     if (!empty($search_field_name)) {
         // post
         $search_field_value = mgm_post_var('search_field_value');
         $search_field_value_two = mgm_post_var('search_field_value_two');
         // view data
         $data['search_field_name'] = $search_field_name;
         // for display
         //issue #1281
         $data['search_field_value'] = htmlentities($search_field_value, ENT_QUOTES, "UTF-8");
         // for display
         $data['search_field_value_two'] = htmlentities($search_field_value_two, ENT_QUOTES, "UTF-8");
         // for display
         //searc value
         $search_field_value = esc_sql($search_field_value);
         // for sql
         // end date value
         $search_field_value_two = esc_sql($search_field_value_two);
         // for sql
         //current date
         $curr_date = mgm_get_current_datetime();
         $current_date = $curr_date['timestamp'];
         // by field
         switch ($search_field_name) {
             case 'user_login':
                 $sql_filter = " AND (`user_login` LIKE '%{$search_field_value}%')";
                 break;
             case 'addon_option':
                 $sql_filter = " AND (`option` LIKE '%{$search_field_value}%')";
                 break;
             case 'purchase_dt':
                 // date start
                 if (empty($search_field_value)) {
                     $search_field_value = date('Y-m-d', $current_date);
                 }
                 // date end
                 if (empty($search_field_value_two)) {
                     $search_field_value_two = date('Y-m-d', $current_date);
                 }
                 // convert
                 $search_field_value = mgm_format_inputdate_to_mysql($search_field_value);
                 $search_field_value_two = mgm_format_inputdate_to_mysql($search_field_value_two);
                 // set
                 $sql_filter = " AND (DATE_FORMAT(`purchase_dt`,'%Y-%m-%d') BETWEEN '{$search_field_value}' AND '{$search_field_value_two}')";
                 break;
         }
     }
     // order
     $sql_order = " ORDER BY `user_login`, `purchase_dt`";
     // sql
     $sql = "SELECT SQL_CALC_FOUND_ROWS A.id, A.purchase_dt, B.option AS addon_option, C.user_login\r\r\n\t\t        FROM `" . TBL_MGM_ADDON_PURCHASES . "` A \r\r\n\t\t\t\tLEFT JOIN " . TBL_MGM_ADDON_OPTION . " B ON (B.id = A.addon_option_id) \r\r\n\t\t\t\tLEFT JOIN " . $wpdb->users . " C ON (C.ID = A.user_id) WHERE 1 \r\r\n\t\t\t\t{$sql_filter} {$sql_order} ";
     // store
     $data['addon_purchases'] = $wpdb->get_results($sql);
     // date format
     $date_format = mgm_get_date_format('date_format');
     // init
     $purchases = array();
     // check
     if (count($data['addon_purchases']) > 0) {
         //purchases
         foreach ($data['addon_purchases'] as $purchase) {
             // int
             $row = new stdClass();
             // export fields
             $row->username = $purchase->user_login;
             $row->addon_option = $purchase->addon_option;
             $row->purchase_date = date($date_format, strtotime($purchase->purchase_dt));
             // cache
             $purchases[] = $row;
             // unset
             unset($row);
         }
     }
     // default response
     $response = array('status' => 'error', 'message' => __('Error while exporting addon purchases.', 'mgm'));
     // check
     if (count($purchases) > 0) {
         // success
         $success = count($purchases);
         // create
         if (mgm_post_var('export_format') == 'csv') {
             $filename = mgm_create_csv_file($purchases, 'addon_purchases');
         } else {
             $filename = mgm_create_xls_file($purchases, 'addon_purchases');
         }
         // src
         $file_src = MGM_FILES_EXPORT_URL . $filename;
         // message
         $message = sprintf(__('Successfully exported %d addon %s.', 'mgm'), $success, $success > 1 ? 'purchases' : 'purchase');
         // init
         $response = array('status' => 'success', 'message' => $message, 'src' => $file_src);
     }
     // return response
     echo json_encode($response);
     exit;
 }
コード例 #4
0
/**
 * fetch users for rebill check
 * 
 * @param string $act (fetch | update )
 * @param int $offset
 * @return void
 * @since 2.7 
 * @deprecated marked for history
 */
function mgm_get_users_for_rebill_status_check($act = 'fetch', $offset = NULL)
{
    global $wpdb;
    // date again
    $current_date = mgm_get_current_datetime('Y-m-d H:i:s');
    // with time part #1023 issue
    // get option
    $cron_record = get_option('mgm_cron_record');
    // check
    if (!isset($cron_record['run_date'])) {
        $cron_record = array('run_date' => date('Y-m-d', $current_date['timestamp']), 'rebill_status_check' => array('user_offset' => 0));
    } elseif (!isset($cron_record['rebill_status_check']['user_offset'])) {
        $cron_record['rebill_status_check'] = array('user_offset' => 0);
    }
    // act
    switch ($act) {
        case 'fetch':
            // user_offset
            $user_offset = (int) $cron_record['rebill_status_check']['user_offset'];
            // sql
            $sql_str = "SELECT ID,user_email,display_name FROM `{$wpdb->users}` WHERE ID <> 1 ORDER BY ID LIMIT %d, 50";
            // get 50 users
            $users = $wpdb->get_results(sprintf($sql_str, $user_offset));
            // check users count
            if (count($users) == 0) {
                // reset and refect
                $user_offset = 0;
                // get 50 users
                $users = $wpdb->get_results(sprintf($sql_str, $user_offset));
            }
            // init
            $a_users = array();
            // check
            if ($users) {
                // loop
                foreach ($users as $user) {
                    // skip admin
                    if (is_super_admin($user->ID)) {
                        continue;
                    }
                    // set
                    $a_users[] = $user;
                }
            }
            return $a_users;
            break;
        case 'update':
            // set
            if ($offset) {
                $cron_record['run_date'] = date('Y-m-d', $current_date['timestamp']);
                $cron_record['rebill_status_check']['user_offset'] = (int) $cron_record['rebill_status_check']['user_offset'] + $offset;
                // update
                update_option('mgm_cron_record', $cron_record);
            }
            break;
    }
}
コード例 #5
0
/**
 * generate members list - short code content
 */
function mgm_generate_member_list($args = array())
{
    global $wpdb, $post;
    //issue #1327
    $show_level = isset($args['show_level']) ? $args['show_level'] : null;
    $show_level_members = array();
    if (!empty($show_level) && $show_level != null) {
        $show_level = explode(',', $show_level);
        $show_level_count = count($show_level);
        for ($i = 0; $i < $show_level_count; $i++) {
            $level_match_members = mgm_get_members_with('membership_type', $show_level[$i]);
            if (!empty($level_match_members)) {
                $show_level_members = array_merge($show_level_members, $level_match_members);
            }
        }
        if (!empty($show_level_members)) {
            $show_level_members = array_unique($show_level_members);
        }
    }
    // current url
    $current_url = get_permalink($post->ID);
    // append ? why?
    // if( !strpos($current_url,'?') !== false) $current_url = ($current_url . '?');
    // echo $current_url;
    // init pager
    $pager = new mgm_pager();
    // init data
    $data = $custom_search_fields = $custom_sort_fields = $custom_user_list = $user_list = array();
    // css group
    $css_group = mgm_get_css_group();
    // html
    $html = '';
    // check
    if ($css_group != 'none') {
        // expand this if needed
        $css_link_format = '<link rel="stylesheet" href="%s" type="text/css" media="all" />';
        $css_file = MGM_ASSETS_URL . 'css/' . $css_group . '/mgm.pages.css';
        $html .= sprintf($css_link_format, $css_file);
    }
    // search fields
    $data['search_fields'] = array('' => __('Select', 'mgm'), 'username' => __('Username', 'mgm'), 'id' => __('User ID', 'mgm'), 'email' => __('User Email', 'mgm'), 'first_name' => __('First Name', 'mgm'), 'last_name' => __('Last Name', 'mgm'), 'membership_type' => __('Membership Type', 'mgm'), 'reg_date' => __('Registration Date', 'mgm'), 'last_payment' => __('Last Payment', 'mgm'), 'expire_date' => __('Expiration Date', 'mgm'), 'fee' => __('Fee', 'mgm'), 'status' => __('Status', 'mgm'));
    // sort fields
    $data['sort_fields'] = array('id' => __('User ID', 'mgm'), 'username' => __('Username', 'mgm'), 'email' => __('User Email', 'mgm'), 'reg_date' => __('Registration Date', 'mgm'));
    // order fields
    $data['order_fields'] = array('desc' => __('DESC', 'mgm'), 'asc' => __('ASC', 'mgm'));
    // custom_fields
    $custom_fields = mgm_get_class('member_custom_fields');
    // getting custom fileds and skip the search fields if allready exists.
    foreach ($custom_fields->custom_fields as $custom_field) {
        if (!array_key_exists($custom_field['name'], $data['search_fields'])) {
            $custom_search_fields[$custom_field['name']] = $custom_field['label'];
        }
    }
    // getting custom fileds and skip the sort fields if allready exists.
    foreach ($custom_fields->custom_fields as $custom_field) {
        if (!array_key_exists($custom_field['name'], $data['sort_fields'])) {
            if ($custom_field['name'] != 'status') {
                $custom_sort_fields[$custom_field['name']] = $custom_field['label'];
            }
        }
    }
    // filter
    $sql_filter = $data['search_field_name'] = $data['search_field_value'] = '';
    // field value
    if (isset($_REQUEST['query'])) {
        $search_field_value = $_REQUEST['query'];
    } else {
        $search_field_value = '';
    }
    // field name
    if (isset($_REQUEST['by'])) {
        $search_field_name = $_REQUEST['by'];
    } else {
        $search_field_name = '';
    }
    // sort field
    if (isset($_REQUEST['sort_field'])) {
        $sort_field_name = $_REQUEST['sort_field'];
    } else {
        $sort_field_name = '';
    }
    // sort order type //order_type
    if (isset($_REQUEST['sort_order'])) {
        $sort_order_type = $_REQUEST['sort_order'];
    } else {
        $sort_order_type = '';
    }
    // members
    $active_members = mgm_get_members_with('status', MGM_STATUS_ACTIVE);
    // wrongly called,use constant
    // check
    if (!empty($search_field_name)) {
        // clean
        $search_field_value = mgm_escape($search_field_value);
        // for sql
        $search_field_name = mgm_escape($search_field_name);
        // for sql
        // view data
        $data['search_field_name'] = $search_field_name;
        $data['search_field_value'] = trim($search_field_value);
        // current date
        $curr_date = mgm_get_current_datetime();
        $current_date = $curr_date['timestamp'];
        // check
        if (array_key_exists($search_field_name, $custom_search_fields)) {
            // members
            $members = mgm_get_members_with_customfiled($search_field_name, $search_field_value);
            //issue #1327
            if (!empty($show_level_members)) {
                $members = array_intersect($show_level_members, $members);
            }
            //check
            $members_in = count($members) == 0 ? 0 : implode(',', $members);
            // set filter
            $sql_filter = " AND `ID` IN ({$members_in})";
        } else {
            // by field
            switch ($search_field_name) {
                case 'username':
                    // issue#: 347(LIKE SEARCH)
                    $filter = " AND `user_login` LIKE '%{$search_field_value}%'";
                    // matched
                    $matched_members = mgm_get_members_with_sql_filter($filter);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                case 'id':
                    // filter
                    $filter = " AND `ID` = '" . (int) $search_field_value . "'";
                    // match
                    $matched_members = mgm_get_members_with_sql_filter($filter);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                case 'email':
                    // issue#: 347(LIKE SEARCH)
                    $filter = " AND `user_email` LIKE '%{$search_field_value}%'";
                    // match
                    $matched_members = mgm_get_members_with_sql_filter($filter);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                case 'membership_type':
                    // match
                    $matched_members = mgm_get_members_with('membership_type', $search_field_value);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                case 'reg_date':
                    // check
                    if (empty($search_field_value)) {
                        $search_field_value = date('Y-m-d', $current_date);
                    }
                    // convert
                    $search_field_value = mgm_format_inputdate_to_mysql($search_field_value);
                    // set filter
                    $filter = " AND DATE_FORMAT(`user_registered`,'%Y-%m-%d') = '{$search_field_value}'";
                    // match
                    $matched_members = mgm_get_members_with_sql_filter($filter);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                case 'last_payment':
                    // check
                    if (empty($search_field_value)) {
                        $search_field_value = date('Y-m-d', $current_date);
                    }
                    // convert
                    $search_field_value = mgm_format_inputdate_to_mysql($search_field_value);
                    // match
                    $matched_members = mgm_get_members_with('last_pay_date', $search_field_value);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                case 'expire_date':
                    // check
                    if (empty($search_field_value)) {
                        $search_field_value = date('Y-m-d', $current_date);
                    }
                    // convert
                    $search_field_value = mgm_format_inputdate_to_mysql($search_field_value);
                    // match
                    $matched_members = mgm_get_members_with('expire_date', $search_field_value);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                case 'fee':
                    // match
                    $matched_members = mgm_get_members_with('amount', $search_field_value);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                    /*				
                    case 'status':
                    	// members
                    	$members    = mgm_get_members_with('status', $search_field_value);
                    	// check
                    	$members_in = (count($members)==0) ? 0 : (implode(',', $members));
                    	// set filter
                    	$sql_filter = " AND `ID` IN ({$members_in})";
                    break;
                    */
                /*				
                case 'status':
                	// members
                	$members    = mgm_get_members_with('status', $search_field_value);
                	// check
                	$members_in = (count($members)==0) ? 0 : (implode(',', $members));
                	// set filter
                	$sql_filter = " AND `ID` IN ({$members_in})";
                break;
                */
                case 'first_name':
                case 'last_name':
                    // members
                    $matched_members = mgm_get_members_with($search_field_name, $search_field_value);
                    //issue #1327
                    if (!empty($show_level_members)) {
                        $matched_members = array_intersect($show_level_members, $matched_members);
                    }
                    // common
                    $members = array_intersect($active_members, $matched_members);
                    // check
                    $members_in = count($members) == 0 ? 0 : implode(',', $members);
                    // set filter
                    $sql_filter = " AND `ID` IN ({$members_in})";
                    break;
            }
        }
    }
    // filters via shortcode args
    $use_field = isset($args['use_field']) ? $args['use_field'] : null;
    $use_filter = isset($args['use_filter']) ? $args['use_filter'] : '';
    $sort_by = isset($args['sort_by']) ? $args['sort_by'] : null;
    $sort_type = isset($args['sort_type']) ? $args['sort_type'] : null;
    // use shortcode field
    if (!empty($use_field)) {
        $use_field = explode(',', $use_field);
    }
    // use shortcode flter
    if (!empty($use_filter)) {
        $use_filter = explode(',', $use_filter);
    }
    // use shortcode sort
    if (!empty($sort_by)) {
        $sort_by = explode(',', $sort_by);
    }
    // use shortcode sort order
    if (!empty($sort_type)) {
        $sort_type = explode(',', $sort_type);
    }
    //setting up the default list fiedls
    if (empty($use_field)) {
        $use_field = array('image', 'first_name', 'last_name', 'email');
    }
    // check length
    $use_field_len = count($use_field);
    //getting user fillter options from short code.
    $arr_filter_search = array();
    if (!empty($use_filter)) {
        $use_filter_len = count($use_filter);
        for ($k = 0; $k < $use_filter_len; $k++) {
            if (array_key_exists($use_filter[$k], $data['search_fields'])) {
                $arr_filter_search[$use_filter[$k]] = $data['search_fields'][$use_filter[$k]];
            } elseif (array_key_exists($use_filter[$k], $custom_search_fields)) {
                $arr_filter_search[$use_filter[$k]] = $custom_search_fields[$use_filter[$k]];
            }
        }
        $data['search_fields'] = $arr_filter_search;
    }
    //getting sort by options from short code.
    $arr_sort_search = array();
    if (!empty($sort_by)) {
        $use_sort_len = count($sort_by);
        for ($k = 0; $k < $use_sort_len; $k++) {
            if (array_key_exists($sort_by[$k], $data['sort_fields'])) {
                $arr_sort_search[$sort_by[$k]] = $data['sort_fields'][$sort_by[$k]];
            } elseif (array_key_exists($sort_by[$k], $custom_sort_fields)) {
                $arr_sort_search[$sort_by[$k]] = $custom_sort_fields[$sort_by[$k]];
            }
        }
        $data['sort_fields'] = $arr_sort_search;
    }
    //getting sort type options from short code.
    $arr_sort_type = array();
    if (!empty($sort_type)) {
        $use_sort_type_len = count($sort_by);
        for ($k = 0; $k < $use_sort_type_len; $k++) {
            if (array_key_exists($sort_type[$k], $data['order_fields'])) {
                $arr_sort_type[$sort_type[$k]] = $data['order_fields'][$sort_type[$k]];
            }
        }
        $data['order_fields'] = $arr_sort_type;
    }
    //issue #1301
    //setting default sort order field as sort fields first value
    if (empty($sort_field_name)) {
        $sort_field_name = array_shift(array_keys($data['sort_fields']));
    }
    //setting default sort order type as sort order fields first value
    if (empty($sort_order_type)) {
        $sort_order_type = array_shift(array_keys($data['order_fields']));
    }
    //setting page limit
    $page_limit = isset($args['page_limit']) ? (int) $args['page_limit'] : 20;
    // page limit
    $data['page_limit'] = isset($_REQUEST['page_limit']) ? (int) $_REQUEST['page_limit'] : $page_limit;
    // page no
    $data['page_no'] = isset($_REQUEST['page_no']) ? (int) $_REQUEST['page_no'] : 1;
    // limit
    $sql_limit = $pager->get_query_limit($data['page_limit']);
    // order
    $sql_order = $data['sort_field'] = $data['sort_type'] = '';
    // sort
    $sort_field_name = mgm_escape($sort_field_name);
    // for sql
    $sort_order_type = mgm_escape($sort_order_type);
    // for sql
    // check
    if (isset($sort_field_name)) {
        // set
        $data['sort_field'] = $sort_field_name;
        $data['sort_type'] = $sort_order_type;
        // init
        $custom_sort = false;
        // check
        if (array_key_exists($sort_field_name, $custom_sort_fields)) {
            $show_level_member = array_intersect($active_members, $show_level_members);
            // members
            $sql_order_by = mgm_userlist_customfield_sort($sort_field_name, $sort_order_type, $sql_filter, $show_level_member);
            // limit
            $lim = str_replace('LIMIT', '', $sql_limit);
            $lim = explode(',', $lim);
            // init
            $temp_array = array();
            // loop
            for ($i = trim($lim[0]); $i < $lim[0] + $lim[1]; $i++) {
                if (!empty($sql_order_by[$i])) {
                    $temp_array[] = $sql_order_by[$i];
                }
            }
            //check for active members
            //$temp_array = array_intersect ($active_members,$temp_array);
            $in_order = count($temp_array) == 0 ? 0 : implode(',', $temp_array);
            // order
            //$in_order = implode(',',$temp_array);
            if (!empty($temp_array)) {
                // set
                $sql_order = " ORDER BY FIELD( ID, {$in_order} ) ";
            } else {
                $sql_order = '';
            }
            // sql
            $sql = "SELECT * FROM `{$wpdb->users}` WHERE ID != 1 AND `ID` IN ({$in_order}) {$sql_order}";
            //  list
            $custom_user_list = $wpdb->get_results($sql);
            // flag
            $custom_sort = true;
        } else {
            // by name
            switch ($sort_field_name) {
                case 'username':
                    $sql_order_by = "user_login";
                    break;
                case 'id':
                    $sql_order_by = "ID";
                    break;
                case 'email':
                    $sql_order_by = "user_email";
                    break;
                case 'membership_type':
                    break;
                case 'reg_date':
                    $sql_order_by = "user_registered";
                    break;
            }
            // set
            if (isset($sql_order_by)) {
                $sql_order = " ORDER BY {$sql_order_by} {$sort_order_type}";
            }
        }
    }
    // default
    if (!isset($sql_order_by)) {
        $sql_order = " ORDER BY ID desc";
    }
    //default active members ids
    if (empty($sql_filter)) {
        //issue #1327
        if (!empty($show_level_members)) {
            // common
            $members = array_intersect($active_members, $show_level_members);
            $members_in = count($members) == 0 ? 0 : implode(',', $members);
        } else {
            $members_in = count($active_members) == 0 ? 0 : implode(',', $active_members);
        }
        // set filter
        $sql_filter = " AND `ID` IN ({$members_in})";
    }
    // get members
    $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM `{$wpdb->users}` WHERE ID != 1 {$sql_filter} {$sql_order} {$sql_limit}";
    // users
    $user_list = $wpdb->get_results($sql);
    // echo $wpdb->last_query;
    // set
    if ($custom_sort) {
        $data['users'] = $custom_user_list;
    } else {
        $data['users'] = $user_list;
    }
    // page url
    $data['page_url'] = add_query_arg(array('query' => $search_field_value, 'by' => $search_field_name, 'sort_field' => $sort_field_name, 'sort_order' => $sort_order_type), $current_url);
    //$url.'query='.$search_field_value.'&by='.$search_field_name.'&sort_field='.$sort_field_name.'&order_type='.$order_type;
    // get page links
    $data['page_links'] = $pager->get_pager_links($data['page_url']);
    // total pages
    $data['page_count'] = $pager->get_page_count();
    // total rows/results
    $data['row_count'] = $pager->get_row_count();
    //sort by filed
    $sort_field_html = sprintf('<select id="sort_field" name="sort_field" class="width100px">%s</select>', mgm_make_combo_options($data['sort_fields'], $data['sort_field'], MGM_KEY_VALUE));
    //order by asc/desc
    $sort_order_html = sprintf('<select id="sort_order" name="sort_order" class="width100px">%s</select>', mgm_make_combo_options($data['order_fields'], $data['sort_type'], MGM_KEY_VALUE));
    //search by
    $search_by_html = sprintf('<select id="by" name="by" class="width100px">%s</select>', mgm_make_combo_options($data['search_fields'], $data['search_field_name'], MGM_KEY_VALUE));
    //search box
    $html = '<div>
				<form method="get" action="' . $current_url . '">
					<h5>' . __('Search Our Members', 'mgm') . ':</h5>
					<input type="text" id="query" name="query" value="' . $data['search_field_value'] . '" /> 
					' . __('in', 'mgm') . ' ' . $search_by_html . ' ' . __('sort by', 'mgm') . ' ' . $sort_field_html . ' ' . $sort_order_html . '					
					<input class="button" type="submit" id="submit" value="' . __('Submit', 'mgm') . '" />
					<input type="hidden" name="search" id="search" value="search" />
				</form>
			</div>';
    $html .= '<div><table><tr>';
    for ($i = 0; $i < $use_field_len; $i++) {
        $html .= sprintf('<th class="th_div mgm_text_align_left mgm_column_%s" id="mgm_column_%s"><label><b>%s</b></label></th>', $use_field[$i], $use_field[$i], ucwords(str_replace('_', ' ', $use_field[$i])));
    }
    $html .= '</tr>';
    $enable_public_profile = mgm_get_class('system')->get_setting('enable_public_profile');
    if (!empty($data['users'])) {
        foreach ($data['users'] as $user) {
            // user object
            $user = get_userdata($user->ID);
            // mgm member object
            $member = mgm_get_member($user->ID);
            $html .= '<tr>';
            for ($i = 0; $i < $use_field_len; $i++) {
                $app_user_filed = 'user_' . $use_field[$i];
                if (isset($member->custom_fields->{$use_field}[$i]) || isset($user->{$use_field}[$i]) || isset($user->{$app_user_filed}) || $use_field[$i] == 'image') {
                    if ($use_field[$i] == 'image') {
                        //is_multisite,network_home_url
                        $html .= sprintf('<td align="left" valign="top" class="mgm_%s_value">', $use_field[$i]);
                        if (bool_from_yn($enable_public_profile)) {
                            //$profile_url = add_query_arg(array('username'=>$user->user_login), site_url('userprofile'));
                            $profile_url = network_site_url() . '/userprofile/?username='******'<a class="tern_wp_member_gravatar" href="%s">%s</a>', $profile_url, get_avatar($user->ID, 60));
                        } else {
                            $html .= sprintf('<a href="javascript://">%s</a>', get_avatar($user->ID, 60));
                        }
                        $html .= '</td>';
                    } else {
                        //getting data from user object
                        if (isset($user->{$use_field}[$i])) {
                            $member->custom_fields->{$use_field}[$i] = $user->{$use_field}[$i];
                        }
                        //getting data from user object
                        if ($use_field[$i] == 'email') {
                            $member->custom_fields->{$use_field}[$i] = $user->{$app_user_filed};
                        }
                        // val unserialize
                        $val = maybe_unserialize($member->custom_fields->{$use_field}[$i]);
                        // array to string
                        if (is_array($val)) {
                            $val = implode(', ', $val);
                        }
                        // set
                        $html .= sprintf('<td align="left" valign="top" class="mgm_%s_value"><b>%s</b></td>', $use_field[$i], $val);
                    }
                }
            }
            $html .= '</tr>';
        }
    } else {
        $html .= '<tr><td colspan="' . $use_field_len . '" align="center">' . __('No members found', 'mgm') . ' ...! </td></tr>';
    }
    $html .= '</table></div><br/>';
    $html .= '<div class="mgm_page_links_div">';
    if ($data['page_links']) {
        $html .= '<div class="pager-wrap">' . $data['page_links'] . '</div><div class="clearfix"></div>';
    }
    $html .= '</div><br/>';
    //issue #1635
    $users_list_html = '<div class="mgm_user_list_container">' . $html . '</div>';
    return $users_list_html;
}
コード例 #6
0
/**
 * Hook to specifically check rebill status 
 *
 * @param int $user_id
 * @param object $member
 * @return boolean
 */
function mgm_module_rebill_status($user_id, $member = NULL)
{
    // object
    if (!isset($member) && !is_object($member)) {
        $member = mgm_get_member($user_id);
    }
    // return
    $return = false;
    //Give exceptions to check rebill status for express checkout,mgm_authorizenet and epoch modules even AWAITING_CANCEL status also.
    $rebill_module_exceptions = array('mgm_paypalexpresscheckout', 'mgm_epoch', 'mgm_authorizenet');
    // do not process if user is awaiting cancel #1259
    if ($member->status == MGM_STATUS_AWAITING_CANCEL) {
        // before reset date, DO NOT CHECK
        if (time() < strtotime($member->status_reset_on)) {
            return false;
        }
        // excluded modules, DO NOT CHECK, better use $module_obj->is_rebill_status_check_supported()
        if (!empty($member->payment_info->module) && !in_array($member->payment_info->module, $rebill_module_exceptions)) {
            return false;
        }
    }
    // do not run on expire date
    if (isset($member->expire_date) && !empty($member->expire_date)) {
        // current tim
        $c_date = mgm_get_current_datetime('Y-m-d', false, 'date');
        $e_date = date('Y-m-d', strtotime($member->expire_date));
        // mgm_log( 'date run: '. $c_date . ' ' . $e_date, $this->module . '_' . __FUNCTION__);
        // skip
        if ($e_date == $c_date) {
            return false;
        }
    }
    // if not disabled or manual
    if (!isset($member->last_payment_check) || isset($member->last_payment_check) && $member->last_payment_check != 'disabled') {
        // check
        if (!empty($member->payment_info->module) && ($module_obj = mgm_is_valid_module($member->payment_info->module, 'payment', 'object'))) {
            // check is supported
            if ($module_obj->is_rebill_status_check_supported()) {
                // query api, triggered by MGM,
                // module::process_rebill_status() will be triggered via module::process_status_notify() web hook triggered by gateway
                if ($module_obj->query_rebill_status($user_id, $member)) {
                    // return
                    $return = true;
                }
            }
        }
    }
    // nothing
    return $return;
}
コード例 #7
0
 function member_list()
 {
     global $wpdb;
     // system
     $system_obj = mgm_get_class('system');
     // getting super admin ids - issue#1219
     $super_adminids = mgm_get_super_adminids();
     // pager
     $pager = new mgm_pager();
     // data
     $data = array();
     // search fields
     $data['search_fields'] = array('' => __('Select', 'mgm'), 'username' => __('Username', 'mgm'), 'id' => __('User ID', 'mgm'), 'email' => __('User Email', 'mgm'), 'first_name' => __('First Name', 'mgm'), 'last_name' => __('Last Name', 'mgm'), 'membership_type' => __('Membership Type', 'mgm'), 'reg_date' => __('Registration Date', 'mgm'), 'last_payment' => __('Last Payment', 'mgm'), 'expire_date' => __('Expiration Date', 'mgm'), 'join_date' => __('Join Date', 'mgm'), 'fee' => __('Fee', 'mgm'), 'status' => __('Status', 'mgm'), 'transaction_id' => __('Transaction ID', 'mgm'), 'payment_module' => __('Payment Module', 'mgm'), 'pack_id' => __('Pack ID', 'mgm'));
     // sort fields
     $data['sort_fields'] = array('id' => __('User ID', 'mgm'), 'username' => __('Username', 'mgm'), 'email' => __('User Email', 'mgm'), 'reg_date' => __('Registration Date', 'mgm'), 'last_pay_date' => __('Last Pay Date', 'mgm'));
     // filter
     $sql_filter = $data['search_field_name'] = $data['search_field_value'] = '';
     $search_field_name = mgm_post_var('search_field_name');
     //issue #1311
     $sformat = mgm_get_date_format('date_format_short');
     // check
     if (!empty($search_field_name)) {
         // post
         $search_field_value = mgm_post_var('search_field_value');
         $search_field_value_two = mgm_post_var('search_field_value_two');
         // view data
         $data['search_field_name'] = $search_field_name;
         // for display
         //issue #1281
         $data['search_field_value'] = htmlentities($search_field_value, ENT_QUOTES, "UTF-8");
         // for display
         $data['search_field_value_two'] = htmlentities($search_field_value_two, ENT_QUOTES, "UTF-8");
         // for display
         // issue#: 219
         $search_field_value = mgm_escape($search_field_value);
         // for sql
         // end date value
         $search_field_value_two = mgm_escape($search_field_value_two);
         // for sql
         //current date
         $curr_date = mgm_get_current_datetime();
         $current_date = $curr_date['timestamp'];
         // by field
         switch ($search_field_name) {
             case 'username':
                 // issue#: 347(LIKE SEARCH)
                 $sql_filter = " AND `user_login` LIKE '%{$search_field_value}%'";
                 break;
             case 'id':
                 $sql_filter = " AND `ID` = '" . (int) $search_field_value . "'";
                 break;
             case 'email':
                 // issue#: 347(LIKE SEARCH)
                 $sql_filter = " AND `user_email` LIKE '%{$search_field_value}%'";
                 break;
             case 'membership_type':
                 // members
                 $members = mgm_get_members_with('membership_type', $search_field_value);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'reg_date':
                 if (empty($search_field_value)) {
                     $search_field_value = date('Y-m-d', $current_date);
                 }
                 if (empty($search_field_value_two)) {
                     $search_field_value_two = date('Y-m-d', $current_date);
                 }
                 // convert
                 $search_field_value = mgm_format_inputdate_to_mysql($search_field_value, $sformat);
                 $search_field_value_two = mgm_format_inputdate_to_mysql($search_field_value_two, $sformat);
                 // set filter
                 // $sql_filter = " AND DATE_FORMAT(user_registered,'%Y-%m-%d') = '{$search_field_value}'";
                 $sql_filter = " AND DATE_FORMAT(user_registered,'%Y-%m-%d') BETWEEN '{$search_field_value}' AND '{$search_field_value_two}'";
                 // AND transaction_dt BETWEEN  '$start_date' AND  '$end_date'";
                 break;
             case 'last_payment':
                 // date1
                 if (empty($search_field_value)) {
                     $search_field_value = date('Y-m-d', $current_date);
                 }
                 // date2
                 if (empty($search_field_value_two)) {
                     $search_field_value_two = date('Y-m-d', $current_date);
                 }
                 // convert
                 $date_one = mgm_format_inputdate_to_mysql($search_field_value, $sformat);
                 $date_two = mgm_format_inputdate_to_mysql($search_field_value_two, $sformat);
                 // members
                 $members = mgm_get_members_between_two_dates('last_pay_date', $date_one, $date_two);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // convert
                 // $search_field_value = mgm_format_inputdate_to_mysql($search_field_value);
                 // members
                 // $members = mgm_get_members_with('last_pay_date', $search_field_value);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'expire_date':
                 // date1
                 if (empty($search_field_value)) {
                     $search_field_value = date('Y-m-d', $current_date);
                 }
                 // date2
                 if (empty($search_field_value_two)) {
                     $search_field_value_two = date('Y-m-d', $current_date);
                 }
                 // convert
                 $date_one = mgm_format_inputdate_to_mysql($search_field_value, $sformat);
                 $date_two = mgm_format_inputdate_to_mysql($search_field_value_two, $sformat);
                 // members
                 $members = mgm_get_members_between_two_dates('expire_date', $date_one, $date_two);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'join_date':
                 // date1
                 if (empty($search_field_value)) {
                     $search_field_value = date('Y-m-d', $current_date);
                 }
                 // date2
                 if (empty($search_field_value_two)) {
                     $search_field_value_two = date('Y-m-d', $current_date);
                 }
                 // convert
                 $date_one = mgm_format_inputdate_to_mysql($search_field_value, $sformat);
                 $date_two = mgm_format_inputdate_to_mysql($search_field_value_two, $sformat);
                 // members
                 $members = mgm_get_members_between_two_dates('join_date', $date_one, $date_two);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'fee':
                 // members
                 $members = mgm_get_members_with('amount', $search_field_value);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'status':
                 // members
                 $members = mgm_get_members_with('status', $search_field_value);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'first_name':
             case 'last_name':
                 // members
                 $members = mgm_get_members_with($search_field_name, $search_field_value);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 //check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'transaction_id':
                 // members
                 $members = mgm_get_members_with('transaction_id', $search_field_value);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
             case 'payment_module':
                 // members
                 $members = mgm_get_members_with('payment_module', $search_field_value);
                 //super admins check - issue#1219
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 // show nice name
                 $data['search_field_value'] = mgm_get_module($search_field_value)->name;
                 break;
             case 'pack_id':
                 // members
                 $members = mgm_get_members_with('pack_id', $search_field_value);
                 //super admins check
                 $members = array_diff($members, $super_adminids);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND `ID` IN ({$members_in})";
                 break;
         }
     }
     //super admins check - issue#1219
     $super_admin_in = count($super_adminids) == 0 ? 0 : implode(',', $super_adminids);
     // page limit
     $data['page_limit'] = isset($_REQUEST['page_limit']) ? (int) $_REQUEST['page_limit'] : 20;
     // page no
     $data['page_no'] = isset($_REQUEST['page_no']) ? (int) $_REQUEST['page_no'] : 1;
     // limit
     $sql_limit = $pager->get_query_limit($data['page_limit']);
     //init
     $custom_user_list = array();
     $member_custom_sort = false;
     // order
     $sql_order = $data['sort_field'] = $data['sort_type'] = '';
     // sort
     $sort_field_name = mgm_post_var('sort_field_name');
     $sort_type = mgm_post_var('sort_type');
     // check
     if (isset($sort_field_name)) {
         //issue#: 219
         $data['sort_field'] = $sort_field_name;
         $data['sort_type'] = $sort_type;
         // by name
         switch ($sort_field_name) {
             case 'username':
                 $sql_order_by = "user_login";
                 break;
             case 'id':
                 $sql_order_by = "ID";
                 break;
             case 'email':
                 $sql_order_by = "user_email";
                 break;
             case 'membership_type':
                 break;
             case 'reg_date':
                 $sql_order_by = "user_registered";
                 break;
             case 'last_pay_date':
                 $sql_order_by = mgm_member_sort($sort_field_name, $sort_type, $sql_filter, $super_adminids);
                 //mgm_log(mgm_array_dump($sql_order_by,true),__FUNCTION__);
                 // limit
                 $lim = str_replace('LIMIT', '', $sql_limit);
                 $lim = explode(',', $lim);
                 // init
                 $temp_array = array();
                 // loop
                 for ($i = trim($lim[0]); $i < $lim[0] + $lim[1]; $i++) {
                     if (!empty($sql_order_by[$i])) {
                         $temp_array[] = $sql_order_by[$i];
                     }
                 }
                 $in_order = count($temp_array) == 0 ? 0 : implode(',', $temp_array);
                 // order
                 if (!empty($temp_array)) {
                     // set
                     $sql_order = " ORDER BY FIELD( ID, {$in_order} ) ";
                 } else {
                     $sql_order = '';
                 }
                 // sql
                 $sql = "SELECT * FROM `{$wpdb->users}` WHERE ID != 1 AND `ID` IN ({$in_order}) {$sql_order}";
                 //mgm_log($sql,__FUNCTION__);
                 //  list
                 $custom_user_list = $wpdb->get_results($sql);
                 unset($sql_order_by);
                 // flag
                 $member_custom_sort = true;
                 break;
         }
         // set
         if (isset($sql_order_by)) {
             $sql_order = " ORDER BY {$sql_order_by} {$sort_type}";
         }
     }
     // issue #1119
     if (!isset($sql_order_by)) {
         $sql_order = " ORDER BY ID desc";
     }
     // get members
     $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM `{$wpdb->users}` WHERE ID NOT IN ({$super_admin_in}) {$sql_filter} {$sql_order} {$sql_limit}";
     //list
     $user_list = $wpdb->get_results($sql);
     // users
     if ($member_custom_sort) {
         // users
         $data['users'] = $custom_user_list;
     } else {
         // users
         $data['users'] = $user_list;
     }
     // page url
     $data['page_url'] = 'admin-ajax.php?action=mgm_admin_ajax_action&page=mgm/admin/members&method=member_list';
     // get page links
     $data['page_links'] = $pager->get_pager_links($data['page_url']);
     // total pages
     $data['page_count'] = $pager->get_page_count();
     // total rows/results
     $data['row_count'] = $pager->get_row_count();
     // search term
     $search_term = '';
     // search provided
     if (!empty($data['search_field_value'])) {
         if (!empty($data['search_field_value_two'])) {
             $search_term = sprintf('where <b>%s</b> between <b>%s</b> and <b>%s</b> dates', isset($data['search_fields'][$search_field_name]) ? $data['search_fields'][$search_field_name] : '', $data['search_field_value'], $data['search_field_value_two']);
         } else {
             $search_term = sprintf('where <b>%s</b> is <b>%s</b>', isset($data['search_fields'][$search_field_name]) ? $data['search_fields'][$search_field_name] : '', $data['search_field_value']);
         }
     }
     // message
     $data['message'] = sprintf(__('%d %s matched %s', 'mgm'), $data['row_count'], $data['row_count'] > 1 ? 'members' : 'member', $search_term);
     // modules
     $data['payment_modules'] = $system_obj->get_active_modules('payment');
     // load template view
     $this->load->template('members/member/lists', array('data' => $data));
 }
コード例 #8
0
/**
 * generate dashboard widget data
 * 
 * @param void
 * @return array
 * @since 2.7
 */
function mgm_set_dashboard_widget_data()
{
    // obj
    $mtypes_obj = mgm_get_class('membership_types');
    // get membership counts
    $membership_count = mgm_get_membershiptype_users_count();
    // init
    $memberships_c = array();
    // loop through and update $arr_membership with count
    foreach ($mtypes_obj->membership_types as $type_code => $type_name) {
        // store
        $memberships_c[] = array('count' => $membership_count[$type_code], 'name' => mgm_stripslashes_deep($type_name), 'code' => $type_code);
    }
    // Membership count ends
    // Status count starts
    // get status counts
    $statuses = mgm_get_subscription_statuses(true);
    $status_count = mgm_get_subscription_status_users_count($statuses);
    $statuses_c = array();
    // loop
    foreach ($statuses as $status) {
        // store
        $statuses_c[] = array('count' => isset($status_count[$status]) ? $status_count[$status] : 0, 'name' => $status, 'css_class' => mgm_get_status_css_class($status));
    }
    // Current time
    $time = mgm_get_current_datetime('Y-m-d H:i:s');
    // Form data
    return $widget_data = array('membership_count' => $memberships_c, 'status_count' => $statuses_c, 'updated_time' => $time['date']);
}
コード例 #9
0
 function post_purchase_export()
 {
     global $wpdb;
     // data
     $data = array();
     // filter
     $sql_filter = $data['search_field_name'] = $data['search_field_value'] = '';
     $search_field_name = mgm_post_var('search_field_name');
     // check
     if (!empty($search_field_name)) {
         // post
         $search_field_value = mgm_post_var('search_field_value');
         $search_field_value_two = mgm_post_var('search_field_value_two');
         // view data
         $data['search_field_name'] = $search_field_name;
         // for display
         //issue #1281
         $data['search_field_value'] = htmlentities($search_field_value, ENT_QUOTES, "UTF-8");
         // for display
         $data['search_field_value_two'] = htmlentities($search_field_value_two, ENT_QUOTES, "UTF-8");
         // for display
         //searc value
         $search_field_value = esc_sql($search_field_value);
         // for sql
         // end date value
         $search_field_value_two = esc_sql($search_field_value_two);
         // for sql
         //current date
         $curr_date = mgm_get_current_datetime();
         $current_date = $curr_date['timestamp'];
         // by field
         switch ($search_field_name) {
             case 'user_login':
                 $sql_filter = " AND (`user_login` LIKE '%{$search_field_value}%' OR `guest_token` LIKE '%{$search_field_value}%')";
                 break;
             case 'post_title':
                 $sql_filter = " AND (`post_title` LIKE '%{$search_field_value}%')";
                 break;
             case 'is_gift':
                 $sql_filter = " AND (`is_gift` = '{$search_field_value}')";
                 break;
             case 'purchase_dt':
                 // date start
                 if (empty($search_field_value)) {
                     $search_field_value = date('Y-m-d', $current_date);
                 }
                 // date end
                 if (empty($search_field_value_two)) {
                     $search_field_value_two = date('Y-m-d', $current_date);
                 }
                 // convert
                 $search_field_value = mgm_format_inputdate_to_mysql($search_field_value);
                 $search_field_value_two = mgm_format_inputdate_to_mysql($search_field_value_two);
                 // set
                 $sql_filter = " AND (DATE_FORMAT(`pp`.`purchase_dt`,'%Y-%m-%d') BETWEEN '{$search_field_value}' AND '{$search_field_value_two}')";
                 break;
         }
     }
     // order
     $sql_order = " ORDER BY u.user_login, p.post_title";
     // sql
     $sql = "SELECT SQL_CALC_FOUND_ROWS p.ID AS post_id, p.post_title, pp.purchase_dt, \r\r\n\t\t        IF(user_id IS NULL, CONCAT('guest-', guest_token), u.user_login) AS user_login, pp.id,\r\r\n\t\t        pp.is_gift,pp.is_expire FROM `" . TBL_MGM_POST_PURCHASES . "` pp \r\r\n\t\t\t\tLEFT JOIN " . $wpdb->posts . " p ON (p.id = pp.post_id) \r\r\n\t\t\t\tLEFT JOIN " . $wpdb->users . " u ON (u.ID = pp.user_id) WHERE 1 \r\r\n\t\t\t\t{$sql_filter} {$sql_order} ";
     // log
     // mgm_log($sql);
     // store
     $data['post_purchases'] = $wpdb->get_results($sql);
     // date format
     $date_format = mgm_get_date_format('date_format');
     // init
     $purchases = array();
     // check
     if (count($data['post_purchases']) > 0) {
         //purchases
         foreach ($data['post_purchases'] as $purchase) {
             // int
             $row = new stdClass();
             // type
             $type = $purchase->is_gift == 'Y' ? __('Gift', 'mgm') : __('Purchase', 'mgm');
             // check is_expiry
             if ($purchase->is_expire == 'N') {
                 $expiry = __('Indefinite', 'mgm');
             } else {
                 $expiry = mgm_get_post($purchase->post_id)->get_access_duration();
                 $expiry = !$expiry ? __('Indefinite', 'mgm') : date($date_format, 86400 * $expiry + strtotime($purchase->purchase_dt)) . " (" . $expiry . __(' D', 'mgm') . ")";
             }
             // member name
             if (preg_match('/^guest-/', $purchase->user_login)) {
                 // guest token
                 $guest_token = str_replace('guest-', '', $purchase->user_login);
                 // username
                 $username = __('Guest', 'mgm') . sprintf(' (%s)', $guest_token);
             } else {
                 // username
                 $username = $purchase->user_login;
             }
             //export fields
             $row->username = $username;
             $row->post = $purchase->post_title;
             $row->type = $type;
             $row->expire_date = $expiry;
             $row->purchase_or_gift_date = date($date_format, strtotime($purchase->purchase_dt));
             // cache
             $purchases[] = $row;
             // unset
             unset($row);
         }
     }
     // default response
     $response = array('status' => 'error', 'message' => __('Error while exporting post (purchase/gift)s.', 'mgm'));
     // check
     if (count($purchases) > 0) {
         // success
         $success = count($purchases);
         // create
         if (mgm_post_var('export_format') == 'csv') {
             $filename = mgm_create_csv_file($purchases, 'post_purchases');
         } else {
             $filename = mgm_create_xls_file($purchases, 'post_purchases');
         }
         // src
         $file_src = MGM_FILES_EXPORT_URL . $filename;
         // message
         $message = sprintf(__('Successfully exported %d post %s.', 'mgm'), $success, $success > 1 ? 'purchases' : 'purchase');
         // init
         $response = array('status' => 'success', 'message' => $message, 'src' => $file_src);
     }
     // return response
     echo json_encode($response);
     exit;
 }