### Eclipse Workspace Patch 1.0
#P contrib
Index: plugins/blocks/birthday/config_global.html
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/birthday/config_global.html,v
retrieving revision 1.3
diff -u -r1.3 config_global.html
--- plugins/blocks/birthday/config_global.html	31 Aug 2007 03:42:28 -0000	1.3
+++ plugins/blocks/birthday/config_global.html	16 Apr 2008 22:32:30 -0000
@@ -3,9 +3,10 @@
     <td align="right">block_birthday_fieldname: </td>
     <td>
     <input name="block" type="hidden" value="<?php echo intval($_REQUEST['block']); ?>" />
-    <input name="block_birthday_fieldname" type="text" size="10" value="<?php 
-    if(isset($CFG->block_birthday_fieldname)) {
-        p($CFG->block_birthday_fieldname);
+    <input name="block_birthday_fieldname" type="text" size="10" value="<?php
+    $config_birthday = get_config('block/birthday');
+    if(isset($config_birthday->block_birthday_fieldname)) {
+        p($config_birthday->block_birthday_fieldname);
     } else {
         p('DOB');
     } ?>" />
@@ -14,26 +15,43 @@
     <?php print_string('user_info_field_shortname', 'block_birthday') ?>
     </td>
 </tr>
+   
+<tr valign="top">
+    <td align="right">block_birthday_days: </td>
+    <td>
+    <input name="block_birthday_days" type="text" size="3" value="<?php
+    
+    if(isset($config_birthday->block_birthday_days)) {
+        p($config_birthday->block_birthday_days);
+    } else {
+        p('0');
+    } ?>" />
+    </td>
+    <td>
+    <?php print_string('user_info_field_days', 'block_birthday') ?>
+    </td>
+</tr>
+
 
 <tr valign="top">
 <td align="right">block_birthday_dateformat: </td>
 <td>
     <select name="block_birthday_dateformat">
 
-     <option value="ISO" <?php if(isset($CFG->block_birthday_dateformat)){ 
-     if($CFG->block_birthday_dateformat == "ISO"){ echo "selected=\"selected\"";}
+     <option value="ISO" <?php if(isset($config_birthday->block_birthday_dateformat)){ 
+     if($config_birthday->block_birthday_dateformat == "ISO"){ echo "selected=\"selected\"";}
      }else{
          echo "selected=\"selected\"";
      }?>     
      ><?php p(get_string('dateformatiso', 'block_birthday')) ?></option>
 
-     <option value="USA" <?php if(isset($CFG->block_birthday_dateformat)){ 
-         if($CFG->block_birthday_dateformat == "USA"){ echo "selected=\"selected\""; }
+     <option value="USA" <?php if(isset($config_birthday->block_birthday_dateformat)){ 
+         if($config_birthday->block_birthday_dateformat == "USA"){ echo "selected=\"selected\""; }
      }?>
      ><?php p(get_string('dateformatusa', 'block_birthday')) ?></option>
 
-     <option value="EUR" <?php if(isset($CFG->block_birthday_dateformat)){ 
-         if($CFG->block_birthday_dateformat == "EUR"){ echo "selected=\"selected\""; }
+     <option value="EUR" <?php if(isset($config_birthday->block_birthday_dateformat)){ 
+         if($config_birthday->block_birthday_dateformat == "EUR"){ echo "selected=\"selected\""; }
      }?>
      ><?php p(get_string('dateformateur', 'block_birthday')) ?></option>
 
@@ -49,15 +67,15 @@
 <td>
     <select name="block_birthday_visible">
      
-     <option value="Show" <?php if(isset($CFG->block_birthday_visible)){ 
-     if($CFG->block_birthday_visible == "Show"){ echo "selected=\"selected\"";}
+     <option value="Show" <?php if(isset($config_birthday->block_birthday_visible)){ 
+     if($config_birthday->block_birthday_visible == "Show"){ echo "selected=\"selected\"";}
      }else{
          echo "selected=\"selected\"";
      }?>     
      ><?php p(get_string('blockshow', 'block_birthday')) ?></option>
      
-     <option value="Hide" <?php if(isset($CFG->block_birthday_visible)){ 
-         if($CFG->block_birthday_visible == "Hide"){ echo "selected=\"selected\""; }
+     <option value="Hide" <?php if(isset($config_birthday->block_birthday_visible)){ 
+         if($config_birthday->block_birthday_visible == "Hide"){ echo "selected=\"selected\""; }
      }?>
      ><?php p(get_string('blockhide', 'block_birthday')) ?></option>
      
Index: plugins/blocks/birthday/block_birthday.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/birthday/block_birthday.php,v
retrieving revision 1.10
diff -u -r1.10 block_birthday.php
--- plugins/blocks/birthday/block_birthday.php	15 Apr 2008 09:07:10 -0000	1.10
+++ plugins/blocks/birthday/block_birthday.php	16 Apr 2008 22:32:30 -0000
@@ -1,21 +1,57 @@
-<?php //$Id: block_birthday.php,v 1.10 2008/04/15 09:07:10 arborrow Exp $
+<?php //$Id: block_birthday.php,v 1.9 2008/04/02 05:28:35 arborrow Exp $
 
 /**
  * An elementary way of getting a list of the students with birthdays
  * based off of the site_online_users block
  */
+function get_month_day($date, $format='ISO') {
+
+        $year = date('Y');
+        
+        switch ($format) {
+            case 'USA': 
+                $period = explode('.',$date);
+                $month = $period[0];
+                $day = $period[1]; 
+                break;
+            case 'ISO': 
+                $period = explode('-',$date); 
+                $month = $period[1];
+                $day = $period[2];
+                break;
+            case 'EUR': 
+                $period = explode('.',$date); 
+                $month = $period[1];
+                $day = $period[0];
+                break;
+            default : error('Invalid field type'); 
+        }
+            $return = date('M d',mktime(0,0,0,$month,$day,$year)); 
+            return $return; 
+        
+    }
  
 class block_birthday extends block_base {
     function init() {
         $this->title = get_string('birthday','block_birthday'); //can be used for multiple languages as it gets developed further
-        $this->version = 2007071300;
+        $this->version = 2008041601;
     }
-
+    // $date a string value of the user profile field data
+    // $format is a string of the $dateformat - either ISO, USA, or EUR
+        
     function has_config() {return true;}
+
+    function config_save($data) {
+        foreach ($data as $name => $value) {
+            set_config($name, $value,'block/birthday');
+        }
+        return true;
+    }
     
     function get_content() {
         global $USER, $CFG, $COURSE;
-
+        $cfg_birthday = get_config('block/birthday');
+        
         if ($this->content !== NULL) {
             return $this->content;
         }
@@ -29,21 +65,27 @@
         }
 
 // make sure config variables are defined - if not, set them to default values
-        if (!isset($CFG->block_birthday_fieldname)) {
-          $fieldname = 'DOB';
+        
+        if (!isset($cfg_birthday->block_birthday_fieldname)) {
+          $fieldname = 'DOB';            //this is the default
          }
-           //this is the default
           else {
-           $fieldname = $CFG->block_birthday_fieldname ;
+           $fieldname = $cfg_birthday->block_birthday_fieldname ;
           }
 
-        if (!isset($CFG->block_birthday_dateformat)) {
-          $dateformat = 'ISO';
+        if (!isset($cfg_birthday->block_birthday_dateformat)) {
+          $dateformat = 'ISO';            //this is the default
          }
-           //this is the default
           else {
-           $dateformat = $CFG->block_birthday_dateformat ;
+           $dateformat = $cfg_birthday->block_birthday_dateformat ;
           }
+
+        if (!isset($cfg_birthday->block_birthday_days)) {
+          $days = 0; //this is the default
+         }
+          else {
+           $days = $cfg_birthday->block_birthday_days ;
+          }          
         
 // get the field id for the given fieldname
          if (isset($fieldname)) { 
@@ -64,9 +106,22 @@
                              && $COURSE->groupmodeforce
                              && !has_capability('moodle/site:accessallgroups', $context));
 
+  //Get the user current group
+        $currentgroup = $isseparategroups ? groups_get_course_group($COURSE) : NULL;
+
+        $groupmembers = "";
+        $groupselect = "";
+
+        //Add this to the SQL to show only group users
+        if ($currentgroup !== NULL) {
+            $groupmembers = ",  {$CFG->prefix}groups_members gm ";
+            $groupselect = " AND u.id = gm.userid AND gm.groupid = '$currentgroup'";
+        }
+
         $users = array();
 // there are probably more eloquent ways of getting the current user's time/date information
-        $userdate = usergetdate(time(),$USER->timezone);
+        for ($i=0; $i <= $days; $i++) {
+        $userdate = usergetdate((time()+($i*86400)),$USER->timezone);
         $usermonth = $userdate['mon'];
         $userday = $userdate['mday'];
         $SQL = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, u.lastaccess, ud.data
@@ -78,8 +133,8 @@
                       AND day(STR_TO_DATE(ud.data,GET_FORMAT(DATE,'{$dateformat}'))) = $userday 
                       AND ud.fieldid={$fieldid}
                       AND u.deleted = 0
-                ORDER BY u.lastname, u.firstname ASC";
-        
+                ORDER BY ud.data, u.lastname, u.firstname ASC";
+                
         $pcontext = get_related_contexts_string($context);
     
         if ($pusers = get_records_sql($SQL, 0, 50)) {   // We'll just take the most recent 50 maximum
@@ -99,58 +154,89 @@
                     // and this user has a hidden assignment at this context or higher
                     continue;  
                 }
+                
+                if ($COURSE->id == SITEID) {
+                    ;  // Site-level
+                } else { // Course-level
+                    if ((!has_capability('moodle/course:viewparticipants', $context, $USER->id)) or (!has_capability('moodle/course:view',$context, $puser->id))) {
+                        continue;
+                    }
+                }
               
                 $puser->fullname = fullname($puser);
                 $users[$puser->id] = $puser;  
             }
-        }  
+        }
+        } //end of for i loop  
            
         //Calculate minutes
 //        $minutes  = floor($timetoshowusers/60);
 
-
+        $curday = date('M j', time()); //initialize current day
+            //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string).
+            //Accessibility: Converted <div> to <ul>, inherit existing classes & styles.
+                    
         //Now, we have in users, the list of users to show
         //Because it is their birthday
         if (!empty($users)) {
-            $this->content->text = "<div class=\"info\">".get_string("block_title","block_birthday")."</div>";
-            //Accessibility: Don't want 'Alt' text for the user picture; DO want it for the envelope/message link (existing lang string).
-            //Accessibility: Converted <div> to <ul>, inherit existing classes & styles.
-            $this->content->text .= "<ul class='list'>\n";
-            foreach ($users as $user) {
-                $this->content->text .= '<li class="listentry">';
-                // $timeago = format_time(time() - max($user->timeaccess, $user->lastaccess)); //bruno to calculate correctly on frontpage 
 
-                if ($user->username == 'guest') {
-                    $this->content->text .= '<div class="user">'.print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
-                    $this->content->text .= get_string('guestuser').'</div>';
+            $this->content->text = '<div class="info">'.get_string("block_title","block_birthday").'</div>';    
+            $this->content->text .= '<ul class="list">';
+            
+            foreach ($users as $user) {
+                if ($curday == get_month_day($user->data,$dateformat)) {
+                    $this->content->text .= '<li class="listentry">';
+                    if ($user->username == 'guest') {
+                        $this->content->text .= '<div class="user">'.print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
+                        $this->content->text .= get_string('guestuser').'</div>';
+                    } else {
+                        $this->content->text .= '<div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$COURSE->id.'">';
+                        $this->content->text .= print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
+                        $this->content->text .= $user->fullname.'</a></div>';
+                    }
+                    if (!empty($USER->id) and ($USER->id != $user->id) and !empty($CFG->messaging) and 
+                        !isguest() and $user->username != 'guest') {  // Only when logged in and messaging active etc
+                        $this->content->text .= '<div class="message"><a title="'.get_string('messageselectadd').'" href="'.$CFG->wwwroot.'/message/discussion.php?id='.$user->id.'" onclick="this.target=\'message_'.$user->id.'\';return openpopup(\'/message/discussion.php?id='.$user->id.'\', \'message_'.$user->id.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">'
+                            .'<img class="iconsmall" src="'.$CFG->pixpath.'/t/message.gif" alt="'. get_string('messageselectadd') .'" /></a></div>';
+                    }
 
+                    $this->content->text .= '</li>';
                 } else {
-                    $this->content->text .= '<div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$COURSE->id.'">';
-                    $this->content->text .= print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
-                    $this->content->text .= $user->fullname.'</a></div>';
-                }
-                if (!empty($USER->id) and ($USER->id != $user->id) and !empty($CFG->messaging) and 
-                    !isguest() and $user->username != 'guest') {  // Only when logged in and messaging active etc
-                    $this->content->text .= '<div class="message"><a title="'.get_string('messageselectadd').'" href="'.$CFG->wwwroot.'/message/discussion.php?id='.$user->id.'" onclick="this.target=\'message_'.$user->id.'\';return openpopup(\'/message/discussion.php?id='.$user->id.'\', \'message_'.$user->id.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">'
-                        .'<img class="i<u></u>consmall" src="'.$CFG->pixpath.'/t/message.gif" alt="'. get_string('messageselectadd') .'" /></a></div>';
-                }
+                    $this->content->text .= '</ul><div class="clearer"><!-- --></div>';
+                    
+                    $curday = get_month_day($user->data,$dateformat); //if we have switched days then set the current day to the new day
+                    $this->content->text .= '<div class="info">'.$curday.'</div>';
+                    $this->content->text .= '<ul class="list">';
+                    $this->content->text .= '<li class="listentry">';
+         
+                    if ($user->username == 'guest') {
+                        $this->content->text .= '<div class="user">'.print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
+                        $this->content->text .= get_string('guestuser').'</div>';
+                    } else {
+                        $this->content->text .= '<div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$COURSE->id.'">';
+                        $this->content->text .= print_user_picture($user->id, $COURSE->id, $user->picture, 16, true, false, '', false);
+                        $this->content->text .= $user->fullname.'</a></div>';
+                    }
+                    if (!empty($USER->id) and ($USER->id != $user->id) and !empty($CFG->messaging) and 
+                        !isguest() and $user->username != 'guest') {  // Only when logged in and messaging active etc
+                        $this->content->text .= '<div class="message"><a title="'.get_string('messageselectadd').'" href="'.$CFG->wwwroot.'/message/discussion.php?id='.$user->id.'" onclick="this.target=\'message_'.$user->id.'\';return openpopup(\'/message/discussion.php?id='.$user->id.'\', \'message_'.$user->id.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">'
+                            .'<img class="iconsmall" src="'.$CFG->pixpath.'/t/message.gif" alt="'. get_string('messageselectadd') .'" /></a></div>';
+                    }
 
-                $this->content->text .= "</li>\n";
+                    $this->content->text .= '</li>';
+                }
             }
             $this->content->text .= '</ul><div class="clearer"><!-- --></div>';
        } else {
-            if (!empty($CFG->block_birth_visible)) {
-                if ($CFG->block_birthday_visible=='Hide') {
+            $this->content->text .= '<div class="info">'.get_string("nobirthdays","block_birthday").'</div>';
+            if (!empty($cfg_birthday->block_birthday_visible)) {
+                if ($cfg_birthday->block_birthday_visible=='Hide') { //block is hidden when empty
                     $this->content->text = '';
                 } 
-            }
-            else {
-               $this->content->text .= "<div class=\"info\">".get_string("nobirthdays","block_birthday")."</div>";
-             }
+            } 
         }
-
         return $this->content;
-    }
+    } //get_content
 }
 
 ?>
Index: plugins/blocks/birthday/README.TXT
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/birthday/README.TXT,v
retrieving revision 1.2
diff -u -r1.2 README.TXT
--- plugins/blocks/birthday/README.TXT	14 Jul 2007 14:33:42 -0000	1.2
+++ plugins/blocks/birthday/README.TXT	16 Apr 2008 22:32:30 -0000
@@ -1,10 +1,12 @@
 Birthday Block:
 
-This is a first attempt at developing a birthday block. As such, there is probably great room for improvement. I am gladly welcome any suggestions and comments for improving it. 
+This is an attempt at developing a birthday block. Suggestions for improvement are welcome on the tracker (tracker.moodle.org).  Currently the block allows for the admin to configure the name of the custom user profile field, the date format, whether to show or hide the block if there are no birthdays, and the number of days in the future to display upcoming birthdays. The older version (prior to 2008041601) stored the configuration data in mdl_config; however, it is preferred that such data be stored in mdl_config_plugins. 
 
-This block will display in alphabetical order (lastname, firstname) all users who are celebrating a birthday (or anniversary) on a given day (namely, today). The block makes use of the custom user profile fields and assumes that you have created a field with a default shortname of DOB (i.e. date of birth). However, the field's shortname is configurable so you could use Anniversary or any other name you choose. The block further assumes, since the data stored in the custom user profile fields is a text value (and not an actual date) that it is entered in a correct date format (either the default ISO format of YYYY-MM-DD format, the USA format of m.d.Y, or the EUR format of d.m.Y). There is no data validation when the user enters the data and therefore I would recommend that the user not be able to edit their own record. 
+This block will alphabettically (lastname, firstname) display users who are celebrating a birthday (or anniversary) on a given day (namely, today). The block makes use of the custom user profile fields and assumes that you have created a field with a default shortname of DOB (i.e. date of birth). However, the field's shortname is configurable so you could use Anniversary or any other name you choose. The block further assumes, since the data stored in the custom user profile fields is a text value (and not an actual date) that it is entered in a correct date format (either the default ISO format of YYYY-MM-DD format, the USA format of m.d.Y, or the EUR format of d.m.Y). There is no data validation when the user enters the data and therefore I would recommend that the user not be able to edit their own record. 
 
-Currently only English, German, and Spanish are supported although I am happy to add language files as I receive them. If you have any questions please send me (Anthony Borrow, S.J.) a message via Moodle.org. 
+Thanks to the generosity of translators the birthday block is now available in English, French, German, Hungarian, Italian, Japanese, Spanish, and Swedish. Other languages are welcome, simply create an issue in the tracker and upload the file and then I can add it to CVS.
+
+ If you have any questions about the Birthday block please send me (Anthony Borrow, S.J.) a message via Moodle.org. 
 
 Installation:
 
Index: plugins/blocks/birthday/lang/en_utf8/block_birthday.php
===================================================================
RCS file: /cvsroot/moodle/contrib/plugins/blocks/birthday/lang/en_utf8/block_birthday.php,v
retrieving revision 1.4
diff -u -r1.4 block_birthday.php
--- plugins/blocks/birthday/lang/en_utf8/block_birthday.php	31 Aug 2007 03:42:32 -0000	1.4
+++ plugins/blocks/birthday/lang/en_utf8/block_birthday.php	16 Apr 2008 22:32:30 -0000
@@ -15,5 +15,6 @@
 $string['nobirthdays'] = 'There are no birthdays today.';
 $string['periodnminutes'] = 'last $a minutes';
 $string['user_info_field_shortname'] = 'The unique shortname of the user profile field that contains the user\'s date of birth (the default shortname is \'DOB\').';
-
+$string['user_info_field_days'] = 'The number of days in the future to display birthdays (the default is 0 and will show only today\'s birthdays).';
+ 
 ?>
Index: plugins/blocks/birthday/db/upgrade.php
===================================================================
RCS file: plugins/blocks/birthday/db/upgrade.php
diff -N plugins/blocks/birthday/db/upgrade.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/blocks/birthday/db/upgrade.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,49 @@
+<?php  //$Id: upgrade.php,v 1.1 2006/10/26 16:33:53 stronk7 Exp $
+
+// This file keeps track of upgrades to 
+// the birthday block
+//
+// Sometimes, changes between versions involve
+// alterations to database structures and other
+// major things that may break installations.
+//
+// The upgrade function in this file will attempt
+// to perform all the necessary actions to upgrade
+// your older installtion to the current version.
+//
+// If there's something it cannot do itself, it
+// will tell you what you need to do.
+//
+// The commands in here will all be database-neutral,
+// using the functions defined in lib/ddllib.php
+
+function xmldb_block_birthday_upgrade($oldversion=0) {
+
+    global $CFG, $THEME, $db;
+
+    $result = true;
+
+    if ($result && $oldversion < 2008041601) { //New version in version.php
+        // attempt to cleanup any previous data stored in the mdl_config table, data is now stored in mdl_config_plugins
+        // first get the data if it exists
+        $fieldname = get_config(NULL,'block_birthday_fieldname'); 
+        $dateformat = get_config(NULL,'block_birthday_dateformat');
+        $visible = get_config(NULL,'block_birthday_visible');
+        // then delete the data from mdl_config
+        $result = (set_config('block_birthday_fieldname',NULL) && set_config('block_birthday_dateformat',NULL) && set_config('block_birthday_visible',NULL));
+        // finally if there is data, then add to mdl_config_plugin
+        if (!empty($fieldname)) {
+            set_config('block_birthday_fieldname',$fieldname,'block/birthday');
+        } 
+        if (!empty($dateformat)) {
+            set_config('block_birthday_dateformat',$dateformat,'block/birthday');
+        }
+        if (!empty($visible)) {
+            set_config('block_birthday_visible',$visible,'block/birthday');
+        }
+    }
+
+    return $result;
+}
+
+?>

