From 5c11b818ec1dbe6e2f48337dccb8db1aca014531 Mon Sep 17 00:00:00 2001 From: ikawhero Date: Fri, 12 Jan 2007 08:07:15 +0000 Subject: [PATCH] Making the interface friendlier: - heading context sensitive - don't display the default category unless some fields have been defined - if no categories have been defined, then create the default category silently --- user/profile/index.php | 62 ++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/user/profile/index.php b/user/profile/index.php index 8cd326aaa9..919c2aa109 100644 --- a/user/profile/index.php +++ b/user/profile/index.php @@ -20,8 +20,12 @@ $type = optional_param('type', '', PARAM_ALPHANUM); $datatypes = profile_list_datatypes(); $redirect = $CFG->wwwroot.'/user/profile/index.php'; -$strchangessaved = get_string('changessaved'); -$strcancelled = get_string('cancelled'); + +$strchangessaved = get_string('changessaved'); +$strcancelled = get_string('cancelled'); +$strdefaultcategory = get_string('profiledefaultcategory', 'admin'); +$strnofields = get_string('profilenofieldsdefined', 'admin'); +$strcreatefield = get_string('profilecreatefield', 'admin'); /// Do we have any actions to perform before printing the header @@ -101,11 +105,19 @@ switch ($action) { /// Print the header admin_externalpage_print_header($adminroot); -print_heading(get_string('profilefields', 'admin')); /// Are we adding or editing a cateogory? if ( ($action == 'editcategory' )) { + + if ($id == 0) { + $strheading = get_string('profilecreatenewcategory', 'admin'); + } else { + $strheading = get_string('profileeditcategory', 'admin', $category->name); + } + + print_heading($strheading); + require_once('index_category_form.php'); $categoryform = new category_form(null, compact('category')); if ($categoryform->is_cancelled()) { @@ -133,6 +145,15 @@ if ( ($action == 'editcategory' )) { /// Are we adding or editing a field? } elseif ( $action == 'editfield' ) { + + if ($id == 0) { + $strheading = get_string('profilecreatenewfield', 'admin'); + } else { + $strheading = get_string('profileeditfield', 'admin', $field->name); + } + + print_heading($strheading); + require_once('index_field_form.php'); $fieldform = new field_form(null, compact('field')); if ($fieldform->is_cancelled()) { @@ -155,12 +176,18 @@ if ( ($action == 'editcategory' )) { /// Deleting a category that has fields in it, print confirm screen? } elseif ( ($action == 'deletecategory') and !$confirm ) { + + print_heading('profiledeletecategory', 'admin'); + $fieldcount = count_records('user_info_field', 'categoryid', $id); echo '
'.get_string('profileconfirmcategorydeletion', 'admin', $fieldcount).'
'.get_string('yes').' '.get_string('no').'
'; /// Deleting a field that has user data, print confirm screen } elseif ( ($action == 'deletefield') and !$confirm ) { + + print_heading('profiledeletefield', 'admin'); + $datacount = count_records('user_info_data', 'fieldid', $id); echo '
'.get_string('profileconfirmfielddeletion', 'admin', $datacount).'
'.get_string('yes').' '.get_string('no').'
'; @@ -169,8 +196,20 @@ if ( ($action == 'editcategory' )) { /// Print the table of categories and fields } else { - if ($categories = get_records_select('user_info_category', '1', 'sortorder ASC')) { + /// Check that we have at least one category defined + if (count_records_select('user_info_category', '1') == 0) { + unset($defaultcategory); + $defaultcategory->name = $strdefaultcategory; + $defaultcategory->sortorder = 1; + insert_record('user_info_category', $defaultcategory); + } + + print_heading(get_string('profilefields', 'admin')); + /// We only displaying if there are fields defined or there is a category with a name different to the default name + if ( ( (count_records_select('user_info_category', "name<>'$strdefaultcategory'") > 0) or + (count_records_select('user_info_field', '1') > 0) ) and + ( $categories = get_records_select('user_info_category', '1', 'sortorder ASC')) ) { unset ($table); $table->align = array('left', 'right'); $table->width = '95%'; @@ -200,25 +239,20 @@ if ( ($action == 'editcategory' )) { } /// End of $categories foreach print_table($table); - + } else { - - notify(get_string('profilenocategoriesdefined', 'admin')); + + notify($strnofields); } /// End of $categories if - - echo '
'; echo '
'; /// Create a new field link - if ($categories) { - $options = profile_list_datatypes(); - print_string('profilecreatefield', 'admin'); - popup_form($CFG->wwwroot.'/user/profile/index.php?id=0&action=editfield&type=', $options, 'newfieldform'); - } + $options = profile_list_datatypes(); + popup_form($CFG->wwwroot.'/user/profile/index.php?id=0&action=editfield&type=', $options, 'newfieldform','','choose','','',false,'self',$strcreatefield); /// Create a new category link $options = array('action'=>'editcategory', 'id'=>'0'); -- 2.39.5