Fix class/users relations see BT#13493

pull/2487/head
jmontoyaa 7 years ago
parent 374f67a595
commit 6105679fd5
  1. 10
      main/admin/add_users_to_usergroup.php
  2. 21
      main/inc/lib/usergroup.lib.php
  3. 2
      main/user/class.php

@ -39,12 +39,9 @@ $(document).ready( function() {
});
function add_user_to_session (code, content) {
document.getElementById("user_to_add").value = "";
document.getElementById("ajax_list_users_single").innerHTML = "";
destination = document.getElementById("elements_in");
for (i=0;i<destination.length;i++) {
if(destination.options[i].text == content) {
return false;
@ -125,10 +122,9 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$elements_posted = array();
}
// If "social group" you need to select a role
if ($groupInfo['group_type'] == 1 && empty($relation)) {
Display::addFlash(Display::return_message(get_lang('SelectRole')));
header('Location: add_users_to_usergroup.php?id='.$id);
exit;
}
if ($form_sent == 1) {
@ -231,7 +227,6 @@ if ($orderListByOfficialCode === 'true') {
}
$conditions = array();
if (!empty($first_letter_user)) {
$conditions['lastname'] = $first_letter_user;
}
@ -308,9 +303,10 @@ if (!empty($user_list)) {
}
// Avoid anonymous users
if ($item['status'] == 6) {
if ($item['status'] == ANONYMOUS) {
continue;
}
$officialCode = !empty($item['official_code']) ? ' - '.$item['official_code'] : null;
$person_name = api_get_person_name(
$item['firstname'],

@ -473,9 +473,18 @@ class UserGroup extends Model
{
$relationCondition = '';
if (!empty($relationList)) {
$relationList = array_map('intval', $relationList);
$relationListToString = implode("', '", $relationList);
$relationCondition = " AND relation_type IN('$relationListToString')";
$relationConditionArray = [];
foreach ($relationList as $relation) {
$relation = (int) $relation;
if (empty($relation)) {
$relationConditionArray[] = " (relation_type = 0 OR relation_type IS NULL OR relation_type = '') ";
} else {
$relationConditionArray[] = " relation_type = $relation ";
}
}
$relationCondition = " AND ( ";
$relationCondition .= implode("AND", $relationConditionArray);
$relationCondition .= " ) ";
}
if (empty($id)) {
@ -507,8 +516,12 @@ class UserGroup extends Model
public function getUsersByUsergroupAndRelation($id, $relation = 0)
{
$relation = (int) $relation;
if (empty($relation)) {
$conditions = array('where' => array('usergroup_id = ? AND (relation_type = 0 OR relation_type IS NULL OR relation_type = "") ' => [$id]));
} else {
$conditions = array('where' => array('usergroup_id = ? AND relation_type = ?' => [$id, $relation]));
}
$conditions = array('where' => array('usergroup_id = ? AND relation_type = ?' => [$id, $relation]));
$results = Database::select(
'user_id',
$this->usergroup_rel_user_table,

@ -86,6 +86,8 @@ if (api_is_allowed_to_edit()) {
false
);
Display::addFlash(Display::return_message(get_lang('Added')));
header('Location: class.php?'.api_get_cidreq().'&type=registered');
exit;
}
break;
case 'remove_class_from_course':

Loading…
Cancel
Save