Exemplo n.º 1
0
    function show_user_details($bannerlink = '')
    {
        $user = wp_get_current_user();
        $user_ID = $user->ID;
        if (empty($user_ID)) {
            return '';
        }
        if (function_exists('is_multisite') && is_multisite() && function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('affiliate/affiliate.php')) {
            $site = aff_get_option('site_name');
            // switch to use new option
            $siteurl = get_blog_option(1, 'home');
            $affiliatelinkurl = aff_get_option('affiliatelinkurl', $siteurl);
        } else {
            $site = aff_get_option('blogname');
            // switch to use new option
            $siteurl = aff_get_option('home');
            $affiliatelinkurl = aff_get_option('affiliatelinkurl', $siteurl);
        }
        ob_start();
        if (isset($_POST['action']) && addslashes($_POST['action']) == 'update') {
            check_admin_referer("affiliatepublicsettings-" . $user_ID);
            update_user_meta($user_ID, 'enable_affiliate', $_POST['enable_affiliate']);
            update_user_meta($user_ID, 'affiliate_paypal', $_POST['affiliate_paypal']);
            if (isset($_POST['affiliate_referrer'])) {
                $url = str_replace('http://', '', untrailingslashit($_POST['affiliate_referrer']));
                // store the update - even though it could be wrong
                update_user_meta($user_ID, 'affiliate_referrer', $url);
                // Remove any validated referrers as it may have been changed
                delete_user_meta($user_ID, 'affiliate_referrer_validated');
                // Check for duplicate and if not unique we need to display the open box with an error message
                if ($this->is_duplicate_url($url, $user_ID)) {
                    $error = 'yes';
                    $chkmsg = __('This URL is already in use.', 'affiliate');
                } else {
                    // Create the message we are looking for
                    $chkmsg = '';
                    // Check a file with it exists and contains the content
                    if (defined('AFFILIATE_VALIDATE_REFERRER_URLS') && AFFILIATE_VALIDATE_REFERRER_URLS == 'yes') {
                        $referrer = $_POST['affiliate_referrer'];
                        $filename = md5('affiliatefilename-' . $user_ID . '-' . $user->user_login . "-" . $referrer) . '.html';
                        if ($this->validate_url_for_file(trailingslashit($url), $filename)) {
                            update_user_meta($user_ID, 'affiliate_referrer_validated', 'yes');
                            $chkmsg = __('Validated', 'affiliate');
                        } else {
                            $error = 'yes';
                            $chkmsg = __('Not validated', 'affiliate');
                        }
                    }
                }
            } else {
                delete_user_meta($user_ID, 'affiliate_referrer_validated');
                delete_user_meta($user_ID, 'affiliate_referrer');
            }
            if (isset($_POST['enable_affiliate']) && addslashes($_POST['enable_affiliate']) == 'yes') {
                // Set up the affiliation details
                // Store a record of the reference
                $reference = aff_build_reference($user);
                update_user_meta($user_ID, 'affiliate_reference', $reference);
                update_user_meta($user_ID, 'affiliate_hash', 'aff' . md5(AUTH_SALT . $reference));
            } else {
                // Wipe the affiliation details
                delete_user_meta($user_ID, 'affiliate_reference');
                delete_user_meta($user_ID, 'affiliate_hash');
            }
        }
        echo "<div class='formholder'>";
        if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
            echo "<strong>" . __('Hello, Thank you for supporting us</strong>, to view or change any of your affiliate settings click on the edit link.', 'affiliate') . "</strong><a href='#view' id='editaffsettingslink' style='float:right; font-size: 8pt;'>" . __('edit', 'affiliate') . "</a>";
            if (empty($error)) {
                echo "<div class='innerbox closed'>";
            } else {
                echo "<div class='innerbox open'>";
            }
            echo "<form action='' method='post'>";
            wp_nonce_field("affiliatepublicsettings-" . $user_ID);
            echo "<input type='hidden' name='action' value='update' />";
            $settingstextdefault = "<p>We love it when people talk about us, and even more so when they recommend us to their friends.</p>\n\t\t<p>As a thank you we would like to offer something back, which is why we have set up this affiliate program.</p>\n\t\t<p>To get started simply enable the links for your account and enter your PayPal email address below, for more details on our affiliate program please visit our main site.</p>";
            echo stripslashes(aff_get_option('affiliatesettingstext', $settingstextdefault));
            ?>

			<table class="form-table">
				<tr style='background: transparent;'>
					<th><label for="enable_affiliate"><?php 
            _e('Enable Affiliate links', 'affiliate');
            ?>
</label></th>
					<td>
						<select name='enable_affiliate'>
							<option value='yes' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('Yes please', 'affiliate');
            ?>
</option>
							<option value='no' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) != 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('No thanks', 'affiliate');
            ?>
