specific_fields_add.php 2.8 KB

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