%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/var/www/html/buggydubrovnik.com/bookingv2/
Upload File :
Create Path :
Current File : //proc/self/root/var/www/html/buggydubrovnik.com/bookingv2/functions.php

<?php
const BUGGIES=4;
const PEOPLE_PER_BUGGY=3;

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

function getDB(){
    $servername = "localhost";
    $username="buggydubrovnik_app_production";
    $password="appr-17";
    $db="buggydubrovnik_app_production";
    $conn = mysqli_connect($servername, $username, $password, $db);
    mysqli_query($conn,"set names 'utf8'");
    return $conn;
}
function formatMoney($number, $cents = 1) { // cents: 0=never, 1=if needed, 2=always
if (is_numeric($number)) { // a number
if (!$number) { // zero
$money = ($cents == 2 ? '0.00' : '0'); // output zero
} else { // value
if (floor($number) == $number) { // whole number
$money = number_format($number, ($cents == 2 ? 2 : 0)); // format
} else { // cents
$money = number_format(round($number, 2), ($cents == 0 ? 0 : 2)); // format
} // integer or decimal
} // value
$money = str_replace(",","[]", $money);
$money = str_replace(".",",", $money);
$money = str_replace("[]",".", $money);
return $money;
} // numeric
}

function getTour($id){
    $db=getDB();
    $result=$db->query("SELECT * FROM izlet_tip WHERE aktivan=1 AND id_izlet_tip=$id AND online=1");
    return $result->num_rows?$result->fetch_assoc():false;

}
function addTime($time1, $time2) {
    $times = array($time1, $time2);
    $seconds = 0;

    // loop through each time and convert it to seconds
    foreach ($times as $time) {
        list($hour, $minute) = explode(':', $time);
        $seconds += $hour * 3600;
        $seconds += $minute * 60;
    }

    // convert seconds back into a time format
    $hour = floor($seconds / 3600);
    $minute = floor($seconds % 3600 / 60);

    // add leading zeros if needed
    $hour = str_pad($hour, 2, '0', STR_PAD_LEFT);
    $minute = str_pad($minute, 2, '0', STR_PAD_LEFT);

    return "$hour:$minute";
}
function getCountries(){
    $db=getDB();
    return $db->query("SELECT * FROM drzava WHERE aktivan=1 ORDER BY naziv ASC");
}

function getTimes($id, $date){
    $con=getDB();
    $timestamp = strtotime($date);
    $date = date("Y-m-d", $timestamp);
    $m = date("n", $timestamp);

    $tour=getTour($id);

    $times = [
        //premium
        "1" => [
            "3" => ['10:00', '16:00'],
            "4" => ['10:00', '14:00', '17:00'],
            "5" => ['10:00', '15:00', '18:00'],
            "6" => ['10:00', '15:00', '18:00'],
            "7" => ['10:00', '15:00', '18:00'],
            "8" => ['10:00', '15:00', '18:00'],
            "9" => ['10:00', '14:00', '17:00'],
            "10" => ['10:00', '16:00'],
            "11" => ['10:00', '14:00'],
        ],
        //group
        "2" => [
            "3" => ['10:00'],
            "4" => ['10:00'],
            "5" => ['10:00'],
            "6" => ['10:00'],
            "7" => ['10:00'],
            "8" => ['10:00'],
            "9" => ['10:00'],
            "10" => ['10:00'],
            "11" => ['10:00'],

        ],
        //premium plus
        "3" => [
            "3" => ['10:00', '16:00'],
            "4" => ['10:00', '16:00'],
            "5" => ['10:00', '16:00'],
            "6" => ['10:00', '16:00'],
            "7" => ['10:00', '16:00'],
            "8" => ['10:00', '16:00'],
            "9" => ['10:00', '16:00'],
            "10" => ['10:00', '14:00'],
            "11" => ['10:00', '14:00']
        ],

        //sunset group
        "4" => [
            "3" => ['16:00'],
            "4" => ['17:00'],
            "5" => ['18:00'],
            "6" => ['18:00'],
            "7" => ['18:00'],
            "8" => ['18:00'],
            "9" => ['17:00'],
            "10" => ['16:00'],
            "11" => ['14:00']
        ],
    ];


    $min = 10;
    if ($timestamp == strtotime("today")) {
        $min = intval(date("H", strtotime("now"))) + 6;
        if ($min < 10) $min = 10;

    }



    $termini=$times[$tour["id_izlet_tip"]][$m];


    $result=[];
    foreach ($termini as $startTime) {
        if ($startTime < $min) continue;

        $start = $date . " " . $startTime . ":00";
        $end = $date . " " . (addTime($startTime, $tour["trajanje"])) . ":00";


        //(StartA <= EndB) and (EndA >= StartB)
        $sql = "SELECT COALESCE(SUM(r.resurs),0) FROM rezervacija r 
    JOIN izlet_termin t ON t.id_izlet_termin=r.id_izlet_termin
    JOIN izlet_tip it ON it.id_izlet_tip=t.id_izlet_tip
WHERE r.aktivan=1 AND t.aktivan=1 AND it.privatni=1
  AND t.termin < STR_TO_DATE('$end', '%Y-%m-%d %H:%i:%s')  AND r.datum_kupnja > STR_TO_DATE('$start', '%Y-%m-%d %H:%i:%s')";
//         echo $sql;
        $res = $con->query($sql);
        $row = $res->fetch_row();
        $sql2 = "SELECT COALESCE(SUM(r.odrasli)+SUM(r.djeca), 0) FROM rezervacija r
    JOIN izlet_termin t ON t.id_izlet_termin=r.id_izlet_termin 
 JOIN izlet_tip it ON it.id_izlet_tip=t.id_izlet_tip
WHERE r.aktivan=1 AND t.aktivan=1 AND it.privatni=0 AND t.termin < STR_TO_DATE('$end', '%Y-%m-%d %H:%i:%s')  AND r.datum_kupnja > STR_TO_DATE('$start', '%Y-%m-%d %H:%i:%s')";
//         echo $sql2;
        $res2 = $con->query($sql2);
        $row2 = $res2->fetch_row();
//        echo($row2[0]);

        $privateTourBuggies=$row[0];

        $groupTourPeople=$row2[0];

        $groupTourBuggies=ceil($groupTourPeople/3); //ako je više od cijelog broja, onda je taj gornji.

        if($tour["privatni"]){
            //gledam broj buggya.
            $remaining=BUGGIES-$privateTourBuggies-$groupTourBuggies;
        }
        else {
            //gledam broj ljudi.

            $remaining=((BUGGIES-$privateTourBuggies)*PEOPLE_PER_BUGGY)-$groupTourPeople;
        }
        if($remaining<0) $remaining=0;
        $result[$startTime]=$remaining;
        }
    return $result;
}

function insertRow($conn, $table, $data) {
    // Build the list of column names and values
    $columns = "";
    $values = "";
    foreach ($data as $column => $value) {
        $escapedValue=$conn->real_escape_string($value);
        $columns .= "`$column`, ";
        $values .= "'$escapedValue', ";
    }
    // Trim the trailing comma and space from the column names and values lists
    $columns = rtrim($columns, ", ");
    $values = rtrim($values, ", ");

    // Build and execute the query
    $query = "INSERT INTO `$table` ($columns) VALUES ($values)";
    $result = $conn->query($query);
    if (!$result) {
        // Query failed, return false
        echo $conn->error;
        return false;
    }
    // Query was successful, return the ID of the inserted row
    return $conn->insert_id;
}

Zerion Mini Shell 1.0