Skip to content

Commit

Permalink
many improvements to functions and also new, list and edit features (l…
Browse files Browse the repository at this point in the history
…irantal#347)

* Uniformed list features UI

* Uniformed all new layouts

* uniformed some "edit" layouts

* fixed menu interactions

* Improved some utility function
  • Loading branch information
filippolauria authored Jan 24, 2023
1 parent 561884c commit 00ca70b
Show file tree
Hide file tree
Showing 60 changed files with 2,322 additions and 1,783 deletions.
91 changes: 42 additions & 49 deletions bill-invoice-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,42 @@
include("library/checklogin.php");
$operator = $_SESSION['operator_user'];

include('library/check_operator_perm.php');
include_once('library/config_read.php');
include_once("lang/main.php");
include("library/layout.php");

// init logging variables
$log = "visited page: ";
$logQuery = "performed query on page: ";
$logDebugSQL = "";

include('library/check_operator_perm.php');
include_once('library/config_read.php');
// set session's page variable
$_SESSION['PREV_LIST_PAGE'] = $_SERVER['REQUEST_URI'];

$cols = array(
"id" => t('all','Invoice'),
"contactperson" => t('all','ClientName'),
"date" => t('all','Date'),
"totalbilled" => t('all','TotalBilled'),
"totalpayed" => t('all','TotalPayed'),
t('all','Balance'),
"status_id" => t('all','Status')
);
$colspan = count($cols);
$half_colspan = intval($colspan / 2);

$param_cols = array();
foreach ($cols as $k => $v) { if (!is_int($k)) { $param_cols[$k] = $v; } }

// whenever possible we use a whitelist approach
$orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) &&
in_array($_GET['orderBy'], array_keys($param_cols)))
? $_GET['orderBy'] : array_keys($param_cols)[0];

$orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) &&
in_array(strtolower($_GET['orderType']), array( "desc", "asc" )))
? strtolower($_GET['orderType']) : "desc";

$user_id = (array_key_exists('user_id', $_GET) && isset($_GET['user_id']) &&
preg_match('/^[0-9]+$/', $_GET['user_id']) !== false)
Expand All @@ -44,13 +73,11 @@
preg_match('/^[0-9]+$/', $_GET['invoice_status_id']) !== false)
? $_GET['invoice_status_id'] : "";

// feed the sidebar
$edit_invoice_status_id = $invoice_status_id;
$edit_invoiceUsername = $username_enc;

include_once("lang/main.php");

include("library/layout.php");

// print HTML prologue
$extra_js = array(
"library/javascript/ajax.js",
Expand All @@ -64,30 +91,7 @@

include("menu-bill-invoice.php");

$cols = array(
"id" => t('all','Invoice'),
"contactperson" => t('all','ClientName'),
"date" => t('all','Date'),
"totalbilled" => t('all','TotalBilled'),
"totalpayed" => t('all','TotalPayed'),
t('all','Balance'),
"status_id" => t('all','Status')
);
$colspan = count($cols);
$half_colspan = intval($colspan / 2);

$param_cols = array();
foreach ($cols as $k => $v) { if (!is_int($k)) { $param_cols[$k] = $v; } }

// whenever possible we use a whitelist approach
$orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) &&
in_array($_GET['orderBy'], array_keys($param_cols)))
? $_GET['orderBy'] : array_keys($param_cols)[0];

$orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) &&
in_array(strtolower($_GET['orderType']), array( "desc", "asc" )))
? strtolower($_GET['orderType']) : "desc";

// start printing content
echo '<div id="contentnorightbar">';
print_title_and_help($title, $help);
Expand Down Expand Up @@ -268,26 +272,15 @@
}

include('library/closedb.php');
?>

</div><!-- #contentnorightbar -->

<div id="footer">
<?php

include('include/config/logging.php');
include('page-footer.php');

$inline_extra_js = "
var tooltipObj = new DHTMLgoodies_formTooltip();
tooltipObj.setTooltipPosition('right');
tooltipObj.setPageBgColor('#EEEEEE');
tooltipObj.setTooltipCornerSize(15);
tooltipObj.initFormFieldTooltip()";

print_footer_and_html_epilogue($inline_extra_js);
?>
</div><!-- #footer -->
</div>
</div>

<script>
var tooltipObj = new DHTMLgoodies_formTooltip();
tooltipObj.setTooltipPosition('right');
tooltipObj.setPageBgColor('#EEEEEE');
tooltipObj.setTooltipCornerSize(15);
tooltipObj.initFormFieldTooltip();
</script>

