public function get_content()
    {
        global $CFG;
        if ($this->content !== null) {
            return $this->content;
        }
        $this->content = new stdClass();
        $this->content->text = '';
        $this->content->footer = '';
        if (empty($this->instance)) {
            print_error('No instance ' . 'block_mailchimp');
        }
        $permissions = \block_mailchimp\helper::get_permission();
        // Make sure the correct settings are set.
        if (!isset($CFG->block_mailchimp_apicode) || !isset($CFG->block_mailchimp_linked_profile_field) || !isset($CFG->block_mailchimp_listid)) {
            $this->content->text .= get_string('not_setup_yet', 'block_mailchimp');
            return false;
        }
        if ($permissions['administration']) {
            // Global block settings.
            $url = "{$CFG->wwwroot}/admin/settings.php?section=blocksettingmailchimp";
            $this->content->text .= "<br /><a href='{$url}'>" . get_string('goto_settings', 'block_mailchimp') . "</a><br />";
        }
        $isregistered = \block_mailchimp\helper::is_mailchimp_registered_user($CFG->block_mailchimp_linked_profile_field);
        $submitbutton = !$isregistered ? 'subscribe' : 'unsubscribe';
        $welcometxtid = $isregistered ? 'welcome_txt_subscribed' : 'welcome_txt_unsubscribed';
        if (isloggedin() && !isguestuser()) {
            // Now time to start outputting the info.
            $this->content->text .= get_string($welcometxtid, 'block_mailchimp');
            $this->content->text .= '
            <div id="mailchimp">
            <form name="process_mailchimp" method="POST" action="' . $CFG->wwwroot . '/blocks/mailchimp/view/register.php">
                <input type="hidden" name="sourcePage" value="' . $_SERVER['PHP_SELF'] . '" />
                <input type="hidden" name="submit" value="true" />

                <input type="submit" name="process_mailchimp" value="' . get_string($submitbutton, 'block_mailchimp') . '" />
            </form>
            </div>';
        }
    }
}
$issubmitted = optional_param('submit', 'false', PARAM_ALPHA);
$sourcepage = required_param('sourcePage', PARAM_RAW);
if ($issubmitted != "true") {
    // Simple checking if the sourcePage at least contains the source domainname.
    if (stristr($CFG->wwwroot, $sourcepage)) {
        redirect($sourcepage);
    } else {
        redirect(new moodle_url("/"));
    }
}
// Kill off if we're missing something.
if (!isset($CFG->block_mailchimp_apicode) || !isset($CFG->block_mailchimp_listid) || !isset($CFG->block_mailchimp_linked_profile_field)) {
    print_error('missing_config_settings', 'block_mailchimp');
}
$actionregister = !\block_mailchimp\helper::is_mailchimp_registered_user($CFG->block_mailchimp_linked_profile_field);
// Now lets call for the records we're going to work with.
$usertoprocess = $DB->get_record('block_mailchimp_users', array('userid' => $USER->id));
$params = array('fieldid' => $CFG->block_mailchimp_linked_profile_field, 'userid' => $USER->id);
$profilefieldtoprocess = $DB->get_record('user_info_data', $params);
if (!$usertoprocess) {
    $userparams = new stdClass();
    $userparams->userid = $USER->id;
    $userparams->email = $USER->email;
    $userparams->registered = $actionregister ? 1 : 0;
    $userparams->timecreated = time();
    $userparams->timemodified = time();
    $DB->insert_record('block_mailchimp_users', $userparams);
    $usertoprocess = $DB->get_record('block_mailchimp_users', array('userid' => $USER->id));
} else {
    $usertoprocess->registered = $actionregister;