-
Notifications
You must be signed in to change notification settings - Fork 3
/
edit_sections.php
123 lines (95 loc) · 3.86 KB
/
edit_sections.php
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
<?php
/*
Martial Arts Tournament System (MATS)
Copyright (C) 2015 David Ball (davidmichaelball @ gmail . com) and Ruth Schulz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
require_once('../../tournament_settings.php');
require '../libs/Smarty.class.php';
$smarty = new Smarty;
require 'loginlogout.php';
require 'configDB.php';
if ($user_access != "admin") {
$smarty->display('denied.tpl');
exit;
}
$smarty->assign('current_menu', "Admin");
require 'utility.php';
$delete_success = false;
echo "<br><br><br><br>";
if(isset($_POST["Submit"])) {
if ($_POST["ID"] == "new") {
$section = DB_DataObject::factory('sections');
$section->name = strip_tags($_POST["Name"]);
$section->part = strip_tags($_POST["Part"]);
$section->tournament_id = $active_tournament->tournament_id;
$section->date = $_POST["Date_Year"]."-".$_POST["Date_Month"]."-".$_POST["Date_Day"];
if (!($new_id = $section->insert())) {
$primary = "section has not been added.";
$smarty->assign(array('primary' => $primary, 'level' => "error"));
} else {
$primary = "section (".$new_id.") has been added.";
$smarty->assign(array('primary' => $primary, 'level' => "success"));
}
} else {
$section = DB_DataObject::factory('sections');
$section->get($_POST["ID"]);
$section->tournament_id = $active_tournament->tournament_id;
$section->name = strip_tags($_POST["Name"]);
$section->part = strip_tags($_POST["Part"]);
$section->date = $_POST["Date_Year"]."-".$_POST["Date_Month"]."-".$_POST["Date_Day"];
if (!$section->update()) {
$primary = "section (".$_POST["ID"].") has not been updated";
$smarty->assign(array('primary' => $primary, 'level' => "error"));
} else {
$primary = "section (".$_POST["ID"].") has been updated";
$smarty->assign(array('primary' => $primary, 'level' => "success"));
}
}
} elseif (isset($_POST["Delete"])) {
$section = DB_DataObject::factory('sections');
$section->get($_POST["ID"]);
if (!$section->delete()) {
$primary = "section (".$_POST["ID"].") has not been deleted";
$smarty->assign(array('primary' => $primary, 'level' => "error"));
} else {
$delete_success = true;
$primary = "section (".$_POST["ID"].") has been deleted";
$smarty->assign(array('primary' => $primary, 'level' => "success"));
}
}
if (isset($_POST["Delete"]) && $delete_success == true) {
$smarty->assign('delete_success', $delete_success);
} elseif (isset($_GET["ID"]) && $_GET["ID"] == "new") {
$command = "Enter details for a new section.";
$smarty->assign("command", $command);
$smarty->assign('section', array('ID' => "new"));
} else {
$command = "Edit details and submit or delete.";
$smarty->assign("command", $command);
$section = DB_DataObject::factory('sections');
if (isset($_POST["ID"]) && $_POST["ID"] == "new") {
$section->section_id = $new_id;
} else {
$section->section_id = $_REQUEST["ID"];
}
$section->find();
$section->fetch();
$smarty->assign('section', array(
'ID' => $section->section_id,
'NAME' => $section->name,
'DATE' => $section->date,
'PART' => $section->part,
));
}
$smarty->display('edit_sections.tpl');
?>