</option>
						</select>
					</td>
				</tr>

				<tr style='background: transparent;'>
					<th><label for="affiliate_paypal"><?php 
            _e('PayPal Email Address', 'affiliate');
            ?>
</label></th>
					<td>
					<input type="text" name="affiliate_paypal" id="affiliate_paypal" value="<?php 
            echo esc_attr(get_user_meta($user_ID, 'affiliate_paypal', true));
            ?>
" class="regular-text" />
					</td>
				</tr>

			</table>

			<?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
                $reference = get_user_meta($user_ID, 'affiliate_reference', true);
                $referrer = get_user_meta($user_ID, 'affiliate_referrer', true);
                $refurl = "profile.php?page=affiliateearnings";
                $validreferrer = get_user_meta($user_ID, 'affiliate_referrer_validated', true);
                if (defined('AFFILIATE_CHECKALL') && AFFILIATE_CHECKALL == 'yes') {
                    ?>

					<h3><?php 
                    _e('Affiliate Advanced Settings', 'affiliate');
                    ?>
</h3>

					<?php 
                    $advsettingstextdefault = "<p>There are times when you would rather hide your affiliate link, or simply not have to bother remembering the affiliate reference to put on the end of our URL.</p>\n\t\t\t\t<p>If this is the case, then you can enter the main URL of the site you will be sending requests from below, and we will sort out the tricky bits for you.</p>";
                    echo stripslashes(aff_get_option('affiliateadvancedsettingstext', $advsettingstextdefault));
                    if (!empty($chkmsg)) {
                        if (empty($error)) {
                            // valid
                            $msg = "<span style='color: green;'>" . $chkmsg . "</span>";
                        } else {
                            // not valid
                            $msg = "<span style='color: red;'>" . $chkmsg . "</span>";
                        }
                    }
                    ?>

					<table class="form-table">
						<tr style='background: transparent;'>
							<th valign='top'><label for="affiliate_referrer"><?php 
                    _e('Your URL', 'affiliate');
                    ?>
</label></th>
							<td>
								<?php 
                    echo is_ssl() ? 'https' : 'http';
                    ?>
://&nbsp;<input type="text" name="affiliate_referrer" id="affiliate_referrer" value="<?php 
                    echo esc_attr(get_user_meta($user_ID, 'affiliate_referrer', true));
                    ?>
" class="regular-text" />
								<?php 
                    echo "&nbsp;&nbsp;";
                    if (isset($msg)) {
                        echo $msg;
                    }
                    ?>
								<?php 
                    if (defined('AFFILIATE_VALIDATE_REFERRER_URLS') && AFFILIATE_VALIDATE_REFERRER_URLS == 'yes') {
                        if (!empty($validreferrer) && $validreferrer == 'yes') {
                        } else {
                            // Not valid - generate filename
                            $filename = md5('affiliatefilename-' . $user_ID . '-' . $user->user_login . "-" . $referrer) . '.html';
                            // Output message
                            echo "<br/>";
                            _e('You need to validate this URL by uploading a file to the root of the site above with the following name : ', 'affiliate');
                            echo "<br/>";
                            echo __('Filename : ', 'affiliate') . $filename;
                            echo " <a href='http://" . trailingslashit($referrer) . $filename . "' target=_blank>" . __('[click here to check if the file exists]', 'affiliate') . "</a>";
                            echo '<br/><input type="submit" name="Submit" class="button" value="' . __('Validate', 'affiliate') . '" />';
                        }
                    }
                    ?>
							</td>
						</tr>

					</table>

				<?php 
                }
                ?>
				<p><?php 
                _e('<h3>Affiliate Details</h3>', 'affiliate');
                ?>