</body>
</html>
7 changes: 5 additions & 2 deletions bill-invoice-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@
$failureMsg = sprintf("The required field '%s' is empty or invalid", t('all','UserId'));
$logAction .= "$failureMsg on page: ";
} else {
$sql = sprintf("INSERT INTO %s (id, user_id, date, status_id, type_id, notes, creationdate, creationby)
VALUES (0, %d, '%s', %d, %d, '%s', '%s', '%s')",
$sql = sprintf("INSERT INTO %s (id, user_id, date, status_id, type_id, notes,
creationdate, creationby, updatedate, updateby)
VALUES (0, %d, '%s', %d, %d, '%s', '%s', '%s', NULL, NULL)",
$configValues['CONFIG_DB_TBL_DALOBILLINGINVOICE'], $user_id, $invoice_date,
$invoice_status_id, $invoice_type_id, $dbSocket->escapeSimple($invoice_notes),
$currDate, $currBy);
Expand Down Expand Up @@ -469,6 +470,8 @@ function removeTableRow(rowId) {
close_form();
}

print_back_to_previous_page();

include('include/config/logging.php');
print_footer_and_html_epilogue();

Expand Down
8 changes: 4 additions & 4 deletions bill-payment-types-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
include('library/opendb.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$paymentname = (array_key_exists('paymentname', $_POST) && !empty(trim($_POST['paymentname'])))
? trim($_POST['paymentname']) : "";
$paymentname = (array_key_exists('paymentname', $_POST) && !empty(str_replace("%", "", trim($_POST['paymentname']))))
? str_replace("%", "", trim($_POST['paymentname'])) : "";
} else {
$paymentname = (array_key_exists('paymentname', $_REQUEST) && !empty(trim($_REQUEST['paymentname'])))
? trim($_REQUEST['paymentname']) : "";
$paymentname = (array_key_exists('paymentname', $_REQUEST) && !empty(str_replace("%", "", trim($_REQUEST['paymentname']))))
? str_replace("%", "", trim($_REQUEST['paymentname'])) : "";
}


Expand Down
29 changes: 13 additions & 16 deletions bill-payment-types-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,18 @@
$operator = $_SESSION['operator_user'];

include('library/check_operator_perm.php');

include_once('library/config_read.php');

// init loggin variables
include_once("lang/main.php");
include("library/layout.php");

// init logging variables
$log = "visited page: ";
$logQuery = "performed query for listing of records on page: ";
$logQuery = "performed query on page: ";
$logDebugSQL = "";

// set session's page variable
$_SESSION['PREV_LIST_PAGE'] = $_SERVER['REQUEST_URI'];

include_once("lang/main.php");

include("library/layout.php");

// print HTML prologue
$title = t('Intro','paymenttypeslist.php');
$help = t('helpPage','paymenttypeslist');

print_html_prologue($title, $langCode);

include("menu-bill-payments.php");

$cols = array(
"id" => t('all','ID'),
"paymentname" => t('all','PayTypeName'),
Expand All @@ -69,6 +58,14 @@
in_array(strtolower($_GET['orderType']), array( "desc", "asc" )))
? strtolower($_GET['orderType']) : "asc";

// print HTML prologue
$title = t('Intro','paymenttypeslist.php');
$help = t('helpPage','paymenttypeslist');

print_html_prologue($title, $langCode);

include("menu-bill-payments.php");


// start printing content
echo '<div id="contentnorightbar">';
Expand Down
8 changes: 5 additions & 3 deletions bill-payment-types-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@
$currBy = $operator;

// insert apyment type info
$sql = sprintf("INSERT INTO %s (id, value, notes, creationdate, creationby)
VALUES (0, '%s', '%s', '%s', '%s')",
$sql = sprintf("INSERT INTO %s (id, value, notes, creationdate, creationby, updatedate, updateby)
VALUES (0, '%s', '%s', '%s', '%s', NULL, NULL)",
$configValues['CONFIG_DB_TBL_DALOPAYMENTTYPES'], $dbSocket->escapeSimple($paymentname),
$dbSocket->escapeSimple($paymentnotes), $currDate, $currBy);
$res = $dbSocket->query($sql);
$logDebugSQL .= "$sql;\n";

if (!DB::isError($res)) {
$successMsg = "Successfully inserted new payment type (<strong>$paymentname_enc</strong>)";
$successMsg = sprintf('Successfully inserted new payment type (<strong>%s</strong>) '
. '[<a href="bill-payment-types-edit.php?paymentname=%s" title="Edit">Edit</a>]',
$paymentname_enc, urlencode($paymentname_enc));
$logAction .= "Successfully inserted new payment type [$paymentname] on page: ";
} else {
$failureMsg = "Failed to insert new payment type (<strong>$paymentname_enc</strong>)";
Expand Down
59 changes: 32 additions & 27 deletions bill-payments-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,41 @@
include("library/checklogin.php");
$operator = $_SESSION['operator_user'];

include('library/check_operator_perm.php');
include_once('library/config_read.php');
include_once("lang/main.php");
include("library/layout.php");

// init logging variables
$log = "visited page: ";
$logQuery = "performed query on page: ";
$logDebugSQL = "";

include('library/check_operator_perm.php');
include_once('library/config_read.php');
// set session's page variable
$_SESSION['PREV_LIST_PAGE'] = $_SERVER['REQUEST_URI'];

$cols = array(
"id" => t('all','ID'),
"invoice_id" => t('all','PaymentInvoiceID'),
t('all','PaymentAmount'),
t('all','PaymentDate'),
t('all','PaymentType'),
t('all','PaymentNotes')
);
$colspan = count($cols);
$half_colspan = intval($colspan / 2);

$param_cols = array();
foreach ($cols as $k => $v) { if (!is_int($k)) { $param_cols[$k] = $v; } }

// whenever possible we use a whitelist approach
$orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) &&
in_array($_GET['orderBy'], array_keys($param_cols)))
? $_GET['orderBy'] : array_keys($param_cols)[0];

$orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) &&
in_array(strtolower($_GET['orderType']), array( "desc", "asc" )))
? strtolower($_GET['orderType']) : "desc";

