Exemplo n.º 1
0
/**
 * status widget : multiple instance
 * admin instance
 *
 * @param array $widget_args
 * @return void
 * @since 1.0
 */
function mgm_sidebar_widget_status_admin($widget_args = 1)
{
    global $wp_registered_widgets, $mgm_sidebar_widget;
    static $updated = false;
    if (is_numeric($widget_args)) {
        $widget_args = array('number' => $widget_args);
    }
    $widget_args = wp_parse_args($widget_args, array('number' => -1));
    extract($widget_args, EXTR_SKIP);
    $options = $mgm_sidebar_widget->status_widget;
    if (!is_array($options)) {
        $options = array();
    }
    // sidebar
    $m_sidebar = mgm_post_var('sidebar');
    // update
    if (!$updated && !empty($m_sidebar)) {
        $sidebar = (string) $m_sidebar;
        $sidebars_widgets = wp_get_sidebars_widgets();
        if (isset($sidebars_widgets[$sidebar])) {
            $this_sidebar =& $sidebars_widgets[$sidebar];
        } else {
            $this_sidebar = array();
        }
        foreach ($this_sidebar as $_widget_id) {
            // check
            if (isset($wp_registered_widgets[$_widget_id]['callback']) && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
                if ('mgm_widget_status' == $wp_registered_widgets[$_widget_id]['callback']) {
                    $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
                    if (!in_array("status-{$widget_number}", mgm_post_var('widget-id'))) {
                        // the widget has been removed.
                        unset($options[$widget_number]);
                    }
                }
            }
        }
        foreach ((array) mgm_post_var('mgm_widget_status') as $widget_number => $mgm_widget_status) {
            if (!isset($mgm_widget_status['title']) && isset($options[$widget_number])) {
                // user clicked cancel
                continue;
            }
            // set vars
            $title = isset($mgm_widget_status['title']) ? stripslashes($mgm_widget_status['title']) : '';
            $active_intro = isset($mgm_widget_status['active_intro']) ? stripslashes($mgm_widget_status['active_intro']) : '';
            $inactive_intro = isset($mgm_widget_status['inactive_intro']) ? stripslashes($mgm_widget_status['inactive_intro']) : '';
            $logged_out_intro = isset($mgm_widget_status['logged_out_intro']) ? stripslashes($mgm_widget_status['logged_out_intro']) : '';
            $hide_logged_out = isset($mgm_widget_status['hide_logged_out']) ? (int) $mgm_widget_status['hide_logged_out'] : false;
            // set
            $options[$widget_number] = compact('title', 'active_intro', 'inactive_intro', 'logged_out_intro', 'hide_logged_out');
        }
        $mgm_sidebar_widget->status_widget = $options;
        // update_option('mgm_sidebar_widget', $mgm_sidebar_widget);
        $mgm_sidebar_widget->save();
        // updated
        $updated = true;
    }
    // get selected
    if (-1 == $number) {
        $number = '%i%';
        $title = __('Membership Status', 'mgm');
        $active_intro = trim($mgm_sidebar_widget->default_text['active_intro']);
        $inactive_intro = trim($mgm_sidebar_widget->default_text['inactive_intro']);
        $logged_out_intro = trim($mgm_sidebar_widget->default_text['logged_out_intro']);
        $hide_logged_out = 0;
    } else {
        $title = stripslashes($options[$number]['title']);
        $active_intro = stripslashes($options[$number]['active_intro']);
        $inactive_intro = stripslashes($options[$number]['inactive_intro']);
        $logged_out_intro = stripslashes($options[$number]['logged_out_intro']);
        $hide_logged_out = (int) $options[$number]['hide_logged_out'];
    }
    // html
    $html = '<input type="hidden" name="mgm_sidebar_widget_submit" id="mgm_sidebar_widget_submit" value="1" />
				<p>
				<div class="mgm_margin_bottom_5px">
				<label for="mgm_sidebar_widget_title">
					<div><strong>' . __('Widget Title', 'mgm') . '</strong></div>
					<input class="mgm_width_300px" type="text" value="' . $title . '" id="mgm_widget_status_title_' . $number . '" name="mgm_widget_status[' . $number . '][title]" />
				</label>
				</div>
				<div class="mgm_margin_bottom_5px">
				<label for="mgm_sidebar_widget_active_intro">
					<div><strong>' . __('User Active Introduction', 'mgm') . '</strong> - Use [membership_type] and [expiry_date]</div>
					<textarea rows="6" cols="50" id="mgm_widget_status_active_intro_' . $number . '" name="mgm_widget_status[' . $number . '][active_intro]">' . $active_intro . '</textarea>
				</label>
				</div>
				<div class="mgm_margin_bottom_5px">				
				<label for="mgm_sidebar_widget_inactive_intro">
					<div><strong>' . __('User Inactive Introduction', 'mgm') . '</strong></div>
					<textarea rows="6" cols="50" id="mgm_widget_status_inactive_intro_' . $number . '" name="mgm_widget_status[' . $number . '][inactive_intro]">' . $inactive_intro . '</textarea>
				</label>
				</div>
				<div class="mgm_margin_bottom_5px">				
				<label for="mgm_sidebar_widget_logged_out_intro">
					<div><strong>' . __('User Logged Out Introduction', 'mgm') . '</strong></div>
					<textarea rows="6" cols="50" id="mgm_widget_status_logged_out_intro_' . $number . '" name="mgm_widget_status[' . $number . '][logged_out_intro]">' . $logged_out_intro . '</textarea>
				</label>
				</div>
				<div class="mgm_margin_bottom_5px">				
				<label for="mgm_sidebar_widget_hide_logged_out">
					<div><strong>' . __('Hide widget when user logged out?', 'mgm') . '</strong>
					<input type="checkbox" id="mgm_widget_status_hide_logged_out_' . $number . '" name="mgm_widget_status[' . $number . '][hide_logged_out]" value="1" ' . ($hide_logged_out ? 'checked="checked"' : '') . ' />
				</div>
				</label>
				</div>				
			</p>';
    // print
    print $html;
}
/**
 * register widget : multiple instance
 * admin instance
 *
 * @param array $widget_args
 * @return void
 * @since 1.0
 */
function mgm_sidebar_widget_registration_admin($widget_args = 1)
{
    global $wp_registered_widgets, $mgm_sidebar_widget;
    static $updated = false;
    if (is_numeric($widget_args)) {
        $widget_args = array('number' => $widget_args);
    }
    $widget_args = wp_parse_args($widget_args, array('number' => -1));
    extract($widget_args, EXTR_SKIP);
    // options init
    $options = $mgm_sidebar_widget->register_widget;
    // default
    if (!is_array($options)) {
        $options = array();
    }
    // m_sidebar
    $m_sidebar = mgm_post_var('sidebar');
    // update
    if (!$updated && !empty($m_sidebar)) {
        $sidebar = (string) $m_sidebar;
        $sidebars_widgets = wp_get_sidebars_widgets();
        if (isset($sidebars_widgets[$sidebar])) {
            $this_sidebar =& $sidebars_widgets[$sidebar];
        } else {
            $this_sidebar = array();
        }
        foreach ($this_sidebar as $_widget_id) {
            // check
            if (isset($wp_registered_widgets[$_widget_id]['callback']) && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
                if ('mgm_widget_registration' == $wp_registered_widgets[$_widget_id]['callback']) {
                    $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
                    if (!in_array("registration-{$widget_number}", mgm_post_var('widget-id'))) {
                        // the widget has been removed.
                        unset($options[$widget_number]);
                    }
                }
            }
        }
        // update
        foreach ((array) mgm_post_var('mgm_widget_registration') as $widget_number => $mgm_widget_registration) {
            if (!isset($mgm_widget_registration['title']) && isset($options[$widget_number])) {
                // user clicked cancel
                continue;
            }
            // set vars
            $title = isset($mgm_widget_registration['title']) ? stripslashes($mgm_widget_registration['title']) : '';
            $intro = isset($mgm_widget_registration['intro']) ? stripslashes($mgm_widget_registration['intro']) : '';
            $use_custom_fields = isset($mgm_widget_registration['use_custom_fields']) ? $mgm_widget_registration['use_custom_fields'] : false;
            //Issue #777
            $default_subscription_pack = isset($mgm_widget_registration['default_subscription_pack']) ? $mgm_widget_registration['default_subscription_pack'] : 'free';
            // set
            $options[$widget_number] = compact('title', 'intro', 'use_custom_fields', 'default_subscription_pack');
        }
        // update
        $mgm_sidebar_widget->register_widget = $options;
        // save
        $mgm_sidebar_widget->save();
        // updated
        $updated = true;
    }
    // get selected
    if (-1 == $number) {
        $number = '%i%';
        // convert to js expression
        $js_number = '_i_';
        $title = __('Register', 'mgm');
        $intro = trim($mgm_sidebar_widget->default_text['active_intro']);
        $use_custom_fields = false;
        $default_subscription_pack = 'free';
    } else {
        // convert to js expression
        $js_number = $number;
        $title = stripslashes($options[$number]['title']);
        $intro = stripslashes($options[$number]['intro']);
        $use_custom_fields = $options[$number]['use_custom_fields'];
        $default_subscription_pack = $options[$number]['default_subscription_pack'];
    }
    // Issue #777
    $subscription_pack_list = sprintf('<option value="-">%s</option>', __('Select', 'mgm'));
    foreach ($packages = mgm_get_subscription_packages() as $pack) {
        if ($default_subscription_pack == $pack['key']) {
            $subscription_pack_list .= sprintf('<option selected="selected" value="%s">%s</option>', $pack['key'], $pack['label']);
        } else {
            $subscription_pack_list .= sprintf('<option value="%s">%s</option>', $pack['key'], $pack['label']);
        }
    }
    // generate html
    $html = '<input type="hidden" name="mgm_widget_registration[' . $number . '][submit]" id="mgm_widget_registration_submit_' . $js_number . '" value="1" />
			 <p>
				<div class="mgm_margin_bottom_5px">
					<label for="mgm_register_sidebar_widget_title">
						<div><strong>' . __('Widget Title', 'mgm') . '</strong></div>
						<input class="mgm_width_300px" type="text" name="mgm_widget_registration[' . $number . '][title]" id="mgm_widget_registration_title_' . $js_number . '"  value="' . $title . '"/>
					</label>
				</div>
				<div class="mgm_margin_bottom_5px">
					<label for="mgm_register_sidebar_widget_use_custom_fields">						
						<input class="mgm_width_30px" type="checkbox" ' . ($use_custom_fields ? 'checked="checked"' : '') . ' 
						name="mgm_widget_registration[' . $number . '][use_custom_fields]" id="mgm_widget_registration_use_custom_fields_' . $js_number . '" value="1"/>
						<strong>' . __('Use Custom Fields in form?', 'mgm') . '</strong>
					</label>
				</div>
				<div class="mgm_margin_bottom_5px" id="cusFldDropdown_' . $number . '">
					<label for="mgm_register__widget_default_subscription_pack">						
						<div><strong>' . __('Select default subscription pack ', 'mgm') . '</strong></div>
						<select class="mgm_width_300px" name="mgm_widget_registration[' . $number . '][default_subscription_pack]" 
						id="mgm_widget_registration_default_subscription_pack_' . $js_number . '">' . $subscription_pack_list . '</select>
					</label>
				</div>
				<div class="mgm_margin_bottom_5px">
					<label for="mgm_register_sidebar_widget_active_intro">
						<div><strong>' . __('Introduction', 'mgm') . '</strong></div>
						<textarea rows="6" cols="50" name="mgm_widget_registration[' . $number . '][intro]" id="mgm_widget_registration_intro_' . $js_number . '" >' . $intro . '</textarea>
					</label>
				</div>
			 </p>';
    // script
    $html .= '<script language="javascript">
	jQuery(document).ready(function(){			
		if(jQuery("#mgm_widget_registration_use_custom_fields_' . $js_number . '").val() == 1){
			//issue #1298
			if(jQuery("#mgm_widget_registration_use_custom_fields_' . $js_number . '").is(":checked")){			
				jQuery("#cusFldDropdown_' . $js_number . '").hide();
			}
		}else{
			jQuery("#cusFldDropdown_' . $js_number . '").show();
		}
	
		jQuery("#mgm_widget_registration_use_custom_fields_' . $js_number . '").click(function() {			
			if(this.checked){	
				jQuery("#cusFldDropdown_' . $js_number . '").hide();
				jQuery("#mgm_widget_registration_use_custom_fields_' . $js_number . '").val(1);
			}else{
				jQuery("#cusFldDropdown_' . $js_number . '").show();
				jQuery("#mgm_widget_registration_use_custom_fields_' . $js_number . '").val(1);				  
			}
		});
	});	
	</script>';
    // print
    print $html;
}
Exemplo n.º 3
0
/**
 * text widget : multiple instance
 * admin instance
 *
 * @param array $widget_args
 * @return void
 * @since 1.0
 */
