/    Sign up×
Community /Pin to ProfileBookmark

Advanced PHP question

Could you please edit the below code so that the user can change the dates themselves? At present they can change the pricing and availabilty but I need the dates to be editable as well. Its pretty advanced….. Any help is fantastic. Thank you

[code=php]<?php
//————- CONFIG —————————–
$DATEstart = gmmktime(0, 0, 0, 3, 15, 2008);
$DATEend = gmmktime(0, 0, 0, 10, 30, 2008);

// Define rental week start
$WEEKstart = 6;

$REALstart = $DATEstart;
//Find the first DOW to match rental week start
WHILE (date(“w”, $REALstart) <> $WEEKstart) :
$REALstart += 24*60*60;
ENDWHILE;

$RENTWKstart = $REALstart;
$arrWEEKS = array();
WHILE ($RENTWKstart < $DATEend) :
$arrWEEKS[$RENTWKstart][‘status’] = 0;
$arrWEEKS[$RENTWKstart][‘rate’] = 500;
$RENTWKstart += (7*24*60*60);
ENDWHILE;

IF (!file_exists(“rental_data.php”)) :
$incCONT = ‘<‘ . ‘?php’ . “n”;
$incCONT .= ‘if (!isset($arrWEEKS)) {‘ . “n”;
$incCONT .= ‘ $arrWEEKS = array();’ . “n”;
$incCONT .= ‘}’ . “n”;
FOREACH ($arrWEEKS as $key => $status):
$incCONT .= ‘$arrWEEKS[‘ . $key . ‘][‘status’] = ‘ .
$arrWEEKS[$key][‘status’] . “;n”;
$incCONT .= ‘$arrWEEKS[‘ . $key . ‘][‘rate’] = ‘ .
$arrWEEKS[$key][‘rate’] . “;n”;
ENDFOREACH;
$incCONT .= ‘?’ . ‘>’ . “n”;
IF ($fh = fopen(“rental_data.php”, “w”)) :
fwrite($fh, $incCONT) or die(“Error writing file!”);
fclose($fh);
ENDIF;
ENDIF;

$arrSTATUS = array(“Available”, “Reserved”, “Booked”);
$arrCOLORS = array(“Green”, “Orange”, “Red”);

IF (isset($_GET[‘mode’]) AND $_GET[‘mode’] == “admin”) :
//————– ADMIN ————————
IF (isset($_POST[‘submit’])) :
$incCONT = ‘<‘ . ‘?php’ . “n”;
$incCONT .= ‘if (!isset($arrWEEKS)) {‘ . “n”;
$incCONT .= ‘ $arrWEEKS = array();’ . “n”;
$incCONT .= ‘}’ . “n”;
FOREACH ($_POST[‘week’] as $key => $item):
$incCONT .= ‘$arrWEEKS[‘ . $key . ‘][‘status’] = ‘ .
$_POST[‘status’][$key] . “;n”;
$incCONT .= ‘$arrWEEKS[‘ . $key . ‘][‘rate’] = ‘ .
$_POST[‘rate’][$key] . “;n”;
ENDFOREACH;
$incCONT .= ‘?’ . ‘>’ . “n”;
IF ($fh = fopen(“rental_data.php”, “w”)) :
fwrite($fh, $incCONT) or die(“Error writing file!”);
fclose($fh);
ENDIF;
ENDIF;
print “<form method=’post’ action='” . $_SERVER[‘PHP_SELF’] .
“?mode=admin’>”;
print “<table border=’1′>”;
print “<tr><td colspan=’4′ align=’center’><b>R E N T A
L&nbsp;&nbsp;&nbsp;&nbsp;A V A I L A B I L I T Y</b></td></tr>”;
print “<tr><td align=’center’>FROM</td><td
align=’center’>TO</td><td
align=’center’>STATUS</td><td>RATE</td></tr>”;
include(“rental_data.php”);
FOREACH ($arrWEEKS as $key => $status):
print “<input type=’hidden’ name=’week[$key]’ value=’1′>”;
print “<tr>”;
print “<td>” . date(“Y-m-d”, $key) . “</td>”;
print “<td>” . date(“Y-m-d”, $key+(7*24*60*60)) . “</td>”;
print “<td>”;
print ” <input type=’radio’ name=’status[$key]’ ” .
($arrWEEKS[$key][‘status’]==0? ‘checked’ : ”) . ”
value=’0′>Available&nbsp;”;
print ” <input type=’radio’ name=’status[$key]’ ” .
($arrWEEKS[$key][‘status’]==1? ‘checked’ : ”) . ”
value=’1′>Reserved&nbsp;”;
print ” <input type=’radio’ name=’status[$key]’ ” .
($arrWEEKS[$key][‘status’]==2? ‘checked’ : ”) . ”
value=’2′>Booked&nbsp;”;
print “</td>”;
print “<td>”;
print ” <input type=’text’ name=’rate[$key]’ value='” .
$arrWEEKS[$key][‘rate’] . “‘>”;
print “</td>”;
print “</tr>”;
ENDFOREACH;
print “</table>”;
print “<input type=’submit’ name=’submit’ value=’Update rental
schedule’>”;
print “</form>”;
ELSE :
//————– USER ————————
include(“rental_data.php”);
print “<table border=’0′>”;
print “<tr><td align=’left’
style=’font-family:verdana;font-size:14px;font-weight:bold;color:navy;’
>FROM
</td><td align=’left’
style=’font-family:verdana;font-size:14px;font-weight:bold;color:navy;’
>TO</
td><td align=’left’
style=’font-family:verdana;font-size:14px;font-weight:bold;color:navy;’
>STATUS</td><td
align=’right’style=’font-family:verdana;font-size:14px;font-weight:bold;color:navy;’>RATE</td></tr>”;
FOREACH ($arrWEEKS as $key => $status):
print “<tr>”;
print “<td
style=’font-family:verdana;font-size:14px;font-weight:bold;color:#369;’
>” .
date(“M jS”, $key) . “&nbsp;&nbsp;</td>”;
print “<td
style=’font-family:verdana;font-size:14px;font-weight:bold;color:#369;’
>” .
date(“M jS”, $key+(7*24*60*60)) . “&nbsp;&nbsp;</td>”;
print “<td
style=’font-family:verdana;font-size:14px;font-weight:bold;color:” .
$arrCOLORS[$arrWEEKS[$key][‘status’]] . “;’>” .
$arrSTATUS[$arrWEEKS[$key][‘status’]] . “&nbsp;&nbsp;</td>”;
print “<td
style=’font-family:verdana;font-size:14px;font-weight:bold;color:navy;t
ext-a
lign:right;’>&nbsp;£” . $arrWEEKS[$key][‘rate’] . “</td>”;
print “</tr>”;
ENDFOREACH;
print “</table>”;
ENDIF;
?>[/code]

