Adding new pages enroll trainers/students from existing sessions in a specified course

see BT#6782
1.9.x
Julio Montoya 11 years ago
parent e38707e57f
commit 535e857b3c
  1. 189
      main/admin/add_students_to_session.php
  2. 53
      main/admin/add_teachers_to_session.php
  3. 144
      main/admin/add_users_to_session.php
  4. 18
      main/inc/lib/course.lib.php
  5. 139
      main/inc/lib/sessionmanager.lib.php
  6. 20
      main/lang/english/trad4all.inc.php
  7. 4
      main/lang/spanish/trad4all.inc.php

@ -0,0 +1,189 @@
<?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).'sessionmanager.lib.php';
// 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' => 'session_list.php','name' => get_lang('SessionList'));
// Setting the name of the tool
$tool_name = get_lang('SubscribeStudentsToSession');
$add_type = 'multiple';
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') {
$add_type = Security::remove_XSS($_REQUEST['add_type']);
}
$form_sent = 0;
$errorMsg = '';
$users = $sessions = array();
$id = intval($_GET['id']);
$htmlResult = null;
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$form_sent = $_POST['form_sent'];
if ($form_sent == 1) {
$sessionSourceList = $_POST['sessions'];
$sessionDestinationList = $_POST['sessions_destination'];
$result = SessionManager::copyStudentsFromSession($sessionSourceList, $sessionDestinationList);
foreach ($result as $message) {
$htmlResult .= $message;
}
}
}
$session_list = SessionManager::get_sessions_list(array(), array('name'));
$sessionList = array();
foreach ($session_list as $session) {
$sessionList[$session['id']] = $session['name'];
}
Display::display_header($tool_name);
?>
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;" >
<?php echo '<legend>'.$tool_name.' </legend>';
echo $htmlResult;
echo Display::input('hidden', 'form_sent', '1');
?>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr>
<td align="center">
<b><?php echo get_lang('Sessions') ?> :</b>
</td>
<td></td>
<td align="center">
<b><?php echo get_lang('Sessions') ?> :</b>
</td>
</tr>
<tr>
<td align="center">
<?php
echo Display::select(
'sessions[]',
$sessionList,
'',
array('style'=>'width:360px', 'id'=>'sessions', 'size'=>'15px'),
false
);
?>
</td>
<td align="center">
</td>
<td align="center">
<?php
echo Display::select(
'sessions_destination[]',
$sessionList,
'',
array('style'=>'width:360px', 'multiple'=>'multiple', 'id'=>'courses', 'size'=>'15px'),
false
);
?>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<br />
<?php
echo '<button class="save" type="submit"" >'.
get_lang('SubscribeStudentsToSession').'</button>';
?>
</td>
</tr>
</table>
</form>
<script>
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('session_in_promotion').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('session_not_in_promotion'));
sessionUsers = makepost(document.getElementById('session_in_promotion'));
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();

