parent
663a78f34a
commit
082978f6d9
@ -0,0 +1,386 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @package chamilo.admin |
||||
*/ |
||||
|
||||
// name of the language file that needs to be included |
||||
$language_file=array('admin','registration'); |
||||
|
||||
// resetting the course id |
||||
$cidReset=true; |
||||
|
||||
// including some necessary files |
||||
require_once '../inc/global.inc.php'; |
||||
require_once '../inc/lib/xajax/xajax.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php'; |
||||
|
||||
$xajax = new xajax(); |
||||
|
||||
//$xajax->debugOn(); |
||||
$xajax->registerFunction('search'); |
||||
|
||||
// setting the section (for the tabs) |
||||
$this_section = SECTION_PLATFORM_ADMIN; |
||||
|
||||
// Access restrictions |
||||
api_protect_admin_script(true); |
||||
|
||||
// setting breadcrumbs |
||||
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin')); |
||||
$interbreadcrumb[]=array('url' => 'usergroups.php','name' => get_lang('UserGroups')); |
||||
|
||||
// Database Table Definitions |
||||
|
||||
// setting the name of the tool |
||||
$tool_name=get_lang('SubscribeSessionsToUserGroup'); |
||||
|
||||
$add_type = 'multiple'; |
||||
if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){ |
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']); |
||||
} |
||||
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); |
||||
$htmlHeadXtra[] = ' |
||||
<script type="text/javascript"> |
||||
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; |
||||
} |
||||
} |
||||
|
||||
destination.options[destination.length] = new Option(content,code); |
||||
destination.selectedIndex = -1; |
||||
sortOptions(destination.options); |
||||
} |
||||
function remove_item(origin) { |
||||
for(var i = 0 ; i<origin.options.length ; i++) { |
||||
if(origin.options[i].selected) { |
||||
origin.options[i]=null; |
||||
i = i-1; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function validate_filter() { |
||||
document.formulaire.add_type.value = \''.$add_type.'\'; |
||||
document.formulaire.form_sent.value=0; |
||||
document.formulaire.submit(); |
||||
} |
||||
</script>'; |
||||
|
||||
|
||||
$form_sent = 0; |
||||
$errorMsg = ''; |
||||
$sessions=array(); |
||||
$usergroup = new UserGroup(); |
||||
$id = intval($_GET['id']); |
||||
if($_POST['form_sent']) { |
||||
$form_sent = $_POST['form_sent']; |
||||
$elements_posted = $_POST['elements_in_name']; |
||||
if (!is_array($elements_posted)) { |
||||
$elements_posted=array(); |
||||
} |
||||
if ($form_sent == 1) { |
||||
//added a parameter to send emails when registering a user |
||||
$usergroup->subscribe_courses_to_usergroup($id, $elements_posted); |
||||
header('Location: usergroups.php'); |
||||
exit; |
||||
} |
||||
} |
||||
$data = $usergroup->get($id); |
||||
$course_list_in = $usergroup->get_courses_by_usergroup($id); |
||||
$course_list = CourseManager::get_courses_list(); |
||||
|
||||
//api_display_tool_title($tool_name.' ('.$session_info['name'].')'); |
||||
$elements_not_in = $elements_in= array(); |
||||
|
||||
if (!empty($course_list)) { |
||||
foreach($course_list as $item) { |
||||
if (in_array($item['id'], $course_list_in)) { |
||||
$elements_in[$item['id']] = $item['title']; |
||||
} else { |
||||
$elements_not_in[$item['id']] = $item['title']; |
||||
} |
||||
} |
||||
} |
||||
$ajax_search = $add_type == 'unique' ? true : false; |
||||
|
||||
//checking for extra field with filter on |
||||
|
||||
function search($needle,$type) { |
||||
global $tbl_user,$elements_in; |
||||
$xajax_response = new XajaxResponse(); |
||||
$return = ''; |
||||
if (!empty($needle) && !empty($type)) { |
||||
|
||||
// xajax send utf8 datas... datas in db can be non-utf8 datas |
||||
$charset = api_get_system_encoding(); |
||||
$needle = Database::escape_string($needle); |
||||
$needle = api_convert_encoding($needle, $charset, 'utf-8'); |
||||
|
||||
if ($type == 'single') { |
||||
// search users where username or firstname or lastname begins likes $needle |
||||
/* $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user |
||||
WHERE (username LIKE "'.$needle.'%" |
||||
OR firstname LIKE "'.$needle.'%" |
||||
OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'" AND user.status<>'.DRH.''. |
||||
$order_clause. |
||||
' LIMIT 11';*/ |
||||
} else { |
||||
$list = CourseManager::get_courses_list(0, 0, 1, 'ASC', -1, $needle); |
||||
} |
||||
$i=0; |
||||
if ($type=='single') { |
||||
/* |
||||
while ($user = Database :: fetch_array($rs)) { |
||||
$i++; |
||||
if ($i<=10) { |
||||
$person_name = api_get_person_name($user['firstname'], $user['lastname']); |
||||
$return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />'; |
||||
} else { |
||||
$return .= '...<br />'; |
||||
} |
||||
} |
||||
$xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/ |
||||
} else { |
||||
$return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">'; |
||||
|
||||
foreach ($list as $row ) { |
||||
if (!in_array($row['id'], array_keys($elements_in))) { |
||||
$return .= '<option value="'.$row['id'].'">'.$row['title'].'</option>'; |
||||
} |
||||
} |
||||
$return .= '</select>'; |
||||
$xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return)); |
||||
} |
||||
} |
||||
return $xajax_response; |
||||
} |
||||
$xajax -> processRequests(); |
||||
|
||||
Display::display_header($tool_name); |
||||
|
||||
if ($add_type == 'multiple') { |
||||
$link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>'; |
||||
$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'); |
||||
} else { |
||||
$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'); |
||||
$link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>'; |
||||
} |
||||
|
||||
echo '<div class="actions">'; |
||||
echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>'; |
||||
echo '</div>'; |
||||
|
||||
echo '<div class="row"><div class="form_header">'.$tool_name.' '.$data['name'].'</div></div><br/>'; ?> |
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
|
||||
|
||||
<?php |
||||
if ($add_type=='multiple') { |
||||
if (is_array($extra_field_list)) { |
||||
if (is_array($new_field_list) && count($new_field_list)>0 ) { |
||||
echo '<h3>'.get_lang('FilterUsers').'</h3>'; |
||||
foreach ($new_field_list as $new_field) { |
||||
echo $new_field['name']; |
||||
$varname = 'field_'.$new_field['variable']; |
||||
echo ' <select name="'.$varname.'">'; |
||||
echo '<option value="0">--'.get_lang('Select').'--</option>'; |
||||
foreach ($new_field['data'] as $option) { |
||||
$checked=''; |
||||
if (isset($_POST[$varname])) { |
||||
if ($_POST[$varname]==$option[1]) { |
||||
$checked = 'selected="true"'; |
||||
} |
||||
} |
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>'; |
||||
} |
||||
echo '</select>'; |
||||
echo ' '; |
||||
} |
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />'; |
||||
echo '<br /><br />'; |
||||
} |
||||
} |
||||
} |
||||
echo Display::input('hidden','id',$id); |
||||
echo Display::input('hidden','form_sent','1'); |
||||
echo Display::input('hidden','add_type',null); |
||||
if(!empty($errorMsg)) { |
||||
Display::display_normal_message($errorMsg); //main API |
||||
} |
||||
?> |
||||
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%"> |
||||
<tr> |
||||
<td align="center"><b><?php echo get_lang('CoursesInPlatform') ?> :</b>
|
||||
</td> |
||||
<td></td> |
||||
<td align="center"><b><?php echo get_lang('CoursesInGroup') ?> :</b></td>
|
||||
</tr> |
||||
|
||||
<?php if ($add_type=='multiple') { ?> |
||||
<tr> |
||||
<td align="center"> |
||||
<?php echo get_lang('FirstLetterSessions'); ?> :
|
||||
<select name="firstLetterUser" onchange = "xajax_search(this.value,'multiple')" > |
||||
<option value = "%">--</option> |
||||
<?php |
||||
echo Display :: get_alphabet_options(); |
||||
?> |
||||
</select> |
||||
</td> |
||||
<td align="center"> </td> |
||||
</tr> |
||||
<?php } ?> |
||||
<tr> |
||||
<td align="center"> |
||||
<div id="content_source"> |
||||
<?php
|
||||
if (!($add_type=='multiple')) { |
||||
?> |
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" /> |
||||
<div id="ajax_list_users_single"></div> |
||||
<?php |
||||
} else { |
||||
?> |
||||
<div id="ajax_list_multiple"> |
||||
<?php echo Display::select('elements_not_in_name',$elements_not_in, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?>
|
||||
</div> |
||||
<?php |
||||
} |
||||
?> |
||||
</div> |
||||
</td> |
||||
<td width="10%" valign="middle" align="center"> |
||||
<?php |
||||
if ($ajax_search) { |
||||
?> |
||||
<button class="arrowl" type="button" onclick="remove_item(document.getElementById('elements_in'))" ></button> |
||||
<?php |
||||
} else { |
||||
?> |
||||
<button class="arrowr" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"></button> |
||||
<br /><br /> |
||||
<button class="arrowl" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))"></button> |
||||
<?php |
||||
} |
||||
?> |
||||
<br /><br /><br /><br /><br /><br /> |
||||
</td> |
||||
<td align="center"> |
||||
<?php |
||||
echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false ); |
||||
unset($sessionUsersList); |
||||
?> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td colspan="3" align="center"> |
||||
<br /> |
||||
<?php |
||||
echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeCoursesToGroup').'</button>'; |
||||
?> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</form> |
||||
|
||||
<script type="text/javascript"> |
||||
<!-- |
||||
function moveItem(origin , destination){ |
||||
|
||||
for(var i = 0 ; i<origin.options.length ; i++) { |
||||
if(origin.options[i].selected) { |
||||
destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value); |
||||
origin.options[i]=null; |
||||
i = i-1; |
||||
} |
||||
} |
||||
destination.selectedIndex = -1; |
||||
sortOptions(destination.options); |
||||
|
||||
} |
||||
|
||||
function sortOptions(options) { |
||||
|
||||
newOptions = new Array(); |
||||
for (i = 0 ; i<options.length ; i++) |
||||
newOptions[i] = options[i]; |
||||
|
||||
newOptions = newOptions.sort(mysort); |
||||
options.length = 0; |
||||
for(i = 0 ; i < newOptions.length ; i++) |
||||
options[i] = newOptions[i]; |
||||
|
||||
} |
||||
|
||||
function mysort(a, b){ |
||||
if(a.text.toLowerCase() > b.text.toLowerCase()){ |
||||
return 1; |
||||
} |
||||
if(a.text.toLowerCase() < b.text.toLowerCase()){ |
||||
return -1; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
function valide(){ |
||||
var options = document.getElementById('elements_in').options; |
||||
for (i = 0 ; i<options.length ; i++) |
||||
options[i].selected = true; |
||||
document.forms.formulaire.submit(); |
||||
} |
||||
|
||||
|
||||
function loadUsersInSelect(select){ |
||||
|
||||
var xhr_object = null; |
||||
|
||||
if(window.XMLHttpRequest) // Firefox |
||||
xhr_object = new XMLHttpRequest(); |
||||
else if(window.ActiveXObject) // Internet Explorer |
||||
xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); |
||||
else // XMLHttpRequest non supporté par le navigateur |
||||
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); |
||||
|
||||
//xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
|
||||
xhr_object.open("POST", "loadUsersInSelect.ajax.php"); |
||||
|
||||
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
||||
|
||||
|
||||
nosessionUsers = makepost(document.getElementById('elements_not_in')); |
||||
sessionUsers = makepost(document.getElementById('elements_in')); |
||||
nosessionClasses = makepost(document.getElementById('origin_classes')); |
||||
sessionClasses = makepost(document.getElementById('destination_classes')); |
||||
xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses); |
||||
|
||||
xhr_object.onreadystatechange = function() { |
||||
if(xhr_object.readyState == 4) { |
||||
document.getElementById('content_source').innerHTML = result = xhr_object.responseText; |
||||
//alert(xhr_object.responseText); |
||||
} |
||||
} |
||||
} |
||||
|
||||
function makepost(select){ |
||||
var options = select.options; |
||||
var ret = ""; |
||||
for (i = 0 ; i<options.length ; i++) |
||||
ret = ret + options[i].value +'::'+options[i].text+";;"; |
||||
|
||||
return ret; |
||||
} |
||||
--> |
||||
</script> |
||||
<?php |
||||
Display::display_footer(); |
@ -0,0 +1,388 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @package chamilo.admin |
||||
*/ |
||||
|
||||
// name of the language file that needs to be included |
||||
$language_file=array('admin','registration'); |
||||
|
||||
// resetting the course id |
||||
$cidReset=true; |
||||
|
||||
// including some necessary files |
||||
require_once '../inc/global.inc.php'; |
||||
require_once '../inc/lib/xajax/xajax.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php'; |
||||
|
||||
$xajax = new xajax(); |
||||
|
||||
//$xajax->debugOn(); |
||||
$xajax->registerFunction('search_sessions'); |
||||
|
||||
// setting the section (for the tabs) |
||||
$this_section = SECTION_PLATFORM_ADMIN; |
||||
|
||||
// Access restrictions |
||||
api_protect_admin_script(true); |
||||
|
||||
// setting breadcrumbs |
||||
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin')); |
||||
$interbreadcrumb[]=array('url' => 'usergroups.php','name' => get_lang('UserGroups')); |
||||
|
||||
// Database Table Definitions |
||||
|
||||
// setting the name of the tool |
||||
$tool_name=get_lang('SubscribeSessionsToUserGroup'); |
||||
|
||||
$add_type = 'multiple'; |
||||
if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){ |
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']); |
||||
} |
||||
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); |
||||
$htmlHeadXtra[] = ' |
||||
<script type="text/javascript"> |
||||
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; |
||||
} |
||||
} |
||||
|
||||
destination.options[destination.length] = new Option(content,code); |
||||
destination.selectedIndex = -1; |
||||
sortOptions(destination.options); |
||||
} |
||||
function remove_item(origin) { |
||||
for(var i = 0 ; i<origin.options.length ; i++) { |
||||
if(origin.options[i].selected) { |
||||
origin.options[i]=null; |
||||
i = i-1; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function validate_filter() { |
||||
document.formulaire.add_type.value = \''.$add_type.'\'; |
||||
document.formulaire.form_sent.value=0; |
||||
document.formulaire.submit(); |
||||
} |
||||
</script>'; |
||||
|
||||
|
||||
$form_sent = 0; |
||||
$errorMsg = ''; |
||||
$sessions=array(); |
||||
$usergroup = new UserGroup(); |
||||
$id = intval($_GET['id']); |
||||
if($_POST['form_sent']) { |
||||
$form_sent = $_POST['form_sent']; |
||||
$elements_posted = $_POST['elements_in_name']; |
||||
if (!is_array($elements_posted)) { |
||||
$elements_posted = array(); |
||||
} |
||||
if ($form_sent == 1) { |
||||
//added a parameter to send emails when registering a user |
||||
$usergroup->subscribe_sessions_to_usergroup($id, $elements_posted); |
||||
header('Location: usergroups.php'); |
||||
exit; |
||||
} |
||||
} |
||||
$data = $usergroup->get($id); |
||||
$session_list_in = $usergroup->get_sessions_by_usergroup($id); |
||||
$session_list = SessionManager::get_sessions_list(array(), array('name')); |
||||
|
||||
//api_display_tool_title($tool_name.' ('.$session_info['name'].')'); |
||||
$elements_not_in = $elements_in= array(); |
||||
|
||||
if (!empty($session_list)) { |
||||
foreach($session_list as $session) { |
||||
if (in_array($session['id'], $session_list_in)) { |
||||
$elements_in[$session['id']] = $session['name']; |
||||
} else { |
||||
$elements_not_in[$session['id']] = $session['name']; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$ajax_search = $add_type == 'unique' ? true : false; |
||||
|
||||
//checking for extra field with filter on |
||||
|
||||
function search_sessions($needle,$type) { |
||||
global $tbl_user,$elements_in; |
||||
$xajax_response = new XajaxResponse(); |
||||
$return = ''; |
||||
if (!empty($needle) && !empty($type)) { |
||||
|
||||
// xajax send utf8 datas... datas in db can be non-utf8 datas |
||||
$charset = api_get_system_encoding(); |
||||
$needle = Database::escape_string($needle); |
||||
$needle = api_convert_encoding($needle, $charset, 'utf-8'); |
||||
|
||||
if ($type == 'single') { |
||||
// search users where username or firstname or lastname begins likes $needle |
||||
/* $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user |
||||
WHERE (username LIKE "'.$needle.'%" |
||||
OR firstname LIKE "'.$needle.'%" |
||||
OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'" AND user.status<>'.DRH.''. |
||||
$order_clause. |
||||
' LIMIT 11';*/ |
||||
} else { |
||||
$session_list = SessionManager::get_sessions_list(array('s.name LIKE' => "$needle%")); |
||||
} |
||||
$i=0; |
||||
if ($type=='single') { |
||||
/* |
||||
while ($user = Database :: fetch_array($rs)) { |
||||
$i++; |
||||
if ($i<=10) { |
||||
$person_name = api_get_person_name($user['firstname'], $user['lastname']); |
||||
$return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />'; |
||||
} else { |
||||
$return .= '...<br />'; |
||||
} |
||||
} |
||||
$xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/ |
||||
} else { |
||||
$return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">'; |
||||
|
||||
foreach ($session_list as $row ) { |
||||
if (!in_array($row['id'], array_keys($elements_in))) { |
||||
$return .= '<option value="'.$row['id'].'">'.$row['name'].'</option>'; |
||||
} |
||||
} |
||||
$return .= '</select>'; |
||||
$xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return)); |
||||
} |
||||
} |
||||
return $xajax_response; |
||||
} |
||||
$xajax -> processRequests(); |
||||
|
||||
Display::display_header($tool_name); |
||||
|
||||
if ($add_type == 'multiple') { |
||||
$link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>'; |
||||
$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'); |
||||
} else { |
||||
$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'); |
||||
$link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>'; |
||||
} |
||||
|
||||
echo '<div class="actions">'; |
||||
echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>'; |
||||
echo '</div>'; |
||||
|
||||
echo '<div class="row"><div class="form_header">'.$tool_name.' '.$data['name'].'</div></div><br/>'; ?> |
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
|
||||
|
||||
<?php |
||||
if ($add_type=='multiple') { |
||||
if (is_array($extra_field_list)) { |
||||
if (is_array($new_field_list) && count($new_field_list)>0 ) { |
||||
echo '<h3>'.get_lang('FilterUsers').'</h3>'; |
||||
foreach ($new_field_list as $new_field) { |
||||
echo $new_field['name']; |
||||
$varname = 'field_'.$new_field['variable']; |
||||
echo ' <select name="'.$varname.'">'; |
||||
echo '<option value="0">--'.get_lang('Select').'--</option>'; |
||||
foreach ($new_field['data'] as $option) { |
||||
$checked=''; |
||||
if (isset($_POST[$varname])) { |
||||
if ($_POST[$varname]==$option[1]) { |
||||
$checked = 'selected="true"'; |
||||
} |
||||
} |
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>'; |
||||
} |
||||
echo '</select>'; |
||||
echo ' '; |
||||
} |
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />'; |
||||
echo '<br /><br />'; |
||||
} |
||||
} |
||||
} |
||||
echo Display::input('hidden','id',$id); |
||||
echo Display::input('hidden','form_sent','1'); |
||||
echo Display::input('hidden','add_type',null); |
||||
if(!empty($errorMsg)) { |
||||
Display::display_normal_message($errorMsg); //main API |
||||
} |
||||
?> |
||||
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%"> |
||||
<tr> |
||||
<td align="center"><b><?php echo get_lang('SessionsInPlatform') ?> :</b>
|
||||
</td> |
||||
<td></td> |
||||
<td align="center"><b><?php echo get_lang('SessionsInGroup') ?> :</b></td>
|
||||
</tr> |
||||
|
||||
<?php if ($add_type=='multiple') { ?> |
||||
<tr> |
||||
<td align="center"> |
||||
<?php echo get_lang('FirstLetterSessions'); ?> :
|
||||
<select name="firstLetterUser" onchange = "xajax_search_sessions(this.value,'multiple')" > |
||||
<option value = "%">--</option> |
||||
<?php |
||||
echo Display :: get_alphabet_options(); |
||||
?> |
||||
</select> |
||||
</td> |
||||
<td align="center"> </td> |
||||
</tr> |
||||
<?php } ?> |
||||
<tr> |
||||
<td align="center"> |
||||
<div id="content_source"> |
||||
<?php
|
||||
if (!($add_type=='multiple')) { |
||||
?> |
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" /> |
||||
<div id="ajax_list_users_single"></div> |
||||
<?php |
||||
} else { |
||||
?> |
||||
<div id="ajax_list_multiple"> |
||||
<?php echo Display::select('elements_not_in_name',$elements_not_in, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?>
|
||||
</div> |
||||
<?php |
||||
} |
||||
?> |
||||
</div> |
||||
</td> |
||||
<td width="10%" valign="middle" align="center"> |
||||
<?php |
||||
if ($ajax_search) { |
||||
?> |
||||
<button class="arrowl" type="button" onclick="remove_item(document.getElementById('elements_in'))" ></button> |
||||
<?php |
||||
} else { |
||||
?> |
||||
<button class="arrowr" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"></button> |
||||
<br /><br /> |
||||
<button class="arrowl" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))"></button> |
||||
<?php |
||||
} |
||||
?> |
||||
<br /><br /><br /><br /><br /><br /> |
||||
</td> |
||||
<td align="center"> |
||||
<?php |
||||
echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false ); |
||||
unset($sessionUsersList); |
||||
?> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td colspan="3" align="center"> |
||||
<br /> |
||||
<?php |
||||
echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeSessionsToGroup').'</button>'; |
||||
?> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</form> |
||||
|
||||
<script type="text/javascript"> |
||||
<!-- |
||||
function moveItem(origin , destination){ |
||||
|
||||
for(var i = 0 ; i<origin.options.length ; i++) { |
||||
if(origin.options[i].selected) { |
||||
destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value); |
||||
origin.options[i]=null; |
||||
i = i-1; |
||||
} |
||||
} |
||||
destination.selectedIndex = -1; |
||||
sortOptions(destination.options); |
||||
|
||||
} |
||||
|
||||
function sortOptions(options) { |
||||
|
||||
newOptions = new Array(); |
||||
for (i = 0 ; i<options.length ; i++) |
||||
newOptions[i] = options[i]; |
||||
|
||||
newOptions = newOptions.sort(mysort); |
||||
options.length = 0; |
||||
for(i = 0 ; i < newOptions.length ; i++) |
||||
options[i] = newOptions[i]; |
||||
|
||||
} |
||||
|
||||
function mysort(a, b){ |
||||
if(a.text.toLowerCase() > b.text.toLowerCase()){ |
||||
return 1; |
||||
} |
||||
if(a.text.toLowerCase() < b.text.toLowerCase()){ |
||||
return -1; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
function valide(){ |
||||
var options = document.getElementById('elements_in').options; |
||||
for (i = 0 ; i<options.length ; i++) |
||||
options[i].selected = true; |
||||
document.forms.formulaire.submit(); |
||||
} |
||||
|
||||
|
||||
function loadUsersInSelect(select){ |
||||
|
||||
var xhr_object = null; |
||||
|
||||
if(window.XMLHttpRequest) // Firefox |
||||
xhr_object = new XMLHttpRequest(); |
||||
else if(window.ActiveXObject) // Internet Explorer |
||||
xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); |
||||
else // XMLHttpRequest non supporté par le navigateur |
||||
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); |
||||
|
||||
//xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
|
||||
xhr_object.open("POST", "loadUsersInSelect.ajax.php"); |
||||
|
||||
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
||||
|
||||
|
||||
nosessionUsers = makepost(document.getElementById('elements_not_in')); |
||||
sessionUsers = makepost(document.getElementById('elements_in')); |
||||
nosessionClasses = makepost(document.getElementById('origin_classes')); |
||||
sessionClasses = makepost(document.getElementById('destination_classes')); |
||||
xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses); |
||||
|
||||
xhr_object.onreadystatechange = function() { |
||||
if(xhr_object.readyState == 4) { |
||||
document.getElementById('content_source').innerHTML = result = xhr_object.responseText; |
||||
//alert(xhr_object.responseText); |
||||
} |
||||
} |
||||
} |
||||
|
||||
function makepost(select){ |
||||
var options = select.options; |
||||
var ret = ""; |
||||
for (i = 0 ; i<options.length ; i++) |
||||
ret = ret + options[i].value +'::'+options[i].text+";;"; |
||||
|
||||
return ret; |
||||
} |
||||
--> |
||||
</script> |
||||
<?php |
||||
Display::display_footer(); |
@ -0,0 +1,391 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @package chamilo.admin |
||||
*/ |
||||
|
||||
// name of the language file that needs to be included |
||||
$language_file=array('admin','registration'); |
||||
|
||||
// resetting the course id |
||||
$cidReset=true; |
||||
|
||||
// including some necessary files |
||||
require_once '../inc/global.inc.php'; |
||||
require_once '../inc/lib/xajax/xajax.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; |
||||
|
||||
$xajax = new xajax(); |
||||
|
||||
//$xajax->debugOn(); |
||||
$xajax->registerFunction('search'); |
||||
|
||||
// setting the section (for the tabs) |
||||
$this_section = SECTION_PLATFORM_ADMIN; |
||||
|
||||
// Access restrictions |
||||
api_protect_admin_script(true); |
||||
|
||||
// setting breadcrumbs |
||||
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin')); |
||||
$interbreadcrumb[]=array('url' => 'usergroups.php','name' => get_lang('UserGroups')); |
||||
|
||||
// Database Table Definitions |
||||
|
||||
// setting the name of the tool |
||||
$tool_name=get_lang('SubscribeUsersToUserGroup'); |
||||
|
||||
$add_type = 'multiple'; |
||||
if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){ |
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']); |
||||
} |
||||
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); |
||||
$htmlHeadXtra[] = ' |
||||
<script type="text/javascript"> |
||||
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; |
||||
} |
||||
} |
||||
|
||||
destination.options[destination.length] = new Option(content,code); |
||||
destination.selectedIndex = -1; |
||||
sortOptions(destination.options); |
||||
} |
||||
function remove_item(origin) { |
||||
for(var i = 0 ; i<origin.options.length ; i++) { |
||||
if(origin.options[i].selected) { |
||||
origin.options[i]=null; |
||||
i = i-1; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function validate_filter() { |
||||
document.formulaire.add_type.value = \''.$add_type.'\'; |
||||
document.formulaire.form_sent.value=0; |
||||
document.formulaire.submit(); |
||||
} |
||||
</script>'; |
||||
|
||||
|
||||
$form_sent = 0; |
||||
$errorMsg = ''; |
||||
$sessions=array(); |
||||
$usergroup = new UserGroup(); |
||||
$id = intval($_GET['id']); |
||||
if($_POST['form_sent']) { |
||||
$form_sent = $_POST['form_sent']; |
||||
$elements_posted = $_POST['elements_in_name']; |
||||
if (!is_array($elements_posted)) { |
||||
$elements_posted=array(); |
||||
} |
||||
if ($form_sent == 1) { |
||||
//added a parameter to send emails when registering a user |
||||
$usergroup->subscribe_users_to_usergroup($id, $elements_posted); |
||||
header('Location: usergroups.php'); |
||||
exit; |
||||
} |
||||
} |
||||
$data = $usergroup->get($id); |
||||
$list_in = $usergroup->get_users_by_usergroup($id); |
||||
$user_list = UserManager::get_user_list(); |
||||
|
||||
//api_display_tool_title($tool_name.' ('.$session_info['name'].')'); |
||||
$elements_not_in = $elements_in = array(); |
||||
|
||||
if (!empty($user_list)) { |
||||
foreach($user_list as $item) { |
||||
$person_name = api_get_person_name($item['firstname'], $item['lastname']); |
||||
if (in_array($item['user_id'], $list_in)) { |
||||
$elements_in[$item['user_id']] = $person_name; |
||||
} else { |
||||
$elements_not_in[$item['user_id']] = $person_name; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
$ajax_search = $add_type == 'unique' ? true : false; |
||||
|
||||
//checking for extra field with filter on |
||||
|
||||
function search($needle,$type) { |
||||
global $tbl_user,$elements_in; |
||||
$xajax_response = new XajaxResponse(); |
||||
$return = ''; |
||||
if (!empty($needle) && !empty($type)) { |
||||
|
||||
// xajax send utf8 datas... datas in db can be non-utf8 datas |
||||
$charset = api_get_system_encoding(); |
||||
$needle = Database::escape_string($needle); |
||||
$needle = api_convert_encoding($needle, $charset, 'utf-8'); |
||||
|
||||
if ($type == 'single') { |
||||
// search users where username or firstname or lastname begins likes $needle |
||||
/* $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user |
||||
WHERE (username LIKE "'.$needle.'%" |
||||
OR firstname LIKE "'.$needle.'%" |
||||
OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'" AND user.status<>'.DRH.''. |
||||
$order_clause. |
||||
' LIMIT 11';*/ |
||||
} else { |
||||
$list = UserManager::get_user_list_like(array('firstname'=>$needle)); |
||||
} |
||||
$i=0; |
||||
if ($type=='single') { |
||||
/* |
||||
while ($user = Database :: fetch_array($rs)) { |
||||
$i++; |
||||
if ($i<=10) { |
||||
$person_name = api_get_person_name($user['firstname'], $user['lastname']); |
||||
$return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />'; |
||||
} else { |
||||
$return .= '...<br />'; |
||||
} |
||||
} |
||||
$xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/ |
||||
} else { |
||||
$return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">'; |
||||
|
||||
foreach ($list as $item ) { |
||||
if (!in_array($item['user_id'], array_keys($elements_in))) { |
||||
$person_name = api_get_person_name($item['firstname'], $item['lastname']); |
||||
$return .= '<option value="'.$item['user_id'].'">'.$person_name.'</option>'; |
||||
} |
||||
} |
||||
$return .= '</select>'; |
||||
$xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return)); |
||||
} |
||||
} |
||||
return $xajax_response; |
||||
} |
||||
$xajax -> processRequests(); |
||||
|
||||
Display::display_header($tool_name); |
||||
|
||||
if ($add_type == 'multiple') { |
||||
$link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>'; |
||||
$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'); |
||||
} else { |
||||
$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'); |
||||
$link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>'; |
||||
} |
||||
|
||||
echo '<div class="actions">'; |
||||
echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>'; |
||||
echo '</div>'; |
||||
|
||||
echo '<div class="row"><div class="form_header">'.$tool_name.' '.$data['name'].'</div></div><br/>'; ?> |
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
|
||||
|
||||
<?php |
||||
if ($add_type=='multiple') { |
||||
if (is_array($extra_field_list)) { |
||||
if (is_array($new_field_list) && count($new_field_list)>0 ) { |
||||
echo '<h3>'.get_lang('FilterUsers').'</h3>'; |
||||
foreach ($new_field_list as $new_field) { |
||||
echo $new_field['name']; |
||||
$varname = 'field_'.$new_field['variable']; |
||||
echo ' <select name="'.$varname.'">'; |
||||
echo '<option value="0">--'.get_lang('Select').'--</option>'; |
||||
foreach ($new_field['data'] as $option) { |
||||
$checked=''; |
||||
if (isset($_POST[$varname])) { |
||||
if ($_POST[$varname]==$option[1]) { |
||||
$checked = 'selected="true"'; |
||||
} |
||||
} |
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>'; |
||||
} |
||||
echo '</select>'; |
||||
echo ' '; |
||||
} |
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />'; |
||||
echo '<br /><br />'; |
||||
} |
||||
} |
||||
} |
||||
echo Display::input('hidden','id',$id); |
||||
echo Display::input('hidden','form_sent','1'); |
||||
echo Display::input('hidden','add_type',null); |
||||
if(!empty($errorMsg)) { |
||||
Display::display_normal_message($errorMsg); //main API |
||||
} |
||||
?> |
||||
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%"> |
||||
<tr> |
||||
<td align="center"><b><?php echo get_lang('SessionsInPlatform') ?> :</b>
|
||||
</td> |
||||
<td></td> |
||||
<td align="center"><b><?php echo get_lang('SessionsInGroup') ?> :</b></td>
|
||||
</tr> |
||||
|
||||
<?php if ($add_type=='multiple') { ?> |
||||
<tr> |
||||
<td align="center"> |
||||
<?php echo get_lang('FirstLetterSessions'); ?> :
|
||||
<select name="firstLetterUser" onchange = "xajax_search(this.value,'multiple')" > |
||||
<option value = "%">--</option> |
||||
<?php |
||||
echo Display :: get_alphabet_options(); |
||||
?> |
||||
</select> |
||||
</td> |
||||
<td align="center"> </td> |
||||
</tr> |
||||
<?php } ?> |
||||
<tr> |
||||
<td align="center"> |
||||
<div id="content_source"> |
||||
<?php
|
||||
if (!($add_type=='multiple')) { |
||||
?> |
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" /> |
||||
<div id="ajax_list_users_single"></div> |
||||
<?php |
||||
} else { |
||||
?> |
||||
<div id="ajax_list_multiple"> |
||||
<?php echo Display::select('elements_not_in_name',$elements_not_in, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?>
|
||||
</div> |
||||
<?php |
||||
} |
||||
?> |
||||
</div> |
||||
</td> |
||||
<td width="10%" valign="middle" align="center"> |
||||
<?php |
||||
if ($ajax_search) { |
||||
?> |
||||
<button class="arrowl" type="button" onclick="remove_item(document.getElementById('elements_in'))" ></button> |
||||
<?php |
||||
} else { |
||||
?> |
||||
<button class="arrowr" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"></button> |
||||
<br /><br /> |
||||
<button class="arrowl" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))"></button> |
||||
<?php |
||||
} |
||||
?> |
||||
<br /><br /><br /><br /><br /><br /> |
||||
</td> |
||||
<td align="center"> |
||||
<?php |
||||
echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false ); |
||||
unset($sessionUsersList); |
||||
?> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<td colspan="3" align="center"> |
||||
<br /> |
||||
<?php |
||||
echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeUsersToGroup').'</button>'; |
||||
?> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</form> |
||||
|
||||
<script type="text/javascript"> |
||||
<!-- |
||||
function moveItem(origin , destination){ |
||||
|
||||
for(var i = 0 ; i<origin.options.length ; i++) { |
||||
if(origin.options[i].selected) { |
||||
destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value); |
||||
origin.options[i]=null; |
||||
i = i-1; |
||||
} |
||||
} |
||||
destination.selectedIndex = -1; |
||||
sortOptions(destination.options); |
||||
|
||||
} |
||||
|
||||
function sortOptions(options) { |
||||
|
||||
newOptions = new Array(); |
||||
for (i = 0 ; i<options.length ; i++) |
||||
newOptions[i] = options[i]; |
||||
|
||||
newOptions = newOptions.sort(mysort); |
||||
options.length = 0; |
||||
for(i = 0 ; i < newOptions.length ; i++) |
||||
options[i] = newOptions[i]; |
||||
|
||||
} |
||||
|
||||
function mysort(a, b){ |
||||
if(a.text.toLowerCase() > b.text.toLowerCase()){ |
||||
return 1; |
||||
} |
||||
if(a.text.toLowerCase() < b.text.toLowerCase()){ |
||||
return -1; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
function valide(){ |
||||
var options = document.getElementById('elements_in').options; |
||||
for (i = 0 ; i<options.length ; i++) |
||||
options[i].selected = true; |
||||
document.forms.formulaire.submit(); |
||||
} |
||||
|
||||
|
||||
function loadUsersInSelect(select){ |
||||
|
||||
var xhr_object = null; |
||||
|
||||
if(window.XMLHttpRequest) // Firefox |
||||
xhr_object = new XMLHttpRequest(); |
||||
else if(window.ActiveXObject) // Internet Explorer |
||||
xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); |
||||
else // XMLHttpRequest non supporté par le navigateur |
||||
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); |
||||
|
||||
//xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
|
||||
xhr_object.open("POST", "loadUsersInSelect.ajax.php"); |
||||
|
||||
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
||||
|
||||
|
||||
nosessionUsers = makepost(document.getElementById('elements_not_in')); |
||||
sessionUsers = makepost(document.getElementById('elements_in')); |
||||
nosessionClasses = makepost(document.getElementById('origin_classes')); |
||||
sessionClasses = makepost(document.getElementById('destination_classes')); |
||||
xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses); |
||||
|
||||
xhr_object.onreadystatechange = function() { |
||||
if(xhr_object.readyState == 4) { |
||||
document.getElementById('content_source').innerHTML = result = xhr_object.responseText; |
||||
//alert(xhr_object.responseText); |
||||
} |
||||
} |
||||
} |
||||
|
||||
function makepost(select){ |
||||
var options = select.options; |
||||
var ret = ""; |
||||
for (i = 0 ; i<options.length ; i++) |
||||
ret = ret + options[i].value +'::'+options[i].text+";;"; |
||||
|
||||
return ret; |
||||
} |
||||
--> |
||||
</script> |
||||
<?php |
||||
Display::display_footer(); |
@ -0,0 +1,171 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* @package chamilo.admin |
||||
*/ |
||||
|
||||
// Language files that need to be included. |
||||
$language_file = array('admin'); |
||||
|
||||
$cidReset = true; |
||||
require_once '../inc/global.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php'; |
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
|
||||
//Add the JS needed to use the jqgrid |
||||
$htmlHeadXtra[] = api_get_jqgrid_js(); |
||||
|
||||
// The header. |
||||
Display::display_header($tool_name); |
||||
|
||||
|
||||
// Tool name |
||||
if (isset($_GET['action']) && $_GET['action'] == 'add') { |
||||
$tool = 'Add'; |
||||
$interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('Group')); |
||||
} |
||||
if (isset($_GET['action']) && $_GET['action'] == 'editnote') { |
||||
$tool = 'Modify'; |
||||
$interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('Group')); |
||||
} |
||||
|
||||
//jqgrid will use this URL to do the selects |
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups'; |
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file |
||||
$columns = array(get_lang('Name'),get_lang('Description'),get_lang('Actions')); |
||||
|
||||
//Column config |
||||
$column_model = array(array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'), |
||||
array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left'), |
||||
array('name'=>'actions', 'index'=>'actions', 'formatter'=>'action_formatter','width'=>'100', 'align'=>'left'), |
||||
); |
||||
//Autowidth |
||||
$extra_params['autowidth'] = 'true'; |
||||
//height auto |
||||
$extra_params['height'] = 'auto'; |
||||
|
||||
//With this function we can add actions to the jgrid |
||||
$action_links = 'function action_formatter (cellvalue, options, rowObject) { |
||||
return \'<a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/course_add.gif" title="'.get_lang('AddSession').'"></a>' |
||||
.'<a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/course_add.gif" title="'.get_lang('AddCourses').'"></a>' |
||||
.'<a href="add_users_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/add_user_big.gif" title="'.get_lang('AddUsers').'"></a>' |
||||
.'<a href="?action=edit&id=\'+options.rowId+\'"><img src="../img/edit.gif" title="'.get_lang('Edit').'"></a>' |
||||
.'<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.gif"></a>\'; |
||||
}'; |
||||
?> |
||||
<script> |
||||
$(function() { |
||||
<?php
|
||||
// grid definition see the $usergroup>display() function |
||||
echo Display::grid_js('usergroups', $url,$columns,$column_model,$extra_params, array(), $action_links); |
||||
?> |
||||
}); |
||||
</script> |
||||
<?php |
||||
// Tool introduction |
||||
Display::display_introduction_section(get_lang('Groups')); |
||||
|
||||
$usergroup = new UserGroup(); |
||||
|
||||
// Action handling: Adding a note |
||||
if (isset($_GET['action']) && $_GET['action'] == 'add') { |
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
$_SESSION['notebook_view'] = 'creation_date'; |
||||
//@todo move this in the career.lib.php |
||||
|
||||
// Initiate the object |
||||
$form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action'])); |
||||
// Settting the form elements |
||||
$form->addElement('header', '', get_lang('Add')); |
||||
$form->addElement('text', 'name', get_lang('name'), array('size' => '95', 'id' => 'name')); |
||||
//$form->applyFilter('note_title', 'html_filter'); |
||||
$form->addElement('html_editor', 'description', get_lang('Description'), null); |
||||
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"'); |
||||
|
||||
// Setting the rules |
||||
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required'); |
||||
|
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
$check = Security::check_token('post'); |
||||
if ($check) { |
||||
$values = $form->exportValues(); |
||||
$res = $usergroup->save($values); |
||||
if ($res) { |
||||
Display::display_confirmation_message(get_lang('Added')); |
||||
} |
||||
} |
||||
Security::clear_token(); |
||||
$usergroup->display(); |
||||
} else { |
||||
echo '<div class="actions">'; |
||||
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png').' '.get_lang('Back').'</a>'; |
||||
echo '</div>'; |
||||
$token = Security::get_token(); |
||||
$form->addElement('hidden', 'sec_token'); |
||||
$form->setConstants(array('sec_token' => $token)); |
||||
$form->display(); |
||||
} |
||||
}// Action handling: Editing a note |
||||
elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) { |
||||
// Initialize the object |
||||
$form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id'])); |
||||
// Settting the form elements |
||||
$form->addElement('header', '', get_lang('Modify')); |
||||
$form->addElement('hidden', 'id',intval($_GET['id'])); |
||||
$form->addElement('text', 'name', get_lang('Name'), array('size' => '100')); |
||||
$form->addElement('html_editor', 'description', get_lang('description'), null); |
||||
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); |
||||
|
||||
// Setting the defaults |
||||
$defaults = $usergroup->get($_GET['id']); |
||||
$form->setDefaults($defaults); |
||||
|
||||
// Setting the rules |
||||
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required'); |
||||
|
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
$check = Security::check_token('post'); |
||||
if ($check) { |
||||
$values = $form->exportValues(); |
||||
$res = $usergroup->update($values); |
||||
if ($res) { |
||||
Display::display_confirmation_message(get_lang('Updated')); |
||||
} |
||||
} |
||||
Security::clear_token(); |
||||
$usergroup->display(); |
||||
} else { |
||||
echo '<div class="actions">'; |
||||
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png').' '.get_lang('Back').'</a>'; |
||||
echo '</div>'; |
||||
$token = Security::get_token(); |
||||
$form->addElement('hidden', 'sec_token'); |
||||
$form->setConstants(array('sec_token' => $token)); |
||||
$form->display(); |
||||
} |
||||
} |
||||
// Action handling: deleting a note |
||||
elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) { |
||||
$res = $usergroup->delete(Security::remove_XSS($_GET['id'])); |
||||
if ($res) { |
||||
Display::display_confirmation_message(get_lang('Deleted')); |
||||
} |
||||
$usergroup->display(); |
||||
} else { |
||||
$usergroup->display(); |
||||
} |
||||
|
||||
Display :: display_footer(); |
@ -0,0 +1,210 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This class provides methods for the notebook management. |
||||
* Include/require it in your code to use its features. |
||||
* @package chamilo.library |
||||
*/ |
||||
|
||||
require_once 'model.lib.php'; |
||||
|
||||
class UserGroup extends Model { |
||||
|
||||
var $columns = array('id', 'name','description'); |
||||
|
||||
public function __construct() { |
||||
$this->table = Database::get_main_table(TABLE_USERGROUP); |
||||
$this->usergroup_rel_user_table = Database::get_main_table(TABLE_USERGROUP_REL_USER); |
||||
$this->usergroup_rel_course_table = Database::get_main_table(TABLE_USERGROUP_REL_COURSE); |
||||
$this->usergroup_rel_session_table = Database::get_main_table(TABLE_USERGROUP_REL_SESSION); |
||||
} |
||||
|
||||
/** |
||||
* Displays the title + grid |
||||
*/ |
||||
function display() { |
||||
// action links |
||||
echo '<div class="actions" style="margin-bottom:20px">'; |
||||
echo '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>'; |
||||
echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('filenew.gif',get_lang('Add')).get_lang('Add').'</a>'; |
||||
echo '</div>'; |
||||
echo Display::grid_html('usergroups'); |
||||
} |
||||
|
||||
|
||||
public function get_courses_by_usergroup($id) { |
||||
$results = Database::select('*',$this->usergroup_rel_course_table, array('where'=>array('usergroup_id = ?'=>$id))); |
||||
$array = array(); |
||||
if (!empty($results)) { |
||||
foreach($results as $row) { |
||||
$array[]= $row['course_id']; |
||||
} |
||||
} |
||||
return $array; |
||||
} |
||||
|
||||
public function get_sessions_by_usergroup($id) { |
||||
$results = Database::select('*',$this->usergroup_rel_session_table, array('where'=>array('usergroup_id = ?'=>$id))); |
||||
$array = array(); |
||||
if (!empty($results)) { |
||||
foreach($results as $row) { |
||||
$array[]= $row['session_id']; |
||||
} |
||||
} |
||||
return $array; |
||||
} |
||||
|
||||
public function get_users_by_usergroup($id) { |
||||
$results = Database::select('*',$this->usergroup_rel_user_table, array('where'=>array('usergroup_id = ?'=>$id))); |
||||
$array = array(); |
||||
if (!empty($results)) { |
||||
foreach($results as $row) { |
||||
$array[]= $row['user_id']; |
||||
} |
||||
} |
||||
return $array; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Subscribes sessions to a group (also adding the members of the group in the session and course) |
||||
* @param int usergroup id |
||||
* @param array list of session ids |
||||
*/ |
||||
function subscribe_sessions_to_usergroup($usergroup_id, $list) { |
||||
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php'; |
||||
|
||||
$t = Database::get_main_table(TABLE_USERGROUP_REL_SESSION); |
||||
//Deleting relationships |
||||
|
||||
$current_list = self::get_sessions_by_usergroup($usergroup_id); |
||||
$user_list = self::get_users_by_usergroup($usergroup_id); |
||||
|
||||
$delete_items = $new_items = array(); |
||||
if (!empty($list)) { |
||||
foreach ($list as $session_id) { |
||||
if (!in_array($session_id, $current_list)) { |
||||
$new_items[] = $session_id; |
||||
} |
||||
} |
||||
} |
||||
if (!empty($current_list)) { |
||||
foreach($current_list as $session_id) { |
||||
if (!in_array($session_id, $list)) { |
||||
$delete_items[] = $session_id; |
||||
} |
||||
} |
||||
} |
||||
|
||||
//Deleting items |
||||
if (!empty($delete_items)) { |
||||
foreach($delete_items as $session_id) { |
||||
foreach($user_list as $user_id) { |
||||
SessionManager::unsubscribe_user_from_session($session_id, $user_id); |
||||
/*foreach ($course_list as $course_data) { |
||||
foreach($user_list as $user_id) { |
||||
CourseManager::subscribe_user($user_id, $course_data['code'], $session_id); |
||||
} |
||||
}*/ |
||||
} |
||||
Database::delete($t, array('usergroup_id = ? AND session_id = ?'=>array($usergroup_id, $session_id))); |
||||
} |
||||
} |
||||
|
||||
|
||||
//Addding new relationships |
||||
if (!empty($new_items)) { |
||||
foreach($new_items as $id) { |
||||
$params = array('session_id'=>$id, 'usergroup_id'=>$usergroup_id); |
||||
Database::insert($t, $params); |
||||
SessionManager::suscribe_users_to_session($session_id, $user_list); |
||||
/* |
||||
$course_list = SessionManager::get_course_list_by_session_id($id); |
||||
foreach ($course_list as $course_data) { |
||||
foreach($user_list as $user_id) { |
||||
CourseManager::subscribe_user($user_id, $course_data['code'], $id); |
||||
} |
||||
}*/ |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Subscribes courses to a group (also adding the members of the group in the course) |
||||
* @param int usergroup id |
||||
* @param array list of course ids |
||||
*/ |
||||
function subscribe_courses_to_usergroup($usergroup_id, $list) { |
||||
require_once api_get_path(LIBRARY_PATH).'course.lib.php'; |
||||
|
||||
$t = Database::get_main_table(TABLE_USERGROUP_REL_COURSE); |
||||
//Deleting relationships |
||||
|
||||
$current_list = self::get_courses_by_usergroup($usergroup_id); |
||||
$user_list = self::get_users_by_usergroup($usergroup_id); |
||||
|
||||
$delete_items = $new_items = array(); |
||||
if (!empty($list)) { |
||||
foreach ($list as $id) { |
||||
if (!in_array($id, $current_list)) { |
||||
$new_items[] = $id; |
||||
} |
||||
} |
||||
} |
||||
if (!empty($current_list)) { |
||||
foreach($current_list as $id) { |
||||
if (!in_array($id, $list)) { |
||||
$delete_items[] = $id; |
||||
} |
||||
} |
||||
} |
||||
|
||||
//Deleting items |
||||
if (!empty($delete_items)) { |
||||
foreach($delete_items as $course_id) { |
||||
$course_info = api_get_course_info_by_id($course_id); |
||||
foreach($user_list as $user_id) { |
||||
CourseManager::unsubscribe_user($user_id, $course_info['code']); |
||||
} |
||||
Database::delete($t, array('usergroup_id = ? AND course_id = ?'=>array($usergroup_id, $course_id))); |
||||
} |
||||
} |
||||
|
||||
//Addding new relationships |
||||
if (!empty($new_items)) { |
||||
foreach($new_items as $course_id) { |
||||
$course_info = api_get_course_info_by_id($course_id); |
||||
|
||||
foreach($user_list as $user_id) { |
||||
CourseManager::subscribe_user($user_id, $course_info['code']); |
||||
} |
||||
|
||||
$params = array('course_id'=>$id, 'usergroup_id'=>$usergroup_id); |
||||
Database::insert($t, $params); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Subscribes users to a group |
||||
* @param int usergroup id |
||||
* @param array list of user ids |
||||
*/ |
||||
function subscribe_users_to_usergroup($usergroup_id, $list) { |
||||
$t = Database::get_main_table(TABLE_USERGROUP_REL_USER); |
||||
$user_list = self::get_users_by_usergroup($usergroup_id); |
||||
|
||||
//Deleting relationships |
||||
Database::delete($t, array('usergroup_id = ?'=>$usergroup_id)); |
||||
|
||||
//Adding new relationships |
||||
if (!empty($list)) { |
||||
foreach($list as $id) { |
||||
$params = array('user_id'=>$id, 'usergroup_id'=>$usergroup_id); |
||||
Database::insert($t, $params); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue