Skip to content

Commit e02d45d

Browse files
committed
More Migration to AJAX Modal
1 parent 650b875 commit e02d45d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3546
-3320
lines changed

accounts.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@
8585
?>
8686

8787
<tr>
88-
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editAccountModal<?php echo $account_id; ?>"><?php echo $account_name; ?></a></td>
88+
<td>
89+
<a class="text-dark" href="#"
90+
data-toggle="ajax-modal"
91+
data-ajax-url="ajax/ajax_account_edit.php"
92+
data-ajax-id="<?php echo $account_id; ?>"
93+
>
94+
<?php echo $account_name; ?>
95+
</a>
96+
</td>
8997
<td><?php echo $account_currency_code; ?></td>
9098
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $balance, $account_currency_code); ?></td>
9199
<td>
@@ -94,7 +102,11 @@
94102
<i class="fas fa-ellipsis-h"></i>
95103
</button>
96104
<div class="dropdown-menu">
97-
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editAccountModal<?php echo $account_id; ?>">
105+
<a class="dropdown-item" href="#"
106+
data-toggle="ajax-modal"
107+
data-ajax-url="ajax/ajax_account_edit.php"
108+
data-ajax-id="<?php echo $account_id; ?>"
109+
>
98110
<i class="fas fa-fw fa-edit mr-2"></i>Edit
99111
</a>
100112
<?php if ($balance == 0 && $account_id != $config_stripe_account) { //Cannot Archive an Account until it reaches 0 Balance and cant be selected as an online account ?>
@@ -109,7 +121,6 @@
109121
</tr>
110122

111123
<?php
112-
require "modals/account_edit_modal.php";
113124
}
114125
?>
115126

ajax/ajax_account_edit.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
require_once '../includes/ajax_header.php';
4+
5+
$account_id = intval($_GET['id']);
6+
7+
$sql = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_id = $account_id LIMIT 1");
8+
9+
$row = mysqli_fetch_array($sql);
10+
$account_name = nullable_htmlentities($row['account_name']);
11+
$account_notes = nullable_htmlentities($row['account_notes']);
12+
13+
// Generate the HTML form content using output buffering.
14+
ob_start();
15+
?>
16+
17+
<div class="modal-header">
18+
<h5 class="modal-title"><i class="fa fa-fw fa-piggy-bank mr-2"></i>Editing account: <strong><?php echo $account_name; ?></strong></h5>
19+
<button type="button" class="close text-white" data-dismiss="modal">
20+
<span>&times;</span>
21+
</button>
22+
</div>
23+
<form action="post.php" method="post" autocomplete="off">
24+
<input type="hidden" name="account_id" value="<?php echo $account_id; ?>">
25+
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
26+
<div class="modal-body bg-white">
27+
<div class="form-group">
28+
<label>Account Name <strong class="text-danger">*</strong></label>
29+
<div class="input-group">
30+
<div class="input-group-prepend">
31+
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
32+
</div>
33+
<input type="text" class="form-control" name="name" maxlength="200" value="<?php echo $account_name; ?>" required>
34+
</div>
35+
</div>
36+
37+
<div class="form-group">
38+
<label>Notes</label>
39+
<textarea class="form-control" rows="5" placeholder="Enter some notes" name="notes"><?php echo $account_notes; ?></textarea>
40+
</div>
41+
42+
</div>
43+
<div class="modal-footer bg-white">
44+
<button type="submit" name="edit_account" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Save</button>
45+
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
46+
</div>
47+
</form>
48+
49+
<?php
50+
51+
require_once "../includes/ajax_footer.php";