function mgm_sidebar_widget_text_admin($widget_args = 1)
{
    global $wp_registered_widgets, $mgm_sidebar_widget;
    static $updated = false;
    if (is_numeric($widget_args)) {
        $widget_args = array('number' => $widget_args);
    }
    $widget_args = wp_parse_args($widget_args, array('number' => -1));
    extract($widget_args, EXTR_SKIP);
    $options = $mgm_sidebar_widget->text_widget;
    if (!is_array($options)) {
        $options = array();
    }
    // m_sidebar
    $m_sidebar = mgm_post_var('sidebar');
    // updated
    if (!$updated && !empty($m_sidebar)) {
        $sidebar = (string) $m_sidebar;
        $sidebars_widgets = wp_get_sidebars_widgets();
        if (isset($sidebars_widgets[$sidebar])) {
            $this_sidebar =& $sidebars_widgets[$sidebar];
        } else {
            $this_sidebar = array();
        }
        foreach ($this_sidebar as $_widget_id) {
            // check
            if (isset($wp_registered_widgets[$_widget_id]['callback']) && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
                if ('mgm_widget_text' == $wp_registered_widgets[$_widget_id]['callback']) {
                    $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
                    if (!in_array("text-{$widget_number}", mgm_post_var('widget-id'))) {
                        // the widget has been removed.
                        unset($options[$widget_number]);
                    }
                }
            }
        }
        foreach ((array) mgm_post_var('mgm_widget_text') as $widget_number => $mgm_widget_text) {
            if (!isset($mgm_widget_text['text']) && isset($options[$widget_number])) {
                // user clicked cancel
                continue;
            }
            // title
            $title = isset($mgm_widget_text['title']) ? strip_tags(stripslashes($mgm_widget_text['title'])) : '';
            // text
            if (current_user_can('unfiltered_html')) {
                $text = isset($mgm_widget_text['text']) ? stripslashes($mgm_widget_text['text']) : '';
            } else {
                $text = isset($mgm_widget_text['text']) ? stripslashes(wp_filter_post_kses($mgm_widget_text['text'])) : '';
            }
            // types
            $access_membership_types = isset($mgm_widget_text['access_membership_types']) ? implode('|', $mgm_widget_text['access_membership_types']) : '';
            // set
            $options[$widget_number] = compact('title', 'text', 'access_membership_types');
        }
        // set
        $mgm_sidebar_widget->text_widget = $options;
        // update_option('mgm_sidebar_widget', $mgm_sidebar_widget);
        $mgm_sidebar_widget->save();
        // updated
        $updated = true;
    }
    // get available membership types
    $membership_types = mgm_get_class('membership_types')->membership_types;
    // selected
    $selected_membership_types = array();
    // get selected
    if (-1 == $number) {
        $number = '%i%';
        $title = '';
        $text = '';
        $selected_membership_types = implode(';', $membership_types);
    } else {
        $title = esc_attr($options[$number]['title']);
        $text = format_to_edit($options[$number]['text']);
        if (isset($options[$number]['access_membership_types'])) {
            $selected_membership_types = explode('|', $options[$number]['access_membership_types']);
        }
    }
    echo '<p>' . __('Available to', 'mgm') . ':<br />';
    foreach ((array) $membership_types as $type_code => $type_name) {
        if (is_array($selected_membership_types)) {
            $c = in_array($type_code, $selected_membership_types) ? 'checked="checked"' : '';
        } else {
            $c = '';
        }
        echo '<input type="checkbox" id="mgm_widget_text_' . $number . '" class="checkbox" name="mgm_widget_text[' . $number . '][access_membership_types][]" value="' . $type_code . '" ' . $c . ' />
			  &nbsp;&nbsp;<label class="mgm_font_italic" for="' . __($type_code, 'mgm') . '">' . __($type_name, 'mgm') . '</label>&nbsp;&nbsp;';
    }
    echo '</p>';
    ?>

	<p>
		<label><?php 
    _e('Title', 'mgm');
    ?>
:</label> 		
		<input class="widefat" id="mgm_widget_text_<?php 
    echo $number;
    ?>
" name="mgm_widget_text[<?php 
    echo $number;
    ?>
][title]" type="text" value="<?php 
    echo $title;
    ?>
" />
	</p>
	<p>
		<label><?php 
    _e('Text', 'mgm');
    ?>
: </label>
		<textarea class="widefat" rows="16" cols="20" id="mgm_widget_text_<?php 
    echo $number;
    ?>
" name="mgm_widget_text[<?php 
    echo $number;
    ?>
][text]"><?php 
    echo $text;
    ?>
</textarea>
		<input type="hidden" name="mgm_widget_text[<?php 
    echo $number;
    ?>
][submit]" value="1" />
	</p>
	<?php 
}
 /**
  * API method save settings, callback main and quick settings data save
  *
  * must be overriden in module	 
  *
  * @param none
  * @return none	 
  */
 function settings_update()
 {
     // form type
     switch (mgm_post_var('setting_form')) {
         case 'box':
             // from box
             break;
         case 'main':
             // form main
             break;
     }
     // return
     return true;
 }
 function payment_history_export()
 {
     global $wpdb;
     // data
     $data = array();
     // filter
     $sql_filter = $payment_type = '';
     // check
     if (isset($_POST['search_field_name'])) {
         // issue#: 219
         $search_field_name = $_POST['search_field_name'];
         // for sql
         $search_field_value = mgm_escape($_POST['search_field_value']);
         // for sql
         $search_field_value = trim($search_field_value);
         // by field
         switch ($search_field_name) {
             case 'username':
                 // issue#: 347(LIKE SEARCH)
                 $sql_filter = " AND user.user_login LIKE '%{$search_field_value}%'";
                 break;
             case 'id':
                 $sql_filter = " AND user.ID = '" . (int) $search_field_value . "'";
                 break;
             case 'email':
                 // issue#: 347(LIKE SEARCH)
                 $sql_filter = " AND user.user_email LIKE '%{$search_field_value}%'";
                 break;
             case 'membership_type':
                 // members
                 $members = mgm_get_members_with('membership_type', $search_field_value);
                 // check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND user.ID IN ({$members_in})";
                 break;
             case 'payment_type':
                 $payment_type = $search_field_value;
                 break;
             case 'first_name':
             case 'last_name':
                 // members
                 $members = mgm_get_members_with($search_field_name, $search_field_value);
                 //check
                 $members_in = count($members) == 0 ? 0 : implode(',', $members);
                 // set filter
                 $sql_filter = " AND user.ID IN ({$members_in})";
                 break;
         }
     }
     if (!empty($payment_type)) {
         $con = " AND transaction.payment_type =  '" . $payment_type . "' ";
     } else {
         $con = '';
     }
     //payment success check
     $pay_succ = " AND transaction.status_text =  'Last payment was successful'";
     $transaction_sql = "SELECT SQL_CALC_FOUND_ROWS * FROM " . TBL_MGM_TRANSACTION . " transaction LEFT JOIN {$wpdb->users} user ON transaction.user_id = user.ID ";
     $transaction_sql .= "WHERE transaction.module IS NOT NULL";
     $transaction_sql .= $pay_succ;
     $transaction_sql .= $con;
     $transaction_sql .= $sql_filter;
     $transaction_sql .= " ORDER BY transaction.transaction_dt DESC {$sql_limit}";
     $data['transactions'] = $wpdb->get_results($transaction_sql);
     $export_transactions = array();
     if (count($data['transactions']) > 0) {
         foreach ($data['transactions'] as $tran_log) {
             $json_decoded = json_decode($tran_log->data);
             $user_obj = get_userdata($json_decoded->user_id);
             //empty obj
             $row = new stdClass();
             if (!empty($user_obj)) {
                 //export fields
                 $row->id = $user_obj->ID;
                 $row->username = $user_obj->user_login;
                 $row->firstname = $user_obj->first_name;
                 $row->lastname = $user_obj->last_name;
                 $row->email = $user_obj->user_email;
                 $row->payment_type = ucwords(str_replace('_', ' ', $tran_log->payment_type));
                 $row->module = ucwords($tran_log->module);
                 $row->amount = $json_decoded->trial_on ? $json_decoded->trial_cost : $json_decoded->cost;
                 $row->transaction_date = date(MGM_DATE_FORMAT_SHORT, strtotime($tran_log->transaction_dt));
             }
             // cache
             $export_transactions[] = $row;
             // unset
             unset($row);
         }
     }
     // message
     $message = __('Error while exporting transactions. Could not find any transaction with requested search parameters.', 'mgm');
     // default response
     $response = array('status' => 'error', 'message' => $message);
     // check
     if (count($export_transactions) > 0) {
         // success
         $success = count($export_transactions);
         // create
         if (mgm_post_var('export_format') == 'csv') {
             $filename = mgm_create_csv_file($export_transactions, 'export_transactions');
         } else {
             $filename = mgm_create_xls_file($export_transactions, 'export_transactions');
         }
         // src
         $file_src = MGM_FILES_EXPORT_URL . $filename;
         // message
         $response['message'] = sprintf(__('Successfully exported %d %s.', 'mgm'), $success, $success > 1 ? 'transactions' : 'transaction');
         $response['status'] = 'success';
         $response['src'] = $file_src;
     }
     // return response
     echo json_encode($response);
     exit;
 }
