Jump to content

[SOLVED] Calendar


arn_php

Recommended Posts

I have a calendar page to show the schedule on a 'month view' mode. The problem is, it starts from Monday to Sunday. I want to change it from Sunday to Saturday.  And also the page only shows a 12 months of a current year.  How can I make it to show an option of 12 months of a current year PLUS 2-3 years ahead?  So a 36 to 48 months option on a drop down box.. ?

If anybody could help me, I really appreciate it. Here is the code.

 

 

 

<?php
include_once('_init.php');
if(isset($_POST['month'])){
	$_GET['month'] = $_POST['month'];
}else{
	if($_GET['date'] != ''){
		$exp = explode('-', $_GET['date']);
		$_GET['month'] = $exp[1];
	}else{
		$_GET['month'] = date('m');
	}
}
$_GET['date'] = '01-'.$_GET['month'].'-'.date('Y');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Calendar</TITLE>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="resource-type" content="document" />
<meta name="googlebot" content="nosnippet" />
<meta name="revisit-after" content="7 days" />
<meta name="robots" content="all,index" />
<meta name="language" content="en" />
<meta name="classification" content="services" />
<link href="style.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY>
<TABLE WIDTH=1000 BORDER=0 CELLPADDING=0 CELLSPACING=0 align="center">
  <TR> 
    <TD WIDTH=14 bgcolor="#752802"></TD>
    <TD valign="top" bgcolor="#C8A86D"> 
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td><p><br><strong>Calendar of Events</strong></p>
  <p><form method="post" name="form1">
        <div align="center">
          <select name="month" onChange="javascript:document.forms['form1'].submit();">
            <? select_array($array_month, $_GET['month']);?>
          </select>
            Quick jump to month </div>
      </form></p>
          <table width="700" align="center" cellpadding="0" cellspacing="0" class="tabel">
            <tr>
              <td width="100" align="center" class="tabel"><strong>Mon</strong></td>
              <td width="100" align="center" class="tabel"><strong>Tue</strong></td>
              <td width="100" align="center" class="tabel"><strong>Wed</strong></td>
              <td width="100" align="center" class="tabel"><strong>Thu</strong></td>
              <td width="100" align="center" class="tabel"><strong>Fri</strong></td>
              <td width="100" align="center" class="tabel"><strong>Sat</strong></td>
              <td width="100" align="center" class="tabel"><strong>Sun</strong></td>
            </tr>
<?php
$date = $_GET['date'];
$zi = explode('-', $date);
$day_week = date("w", mktime(0,0,0, $zi[1], "1", $zi[2]));
if($day_week == 0){
	$day_week = 7;
}
$fin = 5;
if($day_week >4){
	$fin = 6;
}
for($i=0;$i<$fin;$i++){
?>
<tr>
<?php
	for($j=0;$j<7;$j++){
		$query = "SELECT cid FROM isc_cal WHERE FROM_UNIXTIME(date_added, '%d-%m-%Y') = '".date("d-m-Y", mktime(0,0,0,$zi[1], 1+$j+7*$i-($day_week-1), $zi[2]))."' and flag_status = '1' ";
		$result = mysql_query($query, $connection) or die('ERROR :: QUERY'."<br>".$query."<br>".mysql_error());
		$xx_m = date("m", mktime(0,0,0,$zi[1], 1+$j+7*$i-($day_week-1), $zi[2]));
		$xx_d = date("d", mktime(0,0,0,$zi[1], 1+$j+7*$i-($day_week-1), $zi[2]));
		$detail = '';
		if($xx_m != $zi[1]){
			$class = "customtext2";
			$detail =  '';
		}elseif(($xx_d == date('d'))&&($xx_m == date("m"))){
			$class = "td_today";
			if(mysql_num_rows($result) > 0){
				$class = "td_today_ap";
				$detail = '<br><a href="javascript:void(0)" onClick="javascript:window.open(\'open_details.php?date='.date("d-m-Y", mktime(0,0,0,$zi[1], 1+$j+7*$i-($day_week-1), $zi[2])).'\', \'title\', \'width=400, height=300, statusbar=yes, scroolbars=yes\')"><font color="ffffff" size="2">See Events,<br><em>please click here</em></font></a>';
			}
		}else{
			if(mysql_num_rows($result) > 0){
				$class = "td_ap";
				$detail = '<br><a href="javascript:void(0)" onClick="javascript:window.open(\'open_details.php?date='.date("d-m-Y", mktime(0,0,0,$zi[1], 1+$j+7*$i-($day_week-1), $zi[2])).'\', \'title\', \'width=600, height=300, statusbar=yes, scroolbars=yes\')"><font color="ffffff" size="2">See Events,<br><em>please click here</em></font></a>';
			}else{
				$class = "tabel";
				$detail = '';
			}
		}
?>
	<td width="100" align="center" class="<?=$class;?>"><?=date("d", mktime(0,0,0,$zi[1], 1+7*$i+$j-($day_week-1), $zi[2])).$detail;?></td>
<?php	
	}
?>
</tr>
<?php
}
?>
          </table><p> </p></td>
  </tr>
