Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

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 http://q8calendar.com/eng/yearCal.php?month=0&year=1960 and last thing is a week claendar and it's also need first day of week and current week no in the current month !!!?

thanx

 
 

 



0
AL3OMDAH
Asked:
AL3OMDAH
  • 7
  • 7
1 Solution
 
Richard QuadlingSenior Software DeverloperCommented:
Many scripts are around ...

http://www.easyphpcalendar.com/index.php
http://php-calendar.sourceforge.net/

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.
0
 
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 !!
0
 
Richard QuadlingSenior Software DeverloperCommented:
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.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
AL3OMDAHAuthor Commented:
php calendar algorithm this is what I need
regards
0
 
Richard QuadlingSenior Software DeverloperCommented:
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.
0
 
AL3OMDAHAuthor Commented:
<?php

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 http://diveintomark.org/archives/2002/07/03
    @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);

?>
0
 
Richard QuadlingSenior Software DeverloperCommented:
Right. Now we can get somewhere. What problems are you having?
0
 
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
to
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



0
 
Richard QuadlingSenior Software DeverloperCommented:
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.


0
 
AL3OMDAHAuthor Commented:
does the style will change the direction of the calendar ??
0
 
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
0
 
Richard QuadlingSenior Software DeverloperCommented:
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!
0
 
AL3OMDAHAuthor Commented:
But what If it's without CSS !! is there any solution by PHP code !!!
0
 
Richard QuadlingSenior Software DeverloperCommented:
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?
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now