function profile_edit_category($id, $redirect) { global $CFG, $DB, $OUTPUT; require_once 'index_category_form.php'; $categoryform = new category_form(); if ($category = $DB->get_record('user_info_category', array('id' => $id))) { $categoryform->set_data($category); } if ($categoryform->is_cancelled()) { redirect($redirect); } else { if ($data = $categoryform->get_data()) { if (empty($data->id)) { unset($data->id); $data->sortorder = $DB->count_records('user_info_category') + 1; $DB->insert_record('user_info_category', $data, false); } else { $DB->update_record('user_info_category', $data); } profile_reorder_categories(); redirect($redirect); } if (empty($id)) { $strheading = get_string('profilecreatenewcategory', 'admin'); } else { $strheading = get_string('profileeditcategory', 'admin', format_string($category->name)); } /// Print the page echo $OUTPUT->header(); echo $OUTPUT->heading($strheading); $categoryform->display(); echo $OUTPUT->footer(); die; } }
function profile_edit_category($id, $redirect) { global $CFG; require_once 'index_category_form.php'; $categoryform = new category_form(); if ($category = get_record('user_info_category', 'id', $id)) { $categoryform->set_data($category); } if ($categoryform->is_cancelled()) { redirect($redirect); } else { if ($data = $categoryform->get_data()) { if (empty($data->id)) { unset($data->id); $data->sortorder = count_records('user_info_category') + 1; if (!insert_record('user_info_category', $data, false)) { error('There was a problem adding the record to the database'); } } else { if (!update_record('user_info_category', $data)) { error('There was a problem updating the record in the database'); } } profile_reorder_categories(); redirect($redirect); } if (empty($id)) { $strheading = get_string('profilecreatenewcategory', 'admin'); } else { $strheading = get_string('profileeditcategory', 'admin', format_string($category->name)); } /// Print the page admin_externalpage_print_header(); print_heading($strheading); $categoryform->display(); admin_externalpage_print_footer(); die; } }