libdir.'/adminlib.php'); require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/profile/definelib.php'); admin_externalpage_setup('profilefields'); $action = optional_param('action', '', PARAM_ALPHA); $redirect = $CFG->wwwroot.'/user/profile/index.php'; $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 switch ($action) { case 'movecategory': $id = required_param('id', PARAM_INT); $dir = required_param('dir', PARAM_ALPHA); if (confirm_sesskey()) { profile_move_category($id, $dir); } redirect($redirect); break; case 'movefield': $id = required_param('id', PARAM_INT); $dir = required_param('dir', PARAM_ALPHA); if (confirm_sesskey()) { profile_move_field($id, $dir); } redirect($redirect); break; case 'deletecategory': $id = required_param('id', PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); if (data_submitted() and $confirm and confirm_sesskey()) { profile_delete_category($id); redirect($redirect); } //ask for confirmation $fieldcount = count_records('user_info_field', 'categoryid', $id); $optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletecategory', 'sesskey'=>sesskey()); admin_externalpage_print_header(); print_heading('profiledeletecategory', 'admin'); notice_yesno(get_string('profileconfirmcategorydeletion', 'admin', $fieldcount), $redirect, $redirect, $optionsyes, null, 'post', 'get'); admin_externalpage_print_footer(); die; break; case 'deletefield': $id = required_param('id', PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); if (data_submitted() and $confirm and confirm_sesskey()) { profile_delete_field($id); redirect($redirect); } //ask for confirmation $datacount = count_records('user_info_data', 'fieldid', $id); $optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletefield', 'sesskey'=>sesskey()); admin_externalpage_print_header(); print_heading('profiledeletefield', 'admin'); notice_yesno(get_string('profileconfirmfielddeletion', 'admin', $datacount), $redirect, $redirect, $optionsyes, null, 'post', 'get'); admin_externalpage_print_footer(); die; break; case 'editfield': $id = optional_param('id', 0, PARAM_INT); $datatype = optional_param('datatype', '', PARAM_ALPHA); profile_edit_field($id, $datatype, $redirect); die; break; case 'editcategory': $id = optional_param('id', 0, PARAM_INT); profile_edit_category($id, $redirect); die; break; default: //normal form } /// Print the header admin_externalpage_print_header(); print_heading(get_string('profilefields', 'admin')); /// Check that we have at least one category defined if (count_records('user_info_category') == 0) { $defaultcategory = new object(); $defaultcategory->name = $strdefaultcategory; $defaultcategory->sortorder = 1; insert_record('user_info_category', $defaultcategory); redirect($redirect); } /// Show all categories $categories = get_records_select('user_info_category', '', 'sortorder ASC'); foreach ($categories as $category) { $table = new object(); $table->head = array(get_string('profilefield', 'admin'), get_string('edit')); $table->align = array('left', 'right'); $table->width = '95%'; $table->class = 'generaltable profilefield'; $table->data = array(); if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) { foreach ($fields as $field) { $table->data[] = array($field->name, profile_field_icons($field)); } } print_heading(format_string($category->name) .' '.profile_category_icons($category)); if (count($table->data)) { print_table($table); } else { notify($strnofields); } } /// End of $categories foreach echo '