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

@ -121,6 +121,11 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
$res = $usergroup->save($values);
if ($res) {
Display::display_confirmation_message(get_lang('ItemAdded'));
} else {
Display::display_warning_message(
Security::remove_XSS($values['name']).': '.
get_lang('AlreadyExists')
);
}
}
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']));
// Setting the form elements
$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->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"');

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