WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: pcwacht on November 04, 2009, 11:27:52 AM

Title: Droplet -> Generate_Calender
Post by: pcwacht on November 04, 2009, 11:27:52 AM
This droplet generates a nifty month calender.
Code is taken from http://keithdevens.com/software/php_calendar#examples
It can do loads with calenders.

Used variables:
$year , $month , $days = array() , $day_name_length = 3 , $month_href = NULL , $first_day = 0 , $pn = array())

generate_calendar returns a string containing the output HTML. $year and $month are obvious. However, a neat side effect of using PHP's mktime function internally is that generate_calendar does "date rounding". So, basically, if you try to do month 13 of 2002, it'll round to January of 2003. See the documentation for mktime.

$days is an optional array that can contain information you want to specify for each day, including a location to link that day to, a stylesheet class for that day, and any content you want to appear for that day of the calendar. For example, an array passed for the days parameter might look something like this:

<?php
$days = array(
    2=>array('/weblog/archive/2004/Jan/02','linked-day'),
    3=>array('/weblog/archive/2004/Jan/03','linked-day'),
    8=>array('/weblog/archive/2004/Jan/08','linked-day'),
    22=>array('/weblog/archive/2004/Jan/22','linked-day'),
);
?> Each key corresponds to the day of the month, and each value is an array containing one to three elements. The first element is the location you want the day to link to, the second element is a space-separated list of classes (for stylesheets), and the third element is content that you want to appear in that day's cell, instead of just the day's number.

$day_name_length (optional, defaults to 3) is the number of characters to show for the day name ("Monday", "Tuesday", etc.). If you choose zero, the day headings don't display at all, and if you choose >3 it displays the whole name of the day.

$month_href is the location you'd like the month to be a link to (optional).

$first day is the number of the day you want your weeks to start on. Sunday is 0, Monday is 1, etc. Defaults to 0, hence Sunday.

$pn contains the links for the previous and next months to link to (hence, 'pn'). It should be in the following format: $pn = array('<'=>'prev-link','>'=>'next-link'); Note that it's not necessary that the key for next and previous be < (<) and > (>). They could also be things like ← (←) and → (→) or « («) and » (»). In addition, it's important that you define them in the order just shown (previous before next in the array). If you just want to have a previous link, just define the first. If you just want to have a next link, you must define the first with a NULL key and then define the second. If one of the "directions" is defined but the link field is blank, the key (such as < or >) will still be shown, but it won't be a link.

See http://keithdevens.com/software/php_calendar#examples for original script
I just made a droplet out of this one ;)

