dolibarr 18.0.6
floors.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
25//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
26//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
27//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
28if (!defined('NOREQUIREMENU')) {
29 define('NOREQUIREMENU', '1');
30}
31if (!defined('NOREQUIREHTML')) {
32 define('NOREQUIREHTML', '1');
33}
34if (!defined('NOREQUIREAJAX')) {
35 define('NOREQUIREAJAX', '1');
36}
37
38// Load Dolibarr environment
39require '../main.inc.php'; // Load $user and permissions
40require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
41
42$langs->loadLangs(array("bills", "orders", "commercial", "cashdesk"));
43
44$floor = GETPOST('floor', 'int');
45if ($floor == "") {
46 $floor = 1;
47}
48$id = GETPOST('id', 'int');
49$action = GETPOST('action', 'aZ09');
50$left = GETPOST('left', 'alpha');
51$top = GETPOST('top', 'alpha');
52
53$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
54
55$newname = GETPOST('newname', 'alpha');
56$mode = GETPOST('mode', 'alpha');
57
58if (empty($user->rights->takepos->run)) {
60}
61
62
63/*
64 * Actions
65 */
66
67if ($action == "getTables") {
68 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM ".MAIN_DB_PREFIX."takepos_floor_tables where floor = ".((int) $floor);
69 $resql = $db->query($sql);
70 $rows = array();
71 while ($row = $db->fetch_array($resql)) {
72 $invoice = new Facture($db);
73 $result = $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$row['rowid'].')');
74 if ($result > 0) {
75 $row['occupied'] = "red";
76 }
77 $rows[] = $row;
78 }
79
80 top_httphead('application/json');
81 echo json_encode($rows);
82 exit;
83}
84
85if ($action == "update") {
86 if ($left > 95) {
87 $left = 95;
88 }
89 if ($top > 95) {
90 $top = 95;
91 }
92 if ($left > 3 or $top > 4) {
93 $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables set leftpos = ".((int) $left).", toppos = ".((int) $top)." WHERE rowid = ".((int) $place));
94 } else {
95 $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables where rowid = ".((int) $place));
96 }
97}
98
99if ($action == "updatename") {
100 $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
101 if (strlen($newname) > 3) {
102 $newname = substr($newname, 0, 3); // Only 3 chars
103 }
104 $resql = $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables set label='".$db->escape($newname)."' WHERE rowid = ".((int) $place));
105}
106
107if ($action == "add") {
108 $sql = "INSERT INTO ".MAIN_DB_PREFIX."takepos_floor_tables(entity, label, leftpos, toppos, floor) VALUES (".$conf->entity.", '', '45', '45', ".((int) $floor).")";
109 $asdf = $db->query($sql);
110 $db->query("update ".MAIN_DB_PREFIX."takepos_floor_tables set label=rowid where label=''"); // No empty table names
111}
112
113
114/*
115 * View
116 */
117
118// Title
119$head = '';
120$title = 'TakePOS - Dolibarr '.DOL_VERSION;
121if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
122 $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
123}
124$arrayofcss = array('/takepos/css/pos.css.php?a=xxx');
125
126top_htmlhead($head, $title, 0, 0, '', $arrayofcss);
127
128?>
129<body style="overflow: hidden">
130
131<style type="text/css">
132div.tablediv{
133 background-image:url(img/table.gif);
134 -moz-background-size:100% 100%;
135 -webkit-background-size:100% 100%;
136 background-size:100% 100%;
137 height:10%;
138 width:10%;
139 text-align: center;
140 font-size:300%;
141 color:white;
142}
143
144/* Color when a table has a pending order/invoice */
145div.red{
146 color:red;
147}
148</style>
149
150<script>
151var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
152
153function updateplace(idplace, left, top) {
154 console.log("updateplace idplace="+idplace+" left="+left+" top="+top);
155 $.ajax({
156 type: "POST",
157 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
158 data: { action: "update", left: left, top: top, place: idplace, token: '<?php echo currentToken(); ?>' }
159 }).done(function( msg ) {
160 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
161 });
162}
163
164function updatename(rowid) {
165 var after=$("#tablename"+rowid).text();
166 console.log("updatename rowid="+rowid+" after="+after);
167 $.ajax({
168 type: "POST",
169 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
170 data: { action: "updatename", place: rowid, newname: after, token: '<?php echo currentToken(); ?>' }
171 }).done(function( msg ) {
172 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
173 });
174}
175
176function LoadPlace(place){
177 parent.location.href='index.php?place='+place;
178}
179
180
181$( document ).ready(function() {
182 $.getJSON('./floors.php?action=getTables&token=<?php echo newToken();?>&floor=<?php echo $floor; ?>', function(data) {
183 $.each(data, function(key, val) {
184 <?php if ($mode == "edit") {?>
185 $('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>');
186 $( "#tablename"+val.rowid ).draggable(
187 {
188 start: function() {
189 $("#add").html("<?php echo $langs->trans("Delete"); ?>");
190 },
191 stop: function() {
192 var left=$(this).offset().left*100/$(window).width();
193 var top=$(this).offset().top*100/$(window).height();
194 updateplace($(this).attr('id').substr(9), left, top);
195 }
196 }
197 );
198 //simultaneous draggable and contenteditable
199 $('#'+val.label).draggable().bind('click', function(){
200 $(this).focus();
201 })
202 <?php } else {?>
203 $('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>');
204 <?php } ?>
205 });
206 });
207});
208
209</script>
210
211<?php if ($user->admin) {?>
212<div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
213 <?php if ($mode == "edit") {?>
214<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>
215 <?php } else { ?>
216<a onclick="window.location.href='floors.php?mode=edit&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
217 <?php } ?>
218</div>
219<?php }
220?>
221
222<div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
223 <center>
224 <h1>
225 <?php if ($floor > 1) { ?>
226 <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 1) {
227 $floor--; echo $floor; $floor++;
228 } else {
229 echo "1";
230 } ?>';">
231 <?php } ?>
232 <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
233 <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++; echo $floor; ?>';">
234 </h1>
235 </center>
236</div>
237
238</body>
239</html>
Class to manage invoices.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
Definition invoice.php:1632
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.