floors.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 <http://www.gnu.org/licenses/>.
  16. */
  17. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  18. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  19. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  20. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  21. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  22. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  23. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  24. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  25. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  26. $_GET['theme']="md"; // Force theme. MD theme provides better look and feel to TakePOS
  27. require '../main.inc.php'; // Load $user and permissions
  28. $langs->loadLangs(array("bills","orders","commercial","cashdesk"));
  29. $floor=GETPOST('floor','alpha');
  30. if ($floor=="") $floor=1;
  31. $id = GETPOST('id','int');
  32. $action = GETPOST('action','alpha');
  33. $left = GETPOST('left','alpha');
  34. $top = GETPOST('top','alpha');
  35. $place = GETPOST('place','int');
  36. $newname = GETPOST('newname');
  37. $mode = GETPOST('mode','alpha');
  38. if ($action=="getTables"){
  39. $sql="SELECT * from ".MAIN_DB_PREFIX."takepos_floor_tables where floor=".$floor;
  40. $resql = $db->query($sql);
  41. $rows = array();
  42. while($row = $db->fetch_array ($resql)){
  43. $rows[] = $row;
  44. }
  45. echo json_encode($rows);
  46. exit;
  47. }
  48. if ($action=="update")
  49. {
  50. if ($left>95) $left=95;
  51. if ($top>95) $top=95;
  52. if ($left>3 or $top>4) $db->query("update ".MAIN_DB_PREFIX."takepos_floor_tables set leftpos=$left, toppos=$top where label='$place'");
  53. else $db->query("delete from ".MAIN_DB_PREFIX."takepos_floor_tables where label='$place'");
  54. }
  55. if ($action=="updatename")
  56. {
  57. $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
  58. if (strlen($newname) > 3) $newname = substr($newname, 0, 3); // Only 3 chars
  59. $db->query("update ".MAIN_DB_PREFIX."takepos_floor_tables set label='$newname' where label='$place'");
  60. }
  61. if ($action=="add")
  62. {
  63. $asdf=$db->query("insert into ".MAIN_DB_PREFIX."takepos_floor_tables values ('', '', '', '45', '45', $floor)");
  64. $db->query("update ".MAIN_DB_PREFIX."takepos_floor_tables set label=rowid where label=''"); // No empty table names
  65. }
  66. // Title
  67. $title='TakePOS - Dolibarr '.DOL_VERSION;
  68. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title='TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
  69. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  70. ?>
  71. <link rel="stylesheet" href="css/pos.css?a=xxx">
  72. <style type="text/css">
  73. div.tablediv{
  74. background-image:url(img/table.gif);
  75. -moz-background-size:100% 100%;
  76. -webkit-background-size:100% 100%;
  77. background-size:100% 100%;
  78. height:10%;
  79. width:10%;
  80. text-align: center;
  81. font-size:300%;
  82. color:white;
  83. }
  84. html, body
  85. {
  86. height: 100%;
  87. }
  88. </style>
  89. <script>
  90. var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
  91. function updateplace(idplace, left, top) {
  92. $.ajax({
  93. type: "POST",
  94. url: "floors.php",
  95. data: { action: "update", left: left, top: top, place: idplace }
  96. }).done(function( msg ) {
  97. window.location.href='floors.php?mode=edit&floor=<?php echo $floor;?>';
  98. });
  99. }
  100. function updatename(before) {
  101. var after=$("#"+before).text();
  102. $.ajax({
  103. type: "POST",
  104. url: "floors.php",
  105. data: { action: "updatename", place: before, newname: after }
  106. }).done(function( msg ) {
  107. window.location.href='floors.php?mode=edit&floor=<?php echo $floor;?>';
  108. });
  109. }
  110. function LoadPlace(place){
  111. parent.location.href='takepos.php?place='+place;
  112. }
  113. $( document ).ready(function() {
  114. $.getJSON('./floors.php?action=getTables&floor=<?php echo $floor; ?>', function(data) {
  115. $.each(data, function(key, val) {
  116. <?php if ($mode=="edit"){?>
  117. $('body').append('<div class="tablediv" contenteditable onblur="updatename('+val.label+');" style="position: absolute; left: '+val.leftpos+'%; top: '+val.toppos+'%;" id="'+val.label+'">'+val.label+'</div>');
  118. $( "#"+val.label ).draggable(
  119. {
  120. start: function() {
  121. $("#add").html("<?php echo $langs->trans("Delete"); ?>");
  122. },
  123. stop: function() {
  124. var left=$(this).offset().left*100/$(window).width();
  125. var top=$(this).offset().top*100/$(window).height();
  126. updateplace($(this).attr('id'), left, top);
  127. }
  128. }
  129. );
  130. //simultaneous draggable and contenteditable
  131. $('#'+val.label).draggable().bind('click', function(){
  132. $(this).focus();
  133. })
  134. <?php }
  135. else {?>
  136. $('body').append('<div class="tablediv" onclick="LoadPlace('+val.label+');" style="position: absolute; left: '+val.leftpos+'%; top: '+val.toppos+'%;" id="'+val.label+'">'+val.label+'</div>');
  137. <?php } ?>
  138. });
  139. });
  140. });
  141. </script>
  142. </head>
  143. <body style="overflow: hidden">
  144. <?php if ($user->admin){?>
  145. <div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
  146. <?php if ($mode=="edit"){?>
  147. <a id="add" onclick="window.location.href='floors.php?mode=edit&action=add&floor=<?php echo $floor;?>';"><?php echo $langs->trans("AddTable"); ?></a>
  148. <?php } else { ?>
  149. <a onclick="window.location.href='floors.php?mode=edit&floor=<?php echo $floor;?>';"><?php echo $langs->trans("Edit"); ?></a>
  150. <?php } ?>
  151. </div>
  152. <?php }
  153. ?>
  154. <div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
  155. <center>
  156. <h1><img src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor>1) { $floor--; echo $floor; $floor++;} else echo "1"; ?>';"><?php echo $langs->trans("Floor")." ".$floor; ?><img src="./img/arrow-next.png" width="5%" onclick="location.href='floors.php?floor=<?php $floor++; echo $floor; ?>';"></h1>
  157. </center>
  158. </div>
  159. </body>
  160. </html>