dolibarr  16.0.5
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');
28 if (!defined('NOCSRFCHECK')) {
29  define('NOCSRFCHECK', '1');
30 }
31 if (!defined('NOTOKENRENEWAL')) {
32  define('NOTOKENRENEWAL', '1');
33 }
34 if (!defined('NOREQUIREMENU')) {
35  define('NOREQUIREMENU', '1');
36 }
37 if (!defined('NOREQUIREHTML')) {
38  define('NOREQUIREHTML', '1');
39 }
40 if (!defined('NOREQUIREAJAX')) {
41  define('NOREQUIREAJAX', '1');
42 }
43 
44 require '../main.inc.php'; // Load $user and permissions
45 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
46 
47 $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk"));
48 
49 $floor = GETPOST('floor', 'int');
50 if ($floor == "") {
51  $floor = 1;
52 }
53 $id = GETPOST('id', 'int');
54 $action = GETPOST('action', 'aZ09');
55 $left = GETPOST('left', 'alpha');
56 $top = GETPOST('top', 'alpha');
57 
58 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
59 
60 $newname = GETPOST('newname', 'alpha');
61 $mode = GETPOST('mode', 'alpha');
62 
63 if (empty($user->rights->takepos->run)) {
65 }
66 
67 
68 /*
69  * Actions
70  */
71 
72 if ($action == "getTables") {
73  $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM ".MAIN_DB_PREFIX."takepos_floor_tables where floor = ".((int) $floor);
74  $resql = $db->query($sql);
75  $rows = array();
76  while ($row = $db->fetch_array($resql)) {
77  $invoice = new Facture($db);
78  $result = $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$row['rowid'].')');
79  if ($result > 0) {
80  $row['occupied'] = "red";
81  }
82  $rows[] = $row;
83  }
84  echo json_encode($rows);
85  exit;
86 }
87 
88 if ($action == "update") {
89  if ($left > 95) {
90  $left = 95;
91  }
92  if ($top > 95) {
93  $top = 95;
94  }
95  if ($left > 3 or $top > 4) {
96  $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables set leftpos = ".((int) $left).", toppos = ".((int) $top)." WHERE rowid = ".((int) $place));
97  } else {
98  $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables where rowid = ".((int) $place));
99  }
100 }
101 
102 if ($action == "updatename") {
103  $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
104  if (strlen($newname) > 3) {
105  $newname = substr($newname, 0, 3); // Only 3 chars
106  }
107  $resql = $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables set label='".$db->escape($newname)."' WHERE rowid = ".((int) $place));
108 }
109 
110 if ($action == "add") {
111  $sql = "INSERT INTO ".MAIN_DB_PREFIX."takepos_floor_tables(entity, label, leftpos, toppos, floor) VALUES (".$conf->entity.", '', '45', '45', ".((int) $floor).")";
112  $asdf = $db->query($sql);
113  $db->query("update ".MAIN_DB_PREFIX."takepos_floor_tables set label=rowid where label=''"); // No empty table names
114 }
115 
116 
117 /*
118  * View
119  */
120 
121 // Title
122 $title = 'TakePOS - Dolibarr '.DOL_VERSION;
123 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
124  $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
125 }
126 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
127 ?>
128 <link rel="stylesheet" href="css/pos.css.php?a=xxx">
129 <style type="text/css">
130 div.tablediv{
131  background-image:url(img/table.gif);
132  -moz-background-size:100% 100%;
133  -webkit-background-size:100% 100%;
134  background-size:100% 100%;
135  height:10%;
136  width:10%;
137  text-align: center;
138  font-size:300%;
139  color:white;
140 }
141 
142 /* Color when a table has a pending order/invoice */
143 div.red{
144  color:red;
145 }
146 </style>
147 
148 <script>
149 var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
150 
151 function updateplace(idplace, left, top) {
152  console.log("updateplace idplace="+idplace+" left="+left+" top="+top);
153  $.ajax({
154  type: "POST",
155  url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
156  data: { action: "update", left: left, top: top, place: idplace, token: '<?php echo currentToken(); ?>' }
157  }).done(function( msg ) {
158  window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
159  });
160 }
161 
162 function updatename(rowid) {
163  var after=$("#tablename"+rowid).text();
164  console.log("updatename rowid="+rowid+" after="+after);
165  $.ajax({
166  type: "POST",
167  url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
168  data: { action: "updatename", place: rowid, newname: after, token: '<?php echo currentToken(); ?>' }
169  }).done(function( msg ) {
170  window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
171  });
172 }
173 
174 function LoadPlace(place){
175  parent.location.href='index.php?place='+place;
176 }
177 
178 
179 $( document ).ready(function() {
180  $.getJSON('./floors.php?action=getTables&floor=<?php echo $floor; ?>', function(data) {
181  $.each(data, function(key, val) {
182  <?php if ($mode == "edit") {?>
183  $('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>');
184  $( "#tablename"+val.rowid ).draggable(
185  {
186  start: function() {
187  $("#add").html("<?php echo $langs->trans("Delete"); ?>");
188  },
189  stop: function() {
190  var left=$(this).offset().left*100/$(window).width();
191  var top=$(this).offset().top*100/$(window).height();
192  updateplace($(this).attr('id').substr(9), left, top);
193  }
194  }
195  );
196  //simultaneous draggable and contenteditable
197  $('#'+val.label).draggable().bind('click', function(){
198  $(this).focus();
199  })
200  <?php } else {?>
201  $('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>');
202  <?php } ?>
203  });
204  });
205 });
206 
207 </script>
208 </head>
209 <body style="overflow: hidden">
210 <?php if ($user->admin) {?>
211 <div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
212  <?php if ($mode == "edit") {?>
213 <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>
214  <?php } else { ?>
215 <a onclick="window.location.href='floors.php?mode=edit&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
216  <?php } ?>
217 </div>
218 <?php }
219 ?>
220 
221 <div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
222  <center>
223  <h1>
224  <?php if ($floor > 1) { ?>
225  <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 1) {
226  $floor--; echo $floor; $floor++;
227  } else {
228  echo "1";
229  } ?>';">
230  <?php } ?>
231  <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
232  <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++; echo $floor; ?>';">
233  </h1>
234  </center>
235 </div>
236 </body>
237 </html>
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_htmlhead
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
Definition: main.inc.php:1482
rowid
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
Definition: email_expire_services_to_representatives.php:79
Facture
Class to manage invoices.
Definition: facture.class.php:60
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119