-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_project.php
373 lines (368 loc) · 15.5 KB
/
edit_project.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php
include 'core/init.php';
include 'includes/check_connect.php';
protect_page();
$project_id = $activeProject['project_id'];
if ($project_id == 0) { //redirects if there's no active project for the user (if they've not created one)
header("Location: new_project.php");
exit;
}
if (isset($_POST['restore_character'])) {
$character_id = (int)$_POST['restore_character'];
mysql_query("UPDATE `characters` SET `deleted` = 0 WHERE `character_id` = " . $character_id);
}
$factions = get_project_factions($project_id);
$character_data = get_project_characters($project_id);
$deleted_characters = array();
$deleted_factions = array();
foreach ($character_data as $faction_num => $faction) {
if (isset($factions[$faction_num]) && $factions[$faction_num]['deleted']) {
$deleted_factions[$faction_num] = $faction;
unset($character_data[$faction_num]);
continue;
}
foreach ($faction as $key => $character) {
if ($character['deleted']) {
$deleted_characters[$faction_num][$key] = $character;
unset($character_data[$faction_num][$key]);
}
}
}
if ( ! empty($_POST)) {
$required_fields = array('project_name', 'faction_1', 'faction_2'); // can add other fields here later
foreach($_POST as $key => $value) { //checks for required fields
if (empty($value) && in_array($key, $required_fields)){
$errors[] = 'Fields marked with an asterisk are required.';
break;
}
}
}
$new_project = false;
if (isset($_SESSION['new-project'])) {
$new_project = true;
unset($_SESSION['new-project']);
}
if (isset($_GET['action'])) {
$type = '';
$id = null;
$action = $_GET['action'];
if (isset($_GET['type'])) {
$type = $_GET['type'];
}
if (isset($_GET['id'])) {
$id = (int)$_GET['id'];
}
$result = null;
switch ($action) {
case 'restore':
case 'delete':
if ($type == 'character') {
$result = call_user_func($action . "_" . $type . "_by_id", $id);
if ($result) {
echo json_encode("success");
} else {
echo json_encode("error");
}
exit;
} else {
$result = call_user_func($action . "_" . $type . "_by_id", $id);
if ($result) {
$_SESSION['edit-project-save-message'] = "Faction " . $action ."d sucessfully";
} else {
$result = true;
$_SESSION['edit-project-save-message'] = "There was a problem with that action.";
}
}
break;
case 'get-names':
if (isset($_GET['name-count'])) {
$name_count = $_GET['name-count'];
$names = get_random_names($name_count);
echo json_encode($names);
exit;
}
break;
case 'add-faction':
$result = project_add_faction($project_id);
if ($result) {
$_SESSION['edit-project-save-message'] = "New faction added. Character names auto-filled.";
} else {
$result = true;
$_SESSION['edit-project-save-message'] = "There was a problem adding a new faction.";
}
break;
case 'save-form':
if ( ! empty($errors)) {
break;
}
$result = true;
$saveData = array();
if (trim($_POST['project_name']) != $activeProject['project_name']) {
$saveData['project_name'][$activeProject['project_id']] = trim($_POST['project_name']);
}
foreach ($_POST['names'] as $faction_num => $names) {
if ($factions[$faction_num]['faction_name'] != trim($names['faction_name'])) {
$saveData['factions'][$factions[$faction_num]['faction_id']] = trim($names['faction_name']);
}
foreach ($names as $character_number => $character) {
if ($character_number == 'faction_name') {
continue;
}
$charName = trim($character['character_name']);
if ( ! empty($charName) && $charName != $character_data[$faction_num][$character_number]['character_name']) {
$saveData['characters'][$character_data[$faction_num][$character_number]['character_id']]['character_name'] = $charName;
}
$characterPriority = trim($character['priority']);
if ($characterPriority != $character_data[$faction_num][$character_number]['priority']) {
$saveData['characters'][$character_data[$faction_num][$character_number]['character_id']]['priority'] = $characterPriority;
}
$playerName = trim($character['player_name']);
if ($playerName != $character_data[$faction_num][$character_number]['player_name']) {
$saveData['characters'][$character_data[$faction_num][$character_number]['character_id']]['player_name'] = $playerName;
}
$characterBio = trim($character['character_bio']);
if ($characterBio != $character_data[$faction_num][$character_number]['character_bio']) {
$saveData['characters'][$character_data[$faction_num][$character_number]['character_id']]['character_bio'] = $characterBio;
}
}
}
if ( ! empty($saveData)) {
if (save_project_data($project_id, $saveData)) {
if (isset($_GET['result']) && $_GET['result'] == 'json') {
echo json_encode("success");
exit;
}
$_SESSION['edit-project-save-message'] = "Project and names saved!";
} else {
if (isset($_GET['result']) && $_GET['result'] == 'json') {
echo json_encode("error");
exit;
}
}
} else {
if (isset($_GET['result']) && $_GET['result'] == 'json') {
echo json_encode("success");
exit;
}
}
break;
}
if ($result) {
header("Location: edit_project.php");
exit;
}
}
$saveMessage = null;
if (isset($_SESSION['edit-project-save-message'])) {
$saveMessage = $_SESSION['edit-project-save-message'];
unset($_SESSION['edit-project-save-message']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>The Factionizer</title>
<meta name="keywords" content="factionizer, larp, the factionizer, double exposure, dexcon, dreamation, create larp, convention, gaming">
<meta name="description" content="A tool for LARP. Create character factions and see their interactions - then print character cards.">
<meta charset="UTF-8">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap-tour.min.css">
<link rel="stylesheet" href="css/primary.css">
<script src="includes/jquery-1.9.0.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/includes/javascript_edit.js"></script>
<script src="javascript/bootstrap-tour.min.js"></script>
<script type="text/javascript">
var user_viewed_tutorial = <?php echo $user_data['viewed_tutorial'];?>;
var user_id = <?php echo $_SESSION['user_id'];?>;
</script>
<script src="javascript/tour.js"></script>
<style>
i.fa {
color: #548B54;
}
a.delete_faction i, i.delete-character {
color: #ff0000;
}
a.toggle_character, #random-names, #add-faction, #clear-all-names, #clear-player-names {
/*float: left;*/
vertical-align: -4px;
margin-right: 10px;
}
.edit-project>ul>li {
padding-left: 25px;
}
#edit-actions li {
display: inline;
}
#edit-actions {
margin-left: -25px;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="container">
<div class="logo">
<img src="/images/Factionizerlogo.png">
</div>
<!-- <h1>The Factionizer - Project: <?php echo $activeProject['project_name'];?></h1> -->
<ul class="menu">
<li><a href="index.php">Home</a></li>
<li><a href="new_project.php">New</a></li>
<li><a href="load.php">Open</a></li>
<li class="selected"><a href="edit_project.php">Edit Project</a></li>
<li id="nav-grid"><a href="grid.php">Grid</a></li>
<li><a href="character_card.php" target="_blank">Character Cards</a></li>
<li><a href="print.php" target="_blank">Print CC's</a></li>
</ul>
<div id="grid_container">
<button id="tour-start-edit" class="btn btn-primary" style="float:right;"><i class="fa fa-question-circle" style="color: #ffffff;"></i> Show the Tour</button>
<form action="edit_project.php?action=save-form" method="post" role="form" id="project-form">
<div class="edit-project">
<?php if ( ! empty($errors)) {
echo output_errors($errors);
}?>
<?php if ( ! empty($saveMessage)) {
echo '<h3 style="color: #548B54">' . $saveMessage . '</h3>';
}?>
<?php if ($new_project) : ?>
<h3><p>Your new project has been created!</p></h3>
<?php endif; ?>
<h4><p>On this page, you can edit the names and numbers within your project, including the name of your project, the names and numbers of your factions, and the names and numbers of active characters in each faction.</p></h4>
<?php if ($new_project) : ?>
<h4><p>We've created some generic names for you to use for now.</p></h4>
<?php endif; ?>
<h3>
<label for="project_name">Project Name:</label>
<input type="text" name="project_name" value="<?php echo $activeProject['project_name'];?>" id="project-name"></input>
Active factions: <span id="faction-count"><?php echo ($activeProject['faction_qty'] - count($deleted_factions));?></span> / <span id="faction-limit"><?php echo FACTION_LIMIT; ?></span>
</h3>
<ul id="edit-actions">
<?php if ($activeProject['faction_qty'] < FACTION_LIMIT) : ?>
<li id="add-faction-container">
<button class="btn btn-primary btn-sm" id="add-faction"><i class="fa fa-plus fa-lg" style="color: #fff;"></i> Add another faction</button>
</li>
<?php endif; ?>
<li>
<button class="btn btn-primary btn-sm" id="random-names"><i class="fa fa-random fa-lg" style="color: #fff;"></i> Randomize character names</button>
</li>
<li>
<button class="btn btn-primary btn-sm" id="clear-all-names"><i class="fa fa-times fa-lg" style="color: #fff;"></i> Clear all character and faction names</button>
</li>
<li>
<button class="btn btn-primary btn-sm" id="clear-player-names"><i class="fa fa-times fa-lg" style="color: #fff;"></i> Clear all player names</button>
</li>
</ul>
<?php foreach ($character_data as $faction_num => $faction_characters) : ?>
<div id="faction_<?php echo $faction_num;?>">
<a title="Delete Faction" class="delete_faction" id="delete_faction_<?php echo $faction_num; ?>" data-faction-id="<?php echo $factions[$faction_num]['faction_id'];?>" data-faction-name="<?php echo $factions[$faction_num]['faction_name'];?>"><i class="fa fa-times fa-2x"></i></a>
<strong>Faction:</strong>
<input type="text" id="faction_name_<?php echo $faction_num;?>" name="names[<?php echo $faction_num; ?>][faction_name]" class="edit edit-faction-name" value="<?php echo @$factions[$faction_num]['faction_name'];?>"></input>
<!-- Number of Characters: <?php echo count($faction_characters); ?> / <?php echo CHARACTER_LIMIT; ?>-->
<br >
<br >
<ul id="active_characters_<?php echo $faction_num;?>">
<?php foreach ($faction_characters as $character_num => $character) :
$optionA = $optionB = $optionC = $optionD = $optionE = $option0 = '';
switch ($character['priority']) {
case '0':
$option0 = 'selected="selected"';
break;
case '1':
$optionA = 'selected="selected"';
break;
case '2':
$optionB = 'selected="selected"';
break;
case '3':
$optionC = 'selected="selected"';
break;
case '4':
$optionD = 'selected="selected"';
break;
default:
}
?>
<li id="character_<?php echo $character['character_id'];?>" data-char-num="<?php echo $character_num;?>-<?php echo $faction_num;?>">
<a title="Delete Character" class="toggle_character" data-action="delete" data-character-id="<?php echo $character['character_id'];?>" data-character-faction="<?php echo $faction_num;?>" data-character-num="<?php echo $character_num;?>" data-character-name="<?php echo $character['character_name'];?>"><i class="fa fa-times fa-2x delete-character"></i></a>
Priority:
<select name="names[<?php echo $faction_num;?>][<?php echo $character_num;?>][priority]" id="character_priority_<?php echo $character_num;?>">
<option value="0" <?php echo $option0;?>>None</option>
<option value="1" <?php echo $optionA;?>>A</option>
<option value="2" <?php echo $optionB;?>>B</option>
<option value="3" <?php echo $optionC;?>>C</option>
<option value="4" <?php echo $optionD;?>>D</option>
</select>
Character:
<input class="character-names" type="text" name="names[<?php echo $faction_num;?>][<?php echo $character_num;?>][character_name]" value="<?php echo $character['character_name'];?>"></input>
Player:
<input class="player-names" type="text" name="names[<?php echo $faction_num;?>][<?php echo $character_num;?>][player_name]" value="<?php echo $character['player_name'];?>"></input>
</li>
<?php endforeach; ?>
</ul>
<ul id="deleted_characters_<?php echo $faction_num;?>">
<?php if ( ! empty($deleted_characters[$faction_num])) : ?>
<?php foreach ($deleted_characters[$faction_num] as $character_num => $character) :
$optionA = $optionB = $optionC = $optionD = $optionE = $option0 = '';
switch ($character['priority']) {
case '0':
$option0 = 'selected="selected"';
break;
case '1':
$optionA = 'selected="selected"';
break;
case '2':
$optionB = 'selected="selected"';
break;
case '3':
$optionC = 'selected="selected"';
break;
case '4':
$optionD = 'selected="selected"';
break;
default:
}
?>
<li id="character_<?php echo $character['character_id'];?>">
<a title="Restore Character" class="toggle_character" data-action="restore" data-character-id="<?php echo $character['character_id'];?>" data-character-faction="<?php echo $faction_num;?>" data-character-num="<?php echo $character_num;?>" data-character-name="<?php echo $character['character_name'];?>"><i class="fa fa-undo fa-lg restore-character"></i></a>
Priority:
<select disabled name="names[<?php echo $faction_num;?>][<?php echo $character_num;?>][priority]">
<option value="0" <?php echo $option0;?>>None</option>
<option value="1" <?php echo $optionA;?>>A</option>
<option value="2" <?php echo $optionB;?>>B</option>
<option value="3" <?php echo $optionC;?>>C</option>
<option value="4" <?php echo $optionD;?>>D</option>
</select>
Character:
<input disabled class="character-names" type="text" name="names[<?php echo $faction_num;?>][<?php echo $character_num;?>][character_name]" value="<?php echo $character['character_name'];?>"></input>
Player:
<input disabled class="player-names" type="text" name="names[<?php echo $faction_num;?>][<?php echo $character_num;?>][player_name]" value="<?php echo $character['player_name'];?>"></input>
</li>
<?php endforeach ; ?>
<?php endif; ?>
</ul>
</div>
<?php endforeach; ?>
<div id="deleted-factions" style="padding: 10px;">
<?php if ( ! empty($deleted_factions)) : ?>
<h4>Deleted Factions</h4>
<?php foreach ($deleted_factions as $faction_num => $faction_characters) : ?>
<p>
<a title="Restore Faction" class="restore_faction" id="restore_faction_<?php echo $faction_num;?>" data-faction-id="<?php echo $factions[$faction_num]['faction_id'];?>" data-faction-name="<?php echo $factions[$faction_num]['faction_name'];?>"><i class="fa fa-undo fa-lg"></i></a>
Faction: <?php echo $factions[$faction_num]['faction_name'];?>
</p>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<br >
<input type="submit" value="Save Project" id="save-project">
</form>
<?php include 'includes/footer.php'; ?>
</div>
</div>
</body>
</html>