Commit 43ff4f68 authored by Malcolm Blaney's avatar Malcolm Blaney

Cart module fixed a bug where tabs didn't match up due to special

characters in html. Also missed a case where tracking wasn't turned
back on for previously tracked products. Organiser->Parent() was
returning an empty string when an organisation wasn't found, it now
returns false in this case as the empty string is a valid group.
Other changes were required to allow for this. Writer module needs
to set a default location for posts for Micropub to work. Tried to
improve how tooltips work in Reader module js. Also unread count is
accumulative so need to parse the current unread total before
modifying the page-select button.
parent 375aeb27
Pipeline #44866481 passed with stage
in 1 minute and 15 seconds
......@@ -96,7 +96,11 @@ class Cart extends Base {
if (strpos($tab_names, ',') !== false) {
$tabs .= '<div id="cart-tabs"><ul id="cart-tabs-list">';
foreach (explode(',', $tab_names) as $current_tab) {
$tab_id = preg_replace('/[^a-z0-9_-]/', '-', strtolower($current_tab));
// The tab names template is stored encoded for display in html, but
// the tabs used below from cart_item_page is not encoded so decode
// here so that tab links match the generated ids.
$decode_current_tab = strtolower(htmlspecialchars_decode($current_tab));
$tab_id = preg_replace('/[^a-z0-9_-]/', '-', $decode_current_tab);
$tabs .= '<li><a href="#cart-tab-' . $tab_id . '">' . $current_tab .
'</a></li>';
}
......@@ -669,7 +673,8 @@ class Cart extends Base {
// in two steps because the queries don't join well. Need everything from
// the cart_items table and only existing values from cart_item_page table.
$query = 'SELECT name, available, tab, item_order FROM cart_item_page ' .
'WHERE user = "' . $this->owner . '" AND page = "' .$this->user->page.'"';
'WHERE user = "' . $this->owner . '" AND ' .
'page = "' . $this->user->page . '"';
if ($mysqli_result = $mysqli->query($query)) {
while ($cart_item_page = $mysqli_result->fetch_assoc()) {
$current[$cart_item_page['name']] =
......@@ -1589,8 +1594,9 @@ class Cart extends Base {
$variable = (int)$_POST['variable'];
$minimum = price_string((float)$_POST['minimum']);
$download = $mysqli->escape_string(htmlspecialchars($_POST['download']));
$us_item_tab = htmlspecialchars($_POST['itemTab']);
$item_tab = $mysqli->escape_string($us_item_tab);
// Note that tabs are not escaped as they are not expected to be displayed
// as they are in html and are required to be used elsewere unescaped.
$item_tab = $mysqli->escape_string($_POST['itemTab']);
$item_order = (int)$_POST['itemOrder'];
$available = (int)$_POST['available'];
$tracking = (int)$_POST['tracking'];
......@@ -1653,23 +1659,6 @@ class Cart extends Base {
else {
$this->Log('Cart->SaveItem 5: ' . $mysqli->error);
}
// Also make sure the tab doesn't get modified on the tracked page.
if (!$modified && $this->user->page === $this->Substitute('cart-page')) {
$query = 'SELECT tab FROM cart_item_page WHERE ' .
'user = "' . $this->owner . '" AND name = "' . $name . '" AND ' .
'page = "' . $this->user->page . '"';
if ($mysqli_result = $mysqli->query($query)) {
if ($cart_item_page = $mysqli_result->fetch_assoc()) {
if ($cart_item_page['tab'] !== $us_item_tab) {
$modified = true;
}
}
$mysqli_result->close();
}
else {
$this->Log('Cart->SaveItem 6: ' . $mysqli->error);
}
}
if ($modified) {
$query = 'UPDATE cart_tracking SET modified = 1 WHERE ' .
'user = "' . $this->owner . '" AND name = "' . $name . '"';
......@@ -2023,7 +2012,7 @@ class Cart extends Base {
$modified = false;
$current_tracking = false;
$query = 'SELECT name, modified, tracking FROM cart_tracking WHERE ' .
'user = "' . $user .'" AND product = "' . $product . '" AND ' .
'user = "' . $user . '" AND product = "' . $product . '" AND ' .
'supplier = "' . $supplier . '"';
if ($mysqli_result = $mysqli->query($query)) {
if ($cart_tracking = $mysqli_result->fetch_assoc()) {
......@@ -2052,15 +2041,13 @@ class Cart extends Base {
}
// Use the stock name from the product when it doesn't exist here.
if ($name === '') {
$name = $product;
$query = 'INSERT INTO cart_tracking VALUES ("' . $user . '", ' .
'"' . $name . '", "' . $supplier . '", "' . $product . '", 0, 1) ' .
'ON DUPLICATE KEY UPDATE supplier = "' . $supplier . '", ' .
'product = "' . $product . '", tracking = 1';
if (!$mysqli->query($query)) {
$this->Log('Cart->UpdateItem 4: ' . $mysqli->error);
}
if ($name === '') $name = $product;
$query = 'INSERT INTO cart_tracking VALUES ("' . $user . '", ' .
'"' . $name . '", "' . $supplier . '", "' . $product . '", 0, 1) ' .
'ON DUPLICATE KEY UPDATE supplier = "' . $supplier . '", ' .
'product = "' . $product . '", tracking = 1';
if (!$mysqli->query($query)) {
$this->Log('Cart->UpdateItem 4: ' . $mysqli->error);
}
// The modified flag is used here to decide which fields can be updated for
// existing items.
......@@ -2087,15 +2074,8 @@ class Cart extends Base {
$query = 'INSERT INTO cart_item_page VALUES ("' . $user . '", ' .
'"' . $name . '", "' . $page . '", ' . $available . ', ' .
'"' . $category . '", 0) ';
// If this cart item has been modified don't want to update the tab here.
if ($modified) {
$query .= 'ON DUPLICATE KEY UPDATE available = ' . $available;
}
else {
$query .= 'ON DUPLICATE KEY UPDATE available = ' . $available .
', tab = "' . $category . '"';
}
'"' . $category . '", 0) ON DUPLICATE KEY UPDATE ' .
'available = ' . $available . ', tab = "' . $category . '"';
if (!$mysqli->query($query)) {
$this->Log('Cart->UpdateItem 6: ' . $mysqli->error);
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2018 Malcolm Blaney
// Copyright (C) 2019 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -29,6 +29,8 @@ class Contact extends Base {
$this->AddBoxStyle($box_style);
$organiser = new Organiser($this->user, $this->owner);
$parent = $organiser->Parent();
if ($parent === false) $parent = '';
$content = '<form class="contact-form">' .
'When editing this form, make sure each field you add has a name ' .
'attribute.<br>The field with the name "contact-name" is used on the ' .
......@@ -40,7 +42,7 @@ class Contact extends Base {
'<label>Contact name:</label><input name="contact-name" type="text">' .
'</div>' .
'<input name="contact-organisation" ' .
'value="' . $organiser->Parent() . '" type="hidden">' .
'value="' . $parent . '" type="hidden">' .
'<button class="submit">submit</button>' .
'<span class="contact-info" style="display:none;">' .
'ckeditor removes this span if empty</span>' .
......@@ -280,12 +282,12 @@ class Contact extends Base {
$mysqli = connect_db();
$query = 'SELECT content FROM contact WHERE user = "' . $user . '" ' .
'AND box_id = ' . $id;
if ($result = $mysqli->query($query)) {
if ($contact = $result->fetch_assoc()) {
if ($mysqli_result = $mysqli->query($query)) {
if ($contact = $mysqli_result->fetch_assoc()) {
$content = $escape ? $mysqli->escape_string($contact['content']) :
$contact['content'];
}
$result->close();
$mysqli_result->close();
}
else {
$this->Log('Contact->PlainContent: ' . $mysqli->error);
......
<?php
// Dobrado Content Management System
// Copyright (C) 2018 Malcolm Blaney
// Copyright (C) 2019 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -75,11 +75,11 @@ class Groupwizard extends Base {
$mysqli = connect_db();
$query = 'SELECT label FROM modules WHERE user = "admin" AND ' .
'page = "' . $page . '" AND label = "banking" AND deleted = 0';
if ($result = $mysqli->query($query)) {
if ($result->num_rows === 1) {
if ($mysqli_result = $mysqli->query($query)) {
if ($mysqli_result->num_rows === 1) {
$banking = true;
}
$result->close();
$mysqli_result->close();
}
else {
$this->Log('Groupwizard->Content: ' . $mysqli->error);
......@@ -171,7 +171,7 @@ class Groupwizard extends Base {
if (count($groups) > 1) {
$organisation = true;
$parent = $organiser->Parent();
$parent_text = $parent === '' ? '' :
$parent_text = $parent === false || $parent === '' ? '' :
' in <b>' . ucfirst($parent) . '</b>';
$group_text = $this->user->group === '' ? '' :
' group, <b>' . ucfirst($this->user->group) . '</b>';
......@@ -573,9 +573,10 @@ class Groupwizard extends Base {
'<input id="groupwizard-stock-tax-percent" type="text" ' .
'maxlength="5" value="' . $this->Value('stock-tax-percent') . '">' .
'</div>' .
'<p>Edit the default markup to apply to stock supplier prices:<br>' .
'Leave either option empty to hide it on the stock page, to update ' .
'all prices for a supplier please re-import their stock list.</p>' .
'<p>Edit the default markup to apply to supplier prices. Leave ' .
'either option empty to hide it on the stock page. You can also ' .
'set the options to \'0\' to show it on the stock page and not ' .
'have it apply markup automatically.</p>' .
'<div class="form-spacing">' .
'<label for="groupwizard-stock-wholesale-percent">The markup for ' .
'wholesale:</label>' .
......@@ -924,13 +925,13 @@ class Groupwizard extends Base {
return ['error' => 'Group name has the wrong format.'];
}
$object = [];
$result = [];
$default_group = $this->user->group;
$this->user->group = $group;
// Check if a group with this name already exists in an organisation.
$organiser = new Organiser($this->user, $this->owner);
if ($organiser->Parent() !== '') {
$object['error'] = 'Group name is not available.';
if ($organiser->Parent() !== false) {
$result['error'] = 'Group name is not available.';
}
else {
$invite = new Invite($this->user, $this->owner);
......@@ -938,14 +939,14 @@ class Groupwizard extends Base {
$_SESSION['purchase-group'] = $this->user->group;
$_SESSION['purchase-group-changed'] = true;
$this->user->group = $default_group;
$object['content'] = $this->Content(0);
$result['content'] = $this->Content(0);
}
else {
$object['error'] = 'Group name is not available.';
$result['error'] = 'Group name is not available.';
}
}
$this->user->group = $default_group;
return $object;
return $result;
}
private function ChangeGroup() {
......
<?php
// Dobrado Content Management System
// Copyright (C) 2018 Malcolm Blaney
// Copyright (C) 2019 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -198,8 +198,9 @@ class Invoice extends Base {
// Only send orders for the organisation if more than one group.
if (count($send_groups) > 1) {
$result = $this->NextOrder(true, true, $send_groups);
$organisation = $organiser->Parent();
if ($organisation === false) $organisation = '';
if ($result['done'] === true) {
$organisation = $organiser->Parent();
$description = 'Cron: sent organisation order';
if ($organisation !== '') {
$description .= ' for ' . $organisation;
......@@ -209,7 +210,6 @@ class Invoice extends Base {
}
else {
// Add a notification for unsent orders.
$organisation = $organiser->Parent();
$description = 'Cron: ' . $result['error'];
if ($organisation !== '') {
$description .= ' for ' . $organisation;
......@@ -783,13 +783,12 @@ class Invoice extends Base {
$sold < 0.01 && $purchase_value > -0.01 && $purchase_value < 0.01) {
continue;
}
$result['grid'][] =
['name' => $user,
'purchases' => number_format($purchase_value, 2, '.', ''),
'surcharge' => number_format($surcharge, 2, '.', ''),
'sold' => number_format($sold, 2, '.', ''),
'balance' => number_format($balance * -1, 2, '.', ''),
'credit' => $credit, 'active' => $active];
$result['grid'][] = ['name' => $user,
'purchases' => price_string($purchase_value),
'surcharge' => price_string($surcharge),
'sold' => price_string($sold),
'balance' => price_string($balance * -1),
'credit' => $credit, 'active' => $active];
}
return $result;
}
......@@ -1049,7 +1048,7 @@ class Invoice extends Base {
}
$message .= '<tr><td>' . htmlspecialchars($name) . '</td><td>' .
$supplier . '</td><td>' . $next_week[$i]['quantity'] . '</td><td>$' .
number_format($next_week[$i]['price'], 2, '.', '') . '/' .
price_string($next_week[$i]['price']) . '/' .
$products[$name]['unit'] . '</td></tr>' . "\n";
}
$message .= "</table>\n" .
......@@ -1307,22 +1306,19 @@ class Invoice extends Base {
$surcharge_description =
$this->Substitute('invoice-surcharge-description');
$message .= '<tr><td></td><td></td><td></td><td>Subtotal</td><td>$' .
number_format($total, 2, '.', '') . '</td></tr>' . "\n" .
price_string($total) . '</td></tr>' . "\n" .
'<tr><td></td><td></td><td></td><td>' . $surcharge_description .
'</td><td>$' . number_format($surcharge, 2, '.', '') . '</td></tr>' .
"\n" .
'</td><td>$' . price_string($surcharge) . '</td></tr>' . "\n" .
'<tr><td></td><td></td><td></td><td><b>Total</b></td><td><b>$' .
number_format($total + $surcharge, 2, '.', '') .
'</b></td></tr></table>' . "\n";
price_string($total + $surcharge) . '</b></td></tr></table>' . "\n";
}
else {
$message .= '<tr><td></td><td></td><td></td><td><b>Total</b></td><td>' .
'<b>$' . number_format($total, 2, '.', '') . '</b></td></tr>' .
'</table>' . "\n";
'<b>$' . price_string($total) . '</b></td></tr></table>' . "\n";
}
if ($tax_included !== 0) {
$message .= $this->Substitute('invoice-tax-included', '/!total/',
number_format($tax_included, 2, '.', ''));
price_string($tax_included));
}
}
if ($xero_enabled && $invoice_number !== 0) {
......@@ -1342,9 +1338,9 @@ class Invoice extends Base {
'<DueDate>' . date('Y-m-d\TH:i:s', $invoice_date + $terms) .
'</DueDate>' .
'<InvoiceNumber>' . $invoice_number . '</InvoiceNumber>' .
'<TotalTax>' . number_format($tax_included, 2, '.', '') .
'<TotalTax>' . price_string($tax_included) .
'</TotalTax>' .
'<Total>' . number_format($total + $surcharge, 2, '.', '') .
'<Total>' . price_string($total + $surcharge) .
'</Total>' .
'<LineAmountTypes>Inclusive</LineAmountTypes>' .
'<LineItems>' . $line_items . '</LineItems>' .
......@@ -1397,7 +1393,7 @@ class Invoice extends Base {
// Only show the title if there's more than one product sold.
if (count($data) > 1) {
$message .= '<tr><td></td><td></td><td><b>Total</b></td><td><b>$' .
number_format($total, 2, '.', '') . '</b></td></tr>';
price_string($total) . '</b></td></tr>';
}
$message .= '</table>' . "\n";
}
......@@ -1474,14 +1470,14 @@ class Invoice extends Base {
$invoice_balance = (float)$this->Substitute('invoice-balance');
if ($balance > $invoice_balance + 0.01) {
if ($credit === 1) {
$text .= '<p>Your balance is currently <b>$' .
number_format($balance, 2, '.', '') . '</b> and you have chosen ' .
'to keep this as credit in the system.</p>' . "\n";
$text .= '<p>Your balance is currently <b>$' . price_string($balance) .
'</b> and you have chosen to keep this as credit in the system.</p>' .
"\n";
}
else {
$text .= '<p>Your balance is currently <b>$' .
number_format($balance, 2, '.', '') . '</b>, ' .
'please expect a payment from our finance team shortly.</p>' . "\n";
$text .= '<p>Your balance is currently <b>$' . price_string($balance) .
'</b>, please expect a payment from our finance team shortly.</p>' .
"\n";
}
}
else if ($balance < $invoice_balance - 0.01) {
......@@ -1497,12 +1493,12 @@ class Invoice extends Base {
// Also if processing has never been done, don't want to show a timestamp.
if ($timestamp === 0 || time() < $timestamp + 86400) {
$text .= $this->Substitute('invoice-current-balance', '/!balance/',
number_format($balance, 2, '.', ''));
price_string($balance));
}
else {
$text .= $this->Substitute('invoice-old-balance',
['/!balance/', '/!date/'],
[number_format($balance, 2, '.', ''),
[price_string($balance),
date('j F Y', $timestamp)]);
}
}
......@@ -1612,7 +1608,7 @@ class Invoice extends Base {
$quantity = $details['quantity'];
$unit = isset($products[$name]['unit']) ?
'/' . $products[$name]['unit'] : '';
$price = '$' . number_format($details['basePrice'], 2, '.', '') . $unit;
$price = '$' . price_string($details['basePrice']) . $unit;
if ($format === 'user') {
$message .= '<tr><td>' . $user . '</td><td>' . $name . '</td><td>' .
$supplier . '</td><td>' . $quantity . '</td><td>' . $price .
......@@ -1743,7 +1739,7 @@ class Invoice extends Base {
$quantity = $details['quantity'];
$unit = isset($products[$name]['unit']) ?
'/' . $products[$name]['unit'] : '';
$price = '$' . number_format($details['basePrice'], 2, '.', '') . $unit;
$price = '$' . price_string($details['basePrice']) . $unit;
$previous_name = $name;
$total_quantity += $quantity;
$count++;
......@@ -1760,7 +1756,7 @@ class Invoice extends Base {
}
// Also store each product order in the supplier data.
if (!is_array($data[$supplier])) $data[$supplier] = [];
if (!isset($data[$supplier])) $data[$supplier] = [];
if ($format === 'vertical') {
$size = isset($products[$name]['size']) ?
$products[$name]['size'] : 'unavailable';
......@@ -1769,7 +1765,7 @@ class Invoice extends Base {
'size' => $size];
}
else {
if (!is_array($data[$supplier][$name])) {
if (!isset($data[$supplier][$name])) {
$size = isset($products[$name]['size']) ?
$products[$name]['size'] : 'unavailable';
$data[$supplier][$name] = ['price' => $price, 'group' => [],
......@@ -2225,7 +2221,7 @@ class Invoice extends Base {
'payments' => ''];
$balance = $total_payments + $total_sold - $total_purchase;
$indexed[] = ['date' => 'BALANCE', 'purchases' => '', 'sold' => '',
'payments' => number_format($balance, 2, '.', '')];
'payments' => price_string($balance)];
$date = date('Y-m-d');
$filename = 'invoice-' . $username . '-' . $date . '.csv';
$this->CreateCSV($filename, $indexed, false);
......
<?php
// Dobrado Content Management System
// Copyright (C) 2017 Malcolm Blaney
// Copyright (C) 2019 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -110,21 +110,22 @@ class Report extends Base {
$this->user->group = $purchase_group;
}
$parent = $organiser->Parent();
if ($parent === false) $parent = '';
// The organisation can use 'group-name' to add a descriptive name.
$parent_description = $this->Substitute('group-name', '', '', $parent);
if ($parent_description === '') $parent_description = $parent;
$content .= '<div class="report-spacing">Showing report for '.
'<select id="report-group-select">'.
'<option value="'.$parent.'">'.$parent_description.'</option>';
$content .= '<div class="report-spacing">Showing report for ' .
'<select id="report-group-select">' .
'<option value="' . $parent . '">' . $parent_description .'</option>';
for ($i = 0; $i < count($siblings); $i++) {
$group = $siblings[$i];
if ($group === $this->user->group && $purchase_group !== '') {
$content .= '<option selected="selected" value="'.$group.'">'.
$this->Substitute('group-name').'</option>';
$content .= '<option selected="selected" value="' . $group . '">' .
$this->Substitute('group-name') . '</option>';
}
else {
$content .= '<option value="'.$group.'">'.
$this->Substitute('group-name', '', '', $group).'</option>';
$content .= '<option value="' . $group . '">' .
$this->Substitute('group-name', '', '', $group) . '</option>';
}
}
// If purchase_group isn't set, show report for the organisation.
......@@ -139,21 +140,22 @@ class Report extends Base {
$this->user->group = $purchase_group;
}
if ($content === '') {
$content .= '<div class="report-spacing">Showing report for '.
'<select id="report-group-select">'.
'<option value="'.$default_group.'">'.
$this->Substitute('group-name', '', '', $default_group).'</option>';
$content .= '<div class="report-spacing">Showing report for ' .
'<select id="report-group-select">' .
'<option value="' . $default_group . '">' .
$this->Substitute('group-name', '', '', $default_group) .
'</option>';
}
for ($i = 0; $i < count($created); $i++) {
$group = $created[$i];
if ($group === $this->user->group) {
$content .= '<option selected="selected" value="'.$group.'">'.
$this->Substitute('group-name').'</option>';
$content .= '<option selected="selected" value="' . $group . '">' .
$this->Substitute('group-name') . '</option>';
$invite_group = true;
}
else {
$content .= '<option value="'.$group.'">'.
$this->Substitute('group-name', '', '', $group).'</option>';
$content .= '<option value="' . $group . '">' .
$this->Substitute('group-name', '', '', $group) . '</option>';
}
}
}
......@@ -161,7 +163,7 @@ class Report extends Base {
$content .= '</select></div>';
}
$report_content = $this->CreateReport($invite_group, $organisation);
$content .= '<div class="report-content">'.$report_content.'</div>';
$content .= '<div class="report-content">' . $report_content . '</div>';
$this->user->group = $default_group;
return $content;
}
......@@ -197,7 +199,7 @@ class Report extends Base {
$site_style = ['"",".report label","width","5em"',
'"","#report-collate-orders","margin-left","4.8em"',
'"","#report-collate-orders","margin-bottom","1em"',
'"","#report-collate-orders-search","border",'.
'"","#report-collate-orders-search","border",' .
'"1px solid #aaaaaa"',
'"","#report-collate-orders-search","margin-bottom","20px"',
'"","#report-collate-orders-search","padding","5px"',
......@@ -216,20 +218,20 @@ class Report extends Base {
'"",".report-purchase-search","border","1px solid #aaaaaa"',
'"",".report-purchase-search","margin-bottom","20px"',
'"",".report-purchase-search","padding","5px"',
'"",".report-received-payment-search","border",'.
'"",".report-received-payment-search","border",' .
'"1px solid #aaaaaa"',
'"",".report-received-payment-search",'.
'"",".report-received-payment-search",' .
'"margin-bottom","20px"',
'"",".report-received-payment-search","padding","5px"',
'"",".report-outgoing-payment-search","border",'.
'"",".report-outgoing-payment-search","border",' .
'"1px solid #aaaaaa"',
'"",".report-outgoing-payment-search",'.
'"",".report-outgoing-payment-search",' .
'"margin-bottom","20px"',
'"",".report-outgoing-payment-search","padding","5px"',
'"",".report-sales-search","border","1px solid #aaaaaa"',
'"",".report-sales-search","margin-bottom","20px"',
'"",".report-sales-search","padding","5px"',
'"",".report-attendance-search","border",'.
'"",".report-attendance-search","border",' .
'"1px solid #aaaaaa"',
'"",".report-attendance-search","margin-bottom","20px"',
'"",".report-attendance-search","padding","5px"'];
......@@ -329,7 +331,7 @@ class Report extends Base {
$payment = $balance - $invoice_balance;
$total += $payment;
$data[] = ['user' => $user, 'fullname' => $full_name, 'email' => $email,
'data' => number_format($payment * -1, 2, '.', '')];
'data' => price_string($payment * -1)];
}
$this->user->group = $default_group;
$info = '';
......@@ -337,13 +339,13 @@ class Report extends Base {
$info = '<b>1</b> account payable, total: <b>$';
}
else {
$info = '<b>'.count($data).'</b> accounts payable, total: <b>$';
$info = '<b>' . count($data) . '</b> accounts payable, total: <b>$';
}
$info .= number_format($total * -1, 2, '.', '').'</b>';
$info .= price_string($total * -1) . '</b>';
if ($_POST['download'] === '1' && count($data) > 0) {
$date = date('Y-m-d');
$filename = 'accounts-payable-'.$date.'.csv';
$filename = 'accounts-payable-' . $date . '.csv';
$this->CreateCSV($filename, $data, false, 'payment');
return ['info' => $info, 'data' => $data, 'filename' => $filename];
}
......@@ -381,15 +383,15 @@ class Report extends Base {
$group_query = $organiser->GroupQuery();
}
else {
$group_query = 'users.system_group = "'.$this->user->group.'"';
$group_query = 'users.system_group = "' . $this->user->group . '"';
}
$total = 0;
$data = [];
$mysqli = connect_db();
$query = 'SELECT user, active FROM users WHERE user NOT LIKE "buyer\_%" '.
'AND '.$group_query;
if ($result = $mysqli->query($query)) {
while ($users = $result->fetch_assoc()) {
$query = 'SELECT user, active FROM users WHERE user NOT LIKE "buyer\_%" ' .
'AND ' . $group_query;
if ($mysqli_result = $mysqli->query($query)) {
while ($users = $mysqli_result->fetch_assoc()) {
$username = $users['user'];
$active = (int)$users['active'];
if ($active === 1) $total++;
......@@ -410,10 +412,10 @@ class Report extends Base {
$data[] = ['user' => $username, 'fullname' => $full_name,
'email' => $email, 'data' => $active];
}
$result->close();
$mysqli_result->close();
}
else {
$this->Log('Report->ActiveMembers: '.$mysqli->error);
$this->Log('Report->ActiveMembers: ' . $mysqli->error);
}
$mysqli->close();
$this->user->group = $default_group;
......@@ -422,13 +424,13 @@ class Report extends Base {
$info = '<b>1</b> active member';
}
else {
$info = '<b>'.$total.'</b> active members';
$info = '<b>' . $total . '</b> active members';
}
$info .= ' ('.(count($data) - $total).' inactive).';
$info .= ' (' . (count($data) - $total) . ' inactive).';
if ($_POST['download'] === '1' && count($data) > 0) {
$date = date('Y-m-d');
$filename = 'active-members-'.$date.'.csv';
$filename = 'active-members-' . $date . '.csv';
$this->CreateCSV($filename, $data, false, 'active');
return ['info' => $info, 'data' => $data, 'filename' => $filename];
}
......@@ -490,7 +492,7 @@ class Report extends Base {
if ($days === 1) return $result;
// Add the end date to the displayed date text.
$result['date'] .= ' - '.date('j M Y', $end);
$result['date'] .= ' - ' . date('j M Y', $end);
$result['series'] = [['showMarker' => false]];
// There's only one data series to display, so it can just be wrapped in
// another array here.
......@@ -579,38 +581,38 @@ class Report extends Base {
$display_total = false;
$content .= '<div class="report-spacing">';
if ($this->Substitute('report-change-order-dates') === 'true') {
$content .= '<div id="report-collate-orders-search">'.
'Enter dates to collate order:'.
'<div class="form-spacing">'.
'<label for="report-collate-start">Start:</label>'.
'<input id="report-collate-start" maxlength="50" type="text">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="report-collate-end">End:</label>'.
'<input id="report-collate-end" maxlength="50" type="text">'.
'</div>'.
'<button id="report-collate-orders">collate orders</button>'.
'<span id="report-collate-info"></span>'.
$content .= '<div id="report-collate-orders-search">' .
'Enter dates to collate order:' .
'<div class="form-spacing">' .
'<label for="report-collate-start">Start:</label>' .
'<input id="report-collate-start" maxlength="50" type="text">' .
'</div>' .
'<div class="form-spacing">' .
'<label for="report-collate-end">End:</label>' .
'<input id="report-collate-end" maxlength="50" type="text">' .
'</div>' .
'<button id="report-collate-orders">collate orders</button>' .
'<span id="report-collate-info"></span>' .
'</div>';
}
else {
$content .= '<div id="report-collate-orders-search">'.
'If the order has been modified after the collated order '.
'email was sent, you can re-process the order now and then '.
'download the new order list when it has finished processing: '.
'<button id="report-collate-orders">collate orders</button>'.
'<span id="report-collate-info"></span>'.
$content .= '<div id="report-collate-orders-search">' .
'If the order has been modified after the collated order ' .
'email was sent, you can re-process the order now and then ' .
'download the new order list when it has finished processing: ' .
'<button id="report-collate-orders">collate orders</button>' .
'<span id="report-collate-info"></span>' .
'</div>';
}
$content .= '<div id="report-order-info">Download lists for order: '.
'<select id="report-format-select">'.
$this->FormatSelect($invite_group || $organisation).'</select>'.
'<button id="report-order-download">download</button>'.
$content .= '<div id="report-order-info">Download lists for order: ' .
'<select id="report-format-select">' .
$this->FormatSelect($invite_group || $organisation) . '</select>' .
'<button id="report-order-download">download</button>' .
'</div><div id="report-order-result"></div>';
if ($weekly) {
$display_total = true;
$content .= '<div class="report-order">Total orders for next week: ';
$start = (int)strtotime('next '.$co_op_day);
$start = (int)strtotime('next ' . $co_op_day);
$end = $start + 86400;
}
else if (strtotime($co_op_day) > time()) {
......@@ -624,8 +626,8 @@ class Report extends Base {
$content .= '<div class="report-order">Total orders: ';
}
else {
$content .= '<div class="report-order">Total orders for '.
$co_op_day.': ';
$content .= '<div class="report-order">Total orders for ' .
$co_op_day . ': ';
}
}
if ($display_total) {
......@@ -635,11 +637,11 @@ class Report extends Base {
foreach ($all_totals as $user => $total) {
$order_total += $total;
}
$content .= '<b>$'.number_format($order_total, 2, '.', '').'</b></div>';
$content .= '<b>$' . price_string($order_total) . '</b></div>';
}
// Close "report-spacing" div before "report-quotas" div which needs to
// be the full width of the parent to show the grid properly.
$content .= '<button id="report-quotas-button">show quotas</button>'.
$content .= '<button id="report-quotas-button">show quotas</button>' .
'</div><div class="report-quotas"></div>';
}
$content .= '<div class="report-spacing">';
......@@ -649,29 +651,29 @@ class Report extends Base {
if ($weekly) {
$start = (int)strtotime($co_op_day);
if ($start > time()) {
$start = (int)strtotime('last '.$co_op_day);
$start = (int)strtotime('last ' . $co_op_day);
}
$end = $start + 7 * 86400;
$content .= '<div class="report-purchase">Total purchases for '.
$content .= '<div class="report-purchase">Total purchases for ' .
'<span class="report-purchase-date">this week</span>: ';
}
else if (strtotime($co_op_day) < time()) {
$start = (int)strtotime($co_op_day);
$end = $start + 86400;
$content .= '<div class="report-purchase">Total purchases for '.
'<span class="report-purchase-date">'.$co_op_day.'</span>: ';
$content .= '<div class="report-purchase">Total purchases for ' .
'<span class="report-purchase-date">' . $co_op_day . '</span>: ';
}
else {
$content .= '<div class="report-purchase hidden">Total purchases for '.
'<span class="report-purchase-date"></span>: '.
'<b>$<span class="report-purchase-total"></span></b>'.
'</div>'.