Solved

Previous and next text buttons

Posted on 2010-11-11
13
404 Views
Last Modified: 2012-05-10
Hello experts,

Please look at the attached code and screenshot. I want to add two buttons; "Previous week" and "Next week" beside of the dropdown list.

I hope someone can help me implement this :-)

Thanks in advance!
//Get First Day of year;
				$year = date('Y');
				
				$get_week = (isset($_GET['week'])) ? urldecode($_GET['week']) : date('W')." ({$year})";
				$get_week = 'Week ' . $get_week;
				
				$yearBeginDate = strtotime("{$year}-01-01");
				$yearVal = intval(date('Y') + 1);
				$yearEndDate = strtotime("{$yearVal}-06-01");
				
				$currentDate = $yearBeginDate;
				
				//Get the Day of the Week Jan 1st is on
				$janFirstDay = date('N',$currentDate) - 1;
				$currentDate = $currentDate - (86400 * $janFirstDay);
				
				//Get the Last Day of the year to finish the week
				$DecLastDay = date('N',$yearEndDate) - 1;
				$yearEndDate = $yearEndDate + (86400 * $DecLastDay);
				
				$weekDays = array();
				while($currentDate < $yearEndDate){
					$weekDays[date('l',$currentDate)] = $currentDate;
					if(date('N',$currentDate) == 7){
						$weeks[] = array('weeks' => 'Week ' . date('W (Y)',$currentDate), 'weekdays' => $weekDays);
						$weekDays = array();
					}
					$currentDate += 86400;
				}

//Create the Drop down for the weeks
				echo 'Select week: <select onchange="window.location=\'?week=\' + (this.value);">';
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				  $firstWeekDay = reset($days);
					$lastWeekDay = end($days);
					$option = '<option ';
					$option .= ($week == $get_week) ? ' selected="selected" ' : '';
					$option .= ' value="' . urlencode(substr($week, 5)) . '">' . $week . ': ' . date('Y-m-d',$firstWeekDay) . ' - ' . date('Y-m-d',$lastWeekDay) . '</option>';
					echo $option;
				}
				echo '</select>'; if (isset($_GET['week'])) { echo ' <a href="tablebookings.php">Show current week</a>'; }
				echo '<div class="clear">&nbsp;</div>';

Open in new window

tb.jpg
0
Comment
Question by:sittinDuck
  • 7
  • 6
13 Comments
 
LVL 14

Expert Comment

by:sam2912
ID: 34117662
Try this quick fix:
//Get First Day of year;
                                $year = date('Y');
                                
                                $get_week = (isset($_GET['week'])) ? urldecode($_GET['week']) : date('W')." ({$year})";
                                $get_week = 'Week ' . $get_week;
                                
                                $yearBeginDate = strtotime("{$year}-01-01");
                                $yearVal = intval(date('Y') + 1);
                                $yearEndDate = strtotime("{$yearVal}-06-01");
                                
                                $currentDate = $yearBeginDate;
                                
                                //Get the Day of the Week Jan 1st is on
                                $janFirstDay = date('N',$currentDate) - 1;
                                $currentDate = $currentDate - (86400 * $janFirstDay);
                                
                                //Get the Last Day of the year to finish the week
                                $DecLastDay = date('N',$yearEndDate) - 1;
                                $yearEndDate = $yearEndDate + (86400 * $DecLastDay);
                                
                                $weekDays = array();
                                while($currentDate < $yearEndDate){
                                        $weekDays[date('l',$currentDate)] = $currentDate;
                                        if(date('N',$currentDate) == 7){
                                                $weeks[] = array('weeks' => 'Week ' . date('W (Y)',$currentDate), 'weekdays' => $weekDays);
                                                $weekDays = array();
                                        }
                                        $currentDate += 86400;
                                }

