group_add.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $language_file= 'userInfo';
  8. $cidReset=true;
  9. require_once '../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') !='true') {
  12. api_not_allowed();
  13. }
  14. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  15. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  16. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  17. if (api_get_setting('allow_students_to_create_groups_in_social') == 'false' && !api_is_allowed_to_edit()) {
  18. api_not_allowed();
  19. }
  20. global $charset;
  21. //jquery already called from main/inc/header.inc.php
  22. $htmlHeadXtra[] = '<script type="text/javascript">
  23. textarea = "";
  24. num_characters_permited = 255;
  25. function text_longitud(){
  26. num_characters = document.forms[0].description.value.length;
  27. if (num_characters > num_characters_permited){
  28. document.forms[0].description.value = textarea;
  29. }else{
  30. textarea = document.forms[0].description.value;
  31. }
  32. }
  33. </script>
  34. <style>
  35. div.row div.label {
  36. width:15%;
  37. }
  38. div.row div.formw {
  39. width:80%;
  40. }
  41. </style>';
  42. $table_message = Database::get_main_table(TABLE_MESSAGE);
  43. $form = new FormValidator('add_group');
  44. // name
  45. $form->addElement('text', 'name', get_lang('Name'), array('size'=>60, 'maxlength'=>120));
  46. $form->applyFilter('name', 'html_filter');
  47. $form->applyFilter('name', 'trim');
  48. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  49. // Description
  50. $form->addElement('textarea', 'description', get_lang('Description'), array('rows'=>3, 'cols'=>58, onKeyDown => "text_longitud()", onKeyUp => "text_longitud()"));
  51. $form->applyFilter('description', 'html_filter');
  52. $form->applyFilter('description', 'trim');
  53. // url
  54. $form->addElement('text', 'url', get_lang('URL'), array('size'=>35));
  55. $form->applyFilter('url', 'html_filter');
  56. $form->applyFilter('url', 'trim');
  57. // Picture
  58. $form->addElement('file', 'picture', get_lang('AddPicture'));
  59. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  60. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  61. // Status
  62. $status = array();
  63. $status[GROUP_PERMISSION_OPEN] = get_lang('Open');
  64. $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
  65. $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status);
  66. $form->addElement('style_submit_button','add_group', get_lang('AddGroup'),'class="save"');
  67. $form->setRequiredNote(api_xml_http_response_encode('<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>'));
  68. $form->setDefaults($default);
  69. if ($form->validate()) {
  70. $values = $form->exportValues();
  71. $picture_element = & $form->getElement('picture');
  72. $picture = $picture_element->getValue();
  73. $picture_uri = '';
  74. $name = $values['name'];
  75. $description = $values['description'];
  76. $url = $values['url'];
  77. $status = intval($values['visibility']);
  78. $picture = $_FILES['picture'];
  79. $group_id = GroupPortalManager::add($name, $description, $url, $status);
  80. GroupPortalManager::add_user_to_group(api_get_user_id(), $group_id,GROUP_USER_PERMISSION_ADMIN);
  81. if (!empty($picture['name'])) {
  82. $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
  83. GroupPortalManager::update($group_id, $name, $description, $url,$status, $picture_uri);
  84. }
  85. header('Location: groups.php?id='.$group_id.'&action=show_message&message='.urlencode(get_lang('GroupAdded')));
  86. exit();
  87. }
  88. $nameTools = get_lang('AddGroup');
  89. $this_section = SECTION_SOCIAL;
  90. $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('Social'));
  91. $interbreadcrumb[]= array ('url' =>'groups.php','name' => get_lang('Groups'));
  92. $interbreadcrumb[]= array ('url' =>'#','name' => $nameTools);
  93. Display :: display_header($tool_name, 'Groups');
  94. echo '<div id="social-content">';
  95. echo '<div id="social-content-left">';
  96. //show the action menu
  97. SocialManager::show_social_menu('group_add');
  98. echo '</div>';
  99. echo '<div id="social-content-right">';
  100. $form->display();
  101. echo '</div>';
  102. echo '</div>';
  103. Display :: display_footer();