Bernd Posted February 8, 2021 Share Posted February 8, 2021 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/ Share on other sites More sharing options...
gw1500se Posted February 8, 2021 Share Posted February 8, 2021 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? Quote Link to comment https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/#findComment-1584326 Share on other sites More sharing options...
prontik Posted May 4, 2022 Share Posted May 4, 2022 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/#findComment-1595931 Share on other sites More sharing options...
ginerjm Posted May 4, 2022 Share Posted May 4, 2022 If this is some 3rd party code then why not get them to help you with it? Quote Link to comment https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/#findComment-1595934 Share on other sites More sharing options...
prontik Posted May 4, 2022 Share Posted May 4, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/#findComment-1595936 Share on other sites More sharing options...
ginerjm Posted May 4, 2022 Share Posted May 4, 2022 Since we don't know what it does and there don't seem to be very many comments and the use of meaningless variable names, we would be committing a lot of time to help you out. Quote Link to comment https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/#findComment-1595938 Share on other sites More sharing options...
mac_gyver Posted May 4, 2022 Share Posted May 4, 2022 (edited) 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 May 4, 2022 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/312112-booking-code-fixed-time/#findComment-1595941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.