specific_fields_add.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 __DIR__.'/../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(
  18. 'url' => 'index.php',
  19. 'name' => get_lang('PlatformAdmin'),
  20. );
  21. $interbreadcrumb[] = array(
  22. 'url' => 'settings.php?category=Search',
  23. 'name' => get_lang('PlatformConfigSettings'),
  24. );
  25. $interbreadcrumb[] = array(
  26. 'url' => 'specific_fields.php',
  27. 'name' => get_lang('SpecificSearchFields'),
  28. );
  29. $tool_name = get_lang('AddSpecificSearchField');
  30. if (isset($_GET['action']) && $_GET['action'] === 'edit') {
  31. $tool_name = get_lang('EditSpecificSearchField');
  32. }
  33. // Create the form
  34. $form = new FormValidator('specific_fields_add');
  35. // Field variable name
  36. $form->addElement('hidden', 'field_id', $fieldId);
  37. $form->addElement('text', 'field_name', get_lang('FieldName'));
  38. $form->applyFilter('field_name', 'html_filter');
  39. $form->applyFilter('field_name', 'trim');
  40. $form->addRule('field_name', get_lang('ThisFieldIsRequired'), 'required');
  41. $form->addRule('field_name', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
  42. $form->addRule('field_name', '', 'maxlength', 20);
  43. // Set default values (only not empty when editing)
  44. $defaults = array();
  45. if ($fieldId) {
  46. $form_information = get_specific_field_list(array('id' => $fieldId));
  47. $defaults['field_name'] = $form_information[0]['name'];
  48. }
  49. $form->setDefaults($defaults);
  50. // Submit button
  51. $form->addButtonCreate(get_lang('Add'), 'submit');
  52. // Validate form
  53. if ($form->validate()) {
  54. $field = $form->exportValues();
  55. $field_name = $field['field_name'];
  56. if (is_numeric($field['field_id']) && $field['field_id'] <> 0 && !empty($field['field_id'])) {
  57. edit_specific_field($field['field_id'], $field['field_name']);
  58. $message = get_lang('FieldEdited');
  59. } else {
  60. $field_id = add_specific_field($field_name);
  61. $message = get_lang('FieldAdded');
  62. }
  63. header('Location: specific_fields.php?message='.$message);
  64. //exit ();
  65. }
  66. // Display form
  67. Display::display_header($tool_name);
  68. $form->display();
  69. Display::display_footer();