group_add.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. //@todo send emails
  104. /* if (!empty($email) && $send_mail) {
  105. $recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
  106. $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
  107. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  108. $email_admin = api_get_setting('emailAdministrator');
  109. if ($_configuration['multiple_access_urls']) {
  110. $access_url_id = api_get_current_access_url_id();
  111. if ($access_url_id != -1) {
  112. $url = api_get_access_url($access_url_id);
  113. $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('Formula').",\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');
  114. }
  115. }
  116. else {
  117. $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('Formula').",\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');
  118. }
  119. api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
  120. }*/
  121. Security::clear_token();
  122. $tok = Security::get_token();
  123. header(
  124. 'Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupAdded')).'&sec_token='.$tok
  125. );
  126. exit ();
  127. }
  128. } else {
  129. if (isset($_POST['submit'])) {
  130. Security::clear_token();
  131. }
  132. $token = Security::get_token();
  133. $form->addElement('hidden', 'sec_token');
  134. $form->setConstants(array('sec_token' => $token));
  135. }
  136. // Display form
  137. Display::display_header($tool_name);
  138. //api_display_tool_title($tool_name);
  139. if (!empty($message)) {
  140. Display::display_normal_message(stripslashes($message));
  141. }
  142. $form->display();
  143. // Footer
  144. Display::display_footer();