upgrade
This commit is contained in:
253
main/session/about.php
Normal file
253
main/session/about.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Course;
|
||||
use Chamilo\CoreBundle\Entity\ExtraField;
|
||||
use Chamilo\CoreBundle\Entity\Repository\SequenceResourceRepository;
|
||||
use Chamilo\CoreBundle\Entity\SequenceResource;
|
||||
use Chamilo\CourseBundle\Entity\CCourseDescription;
|
||||
use Chamilo\UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* Session about page
|
||||
* Show information about a session and its courses.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
* @author Julio Montoya
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
if ((api_get_setting('course_catalog_published') != 'true' && api_is_anonymous()) || api_get_configuration_value('session_about_block_all_access') == 'true') {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
|
||||
|
||||
$em = Database::getManager();
|
||||
|
||||
$session = api_get_session_entity($sessionId);
|
||||
|
||||
if (!$session) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$accessUrlId = api_get_current_access_url_id();
|
||||
$sessionOnUrl = UrlManager::relation_url_session_exist($sessionId, $accessUrlId);
|
||||
|
||||
if (!$sessionOnUrl) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js');
|
||||
$courses = [];
|
||||
$sessionCourses = $em->getRepository('ChamiloCoreBundle:Session')->getCoursesOrderedByPosition($session);
|
||||
$fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField');
|
||||
$fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
|
||||
$userRepo = UserManager::getRepository();
|
||||
/** @var SequenceResourceRepository $sequenceResourceRepo */
|
||||
$sequenceResourceRepo = $em->getRepository('ChamiloCoreBundle:SequenceResource');
|
||||
|
||||
$tagField = $fieldsRepo->findOneBy([
|
||||
'extraFieldType' => ExtraField::COURSE_FIELD_TYPE,
|
||||
'variable' => 'tags',
|
||||
]);
|
||||
|
||||
$courseValues = new ExtraFieldValue('course');
|
||||
$userValues = new ExtraFieldValue('user');
|
||||
$sessionValues = new ExtraFieldValue('session');
|
||||
|
||||
/** @var Course $sessionCourse */
|
||||
foreach ($sessionCourses as $sessionCourse) {
|
||||
$courseTags = [];
|
||||
|
||||
if (!is_null($tagField)) {
|
||||
$courseTags = $fieldTagsRepo->getTags($tagField, $sessionCourse->getId());
|
||||
}
|
||||
|
||||
$courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse);
|
||||
$coachesData = [];
|
||||
/** @var User $courseCoach */
|
||||
foreach ($courseCoaches as $courseCoach) {
|
||||
$coachData = [
|
||||
'complete_name' => UserManager::formatUserFullName($courseCoach),
|
||||
'image' => UserManager::getUserPicture(
|
||||
$courseCoach->getId(),
|
||||
USER_IMAGE_SIZE_ORIGINAL
|
||||
),
|
||||
'diploma' => $courseCoach->getDiplomas(),
|
||||
'openarea' => $courseCoach->getOpenarea(),
|
||||
'extra_fields' => $userValues->getAllValuesForAnItem(
|
||||
$courseCoach->getId(),
|
||||
null,
|
||||
true
|
||||
),
|
||||
];
|
||||
|
||||
$coachesData[] = $coachData;
|
||||
}
|
||||
|
||||
$cd = new CourseDescription();
|
||||
$cd->set_course_id($sessionCourse->getId());
|
||||
$cd->set_session_id($session->getId());
|
||||
$descriptionsData = $cd->get_description_data();
|
||||
|
||||
$courseDescription = [];
|
||||
$courseObjectives = [];
|
||||
$courseTopics = [];
|
||||
$courseMethodology = [];
|
||||
$courseMaterial = [];
|
||||
$courseResources = [];
|
||||
$courseAssessment = [];
|
||||
$courseCustom = [];
|
||||
|
||||
if (!empty($descriptionsData['descriptions'])) {
|
||||
foreach ($descriptionsData['descriptions'] as $descriptionInfo) {
|
||||
switch ($descriptionInfo['description_type']) {
|
||||
case CCourseDescription::TYPE_DESCRIPTION:
|
||||
$courseDescription[] = $descriptionInfo;
|
||||
break;
|
||||
case CCourseDescription::TYPE_OBJECTIVES:
|
||||
$courseObjectives[] = $descriptionInfo;
|
||||
break;
|
||||
case CCourseDescription::TYPE_TOPICS:
|
||||
$courseTopics[] = $descriptionInfo;
|
||||
break;
|
||||
case CCourseDescription::TYPE_METHODOLOGY:
|
||||
$courseMethodology[] = $descriptionInfo;
|
||||
break;
|
||||
case CCourseDescription::TYPE_COURSE_MATERIAL:
|
||||
$courseMaterial[] = $descriptionInfo;
|
||||
break;
|
||||
case CCourseDescription::TYPE_RESOURCES:
|
||||
$courseResources[] = $descriptionInfo;
|
||||
break;
|
||||
case CCourseDescription::TYPE_ASSESSMENT:
|
||||
$courseAssessment[] = $descriptionInfo;
|
||||
break;
|
||||
case CCourseDescription::TYPE_CUSTOM:
|
||||
$courseCustom[] = $descriptionInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$courses[] = [
|
||||
'course' => $sessionCourse,
|
||||
'description' => $courseDescription,
|
||||
'image' => CourseManager::getPicturePath($sessionCourse, true),
|
||||
'tags' => $courseTags,
|
||||
'objectives' => $courseObjectives,
|
||||
'topics' => $courseTopics,
|
||||
'methodology' => $courseMethodology,
|
||||
'material' => $courseMaterial,
|
||||
'resources' => $courseResources,
|
||||
'assessment' => $courseAssessment,
|
||||
'custom' => array_reverse($courseCustom),
|
||||
'coaches' => $coachesData,
|
||||
'extra_fields' => $courseValues->getAllValuesForAnItem(
|
||||
$sessionCourse->getId(),
|
||||
null,
|
||||
true
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
$sessionDates = SessionManager::parseSessionDates(
|
||||
[
|
||||
'display_start_date' => $session->getDisplayStartDate(),
|
||||
'display_end_date' => $session->getDisplayEndDate(),
|
||||
'access_start_date' => $session->getAccessStartDate(),
|
||||
'access_end_date' => $session->getAccessEndDate(),
|
||||
'coach_access_start_date' => $session->getCoachAccessStartDate(),
|
||||
'coach_access_end_date' => $session->getCoachAccessEndDate(),
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
$requirements = $sequenceResourceRepo->getRequirements(
|
||||
$session->getId(),
|
||||
SequenceResource::SESSION_TYPE
|
||||
);
|
||||
|
||||
$hasRequirements = false;
|
||||
foreach ($requirements as $sequence) {
|
||||
if (!empty($sequence['requirements'])) {
|
||||
$hasRequirements = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* View */
|
||||
$template = new Template($session->getName(), true, true, false, true, false);
|
||||
$template->assign('show_tutor', ('true' === api_get_setting('show_session_coach') ? true : false));
|
||||
$template->assign('page_url', api_get_path(WEB_PATH)."session/{$session->getId()}/about/");
|
||||
$template->assign('session', $session);
|
||||
$template->assign('session_date', $sessionDates);
|
||||
$template->assign(
|
||||
'is_subscribed',
|
||||
SessionManager::isUserSubscribedAsStudent(
|
||||
$session->getId(),
|
||||
api_get_user_id()
|
||||
)
|
||||
);
|
||||
$template->assign(
|
||||
'subscribe_button',
|
||||
CoursesAndSessionsCatalog::getRegisteredInSessionButton(
|
||||
$session->getId(),
|
||||
$session->getName(),
|
||||
$hasRequirements,
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
$template->assign(
|
||||
'user_session_time',
|
||||
SessionManager::getDayLeftInSession(
|
||||
['id' => $session->getId(), 'duration' => $session->getDuration()],
|
||||
api_get_user_id()
|
||||
)
|
||||
);
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$checker = $plugin->isEnabled();
|
||||
$sessionIsPremium = null;
|
||||
if ($checker) {
|
||||
$sessionIsPremium = $plugin->getItemByProduct(
|
||||
$sessionId,
|
||||
BuyCoursesPlugin::PRODUCT_TYPE_SESSION
|
||||
);
|
||||
if ($sessionIsPremium) {
|
||||
ChamiloSession::write('SessionIsPremium', true);
|
||||
ChamiloSession::write('sessionId', $sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
$redirectToSession = api_get_configuration_value('allow_redirect_to_session_after_inscription_about');
|
||||
$redirectToSession = $redirectToSession ? '?s='.$sessionId : false;
|
||||
|
||||
$coursesInThisSession = SessionManager::get_course_list_by_session_id($sessionId);
|
||||
$coursesCount = count($coursesInThisSession);
|
||||
$redirectToSession = 1 == $coursesCount && $redirectToSession
|
||||
? ($redirectToSession.'&cr='.array_values($coursesInThisSession)[0]['directory'])
|
||||
: $redirectToSession;
|
||||
|
||||
$template->assign('redirect_to_session', $redirectToSession);
|
||||
$template->assign('courses', $courses);
|
||||
$essence = Essence\Essence::instance();
|
||||
$template->assign('essence', $essence);
|
||||
$template->assign(
|
||||
'session_extra_fields',
|
||||
$sessionValues->getAllValuesForAnItem($session->getId(), null, true)
|
||||
);
|
||||
$template->assign('has_requirements', $hasRequirements);
|
||||
$template->assign('sequences', $requirements);
|
||||
$template->assign('is_premium', $sessionIsPremium);
|
||||
$layout = $template->get_template('session/about.tpl');
|
||||
$content = $template->fetch($layout);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
378
main/session/add_courses_to_session.php
Normal file
378
main/session/add_courses_to_session.php
Normal file
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*
|
||||
* @todo use formvalidator
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
$add = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null;
|
||||
|
||||
SessionManager::protectSession($sessionId);
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction(['search_courses', 'AddCourseToSession', 'search_courses']);
|
||||
|
||||
// Setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "resume_session.php?id_session=$sessionId",
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeCoursesToSession');
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_GET['add_type']) && $_GET['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
|
||||
|
||||
$xajax->processRequests();
|
||||
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function add_course_to_session(code, content) {
|
||||
document.getElementById("course_to_add").value = "";
|
||||
document.getElementById("ajax_list_courses_single").innerHTML = "";
|
||||
destination = document.getElementById("destination");
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
|
||||
$CourseList = $SessionList = [];
|
||||
$courses = $sessions = [];
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
$courseList = $_POST['SessionCoursesList'];
|
||||
$copyEvaluation = isset($_POST['copy_evaluation']);
|
||||
$copyCourseTeachersAsCoach = isset($_POST['import_teachers_as_course_coach']);
|
||||
$importAssignments = isset($_POST['import_assignments']);
|
||||
|
||||
SessionManager::add_courses_to_session(
|
||||
$sessionId,
|
||||
$courseList,
|
||||
true,
|
||||
$copyEvaluation,
|
||||
$copyCourseTeachersAsCoach,
|
||||
$importAssignments
|
||||
);
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
|
||||
$url = api_get_path(WEB_CODE_PATH).'session/';
|
||||
if (isset($add)) {
|
||||
header('Location: '.$url.'add_users_to_session.php?id_session='.$sessionId.'&add=true');
|
||||
} else {
|
||||
header('Location: '.$url.'resume_session.php?id_session='.$sessionId);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
// Display the header
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if ($add_type === 'multiple') {
|
||||
$link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$sessionId.'&add='.$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='.$sessionId.'&add='.$add.'&add_type=multiple">'.
|
||||
Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
|
||||
// the form header
|
||||
$session_info = SessionManager::fetch($sessionId);
|
||||
echo '<div class="actions">';
|
||||
echo $link_add_type_unique.$link_add_type_multiple;
|
||||
echo '</div>';
|
||||
|
||||
$ajax_search = $add_type === 'unique' ? true : false;
|
||||
$nosessionCourses = $sessionCourses = [];
|
||||
if ($ajax_search) {
|
||||
$sql = "SELECT course.id, code, title, visual_code, session_id
|
||||
FROM $tbl_course course
|
||||
INNER JOIN $tbl_session_rel_course session_rel_course
|
||||
ON
|
||||
course.id = session_rel_course.c_id AND
|
||||
session_rel_course.session_id = $sessionId
|
||||
ORDER BY ".(count($courses) ? "(code IN (".implode(',', $courses).")) DESC," : '')." title";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "SELECT course.id, code, title, visual_code, session_id
|
||||
FROM $tbl_course course
|
||||
INNER JOIN $tbl_session_rel_course session_rel_course
|
||||
ON course.id = session_rel_course.c_id AND session_rel_course.session_id = $sessionId
|
||||
INNER JOIN $tbl_course_rel_access_url url_course
|
||||
ON (url_course.c_id = course.id)
|
||||
WHERE access_url_id = $access_url_id
|
||||
ORDER BY ".(count($courses) ? " (code IN(".implode(',', $courses).")) DESC," : '')." title";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$Courses = Database::store_result($result);
|
||||
foreach ($Courses as $course) {
|
||||
$sessionCourses[$course['id']] = $course;
|
||||
}
|
||||
} else {
|
||||
$sql = "SELECT course.id, code, title, visual_code, session_id
|
||||
FROM $tbl_course course
|
||||
LEFT JOIN $tbl_session_rel_course session_rel_course
|
||||
ON
|
||||
course.id = session_rel_course.c_id AND
|
||||
session_rel_course.session_id = $sessionId
|
||||
ORDER BY ".(count($courses) ? "(code IN(".implode(',', $courses).")) DESC," : '')." title";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "SELECT course.id, code, title, visual_code, session_id
|
||||
FROM $tbl_course course
|
||||
LEFT JOIN $tbl_session_rel_course session_rel_course
|
||||
ON
|
||||
course.id = session_rel_course.c_id AND
|
||||
session_rel_course.session_id = $sessionId
|
||||
INNER JOIN $tbl_course_rel_access_url url_course
|
||||
ON (url_course.c_id = course.id)
|
||||
WHERE access_url_id = $access_url_id
|
||||
ORDER BY ".(count($courses) ? "(code IN(".implode(',', $courses).")) DESC," : '')." title";
|
||||
}
|
||||
}
|
||||
$result = Database::query($sql);
|
||||
$Courses = Database::store_result($result);
|
||||
foreach ($Courses as $course) {
|
||||
if ($course['session_id'] == $sessionId) {
|
||||
$sessionCourses[$course['id']] = $course;
|
||||
} else {
|
||||
$nosessionCourses[$course['id']] = $course;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!api_is_platform_admin() && api_is_teacher()) {
|
||||
$coursesFromTeacher = CourseManager::getCoursesFollowedByUser(
|
||||
api_get_user_id(),
|
||||
COURSEMANAGER
|
||||
);
|
||||
|
||||
foreach ($nosessionCourses as &$course) {
|
||||
if (in_array($course['code'], array_keys($coursesFromTeacher))) {
|
||||
continue;
|
||||
} else {
|
||||
unset($nosessionCourses[$course['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($Courses);
|
||||
?>
|
||||
<form name="formulaire"
|
||||
method="post" action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $sessionId; if (!empty($_GET['add'])) {
|
||||
echo '&add=true';
|
||||
} ?>" style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
}?>>
|
||||
<legend><?php echo $tool_name.' ('.Security::remove_XSS($session_info['name']).')'; ?></legend>
|
||||
<input type="hidden" name="formSent" value="1" />
|
||||
<div id="multiple-add-session" class="row">
|
||||
<div class="col-md-4">
|
||||
<label><?php echo get_lang('CourseListInPlatform'); ?> :</label>
|
||||
<?php
|
||||
if (!($add_type == 'multiple')) {
|
||||
?>
|
||||
<input type="text" id="course_to_add" onkeyup="xajax_search_courses(this.value, 'single', <?php echo $sessionId; ?>)" class="form-control"/>
|
||||
<div id="ajax_list_courses_single"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="ajax_list_courses_multiple">
|
||||
<select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" class="form-control">
|
||||
<?php foreach ($nosessionCourses as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')', ENT_QUOTES).'"';
|
||||
if (in_array($enreg['code'], $CourseList)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
unset($nosessionCourses);
|
||||
?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<div class="code-course">
|
||||
<?php echo get_lang('FirstLetterCourse'); ?> :
|
||||
|
||||
<select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple', <?php echo $sessionId; ?>)" class="selectpicker form-control">
|
||||
<option value="%">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options();
|
||||
echo Display::get_numeric_options(0, 9, ''); ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php
|
||||
} ?>
|
||||
<div class="control-course">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button class="btn btn-primary" type="button" onclick="remove_item(document.getElementById('destination'))">
|
||||
<em class="fa fa-chevron-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button name="add_course" class="btn btn-primary" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))">
|
||||
<em class="fa fa-chevron-right"></em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="separate-action">
|
||||
<button name="remove_course" class="btn btn-primary" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))">
|
||||
<em class="fa fa-chevron-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
} ?>
|
||||
<div class="separate-action">
|
||||
<label>
|
||||
<input type="checkbox" name="copy_evaluation">
|
||||
<?php echo get_lang('ImportGradebookInCourse'); ?>
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" name="import_teachers_as_course_coach">
|
||||
<?php echo get_lang('ImportCourseTeachersAsCourseCoach'); ?>
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" name="import_assignments">
|
||||
<?php echo get_lang('SessionImportAssignments'); ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php
|
||||
echo '<div class="separate-action">';
|
||||
if (isset($_GET['add'])) {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'.get_lang('NextStep').'</button>';
|
||||
} else {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'.get_lang('SubscribeCoursesToSession').'</button>';
|
||||
}
|
||||
echo '</div>';
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label><?php echo get_lang('CourseListInSession'); ?> :</label>
|
||||
<select id='destination' name="SessionCoursesList[]" multiple="multiple" size="20" class="form-control">
|
||||
<?php
|
||||
foreach ($sessionCourses as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')', ENT_QUOTES); ?>">
|
||||
<?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
unset($sessionCourses);
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</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('destination').options;
|
||||
for (i = 0 ; i<options.length ; i++)
|
||||
options[i].selected = true;
|
||||
|
||||
document.forms.formulaire.submit();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
890
main/session/add_edit_users_to_session.php
Normal file
890
main/session/add_edit_users_to_session.php
Normal file
@@ -0,0 +1,890 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_users');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
if (empty($id_session)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$addProcess = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null;
|
||||
|
||||
SessionManager::protectSession($id_session);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "resume_session.php?id_session=".$id_session,
|
||||
"name" => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeUsersToSession');
|
||||
$add_type = 'unique';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
|
||||
|
||||
// Checking for extra field with filter on
|
||||
|
||||
$extra_field_list = UserManager::get_extra_fields();
|
||||
|
||||
$new_field_list = [];
|
||||
if (is_array($extra_field_list)) {
|
||||
foreach ($extra_field_list as $extra_field) {
|
||||
//if is enabled to filter and is a "<select>" field type
|
||||
if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_SELECT) {
|
||||
$new_field_list[] = [
|
||||
'name' => $extra_field[3],
|
||||
'type' => $extra_field[2],
|
||||
'variable' => $extra_field[1],
|
||||
'data' => $extra_field[9],
|
||||
];
|
||||
}
|
||||
if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_TAG) {
|
||||
$options = UserManager::get_extra_user_data_for_tags($extra_field[1]);
|
||||
$new_field_list[] = [
|
||||
'name' => $extra_field[3],
|
||||
'type' => $extra_field[2],
|
||||
'variable' => $extra_field[1],
|
||||
'data' => $options['options'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function search_users($needle, $type)
|
||||
{
|
||||
global $id_session;
|
||||
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
// Normal behaviour
|
||||
if ($type == 'any_session' && $needle == 'false') {
|
||||
$type = 'multiple';
|
||||
$needle = '';
|
||||
}
|
||||
|
||||
$needle = Database::escape_string($needle);
|
||||
$order_clause = ' ORDER BY lastname, firstname, username';
|
||||
$showOfficialCode = false;
|
||||
|
||||
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
|
||||
if ($orderListByOfficialCode === 'true') {
|
||||
$showOfficialCode = true;
|
||||
$order_clause = ' ORDER BY official_code, lastname, firstname, username';
|
||||
}
|
||||
|
||||
if (api_is_session_admin()
|
||||
&& api_get_setting('prevent_session_admins_to_manage_all_users') === 'true'
|
||||
) {
|
||||
$order_clause = " AND user.creator_id = ".api_get_user_id().$order_clause;
|
||||
}
|
||||
|
||||
$cond_user_id = '';
|
||||
|
||||
// Only for single & multiple
|
||||
if (in_array($type, ['single', 'multiple'])) {
|
||||
if (!empty($id_session)) {
|
||||
$id_session = intval($id_session);
|
||||
// check id_user from session_rel_user table
|
||||
$sql = "
|
||||
SELECT user_id FROM $tbl_session_rel_user
|
||||
WHERE session_id = $id_session AND relation_type <> ".SESSION_RELATION_TYPE_RRHH;
|
||||
$res = Database::query($sql);
|
||||
$user_ids = [];
|
||||
if (Database::num_rows($res) > 0) {
|
||||
while ($row = Database::fetch_row($res)) {
|
||||
$user_ids[] = (int) $row[0];
|
||||
}
|
||||
}
|
||||
if (count($user_ids) > 0) {
|
||||
$cond_user_id = ' AND user.id NOT IN('.implode(",", $user_ids).')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'single':
|
||||
// search users where username or firstname or lastname begins likes $needle
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
(
|
||||
username LIKE '$needle%'
|
||||
OR lastname LIKE '$needle%'
|
||||
OR firstname LIKE '$needle%'
|
||||
)
|
||||
AND user.status <> 6
|
||||
AND user.status <> ".DRH."
|
||||
$order_clause LIMIT 11
|
||||
";
|
||||
break;
|
||||
case 'multiple':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
lastname LIKE '$needle%'
|
||||
AND user.status <> ".DRH."
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
case 'any_session':
|
||||
$sql = "
|
||||
SELECT DISTINCT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
LEFT OUTER JOIN $tbl_session_rel_user s ON (s.user_id = user.id)
|
||||
WHERE
|
||||
s.user_id IS NULL
|
||||
AND user.status <> ".DRH."
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
switch ($type) {
|
||||
case 'single':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = user.id)
|
||||
WHERE
|
||||
access_url_id = '$access_url_id'
|
||||
AND (
|
||||
username LIKE '$needle%'
|
||||
OR lastname LIKE '$needle%'
|
||||
OR firstname LIKE '$needle%'
|
||||
)
|
||||
AND user.status <> 6
|
||||
AND user.status <> ".DRH."
|
||||
$order_clause LIMIT 11
|
||||
";
|
||||
break;
|
||||
case 'multiple':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.id)
|
||||
WHERE
|
||||
access_url_id = $access_url_id
|
||||
AND lastname LIKE '$needle%'
|
||||
AND user.status <> ".DRH."
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
case 'any_session':
|
||||
$sql = "
|
||||
SELECT DISTINCT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
LEFT OUTER JOIN $tbl_session_rel_user s
|
||||
ON (s.user_id = user.id)
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = user.id)
|
||||
WHERE
|
||||
access_url_id = $access_url_id
|
||||
AND s.user_id IS null
|
||||
AND user.status <> ".DRH."
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rs = Database::query($sql);
|
||||
$i = 0;
|
||||
if ($type == 'single') {
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$i++;
|
||||
if ($i <= 10) {
|
||||
$person_name =
|
||||
$user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
|
||||
$person_name =
|
||||
$officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
|
||||
}
|
||||
|
||||
$return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['id']
|
||||
.'\',\''.$person_name.' '.'\')">'.$person_name.' </a><br />';
|
||||
} else {
|
||||
$return .= '...<br />';
|
||||
}
|
||||
}
|
||||
|
||||
$xajax_response->addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return));
|
||||
} else {
|
||||
global $nosessionUsersList;
|
||||
$return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$person_name =
|
||||
$user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
|
||||
$person_name = $officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
|
||||
}
|
||||
$return .= '<option value="'.$user['id'].'">'.$person_name.' </option>';
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return));
|
||||
}
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function add_user_to_session (code, content) {
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users_single").innerHTML = "";
|
||||
destination = document.getElementById("destination_users");
|
||||
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();
|
||||
}
|
||||
|
||||
function checked_in_no_session(checked) {
|
||||
$("#first_letter_user")
|
||||
.find("option")
|
||||
.attr("selected", false);
|
||||
xajax_search_users(checked, "any_session");
|
||||
}
|
||||
|
||||
function change_select(val) {
|
||||
$("#user_with_any_session_id").attr("checked", false);
|
||||
xajax_search_users(val,"multiple");
|
||||
}
|
||||
</script>';
|
||||
|
||||
$form_sent = 0;
|
||||
$errorMsg = $firstLetterUser = $firstLetterSession = '';
|
||||
$UserList = $SessionList = [];
|
||||
$sessions = [];
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : '';
|
||||
$firstLetterSession = isset($_POST['firstLetterSession']) ? $_POST['firstLetterSession'] : '';
|
||||
$UserList = isset($_POST['sessionUsersList']) ? $_POST['sessionUsersList'] : [];
|
||||
|
||||
if (!is_array($UserList)) {
|
||||
$UserList = [];
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
$notEmptyList = api_get_configuration_value('session_multiple_subscription_students_list_avoid_emptying');
|
||||
|
||||
// Added a parameter to send emails when registering a user
|
||||
SessionManager::subscribeUsersToSession(
|
||||
$id_session,
|
||||
$UserList,
|
||||
null,
|
||||
!$notEmptyList
|
||||
);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: resume_session.php?id_session='.$id_session);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$session_info = SessionManager::fetch($id_session);
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$nosessionUsersList = $sessionUsersList = [];
|
||||
$where_filter = null;
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
//$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
|
||||
// On this screen, it doesn't make sense to order users by firstname. Always use lastname first
|
||||
// api_get_person_name() calls have been removed because ordering users in a simple list must always
|
||||
// be done by lastname, even if we like to show user names with the firstname first.
|
||||
// By simple logic, lastnames are the smallest common denominator
|
||||
$order_clause = ' ORDER BY lastname, firstname, username';
|
||||
|
||||
$showOfficialCode = false;
|
||||
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
|
||||
if ($orderListByOfficialCode === 'true') {
|
||||
$showOfficialCode = true;
|
||||
$order_clause = ' ORDER BY official_code, lastname, firstname, username';
|
||||
}
|
||||
|
||||
if ($ajax_search) {
|
||||
$sql = "
|
||||
SELECT u.id, u.lastname, u.firstname, u.username, session_id, u.official_code
|
||||
FROM $tbl_user u
|
||||
INNER JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
AND su.session_id = ".intval($id_session)."
|
||||
WHERE u.status<>".DRH."
|
||||
AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, u.lastname, u.firstname, u.username, session_id, u.official_code
|
||||
FROM $tbl_user u
|
||||
INNER JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
AND su.session_id = ".intval($id_session)."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id = u.id)
|
||||
WHERE access_url_id = $access_url_id
|
||||
AND u.status <> ".DRH."
|
||||
AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result);
|
||||
foreach ($users as $user) {
|
||||
$sessionUsersList[$user['id']] = $user;
|
||||
}
|
||||
|
||||
$sessionUserInfo = SessionManager::getTotalUserCoursesInSession($id_session);
|
||||
|
||||
// Filter the user list in all courses in the session
|
||||
foreach ($sessionUserInfo as $sessionUser) {
|
||||
// filter students in session
|
||||
if ($sessionUser['status_in_session'] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!array_key_exists($sessionUser['id'], $sessionUsersList)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unset($users); //clean to free memory
|
||||
} else {
|
||||
// Filter by Extra Fields
|
||||
$extra_field_result = [];
|
||||
$use_extra_fields = false;
|
||||
if (is_array($extra_field_list)) {
|
||||
if (is_array($new_field_list) && count($new_field_list) > 0) {
|
||||
$result_list = [];
|
||||
foreach ($new_field_list as $new_field) {
|
||||
$varname = 'field_'.$new_field['variable'];
|
||||
$fieldtype = $new_field['type'];
|
||||
if (UserManager::is_extra_field_available($new_field['variable'])) {
|
||||
if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
|
||||
$use_extra_fields = true;
|
||||
if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
|
||||
$extra_field_result[] = UserManager::get_extra_user_data_by_tags(
|
||||
intval($_POST['field_id']),
|
||||
$_POST[$varname]
|
||||
);
|
||||
} else {
|
||||
$extra_field_result[] = UserManager::get_extra_user_data_by_value(
|
||||
$new_field['variable'],
|
||||
$_POST[$varname]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($use_extra_fields) {
|
||||
$final_result = [];
|
||||
if (count($extra_field_result) > 1) {
|
||||
for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
|
||||
if (is_array($extra_field_result[$i + 1])) {
|
||||
$final_result = array_intersect(
|
||||
$extra_field_result[$i],
|
||||
$extra_field_result[$i + 1]
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$final_result = $extra_field_result[0];
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
if (is_array($final_result) && count($final_result) > 0) {
|
||||
$where_filter = " AND u.id IN ('".implode("','", $final_result)."') ";
|
||||
} else {
|
||||
//no results
|
||||
$where_filter = " AND u.id = -1";
|
||||
}
|
||||
} else {
|
||||
if (is_array($final_result) && count($final_result) > 0) {
|
||||
$where_filter = " WHERE u.id IN ('".implode("','", $final_result)."') ";
|
||||
} else {
|
||||
//no results
|
||||
$where_filter = " WHERE u.id = -1";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (api_is_session_admin() && api_get_setting('prevent_session_admins_to_manage_all_users') === 'true') {
|
||||
$order_clause = " AND u.creator_id = ".api_get_user_id().$order_clause;
|
||||
}
|
||||
if ($use_extra_fields) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
$where_filter
|
||||
AND u.status <> ".DRH."
|
||||
AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
} else {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
WHERE u.status <> ".DRH." AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = u.id)
|
||||
WHERE access_url_id = $access_url_id $where_filter
|
||||
AND u.status <> ".DRH."
|
||||
AND u.status<>6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result, 'ASSOC');
|
||||
foreach ($users as $uid => $user) {
|
||||
if ($user['session_id'] != $id_session) {
|
||||
$nosessionUsersList[$user['id']] = [
|
||||
'fn' => $user['firstname'],
|
||||
'ln' => $user['lastname'],
|
||||
'un' => $user['username'],
|
||||
'official_code' => $user['official_code'],
|
||||
];
|
||||
unset($users[$uid]);
|
||||
}
|
||||
}
|
||||
unset($users); //clean to free memory
|
||||
|
||||
// filling the correct users in list
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user
|
||||
ON $tbl_session_rel_user.user_id = u.id
|
||||
AND $tbl_session_rel_user.session_id = $id_session
|
||||
AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
WHERE u.status <> ".DRH." AND u.status <> 6 $order_clause
|
||||
";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user
|
||||
ON $tbl_session_rel_user.user_id = u.id
|
||||
AND $tbl_session_rel_user.session_id = $id_session
|
||||
AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id = u.id)
|
||||
WHERE access_url_id = $access_url_id
|
||||
AND u.status <> ".DRH."
|
||||
AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result, 'ASSOC');
|
||||
foreach ($users as $uid => $user) {
|
||||
if ($user['session_id'] == $id_session) {
|
||||
$sessionUsersList[$user['id']] = $user;
|
||||
if (array_key_exists($user['id'], $nosessionUsersList)) {
|
||||
unset($nosessionUsersList[$user['id']]);
|
||||
}
|
||||
}
|
||||
unset($users[$uid]);
|
||||
}
|
||||
unset($users); //clean to free memory
|
||||
}
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique =
|
||||
'<a href="'.api_get_self().'?id_session='.$id_session.'&add='.$addProcess.'&add_type=unique">'.
|
||||
Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
|
||||
$link_add_type_multiple = Display::url(Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'), '');
|
||||
} else {
|
||||
$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.'&add='.$addProcess.'&add_type=multiple">'
|
||||
.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
$link_add_group = Display::url(
|
||||
Display::return_icon('multiple.gif', get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups'),
|
||||
api_get_path(WEB_CODE_PATH).'admin/usergroups.php'
|
||||
);
|
||||
|
||||
$newLinks = Display::url(
|
||||
Display::return_icon('teacher.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
|
||||
get_lang('EnrollTrainersFromExistingSessions'),
|
||||
api_get_path(WEB_CODE_PATH).'session/add_teachers_to_session.php?id='.$id_session
|
||||
);
|
||||
$newLinks .= Display::url(
|
||||
Display::return_icon('user.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
|
||||
get_lang('EnrollStudentsFromExistingSessions'),
|
||||
api_get_path(WEB_CODE_PATH).'session/add_students_to_session.php?id='.$id_session
|
||||
);
|
||||
?>
|
||||
<div class="actions">
|
||||
<?php
|
||||
echo $link_add_type_unique;
|
||||
echo $link_add_type_multiple;
|
||||
echo $link_add_group;
|
||||
echo $newLinks;
|
||||
?>
|
||||
</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($addProcess)) {
|
||||
echo '&add=true';
|
||||
} ?>" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
} ?>>
|
||||
<?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?>
|
||||
<?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'];
|
||||
$fieldtype = $new_field['type'];
|
||||
echo ' <select name="'.$varname.'">';
|
||||
echo '<option value="0">--'.get_lang('Select').'--</option>';
|
||||
foreach ($new_field['data'] as $option) {
|
||||
$checked = '';
|
||||
if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option['tag']) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option['tag'].'" '.$checked.'>'.$option['tag'].'</option>';
|
||||
} else {
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option[1]) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[2].'</option>';
|
||||
}
|
||||
}
|
||||
echo '</select>';
|
||||
$extraHidden =
|
||||
$fieldtype == ExtraField::FIELD_TYPE_TAG ? '<input type="hidden" name="field_id" value="'
|
||||
.$option['field_id'].'" />' : '';
|
||||
echo $extraHidden;
|
||||
echo ' ';
|
||||
}
|
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="form_sent" value="1"/>
|
||||
<input type="hidden" name="add_type"/>
|
||||
|
||||
<?php
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg); //main API
|
||||
}
|
||||
?>
|
||||
<div id="multiple-add-session" class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label><?php echo get_lang('UserListInPlatform'); ?> </label>
|
||||
<?php
|
||||
if (!($add_type == 'multiple')) {
|
||||
?>
|
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')"
|
||||
class="form-control"/>
|
||||
<div id="ajax_list_users_single" class="select-list-ajax"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="ajax_list_users_multiple">
|
||||
<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15"
|
||||
class="form-control">
|
||||
<?php
|
||||
foreach ($nosessionUsersList as $uid => $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $uid; ?>" <?php if (in_array($uid, $UserList)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php
|
||||
$personName = $enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].') '
|
||||
.$enreg['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode =
|
||||
!empty($enreg['official_code']) ? $enreg['official_code'].' - '
|
||||
: '? - ';
|
||||
$personName =
|
||||
$officialCode.$enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].')';
|
||||
}
|
||||
echo $personName; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="checkbox" onchange="checked_in_no_session(this.checked);"
|
||||
name="user_with_any_session" id="user_with_any_session_id">
|
||||
<label
|
||||
for="user_with_any_session_id"><?php echo get_lang('UsersRegisteredInNoSession'); ?></label>
|
||||
<?php
|
||||
}
|
||||
unset($nosessionUsersList);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<?php echo get_lang('FirstLetterUser'); ?> :
|
||||
<select id="first_letter_user" name="firstLetterUser" onchange="change_select(this.value);">
|
||||
<option value="%">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options(); ?>
|
||||
</select>
|
||||
<br/>
|
||||
<br/>
|
||||
<?php
|
||||
} ?>
|
||||
<div class="control-course">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button name="remove_user" class="btn btn-primary" type="button"
|
||||
onclick="remove_item(document.getElementById('destination_users'))">
|
||||
<em class="fa fa-chevron-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button name="add_user" class="btn btn-primary" type="button"
|
||||
onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))"
|
||||
onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
|
||||
<em class="fa fa-chevron-right"></em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="separate-action">
|
||||
<button name="remove_user" class="btn btn-primary" type="button"
|
||||
onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))"
|
||||
onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
|
||||
<em class="fa fa-chevron-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
if (!empty($addProcess)) {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
|
||||
.get_lang('FinishSessionCreation').'</button>';
|
||||
} else {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
|
||||
.get_lang('SubscribeUsersToSession').'</button>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label><?php echo get_lang('UserListInSession'); ?> :</label>
|
||||
<select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15"
|
||||
class="form-control">
|
||||
<?php
|
||||
foreach ($sessionUsersList as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>">
|
||||
<?php
|
||||
$personName = $enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username'].') '
|
||||
.$enreg['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode =
|
||||
!empty($enreg['official_code']) ? $enreg['official_code'].' - ' : '? - ';
|
||||
$personName =
|
||||
$officialCode.$enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username']
|
||||
.')';
|
||||
}
|
||||
echo $personName; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
unset($sessionUsersList);
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</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('destination_users').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("POST", "loadUsersInSelect.ajax.php");
|
||||
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
nosessionUsers = makepost(document.getElementById('origin_users'));
|
||||
sessionUsers = makepost(document.getElementById('destination_users'));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
308
main/session/add_many_session_to_category.php
Normal file
308
main/session/add_many_session_to_category.php
Normal file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*
|
||||
* @todo use formvalidator
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_courses');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeSessionsToCategory');
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_GET['add_type']) && $_GET['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
if (!api_is_platform_admin() && !api_is_session_admin()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function add_course_to_session (code, content) {
|
||||
document.getElementById("course_to_add").value = "";
|
||||
document.getElementById("ajax_list_courses_single").innerHTML = "";
|
||||
destination = document.getElementById("destination");
|
||||
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 send() {
|
||||
if (document.formulaire.CategorySessionId.value!=0) {
|
||||
document.formulaire.formSent.value=0;
|
||||
document.formulaire.submit();
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
|
||||
$formSent = 0;
|
||||
$errorMsg = $firstLetterCourse = $firstLetterSession = '';
|
||||
$CourseList = $SessionList = [];
|
||||
$courses = $sessions = [];
|
||||
$categoryId = isset($_POST['CategorySessionId']) ? intval($_POST['CategorySessionId']) : null;
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
$formSent = $_POST['formSent'];
|
||||
$sessionCategoryList = $_POST['SessionCategoryList'];
|
||||
|
||||
if ($categoryId != 0 && count($sessionCategoryList) > 0) {
|
||||
// Removing all
|
||||
$sql = "UPDATE $tbl_session SET session_category_id = NULL WHERE session_category_id = $categoryId";
|
||||
Database::query($sql);
|
||||
// Adding new
|
||||
$sessionCategoryList = array_map('intval', $sessionCategoryList);
|
||||
$session_id = join(',', $sessionCategoryList);
|
||||
|
||||
$sql = "UPDATE $tbl_session SET session_category_id = $categoryId WHERE id in ($session_id) ";
|
||||
Database::query($sql);
|
||||
header('Location: add_many_session_to_category.php?id_category='.$categoryId.'&msg=ok');
|
||||
exit;
|
||||
} else {
|
||||
header('Location: add_many_session_to_category.php?msg=error');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['id_category'])) {
|
||||
$categoryId = intval($_GET['id_category']);
|
||||
}
|
||||
|
||||
if (isset($_GET['msg']) && $_GET['msg'] == 'error') {
|
||||
$errorMsg = get_lang('MsgErrorSessionCategory');
|
||||
}
|
||||
|
||||
if (isset($_GET['msg']) && $_GET['msg'] == 'ok') {
|
||||
$OkMsg = get_lang('SessionCategoryUpdate');
|
||||
}
|
||||
|
||||
$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$where = '';
|
||||
$rows_category_session = [];
|
||||
if ((isset($_POST['CategorySessionId']) && $_POST['formSent'] == 0) || isset($_GET['id_category'])) {
|
||||
$where = 'WHERE session_category_id != '.$categoryId.' OR session_category_id IS NULL';
|
||||
$sql = 'SELECT id, name FROM '.$tbl_session.' WHERE session_category_id ='.$categoryId.' ORDER BY name';
|
||||
$result = Database::query($sql);
|
||||
$rows_category_session = Database::store_result($result);
|
||||
}
|
||||
|
||||
$rows_session_category = SessionManager::get_all_session_category();
|
||||
if (empty($rows_session_category)) {
|
||||
echo Display::return_message(get_lang('YouNeedToAddASessionCategoryFirst'), 'warning');
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
if (api_get_multiple_access_url()) {
|
||||
$table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
$sql = "SELECT s.id, s.name
|
||||
FROM $tbl_session s
|
||||
INNER JOIN $table_access_url_rel_session u
|
||||
ON s.id = u.session_id $where AND u.access_url_id = $access_url_id
|
||||
ORDER BY name";
|
||||
} else {
|
||||
$sql = "SELECT id, name FROM $tbl_session $where ORDER BY name";
|
||||
}
|
||||
$result = Database::query($sql);
|
||||
$rows_session = Database::store_result($result);
|
||||
?>
|
||||
<form name="formulaire" method="post"
|
||||
action="<?php echo api_get_self(); ?>?page=<?php echo $page;
|
||||
if (!empty($_GET['add'])) {
|
||||
echo '&add=true';
|
||||
} ?>" style="margin:0px;">
|
||||
<?php echo '<legend>'.$tool_name.'</legend>'; ?>
|
||||
<input type="hidden" name="formSent" value="1"/>
|
||||
<?php
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'error'); //main API
|
||||
}
|
||||
|
||||
if (!empty($OkMsg)) {
|
||||
echo Display::return_message($OkMsg, 'confirm'); //main API
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* The a/b/c Filter is not a priority
|
||||
*
|
||||
* <td width="45%" align="center">
|
||||
<?php echo get_lang('FirstLetterCourse'); ?> :
|
||||
<select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple')">
|
||||
<option value="%">--</option>
|
||||
<?php
|
||||
echo Display :: get_alphabet_options();
|
||||
echo Display :: get_numeric_options(0,9,'');
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
|
||||
*/
|
||||
?>
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
|
||||
<tr>
|
||||
<td align="left"></td>
|
||||
<td align="left"></td>
|
||||
<td align="center">
|
||||
<b><?php echo get_lang('SessionCategoryName'); ?> :</b><br />
|
||||
<select name="CategorySessionId" style="width: 320px;" onchange="javascript:send();" >
|
||||
<option value="0" ></option>
|
||||
<?php
|
||||
if (!empty($rows_session_category)) {
|
||||
foreach ($rows_session_category as $category) {
|
||||
if ($category['id'] == $categoryId) {
|
||||
echo '<option value="'.$category['id'].'" selected>'.$category['name'].'</option>';
|
||||
} else {
|
||||
echo '<option value="'.$category['id'].'">'.$category['name'].'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="45%" align="center"><b><?php echo get_lang('SessionListInPlatform'); ?> :</b></td>
|
||||
<td width="10%"> </td>
|
||||
<td align="center" width="45%"><b><?php echo get_lang('SessionListInCategory'); ?> :</b></td>
|
||||
</tr>
|
||||
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<tr>
|
||||
<td> </td></tr>
|
||||
<?php
|
||||
} ?>
|
||||
<tr>
|
||||
<td width="45%" align="center">
|
||||
<div id="ajax_list_courses_multiple">
|
||||
<select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
|
||||
<?php
|
||||
foreach ($rows_session as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'], ENT_QUOTES).'"';
|
||||
if (in_array($enreg['id'], $CourseList)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>><?php echo $enreg['name']; ?></option>
|
||||
<?php
|
||||
} ?>
|
||||
</select></div>
|
||||
<?php unset($nosessionCourses); ?>
|
||||
</td>
|
||||
<td width="10%" valign="middle" align="center">
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))">
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br /><br />
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<br /><br /><br /><br /><br /><br />
|
||||
<?php
|
||||
echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('SubscribeSessionsToCategory').'</button>';
|
||||
?>
|
||||
</td>
|
||||
<td width="45%" align="center">
|
||||
<select id='destination' name="SessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
|
||||
<?php
|
||||
foreach ($rows_category_session as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'], ENT_QUOTES).'"';
|
||||
if (in_array($enreg['id'], $CourseList)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>><?php echo $enreg['name']; ?></option>
|
||||
<?php
|
||||
} ?>
|
||||
</select></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('destination').options;
|
||||
for (i = 0; i < options.length; i++) {
|
||||
options[i].selected = true;
|
||||
}
|
||||
document.forms.formulaire.submit();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
185
main/session/add_students_to_session.php
Normal file
185
main/session/add_students_to_session.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'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 = [];
|
||||
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
SessionManager::protectSession($id);
|
||||
|
||||
$htmlResult = '';
|
||||
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([], ['name']);
|
||||
$sessionList = [];
|
||||
foreach ($session_list as $session) {
|
||||
$sessionList[$session['id']] = Security::remove_XSS($session['name']);
|
||||
}
|
||||
Display::display_header($tool_name);
|
||||
?>
|
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self().'?id='.$id; ?>" 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,
|
||||
'',
|
||||
['style' => 'width:100%', 'multiple' => 'multiple', 'id' => 'sessions', 'size' => '15px'],
|
||||
false
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
<td align="center">
|
||||
</td>
|
||||
<td align="center">
|
||||
<?php
|
||||
echo Display::select(
|
||||
'sessions_destination[]',
|
||||
$sessionList,
|
||||
'',
|
||||
['style' => 'width:100%', '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("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();
|
||||
114
main/session/add_teachers_to_session.php
Normal file
114
main/session/add_teachers_to_session.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// Setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Setting breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
|
||||
// Setting the name of the tool
|
||||
$tool_name = get_lang('EnrollTrainersFromExistingSessions');
|
||||
|
||||
$form_sent = 0;
|
||||
$errorMsg = '';
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
|
||||
SessionManager::protectSession($id);
|
||||
|
||||
$htmlResult = '';
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
|
||||
if ($form_sent == 1 &&
|
||||
isset($_POST['sessions']) && isset($_POST['courses'])
|
||||
) {
|
||||
$sessions = $_POST['sessions'];
|
||||
$courses = $_POST['courses'];
|
||||
$htmlResult = SessionManager::copyCoachesFromSessionToCourse(
|
||||
$sessions,
|
||||
$courses
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$session_list = SessionManager::get_sessions_list([], ['name']);
|
||||
$sessionList = [];
|
||||
foreach ($session_list as $session) {
|
||||
$sessionList[$session['id']] = Security::remove_XSS($session['name']);
|
||||
}
|
||||
|
||||
$courseList = CourseManager::get_courses_list(0, 0, 'title');
|
||||
$courseOptions = [];
|
||||
foreach ($courseList as $course) {
|
||||
$courseOptions[$course['id']] = $course['title'];
|
||||
}
|
||||
Display::display_header($tool_name);
|
||||
?>
|
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self().'?id='.$id; ?>">
|
||||
<?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('Courses'); ?> :</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php
|
||||
echo Display::select(
|
||||
'sessions[]',
|
||||
$sessionList,
|
||||
'',
|
||||
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'sessions', 'size' => '15px'],
|
||||
false
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
<td align="center">
|
||||
</td>
|
||||
<td align="center">
|
||||
<?php
|
||||
echo Display::select(
|
||||
'courses[]',
|
||||
$courseOptions,
|
||||
'',
|
||||
['style' => 'width:360px', 'id' => 'courses', 'size' => '15px'],
|
||||
false
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<br />
|
||||
<?php
|
||||
echo '<button class="btn btn-success" type="submit">'.
|
||||
get_lang('SubscribeTeachersToSession').'</button>';
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
953
main/session/add_users_to_session.php
Normal file
953
main/session/add_users_to_session.php
Normal file
@@ -0,0 +1,953 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
// resetting the course id
|
||||
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_users');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$id_session = isset($_REQUEST['id_session']) ? (int) $_REQUEST['id_session'] : 0;
|
||||
$addProcess = isset($_REQUEST['add']) && 'true' === $_REQUEST['add'] ? 'true' : null;
|
||||
|
||||
SessionManager::protectSession($id_session);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'resume_session.php?id_session='.$id_session,
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeUsersToSession');
|
||||
$add_type = 'unique';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
// Checking for extra field with filter on
|
||||
$extra_field_list = UserManager::get_extra_fields();
|
||||
|
||||
$new_field_list = [];
|
||||
if (is_array($extra_field_list)) {
|
||||
foreach ($extra_field_list as $extra_field) {
|
||||
//if is enabled to filter and is a "<select>" field type
|
||||
if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_SELECT) {
|
||||
$new_field_list[] = [
|
||||
'name' => $extra_field[3],
|
||||
'type' => $extra_field[2],
|
||||
'variable' => $extra_field[1],
|
||||
'data' => $extra_field[9],
|
||||
];
|
||||
}
|
||||
if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_TAG) {
|
||||
$options = UserManager::get_extra_user_data_for_tags($extra_field[1]);
|
||||
$new_field_list[] = [
|
||||
'name' => $extra_field[3],
|
||||
'type' => $extra_field[2],
|
||||
'variable' => $extra_field[1],
|
||||
'data' => $options['options'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ChamiloApi::isAjaxRequest() && isset($_POST['action'])) {
|
||||
$id_session = isset($_POST['id_session']) ? (int) $_POST['id_session'] : 0;
|
||||
$excludedUsers = isset($_POST['excludedUsers']) ? $_POST['excludedUsers'] : [];
|
||||
|
||||
$excludedUsersList = count($excludedUsers) > 0 ? implode(",", array_map('intval', $excludedUsers)) : '0';
|
||||
$accessUrlId = api_get_current_access_url_id();
|
||||
|
||||
if ($_POST['action'] == 'get_last_ten_users') {
|
||||
$sql = "SELECT u.id, u.username, u.firstname, u.lastname
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user sru ON (u.id = sru.user_id AND sru.session_id = $id_session)
|
||||
WHERE sru.user_id IS NULL
|
||||
AND u.id NOT IN ($excludedUsersList)
|
||||
AND u.id IN (
|
||||
SELECT user_id
|
||||
FROM access_url_rel_user
|
||||
WHERE access_url_id ='$accessUrlId')
|
||||
ORDER BY u.id DESC
|
||||
LIMIT 10";
|
||||
} elseif ($_POST['action'] == 'get_all_users') {
|
||||
$sql = "SELECT u.id, u.username, u.firstname, u.lastname
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user sru ON (u.id = sru.user_id AND sru.session_id = $id_session)
|
||||
WHERE sru.user_id IS NULL
|
||||
AND u.id NOT IN ($excludedUsersList)
|
||||
AND u.id IN (
|
||||
SELECT user_id
|
||||
FROM access_url_rel_user
|
||||
WHERE access_url_id ='$accessUrlId')
|
||||
ORDER BY u.lastname ASC, u.firstname ASC";
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = [];
|
||||
while ($row = Database::fetch_assoc($result)) {
|
||||
$row['complete_name_with_username'] = api_get_person_name(
|
||||
$row['firstname'],
|
||||
$row['lastname'],
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$row['username']
|
||||
);
|
||||
$row['complete_name_with_username'] .= ' ('.$row['username'].')';
|
||||
$users[] = $row;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($users);
|
||||
exit();
|
||||
}
|
||||
|
||||
function search_users($needle, $type)
|
||||
{
|
||||
global $id_session;
|
||||
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
// Normal behaviour
|
||||
if ($type == 'any_session' && $needle == 'false') {
|
||||
$type = 'multiple';
|
||||
$needle = '';
|
||||
}
|
||||
|
||||
$needle = Database::escape_string($needle);
|
||||
$order_clause = ' ORDER BY lastname, firstname, username';
|
||||
$showOfficialCode = false;
|
||||
|
||||
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
|
||||
if ($orderListByOfficialCode === 'true') {
|
||||
$showOfficialCode = true;
|
||||
$order_clause = ' ORDER BY official_code, lastname, firstname, username';
|
||||
}
|
||||
|
||||
if (api_is_session_admin()
|
||||
&& api_get_setting('prevent_session_admins_to_manage_all_users') === 'true'
|
||||
) {
|
||||
$order_clause = " AND user.creator_id = ".api_get_user_id().$order_clause;
|
||||
}
|
||||
|
||||
$cond_user_id = '';
|
||||
|
||||
// Only for single & multiple
|
||||
if (in_array($type, ['single', 'multiple'])) {
|
||||
if (!empty($id_session)) {
|
||||
$id_session = (int) $id_session;
|
||||
// check id_user from session_rel_user table
|
||||
$sql = "
|
||||
SELECT user_id FROM $tbl_session_rel_user
|
||||
WHERE session_id = $id_session AND relation_type <> ".SESSION_RELATION_TYPE_RRHH;
|
||||
$res = Database::query($sql);
|
||||
$user_ids = [];
|
||||
if (Database::num_rows($res) > 0) {
|
||||
while ($row = Database::fetch_row($res)) {
|
||||
$user_ids[] = (int) $row[0];
|
||||
}
|
||||
}
|
||||
if (count($user_ids) > 0) {
|
||||
$cond_user_id = ' AND user.id NOT IN('.implode(",", $user_ids).')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'single':
|
||||
// search users where username or firstname or lastname begins likes $needle
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
(
|
||||
username LIKE '$needle%'
|
||||
OR lastname LIKE '$needle%'
|
||||
OR firstname LIKE '$needle%'
|
||||
)
|
||||
AND user.status <> 6
|
||||
$order_clause LIMIT 11
|
||||
";
|
||||
break;
|
||||
case 'multiple':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
lastname LIKE '$needle%'
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
case 'any_session':
|
||||
$sql = "
|
||||
SELECT DISTINCT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
LEFT OUTER JOIN $tbl_session_rel_user s ON (s.user_id = user.id)
|
||||
WHERE
|
||||
s.user_id IS NULL
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
switch ($type) {
|
||||
case 'single':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = user.id)
|
||||
WHERE
|
||||
access_url_id = '$access_url_id' AND
|
||||
(
|
||||
username LIKE '$needle%' OR
|
||||
lastname LIKE '$needle%' OR
|
||||
firstname LIKE '$needle%'
|
||||
) AND
|
||||
user.status <> 6
|
||||
$order_clause LIMIT 11
|
||||
";
|
||||
break;
|
||||
case 'multiple':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.id)
|
||||
WHERE
|
||||
access_url_id = $access_url_id
|
||||
AND lastname LIKE '$needle%'
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
case 'any_session':
|
||||
$sql = "
|
||||
SELECT DISTINCT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
LEFT OUTER JOIN $tbl_session_rel_user s
|
||||
ON (s.user_id = user.id)
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = user.id)
|
||||
WHERE
|
||||
access_url_id = $access_url_id
|
||||
AND s.user_id IS null
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rs = Database::query($sql);
|
||||
$i = 0;
|
||||
if ($type == 'single') {
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$i++;
|
||||
if ($i <= 10) {
|
||||
$person_name =
|
||||
$user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
|
||||
$person_name =
|
||||
$officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
|
||||
}
|
||||
|
||||
$return .= Display::url(
|
||||
$person_name,
|
||||
'javascript: void(0);',
|
||||
['onclick' => "add_user_to_session('".$user['id']."', '".addslashes($person_name)."');"]
|
||||
).'<br>';
|
||||
} else {
|
||||
$return .= '...<br />';
|
||||
}
|
||||
}
|
||||
|
||||
$xajax_response->addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return));
|
||||
} else {
|
||||
$return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$person_name =
|
||||
$user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
|
||||
$person_name = $officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
|
||||
}
|
||||
$return .= '<option value="'.$user['id'].'">'.$person_name.' </option>';
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return));
|
||||
}
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function add_user_to_session (code, content) {
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users_single").innerHTML = "";
|
||||
destination = document.getElementById("destination_users");
|
||||
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;
|
||||
|
||||
$("#remove_user").show();
|
||||
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();
|
||||
}
|
||||
|
||||
function checked_in_no_session(checked) {
|
||||
$("#first_letter_user")
|
||||
.find("option")
|
||||
.attr("selected", false);
|
||||
xajax_search_users(checked, "any_session");
|
||||
}
|
||||
|
||||
function change_select(val) {
|
||||
$("#user_with_any_session_id").attr("checked", false);
|
||||
xajax_search_users(val,"multiple");
|
||||
}
|
||||
</script>';
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function showLastTenUsers() {
|
||||
var selectedUsers = [];
|
||||
$("#destination_users option").each(function() {
|
||||
selectedUsers.push($(this).val());
|
||||
});
|
||||
|
||||
if (selectedUsers.length === 0) {
|
||||
selectedUsers.push(0);
|
||||
}
|
||||
|
||||
var idSession = "'.(int) $id_session.'";
|
||||
$.post("'.api_get_self().'",
|
||||
{
|
||||
action: "get_last_ten_users",
|
||||
excludedUsers: selectedUsers,
|
||||
id_session: idSession,
|
||||
add: "",
|
||||
add_type: "multiple"
|
||||
}, function(data) {
|
||||
console.log(data);
|
||||
var select = document.getElementById("origin_users");
|
||||
select.innerHTML = "";
|
||||
$.each(data, function(index, user) {
|
||||
select.append(new Option(user.complete_name_with_username, user.id));
|
||||
});
|
||||
}, "json").fail(function(xhr, status, error) {
|
||||
console.error("Error en la solicitud AJAX: " + error);
|
||||
console.log(xhr.responseText);
|
||||
});
|
||||
}
|
||||
|
||||
function loadAllUsers() {
|
||||
var selectedUsers = [];
|
||||
|
||||
$("#destination_users option").each(function() {
|
||||
selectedUsers.push($(this).val());
|
||||
});
|
||||
|
||||
if (selectedUsers.length === 0) {
|
||||
selectedUsers.push(0);
|
||||
}
|
||||
|
||||
var idSession = "'.(int) $id_session.'";
|
||||
$.post("'.api_get_self().'",
|
||||
{
|
||||
action: "get_all_users",
|
||||
excludedUsers: selectedUsers,
|
||||
id_session: idSession,
|
||||
add: "",
|
||||
add_type: "multiple"
|
||||
}, function(data) {
|
||||
var select = document.getElementById("origin_users");
|
||||
select.innerHTML = "";
|
||||
|
||||
$.each(data, function(index, user) {
|
||||
select.append(new Option(user.complete_name_with_username, user.id));
|
||||
});
|
||||
}, "json").fail(function(xhr, status, error) {
|
||||
console.error("Error en la solicitud AJAX: " + error);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
loadAllUsers();
|
||||
$("#show_last_ten_users_button").on("click", showLastTenUsers);
|
||||
$("#reset_users_button").on("click", loadAllUsers);
|
||||
});
|
||||
</script>
|
||||
';
|
||||
|
||||
$form_sent = 0;
|
||||
$errorMsg = $firstLetterUser = $firstLetterSession = '';
|
||||
$UserList = $SessionList = [];
|
||||
$sessions = [];
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$UserList = isset($_POST['sessionUsersList']) ? $_POST['sessionUsersList'] : [];
|
||||
|
||||
if (!is_array($UserList)) {
|
||||
$UserList = [];
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
//$notEmptyList = api_get_configuration_value('session_multiple_subscription_students_list_avoid_emptying');
|
||||
$isLimited = api_get_configuration_value('session_course_users_subscription_limited_to_session_users');
|
||||
|
||||
// Added a parameter to send emails when registering a user
|
||||
SessionManager::subscribeUsersToSession(
|
||||
$id_session,
|
||||
$UserList,
|
||||
null,
|
||||
false,
|
||||
false === $isLimited
|
||||
);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: resume_session.php?id_session='.$id_session);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$session_info = SessionManager::fetch($id_session);
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$nosessionUsersList = $sessionUsersList = [];
|
||||
$where_filter = null;
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
//$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
|
||||
// On this screen, it doesn't make sense to order users by firstname. Always use lastname first
|
||||
// api_get_person_name() calls have been removed because ordering users in a simple list must always
|
||||
// be done by lastname, even if we like to show user names with the firstname first.
|
||||
// By simple logic, lastnames are the smallest common denominator
|
||||
$order_clause = ' ORDER BY lastname, firstname, username';
|
||||
|
||||
$showOfficialCode = false;
|
||||
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
|
||||
if ($orderListByOfficialCode === 'true') {
|
||||
$showOfficialCode = true;
|
||||
$order_clause = ' ORDER BY official_code, lastname, firstname, username';
|
||||
}
|
||||
|
||||
if ($ajax_search) {
|
||||
$sessionUserInfo = SessionManager::getTotalUserCoursesInSession($id_session);
|
||||
|
||||
// Filter the user list in all courses in the session
|
||||
foreach ($sessionUserInfo as $sessionUser) {
|
||||
// filter students in session
|
||||
if ($sessionUser['status_in_session'] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!array_key_exists($sessionUser['id'], $sessionUsersList)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unset($users); //clean to free memory
|
||||
} else {
|
||||
// Filter by Extra Fields
|
||||
$extra_field_result = [];
|
||||
$use_extra_fields = false;
|
||||
if (is_array($extra_field_list)) {
|
||||
if (is_array($new_field_list) && count($new_field_list) > 0) {
|
||||
$result_list = [];
|
||||
foreach ($new_field_list as $new_field) {
|
||||
$varname = 'field_'.$new_field['variable'];
|
||||
$fieldtype = $new_field['type'];
|
||||
if (UserManager::is_extra_field_available($new_field['variable'])) {
|
||||
if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
|
||||
$use_extra_fields = true;
|
||||
if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
|
||||
$extra_field_result[] = UserManager::get_extra_user_data_by_tags(
|
||||
intval($_POST['field_id']),
|
||||
$_POST[$varname]
|
||||
);
|
||||
} else {
|
||||
$extra_field_result[] = UserManager::get_extra_user_data_by_value(
|
||||
$new_field['variable'],
|
||||
$_POST[$varname]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($use_extra_fields) {
|
||||
$final_result = [];
|
||||
if (count($extra_field_result) > 1) {
|
||||
for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
|
||||
if (is_array($extra_field_result[$i + 1])) {
|
||||
$final_result = array_intersect(
|
||||
$extra_field_result[$i],
|
||||
$extra_field_result[$i + 1]
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$final_result = $extra_field_result[0];
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
if (is_array($final_result) && count($final_result) > 0) {
|
||||
$where_filter = " AND u.id IN ('".implode("','", $final_result)."') ";
|
||||
} else {
|
||||
//no results
|
||||
$where_filter = " AND u.id = -1";
|
||||
}
|
||||
} else {
|
||||
if (is_array($final_result) && count($final_result) > 0) {
|
||||
$where_filter = " WHERE u.id IN ('".implode("','", $final_result)."') ";
|
||||
} else {
|
||||
//no results
|
||||
$where_filter = " WHERE u.id = -1";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (api_is_session_admin() && api_get_setting('prevent_session_admins_to_manage_all_users') === 'true') {
|
||||
$order_clause = " AND u.creator_id = ".api_get_user_id().$order_clause;
|
||||
}
|
||||
if ($use_extra_fields) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
$where_filter
|
||||
AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
} else {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
WHERE u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = u.id)
|
||||
WHERE access_url_id = $access_url_id $where_filter
|
||||
AND u.status<>6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result, 'ASSOC');
|
||||
|
||||
foreach ($users as $uid => $user) {
|
||||
if ($user['session_id'] != $id_session) {
|
||||
$nosessionUsersList[$user['id']] = [
|
||||
'fn' => $user['firstname'],
|
||||
'ln' => $user['lastname'],
|
||||
'un' => $user['username'],
|
||||
'official_code' => $user['official_code'],
|
||||
];
|
||||
unset($users[$uid]);
|
||||
}
|
||||
}
|
||||
unset($users); //clean to free memory
|
||||
|
||||
// filling the correct users in list
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user
|
||||
ON $tbl_session_rel_user.user_id = u.id
|
||||
AND $tbl_session_rel_user.session_id = $id_session
|
||||
AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
WHERE u.status <> 6 $order_clause
|
||||
";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user
|
||||
ON $tbl_session_rel_user.user_id = u.id
|
||||
AND $tbl_session_rel_user.session_id = $id_session
|
||||
AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id = u.id)
|
||||
WHERE access_url_id = $access_url_id
|
||||
AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result, 'ASSOC');
|
||||
foreach ($users as $uid => $user) {
|
||||
if ($user['session_id'] == $id_session) {
|
||||
$sessionUsersList[$user['id']] = $user;
|
||||
if (array_key_exists($user['id'], $nosessionUsersList)) {
|
||||
unset($nosessionUsersList[$user['id']]);
|
||||
}
|
||||
}
|
||||
unset($users[$uid]);
|
||||
}
|
||||
unset($users); //clean to free memory
|
||||
}
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique =
|
||||
'<a href="'.api_get_self().'?id_session='.$id_session.'&add='.$addProcess.'&add_type=unique">'.
|
||||
Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
|
||||
$link_add_type_multiple = Display::url(Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'), '');
|
||||
} else {
|
||||
$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.'&add='.$addProcess.'&add_type=multiple">'
|
||||
.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
$link_add_group = Display::url(
|
||||
Display::return_icon('multiple.gif', get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups'),
|
||||
api_get_path(WEB_CODE_PATH).'admin/usergroups.php'
|
||||
);
|
||||
|
||||
$newLinks = Display::url(
|
||||
Display::return_icon('teacher.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
|
||||
get_lang('EnrollTrainersFromExistingSessions'),
|
||||
api_get_path(WEB_CODE_PATH).'session/add_teachers_to_session.php?id='.$id_session
|
||||
);
|
||||
$newLinks .= Display::url(
|
||||
Display::return_icon('user.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
|
||||
get_lang('EnrollStudentsFromExistingSessions'),
|
||||
api_get_path(WEB_CODE_PATH).'session/add_students_to_session.php?id='.$id_session
|
||||
);
|
||||
?>
|
||||
<div class="actions">
|
||||
<?php
|
||||
echo $link_add_type_unique;
|
||||
echo $link_add_type_multiple;
|
||||
echo $link_add_group;
|
||||
echo $newLinks;
|
||||
?>
|
||||
</div>
|
||||
<form name="formulaire" method="post"
|
||||
action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?><?php if (!empty($addProcess)) {
|
||||
echo '&add=true';
|
||||
} ?>" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
} ?>>
|
||||
<?php echo '<legend>'.$tool_name.' ('.Security::remove_XSS($session_info['name']).') </legend>'; ?>
|
||||
<?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'];
|
||||
$fieldtype = $new_field['type'];
|
||||
echo ' <select name="'.$varname.'">';
|
||||
echo '<option value="0">--'.get_lang('Select').'--</option>';
|
||||
foreach ($new_field['data'] as $option) {
|
||||
$checked = '';
|
||||
if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option['tag']) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option['tag'].'" '.$checked.'>'.$option['tag'].'</option>';
|
||||
} else {
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option[1]) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[2].'</option>';
|
||||
}
|
||||
}
|
||||
echo '</select>';
|
||||
$extraHidden =
|
||||
$fieldtype == ExtraField::FIELD_TYPE_TAG ? '<input type="hidden" name="field_id" value="'
|
||||
.$option['field_id'].'" />' : '';
|
||||
echo $extraHidden;
|
||||
echo ' ';
|
||||
}
|
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="form_sent" value="1"/>
|
||||
<input type="hidden" name="add_type"/>
|
||||
|
||||
<?php
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg); //main API
|
||||
}
|
||||
?>
|
||||
<div id="multiple-add-session" class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<?php
|
||||
if (!($add_type == 'multiple')) {
|
||||
?>
|
||||
<input
|
||||
placeholder="<?php echo get_lang('Search'); ?>"
|
||||
type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')"
|
||||
class="form-control"/>
|
||||
<div id="ajax_list_users_single" class="select-list-ajax"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="ajax_list_users_multiple">
|
||||
<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15"
|
||||
class="form-control">
|
||||
<?php
|
||||
foreach ($nosessionUsersList as $uid => $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $uid; ?>" <?php if (in_array($uid, $UserList)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php
|
||||
$personName = $enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].') '
|
||||
.$enreg['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode =
|
||||
!empty($enreg['official_code']) ? $enreg['official_code'].' - '
|
||||
: '? - ';
|
||||
$personName =
|
||||
$officialCode.$enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].')';
|
||||
}
|
||||
echo $personName; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
<input type="checkbox" onchange="checked_in_no_session(this.checked);"
|
||||
name="user_with_any_session" id="user_with_any_session_id">
|
||||
<label
|
||||
for="user_with_any_session_id"><?php echo get_lang('UsersRegisteredInNoSession'); ?></label>
|
||||
<?php
|
||||
}
|
||||
unset($nosessionUsersList);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<?php echo get_lang('FirstLetterUser'); ?> :
|
||||
<select id="first_letter_user" name="firstLetterUser" onchange="change_select(this.value);">
|
||||
<option value="%">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options(); ?>
|
||||
</select>
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="button" id="show_last_ten_users_button" title="<?php echo get_lang('ShowLastTenUsers'); ?>">
|
||||
<i class="fa fa-clock-o"></i>
|
||||
</button>
|
||||
<button class="btn btn-default" type="button" id="reset_users_button" title="<?php echo get_lang('Reset'); ?>">
|
||||
<i class="fa fa-refresh"></i>
|
||||
</button>
|
||||
</span>
|
||||
<br/>
|
||||
<br/>
|
||||
<?php
|
||||
} ?>
|
||||
<div class="control-course">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button name="add_user" class="btn btn-primary" type="button"
|
||||
onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))"
|
||||
onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
|
||||
<em class="fa fa-chevron-right"></em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="separate-action">
|
||||
<button name="remove_user" class="btn btn-primary" type="button"
|
||||
onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))"
|
||||
onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
|
||||
<em class="fa fa-chevron-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
if (!empty($addProcess)) {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
|
||||
.get_lang('FinishSessionCreation').'</button>';
|
||||
} else {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
|
||||
.get_lang('SubscribeUsersToSession').'</button>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15"
|
||||
class="form-control">
|
||||
</select>
|
||||
<br />
|
||||
<button style="display:none" id="remove_user" name="remove_user" class="btn btn-danger" type="button"
|
||||
onclick="remove_item(document.getElementById('destination_users'))">
|
||||
<?php echo get_lang('Remove'); ?> <em class="fa fa-trash"></em>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</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('destination_users').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("POST", "loadUsersInSelect.ajax.php");
|
||||
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
nosessionUsers = makepost(document.getElementById('origin_users'));
|
||||
sessionUsers = makepost(document.getElementById('destination_users'));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
916
main/session/add_users_to_session_course.php
Normal file
916
main/session/add_users_to_session_course.php
Normal file
@@ -0,0 +1,916 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_users');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
$courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
|
||||
|
||||
if (empty($id_session) || empty($courseId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$addProcess = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null;
|
||||
|
||||
SessionManager::protectSession($id_session);
|
||||
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "resume_session.php?id_session=".$id_session,
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tableRelSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeUsersToSession');
|
||||
$add_type = 'unique';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
|
||||
|
||||
// Checking for extra field with filter on
|
||||
|
||||
$extra_field_list = UserManager::get_extra_fields();
|
||||
|
||||
$new_field_list = [];
|
||||
if (is_array($extra_field_list)) {
|
||||
foreach ($extra_field_list as $extra_field) {
|
||||
//if is enabled to filter and is a "<select>" field type
|
||||
if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_SELECT) {
|
||||
$new_field_list[] = [
|
||||
'name' => $extra_field[3],
|
||||
'type' => $extra_field[2],
|
||||
'variable' => $extra_field[1],
|
||||
'data' => $extra_field[9],
|
||||
];
|
||||
}
|
||||
if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_TAG) {
|
||||
$options = UserManager::get_extra_user_data_for_tags($extra_field[1]);
|
||||
$new_field_list[] = [
|
||||
'name' => $extra_field[3],
|
||||
'type' => $extra_field[2],
|
||||
'variable' => $extra_field[1],
|
||||
'data' => $options['options'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function search_users($needle, $type)
|
||||
{
|
||||
global $id_session, $courseId;
|
||||
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tableRelSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
||||
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
// Normal behaviour
|
||||
if ($type == 'any_session' && $needle == 'false') {
|
||||
$type = 'multiple';
|
||||
$needle = '';
|
||||
}
|
||||
|
||||
$needle = Database::escape_string($needle);
|
||||
$order_clause = ' ORDER BY lastname, firstname, username';
|
||||
$showOfficialCode = false;
|
||||
|
||||
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
|
||||
if ($orderListByOfficialCode === 'true') {
|
||||
$showOfficialCode = true;
|
||||
$order_clause = ' ORDER BY official_code, lastname, firstname, username';
|
||||
}
|
||||
|
||||
if (api_is_session_admin()
|
||||
&& api_get_setting('prevent_session_admins_to_manage_all_users') === 'true'
|
||||
) {
|
||||
$order_clause = ' AND user.creator_id = '.api_get_user_id().$order_clause;
|
||||
}
|
||||
|
||||
$cond_user_id = '';
|
||||
|
||||
// Only for single & multiple
|
||||
if (in_array($type, ['single', 'multiple'])) {
|
||||
if (!empty($id_session)) {
|
||||
$id_session = (int) $id_session;
|
||||
// check id_user from session_rel_user table
|
||||
$sql = "
|
||||
SELECT su.user_id
|
||||
FROM $tbl_session_rel_user su
|
||||
INNER JOIN $tableRelSessionCourseUser sc
|
||||
ON (sc.session_id = su.session_id AND su.user_id = sc.user_id)
|
||||
WHERE
|
||||
sc.c_id = $courseId AND
|
||||
su.session_id = $id_session AND
|
||||
relation_type <> ".SESSION_RELATION_TYPE_RRHH;
|
||||
$res = Database::query($sql);
|
||||
$user_ids = [];
|
||||
if (Database::num_rows($res) > 0) {
|
||||
while ($row = Database::fetch_row($res)) {
|
||||
$user_ids[] = (int) $row[0];
|
||||
}
|
||||
}
|
||||
if (count($user_ids) > 0) {
|
||||
$cond_user_id = ' AND user.id NOT IN('.implode(",", $user_ids).')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 'single':
|
||||
// search users where username or firstname or lastname begins likes $needle
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
(
|
||||
username LIKE '$needle%'
|
||||
OR lastname LIKE '$needle%'
|
||||
OR firstname LIKE '$needle%'
|
||||
) AND
|
||||
user.status <> 6 AND
|
||||
user.status <> ".DRH."
|
||||
$order_clause
|
||||
LIMIT 11
|
||||
";
|
||||
break;
|
||||
case 'multiple':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
lastname LIKE '$needle%' AND
|
||||
user.status <> ".DRH." AND
|
||||
user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
case 'any_session':
|
||||
$sql = "
|
||||
SELECT DISTINCT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
LEFT OUTER JOIN $tbl_session_rel_user s
|
||||
ON (s.user_id = user.id)
|
||||
WHERE
|
||||
s.user_id IS NULL AND
|
||||
user.status <> ".DRH." AND
|
||||
user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
switch ($type) {
|
||||
case 'single':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = user.id)
|
||||
WHERE
|
||||
access_url_id = '$access_url_id'
|
||||
AND (
|
||||
username LIKE '$needle%'
|
||||
OR lastname LIKE '$needle%'
|
||||
OR firstname LIKE '$needle%'
|
||||
)
|
||||
AND user.status <> 6
|
||||
AND user.status <> ".DRH."
|
||||
$order_clause LIMIT 11
|
||||
";
|
||||
break;
|
||||
case 'multiple':
|
||||
$sql = "
|
||||
SELECT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.id)
|
||||
WHERE
|
||||
access_url_id = $access_url_id
|
||||
AND lastname LIKE '$needle%'
|
||||
AND user.status <> ".DRH."
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
case 'any_session':
|
||||
$sql = "
|
||||
SELECT DISTINCT user.id, username, lastname, firstname, official_code
|
||||
FROM $tbl_user user
|
||||
LEFT OUTER JOIN $tbl_session_rel_user s
|
||||
ON (s.user_id = user.id)
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = user.id)
|
||||
WHERE
|
||||
access_url_id = $access_url_id
|
||||
AND s.user_id IS null
|
||||
AND user.status <> ".DRH."
|
||||
AND user.status <> 6 $cond_user_id
|
||||
$order_clause
|
||||
";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rs = Database::query($sql);
|
||||
$i = 0;
|
||||
if ($type == 'single') {
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$i++;
|
||||
if ($i <= 10) {
|
||||
$person_name =
|
||||
$user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
|
||||
$person_name =
|
||||
$officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
|
||||
}
|
||||
|
||||
$return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['id']
|
||||
.'\',\''.addslashes(htmlentities($person_name)).' '.'\')">'.$person_name.' </a><br />';
|
||||
} else {
|
||||
$return .= '...<br />';
|
||||
}
|
||||
}
|
||||
|
||||
$xajax_response->addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return));
|
||||
} else {
|
||||
$return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$person_name =
|
||||
$user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
|
||||
$person_name = $officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
|
||||
}
|
||||
$return .= '<option value="'.$user['id'].'">'.$person_name.' </option>';
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return));
|
||||
}
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function add_user_to_session (code, content) {
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users_single").innerHTML = "";
|
||||
destination = document.getElementById("destination_users");
|
||||
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();
|
||||
}
|
||||
|
||||
function checked_in_no_session(checked) {
|
||||
$("#first_letter_user")
|
||||
.find("option")
|
||||
.attr("selected", false);
|
||||
xajax_search_users(checked, "any_session");
|
||||
}
|
||||
|
||||
function change_select(val) {
|
||||
$("#user_with_any_session_id").attr("checked", false);
|
||||
xajax_search_users(val,"multiple");
|
||||
}
|
||||
</script>';
|
||||
|
||||
$form_sent = 0;
|
||||
$errorMsg = $firstLetterUser = $firstLetterSession = '';
|
||||
$UserList = $SessionList = [];
|
||||
$sessions = [];
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : '';
|
||||
$firstLetterSession = isset($_POST['firstLetterSession']) ? $_POST['firstLetterSession'] : '';
|
||||
$UserList = isset($_POST['sessionUsersList']) ? $_POST['sessionUsersList'] : [];
|
||||
|
||||
if (!is_array($UserList)) {
|
||||
$UserList = [];
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
// Added a parameter to send emails when registering a user
|
||||
SessionManager::subscribeUsersToSession(
|
||||
$id_session,
|
||||
$UserList,
|
||||
null,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
SessionManager::subscribe_users_to_session_course(
|
||||
$UserList,
|
||||
$id_session,
|
||||
$courseInfo['code']
|
||||
);
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: resume_session.php?id_session='.$id_session);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$session_info = SessionManager::fetch($id_session);
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$nosessionUsersList = $sessionUsersList = [];
|
||||
$where_filter = null;
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
//$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
|
||||
// On this screen, it doesn't make sense to order users by firstname. Always use lastname first
|
||||
// api_get_person_name() calls have been removed because ordering users in a simple list must always
|
||||
// be done by lastname, even if we like to show user names with the firstname first.
|
||||
// By simple logic, lastnames are the smallest common denominator
|
||||
$order_clause = ' ORDER BY lastname, firstname, username';
|
||||
|
||||
$showOfficialCode = false;
|
||||
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
|
||||
if ($orderListByOfficialCode === 'true') {
|
||||
$showOfficialCode = true;
|
||||
$order_clause = ' ORDER BY official_code, lastname, firstname, username';
|
||||
}
|
||||
|
||||
if ($ajax_search) {
|
||||
$sql = "
|
||||
SELECT u.id, u.lastname, u.firstname, u.username, su.session_id, u.official_code
|
||||
FROM $tbl_session_rel_user su
|
||||
INNER JOIN $tableRelSessionCourseUser sc
|
||||
ON (sc.session_id = su.session_id AND su.user_id = sc.user_id)
|
||||
INNER JOIN $tbl_user u
|
||||
ON su.user_id = u.id
|
||||
WHERE
|
||||
su.session_id = ".intval($id_session)." AND
|
||||
su.relation_type <> ".SESSION_RELATION_TYPE_RRHH." AND
|
||||
sc.c_id = $courseId AND
|
||||
u.status<>".DRH." AND
|
||||
u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, u.lastname, u.firstname, u.username, su.session_id, u.official_code
|
||||
FROM $tbl_user u
|
||||
INNER JOIN $tbl_session_rel_user su
|
||||
ON
|
||||
su.user_id = u.id AND
|
||||
su.relation_type <> ".SESSION_RELATION_TYPE_RRHH." AND
|
||||
su.session_id = ".intval($id_session)."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = u.id)
|
||||
INNER JOIN $tableRelSessionCourseUser sc
|
||||
ON (sc.session_id = su.session_id AND su.user_id = sc.user_id)
|
||||
WHERE
|
||||
access_url_id = $access_url_id AND
|
||||
sc.c_id = $courseId AND
|
||||
u.status <> ".DRH." AND
|
||||
u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result);
|
||||
foreach ($users as $user) {
|
||||
$sessionUsersList[$user['id']] = $user;
|
||||
}
|
||||
|
||||
$sessionUserInfo = SessionManager::getTotalUserCoursesInSession($id_session, $courseId);
|
||||
// Filter the user list in all courses in the session
|
||||
foreach ($sessionUserInfo as $sessionUser) {
|
||||
// filter students in session
|
||||
if ($sessionUser['status_in_session'] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!array_key_exists($sessionUser['id'], $sessionUsersList)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unset($users); //clean to free memory
|
||||
} else {
|
||||
// Filter by Extra Fields
|
||||
$extra_field_result = [];
|
||||
$use_extra_fields = false;
|
||||
if (is_array($extra_field_list)) {
|
||||
if (is_array($new_field_list) && count($new_field_list) > 0) {
|
||||
$result_list = [];
|
||||
foreach ($new_field_list as $new_field) {
|
||||
$varname = 'field_'.$new_field['variable'];
|
||||
$fieldtype = $new_field['type'];
|
||||
if (UserManager::is_extra_field_available($new_field['variable'])) {
|
||||
if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
|
||||
$use_extra_fields = true;
|
||||
if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
|
||||
$extra_field_result[] = UserManager::get_extra_user_data_by_tags(
|
||||
$_POST['field_id'],
|
||||
$_POST[$varname]
|
||||
);
|
||||
} else {
|
||||
$extra_field_result[] = UserManager::get_extra_user_data_by_value(
|
||||
$new_field['variable'],
|
||||
$_POST[$varname]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($use_extra_fields) {
|
||||
$final_result = [];
|
||||
if (count($extra_field_result) > 1) {
|
||||
for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
|
||||
if (is_array($extra_field_result[$i + 1])) {
|
||||
$final_result = array_intersect(
|
||||
$extra_field_result[$i],
|
||||
$extra_field_result[$i + 1]
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$final_result = $extra_field_result[0];
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
if (is_array($final_result) && count($final_result) > 0) {
|
||||
$where_filter = " AND u.id IN ('".implode("','", $final_result)."') ";
|
||||
} else {
|
||||
//no results
|
||||
$where_filter = " AND u.id = -1";
|
||||
}
|
||||
} else {
|
||||
if (is_array($final_result) && count($final_result) > 0) {
|
||||
$where_filter = " WHERE u.id IN ('".implode("','", $final_result)."') ";
|
||||
} else {
|
||||
//no results
|
||||
$where_filter = " WHERE u.id = -1";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (api_is_session_admin() && api_get_setting('prevent_session_admins_to_manage_all_users') === 'true') {
|
||||
$order_clause = " AND u.creator_id = ".api_get_user_id().$order_clause;
|
||||
}
|
||||
if ($use_extra_fields) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, su.session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tableRelSessionCourseUser sc
|
||||
ON (sc.session_id = su.session_id AND su.user_id = sc.user_id)
|
||||
$where_filter
|
||||
AND u.status <> ".DRH."
|
||||
AND u.status <> 6
|
||||
AND sc.c_id = $courseId
|
||||
$order_clause
|
||||
";
|
||||
} else {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, su.session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
WHERE
|
||||
u.status <> ".DRH." AND
|
||||
u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, su.session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = u.id)
|
||||
|
||||
WHERE
|
||||
access_url_id = $access_url_id
|
||||
$where_filter
|
||||
AND u.status <> ".DRH."
|
||||
AND u.status<>6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result, 'ASSOC');
|
||||
foreach ($users as $uid => $user) {
|
||||
if ($user['session_id'] != $id_session) {
|
||||
$nosessionUsersList[$user['id']] = [
|
||||
'fn' => $user['firstname'],
|
||||
'ln' => $user['lastname'],
|
||||
'un' => $user['username'],
|
||||
'official_code' => $user['official_code'],
|
||||
];
|
||||
unset($users[$uid]);
|
||||
}
|
||||
}
|
||||
unset($users); //clean to free memory
|
||||
|
||||
// filling the correct users in list
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, su.session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tableRelSessionCourseUser sc
|
||||
ON (sc.session_id = su.session_id AND su.user_id = sc.user_id)
|
||||
WHERE
|
||||
sc.c_id = $courseId AND
|
||||
u.status <> ".DRH." AND u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "
|
||||
SELECT u.id, lastname, firstname, username, su.session_id, official_code
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_session_rel_user su
|
||||
ON su.user_id = u.id
|
||||
AND su.session_id = $id_session
|
||||
AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tbl_user_rel_access_url url_user
|
||||
ON (url_user.user_id = u.id)
|
||||
INNER JOIN $tableRelSessionCourseUser sc
|
||||
ON (sc.session_id = su.session_id AND su.user_id = sc.user_id)
|
||||
WHERE
|
||||
sc.c_id = $courseId AND
|
||||
access_url_id = $access_url_id AND
|
||||
u.status <> ".DRH." AND
|
||||
u.status <> 6
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result, 'ASSOC');
|
||||
foreach ($users as $uid => $user) {
|
||||
if ($user['session_id'] == $id_session) {
|
||||
$sessionUsersList[$user['id']] = $user;
|
||||
if (array_key_exists($user['id'], $nosessionUsersList)) {
|
||||
unset($nosessionUsersList[$user['id']]);
|
||||
}
|
||||
}
|
||||
unset($users[$uid]);
|
||||
}
|
||||
unset($users); //clean to free memory
|
||||
}
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique =
|
||||
'<a href="'.api_get_self().'?course_id='.$courseId.'&id_session='.$id_session.'&add='.$addProcess.'&add_type=unique">'.
|
||||
Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
|
||||
$link_add_type_multiple = Display::url(Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'), '');
|
||||
} else {
|
||||
$link_add_type_unique = Display::url(Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'), '');
|
||||
$link_add_type_multiple =
|
||||
'<a href="'.api_get_self().'?course_id='.$courseId.'&id_session='.$id_session.'&add='.$addProcess.'&add_type=multiple">'
|
||||
.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
?>
|
||||
<div class="actions">
|
||||
<?php
|
||||
echo $link_add_type_unique;
|
||||
echo $link_add_type_multiple;
|
||||
?>
|
||||
</div>
|
||||
<form name="formulaire" method="post"
|
||||
action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&course_id=<?php echo $courseId; ?>&id_session=<?php echo $id_session; ?><?php if (!empty($addProcess)) {
|
||||
echo '&add=true';
|
||||
} ?>" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
} ?>>
|
||||
<?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') - '.$courseInfo['title'].' </legend>'; ?>
|
||||
<?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'];
|
||||
$fieldtype = $new_field['type'];
|
||||
echo ' <select name="'.$varname.'">';
|
||||
echo '<option value="0">--'.get_lang('Select').'--</option>';
|
||||
foreach ($new_field['data'] as $option) {
|
||||
$checked = '';
|
||||
if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option['tag']) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option['tag'].'" '.$checked.'>'.$option['tag'].'</option>';
|
||||
} else {
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option[1]) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[2].'</option>';
|
||||
}
|
||||
}
|
||||
echo '</select>';
|
||||
$extraHidden =
|
||||
$fieldtype == ExtraField::FIELD_TYPE_TAG ? '<input type="hidden" name="field_id" value="'
|
||||
.$option['field_id'].'" />' : '';
|
||||
echo $extraHidden;
|
||||
echo ' ';
|
||||
}
|
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="form_sent" value="1"/>
|
||||
<input type="hidden" name="add_type"/>
|
||||
|
||||
<?php
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg); //main API
|
||||
}
|
||||
?>
|
||||
<div id="multiple-add-session" class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label><?php echo get_lang('UserListInPlatform'); ?> </label>
|
||||
<?php
|
||||
if (!($add_type == 'multiple')) {
|
||||
?>
|
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')"
|
||||
class="form-control"/>
|
||||
<div id="ajax_list_users_single" class="select-list-ajax"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="ajax_list_users_multiple">
|
||||
<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15"
|
||||
class="form-control">
|
||||
<?php
|
||||
foreach ($nosessionUsersList as $uid => $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $uid; ?>" <?php if (in_array($uid, $UserList)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php
|
||||
$personName = $enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].') '
|
||||
.$enreg['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode =
|
||||
!empty($enreg['official_code']) ? $enreg['official_code'].' - '
|
||||
: '? - ';
|
||||
$personName =
|
||||
$officialCode.$enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].')';
|
||||
}
|
||||
echo $personName; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
unset($nosessionUsersList);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<?php echo get_lang('FirstLetterUser'); ?> :
|
||||
<select id="first_letter_user" name="firstLetterUser" onchange="change_select(this.value);">
|
||||
<option value="%">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options(); ?>
|
||||
</select>
|
||||
<br/>
|
||||
<br/>
|
||||
<?php
|
||||
} ?>
|
||||
<div class="control-course">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button name="remove_user" class="btn btn-primary" type="button"
|
||||
onclick="remove_item(document.getElementById('destination_users'))">
|
||||
<em class="fa fa-chevron-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button name="add_user" class="btn btn-primary" type="button"
|
||||
onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))"
|
||||
onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
|
||||
<em class="fa fa-chevron-right"></em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="separate-action">
|
||||
<button name="remove_user" class="btn btn-primary" type="button"
|
||||
onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))"
|
||||
onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
|
||||
<em class="fa fa-chevron-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
if (!empty($addProcess)) {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
|
||||
.get_lang('FinishSessionCreation').'</button>';
|
||||
} else {
|
||||
echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
|
||||
.get_lang('SubscribeUsersToSession').'</button>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label><?php echo get_lang('UserListInSession'); ?> :</label>
|
||||
<select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15"
|
||||
class="form-control">
|
||||
<?php
|
||||
foreach ($sessionUsersList as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>">
|
||||
<?php
|
||||
$personName = $enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username'].') '
|
||||
.$enreg['official_code'];
|
||||
if ($showOfficialCode) {
|
||||
$officialCode =
|
||||
!empty($enreg['official_code']) ? $enreg['official_code'].' - ' : '? - ';
|
||||
$personName =
|
||||
$officialCode.$enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username']
|
||||
.')';
|
||||
}
|
||||
echo $personName; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
unset($sessionUsersList);
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</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('destination_users').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("POST", "loadUsersInSelect.ajax.php");
|
||||
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
nosessionUsers = makepost(document.getElementById('origin_users'));
|
||||
sessionUsers = makepost(document.getElementById('destination_users'));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
2
main/session/importCourseEventInSessionExample.csv
Normal file
2
main/session/importCourseEventInSessionExample.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
StartDate;EndDate
|
||||
YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss
|
||||
|
192
main/session/import_course_agenda_reminders.php
Normal file
192
main/session/import_course_agenda_reminders.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$sessionId = api_get_session_id();
|
||||
$sessionUrl = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$sessionId;
|
||||
$selfUrl = api_get_self()."?session_id=$sessionId";
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$isAgendaRemindersEnabled = api_get_configuration_value('agenda_reminders');
|
||||
|
||||
if (!$isAgendaRemindersEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$tblPersonalAgenda = Database::get_main_table(TABLE_PERSONAL_AGENDA);
|
||||
|
||||
$tags = AnnouncementManager::getTags([
|
||||
'((course_title))',
|
||||
'((course_link))',
|
||||
'((teachers))',
|
||||
'((coaches))',
|
||||
]);
|
||||
$tags[] = '((date_start))';
|
||||
$tags[] = '((date_end))';
|
||||
$tags[] = '((session_name))';
|
||||
|
||||
$tagsHelp = '<strong>'.get_lang('Tags').'</strong>'
|
||||
.'<pre>'.implode("\n", $tags).'</pre>';
|
||||
|
||||
$fileHelpText = get_lang('ImportCSVFileLocation').'<br>'
|
||||
.Display::url(
|
||||
get_lang('ExampleCSVFile'),
|
||||
'importCourseEventInSessionExample.csv',
|
||||
[
|
||||
'target' => '_blank',
|
||||
'download' => 'importCourseEventInSessionExample.csv',
|
||||
]
|
||||
)
|
||||
.'<pre>StartDate;EndDate<br>YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss</pre>';
|
||||
|
||||
$form = new FormValidator('agenda_reminders', 'post', $selfUrl);
|
||||
$form->addHeader(get_lang('CsvImport'));
|
||||
$form->addFile(
|
||||
'events_file',
|
||||
[get_lang('ImportAsCSV'), $fileHelpText],
|
||||
['accept' => 'text/csv']
|
||||
);
|
||||
$form->addRule('events_file', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('events_file', get_lang('InvalidExtension'), 'filetype', ['csv']);
|
||||
$form->addHeader(get_lang('AddEventInCourseCalendar'));
|
||||
$form->addText(
|
||||
'title',
|
||||
[get_lang('ItemTitle'), get_lang('TagsCanBeUsed')],
|
||||
true,
|
||||
['cols-size' => [2, 7, 3]]
|
||||
);
|
||||
$form->applyFilter('title', 'trim');
|
||||
$form->addHtmlEditor(
|
||||
'description',
|
||||
[get_lang('Description'), null, $tagsHelp],
|
||||
true,
|
||||
false,
|
||||
['ToolbarSet' => 'Minimal', 'cols-size' => [2, 7, 3]]
|
||||
);
|
||||
//$form->applyFilter('description', 'html_filter_teacher');
|
||||
|
||||
if ($isAgendaRemindersEnabled) {
|
||||
$form->addHeader(get_lang('NotifyBeforeTheEventStarts'));
|
||||
$form->addHtml('<div id="notification_list"></div>');
|
||||
$form->addButton('add_notification', get_lang('AddNotification'), 'bell-o')->setType('button');
|
||||
}
|
||||
|
||||
$form->addHtml('<hr>');
|
||||
$form->addButtonImport(get_lang('Import'));
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$uploadInfo = pathinfo($_FILES['events_file']['name']);
|
||||
$notificationCount = $_POST['notification_count'] ?? [];
|
||||
$notificationPeriod = $_POST['notification_period'] ?? [];
|
||||
$session = api_get_session_entity($sessionId);
|
||||
|
||||
$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];
|
||||
|
||||
if ('csv' !== $uploadInfo['extension']) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('NotCSV'), 'error')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$csvEvents = Import::csvToArray($_FILES['events_file']['tmp_name']);
|
||||
|
||||
if (empty($csvEvents)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$agenda = new Agenda('personal');
|
||||
|
||||
$grouppedData = [];
|
||||
|
||||
$studentList = SessionManager::get_users_by_session($sessionId, Session::STUDENT);
|
||||
|
||||
foreach ($csvEvents as $csvEvent) {
|
||||
$hashDate = base64_encode($csvEvent['StartDate'].'||'.$csvEvent['EndDate']);
|
||||
|
||||
foreach ($studentList as $studentInfo) {
|
||||
$grouppedData[$hashDate][] = $studentInfo['user_id'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($grouppedData as $hashDate => $userIdList) {
|
||||
$dateRange = base64_decode($hashDate);
|
||||
list($dateStart, $dateEnd) = explode('||', $dateRange);
|
||||
|
||||
$dateStart = api_get_utc_datetime($dateStart);
|
||||
$dateEnd = api_get_utc_datetime($dateEnd);
|
||||
|
||||
$strDateStart = api_format_date($dateStart, DATE_TIME_FORMAT_LONG_24H);
|
||||
$strDateEnd = api_format_date($dateEnd, DATE_TIME_FORMAT_LONG_24H);
|
||||
|
||||
foreach ($userIdList as $userId) {
|
||||
$title = AnnouncementManager::parseContent($userId, $values['title'], '', $sessionId);
|
||||
$content = AnnouncementManager::parseContent($userId, $values['description'], '', $sessionId);
|
||||
|
||||
$title = str_replace(['((date_start))', '((date_end))', '((session_name))'], [$strDateStart, $strDateEnd, $session->getName()], $title);
|
||||
$content = str_replace(['((date_start))', '((date_end))', '((session_name))'], [$strDateStart, $strDateEnd, $session->getName()], $content);
|
||||
|
||||
$eventId = Database::insert(
|
||||
$tblPersonalAgenda,
|
||||
[
|
||||
'user' => $userId,
|
||||
'title' => $title,
|
||||
'text' => $content,
|
||||
'date' => $dateStart,
|
||||
'enddate' => $dateEnd,
|
||||
'all_day' => 0,
|
||||
'color' => '',
|
||||
]
|
||||
);
|
||||
|
||||
if ($isAgendaRemindersEnabled) {
|
||||
foreach ($reminders as $reminder) {
|
||||
$agenda->addReminder($eventId, $reminder[0], $reminder[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('FileImported'), 'success')
|
||||
);
|
||||
|
||||
header("Location: $selfUrl");
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults(
|
||||
[
|
||||
'title' => get_lang('ImportSessionAgendaReminderTitleDefault'),
|
||||
'description' => get_lang('ImportSessionAgendaReminderDescriptionDefault'),
|
||||
]
|
||||
);
|
||||
|
||||
$htmlHeadXtra[] = '<script>$(function () {'
|
||||
.Agenda::getJsForReminders('#agenda_reminders_add_notification')
|
||||
.'});</script>';
|
||||
|
||||
$pageTitle = get_lang('ImportCourseEvents');
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => $sessionUrl,
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
$template = new Template($pageTitle);
|
||||
$template->assign('header', $pageTitle);
|
||||
$template->assign('content', $form->returnForm());
|
||||
$template->display_one_col_template();
|
||||
687
main/session/index.php
Normal file
687
main/session/index.php
Normal file
@@ -0,0 +1,687 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* Session view.
|
||||
*
|
||||
* @package chamilo.session
|
||||
*
|
||||
* @author Julio Montoya <gugli100@gmail.com> Beeznest
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$session_id = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
|
||||
|
||||
if (empty($session_id)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionField = new ExtraFieldValue('session');
|
||||
$valueAllowVisitors = $sessionField->get_values_by_handler_and_field_variable(
|
||||
$session_id,
|
||||
'allow_visitors'
|
||||
);
|
||||
$allowVisitors = $valueAllowVisitors != false;
|
||||
|
||||
if (!$allowVisitors) {
|
||||
// Only users who are logged in can proceed.
|
||||
api_block_anonymous_users();
|
||||
}
|
||||
|
||||
$this_section = SECTION_COURSES;
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
$course_id = isset($_GET['course_id']) ? (int) $_GET['course_id'] : null;
|
||||
Session::write('id_session', $session_id);
|
||||
|
||||
// Clear the exercise session just in case
|
||||
Session::erase('objExercise');
|
||||
Session::erase('duration_time_previous');
|
||||
Session::erase('duration_time');
|
||||
|
||||
$userId = api_get_user_id();
|
||||
$session_info = SessionManager::fetch($session_id);
|
||||
$session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
|
||||
$courseList = SessionManager::get_course_list_by_session_id($session_id);
|
||||
$userIsGeneralCoach = SessionManager::user_is_general_coach($userId, $session_id);
|
||||
|
||||
$user_course_list = [];
|
||||
$exerciseListPerCourse = [];
|
||||
|
||||
foreach ($courseList as $course) {
|
||||
$status = SessionManager::get_user_status_in_course_session(
|
||||
$userId,
|
||||
$course['real_id'],
|
||||
$session_id
|
||||
);
|
||||
if ($status !== false || api_is_platform_admin() || $userIsGeneralCoach) {
|
||||
$user_course_list[] = $course['real_id'];
|
||||
}
|
||||
|
||||
$exerciseList = ExerciseLib::get_all_exercises_for_course_id(
|
||||
$course,
|
||||
$session_id,
|
||||
$course['real_id'],
|
||||
true
|
||||
);
|
||||
|
||||
$exerciseListNew = [];
|
||||
if (!empty($exerciseList)) {
|
||||
// Exercises
|
||||
foreach ($exerciseList as $exerciseInfo) {
|
||||
$exerciseId = $exerciseInfo['iid'];
|
||||
$visibility = api_get_item_visibility(
|
||||
$course,
|
||||
TOOL_QUIZ,
|
||||
$exerciseId,
|
||||
$session_id
|
||||
);
|
||||
if ($visibility == 0) {
|
||||
continue;
|
||||
}
|
||||
$exerciseListNew[] = $exerciseInfo;
|
||||
}
|
||||
}
|
||||
$exerciseListPerCourse[$course['real_id']] = $exerciseListNew;
|
||||
}
|
||||
|
||||
if (empty($user_course_list)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$my_session_list = [];
|
||||
$final_array = [];
|
||||
$new_course_list = [];
|
||||
if (!empty($courseList)) {
|
||||
foreach ($courseList as $course_data) {
|
||||
if (api_is_platform_admin()) {
|
||||
$course_data['title'] = Display::url(
|
||||
$course_data['title'],
|
||||
api_get_course_url($course_data['code'], $session_id)
|
||||
);
|
||||
} else {
|
||||
if (in_array($course_data['real_id'], $user_course_list) || api_is_anonymous()) {
|
||||
$course_data['title'] = Display::url(
|
||||
$course_data['title'],
|
||||
api_get_course_url($course_data['code'], $session_id)
|
||||
);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$list = new LearnpathList(
|
||||
api_get_user_id(),
|
||||
api_get_course_info($course_data['code']),
|
||||
$session_id,
|
||||
'lp.publicatedOn ASC',
|
||||
true,
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$lp_list = $list->get_flat_list();
|
||||
$lp_count = 0;
|
||||
|
||||
if (!empty($lp_list)) {
|
||||
foreach ($lp_list as $valLp) {
|
||||
if ($valLp['lp_visibility']) {
|
||||
$lp_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$course_info = api_get_course_info($course_data['code']);
|
||||
$exerciseCount = count($exerciseListPerCourse[$course_info['real_id']]);
|
||||
$max_mutation_date = '';
|
||||
$last_date = Tracking::get_last_connection_date_on_the_course(
|
||||
api_get_user_id(),
|
||||
$course_info,
|
||||
$session_id,
|
||||
false
|
||||
);
|
||||
|
||||
$icons = '';
|
||||
foreach ($lp_list as $item) {
|
||||
if (empty($item['modified_on'])) {
|
||||
$lp_date_original = $item['created_on'];
|
||||
$image = 'new.gif';
|
||||
$label = get_lang('LearnpathAdded');
|
||||
} else {
|
||||
$lp_date_original = $item['modified_on'];
|
||||
$image = 'moderator_star.png';
|
||||
$label = get_lang('LearnpathUpdated');
|
||||
}
|
||||
|
||||
$mutation_date = api_strtotime($item['publicated_on']) > api_strtotime($lp_date_original) ? $item['publicated_on'] : $lp_date_original;
|
||||
|
||||
if (api_strtotime($mutation_date) > api_strtotime($max_mutation_date)) {
|
||||
$max_mutation_date = $mutation_date;
|
||||
}
|
||||
|
||||
if (strtotime($last_date) < strtotime($lp_date_original)) {
|
||||
if (empty($icons)) {
|
||||
$icons .= ' '.Display::return_icon(
|
||||
$image,
|
||||
get_lang('TitleNotification').': '.$label.' - '.$lp_date_original
|
||||
).' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$new_course_list[] = [
|
||||
'title' => $course_data['title'].$icons,
|
||||
// 'recent_lps' => $icons,
|
||||
//'max_mutation_date' => substr(api_get_local_time($max_mutation_date),0,10),
|
||||
'exercise_count' => $exerciseCount,
|
||||
'lp_count' => $lp_count,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//If session is not active we stop de script
|
||||
if (api_is_coach_of_course_in_session($session_id) == false) {
|
||||
//If session is not active we stop de script
|
||||
if (!api_is_allowed_to_session_edit()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$session = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
|
||||
$sessionTitleLink = api_get_configuration_value('courses_list_session_title_link');
|
||||
|
||||
if ($sessionTitleLink == 2 && $session->getNbrCourses() === 1) {
|
||||
$sessionCourses = $session->getCourses();
|
||||
$sessionCourse = $sessionCourses[0]->getCourse();
|
||||
$courseUrl = $sessionCourse->getDirectory().'/index.php?';
|
||||
$courseUrl .= http_build_query([
|
||||
'id_session' => $session->getId(),
|
||||
]);
|
||||
|
||||
header('Location: '.api_get_path(WEB_COURSE_PATH).$courseUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::display_header(get_lang('Session'));
|
||||
|
||||
$session_select = [];
|
||||
foreach ($session_list as $item) {
|
||||
$session_select[$item['id']] = $item['name'];
|
||||
}
|
||||
|
||||
// Session list form
|
||||
if (count($session_select) > 1) {
|
||||
$form = new FormValidator(
|
||||
'exercise_admin',
|
||||
'get',
|
||||
api_get_self().'?session_id='.$session_id
|
||||
);
|
||||
$form->addElement(
|
||||
'select',
|
||||
'session_id',
|
||||
get_lang('SessionList'),
|
||||
$session_select,
|
||||
'onchange="javascript:change_session()"'
|
||||
);
|
||||
$defaults['session_id'] = $session_id;
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
}
|
||||
|
||||
if (empty($session_id)) {
|
||||
$user_list = UserManager::get_user_list();
|
||||
} else {
|
||||
$user_list = SessionManager::get_users_by_session($session_id);
|
||||
}
|
||||
|
||||
//Final data to be show
|
||||
$my_real_array = $new_exercises = [];
|
||||
$now = time();
|
||||
|
||||
if (!empty($courseList)) {
|
||||
foreach ($courseList as $courseInfo) {
|
||||
$courseCode = $courseInfo['code'];
|
||||
$courseId = $courseInfo['real_id'];
|
||||
|
||||
$isSubscribed = CourseManager::is_user_subscribed_in_course(
|
||||
api_get_user_id(),
|
||||
$courseCode,
|
||||
true,
|
||||
$session_id
|
||||
);
|
||||
|
||||
$exerciseList = $exerciseListPerCourse[$courseId];
|
||||
|
||||
if (!empty($exerciseList)) {
|
||||
// Exercises
|
||||
foreach ($exerciseList as $exerciseInfo) {
|
||||
if ($exerciseInfo['start_time'] == '0000-00-00 00:00:00') {
|
||||
$start_date = '-';
|
||||
} else {
|
||||
$start_date = $exerciseInfo['start_time'];
|
||||
}
|
||||
|
||||
$exerciseId = $exerciseInfo['iid'];
|
||||
|
||||
$best_score_data = ExerciseLib::get_best_attempt_in_course(
|
||||
$exerciseId,
|
||||
$courseInfo['real_id'],
|
||||
$session_id
|
||||
);
|
||||
|
||||
$best_score = '';
|
||||
if (!empty($best_score_data)) {
|
||||
$best_score = ExerciseLib::show_score(
|
||||
$best_score_data['exe_result'],
|
||||
$best_score_data['exe_weighting']
|
||||
);
|
||||
}
|
||||
|
||||
$exerciseResultInfo = Event::getExerciseResultsByUser(
|
||||
$userId,
|
||||
$exerciseId,
|
||||
$courseId,
|
||||
$session_id
|
||||
);
|
||||
|
||||
if (empty($exerciseResultInfo)) {
|
||||
// We check the date validation of the exercise if the user can make it
|
||||
if ($exerciseInfo['start_time'] != '0000-00-00 00:00:00') {
|
||||
$allowed_time = api_strtotime($exerciseInfo['start_time'], 'UTC');
|
||||
if ($now < $allowed_time) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$name = Display::url(
|
||||
$exerciseInfo['title'],
|
||||
api_get_path(WEB_CODE_PATH)."exercise/overview.php?cidReq=$courseCode&exerciseId={$exerciseId}&id_session=$session_id",
|
||||
['target' => SESSION_LINK_TARGET]
|
||||
);
|
||||
|
||||
$new_exercises[] = [
|
||||
'status' => Display::return_icon(
|
||||
'star.png',
|
||||
get_lang('New'),
|
||||
['width' => ICON_SIZE_SMALL]
|
||||
),
|
||||
'date' => $exerciseInfo['start_time'],
|
||||
'course' => $courseInfo['title'],
|
||||
'exercise' => $name,
|
||||
'attempt' => '-',
|
||||
'result' => '-',
|
||||
'best_result' => '-',
|
||||
'position' => '-',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Exercise results
|
||||
$counter = 1;
|
||||
foreach ($exerciseResultInfo as $result) {
|
||||
$platform_score = ExerciseLib::show_score(
|
||||
$result['exe_result'],
|
||||
$result['exe_weighting']
|
||||
);
|
||||
$my_score = 0;
|
||||
if (!empty($result['exe_weighting']) &&
|
||||
intval($result['exe_weighting']) != 0
|
||||
) {
|
||||
$my_score = $result['exe_result'] / $result['exe_weighting'];
|
||||
}
|
||||
$position = ExerciseLib::get_exercise_result_ranking(
|
||||
$my_score,
|
||||
$result['exe_id'],
|
||||
$exerciseId,
|
||||
$courseCode,
|
||||
$session_id,
|
||||
$user_list
|
||||
);
|
||||
|
||||
$name = Display::url(
|
||||
$exerciseInfo['title'],
|
||||
api_get_path(WEB_CODE_PATH)."exercise/result.php?cidReq=$courseCode&id={$result['exe_id']}&id_session=$session_id&show_headers=1",
|
||||
['target' => SESSION_LINK_TARGET, 'class' => 'exercise-result-link']
|
||||
);
|
||||
|
||||
$my_real_array[] = [
|
||||
'status' => Display::return_icon(
|
||||
'quiz.png',
|
||||
get_lang('Attempted'),
|
||||
'',
|
||||
ICON_SIZE_SMALL
|
||||
),
|
||||
'date' => $start_date,
|
||||
'course' => $courseInfo['title'],
|
||||
'exercise' => $name,
|
||||
'attempt' => $counter,
|
||||
'result' => $platform_score,
|
||||
'best_result' => $best_score,
|
||||
'position' => $position,
|
||||
];
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$my_real_array = msort($my_real_array, 'date', 'asc');
|
||||
|
||||
if (!empty($new_exercises)) {
|
||||
$my_real_array = array_merge($new_exercises, $my_real_array);
|
||||
}
|
||||
|
||||
$start = $end = $start_only = $end_only = '';
|
||||
|
||||
if (!empty($session_info['access_start_date'])) {
|
||||
$start = api_convert_and_format_date($session_info['access_start_date'], DATE_FORMAT_SHORT);
|
||||
$start_only = get_lang('From').' '.$session_info['access_start_date'];
|
||||
}
|
||||
if (!empty($session_info['access_start_date'])) {
|
||||
$end = api_convert_and_format_date($session_info['access_end_date'], DATE_FORMAT_SHORT);
|
||||
$end_only = get_lang('Until').' '.$session_info['access_end_date'];
|
||||
}
|
||||
|
||||
if (!empty($start) && !empty($end)) {
|
||||
$dates = Display::tag('i', sprintf(get_lang('FromDateXToDateY'), $start, $end));
|
||||
} else {
|
||||
$dates = Display::tag('i', $start_only.' '.$end_only);
|
||||
}
|
||||
|
||||
$editLink = '';
|
||||
if (api_is_platform_admin()) {
|
||||
$editLink = ' '.Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
api_get_path(WEB_CODE_PATH).'session/session_edit.php?page=resume_session.php&id='.$session_id
|
||||
);
|
||||
}
|
||||
|
||||
echo Display::tag('h1', $session_info['name'].$editLink);
|
||||
echo $dates.'<br />';
|
||||
$allow = api_get_setting('show_session_description') === 'true';
|
||||
|
||||
if ($session_info['show_description'] == 1 && $allow) {
|
||||
?>
|
||||
<div class="home-course-intro">
|
||||
<div class="page-course">
|
||||
<div class="page-course-intro">
|
||||
<p><?php echo $session_info['description']; ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// All Learnpaths grid settings (First tab, first subtab)
|
||||
$columns_courses = [
|
||||
get_lang('Title'),
|
||||
get_lang('NumberOfPublishedExercises'),
|
||||
get_lang('NumberOfPublishedLps'),
|
||||
];
|
||||
$column_model_courses = [
|
||||
['name' => 'title', 'index' => 'title', 'width' => '400px', 'align' => 'left', 'sortable' => 'true'],
|
||||
//array('name'=>'recent_lps', 'index'=>'recent_lps', 'width'=>'10px', 'align'=>'left', 'sortable'=>'false'),
|
||||
// array('name'=>'max_mutation_date', 'index'=>'max_mutation_date', 'width'=>'120px', 'align'=>'left', 'sortable'=>'true'),
|
||||
['name' => 'exercise_count', 'index' => 'exercise_count', 'width' => '180px', 'align' => 'left', 'sortable' => 'true'],
|
||||
['name' => 'lp_count', 'index' => 'lp_count', 'width' => '180px', 'align' => 'left', 'sortable' => 'true'],
|
||||
];
|
||||
|
||||
$extra_params_courses['height'] = '100%';
|
||||
$extra_params_courses['autowidth'] = 'true'; //use the width of the parent
|
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id.'&course_id='.$course_id;
|
||||
$columns = [
|
||||
get_lang('PublicationDate'),
|
||||
get_lang('Course'),
|
||||
get_lang('LearningPaths'),
|
||||
];
|
||||
|
||||
$column_model = [
|
||||
['name' => 'date', 'index' => 'date', 'width' => '120', 'align' => 'left', 'sortable' => 'true'],
|
||||
['name' => 'course', 'index' => 'course', 'width' => '300', 'align' => 'left', 'sortable' => 'true', 'wrap_cell' => 'true'],
|
||||
['name' => 'lp', 'index' => 'lp', 'width' => '440', 'align' => 'left', 'sortable' => 'true'],
|
||||
];
|
||||
|
||||
$extra_params = [];
|
||||
$extra_params['sortname'] = 'date';
|
||||
$extra_params['height'] = '100%';
|
||||
$extra_params['autowidth'] = 'true'; //use the width of the parent
|
||||
|
||||
//Per course grid settings
|
||||
$url_by_course = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_course&session_id='.$session_id.'&course_id='.$course_id;
|
||||
$extra_params_course = [];
|
||||
$extra_params_course['grouping'] = 'true';
|
||||
$extra_params_course['groupingView'] = [
|
||||
'groupCollapse' => false,
|
||||
'groupField' => ['course'],
|
||||
'groupColumnShow' => ['false'],
|
||||
'groupText' => ['<b>'.get_lang('Course').' {0}</b>'],
|
||||
];
|
||||
$extra_params_course['autowidth'] = 'true'; //use the width of the parent
|
||||
$extra_params_course['height'] = "100%";
|
||||
|
||||
//Per Week grid
|
||||
$url_week = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id.'&course_id='.$course_id;
|
||||
$column_week = [
|
||||
get_lang('PeriodWeek'),
|
||||
get_lang('PublicationDate'),
|
||||
get_lang('Course'),
|
||||
get_lang('LearningPaths'),
|
||||
];
|
||||
|
||||
$column_week_model = [
|
||||
['name' => 'week', 'index' => 'week', 'width' => '40', 'align' => 'left', 'sortable' => 'false'],
|
||||
['name' => 'date', 'index' => 'date', 'width' => '120', 'align' => 'left', 'sortable' => 'false'],
|
||||
['name' => 'course', 'index' => 'course', 'width' => '300', 'align' => 'left', 'sortable' => 'true', 'wrap_cell' => 'true'],
|
||||
['name' => 'lp', 'index' => 'lp', 'width' => '440', 'align' => 'left', 'sortable' => 'true'],
|
||||
];
|
||||
|
||||
$extra_params_week = [];
|
||||
$extra_params_week['grouping'] = 'true';
|
||||
//For more details see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping
|
||||
$extra_params_week['groupingView'] = [
|
||||
'groupCollapse' => false,
|
||||
'groupDataSorted' => false,
|
||||
'groupField' => ['week'],
|
||||
'groupOrder' => ['desc'],
|
||||
'groupColumnShow' => 'false',
|
||||
'groupText' => ['<b>'.get_lang('PeriodWeek').' {0}</b>'],
|
||||
];
|
||||
$extra_params_week['autowidth'] = 'true'; //use the width of the parent
|
||||
$extra_params_week['height'] = '100%';
|
||||
|
||||
// MyQCM grid
|
||||
if (!api_is_anonymous()) {
|
||||
$column_exercise = [
|
||||
get_lang('Status'),
|
||||
get_lang('ExerciseStartDate'),
|
||||
get_lang('Course'),
|
||||
get_lang('Exercise'),
|
||||
get_lang('Attempts'),
|
||||
get_lang('Result'),
|
||||
get_lang('BestResultInCourse'),
|
||||
get_lang('Ranking'),
|
||||
];
|
||||
$column_exercise_model = [
|
||||
['name' => 'status', 'index' => 'status', 'width' => '40', 'align' => 'left', 'sortable' => 'false'],
|
||||
['name' => 'date', 'index' => 'date', 'width' => '130', 'align' => 'left', 'sortable' => 'true'],
|
||||
['name' => 'course', 'index' => 'course', 'width' => '200', 'align' => 'left', 'sortable' => 'true', 'wrap_cell' => 'true'],
|
||||
['name' => 'exercise', 'index' => 'exercise', 'width' => '200', 'align' => 'left', 'sortable' => 'false'],
|
||||
['name' => 'attempt', 'index' => 'attempt', 'width' => '60', 'align' => 'center', 'sortable' => 'true'],
|
||||
['name' => 'result', 'index' => 'result', 'width' => '120', 'align' => 'center', 'sortable' => 'true'],
|
||||
['name' => 'best_result', 'index' => 'best_result', 'width' => '140', 'align' => 'center', 'sortable' => 'true'],
|
||||
['name' => 'position', 'index' => 'position', 'width' => '55', 'align' => 'center', 'sortable' => 'true'],
|
||||
];
|
||||
$extra_params_exercise['height'] = '100%';
|
||||
$extra_params_exercise['autowidth'] = 'true';
|
||||
//$extra_params_exercise['sortname'] = 'status';
|
||||
//$extra_params_exercise['sortorder'] = 'desc';
|
||||
//$extra_params_exercise['grouping'] = 'true';
|
||||
//$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
|
||||
//$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0} - {1} Item(s)</b>'));
|
||||
}
|
||||
?>
|
||||
<br />
|
||||
<script>
|
||||
function change_session() {
|
||||
document.exercise_admin.submit();
|
||||
}
|
||||
|
||||
$(function() {
|
||||
//js used when generating images on the fly see function Tracking::show_course_detail()
|
||||
//$(".dialog").dialog("destroy");
|
||||
$(".dialog").dialog({
|
||||
autoOpen: false,
|
||||
show: "blind",
|
||||
resizable: false,
|
||||
height:300,
|
||||
width:550,
|
||||
modal: true
|
||||
});
|
||||
|
||||
$(".opener").click(function() {
|
||||
var my_id = $(this).attr('id');
|
||||
var big_image = '#main_graph_' + my_id;
|
||||
$( big_image ).dialog("open");
|
||||
return false;
|
||||
});
|
||||
|
||||
// Redirect to tab
|
||||
var url = document.location.toString();
|
||||
if (url.match('#')) {
|
||||
var tabLink = url.split('#')[1];
|
||||
$('.nav-tabs a[href="#' + tabLink + '"]').tab('show');
|
||||
|
||||
// Redirect to course part
|
||||
var secondLink = url.split('#')[2];
|
||||
if (secondLink) {
|
||||
var aTag = $("a[href='#" + secondLink + "']");
|
||||
$('html,body').animate({scrollTop: aTag.offset().top}, 'slow');
|
||||
}
|
||||
}
|
||||
<?php
|
||||
//Displays js code to use a jqgrid
|
||||
echo Display::grid_js(
|
||||
'courses',
|
||||
'',
|
||||
$columns_courses,
|
||||
$column_model_courses,
|
||||
$extra_params_courses,
|
||||
$new_course_list
|
||||
);
|
||||
echo Display::grid_js(
|
||||
'list_default',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
''
|
||||
);
|
||||
echo Display::grid_js(
|
||||
'list_course',
|
||||
$url_by_course,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params_course,
|
||||
[],
|
||||
''
|
||||
);
|
||||
echo Display::grid_js(
|
||||
'list_week',
|
||||
$url_week,
|
||||
$column_week,
|
||||
$column_week_model,
|
||||
$extra_params_week,
|
||||
[],
|
||||
''
|
||||
);
|
||||
|
||||
if (!api_is_anonymous()) {
|
||||
echo Display::grid_js(
|
||||
'exercises',
|
||||
'',
|
||||
$column_exercise,
|
||||
$column_exercise_model,
|
||||
$extra_params_exercise,
|
||||
$my_real_array
|
||||
);
|
||||
}
|
||||
?>
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
$courseCode = isset($_GET['course']) ? $_GET['course'] : null;
|
||||
$reportingTab = '';
|
||||
if (!api_is_anonymous()) {
|
||||
$reportingTab = Tracking::showUserProgress(
|
||||
api_get_user_id(),
|
||||
$session_id,
|
||||
'#tabs-5',
|
||||
false,
|
||||
false
|
||||
);
|
||||
if (!empty($reportingTab)) {
|
||||
$reportingTab .= '<br />';
|
||||
$reportingTab .= Tracking::show_course_detail(
|
||||
api_get_user_id(),
|
||||
$courseCode,
|
||||
$session_id
|
||||
);
|
||||
}
|
||||
if (empty($reportingTab)) {
|
||||
$reportingTab = Display::return_message(get_lang('NoDataAvailable'), 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
// Main headers
|
||||
$headers = [
|
||||
Display::return_icon('moderator_star.png'),
|
||||
get_lang('Courses'),
|
||||
get_lang('LearningPaths'),
|
||||
];
|
||||
|
||||
if (!api_is_anonymous()) {
|
||||
$headers[] = get_lang('MyQCM');
|
||||
$headers[] = get_lang('MyStatistics');
|
||||
}
|
||||
|
||||
$coursesTab = Display::grid_html('courses');
|
||||
$starTab = Display::grid_html('list_default');
|
||||
|
||||
$tabs = [
|
||||
$starTab,
|
||||
$coursesTab,
|
||||
Display::grid_html('list_course'),
|
||||
Display::grid_html('exercises'),
|
||||
$reportingTab,
|
||||
];
|
||||
|
||||
$tabToHide = api_get_configuration_value('session_hide_tab_list');
|
||||
|
||||
if (!empty($tabToHide)) {
|
||||
foreach ($tabToHide as $columnId) {
|
||||
unset($headers[$columnId]);
|
||||
unset($tabs[$columnId]);
|
||||
}
|
||||
}
|
||||
|
||||
// Main headers data
|
||||
echo Display::tabs(
|
||||
$headers,
|
||||
$tabs
|
||||
);
|
||||
|
||||
// Deleting the objects
|
||||
Session::erase('_gid');
|
||||
Session::erase('oLP');
|
||||
Session::erase('lpobject');
|
||||
api_remove_in_gradebook();
|
||||
|
||||
Display::display_footer();
|
||||
518
main/session/resume_session.php
Normal file
518
main/session/resume_session.php
Normal file
@@ -0,0 +1,518 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Course;
|
||||
use Chamilo\CoreBundle\Entity\Repository\SequenceResourceRepository;
|
||||
use Chamilo\CoreBundle\Entity\Repository\SessionRepository;
|
||||
use Chamilo\CoreBundle\Entity\SequenceResource;
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
|
||||
use ChamiloSession as PHPSession;
|
||||
|
||||
/**
|
||||
* @author Bart Mollet, Julio Montoya lot of fixes
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : null;
|
||||
|
||||
if (empty($sessionId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
PHPSession::write('id_session', $sessionId);
|
||||
SessionManager::protectSession($sessionId);
|
||||
$codePath = api_get_path(WEB_CODE_PATH);
|
||||
|
||||
$tool_name = get_lang('SessionOverview');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
|
||||
$orig_param = '&origin=resume_session';
|
||||
|
||||
$allowSkills = api_get_configuration_value('allow_skill_rel_items');
|
||||
if ($allowSkills) {
|
||||
$htmlContentExtraClass[] = 'feature-item-user-skill-on';
|
||||
}
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
|
||||
|
||||
$em = Database::getManager();
|
||||
$sessionInfo = api_get_session_info($sessionId);
|
||||
/** @var SessionRepository $sessionRepository */
|
||||
$sessionRepository = $em->getRepository('ChamiloCoreBundle:Session');
|
||||
/** @var Session $session */
|
||||
$session = $sessionRepository->find($sessionId);
|
||||
$sessionCategory = $session->getCategory();
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
$url_id = api_get_current_access_url_id();
|
||||
|
||||
switch ($action) {
|
||||
case 'export_certified_course_users':
|
||||
$courseCode = $_GET['course_code'] ?? null;
|
||||
if (!empty($courseCode)) {
|
||||
SessionManager::exportCourseSessionReport($sessionId, $courseCode);
|
||||
}
|
||||
break;
|
||||
case 'move_up':
|
||||
SessionManager::moveUp($sessionId, $_GET['course_id']);
|
||||
header('Location: resume_session.php?id_session='.$sessionId);
|
||||
exit;
|
||||
break;
|
||||
case 'move_down':
|
||||
SessionManager::moveDown($sessionId, $_GET['course_id']);
|
||||
header('Location: resume_session.php?id_session='.$sessionId);
|
||||
exit;
|
||||
break;
|
||||
case 'add_user_to_url':
|
||||
$user_id = $_REQUEST['user_id'];
|
||||
$result = UrlManager::add_user_to_url($user_id, $url_id);
|
||||
$user_info = api_get_user_info($user_id);
|
||||
if ($result) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']),
|
||||
'confirm'
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
// Delete course from session.
|
||||
$idChecked = isset($_GET['idChecked']) ? $_GET['idChecked'] : null;
|
||||
$message = get_lang('TokenExpiredActionAlreadyRealized');
|
||||
if (is_array($idChecked)) {
|
||||
$usersToDelete = [];
|
||||
$check = Security::check_token('get');
|
||||
if ($check) {
|
||||
foreach ($idChecked as $courseCode) {
|
||||
// forcing the escape_string
|
||||
$courseInfo = api_get_course_info($courseCode);
|
||||
SessionManager::unsubscribe_course_from_session(
|
||||
$sessionId,
|
||||
$courseInfo['real_id']
|
||||
);
|
||||
}
|
||||
$message = get_lang('Updated');
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_GET['class'])) {
|
||||
$class = (int) $_GET['class'];
|
||||
$result = Database::query(
|
||||
"DELETE FROM $tbl_session_rel_class
|
||||
WHERE session_id = $sessionId
|
||||
AND class_id = $class"
|
||||
);
|
||||
$nbr_affected_rows = Database::affected_rows($result);
|
||||
Database::query(
|
||||
"UPDATE $tbl_session
|
||||
SET nbr_classes = nbr_classes - $nbr_affected_rows
|
||||
WHERE id = $sessionId");
|
||||
$message = get_lang('Updated');
|
||||
}
|
||||
|
||||
if (!empty($_GET['user'])) {
|
||||
$check = Security::check_token('get');
|
||||
if ($check) {
|
||||
SessionManager::unsubscribe_user_from_session(
|
||||
$sessionId,
|
||||
$_GET['user']
|
||||
);
|
||||
$message = get_lang('Updated');
|
||||
}
|
||||
Security::clear_token();
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message($message));
|
||||
break;
|
||||
}
|
||||
|
||||
$sessionHeader = Display::page_header(
|
||||
Display::return_icon('session.png', get_lang('Session')).' '.$session->getName(),
|
||||
null,
|
||||
'h3'
|
||||
);
|
||||
|
||||
$url = Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
|
||||
"session_edit.php?page=resume_session.php&id=$sessionId"
|
||||
);
|
||||
|
||||
$sessionTitle = Display::page_subheader(get_lang('GeneralProperties').$url);
|
||||
$generalCoach = api_get_user_info($sessionInfo['id_coach']);
|
||||
|
||||
$sessionField = new ExtraField('session');
|
||||
$extraFieldData = $sessionField->getDataAndFormattedValues($sessionId);
|
||||
|
||||
$multiple_url_is_on = api_get_multiple_access_url();
|
||||
$urlList = [];
|
||||
if ($multiple_url_is_on) {
|
||||
$urlList = UrlManager::get_access_url_from_session($sessionId);
|
||||
}
|
||||
|
||||
$url = Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
|
||||
"add_courses_to_session.php?page=resume_session.php&id_session=$sessionId"
|
||||
);
|
||||
$courseListToShow = Display::page_subheader(get_lang('CourseList').$url);
|
||||
|
||||
$courseListToShow .= '<table id="session-list-course" class="table table-hover table-striped data_table">
|
||||
<tr>
|
||||
<th width="35%">'.get_lang('CourseTitle').'</th>
|
||||
<th width="30%">'.get_lang('CourseCoach').'</th>
|
||||
<th width="10%">'.get_lang('UsersNumber').'</th>
|
||||
<th width="25%">'.get_lang('Actions').'</th>
|
||||
</tr>';
|
||||
|
||||
if ($session->getNbrCourses() === 0) {
|
||||
$courseListToShow .= '<tr>
|
||||
<td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
|
||||
</tr>';
|
||||
} else {
|
||||
$secToken = Security::get_token();
|
||||
$count = 0;
|
||||
$courseItem = '';
|
||||
//$courses = $sessionRepository->getCoursesOrderedByPosition($session);
|
||||
|
||||
$courses = $session->getCourses();
|
||||
$iterator = $courses->getIterator();
|
||||
// define ordering closure, using preferred comparison method/field
|
||||
$iterator->uasort(function ($first, $second) {
|
||||
return (int) $first->getPosition() > (int) $second->getPosition() ? 1 : -1;
|
||||
});
|
||||
$courseList = [];
|
||||
$positionList = [];
|
||||
$courseListByCode = [];
|
||||
/** @var \Chamilo\CoreBundle\Entity\SessionRelCourse $sessionRelCourse */
|
||||
foreach ($iterator as $sessionRelCourse) {
|
||||
$courseList[] = $sessionRelCourse->getCourse();
|
||||
$courseListByCode[$sessionRelCourse->getCourse()->getCode()] = $sessionRelCourse->getCourse();
|
||||
$positionList[] = $sessionRelCourse->getPosition();
|
||||
}
|
||||
|
||||
$checkPosition = array_filter($positionList);
|
||||
if (empty($checkPosition)) {
|
||||
// The session course list doesn't have any position,
|
||||
// then order the course list by course code.
|
||||
$orderByCode = array_keys($courseListByCode);
|
||||
sort($orderByCode, SORT_NATURAL);
|
||||
$newCourseList = [];
|
||||
foreach ($orderByCode as $code) {
|
||||
$newCourseList[] = $courseListByCode[$code];
|
||||
}
|
||||
$courseList = $newCourseList;
|
||||
}
|
||||
|
||||
/** @var Course $course */
|
||||
foreach ($courseList as $course) {
|
||||
// Select the number of users
|
||||
$numberOfUsers = SessionManager::getCountUsersInCourseSession($course, $session);
|
||||
|
||||
// Get coachs of the courses in session
|
||||
$namesOfCoaches = [];
|
||||
$coachSubscriptions = $session->getUserCourseSubscriptionsByStatus($course, Session::COACH);
|
||||
|
||||
if ($coachSubscriptions) {
|
||||
/** @var SessionRelCourseRelUser $subscription */
|
||||
foreach ($coachSubscriptions as $subscription) {
|
||||
$namesOfCoaches[] = $subscription->getUser()->getCompleteNameWithUserName();
|
||||
}
|
||||
}
|
||||
|
||||
$orderButtons = '';
|
||||
if (SessionManager::orderCourseIsEnabled()) {
|
||||
$orderButtons = Display::url(
|
||||
Display::return_icon(
|
||||
!$count ? 'up_na.png' : 'up.png',
|
||||
get_lang('MoveUp')
|
||||
),
|
||||
!$count
|
||||
? '#'
|
||||
: api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_up'
|
||||
);
|
||||
|
||||
$orderButtons .= Display::url(
|
||||
Display::return_icon(
|
||||
$count + 1 == count($courses) ? 'down_na.png' : 'down.png',
|
||||
get_lang('MoveDown')
|
||||
),
|
||||
$count + 1 == count($courses)
|
||||
? '#'
|
||||
: api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_down'
|
||||
);
|
||||
}
|
||||
|
||||
$courseUrl = api_get_course_url($course->getCode(), $sessionId);
|
||||
$courseBaseUrl = api_get_course_url($course->getCode());
|
||||
|
||||
// hide_course_breadcrumb the parameter has been added to hide the name
|
||||
// of the course, that appeared in the default $interbreadcrumb
|
||||
$courseItem .= '<tr>
|
||||
<td class="title">'
|
||||
.Display::url(
|
||||
$course->getTitle().' ('.$course->getVisualCode().')',
|
||||
$courseUrl
|
||||
)
|
||||
.'</td>';
|
||||
$courseItem .= '<td>'.($namesOfCoaches ? implode('<br>', $namesOfCoaches) : get_lang('None')).'</td>';
|
||||
$courseItem .= '<td>'.$numberOfUsers.'</td>';
|
||||
$courseItem .= '<td>';
|
||||
$courseItem .= Display::url(Display::return_icon('course_home.gif', get_lang('CourseInSession')), $courseUrl);
|
||||
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('settings.png', get_lang('Course')),
|
||||
$courseBaseUrl,
|
||||
['target' => '_blank']
|
||||
);
|
||||
|
||||
if ($allowSkills) {
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('skill-badges.png', get_lang('Skills')),
|
||||
$codePath.'admin/skill_rel_course.php?session_id='.$sessionId.'&course_id='.$course->getId()
|
||||
);
|
||||
}
|
||||
$courseItem .= $orderButtons;
|
||||
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('new_user.png', get_lang('AddUsers')),
|
||||
$codePath."session/add_users_to_session_course.php?id_session=$sessionId&course_id=".$course->getId()
|
||||
);
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('user.png', get_lang('Users')),
|
||||
$codePath."session/session_course_user_list.php?id_session=$sessionId&course_code=".$course->getCode()
|
||||
);
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse')),
|
||||
$codePath."user/user_import.php?action=import&cidReq={$course->getCode()}&id_session=$sessionId"
|
||||
);
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('export_csv.png', get_lang('ExportUsersOfACourse')),
|
||||
$codePath."user/user_export.php?file_type=csv&course_session={$course->getCode()}:$sessionId&addcsvheader=1"
|
||||
);
|
||||
|
||||
$config = api_get_configuration_value('session_course_excel_export');
|
||||
if (!empty($config)) {
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('excel.png', get_lang('ExportCertifiedUsersExcel')),
|
||||
api_get_self()."?id_session=$sessionId&action=export_certified_course_users&course_code=".$course->getCode()
|
||||
);
|
||||
}
|
||||
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('statistics.gif', get_lang('Tracking')),
|
||||
$codePath."tracking/courseLog.php?id_session=$sessionId&cidReq={$course->getCode()}$orig_param&hide_course_breadcrumb=1"
|
||||
);
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('teacher.png', get_lang('ModifyCoach')),
|
||||
$codePath."session/session_course_edit.php?id_session=$sessionId&page=resume_session.php&course_code={$course->getCode()}$orig_param"
|
||||
);
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('folder_document.png', get_lang('UploadFile')),
|
||||
'#',
|
||||
[
|
||||
'class' => 'session-upload-file-btn',
|
||||
'data-session' => $sessionId,
|
||||
'data-course' => $course->getId(),
|
||||
]
|
||||
);
|
||||
$courseItem .= Display::url(
|
||||
Display::return_icon('delete.png', get_lang('Delete')),
|
||||
api_get_self()."?id_session=$sessionId&action=delete&idChecked[]={$course->getCode()}&sec_token=".Security::getTokenFromSession(),
|
||||
[
|
||||
'onclick' => "javascript:if(!confirm('".get_lang('ConfirmYourChoice')."')) return false;",
|
||||
]
|
||||
);
|
||||
|
||||
$courseItem .= '</td></tr>';
|
||||
$count++;
|
||||
}
|
||||
$courseListToShow .= $courseItem;
|
||||
}
|
||||
$courseListToShow .= '</table><br />';
|
||||
|
||||
$url = ' '.Display::url(
|
||||
Display::return_icon('user_subscribe_session.png', get_lang('Add')),
|
||||
$codePath."session/add_users_to_session.php?page=resume_session.php&id_session=$sessionId"
|
||||
);
|
||||
$url .= Display::url(
|
||||
Display::return_icon('import_csv.png', get_lang('ImportUsers')),
|
||||
$codePath."session/session_user_import.php?id_session=$sessionId"
|
||||
);
|
||||
$url .= Display::url(
|
||||
Display::return_icon('export_csv.png', get_lang('ExportUsers')),
|
||||
$codePath."user/user_export.php?file_type=csv&session=$sessionId&addcsvheader=1"
|
||||
);
|
||||
$url .= Display::url(
|
||||
Display::return_icon('pdf.png', get_lang('CertificateOfAchievement'), [], ICON_SIZE_SMALL),
|
||||
$codePath.'mySpace/session.php?'.http_build_query(
|
||||
[
|
||||
'action' => 'export_to_pdf',
|
||||
'type' => 'achievement',
|
||||
'session_to_export' => $sessionId,
|
||||
'all_students' => 1,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$userListToShow = Display::page_subheader(get_lang('UserList').$url);
|
||||
$userList = SessionManager::get_users_by_session($sessionId);
|
||||
|
||||
if (!empty($userList)) {
|
||||
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : null;
|
||||
$sortColumn = isset($_GET['sort']) ? Security::remove_XSS($_GET['sort']) : 'registration_date';
|
||||
$sortOrder = isset($_GET['order']) && Security::remove_XSS($_GET['order']) === 'ASC' ? SORT_ASC : SORT_DESC;
|
||||
|
||||
$allowedColumns = ['user', 'registration_date'];
|
||||
if (!in_array($sortColumn, $allowedColumns, true)) {
|
||||
$sortColumn = 'registration_date';
|
||||
}
|
||||
|
||||
usort($userList, function ($a, $b) use ($sortColumn, $sortOrder) {
|
||||
if ($sortColumn === 'user') {
|
||||
$valueA = strtolower(api_get_user_info($a['user_id'])['complete_name_with_username']);
|
||||
$valueB = strtolower(api_get_user_info($b['user_id'])['complete_name_with_username']);
|
||||
} else {
|
||||
$valueA = strtotime($a['registered_at']);
|
||||
$valueB = strtotime($b['registered_at']);
|
||||
}
|
||||
|
||||
return $sortOrder === SORT_ASC ? $valueA <=> $valueB : $valueB <=> $valueA;
|
||||
});
|
||||
|
||||
$table = new HTML_Table(
|
||||
['class' => 'table table-hover table-striped data_table', 'id' => 'session-user-list']
|
||||
);
|
||||
$table->setHeaderContents(0, 0, '<a href="?id_session='.$sessionId.'&sort=user&order='.($sortColumn === 'user' && $sortOrder === SORT_ASC ? 'DESC' : 'ASC').'">'.get_lang('User').'</a>');
|
||||
$table->setHeaderContents(0, 1, get_lang('Status'));
|
||||
$table->setHeaderContents(0, 2, '<a href="?id_session='.$sessionId.'&sort=registration_date&order='.($sortColumn === 'registration_date' && $sortOrder === SORT_ASC ? 'DESC' : 'ASC').'">'.get_lang('RegistrationDate').'</a>');
|
||||
$table->setHeaderContents(0, 3, get_lang('Actions'));
|
||||
|
||||
$row = 1;
|
||||
foreach ($userList as $user) {
|
||||
$userId = $user['user_id'];
|
||||
$userInfo = api_get_user_info($userId);
|
||||
|
||||
$userLink = '<a href="'.$codePath.'admin/user_information.php?user_id='.$userId.'">'.
|
||||
api_htmlentities($userInfo['complete_name_with_username']).'</a>';
|
||||
|
||||
$reportingLink = Display::url(
|
||||
Display::return_icon('statistics.gif', get_lang('Reporting')),
|
||||
$codePath.'mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'&id_session='
|
||||
.$sessionId
|
||||
);
|
||||
|
||||
$courseUserLink = Display::url(
|
||||
Display::return_icon('course.png', get_lang('BlockCoursesForThisUser')),
|
||||
$codePath.'session/session_course_user.php?id_user='.$user['user_id'].'&id_session='
|
||||
.$sessionId
|
||||
);
|
||||
|
||||
$removeLink = Display::url(
|
||||
Display::return_icon('delete.png', get_lang('Delete')),
|
||||
api_get_self().'?id_session='.$sessionId.'&action=delete&user='.$user['user_id'].'&sec_token='.Security::getTokenFromSession(),
|
||||
['onclick' => "javascript:if(!confirm('".get_lang('ConfirmYourChoice')."')) return false;"]
|
||||
);
|
||||
|
||||
$addUserToUrlLink = '';
|
||||
if ($multiple_url_is_on) {
|
||||
if ($user['access_url_id'] != $url_id) {
|
||||
$userLink .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'));
|
||||
$add = Display::return_icon('add.png', get_lang('AddUsersToURL'));
|
||||
$addUserToUrlLink = '<a href="resume_session.php?action=add_user_to_url&id_session='.$sessionId
|
||||
.'&user_id='.$user['user_id'].'">'.$add.'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
$editUrl = null;
|
||||
|
||||
if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
|
||||
$editUrl = $codePath . 'session/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
|
||||
$editUrl = Display::url(
|
||||
Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
|
||||
$editUrl
|
||||
);
|
||||
}
|
||||
|
||||
$table->setCellContents($row, 0, $userLink);
|
||||
$link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;
|
||||
switch ($user['relation_type']) {
|
||||
case 1:
|
||||
$status = get_lang('Drh');
|
||||
$link = Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
$codePath.'admin/dashboard_add_sessions_to_user.php?user='.$userId
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$status = get_lang('Student');
|
||||
}
|
||||
|
||||
$registered = !empty($user['registered_at']) ? Display::dateToStringAgoAndLongDate($user['registered_at']) : '';
|
||||
|
||||
$table->setCellContents($row, 1, $status);
|
||||
$table->setCellContents($row, 2, $registered);
|
||||
$table->setCellContents($row, 3, $link);
|
||||
$row++;
|
||||
}
|
||||
$userListToShow .= $table->toHtml();
|
||||
}
|
||||
|
||||
/** @var SequenceResourceRepository $repo */
|
||||
$repo = $em->getRepository('ChamiloCoreBundle:SequenceResource');
|
||||
$requirementAndDependencies = $repo->getRequirementAndDependencies(
|
||||
$sessionId,
|
||||
SequenceResource::SESSION_TYPE
|
||||
);
|
||||
|
||||
$requirements = '';
|
||||
if (!empty($requirementAndDependencies['requirements'])) {
|
||||
$requirements = Display::page_subheader(get_lang('Requirements'));
|
||||
$requirements .= implode(' + ', array_column($requirementAndDependencies['requirements'], 'admin_link'));
|
||||
}
|
||||
$dependencies = '';
|
||||
if (!empty($requirementAndDependencies['dependencies'])) {
|
||||
$dependencies = Display::page_subheader(get_lang('Dependencies'));
|
||||
$dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link'));
|
||||
}
|
||||
|
||||
$promotion = null;
|
||||
if (!empty($sessionInfo['promotion_id'])) {
|
||||
$promotion = $em->getRepository('ChamiloCoreBundle:Promotion');
|
||||
$promotion = $promotion->find($sessionInfo['promotion_id']);
|
||||
}
|
||||
|
||||
$programmedAnnouncement = new ScheduledAnnouncement();
|
||||
$programmedAnnouncement = $programmedAnnouncement->allowed();
|
||||
|
||||
$htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
|
||||
|
||||
$tpl = new Template($tool_name);
|
||||
$tpl->assign('session_header', $sessionHeader);
|
||||
$tpl->assign('title', $sessionTitle);
|
||||
$tpl->assign('general_coach', $generalCoach);
|
||||
$tpl->assign('session_admin', api_get_user_info($session->getSessionAdminId()));
|
||||
$tpl->assign('session', $sessionInfo);
|
||||
$tpl->assign('programmed_announcement', $programmedAnnouncement);
|
||||
$tpl->assign('session_category', is_null($sessionCategory) ? null : $sessionCategory->getName());
|
||||
$tpl->assign('session_dates', SessionManager::parseSessionDates($sessionInfo, true));
|
||||
$tpl->assign('session_visibility', SessionManager::getSessionVisibility($sessionInfo));
|
||||
$tpl->assign('promotion', $promotion);
|
||||
$tpl->assign('url_list', $urlList);
|
||||
$tpl->assign('extra_fields', $extraFieldData);
|
||||
$tpl->assign('course_list', $courseListToShow);
|
||||
$tpl->assign('user_list', $userListToShow);
|
||||
$tpl->assign('dependencies', $dependencies);
|
||||
$tpl->assign('requirements', $requirements);
|
||||
|
||||
$layout = $tpl->get_template('session/resume_session.tpl');
|
||||
$tpl->display($layout);
|
||||
240
main/session/scheduled_announcement.php
Normal file
240
main/session/scheduled_announcement.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
|
||||
$sessionInfo = api_get_session_info($sessionId);
|
||||
if (!$sessionInfo) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$object = new ScheduledAnnouncement();
|
||||
|
||||
if (!$object->allowed()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionUrl = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$sessionId;
|
||||
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => $sessionUrl,
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
$tool_name = get_lang('ScheduledAnnouncements');
|
||||
|
||||
switch ($action) {
|
||||
case 'run':
|
||||
$messagesSent = $object->sendPendingMessages();
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('MessageSent').': '.$messagesSent,
|
||||
'confirmation'
|
||||
)
|
||||
);
|
||||
$content = $object->getGrid($sessionId);
|
||||
break;
|
||||
case 'add':
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_self().'?session_id='.$sessionId,
|
||||
'name' => get_lang('ScheduledAnnouncements'),
|
||||
];
|
||||
$tool_name = get_lang('Add');
|
||||
|
||||
$url = api_get_self().'?action=add&session_id='.$sessionId;
|
||||
$form = $object->returnForm($url, 'add', $sessionInfo);
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
switch ($values['type']) {
|
||||
case 'base_date':
|
||||
case 'base_progress':
|
||||
$numberDays = (int) $values['days'];
|
||||
switch ($values['base_date']) {
|
||||
case 'start_date':
|
||||
$baseDate = new DateTime($sessionInfo['access_start_date']);
|
||||
break;
|
||||
case 'end_date':
|
||||
$baseDate = new DateTime($sessionInfo['access_end_date']);
|
||||
break;
|
||||
}
|
||||
$interval = new DateInterval('P'.$numberDays.'D');
|
||||
switch ($values['moment_type']) {
|
||||
case 'after':
|
||||
$newDate = $baseDate->add($interval);
|
||||
break;
|
||||
case 'before':
|
||||
$newDate = $baseDate->sub($interval);
|
||||
break;
|
||||
}
|
||||
$values['date'] = $newDate->format('Y-m-d h:i:s');
|
||||
|
||||
if ($values['type'] == 'base_progress') {
|
||||
$values['extra_use_base_progress'] = $values['progress'];
|
||||
}
|
||||
|
||||
break;
|
||||
case 'specific_date':
|
||||
$values['date'] = api_get_utc_datetime($values['date']);
|
||||
break;
|
||||
}
|
||||
|
||||
$res = $object->save($values);
|
||||
|
||||
if ($res) {
|
||||
$extraFieldValue = new ExtraFieldValue('scheduled_announcement');
|
||||
$values['item_id'] = $res;
|
||||
$extraFieldValue->saveFieldValues($values);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('ItemAdded'),
|
||||
'confirmation'
|
||||
)
|
||||
);
|
||||
}
|
||||
$content = $object->getGrid($sessionId);
|
||||
} else {
|
||||
$content = '<div class="actions">';
|
||||
$content .= Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
|
||||
api_get_self().'?session_id='.$sessionId
|
||||
);
|
||||
$content .= '</div>';
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
|
||||
$content .= $form->returnForm();
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
$tool_name = get_lang('Edit');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_self().'?session_id='.$sessionId,
|
||||
'name' => get_lang('ScheduledAnnouncements'),
|
||||
];
|
||||
|
||||
// Action handling: Editing
|
||||
$url = api_get_self().'?action=edit&id='.$id.'&session_id='.$sessionId;
|
||||
$form = $object->returnSimpleForm($id, $url, 'edit', $sessionInfo);
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
$values['id'] = $id;
|
||||
$values['sent'] = isset($values['sent']) ? 1 : '';
|
||||
$values['date'] = api_get_utc_datetime($values['date']);
|
||||
$res = $object->update($values);
|
||||
|
||||
$values['extra_use_base_progress'] = $values['progress'];
|
||||
$extraFieldValue = new ExtraFieldValue('scheduled_announcement');
|
||||
$baseProgress = $extraFieldValue->get_values_by_handler_and_field_variable(
|
||||
$id,
|
||||
'use_base_progress'
|
||||
);
|
||||
$values['extra_use_base_progress_comment'] = $baseProgress["comment"];
|
||||
|
||||
$values['item_id'] = $id;
|
||||
$extraFieldValue->saveFieldValues($values);
|
||||
|
||||
Display::addFlash(Display::return_message(
|
||||
get_lang('Updated'),
|
||||
'confirmation'
|
||||
));
|
||||
header("Location: $url");
|
||||
exit;
|
||||
}
|
||||
$item = $object->get($id);
|
||||
$item['date'] = api_get_local_time($item['date']);
|
||||
$form->setDefaults($item);
|
||||
$content = $form->returnForm();
|
||||
break;
|
||||
case 'delete':
|
||||
$object->delete($id);
|
||||
$content = $object->getGrid($sessionId);
|
||||
break;
|
||||
default:
|
||||
$content = $object->getGrid($sessionId);
|
||||
break;
|
||||
}
|
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_programmed_announcements&session_id='.$sessionId;
|
||||
|
||||
$columns = [
|
||||
get_lang('Subject'),
|
||||
get_lang('Date'),
|
||||
get_lang('Sent'),
|
||||
get_lang('Actions'),
|
||||
];
|
||||
|
||||
$columnModel = [
|
||||
[
|
||||
'name' => 'subject',
|
||||
'index' => 'subject',
|
||||
'width' => '250',
|
||||
'align' => 'left',
|
||||
],
|
||||
[
|
||||
'name' => 'date',
|
||||
'index' => 'date',
|
||||
//'width' => '90',
|
||||
//'align' => 'left',
|
||||
'sortable' => 'true',
|
||||
],
|
||||
[
|
||||
'name' => 'sent',
|
||||
'index' => 'sent',
|
||||
//'width' => '90',
|
||||
//'align' => 'left',
|
||||
'sortable' => 'true',
|
||||
],
|
||||
[
|
||||
'name' => 'actions',
|
||||
'index' => 'actions',
|
||||
'width' => '100',
|
||||
'align' => 'left',
|
||||
'formatter' => 'action_formatter',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
];
|
||||
|
||||
$actionLinks = 'function action_formatter(cellvalue, options, rowObject) {
|
||||
return \'<a href="?action=edit&session_id='.$sessionId.'&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?action=delete&session_id='.$sessionId.'&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
'\';
|
||||
}';
|
||||
|
||||
$extraParams = [];
|
||||
$extraParams['autowidth'] = 'true';
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
// grid definition see the $obj->display() function
|
||||
'.Display::grid_js(
|
||||
'programmed',
|
||||
$url,
|
||||
$columns,
|
||||
$columnModel,
|
||||
$extraParams,
|
||||
[],
|
||||
$actionLinks,
|
||||
true
|
||||
).'
|
||||
});
|
||||
</script>';
|
||||
|
||||
$tpl = new Template($tool_name);
|
||||
$sessionTitle = Display::page_header($sessionInfo['name']);
|
||||
$tpl->assign('content', $sessionTitle.$content);
|
||||
$tpl->display_one_col_template();
|
||||
474
main/session/session_add.php
Normal file
474
main/session/session_add.php
Normal file
@@ -0,0 +1,474 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_coachs');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
SessionManager::protectSession(null, false);
|
||||
api_protect_limit_for_session_admin();
|
||||
|
||||
$formSent = 0;
|
||||
$errorMsg = '';
|
||||
|
||||
// Crop picture plugin for session images
|
||||
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
|
||||
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
|
||||
function search_coachs($needle)
|
||||
{
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
|
||||
if (!empty($needle)) {
|
||||
$needle = Database::escape_string($needle);
|
||||
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
|
||||
|
||||
// search users where username or firstname or lastname begins likes $needle
|
||||
$sql = 'SELECT username, lastname, firstname
|
||||
FROM '.$tbl_user.' user
|
||||
WHERE (username LIKE "'.$needle.'%"
|
||||
OR firstname LIKE "'.$needle.'%"
|
||||
OR lastname LIKE "'.$needle.'%")
|
||||
AND status=1'.
|
||||
$order_clause.
|
||||
' LIMIT 10';
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = 'SELECT username, lastname, firstname
|
||||
FROM '.$tbl_user.' user
|
||||
INNER JOIN '.$tbl_user_rel_access_url.' url_user
|
||||
ON (url_user.user_id=user.user_id)
|
||||
WHERE
|
||||
access_url_id = '.$access_url_id.' AND
|
||||
(
|
||||
username LIKE "'.$needle.'%" OR
|
||||
firstname LIKE "'.$needle.'%" OR
|
||||
lastname LIKE "'.$needle.'%"
|
||||
)
|
||||
AND status=1'.
|
||||
$order_clause.'
|
||||
LIMIT 10';
|
||||
}
|
||||
}
|
||||
|
||||
$rs = Database::query($sql);
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$return .= '<a href="javascript: void(0);" onclick="javascript: fill_coach_field(\''.$user['username'].'\')">'.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')</a><br />';
|
||||
}
|
||||
}
|
||||
$xajax_response->addAssign('ajax_list_coachs', 'innerHTML', api_utf8_encode($return));
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = "
|
||||
<script>
|
||||
$(function() {
|
||||
accessSwitcher(0);
|
||||
});
|
||||
|
||||
function fill_coach_field (username) {
|
||||
document.getElementById('coach_username').value = username;
|
||||
document.getElementById('ajax_list_coachs').innerHTML = '';
|
||||
}
|
||||
|
||||
function accessSwitcher(accessFromReady) {
|
||||
var access = $('#access option:selected').val();
|
||||
|
||||
if (accessFromReady >= 0) {
|
||||
access = accessFromReady;
|
||||
}
|
||||
|
||||
if (access == 1) {
|
||||
$('#duration_div').hide();
|
||||
$('#date_fields').show();
|
||||
} else {
|
||||
$('#duration_div').show();
|
||||
$('#date_fields').hide();
|
||||
}
|
||||
emptyDuration();
|
||||
}
|
||||
|
||||
function emptyDuration() {
|
||||
if ($('#duration').val()) {
|
||||
$('#duration').val('');
|
||||
}
|
||||
}
|
||||
</script>";
|
||||
|
||||
if (isset($_POST['formSent'])) {
|
||||
$formSent = (int) $_POST['formSent'];
|
||||
}
|
||||
|
||||
$tool_name = get_lang('AddSession');
|
||||
|
||||
$urlAction = api_get_self();
|
||||
|
||||
function check_session_name($name)
|
||||
{
|
||||
$session = SessionManager::get_session_by_name($name);
|
||||
|
||||
return empty($session) ? true : false;
|
||||
}
|
||||
|
||||
$form = new FormValidator('add_session', 'post', $urlAction);
|
||||
$form->addElement('header', $tool_name);
|
||||
$result = SessionManager::setForm($form);
|
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'session.ajax.php';
|
||||
$urlUpload = api_get_path(WEB_UPLOAD_PATH);
|
||||
$sysUploadPath = api_get_path(SYS_UPLOAD_PATH);
|
||||
$urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
|
||||
|
||||
$htmlHeadXtra[] = "
|
||||
<script>
|
||||
$(function() {
|
||||
".$result['js']."
|
||||
$('#system_template').on('change', function() {
|
||||
var sessionId = $(this).find('option:selected').val();
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
url: '".$url."',
|
||||
data: 'a=session_info&load_empty_extra_fields=true&session_id=' + sessionId,
|
||||
success: function(data) {
|
||||
if (data.session_category_id > 0) {
|
||||
$('#session_category').val(data.session_category_id);
|
||||
$('#session_category').selectpicker('render');
|
||||
} else {
|
||||
$('#session_category').val(0);
|
||||
$('#session_category').selectpicker('render');
|
||||
}
|
||||
|
||||
CKEDITOR.instances.description.setData(data.description);
|
||||
|
||||
if (data.duration > 0) {
|
||||
$('#access').val(0);
|
||||
$('#access').selectpicker('render');
|
||||
accessSwitcher(0);
|
||||
$('#duration').val(parseInt(data.duration));
|
||||
} else {
|
||||
$('#access').val(1);
|
||||
$('#access').selectpicker('render');
|
||||
accessSwitcher(1);
|
||||
|
||||
var variables = [
|
||||
'display_start_date',
|
||||
'access_start_date',
|
||||
'coach_access_start_date',
|
||||
'display_end_date',
|
||||
'access_end_date',
|
||||
'coach_access_end_date'
|
||||
];
|
||||
variables.forEach(function(variable) {
|
||||
var variableName = variable + '_to_local_time';
|
||||
if (data[variableName]) {
|
||||
var parsedDate = $.datepicker.parseDateTime(
|
||||
'yy-mm-dd',
|
||||
'hh:mm:ss',
|
||||
data[variableName]
|
||||
);
|
||||
if (parsedDate) {
|
||||
$('#'+variable).datetimepicker('setDate', parsedDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('[name=\'show_description\']').prop('checked', false);
|
||||
if (data.show_description) {
|
||||
$('[name=\'show_description\']').prop('checked', true);
|
||||
}
|
||||
|
||||
$('[name=\'send_subscription_notification\']').prop('checked', false);
|
||||
if (data.send_subscription_notification) {
|
||||
$('[name=\'send_subscription_notification\']').prop('checked', true);
|
||||
}
|
||||
|
||||
$.each(data.extra_fields, function(i, item) {
|
||||
var fieldName = 'extra_'+item.variable;
|
||||
/*
|
||||
const FIELD_TYPE_TEXT = 1;
|
||||
const FIELD_TYPE_TEXTAREA = 2;
|
||||
const FIELD_TYPE_RADIO = 3;
|
||||
const FIELD_TYPE_SELECT = 4;
|
||||
const FIELD_TYPE_SELECT_MULTIPLE = 5;
|
||||
const FIELD_TYPE_DATE = 6;
|
||||
const FIELD_TYPE_DATETIME = 7;
|
||||
const FIELD_TYPE_DOUBLE_SELECT = 8;
|
||||
const FIELD_TYPE_DIVIDER = 9;
|
||||
const FIELD_TYPE_TAG = 10;
|
||||
const FIELD_TYPE_TIMEZONE = 11;
|
||||
const FIELD_TYPE_SOCIAL_PROFILE = 12;
|
||||
const FIELD_TYPE_CHECKBOX = 13;
|
||||
const FIELD_TYPE_MOBILE_PHONE_NUMBER = 14;
|
||||
const FIELD_TYPE_INTEGER = 15;
|
||||
const FIELD_TYPE_FILE_IMAGE = 16;
|
||||
const FIELD_TYPE_FLOAT = 17;
|
||||
const FIELD_TYPE_FILE = 18;
|
||||
const FIELD_TYPE_VIDEO_URL = 19;
|
||||
const FIELD_TYPE_LETTERS_ONLY = 20;
|
||||
const FIELD_TYPE_ALPHANUMERIC = 21;
|
||||
const FIELD_TYPE_LETTERS_SPACE = 22;
|
||||
const FIELD_TYPE_ALPHANUMERIC_SPACE = 23;*/
|
||||
switch (item.field_type) {
|
||||
case '1': // text
|
||||
case '6': // date
|
||||
case '7': // datetime
|
||||
case '15': // integer
|
||||
case '17': // float
|
||||
case '20': // letters only
|
||||
case '21': // alphanum
|
||||
$('input[name='+fieldName+']').val(item.value);
|
||||
break;
|
||||
case '2': // textarea
|
||||
CKEDITOR.instances[fieldName].setData(item.value);
|
||||
break;
|
||||
case '3': // radio
|
||||
var radio = fieldName+'['+fieldName+']';
|
||||
$('[name=\''+radio+'\']').val([item.value]);
|
||||
break;
|
||||
case '4': // simple select
|
||||
case '5': // multiple select
|
||||
var options = item.value.split(';');
|
||||
$('#'+fieldName+'').val(options);
|
||||
$('#'+fieldName+'').selectpicker('render');
|
||||
break;
|
||||
case '8': // double
|
||||
var first = 'first_'+fieldName;
|
||||
var second = 'second_'+fieldName;
|
||||
// item.value has format : 85::86
|
||||
if (item.value) {
|
||||
var values = item.value.split('::');
|
||||
var firstFieldId = values[0];
|
||||
var secondFieldId = values[1];
|
||||
$('#'+first+'').val(firstFieldId);
|
||||
$('#'+first+'').selectpicker('render');
|
||||
|
||||
// Remove all options
|
||||
$('#'+second+'')
|
||||
.find('option')
|
||||
.remove()
|
||||
.end();
|
||||
|
||||
// Load items for this item then update:
|
||||
$.ajax({
|
||||
url: '".$urlAjaxExtraField."&a=get_second_select_options',
|
||||
dataType: 'json',
|
||||
data: 'type=session&field_id='+item.id+'&option_value_id='+firstFieldId,
|
||||
success: function(data) {
|
||||
$.each(data, function(index, value) {
|
||||
var my_select = $('#'+second+'');
|
||||
my_select.append($(\"<option/>\", {
|
||||
value: index,
|
||||
text: value
|
||||
}));
|
||||
});
|
||||
$('#'+second+'').selectpicker('refresh');
|
||||
}
|
||||
});
|
||||
|
||||
$('#'+second+'').val(secondFieldId);
|
||||
$('#'+second+'').selectpicker('render');
|
||||
}
|
||||
break;
|
||||
case '10': // tags
|
||||
// Remove all options
|
||||
$('#'+fieldName+' option').each(function(i, optionItem) {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
$('#'+fieldName).next().find('.bit-box').each(function(i, optionItem) {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
// Add new options
|
||||
if (item.value) {
|
||||
$.each(item.value, function(i, tagItem) {
|
||||
// Select2 changes
|
||||
//console.log(tagItem.value);
|
||||
//$('#'+fieldName)[0].addItem(tagItem.value, tagItem.value);
|
||||
var option = new Option(tagItem.value, tagItem.value);
|
||||
option.selected = true;
|
||||
$('#'+fieldName).append(option);
|
||||
$('#'+fieldName).trigger(\"change\");
|
||||
});
|
||||
}
|
||||
break;
|
||||
case '13': // check
|
||||
var check = fieldName+'['+fieldName+']';
|
||||
// Default is uncheck
|
||||
$('[name=\''+check+'\']').prop('checked', false);
|
||||
|
||||
if (item.value == 1) {
|
||||
$('[name=\''+check+'\']').prop('checked', true);
|
||||
}
|
||||
break;
|
||||
case '16':
|
||||
if (item.value) {
|
||||
// $('input[name='+fieldName+']').val(item.value);
|
||||
var url = '".$urlUpload."';
|
||||
|
||||
url = url + item.value;
|
||||
|
||||
var divFormGroup = fieldName + '-form-group';
|
||||
var divWrapper = fieldName + '_crop_image';
|
||||
var divPreview = fieldName + '_preview_image';
|
||||
var divCropButton = fieldName + '_crop_button';
|
||||
var cropResult = fieldName + '_crop_result';
|
||||
|
||||
$('[name=\''+cropResult+'\']').val('import_file_from_session::' + sessionId);
|
||||
$('#' + divFormGroup).show();
|
||||
$('#' + divWrapper).show();
|
||||
$('#' + divCropButton).hide();
|
||||
$('#' + divPreview).attr('src', url);
|
||||
//$('[name=\''+fieldName+'\']')
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
</script>";
|
||||
|
||||
$form->addButtonNext(get_lang('NextStep'));
|
||||
|
||||
if (!$formSent) {
|
||||
$formDefaults['access_start_date'] = $formDefaults['display_start_date'] = api_get_local_time();
|
||||
$formDefaults['coach_username'] = api_get_user_id();
|
||||
} else {
|
||||
$formDefaults['name'] = api_htmlentities($name, ENT_QUOTES, $charset);
|
||||
}
|
||||
|
||||
// Relation to prefill session extra field with user extra field
|
||||
$fillExtraField = api_get_configuration_value('session_creation_user_course_extra_field_relation_to_prefill');
|
||||
if (false !== $fillExtraField && !empty($fillExtraField['fields'])) {
|
||||
foreach ($fillExtraField['fields'] as $sessionVariable => $userVariable) {
|
||||
$extraValue = UserManager::get_extra_user_data_by_field(api_get_user_id(), $userVariable);
|
||||
$formDefaults['extra_'.$sessionVariable] = isset($extraValue[$userVariable]) ? $extraValue[$userVariable] : '';
|
||||
}
|
||||
}
|
||||
|
||||
$form->setDefaults($formDefaults);
|
||||
|
||||
if ($form->validate()) {
|
||||
$params = $form->getSubmitValues();
|
||||
$name = $params['name'];
|
||||
$startDate = $params['access_start_date'];
|
||||
$endDate = $params['access_end_date'];
|
||||
$displayStartDate = $params['display_start_date'];
|
||||
$displayEndDate = $params['display_end_date'];
|
||||
$coachStartDate = $params['coach_access_start_date'];
|
||||
if (empty($coachStartDate)) {
|
||||
$coachStartDate = $displayStartDate;
|
||||
}
|
||||
$coachEndDate = $params['coach_access_end_date'];
|
||||
$coach_username = intval($params['coach_username']);
|
||||
$id_session_category = $params['session_category'];
|
||||
$id_visibility = $params['session_visibility'];
|
||||
$duration = isset($params['duration']) ? $params['duration'] : null;
|
||||
$description = $params['description'];
|
||||
$showDescription = isset($params['show_description']) ? 1 : 0;
|
||||
$sendSubscriptionNotification = isset($params['send_subscription_notification']);
|
||||
$isThisImageCropped = isset($params['picture_crop_result']);
|
||||
$status = isset($params['status']) ? $params['status'] : 0;
|
||||
|
||||
$extraFields = [];
|
||||
foreach ($params as $key => $value) {
|
||||
if (strpos($key, 'extra_') === 0) {
|
||||
$extraFields[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($extraFields['extra_image']) && !empty($extraFields['extra_image']['name']) && $isThisImageCropped) {
|
||||
$extraFields['extra_image']['crop_parameters'] = $params['picture_crop_result'];
|
||||
}
|
||||
|
||||
// Check if the session image will be copied from the template
|
||||
$importImageFromSession = false;
|
||||
$sessionIdToImport = explode('::', $params['extra_image_crop_result']);
|
||||
$sessionIdToImport = isset($sessionIdToImport[1]) ? (int) $sessionIdToImport[1] : 0;
|
||||
if (!empty($sessionIdToImport)) {
|
||||
$extraField = new ExtraField('session');
|
||||
$extraFieldInfo = $extraField->get_handler_field_info_by_field_variable('image');
|
||||
|
||||
$extraFieldValue = new ExtraFieldValue('session');
|
||||
$extraFieldValueData = $extraFieldValue->get_values_by_handler_and_field_id(
|
||||
$sessionIdToImport,
|
||||
$extraFieldInfo['id']
|
||||
);
|
||||
|
||||
if ($extraFieldValueData && file_exists($sysUploadPath.$extraFieldValueData['value'])) {
|
||||
$extraFields['extra_image']['name'] = basename($extraFieldValueData['value']);
|
||||
$extraFields['extra_image']['tmp_name'] = $sysUploadPath.$extraFieldValueData['value'];
|
||||
$extraFields['extra_image']['type'] = 'image/png';
|
||||
$extraFields['extra_image']['error'] = 0;
|
||||
$extraFields['extra_image']['size'] = filesize($sysUploadPath.$extraFieldValueData['value']);
|
||||
}
|
||||
}
|
||||
|
||||
$return = SessionManager::create_session(
|
||||
$name,
|
||||
$startDate,
|
||||
$endDate,
|
||||
$displayStartDate,
|
||||
$displayEndDate,
|
||||
$coachStartDate,
|
||||
$coachEndDate,
|
||||
$coach_username,
|
||||
$id_session_category,
|
||||
$id_visibility,
|
||||
false,
|
||||
$duration,
|
||||
$description,
|
||||
$showDescription,
|
||||
$extraFields,
|
||||
null,
|
||||
$sendSubscriptionNotification,
|
||||
api_get_current_access_url_id(),
|
||||
$status
|
||||
);
|
||||
|
||||
if ($return == strval(intval($return))) {
|
||||
// integer => no error on session creation
|
||||
header('Location: add_courses_to_session.php?id_session='.$return.'&add=true');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!empty($return)) {
|
||||
echo Display::return_message($return, 'error', false);
|
||||
}
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="../session/session_list.php">'.
|
||||
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
329
main/session/session_category_add.php
Normal file
329
main/session/session_category_add.php
Normal file
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*
|
||||
* @todo use formvalidator for the form
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_coachs');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$formSent = 0;
|
||||
$errorMsg = '';
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "session_category_list.php",
|
||||
"name" => get_lang('ListSessionCategory'),
|
||||
];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
$formSent = 1;
|
||||
$name = $_POST['name'];
|
||||
$year_start = $_POST['year_start'];
|
||||
$month_start = $_POST['month_start'];
|
||||
$day_start = $_POST['day_start'];
|
||||
$year_end = $_POST['year_end'];
|
||||
$month_end = $_POST['month_end'];
|
||||
$day_end = $_POST['day_end'];
|
||||
$return = SessionManager::create_category_session(
|
||||
$name,
|
||||
$year_start,
|
||||
$month_start,
|
||||
$day_start,
|
||||
$year_end,
|
||||
$month_end,
|
||||
$day_end
|
||||
);
|
||||
|
||||
if ($return == strval(intval($return))) {
|
||||
Display::addFlash(Display::return_message(get_lang('SessionCategoryAdded')));
|
||||
header('Location: session_category_list.php');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$thisYear = date('Y');
|
||||
$thisMonth = date('m');
|
||||
$thisDay = date('d');
|
||||
$tool_name = get_lang('AddACategory');
|
||||
|
||||
//display the header
|
||||
Display::display_header($tool_name);
|
||||
if (!empty($return)) {
|
||||
echo Display::return_message($return, 'error', false);
|
||||
}
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<form method="post" name="form" action="<?php echo api_get_self(); ?>" class="form-horizontal">
|
||||
<input type="hidden" name="formSent" value="1">
|
||||
<legend><?php echo $tool_name; ?></legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"><?php echo get_lang('SessionCategoryName'); ?></label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control" name="name" placeholder="<?php echo get_lang('Category'); ?>" size="50" maxlength="50" value="<?php if ($formSent) {
|
||||
echo api_htmlentities($name, ENT_QUOTES, $charset);
|
||||
} ?>">
|
||||
</div>
|
||||
<div class="col-md-3"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-6">
|
||||
<?php echo get_lang('TheTimeLimitsAreReferential'); ?> <a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}"><?php echo get_lang('AddTimeLimit'); ?></a>
|
||||
</div>
|
||||
<div class="col-md-3"></div>
|
||||
</div>
|
||||
|
||||
<div style="display: none" id="options">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"><?php echo get_lang('DateStart'); ?></label>
|
||||
<div class="col-sm-6">
|
||||
<select name="day_start">
|
||||
<option value="1">01</option>
|
||||
<option value="2" <?php if ((!$formSent && $thisDay == 2) || ($formSent && $day_start == 2)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >02</option>
|
||||
<option value="3" <?php if ((!$formSent && $thisDay == 3) || ($formSent && $day_start == 3)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >03</option>
|
||||
<option value="4" <?php if ((!$formSent && $thisDay == 4) || ($formSent && $day_start == 4)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >04</option>
|
||||
<option value="5" <?php if ((!$formSent && $thisDay == 5) || ($formSent && $day_start == 5)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >05</option>
|
||||
<option value="6" <?php if ((!$formSent && $thisDay == 6) || ($formSent && $day_start == 6)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >06</option>
|
||||
<option value="7" <?php if ((!$formSent && $thisDay == 7) || ($formSent && $day_start == 7)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >07</option>
|
||||
<option value="8" <?php if ((!$formSent && $thisDay == 8) || ($formSent && $day_start == 8)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >08</option>
|
||||
<option value="9" <?php if ((!$formSent && $thisDay == 9) || ($formSent && $day_start == 9)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >09</option>
|
||||
<option value="10" <?php if ((!$formSent && $thisDay == 10) || ($formSent && $day_start == 10)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >10</option>
|
||||
<option value="11" <?php if ((!$formSent && $thisDay == 11) || ($formSent && $day_start == 11)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >11</option>
|
||||
<option value="12" <?php if ((!$formSent && $thisDay == 12) || ($formSent && $day_start == 12)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >12</option>
|
||||
<option value="13" <?php if ((!$formSent && $thisDay == 13) || ($formSent && $day_start == 13)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >13</option>
|
||||
<option value="14" <?php if ((!$formSent && $thisDay == 14) || ($formSent && $day_start == 14)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >14</option>
|
||||
<option value="15" <?php if ((!$formSent && $thisDay == 15) || ($formSent && $day_start == 15)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >15</option>
|
||||
<option value="16" <?php if ((!$formSent && $thisDay == 16) || ($formSent && $day_start == 16)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >16</option>
|
||||
<option value="17" <?php if ((!$formSent && $thisDay == 17) || ($formSent && $day_start == 17)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >17</option>
|
||||
<option value="18" <?php if ((!$formSent && $thisDay == 18) || ($formSent && $day_start == 18)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >18</option>
|
||||
<option value="19" <?php if ((!$formSent && $thisDay == 19) || ($formSent && $day_start == 19)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >19</option>
|
||||
<option value="20" <?php if ((!$formSent && $thisDay == 20) || ($formSent && $day_start == 20)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >20</option>
|
||||
<option value="21" <?php if ((!$formSent && $thisDay == 21) || ($formSent && $day_start == 21)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >21</option>
|
||||
<option value="22" <?php if ((!$formSent && $thisDay == 22) || ($formSent && $day_start == 22)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >22</option>
|
||||
<option value="23" <?php if ((!$formSent && $thisDay == 23) || ($formSent && $day_start == 23)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >23</option>
|
||||
<option value="24" <?php if ((!$formSent && $thisDay == 24) || ($formSent && $day_start == 24)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >24</option>
|
||||
<option value="25" <?php if ((!$formSent && $thisDay == 25) || ($formSent && $day_start == 25)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >25</option>
|
||||
<option value="26" <?php if ((!$formSent && $thisDay == 26) || ($formSent && $day_start == 26)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >26</option>
|
||||
<option value="27" <?php if ((!$formSent && $thisDay == 27) || ($formSent && $day_start == 27)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >27</option>
|
||||
<option value="28" <?php if ((!$formSent && $thisDay == 28) || ($formSent && $day_start == 28)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >28</option>
|
||||
<option value="29" <?php if ((!$formSent && $thisDay == 29) || ($formSent && $day_start == 29)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >29</option>
|
||||
<option value="30" <?php if ((!$formSent && $thisDay == 30) || ($formSent && $day_start == 30)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >30</option>
|
||||
<option value="31" <?php if ((!$formSent && $thisDay == 31) || ($formSent && $day_start == 31)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >31</option>
|
||||
</select>
|
||||
/
|
||||
<select name="month_start">
|
||||
<option value="1">01</option>
|
||||
<option value="2" <?php if ((!$formSent && $thisMonth == 2) || ($formSent && $month_start == 2)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >02</option>
|
||||
<option value="3" <?php if ((!$formSent && $thisMonth == 3) || ($formSent && $month_start == 3)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >03</option>
|
||||
<option value="4" <?php if ((!$formSent && $thisMonth == 4) || ($formSent && $month_start == 4)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >04</option>
|
||||
<option value="5" <?php if ((!$formSent && $thisMonth == 5) || ($formSent && $month_start == 5)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >05</option>
|
||||
<option value="6" <?php if ((!$formSent && $thisMonth == 6) || ($formSent && $month_start == 6)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >06</option>
|
||||
<option value="7" <?php if ((!$formSent && $thisMonth == 7) || ($formSent && $month_start == 7)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >07</option>
|
||||
<option value="8" <?php if ((!$formSent && $thisMonth == 8) || ($formSent && $month_start == 8)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >08</option>
|
||||
<option value="9" <?php if ((!$formSent && $thisMonth == 9) || ($formSent && $month_start == 9)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >09</option>
|
||||
<option value="10" <?php if ((!$formSent && $thisMonth == 10) || ($formSent && $month_start == 10)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >10</option>
|
||||
<option value="11" <?php if ((!$formSent && $thisMonth == 11) || ($formSent && $month_start == 11)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >11</option>
|
||||
<option value="12" <?php if ((!$formSent && $thisMonth == 12) || ($formSent && $month_start == 12)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >12</option>
|
||||
</select>
|
||||
/
|
||||
<select name="year_start">
|
||||
<?php
|
||||
for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
|
||||
?>
|
||||
<option value="<?php echo $i; ?>" <?php if ((!$formSent && $thisYear == $i) || ($formSent && $year_start == $i)) {
|
||||
echo 'selected="selected"';
|
||||
} ?> ><?php echo $i; ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"><?php echo get_lang('DateEnd'); ?></label>
|
||||
<div class="col-sm-6">
|
||||
<select name="day_end">
|
||||
<option value="0">--</option>
|
||||
<option value="1">01</option>
|
||||
<option value="2">02</option>
|
||||
<option value="3">03</option>
|
||||
<option value="4">04</option>
|
||||
<option value="5">05</option>
|
||||
<option value="6">06</option>
|
||||
<option value="7">07</option>
|
||||
<option value="8">08</option>
|
||||
<option value="9">09</option>
|
||||
<option value="10">10</option>
|
||||
<option value="11">11</option>
|
||||
<option value="12">12</option>
|
||||
<option value="13">13</option>
|
||||
<option value="14">14</option>
|
||||
<option value="15">15</option>
|
||||
<option value="16">16</option>
|
||||
<option value="17">17</option>
|
||||
<option value="18">18</option>
|
||||
<option value="19">19</option>
|
||||
<option value="20">20</option>
|
||||
<option value="21">21</option>
|
||||
<option value="22">22</option>
|
||||
<option value="23">23</option>
|
||||
<option value="24">24</option>
|
||||
<option value="25">25</option>
|
||||
<option value="26">26</option>
|
||||
<option value="27">27</option>
|
||||
<option value="28">28</option>
|
||||
<option value="29">29</option>
|
||||
<option value="30">30</option>
|
||||
<option value="31">31</option>
|
||||
</select>
|
||||
/
|
||||
<select name="month_end">
|
||||
<option value="0">--</option>
|
||||
<option value="1">01</option>
|
||||
<option value="2">02</option>
|
||||
<option value="3">03</option>
|
||||
<option value="4">04</option>
|
||||
<option value="5">05</option>
|
||||
<option value="6">06</option>
|
||||
<option value="7">07</option>
|
||||
<option value="8">08</option>
|
||||
<option value="9">09</option>
|
||||
<option value="10">10</option>
|
||||
<option value="11">11</option>
|
||||
<option value="12">12</option>
|
||||
</select>
|
||||
/
|
||||
<select name="year_end">
|
||||
<option value="0">----</option>
|
||||
<?php
|
||||
for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
|
||||
?>
|
||||
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-6">
|
||||
<button class="btn btn-success" type="submit" value="<?php echo get_lang('AddACategory'); ?>"><em class="fa fa-plus"></em> <?php echo get_lang('AddACategory'); ?></button>
|
||||
</div>
|
||||
<div class="col-md-3"></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
function setDisable(select) {
|
||||
document.form.day_start.disabled = (select.checked) ? true : false;
|
||||
document.form.month_start.disabled = (select.checked) ? true : false;
|
||||
document.form.year_start.disabled = (select.checked) ? true : false;
|
||||
document.form.day_end.disabled = (select.checked) ? true : false;
|
||||
document.form.month_end.disabled = (select.checked) ? true : false;
|
||||
document.form.year_end.disabled = (select.checked) ? true : false;
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
440
main/session/session_category_edit.php
Normal file
440
main/session/session_category_edit.php
Normal file
@@ -0,0 +1,440 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Edition script for sessions categories.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script(true);
|
||||
$id = (int) $_GET['id'];
|
||||
$formSent = 0;
|
||||
$errorMsg = '';
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
|
||||
$tool_name = get_lang('EditSessionCategory');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'session_list.php',
|
||||
"name" => get_lang('SessionList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "session_category_list.php",
|
||||
"name" => get_lang('ListSessionCategory'),
|
||||
];
|
||||
|
||||
$sql = "SELECT * FROM $tbl_session_category WHERE id='".$id."' ORDER BY name";
|
||||
$result = Database::query($sql);
|
||||
if (!$infos = Database::fetch_array($result)) {
|
||||
header('Location: session_list.php');
|
||||
exit();
|
||||
}
|
||||
$year_start = $month_start = $day_start = null;
|
||||
$year_end = $month_end = $day_end = null;
|
||||
|
||||
if ($infos['date_start']) {
|
||||
list($year_start, $month_start, $day_start) = explode('-', $infos['date_start']);
|
||||
}
|
||||
|
||||
if ($infos['date_end']) {
|
||||
list($year_end, $month_end, $day_end) = explode('-', $infos['date_end']);
|
||||
}
|
||||
|
||||
if (!api_is_platform_admin() && $infos['session_admin_id'] != $_user['user_id'] && !api_is_session_admin()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
$formSent = 1;
|
||||
$name = $_POST['name'];
|
||||
$year_start = $_POST['year_start'];
|
||||
$month_start = $_POST['month_start'];
|
||||
$day_start = $_POST['day_start'];
|
||||
$year_end = $_POST['year_end'];
|
||||
$month_end = $_POST['month_end'];
|
||||
$day_end = $_POST['day_end'];
|
||||
$return = SessionManager::edit_category_session(
|
||||
$id,
|
||||
$name,
|
||||
$year_start,
|
||||
$month_start,
|
||||
$day_start,
|
||||
$year_end,
|
||||
$month_end,
|
||||
$day_end
|
||||
);
|
||||
if ($return == strval(intval($return))) {
|
||||
Display::addFlash(Display::return_message(get_lang('SessionCategoryUpdate')));
|
||||
header('Location: session_category_list.php');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$thisYear = date('Y');
|
||||
$thisMonth = date('m');
|
||||
$thisDay = date('d');
|
||||
|
||||
// display the header
|
||||
Display::display_header($tool_name);
|
||||
if (!empty($return)) {
|
||||
echo Display::return_message($return, 'error', false);
|
||||
}
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<form method="post" name="form" action="<?php echo api_get_self(); ?>?id=<?php echo $id; ?>" class="form-horizontal">
|
||||
<input type="hidden" name="formSent" value="1">
|
||||
<legend><?php echo $tool_name; ?> </legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"><?php echo get_lang('Name'); ?></label>
|
||||
<div class="col-sm-6">
|
||||
<input class="form-control" type="text" name="name" size="50" maxlength="50" value="<?php if ($formSent) {
|
||||
echo api_htmlentities($name, ENT_QUOTES, $charset);
|
||||
} else {
|
||||
echo api_htmlentities($infos['name'], ENT_QUOTES, $charset);
|
||||
} ?>">
|
||||
</div>
|
||||
<div class="col-sm-3"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-6">
|
||||
<?php echo get_lang('TheTimeLimitsAreReferential'); ?>
|
||||
<a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}">
|
||||
<?php echo get_lang('EditTimeLimit'); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: <?php echo $formSent ? 'display' : 'none'; ?>;" id="options">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"><?php echo get_lang('DateStart'); ?></label>
|
||||
<div class="col-sm-6">
|
||||
<select name="day_start">
|
||||
<option value="1">01</option>
|
||||
<option value="2" <?php if ($day_start == 2) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >02</option>
|
||||
<option value="3" <?php if ($day_start == 3) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >03</option>
|
||||
<option value="4" <?php if ($day_start == 4) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >04</option>
|
||||
<option value="5" <?php if ($day_start == 5) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >05</option>
|
||||
<option value="6" <?php if ($day_start == 6) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >06</option>
|
||||
<option value="7" <?php if ($day_start == 7) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >07</option>
|
||||
<option value="8" <?php if ($day_start == 8) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >08</option>
|
||||
<option value="9" <?php if ($day_start == 9) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >09</option>
|
||||
<option value="10" <?php if ($day_start == 10) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >10</option>
|
||||
<option value="11" <?php if ($day_start == 11) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >11</option>
|
||||
<option value="12" <?php if ($day_start == 12) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >12</option>
|
||||
<option value="13" <?php if ($day_start == 13) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >13</option>
|
||||
<option value="14" <?php if ($day_start == 14) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >14</option>
|
||||
<option value="15" <?php if ($day_start == 15) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >15</option>
|
||||
<option value="16" <?php if ($day_start == 16) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >16</option>
|
||||
<option value="17" <?php if ($day_start == 17) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >17</option>
|
||||
<option value="18" <?php if ($day_start == 18) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >18</option>
|
||||
<option value="19" <?php if ($day_start == 19) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >19</option>
|
||||
<option value="20" <?php if ($day_start == 20) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >20</option>
|
||||
<option value="21" <?php if ($day_start == 21) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >21</option>
|
||||
<option value="22" <?php if ($day_start == 22) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >22</option>
|
||||
<option value="23" <?php if ($day_start == 23) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >23</option>
|
||||
<option value="24" <?php if ($day_start == 24) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >24</option>
|
||||
<option value="25" <?php if ($day_start == 25) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >25</option>
|
||||
<option value="26" <?php if ($day_start == 26) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >26</option>
|
||||
<option value="27" <?php if ($day_start == 27) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >27</option>
|
||||
<option value="28" <?php if ($day_start == 28) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >28</option>
|
||||
<option value="29" <?php if ($day_start == 29) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >29</option>
|
||||
<option value="30" <?php if ($day_start == 30) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >30</option>
|
||||
<option value="31" <?php if ($day_start == 31) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >31</option>
|
||||
</select>
|
||||
/
|
||||
<select name="month_start">
|
||||
<option value="1">01</option>
|
||||
<option value="2" <?php if ($month_start == 2) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >02</option>
|
||||
<option value="3" <?php if ($month_start == 3) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >03</option>
|
||||
<option value="4" <?php if ($month_start == 4) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >04</option>
|
||||
<option value="5" <?php if ($month_start == 5) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >05</option>
|
||||
<option value="6" <?php if ($month_start == 6) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >06</option>
|
||||
<option value="7" <?php if ($month_start == 7) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >07</option>
|
||||
<option value="8" <?php if ($month_start == 8) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >08</option>
|
||||
<option value="9" <?php if ($month_start == 9) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >09</option>
|
||||
<option value="10" <?php if ($month_start == 10) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >10</option>
|
||||
<option value="11" <?php if ($month_start == 11) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >11</option>
|
||||
<option value="12" <?php if ($month_start == 12) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >12</option>
|
||||
</select>
|
||||
/
|
||||
<select name="year_start">
|
||||
<?php
|
||||
for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
|
||||
?>
|
||||
<option value="<?php echo $i; ?>" <?php if ($year_start == $i) {
|
||||
echo 'selected="selected"';
|
||||
} ?> ><?php echo $i; ?></option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-3"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label"><?php echo get_lang('DateEnd'); ?></label>
|
||||
<div class="col-sm-6">
|
||||
<select name="day_end">
|
||||
<option value="0">--</option>
|
||||
<option value="1" <?php if ($day_end == 1) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >01</option>
|
||||
<option value="2" <?php if ($day_end == 2) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >02</option>
|
||||
<option value="3" <?php if ($day_end == 3) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >03</option>
|
||||
<option value="4" <?php if ($day_end == 4) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >04</option>
|
||||
<option value="5" <?php if ($day_end == 5) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >05</option>
|
||||
<option value="6" <?php if ($day_end == 6) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >06</option>
|
||||
<option value="7" <?php if ($day_end == 7) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >07</option>
|
||||
<option value="8" <?php if ($day_end == 8) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >08</option>
|
||||
<option value="9" <?php if ($day_end == 9) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >09</option>
|
||||
<option value="10" <?php if ($day_end == 10) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >10</option>
|
||||
<option value="11" <?php if ($day_end == 11) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >11</option>
|
||||
<option value="12" <?php if ($day_end == 12) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >12</option>
|
||||
<option value="13" <?php if ($day_end == 13) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >13</option>
|
||||
<option value="14" <?php if ($day_end == 14) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >14</option>
|
||||
<option value="15" <?php if ($day_end == 15) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >15</option>
|
||||
<option value="16" <?php if ($day_end == 16) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >16</option>
|
||||
<option value="17" <?php if ($day_end == 17) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >17</option>
|
||||
<option value="18" <?php if ($day_end == 18) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >18</option>
|
||||
<option value="19" <?php if ($day_end == 19) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >19</option>
|
||||
<option value="20" <?php if ($day_end == 20) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >20</option>
|
||||
<option value="21" <?php if ($day_end == 21) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >21</option>
|
||||
<option value="22" <?php if ($day_end == 22) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >22</option>
|
||||
<option value="23" <?php if ($day_end == 23) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >23</option>
|
||||
<option value="24" <?php if ($day_end == 24) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >24</option>
|
||||
<option value="25" <?php if ($day_end == 25) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >25</option>
|
||||
<option value="26" <?php if ($day_end == 26) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >26</option>
|
||||
<option value="27" <?php if ($day_end == 27) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >27</option>
|
||||
<option value="28" <?php if ($day_end == 28) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >28</option>
|
||||
<option value="29" <?php if ($day_end == 29) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >29</option>
|
||||
<option value="30" <?php if ($day_end == 30) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >30</option>
|
||||
<option value="31" <?php if ($day_end == 31) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >31</option>
|
||||
</select>
|
||||
/
|
||||
<select name="month_end">
|
||||
<option value="0">--</option>
|
||||
<option value="1" <?php if ($month_end == 1) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >01</option>
|
||||
<option value="2" <?php if ($month_end == 2) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >02</option>
|
||||
<option value="3" <?php if ($month_end == 3) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >03</option>
|
||||
<option value="4" <?php if ($month_end == 4) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >04</option>
|
||||
<option value="5" <?php if ($month_end == 5) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >05</option>
|
||||
<option value="6" <?php if ($month_end == 6) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >06</option>
|
||||
<option value="7" <?php if ($month_end == 7) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >07</option>
|
||||
<option value="8" <?php if ($month_end == 8) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >08</option>
|
||||
<option value="9" <?php if ($month_end == 9) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >09</option>
|
||||
<option value="10" <?php if ($month_end == 10) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >10</option>
|
||||
<option value="11" <?php if ($month_end == 11) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >11</option>
|
||||
<option value="12" <?php if ($month_end == 12) {
|
||||
echo 'selected="selected"';
|
||||
} ?> >12</option>
|
||||
</select>
|
||||
/
|
||||
<select name="year_end">
|
||||
<option value="0">----</option>
|
||||
<?php
|
||||
for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
|
||||
?>
|
||||
<option value="<?php echo $i; ?>" <?php if ($year_end == $i) {
|
||||
echo 'selected="selected"';
|
||||
} ?> ><?php echo $i; ?></option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-3"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-6">
|
||||
<button class="btn btn-primary" type="submit" value="<?php echo get_lang('Edit'); ?>">
|
||||
<?php echo get_lang('Edit'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
<?php if ($year_start == "0000") {
|
||||
echo "setDisable(document.form.nolimit);\r\n";
|
||||
} ?>
|
||||
function setDisable(select){
|
||||
document.form.day_start.disabled = (select.checked) ? true : false;
|
||||
document.form.month_start.disabled = (select.checked) ? true : false;
|
||||
document.form.year_start.disabled = (select.checked) ? true : false;
|
||||
document.form.day_end.disabled = (select.checked) ? true : false;
|
||||
document.form.month_end.disabled = (select.checked) ? true : false;
|
||||
document.form.year_end.disabled = (select.checked) ? true : false;
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
300
main/session/session_category_list.php
Normal file
300
main/session/session_category_list.php
Normal file
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* List sessions categories.
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
api_protect_limit_for_session_admin();
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function selectAll(idCheck,numRows,action) {
|
||||
for(i = 0; i < numRows; i++) {
|
||||
idcheck = document.getElementById(idCheck + "_" + i);
|
||||
idcheck.checked = action == "true";
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
|
||||
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
|
||||
$page = isset($_GET['page']) ? (int) $_GET['page'] : null;
|
||||
$action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : null;
|
||||
$columns = ['name', 'nbr_session', 'date_start', 'date_end'];
|
||||
$sort = isset($_GET['sort']) && in_array($_GET['sort'], $columns) ? Security::remove_XSS($_GET['sort']) : 'name';
|
||||
$idChecked = isset($_REQUEST['idChecked']) ? Security::remove_XSS($_REQUEST['idChecked']) : null;
|
||||
$order = $_REQUEST['order'] ?? 'ASC';
|
||||
$order = $order === 'ASC' ? 'DESC' : 'ASC';
|
||||
$keyword = null;
|
||||
|
||||
if ($action === 'delete_on_session' || $action === 'delete_off_session') {
|
||||
$delete_session = $action === 'delete_on_session' ? true : false;
|
||||
SessionManager::delete_session_category($idChecked, $delete_session);
|
||||
Display::addFlash(Display::return_message(get_lang('SessionCategoryDelete')));
|
||||
header('Location: '.api_get_self().'?sort='.$sort);
|
||||
exit();
|
||||
}
|
||||
|
||||
$frmSearch = new FormValidator('search', 'get', 'session_category_list.php', '', [], FormValidator::LAYOUT_INLINE);
|
||||
$frmSearch->addText('keyword', get_lang('Search'), false);
|
||||
$frmSearch->addButtonSearch(get_lang('Search'));
|
||||
|
||||
if ($frmSearch->validate()) {
|
||||
$keyword = $frmSearch->exportValues()['keyword'];
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
|
||||
if (isset($_GET['search']) && $_GET['search'] === 'advanced') {
|
||||
$interbreadcrumb[] = ['url' => 'session_category_list.php', 'name' => get_lang('ListSessionCategory')];
|
||||
$tool_name = get_lang('SearchASession');
|
||||
Display::display_header($tool_name);
|
||||
$form = new FormValidator('advanced_search', 'get');
|
||||
$form->addElement('header', '', $tool_name);
|
||||
$active_group = [];
|
||||
$active_group[] = $form->createElement('checkbox', 'active', '', get_lang('Active'));
|
||||
$active_group[] = $form->createElement('checkbox', 'inactive', '', get_lang('Inactive'));
|
||||
$form->addGroup($active_group, '', get_lang('ActiveSession'), null, false);
|
||||
$form->addButtonSearch(get_lang('SearchUsers'));
|
||||
$defaults['active'] = 1;
|
||||
$defaults['inactive'] = 1;
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
} else {
|
||||
$limit = 20;
|
||||
$from = $page * $limit;
|
||||
//if user is crfp admin only list its sessions
|
||||
$where = null;
|
||||
if (!api_is_platform_admin()) {
|
||||
$where .= empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($keyword))."%'";
|
||||
} else {
|
||||
$where .= empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($keyword))."%'";
|
||||
}
|
||||
if (empty($where)) {
|
||||
$where = " WHERE access_url_id = ".api_get_current_access_url_id()." ";
|
||||
} else {
|
||||
$where .= " AND access_url_id = ".api_get_current_access_url_id()." ";
|
||||
}
|
||||
|
||||
$table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
|
||||
$query = "SELECT sc.*, (
|
||||
SELECT count(s.id) FROM $tbl_session s
|
||||
INNER JOIN $table_access_url_rel_session us
|
||||
ON (s.id = us.session_id)
|
||||
WHERE
|
||||
s.session_category_id = sc.id AND
|
||||
access_url_id = ".api_get_current_access_url_id()."
|
||||
) as nbr_session
|
||||
FROM $tbl_session_category sc
|
||||
$where
|
||||
ORDER BY `$sort` $order
|
||||
LIMIT $from,".($limit + 1);
|
||||
|
||||
$query_rows = "SELECT count(*) as total_rows
|
||||
FROM $tbl_session_category sc $where ";
|
||||
$result_rows = Database::query($query_rows);
|
||||
$recorset = Database::fetch_array($result_rows);
|
||||
$num = $recorset['total_rows'];
|
||||
$result = Database::query($query);
|
||||
$Sessions = Database::store_result($result);
|
||||
$nbr_results = sizeof($Sessions);
|
||||
$tool_name = get_lang('ListSessionCategory');
|
||||
Display::display_header($tool_name); ?>
|
||||
<div class="actions">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<?php
|
||||
echo Display::url(
|
||||
Display::return_icon('new_folder.png', get_lang('AddSessionCategory'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'session/session_category_add.php'
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('session.png', get_lang('ListSession'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'session/session_list.php'
|
||||
); ?>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="pull-right">
|
||||
<?php echo $frmSearch->returnForm(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" action="<?php echo api_get_self(); ?>?action=delete&sort=<?php echo $sort; ?>"
|
||||
onsubmit="if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
|
||||
<?php
|
||||
if (count($Sessions) == 0 && isset($_POST['keyword'])) {
|
||||
echo Display::return_message(get_lang('NoSearchResults'), 'warning');
|
||||
} else {
|
||||
if ($num > $limit) {
|
||||
?>
|
||||
<div>
|
||||
<?php
|
||||
if ($page) {
|
||||
?>
|
||||
<a href="<?php echo api_get_self(); ?>?page=<?php echo $page
|
||||
- 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
|
||||
$order
|
||||
); ?>&keyword=<?php echo $keyword; ?><?php echo @$cond_url; ?>"><?php echo get_lang(
|
||||
'Previous'
|
||||
); ?></a>
|
||||
<?php
|
||||
} else {
|
||||
echo get_lang('Previous');
|
||||
} ?>
|
||||
|
|
||||
<?php
|
||||
if ($nbr_results > $limit) {
|
||||
?>
|
||||
<a href="<?php echo api_get_self(); ?>?page=<?php echo $page
|
||||
+ 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
|
||||
$order
|
||||
); ?>&keyword=<?php echo $keyword; ?><?php echo @$cond_url; ?>"><?php echo get_lang(
|
||||
'Next'
|
||||
); ?></a>
|
||||
<?php
|
||||
} else {
|
||||
echo get_lang('Next');
|
||||
} ?>
|
||||
</div>
|
||||
<?php
|
||||
} ?>
|
||||
|
||||
<table class="table table-hover table-striped data_table" width="100%">
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort == 'name') ? $order
|
||||
: 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
|
||||
<th><a href="<?php echo api_get_self(); ?>?sort=nbr_session&order=<?php echo ($sort
|
||||
== 'nbr_session') ? $order : 'ASC'; ?>"><?php echo get_lang('NumberOfSession'); ?></a></th>
|
||||
<th><a href="<?php echo api_get_self(); ?>?sort=date_start&order=<?php echo ($sort == 'date_start')
|
||||
? $order : 'ASC'; ?>"><?php echo get_lang('StartDate'); ?></a></th>
|
||||
<th><a href="<?php echo api_get_self(); ?>?sort=date_end&order=<?php echo ($sort == 'date_end')
|
||||
? $order : 'ASC'; ?>"><?php echo get_lang('EndDate'); ?></a></th>
|
||||
<th><?php echo get_lang('Actions'); ?></th>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$i = 0;
|
||||
$x = 0;
|
||||
foreach ($Sessions as $key => $enreg) {
|
||||
if ($key == $limit) {
|
||||
break;
|
||||
}
|
||||
$sql = 'SELECT COUNT(session_category_id)
|
||||
FROM '.$tbl_session.' s
|
||||
INNER JOIN '.$table_access_url_rel_session.' us
|
||||
ON (s.id = us.session_id)
|
||||
WHERE
|
||||
s.session_category_id = '.intval($enreg['id']).' AND
|
||||
us.access_url_id = '.api_get_current_access_url_id();
|
||||
|
||||
$rs = Database::query($sql);
|
||||
list($nb_courses) = Database::fetch_array($rs); ?>
|
||||
<tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
|
||||
<td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]"
|
||||
value="<?php echo $enreg['id']; ?>"></td>
|
||||
<td><?php echo api_htmlentities($enreg['name'], ENT_QUOTES, $charset); ?></td>
|
||||
<td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses
|
||||
." Session(s) </a>"; ?></td>
|
||||
<td><?php echo api_format_date($enreg['date_start'], DATE_FORMAT_SHORT); ?></td>
|
||||
<td>
|
||||
<?php
|
||||
if (!empty($enreg['date_end']) && $enreg['date_end'] != '0000-00-00') {
|
||||
echo api_format_date($enreg['date_end'], DATE_FORMAT_SHORT);
|
||||
} else {
|
||||
echo '-';
|
||||
} ?>
|
||||
</td>
|
||||
<td>
|
||||
<a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
|
||||
<?php Display::display_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL); ?>
|
||||
</a>
|
||||
<a href="<?php echo api_get_self(
|
||||
); ?>?sort=<?php echo $sort; ?>&action=delete_off_session&idChecked=<?php echo $enreg['id']; ?>"
|
||||
onclick="if(!confirm('<?php echo get_lang(
|
||||
'ConfirmYourChoice'
|
||||
); ?>')) return false;">
|
||||
<?php Display::display_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL); ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$i = $i ? 0 : 1;
|
||||
$x++;
|
||||
}
|
||||
unset($Sessions); ?>
|
||||
</table>
|
||||
<br/>
|
||||
<div>
|
||||
<?php
|
||||
if ($num > $limit) {
|
||||
if ($page) {
|
||||
?>
|
||||
<a href="<?php echo api_get_self(); ?>?page=<?php echo $page
|
||||
- 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
|
||||
$_REQUEST['order']
|
||||
); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>">
|
||||
<?php echo get_lang('Previous'); ?></a>
|
||||
<?php
|
||||
} else {
|
||||
echo get_lang('Previous');
|
||||
} ?>
|
||||
|
|
||||
<?php
|
||||
if ($nbr_results > $limit) {
|
||||
?>
|
||||
|
||||
<a href="<?php echo api_get_self(); ?>?page=<?php echo $page
|
||||
+ 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
|
||||
$_REQUEST['order']
|
||||
); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>">
|
||||
<?php echo get_lang('Next'); ?></a>
|
||||
|
||||
<?php
|
||||
} else {
|
||||
echo get_lang('Next');
|
||||
}
|
||||
} ?>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');">
|
||||
<?php echo get_lang('SelectAll'); ?>
|
||||
</button>
|
||||
<button type="button" class="btn btn-default" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');">
|
||||
<?php echo get_lang('UnSelectAll'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<select class="selectpicker form-control" name="action">
|
||||
<option value="delete_off_session" selected="selected">
|
||||
<?php echo get_lang('DeleteSelectedSessionCategory'); ?>
|
||||
</option>
|
||||
<option value="delete_on_session">
|
||||
<?php echo get_lang('DeleteSelectedFullSessionCategory'); ?>
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button class="btn btn-success" type="submit" name="name" value="<?php echo get_lang('Ok'); ?>">
|
||||
<?php echo get_lang('Ok'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
} ?>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
Display::display_footer();
|
||||
168
main/session/session_course_edit.php
Normal file
168
main/session/session_course_edit.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Implements the edition of course-session settings.
|
||||
*
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
SessionManager::protectSession($id_session);
|
||||
$course_code = $_GET['course_code'];
|
||||
$course_info = api_get_course_info($_REQUEST['course_code']);
|
||||
|
||||
if (empty($course_info)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
||||
|
||||
$courseId = $course_info['real_id'];
|
||||
$tool_name = $course_info['name'];
|
||||
$sql = "SELECT s.name, c.title
|
||||
FROM $tbl_session_course sc, $tbl_session s, $tbl_course c
|
||||
WHERE
|
||||
sc.session_id = s.id AND
|
||||
sc.c_id = c.id AND
|
||||
sc.session_id='$id_session' AND
|
||||
sc.c_id ='".$courseId."'";
|
||||
$result = Database::query($sql);
|
||||
|
||||
if (!list($session_name, $course_title) = Database::fetch_row($result)) {
|
||||
header('Location: session_course_list.php?id_session='.$id_session);
|
||||
exit();
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => "session_list.php", "name" => get_lang("SessionList")];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "resume_session.php?id_session=".$id_session,
|
||||
"name" => get_lang('SessionOverview'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "session_course_list.php?id_session=$id_session",
|
||||
"name" => api_htmlentities($session_name, ENT_QUOTES, $charset),
|
||||
];
|
||||
|
||||
$arr_infos = [];
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
// get all tutor by course_code in the session
|
||||
$sql = "SELECT user_id
|
||||
FROM $tbl_session_rel_course_rel_user
|
||||
WHERE session_id = '$id_session' AND c_id = '".$courseId."' AND status = 2";
|
||||
$rs_coaches = Database::query($sql);
|
||||
|
||||
$coaches_course_session = [];
|
||||
if (Database::num_rows($rs_coaches) > 0) {
|
||||
while ($row_coaches = Database::fetch_row($rs_coaches)) {
|
||||
$coaches_course_session[] = $row_coaches[0];
|
||||
}
|
||||
}
|
||||
|
||||
$id_coaches = isset($_POST['id_coach']) ? $_POST['id_coach'] : [0];
|
||||
if (is_array($id_coaches) && count($id_coaches) > 0) {
|
||||
foreach ($id_coaches as $id_coach) {
|
||||
$id_coach = intval($id_coach);
|
||||
$rs1 = SessionManager::set_coach_to_course_session(
|
||||
$id_coach,
|
||||
$id_session,
|
||||
$courseId
|
||||
);
|
||||
}
|
||||
|
||||
// set status to 0 other tutors from multiple list
|
||||
$array_intersect = array_diff($coaches_course_session, $id_coaches);
|
||||
|
||||
foreach ($array_intersect as $no_coach_user_id) {
|
||||
$rs2 = SessionManager::set_coach_to_course_session(
|
||||
$no_coach_user_id,
|
||||
$id_session,
|
||||
$courseId,
|
||||
true
|
||||
);
|
||||
}
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session);
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
$sql = "SELECT user_id
|
||||
FROM $tbl_session_rel_course_rel_user
|
||||
WHERE
|
||||
session_id = '$id_session' AND
|
||||
c_id = '".$courseId."' AND
|
||||
status = 2 ";
|
||||
$rs = Database::query($sql);
|
||||
|
||||
if (Database::num_rows($rs) > 0) {
|
||||
while ($infos = Database::fetch_array($rs)) {
|
||||
$arr_infos[] = $infos['user_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_access_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
$sql = "SELECT u.user_id,lastname,firstname,username
|
||||
FROM $tbl_user u
|
||||
LEFT JOIN $tbl_access_rel_user a
|
||||
ON(u.user_id= a.user_id)
|
||||
WHERE
|
||||
status='1' AND
|
||||
active = 1 AND
|
||||
access_url_id = $access_url_id ".
|
||||
$order_clause;
|
||||
} else {
|
||||
$sql = "SELECT user_id,lastname,firstname,username
|
||||
FROM $tbl_user
|
||||
WHERE
|
||||
status = '1' AND
|
||||
active = 1 ".
|
||||
$order_clause;
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$coaches = Database::store_result($result);
|
||||
|
||||
if (!api_is_platform_admin() && api_is_teacher()) {
|
||||
$userInfo = api_get_user_info();
|
||||
$coaches = [$userInfo];
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
$tool_name = get_lang('ModifySessionCourse');
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
$form = new FormValidator(
|
||||
'form',
|
||||
'post',
|
||||
api_get_self().'?id_session='.$id_session.'&course_code='.$course_code.'&page='.Security::remove_XSS($_GET['page'])
|
||||
);
|
||||
|
||||
$options = [];
|
||||
$selected = [];
|
||||
foreach ($coaches as $enreg) {
|
||||
$options[$enreg['user_id']] = api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')';
|
||||
if (in_array($enreg['user_id'], $arr_infos)) {
|
||||
$selected[] = $enreg['user_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$form->addSelect('id_coach', get_lang('CoachName'), $options, ['multiple' => 'multiple']);
|
||||
$form->addHidden('formSent', 1);
|
||||
$form->addButtonSave(get_lang('AssignCoach'));
|
||||
$form->setDefaults(['id_coach' => $selected]);
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
102
main/session/session_course_list.php
Normal file
102
main/session/session_course_list.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
SessionManager::protectSession($id_session);
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
||||
|
||||
if (empty($id_session)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$page = isset($_GET['page']) ? intval($_GET['page']) : 0;
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
|
||||
$sort = isset($_GET['sort']) && in_array($_GET['sort'], ['title', 'nbr_users']) ? $_GET['sort'] : 'title';
|
||||
|
||||
$result = Database::query("SELECT name FROM $tbl_session WHERE id='$id_session'");
|
||||
|
||||
if (!list($session_name) = Database::fetch_row($result)) {
|
||||
header('Location: session_list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'delete') {
|
||||
$idChecked = $_REQUEST['idChecked'];
|
||||
if (is_array($idChecked) && count($idChecked) > 0) {
|
||||
$my_temp = [];
|
||||
foreach ($idChecked as $id) {
|
||||
$my_temp[] = Database::escape_string($id); // forcing the escape_string
|
||||
}
|
||||
$idChecked = $my_temp;
|
||||
$idChecked = "'".implode("','", $idChecked)."'";
|
||||
$result = Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id='$id_session' AND c_id IN($idChecked)");
|
||||
$nbr_affected_rows = Database::affected_rows($result);
|
||||
Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id='$id_session' AND c_id IN($idChecked)");
|
||||
Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
|
||||
}
|
||||
header('Location: '.api_get_self().'?id_session='.$id_session.'&sort='.$sort);
|
||||
exit();
|
||||
}
|
||||
|
||||
$limit = 20;
|
||||
$from = $page * $limit;
|
||||
|
||||
$sql = "SELECT c.id, c.code, c.title, nbr_users
|
||||
FROM $tbl_session_rel_course, $tbl_course c
|
||||
WHERE c_id = c.id AND session_id='$id_session'
|
||||
ORDER BY `$sort`
|
||||
LIMIT $from,".($limit + 1);
|
||||
$result = Database::query($sql);
|
||||
$Courses = Database::store_result($result);
|
||||
$tool_name = api_htmlentities($session_name, ENT_QUOTES, $charset).' : '.get_lang('CourseListInSession');
|
||||
|
||||
$interbreadcrumb[] = ['url' => "session_list.php", "name" => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = ['url' => "resume_session.php?id_session=".Security::remove_XSS($_REQUEST['id_session']), "name" => get_lang('SessionOverview')];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
echo Display::page_header($tool_name);
|
||||
?>
|
||||
<form method="post" action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&sort=<?php echo $sort; ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
|
||||
<?php
|
||||
$tableHeader = [];
|
||||
$tableHeader[] = [' '];
|
||||
$tableHeader[] = [get_lang('CourseTitle')];
|
||||
$tableHeader[] = [get_lang('NbUsers')];
|
||||
$tableHeader[] = [get_lang('Actions')];
|
||||
|
||||
$tableCourses = [];
|
||||
|
||||
foreach ($Courses as $key => $enreg) {
|
||||
$course = [];
|
||||
$course[] = '<input type="checkbox" name="idChecked[]" value="'.$enreg['id'].'">';
|
||||
$course[] = api_htmlentities($enreg['title'], ENT_QUOTES, $charset);
|
||||
$course[] = '<a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$enreg['code'].'">'.$enreg['nbr_users'].' '.get_lang('Users').'</a>';
|
||||
$course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['code'].'/?id_session='.$id_session.'">'.
|
||||
Display::return_icon('course_home.gif', get_lang('Course')).'</a>
|
||||
<a href="session_course_edit.php?id_session='.$id_session.'&page=session_course_list.php&course_code='.$enreg['code'].'">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit')).'</a>
|
||||
<a href="'.api_get_self().'?id_session='.$id_session.'&sort='.$sort.'&action=delete&idChecked[]='.$enreg['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete')).'</a>';
|
||||
$tableCourses[] = $course;
|
||||
}
|
||||
echo '<form method="post" action="'.api_get_self().'">';
|
||||
Display::display_sortable_table($tableHeader, $tableCourses, [], []);
|
||||
echo '<select name="action">
|
||||
<option value="delete">'.get_lang('UnsubscribeCoursesFromSession').'</option>
|
||||
</select>
|
||||
<button class="save" type="submit">'.get_lang('Ok').'</button>
|
||||
</form>';
|
||||
Display::display_footer();
|
||||
138
main/session/session_course_user.php
Normal file
138
main/session/session_course_user.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
use Chamilo\CoreBundle\Entity\Course;
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$tool_name = get_lang('EditSessionCoursesByUser');
|
||||
$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
SessionManager::protectSession($id_session);
|
||||
|
||||
$id_user = intval($_GET['id_user']);
|
||||
|
||||
$em = Database::getManager();
|
||||
/** @var Session $session */
|
||||
$session = $em->find('ChamiloCoreBundle:Session', $id_session);
|
||||
$user = api_get_user_entity($id_user);
|
||||
|
||||
if (!api_is_platform_admin() && $session->getSessionAdminId() != api_get_user_id()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!$session->getCourses()->count()) {
|
||||
Display::addFlash(Display::return_message(get_lang('NoCoursesForThisSession'), 'warning'));
|
||||
header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user);
|
||||
exit;
|
||||
}
|
||||
|
||||
$avoidedCourseIds = SessionManager::getAvoidedCoursesInSession($user, $session);
|
||||
|
||||
$form = new FormValidator(
|
||||
'session_course_user',
|
||||
'post',
|
||||
api_get_self().'?id_user='.$user->getId().'&id_session='.$session->getId()
|
||||
);
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
'courses_to_avoid',
|
||||
$tool_name,
|
||||
getSessionCourseList($session)
|
||||
);
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$values['courses_to_avoid'] = !empty($values['courses_to_avoid']) ? $values['courses_to_avoid'] : [];
|
||||
|
||||
if ($session->getCourses()->count() == count($values['courses_to_avoid'])) {
|
||||
Display::addFlash(Display::return_message(get_lang('MaybeYouWantToDeleteThisUserFromSession')));
|
||||
header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($values['courses_to_avoid'] as $courseId) {
|
||||
/** @var Course $course */
|
||||
$course = $em->find('ChamiloCoreBundle:Course', $courseId);
|
||||
|
||||
if (!$session->getUserInCourse($user, $course)->count()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$session->removeUserCourseSubscription($user, $course);
|
||||
}
|
||||
|
||||
$coursesToResubscribe = array_diff($avoidedCourseIds, $values['courses_to_avoid']);
|
||||
|
||||
foreach ($coursesToResubscribe as $courseId) {
|
||||
/** @var Course $course */
|
||||
$course = $em->find('ChamiloCoreBundle:Course', $courseId);
|
||||
|
||||
if ($session->getUserInCourse($user, $course)->count()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$session->addUserInCourse(Session::STUDENT, $user, $course);
|
||||
}
|
||||
|
||||
$em->persist($session);
|
||||
$em->flush();
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('CoursesUpdated')));
|
||||
header('Location: session_course_user.php?id_session='.$session->getId().'&id_user='.$user->getId());
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults(['courses_to_avoid' => $avoidedCourseIds]);
|
||||
|
||||
/* View */
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'resume_session.php?id_session='.$id_session,
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
echo Display::page_header($session->getName().' - '.UserManager::formatUserFullName($user));
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-8 col-sm-offset-2">
|
||||
<div class="row">
|
||||
<div class="col-sm-5">
|
||||
<label for="courses_to_avoid-f"><?php echo get_lang('CourseListInSession'); ?></label>
|
||||
</div>
|
||||
<div class="col-sm-5 col-sm-offset-2">
|
||||
<label for="courses_to_avoid-t"><?php echo get_lang('CoursesToAvoid'); ?></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
echo $form->returnForm();
|
||||
|
||||
Display::display_footer();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function getSessionCourseList(Session $session)
|
||||
{
|
||||
$return = [];
|
||||
|
||||
foreach ($session->getCourses() as $sessionCourse) {
|
||||
/** @var Course $course */
|
||||
$course = $sessionCourse->getCourse();
|
||||
$return[$course->getId()] = $course->getTitle().' ('.$course->getCode().')';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
208
main/session/session_course_user_list.php
Normal file
208
main/session/session_course_user_list.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
|
||||
SessionManager::protectSession($id_session);
|
||||
|
||||
if (empty($id_session)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$action = $_REQUEST['action'] ?? null;
|
||||
$idChecked = isset($_REQUEST['idChecked']) && is_array($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : [];
|
||||
|
||||
$course_code = Database::escape_string(trim($_GET['course_code']));
|
||||
$courseInfo = api_get_course_info($course_code);
|
||||
$courseId = $courseInfo['real_id'];
|
||||
$apiIsWesternNameOrder = api_is_western_name_order();
|
||||
|
||||
$check = Security::check_token('get');
|
||||
|
||||
if ($check) {
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
foreach ($idChecked as $userId) {
|
||||
SessionManager::unSubscribeUserFromCourseSession((int) $userId, $courseId, $id_session);
|
||||
}
|
||||
header(
|
||||
'Location: '.api_get_self().'?'
|
||||
.http_build_query(['id_session' => $id_session, 'course_code' => $course_code])
|
||||
);
|
||||
exit;
|
||||
case 'add':
|
||||
SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code);
|
||||
header(
|
||||
'Location: '.api_get_self().'?'
|
||||
.http_build_query(['id_session' => $id_session, 'course_code' => $course_code])
|
||||
);
|
||||
exit;
|
||||
}
|
||||
Security::clear_token();
|
||||
}
|
||||
|
||||
$tblSessionRelUser = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tblUser = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tblCourse = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tblSession = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$urlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$tblSessionRelCourseRelUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
||||
$tblSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
|
||||
$sql = "SELECT s.name, c.title
|
||||
FROM $tblSessionRelCourse src
|
||||
INNER JOIN $tblSession s ON s.id = src.session_id
|
||||
INNER JOIN $tblCourse c ON c.id = src.c_id
|
||||
WHERE src.session_id='$id_session' AND src.c_id='$courseId' ";
|
||||
|
||||
$result = Database::query($sql);
|
||||
if (!list($session_name, $course_title) = Database::fetch_row($result)) {
|
||||
header('Location: session_course_list.php?id_session='.$id_session);
|
||||
exit();
|
||||
}
|
||||
|
||||
function get_number_of_users(): int
|
||||
{
|
||||
$tblSessionRelUser = $GLOBALS['tblSessionRelUser'];
|
||||
$tblUser = $GLOBALS['tblUser'];
|
||||
$urlTable = $GLOBALS['urlTable'];
|
||||
$tblSessionRelCourseRelUser = $GLOBALS['tblSessionRelCourseRelUser'];
|
||||
|
||||
$sessionId = (int) $GLOBALS['id_session'];
|
||||
$courseId = (int) $GLOBALS['courseId'];
|
||||
$urlId = api_get_current_access_url_id();
|
||||
|
||||
$sql = "SELECT COUNT(DISTINCT u.user_id) AS nbr
|
||||
FROM $tblSessionRelUser s
|
||||
INNER JOIN $tblUser u ON (u.id = s.user_id)
|
||||
INNER JOIN $urlTable url ON (url.user_id = u.id)
|
||||
LEFT JOIN $tblSessionRelCourseRelUser scru
|
||||
ON (s.session_id = scru.session_id AND s.user_id = scru.user_id AND scru.c_id = $courseId)
|
||||
WHERE
|
||||
s.session_id = $sessionId AND
|
||||
url.access_url_id = $urlId";
|
||||
|
||||
$row = Database::fetch_assoc(Database::query($sql));
|
||||
|
||||
return (int) $row['nbr'];
|
||||
}
|
||||
|
||||
function get_user_list(int $from, int $limit, int $column, string $direction): array
|
||||
{
|
||||
$tblSessionRelUser = $GLOBALS['tblSessionRelUser'];
|
||||
$tblUser = $GLOBALS['tblUser'];
|
||||
$urlTable = $GLOBALS['urlTable'];
|
||||
$tblSessionRelCourseRelUser = $GLOBALS['tblSessionRelCourseRelUser'];
|
||||
$apiIsWesternNameOrder = $GLOBALS['apiIsWesternNameOrder'];
|
||||
|
||||
$sessionId = (int) $GLOBALS['id_session'];
|
||||
$courseId = (int) $GLOBALS['courseId'];
|
||||
$urlId = api_get_current_access_url_id();
|
||||
|
||||
$orderBy = "is_subscribed $direction, u.lastname";
|
||||
|
||||
if ($column == 1) {
|
||||
$orderBy = $apiIsWesternNameOrder ? "u.firstname $direction, u.lastname" : "u.lastname $direction, u.firstname";
|
||||
} elseif ($column == 2) {
|
||||
$orderBy = $apiIsWesternNameOrder ? "u.lastname $direction, u.firstname" : "u.firstname $direction, u.lastname";
|
||||
} elseif (3 == $column) {
|
||||
$orderBy = "u.username $direction";
|
||||
}
|
||||
|
||||
$sql = "SELECT DISTINCT u.user_id,"
|
||||
.($apiIsWesternNameOrder ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname')
|
||||
.", u.username, scru.user_id as is_subscribed
|
||||
FROM $tblSessionRelUser s
|
||||
INNER JOIN $tblUser u
|
||||
ON (u.id = s.user_id)
|
||||
INNER JOIN $urlTable url
|
||||
ON (url.user_id = u.id)
|
||||
LEFT JOIN $tblSessionRelCourseRelUser scru
|
||||
ON (s.session_id = scru.session_id AND s.user_id = scru.user_id AND scru.c_id = $courseId)
|
||||
WHERE
|
||||
s.session_id = $sessionId AND
|
||||
url.access_url_id = $urlId
|
||||
ORDER BY $orderBy
|
||||
LIMIT $from, $limit";
|
||||
|
||||
$result = Database::query($sql);
|
||||
|
||||
return Database::store_result($result);
|
||||
}
|
||||
|
||||
function actions_filter(?int $sessionCourseSubscriptionId, string $urlParams, array $row): string
|
||||
{
|
||||
$params = [
|
||||
'idChecked[]' => $row['user_id'],
|
||||
'action' => 'add',
|
||||
];
|
||||
|
||||
$icon = Display::return_icon('add.png', get_lang('Add'));
|
||||
|
||||
if ($sessionCourseSubscriptionId) {
|
||||
$params['action'] = 'delete';
|
||||
|
||||
$icon = Display::return_icon('delete.png', get_lang('Delete'));
|
||||
}
|
||||
|
||||
return Display::url(
|
||||
$icon,
|
||||
api_get_self().'?'.http_build_query($params)."&$urlParams",
|
||||
[
|
||||
'onclick' => 'javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$table = new SortableTable(
|
||||
'users',
|
||||
'get_number_of_users',
|
||||
'get_user_list'
|
||||
);
|
||||
$table->set_additional_parameters(
|
||||
[
|
||||
'sec_token' => Security::get_token(),
|
||||
'id_session' => $id_session,
|
||||
'course_code' => $course_code,
|
||||
]
|
||||
);
|
||||
$table->set_header(0, ' ', false);
|
||||
|
||||
if ($apiIsWesternNameOrder) {
|
||||
$table->set_header(1, get_lang('FirstName'));
|
||||
$table->set_header(2, get_lang('LastName'));
|
||||
} else {
|
||||
$table->set_header(1, get_lang('LastName'));
|
||||
$table->set_header(2, get_lang('FirstName'));
|
||||
}
|
||||
|
||||
$table->set_header(3, get_lang('LoginName'));
|
||||
$table->set_header(4, get_lang('Action'));
|
||||
$table->set_column_filter(4, 'actions_filter');
|
||||
$table->set_form_actions(
|
||||
[
|
||||
'delete' => get_lang('UnsubscribeSelectedUsersFromSession'),
|
||||
'add' => get_lang('AddUsers'),
|
||||
],
|
||||
'idChecked'
|
||||
);
|
||||
|
||||
$tool_name = get_lang('Session').': '.$session_name.' - '.get_lang('Course').': '.$course_title;
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "resume_session.php?id_session=".$id_session,
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
echo Display::page_header($tool_name);
|
||||
|
||||
$table->display();
|
||||
|
||||
Display::display_footer();
|
||||
252
main/session/session_edit.php
Normal file
252
main/session/session_edit.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Sessions edition script.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$formSent = 0;
|
||||
|
||||
// Crop picture plugin for session images
|
||||
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
|
||||
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
|
||||
$id = (int) $_GET['id'];
|
||||
|
||||
SessionManager::protectSession($id);
|
||||
|
||||
$sessionInfo = SessionManager::fetch($id);
|
||||
|
||||
// Sets to local time to show it correctly when you edit a session
|
||||
if (!empty($sessionInfo['display_start_date'])) {
|
||||
$sessionInfo['display_start_date'] = api_get_local_time($sessionInfo['display_start_date']);
|
||||
}
|
||||
if (!empty($sessionInfo['display_end_date'])) {
|
||||
$sessionInfo['display_end_date'] = api_get_local_time($sessionInfo['display_end_date']);
|
||||
}
|
||||
|
||||
if (!empty($sessionInfo['access_start_date'])) {
|
||||
$sessionInfo['access_start_date'] = api_get_local_time($sessionInfo['access_start_date']);
|
||||
}
|
||||
|
||||
if (!empty($sessionInfo['access_end_date'])) {
|
||||
$sessionInfo['access_end_date'] = api_get_local_time($sessionInfo['access_end_date']);
|
||||
}
|
||||
|
||||
if (!empty($sessionInfo['coach_access_start_date'])) {
|
||||
$sessionInfo['coach_access_start_date'] = api_get_local_time($sessionInfo['coach_access_start_date']);
|
||||
}
|
||||
|
||||
if (!empty($sessionInfo['coach_access_end_date'])) {
|
||||
$sessionInfo['coach_access_end_date'] = api_get_local_time($sessionInfo['coach_access_end_date']);
|
||||
}
|
||||
|
||||
$tool_name = get_lang('EditSession');
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = ['url' => 'resume_session.php?id_session='.$id, 'name' => get_lang('SessionOverview')];
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
$formSent = 1;
|
||||
}
|
||||
|
||||
$order_clause = 'ORDER BY ';
|
||||
$order_clause .= api_sort_by_first_name() ? 'firstname, lastname, username' : 'lastname, firstname, username';
|
||||
|
||||
$sql = "SELECT user_id,lastname,firstname,username
|
||||
FROM $tbl_user
|
||||
WHERE status='1'".$order_clause;
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$table_access_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "SELECT DISTINCT u.user_id,lastname,firstname,username
|
||||
FROM $tbl_user u
|
||||
INNER JOIN $table_access_url_rel_user url_rel_user
|
||||
ON (url_rel_user.user_id = u.user_id)
|
||||
WHERE status='1' AND access_url_id = '$access_url_id' $order_clause";
|
||||
}
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$coaches = Database::store_result($result);
|
||||
$thisYear = date('Y');
|
||||
|
||||
$coachesOption = [
|
||||
'' => '----- '.get_lang('None').' -----',
|
||||
];
|
||||
|
||||
foreach ($coaches as $coach) {
|
||||
$personName = api_get_person_name($coach['firstname'], $coach['lastname']);
|
||||
$coachesOption[$coach['user_id']] = "$personName ({$coach['username']})";
|
||||
}
|
||||
|
||||
$categoriesList = SessionManager::get_all_session_category();
|
||||
|
||||
$categoriesOption = [
|
||||
'0' => get_lang('None'),
|
||||
];
|
||||
|
||||
if ($categoriesList != false) {
|
||||
foreach ($categoriesList as $categoryItem) {
|
||||
$categoriesOption[$categoryItem['id']] = $categoryItem['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$formAction = api_get_self().'?';
|
||||
$formAction .= http_build_query([
|
||||
'page' => Security::remove_XSS($_GET['page']),
|
||||
'id' => $id,
|
||||
]);
|
||||
|
||||
$form = new FormValidator('edit_session', 'post', $formAction);
|
||||
$form->addElement('header', $tool_name);
|
||||
$result = SessionManager::setForm($form, $sessionInfo);
|
||||
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
$(function() {
|
||||
'.$result['js'].'
|
||||
});
|
||||
</script>';
|
||||
|
||||
$form->addButtonUpdate(get_lang('ModifyThisSession'));
|
||||
|
||||
$formDefaults = $sessionInfo;
|
||||
|
||||
$formDefaults['coach_username'] = $sessionInfo['id_coach'];
|
||||
$formDefaults['session_category'] = $sessionInfo['session_category_id'];
|
||||
$formDefaults['session_visibility'] = $sessionInfo['visibility'];
|
||||
|
||||
if ($formSent) {
|
||||
$formDefaults['name'] = api_htmlentities($name, ENT_QUOTES, $charset);
|
||||
} else {
|
||||
$formDefaults['name'] = Security::remove_XSS($sessionInfo['name']);
|
||||
}
|
||||
|
||||
$form->setDefaults($formDefaults);
|
||||
|
||||
if ($form->validate()) {
|
||||
$params = $form->getSubmitValues();
|
||||
|
||||
$name = $params['name'];
|
||||
$startDate = $params['access_start_date'];
|
||||
$endDate = $params['access_end_date'];
|
||||
$displayStartDate = $params['display_start_date'];
|
||||
$displayEndDate = $params['display_end_date'];
|
||||
$coachStartDate = $params['coach_access_start_date'];
|
||||
$coachEndDate = $params['coach_access_end_date'];
|
||||
$coach_username = intval($params['coach_username']);
|
||||
$id_session_category = $params['session_category'];
|
||||
$id_visibility = $params['session_visibility'];
|
||||
$duration = isset($params['duration']) ? $params['duration'] : null;
|
||||
if ($params['access'] == 1) {
|
||||
$duration = null;
|
||||
}
|
||||
|
||||
$description = $params['description'];
|
||||
$showDescription = isset($params['show_description']) ? 1 : 0;
|
||||
$sendSubscriptionNotification = isset($params['send_subscription_notification']);
|
||||
$isThisImageCropped = isset($params['picture_crop_result']);
|
||||
|
||||
$extraFields = [];
|
||||
foreach ($params as $key => $value) {
|
||||
if (strpos($key, 'extra_') === 0) {
|
||||
$extraFields[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($extraFields['extra_image']) && $isThisImageCropped) {
|
||||
$extraFields['extra_image']['crop_parameters'] = $params['picture_crop_result'];
|
||||
}
|
||||
|
||||
$status = isset($params['status']) ? $params['status'] : 0;
|
||||
|
||||
$return = SessionManager::edit_session(
|
||||
$id,
|
||||
$name,
|
||||
$startDate,
|
||||
$endDate,
|
||||
$displayStartDate,
|
||||
$displayEndDate,
|
||||
$coachStartDate,
|
||||
$coachEndDate,
|
||||
$coach_username,
|
||||
$id_session_category,
|
||||
$id_visibility,
|
||||
$description,
|
||||
$showDescription,
|
||||
$duration,
|
||||
$extraFields,
|
||||
null,
|
||||
$sendSubscriptionNotification,
|
||||
$status
|
||||
);
|
||||
|
||||
if ($return) {
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: resume_session.php?id_session='.$return);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// display the header
|
||||
Display::display_header($tool_name);
|
||||
$form->display();
|
||||
?>
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
<?php
|
||||
if (!empty($sessionInfo['duration'])) {
|
||||
echo 'accessSwitcher(0);';
|
||||
} else {
|
||||
echo 'accessSwitcher(1);';
|
||||
}
|
||||
?>
|
||||
});
|
||||
|
||||
function accessSwitcher(accessFromReady) {
|
||||
var access = $('#access option:selected').val();
|
||||
|
||||
if (accessFromReady >= 0) {
|
||||
access = accessFromReady;
|
||||
$('[name=access]').val(access);
|
||||
}
|
||||
if (access == 1) {
|
||||
$('#duration_div').hide();
|
||||
$('#date_fields').show();
|
||||
emptyDuration();
|
||||
} else {
|
||||
$('#duration_div').show();
|
||||
$('#date_fields').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function emptyDuration() {
|
||||
if ($('#duration').val()) {
|
||||
$('#duration').val('');
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$('#show-options').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var display = $('#options').css('display');
|
||||
display === 'block' ? $('#options').slideUp() : $('#options').slideDown() ;
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
398
main/session/session_export.php
Normal file
398
main/session/session_export.php
Normal file
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$session_id = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
|
||||
|
||||
$formSent = 0;
|
||||
$errorMsg = '';
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
||||
|
||||
$archivePath = api_get_path(SYS_ARCHIVE_PATH);
|
||||
$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive=';
|
||||
|
||||
$tool_name = get_lang('ExportSessionListXMLCSV');
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
set_time_limit(0);
|
||||
if (isset($_POST['formSent'])) {
|
||||
$formSent = $_POST['formSent'];
|
||||
$file_type = $_POST['file_type'] ?? 'csv';
|
||||
$session_id = $_POST['session_id'];
|
||||
$includeUsers = !isset($_POST['no_include_users']);
|
||||
$includeCourseExtraFields = isset($_POST['include_course_fields']);
|
||||
|
||||
if (empty($session_id)) {
|
||||
$sql = "SELECT
|
||||
s.id,
|
||||
name,
|
||||
id_coach,
|
||||
username,
|
||||
access_start_date,
|
||||
access_end_date,
|
||||
visibility,
|
||||
session_category_id
|
||||
FROM $tbl_session s
|
||||
INNER JOIN $tbl_user
|
||||
ON $tbl_user.user_id = s.id_coach
|
||||
ORDER BY id";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "SELECT s.id, name,id_coach,username,access_start_date,access_end_date,visibility,session_category_id
|
||||
FROM $tbl_session s
|
||||
INNER JOIN $tbl_session_rel_access_url as session_rel_url
|
||||
ON (s.id= session_rel_url.session_id)
|
||||
INNER JOIN $tbl_user u ON (u.user_id = s.id_coach)
|
||||
WHERE access_url_id = $access_url_id
|
||||
ORDER BY id";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sql = "SELECT s.id,name,username,access_start_date,access_end_date,visibility,session_category_id
|
||||
FROM $tbl_session s
|
||||
INNER JOIN $tbl_user
|
||||
ON $tbl_user.user_id = s.id_coach
|
||||
WHERE s.id='$session_id'";
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
$extraVariables = [];
|
||||
if (Database::num_rows($result)) {
|
||||
$sessionListToExport = [];
|
||||
if (in_array($file_type, ['csv', 'xls'])) {
|
||||
$archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time();
|
||||
$cvs = true;
|
||||
$exportHeaders = [
|
||||
'SessionId',
|
||||
'SessionName',
|
||||
'Coach',
|
||||
'DateStart',
|
||||
'DateEnd',
|
||||
'Visibility',
|
||||
'SessionCategory',
|
||||
];
|
||||
|
||||
$extraField = new ExtraField('session');
|
||||
$allExtraFields = $extraField->get_all();
|
||||
foreach ($allExtraFields as $extra) {
|
||||
$exportHeaders[] = $extra['display_text'];
|
||||
$extraVariables[] = $extra['variable'];
|
||||
}
|
||||
|
||||
if ($includeUsers) {
|
||||
$exportHeaders[] = 'Users';
|
||||
}
|
||||
|
||||
$exportHeaders[] = 'Courses';
|
||||
|
||||
$sessionListToExport[] = $exportHeaders;
|
||||
} else {
|
||||
if (!file_exists($archivePath)) {
|
||||
mkdir($archivePath, api_get_permissions_for_new_directories(), true);
|
||||
}
|
||||
|
||||
if (!file_exists($archivePath.'index.html')) {
|
||||
$fp = fopen($archivePath.'index.html', 'w');
|
||||
fputs($fp, '<html><head></head><body></body></html>');
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
$archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time().'.'.$file_type;
|
||||
while (file_exists($archivePath.$archiveFile)) {
|
||||
$archiveFile = 'export_users_'.$session_id.'_'.api_get_local_time().'_'.uniqid('').'.'.$file_type;
|
||||
}
|
||||
|
||||
$cvs = false;
|
||||
$fp = fopen($archivePath.$archiveFile, 'w');
|
||||
fputs($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Sessions>\n");
|
||||
}
|
||||
|
||||
$extraFieldValueSession = new ExtraFieldValue('session');
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
$row['name'] = str_replace(';', ',', $row['name']);
|
||||
$row['username'] = str_replace(';', ',', $row['username']);
|
||||
$row['access_start_date'] = str_replace(';', ',', $row['access_start_date']);
|
||||
$row['access_end_date'] = str_replace(';', ',', $row['access_end_date']);
|
||||
$row['visibility'] = str_replace(';', ',', $row['visibility']);
|
||||
$row['session_category'] = str_replace(';', ',', $row['session_category_id']);
|
||||
// users
|
||||
$users = '';
|
||||
|
||||
if ($includeUsers) {
|
||||
$sql = "SELECT DISTINCT $tbl_user.username
|
||||
FROM $tbl_user
|
||||
INNER JOIN $tbl_session_user
|
||||
ON
|
||||
$tbl_user.user_id = $tbl_session_user.user_id AND
|
||||
$tbl_session_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
|
||||
$tbl_session_user.session_id = '".$row['id']."'";
|
||||
|
||||
$rsUsers = Database::query($sql);
|
||||
|
||||
while ($rowUsers = Database::fetch_array($rsUsers)) {
|
||||
if ($cvs) {
|
||||
$users .= str_replace(';', ',', $rowUsers['username']).'|';
|
||||
} else {
|
||||
$users .= "\t\t<User>$rowUsers[username]</User>\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($users) && $cvs) {
|
||||
$users = api_substr($users, 0, api_strlen($users) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Courses
|
||||
$sql = "SELECT DISTINCT c.code, sc.c_id, sr.position
|
||||
FROM $tbl_course c
|
||||
INNER JOIN $tbl_session_course_user sc
|
||||
ON c.id = sc.c_id AND sc.session_id = '".$row['id']."'
|
||||
INNER JOIN $tbl_session_course sr
|
||||
ON sc.session_id = sr.session_id AND sc.c_id = sr.c_id
|
||||
ORDER BY sr.position ASC";
|
||||
|
||||
$rsCourses = Database::query($sql);
|
||||
|
||||
$courses = '';
|
||||
while ($rowCourses = Database::fetch_array($rsCourses)) {
|
||||
// get coachs from a course
|
||||
$sql = "SELECT u.username
|
||||
FROM $tbl_session_course_user scu
|
||||
INNER JOIN $tbl_user u
|
||||
ON u.user_id = scu.user_id
|
||||
WHERE
|
||||
scu.c_id = '{$rowCourses['c_id']}' AND
|
||||
scu.session_id = '".$row['id']."' AND
|
||||
scu.status = 2 ";
|
||||
|
||||
$rs_coachs = Database::query($sql);
|
||||
$coachs = [];
|
||||
while ($row_coachs = Database::fetch_array($rs_coachs)) {
|
||||
$coachs[] = $row_coachs['username'];
|
||||
}
|
||||
|
||||
$coachs = implode(",", $coachs);
|
||||
|
||||
if ($cvs) {
|
||||
$courses .= str_replace(';', ',', $rowCourses['code']);
|
||||
$courses .= '['.str_replace(';', ',', $coachs).']';
|
||||
|
||||
if ($includeUsers) {
|
||||
$courses .= '[';
|
||||
}
|
||||
} else {
|
||||
$courses .= "\t\t<Course>\n";
|
||||
$courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n";
|
||||
$courses .= "\t\t\t<Coach>$coachs</Coach>\n";
|
||||
}
|
||||
|
||||
$userscourse = '';
|
||||
|
||||
if ($includeUsers) {
|
||||
// rel user courses
|
||||
$sql = "SELECT DISTINCT u.username
|
||||
FROM $tbl_session_course_user scu
|
||||
INNER JOIN $tbl_session_user su
|
||||
ON
|
||||
scu.user_id = su.user_id AND
|
||||
scu.session_id = su.session_id AND
|
||||
su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
|
||||
INNER JOIN $tbl_user u
|
||||
ON
|
||||
scu.user_id = u.user_id AND
|
||||
scu.c_id='".$rowCourses['c_id']."' AND
|
||||
scu.session_id='".$row['id']."'";
|
||||
|
||||
$rsUsersCourse = Database::query($sql);
|
||||
while ($rowUsersCourse = Database::fetch_array($rsUsersCourse)) {
|
||||
if ($cvs) {
|
||||
$userscourse .= str_replace(';', ',', $rowUsersCourse['username']).',';
|
||||
} else {
|
||||
$courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($cvs) {
|
||||
if (!empty($userscourse)) {
|
||||
$userscourse = api_substr(
|
||||
$userscourse,
|
||||
0,
|
||||
api_strlen($userscourse) - 1
|
||||
);
|
||||
}
|
||||
|
||||
$courses .= $userscourse.']';
|
||||
}
|
||||
}
|
||||
|
||||
if ($includeCourseExtraFields) {
|
||||
$extraData = CourseManager::getExtraData($rowCourses['c_id'], ['special_course']);
|
||||
$extraData = array_map(
|
||||
function ($variable, $value) use ($cvs) {
|
||||
$value = str_replace(';', ',', $value);
|
||||
|
||||
return $cvs
|
||||
? '{'.$variable.'='.$value.'}'
|
||||
: "<Variable>$variable</Variable><Value>$value</Value>";
|
||||
},
|
||||
array_keys($extraData),
|
||||
array_values($extraData)
|
||||
);
|
||||
|
||||
$courses .= $cvs
|
||||
? '['.implode('', $extraData).']'
|
||||
: "\t\t\t<ExtraField>".implode("\n", $extraData)."</ExtraField>\n";
|
||||
}
|
||||
|
||||
if ($cvs) {
|
||||
$courses .= '|';
|
||||
} else {
|
||||
$courses .= "\t\t</Course>\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($courses) && $cvs) {
|
||||
$courses = api_substr($courses, 0, api_strlen($courses) - 1);
|
||||
}
|
||||
|
||||
if (in_array($file_type, ['csv', 'xls'])) {
|
||||
$exportContent = [
|
||||
$row['id'],
|
||||
$row['name'],
|
||||
$row['username'],
|
||||
$row['access_start_date'],
|
||||
$row['access_end_date'],
|
||||
$row['visibility'],
|
||||
$row['session_category'],
|
||||
];
|
||||
|
||||
if (!empty($extraVariables)) {
|
||||
foreach ($extraVariables as $variable) {
|
||||
$extraData = $extraFieldValueSession->get_values_by_handler_and_field_variable(
|
||||
$row['id'],
|
||||
$variable
|
||||
);
|
||||
$exportContent[] = !empty($extraData['value']) ? $extraData['value'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($includeUsers) {
|
||||
$exportContent[] = $users;
|
||||
}
|
||||
|
||||
$exportContent[] = $courses;
|
||||
$sessionListToExport[] = $exportContent;
|
||||
} else {
|
||||
$add = "\t<Session>\n"
|
||||
."\t\t<SessionId>$row[id]</SessionId>\n"
|
||||
."\t\t<SessionName>$row[name]</SessionName>\n"
|
||||
."\t\t<Coach>$row[username]</Coach>\n"
|
||||
."\t\t<DateStart>$row[access_start_date]</DateStart>\n"
|
||||
."\t\t<DateEnd>$row[access_end_date]</DateEnd>\n"
|
||||
."\t\t<Visibility>$row[visibility]</Visibility>\n"
|
||||
."\t\t<SessionCategory>$row[session_category]</SessionCategory>\n";
|
||||
|
||||
if ($includeUsers) {
|
||||
$add .= $courses;
|
||||
}
|
||||
|
||||
$add .= "\t</Session>\n";
|
||||
|
||||
fputs($fp, $add);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($file_type) {
|
||||
case 'xml':
|
||||
fputs($fp, "</Sessions>\n");
|
||||
fclose($fp);
|
||||
$errorMsg = get_lang('UserListHasBeenExported').'<br/>
|
||||
<a class="btn btn-default" href="'.$archiveURL.$archiveFile.'">'.get_lang('ClickHereToDownloadTheFile').'</a>';
|
||||
break;
|
||||
case 'csv':
|
||||
Export::arrayToCsv($sessionListToExport, $archiveFile);
|
||||
exit;
|
||||
case 'xls':
|
||||
Export::arrayToXls($sessionListToExport, $archiveFile);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
//select of sessions
|
||||
$sql = "SELECT id, name FROM $tbl_session ORDER BY name";
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$sql = "SELECT s.id, name FROM $tbl_session s
|
||||
INNER JOIN $tbl_session_rel_access_url as session_rel_url
|
||||
ON (s.id = session_rel_url.session_id)
|
||||
WHERE access_url_id = $access_url_id
|
||||
ORDER BY name";
|
||||
}
|
||||
}
|
||||
$result = Database::query($sql);
|
||||
$Sessions = Database::store_result($result);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="../session/session_list.php">'.
|
||||
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('SessionList'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'normal', false); //main API
|
||||
}
|
||||
|
||||
$form = new FormValidator('session_export', 'post', api_get_self());
|
||||
$form->addElement('hidden', 'formSent', 1);
|
||||
$form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV', 'csv', null);
|
||||
$form->addElement('radio', 'file_type', '', 'XLS', 'xls', null);
|
||||
$form->addElement('radio', 'file_type', null, 'XML', 'xml', null, ['id' => 'file_type_xml']);
|
||||
|
||||
$options = [];
|
||||
$options['0'] = get_lang('AllSessions');
|
||||
foreach ($Sessions as $enreg) {
|
||||
$options[$enreg['id']] = $enreg['name'];
|
||||
}
|
||||
|
||||
$form->addElement('select', 'session_id', get_lang('WhichSessionToExport'), $options);
|
||||
$form->addCheckBox(
|
||||
'no_include_users',
|
||||
[
|
||||
get_lang('Users'),
|
||||
get_lang('ReportDoesNotIncludeListOfUsersNeitherForSessionNorForEachCourse'),
|
||||
],
|
||||
get_lang('DoNotIncludeUsers')
|
||||
);
|
||||
$form->addCheckBox('include_course_fields', get_lang('Courses'), get_lang('IncludeExtraFields'));
|
||||
$form->addButtonExport(get_lang('ExportSession'));
|
||||
|
||||
$defaults = [];
|
||||
$defaults['file_type'] = 'csv';
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
unset($courses);
|
||||
Display::display_footer();
|
||||
622
main/session/session_import.php
Normal file
622
main/session/session_import.php
Normal file
@@ -0,0 +1,622 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script(true);
|
||||
api_protect_limit_for_session_admin();
|
||||
|
||||
$form_sent = 0;
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
||||
|
||||
$tool_name = get_lang('ImportSessionListXMLCSV');
|
||||
|
||||
//$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
// Set this option to true to enforce strict purification for usenames.
|
||||
$purification_option_for_usernames = false;
|
||||
$inserted_in_course = [];
|
||||
|
||||
$error_message = '';
|
||||
|
||||
$warn = null;
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
if (!empty($_FILES['import_file']['tmp_name'])
|
||||
) {
|
||||
$form_sent = $_POST['formSent'];
|
||||
$file_type = $_POST['file_type'] ?? null;
|
||||
$send_mail = isset($_POST['sendMail']) && $_POST['sendMail'] ? 1 : 0;
|
||||
$isOverwrite = isset($_POST['overwrite']) && $_POST['overwrite'];
|
||||
$deleteUsersNotInList = isset($_POST['delete_users_not_in_list']);
|
||||
$sessions = [];
|
||||
$session_counter = 0;
|
||||
|
||||
if ($file_type == 'xml') {
|
||||
// XML
|
||||
// SimpleXML for PHP5 deals with various encodings, but how many they are, what are version issues, do we need to waste time with configuration options?
|
||||
// For avoiding complications we go some sort of "PHP4 way" - we convert the input xml-file into UTF-8 before passing it to the parser.
|
||||
// Instead of:
|
||||
// $root = @simplexml_load_file($_FILES['import_file']['tmp_name']);
|
||||
// we may use the following construct:
|
||||
// $root = @simplexml_load_string(api_utf8_encode_xml(file_get_contents($_FILES['import_file']['tmp_name'])));
|
||||
// To ease debugging let us use:
|
||||
$content = file_get_contents($_FILES['import_file']['tmp_name']);
|
||||
|
||||
$content = api_utf8_encode_xml($content);
|
||||
$root = @simplexml_load_string($content);
|
||||
unset($content);
|
||||
|
||||
if (is_object($root)) {
|
||||
if (count($root->Users->User) > 0) {
|
||||
// Creating/updating users from <Sessions> <Users> base node.
|
||||
foreach ($root->Users->User as $node_user) {
|
||||
$username = $username_old = trim(api_utf8_decode($node_user->Username));
|
||||
if (UserManager::is_username_available($username)) {
|
||||
$password = api_utf8_decode($node_user->Password);
|
||||
if (empty($password)) {
|
||||
$password = api_generate_password();
|
||||
}
|
||||
switch ($node_user->Status) {
|
||||
case 'student':
|
||||
$status = 5;
|
||||
break;
|
||||
case 'teacher':
|
||||
$status = 1;
|
||||
break;
|
||||
default:
|
||||
$status = 5;
|
||||
$error_message .= get_lang('StudentStatusWasGivenTo').' : '.$username.'<br />';
|
||||
}
|
||||
|
||||
$result = UserManager::create_user(
|
||||
api_utf8_decode($node_user->Firstname),
|
||||
api_utf8_decode($node_user->Lastname),
|
||||
$status,
|
||||
api_utf8_decode($node_user->Email),
|
||||
$username,
|
||||
$password,
|
||||
api_utf8_decode($node_user->OfficialCode),
|
||||
null,
|
||||
api_utf8_decode($node_user->Phone),
|
||||
null,
|
||||
PLATFORM_AUTH_SOURCE,
|
||||
null,
|
||||
1,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
$send_mail
|
||||
);
|
||||
} else {
|
||||
$lastname = trim(api_utf8_decode($node_user->Lastname));
|
||||
$firstname = trim(api_utf8_decode($node_user->Firstname));
|
||||
$password = api_utf8_decode($node_user->Password);
|
||||
$email = trim(api_utf8_decode($node_user->Email));
|
||||
$official_code = trim(api_utf8_decode($node_user->OfficialCode));
|
||||
$phone = trim(api_utf8_decode($node_user->Phone));
|
||||
$status = trim(api_utf8_decode($node_user->Status));
|
||||
switch ($status) {
|
||||
case 'student':
|
||||
$status = 5;
|
||||
break;
|
||||
case 'teacher':
|
||||
$status = 1;
|
||||
break;
|
||||
default:
|
||||
$status = 5;
|
||||
$error_message .= get_lang('StudentStatusWasGivenTo').' : '.$username.'<br />';
|
||||
}
|
||||
|
||||
$userId = UserManager::get_user_id_from_username($username);
|
||||
|
||||
if (!empty($userId)) {
|
||||
UserManager::update_user(
|
||||
$userId,
|
||||
$firstname,
|
||||
$lastname,
|
||||
$username,
|
||||
$password,
|
||||
null,
|
||||
$email,
|
||||
$status,
|
||||
$official_code,
|
||||
$phone,
|
||||
null, //$picture_uri,
|
||||
null, //$expiration_date,
|
||||
null, //$active,
|
||||
null, //$creator_id = null,
|
||||
0,
|
||||
null, //$extra = null,
|
||||
null, //$language = 'english',
|
||||
null, //$encrypt_method = '',
|
||||
false,
|
||||
0 //$reset_password = 0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Creating courses from <Sessions> <Courses> base node.
|
||||
if (count($root->Courses->Course) > 0) {
|
||||
foreach ($root->Courses->Course as $courseNode) {
|
||||
$params = [];
|
||||
if (empty($courseNode->CourseTitle)) {
|
||||
$params['title'] = api_utf8_decode($courseNode->CourseCode);
|
||||
} else {
|
||||
$params['title'] = api_utf8_decode($courseNode->CourseTitle);
|
||||
}
|
||||
$params['wanted_code'] = api_utf8_decode($courseNode->CourseCode);
|
||||
$params['tutor_name'] = null;
|
||||
$params['course_category'] = null;
|
||||
$params['course_language'] = api_utf8_decode($courseNode->CourseLanguage);
|
||||
$params['user_id'] = api_get_user_id();
|
||||
|
||||
// Looking up for the teacher.
|
||||
$username = trim(api_utf8_decode($courseNode->CourseTeacher));
|
||||
$rs = Database::select(
|
||||
['user_id', 'lastname', 'firstname'],
|
||||
$tbl_user,
|
||||
['where' => ['username = ?' => $username]],
|
||||
'first',
|
||||
'NUM'
|
||||
);
|
||||
list($user_id, $lastname, $firstname) = $rs;
|
||||
|
||||
$params['teachers'] = $user_id;
|
||||
CourseManager::create_course($params);
|
||||
}
|
||||
}
|
||||
|
||||
// Creating sessions from <Sessions> base node.
|
||||
if (count($root->Session) > 0) {
|
||||
foreach ($root->Session as $node_session) {
|
||||
$course_counter = 0;
|
||||
$user_counter = 0;
|
||||
$session_name = trim(trim(api_utf8_decode($node_session->SessionName), '"'));
|
||||
$coach = UserManager::purify_username(
|
||||
api_utf8_decode($node_session->Coach),
|
||||
$purification_option_for_usernames
|
||||
);
|
||||
|
||||
if (!empty($coach)) {
|
||||
$coach_id = UserManager::get_user_id_from_username($coach);
|
||||
if ($coach_id === false) {
|
||||
$error_message .= get_lang('UserDoesNotExist').' : '.$coach.'<br />';
|
||||
// Forcing the coach id if user does not exist.
|
||||
$coach_id = api_get_user_id();
|
||||
}
|
||||
} else {
|
||||
// Forcing the coach id.
|
||||
$coach_id = api_get_user_id();
|
||||
}
|
||||
|
||||
// Just in case - encoding conversion.
|
||||
$date_start = trim(api_utf8_decode($node_session->DateStart));
|
||||
|
||||
if (!empty($date_start)) {
|
||||
list($year_start, $month_start, $day_start) = explode('/', $date_start);
|
||||
if (empty($year_start) || empty($month_start) || empty($day_start)) {
|
||||
$error_message .= get_lang('WrongDate').' : '.$date_start.'<br />';
|
||||
break;
|
||||
} else {
|
||||
$time_start = mktime(0, 0, 0, $month_start, $day_start, $year_start);
|
||||
}
|
||||
|
||||
$date_end = trim(api_utf8_decode($node_session->DateEnd));
|
||||
if (!empty($date_start)) {
|
||||
list($year_end, $month_end, $day_end) = explode('/', $date_end);
|
||||
if (empty($year_end) || empty($month_end) || empty($day_end)) {
|
||||
$error_message .= get_lang('Error').' : '.$date_end.'<br />';
|
||||
break;
|
||||
} else {
|
||||
$time_end = mktime(0, 0, 0, $month_end, $day_end, $year_end);
|
||||
}
|
||||
}
|
||||
if ($time_end - $time_start < 0) {
|
||||
$error_message .= get_lang('StartDateShouldBeBeforeEndDate').' : '.$date_end.'<br />';
|
||||
}
|
||||
}
|
||||
|
||||
// Default visibility
|
||||
$visibilityAfterExpirationPerSession = SESSION_VISIBLE_READ_ONLY;
|
||||
|
||||
if (isset($node_session->VisibilityAfterExpiration)) {
|
||||
$visibility = trim(api_utf8_decode($node_session->VisibilityAfterExpiration));
|
||||
switch ($visibility) {
|
||||
case 'accessible':
|
||||
$visibilityAfterExpirationPerSession = SESSION_VISIBLE;
|
||||
break;
|
||||
case 'not_accessible':
|
||||
$visibilityAfterExpirationPerSession = SESSION_INVISIBLE;
|
||||
break;
|
||||
case 'read_only':
|
||||
default:
|
||||
$visibilityAfterExpirationPerSession = SESSION_VISIBLE_READ_ONLY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$session_category_id = (int) trim(api_utf8_decode($node_session->SessionCategory));
|
||||
|
||||
if (!$isOverwrite) {
|
||||
// Always create a session.
|
||||
$unique_name = false; // This MUST be initializead.
|
||||
$i = 0;
|
||||
// Change session name, verify that session doesn't exist.
|
||||
while (!$unique_name) {
|
||||
if ($i > 1) {
|
||||
$suffix = ' - '.$i;
|
||||
}
|
||||
$sql = 'SELECT id FROM '.$tbl_session.'
|
||||
WHERE name="'.Database::escape_string($session_name.$suffix).'"';
|
||||
$rs = Database::query($sql);
|
||||
if (Database::result($rs, 0, 0)) {
|
||||
$i++;
|
||||
} else {
|
||||
$unique_name = true;
|
||||
$session_name .= $suffix;
|
||||
}
|
||||
}
|
||||
|
||||
// Creating the session.
|
||||
$sql_session = "INSERT INTO $tbl_session SET
|
||||
name = '".Database::escape_string($session_name)."',
|
||||
id_coach = '$coach_id',
|
||||
access_start_date = '$date_start',
|
||||
access_end_date = '$date_end',
|
||||
visibility = '$visibilityAfterExpirationPerSession',
|
||||
".(!empty($session_category_id) ? "session_category_id = '{$session_category_id}'," : "")."
|
||||
session_admin_id=".api_get_user_id();
|
||||
|
||||
$rs_session = Database::query($sql_session);
|
||||
$session_id = Database::insert_id();
|
||||
$session_counter++;
|
||||
} else {
|
||||
// Update the session if it is needed.
|
||||
$my_session_result = SessionManager::get_session_by_name($session_name);
|
||||
if ($my_session_result === false) {
|
||||
// Creating the session.
|
||||
$sql_session = "INSERT INTO $tbl_session SET
|
||||
name = '".Database::escape_string($session_name)."',
|
||||
id_coach = '$coach_id',
|
||||
access_start_date = '$date_start',
|
||||
access_end_date = '$date_end',
|
||||
visibility = '$visibilityAfterExpirationPerSession',
|
||||
".(!empty($session_category_id) ? "session_category_id = '{$session_category_id}'," : "")."
|
||||
session_admin_id=".api_get_user_id();
|
||||
$rs_session = Database::query($sql_session);
|
||||
$session_id = Database::insert_id();
|
||||
$session_counter++;
|
||||
} else {
|
||||
// if the session already exists - update it.
|
||||
$sql_session = "UPDATE $tbl_session SET
|
||||
id_coach = '$coach_id',
|
||||
access_start_date = '$date_start',
|
||||
access_end_date = '$date_end',
|
||||
visibility = '$visibilityAfterExpirationPerSession',
|
||||
session_category_id = '$session_category_id'
|
||||
WHERE name = '$session_name'";
|
||||
$rs_session = Database::query($sql_session);
|
||||
$session_id = Database::query("SELECT id FROM $tbl_session WHERE name='$session_name'");
|
||||
list($session_id) = Database::fetch_array($session_id);
|
||||
Database::query("DELETE FROM $tbl_session_user WHERE session_id ='$session_id'");
|
||||
Database::query("DELETE FROM $tbl_session_course WHERE session_id='$session_id'");
|
||||
Database::query("DELETE FROM $tbl_session_course_user WHERE session_id='$session_id'");
|
||||
}
|
||||
}
|
||||
|
||||
// Associate the session with access_url.
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
UrlManager::add_session_to_url($session_id, $access_url_id);
|
||||
} else {
|
||||
// We fill by default the access_url_rel_session table.
|
||||
UrlManager::add_session_to_url($session_id, 1);
|
||||
}
|
||||
|
||||
// Adding users to the new session.
|
||||
foreach ($node_session->User as $node_user) {
|
||||
$username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames);
|
||||
$user_id = UserManager::get_user_id_from_username($username);
|
||||
if ($user_id !== false) {
|
||||
$sql = "INSERT IGNORE INTO $tbl_session_user SET
|
||||
user_id ='$user_id',
|
||||
session_id = '$session_id',
|
||||
registered_at = '".api_get_utc_datetime()."'";
|
||||
$rs_user = Database::query($sql);
|
||||
$user_counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Adding courses to a session.
|
||||
$position = 0;
|
||||
foreach ($node_session->Course as $node_course) {
|
||||
$course_code = Database::escape_string(trim(api_utf8_decode($node_course->CourseCode)));
|
||||
// Verify that the course pointed by the course code node exists.
|
||||
if (CourseManager::course_exists($course_code)) {
|
||||
// If the course exists we continue.
|
||||
$course_info = CourseManager::get_course_information($course_code);
|
||||
$courseId = $course_info['real_id'];
|
||||
|
||||
$session_course_relation = SessionManager::relation_session_course_exist($session_id, $courseId);
|
||||
if (!$session_course_relation) {
|
||||
$sql_course = "INSERT INTO $tbl_session_course SET
|
||||
c_id = $courseId,
|
||||
session_id = $session_id,
|
||||
position = $position";
|
||||
$rs_course = Database::query($sql_course);
|
||||
SessionManager::installCourse($session_id, $courseId);
|
||||
}
|
||||
|
||||
$course_coaches = explode(',', $node_course->Coach);
|
||||
|
||||
// Adding coachs to session course user
|
||||
foreach ($course_coaches as $course_coach) {
|
||||
$coach_id = UserManager::purify_username(api_utf8_decode($course_coach), $purification_option_for_usernames);
|
||||
$coach_id = UserManager::get_user_id_from_username($course_coach);
|
||||
if ($coach_id !== false) {
|
||||
$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
|
||||
user_id = '$coach_id',
|
||||
c_id = '$courseId',
|
||||
session_id = '$session_id',
|
||||
status = 2 ";
|
||||
$rs_coachs = Database::query($sql);
|
||||
} else {
|
||||
$error_message .= get_lang('UserDoesNotExist').' : '.$course_coach.'<br />';
|
||||
}
|
||||
}
|
||||
|
||||
// Adding users.
|
||||
$course_counter++;
|
||||
$users_in_course_counter = 0;
|
||||
foreach ($node_course->User as $node_user) {
|
||||
$username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames);
|
||||
$user_id = UserManager::get_user_id_from_username($username);
|
||||
if ($user_id !== false) {
|
||||
// Adding to session_rel_user table.
|
||||
$sql = "INSERT IGNORE INTO $tbl_session_user SET
|
||||
user_id ='$user_id',
|
||||
session_id = '$session_id',
|
||||
registered_at = '".api_get_utc_datetime()."'";
|
||||
$rs_user = Database::query($sql);
|
||||
$user_counter++;
|
||||
// Adding to session_rel_user_rel_course table.
|
||||
$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
|
||||
user_id = '$user_id',
|
||||
c_id = '$courseId',
|
||||
session_id = '$session_id'";
|
||||
$rs_users = Database::query($sql);
|
||||
$users_in_course_counter++;
|
||||
} else {
|
||||
$error_message .= get_lang('UserDoesNotExist').' : '.$username.'<br />';
|
||||
}
|
||||
}
|
||||
$sql = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE c_id='$courseId'";
|
||||
Database::query($sql);
|
||||
$inserted_in_course[$course_code] = $course_info['title'];
|
||||
$position++;
|
||||
}
|
||||
}
|
||||
Database::query("UPDATE $tbl_session SET nbr_users='$user_counter', nbr_courses='$course_counter' WHERE id='$session_id'");
|
||||
}
|
||||
}
|
||||
if (empty($root->Users->User) && empty($root->Courses->Course) && empty($root->Session)) {
|
||||
$error_message = get_lang('NoNeededData');
|
||||
}
|
||||
} else {
|
||||
$error_message .= get_lang('XMLNotValid');
|
||||
}
|
||||
} else {
|
||||
// CSV
|
||||
$updateCourseCoaches = isset($_POST['update_course_coaches']);
|
||||
$addOriginalCourseTeachersAsCourseSessionCoaches = isset($_POST['add_me_as_coach']);
|
||||
|
||||
$result = SessionManager::importCSV(
|
||||
$_FILES['import_file']['tmp_name'],
|
||||
$isOverwrite,
|
||||
api_get_user_id(),
|
||||
null,
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
1,
|
||||
[],
|
||||
$deleteUsersNotInList,
|
||||
$updateCourseCoaches,
|
||||
false,
|
||||
$addOriginalCourseTeachersAsCourseSessionCoaches,
|
||||
false
|
||||
);
|
||||
$sessionList = $result['session_list'];
|
||||
$error_message = $result['error_message'];
|
||||
$session_counter = $result['session_counter'];
|
||||
}
|
||||
|
||||
if (!empty($error_message)) {
|
||||
$error_message = get_lang('ButProblemsOccured').' :<br />'.$error_message;
|
||||
}
|
||||
|
||||
if (!empty($inserted_in_course)) {
|
||||
$warn = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
|
||||
foreach ($inserted_in_course as $code => $title) {
|
||||
$warn .= ' '.$title.' ('.$code.'),';
|
||||
}
|
||||
$warn = substr($warn, 0, -1);
|
||||
}
|
||||
if ($session_counter == 1) {
|
||||
if ($file_type == 'csv') {
|
||||
$session_id = current($sessionList);
|
||||
}
|
||||
Display::addFlash(Display::return_message($warn));
|
||||
header('Location: resume_session.php?id_session='.$session_id);
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('FileImported').' '.$error_message, 'normal', false));
|
||||
header('Location: session_list.php');
|
||||
}
|
||||
exit;
|
||||
} else {
|
||||
$error_message = get_lang('NoInputFile');
|
||||
}
|
||||
}
|
||||
|
||||
// Display the header.
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!empty($inserted_in_course)) {
|
||||
$msg = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
|
||||
foreach ($inserted_in_course as $code => $title) {
|
||||
$msg .= ' '.$title.' ('.$title.'),';
|
||||
}
|
||||
$msg = substr($msg, 0, -1);
|
||||
echo Display::return_message($msg, 'warning');
|
||||
}
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="../session/session_list.php">'.
|
||||
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
|
||||
if (!empty($error_message)) {
|
||||
echo Display::return_message($error_message, 'normal', false);
|
||||
}
|
||||
|
||||
$form = new FormValidator('import_sessions', 'post', api_get_self(), null, ['enctype' => 'multipart/form-data']);
|
||||
$form->addElement('hidden', 'formSent', 1);
|
||||
$form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'file_type',
|
||||
[
|
||||
get_lang('FileType'),
|
||||
Display::url(
|
||||
get_lang('ExampleCSVFile'),
|
||||
api_get_path(WEB_CODE_PATH).'admin/example_session.csv',
|
||||
['target' => '_blank', 'download' => null]
|
||||
),
|
||||
],
|
||||
'CSV',
|
||||
'csv'
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'file_type',
|
||||
[
|
||||
null,
|
||||
Display::url(
|
||||
get_lang('ExampleXMLFile'),
|
||||
api_get_path(WEB_CODE_PATH).'admin/example_session.xml',
|
||||
['target' => '_blank', 'download' => null]
|
||||
),
|
||||
],
|
||||
'XML',
|
||||
'xml'
|
||||
);
|
||||
|
||||
$form->addElement('checkbox', 'overwrite', null, get_lang('IfSessionExistsUpdate'));
|
||||
$form->addElement('checkbox', 'delete_users_not_in_list', null, get_lang('DeleteUsersNotInList'));
|
||||
$form->addElement('checkbox', 'update_course_coaches', null, get_lang('CleanAndUpdateCourseCoaches'));
|
||||
$form->addElement('checkbox', 'add_me_as_coach', null, get_lang('AddMeAsCoach'));
|
||||
$form->addElement('checkbox', 'sendMail', null, get_lang('SendMailToUsers'));
|
||||
$form->addButtonImport(get_lang('ImportSession'));
|
||||
|
||||
$defaults = ['sendMail' => 'true', 'file_type' => 'csv'];
|
||||
|
||||
$options = api_get_configuration_value('session_import_settings');
|
||||
if (!empty($options) && isset($options['options'])) {
|
||||
if (isset($options['options']['session_exists_default_option'])) {
|
||||
$defaults['overwrite'] = $options['options']['session_exists_default_option'];
|
||||
}
|
||||
if (isset($options['options']['send_mail_default_option'])) {
|
||||
$defaults['sendMail'] = $options['options']['send_mail_default_option'];
|
||||
}
|
||||
}
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
Display::return_message(get_lang('TheXMLImportLetYouAddMoreInfoAndCreateResources'));
|
||||
$form->display();
|
||||
|
||||
?>
|
||||
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
|
||||
<pre>
|
||||
<strong>SessionName</strong>;Coach;<strong>DateStart</strong>;<strong>DateEnd</strong>;Users;Courses;VisibilityAfterExpiration;DisplayStartDate;DisplayEndDate;CoachStartDate;CoachEndDate;Classes
|
||||
<strong>Example 1</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];read_only;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class1|class2
|
||||
<strong>Example 2</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];accessible;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class3|class4
|
||||
<strong>Example 3</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];not_accessible;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class5|class6
|
||||
</pre>
|
||||
<p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
|
||||
<pre>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Sessions>
|
||||
<Users>
|
||||
<User>
|
||||
<Username><strong>username1</strong></Username>
|
||||
<Lastname>xxx</Lastname>
|
||||
<Firstname>xxx</Firstname>
|
||||
<Password>xxx</Password>
|
||||
<Email>xxx@xx.xx</Email>
|
||||
<OfficialCode>xxx</OfficialCode>
|
||||
<Phone>xxx</Phone>
|
||||
<Status>student|teacher</Status>
|
||||
</User>
|
||||
</Users>
|
||||
<Courses>
|
||||
<Course>
|
||||
<CourseCode><strong>xxx</strong></CourseCode>
|
||||
<CourseTeacher><strong>teacher_username</strong></CourseTeacher>
|
||||
<CourseLanguage>xxx</CourseLanguage>
|
||||
<CourseTitle>xxx</CourseTitle>
|
||||
<CourseDescription>xxx</CourseDescription>
|
||||
</Course>
|
||||
</Courses>
|
||||
<Session>
|
||||
<strong><SessionName>xxx</SessionName></strong>
|
||||
<Coach>xxx</Coach>
|
||||
<strong><DateStart>yyyy/mm/dd</DateStart></strong>
|
||||
<strong><DateEnd>yyyy/mm/dd</DateEnd></strong>
|
||||
<User>xxx</User>
|
||||
<User>xxx</User>
|
||||
<Course>
|
||||
<CourseCode>coursecode1</CourseCode>
|
||||
<Coach>coach1</Coach>
|
||||
<User>username1</User>
|
||||
<User>username2</User>
|
||||
</Course>
|
||||
</Session>
|
||||
|
||||
<Session>
|
||||
<strong><SessionName>xxx</SessionName></strong>
|
||||
<Coach>xxx</Coach>
|
||||
<strong><DateStart>xxx</DateStart></strong>
|
||||
<strong><DateEnd>xxx</DateEnd></strong>
|
||||
<User>xxx</User>
|
||||
<User>xxx</User>
|
||||
<Course>
|
||||
<CourseCode>coursecode1</CourseCode>
|
||||
<Coach>coach1</Coach>
|
||||
<User>username1</User>
|
||||
<User>username2</User>
|
||||
</Course>
|
||||
</Session>
|
||||
</Sessions>
|
||||
</pre>
|
||||
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
94
main/session/session_import_drh.php
Normal file
94
main/session/session_import_drh.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script(true);
|
||||
api_protect_limit_for_session_admin();
|
||||
|
||||
$form_sent = 0;
|
||||
$tool_name = get_lang('ImportSessionDrhList');
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$inserted_in_course = [];
|
||||
|
||||
$form = new FormValidator(
|
||||
'import_sessions',
|
||||
'post',
|
||||
api_get_self(),
|
||||
null,
|
||||
['enctype' => 'multipart/form-data']
|
||||
);
|
||||
|
||||
$form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
|
||||
|
||||
$displayRemoveOldRelationshipsCheckbox = true;
|
||||
if (true === api_get_configuration_value('session_import_drh_hide_old_relationships_check_box')) {
|
||||
$displayRemoveOldRelationshipsCheckbox = false;
|
||||
}
|
||||
|
||||
if ($displayRemoveOldRelationshipsCheckbox) {
|
||||
$form->addCheckbox('remove_old_relationships', [get_lang('RemoveOldRelationships'), get_lang('RemoveOldRelationshipsHelp')]);
|
||||
}
|
||||
|
||||
$form->addButtonImport(get_lang('ImportSession'));
|
||||
|
||||
if ($form->validate()) {
|
||||
if (isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) {
|
||||
$values = $form->exportValues();
|
||||
$sendMail = isset($values['send_email']) ? true : false;
|
||||
$removeOldRelationships = isset($values['remove_old_relationships']) ? true : false;
|
||||
|
||||
$result = SessionManager::importSessionDrhCSV(
|
||||
$_FILES['import_file']['tmp_name'],
|
||||
$sendMail,
|
||||
$removeOldRelationships
|
||||
);
|
||||
Display::addFlash(Display::return_message($result, 'info', false));
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
} else {
|
||||
$error_message = get_lang('NoInputFile');
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="../session/session_list.php">'.
|
||||
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
if (!empty($error_message)) {
|
||||
echo Display::return_message($error_message, 'normal', false);
|
||||
}
|
||||
$form->display();
|
||||
|
||||
?>
|
||||
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
Username;SessionName;
|
||||
drh1;Session 1;
|
||||
drh2;Session 2;
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p><?php echo get_lang('Or'); ?> </p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
Username;SessionId;
|
||||
drh1,drh2;100;
|
||||
drh3;102;
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
717
main/session/session_list.php
Normal file
717
main/session/session_list.php
Normal file
@@ -0,0 +1,717 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* List sessions in an efficient and usable way.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
SessionManager::protectSession(null, false);
|
||||
|
||||
// Add the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
|
||||
$idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null;
|
||||
$idMultiple = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
|
||||
$listType = isset($_REQUEST['list_type']) ? Security::remove_XSS($_REQUEST['list_type']) : SessionManager::getDefaultSessionTab();
|
||||
$copySessionContent = isset($_REQUEST['copy_session_content']) ? true : false;
|
||||
$addSessionContent = api_get_configuration_value('duplicate_specific_session_content_on_session_copy');
|
||||
if (false === $addSessionContent) {
|
||||
$copySessionContent = false;
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'delete_multiple':
|
||||
$sessionList = explode(',', $idMultiple);
|
||||
foreach ($sessionList as $id) {
|
||||
$sessionInfo = api_get_session_info($id);
|
||||
if ($sessionInfo) {
|
||||
$response = SessionManager::delete($id);
|
||||
/*if ($response) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Deleted').': '.Security::remove_XSS($sessionInfo['name']))
|
||||
);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
echo 1;
|
||||
exit;
|
||||
break;
|
||||
case 'delete':
|
||||
$sessionInfo = api_get_session_info($idChecked);
|
||||
if ($sessionInfo) {
|
||||
$response = SessionManager::delete($idChecked);
|
||||
if ($response) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Deleted').': '.Security::remove_XSS($sessionInfo['name']))
|
||||
);
|
||||
}
|
||||
}
|
||||
$url = 'session_list.php';
|
||||
if ('custom' !== $listType) {
|
||||
$url = 'session_list.php?list_type='.$listType;
|
||||
}
|
||||
header('Location: '.$url);
|
||||
exit();
|
||||
break;
|
||||
case 'copy':
|
||||
$result = SessionManager::copy(
|
||||
$idChecked,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
$copySessionContent
|
||||
);
|
||||
if ($result) {
|
||||
$sessionInfo = api_get_session_info($result);
|
||||
$url = Display::url(
|
||||
$sessionInfo['name'],
|
||||
api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$result
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('ItemCopied').' - '.$url,
|
||||
'success',
|
||||
false
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('ThereWasAnError'), 'error'));
|
||||
}
|
||||
$url = 'session_list.php';
|
||||
if ('custom' !== $listType) {
|
||||
$url = 'session_list.php?list_type='.$listType;
|
||||
}
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
break;
|
||||
case 'copy_multiple':
|
||||
$sessionList = explode(',', $idMultiple);
|
||||
foreach ($sessionList as $id) {
|
||||
$sessionIdCopied = SessionManager::copy($id);
|
||||
if ($sessionIdCopied) {
|
||||
$sessionInfo = api_get_session_info($sessionIdCopied);
|
||||
Display::addFlash(Display::return_message(get_lang('ItemCopied').' - '.$sessionInfo['name']));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('ThereWasAnError'), 'error'));
|
||||
}
|
||||
}
|
||||
$url = 'session_list.php';
|
||||
if ('custom' !== $listType) {
|
||||
$url = 'session_list.php?list_type='.$listType;
|
||||
}
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
case 'export_csv':
|
||||
$selectedSessions = explode(',', $idMultiple);
|
||||
|
||||
$csvHeaders = [];
|
||||
$csvHeaders[] = get_lang('SessionName');
|
||||
$csvHeaders[] = get_lang('SessionStartDate');
|
||||
$csvHeaders[] = get_lang('SessionEndDate');
|
||||
$csvHeaders[] = get_lang('CourseName');
|
||||
$csvHeaders[] = get_lang('OfficialCode');
|
||||
if (api_sort_by_first_name()) {
|
||||
$csvHeaders[] = get_lang('FirstName');
|
||||
$csvHeaders[] = get_lang('LastName');
|
||||
} else {
|
||||
$csvHeaders[] = get_lang('LastName');
|
||||
$csvHeaders[] = get_lang('FirstName');
|
||||
}
|
||||
$csvHeaders[] = get_lang('Login');
|
||||
$csvHeaders[] = get_lang('TrainingTime');
|
||||
$csvHeaders[] = get_lang('CourseProgress');
|
||||
$csvHeaders[] = get_lang('ExerciseProgress');
|
||||
$csvHeaders[] = get_lang('ExerciseAverage');
|
||||
$csvHeaders[] = get_lang('Score');
|
||||
$csvHeaders[] = get_lang('Score').' - '.get_lang('BestAttempt');
|
||||
$csvHeaders[] = get_lang('Student_publication');
|
||||
$csvHeaders[] = get_lang('Messages');
|
||||
$csvHeaders[] = get_lang('Classes');
|
||||
$csvHeaders[] = get_lang('RegistrationDate');
|
||||
$csvHeaders[] = get_lang('FirstLoginInCourse');
|
||||
$csvHeaders[] = get_lang('LatestLoginInCourse');
|
||||
$csvHeaders[] = get_lang('LpFinalizationDate');
|
||||
$csvHeaders[] = get_lang('QuizFinalizationDate');
|
||||
$csvData = [];
|
||||
$i = 0;
|
||||
foreach ($selectedSessions as $sessionId) {
|
||||
$courses = SessionManager::get_course_list_by_session_id($sessionId);
|
||||
if (!empty($courses)) {
|
||||
foreach ($courses as $course) {
|
||||
$courseCode = $course['course_code'];
|
||||
$studentList = CourseManager::get_student_list_from_course_code(
|
||||
$courseCode,
|
||||
true,
|
||||
$sessionId
|
||||
);
|
||||
|
||||
$nbStudents = count($studentList);
|
||||
// Set global variables used by get_user_data()
|
||||
$GLOBALS['user_ids'] = array_keys($studentList);
|
||||
$GLOBALS['session_id'] = $sessionId;
|
||||
$GLOBALS['course_code'] = $courseCode;
|
||||
$GLOBALS['export_csv'] = true;
|
||||
$csvContentInSession = TrackingCourseLog::getUserData(
|
||||
null,
|
||||
$nbStudents,
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
if (!empty($csvContentInSession)) {
|
||||
$csvData = array_merge($csvData, $csvContentInSession);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($csvData)) {
|
||||
array_unshift($csvData, $csvHeaders);
|
||||
$filename = 'export_session_courses_reports_complete_'.api_get_local_time();
|
||||
Export::arrayToCsv($csvData, $filename);
|
||||
exit;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'export_multiple':
|
||||
$sessionList = explode(',', $idMultiple);
|
||||
$tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().'.zip';
|
||||
$zip = new PclZip($tempZipFile);
|
||||
$csvList = [];
|
||||
|
||||
foreach ($sessionList as $sessionItemId) {
|
||||
$em = Database::getManager();
|
||||
$sessionRepository = $em->getRepository('ChamiloCoreBundle:Session');
|
||||
$session = $sessionRepository->find($sessionItemId);
|
||||
|
||||
Session::write('id_session', $sessionItemId);
|
||||
|
||||
if ($session->getNbrCourses() > 0) {
|
||||
$courses = $session->getCourses();
|
||||
$courseList = [];
|
||||
|
||||
foreach ($courses as $sessionRelCourse) {
|
||||
$courseList[] = $sessionRelCourse->getCourse();
|
||||
}
|
||||
|
||||
foreach ($courseList as $course) {
|
||||
$courseId = $course->getId();
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$addExerciseOption = api_get_configuration_value('add_exercise_best_attempt_in_report');
|
||||
$sortByFirstName = api_sort_by_first_name();
|
||||
$bestScoreLabel = get_lang('Score').' - '.get_lang('BestAttempt');
|
||||
$courseCode = $courseInfo['code'];
|
||||
|
||||
$csvHeaders = [];
|
||||
$csvHeaders[] = get_lang('OfficialCode');
|
||||
|
||||
if ($sortByFirstName) {
|
||||
$csvHeaders[] = get_lang('FirstName');
|
||||
$csvHeaders[] = get_lang('LastName');
|
||||
} else {
|
||||
$csvHeaders[] = get_lang('LastName');
|
||||
$csvHeaders[] = get_lang('FirstName');
|
||||
}
|
||||
|
||||
$csvHeaders[] = get_lang('Login');
|
||||
$csvHeaders[] = get_lang('TrainingTime');
|
||||
$csvHeaders[] = get_lang('CourseProgress');
|
||||
$csvHeaders[] = get_lang('ExerciseProgress');
|
||||
$csvHeaders[] = get_lang('ExerciseAverage');
|
||||
$csvHeaders[] = get_lang('Score');
|
||||
$csvHeaders[] = $bestScoreLabel;
|
||||
$exerciseResultHeaders = [];
|
||||
if (!empty($addExerciseOption) && isset($addExerciseOption['courses']) &&
|
||||
isset($addExerciseOption['courses'][$courseCode])
|
||||
) {
|
||||
foreach ($addExerciseOption['courses'][$courseCode] as $exerciseId) {
|
||||
$exercise = new Exercise();
|
||||
$exercise->read($exerciseId);
|
||||
if ($exercise->iid) {
|
||||
$title = get_lang('Exercise').': '.$exercise->get_formated_title();
|
||||
$table->set_header(
|
||||
$headerCounter++,
|
||||
$title,
|
||||
false
|
||||
);
|
||||
$exerciseResultHeaders[] = $title;
|
||||
$headers['exercise_'.$exercise->iid] = $title;
|
||||
}
|
||||
}
|
||||
}
|
||||
$csvHeaders[] = get_lang('Student_publication');
|
||||
$csvHeaders[] = get_lang('Messages');
|
||||
$csvHeaders[] = get_lang('Classes');
|
||||
$csvHeaders[] = get_lang('RegistrationDate');
|
||||
$csvHeaders[] = get_lang('FirstLoginInCourse');
|
||||
$csvHeaders[] = get_lang('LatestLoginInCourse');
|
||||
|
||||
$studentList = CourseManager::get_student_list_from_course_code(
|
||||
$courseCode,
|
||||
true,
|
||||
$sessionItemId
|
||||
);
|
||||
$nbStudents = count($studentList);
|
||||
|
||||
// Set global variables used by get_user_data()
|
||||
$user_ids = array_keys($studentList);
|
||||
$session_id = $sessionItemId;
|
||||
$course_code = $courseCode;
|
||||
$export_csv = true;
|
||||
|
||||
$csvContentInSession = TrackingCourseLog::getUserData(
|
||||
null,
|
||||
$nbStudents,
|
||||
null,
|
||||
null,
|
||||
[]
|
||||
);
|
||||
|
||||
array_unshift($csvContentInSession, $csvHeaders);
|
||||
|
||||
$sessionInfo = api_get_session_info($sessionItemId);
|
||||
$sessionDates = SessionManager::parseSessionDates($sessionInfo);
|
||||
|
||||
array_unshift($csvContentInSession, [get_lang('Date'), $sessionDates['access']]);
|
||||
array_unshift($csvContentInSession, [get_lang('SessionName'), Security::remove_XSS($sessionInfo['name'])]);
|
||||
|
||||
$csvList[] = [
|
||||
'session_id' => $sessionItemId,
|
||||
'session_name' => $session->getName(),
|
||||
'course_id' => $courseId,
|
||||
'course_name' => $courseInfo['name'],
|
||||
'path' => Export::arrayToCsv($csvContentInSession, '', true),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($csvList as $csv) {
|
||||
$newFileName = $csv['session_id'].'_'.$csv['session_name'];
|
||||
$newFileName .= '-'.$csv['course_id'].'_'.$csv['course_name'].'.csv';
|
||||
|
||||
$zip->add(
|
||||
[
|
||||
[
|
||||
PCLZIP_ATT_FILE_NAME => $csv['path'],
|
||||
PCLZIP_ATT_FILE_NEW_FULL_NAME => $newFileName,
|
||||
],
|
||||
],
|
||||
'fixDocumentNameCallback'
|
||||
);
|
||||
unlink($csv['path']);
|
||||
}
|
||||
|
||||
DocumentManager::file_send_for_download(
|
||||
$tempZipFile,
|
||||
true
|
||||
);
|
||||
unlink($tempZipFile);
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
$tool_name = get_lang('SessionList');
|
||||
Display::display_header($tool_name);
|
||||
$courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null;
|
||||
|
||||
$sessionFilter = new FormValidator(
|
||||
'course_filter',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$courseSelect = $sessionFilter->addElement(
|
||||
'select_ajax',
|
||||
'course_name',
|
||||
get_lang('SearchCourse'),
|
||||
null,
|
||||
['url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course']
|
||||
);
|
||||
|
||||
if (!empty($courseId)) {
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$parents = CourseCategory::getParentsToString($courseInfo['categoryCode']);
|
||||
$courseSelect->addOption($parents.$courseInfo['title'], $courseInfo['code'], ['selected' => 'selected']);
|
||||
}
|
||||
|
||||
$url = api_get_self();
|
||||
$actions = '
|
||||
<script>
|
||||
$(function() {
|
||||
$("#course_name").on("change", function() {
|
||||
var courseId = $(this).val();
|
||||
|
||||
if (!courseId) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.location = "'.$url.'?course_id="+courseId;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
// jqgrid will use this URL to do the selects
|
||||
if (!empty($courseId)) {
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&course_id='.$courseId;
|
||||
} else {
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['keyword'])) {
|
||||
// Begin with see the searchOper param
|
||||
$filter = new stdClass();
|
||||
$filter->groupOp = 'OR';
|
||||
$rule = new stdClass();
|
||||
$rule->field = 'category_name';
|
||||
$rule->op = 'in';
|
||||
$rule->data = Security::remove_XSS($_REQUEST['keyword']);
|
||||
$filter->rules[] = $rule;
|
||||
$filter->groupOp = 'OR';
|
||||
$filter = json_encode($filter);
|
||||
$url = api_get_path(WEB_AJAX_PATH).
|
||||
'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters='.$filter.'&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=in';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['id_category'])) {
|
||||
$sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']);
|
||||
if (!empty($sessionCategory)) {
|
||||
// Begin with see the searchOper param
|
||||
$url = api_get_path(WEB_AJAX_PATH).
|
||||
'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=sc.name&searchString='.Security::remove_XSS($sessionCategory['name']).'&searchOper=in';
|
||||
}
|
||||
}
|
||||
|
||||
$url .= '&list_type='.$listType;
|
||||
$result = SessionManager::getGridColumns($listType);
|
||||
$columns = $result['columns'];
|
||||
$column_model = $result['column_model'];
|
||||
$extra_params['autowidth'] = 'true';
|
||||
$extra_params['height'] = 'auto';
|
||||
|
||||
switch ($listType) {
|
||||
case 'custom':
|
||||
$extra_params['sortname'] = 'display_end_date';
|
||||
$extra_params['sortorder'] = 'desc';
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isset($_GET['keyword'])) {
|
||||
$extra_params['postData'] = [
|
||||
'filters' => [
|
||||
'groupOp' => 'AND',
|
||||
'rules' => $result['rules'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$hideSearch = api_get_configuration_value('hide_search_form_in_session_list');
|
||||
$copySessionContentLink = '';
|
||||
if ($addSessionContent) {
|
||||
$copySessionContentLink = ' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="session_list.php?copy_session_content=1&list_type='.$listType.'&action=copy&idChecked=\'+options.rowId+\'">'.
|
||||
Display::return_icon('copy.png', get_lang('CopyWithSessionContent'), '', ICON_SIZE_SMALL).'</a>';
|
||||
}
|
||||
|
||||
// With this function we can add actions to the jgrid (edit, delete, etc)
|
||||
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
|
||||
return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a href="add_users_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.
|
||||
Display::return_icon('user_subscribe_session.png', get_lang('SubscribeUsersToSession'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a href="add_courses_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.
|
||||
Display::return_icon('courses_to_session.png', get_lang('SubscribeCoursesToSession'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="session_list.php?list_type='.$listType.'&action=copy&idChecked=\'+options.rowId+\'">'.
|
||||
Display::return_icon('copy_partial.png', get_lang('Copy'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
$copySessionContentLink.
|
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="session_list.php?list_type='.$listType.'&action=delete&idChecked=\'+options.rowId+\'">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
'\';
|
||||
}';
|
||||
|
||||
$urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
|
||||
$allowOrder = api_get_configuration_value('session_list_order');
|
||||
$orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
|
||||
$deleteUrl = api_get_self().'?list_type='.$listType.'&action=delete_multiple';
|
||||
$copyUrl = api_get_self().'?list_type='.$listType.'&action=copy_multiple';
|
||||
$exportUrl = api_get_self().'?list_type='.$listType.'&action=export_multiple';
|
||||
$exportCsvUrl = api_get_self().'?list_type='.$listType.'&action=export_csv';
|
||||
$extra_params['multiselect'] = true;
|
||||
|
||||
?>
|
||||
<script>
|
||||
function setSearchSelect(columnName) {
|
||||
$("#sessions").jqGrid('setColProp', columnName, {
|
||||
});
|
||||
}
|
||||
var added_cols = [];
|
||||
var original_cols = [];
|
||||
|
||||
function clean_cols(grid, added_cols) {
|
||||
// Cleaning
|
||||
for (key in added_cols) {
|
||||
grid.hideCol(key);
|
||||
}
|
||||
grid.showCol('name');
|
||||
grid.showCol('display_start_date');
|
||||
grid.showCol('display_end_date');
|
||||
grid.showCol('course_title');
|
||||
}
|
||||
|
||||
function show_cols(grid, added_cols) {
|
||||
grid.showCol('name').trigger('reloadGrid');
|
||||
for (key in added_cols) {
|
||||
grid.showCol(key);
|
||||
}
|
||||
}
|
||||
|
||||
var second_filters = [];
|
||||
$(function() {
|
||||
date_pick_today = function(elem) {
|
||||
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
|
||||
$(elem).datetimepicker('setDate', (new Date()));
|
||||
}
|
||||
date_pick_one_month = function(elem) {
|
||||
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
|
||||
next_month = Date.today().next().month();
|
||||
$(elem).datetimepicker('setDate', next_month);
|
||||
}
|
||||
|
||||
//Great hack
|
||||
register_second_select = function(elem) {
|
||||
second_filters[$(elem).val()] = $(elem);
|
||||
}
|
||||
|
||||
fill_second_select = function(elem) {
|
||||
$(elem).on("change", function() {
|
||||
composed_id = $(this).val();
|
||||
field_id = composed_id.split("#")[0];
|
||||
id = composed_id.split("#")[1];
|
||||
|
||||
$.ajax({
|
||||
url: "<?php echo $urlAjaxExtraField; ?>&a=get_second_select_options",
|
||||
dataType: "json",
|
||||
data: "type=session&field_id="+field_id+"&option_value_id="+id,
|
||||
success: function(data) {
|
||||
my_select = second_filters[field_id];
|
||||
my_select.empty();
|
||||
$.each(data, function(index, value) {
|
||||
my_select.append($("<option/>", {
|
||||
value: index,
|
||||
text: value
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
<?php
|
||||
echo Display::grid_js(
|
||||
'sessions',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
$action_links,
|
||||
true
|
||||
);
|
||||
?>
|
||||
|
||||
setSearchSelect("status");
|
||||
var grid = $("#sessions");
|
||||
var prmSearch = {
|
||||
multipleSearch : true,
|
||||
overlay : false,
|
||||
width: 'auto',
|
||||
caption: '<?php echo addslashes(get_lang('Search')); ?>',
|
||||
formclass:'data_table',
|
||||
onSearch : function() {
|
||||
var postdata = grid.jqGrid('getGridParam', 'postData');
|
||||
|
||||
if (postdata && postdata.filters) {
|
||||
filters = jQuery.parseJSON(postdata.filters);
|
||||
clean_cols(grid, added_cols);
|
||||
added_cols = [];
|
||||
$.each(filters, function(key, value) {
|
||||
if (key == 'rules') {
|
||||
$.each(value, function(subkey, subvalue) {
|
||||
if (subvalue.data == undefined) {
|
||||
}
|
||||
added_cols[subvalue.field] = subvalue.field;
|
||||
});
|
||||
}
|
||||
});
|
||||
show_cols(grid, added_cols);
|
||||
}
|
||||
},
|
||||
onReset: function() {
|
||||
clean_cols(grid, added_cols);
|
||||
}
|
||||
};
|
||||
|
||||
original_cols = grid.jqGrid('getGridParam', 'colModel');
|
||||
|
||||
<?php if ($allowOrder) {
|
||||
?>
|
||||
options = {
|
||||
update: function (e, ui) {
|
||||
var rowNum = jQuery("#sessions").getGridParam('rowNum');
|
||||
var page = jQuery("#sessions").getGridParam('page');
|
||||
page = page - 1;
|
||||
var start = rowNum * page;
|
||||
var list = jQuery('#sessions').jqGrid('getRowData');
|
||||
var orderList = [];
|
||||
$(list).each(function(index, e) {
|
||||
index = index + start;
|
||||
orderList.push({'order':index, 'id': e.id});
|
||||
});
|
||||
orderList = JSON.stringify(orderList);
|
||||
$.get("<?php echo $orderUrl; ?>", "order="+orderList, function (result) {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Sortable rows
|
||||
grid.jqGrid('sortableRows', options);
|
||||
<?php
|
||||
} ?>
|
||||
|
||||
grid.jqGrid('navGrid','#sessions_pager',
|
||||
{edit:false,add:false,del:true},
|
||||
{height:280,reloadAfterSubmit:false}, // edit options
|
||||
{height:280,reloadAfterSubmit:false}, // add options
|
||||
{reloadAfterSubmit:true, url: '<?php echo $deleteUrl; ?>' }, // del options
|
||||
prmSearch
|
||||
).navButtonAdd('#sessions_pager',{
|
||||
caption:"<?php echo addslashes(Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL)); ?>",
|
||||
buttonicon:"ui-icon ui-icon-plus",
|
||||
onClickButton: function(a) {
|
||||
var list = $("#sessions").jqGrid('getGridParam', 'selarrrow');
|
||||
if (list.length) {
|
||||
window.location.replace('<?php echo $copyUrl; ?>&id='+list.join(','));
|
||||
} else {
|
||||
alert("<?php echo addslashes(get_lang('SelectAnOption')); ?>");
|
||||
}
|
||||
}
|
||||
}).navButtonAdd('#sessions_pager',{
|
||||
caption:"<?php echo addslashes(Display::return_icon('save_pack.png', get_lang('ExportCoursesReports'), '', ICON_SIZE_SMALL)); ?>",
|
||||
buttonicon:"ui-icon ui-icon-plus",
|
||||
onClickButton: function(a) {
|
||||
var list = $("#sessions").jqGrid('getGridParam', 'selarrrow');
|
||||
if (list.length) {
|
||||
window.location.replace('<?php echo $exportUrl; ?>&id='+list.join(','));
|
||||
} else {
|
||||
alert("<?php echo addslashes(get_lang('SelectAnOption')); ?>");
|
||||
}
|
||||
},
|
||||
position:"last"
|
||||
}).navButtonAdd('#sessions_pager',{
|
||||
caption:"<?php echo addslashes(Display::return_icon('export_csv.png', get_lang('ExportCoursesReportsComplete'), '', ICON_SIZE_SMALL)); ?>",
|
||||
buttonicon:"ui-icon ui-icon-plus",
|
||||
onClickButton: function(a) {
|
||||
var list = $("#sessions").jqGrid('getGridParam', 'selarrrow');
|
||||
if (list.length) {
|
||||
window.location.replace('<?php echo $exportCsvUrl; ?>&id='+list.join(','));
|
||||
} else {
|
||||
alert("<?php echo addslashes(get_lang('SelectAnOption')); ?>");
|
||||
}
|
||||
},
|
||||
position:"last"
|
||||
});
|
||||
|
||||
<?php
|
||||
// Create the searching dialog.
|
||||
if ($hideSearch !== true) {
|
||||
echo 'grid.searchGrid(prmSearch);';
|
||||
}
|
||||
?>
|
||||
|
||||
// Fixes search table.
|
||||
var searchDialogAll = $("#fbox_"+grid[0].id);
|
||||
searchDialogAll.addClass("table");
|
||||
var searchDialog = $("#searchmodfbox_"+grid[0].id);
|
||||
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
|
||||
searchDialog.css({
|
||||
position: "absolute",
|
||||
"z-index": "100",
|
||||
"float": "left",
|
||||
"top": "55%",
|
||||
"left": "25%",
|
||||
"padding": "5px",
|
||||
"border": "1px solid #CCC"
|
||||
})
|
||||
var gbox = $("#gbox_"+grid[0].id);
|
||||
gbox.before(searchDialog);
|
||||
gbox.css({clear:"left"});
|
||||
|
||||
// Select first elements by default
|
||||
$('.input-elm').each(function(){
|
||||
$(this).find('option:first').attr('selected', 'selected');
|
||||
});
|
||||
|
||||
$('.delete-rule').each(function(){
|
||||
$(this).click(function(){
|
||||
$('.input-elm').each(function(){
|
||||
$(this).find('option:first').attr('selected', 'selected');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<div class="actions">
|
||||
<?php
|
||||
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.
|
||||
Display::return_icon('new_session.png', get_lang('AddSession'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
if (api_is_platform_admin()) {
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/add_many_session_to_category.php">'.
|
||||
Display::return_icon('session_to_category.png', get_lang('AddSessionsInCategories'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_list.php">'.
|
||||
Display::return_icon('folder.png', get_lang('ListSessionCategory'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
}
|
||||
|
||||
echo $actions;
|
||||
if (api_is_platform_admin()) {
|
||||
echo '<div class="pull-right">';
|
||||
// Create a search-box
|
||||
$form = new FormValidator(
|
||||
'search_simple',
|
||||
'get',
|
||||
api_get_self().'?list_type='.$listType,
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$form->addElement('text', 'keyword', null, ['aria-label' => get_lang('Search')]);
|
||||
$form->addHidden('list_type', $listType);
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
$form->display();
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="pull-right">';
|
||||
echo $sessionFilter->returnForm();
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo SessionManager::getSessionListTabs($listType);
|
||||
|
||||
echo '<div id="session-table" class="table-responsive">';
|
||||
echo Display::grid_html('sessions');
|
||||
echo '</div>';
|
||||
|
||||
Display::display_footer();
|
||||
365
main/session/session_list_custom.php
Normal file
365
main/session/session_list_custom.php
Normal file
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List sessions in an efficient and usable way.
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
SessionManager::protectSession(null, false);
|
||||
|
||||
// Add the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
|
||||
$idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null;
|
||||
$listType = isset($_REQUEST['list_type']) ? Security::remove_XSS($_REQUEST['list_type']) : SessionManager::getDefaultSessionTab();
|
||||
|
||||
$tool_name = get_lang('SessionList');
|
||||
Display::display_header($tool_name);
|
||||
$courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null;
|
||||
|
||||
$sessionFilter = new FormValidator(
|
||||
'course_filter',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$courseSelect = $sessionFilter->addElement(
|
||||
'select_ajax',
|
||||
'course_name',
|
||||
get_lang('SearchCourse'),
|
||||
null,
|
||||
['url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course']
|
||||
);
|
||||
|
||||
if (!empty($courseId)) {
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$parents = CourseCategory::getParentsToString($courseInfo['categoryCode']);
|
||||
$courseSelect->addOption($parents.$courseInfo['title'], $courseInfo['code'], ['selected' => 'selected']);
|
||||
}
|
||||
|
||||
$url = api_get_self();
|
||||
$actions = '
|
||||
<script>
|
||||
$(function() {
|
||||
$("#course_name").on("change", function() {
|
||||
var courseId = $(this).val();
|
||||
if (!courseId) {
|
||||
return;
|
||||
}
|
||||
window.location = "'.$url.'?course_id="+courseId;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
// jqgrid will use this URL to do the selects
|
||||
if (!empty($courseId)) {
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&course_id='.$courseId;
|
||||
} else {
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['keyword'])) {
|
||||
//Begin with see the searchOper param
|
||||
$filter = new stdClass();
|
||||
$filter->groupOp = 'OR';
|
||||
$rule = new stdClass();
|
||||
$rule->field = 'category_name';
|
||||
$rule->op = 'in';
|
||||
$rule->data = Security::remove_XSS($_REQUEST['keyword']);
|
||||
$filter->rules[] = $rule;
|
||||
$filter->groupOp = 'OR';
|
||||
|
||||
$filter = json_encode($filter);
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters='.$filter.'&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=in';
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['id_category'])) {
|
||||
$sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']);
|
||||
if (!empty($sessionCategory)) {
|
||||
//Begin with see the searchOper param
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=sc.name&searchString='.Security::remove_XSS($sessionCategory['name']).'&searchOper=in';
|
||||
}
|
||||
}
|
||||
|
||||
$url .= '&list_type='.$listType;
|
||||
$result = SessionManager::getGridColumns($listType);
|
||||
|
||||
$columns = $result['columns'];
|
||||
$column_model = $result['column_model'];
|
||||
|
||||
// Autowidth
|
||||
$extra_params['autowidth'] = 'true';
|
||||
|
||||
// height auto
|
||||
$extra_params['height'] = 'auto';
|
||||
|
||||
// Custom params
|
||||
$extra_params['sortname'] = 'display_end_date';
|
||||
$extra_params['sortorder'] = 'desc';
|
||||
|
||||
if (!isset($_GET['keyword'])) {
|
||||
$extra_params['postData'] = [
|
||||
'filters' => [
|
||||
'groupOp' => 'AND',
|
||||
'rules' => $result['rules'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$hideSearch = api_get_configuration_value('hide_search_form_in_session_list');
|
||||
|
||||
//With this function we can add actions to the jgrid (edit, delete, etc)
|
||||
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
|
||||
return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a href="add_users_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.
|
||||
Display::return_icon('user_subscribe_session.png', get_lang('SubscribeUsersToSession'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a href="add_courses_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.
|
||||
Display::return_icon('courses_to_session.png', get_lang('SubscribeCoursesToSession'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="session_list.php?list_type='.$listType.'&action=copy&idChecked=\'+options.rowId+\'">'.
|
||||
Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="session_list.php?list_type='.$listType.'&action=delete&idChecked=\'+options.rowId+\'">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
'\';
|
||||
}';
|
||||
|
||||
$urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
|
||||
$allowOrder = api_get_configuration_value('session_list_order');
|
||||
$orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
|
||||
|
||||
?>
|
||||
<script>
|
||||
function setSearchSelect(columnName) {
|
||||
$("#sessions").jqGrid('setColProp', columnName, {});
|
||||
}
|
||||
var added_cols = [];
|
||||
var original_cols = [];
|
||||
|
||||
function clean_cols(grid, added_cols) {
|
||||
// Cleaning
|
||||
for (key in added_cols) {
|
||||
grid.hideCol(key);
|
||||
}
|
||||
grid.showCol('name');
|
||||
grid.showCol('display_start_date');
|
||||
grid.showCol('display_end_date');
|
||||
grid.showCol('course_title');
|
||||
}
|
||||
|
||||
function show_cols(grid, added_cols) {
|
||||
grid.showCol('name').trigger('reloadGrid');
|
||||
for (key in added_cols) {
|
||||
grid.showCol(key);
|
||||
};
|
||||
}
|
||||
|
||||
var second_filters = [];
|
||||
|
||||
$(function() {
|
||||
date_pick_today = function(elem) {
|
||||
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
|
||||
$(elem).datetimepicker('setDate', (new Date()));
|
||||
}
|
||||
date_pick_one_month = function(elem) {
|
||||
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
|
||||
next_month = Date.today().next().month();
|
||||
$(elem).datetimepicker('setDate', next_month);
|
||||
}
|
||||
|
||||
//Great hack
|
||||
register_second_select = function(elem) {
|
||||
second_filters[$(elem).val()] = $(elem);
|
||||
}
|
||||
|
||||
fill_second_select = function(elem) {
|
||||
$(elem).on("change", function() {
|
||||
composed_id = $(this).val();
|
||||
field_id = composed_id.split("#")[0];
|
||||
id = composed_id.split("#")[1];
|
||||
|
||||
$.ajax({
|
||||
url: "<?php echo $urlAjaxExtraField; ?>&a=get_second_select_options",
|
||||
dataType: "json",
|
||||
data: "type=session&field_id="+field_id+"&option_value_id="+id,
|
||||
success: function(data) {
|
||||
my_select = second_filters[field_id];
|
||||
my_select.empty();
|
||||
$.each(data, function(index, value) {
|
||||
my_select.append($("<option/>", {
|
||||
value: index,
|
||||
text: value
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
<?php
|
||||
echo Display::grid_js(
|
||||
'sessions',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
$action_links,
|
||||
true
|
||||
);
|
||||
?>
|
||||
|
||||
setSearchSelect("status");
|
||||
|
||||
var grid = $("#sessions"),
|
||||
prmSearch = {
|
||||
multipleSearch : true,
|
||||
overlay : false,
|
||||
width: 'auto',
|
||||
caption: '<?php echo addslashes(get_lang('Search')); ?>',
|
||||
formclass:'data_table',
|
||||
onSearch : function() {
|
||||
var postdata = grid.jqGrid('getGridParam', 'postData');
|
||||
|
||||
if (postdata && postdata.filters) {
|
||||
filters = jQuery.parseJSON(postdata.filters);
|
||||
clean_cols(grid, added_cols);
|
||||
added_cols = [];
|
||||
$.each(filters, function(key, value) {
|
||||
if (key == 'rules') {
|
||||
$.each(value, function(subkey, subvalue) {
|
||||
if (subvalue.data == undefined) {
|
||||
}
|
||||
added_cols[subvalue.field] = subvalue.field;
|
||||
});
|
||||
}
|
||||
});
|
||||
show_cols(grid, added_cols);
|
||||
}
|
||||
},
|
||||
onReset: function() {
|
||||
clean_cols(grid, added_cols);
|
||||
}
|
||||
};
|
||||
|
||||
original_cols = grid.jqGrid('getGridParam', 'colModel');
|
||||
|
||||
<?php if ($allowOrder) {
|
||||
?>
|
||||
options = {
|
||||
update: function (e, ui) {
|
||||
var rowNum = jQuery("#sessions").getGridParam('rowNum');
|
||||
var page = jQuery("#sessions").getGridParam('page');
|
||||
page = page - 1;
|
||||
var start = rowNum * page;
|
||||
var list = jQuery('#sessions').jqGrid('getRowData');
|
||||
var orderList = [];
|
||||
$(list).each(function(index, e) {
|
||||
index = index + start;
|
||||
orderList.push({'order':index, 'id': e.id});
|
||||
});
|
||||
orderList = JSON.stringify(orderList);
|
||||
$.get("<?php echo $orderUrl; ?>", "order="+orderList, function (result) {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Sortable rows
|
||||
grid.jqGrid('sortableRows', options);
|
||||
<?php
|
||||
} ?>
|
||||
|
||||
grid.jqGrid('navGrid','#sessions_pager',
|
||||
{edit:false,add:false,del:false},
|
||||
{height:280,reloadAfterSubmit:false}, // edit options
|
||||
{height:280,reloadAfterSubmit:false}, // add options
|
||||
{reloadAfterSubmit:false},// del options
|
||||
prmSearch
|
||||
);
|
||||
|
||||
<?php
|
||||
// Create the searching dialog.
|
||||
if ($hideSearch !== true) {
|
||||
echo 'grid.searchGrid(prmSearch);';
|
||||
}
|
||||
?>
|
||||
|
||||
// Fixes search table.
|
||||
var searchDialogAll = $("#fbox_"+grid[0].id);
|
||||
searchDialogAll.addClass("table");
|
||||
var searchDialog = $("#searchmodfbox_"+grid[0].id);
|
||||
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
|
||||
searchDialog.css({position:"absolute", "z-index":"100", "float":"left", "top":"55%", "left" : "25%", "padding" : "5px", "border": "1px solid #CCC"})
|
||||
var gbox = $("#gbox_"+grid[0].id);
|
||||
gbox.before(searchDialog);
|
||||
gbox.css({clear:"left"});
|
||||
|
||||
// Select first elements by default
|
||||
$('.input-elm').each(function(){
|
||||
$(this).find('option:first').attr('selected', 'selected');
|
||||
});
|
||||
|
||||
$('.delete-rule').each(function(){
|
||||
$(this).click(function(){
|
||||
$('.input-elm').each(function(){
|
||||
$(this).find('option:first').attr('selected', 'selected');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<div class="actions">
|
||||
<?php
|
||||
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.
|
||||
Display::return_icon('new_session.png', get_lang('AddSession'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
if (api_is_platform_admin()) {
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/add_many_session_to_category.php">'.
|
||||
Display::return_icon('session_to_category.png', get_lang('AddSessionsInCategories'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_list.php">'.
|
||||
Display::return_icon('folder.png', get_lang('ListSessionCategory'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
}
|
||||
|
||||
echo $actions;
|
||||
if (api_is_platform_admin()) {
|
||||
echo '<div class="pull-right">';
|
||||
// Create a search-box
|
||||
$form = new FormValidator(
|
||||
'search_simple',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$form->addElement(
|
||||
'text',
|
||||
'keyword',
|
||||
null,
|
||||
[
|
||||
'aria-label' => get_lang('Search'),
|
||||
]
|
||||
);
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
$form->display();
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="pull-right">';
|
||||
echo $sessionFilter->returnForm();
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo SessionManager::getSessionListTabs($listType);
|
||||
echo '<div id="session-table" class="table-responsive">';
|
||||
echo Display::grid_html('sessions');
|
||||
echo '</div>';
|
||||
|
||||
Display::display_footer();
|
||||
146
main/session/session_user_edit.php
Normal file
146
main/session/session_user_edit.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
// including the global Chamilo file
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
|
||||
$userId = isset($_GET['user_id']) ? $_GET['user_id'] : null;
|
||||
|
||||
SessionManager::protectSession($sessionId);
|
||||
|
||||
$sessionInfo = api_get_session_info($sessionId);
|
||||
|
||||
if (empty($sessionInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!isset($sessionInfo['duration']) ||
|
||||
(isset($sessionInfo['duration']) && empty($sessionInfo['duration']))
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (empty($sessionId) || empty($userId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "resume_session.php?id_session=".$sessionId,
|
||||
"name" => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
$form = new FormValidator('edit', 'post', api_get_self().'?session_id='.$sessionId.'&user_id='.$userId);
|
||||
$form->addHeader(get_lang('EditUserSessionDuration'));
|
||||
$userInfo = api_get_user_info($userId, false, false, false, false, true);
|
||||
|
||||
// Show current end date for the session for this user, if any
|
||||
$userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser(
|
||||
$sessionId,
|
||||
$userId
|
||||
);
|
||||
|
||||
$extension = 0;
|
||||
|
||||
if (count($userAccess) == 0) {
|
||||
// User never accessed the session. End date is still open
|
||||
$msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
|
||||
} else {
|
||||
// The user already accessed the session. Show a clear detail of the days count.
|
||||
$duration = $sessionInfo['duration'];
|
||||
$days = SessionManager::getDayLeftInSession($sessionInfo, $userId);
|
||||
$userSubscription = SessionManager::getUserSession($userId, $sessionId);
|
||||
$extension = $userSubscription['duration'];
|
||||
$firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
|
||||
$firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
|
||||
if ($days > 0) {
|
||||
$userSubscription = SessionManager::getUserSession($userId, $sessionId);
|
||||
$duration = $sessionInfo['duration'];
|
||||
|
||||
if (!empty($userSubscription['duration'])) {
|
||||
$duration = $duration + $userSubscription['duration'];
|
||||
}
|
||||
|
||||
$msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
|
||||
} else {
|
||||
if (!empty($subscription['duration'])) {
|
||||
$duration = $duration + $subscription['duration'];
|
||||
}
|
||||
$endDateInSeconds = $firstAccess + $duration * 24 * 60 * 60;
|
||||
$last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT);
|
||||
$msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last);
|
||||
}
|
||||
}
|
||||
|
||||
$header = '<div class="row">';
|
||||
$header .= '<div class="col-sm-5">';
|
||||
$header .= '<div class="thumbnail">';
|
||||
$header .= Display::img($userInfo['avatar'], $userInfo['complete_name'], null, false);
|
||||
$header .= '</div>';
|
||||
$header .= '</div>';
|
||||
|
||||
$header .= '<div class="col-sm-7">';
|
||||
|
||||
$userData = $userInfo['complete_name']
|
||||
.PHP_EOL
|
||||
.$user_info['mail']
|
||||
.PHP_EOL
|
||||
.$user_info['official_code'];
|
||||
|
||||
$header .= '<h3>Usuario: ' . Display::url(
|
||||
$userData,
|
||||
api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_info['user_id']
|
||||
) .'</h3>';
|
||||
|
||||
$header .= '<p><h3>Sesión: ' . $sessionInfo['name'] . '<h3></p>';
|
||||
|
||||
$header .= '</div>';
|
||||
$header .='</div>';
|
||||
|
||||
$header .= '<div class="row">';
|
||||
$header .= '<div class="col-sm-12">';
|
||||
|
||||
$header .= $msg;
|
||||
$header .= '<p>'.'</p>';
|
||||
|
||||
$header .= '</div>';
|
||||
$header .= '</div>';
|
||||
|
||||
$form->addElement('html', $header);
|
||||
|
||||
$formData = '<div class="row">';
|
||||
$formData .= '<div class="col-sm-12">';
|
||||
|
||||
$form->addElement('html', $formData);
|
||||
$form->addElement('number', 'duration', [get_lang('ExtraDurationForUser'), null, get_lang('Days')]);
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
|
||||
$formData = '</div>';
|
||||
$formData .= '</div>';
|
||||
|
||||
$form->addElement('html', $formData);
|
||||
|
||||
$form->setDefaults(['duration' => $extension]);
|
||||
$message = null;
|
||||
if ($form->validate()) {
|
||||
$duration = $form->getSubmitValue('duration');
|
||||
|
||||
SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
|
||||
$message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
|
||||
|
||||
$url = api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
|
||||
$url = str_replace('&', '&', $url);
|
||||
header("Location: " . $url);
|
||||
exit();
|
||||
}
|
||||
|
||||
// display the header
|
||||
Display::display_header(get_lang('Edit'));
|
||||
|
||||
echo $message;
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
101
main/session/session_user_import.php
Normal file
101
main/session/session_user_import.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$session_id = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
|
||||
SessionManager::protectSession($session_id);
|
||||
|
||||
$form_sent = 0;
|
||||
$tool_name = get_lang('ImportUsers');
|
||||
|
||||
//$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
|
||||
$interbreadcrumb[] = ['url' => "session_list.php", "name" => get_lang('SessionList')];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => "resume_session.php?id_session=".$session_id,
|
||||
"name" => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
if (isset($_FILES['import_file']['tmp_name']) &&
|
||||
!empty($_FILES['import_file']['tmp_name'])
|
||||
) {
|
||||
$form_sent = $_POST['formSent'];
|
||||
|
||||
// CSV
|
||||
$users = Import::csvToArray($_FILES['import_file']['tmp_name']);
|
||||
$user_list = [];
|
||||
foreach ($users as $user_data) {
|
||||
$username = $user_data['username'];
|
||||
$user_id = UserManager::get_user_id_from_username($username);
|
||||
if ($user_id) {
|
||||
$user_list[] = $user_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($user_list)) {
|
||||
SessionManager::subscribeUsersToSession(
|
||||
$session_id,
|
||||
$user_list,
|
||||
null,
|
||||
false
|
||||
);
|
||||
|
||||
foreach ($user_list as &$user_id) {
|
||||
$user_info = api_get_user_info($user_id);
|
||||
$user_id = $user_info['complete_name'];
|
||||
}
|
||||
$error_message = get_lang('UsersAdded').' : '.implode(', ', $user_list);
|
||||
}
|
||||
} else {
|
||||
$error_message = get_lang('NoInputFile');
|
||||
}
|
||||
}
|
||||
|
||||
// Display the header.
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="resume_session.php?id_session='.$session_id.'">'.
|
||||
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM).
|
||||
'</a>';
|
||||
echo '</div>';
|
||||
|
||||
if (!empty($error_message)) {
|
||||
echo Display::return_message($error_message, 'normal', false);
|
||||
}
|
||||
|
||||
$form = new FormValidator(
|
||||
'import_sessions',
|
||||
'post',
|
||||
api_get_self().'?id_session='.$session_id,
|
||||
null,
|
||||
['enctype' => 'multipart/form-data']
|
||||
);
|
||||
$form->addElement('hidden', 'formSent', 1);
|
||||
$form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
|
||||
$form->addButtonImport(get_lang('Import'));
|
||||
|
||||
$form->display();
|
||||
|
||||
?>
|
||||
<p><?php echo get_lang('CSVMustLookLike'); ?> :</p>
|
||||
<blockquote>
|
||||
<pre>
|
||||
username;
|
||||
admin;
|
||||
teacher;
|
||||
jmontoya;
|
||||
</pre>
|
||||
</blockquote>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
Reference in New Issue
Block a user