//Create the Drop down for the weeks
                                echo 'Select week: <select id="weekSel" onchange="window.location=\'?week=\' + (this.value);">';
                                foreach($weeks as $week_data){
                                  $week  = $week_data['weeks'];
                                  $days = $week_data['weekdays'];
                                  $firstWeekDay = reset($days);
                                        $lastWeekDay = end($days);
                                        $option = '<option ';
                                        $option .= ($week == $get_week) ? ' selected="selected" ' : '';
                                        $option .= ' value="' . urlencode(substr($week, 5)) . '">' . $week . ': ' . date('Y-m-d',$firstWeekDay) . ' - ' . date('Y-m-d',$lastWeekDay) . '</option>';
                                        echo $option;
                                }
                                echo '</select>';
										  // Add prev and next buttons
										  echo '<input type="button" value="Previous week" onclick="s=document.getElementById(\'weekSel\');try{s.selectedIndex=s.selectedIndex-1;}catch(e){}" />';
										  echo '<input type="button" value="Next week" onclick="s=document.getElementById(\'weekSel\');try{s.selectedIndex=s.selectedIndex+1;}catch(e){}" />';
										  if (isset($_GET['week'])) { echo ' <a href="tablebookings.php">Show current week</a>'; }
                                echo '<div class="clear">&nbsp;</div>';

Open in new window

0
 

Author Comment

by:sittinDuck
ID: 34119158
Seems like it doesn't work. Can it be text buttons? :-)
0
 
LVL 14

Expert Comment

by:sam2912
ID: 34121194
Did you mean: Text Links or Buttons?

Anyway, if possible please include the page code, or a link to it.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:sittinDuck
ID: 34127355
Text links - sorry!

Page code attached :-)
0
 

Author Comment

by:sittinDuck
ID: 34127356

<?php

//load files
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/datetime.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/session_start.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/Connections/db.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/restrictaccess.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/logout.php");

//page specific files
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/substr.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/timeconvert.php");

//accesscheck
if ($row_access['tablebooking_view'] == 'N') {
	header('location: /dashboard.php'); exit; }


