Ejemplo n.º 1
0
function change()
{
    global $tpl, $login;
    if (isset($_REQUEST['cancel'])) {
        $tpl->redirect('myprofile.php');
    }
    $user = new user($login->userid);
    assignFromUser($user);
    $bError = false;
    // set user properties
    if (isset($_REQUEST['username'])) {
        $tpl->assign('username', $_REQUEST['username']);
        if (!$user->setUsername($_REQUEST['username'])) {
            $tpl->assign('usernameErrorInvalidChars', true);
            $bError = true;
        }
    }
    if (isset($_REQUEST['firstName'])) {
        $tpl->assign('firstName', $_REQUEST['firstName']);
        if (!$user->setFirstName($_REQUEST['firstName'])) {
            $tpl->assign('firstNameError', true);
            $bError = true;
        }
    }
    if (isset($_REQUEST['lastName'])) {
        $tpl->assign('lastName', $_REQUEST['lastName']);
        if (!$user->setLastName($_REQUEST['lastName'])) {
            $tpl->assign('lastNameError', true);
            $bError = true;
        }
    }
    if (isset($_REQUEST['country'])) {
        $tpl->assign('countryCode', $_REQUEST['country']);
        if (!$user->setCountryCode($_REQUEST['country'] == 'XX' ? null : $_REQUEST['country'])) {
            $tpl->assign('countryError', true);
            $bError = true;
        }
    }
    if (isset($_REQUEST['notifyRadius'])) {
        $tpl->assign('notifyRadius', $_REQUEST['notifyRadius']);
        if (!$user->setNotifyRadius($_REQUEST['notifyRadius'])) {
            $tpl->assign('notifyRadiusError', true);
            $bError = true;
        }
    }
    $coord['lat'] = coordinate::parseRequestLat('coord');
    $coord['lon'] = coordinate::parseRequestLon('coord');
    if ($coord['lat'] !== false && $coord['lon'] !== false) {
        $tpl->assign('coordsDecimal', $coord);
        if (!$user->setLatitude($coord['lat'])) {
            $tpl->assign('latitudeError', true);
            $bError = true;
        }
        if (!$user->setLongitude($coord['lon'])) {
            $tpl->assign('longitudeError', true);
            $bError = true;
        }
    }
    $bUsePMR = isset($_REQUEST['save']) ? isset($_REQUEST['usePMR']) : $user->getUsePMR();
    $tpl->assign('usePMR', $bUsePMR);
    $user->setUsePMR($bUsePMR);
    $bPermanentLogin = isset($_REQUEST['save']) ? isset($_REQUEST['permanentLogin']) : $user->getPermanentLogin();
    $tpl->assign('permanentLogin', $bPermanentLogin);
    $user->setPermanentLogin($bPermanentLogin);
    $bNoHTMLEditor = isset($_REQUEST['save']) ? isset($_REQUEST['noHTMLEditor']) : $user->getNoHTMLEditor();
    $tpl->assign('noHTMLEditor', $bNoHTMLEditor);
    $user->setNoHTMLEditor($bNoHTMLEditor);
    if (!$bError && isset($_REQUEST['save'])) {
        if ($user->getAnyChanged()) {
            if (!$user->save()) {
                $bError = true;
                // check for duplicate username
                if ($user->getUsernameChanged() && user::existUsername($_REQUEST['username'])) {
                    $tpl->assign('errorUsernameExist', true);
                } else {
                    $tpl->assign('errorUnknown', true);
                }
            } else {
                $tpl->redirect('myprofile.php');
            }
        } else {
            $tpl->redirect('myprofile.php');
        }
    }
    $showAllCountries = isset($_REQUEST['showAllCountries']) ? $_REQUEST['showAllCountries'] + 0 : 0;
    if (isset($_REQUEST['showAllCountriesSubmit'])) {
        $showAllCountries = 1;
    }
    $countriesList = new countriesList();
    $rs = $countriesList->getRS($user->getCountryCode(), $showAllCountries != 0);
    $tpl->assign_rs('countries', $rs);
    sql_free_result($rs);
    if ($countriesList->defaultUsed() == true) {
        $showAllCountries = 0;
    } else {
        $showAllCountries = 1;
    }
    $tpl->assign('showAllCountries', $showAllCountries);
    $tpl->assign('edit', true);
    $tpl->display();
}