</p>
				<p><?php 
                _e('In order for us to track your referrals, you should use the following URL to link to our site:', 'affiliate');
                ?>
</p>
				<p><?php 
                echo sprintf(__('<strong>%s?ref=%s</strong>', 'affiliate'), $affiliatelinkurl, $reference);
                ?>
</p>

				<?php 
                if (defined('AFFILIATE_CHECKALL') && !empty($referrer)) {
                    // We are always going to check for a referer site
                    ?>
						<p><?php 
                    _e('Alternatively you can just link directly to the URL below from the site you entered in the advanced settings above:', 'affiliate');
                    ?>
</p>
						<p><?php 
                    echo sprintf(__('<strong>%s</strong>', 'affiliate'), $siteurl);
                    ?>
</p>
						<?php 
                }
                if (aff_get_option('affiliateenablebanners', 'no') == 'yes' && !empty($bannerlink)) {
                    ?>
				<p><?php 
                    echo sprintf(__('If you would rather use a banner or button then we have a wide selection of sizes <a href="%s">here</a>.', 'affiliate'), $bannerlink);
                    ?>
</p>
				<?php 
                }
                ?>
				<p><?php 
                _e('<strong>You can check on your referral totals by viewing the details on this page</strong>', 'affiliate');
                ?>
</p>
			<?php 
            }
            echo '<p class="submit">';
            echo '<input type="submit" name="Submit" value="' . __('Update Settings', 'affiliate') . '" /></p>';
            echo "</form>";
            echo "</div>";
        } else {
            // Not an affiliate yet, so display the form
            echo "<strong>" . __('Hello, why not consider becoming an affiliate?', 'affiliate') . "</strong><br/>";
            echo "<div class='innerbox open'>";
            echo "<form action='' method='post'>";
            wp_nonce_field("affiliatepublicsettings-" . $user_ID);
            echo "<input type='hidden' name='action' value='update' />";
            $settingstextdefault = "<p>We love it when people talk about us, and even more so when they recommend us to their friends.</p>\n\t\t<p>As a thank you we would like to offer something back, which is why we have set up this affiliate program.</p>\n\t\t<p>To get started simply enable the links for your account and enter your PayPal email address below, for more details on our affiliate program please visit our main site.</p>";
            echo stripslashes(aff_get_option('affiliatesettingstext', $settingstextdefault));
            ?>

			<table class="form-table">
				<tr style='background: transparent;'>
					<th><label for="enable_affiliate"><?php 
            _e('Enable Affiliate links', 'affiliate');
            ?>
</label></th>
					<td>
						<select name='enable_affiliate'>
							<option value='yes' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('Yes please', 'affiliate');
            ?>
</option>
							<option value='no' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) != 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('No thanks', 'affiliate');
            ?>
</option>
						</select>
					</td>
				</tr>

				<tr style='background: transparent;'>
					<th><label for="affiliate_paypal"><?php 
            _e('PayPal Email Address', 'affiliate');
            ?>
</label></th>
					<td>
					<input type="text" name="affiliate_paypal" id="affiliate_paypal" value="<?php 
            echo esc_attr(get_user_meta($user_ID, 'affiliate_paypal', true));
            ?>