//lock for new reservations
if ( (isset($_GET['date'])) && ($_GET['lock'] == 'true') ) {

  mysql_select_db($database_db, $db);
  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".$_GET['date']."'";
  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
  $row_check_locked = mysql_fetch_assoc($check_locked);
  $totalRows_check_locked = mysql_num_rows($check_locked);	

if ($totalRows_check_locked == 0) {
	
	$mysql = mysql_query("INSERT INTO reservation_locks SET date = '".$_GET['date']."', locked_by = '".$_SESSION['MM_UserId']."'"); 
	
	// Activity
	$activity = mysql_query("INSERT INTO activity SET idid = '".$_SESSION['MM_UserId']."', type = 'tb_locked', time = '".$datetime."', 
	ip = '".$_SERVER['REMOTE_ADDR']."', var_1 = '".$_GET['date']."'") or die(mysql_error());
}
  $_SESSION['msg']['text'] = 'You have locked for new reservations to:<br />'.ucfirst(timeconvert_aar($_GET['date']));
  $_SESSION['msg']['type'] = 'info';
  session_write_close();
  header('location: /booking/tablebookings.php'); exit;
}

//open for new reservations
if ( (isset($_GET['date'])) && ($_GET['lock'] == 'false') ) {

  mysql_select_db($database_db, $db);
  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".$_GET['date']."'";
  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
  $row_check_locked = mysql_fetch_assoc($check_locked);
  $totalRows_check_locked = mysql_num_rows($check_locked);	

if ($totalRows_check_locked > 0) {
	$mysql = mysql_query("DELETE FROM reservation_locks WHERE `date` = '".$_GET['date']."'"); 
	
	// Activity
	$activity = mysql_query("INSERT INTO activity SET idid = '".$_SESSION['MM_UserId']."', type = 'tb_open', time = '".$datetime."', 
	ip = '".$_SERVER['REMOTE_ADDR']."', var_1 = '".$_GET['date']."'") or die(mysql_error());
}
  $_SESSION['msg']['text'] = 'You have opened for new reservations to:<br />'.ucfirst(timeconvert_aar($_GET['date']));
  $_SESSION['msg']['type'] = 'info';
  session_write_close();
  header('location: /booking/tablebookings.php'); exit;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Housekeeping - Karel van Mander</title>
<!-- Favicons --> 
<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/favicons.php'); ?>
<!-- Main Stylesheets --> 
<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/stylesheets.php'); ?>
<!-- JavaScripts --> 
<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/javascripts.php'); ?>
<script type="text/javascript">
$(document).ready(function(){
						   
	/* setup navigation, content boxes, etc... */
	Administry.setup();

});
</script>

</head>
<body>
	
      <!-- Header -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/pageheader.php'); ?>
	<!-- End of Header -->
	
	<!-- Page title -->
		<div id="pagetitle">
		<div class="wrapper">
			<h1>Booking &rarr; <span>Table reservations</span></h1>
			<!-- Quick search box -->
			<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/globalsearch.php'); ?>
		</div>
	</div>
	<!-- End of Page title -->
	
		<!-- Page content -->
		<div id="page">
		<!-- Wrapper -->
		<div class="wrapper">
				<!-- Left column/section -->
				<section class="column width8 first">
                	<h3>Table reservations</h3>
					<span class="subtitle">Table reservations overview</span>
					<hr>
                
                <?php

				//Get First Day of year;
				$year = date('Y');
				
				$get_week = (isset($_GET['week'])) ? urldecode($_GET['week']) : date('W')." ({$year})";
				$get_week = 'Week ' . $get_week;
				
				$yearBeginDate = strtotime("{$year}-01-01");
				$yearVal = intval(date('Y') + 1);
				$yearEndDate = strtotime("{$yearVal}-06-01");
				
				$currentDate = $yearBeginDate;
				
				//Get the Day of the Week Jan 1st is on
				$janFirstDay = date('N',$currentDate) - 1;
				$currentDate = $currentDate - (86400 * $janFirstDay);
				
				//Get the Last Day of the year to finish the week
				$DecLastDay = date('N',$yearEndDate) - 1;
				$yearEndDate = $yearEndDate + (86400 * $DecLastDay);
				
				$weekDays = array();
				while($currentDate < $yearEndDate){
					$weekDays[date('l',$currentDate)] = $currentDate;
					if(date('N',$currentDate) == 7){
						$weeks[] = array('weeks' => 'Week ' . date('W (Y)',$currentDate), 'weekdays' => $weekDays);
						$weekDays = array();
					}
					$currentDate += 86400;
				}
				
				//Create the Drop down for the weeks
				echo 'Select week: <select onchange="window.location=\'?week=\' + (this.value);">';
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				  $firstWeekDay = reset($days);
					$lastWeekDay = end($days);
					$option = '<option ';
					$option .= ($week == $get_week) ? ' selected="selected" ' : '';
					$option .= ' value="' . urlencode(substr($week, 5)) . '">' . $week . ': ' . date('Y-m-d',$firstWeekDay) . ' - ' . date('Y-m-d',$lastWeekDay) . '</option>';
					echo $option;
				}
				echo '</select>'; if (isset($_GET['week'])) { echo ' <a href="tablebookings.php">Show current week</a>'; }
				echo '<div class="clear">&nbsp;</div>';
				
				
				if ($row_access['guestlist'] == 'Y') {
				//Create the Grid for the Guestlist.
				//set How Many Rows and columns
				$row_count = 0;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				   if($week == $get_week){
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }
						  
							echo '';
					  }
					  echo '';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									echo '<td align="center" style="background-color:#e2e9f3;"><strong>Guestlist /no tables</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']); $linkdate = date('d-m-Y', $days['Monday']); }
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); $linkdate = date('d-m-Y', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); $linkdate = date('d-m-Y', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); $linkdate = date('d-m-Y', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); $linkdate = date('d-m-Y', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); $linkdate = date('d-m-Y', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); $linkdate = date('d-m-Y', $days['Sunday']);  }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT id FROM reservations WHERE booking_date = '".$coldate."' AND table_nightclub_1 IS NULL";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									
									if ($totalRows_reservations > 0) { ?>
									<td align="center" class="booking"><a href="/booking/guestlist.php?date=<?php echo $coldate; ?>"><?php echo $totalRows_reservations; ?> groups</a></td>
                                    <?php } else { ?>
                                    <td align="center"><a href="/booking/guestlist.php?date=<?php echo $coldate; ?>"><?php echo $totalRows_reservations; ?> groups</a></td>
                  					<?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
							echo '<div class="clear">&nbsp;</div>'; }
				
				
				//Create the Grid for Nightclub.
				//set How Many Rows and columns
				$row_count = 9;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays']; 
				   if($week == $get_week){
					  echo '<tr><th><strong><font size="2">Nightclub</font></strong><br /><font size="-3"><a href="/img/plans/nightclub.png" class="nyroModal" title="Show nightclub overview">Show map</a></font></th>';
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }
						  
						  mysql_select_db($database_db, $db);
						  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".date('Y-m-d',$day)."'";
						  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
						  $row_check_locked = mysql_fetch_assoc($check_locked);
						  $totalRows_check_locked = mysql_num_rows($check_locked);
						  
						  if ($totalRows_check_locked > 0) { 
						  $locked_bgcolor = ' style="background-color:#f9c8c8;"'; $locked_img = 'lock_open.png';  $locked_link = 'false'; 
						  } else { 
						  $locked_bgcolor = ''; $locked_img = 'lock.png'; $locked_link = 'true'; }
						  
							echo '<th'.$locked_bgcolor.'><strong>' . $d_day . '</strong> <img src="/img/icons/printer.png" width="12" height="12" border="0" 
							onClick="window.location.href=\'print_tablebookings.php?date='.date('Y-m-d', $day).'\'" title="Print table reservations" /> 	
							<img src="/img/icons/script.png" width="12" height="12" border="0" onClick="window.location.href=\'print_guestlist.php?date='.date('Y-m-d', $day).'\'" 
							title="Print guestlist" /> <img src="/img/icons/'.$locked_img.'" width="12" height="12" onClick="window.location.href=\'tablebookings.php?date='.date('Y-m-d', $day).'&lock='.$locked_link.''.'\'" title="Lock/open for new reservations" /><br />' . date('Y-m-d',$day) . '</th>';
					  }
					  echo '</tr>';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									echo '<td align="center"><strong>Table ' . $table . '</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']); }
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT * FROM reservations WHERE booking_date = '".$coldate."' AND table_nightclub_".$table." = 'Y' LIMIT 1";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									if ($totalRows_reservations > 0) { ?>
									<td class="booking"><a href="tablebooking.php?id=<?php echo $row_reservations['id']; ?>" title="<?php echo htmlspecialchars($row_reservations['customer_name']); ?>"><?php echo htmlspecialchars(abbreviate($row_reservations['customer_name'], 17)); ?></a></td>
									<?php } else { ?> 
									<td onClick="document.location.href='create_tablebooking.php?date=<?php echo $coldate; ?>&table=<?php echo $table; ?>'" class="nobooking">New reservation</td>
                                    <?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
							echo '<div class="clear">&nbsp;</div>';
				
				
				//Create the Grid for Lounge.
				//set How Many Rows and columns
				$row_count = 5;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				   if($week == $get_week){
					  echo '<tr><th><strong><font size="2">Lounge</font></strong><br /><font size="-3"><a href="/img/plans/lounge.png" class="nyroModal" title="Show lounge overview">Show map</a></font></th>';
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }

						  mysql_select_db($database_db, $db);
						  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".date('Y-m-d',$day)."'";
						  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
						  $row_check_locked = mysql_fetch_assoc($check_locked);
						  $totalRows_check_locked = mysql_num_rows($check_locked);
						  
						  if ($totalRows_check_locked > 0) { 
						  $locked_bgcolor = ' style="background-color:#f9c8c8;"'; $locked_img = 'lock_open.png';  $locked_link = 'false'; 
						  } else { 
						  $locked_bgcolor = ''; $locked_img = 'lock.png'; $locked_link = 'true'; }
						  
							echo '<th'.$locked_bgcolor.'><strong>' . $d_day . '</strong> <img src="/img/icons/printer.png" width="12" height="12" border="0" 
							onClick="window.location.href=\'print_tablebookings.php?date='.date('Y-m-d', $day).'\'" title="Print table reservations" /> 	
							<img src="/img/icons/script.png" width="12" height="12" border="0" onClick="window.location.href=\'print_guestlist.php?date='.date('Y-m-d', $day).'\'" 
							title="Print guestlist" /> <img src="/img/icons/'.$locked_img.'" width="12" height="12" onClick="window.location.href=\'tablebookings.php?date='.date('Y-m-d', $day).'&lock='.$locked_link.''.'\'" title="Lock/open for new reservations" /><br />' . date('Y-m-d',$day) . '</th>';
							
					  }
					  echo '</tr>';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									$table_pointer = $i+11;
									echo '<td align="center"><strong>Table ' . $table_pointer . '</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']);}
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT * FROM reservations WHERE booking_date = '".$coldate."' AND table_lounge_".$table." = 'Y' LIMIT 1";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									if ($totalRows_reservations > 0) { ?>
									<td class="booking"><a href="tablebooking.php?id=<?php echo $row_reservations['id']; ?>" title="<?php echo htmlspecialchars($row_reservations['customer_name']); ?>"><?php echo htmlspecialchars(abbreviate($row_reservations['customer_name'], 17)); ?></a></td>
									<?php } else { ?> 
									<td onClick="document.location.href='create_tablebooking.php?date=<?php echo $coldate; ?>&table=<?php echo $table_pointer; ?>'" class="nobooking">New reservation</td>
                                    <?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
				echo '<div class="clear">&nbsp;</div>';
				
				
				//Create the Grid for Patio.
				//set How Many Rows and columns
				$row_count = 4;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				   if($week == $get_week){
					  echo '<tr><th><strong><font size="2">Terrace</font></strong><br /><font size="-3"><a href="/img/plans/patio.png" class="nyroModal" title="Show terrace overview">Show map</a></font></th>';
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }

						  
						  mysql_select_db($database_db, $db);
						  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".date('Y-m-d',$day)."'";
						  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
						  $row_check_locked = mysql_fetch_assoc($check_locked);
						  $totalRows_check_locked = mysql_num_rows($check_locked);
						  
						  if ($totalRows_check_locked > 0) { 
						  $locked_bgcolor = ' style="background-color:#f9c8c8;"'; $locked_img = 'lock_open.png';  $locked_link = 'false'; 
						  } else { 
						  $locked_bgcolor = ''; $locked_img = 'lock.png'; $locked_link = 'true'; }
						  
							echo '<th'.$locked_bgcolor.'><strong>' . $d_day . '</strong> <img src="/img/icons/printer.png" width="12" height="12" border="0" 
							onClick="window.location.href=\'print_tablebookings.php?date='.date('Y-m-d', $day).'\'" title="Print table reservations" /> 	
							<img src="/img/icons/script.png" width="12" height="12" border="0" onClick="window.location.href=\'print_guestlist.php?date='.date('Y-m-d', $day).'\'" 
							title="Print guestlist" /> <img src="/img/icons/'.$locked_img.'" width="12" height="12" onClick="window.location.href=\'tablebookings.php?date='.date('Y-m-d', $day).'&lock='.$locked_link.''.'\'" title="Lock/open for new reservations" /><br />' . date('Y-m-d',$day) . '</th>';
							
					  }
					  echo '</tr>';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									if ($table == 1) { $abc = 'A'; 
									} else if ($table == 2) { $abc = 'B'; 
									} else if ($table == 3) { $abc = 'C';
									} else if ($table == 4) { $abc = 'D';
									} else if ($table == 5) { $abc = 'E'; }
									echo '<td align="center"><strong>Table ' . $abc . '</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']); $linkdate = date('d-m-Y', $days['Monday']); }
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); $linkdate = date('d-m-Y', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); $linkdate = date('d-m-Y', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); $linkdate = date('d-m-Y', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); $linkdate = date('d-m-Y', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); $linkdate = date('d-m-Y', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); $linkdate = date('d-m-Y', $days['Sunday']);  }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT * FROM reservations WHERE booking_date = '".$coldate."' AND table_patio_".$table." = 'Y' LIMIT 1";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									if ($totalRows_reservations > 0) { ?>
									<td class="booking"><a href="tablebooking.php?id=<?php echo $row_reservations['id']; ?>" title="<?php echo htmlspecialchars($row_reservations['customer_name']); ?>"><?php echo htmlspecialchars(abbreviate($row_reservations['customer_name'], 17)); ?></a></td>
									<?php } else { ?> 
									<td onClick="document.location.href='create_tablebooking.php?date=<?php echo $linkdate; ?>&table=<?php echo $abc; ?>'" class="nobooking">New reservation</td>
                                    <?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
				echo '<div class="clear">&nbsp;</div>';
				
				//Create the Drop down for the weeks
				echo 'Select week: <select onchange="window.location=\'?week=\' + (this.value);">';
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				  $firstWeekDay = reset($days);
					$lastWeekDay = end($days);
					$option = '<option ';
					$option .= ($week == $get_week) ? ' selected="selected" ' : '';
					$option .= ' value="' . urlencode(substr($week, 5)) . '">' . $week . ': ' . date('Y-m-d',$firstWeekDay) . ' - ' . date('Y-m-d',$lastWeekDay) . '</option>';
					echo $option;
				}
				echo '</select>'; if (isset($_GET['week'])) { echo ' <a href="tablebookings.php">Show current week</a>'; }

				?>

                <div class="clear">&nbsp;</div>

				</section>
				<!-- End of Left column/section -->
				
		</div>
		<!-- End of Wrapper -->
	</div>
	<!-- End of Page content -->
	
	<!-- Page footer -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/pagefooter.php'); ?>
	<!-- End of Page footer -->
	
	<!-- Animated footer -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/animatedfooter.php'); ?>
	<!-- End of Animated footer -->
	
	<!-- Scroll to top link -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/scroll.php'); ?>
    
    <!-- Javascript load -->
	<script type="text/javascript" src="/js/administry.js"></script>
	</body>
	</html>
	<?php
	mysql_free_result($reservations);
	mysql_free_result($check_locked);
	?>