Exemplo n.º 6
0
 /**
  * Validate credit card fields.
  * Modules can override this function
  * @param unknown_type $calling_fun
  * @return unknown
  */
 function validate_cc_fields($calling_fun)
 {
     // init error
     $error = new WP_Error();
     // post
     $post = array();
     // post data
     $post['mgm_card_holder_name'] = mgm_post_var('mgm_card_holder_name');
     $post['mgm_card_number'] = mgm_post_var('mgm_card_number');
     $post['mgm_card_code'] = mgm_post_var('mgm_card_code');
     $post['mgm_card_type'] = mgm_post_var('mgm_card_type');
     // card exp
     $post['mgm_card_expiry_month'] = mgm_post_var('mgm_card_expiry_month');
     $post['mgm_card_expiry_year'] = mgm_post_var('mgm_card_expiry_year');
     // trim
     $post = array_map('trim', $post);
     // check
     if (empty($post['mgm_card_holder_name'])) {
         $error->add('invalid_card_holder_name', __('<strong>ERROR</strong>: Invalid Card Holder Name', 'mgm'));
     }
     if (!is_numeric($post['mgm_card_number']) || strlen($post['mgm_card_number']) > 16 && strlen($post['mgm_card_number']) < 13) {
         $error->add('invalid_card_number', __('<strong>ERROR</strong>: Invalid Credit Card Number', 'mgm'));
     }
     if (!is_numeric($post['mgm_card_expiry_month']) || !is_numeric($post['mgm_card_expiry_year'])) {
         $error->add('invalid_expiry', __('<strong>ERROR</strong>: Invalid Credit Card Expiry', 'mgm'));
     }
     if (!is_numeric($post['mgm_card_code']) || strlen($post['mgm_card_code']) > 4 && strlen($post['mgm_card_code']) < 3) {
         $error->add('invalid_card_code', __('<strong>ERROR</strong>: Invalid CVV', 'mgm'));
     }
     if (empty($post['mgm_card_type'])) {
         $error->add('invalid_cctype', __('<strong>ERROR</strong>: Invalid Card Type', 'mgm'));
     }
     // no error
     if ($error->get_error_message() == '') {
         return false;
     }
     // return
     return $error;
 }
 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;
 }
/**
 * get post purchase buttons
 * final step for post purchase
 *
 * @param void
 * @return $html
 */
function mgm_get_post_purchase_buttons()
{
    // get current user data - issue #1421
    $user = wp_get_current_user();
    // pack
    $pack = NULL;
    // addon options
    if ($addon_option_ids = mgm_post_var('addon_options')) {
        $addon_options = mgm_get_addon_options_only($addon_option_ids);
        // mgm_pr($addon_options);
    }
    // post purchase
    if (isset($_POST['post_id'])) {
        //issue #1250
        if (isset($_POST['mgm_postpurchase_field']['coupon']) && !empty($_POST['mgm_postpurchase_field']['coupon'])) {
            //issue #1250 - Coupon validation
            if (!empty($_POST['form_action'])) {
                // check if its a valid coupon
                if (!($coupon = mgm_get_coupon_data($_POST['mgm_postpurchase_field']['coupon']))) {
                    //redirect back to the form
                    $q_arg = array('error_field' => 'Coupon', 'error_type' => 'invalid', 'error_field_value' => $_POST['mgm_postpurchase_field']['coupon']);
                    $redirect = add_query_arg($q_arg, $_POST['form_action']);
                    mgm_redirect($redirect);
                    exit;
                }
            }
        }
        // post id
        $post_id = $_POST['post_id'];
        // gete mgm data
        $post_obj = mgm_get_post($post_id);
        $cost = mgm_convert_to_currency($post_obj->purchase_cost);
        $product = $post_obj->product;
        $allowed_modules = $post_obj->allowed_modules;
        // post data
        $post = get_post($post_id);
        $title = $post->post_title;
        // item name -issue #1380
        $item_name = apply_filters('mgm_post_purchase_itemname', sprintf(__('Purchase Post - %s', 'mgm'), $title));
        // set pack
        $pack = array('duration' => 1, 'item_name' => $item_name, 'buypost' => 1, 'cost' => $cost, 'title' => $title, 'product' => $product, 'post_id' => $post_id, 'allowed_modules' => $allowed_modules);
    } else {
        if (isset($_POST['postpack_id'])) {
            // post pack purchase
            //issue #1250
            if (isset($_POST['mgm_postpurchase_field']['coupon']) && !empty($_POST['mgm_postpurchase_field']['coupon'])) {
                //issue #1250 - Coupon validation
                if (!empty($_POST['form_action'])) {
                    // check if its a valid coupon
                    if (!($coupon = mgm_get_coupon_data($_POST['mgm_postpurchase_field']['coupon']))) {
                        //redirect back to the form
                        $q_arg = array('error_field' => 'Coupon', 'error_type' => 'invalid', 'error_field_value' => $_POST['mgm_postpurchase_field']['coupon']);
                        $redirect = add_query_arg($q_arg, $_POST['form_action']);
                        mgm_redirect($redirect);
                        exit;
                    }
                }
            }
            // post pack purchase
            $postpack_id = $_POST['postpack_id'];
            // pcak id
            $postpack_post_id = $_POST['postpack_post_id'];
            // post id where pack is listed, redirect here
            // get pack
            $postpack = mgm_get_postpack($postpack_id);
            $cost = mgm_convert_to_currency($postpack->cost);
            $product = json_decode($postpack->product, true);
            $modules = json_decode($postpack->modules, true);
            //mgm_pr($postpack);
            // item name -issue #1380
            $item_name = apply_filters('mgm_postpack_purchase_itemname', sprintf(__('Purchase Post Pack - %s', 'mgm'), $postpack->name));
            // post id
            $post_id = mgm_get_postpack_posts_csv($postpack_id);
            // set pack
            $pack = array('duration' => 1, 'item_name' => $item_name, 'buypost' => 1, 'cost' => $cost, 'title' => $postpack->name, 'product' => $product, 'post_id' => $post_id, 'postpack_id' => $postpack_id, 'postpack_post_id' => $postpack_post_id, 'allowed_modules' => $modules);
        }
    }
    // check
    if (!$pack) {
        return __('Error in Payment! No data available ');
        exit;
    }
    // guest token	-issue #1421
    if (isset($_POST['guest_purchase']) && $_POST['guest_purchase'] == TRUE && $user->ID <= 0) {
        $pack['guest_token'] = sanitize_title_for_query(mgm_create_token());
    }
    // addon options
    if (isset($addon_options) && !empty($addon_options)) {
        $pack['addon_options'] = $addon_options;
    }
    // get coupon
    $post_purchase_coupon = mgm_save_partial_fields(array('on_postpurchase' => true), 'mgm_postpurchase_field', $pack['cost'], false, 'postpurchase');
    // alter
    mgm_get_post_purchase_coupon_pack($post_purchase_coupon, $pack);
    // Eg: $_POST['mgm_payment_gateways'] = mgm_paypal
    $cf_payment_gateways = isset($_POST['mgm_payment_gateways']) && !empty($_POST['mgm_payment_gateways']) ? $_POST['mgm_payment_gateways'] : null;
    // bypass step2 if payment gateway is submitted: issue #: 469
    if (!is_null($cf_payment_gateways)) {
        // get pack
        // mgm_get_upgrade_coupon_pack($member, $selected_pack);
        // cost
        if ((double) $pack['cost'] > 0) {
            //get an object of the payment gateway:
            $mod_obj = mgm_get_module($cf_payment_gateways, 'payment');
            // tran options
            $tran_options = array('user_id' => $user->ID);
            // is register & purchase
            if (isset($_POST['post_id'])) {
                $tran_options['post_id'] = (int) $_POST['post_id'];
            }
            // postpack id
            if (isset($_POST['postpack_id'])) {
                $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
            }
            // is register & purchase postpack
            if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
                $tran_options['postpack_post_id'] = (int) $_POST['postpack_post_id'];
                $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
            }
            // create transaction
            $tran_id = mgm_add_transaction($pack, $tran_options);
            // bypass directly to process return if manual payment:
            if ($cf_payment_gateways == 'mgm_manualpay') {
                // set
                $_POST['custom'] = $tran_id;
                // direct call to module return function:
                $mod_obj->process_return();
                // exit
                exit;
            }
            // encode id:
            $tran_id = mgm_encode_id($tran_id);
            $redirect = $mod_obj->_get_endpoint('html_redirect', true);
            $redirect = add_query_arg(array('tran_id' => $tran_id), $redirect);
            // redirect
            mgm_redirect($redirect);
            // this goes to subscribe, mgm_functions.php/mgm_get_subscription_buttons
            // exit
            exit;
        }
    }
    // get payment modules
    $a_payment_modules = mgm_get_class('system')->get_active_modules('payment');
    // init
    $payment_modules = array();
    // when active
    if ($a_payment_modules) {
        // loop
        foreach ($a_payment_modules as $payment_module) {
            // not trial
            if (in_array($payment_module, array('mgm_free', 'mgm_trial'))) {
                continue;
            }
            // store
            $payment_modules[] = $payment_module;
        }
    }
    // init
    $button = '';
    // transaction
    $tran_id = NULL;
    $button_printed = 0;
    // loop modules
    foreach ($payment_modules as $module) {
        // object
        $mod_obj = mgm_get_module($module, 'payment');
        // check buypost support
        if (in_array('buypost', $mod_obj->supported_buttons)) {
            // create transaction
            if (!$tran_id) {
                $tran_id = mgm_add_transaction($pack);
            }
            // button code
            if (isset($pack['allowed_modules'])) {
                // Issue #1562: If no payment module is selected, display all supported modules
                if (!empty($pack['allowed_modules']) && FALSE === in_array($module, $pack['allowed_modules'])) {
                    continue;
                }
            }
            $button_code = $mod_obj->get_button_buypost(array('pack' => $pack, 'tran_id' => $tran_id), true);
            $button_printed++;
            // get button
            $button .= "<div class='mgm_custom_filed_table'>" . $button_code . "</div>";
        }
    }
    // none active
    if ($button_printed == 0) {
        $button .= sprintf('<p class="mgm-no-module"> %s </p>', __('No Payment module active for this Content Purchase.', 'mgm'));
    }
    // if Cost is zero, then process using free module.: issue#: 883
    if ($tran_id && $pack['cost'] == 0 && in_array('mgm_free', $a_payment_modules) && mgm_get_module('mgm_free')->is_enabled()) {
        // module
        $module = 'mgm_free';
        // payments url
        $payments_url = mgm_get_custom_url('transactions');
        // query_args
        $query_args = array('method' => 'payment_return', 'module' => $module, 'custom' => $tran_id);
        // redirector
        if (isset($_REQUEST['redirector'])) {
            // set
            $query_args['redirector'] = $_REQUEST['redirector'];
        }
        // redirect to module to mark the payment as complete
        $redirect = add_query_arg($query_args, $payments_url);
        // redirect
        mgm_redirect($redirect);
    }
    // html
    $return = '<div class="post_purchase_select_gateway">' . __('Please Select a Payment Gateway.', 'mgm') . '</div>' . $button;
    // return
    return $return;
}
Exemplo n.º 9
0
/**
 * login widget : multiple instance
 * admin instance
 *
 * @param array $widget_args
 * @return void
 * @since 1.0
 */
