<commit_before><?php

//only admins can get this
if(!function_exists("current_user_can") || (!current_user_can("manage_options") && !current_user_can("pmpro_memberslist")))
{
    die(__("You do not have permissions to perform this action.", "pmpro"));
}  

//vars
if(isset($_REQUEST['s']))
    $s = $_REQUEST['s'];
else
    $s = false;

if(isset($_REQUEST['l']))
    $l = $_REQUEST['l'];
else
    $l = false;

?>

<form id="posts-filter" method="get" action="">  
    <h2>
	<?php _e('Members List', 'pmpro');?>
	<a target="_blank" href="<?php echo admin_url('admin-ajax.php');?>?action=hc_memberslist_csv&s=<?php echo $s?>&l=<?php echo $l?>" class="add-new-h2"><?php _e('Export to CSV', 'pmpro');?></a>
    </h2>    
    <ul class="subsubsub">
	<li>      
	    <?php _e('Show', 'pmpro');?>
	    <select name="l" onchange="jQuery('#posts-filter').submit();">
		<option value="" <?php if(!$l) { ?>selected="selected"<?php } ?>><?php _e('All Levels', 'pmpro');?></option>
		<option value="paid" <?php if($l == "paid") { ?>selected="selected"<?php } ?>><?php _e('Paid Subscribers', 'pmpro');?></option>
		<option value="new_non_subs" <?php if($l == "new_non_subs") { ?>selected="selected"<?php } ?>><?php _e('New Non-Subscribers', 'pmpro');?></option>
		<option value="paid_print_domestic" <?php if($l == "paid_print_domestic") { ?>selected="selected"<?php } ?>><?php _e('Paid Domestic Print Subscribers', 'pmpro');?></option>
		<option value="exp_last_60_print" <?php if($l == "exp_last_60_print") { ?>selected="selected"<?php } ?>><?php _e('Recently Expired Domestic Print Subs', 'pmpro');?></option>
		<option value="exp_next_month" <?php if($l == "exp_next_month") { ?>selected="selected"<?php } ?>><?php _e('Expires next month', 'pmpro');?></option>
		<option value="exp_next_2_3" <?php if($l == "exp_next_2_3") { ?>selected="selected"<?php } ?>><?php _e('Expires 2-3 months out', 'pmpro');?></option>
		<option value="exp_next_4_5" <?php if($l == "exp_next_4_5") { ?>selected="selected"<?php } ?>><?php _e('Expires 4-5 months out', 'pmpro');?></option>

		<?php
		$levels = $wpdb->get_results("SELECT id, name FROM $wpdb->pmpro_membership_levels ORDER BY name");
		foreach($levels as $level)
		{
		?>
		    <option value="<?php echo $level->id?>" <?php if($l == $level->id) { ?>selected="selected"<?php } ?>><?php echo $level->name?></option>
                <?php
                }
		?>
		<option value="oldmembers" <?php if($l == "oldmembers") { ?>selected="selected"<?php } ?>><?php _e('Old Members', 'pmpro');?></option>
	    </select>      
	</li>
    </ul>
    <p class="search-box">
	<label class="hidden" for="post-search-input"><?php _e('Search Members', 'pmpro');?>:</label>
	<input type="hidden" name="page" value="hc-members-list" />    
	<input id="post-search-input" type="text" value="<?php echo $s?>" name="s"/>
	<input class="button" type="submit" value="<?php _e('Search Members', 'pmpro');?>"/>
    </p>
	<?php 
	//some vars for the search
	if(isset($_REQUEST['pn']))
	    $pn = $_REQUEST['pn'];
	else
	    $pn = 1;
	
	if(isset($_REQUEST['limit']))
	    $limit = $_REQUEST['limit'];
	else
	    $limit = 15;
	
	$end = $pn * $limit;
	$start = $end - $limit;

	$search_clause = "";
	if($s) {
	    $search_clause = "AND (u.user_login LIKE '%$s%' OR u.user_email LIKE '%$s%' OR um.meta_value LIKE '%$s%')";
	}

	$sqlQuery = "SELECT SQL_CALC_FOUND_ROWS u.ID, u.user_login, u.user_email, UNIX_TIMESTAMP(u.user_registered) as joindate, mu.membership_id, mu.initial_payment, mu.billing_amount, mu.cycle_period, mu.cycle_number, mu.billing_limit, mu.trial_amount, mu.trial_limit, UNIX_TIMESTAMP(mu.startdate) as startdate, UNIX_TIMESTAMP(mu.enddate) as enddate, m.name as membership FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id";

	if($l == "exp_last_60_print") {
	    $sqlQuery .= " AND mu.status = 'expired' AND mu.membership_id IN(2, 6) LEFT JOIN wp_pmpro_memberships_users mu2 ON u.ID = mu2.user_id AND mu2.status = 'active' AND mu2.membership_id = 1 "; 
	} elseif($l == "oldmembers") {
	    $sqlQuery .= " LEFT JOIN $wpdb->pmpro_memberships_users mu2 ON u.ID = mu2.user_id AND mu2.status = 'active' ";
	}

	$sqlQuery .= " LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id WHERE ";

	// where clause used to contain mu.membership_id > 0 
	
	// append the search restriction if any
	$sqlQuery .= $search_clause;
	
	// Add the restrictions for the various member classes
	if($l == "oldmembers")
	    $sqlQuery .= " AND mu.status = 'inactive' AND mu2.status IS NULL ";
	elseif($l == "paid")
	$sqlQuery .= " AND mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 7)";
	elseif($l == "paid_print_domestic")
	$sqlQuery .= " AND mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 4, 5, 7)";
	elseif($l == "exp_last_60_print")
	$sqlQuery .= " AND date(mu.enddate) < CURDATE() AND date(mu.enddate) > (DATE_SUB(CURDATE(), INTERVAL 2 MONTH))";
	elseif($l == "exp_next_month")
        // This is for renewal notices -- only do them for
	// domestic and foreign non-agency subscribers
	$sqlQuery .= " AND mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 7, 8, 9) AND (LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 1 MONTH)) >= date(mu.enddate))";
	elseif($l == "exp_next_2_3")
	$sqlQuery .= " AND mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 7, 8, 9) AND (mu.enddate >= STR_TO_DATE(((PERIOD_ADD(EXTRACT(YEAR_MONTH FROM CURDATE()),2)*100)+1), '%Y%m%d')) AND (mu.enddate <= LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 3 MONTH)))";
	elseif($l == "exp_next_4_5")
	$sqlQuery .= " AND mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 7, 8, 9) AND (mu.enddate >= STR_TO_DATE(((PERIOD_ADD(EXTRACT(YEAR_MONTH FROM CURDATE()),4)*100)+1), '%Y%m%d')) AND (mu.enddate <= LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 5 MONTH)))";
	elseif($l == "new_non_subs")
	// They have no membership, or a guest membership, and they joined
	// less than 60 days ago
	$sqlQuery .= " AND (mu.user_id IS NULL OR mu.membership_id = 0) AND date(u.joindate) >= (DATE_SUB(CURDATE(), INTERVAL 2 MONTH))";
	elseif($l)
	$sqlQuery .= " AND mu.status = 'active' AND mu.membership_id = '" . $l . "' ";          
	else
	    $sqlQuery .= " AND mu.status = 'active' ";      
	
	$sqlQuery .= " GROUP BY u.ID ";
	
	if($l == "oldmembers")
	    $sqlQuery .= "ORDER BY enddate DESC ";
	else
	    $sqlQuery .= "ORDER BY u.user_registered DESC ";
	<commit_msg>Try showing non-members.<commit_after><?php

