function register_form_check($user_id)
{
    $_POST['reg_home_page'] = sanitize_url(trim($_POST['reg_home_page']));
    $_POST['reg_user_image'] = !empty($_POST['reg_user_image']) ? sanitize_url(trim($_POST['reg_user_image'])) : '';
    if (!empty($_POST['reg_icq']) && !(int) $_POST['reg_icq']) {
        /* ICQ # can only be an integer */
        $_POST['reg_icq'] = '';
    }
    /* Image count check */
    if ($GLOBALS['FORUM_IMG_CNT_SIG'] && $GLOBALS['FORUM_IMG_CNT_SIG'] < substr_count(strtolower($_POST['reg_sig']), '[img]')) {
        set_err('reg_sig', 'Stai cercando di utilizzare nella tua signature più immagini delle ' . $GLOBALS['FORUM_IMG_CNT_SIG'] . ' consentite.');
    }
    /* Url Avatar check */
    if (!empty($_POST['reg_avatar_loc']) && !($GLOBALS['reg_avatar_loc_file'] = fetch_img($_POST['reg_avatar_loc'], $user_id))) {
        set_err('avatar', 'L&#39;URL che hai inserito non contiene un&#39;immagine valida');
    }
    /* Alias Check */
    if ($GLOBALS['FUD_OPT_2'] & 128 && isset($_POST['reg_alias'])) {
        if ($_POST['reg_alias'] = trim(sanitize_login($_POST['reg_alias']))) {
            if (strlen($_POST['reg_alias']) > $GLOBALS['MAX_LOGIN_SHOW']) {
                $_POST['reg_alias'] = substr($_POST['reg_alias'], 0, $GLOBALS['MAX_LOGIN_SHOW']);
            }
            if (q_singleval("SELECT id FROM phpgw_fud_users WHERE alias='" . addslashes(htmlspecialchars($_POST['reg_alias'])) . "' AND id!=" . $user_id)) {
                set_err('reg_alias', 'Username già utilizzato');
            }
        }
    }
    if ($GLOBALS['FORUM_SIG_ML'] && strlen($_POST['reg_sig']) > $GLOBALS['FORUM_SIG_ML']) {
        set_err('reg_sig', 'Your signature exceeds the maximum allowed length of ' . $GLOBALS['FORUM_SIG_ML'] . ' characters characters.');
    }
    return $GLOBALS['error'];
}
function check_femail_form()
{
    if (empty($_POST['femail']) || validate_email($_POST['femail'])) {
        set_err('femail', 'Please enter a valid email address of your friend.');
    }
    if (empty($_POST['subj'])) {
        set_err('subj', 'You cannot send an email without a subject.');
    }
    if (empty($_POST['body'])) {
        set_err('body', 'You cannot send an email without the message body.');
    }
    return $GLOBALS['__error__'];
}
function register_form_check($user_id)
{
    $_POST['reg_home_page'] = sanitize_url(trim($_POST['reg_home_page']));
    $_POST['reg_user_image'] = !empty($_POST['reg_user_image']) ? sanitize_url(trim($_POST['reg_user_image'])) : '';
    if (!empty($_POST['reg_icq']) && !(int) $_POST['reg_icq']) {
        /* ICQ # can only be an integer */
        $_POST['reg_icq'] = '';
    }
    /* Image count check */
    if ($GLOBALS['FORUM_IMG_CNT_SIG'] && $GLOBALS['FORUM_IMG_CNT_SIG'] < substr_count(strtolower($_POST['reg_sig']), '[img]')) {
        set_err('reg_sig', 'You are trying to use more then the allowed ' . $GLOBALS['FORUM_IMG_CNT_SIG'] . ' images in your signature.');
    }
    /* Url Avatar check */
    if (!empty($_POST['reg_avatar_loc']) && !($GLOBALS['reg_avatar_loc_file'] = fetch_img($_POST['reg_avatar_loc'], $user_id))) {
        set_err('avatar', 'The specified url does not contain a valid image');
    }
    /* Alias Check */
    if ($GLOBALS['FUD_OPT_2'] & 128 && isset($_POST['reg_alias'])) {
        if ($_POST['reg_alias'] = trim(sanitize_login($_POST['reg_alias']))) {
            if (strlen($_POST['reg_alias']) > $GLOBALS['MAX_LOGIN_SHOW']) {
                $_POST['reg_alias'] = substr($_POST['reg_alias'], 0, $GLOBALS['MAX_LOGIN_SHOW']);
            }
            if (q_singleval("SELECT id FROM phpgw_fud_users WHERE alias='" . addslashes(htmlspecialchars($_POST['reg_alias'])) . "' AND id!=" . $user_id)) {
                set_err('reg_alias', 'The alias you are trying to use is already in use by another forum member, please choose another.');
            }
        }
    }
    if ($GLOBALS['FORUM_SIG_ML'] && strlen($_POST['reg_sig']) > $GLOBALS['FORUM_SIG_ML']) {
        set_err('reg_sig', 'Your signature exceeds the maximum allowed length of ' . $GLOBALS['FORUM_SIG_ML'] . ' characters characters.');
    }
    return $GLOBALS['error'];
}
function check_femail_form()
{
    if (empty($_POST['femail']) || validate_email($_POST['femail'])) {
        set_err('femail', 'Inserisci un indirizzo email valido.');
    }
    if (empty($_POST['subj'])) {
        set_err('subj', 'Non puoi spedire una email lasciando vuoto il campo Oggetto.');
    }
    if (empty($_POST['body'])) {
        set_err('body', 'Non puoi spedire una email lasciando vuoto il campo Testo.');
    }
    return $GLOBALS['__error__'];
}
function mail_check()
{
    $GLOBALS['error'] = 0;
    if (!strlen(trim($_POST['tx_body']))) {
        set_err('tx_body', 'The body is required');
    }
    if (!strlen(trim($_POST['tx_subject']))) {
        set_err('tx_subject', 'Subject is required');
    }
    if (!strlen(trim($_POST['tx_name']))) {
        set_err('tx_name', 'Name is required');
    } else {
        if (!q_singleval("SELECT id FROM phpgw_fud_users WHERE alias='" . addslashes(htmlspecialchars($_POST['tx_name'])) . "'")) {
            set_err('tx_name', 'Invalid user');
        }
    }
    return $GLOBALS['error'];
}
function mail_check()
{
    $GLOBALS['error'] = 0;
    if (!strlen(trim($_POST['tx_body']))) {
        set_err('tx_body', 'Il campo testo è obbligatorio');
    }
    if (!strlen(trim($_POST['tx_subject']))) {
        set_err('tx_subject', 'Oggetto è obbligatorio');
    }
    if (!strlen(trim($_POST['tx_name']))) {
        set_err('tx_name', 'Nome è obbligatorio');
    } else {
        if (!q_singleval("SELECT id FROM phpgw_fud_users WHERE alias='" . addslashes(htmlspecialchars($_POST['tx_name'])) . "'")) {
            set_err('tx_name', 'Utente non corretto');
        }
    }
    return $GLOBALS['error'];
}