function mgm_sidebar_widget_login_admin($widget_args = 1)
{
    global $wp_registered_widgets, $mgm_sidebar_widget;
    static $updated = false;
    if (is_numeric($widget_args)) {
        $widget_args = array('number' => $widget_args);
    }
    $widget_args = wp_parse_args($widget_args, array('number' => -1));
    extract($widget_args, EXTR_SKIP);
    // options init
    $options = $mgm_sidebar_widget->login_widget;
    // default
    if (!is_array($options)) {
        $options = array();
    }
    // m_sidebar
    $m_sidebar = mgm_post_var('sidebar');
    // update
    if (!$updated && !empty($m_sidebar)) {
        $sidebar = (string) $m_sidebar;
        $sidebars_widgets = wp_get_sidebars_widgets();
        if (isset($sidebars_widgets[$sidebar])) {
            $this_sidebar =& $sidebars_widgets[$sidebar];
        } else {
            $this_sidebar = array();
        }
        foreach ($this_sidebar as $_widget_id) {
            // check
            if (isset($wp_registered_widgets[$_widget_id]['callback']) && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
                if ('mgm_widget_login' == $wp_registered_widgets[$_widget_id]['callback']) {
                    $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
                    if (!in_array("login-{$widget_number}", mgm_post_var('widget-id'))) {
                        // the widget has been removed.
                        unset($options[$widget_number]);
                    }
                }
            }
        }
        // update
        foreach ((array) mgm_post_var('mgm_widget_login') as $widget_number => $mgm_widget_login) {
            if (!isset($mgm_widget_login['title_logged_in']) && isset($options[$widget_number])) {
                // user clicked cancel
                continue;
            }
            // set vars
            $title_logged_in = isset($mgm_widget_login['title_logged_in']) ? stripslashes($mgm_widget_login['title_logged_in']) : '';
            $title_logged_out = isset($mgm_widget_login['title_logged_out']) ? stripslashes($mgm_widget_login['title_logged_out']) : '';
            $profile_text = isset($mgm_widget_login['profile_text']) ? stripslashes($mgm_widget_login['profile_text']) : '';
            $membership_details_text = isset($mgm_widget_login['membership_details_text']) ? stripslashes($mgm_widget_login['membership_details_text']) : '';
            $membership_contents_text = isset($mgm_widget_login['membership_contents_text']) ? stripslashes($mgm_widget_login['membership_contents_text']) : '';
            $logout_text = isset($mgm_widget_login['logout_text']) ? stripslashes($mgm_widget_login['logout_text']) : '';
            $register_text = isset($mgm_widget_login['register_text']) ? stripslashes($mgm_widget_login['register_text']) : '';
            $lostpassword_text = isset($mgm_widget_login['lostpassword_text']) ? stripslashes($mgm_widget_login['lostpassword_text']) : '';
            $logged_out_intro = isset($mgm_widget_login['logged_out_intro']) ? stripslashes($mgm_widget_login['logged_out_intro']) : '';
            $logged_in_template = isset($mgm_widget_login['logged_in_template']) ? stripslashes($mgm_widget_login['logged_in_template']) : '';
            // set
            $options[$widget_number] = compact('title_logged_in', 'title_logged_out', 'profile_text', 'membership_contents_text', 'membership_details_text', 'logout_text', 'register_text', 'logged_out_intro', 'lostpassword_text', 'logged_in_template');
        }
        // set
        $mgm_sidebar_widget->login_widget = $options;
        // save
        $mgm_sidebar_widget->save();
        // updated
        $updated = true;
    }
    // get selected
    if (-1 == $number) {
        $number = '%i%';
        $title_logged_in = __('Membership Details', 'mgm');
        $title_logged_out = __('Login', 'mgm');
        $profile_text = __('Profile', 'mgm');
        $membership_contents_text = __('Membership Contents', 'mgm');
        $membership_details_text = __('Membership Details', 'mgm');
        $logout_text = __('Logout', 'mgm');
        $register_text = __('Register', 'mgm');
        $lostpassword_text = __('Lost your Password?', 'mgm');
        $logged_out_intro = '';
        $logged_in_template = $mgm_sidebar_widget->default_text['logged_in_template'];
    } else {
        $title_logged_in = stripslashes($options[$number]['title_logged_in']);
        $title_logged_out = stripslashes($options[$number]['title_logged_out']);
        $profile_text = stripslashes($options[$number]['profile_text']);
        $membership_contents_text = stripslashes($options[$number]['membership_contents_text']);
        $membership_details_text = stripslashes($options[$number]['membership_details_text']);
        $logout_text = stripslashes($options[$number]['logout_text']);
        $register_text = stripslashes($options[$number]['register_text']);
        $lostpassword_text = stripslashes($options[$number]['lostpassword_text']);
        $logged_out_intro = stripslashes($options[$number]['logged_out_intro']);
        $logged_in_template = stripslashes($options[$number]['logged_in_template']);
    }
    // print
    $html = '<p>' . __('When logged out the user will see a login form. Removing the text from the "Register link text" or "Lost password link text" will subsequently remove the links they produce.', 'mgm') . '</p>
	<input type="hidden" name="mgm_widget_login[' . $number . '][submit]" id="mgm-login-widget-submit-' . $number . '" value="1" />
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-widget-title"><strong>' . __('Widget Title (Logged in):', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $title_logged_in . '" id="mgm-login-widget-widget-title-logged-in-' . $number . '" name="mgm_widget_login[' . $number . '][title_logged_in]" /></label>
	</div>
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-widget-title-logged-out"><strong>' . __('Widget Title (Logged out):', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $title_logged_out . '" id="mgm-login-widget-widget-title-logged-out-' . $number . '" name="mgm_widget_login[' . $number . '][title_logged_out]" /></label>
	</div>
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-profile-text"><strong>' . __('Profile link text:', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $profile_text . '" id="mgm-login-widget-profile-text-' . $number . '" name="mgm_widget_login[' . $number . '][profile_text]" /></label>
	</div>
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-membership-details-text"><strong>' . __('Membership Details link text:', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $membership_details_text . '" id="mgm-login-widget-membership-details-text-' . $number . '" name="mgm_widget_login[' . $number . '][membership_details_text]" /></label>
	</div>
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-membership-contents-text"><strong>' . __('Membership Contents link text:', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $membership_contents_text . '" id="mgm-login-widget-membership-contents-text-' . $number . '" name="mgm_widget_login[' . $number . '][membership_contents_text]" /></label>
	</div>
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-logout-text"><strong>' . __('Logout text:', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $logout_text . '" id="mgm-login-widget-logout-text-' . $number . '" name="mgm_widget_login[' . $number . '][logout_text]" />
		</label>
	</div>
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-register-text"><strong>' . __('Register link text:', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $register_text . '" id="mgm-login-widget-register-text-' . $number . '" name="mgm_widget_login[' . $number . '][register_text]" />
		</label>
	</div>
	<div class="mgm_margin_bottom_5px">
		<div><label for="mgm-login-widget-lostpassword-text"><strong>' . __('Lost password link text:', 'mgm') . '</strong></div>
		<input class="mgm_width_300px" value="' . $lostpassword_text . '" id="mgm-login-widget-lostpassword-text-' . $number . '"	name="mgm_widget_login[' . $number . '][lostpassword_text]" /></label>
	</div>
	<div class="mgm_margin_bottom_5px">				
		<label for="mgm-login-widget-logged-out-intro">
			<div><strong>' . __('Logged Out Introduction', 'mgm') . '</strong></div>
			<textarea rows="2" cols="50" id="mgm-login-widget-logged-out-intro-' . $number . '" name="mgm_widget_login[' . $number . '][logged_out_intro]">' . esc_html($logged_out_intro) . '</textarea>
		</label>
	</div>
	<div class="mgm_margin_bottom_5px">				
		<label for="mgm-login-widget-logged-in-template">
			<div><strong>' . __('Logged In Template', 'mgm') . '</strong> - Use the following hooks: [display_name], [profile_url], [profile_link], [membership_details_url], [membership_details_link],[membership_contents_url], [membership_contents_link], [logout_url], [logout_link]</div>
			<textarea rows="6" cols="50" id="mgm-login-widget-logged-in-template-' . $number . '" name="mgm_widget_login[' . $number . '][logged_in_template]">' . $logged_in_template . '</textarea>
		</label>
	</div>
	';
    // print
    print $html;
}
 function _buy_membership()
 {
     // system
     $system_obj = mgm_get_class('system');
     $s_packs = mgm_get_class('subscription_packs');
     $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
     $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails'));
     // get passthrough, stop further process if fails to parse
     $custom = $this->_get_transaction_passthrough($_POST['custom']);
     // local var
     extract($custom);
     // currency
     if (!$currency) {
         $currency = $system_obj->get_setting('currency');
     }
     // find user
     $user = get_userdata($user_id);
     //another_subscription modification
     if (isset($custom['is_another_membership_purchase']) && bool_from_yn($custom['is_another_membership_purchase'])) {
         $member = mgm_get_member_another_purchase($user_id, $custom['membership_type']);
     } else {
         $member = mgm_get_member($user_id);
     }
     // Get the current AC join date
     if (!($join_date = $member->join_date)) {
         $member->join_date = time();
     }
     // Set current AC join date
     // if there is no duration set in the user object then run the following code
     if (empty($duration_type)) {
         //if there is no duration type then use Months
         $duration_type = 'm';
     }
     // membership type default
     if (empty($membership_type)) {
         //if there is no account type in the custom string then use the existing type
         $membership_type = md5($member->membership_type);
     }
     // validate parent method
     $membership_type_verified = $this->_validate_membership_type($membership_type, 'md5|plain');
     // verified
     if (!$membership_type_verified) {
         // check
         if (strtolower($member->membership_type) != 'free') {
             // notify admin, only if gateway emails on
             if (!$dge) {
                 mgm_notify_admin_membership_verification_failed($this->name);
             }
             // abort
             return;
         } else {
             $membership_type_verified = $member->membership_type;
         }
     }
     // set
     $membership_type = $membership_type_verified;
     // sub pack
     $subs_pack = $s_packs->get_pack($pack_id);
     // verify product for another purchase
     if (isset($custom['is_another_membership_purchase']) && bool_from_yn($custom['is_another_membership_purchase'])) {
         // check pack
         if (isset($subs_pack['product']['1shoppingcart_product_id']) && !empty($subs_pack['product']['1shoppingcart_product_id'])) {
             // pack
             $pack_product_id = $subs_pack['product']['1shoppingcart_product_id'];
             // match
             if ($post_product_id = mgm_post_var('product_id')) {
                 // match
                 if (trim($post_product_id) != trim($pack_product_id)) {
                     // log
                     mgm_log(sprintf('Product mismatch: pack[%s] => post[%s]', $pack_product_id, $post_product_id), $_POST['custom'] . '_' . __FUNCTION__);
                     // exit
                     exit;
                 }
             }
         }
     }
     // if trial on
     if ($subs_pack['trial_on']) {
         $member->trial_on = $subs_pack['trial_on'];
         $member->trial_cost = $subs_pack['trial_cost'];
         $member->trial_duration = $subs_pack['trial_duration'];
         $member->trial_duration_type = $subs_pack['trial_duration_type'];
         $member->trial_num_cycles = $subs_pack['trial_num_cycles'];
     }
     //pack currency over rides genral setting currency - issue #1602
     if (isset($subs_pack['currency']) && $subs_pack['currency'] != $currency) {
         $currency = $subs_pack['currency'];
     }
     // duration
     $member->duration = $duration;
     $member->duration_type = strtolower($duration_type);
     $member->amount = $amount;
     $member->currency = $currency;
     $member->membership_type = $membership_type;
     $member->pack_id = $pack_id;
     $member->payment_type = 'subscription';
     $member->transaction_id = $_POST['custom'];
     $member->active_num_cycles = isset($num_cycles) && !empty($num_cycles) ? $num_cycles : $subs_pack['num_cycles'];
     // tracking fields module_field => post_field, will be used to unsubscribe
     $tracking_fields = array('txn_type' => 'status', 'subscr_id' => 'client_id', 'txn_id' => isset($_POST['order_id']) ? 'order_id' : 'transaction_id');
     // save tracking fields
     $this->_save_tracking_fields($tracking_fields, $member);
     // process response
     $new_status = $update_role = false;
     // errors
     $errors = array();
     // by status
     switch ($_POST['status']) {
         case "Approved":
         case "Accepted":
             $new_status = MGM_STATUS_ACTIVE;
             $member->status_str = __('Last payment was successful', 'mgm');
             $time = time();
             $last_pay_date = isset($member->last_pay_date) ? $member->last_pay_date : null;
             $member->last_pay_date = date('Y-m-d', $time);
             // check subscription_option
             if (isset($subscription_option)) {
                 // on option
                 switch ($subscription_option) {
                     // @ToDo, apply expire date login
                     case 'create':
                         // expire date will be based on current time
                     // expire date will be based on current time
                     case 'upgrade':
                         // expire date will be based on current time
                         // already on top
                         break;
                     case 'downgrade':
                         // expire date will be based on expire_date if exists, current time other wise
                     // expire date will be based on expire_date if exists, current time other wise
                     case 'extend':
                         // expire date will be based on expire_date if exists, current time other wise
                         // extend/expire date
                         // calc expiry	- issue #1226
                         // membership extend functionality broken if we try to extend the same day so removed && $last_pay_date != date('Y-m-d', $time) check
                         if (!empty($member->expire_date)) {
                             $expiry = strtotime($member->expire_date);
                             if ($expiry > 0 && $expiry > $time) {
                                 $time = $expiry;
                             }
                         }
                         break;
                 }
             }
             // type expanded
             $duration_exprs = $s_packs->get_duration_exprs();
             // if not lifetime/date range
             if (in_array($member->duration_type, array_keys($duration_exprs))) {
                 // take only date exprs
                 //consider trial duration if trial period is applicable
                 if (isset($trial_on) && $trial_on == 1) {
                     //Do it only once
                     if (!isset($member->rebilled) && isset($member->active_num_cycles) && $member->active_num_cycles != 1) {
                         $time = strtotime("+{$trial_duration} {$duration_exprs[$trial_duration_type]}", $time);
                     }
                 } else {
                     // time - issue #1068
                     $time = strtotime("+{$member->duration} {$duration_exprs[$member->duration_type]}", $time);
                 }
                 // formatted
                 $time_str = date('Y-m-d', $time);
                 // date extended
                 if (!$member->expire_date || strtotime($time_str) > strtotime($member->expire_date)) {
                     $member->expire_date = $time_str;
                 }
             } else {
                 // if lifetime
                 if ($member->duration_type == 'l') {
                     // el = lifetime
                     $member->expire_date = '';
                 }
                 //issue #1096
                 if ($member->duration_type == 'dr') {
                     // el = /date range
                     $member->expire_date = $duration_range_end_dt;
                 }
             }
             // update rebill: issue #: 489
             if ($member->active_num_cycles != 1 && (int) $member->rebilled < (int) $member->active_num_cycles) {
                 // rebill
                 $member->rebilled = !$member->rebilled ? 1 : (int) $member->rebilled + 1;
             }
             // role
             if ($role) {
                 $update_role = true;
             }
             //cancel previous subscription:
             //issue#: 565
             $this->cancel_recurring_subscription($_POST['custom'], null, null, $pack_id);
             // transaction_id
             $transaction_id = $this->_get_transaction_id();
             // hook args
             $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id);
             // after succesful payment hook
             do_action('mgm_membership_transaction_success', $args);
             // backward compatibility
             do_action('mgm_subscription_purchase_payment_success', $args);
             // new organized name
             break;
         case "Declined":
             $new_status = MGM_STATUS_NULL;
             $member->status_str = __('Last payment was refunded or denied', 'mgm');
             // error
             $errors[] = $member->status_str;
             break;
         case "Pending":
             $new_status = MGM_STATUS_PENDING;
             $reason = 'Unnown';
             $member->status_str = sprintf(__('Last payment is pending. Reason: %s', 'mgm'), $reason);
             // error
             $errors[] = $member->status_str;
             break;
         default:
             $new_status = MGM_STATUS_ERROR;
             $member->status_str = sprintf(__('Last payment status: %s', 'mgm'), $ctransaction);
             // error
             $errors[] = $member->status_str;
             break;
     }
     // old status
     $old_status = $member->status;
     // set new status
     $member->status = $new_status;
     // whether to acknowledge the user - This should happen only once
     $acknowledge_user = $this->send_payment_email($_POST['custom']);
     // whether to subscriber the user to Autoresponder - This should happen only once
     $acknowledge_ar = mgm_subscribe_to_autoresponder($member, $_POST['custom']);
     // another_subscription modification
     if (isset($custom['is_another_membership_purchase']) && bool_from_yn($custom['is_another_membership_purchase'])) {
         //issue #1227
         if ($subs_pack['hide_old_content']) {
             $member->hide_old_content = $subs_pack['hide_old_content'];
         }
         // save
         mgm_save_another_membership_fields($member, $user_id);
         // Multiple membership upgrade: first time
         if (isset($custom['multiple_upgrade_prev_packid']) && is_numeric($custom['multiple_upgrade_prev_packid'])) {
             mgm_multiple_upgrade_save_memberobject($custom, $member->transaction_id);
         }
     } else {
         // update
         $member->save();
     }
     // status change event
     do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id);
     //update coupon usage
     do_action('mgm_update_coupon_usage', array('user_id' => $user_id));
     // update role
     if ($update_role) {
         // role;
         $obj_role = new mgm_roles();
         // set
         $obj_role->add_user_role($user_id, $role);
     }
     // return action
     do_action('mgm_return_' . $this->module, array('user_id' => $user_id));
     // backward compatibility
     do_action('mgm_return_subscription_payment_' . $this->module, array('user_id' => $user_id));
     // new , individual
     do_action('mgm_return_subscription_payment', array('user_id' => $user_id, 'acknowledge_ar' => $acknowledge_ar, 'mgm_member' => $member));
     // new, global: pass mgm_member object to consider multiple level purchases as well.
     // transaction status
     mgm_update_transaction_status($member->transaction_id, $member->status, $member->status_str);
     // send email notification to client
     $blogname = get_option('blogname');
     // notify
     if ($acknowledge_user) {
         // notify user, only if gateway emails on
         if (!$dpne) {
             // notify
             if (mgm_notify_user_membership_purchase($blogname, $user, $member, $custom, $subs_pack, $s_packs, $system_obj)) {
                 // update as email sent
                 $this->update_paymentemail_sent($alt_tran_id);
             }
         }
         // notify admin, only if gateway emails on
         if (!$dge) {
             // pack duration
             $pack_duration = $s_packs->get_pack_duration($subs_pack);
             // notify admin,
             mgm_notify_admin_membership_purchase($blogname, $user, $member, $pack_duration);
         }
     }
     // error condition redirect
     if (count($errors) > 0) {
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => implode('|', $errors)), $this->_get_thankyou_url()));
     }
 }
