Lid |
|
Beste lezers,
ik laad mijn agenda in via een jQuery Ajax call.
Echter wil ik graag dat ik een volgende en vorige maand kan kiezen.
Echter krijg ik dit niet goed voor elkaar. Kan iemand mij aub vertellen hoe ik dit moet aanpakken en -of een voorbeeld code maken van de correcte functie?
Ik wil dus dat als er op vorige of volgende geklikt word, de timestamp word meegestuurd minus of plus één maand. Echter krijg ik de timestamp niet mee gestuurd.
De code die je onderaan ziet word al eens door een Ajax call geinclude in mijn index.php.
Mijn huidige code:
// Get this months first day and last day in a timestamp
if(isset($_POST['timestamp'])){
$first_day = $_POST['timestamp'];
} else {
$first_day = strtotime(date("m/d/Y", strtotime(date('m').'/01/'.date('Y').' 00:00:00')));
}
$last_day = strtotime(date("m/d/Y", strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00')))));
// Get time difference
$minus = strtotime('-1 month', $first_day);
$plus = strtotime('+1 month', $first_day);
// Display header
echo '<div class="month">
<div class="previous">
<a href="#" title="Vorige maand" onclick="previousMonth('.$minus.'); return false;"><<</a>
</div>
<div class="monthName">
'.date("F").'
</div>
<div class="next">
<a href="#" title="Volgende maand" onclick="nextMonth('.$plus.'); return false;">>></a>
</div>
</div>';
// Check amount of empty boxes to add
$first_day_of_week = date("D", $first_day);
switch($first_day_of_week)
{
case 'Mon':
$amount = 0;
break;
case 'Tue':
$amount = 1;
break;
case 'Wed':
$amount = 2;
break;
case 'Thu':
$amount = 3;
break;
case 'Fri':
$amount = 4;
break;
case 'Sat':
$amount = 5;
break;
case 'Sun':
$amount = 6;
break;
}
// Display the empty boxes
$b = 1;
for($c = 0; $c < $amount; $c++)
{
if($b % 7 != 0)
{
echo '<div class="day push-right b-space"></div>';
}
else
{
echo '<div class="day b-space"></div>';
}
$b++;
}
// Display all the other days
$i = $b;
// Loop through the results and display the days
while($first_day <= $last_day)
{
// Check for events
$query = mysql_query('SELECT tekst FROM site_agenda
WHERE
datum = "'.mysql_real_escape_string(date("Y-m-d", $first_day)).'"');
$rows = mysql_num_rows($query);
if($rows >= 1)
{
$a = ' booked';
}
else
{
$a = '';
}
// Display
if($i % 7 != 0)
{
echo '<div class="day push-right b-space'.$a.'">'.date("d", $first_day).'</div>';
}
else
{
echo '<div class="day b-space'.$a.'">'.date("d", $first_day).'</div>';
}
// Add 1 day to the timestamp and up the counter
$first_day += 60*60*24;
$i++;
}
?>
<script language="javascript" type="text/javascript">
function nextMonth(adding){
$.ajax({
type: 'POST',
url: 'includes/agenda.php',
data: {
timestamp : adding
},
success: function(html){
$('#agendacall').html(html)
}
});
}
function previousMonth(minus){
$.ajax({
type: 'POST',
url: 'includes/agenda.php',
data: {
timestamp : minus
},
success: function(html){
$('#agendacall').html(html)
}
});
}
</script>
// Get this months first day and last day in a timestamp if(isset($_POST['timestamp'])){ $first_day = $_POST['timestamp']; } else { } // Get time difference // Display header echo '<div class="month"> <div class="previous"> <a href="#" title="Vorige maand" onclick="previousMonth('.$minus.'); return false;"><<</a> </div> <div class="monthName"> </div> <div class="next"> <a href="#" title="Volgende maand" onclick="nextMonth('.$plus.'); return false;">>></a> </div> </div>'; // Check amount of empty boxes to add $first_day_of_week = date("D", $first_day); switch($first_day_of_week) { case 'Mon': $amount = 0; break; case 'Tue': $amount = 1; break; case 'Wed': $amount = 2; break; case 'Thu': $amount = 3; break; case 'Fri': $amount = 4; break; case 'Sat': $amount = 5; break; case 'Sun': $amount = 6; break; } // Display the empty boxes $b = 1; for($c = 0; $c < $amount; $c++) { if($b % 7 != 0) { echo '<div class="day push-right b-space"></div>'; } else { echo '<div class="day b-space"></div>'; } $b++; } // Display all the other days $i = $b; // Loop through the results and display the days while($first_day <= $last_day) { // Check for events WHERE if($rows >= 1) { $a = ' booked'; } else { $a = ''; } // Display if($i % 7 != 0) { echo '<div class="day push-right b-space'.$a.'">'.date("d", $first_day).'</div>'; } else { echo '<div class="day b-space'.$a.'">'.date("d", $first_day).'</div>'; } // Add 1 day to the timestamp and up the counter $first_day += 60*60*24; $i++; } ?> <script language="javascript" type="text/javascript"> function nextMonth(adding){ $.ajax({ type: 'POST', url: 'includes/agenda.php', data: { timestamp : adding }, success: function(html){ $('#agendacall').html(html) } }); } function previousMonth(minus){ $.ajax({ type: 'POST', url: 'includes/agenda.php', data: { timestamp : minus }, success: function(html){ $('#agendacall').html(html) } }); } </script>
EDIT:
Heb het nu werkend alleen gooit hij de dagen en lege velden een beetje in het honderd. Hopelijk kan iemand mij helpen alles correct te krijgen
P.S. Excuses dat ik het in PHP sectie heb geplaatst, had het beter in JS sectie kunnen plaatsen
|