//only admins can get this
if(!function_exists("current_user_can") || (!current_user_can("manage_options") && !current_user_can("pmpro_memberslist")))
{
    die(__("You do not have permissions to perform this action.", "pmpro"));
}  

//vars
if(isset($_REQUEST['s']))
    $s = $_REQUEST['s'];
else
    $s = false;

if(isset($_REQUEST['l']))
    $l = $_REQUEST['l'];
else
    $l = false;

?>

<form id="posts-filter" method="get" action="">  
    <h2>
	<?php _e('Members List', 'pmpro');?>
	<a target="_blank" href="<?php echo admin_url('admin-ajax.php');?>?action=hc_memberslist_csv&s=<?php echo $s?>&l=<?php echo $l?>" class="add-new-h2"><?php _e('Export to CSV', 'pmpro');?></a>
    </h2>    
    <ul class="subsubsub">
	<li>      
	    <?php _e('Show', 'pmpro');?>
	    <select name="l" onchange="jQuery('#posts-filter').submit();">
		<option value="" <?php if(!$l) { ?>selected="selected"<?php } ?>><?php _e('All Levels', 'pmpro');?></option>
		<option value="paid" <?php if($l == "paid") { ?>selected="selected"<?php } ?>><?php _e('Paid Subscribers', 'pmpro');?></option>
		<option value="new_non_subs" <?php if($l == "new_non_subs") { ?>selected="selected"<?php } ?>><?php _e('New Non-Subscribers', 'pmpro');?></option>
		<option value="paid_print_domestic" <?php if($l == "paid_print_domestic") { ?>selected="selected"<?php } ?>><?php _e('Paid Domestic Print Subscribers', 'pmpro');?></option>
		<option value="exp_last_60_print" <?php if($l == "exp_last_60_print") { ?>selected="selected"<?php } ?>><?php _e('Recently Expired Domestic Print Subs', 'pmpro');?></option>
		<option value="exp_next_month" <?php if($l == "exp_next_month") { ?>selected="selected"<?php } ?>><?php _e('Expires next month', 'pmpro');?></option>
		<option value="exp_next_2_3" <?php if($l == "exp_next_2_3") { ?>selected="selected"<?php } ?>><?php _e('Expires 2-3 months out', 'pmpro');?></option>
		<option value="exp_next_4_5" <?php if($l == "exp_next_4_5") { ?>selected="selected"<?php } ?>><?php _e('Expires 4-5 months out', 'pmpro');?></option>

		<?php
		$levels = $wpdb->get_results("SELECT id, name FROM $wpdb->pmpro_membership_levels ORDER BY name");
		foreach($levels as $level)
		{
		?>
		    <option value="<?php echo $level->id?>" <?php if($l == $level->id) { ?>selected="selected"<?php } ?>><?php echo $level->name?></option>
                <?php
                }
		?>
		<option value="oldmembers" <?php if($l == "oldmembers") { ?>selected="selected"<?php } ?>><?php _e('Old Members', 'pmpro');?></option>
	    </select>      
	</li>
    </ul>
    <p class="search-box">
	<label class="hidden" for="post-search-input"><?php _e('Search Members', 'pmpro');?>:</label>
	<input type="hidden" name="page" value="hc-members-list" />    
	<input id="post-search-input" type="text" value="<?php echo $s?>" name="s"/>
	<input class="button" type="submit" value="<?php _e('Search Members', 'pmpro');?>"/>
    </p>
	<?php 
	//some vars for the search
	if(isset($_REQUEST['pn']))
	    $pn = $_REQUEST['pn'];
	else
	    $pn = 1;
	
	if(isset($_REQUEST['limit']))
	    $limit = $_REQUEST['limit'];
	else
	    $limit = 15;
	
	$end = $pn * $limit;
	$start = $end - $limit;

	$search_clause = "";
	if($s) {
	    $search_clause = "AND (u.user_login LIKE '%$s%' OR u.user_email LIKE '%$s%' OR um.meta_value LIKE '%$s%')";
	}

	$sqlQuery = "SELECT SQL_CALC_FOUND_ROWS u.ID, u.user_login, u.user_email, UNIX_TIMESTAMP(u.user_registered) as joindate, mu.membership_id, mu.initial_payment, mu.billing_amount, mu.cycle_period, mu.cycle_number, mu.billing_limit, mu.trial_amount, mu.trial_limit, UNIX_TIMESTAMP(mu.startdate) as startdate, UNIX_TIMESTAMP(mu.enddate) as enddate, m.name as membership FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id";

	if($l == "exp_last_60_print") {
	    $sqlQuery .= " AND mu.status = 'expired' AND mu.membership_id IN(2, 6) LEFT JOIN wp_pmpro_memberships_users mu2 ON u.ID = mu2.user_id AND mu2.status = 'active' AND mu2.membership_id = 1 "; 
	} elseif($l == "oldmembers") {
	    $sqlQuery .= " LEFT JOIN $wpdb->pmpro_memberships_users mu2 ON u.ID = mu2.user_id AND mu2.status = 'active' ";
	}

	$sqlQuery .= " LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id WHERE ";

	// where clause used to contain mu.membership_id > 0 
	
	// Add the restrictions for the various member classes
	if($l == "oldmembers")
	    $sqlQuery .= " mu.status = 'inactive' AND mu2.status IS NULL ";
	elseif($l == "paid")
	$sqlQuery .= " mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 7)";
	elseif($l == "paid_print_domestic")
	$sqlQuery .= " mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 4, 5, 7)";
	elseif($l == "exp_last_60_print")
	$sqlQuery .= " date(mu.enddate) < CURDATE() AND date(mu.enddate) > (DATE_SUB(CURDATE(), INTERVAL 2 MONTH))";
	elseif($l == "exp_next_month")
        // This is for renewal notices -- only do them for
	// domestic and foreign non-agency subscribers
	$sqlQuery .= " mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 7, 8, 9) AND (LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 1 MONTH)) >= date(mu.enddate))";
	elseif($l == "exp_next_2_3")
	$sqlQuery .= " mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 7, 8, 9) AND (mu.enddate >= STR_TO_DATE(((PERIOD_ADD(EXTRACT(YEAR_MONTH FROM CURDATE()),2)*100)+1), '%Y%m%d')) AND (mu.enddate <= LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 3 MONTH)))";
	elseif($l == "exp_next_4_5")
	$sqlQuery .= " mu.status = 'active' AND mu.membership_id NOT IN(0, 1, 3, 7, 8, 9) AND (mu.enddate >= STR_TO_DATE(((PERIOD_ADD(EXTRACT(YEAR_MONTH FROM CURDATE()),4)*100)+1), '%Y%m%d')) AND (mu.enddate <= LAST_DAY(DATE_ADD(CURDATE(), INTERVAL 5 MONTH)))";
	elseif($l == "new_non_subs")
	// They have no membership, or a guest membership, and they joined
	// less than 60 days ago
	$sqlQuery .= " (mu.user_id IS NULL OR mu.membership_id = 0) AND date(u.joindate) >= (DATE_SUB(CURDATE(), INTERVAL 2 MONTH))";
	elseif($l)
	$sqlQuery .= " mu.status = 'active' AND mu.membership_id = '" . $l . "' ";          
	else
	    $sqlQuery .= " mu.status = 'active' ";      
	
	// append the search restriction if any
	$sqlQuery .= $search_clause;
	
	$sqlQuery .= " GROUP BY u.ID ";
	
	if($l == "oldmembers")
	    $sqlQuery .= "ORDER BY enddate DESC ";
	else
	    $sqlQuery .= "ORDER BY u.user_registered DESC ";
	
{'fraction_non_alphanumeric': 0.2075134168157424, 'fraction_numerical': 0.013533483705374504, 'mean_word_length': 4.445997458703939, 'pattern_counts': {'":': 0, '<': 173, '<?xml version=': 0, '>': 197, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '117309', 'n_tokens_mistral': 5011, 'n_tokens_neox': 4767, 'n_words': 1130}