<?php

require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php";
global $CONFIG;
// block non-admin users
admin_gatekeeper();
action_gatekeeper();
// Get the user
$guid = get_input('guid');
$obj = get_entity($guid);
if ($obj instanceof ElggUser && $obj->canEdit()) {
    set_user_validation_status($guid, true, 'admin');
    system_message(elgg_echo('siteaccess:admin:validate:success'));
    siteaccess_notify_user($obj, 'admin_activated');
    siteaccess_add_to_river($obj, 'admin');
} else {
    register_error(elgg_echo('siteaccess:admin:validate:error'));
}
forward($_SERVER['HTTP_REFERER']);
exit;
<?php

global $CONFIG;
// Get user id
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$user_guid = (int) get_input('u');
$user = get_entity($user_guid);
// And the code
$code = sanitise_string(get_input('c'));
if ($code && $user) {
    if (siteaccess_validate_email($user_guid, $code)) {
        system_message(elgg_echo('siteaccess:confirm:success'));
        siteaccess_notify_user($user, 'validated');
    } else {
        register_error(elgg_echo('siteaccess:confirm:fail'));
    }
} else {
    register_error(elgg_echo('siteaccess:confirm:fail'));
}
access_show_hidden_entities($access_status);
forward();
exit;
function siteaccess_email_validation($user_guid)
{
    global $CONFIG;
    $user = get_entity($user_guid);
    if ($user && $user instanceof ElggUser) {
        // Send validation email
        $result = siteaccess_notify_user($user, 'confirm');
        if ($result) {
            system_message(elgg_echo('siteaccess:confirm:email'));
        }
        return $result;
    }
    return false;
}