floors.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. top_httphead('application/json');
  74. echo json_encode($rows);
  75. exit;
  76. }
  77. if ($action == "update") {
  78. if ($left > 95) {
  79. $left = 95;
  80. }
  81. if ($top > 95) {
  82. $top = 95;
  83. }
  84. if ($left > 3 or $top > 4) {
  85. $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables set leftpos = ".((int) $left).", toppos = ".((int) $top)." WHERE rowid = ".((int) $place));
  86. } else {
  87. $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables where rowid = ".((int) $place));
  88. }
  89. }
  90. if ($action == "updatename") {
  91. $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
  92. if (strlen($newname) > 3) {
  93. $newname = substr($newname, 0, 3); // Only 3 chars
  94. }
  95. $resql = $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables set label='".$db->escape($newname)."' WHERE rowid = ".((int) $place));
  96. }
  97. if ($action == "add") {
  98. $sql = "INSERT INTO ".MAIN_DB_PREFIX."takepos_floor_tables(entity, label, leftpos, toppos, floor) VALUES (".$conf->entity.", '', '45', '45', ".((int) $floor).")";
  99. $asdf = $db->query($sql);
  100. $db->query("update ".MAIN_DB_PREFIX."takepos_floor_tables set label=rowid where label=''"); // No empty table names
  101. }
  102. /*
  103. * View
  104. */
  105. // Title
  106. $head = '';
  107. $title = 'TakePOS - Dolibarr '.DOL_VERSION;
  108. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  109. $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
  110. }
  111. $arrayofcss = array('/takepos/css/pos.css.php?a=xxx');
  112. top_htmlhead($head, $title, 0, 0, '', $arrayofcss);
  113. ?>
  114. <body style="overflow: hidden">
  115. <style type="text/css">
  116. div.tablediv{
  117. background-image:url(img/table.gif);
  118. -moz-background-size:100% 100%;
  119. -webkit-background-size:100% 100%;
  120. background-size:100% 100%;
  121. height:10%;
  122. width:10%;
  123. text-align: center;
  124. font-size:300%;
  125. color:white;
  126. }
  127. /* Color when a table has a pending order/invoice */
  128. div.red{
  129. color:red;
  130. }
  131. </style>
  132. <script>
  133. var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
  134. function updateplace(idplace, left, top) {
  135. console.log("updateplace idplace="+idplace+" left="+left+" top="+top);
  136. $.ajax({
  137. type: "POST",
  138. url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
  139. data: { action: "update", left: left, top: top, place: idplace, token: '<?php echo currentToken(); ?>' }
  140. }).done(function( msg ) {
  141. window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
  142. });
  143. }
  144. function updatename(rowid) {
  145. var after=$("#tablename"+rowid).text();
  146. console.log("updatename rowid="+rowid+" after="+after);
  147. $.ajax({
  148. type: "POST",
  149. url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
  150. data: { action: "updatename", place: rowid, newname: after, token: '<?php echo currentToken(); ?>' }
  151. }).done(function( msg ) {
  152. window.location.href='floors.php?mode=edit&floor=<?php echo urlencode($floor); ?>';
  153. });
  154. }
  155. function LoadPlace(place){
  156. parent.location.href='index.php?place='+place;
  157. }
  158. $( document ).ready(function() {
  159. $.getJSON('./floors.php?action=getTables&floor=<?php echo $floor; ?>', function(data) {
  160. $.each(data, function(key, val) {
  161. <?php if ($mode == "edit") {?>
  162. $('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>');
  163. $( "#tablename"+val.rowid ).draggable(
  164. {
  165. start: function() {
  166. $("#add").html("<?php echo $langs->trans("Delete"); ?>");
  167. },
  168. stop: function() {
  169. var left=$(this).offset().left*100/$(window).width();
  170. var top=$(this).offset().top*100/$(window).height();
  171. updateplace($(this).attr('id').substr(9), left, top);
  172. }
  173. }
  174. );
  175. //simultaneous draggable and contenteditable
  176. $('#'+val.label).draggable().bind('click', function(){
  177. $(this).focus();
  178. })
  179. <?php } else {?>
  180. $('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>');
  181. <?php } ?>
  182. });
  183. });
  184. });
  185. </script>
  186. <?php if ($user->admin) {?>
  187. <div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
  188. <?php if ($mode == "edit") {?>
  189. <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>
  190. <?php } else { ?>
  191. <a onclick="window.location.href='floors.php?mode=edit&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
  192. <?php } ?>
  193. </div>
  194. <?php }
  195. ?>
  196. <div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
  197. <center>
  198. <h1>
  199. <?php if ($floor > 1) { ?>
  200. <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 1) {
  201. $floor--; echo $floor; $floor++;
  202. } else {
  203. echo "1";
  204. } ?>';">
  205. <?php } ?>
  206. <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
  207. <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++; echo $floor; ?>';">
  208. </h1>
  209. </center>
  210. </div>
  211. </body>
  212. </html>