Skip to content

Commit b06495a

Browse files
committed
more twig work
1 parent 63c41b2 commit b06495a

7 files changed

+17
-42
lines changed

index.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
1515

1616
$page = $_REQUEST['page'] ?? '';
17-
$file = "pages/$page.php";
1817

1918
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
2019
use Symfony\Component\Form\Forms;
@@ -33,16 +32,15 @@
3332
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
3433

3534
try {
35+
$file = "pages/$page.php";
3636
if (ctype_alpha($page) && file_exists($file)) {
3737
require $file;
38-
} else {
39-
require 'pages/main.php';
4038
}
4139
} catch (PDOException $e) {
4240
if (IN_PRODUCTION) {
43-
echo "<p>Error while accessing the DB</p>";
41+
terminate('Error while accessing the DB');
4442
} else {
45-
echo "<pre>", htmlspecialchars(print_r($e, true)), "</pre>";
43+
terminate(print_r($e, true));
4644
}
4745
}
4846

@@ -86,7 +84,7 @@ function terminate($error_message = null) {
8684
['phpinfo', 'PHP Info', ROLE_PROF],
8785
];
8886
$navbar = [];
89-
$title = '';
87+
$title = 'Welcome';
9088

9189
foreach ($pages as $p) {
9290
if ($p[0] === $page)
@@ -147,6 +145,7 @@ function filter_by($filters) {
147145
? db_fetch_shift_id($selected_shift) : null;
148146

149147
if (in_array('year', $filters)) {
148+
$years = [];
150149
foreach (db_get_group_years() as $year) {
151150
$years[$year['year']] = $year['year'];
152151
}

pages/editpatch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
}
3232

33-
handle_form($patch, [], $readonly, ['group', 'status', 'type'], null, false);
33+
handle_form($patch, [], $readonly, ['group', 'status', 'type']);
3434

3535
if (auth_at_least(ROLE_PROF)) {
3636
$link = dolink('rmpatch', 'Delete', ['id' => $patch->id]);

pages/main.php

-5
This file was deleted.

pages/phpinfo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// Distributed under the MIT license that can be found in the LICENSE file.
44

55
auth_require_at_least(ROLE_PROF);
6-
76
phpinfo();
7+
exit();

pages/profile.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@
66
handle_form($user, [], [], ['repository_user']);
77

88
if ($u = $user->getRepoUser()) {
9-
echo "<p>User data:</p><ul>";
10-
$data = [
11-
"Username" => '<a style="color: white" href="' . $u->profileURL() . '">' .
12-
$u->username() . '</a>',
9+
$info_box['title'] = 'User data';
10+
$info_box['rows'] = [
11+
"Username" => dolink_ext($u->profileURL(), $u->username()),
1312
"Platform" => $u->platform(),
1413
"Name" => $u->name(),
1514
"Email" => $u->email(),
1615
"Company" => $u->company(),
1716
"Location" => $u->location(),
1817
];
19-
foreach ($data as $k => $v) {
20-
if ($v)
21-
echo "<li><b>$k</b>: $v</li>";
22-
}
23-
echo '</ul>';
2418
}

pages/shifts.php

-15
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
auth_require_at_least(ROLE_PROF);
66

7-
html_header('Shifts');
8-
97
$year = get_current_year();
108
$shifts = db_fetch_shifts($year);
119
$profs = db_get_all_profs(true);
@@ -24,19 +22,9 @@
2422
echo "<p>Saved!</p>";
2523
}
2624

27-
$url = htmlspecialchars($_SERVER['REQUEST_URI']);
28-
29-
echo <<<EOF
30-
<form action="$url" method="post">
31-
<input type="hidden" name="submit" value="1">
32-
<table>
33-
<tr><td>Shift</td>
34-
EOF;
35-
3625
foreach ($profs as $prof) {
3726
echo "<td>{$prof->shortName()}</td>";
3827
}
39-
echo "</tr>\n";
4028

4129
foreach ($shifts as $shift) {
4230
echo "<tr><td>", htmlspecialchars($shift->name), "</td>";
@@ -47,7 +35,4 @@
4735
echo "<td><input type=\"radio\" name=\"shift_$shift->id\" value=\"",
4836
htmlspecialchars($prof->id), "\"$selected></td>";
4937
}
50-
echo "</tr>\n";
5138
}
52-
53-
echo "</table><p><input type=\"submit\"></p></form>\n";

templates.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function format_text($text) {
4747
}
4848

4949
function handle_form(&$obj, $hide_fields, $readonly, $only_fields = null,
50-
$extra_buttons = null, $flush_db = true) {
50+
$extra_buttons = null) {
5151
global $form, $formFactory, $request, $success_message;
5252
$form = $formFactory->createBuilder(FormType::class);
5353

@@ -56,6 +56,11 @@ function handle_form(&$obj, $hide_fields, $readonly, $only_fields = null,
5656

5757
$not_all_readonly = false;
5858

59+
// get_object_vars doesn't trigger lazy loading; force it here
60+
if (method_exists($obj, '__isInitialized') && !$obj->__isInitialized()) {
61+
$obj->__load();
62+
}
63+
5964
foreach (get_object_vars($obj) as $name => $orig_value) {
6065
if (in_array($name, $hide_fields) ||
6166
($only_fields && !in_array($name, $only_fields)))
@@ -202,10 +207,7 @@ function handle_form(&$obj, $hide_fields, $readonly, $only_fields = null,
202207
$str .= "\n$print_name: " . $error->getMessage();
203208
}
204209
terminate($str);
205-
} else {
206-
if ($flush_db)
207-
db_flush();
208-
$success_message = 'Database updated!';
209210
}
211+
$success_message = 'Database updated!';
210212
}
211213
}

0 commit comments

Comments
 (0)