Using different colors according to dates

Using different colors according to dates

Postby peter » Mon May 26, 2008 9:53 am

Hello,

I was looking for booking calendar and I stumbled on your script.
Is it possible to display in this calendar different shades of blue for different levels of prices (free days have blue color)? I'd like to make the color of free days to be different depending on the month name or number of the day like:
March - 15th of April (blue);
16th of April - June (light blue);
July - 14 of September (blue);
15 of September - November (light blue);
December - February (dark blue).

Can you tell me how to do it?

Peter.

edit - moved to own topic by admin
peter
 
Posts: 7
Joined: Sat May 24, 2008 4:04 pm

Re: Using different colors according to dates

Postby chris » Mon May 26, 2008 12:09 pm

Hello Peter, welcome to the forum.

I have moved your post from it's original position as you had added it to an unrelated thread.

As you will probably have realised, the current version of the calendar script uses a set of images of differing colors for each of the possible 31 days in each month.
So, to be able to add different colors (or shades) according to the period of the year, the first thing that you need to do is create the new numbers with the coloured backgorund that you will need.
Secondly, you will need to create an array, variables or a database table to hold and define your periods and the images that you want to show for that period.
Finally, you would need to modify the draw_cal() function so that it checks the dates against your array or db table and shows the image colors accordingly.


Personally I would suggest using a new database table to hold this information as the exact dates would probably change from year to year so this method would be more flexible.
In your new image file naming, use an easy to identify prefix such as "low", "middle" or "high" (thinking about typical booking season periods) so that it will be easy in the code to select the correct images.
eg
Code: Select all
if(($the_date>=04/16/2008) && (the_date<=06/30/2008)) $image_prefix="middle_";
elseif(($the_date>=07/01/2008) && (the_date<=09/14/2008)) $image_prefix="high_";
etc.

Note - this is just a "visual" example, you will have to convert the dates to time strings to actually be able to check them.

Clearly this is just an outline of the steps needed to be taken, if you need more detailed help I will try to make more concise and working code for you.

