Usergroup (clases) have unique names in creation see BT#8689

1.9.x
Julio Montoya 11 years ago
parent 09fe93c662
commit 3547a45ddb
  1. 25
      main/admin/usergroup_import.php
  2. 7
      main/admin/usergroups.php
  3. 15
      main/inc/lib/usergroup.lib.php

@ -1,13 +1,10 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* This tool allows platform admins to add classes by uploading a CSV file
* @todo Add some langvars to DLTT
* @package chamilo.admin * @package chamilo.admin
*/ */
/**
* Code
* This tool allows platform admins to add classes by uploading a CSV file
* @todo Add some langvars to DLTT
*/
/** /**
* Validates imported data. * Validates imported data.
@ -21,23 +18,29 @@ function validate_data($classes) {
$class['line'] = $index + 2; $class['line'] = $index + 2;
$class['error'] = get_lang('MissingClassName'); $class['error'] = get_lang('MissingClassName');
$errors[] = $class; $errors[] = $class;
} } else {
// 2. Check whether class doesn't exist yet. // 2. Check whether class doesn't exist yet.
else {
if ($usergroup->usergroup_exists($class['name'])) { if ($usergroup->usergroup_exists($class['name'])) {
$class['line'] = $index + 2; $class['line'] = $index + 2;
$class['error'] = get_lang('ClassNameExists') . ' <strong>' . $class['ClassName'] . '</strong>'; $class['error'] = get_lang('ClassNameExists') .
': <strong>' .$class['name'] . '</strong>';
$errors[] = $class; $errors[] = $class;
} }
} }
} }
return $errors; return $errors;
} }
/** /**
* Save imported class data to database * Save imported class data to database
*
* @param $classes
*
* @return int
*/ */
function save_data($classes) { function save_data($classes)
{
$number_of_added_classes = 0; $number_of_added_classes = 0;
$usergroup = new UserGroup(); $usergroup = new UserGroup();
foreach ($classes as $index => $class) { foreach ($classes as $index => $class) {
@ -115,4 +118,4 @@ $form->display();
</pre> </pre>
<?php <?php
// Displaying the footer. // Displaying the footer.
Display :: display_footer(); Display :: display_footer();

@ -121,6 +121,11 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
$res = $usergroup->save($values); $res = $usergroup->save($values);
if ($res) { if ($res) {
Display::display_confirmation_message(get_lang('ItemAdded')); Display::display_confirmation_message(get_lang('ItemAdded'));
} else {
Display::display_warning_message(
Security::remove_XSS($values['name']).': '.
get_lang('AlreadyExists')
);
} }
} }
Security::clear_token(); Security::clear_token();
@ -140,7 +145,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
$form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id'])); $form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
// Setting the form elements // Setting the form elements
$form->addElement('header', '', get_lang('Modify')); $form->addElement('header', '', get_lang('Modify'));
$form->addElement('hidden', 'id',intval($_GET['id'])); $form->addElement('hidden', 'id', intval($_GET['id']));
$form->addElement('text', 'name', get_lang('Name'), array('size' => '70')); $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
$form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250')); $form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');

@ -749,15 +749,20 @@ class UserGroup extends Model
/** /**
* @param $params * @param $params
* @param bool $show_query * @param bool $show_query
* @return bool|void * @return bool|int
*/ */
public function save($params, $show_query = false) public function save($params, $show_query = false)
{ {
$id = parent::save($params, $show_query); $groupExists = $this->usergroup_exists(trim($params['name']));
if ($this->useMultipleUrl) { if ($groupExists == false) {
$this->subscribeToUrl($id, api_get_current_access_url_id()); $id = parent::save($params, $show_query);
if ($this->useMultipleUrl) {
$this->subscribeToUrl($id, api_get_current_access_url_id());
}
return $id;
} }
return $id;
return false;
} }
/** /**

Loading…
Cancel
Save