specific_fields_add.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  17. $interbreadcrumb[] = array('url' => 'settings.php?category=Search', 'name' => get_lang('PlatformConfigSettings'));
  18. $interbreadcrumb[] = array('url' => 'specific_fields.php', 'name' => get_lang('SpecificSearchFields'));
  19. if ($_GET['action']<>'edit') {
  20. $tool_name = get_lang('AddSpecificSearchField');
  21. } else {
  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',(int)$_REQUEST['field_id']);
  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 (is_numeric($_REQUEST['field_id'])) {
  37. $form_information = get_specific_field_list(array( 'id' => (int)$_GET['field_id'] ));
  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();