" class="regular-text" />
					</td>
				</tr>

			</table>

			<?php 
            echo '<p class="submit">';
            echo '<input type="submit" name="Submit" value="' . __('Update Settings', 'affiliate') . '" /></p>';
            echo "</form>";
            echo "</div>";
        }
        echo "</div>";
        $html = ob_get_contents();
        ob_end_clean();
        return $html;
    }
Exemplo n.º 2
0
    function add_profile_report_page()
    {
        $user = wp_get_current_user();
        $user_ID = $user->ID;
        $headings = aff_get_option('affiliateheadings', array(__('Unique Clicks', 'affiliate'), __('Sign ups', 'affiliate'), __('Paid members', 'affiliate')));
        $headings = array_merge($headings, array(__('Debits', 'affiliate'), __('Credits', 'affiliate'), __('Payments', 'affiliate')));
        $newcolumns = apply_filters('affiliate_column_names', $headings);
        if (count($newcolumns) == 6) {
            // We must have 6 columns
            $columns = $newcolumns;
        }
        $reference = get_user_meta($user_ID, 'affiliate_reference', true);
        if (function_exists('is_multisite') && is_multisite() && function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('affiliate/affiliate.php')) {
            $site = aff_get_option('site_name');
            // switch to use new option
            $siteurl = get_blog_option(1, 'home');
            $affiliatelinkurl = aff_get_option('affiliatelinkurl', $siteurl);
        } else {
            $site = aff_get_option('blogname');
            // switch to use new option
            $siteurl = aff_get_option('home');
            $affiliatelinkurl = aff_get_option('affiliatelinkurl', $siteurl);
        }
        if (isset($_POST['action']) && addslashes($_POST['action']) == 'update') {
            //echo "_POST<pre>"; print_r($_POST); echo "</pre>";
            check_admin_referer('affiliatesettings');
            update_user_meta($user_ID, 'enable_affiliate', $_POST['enable_affiliate']);
            update_user_meta($user_ID, 'affiliate_paypal', $_POST['affiliate_paypal']);
            if (!empty($_POST['affiliate_referrer'])) {
                $url = str_replace('http://', '', untrailingslashit($_POST['affiliate_referrer']));
                // store the update - even though it could be wrong
                update_user_meta($user_ID, 'affiliate_referrer', $url);
                // Remove any validated referrers as it may have been changed
                delete_user_meta($user_ID, 'affiliate_referrer_validated');
                // Check for duplicate and if not unique we need to display the open box with an error message
                if ($this->is_duplicate_url($url, $user_ID)) {
                    $error = 'yes';
                    $chkmsg = __('This URL is already in use.', 'affiliate');
                } else {
                    // Create the message we are looking for
                    $chkmsg = '';
                    // Check a file with it exists and contains the content
                    if (defined('AFFILIATE_VALIDATE_REFERRER_URLS') && AFFILIATE_VALIDATE_REFERRER_URLS == 'yes') {
                        $referrer = $_POST['affiliate_referrer'];
                        $filename = md5('affiliatefilename-' . $user_ID . '-' . $user->user_login . "-" . $referrer) . '.html';
                        //echo "filename=[". $filename ."]<br />";
                        if ($this->validate_url_for_file(trailingslashit($url), $filename)) {
                            update_user_meta($user_ID, 'affiliate_referrer_validated', 'yes');
                            $chkmsg = __('Validated', 'affiliate');
                        } else {
                            $error = 'yes';
                            $chkmsg = __('Not validated', 'affiliate');
                        }
                    }
                }
            } else {
                delete_user_meta($user_ID, 'affiliate_referrer_validated');
                delete_user_meta($user_ID, 'affiliate_referrer');
            }
            if (isset($_POST['enable_affiliate']) && addslashes($_POST['enable_affiliate']) == 'yes') {
                // Set up the affiliation details
                // Store a record of the reference
                $reference = aff_build_reference($user);
                update_user_meta($user_ID, 'affiliate_reference', $reference);
                update_user_meta($user_ID, 'affiliate_hash', 'aff' . md5(AUTH_SALT . $reference));
            } else {
                // Wipe the affiliation details
                delete_user_meta($user_ID, 'affiliate_reference');
                delete_user_meta($user_ID, 'affiliate_hash');
            }
        }
        echo "<div class='wrap'>";
        echo '<div class="icon32" id="icon-themes"><br/></div>';
        echo "<h2>" . __('Affiliate Referral Report', 'affiliate') . "</h2>";
        echo "<div style='width: 98%; margin-top: 20px; background-color: #FFFEEB; margin-left: auto; margin-right: auto; margin-bottom: 20px; border: 1px #e6db55 solid; padding: 10px;'>";
        if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
            echo "<strong>" . __('Hello, Thank you for supporting us</strong>, to view or change any of your affiliate settings click on the edit link.', 'affiliate') . "</strong><a href='#view' id='editaffsettingslink' style='float:right; font-size: 8pt;'>" . __('edit', 'affiliate') . "</a>";
            if (empty($error)) {
                echo "<div id='innerbox' style='width: 100%; display: none;'>";
            } else {
                echo "<div id='innerbox' style='width: 100%;'>";
            }
            echo "<form action='' method='post'>";
            wp_nonce_field("affiliatesettings");
            echo "<input type='hidden' name='action' value='update' />";
            $settingstextdefault = __("<p>We love it when people talk about us, and even more so when they recommend us to their friends.</p><p>As a thank you we would like to offer something back, which is why we have set up this affiliate program.</p><p>To get started simply enable the links for your account and enter your PayPal email address below, for more details on our affiliate program please visit our main site.</p>", 'affiliate');
            echo stripslashes(aff_get_option('affiliatesettingstext', $settingstextdefault));
            ?>

				<table class="form-table">
					<tr style='background: transparent;'>
						<th><label for="enable_affiliate"><?php 
            _e('Enable Affiliate links', 'affiliate');
            ?>
</label></th>
						<td>
							<select name='enable_affiliate'>
								<option value='yes' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('Yes please', 'affiliate');
            ?>
</option>
								<option value='no' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) != 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('No thanks', 'affiliate');
            ?>