[code=php]<?php
if (!isset($arrWEEKS)) {
$arrWEEKS = array();
}
$arrWEEKS[1205539200][‘status’] = 2;
$arrWEEKS[1205539200][‘rate’] = €1700;
$arrWEEKS[1206144000][‘status’] = 0;
$arrWEEKS[1206144000][‘rate’] = 1700;
$arrWEEKS[1206748800][‘status’] = 0;
$arrWEEKS[1206748800][‘rate’] = 1700;
$arrWEEKS[1207353600][‘status’] = 0;
$arrWEEKS[1207353600][‘rate’] = 1700;
$arrWEEKS[1207958400][‘status’] = 0;
$arrWEEKS[1207958400][‘rate’] = 1700;
$arrWEEKS[1208563200][‘status’] = 0;
$arrWEEKS[1208563200][‘rate’] = 1700;
$arrWEEKS[1209168000][‘status’] = 2;
$arrWEEKS[1209168000][‘rate’] = 2200;
$arrWEEKS[1209772800][‘status’] = 2;
$arrWEEKS[1209772800][‘rate’] = 2200;
$arrWEEKS[1210377600][‘status’] = 0;
$arrWEEKS[1210377600][‘rate’] = 2200;
$arrWEEKS[1210982400][‘status’] = 0;
$arrWEEKS[1210982400][‘rate’] = 2200;
$arrWEEKS[1211587200][‘status’] = 2;
$arrWEEKS[1211587200][‘rate’] = 2200;
$arrWEEKS[1212192000][‘status’] = 2;
$arrWEEKS[1212192000][‘rate’] = 2400;
$arrWEEKS[1212796800][‘status’] = 2;
$arrWEEKS[1212796800][‘rate’] = 2400;
$arrWEEKS[1213401600][‘status’] = 2;
$arrWEEKS[1213401600][‘rate’] = 2800;
$arrWEEKS[1214006400][‘status’] = 2;
$arrWEEKS[1214006400][‘rate’] = 2800;
$arrWEEKS[1214611200][‘status’] = 2;
$arrWEEKS[1214611200][‘rate’] = 2800;
$arrWEEKS[1215216000][‘status’] = 2;
$arrWEEKS[1215216000][‘rate’] = 3700;
$arrWEEKS[1215820800][‘status’] = 2;
$arrWEEKS[1215820800][‘rate’] = 3700;
$arrWEEKS[1216425600][‘status’] = 2;
$arrWEEKS[1216425600][‘rate’] = 3700;
$arrWEEKS[1217030400][‘status’] = 2;
$arrWEEKS[1217030400][‘rate’] = 3700;
$arrWEEKS[1217635200][‘status’] = 2;
$arrWEEKS[1217635200][‘rate’] = 3700;
$arrWEEKS[1218240000][‘status’] = 2;
$arrWEEKS[1218240000][‘rate’] = 3700;
$arrWEEKS[1218844800][‘status’] = 2;
$arrWEEKS[1218844800][‘rate’] = 3700;
$arrWEEKS[1219449600][‘status’] = 2;
$arrWEEKS[1219449600][‘rate’] = 3700;
$arrWEEKS[1220054400][‘status’] = 2;
$arrWEEKS[1220054400][‘rate’] = 3000;
$arrWEEKS[1220659200][‘status’] = 2;
$arrWEEKS[1220659200][‘rate’] = 3000;
$arrWEEKS[1221264000][‘status’] = 0;
$arrWEEKS[1221264000][‘rate’] = 2800;
$arrWEEKS[1221868800][‘status’] = 0;
$arrWEEKS[1221868800][‘rate’] = 2800;
$arrWEEKS[1222473600][‘status’] = 0;
$arrWEEKS[1222473600][‘rate’] = 1700;
$arrWEEKS[1223078400][‘status’] = 2;
$arrWEEKS[1223078400][‘rate’] = 1700;
$arrWEEKS[1223683200][‘status’] = 0;
$arrWEEKS[1223683200][‘rate’] = 1700;
$arrWEEKS[1224288000][‘status’] = 2;
$arrWEEKS[1224288000][‘rate’] = 1700;
$arrWEEKS[1224892800][‘status’] = 2;
$arrWEEKS[1224892800][‘rate’] = 1700;
?>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @le007 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...