Hi all,
I have a problem how to put these code together so I can get one solution. First code do booking by clicking each day cell and take it in to mysql and doing fine, but I like to add two datepicker with in. Second code book with datepicker. So I can booking multiple day by few clicking example startday 2010-10-14 and endday 2010-10-22 and take it in to mysql. How I can put these together and take to mysql? Do I have to make two diffrent table in to database? One table for first code and second table for second code? If don't understand, please ask more.
First code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
<link rel="stylesheet" href="calendar.css" />
<script language="JavaScript" src="calendar_eu.js"></script>
<style>
td.pv { width: 20px; text-align: center; }
.la { color: c00; }
a { text-decoration: none; color: 000; }
.la a { color: c00; text-decoration: line-through;}
td.free { background-image:url('0.gif'); background-repeat:no-repeat; }
td.am { background-image:url('1.gif'); background-repeat:no-repeat; }
td.pm { background-image:url('2.gif'); background-repeat:no-repeat; }
td.hole { background-image:url('3.gif'); background-repeat:no-repeat; }
</style>
<script>
/v=year, k=month, p=day/
function SetDay(v,k,p) {
document.getElementById('v').value=v
document.getElementById('k').value=k
document.getElementById('p').value=p
document.getElementById('pv').innerHTML = p+'.'+k+'.'+v
document.getElementById('f').style["display"]=''
}
</script>
</head>
<body><table>
<tr><td></td>
<?php
setlocale(LC_TIME, "fin");
setlocale(LC_TIME, "fi_FI");
//weeksdays
$pvt = explode(',','ma,ti,ke,to,pe,la,su');
for ($i=0;$i<37;$i++) echo '<td class="pv'.(($i%7==5)?' la':'').'">'.$pvt[$i%7].'</td>';
?>
</tr>
<?php
$month = date('n');
$year = date('Y');
$firstDay = date('d');
$lastmonth = $month;
$lastyear = $year+1;
mysql_connect('xxxxx','xxxx','');
mysql_select_db('xxxxxx');
if (isset($POST['p'])) {
$p = (int)$POST['p'];
$v = (int)$POST['v'];
$k = (int)$POST['k'];
$r = (int)$_POST['r'];
if ($p > 0 && $p < 32 && $k>0 && $k<12 && $v>=$year && $v<=$lastyear && $r>=0 && $r<4) {
$res=mysql_query("UPDATE calendar SET book=$r where days='$v-$k-$p'");
if (mysql_affected_rows()==0) mysql_query("INSERT INTO calendar (book,days) VALUES ($r,'$v-$k-$p')");
}
}
//months Januari, februari,...
$kkt = explode(',','Tammi,Helmi,Maalis,Huhti,Touko,Kesä,Heinä,Elo,Syys,Loka,Marras,Joulu');
$futuredate = mktime(0,0,0,1,1,$year+10);
$res = mysql_query("SELECT days,book FROM calendar WHERE days>='$year-$month-$firstDay' AND days<='" .($year+2) . "-01-01' ORDER BY days");
$row = mysql_fetch_row($res);
$classes = explode(',','free,am,pm,hole');
while ($year<$lastyear || $month<=$lastmonth) {
echo '<tr><td>'.$kkt[$month-1].'kuu '.$year . '</td>';
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$dayOffset = (6+date('w',$firstDayOfMonth))%7;
$lastday = date('t',$firstDayOfMonth);
for ($i=1;$i<=37;$i++) {
if ($row===false) $dbdays = $futuredate; else $dbdays=strtotime($row[0]);
$day = $i - $dayOffset;
if ($day >= $firstDay && $day <= $lastday) {
echo '<td class="pv';
if ($i%7==6) echo ' la';
if ($dbdays > mktime(0,0,0,$month,$day,$year)) {
echo ' '.$classes[0];
} else {
echo ' '.$classes[$row[1]];
$row = mysql_fetch_row($res);
}
echo '">';
echo "<a href=\"javascript:SetDay($year,$month,$day)\">$day</a>";
} else echo '<td>';
echo '</td>';
}
echo '</tr>';
$month++;
if ($month==13) {
$year++;
$month=1;
}
$firstDay = 1;
}
?>
</table>
<p><form name="form" method="post" action="<?php $_SERVER['REQUEST_METHOD']; ?>" id="f" style="display:all">
Set days <span id="pv">new</span> book:
<input type="hidden" name="v" id="v" value="">
<input type="hidden" name="k" id="k" value="">
<input type="hidden" name="p" id="p" value="">
<input type="radio" name="r" value="0" selected="">free
<input type="radio" name="r" value="1">am
<input type="radio" name="r" value="2">pm
<input type="radio" name="r" value="3">hole day
<input type="submit" name="submit" value="Book">
</form></p>
</body>
</html>
Second code:
<html>
<head>
<link rel="stylesheet" href="calendar.css" />
<script language="JavaScript" src="calendar_eu.js"></script>
</head>
<body>
<?php
setlocale(LC_TIME, "fin");
$dbuser="xxxxx";
$dbpass="xxxxx";
$host="xxxxxxx";
$conn=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("lincal", $conn);
$today = date('Y-n-j');
$action = mysql_query("SELECT * FROM actions WHERE start1>='$today'", $conn) or die("Query did not succeed:". mysql_error());
$actionlist = array();
while ($row = mysql_fetch_array($action)) {
$start = strtotime($row['start1']);
$end = strtotime($row['end1']);
$actionlist[] = array($start, $end);
}
$month = date('n');
$year = date('Y');
$day = date('j');
echo '<table width="90%" border="0px #009 solid; cellspacing="10" cellpadding="0" style="text-align: center">';
echo "<tr>";
echo "<th></th>";
for ($i=1;$i<=5;$i++)
/these are weekdays/
echo '<th style="width: 25px;">Ma</th><th style="width: 25px;">Ti</th><th>Ke</th><th style="width: 25px;">To</th><th>Pe</th><th>La</th><th style="width: 30px;">Su</th>';
echo '<th>Ma</th><th>Ti</th>';
echo '<tr>';
for ($i=0; $i<12; $i++) {
$timestamp = mktime(0,0,0,$month+$i,$j,$year);
$dayofweek = date('w', $timestamp);
$amountofdays = date('t', $timestamp);
$empties = $dayofweek-1;
echo '<td style=\"width: 20px; text-align: center;\">'.strftime("%B %Y", $timestamp).'</td>';
if($dayofweek == 0) $empties = 6;
$empties--;
for ($j=-1*$empties; $j<=$amountofdays; $j++) {
$thisDay = mktime(0,0,0,$month+$i,$j,$year);
if ($j == date('j') && $i == 0) {
echo '<td bgcolor = "yellow" span style="color: red;">';
}else{
$action = false;
foreach ($actionlist as $tl) {
if ($tl[0] <= $thisDay && $tl[1] >= $thisDay) $action = true;
}
if ($action == true) echo '<td bgcolor="red">';
else echo '<td bgcolor="#91CD92">';
}
if ($j>0 && ($i>0 || $j>=date('j'))) echo $j;
else echo ' ';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
mysql_close($conn);
?>
<form name="form" action="insert2.php" method="post" />
<input name="id" value="" size="" type="hidden" />
<center><p>
startday <input name="start1" size="12" id="start1" type="text" />
<script language="JavaScript">
var o_cal = new tcal ({
// formname
'formname': 'form',
// field name
'controlname': 'start1'
});
o_cal.a_tpl.yearscroll = false;
o_cal.a_tpl.weekstart = 1;
</script>
<span style="padding-left: 19px;">endday <input name="end1" size="12" id="end1" type="text" />
<script language="JavaScript">
var A_CALTPL = {
'months' : ['Tammi', 'Helmi', 'Maalis', 'Huhti', 'Touko', 'Kesä', 'Heinä', 'Elo', 'Syys', 'Loka', 'Marras', 'Joulu'],
'weekdays' : ['su', 'ma', 'ti', 'ke', 'to', 'pe', 'la'],
'yearscroll': true,
'weekstart': 1,
'centyear' : 70,
'imgpath' : ''
}
new tcal ({
'controlname': 'end1'
}, A_CALTPL);
</script>
<input style="width: 40;" type="submit" name="submit" value="Send" />
</form>
</body>
</html>
Please, help me. I'm little pit of confuse with this.