group_add.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // Language files that should be included
  7. $language_file = array('admin', 'registration', 'userInfo');
  8. $cidReset = true;
  9. // Including necessary libraries.
  10. //require '../inc/global.inc.php';
  11. // Section for the tabs
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. // User permissions
  14. api_protect_admin_script();
  15. $htmlHeadXtra[] = '<script>
  16. textarea = "";
  17. num_characters_permited = 255;
  18. function text_longitud(){
  19. num_characters = document.forms[0].description.value.length;
  20. if (num_characters > num_characters_permited){
  21. document.forms[0].description.value = textarea;
  22. }else{
  23. textarea = document.forms[0].description.value;
  24. }
  25. }
  26. </script>';
  27. // Database table definitions
  28. if (!empty($_GET['message'])) {
  29. $message = urldecode($_GET['message']);
  30. }
  31. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  32. $tool_name = get_lang('AddGroups');
  33. // Create the form
  34. $form = new FormValidator('group_add');
  35. $form->addElement('header', $tool_name);
  36. // name
  37. $form->addElement('text', 'name', get_lang('Name'), array('size' => 60, 'maxlength' => 120));
  38. $form->applyFilter('name', 'html_filter');
  39. $form->applyFilter('name', 'trim');
  40. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  41. // Description
  42. $form->addElement(
  43. 'textarea',
  44. 'description',
  45. get_lang('Description'),
  46. array('rows' => 3, 'cols' => 58, 'onKeyDown' => "text_longitud()", 'onKeyUp' => "text_longitud()")
  47. );
  48. $form->applyFilter('description', 'html_filter');
  49. $form->applyFilter('description', 'trim');
  50. // url
  51. $form->addElement('text', 'url', get_lang('URL'), array('size' => 35));
  52. $form->applyFilter('url', 'html_filter');
  53. $form->applyFilter('url', 'trim');
  54. // Picture
  55. $form->addElement('file', 'picture', get_lang('AddPicture'));
  56. $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
  57. $form->addRule(
  58. 'picture',
  59. get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
  60. 'filetype',
  61. $allowed_picture_types
  62. );
  63. //Group Parentship
  64. $groups = array();
  65. $groups[0] = get_lang('NoParentship');
  66. $groups = $groups + GroupPortalManager::get_groups_list($group_id);
  67. $group_data['parent_group'] = GroupPortalManager::get_parent_group($group_id);
  68. $form->addElement('select', 'parent_group', get_lang('GroupParentship'), $groups, array());
  69. // Status
  70. $status = array();
  71. $status[GROUP_PERMISSION_OPEN] = get_lang('Open');
  72. $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
  73. $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status);
  74. // Set default values
  75. $defaults['status'] = GROUP_PERMISSION_OPEN;
  76. $form->setDefaults($defaults);
  77. // Submit button
  78. $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
  79. // Validate form
  80. if ($form->validate()) {
  81. $check = Security::check_token('post');
  82. if ($check) {
  83. $values = $form->exportValues();
  84. $picture_element = $form->getElement('picture');
  85. $picture = $picture_element->getValue();
  86. $picture_uri = '';
  87. $name = $values['name'];
  88. $description = $values['description'];
  89. $url = $values['url'];
  90. $status = intval($values['visibility']);
  91. $picture = $_FILES['picture'];
  92. $parent_group_id = intval($values['parent_group']);
  93. $group_id = GroupPortalManager::add($name, $description, $url, $status);
  94. GroupPortalManager::set_parent_group($group_id, $parent_group_id);
  95. if (!empty($picture['name'])) {
  96. $picture_uri = GroupPortalManager::update_group_picture(
  97. $group_id,
  98. $_FILES['picture']['name'],
  99. $_FILES['picture']['tmp_name']
  100. );
  101. GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri);
  102. }
  103. Security::clear_token();
  104. $tok = Security::get_token();
  105. header(
  106. 'Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupAdded')).'&sec_token='.$tok
  107. );
  108. exit ();
  109. }
  110. } else {
  111. if (isset($_POST['submit'])) {
  112. Security::clear_token();
  113. }
  114. $token = Security::get_token();
  115. $form->addElement('hidden', 'sec_token');
  116. $form->setConstants(array('sec_token' => $token));
  117. }
  118. // Display form
  119. Display::display_header($tool_name);
  120. //api_display_tool_title($tool_name);
  121. if (!empty($message)) {
  122. Display::display_normal_message(stripslashes($message));
  123. }
  124. $form->display();
  125. // Footer
  126. Display::display_footer();