Open in new window

0
 
LVL 14

Expert Comment

by:sam2912
ID: 34127446
1) You need to add an id="weekSel" to the select:

//Create the Drop down for the weeks
echo 'Select week: <select id="weekSel" onchange="window.location=\'?week=\' + (this.value);">';

2) The links will refer to the select with that id:

// Add prev and next links
echo '<a href="javascript:s=document.getElementById(\'weekSel\'); s.selectedIndex=s.selectedIndex-1; return false;">Previous week</a>';
echo '<a href="javascript:s=document.getElementById(\'weekSel\'); s.selectedIndex=s.selectedIndex+1; return false;">Next week</a>';

Test page attached:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Increment/Decrement Selected Option</title>
</head>

<body>
<select id="mySelect">
	<option>a</option>
	<option>b</option>
	<option>c</option>
	<option>d</option>
	<option>e</option>
</select>
<a href="javascript:s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex-1; return false;">Previous</a> 
<a href="javascript:s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex+1; return false;">Next</a>
</body>
</html>

Open in new window

0
 

Author Comment

by:sittinDuck
ID: 34131789
Thank you Sam. I'm using Firefox and in this browser it won't work. However, if I try in Safari, it does work.

Is there a fix for this? ;-)

0
 
LVL 14

Expert Comment

