dolibarr 25.0.0-alpha
floors.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
27//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
28//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
29//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
30if (!defined('NOREQUIREMENU')) {
31 define('NOREQUIREMENU', '1');
32}
33if (!defined('NOREQUIREHTML')) {
34 define('NOREQUIREHTML', '1');
35}
36if (!defined('NOREQUIREAJAX')) {
37 define('NOREQUIREAJAX', '1');
38}
39
40// Load Dolibarr environment
41require '../main.inc.php'; // Load $user and permissions
42require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
51$langs->loadLangs(array("bills", "orders", "commercial", "cashdesk"));
52
53if (GETPOSTISSET('floor')) {
54 $floor = GETPOSTINT('floor');
55} else {
56 // No floor requested: open the lowest floor that has tables (floor 1 for tables created before v20, floor 0 since), or floor 1 when there is no table yet
57 $floor = 1;
58 $sql = "SELECT MIN(floor) as minfloor FROM ".MAIN_DB_PREFIX."takepos_floor_tables";
59 $sql .= " WHERE entity IN (".getEntity('takepos').")";
60 $resql = $db->query($sql);
61 if ($resql) {
62 $obj = $db->fetch_object($resql);
63 if ($obj && !is_null($obj->minfloor)) {
64 $floor = (int) $obj->minfloor;
65 }
66 }
67}
68$id = GETPOSTINT('id');
69$action = GETPOST('action', 'aZ09');
70$left = GETPOST('left', 'alpha');
71$top = GETPOST('top', 'alpha');
72
73$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
74
75$newname = GETPOST('newname', 'alpha');
76$mode = GETPOST('mode', 'alpha');
77
78if (!$user->hasRight('takepos', 'run')) {
80}
81
82
83/*
84 * Actions
85 */
86
87if ($action == "getTables" && $user->hasRight('takepos', 'run')) {
88 $rows = array();
89
90 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor";
91 $sql .= " FROM ".MAIN_DB_PREFIX."takepos_floor_tables";
92 $sql .= " WHERE floor = ".((int) $floor)." AND entity IN (".getEntity('takepos').")";
93
94 $resql = $db->query($sql);
95 while ($row = $db->fetch_array($resql)) {
96 $tmpplace = (int) $row['rowid'];
97
98 $invoice = new Facture($db);
99 $result = $invoice->fetch(0, '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$tmpplace.')');
100 if ($result > 0) {
101 $row['occupied'] = "red";
102 }
103
104 $rows[] = $row;
105 }
106
107 top_httphead('application/json');
108 echo json_encode($rows);
109 exit;
110}
111
112if ($action == "update" && $user->hasRight('takepos', 'run')) {
113 if ($left > 95) {
114 $left = 95;
115 }
116 if ($top > 95) {
117 $top = 95;
118 }
119 if ($left > 3 or $top > 4) {
120 $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET leftpos = ".((int) $left).", toppos = ".((int) $top)." WHERE rowid = ".((int) $place));
121 } else {
122 $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables WHERE rowid = ".((int) $place));
123 }
124}
125
126if ($action == "updatename" && $user->hasRight('takepos', 'run')) {
127 $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
128 if (strlen($newname) > 3) {
129 $newname = substr($newname, 0, 3); // Only 3 chars
130 }
131 $resql = $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label='".$db->escape($newname)."' WHERE rowid = ".((int) $place));
132}
133
134if ($action == "add" && $user->hasRight('takepos', 'run')) {
135 $sql = "INSERT INTO ".MAIN_DB_PREFIX."takepos_floor_tables(entity, label, leftpos, toppos, floor) VALUES (".((int) $conf->entity).", '', '45', '45', ".((int) $floor).")";
136 $asdf = $db->query($sql);
137 $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label = rowid WHERE label = ''"); // No empty table names
138}
139
140
141/*
142 * View
143 */
144
145// Title
146$head = '';
147$title = 'TakePOS - Dolibarr '.DOL_VERSION;
148if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
149 $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
150}
151$arrayofcss = array('/takepos/css/pos.css.php?a=xxx');
152
153top_htmlhead($head, $title, 0, 0, array(), $arrayofcss);
154
155?>
156<body style="overflow: hidden">
157
158<style type="text/css">
159div.tablediv{
160 background-image:url(img/table.gif);
161 -moz-background-size:100% 100%;
162 -webkit-background-size:100% 100%;
163 background-size:100% 100%;
164 height:10%;
165 width:10%;
166 text-align: center;
167 font-size:300%;
168 color:white;
169}
170
171/* Color when a table has a pending order/invoice */
172div.red{
173 color:red;
174}
175</style>
176
177<script>
178var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
179
180function updateplace(idplace, left, top) {
181 console.log("updateplace idplace="+idplace+" left="+left+" top="+top);
182 $.ajax({
183 type: "POST",
184 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
185 data: { action: "update", left: left, top: top, place: idplace, token: '<?php echo currentToken(); ?>' }
186 }).done(function( msg ) {
187 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode((string) ($floor)); ?>';
188 });
189}
190
191function updatename(rowid) {
192 var after=$("#tablename"+rowid).text();
193 console.log("updatename rowid="+rowid+" after="+after);
194 $.ajax({
195 type: "POST",
196 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
197 data: { action: "updatename", place: rowid, newname: after, token: '<?php echo currentToken(); ?>' }
198 }).done(function( msg ) {
199 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode((string) ($floor)); ?>';
200 });
201}
202
203function LoadPlace(place){
204 parent.location.href='index.php?place='+place;
205}
206
207
208$( document ).ready(function() {
209 $.getJSON('./floors.php?action=getTables&token=<?php echo newToken();?>&floor=<?php echo $floor; ?>', function(data) {
210 $.each(data, function(key, val) {
211 <?php if ($mode == "edit") {?>
212 $('body').append('<div class="tablediv" contenteditable onblur="updatename('+val.rowid+');" style="position: absolute; left: '+val.leftpos+'%; top: '+val.toppos+'%;" id="tablename'+val.rowid+'">'+val.label+'</div>');
213 $( "#tablename"+val.rowid ).draggable(
214 {
215 start: function() {
216 $("#add").html("<?php echo $langs->trans("Delete"); ?>");
217 },
218 stop: function() {
219 var left=$(this).offset().left*100/$(window).width();
220 var top=$(this).offset().top*100/$(window).height();
221 updateplace($(this).attr('id').substr(9), left, top);
222 }
223 }
224 );
225 //simultaneous draggable and contenteditable
226 $('#'+val.label).draggable().bind('click', function(){
227 $(this).focus();
228 })
229 <?php } else {?>
230 $('body').append('<div class="tablediv '+val.occupied+'" onclick="LoadPlace('+val.rowid+');" style="position: absolute; left: '+val.leftpos+'%; top: '+val.toppos+'%;" id="tablename'+val.rowid+'">'+val.label+'</div>');
231 <?php } ?>
232 });
233 });
234});
235
236</script>
237
238<?php if ($user->admin) {?>
239<div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
240 <?php if ($mode == "edit") {?>
241<a id="add" onclick="window.location.href='floors.php?mode=edit&action=add&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("AddTable"); ?></a>
242 <?php } else { ?>
243<a onclick="window.location.href='floors.php?mode=edit&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
244 <?php } ?>
245</div>
246<?php }
247?>
248
249<div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
250 <center>
251 <h1>
252 <?php if ($floor > 0) { ?>
253 <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 0) {
254 $floor--;
255 echo $floor;
256 $floor++;
257 } else {
258 echo "0";
259 } ?>';">
260 <?php } ?>
261 <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
262 <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++;
263 echo $floor; ?>';">
264 </h1>
265 </center>
266</div>
267
268</body>
269</html>
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage invoices.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
treeview li table
No Email.