specific_fields_add.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  14. ==============================================================================
  15. */
  16. /**
  17. * Add form
  18. * @package dokeos.admin
  19. */
  20. $language_file[] = 'admin';
  21. // including necessary libraries
  22. require ('../inc/global.inc.php');
  23. $libpath = api_get_path(LIBRARY_PATH);
  24. include_once ($libpath.'specific_fields_manager.lib.php');
  25. require_once ($libpath.'formvalidator/FormValidator.class.php');
  26. // section for the tabs
  27. $this_section=SECTION_PLATFORM_ADMIN;
  28. // user permissions
  29. api_protect_admin_script();
  30. // Database table definitions
  31. $table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  32. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  33. $table_uf = Database :: get_main_table(TABLE_MAIN_USER_FIELD);
  34. $table_uf_opt = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
  35. $table_uf_val = Database :: get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  36. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  37. $interbreadcrumb[] = array ('url' => 'specific_fields.php', 'name' => get_lang('SpecificSearchFields'));
  38. if ($_GET['action']<>'edit')
  39. {
  40. $tool_name = get_lang('AddSpecificSearchField');
  41. }
  42. else
  43. {
  44. $tool_name = get_lang('EditSpecificSearchField');
  45. }
  46. // Create the form
  47. $form = new FormValidator('specific_fields_add');
  48. // Field variable name
  49. $form->addElement('hidden','field_id',(int)$_REQUEST['field_id']);
  50. $form->addElement('text','field_name',get_lang('FieldName'));
  51. $form->applyFilter('field_name','html_filter');
  52. $form->applyFilter('field_name','trim');
  53. $form->addRule('field_name', get_lang('ThisFieldIsRequired'), 'required');
  54. $form->addRule('fieldname', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
  55. $form->addRule('fieldname', '', 'maxlength',20);
  56. // Set default values (only not empty when editing)
  57. $defaults = array();
  58. if (is_numeric($_REQUEST['field_id']))
  59. {
  60. $form_information = get_specific_field_list(array( 'id' => (int)$_GET['field_id'] ));
  61. $defaults['field_name'] = $form_information[0]['name'];
  62. }
  63. $form->setDefaults($defaults);
  64. // Submit button
  65. $form->addElement('submit', 'submit', get_lang('Add'));
  66. // Validate form
  67. if ($form->validate()) {
  68. $field = $form->exportValues();
  69. $field_name = $field['field_name'];
  70. if (is_numeric($field['field_id']) && $field['field_id']<>0 && !empty($field['field_id']))
  71. {
  72. edit_specific_field($field['field_id'],$field['field_name']);
  73. $message = get_lang('FieldEdited');
  74. }
  75. else
  76. {
  77. $field_id = add_specific_field($field_name);
  78. $message = get_lang('FieldAdded');
  79. }
  80. header('Location: specific_fields.php?message='.$message);
  81. //exit ();
  82. }
  83. // Display form
  84. Display::display_header($tool_name);
  85. $form->display();
  86. Display::display_footer();