Skip to content

Commit 8eea19d

Browse files
committed
Small permissions fix for client-specific access
1 parent 2a974c2 commit 8eea19d

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

invoice.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
// If client_id is in URI then show client Side Bar and client header
44
if (isset($_GET['client_id'])) {
55
require_once "includes/inc_all_client.php";
6-
} else {
6+
} else {
77
require_once "includes/inc_all.php";
88
}
99

10+
// Perms
11+
enforceUserPermission('module_sales');
12+
$invoice_permission_snippet = '';
13+
if (!empty($client_access_string)) {
14+
$invoice_permission_snippet = "AND invoice_client_id IN ($client_access_string)";
15+
}
16+
17+
1018
if (isset($_GET['invoice_id'])) {
1119

1220
$invoice_id = intval($_GET['invoice_id']);
@@ -17,7 +25,8 @@
1725
LEFT JOIN clients ON invoice_client_id = client_id
1826
LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1
1927
LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1
20-
WHERE invoice_id = $invoice_id"
28+
WHERE invoice_id = $invoice_id
29+
$invoice_permission_snippet"
2130
);
2231

2332
if (mysqli_num_rows($sql) == 0) {
@@ -215,13 +224,13 @@
215224
</a>
216225
<?php } ?>
217226
<?php } ?>
218-
227+
219228
<?php if (($invoice_status == 'Sent' || $invoice_status == 'Viewed') && $invoice_amount == 0 && $invoice_status !== 'Non-Billable') { ?>
220229
<a class="btn btn-dark" href="post.php?mark_invoice_non-billable=<?php echo $invoice_id; ?>">
221230
Mark Non-Billable
222231
</a>
223232
<?php } ?>
224-
233+
225234
</div>
226235

227236
<div class="col-4">

invoices.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
// Perms
1919
enforceUserPermission('module_sales');
20+
$invoice_permission_snippet = '';
21+
if (!empty($client_access_string)) {
22+
$invoice_permission_snippet = "AND invoice_client_id IN ($client_access_string)";
23+
}
2024

2125
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Sent' $client_query"));
2226
$sent_count = $row['num'];
@@ -94,6 +98,7 @@
9498
$overdue_query
9599
AND DATE(invoice_date) BETWEEN '$dtf' AND '$dtt'
96100
AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$q%' OR invoice_scope LIKE '%$q%' OR client_name LIKE '%$q%' OR invoice_status LIKE '%$q%' OR invoice_amount LIKE '%$q%' OR category_name LIKE '%$q%')
101+
$invoice_permission_snippet
97102
$client_query
98103
ORDER BY $sort $order LIMIT $record_from, $record_to"
99104
);

quote.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
// If client_id is in URI then show client Side Bar and client header
44
if (isset($_GET['client_id'])) {
55
require_once "includes/inc_all_client.php";
6-
} else {
6+
} else {
77
require_once "includes/inc_all.php";
88
}
99

10+
// Perms
11+
enforceUserPermission('module_sales');
12+
$quote_permission_snippet = '';
13+
if (!empty($client_access_string)) {
14+
$quote_permission_snippet = "AND quote_client_id IN ($client_access_string)";
15+
}
16+
1017
if (isset($_GET['quote_id'])) {
1118

1219
$quote_id = intval($_GET['quote_id']);
@@ -17,7 +24,8 @@
1724
LEFT JOIN clients ON quote_client_id = client_id
1825
LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1
1926
LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1
20-
WHERE quote_id = $quote_id"
27+
WHERE quote_id = $quote_id
28+
$quote_permission_snippet"
2129
);
2230

