Jump to content

Recommended Posts

Hi , 

 

I try to change a PHP code for a booking program without succes. Now the time set is from 00.00 - 24.00hours but it must be fixed on 15.00H ( dropoff) and 11.00H (pick-up). Can someone help me please ? 

 

Big thanks in advance !

 

$pickhdeftime = !empty($places[$indvrcplace]['defaulttime']) ? ((int)$places[$indvrcplace]['defaulttime'] / 3600) : '';
    if (!($i < $j)) {
        while (intval($i) != (int)$j) {
            $sayi = $i < 10 ? "0".$i : $i;
            if ($nowtf != 'H:i') {
                $ampm = $i < 12 ? ' am' : ' pm';
                $ampmh = $i > 12 ? ($i - 12) : $i;
                $sayh = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayh = $sayi;
            }
            $hours .= "<option value=\"" . (int)$i . "\"".($pickhdeftime == (int)$i ? ' selected="selected"' : '').">" . $sayh . "</option>\n";
            $i++;
            $i = $i > 23 ? 0 : $i;
        }
        $sayi = $i < 10 ? "0".$i : $i;
        if ($nowtf != 'H:i') {
            $ampm = $i < 12 ? ' am' : ' pm';
            $ampmh = $i > 12 ? ($i - 12) : $i;
            $sayh = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
        } else {
            $sayh = $sayi;
        }
        $hours .= "<option value=\"" . (int)$i . "\">" . $sayh . "</option>\n";
    } else {
        while ($i <= $j) {
            $sayi = $i < 10 ? "0".$i : $i;
            if ($nowtf != 'H:i') {
                $ampm = $i < 12 ? ' am' : ' pm';
                $ampmh = $i > 12 ? ($i - 12) : $i;
                $sayh = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayh = $sayi;
            }
            $hours .= "<option value=\"" . (int)$i . "\"".($pickhdeftime == (int)$i ? ' selected="selected"' : '').">" . $sayh . "</option>\n";
            $i++;
        }
    }
    //
    $hoursret = "";
    //VRC 1.9
    $drophdeftime = !empty($places[$indvrcreturnplace]['defaulttime']) ? ((int)$places[$indvrcreturnplace]['defaulttime'] / 3600) : '';
    if (!($iret < $jret)) {
        while (intval($iret) != (int)$jret) {
            $sayiret = $iret < 10 ? "0".$iret : $iret;
            if ($nowtf != 'H:i') {
                $ampm = $iret < 12 ? ' am' : ' pm';
                $ampmh = $iret > 12 ? ($iret - 12) : $iret;
                $sayhret = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayhret = $sayiret;
            }
            $hoursret .= "<option value=\"" . (int)$iret . "\"".($drophdeftime == (int)$iret ? ' selected="selected"' : '').">" . $sayhret . "</option>\n";
            $iret++;
            $iret = $iret > 23 ? 0 : $iret;
        }
        $sayiret = $iret < 10 ? "0".$iret : $iret;
        if ($nowtf != 'H:i') {
            $ampm = $iret < 12 ? ' am' : ' pm';
            $ampmh = $iret > 12 ? ($iret - 12) : $iret;
            $sayhret = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
        } else {
            $sayhret = $sayiret;
        }
        $hoursret .= "<option value=\"" . (int)$iret . "\">" . $sayhret . "</option>\n";
    } else {
        while ((int)$iret <= $jret) {
            $sayiret = $iret < 10 ? "0".$iret : $iret;
            if ($nowtf != 'H:i') {
                $ampm = $iret < 12 ? ' am' : ' pm';
                $ampmh = $iret > 12 ? ($iret - 12) : $iret;
                $sayhret = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayhret = $sayiret;
            }
            $hoursret .= "<option value=\"" . (int)$iret . "\"".($drophdeftime == (int)$iret ? ' selected="selected"' : '').">" . $sayhret . "</option>\n";
            $iret++;
        }
    }
    //
    $minutes = "";
    for ($i = 0; $i < 60; $i += 15) {
        if ($i < 10) {
            $i = "0" . $i;
        }
        $minutes .= "<option value=\"" . (int)$i . "\"".((int)$i == $imin ? " selected=\"selected\"" : "").">" . $i . "</option>\n";
    }
    $minutesret = "";
    for ($iret = 0; $iret < 60; $iret += 15) {
        if ($iret < 10) {
            $iret = "0" . $iret;
        }
        $minutesret .= "<option value=\"" . (int)$iret . "\"".((int)$iret == $iminret ? " selected=\"selected\"" : "").">" . $iret . "</option>\n";
    }
    
    $sval = $session->get('getDateFormat', '');
    if (!empty($sval)) {
        $dateformat = $sval;
    } else {
        $q = "SELECT `setting` FROM `#__vikrentcar_config` WHERE `param`='dateformat';";
        $dbo->setQuery($q);
        $dbo->execute();
        if ($dbo->getNumRows() == 1) {
            $df = $dbo->loadAssocList();
            $dateformat = $df[0]['setting'];
        } else{
            $dateformat = "%d/%m/%Y";
        }
    }
    
    if (true) {
        if ($dateformat == "%d/%m/%Y") {
            $juidf = 'dd/mm/yy';
        } elseif ($dateformat == "%m/%d/%Y") {
            $juidf = 'mm/dd/yy';
        } else {
            $juidf = 'yy/mm/dd';
        }

Link to comment
https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/
Share on other sites

First please edit your post and use the code icon (<>) on the menu and select PHP. The formatter makes your code much easier to read.

It is not clear what you are trying to do. Which variable(s) are you trying to set and what are you trying to set it(them) to?

  • 1 year later...

Bernd is probably not alone in having problems with this code. This is exactly what I need.

This code is a form from Vik Rent Car component and more specifically this booking form. 

https://extensionsforjoomla.com/livedemo/vikrentcar/index.php/en/vrc-list/ford-focus


It's about selecting a pickup time and dropoff time, where the goal is to set a fixed hour and minute for pickup and a different one for dropoff. And it will not be possible to select a different time (neither hours nor minutes).

For example:
The pickup time will be fixed at 15h and the minutes at 00
The hour of dropoff will be fixed at 11h and 00 minutes

Thank you in advance for your help

$hours = "";
$pickhdeftime = !empty($places[$indvrcplace]['defaulttime']) ? ((int)$places[$indvrcplace]['defaulttime'] / 3600) : '';
    if (!($i < $j)) {
        while (intval($i) != (int)$j) {
            $sayi = $i < 10 ? "0".$i : $i;
            if ($nowtf != 'H:i') {
                $ampm = $i < 12 ? ' am' : ' pm';
                $ampmh = $i > 12 ? ($i - 12) : $i;
                $sayh = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayh = $sayi;
            }
            $hours .= "<option value=\"" . (int)$i . "\"".($pickhdeftime == (int)$i ? ' selected="selected"' : '').">" . $sayh . "</option>\n";
            $i++;
            $i = $i > 23 ? 0 : $i;
        }
        $sayi = $i < 10 ? "0".$i : $i;
        if ($nowtf != 'H:i') {
            $ampm = $i < 12 ? ' am' : ' pm';
            $ampmh = $i > 12 ? ($i - 12) : $i;
            $sayh = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
        } else {
            $sayh = $sayi;
        }
        $hours .= "<option value=\"" . (int)$i . "\">" . $sayh . "</option>\n";
    } else {
        while ($i <= $j) {
            $sayi = $i < 10 ? "0".$i : $i;
            if ($nowtf != 'H:i') {
                $ampm = $i < 12 ? ' am' : ' pm';
                $ampmh = $i > 12 ? ($i - 12) : $i;
                $sayh = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayh = $sayi;
            }
            $hours .= "<option value=\"" . (int)$i . "\"".($pickhdeftime == (int)$i ? ' selected="selected"' : '').">" . $sayh . "</option>\n";
            $i++;
        }
    }
    //
    $hoursret = "";
    //VRC 1.9
    $drophdeftime = !empty($places[$indvrcreturnplace]['defaulttime']) ? ((int)$places[$indvrcreturnplace]['defaulttime'] / 3600) : '';
    if (!($iret < $jret)) {
        while (intval($iret) != (int)$jret) {
            $sayiret = $iret < 10 ? "0".$iret : $iret;
            if ($nowtf != 'H:i') {
                $ampm = $iret < 12 ? ' am' : ' pm';
                $ampmh = $iret > 12 ? ($iret - 12) : $iret;
                $sayhret = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayhret = $sayiret;
            }
            $hoursret .= "<option value=\"" . (int)$iret . "\"".($drophdeftime == (int)$iret ? ' selected="selected"' : '').">" . $sayhret . "</option>\n";
            $iret++;
            $iret = $iret > 23 ? 0 : $iret;
        }
        $sayiret = $iret < 10 ? "0".$iret : $iret;
        if ($nowtf != 'H:i') {
            $ampm = $iret < 12 ? ' am' : ' pm';
            $ampmh = $iret > 12 ? ($iret - 12) : $iret;
            $sayhret = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
        } else {
            $sayhret = $sayiret;
        }
        $hoursret .= "<option value=\"" . (int)$iret . "\">" . $sayhret . "</option>\n";
    } else {
        while ((int)$iret <= $jret) {
            $sayiret = $iret < 10 ? "0".$iret : $iret;
            if ($nowtf != 'H:i') {
                $ampm = $iret < 12 ? ' am' : ' pm';
                $ampmh = $iret > 12 ? ($iret - 12) : $iret;
                $sayhret = $ampmh < 10 ? "0".$ampmh.$ampm : $ampmh.$ampm;
            } else {
                $sayhret = $sayiret;
            }
            $hoursret .= "<option value=\"" . (int)$iret . "\"".($drophdeftime == (int)$iret ? ' selected="selected"' : '').">" . $sayhret . "</option>\n";
            $iret++;
        }
    }
    //
    $minutes = "";
    for ($i = 0; $i < 60; $i += 15) {
        if ($i < 10) {
            $i = "0" . $i;
        }
        $minutes .= "<option value=\"" . (int)$i . "\"".((int)$i == $imin ? " selected=\"selected\"" : "").">" . $i . "</option>\n";
    }
    $minutesret = "";
    for ($iret = 0; $iret < 60; $iret += 15) {
        if ($iret < 10) {
            $iret = "0" . $iret;
        }
        $minutesret .= "<option value=\"" . (int)$iret . "\"".((int)$iret == $iminret ? " selected=\"selected\"" : "").">" . $iret . "</option>\n";
    }
    
    $sval = $session->get('getDateFormat', '');
    if (!empty($sval)) {
        $dateformat = $sval;
    } else {
        $q = "SELECT `setting` FROM `#__vikrentcar_config` WHERE `param`='dateformat';";
        $dbo->setQuery($q);
        $dbo->execute();
        if ($dbo->getNumRows() == 1) {
            $df = $dbo->loadAssocList();
            $dateformat = $df[0]['setting'];
        } else{
            $dateformat = "%d/%m/%Y";
        }
    }
    
    if (true) {
        if ($dateformat == "%d/%m/%Y") {
            $juidf = 'dd/mm/yy';
        } elseif ($dateformat == "%m/%d/%Y") {
            $juidf = 'mm/dd/yy';
        } else {
            $juidf = 'yy/mm/dd';
        }

 

30 minutes ago, ginerjm said:

Pokud je to nějaký kód třetí strany, proč je nepožádejte, aby vám s tím pomohli?

Because they always respond negatively to requests for code editing or advice. They will advise you how it works, but they won't advise you to edit it. It's also written in the support policy. 😪

I don't think what I would need would be too hard for someone who understands it. 

seems like a (trick) question on a quiz?

if you can only modify the posted code, the simple answer would be to build each <option></option> list (4 places) with only a single choice, with fixed value (hour/minute) you want, that's pre-selected.

 

 

Edited by mac_gyver
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.