コード例 #1
0
/**
 * Renders html for editing all tblSettings field for current user
 *
 * @return nothing
 */
function editUserdataSettings($_userid = '')
{
    global $h;
    if (empty($_userid)) {
        $_userid = $h->session->id;
    }
    $list = readAllUserdata($_userid);
    if (!$list) {
        return;
    }
    echo '<div class="settings">';
    echo xhtmlForm('edit_settings_frm', '', 'post', 'multipart/form-data');
    echo xhtmlHidden('edit_settings_check', 1);
    echo '<table>';
    foreach ($list as $row) {
        if (!empty($_POST['edit_settings_check'])) {
            switch ($row['fieldType']) {
                case USERDATA_TYPE_IMAGE:
                    if (!empty($_POST['userdata_' . $row['fieldId'] . '_remove'])) {
                        $h->files->deleteFile($row['settingValue']);
                        $row['settingValue'] = 0;
                    } else {
                        if (isset($_FILES['userdata_' . $row['fieldId']])) {
                            // FIXME: Gör så att handleUpload klarar av att ta userId som parameter
                            $row['settingValue'] = $h->files->handleUpload($_FILES['userdata_' . $row['fieldId']], FILETYPE_USERDATA, $row['fieldId']);
                        }
                    }
                    break;
                case USERDATA_TYPE_EMAIL:
                    if (empty($_POST['userdata_' . $row['fieldId']])) {
                        break;
                    }
                    if (!is_email($_POST['userdata_' . $row['fieldId']])) {
                        echo '<div class="critical">' . t('The email entered is not valid!') . '</div>';
                    } else {
                        $chk = findUserByEmail($_POST['userdata_' . $row['fieldId']]);
                        if ($chk && $chk != $_userid) {
                            echo '<div class="critical">' . t('The email entered already taken!') . '</div>';
                        } else {
                            $row['settingValue'] = $_POST['userdata_' . $row['fieldId']];
                        }
                    }
                    break;
                case USERDATA_TYPE_BIRTHDATE:
                    if (empty($_POST['userdata_' . $row['fieldId'] . '_year'])) {
                        break;
                    }
                    $born = mktime(0, 0, 0, $_POST['userdata_' . $row['fieldId'] . '_month'], $_POST['userdata_' . $row['fieldId'] . '_day'], $_POST['userdata_' . $row['fieldId'] . '_year']);
                    $row['settingValue'] = sql_datetime($born);
                    break;
                case USERDATA_TYPE_BIRTHDATE_SWE:
                    if (empty($_POST['userdata_' . $row['fieldId'] . '_year'])) {
                        break;
                    }
                    $born = mktime(0, 0, 0, $_POST['userdata_' . $row['fieldId'] . '_month'], $_POST['userdata_' . $row['fieldId'] . '_day'], $_POST['userdata_' . $row['fieldId'] . '_year']);
                    if ($check = SsnValidateSwedishNum($_POST['userdata_' . $row['fieldId'] . '_year'], $_POST['userdata_' . $row['fieldId'] . '_month'], $_POST['userdata_' . $row['fieldId'] . '_day'], $_POST['userdata_' . $row['fieldId'] . '_chk']) === true) {
                        $row['settingValue'] = sql_datetime($born);
                    } else {
                        echo '<div class="critical">' . t('The Swedish SSN you entered is not valid!') . '</div>';
                    }
                    break;
                case USERDATA_TYPE_LOCATION_SWE:
                    if (empty($_POST['userdata_' . $row['fieldId']])) {
                        break;
                    }
                    if (!ZipLocation::isValid($_POST['userdata_' . $row['fieldId']])) {
                        echo '<div class="critical">' . t('The Swedish zipcode you entered is not valid!') . '</div>';
                        $h->session->log('User entered invalid swedish zipcode: ' . $_POST['userdata_' . $row['fieldId']], LOGLEVEL_WARNING);
                    } else {
                        saveSetting(SETTING_USERDATA, 0, $_userid, 'city', ZipLocation::cityId($_POST['userdata_' . $row['fieldId']]));
                        saveSetting(SETTING_USERDATA, 0, $_userid, 'region', ZipLocation::regionId($_POST['userdata_' . $row['fieldId']]));
                        $row['settingValue'] = $_POST['userdata_' . $row['fieldId']];
                    }
                    break;
                default:
                    if (!empty($_POST['userdata_' . $row['fieldId']])) {
                        $row['settingValue'] = $_POST['userdata_' . $row['fieldId']];
                    } else {
                        $row['settingValue'] = '';
                    }
                    break;
            }
            //Stores the setting
            saveSetting(SETTING_USERDATA, 0, $_userid, $row['fieldId'], $row['settingValue']);
        }
        echo '<tr>' . getUserdataInput($row) . '</tr>';
    }
    echo '</table>';
    echo xhtmlSubmit('Save');
    echo xhtmlFormClose();
    echo '</div>';
}
コード例 #2
0
<?php

/**
 * $Id$
 *
 * Returns XHTML block for city selection
 */
require_once 'find_config.php';
if (!$h->session->id || empty($_GET['i']) || !is_numeric($_GET['i'])) {
    die('bad');
}
echo ZipLocation::citySelect($_GET['i']);