</option>
							</select>
						</td>
					</tr>

					<tr style='background: transparent;'>
						<th><label for="affiliate_paypal"><?php 
            _e('PayPal Email Address', 'affiliate');
            ?>
</label></th>
						<td>
						<input type="text" name="affiliate_paypal" id="affiliate_paypal" value="<?php 
            echo esc_attr(get_user_meta($user_ID, 'affiliate_paypal', true));
            ?>
" class="regular-text" />
						</td>
					</tr>

				</table>

				<?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
                $reference = get_user_meta($user_ID, 'affiliate_reference', true);
                //echo "reference[". $reference ."]<br />";
                $referrer = get_user_meta($user_ID, 'affiliate_referrer', true);
                //echo "referrer[". $referrer ."]<br />";
                $refurl = "profile.php?page=affiliateearnings";
                $validreferrer = get_user_meta($user_ID, 'affiliate_referrer_validated', true);
                //echo "validreferrer[". $validreferrer ."]<br />";
                ?>
					<p><?php 
                _e('<h3>Affiliate Details</h3>', 'affiliate');
                ?>
</p>
					<p><?php 
                _e('In order for us to track your referrals, you should use the following URL to link to our site:', 'affiliate');
                ?>
</p>
					<p><?php 
                echo sprintf(__('<strong>%s?ref=%s</strong>', 'affiliate'), $affiliatelinkurl, $reference);
                ?>
