floors.php 7.7 KB

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