dolibarr 21.0.0-beta
floors.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 * Copyright (C) 2024 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
53$floor = GETPOSTINT('floor');
54if ($floor == "") {
55 $floor = 1;
56}
57$id = GETPOSTINT('id');
58$action = GETPOST('action', 'aZ09');
59$left = GETPOST('left', 'alpha');
60$top = GETPOST('top', 'alpha');
61
62$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
63
64$newname = GETPOST('newname', 'alpha');
65$mode = GETPOST('mode', 'alpha');
66
67if (!$user->hasRight('takepos', 'run')) {
69}
70
71
72/*
73 * Actions
74 */
75
76if ($action == "getTables" && $user->hasRight('takepos', 'run')) {
77 $rows = array();
78
79 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor";
80 $sql .= " FROM ".MAIN_DB_PREFIX."takepos_floor_tables";
81 $sql .= " WHERE floor = ".((int) $floor)." AND entity IN (".getEntity('takepos').")";
82
83 $resql = $db->query($sql);
84 while ($row = $db->fetch_array($resql)) {
85 $tmpplace = (int) $row['rowid'];
86
87 $invoice = new Facture($db);
88 $result = $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$tmpplace.')');
89 if ($result > 0) {
90 $row['occupied'] = "red";
91 }
92
93 $rows[] = $row;
94 }
95
96 top_httphead('application/json');
97 echo json_encode($rows);
98 exit;
99}
100
101if ($action == "update" && $user->hasRight('takepos', 'run')) {
102 if ($left > 95) {
103 $left = 95;
104 }
105 if ($top > 95) {
106 $top = 95;
107 }
108 if ($left > 3 or $top > 4) {
109 $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET leftpos = ".((int) $left).", toppos = ".((int) $top)." WHERE rowid = ".((int) $place));
110 } else {
111 $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables WHERE rowid = ".((int) $place));
112 }
113}
114
115if ($action == "updatename" && $user->hasRight('takepos', 'run')) {
116 $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
117 if (strlen($newname) > 3) {
118 $newname = substr($newname, 0, 3); // Only 3 chars
119 }
120 $resql = $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label='".$db->escape($newname)."' WHERE rowid = ".((int) $place));
121}
122
123if ($action == "add" && $user->hasRight('takepos', 'run')) {
124 $sql = "INSERT INTO ".MAIN_DB_PREFIX."takepos_floor_tables(entity, label, leftpos, toppos, floor) VALUES (".$conf->entity.", '', '45', '45', ".((int) $floor).")";
125 $asdf = $db->query($sql);
126 $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label = rowid WHERE label = ''"); // No empty table names
127}
128
129
130/*
131 * View
132 */
133
134// Title
135$head = '';
136$title = 'TakePOS - Dolibarr '.DOL_VERSION;
137if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
138 $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
139}
140$arrayofcss = array('/takepos/css/pos.css.php?a=xxx');
141
142top_htmlhead($head, $title, 0, 0, array(), $arrayofcss);
143
144?>
145<body style="overflow: hidden">
146
147<style type="text/css">
148div.tablediv{
149 background-image:url(img/table.gif);
150 -moz-background-size:100% 100%;
151 -webkit-background-size:100% 100%;
152 background-size:100% 100%;
153 height:10%;
154 width:10%;
155 text-align: center;
156 font-size:300%;
157 color:white;
158}
159
160/* Color when a table has a pending order/invoice */
161div.red{
162 color:red;
163}
164</style>
165
166<script>
167var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
168
169function updateplace(idplace, left, top) {
170 console.log("updateplace idplace="+idplace+" left="+left+" top="+top);
171 $.ajax({
172 type: "POST",
173 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
174 data: { action: "update", left: left, top: top, place: idplace, token: '<?php echo currentToken(); ?>' }
175 }).done(function( msg ) {
176 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode((string) ($floor)); ?>';
177 });
178}
179
180function updatename(rowid) {
181 var after=$("#tablename"+rowid).text();
182 console.log("updatename rowid="+rowid+" after="+after);
183 $.ajax({
184 type: "POST",
185 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
186 data: { action: "updatename", place: rowid, newname: after, token: '<?php echo currentToken(); ?>' }
187 }).done(function( msg ) {
188 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode((string) ($floor)); ?>';
189 });
190}
191
192function LoadPlace(place){
193 parent.location.href='index.php?place='+place;
194}
195
196
197$( document ).ready(function() {
198 $.getJSON('./floors.php?action=getTables&token=<?php echo newToken();?>&floor=<?php echo $floor; ?>', function(data) {
199 $.each(data, function(key, val) {
200 <?php if ($mode == "edit") {?>
201 $('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>');
202 $( "#tablename"+val.rowid ).draggable(
203 {
204 start: function() {
205 $("#add").html("<?php echo $langs->trans("Delete"); ?>");
206 },
207 stop: function() {
208 var left=$(this).offset().left*100/$(window).width();
209 var top=$(this).offset().top*100/$(window).height();
210 updateplace($(this).attr('id').substr(9), left, top);
211 }
212 }
213 );
214 //simultaneous draggable and contenteditable
215 $('#'+val.label).draggable().bind('click', function(){
216 $(this).focus();
217 })
218 <?php } else {?>
219 $('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>');
220 <?php } ?>
221 });
222 });
223});
224
225</script>
226
227<?php if ($user->admin) {?>
228<div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
229 <?php if ($mode == "edit") {?>
230<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>
231 <?php } else { ?>
232<a onclick="window.location.href='floors.php?mode=edit&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
233 <?php } ?>
234</div>
235<?php }
236?>
237
238<div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
239 <center>
240 <h1>
241 <?php if ($floor > 1) { ?>
242 <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 1) {
243 $floor--;
244 echo $floor;
245 $floor++;
246 } else {
247 echo "1";
248 } ?>';">
249 <?php } ?>
250 <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
251 <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++;
252 echo $floor; ?>';">
253 </h1>
254 </center>
255</div>
256
257</body>
258</html>
$id
Definition account.php:48
Class to manage invoices.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
treeview li table
No Email.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.