summaryrefslogtreecommitdiff
path: root/htdocs/moderate/schedule/editor.php
blob: 69dabe141789147c5a40e10bbab821e7bf2f5e38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

/* Foursquare Community Site
 * 
 * Copyright (C) 2011 Foursquare Church.
 * 
 * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
 *
 */

require_once('../../src/base.inc.php');

// Verify User is admin
if (!isset($_SESSION['currentUser'])) {
    header('Location: ' . buildUrl('moderate/'));
    exit;
}

$error = '';

// Get the current user object.
$user = new User();
if (isset($_GET['id']) and is_numeric($_GET['id'])) {
    $user = User::getById($_GET['id']);
}

// Save changes?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Name
    if (isset($_POST['name']) and trim($_POST['name']) != '') {
        $user->setName($_POST['name']);

    } else {
        $error .= '<p>Name is a required field.</p>';
    }

    // Email
    if (isset($_POST['email']) and trim($_POST['email']) != '') {
        $user->setEmail($_POST['email']);

    } else {
        $error .= '<p>Email is a required field.</p>';
    }

    // Source
    if (isset($_POST['source']) and trim($_POST['source']) != '') {
        $user->setSource($_POST['source']);

    } else {
        $error .= '<p>Source is a required field.</p>';
    }

    // Set Admin
    $admin = isset($_POST['admin']) and $_POST['admin'] == '1';
    $user->setAdmin($admin);

    // Set Notify
    $notify = isset($_POST['notify']) and $_POST['notify'] == '1';
    $user->setNotify($notify);

    // Send new password
    if (isset($_POST['newpass']) and $_POST['newpass'] == '1') {
        $user->sendNewPassword();
    }

    // Save the user
    if ($error == '') {
        if ($user->save()) {
            // Return to users list
            header("Location: index.php");

        } else {
            $error .= '<p>An error has occured.</p>';
        }
    }
}

require_once('../src/header.inc.php');

echo "<h3>Add Exception</h3>";

if ($error != '') {
    echo "<div class=\"errorbox\">$error</div>";
}

$url = "editor.php";

echo "<form action=\"$url\" method=\"post\">";

?>

<p><label>Date: <input type="text" name="date" value="<?= $date ?>" /></label></p>
<p><label>Substitute: <?php usersDropdown('substitute', $substitute); ?></label></p>

<p>
<input type="submit" class="bigbutton" value="Save" />
<a href="index.php" class="bigbutton">Cancel</a>
</p>


</form>

<?php

function usersDropdown($name, $select) {
    echo "<select name=\"$name\">";

    $ui = new UserIterator();
    $ui->query();

    foreach($ui as $user) {
        if ($user->getId() == $select) {
            echo "<option value=\"". $user->getId()
                ."\" selected=\"selected\">"
                . $user->getName() ."</option>";

        } else {
            echo "<option value=\"". $user->getId() ."\">"
                . $user->getName() ."</option>";
        }
    }

    echo "</select>";
}

require_once('../src/footer.inc.php');

?>