FIX MVC and missing http header in TakePOS

This commit is contained in:
Laurent Destailleur 2022-08-22 01:56:19 +02:00
parent 8e15f95890
commit 0258da808c
15 changed files with 151 additions and 86 deletions

View File

@ -58,11 +58,14 @@ if (empty($user->rights->takepos->run)) {
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
$hookmanager->initHooks(array('takeposproductsearch')); // new context for product search hooks
/*
* View
*/
if ($action == 'getProducts') {
top_httphead('application/json');
$object = new Categorie($db);
if ($category == "supplements") {
$category = getDolGlobalInt('TAKEPOS_SUPPLEMENTS_CATEGORY');
@ -88,9 +91,11 @@ if ($action == 'getProducts') {
}
echo json_encode($res);
} else {
echo 'Failed to load category with id='.$category;
echo 'Failed to load category with id='.dol_escape_htmltag($category);
}
} elseif ($action == 'search' && $term != '') {
top_httphead('application/json');
// Change thirdparty with barcode
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
@ -329,8 +334,8 @@ if ($action == 'getProducts') {
require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
$printer = new dolReceiptPrinter($db);
// check printer for terminal
if ($conf->global->{'TAKEPOS_PRINTER_TO_USE'.$term} > 0) {
$printer->initPrinter($conf->global->{'TAKEPOS_PRINTER_TO_USE'.$term});
if (getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) {
$printer->initPrinter(getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term));
// open cashdrawer
$printer->pulse();
$printer->close();
@ -340,12 +345,14 @@ if ($action == 'getProducts') {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$printer = new dolReceiptPrinter($db);
// check printer for terminal
if (($conf->global->{'TAKEPOS_PRINTER_TO_USE'.$term} > 0 || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") && $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term} > 0) {
if ((getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0 || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") && getDolGlobalInt('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term) > 0) {
$object = new Facture($db);
$object->fetch($id);
$ret = $printer->sendToPrinter($object, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term}, $conf->global->{'TAKEPOS_PRINTER_TO_USE'.$term});
$ret = $printer->sendToPrinter($object, getDolGlobalString('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term), getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$term));
}
} elseif ($action == 'getInvoice') {
top_httphead('application/json');
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$object = new Facture($db);
@ -359,5 +366,5 @@ if ($action == 'getProducts') {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
$printer = new dolReceiptPrinter($db);
$printer->sendToPrinter($object, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term}, $conf->global->{'TAKEPOS_PRINTER_TO_USE'.$term});
$printer->sendToPrinter($object, getDolGlobalString('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term), getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$term));
}

View File

@ -81,6 +81,8 @@ if ($action == "getTables") {
}
$rows[] = $row;
}
top_httphead('application/json');
echo json_encode($rows);
exit;
}
@ -119,13 +121,18 @@ if ($action == "add") {
*/
// Title
$head = '';
$title = 'TakePOS - Dolibarr '.DOL_VERSION;
if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
$title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
}
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
$arrayofcss = array('/takepos/css/pos.css.php?a=xxx');
top_htmlhead($head, $title, 0, 0, '', $arrayofcss);
?>
<link rel="stylesheet" href="css/pos.css.php?a=xxx">
<body style="overflow: hidden">
<style type="text/css">
div.tablediv{
background-image:url(img/table.gif);
@ -205,8 +212,7 @@ $( document ).ready(function() {
});
</script>
</head>
<body style="overflow: hidden">
<?php if ($user->admin) {?>
<div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
<?php if ($mode == "edit") {?>
@ -233,5 +239,6 @@ $( document ).ready(function() {
</h1>
</center>
</div>
</body>
</html>

View File

@ -78,6 +78,7 @@ if ($invoice->socid > 0) {
}
$vatRateDefault = get_default_tva($mysoc, $soc);
/*
* View
*/
@ -87,6 +88,8 @@ $arrayofjs = array();
top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
?>
<body>
<script>
var vatRate = '<?php echo dol_escape_js($vatRateDefault); ?>';
@ -116,8 +119,7 @@ top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
$('#desc').focus()
});
</script>
</head>
<body>
<br>
<center>
<input type="text" id="desc" name="desc" class="takepospay" style="width:40%;" placeholder="<?php echo $langs->trans('Description'); ?>">

View File

@ -15,6 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// This page return an image of a photo
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
if (!defined('NOREQUIRESOC')) {
@ -74,6 +76,7 @@ if ($query == "cat") {
exit;
}
header('Location: ../../public/theme/common/nophoto.png');
exit;
} elseif ($query == "pro") {
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
@ -86,15 +89,18 @@ if ($query == "cat") {
$file = array_pop($match);
if ($file == "") {
header('Location: ../../public/theme/common/nophoto.png');
exit;
} else {
if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
header('Location: '.$file.'&cache=1');
exit;
} else {
header('Location: '.$file.'&cache=1&publictakepos=1&modulepart=product');
exit;
}
}
} else {
// TODO We don't need this. Size of image must be defined on HTML page, image must NOT be resize when downloaded.
// TODO We don't need this. Size of image must be defined on HTML page, image must NOT be resized when downloaded.
// The file
$filename = $query.".jpg";

View File

@ -15,6 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// This page return an image of a QR code
if (!defined("NOLOGIN")) {
define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
}
@ -46,6 +48,13 @@ require '../../core/modules/barcode/doc/tcpdfbarcode.modules.php';
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
/*
* View
*/
// The buildBarCode does not include the http headers but this is a page that just return an image.
if (GETPOSTISSET("key")) {
$key = GETPOST('key');
$module = new modTcpdfbarcode();

View File

@ -97,11 +97,11 @@ $MAXCATEG = (empty($conf->global->TAKEPOS_NB_MAXCATEG) ? $maxcategbydefaultforth
$MAXPRODUCT = (empty($conf->global->TAKEPOS_NB_MAXPRODUCT) ? $maxproductbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXPRODUCT);
/*
$constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
$soc = new Societe($db);
if ($invoice->socid > 0) $soc->fetch($invoice->socid);
else $soc->fetch($conf->global->$constforcompanyid);
*/
$constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
$soc = new Societe($db);
if ($invoice->socid > 0) $soc->fetch($invoice->socid);
else $soc->fetch($conf->global->$constforcompanyid);
*/
// Security check
$result = restrictedArea($user, 'takepos', 0, '');
@ -116,8 +116,13 @@ $form = new Form($db);
$disablejs = 0;
$disablehead = 0;
$arrayofjs = array();
$arrayofcss = array();
$arrayofjs = array('/takepos/js/jquery.colorbox-min.js'); // TODO It seems we don't need this
$arrayofcss = array('/takepos/css/pos.css.php', '/takepos/css/colorbox.css');
if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
$arrayofcss[] = '/takepos/css/colorful.css';
}
// Title
$title = 'TakePOS - Dolibarr '.DOL_VERSION;
@ -130,17 +135,7 @@ $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
?>
<link rel="stylesheet" href="css/pos.css.php">
<link rel="stylesheet" href="css/colorbox.css" type="text/css" media="screen" />
<?php
if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
print '<link rel="stylesheet" href="css/colorful.css">';
}
?>
<script type="text/javascript" src="js/jquery.colorbox-min.js"></script> <!-- TODO It seems we don't need this -->
<script type="text/javascript">
<?php
$categories = $categorie->get_full_arbo('product', ((getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) ? getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') : 0), 1);
@ -172,6 +167,9 @@ $maincategories = dol_sort_array($maincategories, 'label');
$subcategories = dol_sort_array($subcategories, 'label');
?>
<body class="bodytakepos" style="overflow: hidden;">
<script>
var categories = <?php echo json_encode($maincategories); ?>;
var subcategories = <?php echo json_encode($subcategories); ?>;
@ -374,7 +372,11 @@ function LoadProducts(position, issubcat) {
$("#proprice"+ishow).attr("class", "productprice");
$("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']);
}
console.log("#prodiv"+ishow+".data(rowid)="+data[idata]['id']);
console.log($("#prodiv"+ishow));
$("#prodiv"+ishow).data("rowid", data[idata]['id']);
console.log($('#prodiv4').data('rowid'));
$("#prodiv"+ishow).data("iscat", 0);
$("#prodiv"+ishow).attr("class","wrapper2");
$("#prowatermark"+ishow).hide();
@ -464,7 +466,7 @@ function MoreProducts(moreorless) {
}
function ClickProduct(position, qty = 1) {
console.log("ClickProduct");
console.log("ClickProduct at position"+position);
$('#proimg'+position).animate({opacity: '0.5'}, 1);
$('#proimg'+position).animate({opacity: '1'}, 100);
if ($('#prodiv'+position).data('iscat')==1){
@ -472,6 +474,7 @@ function ClickProduct(position, qty = 1) {
LoadProducts(position, true);
}
else{
console.log($('#prodiv4').data('rowid'));
idproduct=$('#prodiv'+position).data('rowid');
console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty);
if (idproduct=="") return;
@ -939,7 +942,6 @@ $( document ).ready(function() {
});
</script>
<body class="bodytakepos" style="overflow: hidden;">
<?php
$keyCodeForEnter = getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) > 0 ? getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : '';
?>

View File

@ -929,14 +929,14 @@ if (empty($reshook)) {
}
}
/*
* View
*/
$form = new Form($db);
if (!defined('INCLUDE_INVOICE_PAGE_FROM_OTHER_PAGE')) {
// llxHeader
if ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
$title = 'TakePOS - Dolibarr '.DOL_VERSION;
if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
$title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
@ -947,15 +947,19 @@ if (!defined('INCLUDE_INVOICE_PAGE_FROM_OTHER_PAGE')) {
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
$arrayofcss = array(
'/takepos/css/pos.css.php',
'/takepos/js/jquery.colorbox-min.js'
);
$arrayofjs = array('/takepos/js/jquery.colorbox-min.js');
$disablejs = 0;
$disablehead = 0;
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
print '<body>'."\n";
} else {
top_httphead('text/html', 1);
}
?>
<!-- invoice.php -->
<script type="text/javascript">
var selectedline=0;
var selectedtext="";
@ -1689,7 +1693,8 @@ if ($action == "search") {
print '</div>';
if (!defined('INCLUDE_INVOICE_PAGE_FROM_OTHER_PAGE')) {
llxFooter();
// llxFooter
if ((getDolGlobalString('TAKEPOS_PHONE_BASIC_LAYOUT') == 1 && $conf->browser->layout == 'phone') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
print '</body></html>';
}

View File

@ -53,6 +53,30 @@ if (empty($user->rights->takepos->run)) {
accessforbidden();
}
/*
* View
*/
$arrayofcss = array('/takepos/css/pos.css.php');
$arrayofjs = array();
$head = '';
$title = '';
$disablejs = 0;
$disablehead = 0;
$head='<link rel="stylesheet" href="css/pos.css.php">';
if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
$head .= '<link rel="stylesheet" href="css/colorful.css">';
}
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
?>
<body>
<?php
if (!empty($conf->stripe->enabled)) {
$service = 'StripeTest';
$servicestatus = 0;
@ -99,10 +123,6 @@ function fetchConnectionToken() {
</script>
<?php }
/*
* View
*/
if (!empty($conf->stripe->enabled) && isset($keyforstripeterminalbank) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning', 1);
}
@ -175,16 +195,6 @@ if ($invoiceid > 0) {
</script>
<?php
$arrayofcss = array('/takepos/css/pos.css.php');
$arrayofjs = array();
$head = '';
$title = '';
$disablejs = 0;
$disablehead = 0;
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
// Define list of possible payments
$arrayOfValidPaymentModes = array();
$arrayOfValidBankAccount = array();
@ -219,14 +229,6 @@ if ($resql) {
}
}
?>
<link rel="stylesheet" href="css/pos.css.php">
<?php
if ($conf->global->TAKEPOS_COLOR_THEME == 1) {
print '<link rel="stylesheet" href="css/colorful.css">';
}
?>
</head>
<body>
<script>
<?php

View File

@ -69,10 +69,27 @@ if (empty($user->rights->takepos->run) && !defined('INCLUDE_PHONEPAGE_FROM_PUBLI
accessforbidden();
}
/*
* View
*/
if (empty($action)) {
// Code for llxHeader()
$title = 'TakePOS - Dolibarr '.DOL_VERSION;
if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
$title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
}
$head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
$arrayofcss = array('/takepos/css/phone.css');
top_htmlhead($head, $title, 0, 0, '', '');
} else {
top_httphead('text/html', 1);
}
if ($action == "productinfo") {
$prod = new Product($db);
$prod->fetch($idproduct);
@ -139,17 +156,6 @@ if ($action == "productinfo") {
}
}
} else {
// Title
$title = 'TakePOS - Dolibarr '.DOL_VERSION;
if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
$title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
}
$head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
$arrayofcss = array('/takepos/css/phone.css');
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
?>
<script type="text/javascript">
<?php

View File

@ -67,7 +67,9 @@ $arrayofjs = array('/takepos/js/jquery.colorbox-min.js');
$head = '';
top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
?>
<body>
<script>
/**
* Save (validate)
@ -82,8 +84,7 @@ top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
$('#label').focus()
});
</script>
</head>
<body>
<br>
<center>
<?php

View File

@ -66,7 +66,7 @@ if (empty($user->rights->takepos->run)) {
* View
*/
top_httphead('text/html');
top_httphead('text/html', 1);
if ($place > 0) {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
@ -90,7 +90,6 @@ if (!empty($hookmanager->resPrint)) {
// IMPORTANT: This file is sended to 'Takepos Printing' application. Keep basic file. No external files as css, js... If you need images use absolute path.
?>
<html>
<body>
<style>
.right {

View File

@ -74,6 +74,7 @@ if ($invoiceid > 0) {
}
}
$head = '';
$arrayofcss = array('/takepos/css/pos.css.php');
$arrayofjs = array();

View File

@ -61,6 +61,11 @@ $invoice->fetch($facid);
$customer = new Societe($db);
$customer->fetch($invoice->socid);
/*
* Actions
*/
if ($action == "send") {
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
@ -86,11 +91,17 @@ if ($action == "send") {
}
exit;
}
/*
* View
*/
$arrayofcss = array('/takepos/css/pos.css.php');
$arrayofjs = array();
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
?>
</head>
<body class="center">
<script>

View File

@ -47,6 +47,13 @@ if (GETPOSTISSET('status')) {
die(strtoupper($_SESSION['SMP_CURRENT_PAYMENT']));
}
/*
* View
*/
top_httphead('text/html', 1);
if (GETPOST('smp-status')) {
print '<html lang="en">';
print '<head>';

View File

@ -53,6 +53,11 @@ if (empty($user->rights->takepos->run)) {
accessforbidden();
}
/*
* Actions
*/
if ($action=="split") {
$line = GETPOST('line', 'int');
$split = GETPOST('split', 'int');
@ -139,6 +144,9 @@ if ($invoiceid > 0) {
}
$arrayofcss = array('/takepos/css/pos.css.php');
if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
$arrayofcss[] = '/takepos/css/colorful.css';
}
$arrayofjs = array();
$head = '';
@ -152,15 +160,7 @@ top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
$arrayOfValidPaymentModes = array();
$arrayOfValidBankAccount = array();
?>
<link rel="stylesheet" href="css/pos.css.php">
<?php
if ($conf->global->TAKEPOS_COLOR_THEME == 1) {
print '<link rel="stylesheet" href="css/colorful.css">';
}
?>
</head>
<body class="takepossplitphp">
<script>