### Eclipse Workspace Patch 1.0
#P moodle19
Index: mod/data/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/lib.php,v
retrieving revision 1.137.2.57
diff -u -r1.137.2.57 lib.php
--- mod/data/lib.php	27 Oct 2009 11:24:56 -0000	1.137.2.57
+++ mod/data/lib.php	26 Dec 2009 04:23:00 -0000
@@ -916,6 +916,7 @@
  ************************************************************************/
 function data_print_template($template, $records, $data, $search='', $page=0, $return=false) {
     global $CFG;
+    require_once($CFG->dirroot.'/user/profile/lib.php');
     $cm = get_coursemodule_from_instance('data', $data->id);
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     static $fields = NULL;
@@ -971,7 +972,7 @@
         $patterns[]='##user##';
         $replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid.
                                '&amp;course='.$data->course.'">'.fullname($record).'</a>';
-        
+
         $patterns[] = '##timeadded##';
         $replacement[] = userdate($record->timecreated); 
 
@@ -992,6 +993,19 @@
         } else {
             $replacement[] = '';
         }
+        
+        //add patterns and replacements for custom profile fields
+        //I am going to first be inclusive and show everything and then go back and worry about security/privacy
+        // TODO: Verify that user viewing record has access to view profile information
+        if ($user_profile = profile_user_record($record->userid)) { //get user profile data for record owner
+            if ($profile_fields = get_records('user_info_field','','','sortorder')) {
+                foreach ($profile_fields as $profile_field) {
+                    $patterns[]='##profile_'.$profile_field->shortname.'##';
+                    $shortname = $profile_field->shortname;
+                    $replacement[] = $user_profile->$shortname;
+                } 
+            }
+        } 
 
         // actual replacement of the tags
         $newtext = str_ireplace($patterns, $replacement, $data->{$template});
Index: mod/data/templates.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/templates.php,v
retrieving revision 1.68.2.5
diff -u -r1.68.2.5 templates.php
--- mod/data/templates.php	16 Apr 2008 12:29:21 -0000	1.68.2.5
+++ mod/data/templates.php	26 Dec 2009 04:23:00 -0000
@@ -232,10 +232,26 @@
                 echo '<option value="##moreurl##">' .get_string('moreurl', 'data'). ' - ##moreurl##</option>';
             }
             echo '</optgroup>';
-            echo '<optgroup label="'.get_string('other', 'data').'">';
+            echo '<optgroup label="'.get_string('user').'">';
+            echo '<option value="##user##">' .get_string('user'). ' - ##user##</option>';
+            echo '</optgroup>';
+            // get user profile field categories and loop through creating options for custom user profile fields
+            if ($profile_categories = get_records('user_info_category','','','sortorder')) {
+                foreach ($profile_categories as $category) {
+                    echo '<optgroup label="'.$category->name.'">';
+                    if ($profile_fields = get_records('user_info_field','categoryid',$category->id,'sortorder')) {
+                        foreach ($profile_fields as $profile_field) {
+                            if ($profile_field->visible>0) {
+                                echo '<option value="##profile_'.$profile_field->shortname.'##">'.$profile_field->name.' - ##profile_'.$profile_field->shortname.'##</option>';
+                            } 
+                        }
+                    }
+                    echo '</optgroup>';
+                }
+            }
+            echo '<optgroup label="'.get_string('other', 'data').'">';            
             echo '<option value="##timeadded##">'.get_string('timeadded', 'data'). ' - ##timeadded##</option>';
             echo '<option value="##timemodified##">'.get_string('timemodified', 'data'). ' - ##timemodified##</option>';
-            echo '<option value="##user##">' .get_string('user'). ' - ##user##</option>';
             if ($mode != 'singletemplate') {
                 // more points to single template - not useable there
                 echo '<option value="##comments##">' .get_string('comments', 'data'). ' - ##comments##</option>';