</table>
    </TD>
    <TD WIDTH=14 bgcolor="#752802"></TD>
  </TR>
</TABLE>
</BODY>
</HTML>

 

 

Link to comment
Share on other sites

arn_php,

 

  Why not try a javascript solution... I use the very inexpensive, and very feature rich,  Tigra Calander Pro...

 

    Here is the web site: http://www.softcomplex.com/products/tigra_calendar_pro/

 

Scot L. Diddle, Richmond VA

Link to comment
Share on other sites

To simply shift the calendar from monday to sunday try this date call in your calendar output:

 

<td width="100" align="center" class="<?=$class;?>"><?=date("j", mktime(0,0,0,$zi[1], ($j+($i*7))-date("w",mktime(0,0,0,$zi[1],0,$zi[2])),$zi[2])).$detail;?></td>

 

this will undoubtedly mess up the querys associated above it ... but using the same alteration to the date in the querys should be a starting point but it's something im not going to attempt without the database itself.

 

As for the month it has to be altered in your include_once(_init.php) file which i obviously don't have access to.

Link to comment
Share on other sites

Wow, that works! about the month to month thingy...

I bet you already noticed this code: (line 38 into the page)

 

<form method="post" name="form1">

        <div align="center">

          <select name="month" onChange="javascript:document.forms['form1'].submit();">

            <? select_array($array_month, $_GET['month']);?>

          </select>

            Quick jump to month </div>

      </form>

 

So the $array_month comes from the _init.php file which contains only 12 months:

$array_month = array('01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');

 

I don't think I could just probably add the next month after December because surely we need to add the yearly thing on the beginning of my calendar page.. correct?

Start with line 3:

 

<?php

include_once('_init.php');

if(isset($_POST['month'])){

  $_GET['month'] = $_POST['month'];

}else{

  if($_GET['date'] != ''){

  $exp = explode('-', $_GET['date']);

  $_GET['month'] = $exp[1];

  }else{

  $_GET['month'] = date('m');

  }

}

$_GET['date'] = '01-'.$_GET['month'].'-'.date('Y');

?>

 

But how? Then maybe tweaking the form of the drop down box above... can you help me? Thanks man..

Link to comment
Share on other sites

Try This:

Replace

<?php
include_once('_init.php');
if(isset($_POST['month'])){
	$_GET['month'] = $_POST['month'];
}else{
	if($_GET['date'] != ''){
		$exp = explode('-', $_GET['date']);
		$_GET['month'] = $exp[1];
	}else{
		$_GET['month'] = date('m');
	}
}
$_GET['date'] = '01-'.$_GET['month'].'-'.date('Y');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

with this

<?php
//include_once('_init.php');
if(isset($_POST['month'])){
	$temp = explode(" ",$_POST['month']);
	$_GET['month'] = $temp[0];
	$_GET['year'] = $temp[1];
}else{
	if($_GET['date'] != ''){
		$exp = explode('-', $_GET['date']);
		$_GET['month'] = $exp[1];
	}else{
		$_GET['month'] = date('m');
	}
	$_GET['year'] = date('Y');
}
$_GET['date'] = '01-'.$_GET['month'].'-'.$_GET['year'];
?>

 

And This

 

          <select name="month" onChange="javascript:document.forms['form1'].submit();">
            <? select_array($array_month, $_GET['month']);?>
          </select>

with this:

          <select name="month" onChange="javascript:document.forms['form1'].submit();">
<?
for($newI = 0; $newI <= 3; $newI++){// $newJ <= 3 = 3 years ahead
for($newJ = 0; $newJ <= 12; $newJ++){ 
?>
			<option value="<?=date("n Y",mktime(0,0,0,Date("m")+$newJ,1,date("Y")+$newI));?>"><?=date("F Y",mktime(0,0,0,Date("m")+$newJ,1,date("Y")+$newI));?></option>
<?
}
}
?>
          </select>

 

Once again be real cautious with the links under the dates as I can't follow the updates effect on the sql querys

Link to comment
Share on other sites

It works! Only then the drop down box is back to show the current month (which is October 2008), not the month in which the page is showing.  So if you choose, just say March 2009, the page would show the calendar of March 2009 but then the drop down box would show the October 2008.  The other thing, when you tried to go back to the October 2008, then you can't do that unless you visit other page then come back to it again.

Link to comment
Share on other sites

          <select name="month" onChange="javascript:document.forms['form1'].submit();">
<?
for($newI = 0; $newI <= 3; $newI++){// $newJ <= 3 = 3 years ahead
for($newJ = 0; $newJ <= 12; $newJ++){ 
$dateValue = date("n Y",mktime(0,0,0,Date("m")+$newJ,1,date("Y")+$newI));
?>
			<option value="<?=$dateValue;?>" <? if($_POST['month']==$dateValue){echo "selected";}?>><?=date("F Y",mktime(0,0,0,Date("m")+$newJ,1,date("Y")+$newI));?></option>
<?
}
}
?>
          </select>

 

That should fix both problems

 

Cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.