@ -23,9 +23,10 @@ api_protect_admin_script(true);
// setting breadcrumbs // setting breadcrumbs
$interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin')); $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
// Setting the name of the tool // Setting the name of the tool
$tool_name = get_lang('SubscribeTeachersToSession'); $tool_name = get_lang('EnrollTrainersFromExistingSessions');
$add_type = 'multiple'; $add_type = 'multiple';
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') { if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') {
$add_type = Security::remove_XSS($_REQUEST['add_type']); $add_type = Security::remove_XSS($_REQUEST['add_type']);
@ -43,55 +44,7 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$sessions = $_POST['sessions']; $sessions = $_POST['sessions'];
$courses = $_POST['courses']; $courses = $_POST['courses'];
$coachesPerSession = array(); $htmlResult = SessionManager::copyCoachesFromSessionToCourse($sessions, $courses);
foreach ($sessions as $sessionId) {
$coaches = SessionManager::getCoachesBySession($sessionId);
$coachesPerSession[$sessionId] = $coaches;
}
$result = array();
if (!empty($courses)) {
foreach ($courses as $courseId) {
$courseInfo = api_get_course_info_by_id($courseId);
foreach ($coachesPerSession as $sessionId => $coachList) {
CourseManager::updateTeachers(
$courseInfo['code'],
$coachList,
false,
false,
false
);
$result[$courseInfo['code']][$sessionId] = $coachList;
}
}
}
$sessionUrl = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session=';
if (!empty($result)) {
foreach ($result as $courseCode => $data) {
$url = api_get_course_url($courseCode);
$htmlResult .= get_lang('Course').': '.Display::url($courseCode, $url, array('target' => '_blank'));
foreach ($data as $sessionId => $coachList) {
$htmlResult .= '<br />';
$htmlResult .= Display::url(
get_lang('Session').' #'.$sessionId.' ', $sessionUrl.$sessionId,
array('target' => '_blank')
);
$teacherList = array();
foreach ($coachList as $coachId) {
$userInfo = api_get_user_info($coachId);
$teacherList[] = $userInfo['complete_name'];
}
if (!empty($teacherList)) {
$htmlResult .= implode(', ', $teacherList);
} else {
$htmlResult .= get_lang('NothingToAdd');
}
}
$htmlResult .= '<br />';
}
$htmlResult = Display::return_message($htmlResult, 'normal', false);
}
} }
} }