$invoice_id = (array_key_exists('invoice_id', $_GET) && isset($_GET['invoice_id']) &&
preg_match('/^[0-9]+$/', $_GET['invoice_id']) !== false)
Expand All @@ -44,13 +72,11 @@
? str_replace('%', '', $_GET['username']) : "";
$username_enc = (!empty($username)) ? htmlspecialchars($username, ENT_QUOTES, 'UTF-8') : "";

// feed the sidebar
$edit_username = $username_enc;
$edit_invoice_id = $invoice_id;

include_once("lang/main.php");

include("library/layout.php");

// print HTML prologue
$title = t('Intro','paymentslist.php');
$help = t('helpPage','paymentslist');
Expand All @@ -59,28 +85,6 @@

include("menu-bill-payments.php");

$cols = array(
"id" => t('all','ID'),
"invoice_id" => t('all','PaymentInvoiceID'),
t('all','PaymentAmount'),
t('all','PaymentDate'),
t('all','PaymentType'),
t('all','PaymentNotes')
);
$colspan = count($cols);
$half_colspan = intval($colspan / 2);

$param_cols = array();
foreach ($cols as $k => $v) { if (!is_int($k)) { $param_cols[$k] = $v; } }

// whenever possible we use a whitelist approach
$orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) &&
in_array($_GET['orderBy'], array_keys($param_cols)))
? $_GET['orderBy'] : array_keys($param_cols)[0];

$orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) &&
in_array(strtolower($_GET['orderType']), array( "desc", "asc" )))
? strtolower($_GET['orderType']) : "desc";

// start printing content
echo '<div id="contentnorightbar">';
Expand Down Expand Up @@ -254,6 +258,7 @@
}

include('library/closedb.php');

include('include/config/logging.php');

$inline_extra_js = "
Expand Down
7 changes: 4 additions & 3 deletions bill-payments-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@
$failureMsg = sprintf("Empty or invalid required field(s) [%s]", implode(", ", array_values($required_fields)));
$logAction .= "$failureMsg on page: ";
} else {
$sql = sprintf("INSERT INTO %s (id, invoice_id, amount, date, type_id, notes, creationdate, creationby)
VALUES (0, %d, %s, '%s', %d, '%s', '%s', '%s')",
$sql = sprintf("INSERT INTO %s (id, invoice_id, amount, date, type_id, notes,
creationdate, creationby, updatedate, updateby)
VALUES (0, %d, %s, '%s', %d, '%s', '%s', '%s', NULL, NULL)",
$configValues['CONFIG_DB_TBL_DALOPAYMENTS'], $payment_invoice_id, $payment_amount,
$payment_date, $payment_type_id, $dbSocket->escapeSimple($payment_notes), $currDate, $currBy);

Expand All @@ -107,7 +108,7 @@

if (!DB::isError($res)) {
$successMsg = sprintf("Inserted new payment for invoice: #<strong>%d</strong><br>", $payment_invoice_id)
. sprintf('<a href="bill-invoice-edit.php?invoice_id=%d">edit invoice #%d</a>',
. sprintf('<a href="bill-invoice-edit.php?invoice_id=%d" title="Edit">edit invoice #%d</a>',
$payment_invoice_id, $payment_invoice_id);
$logAction .= "Successfully inserted new payment for invoice [#$payment_invoice_id] on page: ";
} else {
Expand Down
8 changes: 4 additions & 4 deletions bill-plans-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$planName = (array_key_exists('planName', $_POST) && !empty(trim($_POST['planName'])))
? trim($_POST['planName']) : "";
$planName = (array_key_exists('planName', $_POST) && !empty(str_replace("%", "", trim($_POST['planName']))))
? str_replace("%", "", trim($_POST['planName'])) : "";
} else {
$planName = (array_key_exists('planName', $_REQUEST) && !empty(trim($_REQUEST['planName'])))
? trim($_REQUEST['planName']) : "";
$planName = (array_key_exists('planName', $_REQUEST) && !empty(str_replace("%", "", trim($_REQUEST['planName']))))
? str_replace("%", "", trim($_REQUEST['planName'])) : "";
}


Expand Down
Loading

0 comments on commit 00ca70b

Please sign in to comment.