</p>
					<?php 
                /*
                if(defined('AFFILIATE_CHECKALL') && AFFILIATE_CHECKALL == 'yes' && !empty($referrer)) {
                	// We are always going to check for a referer site
                	?>
                	<p><?php _e('Alternatively you can use the just link directly to the URL below from the site you entered in the advanced settings above:', 'affiliate'); ?></p>
                	<p><?php echo sprintf(__('<strong>%s</strong>', 'affiliate'), $siteurl ); ?></p>
                	<?php
                
                }
                */
                if (aff_get_option('affiliateenablebanners', 'no') == 'yes') {
                    ?>
					<p><?php 
                    echo sprintf(__('If you would rather use a banner or button then we have a wide selection of sizes <a href="%s">here</a>.', 'affiliate'), "profile.php?page=affiliatebanners");
                    ?>
</p>
					<?php 
                }
                ?>
					<?php 
                /* ?><p><?php _e('<strong>You can check on your referral totals by viewing the details on this page</strong>', 'affiliate'); ?></p><?php */
                ?>
					<?php 
                if (defined('AFFILIATE_CHECKALL') && AFFILIATE_CHECKALL == 'yes') {
                    ?>

						<h3><?php 
                    _e('Affiliate Advanced Settings', 'affiliate');
                    ?>
</h3>

						<?php 
                    $advsettingstextdefault = __("<p>There are times when you would rather hide your affiliate link, or simply not have to bother remembering the affiliate reference to put on the end of our URL.</p><p>If this is the case, then you can enter the main URL of the site you will be sending requests from below, and we will sort out the tricky bits for you.</p>", 'affiliate');
                    echo stripslashes(aff_get_option('affiliateadvancedsettingstext', $advsettingstextdefault));
                    if (!empty($chkmsg)) {
                        if (empty($error)) {
                            // valid
                            $msg = "<span style='color: green;'>" . $chkmsg . "</span>";
                        } else {
                            // not valid
                            $msg = "<span style='color: red;'>" . $chkmsg . "</span>";
                        }
                    }
                    ?>

						<table class="form-table">
							<tr style='background: transparent;'>
								<th><label for="affiliate_referrer"><?php 
                    _e('Your URL', 'affiliate');
                    ?>
</label></th>
								<td>
									<?php 
                    echo is_ssl() ? 'https' : 'http';
                    ?>
://&nbsp;<input type="text" name="affiliate_referrer" id="affiliate_referrer" value="<?php 
                    echo esc_attr($referrer);
                    ?>
" class="regular-text" />
									<?php 
                    echo "&nbsp;&nbsp;";
                    if (isset($msg)) {
                        echo $msg;
                    }
                    ?>
									<?php 
                    if (defined('AFFILIATE_VALIDATE_REFERRER_URLS') && AFFILIATE_VALIDATE_REFERRER_URLS == 'yes') {
                        if (empty($referrer) || !empty($validreferrer) && $validreferrer == 'yes') {
                        } else {
                            // Not valid - generate filename
                            $filename = md5('affiliatefilename-' . $user_ID . '-' . $user->user_login . "-" . $referrer) . '.html';
                            // Output message
                            echo "<br/>";
                            _e('You need to validate this URL by uploading a file to the root of the site above with the following name : ', 'affiliate');
                            echo "<br/>";
                            echo __('Filename : ', 'affiliate') . $filename;
                            echo " <a href='http://" . trailingslashit($referrer) . $filename . "' target=_blank>" . __('[click here to check if the file exists]', 'affiliate') . "</a>";
                            echo '<br/><input type="submit" name="Submit" class="button" value="' . __('Validate', 'affiliate') . '" />';
                        }
                    }
                    ?>
								</td>
							</tr>


						</table>
						<?php 
                }
            }
            echo '<p class="submit">';
            echo '<input type="submit" class="button-primary" name="Submit" value="' . __('Update Settings', 'affiliate') . '" /></p>';
            echo "</form>";
            echo "</div>";
        } else {
            // Not an affiliate yet, so display the form
            echo "<strong>" . __('Hello, why not consider becoming an affiliate?', 'affiliate') . "</strong><br/>";
            echo "<div id='innerbox' style='width: 100%'>";
            echo "<form action='' method='post'>";
            wp_nonce_field("affiliatesettings");
            echo "<input type='hidden' name='action' value='update' />";
            $settingstextdefault = __("<p>We love it when people talk about us, and even more so when they recommend us to their friends.</p><p>As a thank you we would like to offer something back, which is why we have set up this affiliate program.</p><p>To get started simply enable the links for your account and enter your PayPal email address below, for more details on our affiliate program please visit our main site.</p>", 'affiliate');
            echo stripslashes(aff_get_option('affiliatesettingstext', $settingstextdefault));
            ?>

				<table class="form-table">
					<tr style='background: transparent;'>
						<th><label for="enable_affiliate"><?php 
            _e('Enable Affiliate links', 'affiliate');
            ?>
</label></th>
						<td>
							<select name='enable_affiliate'>
								<option value='yes' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('Yes please', 'affiliate');
            ?>
</option>
								<option value='no' <?php 
            if (get_user_meta($user_ID, 'enable_affiliate', true) != 'yes') {
                echo "selected = 'selected'";
            }
            ?>
><?php 
            _e('No thanks', 'affiliate');
            ?>
</option>
							</select>
						</td>
					</tr>

					<tr style='background: transparent;'>
						<th><label for="affiliate_paypal"><?php 
            _e('PayPal Email Address', 'affiliate');
            ?>
</label></th>
						<td>
						<input type="text" name="affiliate_paypal" id="affiliate_paypal" value="<?php 
            echo esc_attr(get_user_meta($user_ID, 'affiliate_paypal', true));
            ?>
" class="regular-text" />
						</td>
					</tr>

				</table>

				<?php 
            echo '<p class="submit">';
            echo '<input type="submit" class="button-primary" name="Submit" value="' . __('Update Settings', 'affiliate') . '" /></p>';
            echo "</form>";
            echo "</div>";
        }
        echo "</div>";
        //$results = $this->db->get_results( $this->db->prepare( "SELECT * FROM {$this->affiliatedata} WHERE user_id = %d ORDER BY period DESC", $user_ID ) );
        if (get_user_meta($user_ID, 'enable_affiliate', true) == 'yes') {
            if (isset($_GET['subpage']) && $_GET['subpage'] == "details") {
                echo '<br /><a href="' . esc_url(add_query_arg('subpage', 'summary')) . '">' . __('&larr; Return to Affiliate Period Summary', 'affiliate') . '</a>';
            }
            echo "<div id='affdashgraph' style='width: 100%; margin-top: 20px; min-height: 350px; background-color: #fff; margin-bottom: 20px;'>";
            echo "</div>";
            echo "<div id='clickscolumn' style='width: 48%; margin-right: 2%; margin-top: 20px; min-height: 400px; float: left;'>";
            if (isset($_GET['subpage']) && $_GET['subpage'] == "details") {
                $period = '';
                if (isset($_GET['period'])) {
                    $period = esc_attr($_GET['period']);
                }
                if (!empty($period)) {
                    $period = date('Ym');
                }
                $this->show_users_period_details_table($user_ID, $period);
            } else {
                $this->show_users_period_summary_table($user_ID);
            }
            echo "</div>";
            echo "<div id='referrerscolumn' style='width: 48%; margin-left: 2%; min-height: 400px; margin-top: 20px; background: #fff; float: left;'>";
            do_action('affiliate_before_profile_graphs', $user_ID);
            do_action('affiliate_before_visits_table', $user_ID);
            echo "<div id='affvisitgraph' style='width: 100%; min-height: 350px; background-color: #fff; margin-bottom: 20px;'>";
            echo "</div>";
            // This months visits table
            $rows = $this->db->get_results($this->db->prepare("SELECT * FROM {$this->affiliatereferrers} WHERE user_id = %d AND period = %s ORDER BY referred DESC LIMIT 0, 15", $user_ID, date("Ym")));
            echo "<table class='widefat'>";
            echo "<thead>";
            echo "<tr>";
            echo "<th scope='col'>";
            echo __('Top referrers for ', 'affiliate') . date("M Y");
            echo "</th>";
            echo "<th scope='col' style='width: 3em;'>";
            echo __('Visits', 'affiliate');
            echo "</th>";
            echo "</tr>";
            echo "</thead>";
            echo "<tfoot>";
            echo "<tr>";
            echo "<th scope='col'>";
            echo __('Top referrers for ', 'affiliate') . date("M Y");
            echo "</th>";
            echo "<th scope='col' style='width: 3em;'>";
            echo __('Visits', 'affiliate');
            echo "</th>";
            echo "</tr>";
            echo "</tfoot>";
            echo "<tbody>";
            if (!empty($rows)) {
                $class = 'alternate';
                foreach ($rows as $r) {
                    echo "<tr class='{$class}' style='{$style}'>";
                    echo "<td style='padding: 5px;'>";
                    echo "<a href='http://" . $r->url . "'>" . $r->url . "</a>";
                    echo "</td>";
                    echo "<td style='width: 3em; padding: 5px; text-align: right;'>";
                    echo $r->referred;
                    echo "</td>";
                    echo "</tr>";
                    if ($class != 'alternate') {
                        $class = '';
                    } else {
                        $class = 'alternate';
                    }
                }
            } else {
                echo __('<tr><td colspan="2">You have no referred visits this month.</td></tr>', 'affiliate');
            }
            echo "</tbody>";
            echo "</table>";
            do_action('affiliate_after_visits_table', $user_ID);
            do_action('affiliate_before_topreferrers_table', $user_ID);
            // Top referrers of all time
            // Build 18 months of years
            $startat = strtotime(date("Y-m-15"));
            $years = array();
            for ($n = 0; $n < 18; $n++) {
                $rdate = strtotime("-{$n} month", $startat);
                $years[] = "'" . date('Ym', $rdate) . "'";
            }
            $rows = $this->db->get_results($this->db->prepare("SELECT url, SUM(referred) as totalreferred FROM {$this->affiliatereferrers} WHERE user_id = %d AND period in (" . implode(',', $years) . ") GROUP BY url ORDER BY totalreferred DESC LIMIT 0, 15", $user_ID));
            echo "<br/>";
            echo "<table class='widefat'>";
            echo "<thead>";
            echo "<tr>";
            echo "<th scope='col'>";
            echo __('Top referrers over past 18 months', 'affiliate');
            echo "</th>";
            echo "<th scope='col' style='width: 3em;'>";
            echo __('Visits', 'affiliate');
            echo "</th>";
            echo "</tr>";
            echo "</thead>";
            echo "<tfoot>";
            echo "<tr>";
            echo "<th scope='col'>";
            echo __('Top referrers over past 18 months', 'affiliate');
            echo "</th>";
            echo "<th scope='col' style='width: 3em;'>";
            echo __('Visits', 'affiliate');
            echo "</th>";
            echo "</tr>";
            echo "</tfoot>";
            echo "<tbody>";
            if (!empty($rows)) {
                $class = 'alternate';
                foreach ($rows as $r) {
                    echo "<tr class='{$class}' style='{$style}'>";
                    echo "<td style='padding: 5px;'>";
                    echo "<a href='http://" . $r->url . "'>" . $r->url . "</a>";
                    echo "</td>";
                    echo "<td style='width: 3em; padding: 5px; text-align: right;'>";
                    echo $r->totalreferred;
                    echo "</td>";
                    echo "</tr>";
                    if ($class != 'alternate') {
                        $class = '';
                    } else {
                        $class = 'alternate';
                    }
                }
            } else {
                echo __('<tr><td colspan="2">You have no overall referred visits.</td></tr>', 'affiliate');
            }
            echo "</tbody>";
            echo "</table>";
            echo "</div>";
            do_action('affiliate_after_topreferrers_table', $user_ID);
            do_action('affiliate_after_profile_graphs', $user_ID);
            echo "<div style='clear: both;'></div>";
        }
        ?>

		</div>
		<?php 
    }