Exemplo n.º 11
0
 function _get_notification_data()
 {
     // notificationCode
     $notification_code = mgm_post_var('notificationCode');
     // code
     $notification_type = mgm_post_var('notificationType');
     // transaction
     // check
     if ($notification_code) {
         // parse the pagseguro URL
         $notification_url = $this->_get_endpoint('notification');
         // build
         $notification_url = add_query_arg(array('email' => $this->setting['receiver_email'], 'token' => $this->setting['token']), trailingslashit($notification_url . $notification_code));
         // headers
         $http_headers = array('Content-Type' => 'application/x-www-form-urlencoded');
         // just in case
         // get
         $http_response = mgm_remote_get($notification_url, null, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // log xml as came
         mgm_log('http_response: ' . $http_response, $this->module . '_' . __FUNCTION__);
         // parse as xml
         if ($xml = @simplexml_load_string($http_response)) {
             // parse
             $_POST['code'] = (string) $xml->code;
             $_POST['custom'] = (string) $xml->reference;
             $_POST['type'] = (string) $xml->type;
             $_POST['status'] = (string) $xml->status;
             // code
             $_POST['status_code'] = $this->_get_status_code($_POST['status']);
             // log
             mgm_log('PagSeguro IPN : processed :' . print_r($_POST, true), $this->module . '_' . __FUNCTION__);
         }
     }
 }
Exemplo n.º 12
0
/**
 * login errors display fix for email as username
 *
 * @param string $errors
 * @return string $errors
 * @since 2.7
 */
function mgm_login_errors($errors)
{
    if (bool_from_yn(mgm_get_setting('enable_email_as_username'))) {
        $errors = preg_replace('#username <strong>(.*)</strong> is#', 'email <strong>' . mgm_post_var('log') . '</strong> is', $errors);
        //issue #1412
        if (!preg_match('#' . __('unfinished', 'mgm') . '#', $errors)) {
            $errors = preg_replace('#' . __('username', 'mgm') . '#', __('Email', 'mgm'), $errors);
        }
    }
    return $errors;
}
 private function _save_member_object($user_id, $member, $previous_membership)
 {
     // pack
     $pack = mgm_get_class('subscription_packs')->get_pack($member->pack_id);
     // multiple_level_purchase
     $multiple_level_purchase = bool_from_yn(mgm_get_class('system')->get_setting('enable_multiple_level_purchase'));
     // update options
     $update_options = mgm_post_var('update_opt');
     // new level
     if (in_array('subscription', $update_options) && mgm_post_var('insert_new_level') == 'new') {
         // save flag
         $save = true;
         // guest
         if ($previous_membership->membership_type == "guest" && $previous_membership->amount == 0) {
             // check selected membership already selected:
             if ($previous_membership->membership_type == $member->membership_type) {
                 $save = false;
             }
         } else {
             // old
             $old_subtypes = mgm_get_subscribed_membershiptypes($user_id);
             //check selected membership already selected:
             if (in_array($member->membership_type, $old_subtypes)) {
                 $save = false;
             } else {
                 if (isset($member->custom_fields)) {
                     unset($member->custom_fields);
                 }
                 if (isset($member->other_membership_types) || empty($member->other_membership_types)) {
                     unset($member->other_membership_types);
                 }
             }
         }
         // save
         if ($save) {
             // multiple
             if ($multiple_level_purchase) {
                 mgm_save_another_membership_fields($member, $user_id);
             } else {
                 $member->save();
             }
         }
         // assign role:
         $change_order = isset($_POST['highlight_role']) && isset($_POST['upd_subscription_pack']) && $_POST['upd_subscription_pack'] != '-' ? true : false;
         // set
         $obj_role = new mgm_roles();
         $obj_role->add_user_role($user_id, $pack['role'], $change_order);
     } else {
         if (isset($_POST['ps_mem'][$user_id]) && !empty($_POST['ps_mem'][$user_id])) {
             if (isset($member->custom_fields)) {
                 unset($member->custom_fields);
             }
             if (isset($member->other_membership_types) || empty($member->other_membership_types)) {
                 unset($member->other_membership_types);
             }
             $prev_index = isset($_POST['ps_mem_index'][$user_id][$previous_membership->membership_type]) ? $_POST['ps_mem_index'][$user_id][$previous_membership->membership_type] : null;
             //uncomment
             mgm_save_another_membership_fields($member, $user_id, $prev_index);
         } else {
             $member->save();
         }
         if ($member->status == MGM_STATUS_EXPIRED) {
             //remove role from user:
             mgm_remove_userroles($user_id, $member);
         } else {
             //if($member->membership_type != $previous_membership->membership_type) {//check this condition
             //mgm role object:
             $change_order = isset($_POST['highlight_role']) && isset($_POST['upd_subscription_pack']) && $_POST['upd_subscription_pack'] != '-' ? true : false;
             $obj_role = new mgm_roles();
             //update role/change order
             $obj_role->add_user_role($user_id, $pack['role'], $change_order);
             //}
         }
     }
     return true;
 }
/**
 */
function mgm_replace_email_username($code, $error_str)
{
    switch ($code) {
        case 'empty_username':
        case 'invalid_username':
            if (bool_from_yn(mgm_get_setting('enable_email_as_username'))) {
                $error_str = preg_replace('#' . __('username', 'mgm') . '#', __('Email', 'mgm'), $error_str);
            }
            break;
        case 'incorrect_password':
            if (bool_from_yn(mgm_get_setting('enable_email_as_username'))) {
                $error_str = preg_replace('#username <strong>(.*)</strong> is#', 'email <strong>' . mgm_post_var('log') . '</strong> is', $error_str);
            }
            break;
    }
    return $error_str;
}
/**
 * Custom user profile form
 */
function mgm_user_profile_form($user_id = NULL, $temp_edit = false, $args = array())
{
    global $wpdb;
    // get mgm_system
    $system_obj = mgm_get_class('system');
    // current user
    $current_user = $user_id ? get_userdata($user_id) : wp_get_current_user();
    // current or voew
    if ($current_user->ID) {
        // current
        $user = mgm_get_userdata($current_user->ID);
    } else {
        // query string
        $user = mgm_get_user_from_querystring();
    }
    // if no user
    if (!isset($user) || !$user->ID || is_super_admin($user->ID)) {
        return mgm_user_login_form();
        exit;
    }
    // mgm member
    $member = mgm_get_member($user->ID);
    // edit mode, on for current user
    $edit_mode = $current_user->ID == $user->ID ? true : false;
    $temp = 0;
    // form action
    $form_action = get_permalink();
    // reset
    if ($form_action == null) {
        $form_action = mgm_get_current_url();
        $form_action = str_replace(array('&updated=true', '?updated=true'), '', $form_action);
    }
    //init - issue #1573
    $show_membership_fields_arr = array();
    if (isset($args['membership']) && !empty($args['membership'])) {
        // membership
        $membership = $args['membership'];
        // get active custom fields on register
        $cf_profile_by_membership_types = mgm_get_class('member_custom_fields')->get_fields_where(array('attributes' => array('profile_by_membership_types' => true)));
        //check
        if (!empty($cf_profile_by_membership_types)) {
            //loop
            foreach ($cf_profile_by_membership_types as $cf_profile_by_membership_type) {
                //membership_type
                $membership_types_string = isset($cf_profile_by_membership_type['attributes']['profile_membership_types_field_alias']) ? $cf_profile_by_membership_type['attributes']['profile_membership_types_field_alias'] : null;
                //check
                if (preg_match('/\\b' . $membership . '\\b/', $membership_types_string) && $membership_types_string != null) {
                    $show_fields_arr[] = $cf_profile_by_membership_type['name'];
                    $show_membership_fields_arr[] = $cf_profile_by_membership_type;
                    if ($cf_profile_by_membership_type['name'] == 'password') {
                        foreach ($cf_profile_by_membership_types as $cf_profile_by_membership) {
                            if ($cf_profile_by_membership['name'] == 'password_conf') {
                                $show_membership_fields_arr[] = $cf_profile_by_membership;
                            }
                        }
                    }
                }
            }
        }
    }
    // get default fields
    $profile_fields = mgm_get_config('default_profile_fields', array());
    // get active custom fields on profile page
    $cf_profile_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_profile' => true)));
    $cf_noton_profile = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_profile' => false)));
    //merge - issue #1573
    if (isset($show_membership_fields_arr) && is_array($show_membership_fields_arr) && !empty($show_membership_fields_arr)) {
        $cf_profile_page = array_merge($cf_profile_page, $show_membership_fields_arr);
        $cf_noton_profile = array_merge($cf_noton_profile, $show_membership_fields_arr);
    }
    $error_html = '';
    //issue #867
    $css_group = mgm_get_css_group();
    if ($css_group != 'none') {
        // error_html
        $error_html .= '<link rel="stylesheet" href="' . MGM_ASSETS_URL . 'css/' . $css_group . '/mgm.messages.css' . '" type="text/css" media="all" />';
    }
    // update
    if ($edit_mode) {
        // updated
        if (isset($_POST['method']) && $_POST['method'] == 'update_user') {
            // check security before processing form
            if (!wp_verify_nonce(mgm_post_var('_mgmnonce_user_profile'), 'user_profile')) {
                mgm_security_error('user_profile');
            }
            // user lib
            if (mgm_compare_wp_version('3.1', '<')) {
                // only before 3.1
                require_once ABSPATH . WPINC . '/registration.php';
            }
            // callback
            do_action('personal_options_update', $current_user->ID);
            // not multisite, duplicate email allowed ?
            if (!is_multisite()) {
                // save
                $errors = mgm_user_profile_update($current_user->ID);
            } else {
                // multi site
                // get user
                $user = get_userdata($current_user->ID);
                // update here:
                // Update the email address, if present. duplicate check
                if ($user->user_login && isset($_POST['user_email']) && is_email($_POST['user_email']) && $wpdb->get_var($wpdb->prepare("SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login))) {
                    $wpdb->query($wpdb->prepare("UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['user_email'], $user->user_login));
                }
                // edit
                if (!isset($errors) || isset($errors) && is_object($errors) && false == $errors->get_error_codes()) {
                    $errors = mgm_user_profile_update($current_user->ID);
                }
            }
            // trap erros
            if (!is_wp_error($errors)) {
                // redirect
                mgm_redirect(add_query_arg(array('updated' => 'true'), $form_action));
            }
            // errors
            if (isset($errors) && !is_numeric($errors)) {
                // get error
                $error_html .= mgm_set_errors($errors, true);
            }
        }
    }
    // updated
    if ($edit_mode && isset($_GET['updated'])) {
        $error_html .= '<div class="mgm_message_success">';
        $message = apply_filters('mgm_profile_edit_message', __('User updated.', 'mgm'));
        $error_html .= '<div><strong>' . $message . '</strong></div></div>';
    }
    // 	get row row template
    $form_row_template = $system_obj->get_template('profile_form_row_template');
    // get template row filter, mgm_profile_form_row_template for edit, mgm_profile_form_row_template_view for public view
    $form_row_template = apply_filters('mgm_profile_form_row_template' . (!$edit_mode ? '_view' : ''), $form_row_template);
    $cf_order = array();
    foreach ($cf_profile_page as $fld) {
        $cf_order[] = array('field' => $fld['name']);
    }
    // auto generate form template
    // form_template
    $form_template = '';
    // captured
    $fields_captured = array();
    // get field_groups
    $field_groups = mgm_get_config('profile_field_groups', array());
    // loop groups
    foreach ($field_groups as $group => $group_fields) {
        if ($group == 'Photo') {
            $photo_exists = false;
            foreach ($cf_profile_page as $photo) {
                if ($photo['name'] == 'photo') {
                    $photo_exists = true;
                    break;
                }
            }
            if (!$photo_exists) {
                continue;
            }
        }
        $fields_with_order = array();
        //issue #1197
        $css_title = function_exists('mb_strtolower') ? @mb_strtolower($group) : strtolower($group);
        $css_title = str_replace(' ', '_', $css_title);
        // group
        // PREV CODE
        $form_template .= sprintf('<span class="profile_group_%s">%s</span>', $css_title, $group);
        // loop to create form template
        foreach ($group_fields as $group_field) {
            // skip password
            //if(!$edit_mode && $group_field == 'password') continue;
            if (!$edit_mode && in_array($group_field, array('password', 'password_conf'))) {
                continue;
            }
            // set not found
            $captured = false;
            // first check if in custom fields
            foreach ($cf_profile_page as $field) {
                // skip password in non edit mode
                if ($field['name'] == $group_field) {
                    // set found
                    $captured = true;
                    // skip password
                    //if(!$edit_mode && $field['name'] == 'password') continue;
                    if (!$edit_mode && in_array($field['name'], array('password', 'password_conf'))) {
                        continue;
                    }
                    // store for no repeat
                    $fields_captured[] = $field['name'];
                    // field wrapper
                    $wrapper_ph = sprintf('[user_field_wrapper_%s]', $field['name']);
                    // field label
                    $label_ph = sprintf('[user_field_label_%s]', $field['name']);
                    // field/html element
                    $element_ph = sprintf('[user_field_element_%s]', $field['name']);
                    // set element name
                    // PREV CODE
                    //$form_template .= str_replace(array('[user_field_wrapper]','[user_field_label]','[user_field_element]'),array($wrapper_ph,$label_ph,$element_ph),$form_row_template);
                    // Issue #1149
                    foreach ($cf_order as $index => $cfo) {
                        if ($cfo['field'] == $field['name']) {
                            $fields_with_order[$index] = str_replace(array('[user_field_wrapper]', '[user_field_label]', '[user_field_element]'), array($wrapper_ph, $label_ph, $element_ph), $form_row_template);
                            break;
                        }
                    }
                    // break;
                    break;
                }
            }
            // if not captured
            if (!$captured) {
                $continue = false;
                foreach ($cf_noton_profile as $cffield) {
                    if ($cffield['name'] == $group_field) {
                        $continue = true;
                        break;
                    }
                }
                // break;
                if ($continue) {
                    continue;
                }
                // check set
                if (!isset($profile_fields[$group_field]['name'])) {
                    continue;
                }
                // field wrapper
                $wrapper_ph = sprintf('[user_field_wrapper_%s]', $profile_fields[$group_field]['name']);
                // field label
                $label_ph = sprintf('[user_field_label_%s]', $profile_fields[$group_field]['name']);
                // field/html element
                $element_ph = sprintf('[user_field_element_%s]', $profile_fields[$group_field]['name']);
                // set element name
                // PREV CODE
                // $form_template .= str_replace(array('[user_field_wrapper]','[user_field_label]','[user_field_element]'),array($wrapper_ph,$label_ph,$element_ph),$form_row_template);
                // Issue #1149
                $field_added = false;
                foreach ($cf_order as $index => $cfo) {
                    if ($cfo['field'] == $group_field) {
                        $fields_with_order[$index] = str_replace(array('[user_field_wrapper]', '[user_field_label]', '[user_field_element]'), array($wrapper_ph, $label_ph, $element_ph), $form_row_template);
                        $field_added = true;
                        break;
                    }
                }
                if (!$field_added) {
                    /*$fields_with_order[$index+1] = str_replace(array('[user_field_wrapper]','[user_field_label]','[user_field_element]'),array($wrapper_ph,$label_ph,$element_ph),$form_row_template);*/
                    // default profile instalation fields - issue #1207
                    if (in_array($group_field, array('username', 'email', 'password', 'password', 'password_conf'))) {
                        $fields_with_order[$temp++] = str_replace(array('[user_field_wrapper]', '[user_field_label]', '[user_field_element]'), array($wrapper_ph, $label_ph, $element_ph), $form_row_template);
                    }
                }
            }
        }
        // Issue #1149
        // Process custom field form_template with order
        if (!empty($fields_with_order)) {
            // Sort by key
            ksort($fields_with_order);
            // Loop through fields and attach html
            foreach ($fields_with_order as $fworder) {
                $form_template .= $fworder;
            }
        }
    }
    // other
    $other_header = false;
    // loop to create form template
    foreach ($cf_profile_page as $field) {
        // skip password in non edit mode
        //if(!$edit_mode && $field['name'] == 'password') continue;
        if (!$edit_mode && in_array($field['name'], array('password', 'password_conf'))) {
            continue;
        }
        // skip captured
        if (in_array($field['name'], $fields_captured)) {
            continue;
        }
        // header
        if (!$other_header) {
            // rest
            $form_template .= sprintf('<span class="profile_group_others">%s</span>', __('Others', 'mgm'));
            $other_header = true;
        }
        // field wrapper
        $wrapper_ph = sprintf('[user_field_wrapper_%s]', $field['name']);
        // field label
        $label_ph = sprintf('[user_field_label_%s]', $field['name']);
        // field/html element
        $element_ph = sprintf('[user_field_element_%s]', $field['name']);
        // template for show_public_profile
        if ($field['name'] == 'show_public_profile') {
            // template
            $form_row_template_pf = $system_obj->get_template('register_form_row_autoresponder_template');
            // set element place holders
            $form_template .= str_replace(array('[user_field_wrapper]', '[user_field_label]', '[user_field_element]'), array($wrapper_ph, $label_ph, $element_ph), $form_row_template_pf);
        } else {
            // set element name
            $form_template .= str_replace(array('[user_field_wrapper]', '[user_field_label]', '[user_field_element]'), array($wrapper_ph, $label_ph, $element_ph), $form_row_template);
        }
    }
    // get template filter, mgm_profile_form_template for edit, mgm_profile_form_template_view for public view
    $form_template = apply_filters('mgm_profile_form_template' . (!$edit_mode ? '_view' : ''), $form_template);
    // now replace and create the fields
    $form_html = $form_template;
    // get mgm_form_fields generator
    $form_fields = new mgm_form_fields(array('wordpres_form' => false));
    $arr_images = array();
    // loop custom fields to replace form labels/elements
    foreach ($cf_profile_page as $field) {
        // skip password in non edit mode
        //if(!$edit_mode && $field['name'] == 'password') continue;
        if (!$edit_mode && in_array($field['name'], array('password', 'password_conf'))) {
            continue;
        }
        if ($edit_mode && $field['type'] == 'image') {
            if (!in_array($field['name'], $arr_images)) {
                $arr_images[] = $field['name'];
            }
        }
        // field wrapper
        $wrapper_ph = sprintf('[user_field_wrapper_%s]', $field['name']);
        // field label
        $label_ph = sprintf('[user_field_label_%s]', $field['name']);
        // field/html element
        $element_ph = sprintf('[user_field_element_%s]', $field['name']);
        // edit mode
        if ($edit_mode) {
            // for username
            if ($field['name'] == 'username') {
                //localazing the label  issue# 617
                $label_lcz = mgm_stripslashes_deep($field['label']);
                $label_lcz = __($label_lcz, 'mgm');
                $field['label'] = sprintf('%s (<em>%s</em>)', $label_lcz, __('Username not changeable', 'mgm'));
            } elseif ($field['name'] == 'password') {
                //localazing the label  issue# 617
                $label_lcz = mgm_stripslashes_deep($field['label']);
                $label_lcz = __($label_lcz, 'mgm');
                $field['label'] = sprintf('%s (<em>%s</em>)', $label_lcz, __('Leave blank if don\'t wish to update', 'mgm'));
            }
        } else {
            // for display_name
            if ($field['name'] == 'display_name') {
                $field['label'] = __('Display Name', 'mgm');
            }
        }
        // replace wrapper
        $form_html = str_replace($wrapper_ph, $field['name'] . '_box', $form_html);
        //localazing the label  issue# 617
        $label_lcz = mgm_stripslashes_deep($field['label']);
        $label_lcz = __($label_lcz, 'mgm');
        // replace label(hidden) - issue #1050
        $form_html = str_replace($label_ph, $field['attributes']['hide_label'] ? '' : mgm_stripslashes_deep($field['label']), $form_html);
        // replace label
        $form_html = str_replace($label_ph, $label_lcz, $form_html);
        // selected value
        if (isset($profile_fields[$field['name']]) && isset($user->{$profile_fields}[$field['name']]['name'])) {
            // wp alias'
            // value
            $value = $user->{$profile_fields}[$field['name']]['name'];
            // birthdate
            if ($field['name'] == 'birthdate') {
                // convert saved date to input field format
                $value = mgm_get_datepicker_format('date', $value);
            } elseif ($field['type'] == 'checkbox') {
                //$options = preg_split('/[;,]/', $field['options']);
                //$value  = preg_split('/[;,\s]/', $value);
                //issue #1070
                $value = @unserialize($value);
                // pass " " as value to prevent the default value getting selected, if no option is selected
                $value = empty($value) ? " " : $value;
            }
        } else {
            if (isset($member->custom_fields->{$field}['name'])) {
                // custom field
                // value
                $value = $member->custom_fields->{$field}['name'];
                // birthdate
                if ($field['name'] == 'birthdate') {
                    // convert saved date to input field format
                    $value = mgm_get_datepicker_format('date', $value);
                } elseif ($field['type'] == 'checkbox') {
                    //$options = preg_split('/[;,]/', $field['options']);
                    //$value  = preg_split('/[;,\s]/', $value);
                    //issue #1070
                    $value = @unserialize($value);
                    // pass " " as value to prevent the default value getting selected, if no option is selected
                    $value = empty($value) ? " " : $value;
                }
                //issue #1484
                if ($field['name'] == 'show_public_profile' && $field['type'] == 'checkbox') {
                    $value = $member->custom_fields->{$field}['name'];
                }
            } else {
                if (isset($user->{$field}['name'])) {
                    // object var
                    // value
                    $value = $user->{$field}['name'];
                } else {
                    // none
                    // default
                    $value = '';
                }
            }
        }
        // dont set value for password
        if (in_array($field['name'], array('password', 'password_conf'))) {
            $value = '';
        }
        // disable username
        if ($field['name'] == 'username') {
            $field['attributes']['readonly'] = true;
        }
        // nickname
        if ($field['name'] == 'nickname') {
            $field['attributes']['required'] = true;
        }
        // edit mode
        if ($edit_mode) {
            if ($field['name'] == 'show_public_profile') {
                //echo "xxx".$form_fields->get_field_element($field,'mgm_profile_field',$value);
            }
            // replace element
            $form_html = str_replace($element_ph, $form_fields->get_field_element($field, 'mgm_profile_field', $value), $form_html);
        } else {
            // view
            // country
            if ($field['name'] == 'country') {
                $value = mgm_country_from_code($value);
            } elseif ($field['name'] == 'photo' && !empty($value)) {
                $value = sprintf('<img src="%s" alt="%s" >', $value, basename($value));
            }
            // replace element
            $form_html = str_replace($element_ph, $value, $form_html);
        }
    }
    // loop default fields to replace form elements
    foreach ($profile_fields as $field_key => $field) {
        // skip password in non edit mode
        //if(!$edit_mode && $field['name'] == 'user_password') continue;
        if (!$edit_mode && in_array($field['name'], array('user_password', 'user_password_conf'))) {
            continue;
        }
        $continue = false;
        foreach ($cf_noton_profile as $cffield) {
            if ($cffield['name'] == $field['name']) {
                $continue = true;
                break;
            }
        }
        if ($continue) {
            continue;
        }
        // field wrapper
        $wrapper_ph = sprintf('[user_field_wrapper_%s]', $field['name']);
        // field label
        $label_ph = sprintf('[user_field_label_%s]', $field['name']);
        // field/html element
        $element_ph = sprintf('[user_field_element_%s]', $field['name']);
        // edit mode
        if ($edit_mode) {
            // for username
            if ($field['name'] == 'user_login') {
                //localazing the label  issue# 617
                $label_lcz = mgm_stripslashes_deep($field['label']);
                $label_lcz = __($label_lcz, 'mgm');
                $field['label'] = sprintf('%s (<em>%s</em>)', $label_lcz, __('Username not changeable', 'mgm'));
            } elseif ($field['name'] == 'user_password') {
                //localazing the label  issue# 617
                $label_lcz = mgm_stripslashes_deep($field['label']);
                $label_lcz = __($label_lcz, 'mgm');
                $field['label'] = sprintf('%s (<em>%s</em>)', $label_lcz, __('Leave blank if don\'t wish to update', 'mgm'));
            }
        } else {
            // for display_name
            if ($field['name'] == 'display_name') {
                $field['label'] = __('Display Name', 'mgm');
            }
        }
        // replace wrapper
        $form_html = str_replace($wrapper_ph, $field['name'] . '_box', $form_html);
        //localazing the label  issue# 617
        $label_lcz = mgm_stripslashes_deep($field['label']);
        $label_lcz = __($label_lcz, 'mgm');
        // replace label
        $form_html = str_replace($label_ph, $label_lcz, $form_html);
        // selected value
        if (isset($user->{$field}['name'])) {
            // wp alias
            $value = $user->{$field}['name'];
        } else {
            if (isset($member->custom_fields->{$field_key})) {
                // custom field
                $value = $member->custom_fields->{$field_key};
            } else {
                // none
                $value = '';
            }
        }
        // dont set value for password
        //if($field['name'] == 'user_password') $value = '';
        if (in_array($field['name'], array('user_password', 'user_password_conf'))) {
            $value = '';
        }
        // edit mode
        if ($edit_mode) {
            // replace element
            $form_html = str_replace($element_ph, $form_fields->get_field_element($field, 'mgm_profile_field', $value), $form_html);
        } else {
            // country
            if ($field_key == 'country') {
                $value = mgm_country_from_code($value);
            }
            // set
            $form_html = str_replace($element_ph, $value, $form_html);
        }
    }
    // attach scripts
    $form_html .= mgm_attach_scripts(true, array());
    // range
    $yearRange = mgm_get_calendar_year_range();
    // append script
    $form_html .= '<script language="javascript">jQuery(document).ready(function(){try{mgm_date_picker(".mgm_date",false,{yearRange:"' . $yearRange . '", dateFormat: "' . mgm_get_datepicker_format() . '"});}catch(x){}});</script>';
    //include scripts for image upload:
    if (!empty($arr_images)) {
        $form_html .= mgm_upload_script_js('profileform', $arr_images);
    }
    // buttun
    $button_html = '';
    // button on edit
    if ($edit_mode && !$temp_edit) {
        // default
        $button_html = '<div><input class="button mgm-profile-button" type="submit" name="wp-submit" id="wp-submit" value="' . __('Update', 'mgm') . '" /></div>';
        // apply button filter
        $button_html = apply_filters('mgm_profile_form_button', $button_html);
    }
    //profile by membership - issue #1573
    if (isset($args['membership']) && !empty($args['membership'])) {
        // hidden
        $button_html .= sprintf('<input type="hidden" name="membership" value="%s">', $args['membership']);
    }
    // hidden
    $button_html .= '<input type="hidden" name="method" value="update_user">';
    // nonce
    $button_html .= wp_nonce_field('user_profile', '_mgmnonce_user_profile', true, false);
    // temp
    if (!$temp_edit) {
        // open
        $form_open = sprintf('<form class="mgm_form" name="profileform" id="profileform" action="%s" method="post">', $form_action);
        $form_close = '</form>';
    } else {
        $form_open = $form_close = '';
    }
    // output form
    $html = sprintf('<div class="mgm_prifile_form">%s %s %s %s %s</div>', $error_html, $form_open, $form_html, $button_html, $form_close);
    //issue #1113
    $html = mgm_stripslashes_deep($html);
    // filter
    $html = apply_filters('mgm_user_profile_form_html', $html, $current_user);
    //issue #1635
    $user_profile_html = '<div class="mgm_user_profile_container">' . $html . '</div>';
    // return
    return $user_profile_html;
}
 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;
 }