specific_fields_add.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Add form
  5. * @package chamilo.admin
  6. */
  7. // Resetting the course id.
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $libpath = api_get_path(LIBRARY_PATH);
  11. require_once $libpath.'specific_fields_manager.lib.php';
  12. // section for the tabs
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. // user permissions
  15. api_protect_admin_script();
  16. $fieldId = isset($_REQUEST['field_id']) ? intval($_REQUEST['field_id']) : 0;
  17. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  18. $interbreadcrumb[] = array('url' => 'settings.php?category=Search', 'name' => get_lang('PlatformConfigSettings'));
  19. $interbreadcrumb[] = array('url' => 'specific_fields.php', 'name' => get_lang('SpecificSearchFields'));
  20. $tool_name = get_lang('AddSpecificSearchField');
  21. if (isset($_GET['action']) && $_GET['action'] === 'edit') {
  22. $tool_name = get_lang('EditSpecificSearchField');
  23. }
  24. // Create the form
  25. $form = new FormValidator('specific_fields_add');
  26. // Field variable name
  27. $form->addElement('hidden','field_id', $fieldId);
  28. $form->addElement('text','field_name',get_lang('FieldName'));
  29. $form->applyFilter('field_name','html_filter');
  30. $form->applyFilter('field_name','trim');
  31. $form->addRule('field_name', get_lang('ThisFieldIsRequired'), 'required');
  32. $form->addRule('field_name', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
  33. $form->addRule('field_name', '', 'maxlength',20);
  34. // Set default values (only not empty when editing)
  35. $defaults = array();
  36. if ($fieldId) {
  37. $form_information = get_specific_field_list(array( 'id' => $fieldId ));
  38. $defaults['field_name'] = $form_information[0]['name'];
  39. }
  40. $form->setDefaults($defaults);
  41. // Submit button
  42. $form->addButtonCreate(get_lang('Add'), 'submit');
  43. // Validate form
  44. if ($form->validate()) {
  45. $field = $form->exportValues();
  46. $field_name = $field['field_name'];
  47. if (is_numeric($field['field_id']) && $field['field_id']<>0 && !empty($field['field_id'])) {
  48. edit_specific_field($field['field_id'], $field['field_name']);
  49. $message = get_lang('FieldEdited');
  50. } else {
  51. $field_id = add_specific_field($field_name);
  52. $message = get_lang('FieldAdded');
  53. }
  54. header('Location: specific_fields.php?message='.$message);
  55. //exit ();
  56. }
  57. // Display form
  58. Display::display_header($tool_name);
  59. $form->display();
  60. Display::display_footer();