| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- $res = 0;
- // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
- if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
- $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
- }
- // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
- $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
- $tmp2 = realpath(__FILE__);
- $i = strlen($tmp) - 1;
- $j = strlen($tmp2) - 1;
- while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
- $i--;
- $j--;
- }
- if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
- $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
- }
- if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
- $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
- }
- // Try main.inc.php using relative path
- if (!$res && file_exists("../main.inc.php")) {
- $res = @include "../main.inc.php";
- }
- if (!$res && file_exists("../../main.inc.php")) {
- $res = @include "../../main.inc.php";
- }
- if (!$res && file_exists("../../../main.inc.php")) {
- $res = @include "../../../main.inc.php";
- }
- if (!$res) {
- die("Include of main fails");
- }
- $product_id = GETPOST('product_id', 'alpha');
- $function = GETPOST('function', 'alpha');
- $selectedDate = GETPOST('selectedDate', 'alpha');
- function checkEvent($product_id, $db)
- {
- $sql = "SELECT bbbs.is_event FROM public.llx_product_extrafields as pre
- INNER JOIN llx_bbus_basicservices as bbbs ON CAST(bbbs.rowid AS VARCHAR) = pre.basic_service
- WHERE pre.fk_object = {$product_id}";
- $result = $db->query($sql);
- if ($db->num_rows($result) > 0) {
- while ($row = $db->fetch_object($result)) {
- print $row->is_event == 1 ? 'true' : 'false';
- }
- }
- }
- function GetAllEventsOfTheSelectedProduct($product_id, $db)
- {
- $date_from = date("Y-m-d", dol_now());
- $sql = "SELECT
- ac.id,
- ac.datep,
- ace.max_num,
- ace.participants,
- ace.buffer
- FROM llx_actioncomm as ac
- LEFT JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
- INNER JOIN llx_eventwizard_eventdetails as ed ON ac.fk_element = ed.rowid
- INNER JOIN llx_eventwizard_eventproduct as ep ON ep.fk_eventdetails = ac.fk_element
- WHERE ac.code = 'AC_EVENT'
- AND ep.fk_product = {$product_id}
- AND ac.datep > '{$date_from} 00:00:00'
- ORDER BY ac.datep ASC";
- $result = $db->query($sql);
- $datesArray = [];
- if ($db->num_rows($result) > 0) {
- while ($row = $db->fetch_object($result)) {
- $date = [];
- $date = explode(' ', $row->datep);
- $datesArray[] = $date[0];
- //print $row->datep;
- }
- if(!empty($datesArray)){
- print json_encode($datesArray);
- }else{
- print '';
- }
- }
- }
- function GetAllTimesOfTheSelectedEvent($product_id, $selectedDate, $db)
- {
- $date = new DateTime($selectedDate);
- $date->modify('+1 day');
- $date_to = $date->format('Y-m-d');
- $sql = "SELECT
- ac.id,
- ac.datep,
- ace.max_num,
- ace.participants,
- ace.buffer
- FROM llx_actioncomm as ac
- LEFT JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
- INNER JOIN llx_eventwizard_eventdetails as ed ON ac.fk_element = ed.rowid
- INNER JOIN llx_eventwizard_eventproduct as ep ON ep.fk_eventdetails = ac.fk_element
- WHERE ac.code = 'AC_EVENT'
- AND ep.fk_product = {$product_id}
- AND ac.datep > '{$selectedDate} 00:00:00'
- AND ac.datep2 < '{$date_to} 00:00:00'
- ORDER BY ac.datep ASC";
- $result = $db->query($sql);
- if ($db->num_rows($result) > 0) {
- $datesArray = [];
- while ($row = $db->fetch_object($result)) {
- $date = [];
- $date = explode(' ', $row->datep);
- $time = explode(':', $date[1]);
- $datesArray[$row->id] = $time[0] . ':' . $time[1];
- }
- print json_encode($datesArray);
- }
- }
- if ($function == 'checkEvent') {
- checkEvent($product_id, $db);
- }
- if ($function == 'GetAllEventsOfTheSelectedProduct') {
- GetAllEventsOfTheSelectedProduct($product_id, $db);
- }
- if ($function == 'GetAllTimesOfTheSelectedEvent') {
- GetAllTimesOfTheSelectedEvent($product_id, $selectedDate, $db);
- }
|