@ -16,7 +16,7 @@ require_once '../inc/global.inc.php';
require_once '../inc/lib/xajax/xajax.inc.php';
global $_configuration;
$ajax_search = false;
// create an ajax object
$xajax = new xajax();
$xajax->registerFunction('search_users');
@ -41,6 +41,8 @@ $user_info = api_get_user_info($user_id);
$user_anonymous = api_get_anonymous_id();
$current_user_id = api_get_user_id();
$firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null;
// setting the name of the tool
if (UserManager::is_admin($user_id)) {
$tool_name= get_lang('AssignUsersToPlatformAdministrator');
@ -61,7 +63,7 @@ if (!api_is_platform_admin()) {
function search_users($needle,$type)
{
global $_configuration,$ tbl_access_url_rel_user, $tbl_user, $user_anonymous, $current_user_id, $user_id;
global $tbl_access_url_rel_user, $tbl_user, $user_anonymous, $current_user_id, $user_id;
$xajax_response = new XajaxResponse();
$return = '';
@ -74,19 +76,40 @@ function search_users($needle,$type)
$assigned_users_id = array_keys($assigned_users_to_hrm);
$without_assigned_users = '';
$westernOrder = api_is_western_name_order();
if ($westernOrder) {
$order_clause = " ORDER BY firstname, lastname";
} else {
$order_clause = " ORDER BY lastname, firstname";
}
if (count($assigned_users_id) > 0) {
$without_assigned_users = " AND user.user_id NOT IN(".implode(',',$assigned_users_id).")";
$without_assigned_users = " AND user.user_id NOT IN(".implode(',', $assigned_users_id).")";
}
if (api_is_multiple_url_enabled()) {
$sql = "SELECT user.user_id, username, lastname, firstname
FROM $tbl_user user LEFT JOIN $tbl_access_url_rel_user au ON (au.user_id = user.user_id)
WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND status NOT IN(".DRH.", ".SESSIONADMIN.") AND user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) $without_assigned_users AND access_url_id = ".api_get_current_access_url_id()."";
FROM $tbl_user user
LEFT JOIN $tbl_access_url_rel_user au ON (au.user_id = user.user_id)
WHERE
".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND
status NOT IN(".DRH.", ".SESSIONADMIN.") AND
user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id)
$without_assigned_users AND
access_url_id = ".api_get_current_access_url_id()."
$order_clause
";
} else {
$sql = "SELECT user_id, username, lastname, firstname
FROM $tbl_user user
WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND status NOT IN(".DRH.", ".SESSIONADMIN.") AND user_id NOT IN ($user_anonymous, $current_user_id, $user_id) $without_assigned_users";
WHERE
".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND
status NOT IN(".DRH.", ".SESSIONADMIN.") AND
user_id NOT IN ($user_anonymous, $current_user_id, $user_id)
$without_assigned_users
$order_clause
";
}
$rs = Database::query($sql);
@ -99,9 +122,14 @@ function search_users($needle,$type)
$sql = 'SELECT user.user_id, username, lastname, firstname
FROM '.$tbl_user.' user
INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
WHERE access_url_id = '.$access_url_id.' AND (username LIKE "'.$needle.'%"
OR firstname LIKE "'.$needle.'%"
OR lastname LIKE "'.$needle.'%") AND user.status< >6 AND user.status< >'.DRH.' '.
WHERE
access_url_id = '.$access_url_id.' AND
(
username LIKE "'.$needle.'%" OR
firstname LIKE "'.$needle.'%" OR
lastname LIKE "'.$needle.'%"
) AND
user.status< >6 AND user.status< >'.DRH.' '.
$order_clause.
' LIMIT 11';
$rs = Database::query($sql);
@ -198,13 +226,49 @@ function remove_item(origin) {
< / script > ';
$formSent=0;
$errorMsg = $firstLetterUser = '';
$errorMsg = '';
$UserList = array();
// Filters
$filters = array(
array('type' => 'text', 'name' => 'username', 'label' => get_lang('Username')),
array('type' => 'text', 'name' => 'firstname', 'label' => get_lang('FirstName')),
array('type' => 'text', 'name' => 'lastname', 'label' => get_lang('LastName')),
array('type' => 'text', 'name' => 'official_code', 'label' => get_lang('OfficialCode')),
array('type' => 'text', 'name' => 'email', 'label' => get_lang('Email'))
);
$searchForm = new FormValidator('search', 'get', api_get_self().'?user='.$user_id);
$searchForm->add_header(get_lang('AdvancedSearch'));
$renderer =& $searchForm->defaultRenderer();
$searchForm->addElement('hidden', 'user', $user_id);
foreach ($filters as $param) {
$searchForm->addElement($param['type'], $param['name'], $param['label']);
}
$searchForm->addElement('button', 'submit', get_lang('Search'));
$filterData = array();
if ($searchForm->validate()) {
$filterData = $searchForm->getSubmitValues();
}
$conditions = array();
if (!empty($filters) & & !empty($filterData)) {
foreach ($filters as $filter) {
if (isset($filter['name']) & & isset($filterData[$filter['name']])) {
$value = $filterData[$filter['name']];
if (!empty($value)) {
$conditions[$filter['name']] = $value;
}
}
}
}
$msg = '';
if (isset($_POST['formSent']) & & intval($_POST['formSent']) == 1) {
$user_list = $_POST['UsersList'];
$affected_rows = UserManager::suscribe_users_to_hr_manager($user_id,$user_list);
$affected_rows = UserManager::suscribe_users_to_hr_manager($user_id, $user_list);
if ($affected_rows) {
$msg = get_lang('AssignedUsersHaveBeenUpdatedSuccessfully');
}
@ -214,13 +278,22 @@ if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
Display::display_header($tool_name);
// actions
echo '< div class = "actions" >
< span style = "float: right;margin:0px;padding:0px;" >
< a href = "dashboard_add_courses_to_user.php?user='.$user_id.'" > '.Display::return_icon('course_add.gif', get_lang('AssignCourses'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignCourses').'< / a >
< a href = "dashboard_add_sessions_to_user.php?user='.$user_id.'" > '.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignSessions').'< / a > < / span >
< / div > ';
echo Display::page_header(sprintf(get_lang('AssignUsersToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])));
echo '< div class = "actions" > ';
echo '< span style = "float: right;margin:0px;padding:0px;" >
< a href = "dashboard_add_courses_to_user.php?user='.$user_id.'" > '.
Display::return_icon('course_add.gif', get_lang('AssignCourses'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignCourses').'< / a >
< a href = "dashboard_add_sessions_to_user.php?user='.$user_id.'" > '.
Display::return_icon('view_more_stats.gif', get_lang('AssignSessions'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignSessions').'< / a > < / span > ';
echo Display::url(get_lang('AdvancedSearch'), '#', array('class' => 'advanced_options', 'id' => 'advanced_search'));
echo '< / div > ';
echo '< div id = "advanced_search_options" style = "display:none" > ';
$searchForm->display();
echo '< / div > ';
echo Display::page_header(
sprintf(get_lang('AssignUsersToX'), api_get_person_name($user_info['firstname'], $user_info['lastname']))
);
$assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id);
$assigned_users_id = array_keys($assigned_users_to_hrm);
@ -230,20 +303,46 @@ if (count($assigned_users_id) > 0) {
}
$search_user = '';
if (isset($_POST['firstLetterUser'] )) {
$needle = Database::escape_string($_POST[' firstLetterUser'] );
if (!empty($firstLetterUser )) {
$needle = Database::escape_string($firstLetterUser);
$search_user ="AND ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%'";
}
$sqlConditions = null;
if (!empty($conditions)) {
$temp_conditions = array();
foreach ($conditions as $field => $value) {
$field = Database::escape_string($field);
$value = Database::escape_string($value);
$temp_conditions[] = $field.' LIKE \'%'.$value.'%\'';
}
if (!empty($temp_conditions)) {
$sqlConditions .= implode(' AND ', $temp_conditions);
}
if (!empty($sqlConditions)) {
$sqlConditions = " AND $sqlConditions";
}
}
if (api_is_multiple_url_enabled()) {
$sql = "SELECT user.user_id, username, lastname, firstname
FROM $tbl_user user LEFT JOIN $tbl_access_url_rel_user au ON (au.user_id = user.user_id)
WHERE $without_assigned_users user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND status NOT IN(".DRH.", ".SESSIONADMIN.") $search_user AND access_url_id = ".api_get_current_access_url_id()."
WHERE
$without_assigned_users
user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND
status NOT IN(".DRH.", ".SESSIONADMIN.") $search_user AND
access_url_id = ".api_get_current_access_url_id()."
$sqlConditions
ORDER BY firstname";
} else {
$sql = "SELECT user_id, username, lastname, firstname
FROM $tbl_user user
WHERE $without_assigned_users user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND status NOT IN(".DRH.", ".SESSIONADMIN.") $search_user
WHERE
$without_assigned_users
user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND
status NOT IN(".DRH.", ".SESSIONADMIN.")
$search_user
$sqlConditions
ORDER BY firstname ";
}
$result = Database::query($sql);
@ -283,7 +382,7 @@ if(!empty($msg)) {
< select name = "firstLetterUser" onchange = "xajax_search_users(this.value,'multiple')" >
< option value = "%" > --< / option >
<?php
echo Display :: get_alphabet_options($_POST[' firstLetterUser'] );
echo Display::get_alphabet_options($firstLetterUser);
?>
< / select >
< input type = "text" id = "user_to_add" onkeyup = "xajax_search_users(this.value,'single')" onclick = "moveItem(document.getElementById('user_to_add'), document.getElementById('destination'))" / >
@ -299,24 +398,20 @@ if(!empty($msg)) {
while ($enreg = Database::fetch_array($result)) {
$person_name = api_get_person_name($enreg['firstname'], $enreg['lastname']);
?>
< option value = " <?php echo $enreg [ 'user_id' ]; ?> " <?php echo 'title="' . htmlspecialchars ( $person_name , ENT_QUOTES ) . '"' ; ?> > <?php echo $person_name . ' (' . $enreg [ 'username' ] . ')' ; ?> </ option >
< option value = " <?php echo $enreg [ 'user_id' ]; ?> " <?php echo 'title="' . htmlspecialchars ( $person_name , ENT_QUOTES ) . '"' ; ?> >
<?php echo $person_name . ' (' . $enreg [ 'username' ] . ')' ; ?>
< / option >
<?php } ?>
< / select > < / div >
< / td >
< td width = "10%" valign = "middle" align = "center" >
<?php
if ($ajax_search) {
?>
< button class = "arrowl" type = "button" onclick = "remove_item(document.getElementById('destination'))" > < / button >
<?php
}
else
{
?>
< button class = "arrowr" type = "button" onclick = "moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick = "moveItem(document.getElementById('origin'), document.getElementById('destination'))" > < / button >
< br / > < br / >
< button class = "arrowl" type = "button" onclick = "moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick = "moveItem(document.getElementById('destination'), document.getElementById('origin'))" > < / button >
<?php if ( $ajax_search ) { ?>
< button class = "arrowl" type = "button" onclick = "remove_item(document.getElementById('destination'))" > < / button >
<?php } else { ?>
< button class = "arrowr" type = "button" onclick = "moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick = "moveItem(document.getElementById('origin'), document.getElementById('destination'))" > < / button >
< br / > < br / >
< button class = "arrowl" type = "button" onclick = "moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick = "moveItem(document.getElementById('destination'), document.getElementById('origin'))" > < / button >
<?php
}
?>
@ -332,7 +427,9 @@ if(!empty($msg)) {
foreach($assigned_users_to_hrm as $enreg) {
$person_name = api_get_person_name($enreg['firstname'], $enreg['lastname']);
?>
< option value = " <?php echo $enreg [ 'user_id' ]; ?> " <?php echo 'title="' . htmlspecialchars ( $person_name , ENT_QUOTES ) . '"' ; ?> > <?php echo $person_name . ' (' . $enreg [ 'username' ] . ')' ; ?> </ option >
< option value = " <?php echo $enreg [ 'user_id' ]; ?> " <?php echo 'title="' . htmlspecialchars ( $person_name , ENT_QUOTES ) . '"' ; ?> >
<?php echo $person_name . ' (' . $enreg [ 'username' ] . ')' ; ?>
< / option >
<?php }
}?>
< / select > < / td >