PHP Class Calendar Help !!

I need a simple class calendar it print claendar in html table but I can set the first day  week and first month 2 to to displayed  and another function that take the yaer no to print a whole calendar for that year for example '1930' !! like this web site and last thing is a week claendar and it's also need first day of week and current week no in the current month !!!?




Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard QuadlingSenior Software DeveloperCommented:
Many scripts are around ...

are just 2.

You COULD ask the developers of the q8 one (it looks quite nice) if they are prepared to release the code. A LOT of developers are REALLY pleased to provide their code.
AL3OMDAHAuthor Commented:
Thanx alot but the q8 one would never give any code I have ask them but they don't it's ok thanx anyway but I want to know how the caledar works just a simple example !!
Richard QuadlingSenior Software DeveloperCommented:
What do you need to know? This sort of project is not a few quick lines of code. It is a MAJOR amount of work.

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

AL3OMDAHAuthor Commented:
php calendar algorithm this is what I need
Richard QuadlingSenior Software DeveloperCommented:
As I said, this is not a quick bit of script. We can help you develop one if you have specific questions, but "how do I copy this application" is not the sort of thing we can easily do.
AL3OMDAHAuthor Commented:

function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
    $first_of_month = gmmktime(0,0,0,$month,1,$year);
    #remember that mktime will automatically correct if invalid dates are entered
    # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
    # this provides a built in "rounding" feature to generate_calendar()

    $day_names = array(); #generate all the day names according to the current locale
    for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
        $day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

    list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
    $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
    $title   = htmlentities(ucfirst($month_name)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names

    #Begin calendar. Uses a real <caption>. See
    @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
    if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
    if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
    $calendar = '<table class="calendar">'."\n".
        '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

    if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
        #if day_name_length is >3, the full name of the day will be printed
        foreach($day_names as $d)
            $calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
        $calendar .= "</tr>\n<tr>";

    if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #initial 'empty' days
    for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
        if($weekday == 7){
            $weekday   = 0; #start a new week
            $calendar .= "</tr>\n<tr>";
        if(isset($days[$day]) and is_array($days[$day])){
            @list($link, $classes, $content) = $days[$day];
            if(is_null($content))  $content  = $day;
            $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
                ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        else $calendar .= "<td>$day</td>";
    if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days

    return $calendar."</tr>\n</table>\n";
print generate_calendar(2006, 4, $days = array(),3, NULL,6, 2);

Richard QuadlingSenior Software DeveloperCommented:
Right. Now we can get somewhere. What problems are you having?
AL3OMDAHAuthor Commented:
1 - First thing I want the range for the year from 1/1/1900 not from 1/1/1970
2 - I want to add parameter $direction='RTL' or 'LTR' so that I can load the days in the calendar from
Sat      Sun      Mon      Tue      Wed      Thu      Fri
Fri      Thu      Wed      Tue      Mon     Sun     Sat
and vice versa

Notes : I'm using WinXP Pro SP2  and  Apache/2.0.55 (Win32) mod_ssl/2.0.55 OpenSSL/0.9.8a PHP/5.1.2

Richard QuadlingSenior Software DeveloperCommented:
1 - There is no limit to 1970.

I'm on Win XP SP2 with PHP V5.1.3-dev. I use Sambar Server, so the mods don't apply.

Output of script with ...

print generate_calendar(1967, 10, $days = array(),3, NULL,6);

October 1967 Sat      Sun      Mon      Tue      Wed      Thu      Fri
       1      2      3      4      5      6
7      8      9      10      11      12      13
14      15      16      17      18      19      20
21      22      23      24      25      26      27
28      29      30      31       

Which is correct. I was born on a Sunday!

2. Good one. Have you tried using CSS for that?

Adding ...

<style type="text/css">.calendar { direction:rtl;}</style>

and outputting the same page show them in reverse.

As this is ONLY a styling, copy/paste is NOT affected by the change.

    $calendar = '<style type="text/css">.calendar { direction:rtl;}</style><table class="calendar">'."\n".
        '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

Try it in Firefox and turn the styling on/off to see this in action.

AL3OMDAHAuthor Commented:
does the style will change the direction of the calendar ??
AL3OMDAHAuthor Commented:
this is what the above code generate

Sat      Sun      Mon      Tue      Wed      Thu      Fri
1      2      3      4      5      6      7
8      9      10      11      12      13      14
15      16      17      18      19      20      21
22      23      24      25      26      27      28
29      30      31                         

what if I want to display ir like this ?
Fri      Thu      Wed      Tue      Mon      Sun      Sat
7      6      5      4      3      2      1
14      13      12      11      10      9      8
21      20      19      18      17      16      15
28      27      26      25      24      23      22
                        31      30      29
Richard QuadlingSenior Software DeveloperCommented:
You said "display". The CSS I supplied works in Firefox and IE.

If you cut and past the output though it WILL NOT BE REVERSED AS THE CSS IS STYLING only.

As far as the user is concerned it is reversed!
AL3OMDAHAuthor Commented:
But what If it's without CSS !! is there any solution by PHP code !!!
Richard QuadlingSenior Software DeveloperCommented:
Yes, but it would involve a bit more effort.

Unfortunately, the current script is very orientated to doing it the european way.

Currently, the script generates the output inline and directly.

My approach would be to build an array of weeks each week being an array of days, including the blank days.

Then I would rsort the days prior to rendering them.

You could do all of this inline but you would need to do 2 lots of code. Even then, you could create completely unreadable code and do lots of ternary tests ( rtl ? yes : no - sort of thing).

Another option is to generate the output left to right as you have already done, and then use an output buffer to grab the data, take it apart and reverse it.

Is there a specific reason for having the output rtl rather than using the CSS approach?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.