floors.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. /**
  18. * \file htdocs/takepos/floors.php
  19. * \ingroup takepos
  20. * \brief Page to edit floors and tables.
  21. */
  22. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  24. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  25. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  26. if (!defined('NOREQUIREMENU')) {
  27. define('NOREQUIREMENU', '1');
  28. }
  29. if (!defined('NOREQUIREHTML')) {
  30. define('NOREQUIREHTML', '1');
  31. }
  32. if (!defined('NOREQUIREAJAX')) {
  33. define('NOREQUIREAJAX', '1');
  34. }
  35. // Load Dolibarr environment
  36. require '../main.inc.php'; // Load $user and permissions
  37. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  38. $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk"));
  39. $floor = GETPOST('floor', 'int');
  40. if ($floor == "") {
  41. $floor = 1;
  42. }
  43. $id = GETPOST('id', 'int');
  44. $action = GETPOST('action', 'aZ09');
  45. $left = GETPOST('left', 'alpha');
  46. $top = GETPOST('top', 'alpha');
  47. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
  48. $newname = GETPOST('newname', 'alpha');
  49. $mode = GETPOST('mode', 'alpha');
  50. if (!$user->hasRight('takepos', 'run')) {
  51. accessforbidden();
  52. }
  53. /*
  54. * Actions
  55. */
  56. if ($action == "getTables") {
  57. $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM ".MAIN_DB_PREFIX."takepos_floor_tables WHERE floor = ".((int) $floor)." AND entity IN (".getEntity('takepos').")";
  58. $resql = $db->query($sql);
  59. $rows = array();
  60. while ($row = $db->fetch_array($resql)) {
  61. $invoice = new Facture($db);
  62. $result = $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$row['rowid'].')');
  63. if ($result > 0) {
  64. $row['occupied'] = "red";
  65. }
  66. $rows[] = $row;
  67. }
  68. top_httphead('application/json');
  69. echo json_encode($rows);
  70. exit;
  71. }
  72. if ($action == "update") {
  73. if ($left > 95) {
  74. $left = 95;
  75. }
  76. if ($top > 95) {
  77. $top = 95;
  78. }
  79. if ($left > 3 or $top > 4) {
  80. $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET leftpos = ".((int) $left).", toppos = ".((int) $top)." WHERE rowid = ".((int) $place));
  81. } else {
  82. $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables WHERE rowid = ".((int) $place));
  83. }
  84. }
  85. if ($action == "updatename") {
  86. $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
  87. if (strlen($newname) > 3) {
  88. $newname = substr($newname, 0, 3); // Only 3 chars
  89. }
  90. $resql = $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label='".$db->escape($newname)."' WHERE rowid = ".((int) $place));
  91. }
  92. if ($action == "add") {
  93. $sql = "INSERT INTO ".MAIN_DB_PREFIX."takepos_floor_tables(entity, label, leftpos, toppos, floor) VALUES (".$conf->entity.", '', '45', '45', ".((int) $floor).")";
  94. $asdf = $db->query($sql);
  95. $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label = rowid WHERE label = ''"); // No empty table names
  96. }
  97. /*
  98. * View
  99. */
  100. // Title
  101. $head = '';
  102. $title = 'TakePOS - Dolibarr '.DOL_VERSION;
  103. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  104. $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
  105. }
  106. $arrayofcss = array('/takepos/css/pos.css.php?a=xxx');
  107. top_htmlhead($head, $title, 0, 0, '', $arrayofcss);
  108. ?>
  109. <body style="overflow: hidden">
  110. <style type="text/css">
  111. div.tablediv{
  112. background-image:url(img/table.gif);
  113. -moz-background-size:100% 100%;
  114. -webkit-background-size:100% 100%;
  115. background-size:100% 100%;
  116. height:10%;
  117. width:10%;
  118. text-align: center;
  119. font-size:300%;
  120. color:white;
  121. }
  122. /* Color when a table has a pending order/invoice */
  123. div.red{
  124. color:red;
  125. }
  126. </style>
  127. <script>
  128. var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
  129. function updateplace(idplace, left, top) {
  130. console.log("updateplace idplace="+idplace+" left="+left+" top="+top);
  131. $.ajax({
  132. type: "POST",
  133. url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
  134. data: { action: "update", left: left, top: top, place: idplace, token: '<?php echo currentToken(); ?>' }
  135. }).done(function( msg ) {
  136. window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
  137. });
  138. }
  139. function updatename(rowid) {
  140. var after=$("#tablename"+rowid).text();
  141. console.log("updatename rowid="+rowid+" after="+after);
  142. $.ajax({
  143. type: "POST",
  144. url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
  145. data: { action: "updatename", place: rowid, newname: after, token: '<?php echo currentToken(); ?>' }
  146. }).done(function( msg ) {
  147. window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
  148. });
  149. }
  150. function LoadPlace(place){
  151. parent.location.href='index.php?place='+place;
  152. }
  153. $( document ).ready(function() {
  154. $.getJSON('./floors.php?action=getTables&token=<?php echo newToken();?>&floor=<?php echo $floor; ?>', function(data) {
  155. $.each(data, function(key, val) {
  156. <?php if ($mode == "edit") {?>
  157. $('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>');
  158. $( "#tablename"+val.rowid ).draggable(
  159. {
  160. start: function() {
  161. $("#add").html("<?php echo $langs->trans("Delete"); ?>");
  162. },
  163. stop: function() {
  164. var left=$(this).offset().left*100/$(window).width();
  165. var top=$(this).offset().top*100/$(window).height();
  166. updateplace($(this).attr('id').substr(9), left, top);
  167. }
  168. }
  169. );
  170. //simultaneous draggable and contenteditable
  171. $('#'+val.label).draggable().bind('click', function(){
  172. $(this).focus();
  173. })
  174. <?php } else {?>
  175. $('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>');
  176. <?php } ?>
  177. });
  178. });
  179. });
  180. </script>
  181. <?php if ($user->admin) {?>
  182. <div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
  183. <?php if ($mode == "edit") {?>
  184. <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>
  185. <?php } else { ?>
  186. <a onclick="window.location.href='floors.php?mode=edit&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
  187. <?php } ?>
  188. </div>
  189. <?php }
  190. ?>
  191. <div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
  192. <center>
  193. <h1>
  194. <?php if ($floor > 1) { ?>
  195. <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 1) {
  196. $floor--; echo $floor; $floor++;
  197. } else {
  198. echo "1";
  199. } ?>';">
  200. <?php } ?>
  201. <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
  202. <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++; echo $floor; ?>';">
  203. </h1>
  204. </center>
  205. </div>
  206. </body>
  207. </html>