Esempio n. 1
0
function show_profile_edit_form($db)
{
    //require 'CUsers.php';
    // Get information of logged user.
    $cUsers = new CUsers($db);
    $ret = $cUsers->getUserInfo($_SESSION['id']);
    // Create birthdate in correct format.
    $tmp = explode('-', $ret[0]['birthdate']);
    $ret[0]['birthdate'] = $tmp[2] . '.' . $tmp[1] . '.' . $tmp[0];
    // Fields to add in form
    $fields = array('id' => 'hidden', 'firstname' => 'text', 'lastname' => 'text', 'city' => 'text', 'homepage' => 'text', 'birthdate' => 'text', 'email' => 'text', 'password' => 'password', 'password_again' => 'password');
    // Field names
    $field_names = array('firstname' => 'Etunimi', 'lastname' => 'Sukunimi', 'password' => 'Salasana', 'password_again' => 'Salasana uudelleen', 'city' => 'Kaupunki', 'homepage' => 'Kotisivu', 'birthdate' => 'Syntymäpäivä (pv.kk.vvvv)', 'email' => 'Sähköposti');
    echo '<div class="edit_profile">';
    // Show message if there is any.
    // For example message will be shown if user has changed
    // his/her profile.
    show_message();
    echo '<form action="edit_profile.php" method="post">';
    echo '<table>';
    // Add every field in the form.
    foreach ($fields as $key => $value) {
        echo '<tr>';
        // We do not want add empty input boxes for hidden values!
        if ($value != 'hidden') {
            echo '<td>';
            echo $field_names[$key];
            echo '</td>';
            echo '<td>';
            // If text field is other than password, then we
            // should get user information as an default value.
            if ($key != 'password' && $key != 'password_again') {
                // If we are going to show birthdate, let's check
                // if it is empty value, eg. 00.00.0000. If it is,
                // then we want to show just empty string instead
                // of that 00.00.0000.
                if ($key == 'birthdate' && $ret[0][$key] == '00.00.0000') {
                    $ret[0][$key] = '';
                }
                echo '<input type="' . $value . '" value="' . $ret[0][$key] . '" name="' . $key . '">';
            } else {
                echo '<input type="' . $value . '" name="' . $key . '">';
            }
            echo '</td>';
        }
        echo '</tr>';
    }
    // "Päivitä tiedot" -button.
    echo '<tr>';
    echo '<td colspan="2">';
    echo '<input type="submit" value="Päivitä">';
    echo '</td>';
    echo '</tr>';
    echo '</table>';
    echo '<div class="bottom_note">';
    echo 'Huom! Jos jätät salasanakentät tyhjäksi, salasana ' . 'pysyy muuttamattomana!';
    echo '</div>';
    echo '</form>';
    echo '</div>';
}
Esempio n. 2
0
function show_poet_information($db, $data)
{
    $cUsers = new CUsers($db);
    echo '<div class="poet_info">';
    echo '<div class="textblock">';
    echo '<h3>Runoilijan tiedot</h3>';
    echo '</div>';
    // Get user ID.
    if (isset($data['id'])) {
        $id = mysql_real_escape_string($data['id']);
    } else {
        echo 'Käyttäjän ID:tä ei olla annettu!';
    }
    $ret = $cUsers->getUserInfo($id);
    // Fields to add in form
    $fields = array('username' => 'Käyttäjätunnus', 'firstname' => 'Etunimi', 'lastname' => 'Sukunimi', 'city' => 'Kaupunki', 'homepage' => 'Kotisivu', 'birthdate' => 'Syntymäpäivä', 'email' => 'Sähköposti', 'num_poems' => 'Runoja');
    // Count number of poems
    $cPoem = new CPoem($db, $_SESSION);
    if ($_SESSION['id'] == $id) {
        $ret[0]['num_poems'] = $cPoem->numPoems($ret[0]['id'], true);
    } else {
        $ret[0]['num_poems'] = $cPoem->numPoems($ret[0]['id'], false);
    }
    echo '<table>';
    foreach ($ret[0] as $key => $value) {
        // Convert birthdate to correct format
        if ($key == 'birthdate' && $value != '') {
            $tmp = explode('-', $value);
            $value = $tmp[2] . '.' . $tmp[1] . '.' . $tmp[0];
        }
        // Show only fields what are listed in array $fiels
        if (isset($fields[$key])) {
            echo '<tr>';
            echo '<td>';
            echo $fields[$key];
            echo '</td>';
            echo '<td>';
            echo $value;
            echo '</td>';
            echo '</tr>';
        }
    }
    echo '</table>';
    // Link back to poems
    echo '<div class="back_to_poems">';
    echo '<a href="poet.php?id=' . $ret[0]['id'] . '">' . 'Takaisin runoilijan runoihin</a>';
    echo '</div>';
    echo '</div>';
}