voucerhistory_assistant.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. $res = 0;
  3. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  4. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  5. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  6. }
  7. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  8. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  9. $tmp2 = realpath(__FILE__);
  10. $i = strlen($tmp) - 1;
  11. $j = strlen($tmp2) - 1;
  12. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  13. $i--;
  14. $j--;
  15. }
  16. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  17. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  18. }
  19. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  20. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  21. }
  22. // Try main.inc.php using relative path
  23. if (!$res && file_exists("../main.inc.php")) {
  24. $res = @include "../main.inc.php";
  25. }
  26. if (!$res && file_exists("../../main.inc.php")) {
  27. $res = @include "../../main.inc.php";
  28. }
  29. if (!$res && file_exists("../../../main.inc.php")) {
  30. $res = @include "../../../main.inc.php";
  31. }
  32. if (!$res) {
  33. die("Include of main fails");
  34. }
  35. $product_id = GETPOST('product_id', 'alpha');
  36. $function = GETPOST('function', 'alpha');
  37. $selectedDate = GETPOST('selectedDate', 'alpha');
  38. function checkEvent($product_id, $db)
  39. {
  40. $sql = "SELECT bbbs.is_event FROM public.llx_product_extrafields as pre
  41. INNER JOIN llx_bbus_basicservices as bbbs ON CAST(bbbs.rowid AS VARCHAR) = pre.basic_service
  42. WHERE pre.fk_object = {$product_id}";
  43. $result = $db->query($sql);
  44. if ($db->num_rows($result) > 0) {
  45. while ($row = $db->fetch_object($result)) {
  46. print $row->is_event == 1 ? 'true' : 'false';
  47. }
  48. }
  49. }
  50. function GetAllEventsOfTheSelectedProduct($product_id, $db)
  51. {
  52. $date_from = date("Y-m-d", dol_now());
  53. $sql = "SELECT
  54. ac.id,
  55. ac.datep,
  56. ace.max_num,
  57. ace.participants,
  58. ace.buffer
  59. FROM llx_actioncomm as ac
  60. LEFT JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
  61. INNER JOIN llx_eventwizard_eventdetails as ed ON ac.fk_element = ed.rowid
  62. INNER JOIN llx_eventwizard_eventproduct as ep ON ep.fk_eventdetails = ac.fk_element
  63. WHERE ac.code = 'AC_EVENT'
  64. AND ep.fk_product = {$product_id}
  65. AND ac.datep > '{$date_from} 00:00:00'
  66. ORDER BY ac.datep ASC";
  67. $result = $db->query($sql);
  68. $datesArray = [];
  69. if ($db->num_rows($result) > 0) {
  70. while ($row = $db->fetch_object($result)) {
  71. $date = [];
  72. $date = explode(' ', $row->datep);
  73. $datesArray[] = $date[0];
  74. //print $row->datep;
  75. }
  76. if(!empty($datesArray)){
  77. print json_encode($datesArray);
  78. }else{
  79. print '';
  80. }
  81. }
  82. }
  83. function GetAllTimesOfTheSelectedEvent($product_id, $selectedDate, $db)
  84. {
  85. $date = new DateTime($selectedDate);
  86. $date->modify('+1 day');
  87. $date_to = $date->format('Y-m-d');
  88. $sql = "SELECT
  89. ac.id,
  90. ac.datep,
  91. ace.max_num,
  92. ace.participants,
  93. ace.buffer
  94. FROM llx_actioncomm as ac
  95. LEFT JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
  96. INNER JOIN llx_eventwizard_eventdetails as ed ON ac.fk_element = ed.rowid
  97. INNER JOIN llx_eventwizard_eventproduct as ep ON ep.fk_eventdetails = ac.fk_element
  98. WHERE ac.code = 'AC_EVENT'
  99. AND ep.fk_product = {$product_id}
  100. AND ac.datep > '{$selectedDate} 00:00:00'
  101. AND ac.datep2 < '{$date_to} 00:00:00'
  102. ORDER BY ac.datep ASC";
  103. $result = $db->query($sql);
  104. if ($db->num_rows($result) > 0) {
  105. $datesArray = [];
  106. while ($row = $db->fetch_object($result)) {
  107. $date = [];
  108. $date = explode(' ', $row->datep);
  109. $time = explode(':', $date[1]);
  110. $datesArray[$row->id] = $time[0] . ':' . $time[1];
  111. }
  112. print json_encode($datesArray);
  113. }
  114. }
  115. if ($function == 'checkEvent') {
  116. checkEvent($product_id, $db);
  117. }
  118. if ($function == 'GetAllEventsOfTheSelectedProduct') {
  119. GetAllEventsOfTheSelectedProduct($product_id, $db);
  120. }
  121. if ($function == 'GetAllTimesOfTheSelectedEvent') {
  122. GetAllTimesOfTheSelectedEvent($product_id, $selectedDate, $db);
  123. }