user_fields_add.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php // $Id: user_fields_add.php 14874 2008-04-13 19:25:19Z yannoo $
  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. ==============================================================================
  18. * @package dokeos.admin
  19. ==============================================================================
  20. */
  21. // name of the language file that needs to be included
  22. $language_file = array('admin','registration');
  23. $cidReset = true;
  24. // including necessary libraries
  25. require ('../inc/global.inc.php');
  26. $libpath = api_get_path(LIBRARY_PATH);
  27. include_once ($libpath.'usermanager.lib.php');
  28. require_once ($libpath.'formvalidator/FormValidator.class.php');
  29. // section for the tabs
  30. $this_section=SECTION_PLATFORM_ADMIN;
  31. // user permissions
  32. api_protect_admin_script();
  33. // Database table definitions
  34. $table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  35. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  36. $table_uf = Database :: get_main_table(TABLE_MAIN_USER_FIELD);
  37. $table_uf_opt = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
  38. $table_uf_val = Database :: get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
  39. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  40. $interbreadcrumb[] = array ('url' => 'user_fields.php', 'name' => get_lang('UserFields'));
  41. $tool_name = get_lang('AddUserFields');
  42. // Create the form
  43. $form = new FormValidator('user_fields_add');
  44. // Field variable name
  45. $form->addElement('text','fieldlabel',get_lang('FieldLabel'));
  46. $form->applyFilter('fieldlabel','html_filter');
  47. $form->applyFilter('fieldlabel','trim');
  48. $form->addRule('fieldlabel', get_lang('ThisFieldIsRequired'), 'required');
  49. $form->addRule('fieldlabel', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
  50. $form->addRule('fieldlabel', '', 'maxlength',20);
  51. $form->addRule('fieldlabel', get_lang('FieldTaken'), 'fieldlabel_available');
  52. // Field type
  53. $types = array();
  54. $types[USER_FIELD_TYPE_TEXT] = get_lang('FieldTypeText');
  55. $types[USER_FIELD_TYPE_TEXTAREA] = get_lang('FieldTypeTextarea');
  56. $types[USER_FIELD_TYPE_RADIO] = get_lang('FieldTypeRadio');
  57. $types[USER_FIELD_TYPE_SELECT] = get_lang('FieldTypeSelect');
  58. $types[USER_FIELD_TYPE_SELECT_MULTIPLE] = get_lang('FieldTypeSelectMultiple');
  59. $types[USER_FIELD_TYPE_DATE] = get_lang('FieldTypeDate');
  60. $types[USER_FIELD_TYPE_DATETIME] = get_lang('FieldTypeDatetime');
  61. $form->addElement('select','fieldtype',get_lang('FieldType'),$types);
  62. $form->addRule('fieltype', get_lang('ThisFieldIsRequired'), 'required');
  63. // Field display name
  64. $form->addElement('text','fieldtitle',get_lang('FieldTitle'));
  65. $form->applyFilter('fieldtitle','html_filter');
  66. $form->applyFilter('fieldtitle','trim');
  67. $form->addRule('fieldtitle', get_lang('ThisFieldIsRequired'), 'required');
  68. // Field options
  69. $form->addElement('text','fieldoptions',get_lang('FieldPossibleValues').' <img src="../img/info3.gif" height="16" width="16" alt="'.get_lang('FieldPossibleValuesComment').'" title="'.get_lang('FieldPossibleValuesComment').'">');
  70. $form->applyFilter('fieldoptions','trim');
  71. // Field default value
  72. $form->addElement('text','fielddefaultvalue',get_lang('FieldDefaultValue'));
  73. $form->applyFilter('fielddefaultvalue','trim');
  74. // Set default values
  75. $defaults = array();
  76. $form->setDefaults($defaults);
  77. // Submit button
  78. $form->addElement('submit', 'submit', get_lang('Add'));
  79. // Validate form
  80. if( $form->validate())
  81. {
  82. $check = Security::check_token('post');
  83. if($check)
  84. {
  85. $field = $form->exportValues();
  86. $fieldlabel = $field['fieldlabel'];
  87. $fieldtype = $field['fieldtype'];
  88. $fieldtitle = $field['fieldtitle'];
  89. $fielddefault = $field['fielddefaultvalue'];
  90. $fieldoptions = $field['fieldoptions']; //comma-separated list of options
  91. $field_id = UserManager::create_extra_field($fieldlabel,$fieldtype,$fieldtitle,$fielddefault,$fieldoptions);
  92. Security::clear_token();
  93. header('Location: user_fields.php?action=show_message&message='.urlencode(get_lang('FieldAdded')));
  94. exit ();
  95. }
  96. }else{
  97. if(isset($_POST['submit'])){
  98. Security::clear_token();
  99. }
  100. $token = Security::get_token();
  101. $form->addElement('hidden','sec_token');
  102. $form->setConstants(array('sec_token' => $token));
  103. }
  104. // Display form
  105. Display::display_header($tool_name);
  106. //api_display_tool_title($tool_name);
  107. if(!empty($_GET['message'])){
  108. Display::display_normal_message($_GET['message']);
  109. }
  110. //else
  111. //{
  112. //Display::display_normal_message(get_lang('UserFieldsAddHelp'),false);
  113. //}
  114. $form->display();
  115. echo '<br /><img src="../img/add_user_field_howto.png" alt="'.get_lang('AddUserFields').'" />';
  116. /*
  117. ==============================================================================
  118. FOOTER
  119. ==============================================================================
  120. */
  121. Display::display_footer();
  122. ?>