Hopefully I will (someday) soon be releasing a new version of the calendar which will, amongst many other changes, be using far less images to make up the calendar. However, this is not ready yet so you will have to stick to creating all the images :(

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Using different colors according to dates

Postby peter » Mon May 26, 2008 1:31 pm

For a while I thought I didn't post my question but after a while I found it here :)
I am making new numbers for this modification now. I will need your guide with code modifications to make it work and for new table for the database to hold indicated dates.
I am not a proffessional php programmer but I would follow your instructions if you tell me what to do. I will use this prefixes you proposed.

Peter.
peter
 
Posts: 7
Joined: Sat May 24, 2008 4:04 pm

Re: Using different colors according to dates

Postby chris » Mon May 26, 2008 2:53 pm

OK Peter, let's see if we can get this to work.

Do you have access to phpmyadmin for your database?
If so, we can create the table for the "seasons" directly in the database using that.
Open up a new sql query and paste the following code:
Code: Select all
CREATE TABLE `booking_seasons` (
  `id` int(10) NOT NULL auto_increment,
  `it_item` int(10) NOT NULL,
  `date_from` date NOT NULL,
  `date_to` date NOT NULL,
  `prefix` char(20) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `it_item` (`it_item`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Note - I have included the id_item field in this table but I we are not actually going to use it as I am going to "assume" that you either only have one item or that all your "Items" will use the same season images (correct me if I am assuming too much)
Now we will populate this table with some initial data according to your original post:
Code: Select all
INSERT INTO `booking_seasons` (`id`, `it_item`, `date_from`, `date_to`, `prefix`) VALUES (1, 0, '2008-03-15', '2008-04-30', 'high'),
(2, 0, '2008-05-01', '2008-06-30', 'middle'),
(3, 0, '2008-07-01', '2008-09-15', 'high'),
(4, 0, '2008-05-16', '1008-11-30', 'middle'),
(5, 0, '2008-12-01', '2009-02-28', 'low'),

Note 1 - you might need to adjust the "high", "middle" and "low" tags as you need, I have used them as examples. This can easily be done by editing this query before you execute it, or once the data has been added to the tables.
Note 2 - As I mentioned in my original answer to your post, the idea of using a db table is that you can adjust the "seasons" from year to year. However this has the downside of that you will need to keep on top of this table and add your season blocks for several years in advance.
If you would rather just have "set" seasons, let me know and I will adjust the code.

Finally, we have to modify the draw_calendar() function to check to see in which period each date lies.
There may well be a better way of doing this but, as I want to give you a quick solution, I have opted to do it by checking each date indvidually as it is called (once I have posted this I will think about it a bit more to see if there is a more "economic" way to do it)
So, in "includes/functions.inc.php" add this new function:
Code: Select all
function date_prefix($this_date){
   $sql="SELECT prefix FROM booking_seasons WHERE DATE('".$this_date."') BETWEEN date_from AND date_to";
   $res=mysql_query($sql) or die("Error checking prefixes");
   $row=mysql_fetch_assoc($res);
   if($row["prefix"]!="") return $row["prefix"]."_";
   else               return "";
}

That checks each date that is passed to get it's prefix
And now add a call to this function in the main "draw_cal()" function ONLY on the dates that area available:
Find these lines (more or less ln 86):
Code: Select all
else{
  $day_image='cal_off_'.$day_counter.'.png';
}

and replace with these:
Code: Select all
else{
  //check date season for prefix
  $prefix=date_prefix($this_date);
  $day_image=$prefix.'cal_off_'.$day_counter.'.png';
}


Well, if you have been able to complete all these steps, you "should" have it working.
Let me know how it goes and if we need to fine tune anything or if it all goes terribly wrong ;)

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Using different colors according to dates

Postby chris » Mon May 26, 2008 3:00 pm

am making new numbers for this modification now.

I forgot to mention, I have the original numbers in a fireworks file if you want to use it (probably too late by now)
Let me know and I will dig out the link to the zip file (it is here in one of the threads somewhere)

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Using different colors according to dates

Postby peter » Tue May 27, 2008 4:32 pm

Hi,

After making the changes in calendar script I got message "Error checking prefixes".
All oryginal "call_off" images are now named "low_cal_off", "middle_cal_off" and "high_cal_off".
The message sais it's wrong :?
So what syntax should I use in naming images to make it right?

Peter.
peter
 
Posts: 7
Joined: Sat May 24, 2008 4:04 pm

Re: Using different colors according to dates

Postby chris » Tue May 27, 2008 6:21 pm

Hi
That message error is coming from the db check for the seasons in the new function that we have added:
Code: Select all
function date_prefix($this_date){
   $sql="SELECT prefix FROM booking_seasons WHERE DATE('".$this_date."') BETWEEN date_from AND date_to";
   $res=mysql_query($sql) or die("Error checking prefixes");
   $row=mysql_fetch_assoc($res);
   if($row["prefix"]!="") return $row["prefix"]."_";
   else               return "";
}

Have you added all the date blocks for the seasons?
Can you alter that function to return a more useful error.
Change this:
$res=mysql_query($sql) or die("Error checking prefixes");
to this:
$res=mysql_query($sql) or die("Error checking prefixes.<br><br>".$sql.""<br><br>".mysql_error());

When you have done that, let me know what the mew message is.

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Using different colors according to dates

Postby chris » Tue May 27, 2008 7:42 pm

Glad to hear it and to be of help :)
It would be great to see an url of this when you have it working if that is possible.

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Using different colors according to dates

Postby peter » Tue May 27, 2008 7:54 pm

One more question.

Is it possible to add this feature of item selection to this modification?

Peter.
peter
 
Posts: 7
Joined: Sat May 24, 2008 4:04 pm

Re: Using different colors according to dates

Postby chris » Tue May 27, 2008 8:01 pm

Re you referring to the select box list of items?

There should be no problem adding that (I thought that it was in the zipped file, I get confused with so many modifiactions :( )

This select list is actually nothing special, just a list of the items available and a javascript onchange call to reload the page, something like this:
Code: Select all
<form method="post" action="">
<select name="id_item" onchange="this.form.submit();">
<option value="1">item 1</option>
<option value="2">item 2</option>
<option value="3">item 3</option>
</select>
</form>

Is that what you are referring to?

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Next

Return to General

Who is online

Users browsing this forum: No registered users and 0 guests

cron