@ -15,7 +15,7 @@ require_once '../inc/global.inc.php';
require_once '../inc/lib/xajax/xajax.inc.php'; require_once '../inc/lib/xajax/xajax.inc.php';
$xajax = new xajax(); $xajax = new xajax();
$xajax->registerFunction ('search_users'); $xajax->registerFunction('search_users');
// setting the section (for the tabs) // setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN; $this_section = SECTION_PLATFORM_ADMIN;
@ -53,52 +53,53 @@ $new_field_list = array();
if (is_array($extra_field_list)) { if (is_array($extra_field_list)) {
foreach ($extra_field_list as $extra_field) { foreach ($extra_field_list as $extra_field) {
//if is enabled to filter and is a "<select>" field type //if is enabled to filter and is a "<select>" field type
if ($extra_field[8]==1 && $extra_field[2]==4 ) { if ($extra_field[8]==1 && $extra_field[2]==4) {
$new_field_list[] = array('name'=> $extra_field[3], 'variable'=>$extra_field[1], 'data'=> $extra_field[9]); $new_field_list[] = array('name'=> $extra_field[3], 'variable'=>$extra_field[1], 'data'=> $extra_field[9]);
} }
} }
} }
function search_users($needle, $type) { function search_users($needle, $type)
global $tbl_user,$tbl_session_rel_user,$id_session; {
$xajax_response = new XajaxResponse(); global $tbl_user,$tbl_session_rel_user,$id_session;
$return = ''; $xajax_response = new XajaxResponse();
$return = '';
if (!empty($needle) && !empty($type)) { if (!empty($needle) && !empty($type)) {
//normal behaviour //normal behaviour
if ($type == 'any_session' && $needle == 'false') { if ($type == 'any_session' && $needle == 'false') {
$type = 'multiple'; $type = 'multiple';
$needle = ''; $needle = '';
} }
// xajax send utf8 datas... datas in db can be non-utf8 datas // xajax send utf8 datas... datas in db can be non-utf8 datas
$charset = api_get_system_encoding(); $charset = api_get_system_encoding();
$needle = Database::escape_string($needle); $needle = Database::escape_string($needle);
$needle = api_convert_encoding($needle, $charset, 'utf-8'); $needle = api_convert_encoding($needle, $charset, 'utf-8');
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
$cond_user_id = ''; $cond_user_id = '';
//Only for single & multiple //Only for single & multiple
if (in_array($type, array('single','multiple'))) if (in_array($type, array('single','multiple')))
if (!empty($id_session)) { if (!empty($id_session)) {
$id_session = intval($id_session); $id_session = intval($id_session);
// check id_user from session_rel_user table // check id_user from session_rel_user table
$sql = 'SELECT id_user FROM '.$tbl_session_rel_user.' WHERE id_session ="'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' '; $sql = 'SELECT id_user FROM '.$tbl_session_rel_user.' WHERE id_session ="'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' ';
$res = Database::query($sql); $res = Database::query($sql);
$user_ids = array(); $user_ids = array();
if (Database::num_rows($res) > 0) { if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_row($res)) { while ($row = Database::fetch_row($res)) {
$user_ids[] = (int)$row[0]; $user_ids[] = (int)$row[0];
} }
} }
if (count($user_ids) > 0) { if (count($user_ids) > 0) {
$cond_user_id = ' AND user.user_id NOT IN('.implode(",",$user_ids).')'; $cond_user_id = ' AND user.user_id NOT IN('.implode(",",$user_ids).')';
} }
} }
switch($type) { switch ($type) {
case 'single': case 'single':
// search users where username or firstname or lastname begins likes $needle // search users where username or firstname or lastname begins likes $needle
$sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
@ -119,10 +120,11 @@ function search_users($needle, $type) {
$order_clause; $order_clause;
break; break;
} }
if (api_is_multiple_url_enabled()) { if (api_is_multiple_url_enabled()) {
$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$access_url_id = api_get_current_access_url_id(); $access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) { if ($access_url_id != -1) {
switch($type) { switch($type) {
case 'single': case 'single':
$sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
@ -153,25 +155,25 @@ function search_users($needle, $type) {
} }
} }
$rs = Database::query($sql); $rs = Database::query($sql);
$i = 0; $i = 0;
if ($type=='single') { if ($type=='single') {
while ($user = Database :: fetch_array($rs)) { while ($user = Database :: fetch_array($rs)) {
$i++; $i++;
if ($i<=10) { if ($i<=10) {
$person_name = api_get_person_name($user['firstname'], $user['lastname']); $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 />'; $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 { } else {
$return .= '...<br />'; $return .= '...<br />';
} }
} }
$xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return)); $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));
} else { } else {
global $nosessionUsersList; global $nosessionUsersList;
$return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">'; $return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
while ($user = Database :: fetch_array($rs)) { while ($user = Database :: fetch_array($rs)) {
$person_name = api_get_person_name($user['firstname'], $user['lastname']); $person_name = api_get_person_name($user['firstname'], $user['lastname']);
$return .= '<option value="'.$user['user_id'].'">'.$person_name.' ('.$user['username'].')</option>'; $return .= '<option value="'.$user['user_id'].'">'.$person_name.' ('.$user['username'].')</option>';
} }
$return .= '</select>'; $return .= '</select>';
@ -181,7 +183,7 @@ function search_users($needle, $type) {
return $xajax_response; return $xajax_response;
} }
$xajax -> processRequests(); $xajax->processRequests();
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = ' $htmlHeadXtra[] = '
@ -212,9 +214,9 @@ function remove_item(origin) {
} }
function validate_filter() { function validate_filter() {
document.formulaire.add_type.value = \''.$add_type.'\'; document.formulaire.add_type.value = \''.$add_type.'\';
document.formulaire.form_sent.value=0; document.formulaire.form_sent.value=0;
document.formulaire.submit(); document.formulaire.submit();
} }
function checked_in_no_session(checked) { function checked_in_no_session(checked) {
@ -247,7 +249,7 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
} }
if ($form_sent == 1) { if ($form_sent == 1) {
//added a parameter to send emails when registering a user // Added a parameter to send emails when registering a user
SessionManager::suscribe_users_to_session($id_session, $UserList, null, true); SessionManager::suscribe_users_to_session($id_session, $UserList, null, true);
header('Location: resume_session.php?id_session='.$id_session); header('Location: resume_session.php?id_session='.$id_session);
exit; exit;
@ -284,8 +286,8 @@ if ($ajax_search) {
$order_clause"; $order_clause";
} }
} }
$result=Database::query($sql); $result = Database::query($sql);
$users=Database::store_result($result); $users = Database::store_result($result);
foreach ($users as $user) { foreach ($users as $user) {
$sessionUsersList[$user['user_id']] = $user ; $sessionUsersList[$user['user_id']] = $user ;
} }
@ -399,8 +401,8 @@ if ($ajax_search) {
$order_clause"; $order_clause";
} }
} }
$result=Database::query($sql); $result = Database::query($sql);
$users=Database::store_result($result,'ASSOC'); $users = Database::store_result($result,'ASSOC');
foreach ($users as $uid => $user) { foreach ($users as $uid => $user) {
if ($user['id_session'] == $id_session) { if ($user['id_session'] == $id_session) {
$sessionUsersList[$user['user_id']] = $user; $sessionUsersList[$user['user_id']] = $user;
@ -415,15 +417,23 @@ if ($ajax_search) {
if ($add_type == 'multiple') { 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_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'); $link_add_type_multiple = Display::url(Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'), '');
} else { } else {
$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'); $link_add_type_unique = Display::url(Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'), '');
$link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&amp;add='.Security::remove_XSS($_GET['add']).'&amp;add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>'; $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&amp;add='.Security::remove_XSS($_GET['add']).'&amp;add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
} }
$link_add_group = '<a href="usergroups.php">'.Display::return_icon('multiple.gif',get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups').'</a>'; $link_add_group = '<a href="usergroups.php">'.Display::return_icon('multiple.gif',get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups').'</a>';
$newLinks = Display::url(get_lang('EnrollTrainersFromExistingSessions'), api_get_path(WEB_CODE_PATH).'admin/add_teachers_to_session.php');
$newLinks .= Display::url(get_lang('EnrollStudentsFromExistingSessions'), api_get_path(WEB_CODE_PATH).'admin/add_students_to_session.php');
?> ?>
<div class="actions"> <div class="actions">
<?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>&nbsp;|&nbsp;<?php echo $link_add_group; ?> <?php
echo $link_add_type_unique;
echo $link_add_type_multiple;
echo $link_add_group;
echo $newLinks;
?>
</div> </div>
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>> <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
<?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?> <?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?>
@ -455,7 +465,6 @@ if ($add_type=='multiple') {
} }
} }
?> ?>
<input type="hidden" name="form_sent" value="1" /> <input type="hidden" name="form_sent" value="1" />
<input type="hidden" name="add_type" /> <input type="hidden" name="add_type" />
@ -555,8 +564,7 @@ if (!empty($errorMsg)) {
</div> </div>
</form> </form>
<script> <script>
function moveItem(origin , destination){ function moveItem(origin , destination) {
for(var i = 0 ; i<origin.options.length ; i++) { for(var i = 0 ; i<origin.options.length ; i++) {
if(origin.options[i].selected) { if(origin.options[i].selected) {
destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value); destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
@ -605,7 +613,6 @@ function loadUsersInSelect(select){
else // XMLHttpRequest non supporté par le navigateur else // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 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.open("POST", "loadUsersInSelect.ajax.php");
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
nosessionUsers = makepost(document.getElementById('origin_users')); nosessionUsers = makepost(document.getElementById('origin_users'));
@ -615,9 +622,8 @@ function loadUsersInSelect(select){
xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses); xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
xhr_object.onreadystatechange = function() { xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 4) { if (xhr_object.readyState == 4) {
document.getElementById('content_source').innerHTML = result = xhr_object.responseText; document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
//alert(xhr_object.responseText);
} }
} }
} }

@ -3992,6 +3992,7 @@ class CourseManager {
* @param string $course_code * @param string $course_code
* @param array $teachers * @param array $teachers
* @param bool $editTeacherInSessions * @param bool $editTeacherInSessions
* @param bool $deleteSessionTeacherNotInList
* @return bool * @return bool
*/ */
public static function updateTeachers( public static function updateTeachers(
@ -4026,21 +4027,20 @@ class CourseManager {
} }
if (count($teachers) > 0) { if (count($teachers) > 0) {
foreach ($teachers as $key) { foreach ($teachers as $userId) {
// We check if the teacher is already subscribed in this course // We check if the teacher is already subscribed in this course
$sql_select_teacher = 'SELECT 1 FROM '.$course_user_table.' WHERE user_id = "'.$key.'" AND course_code = "'.$course_code.'" '; $sql = 'SELECT 1 FROM '.$course_user_table.' WHERE user_id = "'.$userId.'" AND course_code = "'.$course_code.'" ';
$result = Database::query($sql_select_teacher); $result = Database::query($sql);
if (Database::num_rows($result)) {
if (Database::num_rows($result) == 1) { $sql = 'UPDATE '.$course_user_table.' SET status = "1" WHERE course_code = "'.$course_code.'" AND user_id = "'.$userId.'" ';
$sql = 'UPDATE '.$course_user_table.' SET status = "1" WHERE course_code = "'.$course_code.'" AND user_id = "'.$key.'" ';
} else { } else {
$sql = "INSERT INTO ".$course_user_table . " SET $sql = "INSERT INTO ".$course_user_table . " SET
course_code = '".Database::escape_string($course_code). "', course_code = '".Database::escape_string($course_code). "',
user_id = '".$key . "', user_id = '".$userId."',
status = '1', status = '1',
role = '', role = '',
tutor_id='0', tutor_id = '0',
sort='0', sort = '0',
user_course_cat='0'"; user_course_cat='0'";
} }
Database::query($sql); Database::query($sql);

@ -675,14 +675,18 @@ class SessionManager
} }
/** /**
* Subscribes users (students) to the given session and optionally (default) unsubscribes previous users * Subscribes students to the given session and optionally (default) unsubscribes previous users
* @author Carlos Vargas from existing code *
* @param integer Session ID * @author Carlos Vargas from existing code
* @param array List of user IDs * @author Julio Montoya. Cleaning code.
* @param bool Whether to unsubscribe existing users (true, default) or not (false) * @param int $id_session
* @return void Nothing, or false on error * @param array $user_list
**/ * @param int $session_visibility
public static function suscribe_users_to_session( * @param bool $empty_users
* @param bool $send_email
* @return bool
*/
public static function suscribe_users_to_session(
$id_session, $id_session,
$user_list, $user_list,
$session_visibility = SESSION_VISIBLE_READ_ONLY, $session_visibility = SESSION_VISIBLE_READ_ONLY,
@ -1665,7 +1669,7 @@ class SessionManager
* @param int filter by status coach = 2 * @param int filter by status coach = 2
* @return array a list with an user list * @return array a list with an user list
*/ */
public static function get_users_by_session($id, $with_status = null) public static function get_users_by_session($id, $status = null)
{ {
if (empty($id)) { if (empty($id)) {
return array(); return array();
@ -1679,9 +1683,9 @@ class SessionManager
ON $tbl_user.user_id = $tbl_session_rel_user.id_user ON $tbl_user.user_id = $tbl_session_rel_user.id_user
AND $tbl_session_rel_user.id_session = $id"; AND $tbl_session_rel_user.id_session = $id";
if (isset($with_status) && $with_status != '') { if (isset($status) && $status != '') {
$with_status = intval($with_status); $status = intval($status);
$sql .= " WHERE relation_type = $with_status "; $sql .= " WHERE relation_type = $status ";
} }
$result = Database::query($sql); $result = Database::query($sql);
@ -2616,4 +2620,115 @@ class SessionManager
} }
} }
} }
/**
* @param array $sessions
* @param array $sessionsDestination
* @return string
*/
public static function copyStudentsFromSession($sessions, $sessionsDestination)
{
$messages = array();
if (!empty($sessions)) {
foreach ($sessions as $sessionId) {
$sessionInfo = self::fetch($sessionId);
$userList = self::get_users_by_session($sessionId, 0);
if (!empty($userList)) {
$newUserList = array();
$userToString = null;
foreach ($userList as $userInfo) {
$newUserList[] = $userInfo['user_id'];
$userToString .= $userInfo['firstname'].' '.$userInfo['lastname'].'<br />';
}
if (!empty($sessionsDestination)) {
foreach ($sessionsDestination as $sessionDestinationId) {
$sessionDestinationInfo = self::fetch($sessionDestinationId);
$messages[] = Display::return_message(
sprintf(get_lang('AddingStudentsFromSessionXToSessionY'), $sessionInfo['name'], $sessionDestinationInfo['name']),
'info',
false
);
if ($sessionId == $sessionDestinationId) {
$messages[] = Display::return_message(get_lang('SkipSession'), 'warning', false);
continue;
}
$messages[] = Display::return_message(get_lang('StudentList').'<br />'.$userToString, 'info', false);
SessionManager::suscribe_users_to_session($sessionDestinationId, $newUserList, SESSION_VISIBLE_READ_ONLY, false);
}
} else {
$messages[] = Display::return_message(get_lang('NoDestinationSessionProvided'), 'warning');
}
} else {
$messages[] = Display::return_message(get_lang('NoStudentsFoundForSession').' #'.$sessionInfo['name'], 'warning');
}
}
} else {
$messages[]= Display::return_message(get_lang('NoData'), 'warning');
}
return $messages;
}
/**
* @param array $sessions
* @param array $courses
*/
public static function copyCoachesFromSessionToCourse($sessions, $courses)
{
$coachesPerSession = array();
foreach ($sessions as $sessionId) {
$coaches = self::getCoachesBySession($sessionId);
$coachesPerSession[$sessionId] = $coaches;
}
$result = array();
if (!empty($courses)) {
foreach ($courses as $courseId) {
$courseInfo = api_get_course_info_by_id($courseId);
foreach ($coachesPerSession as $sessionId => $coachList) {
CourseManager::updateTeachers(
$courseInfo['code'],
$coachList,
false,
false,
false
);
$result[$courseInfo['code']][$sessionId] = $coachList;
}
}
}
$sessionUrl = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session=';
$htmlResult = null;
if (!empty($result)) {
foreach ($result as $courseCode => $data) {
$url = api_get_course_url($courseCode);
$htmlResult .= sprintf(get_lang('CoachesSubscribedAsATeacherInCourseX'), Display::url($courseCode, $url, array('target' => '_blank')));
foreach ($data as $sessionId => $coachList) {
$sessionInfo = self::fetch($sessionId);
$htmlResult .= '<br />';
$htmlResult .= Display::url(
get_lang('Session').': '.$sessionInfo['name'].' <br />',
$sessionUrl.$sessionId,
array('target' => '_blank')
);
$teacherList = array();
foreach ($coachList as $coachId) {
$userInfo = api_get_user_info($coachId);
$teacherList[] = $userInfo['complete_name'];
}
if (!empty($teacherList)) {
$htmlResult .= implode(', ', $teacherList);
} else {
$htmlResult .= get_lang('NothingToAdd');
}
}
$htmlResult .= '<br />';
}
$htmlResult = Display::return_message($htmlResult, 'normal', false);
}
return $htmlResult;
}
} }

@ -1087,13 +1087,13 @@ $YouMustAcceptLicence = "You must accept the licence";
$SelectOne = "Select one"; $SelectOne = "Select one";
$ContactInformationHasBeenSent = "Contact information has been sent"; $ContactInformationHasBeenSent = "Contact information has been sent";
$UserInactivedSinceX = "User inactive since %s"; $UserInactivedSinceX = "User inactive since %s";
$ContactInformationDescription = "Dear user,<br /> $ContactInformationDescription = "Dear user,<br />
<br />You are about to start using one of the best open-source e-learning platform on the market. Like many other open-source project, this project is backed up by a large community of students, teachers, developers and content creators who would like to promote the project better.<br /> <br />You are about to start using one of the best open-source e-learning platform on the market. Like many other open-source project, this project is backed up by a large community of students, teachers, developers and content creators who would like to promote the project better.<br />
<br /> <br />
By knowing a little bit more about you, one of our most important users, who will manage this e-learning system, we will be able to let people know that our software is used and let you know when we organize events that might be relevant to you.<br /> By knowing a little bit more about you, one of our most important users, who will manage this e-learning system, we will be able to let people know that our software is used and let you know when we organize events that might be relevant to you.<br />
<br /> <br />
By filling this form, you accept that the Chamilo association or its members might send you information by e-mail about important events or updates in the Chamilo software or community. This will help the community grow as an organized entity where information flow, with a permanent respect of your time and your privacy.<br /> By filling this form, you accept that the Chamilo association or its members might send you information by e-mail about important events or updates in the Chamilo software or community. This will help the community grow as an organized entity where information flow, with a permanent respect of your time and your privacy.<br />
<br /> <br />
Please note that you are <b>not required</b> to fill this form. If you want to remain anonymous, we will loose the opportunity to offer you all the privileges of being a registered portal administrator, but we will respect your decision. Simply leave this form empty and click \"Next\".<br /><br />"; Please note that you are <b>not required</b> to fill this form. If you want to remain anonymous, we will loose the opportunity to offer you all the privileges of being a registered portal administrator, but we will respect your decision. Simply leave this form empty and click \"Next\".<br /><br />";
$CompanyActivity = "Your company's activity"; $CompanyActivity = "Your company's activity";
$DateUnLock = "Unlock date"; $DateUnLock = "Unlock date";
@ -1299,7 +1299,7 @@ $SaveForNow = "Save and continue later";
$NoQuicktime = "Your browser does not have the QuickTime plugin installed. You can still use the platform, but to run a larger number of media file types, we suggest you might want to install it."; $NoQuicktime = "Your browser does not have the QuickTime plugin installed. You can still use the platform, but to run a larger number of media file types, we suggest you might want to install it.";
$NoJavaSun = "Your browser doesn't seem to have the Sun Java plugin installed. You can still use the platform, but you will lose a few of its capabilities."; $NoJavaSun = "Your browser doesn't seem to have the Sun Java plugin installed. You can still use the platform, but you will lose a few of its capabilities.";
$NoJava = "Your browser does not support Java"; $NoJava = "Your browser does not support Java";
$JavaSun24 = "Your browser has a Java version not supported by this tool. $JavaSun24 = "Your browser has a Java version not supported by this tool.
To use it you have to install a Java Sun version higher than 24"; To use it you have to install a Java Sun version higher than 24";
$NoMessageAnywere = "If you do not want to see this message again during this session, click here"; $NoMessageAnywere = "If you do not want to see this message again during this session, click here";
$Attempts = "Attempts"; $Attempts = "Attempts";
@ -1463,4 +1463,8 @@ $DataTableSearch = "Search";
$HideColumn = "Hide column"; $HideColumn = "Hide column";
$DisplayColumn = "Show column"; $DisplayColumn = "Show column";
$LegalAgreementAccepted = "Legal agreement accepted"; $LegalAgreementAccepted = "Legal agreement accepted";
$AddingStudentsFromSessionXToSessionY = "Adding students from session <b>%s</b> to session <b>%s </b>";
$EnrollTrainersFromExistingSessions = "Enroll trainers from existing sessions";
$EnrollStudentsFromExistingSessions = "Enroll students from existing sessions";
$CoachesSubscribedAsATeacherInCourseX = "Coaches will be subcribed as a teacher in the course %s";
?> ?>

@ -1477,4 +1477,8 @@ $AddUserGroupToURL = "Agregar clases a una URL";
$UserGroupList = "Lista de clases"; $UserGroupList = "Lista de clases";
$FirstLetter = "Primer letra"; $FirstLetter = "Primer letra";
$AddUserGroupToThatURL = "Agregar clases a una URL"; $AddUserGroupToThatURL = "Agregar clases a una URL";
$AddingStudentsFromSessionXToSessionY = "Adding students from session <b>%s</b> to session <b>%s </b>";
$EnrollTrainersFromExistingSessions = "Enroll trainers from existing sessions";
$EnrollStudentsFromExistingSessions = "Enroll students from existing sessions";
$CoachesSubscribedAsATeacherInCourseX = "Coaches will be subcribed as a teacher in the course %s";
?> ?>
Loading…
Cancel
Save