### Eclipse Workspace Patch 1.0
#P moodle19
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	25 Dec 2009 20:57:58 -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->categoryid == $category->id) {
+                                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>';