2331
if (mysqli_num_rows($sql) == 0) {
@@ -186,7 +194,7 @@
186194
</a>
187195
<?php if (lookupUserPermission("module_sales") >= 2) { ?>
188196
<a class="dropdown-item" href="#"
189-
data-toggle = "ajax-modal"
197+
data-toggle = "ajax-modal"
190198
data-ajax-url = "ajax/ajax_quote_copy.php"
191199
data-ajax-id = "<?php echo $quote_id; ?>"
192200
>

quotes.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
// Perms
1919
enforceUserPermission('module_sales');
20+
$quote_permission_snippet = '';
21+
if (!empty($client_access_string)) {
22+
$quote_permission_snippet = "AND quote_client_id IN ($client_access_string)";
23+
}
2024

2125
$sql = mysqli_query(
2226
$mysqli,
@@ -25,6 +29,7 @@
2529
LEFT JOIN categories ON quote_category_id = category_id
2630
WHERE (CONCAT(quote_prefix,quote_number) LIKE '%$q%' OR quote_scope LIKE '%$q%' OR category_name LIKE '%$q%' OR quote_status LIKE '%$q%' OR quote_amount LIKE '%$q%' OR client_name LIKE '%$q%')
2731
AND DATE(quote_date) BETWEEN '$dtf' AND '$dtt'
32+
$quote_permission_snippet
2833
$client_query
2934
ORDER BY $sort $order LIMIT $record_from, $record_to"
3035
);
@@ -206,7 +211,7 @@
206211
<tr>
207212
<td class="text-bold">
208213
<a href="quote.php?<?php echo $client_url; ?>quote_id=<?php echo $quote_id; ?>">
209-
<?php echo "$quote_prefix$quote_number"; ?>
214+
<?php echo "$quote_prefix$quote_number"; ?>
210215
</a>
211216
</td>
212217
<td><?php echo $quote_scope_display; ?></td>
@@ -231,15 +236,15 @@
231236
</button>
232237
<div class="dropdown-menu">
233238
<a class="dropdown-item" href="#"
234-
data-toggle = "ajax-modal"
239+
data-toggle = "ajax-modal"
235240
data-ajax-url = "ajax/ajax_quote_edit.php"
236241
data-ajax-id = "<?php echo $quote_id; ?>"
237242
>
238243
<i class="fas fa-fw fa-edit mr-2"></i>Edit
239244
</a>
240245
<?php if (lookupUserPermission("module_sales") >= 2) { ?>
241246
<a class="dropdown-item" href="#"
242-
data-toggle = "ajax-modal"
247+
data-toggle = "ajax-modal"
243248
data-ajax-url = "ajax/ajax_quote_copy.php"
244249
data-ajax-id = "<?php echo $quote_id; ?>"
245250
>

ticket.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
// Perms
1111
enforceUserPermission('module_support');
12+
$ticket_permission_snippet = '';
13+
if (!empty($client_access_string)) {
14+
$ticket_permission_snippet = "AND ticket_client_id IN ($client_access_string)";
15+
}
1216

1317
// Initialize the HTML Purifier to prevent XSS
1418
require_once "plugins/htmlpurifier/HTMLPurifier.standalone.php";
@@ -18,12 +22,6 @@
1822
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
1923
$purifier = new HTMLPurifier($purifier_config);
2024

21-
// Ticket client access snippet
22-
$ticket_permission_snippet = '';
23-
if (!empty($client_access_string)) {
24-
$ticket_permission_snippet = "AND ticket_client_id IN ($client_access_string)";
25-
}
26-
2725
if (isset($_GET['ticket_id'])) {
2826
$ticket_id = intval($_GET['ticket_id']);
2927

@@ -49,7 +47,7 @@
4947
if (mysqli_num_rows($sql) == 0) {
5048
echo "<center><h1 class='text-secondary mt-5'>Nothing to see here</h1><a class='btn btn-lg btn-secondary mt-3' href='tickets.php'><i class='fa fa-fw fa-arrow-left'></i> Go Back</a></center>";
5149

52-
include_once "footer.php";
50+
include_once "includes/footer.php";
5351
} else {
5452

5553
$row = mysqli_fetch_array($sql);
@@ -979,7 +977,7 @@
979977
</td>
980978
</tr>
981979
<?php
982-
}
980+
}
983981
?>
984982
</table>
985983
</div>

0 commit comments

Comments
 (0)