by:sam2912
ID: 34134190

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Increment/Decrement Selected Option</title>
</head>

<body>
<select id="mySelect">
        <option>a</option>
        <option>b</option>
        <option>c</option>
        <option>d</option>
        <option>e</option>
</select>
<a href="#" onclick="s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex-1;">Previous</a> 
<a href="#" onclick="s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex+1;">Next</a>
</body>
</html>

Open in new window

0
 

Author Comment

by:sittinDuck
ID: 34134445
Thanks!

It's now changing the option in the dropdown but it doesn't reload the page with the new settings.

As you can see I'm using the dropdown to select a week :-) Is there a way to activate the onchange?

<select id="weekSel" onchange="window.location=\'?week=\' + (this.value);">
0
 
LVL 14

Accepted Solution

by:
sam2912 earned 500 total points
ID: 34134848
Yes, the simplest way would be to use a function, as it needs to be referenced by both the select and the links.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Increment/Decrement Selected Option</title>
<script type="text/javascript">
//<![CDATA[
function gotoSelected() {
	window.location = document.getElementById('mySelect').value;
}
//]]>
</script>
</head>

<body>
<select id="mySelect" onchange="gotoSelected();">
        <option>a</option>
        <option>b</option>
        <option>c</option>
        <option>d</option>
        <option>e</option>
</select>
<a href="#" onclick="s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex-1; gotoSelected();">Previous</a> 
<a href="#" onclick="s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex+1; gotoSelected();">Next</a>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:sittinDuck
ID: 34135014
Thank you, it works now!

Is it possible to include the page name in the value? Like..

window.location = 'tablebookings.php?week='.document.getElementById('weekSel').value; ?
0
 
LVL 14

Expert Comment

by:sam2912
ID: 34135291
yes, why not? but to concatentate string, you use the "+" operator instead of a "."
0
 

Author Comment

by:sittinDuck
ID: 34135820
Thanks!!! :-)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Browser Chrome downloads colored link 5 41
HTML5 frame 5 25
two ways encryption with php 3 27
Optimize simple Javascript code to use no repetitions 12 31
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question