group_add.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. // Including necessary libraries.
  8. require_once '../inc/global.inc.php';
  9. $libpath = api_get_path(LIBRARY_PATH);
  10. // Section for the tabs
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. // User permissions
  13. api_protect_admin_script();
  14. $group_id = 0;
  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->addButtonCreate(get_lang('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(
  102. $group_id,
  103. $name,
  104. $description,
  105. $url,
  106. $status,
  107. $picture_uri
  108. );
  109. }
  110. //@todo send emails
  111. /* if (!empty($email) && $send_mail) {
  112. $recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
  113. $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
  114. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  115. $email_admin = api_get_setting('emailAdministrator');
  116. if ($_configuration['multiple_access_urls']) {
  117. $access_url_id = api_get_current_access_url_id();
  118. if ($access_url_id != -1) {
  119. $url = api_get_access_url($access_url_id);
  120. $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('SignatureFormula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
  121. }
  122. }
  123. else {
  124. $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('SignatureFormula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
  125. }
  126. @api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
  127. }*/
  128. Security::clear_token();
  129. $tok = Security::get_token();
  130. header('Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupAdded')).'&sec_token='.$tok);
  131. exit ();
  132. }
  133. } else {
  134. if (isset($_POST['submit'])) {
  135. Security::clear_token();
  136. }
  137. $token = Security::get_token();
  138. $form->addElement('hidden', 'sec_token');
  139. $form->setConstants(array('sec_token' => $token));
  140. }
  141. // Display form
  142. Display::display_header($tool_name);
  143. if (!empty($message)) {
  144. Display::display_normal_message(stripslashes($message));
  145. }
  146. $form->display();
  147. // Footer
  148. Display::display_footer();