ajax/ajax_document_move.php

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
require_once '../includes/ajax_header.php';
4+
5+
$document_id = intval($_GET['id']);
6+
7+
$sql = mysqli_query($mysqli, "SELECT * FROM documents WHERE document_id = $document_id");
8+
9+
$row = mysqli_fetch_array($sql);
10+
$client_id = intval($row['document_client_id']);
11+
$document_folder_id = nullable_htmlentities($row['document_folder_id']);
12+
$document_name = nullable_htmlentities($row['document_name']);
13+
14+
15+
// Generate the HTML form content using output buffering.
16+
ob_start();
17+
?>
18+
<div class="modal-header">
19+
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt mr-2"></i>Moving document: <strong><?php echo $document_name; ?></strong></h5>
20+
<button type="button" class="close text-white" data-dismiss="modal">
21+
<span>&times;</span>
22+
</button>
23+
</div>
24+
<form action="post.php" method="post" autocomplete="off">
25+
<input type="hidden" name="document_id" value="<?php echo $document_id; ?>">
26+
<div class="modal-body bg-white">
27+
28+
<div class="form-group">
29+
<label>Move Document to</label>
30+
<div class="input-group">
31+
<div class="input-group-prepend">
32+
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
33+
</div>
34+
<select class="form-control select2" name="folder">
35+
<option value="0">/</option>
36+
<?php
37+
// Fetch all folders for the client
38+
$sql_all_folders = mysqli_query($mysqli, "SELECT folder_id, folder_name, parent_folder FROM folders WHERE folder_location = 0 AND folder_client_id = $client_id ORDER BY folder_name ASC");
39+
$folders = array();
40+
41+
// Build an associative array of folders indexed by folder_id
42+
while ($row = mysqli_fetch_assoc($sql_all_folders)) {
43+
$folders[$row['folder_id']] = array(
44+
'folder_id' => intval($row['folder_id']),
45+
'folder_name' => nullable_htmlentities($row['folder_name']),
46+
'parent_folder' => intval($row['parent_folder']),
47+
'children' => array()
48+
);
49+
}
50+
51+
// Build the folder hierarchy
52+
foreach ($folders as $id => &$folder) {
53+
if ($folder['parent_folder'] != 0 && isset($folders[$folder['parent_folder']])) {
54+
$folders[$folder['parent_folder']]['children'][] = &$folder;
55+
}
56+
}
57+
unset($folder); // Break the reference
58+
59+
// Prepare a list of root folders
60+
$root_folders = array();
61+
foreach ($folders as $id => $folder) {
62+
if ($folder['parent_folder'] == 0) {
63+
$root_folders[] = $folder;
64+
}
65+
}
66+
67+
// Display the folder options iteratively
68+
$stack = array();
69+
foreach (array_reverse($root_folders) as $folder) {
70+
$stack[] = array('folder' => $folder, 'level' => 0);
71+
}
72+
73+
while (!empty($stack)) {
74+
$node = array_pop($stack);
75+
$folder = $node['folder'];
76+
$level = $node['level'];
77+
78+
// Indentation for subfolders
79+
$indentation = str_repeat('&nbsp;', $level * 4);
80+
81+
// Check if this folder is selected
82+
$selected = '';
83+
if ($folder['folder_id'] == $document_folder_id) {
84+
$selected = 'selected';
85+
}
86+
87+
echo "<option value=\"{$folder['folder_id']}\" $selected>$indentation{$folder['folder_name']}</option>";
88+
89+
// Add children to the stack
90+
if (!empty($folder['children'])) {
91+
foreach (array_reverse($folder['children']) as $child_folder) {
92+
$stack[] = array('folder' => $child_folder, 'level' => $level + 1);
93+
}
94+
}
95+
}
96+
?>
97+
</select>
98+
</div>
99+
</div>
100+
101+
</div>
102+
<div class="modal-footer bg-white">
103+
<button type="submit" name="move_document" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Move</button>
104+
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
105+
</div>
106+
</form>
107+
108+
<?php
109+
require_once "../includes/ajax_footer.php";

ajax/ajax_document_rename.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
require_once '../includes/ajax_header.php';
4+
5+
$document_id = intval($_GET['id']);
6+
7+
$sql = mysqli_query($mysqli, "SELECT * FROM documents WHERE document_id = $document_id");
8+
9+
$row = mysqli_fetch_array($sql);
10+
$client_id = intval($row['document_client_id']);
11+
$document_name = nullable_htmlentities($row['document_name']);
12+
13+
14+
// Generate the HTML form content using output buffering.
15+
ob_start();
16+
?>
17+
<div class="modal-header">
18+
<h5 class="modal-title"><i class="fa fa-fw fa-file-alt mr-2"></i>Renaming document: <strong><?php echo $document_name; ?></strong></h5>
19+
<button type="button" class="close text-white" data-dismiss="modal">
20+
<span>&times;</span>
21+
</button>
22+
</div>
23+
<form action="post.php" method="post" autocomplete="off">
24+
<input type="hidden" name="document_id" value="<?php echo $document_id; ?>">
25+
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
26+
<div class="modal-body bg-white">
27+
28+
<div class="form-group">
29+
<label>Document Name <strong class="text-danger">*</strong></label>
30+
<div class="input-group">
31+
<div class="input-group-prepend">
32+
<span class="input-group-text"><i class="fa fa-fw fa-file-alt"></i></span>
33+
</div>
34+
<input class="form-control" type="text" name="name" maxlength="200" value="<?php echo $document_name; ?>" required>
35+
</div>
36+
</div>
37+
38+
</div>
39+
<div class="modal-footer bg-white">
40+
<button type="submit" name="rename_document" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Rename</button>
41+
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
42+
</div>
43+
</form>
44+
45+
<?php
46+
require_once "../includes/ajax_footer.php";

ajax/ajax_document_view.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
require_once '../includes/ajax_header.php';
4+
5+
// Initialize the HTML Purifier to prevent XSS
6+
require_once "../plugins/htmlpurifier/HTMLPurifier.standalone.php";
7+
8+
$purifier_config = HTMLPurifier_Config::createDefault();
9+
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
10+
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
11+
$purifier = new HTMLPurifier($purifier_config);
12+
13+
$document_id = intval($_GET['id']);
14+
15+
$sql = mysqli_query($mysqli, "SELECT * FROM documents WHERE document_id = $document_id");
16+
17+
$row = mysqli_fetch_array($sql);
18+
$document_name = nullable_htmlentities($row['document_name']);
19+
$document_content = $purifier->purify($row['document_content']);
20+
21+
22+
// Generate the HTML form content using output buffering.
23+
ob_start();
24+
?>
25+
26+
<div class="modal-header">
27+
<h5 class="modal-title text-white"><i class="fa fa-fw fa-file-alt mr-2"></i><?php echo $document_name; ?></h5>
28+
<button type="button" class="close text-white" data-dismiss="modal">
29+
<span>&times;</span>
30+
</button>
31+
</div>
32+
<div class="modal-body bg-white prettyContent">
33+
<?php echo $document_content; ?>
34+
</div>
35+
36+
<?php
37+
require_once "../includes/ajax_footer.php";

0 commit comments

Comments
 (0)