Code: [Select]
<?php 
/* Used variables:
$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(&#39;%A&#39;,$t)); #%A means full textual day name 

list($month$year$month_name$weekday) = explode(&#39;,&#39;,gmstrftime(&#39;%m,%Y,%B,%w&#39;,$first_of_month)); 
$weekday = ($weekday $first_day) % 7#adjust for $first_day 
$title   htmlentities(ucfirst($month_name)).&#39;&nbsp;&#39;.$year;  #note that some locales don&#39;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 = &#39;<span class="calendar-prev">&#39;.($pl ? &#39;<a href="&#39;.htmlspecialchars($pl).&#39;">&#39;.$p.&#39;</a>&#39; : $p).&#39;</span>&nbsp;&#39;; 
if($n$n = &#39;&nbsp;<span class="calendar-next">&#39;.($nl ? &#39;<a href="&#39;.htmlspecialchars($nl).&#39;">&#39;.$n.&#39;</a>&#39; : $n).&#39;</span>&#39;; 
$calendar = &#39;<table class="calendar">&#39;."\n". 
   
&#39;<caption class="calendar-month">&#39;.$p.($month_href ? &#39;<a href="&#39;.htmlspecialchars($month_href).&#39;">&#39;.$title.&#39;</a>&#39; : $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 .= &#39;<th abbr="&#39;.htmlentities($d).&#39;">&#39;.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).&#39;</th>&#39;; 
   
$calendar .= "</tr>\n<tr>"


if(
$weekday 0$calendar .= &#39;<td colspan="&#39;.$weekday.&#39;">&nbsp;</td>&#39;; #initial &#39;empty&#39; days 
for($day=1,$days_in_month=gmdate(&#39;t&#39;,$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 .= &#39;<td&#39;.($classes ? &#39; class="&#39;.htmlspecialchars($classes).&#39;">&#39; : &#39;>&#39;). 
         
($link ? &#39;<a href="&#39;.htmlspecialchars($link).&#39;">&#39;.$content.&#39;</a>&#39; : $content).&#39;</td>&#39;; 
   

   else 
$calendar .= "<td>$day</td>"

if(
$weekday != 7$calendar .= &#39;<td colspan="&#39;.(7-$weekday).&#39;">&nbsp;</td>&#39;; #remaining "empty" days 

return $calendar."</tr>\n</table>\n"


Have fun,
John

Title: Re: Droplet -> Generate_Calender
Post by: Stefek on November 04, 2009, 11:57:30 AM
Hello John.

This is a cool Droplet!

I have one Question to the 4th example "Link or provide content for certain days".
Could you please explain how to specify a link to, say, a single page for example.
Does it work somehow?

Regards,
Stefek
Title: Re: Droplet -> Generate_Calender
Post by: pcwacht on November 04, 2009, 12:00:22 PM
Add
Code: [Select]
<?php
if(!isset($year))  {$year  date(&#39;Y&#39;, time()); };
if(!isset($month)) {$month date(&#39;n&#39;, time()); };
right at the beginning to show current month by default


Have fun,
John
Title: Re: Droplet -> Generate_Calender
Post by: AR1306 on November 04, 2009, 12:01:14 PM
WOW - a cool Droplet, but ...

I have the same question just like Stefek - Is there any way to get this feature.

Thanks - you are one of the best  :wink:

Andreas
Title: Re: Droplet -> Generate_Calender
Post by: Stefek on November 04, 2009, 12:31:50 PM
Add
Code: [Select]
<?php
if(!isset($year))  {$year  date(&#39;Y&#39;, time()); };
if(!isset($month)) {$month date(&#39;n&#39;, time()); };
right at the beginning to show current month by default


Have fun,
John
Hello John,
I think you didn't get my question :-D

I meant in the fourth example there are links on dates.
Is there any way to specify links like this?

Regards,
Stefek
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 04, 2009, 12:35:47 PM
You just put them into a $days Array.

Example taken from http://keithdevens.com/software/php_calendar#examples
Code: [Select]
<?php
    $days 
= array(
        
2=>array(&#39;/weblog/archive/2004/Jan/02&#39;,&#39;linked-day&#39;),
        
3=>array(&#39;/weblog/archive/2004/Jan/03&#39;,&#39;linked-day&#39;),
        
8=>array(&#39;/weblog/archive/2004/Jan/08&#39;,&#39;linked-day&#39;),
        
22=>array(&#39;/weblog/archive/2004/Jan/22&#39;,&#39;linked-day&#39;),
        
26=>array(NULL,&#39;linked-day textual&#39;,&#39;twenty-six&#39;),
    
);
?>



The first param is the link url, the second one is a CSS class. There's also an optional third param to set a content (default is current day number).
Title: Re: Droplet -> Generate_Calender
Post by: pcwacht on November 04, 2009, 12:49:45 PM
Dunnoh how to get it IN the dropletcall, dunnoh how to add arrays in a parameter call like the droplet uses

To do it inside the droplet you should create some code to create the days array

Something like this, add it in the beginning of the droplet to test it:
Code: [Select]
<?php
global $wb$database;
if (
PAGE_ID>0) {
  
$days = array();
  
$query $database->query("SELECT modified_when, link,page_title FROM ".TABLE_PREFIX."pages order by modified_when desc limit 5");
  while(
$mod_page=$query->fetchRow()){
    
$mod_day date("j"$mod_page[&#39;modified_when&#39;]);
    
$weblink=$mod_page[&#39;link&#39;];
    
$webtitle $mod_page[&#39;title&#39;];
    
$days[$mod_day] = array($weblink,&#39;linked-day&#39;); 
  
}  
}    
asort($days);
This will give you a calender with links to pages on the day they are modified.

It would be easier if the droplet was a snippet instead. Then you could fill the $days array and call the function.


Thsi bit Add

Code:
<?php
if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };
right at the beginning to show current month by default

Was NO answer to your question ;)
But a better use of calender.

Have fun,
John
Title: Re: Droplet -> Generate_Calender
Post by: AR1306 on November 04, 2009, 12:56:05 PM
Is there any way to automatically generate links from the entries in the eventcal or news module ... that it would be in my opinion.  :wink:

But for the first it´s a cool Droplet ...
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 04, 2009, 03:02:58 PM
You will have to pull the entries from the database by yourself.
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 06, 2009, 12:37:44 PM
I hacked this droplet to avoid some "undefined" errors and to retrieve event data from "Event Calendar 1.8c". The day is linked to the URL given at the event entry. I am going to extend this for events not having an URL. Done. :-D

Code: [Select]
global $wb, $database;

$days = array();
$day_name_length = 3;
$month_href = NULL;
$first_day = 0;
$pn = array();

$oldlocale = setlocale(LC_TIME, NULL); #save current locale
setlocale(LC_TIME, 'de_DE');

if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month'";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
        }
        else {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'>".$row['day']."</span>" );
        }
    }
}

$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
  
// reset locale
setlocale(LC_TIME, $oldlocale);

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";
Title: Re: Droplet -> Generate_Calender
Post by: macsmet on November 06, 2009, 07:23:29 PM
@Webbird: this is nice!
Is it possible to make a link to: monthno=11&year=2009?
So to go to the month or even day?

Greetings,

MacSmet
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 07, 2009, 09:25:29 AM
I think this is already possible. Try [[HoweverYouCalledThis?year=2009&month=5]]

Day is not useful for a month calendar sheet, I think. :-D

Edit: Default is current month, of course!
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 07, 2009, 09:29:00 AM
Hint: The droplet code above extracts events from any page the event calendar module is included. To give a certain page/section, try to change the SQL to this:

Code: [Select]
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE section_id = '###' AND YEAR(date) = '$year' AND MONTH(date) = '$month'";

Replace ### with the section_id you wish to use.
Title: Re: Droplet -> Generate_Calender
Post by: tiesy on November 12, 2009, 06:35:06 PM
Hey WebBird,

your Generate_Calender-mod for the Event Calendar is very welcome and useful. Many thanks for that. It shows the actual Month and the right days with events are marked correct with a red square.
The only thing: The days with are not linked and I don´t know why. I tried to understand the code, but I´m not a programmer, so I didn´t find, how to solve this. For me, it would be sufficient, when it links to the site, where the Event Calendar is.

Second thing: I don´t know, where the "nnnnnn" comes form (see screenshot). I think, there should be shown prev and next-links. Is that right?

 

[gelöscht durch Administrator]
Title: Re: Droplet -> Generate_Calender
Post by: pcwacht on November 12, 2009, 07:30:56 PM
The n's

Not sure but I think:
Make sure IN your droplet the \n exists and not just a n
Look at the code above to see where they are.

Have fun
John
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 13, 2009, 10:39:46 AM
The only thing: The days with are not linked and I don´t know why.

They are linked only if the Event entry has a link. You may change this code:

Code: [Select]
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
        }
        else {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'>".$row['day']."</span>" );
        }
    }
}

In the else, the day is highligted only, but not linked, as there is no link in the Event entry. So, just add a <a href> that links to your events page. Example:

Code: [Select]
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
        }
        else {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='http://...../'>".$row['day']."</a></span>" );
        }
    }
}

Edit: As of the n's, I think pcwacht is right.
Title: Re: Droplet -> Generate_Calender
Post by: tiesy on November 16, 2009, 08:48:28 PM
The link-problem is solved, thank you very much, but I can´t handle the "n"-problem until yet. I´ve only copied the code to a new droplet without any changes. The prevs and next-links are missing and instead there are seven "n"s above the table-tag and one after the table.

I think, there must be a problem generating the output for the previous and next-links, because the span-tag are missing in the HTML-output. Could it be a little syntax-error between line 45 and 50 in the code?

My HTML-output starts like this:
<table class="calendar">n<caption class="calendar-month">November&nbsp;2009</caption>n<tr><th abbr="Sonntag">Son</th>

And these are the last tags:
<td>30</td><td colspan="5">&nbsp;</td></tr>n</table>n


I think, this droplet is very welcome by many users, because you can find a lot of WB-Sites with "Event Calendar 1.8c" in use.




Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 17, 2009, 11:05:48 AM
I have not provided any prev/next links in my code. :roll:
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 17, 2009, 11:09:24 AM
Look at the very last line of the droplet code. It should look like this:

return $calendar."</tr>\n</table>\n";

Note the Backslash before the n's. Make sure that you really really have Backslashes there!
Title: Re: Droplet -> Generate_Calender
Post by: tiesy on November 17, 2009, 05:06:52 PM
I do have backslashes, believe me and of course there are prevs and next-links.

The last "n" after the calendar-table disappears, if I delete the last "\n" in the last line of your code:

return $calendar."</tr>\n</table>\n";

changed to:

return $calendar."</tr>\n</table>";

I´m shure, there must be a mistake in the code. Some code-parts do not execute.

OK, I´ve to learn php first. If I´ve found the solution in about two years, I´ll post it here :wink:


My first dirty "solution": Delete all "\n" in the code. It works!
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 17, 2009, 05:51:41 PM
I did not provide prev/next, so it's not my code you copied. :roll:
Title: Re: Droplet -> Generate_Calender
Post by: tiesy on November 17, 2009, 06:02:32 PM
Ah, and what about these lines in your reply #9 ?

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable

..and so on
Title: Re: Droplet -> Generate_Calender
Post by: Stefek on November 17, 2009, 06:09:42 PM
Hello Tiesy.
Prev-Next Links won't work with this droplet.

It's not applicable, so WebBird didn't use them..

Regards,
Stefek
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 17, 2009, 06:10:01 PM
They only work if the $pn array is filled. In my code, it isn't.
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 17, 2009, 06:21:47 PM
Here's the code as a download. Open with your favourite text editor (not Word...) and paste as a droplet. I added some comments that may help.

Code: [Select]

global $wb, $database;

// --- config options; you may change these ---
// day names length; values > 3 = full name
$day_name_length = 3;
// first day of week; 0 = Sunday, 1 = Monday
$first_day       = 0;
// set locale to the value you need
// set to NULL to use the OS setting -> $locale = NULL;
$locale          = 'de_DE';

// --- do not change these! ---
$month_href      = NULL;
$pn              = array(); // array for prev/next links; they don't work
                            // in this droplet, so don't add anything!
$days            = array();

if ( isset( $locale ) ) {
    // store old locale
    $oldlocale = setlocale(LC_TIME, NULL); #save current locale
    setlocale( LC_TIME, $locale );
}

// year and month defaults
if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month'";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
        }
        else {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'>".$row['day']."</span>" );
        }
    }
}

$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

if ( isset( $oldlocale ) ) {
    // reset locale
    setlocale(LC_TIME, $oldlocale);
}

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";


[gelöscht durch Administrator]
Title: Re: Droplet -> Generate_Calender
Post by: tiesy on November 17, 2009, 07:01:38 PM
OK, I found out one thing (and yes, with your code not opened with Word, WebBird! ):

on a WB2.7-installation (online) the "n"s are shown.
on a WB2.8-installation (xampp) there are no "n"s. Everything is right there 

Where is the problem, deleting all "\n" in the calendar_droplet.ph p? Without them, it works in 2.7 and 2.8

Title: Re: Droplet -> Generate_Calender
Post by: pcwacht on November 18, 2009, 08:25:50 AM
The \n only generates a linebreak in your html source, not in your output on your screen.
It is only there for source reading purposes

It is safe to delete them all.

Have fun,
John
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 18, 2009, 10:47:57 AM
I tried with 2.7 and can confirm that. Seems to be a bug in the Droplets module.

Edit: Found this in line 59 of the droplets.php:

Code: [Select]
$content = stripslashes($fetch_content['code']);

Droplets 1.0.1 (WB 2.8 ) does this:

Code: [Select]
$codedata = ($fetch_content['code']);

So, the problem is caused by the droplets module. There are two ways to get around it:

* Remove all \-thingies from droplet codes (ALL droplet codes!)
* Correct the Droplets module (remove "stripslashes" in line 59)

But, I think the best way is: Upgrade to 2.8!
Title: Re: Droplet -> Generate_Calender
Post by: tiesy on November 24, 2009, 04:27:55 PM
Ok, I think the mysterious "\n"-problem is solved so far. I have a little enhancement that shows a tooltip with the short decscription of the calendar entries. That was easy to do, only add the "title"-attribute to "a href":

Change line:
Code: [Select]
$days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
To:
Code: [Select]
$days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; border: 1px solid #f00;'><a href='".$row['url']."' title='".$row['descr']."'  target='_blank'>".$row['day']."</a></span>" );


What would make it to a really very nice droplet:
- make previous and next-Links work
- automatically link (not hardcoded) to the page where the Event Calendar-Module is placed.

Title: Re: Droplet -> Generate_Calender
Post by: WebBird on November 24, 2009, 06:21:56 PM
- make previous and next-Links work

Sorry, but this is not possible with Droplets.

Edit: You may include the droplet more than once to have the previous and next month shown, too.

- automatically link (not hardcoded) to the page where the Event Calendar-Module is placed.

An easy way is to set a variable in the droplet.

Title: Re: Droplet -> Generate_Calender
Post by: taurus66 on January 17, 2010, 07:18:30 PM
Hi Webbird,

l like this Droplet a lot!

Little Problem: The Droplet doesn't switch to German, it stays in english.
Something I could have done wrong?
Eventcalendar -as all parts of my site www.sft98.de runs in german.

Thanks,

Bernd
Title: Re: Droplet -> Generate_Calender
Post by: pcwacht on January 17, 2010, 07:53:43 PM
https://forum.WebsiteBaker.org/index.php/topic,15895.msg103993.html#msg103993

John
Title: Re: Droplet -> Generate_Calender
Post by: taurus66 on January 17, 2010, 08:20:14 PM
https://forum.WebsiteBaker.org/index.php/topic,15895.msg103993.html#msg103993

Sorry John, I don't understand what you are trying to say.

Title: Re: Droplet -> Generate_Calender
Post by: pcwacht on January 17, 2010, 08:37:41 PM
At that post there is an explanation how to set this droplet to work with German-time  output

John
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on January 18, 2010, 10:21:03 AM
Hi Webbird,

l like this Droplet a lot!

Thank you, but please note that the droplet was provided by "pcwacht". I only added the "Events" binding. ;)
Title: Re: Droplet -> Generate_Calender
Post by: taurus66 on January 18, 2010, 07:17:20 PM
Hi Webbird,

l like this Droplet a lot!

Thank you, but please note that the droplet was provided by "pcwacht". I only added the "Events" binding. ;)

Oooops, sorry Webbird, sorry pcwacht.  :roll:

Quote
At that post there is an explanation how to set this droplet to work with German-time  output

Ahhh, ok, unterstand. I have these lines in the Droplet. Shouldn't that work?

$locale          = 'de_DE';

if ( isset( $locale ) ) {
    // store old locale
    $oldlocale = setlocale(LC_TIME, NULL); #save current locale
    setlocale( LC_TIME, $locale );
}

Title: Re: Droplet -> Generate_Calender
Post by: pcwacht on January 18, 2010, 08:16:22 PM
Yups it should
What it does is it tells php date and time output should be in German format

Look here for more info and other locale entries

http://nl2.php.net/manual/en/function.setlocale.php

Especially this might be interesting:
http://nl2.php.net/manual/en/function.setlocale.php#77795
http://nl2.php.net/manual/en/function.setlocale.php#62748

And here some more info :
http://www.freeopenbook.com/php5manual/function.setlocale.html


Good luck,
John
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on January 19, 2010, 11:32:49 AM
You can try to check the correct locale setting adding this code AFTER the code you quoted above:

Code: [Select]
echo "Current locale setting: ", setlocale(LC_TIME, NULL), "<br />";
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on January 28, 2010, 05:37:44 PM
I found that the locale is resetted BEFORE the month name is generated. So do the following:

FIND (~line 68)
Code: [Select]
// reset locale
setlocale(LC_TIME, $oldlocale);

CUT and INSERT AFTER:

Code: [Select]
$title   = htmlentities(ucfirst($month_name)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names

(After cutting, about 4 lines later.)

Complete new code I am working with:

Code: [Select]
global $wb, $database;

$days = array();
$day_name_length = 2;
$month_href = NULL;
$where = NULL;
$first_day = 1;
$pn = array();
$events = 0;

$oldlocale = setlocale(LC_TIME, NULL); #save current locale
setlocale(LC_TIME, 'de_DE');

if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };
if ( isset( $section ) ) { $where = "AND section_id='$section'"; }

$today = date('j',time());

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month' $where";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        $text = $row['day'];
        if ( ! empty( $row['descr'] ) ) {
            $text .= ' <span>'.$row['descr'].'</span>';
        }
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ]
                = array(
                      NULL,
                      NULL,
                      "<span style='font-weight: bold; border: 1px solid #f00;'>"
                    . "<a class='tooltip' href='".$row['url']."' target='_blank'>"
                    . $text
                    . "</a></span>"
                  );
        }
        else {
            $days[ $row['day'] ]
                = array(
                      NULL,
                      NULL,
                      "<span style='font-weight: bold; border: 1px solid #f00;'>"
                    . "<a class='tooltip' href='#'>"
                    . $text
                    . "</a></span>"
                  );
        }
        $events++;
    }
}

if ( ! isset( $days[$today] ) ) {
    $days[$today] = array( NULL, 'calendar-today' );
}

$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

// reset locale
setlocale(LC_TIME, $oldlocale);

#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
$calendar .= "</tr>\n</table><br />\n";

if ( $events == 0 ) {
    $calendar .= 'Keine Termine f&uuml;r diesen Monat.<br />';
}
else {
    $calendar .= $events.' '.'Termin'
              .  ( $events > 1 ? 'e' : '' )
              .  ' f&uuml;r diesen Monat.<br />';
}

return $calendar;

Title: Re: Droplet -> Generate_Calender
Post by: crnogorac081 on January 28, 2010, 09:08:02 PM
Is it possible to have a droplet inside droplet, for example something like:

Code: [Select]
$pn              = array('&lt;'=>'[[evcal?year=$year&month=$month-1]]','&gt;'=>'[[evcal?year=$year&month=$month+1]]');


And somehow like this to generate prev and next links :)

BTW droplet is great !!! It would be nice to have something like this for news and topics modules as well..
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on January 29, 2010, 10:50:33 AM
Stefek made a topic version of this droplet. Try the Forum Search.
Title: Re: Droplet -> Generate_Calender
Post by: taurus66 on February 05, 2010, 03:11:28 PM
You can try to check the correct locale setting adding this code AFTER the code you quoted above:

Code: [Select]
echo "Current locale setting: ", setlocale(LC_TIME, NULL), "<br />";

Hi Webbird,

System tells me "Current locale setting: C"

Gruß,

Bernd
Title: Re: Droplet -> Generate_Calender
Post by: taurus66 on February 05, 2010, 03:13:31 PM
I found that the locale is resetted BEFORE the month name is generated. So do the following:

FIND (~line 68)
Code: [Select]
// reset locale
setlocale(LC_TIME, $oldlocale);

CUT and INSERT AFTER:

Code: [Select]
$title   = htmlentities(ucfirst($month_name)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names

(After cutting, about 4 lines later.)


No, this doesn't work, too  :-(
Title: Re: Droplet -> Generate_Calender
Post by: WebBird on February 05, 2010, 03:40:59 PM
Are you sure you did it right?
Title: Re: Droplet -> Generate_Calender
Post by: taurus66 on February 05, 2010, 05:09:39 PM
Are you sure you did it right?

I'm only sure, that 'm not sure  :-D
Here's the code I took from you and changed as you told ... I hope I did

Code: [Select]
global $wb, $database;

$days = array();
$day_name_length = 2;
$month_href = NULL;
$where = NULL;
$first_day = 1;
$pn = array();
$events = 0;

$oldlocale = setlocale(LC_TIME, NULL); #save current locale
setlocale(LC_TIME, 'de_DE');

if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };
if ( isset( $section ) ) { $where = "AND section_id='$section'"; }

$today = date('j',time());

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month' $where";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        $text = $row['day'];
        if ( ! empty( $row['descr'] ) ) {
            $text .= ' <span>'.$row['descr'].'</span>';
        }
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ] = array(NULL,NULL,"<span style='font-weight: bold; border: 1px solid #f00;'>"."<a class='tooltip' href='http://www.sft98.de/pages/kalender.php'>".$row['day']."</a></span>" );
        }
        else {
            $days[ $row['day'] ] = array(NULL,NULL,"<span style='font-weight: bold; border: 1px solid #f00;'>"."<a class='tooltip' href='http://www.sft98.de/pages/kalender.php'>".$row['day']."</a></span>");
        }
        $events++;
    }
}

if ( ! isset( $days[$today] ) ) {
    $days[$today] = array( NULL, 'calendar-today' );
}

$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
// reset locale
setlocale(LC_TIME, $oldlocale);

#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
$calendar .= "</tr>\n</table><br />\n";

if ( $events == 0 ) {
    $calendar .= 'Keine Termine f&uuml;r diesen Monat.<br /><br />';
}
else {
    $calendar .= $events.' '.'Termin'
              .  ( $events > 1 ? 'e' : '' )
              .  ' f&uuml;r diesen Monat.<br /><br />';
}

return $calendar;

Title: Re: Droplet -> Generate_Calender
Post by: WebBird on February 06, 2010, 06:25:17 PM
Hm, looks okay. And works for me. :? Don't know what's wrong. Maybe your webserver doesn't implement that locale. :? Just don't know.
Title: Re: Droplet -> Generate_Calender
Post by: taurus66 on February 06, 2010, 06:29:21 PM
Hm, looks okay. And works for me. :? Don't know what's wrong. Maybe your webserver doesn't implement that locale. :? Just don't know.

Ok, thanks a million anyway.
Title: Re: Droplet -> Generate_Calender - modification Look Calendar
Post by: spoonxaver on June 05, 2010, 10:20:57 PM
Here is my modifikation this droplet:
This modification writte events for actual month inline.
Code: [Select]
global $wb, $database;

$days = array();
$day_name_length = 8;
$month_href = NULL;
$where = NULL;
$first_day = 1;
$pn = array();
$events = 0;

$oldlocale = setlocale(LC_TIME, NULL); #save current locale
setlocale(LC_TIME, 'en_EN');

if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };
if ( isset( $section ) ) { $where = "AND section_id='$section'"; }

$today = date('j',time());

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, date AS mesic, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month' $where";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        $text = $row['mesic'];
$textMonth = $row['mesic'];
        if ( ! empty( $row['descr'] ) ) {
            $text .= ' <span>'.$row['descr'].'</span>';
        }
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ]
                = array(
                      NULL,
                      NULL,
                      "<span class='menuCalendar'>"
                    . "<a href='".$row['url']."' title='".$row['descr']."'  target='_blank'>".$row['textMonth']."</a></span>"
                  );
        }
        else {
            $days[ $row['day'] ]
                = array(
                      NULL,
                      NULL,
                     "<span class='menuCalendar'>"
                    . "<a class='tooltip' href='#'>"
                    . $text
                   // . $textMonth
                    . "</a></span>"
                  );
        }
        $events++;
    }
}

if ( ! isset( $days[$today] ) ) {
    $days[$today] = array( NULL, 'calendar-today' );
}

$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

// reset locale
setlocale(LC_TIME, $oldlocale);

#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 class='calendar-month'>";
}
*/
/*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 .= '<tr><td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
         ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td></tr>';
   }

}
#remaining "empty" days
//if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>';
$calendar .= "</tr>\n</table><br />\n";

if ( $events == 0 ) {
    $calendar .= 'Nothing for this Month.<br />';
}
else {
    $calendar .= $events.' '.'Termins'
              .  ( $events > 1 ? 'e' : '' )
              .  ' for this Month.<br />';
}

return $calendar;
Title: Re: Droplet -> Generate_Calender
Post by: BlackBird on June 05, 2010, 10:30:39 PM
Please explain your modification. What did you do? Why?
Title: Re: Droplet -> Generate_Calender
Post by: capt_funk on April 10, 2012, 03:40:25 PM
I modified the droplet some to display the upcoming events (next 7 days) beneath the calendar. This droplet shows the weekday and the title of the event from the Envent Calendar.
Code: [Select]
global $wb, $database;

$days = array();
$day_name_length = 2;
$month_href = NULL;
$first_day = 1;
$pn = array();

$oldlocale = setlocale(LC_TIME, NULL); #save current locale
setlocale(LC_TIME, 'de_DE');

if(!isset($year))  {$year  = date('Y', time()); };
if(!isset($month)) {$month = date('n', time()); };

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month'";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; color: #006;'><a href='".$row['url']."' target='_blank'>".$row['day']."</a></span>" );
        }
        else {
            $days[ $row['day'] ] = array( NULL, NULL, "<span style='font-weight: bold; color: #006;'>".$row['day']."</span>" );
        }
    }
}

$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
 
// reset locale
setlocale(LC_TIME, $oldlocale);

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 width=140 class="calendar">'."\n".
   '<caption class="calendar-month" style="font-weight: bold;">'.$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 style="font-size: 10px; font-weight: normal;" 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

$month_events=array();
$today=date('j')."<br>\n";
$weekday=date('N');
$days_de=array("Mo","Di","Mi","Do","Fr","Sa","So");
$sql="SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month'";
$result=$database->query($sql);
while($row=$result->fetchrow()){
$temp=date('N',mktime(0,0,0,$month,$row['day'],$year));
$weekday=$days_de[$temp-1];
$month_events[$row['day']].=substr("<tr><td>$weekday</td><td><span style='font-weight: bold;'>&nbsp;".$row['descr'],0,75)."</span></td></tr>\n";
}
for($i=0;$i<7;$i++){     //get events for the next 7 days
$week_events.=$month_events[$today+$i];
}

return $calendar."</tr>\n</table>\n"."\n<table width=140 cellpadding=0>$week_events\n</table>";

To modify the amout of days ahead displayed under the calendar, modify the for-loop at the end (change 7 to whatever you need). An example of the droplet in action can be viewed here: http://scvillip.de/ (http://scvillip.de/)
Title: Re: Droplet -> Generate_Calender
Post by: dbs on October 18, 2012, 05:44:52 PM
For problems with "setlocal", check with this line the correctly local-expression (e.g. after the setlocal-line):
Code: [Select]
echo system('locale -a');So you can see how the local must be written.

In my case "de_DE" was wrong, it must be "de_DE.utf8"
Code: [Select]
setlocale(LC_TIME, 'de_DE.utf8');
Hope it helps ...
Title: Re: Droplet -> Generate_Calender
Post by: Tomno399 on February 14, 2015, 10:22:04 AM
Hello

I use the event calendar and it's mini calendar on wb2.8.3 SP1 with php 5.6 and it runs perfect. Thank you pcwacht and WebBird!

But I have a wish: Can someone tell me the code and the line where it is to insert for highlightning the background of the actual day?

Thank you
Thomas
Title: Re: Droplet -> Generate_Calender
Post by: Tomno399 on February 16, 2015, 09:33:43 AM
I got it in another thread!

Thank you Marmot!!