floors.php 7.6 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('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=".$left.", toppos=".$top." WHERE rowid='".$place."'");
  85. } else {
  86. $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables where rowid='".$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. $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables set label='".$db->escape($newname)."' WHERE rowid='".$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', ".$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. div.red{
  125. color:red;
  126. }
  127. html, body
  128. {
  129. height: 100%;
  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. </head>
  187. <body style="overflow: hidden">
  188. <?php if ($user->admin) {?>
  189. <div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
  190. <?php if ($mode == "edit") {?>
  191. <a id="add" onclick="window.location.href='floors.php?mode=edit&action=add&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("AddTable"); ?></a>
  192. <?php } else { ?>
  193. <a onclick="window.location.href='floors.php?mode=edit&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
  194. <?php } ?>
  195. </div>
  196. <?php }
  197. ?>
  198. <div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
  199. <center>
  200. <h1>
  201. <?php if ($floor > 1) { ?>
  202. <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 1) {
  203. $floor--; echo $floor; $floor++;
  204. } else {
  205. echo "1";
  206. } ?>';">
  207. <?php } ?>
  208. <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
  209. <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++; echo $floor; ?>';">
  210. </h1>
  211. </center>
  212. </div>
  213. </body>
  214. </html>