Actualización
This commit is contained in:
139
main/admin/access_url_add_courses_to_url.php
Normal file
139
main/admin/access_url_add_courses_to_url.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* This script allows platform admins to add users to urls.
|
||||
* It displays a list of users and a list of courses;
|
||||
* you can select multiple users and courses and then click on.
|
||||
*
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_global_admin_script();
|
||||
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$first_letter_course = '';
|
||||
$courses = [];
|
||||
$url_list = [];
|
||||
$users = [];
|
||||
|
||||
$tbl_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
|
||||
/* Header */
|
||||
$tool_name = get_lang('AddCoursesToURL');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('edit.png', get_lang('EditCoursesToURL'), ''),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$courses = is_array($_POST['course_list']) ? $_POST['course_list'] : [];
|
||||
$url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : [];
|
||||
$first_letter_course = $_POST['first_letter_course'];
|
||||
|
||||
foreach ($users as $key => $value) {
|
||||
$users[$key] = intval($value);
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
if (count($courses) == 0 || count($url_list) == 0) {
|
||||
echo Display::return_message(get_lang('AtLeastOneCourseAndOneURL'), 'error');
|
||||
} else {
|
||||
UrlManager::add_courses_to_urls($courses, $url_list);
|
||||
echo Display::return_message(get_lang('CourseBelongURL'), 'confirm');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$first_letter_course_lower = Database::escape_string(api_strtolower($first_letter_course));
|
||||
|
||||
$sql = "SELECT code, title FROM $tbl_course
|
||||
WHERE
|
||||
title LIKE '".$first_letter_course_lower."%' OR
|
||||
title LIKE '".$first_letter_course_lower."%'
|
||||
ORDER BY title, code DESC ";
|
||||
|
||||
$result = Database::query($sql);
|
||||
$db_courses = Database::store_result($result);
|
||||
unset($result);
|
||||
|
||||
$sql = "SELECT id, url FROM $tbl_access_url WHERE active = 1 ORDER BY url";
|
||||
$result = Database::query($sql);
|
||||
$db_urls = Database::store_result($result);
|
||||
unset($result);
|
||||
?>
|
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
|
||||
<input type="hidden" name="form_sent" value="1"/>
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="40%" align="center">
|
||||
<b><?php echo get_lang('CourseList'); ?></b>
|
||||
<br/><br/>
|
||||
<?php echo get_lang('FirstLetterCourse'); ?> :
|
||||
<select name="first_letter_course" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
|
||||
<option value="">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options($first_letter_course);
|
||||
echo Display::get_numeric_options(0, 9, $first_letter_course);
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td width="20%"> </td>
|
||||
<td width="40%" align="center">
|
||||
<b><?php echo get_lang('URLList'); ?> :</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="40%" align="center">
|
||||
<select name="course_list[]" multiple="multiple" size="20" style="width:400px;">
|
||||
<?php foreach ($db_courses as $course) {
|
||||
?>
|
||||
<option value="<?php echo $course['code']; ?>" <?php if (in_array($course['code'], $courses)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php echo $course['title'].' ('.$course['code'].')'; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</td>
|
||||
<td width="20%" valign="middle" align="center">
|
||||
<button type="submit" class="add"> <?php echo get_lang('AddCoursesToThatURL'); ?> </button>
|
||||
</td>
|
||||
<td width="40%" align="center">
|
||||
<select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
|
||||
<?php foreach ($db_urls as $url_obj) {
|
||||
?>
|
||||
<option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php echo $url_obj['url']; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
125
main/admin/access_url_add_usergroup_to_url.php
Normal file
125
main/admin/access_url_add_usergroup_to_url.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* This script allows platform admins to add users to urls.
|
||||
* It displays a list of users and a list of courses;
|
||||
* you can select multiple users and courses and then click on.
|
||||
*
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_global_admin_script();
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$userGroup = new UserGroup();
|
||||
$firstLetterUserGroup = null;
|
||||
$courses = [];
|
||||
$url_list = [];
|
||||
|
||||
$tbl_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
|
||||
$tool_name = get_lang('AddUserGroupToURL');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('edit.png', get_lang('EditUserGroupToURL'), ''),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$userGroups = is_array($_POST['user_group_list']) ? $_POST['user_group_list'] : [];
|
||||
$urlList = is_array($_POST['url_list']) ? $_POST['url_list'] : [];
|
||||
$firstLetterUserGroup = $_POST['first_letter_user_group'];
|
||||
|
||||
if ($form_sent == 1) {
|
||||
if (count($userGroups) == 0 || count($urlList) == 0) {
|
||||
echo Display::return_message(get_lang('AtLeastOneUserGroupAndOneURL'), 'error');
|
||||
} else {
|
||||
UrlManager::addUserGroupListToUrl($userGroups, $urlList);
|
||||
echo Display::return_message(get_lang('UserGroupBelongURL'), 'confirm');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$firstLetterUser = null;
|
||||
if ($userGroup->getTotalCount() > 1000) {
|
||||
//if there are too much num_courses to gracefully handle with the HTML select list,
|
||||
// assign a default filter on users names
|
||||
$firstLetterUser = 'A';
|
||||
}
|
||||
|
||||
$dbUserGroups = $userGroup->filterByFirstLetter($firstLetterUserGroup);
|
||||
|
||||
$sql = "SELECT id, url FROM $tbl_access_url WHERE active = 1 ORDER BY url";
|
||||
$result = Database::query($sql);
|
||||
$db_urls = Database::store_result($result);
|
||||
?>
|
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
|
||||
<input type="hidden" name="form_sent" value="1"/>
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="40%" align="center">
|
||||
<b><?php echo get_lang('UserGroupList'); ?></b>
|
||||
<br/><br/>
|
||||
<?php echo get_lang('FirstLetter'); ?> :
|
||||
<select name="first_letter_user_group" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
|
||||
<option value="">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options($firstLetterUserGroup);
|
||||
echo Display::get_numeric_options(0, 9, $firstLetterUserGroup);
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td width="20%"> </td>
|
||||
<td width="40%" align="center">
|
||||
<b><?php echo get_lang('URLList'); ?> :</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="40%" align="center">
|
||||
<select name="user_group_list[]" multiple="multiple" size="20" style="width:400px;">
|
||||
<?php foreach ($dbUserGroups as $item) {
|
||||
?>
|
||||
<option value="<?php echo $item['id']; ?>" <?php if (in_array($item['id'], $courses)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>><?php echo $item['name']; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</td>
|
||||
<td width="20%" valign="middle" align="center">
|
||||
<button type="submit" class="add"> <?php echo get_lang('AddUserGroupToThatURL'); ?> </button>
|
||||
</td>
|
||||
<td width="40%" align="center">
|
||||
<select name="url_list[]" multiple="multiple" size="20" style="width:300px;">
|
||||
<?php foreach ($db_urls as $url_obj) {
|
||||
?>
|
||||
<option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>><?php echo $url_obj['url']; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
153
main/admin/access_url_add_users_to_url.php
Normal file
153
main/admin/access_url_add_users_to_url.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* This script allows platform admins to add users to urls.
|
||||
* It displays a list of users and a list of courses;
|
||||
* you can select multiple users and courses and then click on.
|
||||
*
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_global_admin_script();
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$first_letter_user = '';
|
||||
$url_list = [];
|
||||
$users = [];
|
||||
|
||||
$tbl_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
|
||||
/* Header */
|
||||
$tool_name = get_lang('AddUsersToURL');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('edit.png', get_lang('EditUsersToURL'), ''),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php'
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
if ($_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$users = is_array($_POST['user_list']) ? $_POST['user_list'] : [];
|
||||
$url_list = is_array($_POST['url_list']) ? $_POST['url_list'] : [];
|
||||
$first_letter_user = $_POST['first_letter_user'];
|
||||
foreach ($users as $key => $value) {
|
||||
$users[$key] = intval($value);
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
if (count($users) == 0 || count($url_list) == 0) {
|
||||
echo Display::return_message(
|
||||
get_lang('AtLeastOneUserAndOneURL'),
|
||||
'error'
|
||||
);
|
||||
} else {
|
||||
UrlManager::add_users_to_urls($users, $url_list);
|
||||
echo Display::return_message(get_lang('UsersBelongURL'), 'confirm');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display GUI */
|
||||
if (empty($first_letter_user)) {
|
||||
$sql = "SELECT count(*) as nb_users FROM $tbl_user";
|
||||
$result = Database::query($sql);
|
||||
$num_row = Database::fetch_array($result);
|
||||
if ($num_row['nb_users'] > 1000) {
|
||||
//if there are too much users to gracefully handle with the HTML select list,
|
||||
// assign a default filter on users names
|
||||
$first_letter_user = 'A';
|
||||
}
|
||||
unset($result);
|
||||
}
|
||||
$first_letter_user_lower = Database::escape_string(api_strtolower($first_letter_user));
|
||||
|
||||
$target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
|
||||
$target_name = 'lastname';
|
||||
$sql = "SELECT user_id,lastname,firstname,username FROM $tbl_user
|
||||
WHERE ".$target_name." LIKE '".$first_letter_user_lower."%' OR ".$target_name." LIKE '".$first_letter_user_lower."%'
|
||||
ORDER BY ".(count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." ".$target_name;
|
||||
$result = Database::query($sql);
|
||||
$db_users = Database::store_result($result);
|
||||
unset($result);
|
||||
|
||||
$sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url";
|
||||
$result = Database::query($sql);
|
||||
$db_urls = Database::store_result($result);
|
||||
unset($result);
|
||||
?>
|
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
|
||||
<input type="hidden" name="form_sent" value="1"/>
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="40%" align="center">
|
||||
<b><?php echo get_lang('UserList'); ?></b>
|
||||
<br/><br/>
|
||||
<?php echo get_lang('Select').' '; echo $target_name == 'firstname' ? get_lang('FirstName') : get_lang('LastName'); ?>
|
||||
<select name="first_letter_user" onchange="javascript:document.formulaire.form_sent.value='2'; document.formulaire.submit();">
|
||||
<option value="">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options($first_letter_user);
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td width="20%"> </td>
|
||||
<td width="40%" align="center">
|
||||
<b><?php echo get_lang('URLList'); ?> :</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="40%" align="center">
|
||||
<select name="user_list[]" multiple="multiple" size="20" style="width:380px;">
|
||||
<?php
|
||||
foreach ($db_users as $user) {
|
||||
?>
|
||||
<option value="<?php echo $user['user_id']; ?>" <?php if (in_array($user['user_id'], $users)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php echo api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td width="20%" valign="middle" align="center">
|
||||
<button type="submit" class="add"> <?php echo get_lang('AddToThatURL'); ?> </button>
|
||||
</td>
|
||||
<td width="40%" align="center">
|
||||
<select name="url_list[]" multiple="multiple" size="20" style="width:230px;">
|
||||
<?php
|
||||
foreach ($db_urls as $url_obj) {
|
||||
?>
|
||||
<option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) {
|
||||
echo 'selected="selected"';
|
||||
} ?>>
|
||||
<?php echo $url_obj['url']; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
114
main/admin/access_url_check_user_session.php
Normal file
114
main/admin/access_url_check_user_session.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @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;
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$tool_name = get_lang('SessionOverview');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$url_id = api_get_current_access_url_id();
|
||||
|
||||
$action = $_GET['action'];
|
||||
|
||||
switch ($action) {
|
||||
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) {
|
||||
$message = Display::return_message(
|
||||
get_lang('UserAdded').' '.api_get_person_name(
|
||||
$user_info['firstname'],
|
||||
$user_info['lastname']
|
||||
),
|
||||
'confirm'
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!empty($message)) {
|
||||
echo $message;
|
||||
}
|
||||
|
||||
$multiple_url_is_on = api_get_multiple_access_url();
|
||||
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
|
||||
$session_list = SessionManager::get_sessions_list();
|
||||
|
||||
$html = '';
|
||||
$show_users_with_problems = isset($_REQUEST['show_users_with_problems']) && $_REQUEST['show_users_with_problems'] == 1 ? true : false;
|
||||
if ($show_users_with_problems) {
|
||||
$html .= '<a href="'.api_get_self().'?show_users_with_problems=0">'.get_lang('ShowAllUsers').'</a>';
|
||||
} else {
|
||||
$html .= '<a href="'.api_get_self().'?show_users_with_problems=1">'.get_lang('ShowUsersNotAddedInTheURL').'</a>';
|
||||
}
|
||||
|
||||
foreach ($session_list as $session_item) {
|
||||
$session_id = $session_item['id'];
|
||||
$html .= '<h3>'.$session_item['name'].'</h3>';
|
||||
$access_where = "(access_url_id = $url_id OR access_url_id is null )";
|
||||
if ($show_users_with_problems) {
|
||||
$access_where = "(access_url_id is null)";
|
||||
}
|
||||
|
||||
$sql = "SELECT u.user_id, lastname, firstname, username, access_url_id
|
||||
FROM $tbl_user u
|
||||
INNER JOIN $tbl_session_rel_user su
|
||||
ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
|
||||
LEFT OUTER JOIN $table_access_url_user uu
|
||||
ON (uu.user_id = u.user_id)
|
||||
WHERE su.session_id = $session_id AND $access_where
|
||||
$order_clause";
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result);
|
||||
|
||||
if (!empty($users)) {
|
||||
$html .= '<table class="table table-hover table-striped data_table">
|
||||
<thead><tr><th>'.get_lang('User').'<th>'.get_lang('Actions').'</th></tr></thead><tbody>';
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user_link = '';
|
||||
if (!empty($user['user_id'])) {
|
||||
$user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.Security::remove_XSS(api_get_person_name($user['firstname'], $user['lastname'])).' ('.$user['username'].')</a>';
|
||||
}
|
||||
|
||||
$link_to_add_user_in_url = '';
|
||||
if ($multiple_url_is_on) {
|
||||
if ($user['access_url_id'] != $url_id) {
|
||||
$user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), [], ICON_SIZE_MEDIUM);
|
||||
$add = Display::return_icon('add.png', get_lang('AddUsersToURL'), [], ICON_SIZE_MEDIUM);
|
||||
$link_to_add_user_in_url = '<a href="'.api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']).'&action=add_user_to_url&id_session='.$id_session.'&user_id='.$user['user_id'].'">'.$add.'</a>';
|
||||
}
|
||||
}
|
||||
$html .= '<tr>
|
||||
<td>
|
||||
<b>'.$user_link.'</b>
|
||||
</td>
|
||||
<td>
|
||||
'.$link_to_add_user_in_url.'
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
$html .= '</tbody></table>';
|
||||
}
|
||||
}
|
||||
echo $html;
|
||||
// footer
|
||||
Display::display_footer();
|
||||
160
main/admin/access_url_edit.php
Normal file
160
main/admin/access_url_edit.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_global_admin_script();
|
||||
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Create the form
|
||||
$form = new FormValidator('add_url');
|
||||
|
||||
if ($form->validate()) {
|
||||
$check = Security::check_token('post');
|
||||
if ($check) {
|
||||
$url_array = $form->getSubmitValues();
|
||||
$url = Security::remove_XSS($url_array['url']);
|
||||
$description = Security::remove_XSS($url_array['description']);
|
||||
$active = isset($url_array['active']) ? (int) $url_array['active'] : 0;
|
||||
$url_id = isset($url_array['id']) ? (int) $url_array['id'] : 0;
|
||||
$url_to_go = 'access_urls.php';
|
||||
if (!empty($url_id)) {
|
||||
//we can't change the status of the url with id=1
|
||||
if (1 == $url_id) {
|
||||
$active = 1;
|
||||
}
|
||||
|
||||
// Checking url
|
||||
if (substr($url, strlen($url) - 1, strlen($url)) == '/') {
|
||||
UrlManager::update($url_id, $url, $description, $active);
|
||||
} else {
|
||||
UrlManager::update($url_id, $url.'/', $description, $active);
|
||||
}
|
||||
// URL Images
|
||||
$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
|
||||
$image_fields = ['url_image_1', 'url_image_2', 'url_image_3'];
|
||||
foreach ($image_fields as $image_field) {
|
||||
if ($_FILES[$image_field]['error'] == 0) {
|
||||
// Hardcoded: only PNG files allowed
|
||||
$fileFields = explode('.', $_FILES[$image_field]['name']);
|
||||
if (end($fileFields) === 'png') {
|
||||
if (file_exists($url_images_dir.$url_id.'_'.$image_field.'.png')) {
|
||||
// if the file exists, we have to remove it before move_uploaded_file
|
||||
unlink($url_images_dir.$url_id.'_'.$image_field.'.png');
|
||||
}
|
||||
move_uploaded_file(
|
||||
$_FILES[$image_field]['tmp_name'],
|
||||
$url_images_dir.$url_id.'_'.$image_field.'.png'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$url_to_go = 'access_urls.php';
|
||||
$message = get_lang('URLEdited');
|
||||
} else {
|
||||
$num = UrlManager::url_exist($url);
|
||||
if ($num == 0) {
|
||||
// checking url
|
||||
if (substr($url, strlen($url) - 1, strlen($url)) == '/') {
|
||||
UrlManager::add($url, $description, $active);
|
||||
} else {
|
||||
//create
|
||||
UrlManager::add($url.'/', $description, $active);
|
||||
}
|
||||
$message = get_lang('URLAdded');
|
||||
$url_to_go = 'access_urls.php';
|
||||
} else {
|
||||
$url_to_go = 'access_url_edit.php';
|
||||
$message = get_lang('URLAlreadyAdded');
|
||||
}
|
||||
// URL Images
|
||||
$url .= (substr($url, strlen($url) - 1, strlen($url)) == '/') ? '' : '/';
|
||||
$url_id = UrlManager::get_url_id($url);
|
||||
$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
|
||||
$image_fields = ["url_image_1", "url_image_2", "url_image_3"];
|
||||
foreach ($image_fields as $image_field) {
|
||||
if ($_FILES[$image_field]['error'] == 0) {
|
||||
// Hardcoded: only PNG files allowed
|
||||
$fileFields = explode('.', $_FILES[$image_field]['name']);
|
||||
if (end($fileFields) == 'png') {
|
||||
move_uploaded_file(
|
||||
$_FILES[$image_field]['tmp_name'],
|
||||
$url_images_dir.$url_id.'_'.$image_field.'.png'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Security::clear_token();
|
||||
$tok = Security::get_token();
|
||||
Display::addFlash(Display::return_message($message));
|
||||
header('Location: '.$url_to_go.'?sec_token='.$tok);
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
if (isset($_POST['submit'])) {
|
||||
Security::clear_token();
|
||||
}
|
||||
$token = Security::get_token();
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
}
|
||||
|
||||
$form->addElement('text', 'url', 'URL');
|
||||
$form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('url', '', 'maxlength', 254);
|
||||
$form->addElement('textarea', 'description', get_lang('Description'));
|
||||
|
||||
//the first url with id = 1 will be always active
|
||||
if (isset($_GET['url_id']) && $_GET['url_id'] != 1) {
|
||||
$form->addElement('checkbox', 'active', null, get_lang('Active'));
|
||||
}
|
||||
|
||||
$defaults['url'] = 'http://';
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
$submit_name = get_lang('AddUrl');
|
||||
if (isset($_GET['url_id'])) {
|
||||
$url_id = (int) $_GET['url_id'];
|
||||
$num_url_id = UrlManager::url_id_exist($url_id);
|
||||
if ($num_url_id != 1) {
|
||||
header('Location: access_urls.php');
|
||||
exit();
|
||||
}
|
||||
$url_data = UrlManager::get_url_data_from_id($url_id);
|
||||
$form->addElement('hidden', 'id', $url_data['id']);
|
||||
$form->setDefaults($url_data);
|
||||
$submit_name = get_lang('AddUrl');
|
||||
}
|
||||
|
||||
if (!api_is_multiple_url_enabled()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$tool_name = get_lang('AddUrl');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
// URL Images
|
||||
$form->addElement('file', 'url_image_1', 'URL Image 1 (PNG)');
|
||||
$form->addElement('file', 'url_image_2', 'URL Image 2 (PNG)');
|
||||
$form->addElement('file', 'url_image_3', 'URL Image 3 (PNG)');
|
||||
|
||||
// Submit button
|
||||
$form->addButtonCreate($submit_name);
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
322
main/admin/access_url_edit_course_category_to_url.php
Normal file
322
main/admin/access_url_edit_course_category_to_url.php
Normal file
@@ -0,0 +1,322 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction(
|
||||
['searchCourseCategoryAjax', 'UrlManager', 'searchCourseCategoryAjax']
|
||||
);
|
||||
|
||||
// Setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_global_admin_script();
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Setting breadcrumbs
|
||||
$tool_name = get_lang('EditUserGroupToURL');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$access_url_id = 1;
|
||||
if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id'] != '') {
|
||||
$access_url_id = (int) $_REQUEST['access_url_id'];
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function add_user_to_url(code, content) {
|
||||
document.getElementById("course_to_add").value = "";
|
||||
document.getElementById("ajax_list_courses").innerHTML = "";
|
||||
destination = document.getElementById("destination_users");
|
||||
destination.options[destination.length] = new Option(content,code);
|
||||
destination.selectedIndex = -1;
|
||||
sortOptions(destination.options);
|
||||
}
|
||||
|
||||
function send() {
|
||||
if (document.formulaire.access_url_id.value!=0) {
|
||||
document.formulaire.form_sent.value=0;
|
||||
document.formulaire.add_type.value=\''.$add_type.'\';
|
||||
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>';
|
||||
|
||||
$form_sent = 0;
|
||||
$UserList = $SessionList = [];
|
||||
$users = $sessions = [];
|
||||
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$list = $_POST['course_list'];
|
||||
|
||||
if (!is_array($list)) {
|
||||
$list = [];
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
if ($access_url_id == 0) {
|
||||
Display::addFlash(Display::return_message(get_lang('SelectURL')));
|
||||
header('Location: access_url_edit_users_to_url.php?');
|
||||
} elseif (is_array($list)) {
|
||||
UrlManager::updateUrlRelCourseCategory($list, $access_url_id);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: access_urls.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
$noUserGroupList = $userGroupList = [];
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
if ($ajax_search) {
|
||||
$userGroups = UrlManager::getUrlRelCourseCategory($access_url_id);
|
||||
foreach ($userGroups as $item) {
|
||||
$userGroupList[$item['id']] = $item;
|
||||
}
|
||||
} else {
|
||||
$userGroups = UrlManager::getUrlRelCourseCategory();
|
||||
|
||||
foreach ($userGroups as $item) {
|
||||
if ($item['access_url_id'] == $access_url_id) {
|
||||
$userGroupList[$item['id']] = $item;
|
||||
}
|
||||
}
|
||||
$noUserGroupList = CourseCategory::getCourseCategoryNotInList(array_keys($userGroupList));
|
||||
}
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique = '<a href="'.api_get_self().'?add_type=unique&access_url_id='.$access_url_id.'">'.
|
||||
get_lang('SessionAddTypeUnique').'</a>';
|
||||
$link_add_type_multiple = get_lang('SessionAddTypeMultiple');
|
||||
} else {
|
||||
$link_add_type_unique = get_lang('SessionAddTypeUnique');
|
||||
$link_add_type_multiple = '<a href="'.api_get_self().'?add_type=multiple&access_url_id='.$access_url_id.'">'.
|
||||
get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
|
||||
$url_list = UrlManager::get_url_data();
|
||||
?>
|
||||
<div style="text-align: left;">
|
||||
<?php echo $link_add_type_unique; ?> | <?php echo $link_add_type_multiple; ?>
|
||||
</div>
|
||||
<br /><br />
|
||||
<form
|
||||
name="formulaire"
|
||||
method="post"
|
||||
action="<?php echo api_get_self(); ?>"
|
||||
style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
} ?>
|
||||
>
|
||||
<?php echo get_lang('SelectUrl').' : '; ?>
|
||||
<select name="access_url_id" onchange="javascript:send();">
|
||||
<option value="0">-- <?php echo get_lang('SelectUrl'); ?> -- </option>
|
||||
<?php
|
||||
$url_selected = '';
|
||||
foreach ($url_list as $url_obj) {
|
||||
$checked = '';
|
||||
if (!empty($access_url_id)) {
|
||||
if ($url_obj[0] == $access_url_id) {
|
||||
$checked = 'selected=true';
|
||||
$url_selected = $url_obj[1];
|
||||
}
|
||||
}
|
||||
if ($url_obj['active'] == 1) {
|
||||
?>
|
||||
<option <?php echo $checked; ?> value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br /><br />
|
||||
<input type="hidden" name="form_sent" value="1" />
|
||||
<input type="hidden" name="add_type" value = "<?php echo $add_type; ?>" />
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<!-- Users -->
|
||||
<tr>
|
||||
<td align="center"><b><?php echo get_lang('CourseCategoryInPlatform'); ?> :</b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td align="center"><b><?php printf(get_lang('CourseCategoryListInX'), $url_selected); ?></b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="center">
|
||||
<div id="content_source">
|
||||
<?php if ($ajax_search) {
|
||||
?>
|
||||
<input type="text" id="course_to_add" onkeyup="xajax_searchCourseCategoryAjax(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)" />
|
||||
<div id="ajax_list_courses"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<select id="origin_users" name="no_course_list[]" multiple="multiple" size="15" style="width:380px;">
|
||||
<?php foreach ($noUserGroupList as $noItem) {
|
||||
?>
|
||||
<option value="<?php echo $noItem['id']; ?>">
|
||||
<?php echo $noItem['name']; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
<?php
|
||||
} ?>
|
||||
</div>
|
||||
</td>
|
||||
<td width="10%" valign="middle" align="center">
|
||||
<?php if ($ajax_search) {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('destination_users'))" ></button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))" >
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br /><br />
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))" >
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} ?>
|
||||
<br /><br /><br /><br /><br /><br />
|
||||
</td>
|
||||
<td align="center">
|
||||
<select id="destination_users" name="course_list[]" multiple="multiple" size="15" style="width:380px;">
|
||||
<?php
|
||||
foreach ($userGroupList as $item) {
|
||||
?>
|
||||
<option value="<?php echo $item['id']; ?>">
|
||||
<?php echo $item['name']; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<br />
|
||||
<?php
|
||||
if (isset($_GET['add'])) {
|
||||
echo '<button class="save" onclick="valide()" >'.get_lang('Add').'</button>';
|
||||
} else {
|
||||
echo '<button class="save" onclick="valide()" >'.get_lang('Edit').'</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('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();
|
||||
313
main/admin/access_url_edit_courses_to_url.php
Normal file
313
main/admin/access_url_edit_courses_to_url.php
Normal file
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction(
|
||||
['search_courses', 'Accessurleditcoursestourl', 'search_courses']
|
||||
);
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_global_admin_script();
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// setting breadcrumbs
|
||||
$tool_name = get_lang('EditCoursesToURL');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$access_url_id = 1;
|
||||
if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id'] != '') {
|
||||
$access_url_id = Security::remove_XSS($_REQUEST['access_url_id']);
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function add_course_to_url(code, content) {
|
||||
document.getElementById("course_to_add").value = "";
|
||||
document.getElementById("ajax_list_courses").innerHTML = "";
|
||||
destination = document.getElementById("destination_courses");
|
||||
destination.options[destination.length] = new Option(content,code);
|
||||
destination.selectedIndex = -1;
|
||||
sortOptions(destination.options);
|
||||
}
|
||||
|
||||
function send() {
|
||||
if (document.formulaire.access_url_id.value != 0) {
|
||||
document.formulaire.form_sent.value=0;
|
||||
document.formulaire.add_type.value=\''.$add_type.'\';
|
||||
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>';
|
||||
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$course_list = $_POST['course_list'];
|
||||
|
||||
if (!is_array($course_list)) {
|
||||
$course_list = [];
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
if ($access_url_id == 0) {
|
||||
Display::addFlash(Display::return_message(get_lang('SelectURL')));
|
||||
header('Location: access_url_edit_courses_to_url.php?');
|
||||
} elseif (is_array($course_list)) {
|
||||
UrlManager::update_urls_rel_course($course_list, $access_url_id);
|
||||
Display::addFlash(Display::return_message(get_lang('CoursesWereEdited')));
|
||||
header('Location: access_urls.php?');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('view_more_stats.gif', get_lang('AddCoursesToURL')),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_add_courses_to_url.php'
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
$no_course_list = $course_list = [];
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
if ($ajax_search) {
|
||||
$courses = UrlManager::get_url_rel_course_data($access_url_id);
|
||||
foreach ($courses as $course) {
|
||||
$course_list[$course['c_id']] = $course;
|
||||
}
|
||||
} else {
|
||||
$courses = UrlManager::get_url_rel_course_data();
|
||||
|
||||
foreach ($courses as $course) {
|
||||
if ($course['access_url_id'] == $access_url_id) {
|
||||
$course_list[$course['c_id']] = $course;
|
||||
}
|
||||
}
|
||||
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$sql = "SELECT id, code, title
|
||||
FROM $tbl_course u
|
||||
ORDER BY title, code";
|
||||
$result = Database::query($sql);
|
||||
$courses = Database::store_result($result);
|
||||
$course_list_leys = array_keys($course_list);
|
||||
foreach ($courses as $course) {
|
||||
if (!in_array($course['id'], $course_list_leys)) {
|
||||
$no_course_list[$course['id']] = $course;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique = '<a href="'.api_get_self().'?add_type=unique&access_url_id='.$access_url_id.'">'.
|
||||
get_lang('SessionAddTypeUnique').'</a>';
|
||||
$link_add_type_multiple = get_lang('SessionAddTypeMultiple');
|
||||
} else {
|
||||
$link_add_type_unique = get_lang('SessionAddTypeUnique');
|
||||
$link_add_type_multiple = '<a href="'.api_get_self().'?add_type=multiple&access_url_id='.$access_url_id.'">'.
|
||||
get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
$url_list = UrlManager::get_url_data();
|
||||
?>
|
||||
<div style="text-align: left;">
|
||||
<?php echo $link_add_type_unique; ?> | <?php echo $link_add_type_multiple; ?>
|
||||
</div>
|
||||
<br /><br />
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
}?> >
|
||||
<?php echo get_lang('SelectUrl').' : '; ?>
|
||||
<select name="access_url_id" onchange="javascript:send();">
|
||||
<option value="0">-- <?php echo get_lang('SelectUrl'); ?> -- </option>
|
||||
<?php
|
||||
$url_selected = '';
|
||||
foreach ($url_list as $url_obj) {
|
||||
$checked = '';
|
||||
if (!empty($access_url_id)) {
|
||||
if ($url_obj[0] == $access_url_id) {
|
||||
$checked = 'selected=true';
|
||||
$url_selected = $url_obj[1];
|
||||
}
|
||||
}
|
||||
if ($url_obj['active'] == 1) {
|
||||
?>
|
||||
<option <?php echo $checked; ?> value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br /><br />
|
||||
<input type="hidden" name="form_sent" value="1" />
|
||||
<input type="hidden" name="add_type" value = "<?php echo $add_type; ?>" />
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<!-- Users -->
|
||||
<tr>
|
||||
<td align="center"><b><?php echo get_lang('CourseListInPlatform'); ?> :</b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td align="center"><b><?php echo get_lang('CourseListIn').' '.$url_selected; ?></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<div id="content_source">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<input type="text" id="course_to_add" onkeyup="xajax_search_courses(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)" />
|
||||
<div id="ajax_list_courses"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<select id="origin_courses" name="no_course_list[]" multiple="multiple" size="15" style="width:380px;">
|
||||
<?php
|
||||
foreach ($no_course_list as $no_course) {
|
||||
?>
|
||||
<option value="<?php echo $no_course['id']; ?>" title="<?php echo htmlentities($no_course['title'], ENT_QUOTES).' ('.$no_course['code'].')'; ?>"><?php echo $no_course['title'].' ('.$no_course['code'].')'; ?></option>
|
||||
<?php
|
||||
}
|
||||
unset($no_course_list); ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td width="10%" valign="middle" align="center">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('destination_courses'))" >
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('origin_courses'), document.getElementById('destination_courses'))" >
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br /><br />
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('destination_courses'), document.getElementById('origin_courses'))" >
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<br /><br /><br /><br /><br /><br />
|
||||
</td>
|
||||
<td align="center">
|
||||
<select id="destination_courses" name="course_list[]" multiple="multiple" size="15" style="width:380px;">
|
||||
<?php
|
||||
foreach ($course_list as $course) {
|
||||
$courseInfo = api_get_course_info_by_id($course['id']); ?>
|
||||
<option value="<?php echo $course['id']; ?>" title="<?php echo htmlentities($course['title'], ENT_QUOTES).' ('.$courseInfo['code'].')'; ?>">
|
||||
<?php echo $course['title'].' ('.$courseInfo['code'].')'; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
unset($course_list);
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<br />
|
||||
<?php
|
||||
if (isset($_GET['add'])) {
|
||||
echo '<button class="btn btn-default" onclick="valide()" >'.get_lang('AddCoursesToURL').'</button>';
|
||||
} else {
|
||||
echo '<button class="btn btn-default" onclick="valide()" >'.get_lang('EditCoursesToURL').'</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('destination_courses').options;
|
||||
for (i = 0 ; i<options.length ; i++)
|
||||
options[i].selected = true;
|
||||
document.forms.formulaire.submit();
|
||||
}
|
||||
|
||||
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();
|
||||
349
main/admin/access_url_edit_usergroup_to_url.php
Normal file
349
main/admin/access_url_edit_usergroup_to_url.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction(['searchUserGroupAjax', 'UserGroup', 'searchUserGroupAjax']);
|
||||
$userGroup = new UserGroup();
|
||||
|
||||
// Setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_global_admin_script();
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// setting breadcrumbs
|
||||
$tool_name = get_lang('EditUserGroupToURL');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$access_url_id = 1;
|
||||
if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id'] != '') {
|
||||
$access_url_id = Security::remove_XSS($_REQUEST['access_url_id']);
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function add_user_to_url(code, content) {
|
||||
document.getElementById("course_to_add").value = "";
|
||||
document.getElementById("ajax_list_courses").innerHTML = "";
|
||||
destination = document.getElementById("destination_users");
|
||||
destination.options[destination.length] = new Option(content,code);
|
||||
destination.selectedIndex = -1;
|
||||
sortOptions(destination.options);
|
||||
}
|
||||
|
||||
function send() {
|
||||
if (document.formulaire.access_url_id.value!=0) {
|
||||
document.formulaire.form_sent.value=0;
|
||||
document.formulaire.add_type.value=\''.$add_type.'\';
|
||||
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>';
|
||||
|
||||
$errorMsg = '';
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$course_list = $_POST['course_list'];
|
||||
|
||||
if (!is_array($course_list)) {
|
||||
$course_list = [];
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
if ($access_url_id == 0) {
|
||||
Display::addFlash(Display::return_message(get_lang('SelectURL')));
|
||||
header('Location: access_url_edit_users_to_url.php');
|
||||
} elseif (is_array($course_list)) {
|
||||
UrlManager::update_urls_rel_usergroup($course_list, $access_url_id);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: access_urls.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('view_more_stats.gif', get_lang('AddUserGroupToURL'), ''),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_add_usergroup_to_url.php'
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
$noUserGroupList = $userGroupList = [];
|
||||
$ajax_search = $add_type === 'unique' ? true : false;
|
||||
|
||||
if ($ajax_search) {
|
||||
$userGroups = UrlManager::get_url_rel_usergroup_data($access_url_id);
|
||||
foreach ($userGroups as $item) {
|
||||
$userGroupList[$item['id']] = $item;
|
||||
}
|
||||
} else {
|
||||
$userGroups = UrlManager::get_url_rel_usergroup_data();
|
||||
|
||||
foreach ($userGroups as $item) {
|
||||
if ($item['access_url_id'] == $access_url_id) {
|
||||
$userGroupList[$item['id']] = $item;
|
||||
}
|
||||
}
|
||||
$noUserGroupList = $userGroup->getUserGroupNotInList(array_keys($userGroupList));
|
||||
}
|
||||
|
||||
$link_add_type_unique = ['class' => 'disabled'];
|
||||
$link_add_type_multiple = [];
|
||||
|
||||
if ($add_type === 'multiple') {
|
||||
$link_add_type_unique = [];
|
||||
$link_add_type_multiple = ['class' => 'disabled'];
|
||||
}
|
||||
?>
|
||||
<div class="btn-toolbar">
|
||||
<div class="btn-group">
|
||||
<?php
|
||||
echo Display::toolbarButton(
|
||||
get_lang('SessionAddTypeUnique'),
|
||||
api_get_self().'?'.http_build_query([
|
||||
'add_type' => 'unique',
|
||||
'access_url_id' => $access_url_id,
|
||||
]),
|
||||
'file-o',
|
||||
'default',
|
||||
$link_add_type_unique
|
||||
);
|
||||
echo Display::toolbarButton(
|
||||
get_lang('SessionAddTypeMultiple'),
|
||||
api_get_self().'?'.http_build_query([
|
||||
'add_type' => 'multiple',
|
||||
'access_url_id' => $access_url_id,
|
||||
]),
|
||||
'files-o',
|
||||
'default',
|
||||
$link_add_type_multiple
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$url_list = UrlManager::get_url_data();
|
||||
?>
|
||||
<form
|
||||
name="formulaire"
|
||||
method="post"
|
||||
action="<?php echo api_get_self(); ?>"
|
||||
style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
} ?>
|
||||
>
|
||||
<div class="row">
|
||||
<div class="col-xs-2">
|
||||
<label for="access_url_id"><?php echo get_lang('SelectUrl'); ?></label>
|
||||
</div>
|
||||
<div class="col-xs-5">
|
||||
<select name="access_url_id" id="access_url_id" onchange="javascript:send();" class="form-control">
|
||||
<option value="0">-- <?php echo get_lang('SelectUrl'); ?> --</option>
|
||||
<?php
|
||||
$url_selected = '';
|
||||
foreach ($url_list as $url_obj) {
|
||||
$checked = '';
|
||||
if (!empty($access_url_id)) {
|
||||
if ($url_obj[0] == $access_url_id) {
|
||||
$checked = 'selected=true';
|
||||
$url_selected = $url_obj[1];
|
||||
}
|
||||
}
|
||||
if ($url_obj['active'] == 1) {
|
||||
?>
|
||||
<option <?php echo $checked; ?>
|
||||
value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="form_sent" value="1"/>
|
||||
<input type="hidden" name="add_type" value="<?php echo $add_type; ?>"/>
|
||||
<?php
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'normal'); //main API
|
||||
}
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-5">
|
||||
<label for="<?php echo $ajax_search ? 'course_to_add' : 'origin_users'; ?>"><?php echo get_lang('UserGroupListInPlatform'); ?></label>
|
||||
<div id="content_source">
|
||||
<?php if ($ajax_search) {
|
||||
?>
|
||||
<input type="text" id="course_to_add" class="form-control"
|
||||
onkeyup="xajax_searchUserGroupAjax(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)"/>
|
||||
<div id="ajax_list_courses"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<select id="origin_users" name="no_course_list[]" multiple="multiple" size="15" class="form-control">
|
||||
<?php foreach ($noUserGroupList as $noItem) {
|
||||
?>
|
||||
<option value="<?php echo $noItem['id']; ?>"><?php echo $noItem['name']; ?></option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
<?php
|
||||
} ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-2 text-center">
|
||||
<br><br><br><br>
|
||||
<?php if ($ajax_search) {
|
||||
?>
|
||||
<button class="btn btn-default" type="button"
|
||||
onclick="remove_item(document.getElementById('destination_users'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<button class="btn btn-default" type="button"
|
||||
onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br/><br/>
|
||||
<button class="btn btn-default" type="button"
|
||||
onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} ?>
|
||||
</div>
|
||||
<div class="col-sm-5">
|
||||
<label for="destination_users"><?php printf(get_lang('UserGroupListInX'), $url_selected); ?></label>
|
||||
<select id="destination_users" name="course_list[]" multiple="multiple" size="15" class="form-control">
|
||||
<?php foreach ($userGroupList as $item) {
|
||||
?>
|
||||
<option value="<?php echo $item['id']; ?>">
|
||||
<?php echo $item['name']; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 text-center">
|
||||
<button class="save btn btn-primary" onclick="valide()">
|
||||
<span class="fa fa-save fa-fw" aria-hidden="true"></span>
|
||||
<?php echo isset($_GET['add']) ? get_lang('AddUserGroupToURL') : get_lang('EditUserGroupToURL'); ?>
|
||||
</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();
|
||||
443
main/admin/access_url_edit_users_to_url.php
Normal file
443
main/admin/access_url_edit_users_to_url.php
Normal file
@@ -0,0 +1,443 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction(['search_users', 'AccessUrlEditUsersToUrl', 'search_users']);
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_global_admin_script();
|
||||
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
// setting breadcrumbs
|
||||
$tool_name = get_lang('EditUsersToURL');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$access_url_id = 1;
|
||||
if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id'] != '') {
|
||||
$access_url_id = Security::remove_XSS($_REQUEST['access_url_id']);
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function add_user_to_url(code, content) {
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users").innerHTML = "";
|
||||
destination = document.getElementById("destination_users");
|
||||
destination.options[destination.length] = new Option(content,code);
|
||||
destination.selectedIndex = -1;
|
||||
sortOptions(destination.options);
|
||||
}
|
||||
|
||||
function send() {
|
||||
if (document.formulaire.access_url_id.value!=0) {
|
||||
document.formulaire.form_sent.value=0;
|
||||
document.formulaire.add_type.value=\''.$add_type.'\';
|
||||
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>';
|
||||
|
||||
$errorMsg = '';
|
||||
$message = '';
|
||||
$userGroup = new UserGroup();
|
||||
$allUserGroup = $userGroup->get_all_group_tags();
|
||||
$checkList = [];
|
||||
$join = '';
|
||||
$where = '';
|
||||
|
||||
if (isset($_POST['form_sent'])) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$UserList = ($_POST['sessionUsersList'] ?? []);
|
||||
|
||||
if (!is_array($UserList)) {
|
||||
$UserList = [];
|
||||
}
|
||||
if ($form_sent == 0) {
|
||||
$tblUsergroupRelUser = Database::get_main_table(TABLE_USERGROUP_REL_USER);
|
||||
if (isset($_POST['no_any_class'])) {
|
||||
$where = "AND u.id NOT IN(SELECT g.user_id FROM $tblUsergroupRelUser g)";
|
||||
} else {
|
||||
foreach ($allUserGroup as $userGroup) {
|
||||
if (isset($_POST[$userGroup['id']])) {
|
||||
$checkList[] = $userGroup['id'];
|
||||
$where .= $userGroup['id'].',';
|
||||
}
|
||||
}
|
||||
if (count($checkList) > 0) {
|
||||
$join = "INNER JOIN $tblUsergroupRelUser g ON u.user_id = g.user_id";
|
||||
$where = trim($where, ',');
|
||||
$where = "AND g.usergroup_id IN($where)";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($form_sent == 1) {
|
||||
if ($access_url_id == 0) {
|
||||
Display::addFlash(Display::return_message(get_lang('SelectURL')));
|
||||
header('Location: access_url_edit_users_to_url.php');
|
||||
exit;
|
||||
} elseif (is_array($UserList)) {
|
||||
$result = UrlManager::update_urls_rel_user($UserList, $access_url_id);
|
||||
$url_info = UrlManager::get_url_data_from_id($access_url_id);
|
||||
if (!empty($result)) {
|
||||
$message .= 'URL: '.$url_info['url'].'<br />';
|
||||
}
|
||||
|
||||
if (!empty($result['users_added'])) {
|
||||
$message .= '<h4>'.get_lang('UsersAdded').':</h4>';
|
||||
$i = 1;
|
||||
$user_added_list = [];
|
||||
foreach ($result['users_added'] as $user) {
|
||||
$user_info = api_get_user_info($user);
|
||||
if (!empty($user_info)) {
|
||||
$user_added_list[] = $i.'. '.api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, null, $user_info['username']);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if (!empty($user_added_list)) {
|
||||
$message .= implode(', ', $user_added_list);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($result['users_deleted'])) {
|
||||
$message .= '<br /><h4>'.get_lang('UsersDeleted').': </h4>';
|
||||
$user_deleted_list = [];
|
||||
$i = 1;
|
||||
foreach ($result['users_deleted'] as $user) {
|
||||
$user_info = api_get_user_info($user);
|
||||
if (!empty($user_info)) {
|
||||
$user_deleted_list[] = $i.'. '.api_get_person_name($user_info['firstname'], $user_info['lastname']);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if (!empty($user_deleted_list)) {
|
||||
$message .= implode(', ', $user_deleted_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!empty($message)) {
|
||||
echo Display::return_message($message, 'normal', false);
|
||||
}
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('view_more_stats.gif', get_lang('AddUserToURL'), ''),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_add_users_to_url.php'
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
api_display_tool_title($tool_name);
|
||||
|
||||
$nosessionUsersList = $sessionUsersList = [];
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
$showAndOrderByOfficialCode = api_get_configuration_value('multiple_access_url_user_management_show_and_order_by_official_code');
|
||||
|
||||
if ($ajax_search) {
|
||||
$Users = UrlManager::get_url_rel_user_data($access_url_id, null, $join, $where);
|
||||
foreach ($Users as $user) {
|
||||
$sessionUsersList[$user['user_id']] = $user;
|
||||
}
|
||||
} else {
|
||||
if ($showAndOrderByOfficialCode) {
|
||||
$order_clause = 'ORDER BY official_code, username';
|
||||
} else {
|
||||
$order_clause = api_sort_by_first_name() ? ' ORDER BY username, firstname, lastname' : ' ORDER BY username, lastname, firstname';
|
||||
}
|
||||
|
||||
$Users = UrlManager::get_url_rel_user_data(null, $order_clause);
|
||||
foreach ($Users as $user) {
|
||||
if ($user['access_url_id'] == $access_url_id) {
|
||||
$sessionUsersList[$user['user_id']] = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT u.user_id, lastname, firstname, username, official_code
|
||||
FROM $tbl_user u
|
||||
$join
|
||||
WHERE u.status <> ".ANONYMOUS."
|
||||
$where
|
||||
$order_clause";
|
||||
$result = Database::query($sql);
|
||||
$Users = Database::store_result($result);
|
||||
$user_list_leys = array_keys($sessionUsersList);
|
||||
foreach ($Users as $user) {
|
||||
if (!in_array($user['user_id'], $user_list_leys)) {
|
||||
$nosessionUsersList[$user['user_id']] = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique = '<a href="'.api_get_self().'?add_type=unique&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeUnique').'</a>';
|
||||
$link_add_type_multiple = get_lang('SessionAddTypeMultiple');
|
||||
} else {
|
||||
$link_add_type_unique = get_lang('SessionAddTypeUnique');
|
||||
$link_add_type_multiple = '<a href="'.api_get_self().'?add_type=multiple&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
$url_list = UrlManager::get_url_data();
|
||||
?>
|
||||
|
||||
<div style="text-align: left;">
|
||||
<?php echo $link_add_type_unique; ?> | <?php echo $link_add_type_multiple; ?>
|
||||
</div>
|
||||
<br /><br />
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
} ?> >
|
||||
<?php echo get_lang('SelectUrl').' : '; ?>
|
||||
<select name="access_url_id" onchange="javascript:send();">
|
||||
<option value="0"> <?php echo get_lang('SelectUrl'); ?></option>
|
||||
<?php
|
||||
$url_selected = '';
|
||||
foreach ($url_list as $url_obj) {
|
||||
$checked = '';
|
||||
if (!empty($access_url_id)) {
|
||||
if ($url_obj['id'] == $access_url_id) {
|
||||
$checked = 'selected=true';
|
||||
$url_selected = $url_obj[1];
|
||||
}
|
||||
}
|
||||
if ($url_obj['active'] == 1) {
|
||||
?>
|
||||
<option <?php echo $checked; ?> value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br /><br />
|
||||
|
||||
<?php
|
||||
|
||||
if (count($allUserGroup) > 0) {
|
||||
echo get_lang('FilterByClass').' : ';
|
||||
echo '<ul>';
|
||||
foreach ($allUserGroup as $userGroup) {
|
||||
$checked = in_array($userGroup['id'], $checkList) ? 'checked' : '';
|
||||
echo '<li>';
|
||||
echo '<input type="checkbox" name="'.$userGroup['id'].'" value="'.$userGroup['id'].'" onclick="javascript:send();" '.$checked.'>';
|
||||
echo ' '.$userGroup['name'];
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
$checked = isset($_POST['no_any_class']) ? 'checked' : '';
|
||||
echo '<input type="checkbox" name="no_any_class" onclick="javascript:send();" '.$checked.'> ';
|
||||
echo get_lang('NotInAnyClass');
|
||||
}
|
||||
?>
|
||||
<br /><br />
|
||||
|
||||
<input type="hidden" name="form_sent" value="1" />
|
||||
<input type="hidden" name="add_type" value = "<?php echo $add_type; ?>" />
|
||||
|
||||
<?php
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'normal'); //main API
|
||||
}
|
||||
?>
|
||||
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td>
|
||||
<h3>
|
||||
<?php
|
||||
$total_users = count($nosessionUsersList) + count($sessionUsersList);
|
||||
echo get_lang('TotalAvailableUsers').' '.$total_users;
|
||||
?>
|
||||
</h3>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><b><?php echo get_lang('UserListInPlatform'); ?> : <?php echo count($nosessionUsersList); ?></b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td align="center"><b><?php echo get_lang('UserListIn').' '.$url_selected; ?> : <?php echo count($sessionUsersList); ?></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<div id="content_source">
|
||||
<?php if ($ajax_search) {
|
||||
?>
|
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)" />
|
||||
<div id="ajax_list_users"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:380px;">
|
||||
<?php
|
||||
$userOfficialCode = '';
|
||||
foreach ($nosessionUsersList as $enreg) {
|
||||
if ($showAndOrderByOfficialCode) {
|
||||
$userOfficialCode = $enreg['official_code'].' - ';
|
||||
} ?>
|
||||
<option value="<?php echo $enreg['user_id']; ?>"><?php echo $userOfficialCode.$enreg['username'].' - '.api_get_person_name($enreg['firstname'], $enreg['lastname']); ?></option>
|
||||
<?php
|
||||
}
|
||||
unset($nosessionUsersList); ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td width="10%" valign="middle" align="center">
|
||||
<?php if ($ajax_search) {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('destination_users'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))" >
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br /><br />
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))" >
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
|
||||
</button>
|
||||
<?php
|
||||
} ?>
|
||||
<br /><br /><br /><br /><br /><br />
|
||||
</td>
|
||||
<td align="center">
|
||||
<select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15" style="width:380px;">
|
||||
<?php
|
||||
foreach ($sessionUsersList as $enreg) {
|
||||
if ($showAndOrderByOfficialCode) {
|
||||
$userOfficialCode = $enreg['official_code'].' - ';
|
||||
} ?>
|
||||
<option value="<?php echo $enreg['user_id']; ?>">
|
||||
<?php echo $userOfficialCode.$enreg['username'].' - '.api_get_person_name($enreg['firstname'], $enreg['lastname']); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
unset($sessionUsersList);
|
||||
?>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<br />
|
||||
<?php
|
||||
if (isset($_GET['add'])) {
|
||||
echo '<button class="save" type="button" onclick="valide()" >'.get_lang('AddUsersToURL').'</button>';
|
||||
} else {
|
||||
echo '<button class="save" type="button" onclick="valide()" >'.get_lang('EditUsersToURL').'</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('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();
|
||||
187
main/admin/access_urls.php
Normal file
187
main/admin/access_urls.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Frontend script for multiple access urls.
|
||||
*
|
||||
* @author Julio Montoya <gugli100@gmail.com>
|
||||
* @author Yannick Warnier <yannick.warnier@beeznest.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
//api_protect_admin_script();
|
||||
api_protect_global_admin_script();
|
||||
|
||||
if (!api_get_multiple_access_url()) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$tool_name = get_lang('MultipleAccessURLs');
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$my_user_url_list = api_get_access_url_from_user(api_get_user_id());
|
||||
$current_access_url_id = api_get_current_access_url_id();
|
||||
$url_list = UrlManager::get_url_data();
|
||||
|
||||
// Actions
|
||||
if (isset($_GET['action'])) {
|
||||
$url_id = empty($_GET['url_id']) ? 0 : (int) $_GET['url_id'];
|
||||
|
||||
switch ($_GET['action']) {
|
||||
case 'delete_url':
|
||||
$result = UrlManager::delete($url_id);
|
||||
if ($result) {
|
||||
echo Display::return_message(get_lang('URLDeleted'), 'normal');
|
||||
} else {
|
||||
echo Display::return_message(get_lang('CannotDeleteURL'), 'error');
|
||||
}
|
||||
break;
|
||||
case 'lock':
|
||||
UrlManager::set_url_status('lock', $url_id);
|
||||
echo Display::return_message(get_lang('URLInactive'), 'normal');
|
||||
break;
|
||||
case 'unlock':
|
||||
UrlManager::set_url_status('unlock', $url_id);
|
||||
echo Display::return_message(get_lang('URLActive'), 'normal');
|
||||
break;
|
||||
case 'register':
|
||||
// we are going to register the admin
|
||||
if (api_is_platform_admin()) {
|
||||
if ($current_access_url_id != -1) {
|
||||
$url_str = '';
|
||||
foreach ($url_list as $my_url) {
|
||||
if (!in_array($my_url['id'], $my_user_url_list)) {
|
||||
UrlManager::add_user_to_url(api_get_user_id(), $my_url['id']);
|
||||
$url_str .= $my_url['url'].' <br />';
|
||||
}
|
||||
}
|
||||
echo Display::return_message(
|
||||
get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',
|
||||
'normal',
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$parameters['sec_token'] = Security::get_token();
|
||||
|
||||
// Checking if the admin is registered in all sites
|
||||
$url_string = '';
|
||||
$my_user_url_list = api_get_access_url_from_user(api_get_user_id());
|
||||
foreach ($url_list as $my_url) {
|
||||
if (!in_array($my_url['id'], $my_user_url_list)) {
|
||||
$url_string .= $my_url['url'].' <br />';
|
||||
}
|
||||
}
|
||||
if (!empty($url_string)) {
|
||||
echo Display::return_message(
|
||||
get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,
|
||||
'warning',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
// checking the current installation
|
||||
if ($current_access_url_id == -1) {
|
||||
echo Display::return_message(
|
||||
get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH),
|
||||
'warning'
|
||||
);
|
||||
} elseif (api_is_platform_admin()) {
|
||||
$quant = UrlManager::relation_url_user_exist(
|
||||
api_get_user_id(),
|
||||
$current_access_url_id
|
||||
);
|
||||
if ($quant == 0) {
|
||||
echo Display::return_message(
|
||||
'<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'.
|
||||
get_lang('ClickToRegisterAdmin').'</a>',
|
||||
'warning',
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// action menu
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('new_link.png', get_lang('AddUrl'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php'
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('user.png', get_lang('ManageUsers'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php'
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('course.png', get_lang('ManageCourses'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php'
|
||||
);
|
||||
|
||||
$userGroup = new UserGroup();
|
||||
if ($userGroup->getUseMultipleUrl()) {
|
||||
echo Display::url(
|
||||
Display::return_icon('class.png', get_lang('ManageUserGroup'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
|
||||
);
|
||||
}
|
||||
|
||||
echo Display::url(
|
||||
Display::return_icon('folder.png', get_lang('ManageCourseCategories'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/access_url_edit_course_category_to_url.php'
|
||||
);
|
||||
|
||||
echo '</div>';
|
||||
|
||||
$data = UrlManager::get_url_data();
|
||||
$urls = [];
|
||||
foreach ($data as $row) {
|
||||
// Title
|
||||
$url = Display::url($row['url'], $row['url'], ['target' => '_blank']);
|
||||
$description = $row['description'];
|
||||
$createdAt = api_get_local_time($row['tms']);
|
||||
|
||||
//Status
|
||||
$active = $row['active'];
|
||||
$action = 'unlock';
|
||||
$image = 'wrong';
|
||||
if ($active == '1') {
|
||||
$action = 'lock';
|
||||
$image = 'right';
|
||||
}
|
||||
// you cannot lock the default
|
||||
if ($row['id'] == '1') {
|
||||
$status = Display::return_icon($image.'.gif', get_lang(ucfirst($action)));
|
||||
} else {
|
||||
$status = '<a href="access_urls.php?action='.$action.'&url_id='.$row['id'].'">'.
|
||||
Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
|
||||
}
|
||||
// Actions
|
||||
$url_id = $row['id'];
|
||||
$actions = Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
|
||||
"access_url_edit.php?url_id=$url_id"
|
||||
);
|
||||
if ($url_id != '1') {
|
||||
$actions .= '<a href="access_urls.php?action=delete_url&url_id='.$url_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."'".')) return false;">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL).'</a>';
|
||||
}
|
||||
$urls[] = [$url, $description, $status, $createdAt, $actions];
|
||||
}
|
||||
|
||||
$table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls');
|
||||
$table->set_additional_parameters($parameters);
|
||||
$table->set_header(0, 'URL');
|
||||
$table->set_header(1, get_lang('Description'));
|
||||
$table->set_header(2, get_lang('Active'));
|
||||
$table->set_header(3, get_lang('CreatedAt'));
|
||||
$table->set_header(4, get_lang('Modify'), false);
|
||||
$table->display();
|
||||
|
||||
Display::display_footer();
|
||||
341
main/admin/add_courses_to_usergroup.php
Normal file
341
main/admin/add_courses_to_usergroup.php
Normal file
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
// Resetting the course id.
|
||||
$cidReset = true;
|
||||
|
||||
// Including some necessary files.
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
$usergroup = new UserGroup();
|
||||
$data = $usergroup->get($id);
|
||||
$usergroup->protectScript($data);
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search');
|
||||
|
||||
// Setting the section (for the tabs).
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Setting breadcrumbs.
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
|
||||
|
||||
// Setting the name of the tool.
|
||||
$tool_name = get_lang('SubscribeClassToCourses');
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$add = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null;
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<script>
|
||||
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>';
|
||||
|
||||
$errorMsg = '';
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = (int) $_POST['form_sent'];
|
||||
$elements_posted = Security::remove_XSS($_POST['elements_in_name']);
|
||||
if (!is_array($elements_posted)) {
|
||||
$elements_posted = [];
|
||||
}
|
||||
if ($form_sent == 1) {
|
||||
$usergroup->subscribe_courses_to_usergroup($id, $elements_posted);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: usergroups.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Filters
|
||||
$filters = [
|
||||
['type' => 'text', 'name' => 'code', 'label' => get_lang('CourseCode')],
|
||||
['type' => 'text', 'name' => 'title', 'label' => get_lang('Title')],
|
||||
];
|
||||
|
||||
$searchForm = new FormValidator('search', 'get', api_get_self().'?id='.$id);
|
||||
$searchForm->addHeader(get_lang('AdvancedSearch'));
|
||||
$renderer = &$searchForm->defaultRenderer();
|
||||
$searchForm->addElement('hidden', 'id', $id);
|
||||
foreach ($filters as $param) {
|
||||
$searchForm->addElement($param['type'], $param['name'], $param['label']);
|
||||
}
|
||||
$searchForm->addButtonSearch();
|
||||
|
||||
$filterData = [];
|
||||
if ($searchForm->validate()) {
|
||||
$filterData = $searchForm->getSubmitValues();
|
||||
}
|
||||
|
||||
$conditions = [];
|
||||
if (!empty($filters) && !empty($filterData)) {
|
||||
foreach ($filters as $filter) {
|
||||
if (isset($filter['name']) && isset($filterData[$filter['name']])) {
|
||||
$value = $filterData[$filter['name']];
|
||||
if (!empty($value)) {
|
||||
$conditions[$filter['name']] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$course_list_in = $usergroup->get_courses_by_usergroup($id, true);
|
||||
|
||||
$onlyThisCourseList = [];
|
||||
if ($usergroup->allowTeachers()) {
|
||||
$userId = api_get_user_id();
|
||||
$courseList = CourseManager::getCoursesFollowedByUser($userId, COURSEMANAGER);
|
||||
if (!empty($courseList)) {
|
||||
$onlyThisCourseList = array_column($courseList, 'id');
|
||||
}
|
||||
}
|
||||
|
||||
$course_list = CourseManager::get_courses_list(
|
||||
0,
|
||||
0,
|
||||
'title',
|
||||
'asc',
|
||||
-1,
|
||||
null,
|
||||
api_get_current_access_url_id(),
|
||||
false,
|
||||
$conditions,
|
||||
$onlyThisCourseList
|
||||
);
|
||||
|
||||
$elements_not_in = $elements_in = [];
|
||||
foreach ($course_list_in as $course) {
|
||||
$elements_in[$course['id']] = $course['title']." (".$course['visual_code'].")";
|
||||
}
|
||||
|
||||
if (!empty($course_list)) {
|
||||
foreach ($course_list as $item) {
|
||||
if (isset($elements_in[$item['id']])) {
|
||||
continue;
|
||||
}
|
||||
$elements_not_in[$item['id']] = $item['title']." (".$item['visual_code'].")";
|
||||
}
|
||||
}
|
||||
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
// checking for extra field with filter on
|
||||
function search($needle, $type)
|
||||
{
|
||||
global $elements_in;
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
if ($type != 'single') {
|
||||
$list = CourseManager::get_courses_list(
|
||||
0,
|
||||
0,
|
||||
'title',
|
||||
'ASC',
|
||||
-1,
|
||||
$needle
|
||||
);
|
||||
}
|
||||
if ($type != 'single') {
|
||||
$return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">';
|
||||
|
||||
foreach ($list as $row) {
|
||||
if (!in_array($row['id'], array_keys($elements_in))) {
|
||||
$return .= '<option value="'.$row['id'].'">'.$row['title'].' ('.$row['visual_code'].')</option>';
|
||||
}
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign('ajax_list_multiple', 'innerHTML', api_utf8_encode($return));
|
||||
}
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique = '<a href="'.api_get_self().'?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().'?add='.$add.'&add_type=multiple">'.
|
||||
Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="usergroups.php">';
|
||||
echo Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM).'</a>';
|
||||
echo Display::url(get_lang('AdvancedSearch'), '#', ['class' => 'advanced_options', 'id' => 'advanced_search']);
|
||||
echo '</div>';
|
||||
|
||||
echo '<div id="advanced_search_options" style="display:none">';
|
||||
$searchForm->display();
|
||||
echo '</div>';
|
||||
?>
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($add)) {
|
||||
echo '&add=true';
|
||||
} ?>" style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
}?>>
|
||||
<?php echo '<legend>'.$data['name'].': '.$tool_name.'</legend>';
|
||||
echo Display::input('hidden', 'id', $id);
|
||||
echo Display::input('hidden', 'form_sent', '1');
|
||||
echo Display::input('hidden', 'add_type', null);
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'normal'); //main API
|
||||
}
|
||||
?>
|
||||
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td align="center"><b><?php echo get_lang('CoursesInPlatform'); ?> :</b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td align="center"><b><?php echo get_lang('CoursesInGroup'); ?> :</b></td>
|
||||
</tr>
|
||||
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php echo get_lang('FirstLetterCourseTitle'); ?> :
|
||||
<select name="firstLetterUser" onchange = "xajax_search(this.value,'multiple')" >
|
||||
<option value = "%">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options(); ?>
|
||||
</select>
|
||||
</td>
|
||||
<td align="center"> </td>
|
||||
</tr>
|
||||
<?php
|
||||
} ?>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<div id="content_source">
|
||||
<?php
|
||||
if (!($add_type == 'multiple')) {
|
||||
?>
|
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
|
||||
<div id="ajax_list_users_single"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="ajax_list_multiple">
|
||||
<?php
|
||||
echo Display::select(
|
||||
'elements_not_in_name',
|
||||
$elements_not_in,
|
||||
'',
|
||||
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_not_in', 'size' => '15px'],
|
||||
false
|
||||
); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td width="10%" valign="middle" align="center">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<button class="btn bt-default" type="button" onclick="remove_item(document.getElementById('elements_in'))" >
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))">
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br /><br />
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<br /><br /><br /><br /><br /><br />
|
||||
</td>
|
||||
<td align="center">
|
||||
<?php
|
||||
echo Display::select(
|
||||
'elements_in_name[]',
|
||||
$elements_in,
|
||||
'',
|
||||
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_in', 'size' => '15px'],
|
||||
false
|
||||
);
|
||||
unset($sessionUsersList);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<br />
|
||||
<?php
|
||||
echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('SubscribeClassToCourses').'</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('elements_in').options;
|
||||
for (i = 0 ; i<options.length ; i++)
|
||||
options[i].selected = true;
|
||||
document.forms.formulaire.submit();
|
||||
}
|
||||
|
||||
</script>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
103
main/admin/add_drh_to_user.php
Normal file
103
main/admin/add_drh_to_user.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\UserRelUser;
|
||||
use Chamilo\UserBundle\Entity\User as UserEntity;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
if (!isset($_REQUEST['u'])) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$em = Database::getManager();
|
||||
$userRepository = UserManager::getRepository();
|
||||
/** @var UserEntity $user */
|
||||
$user = UserManager::getManager()->find($_REQUEST['u']);
|
||||
|
||||
if (!$user) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$subscribedUsers = $userRepository->getAssignedHrmUserList(
|
||||
$user->getId(),
|
||||
api_get_current_access_url_id()
|
||||
);
|
||||
|
||||
$hrmOptions = [];
|
||||
/** @var UserRelUser $subscribedUser */
|
||||
foreach ($subscribedUsers as $subscribedUser) {
|
||||
/** @var UserEntity $hrm */
|
||||
$hrm = UserManager::getManager()->find($subscribedUser->getFriendUserId());
|
||||
|
||||
if (!$hrm) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$hrmOptions[$hrm->getId()] = UserManager::formatUserFullName($hrm, true);
|
||||
}
|
||||
|
||||
$form = new FormValidator('assign_hrm');
|
||||
$form->addUserAvatar('u', get_lang('User'), 'medium');
|
||||
$form->addSelectAjax(
|
||||
'hrm',
|
||||
get_lang('HrmList'),
|
||||
$hrmOptions,
|
||||
['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role']
|
||||
);
|
||||
$form->addButtonSave(get_lang('Send'));
|
||||
$form->setDefaults([
|
||||
'u' => $user,
|
||||
'hrm' => array_keys($hrmOptions),
|
||||
]);
|
||||
|
||||
if ($form->validate()) {
|
||||
/** @var UserRelUser $subscribedUser */
|
||||
foreach ($subscribedUsers as $subscribedUser) {
|
||||
$em->remove($subscribedUser);
|
||||
}
|
||||
$em->flush();
|
||||
|
||||
$values = $form->exportValues();
|
||||
|
||||
foreach ($values['hrm'] as $hrmId) {
|
||||
/** @var UserEntity $hrm */
|
||||
$hrm = UserManager::getManager()->find($hrmId);
|
||||
|
||||
if (!$hrm) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($hrm->getStatus() !== DRH) {
|
||||
continue;
|
||||
}
|
||||
|
||||
UserManager::subscribeUsersToHRManager($hrm->getId(), [$user->getId()], false);
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('AssignedUsersHaveBeenUpdatedSuccessfully'), 'success')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$user->getId());
|
||||
exit;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['name' => get_lang('PlatformAdmin'), 'url' => 'index.php'];
|
||||
$interbreadcrumb[] = ['name' => get_lang('UserList'), 'url' => 'user_list.php'];
|
||||
$interbreadcrumb[] = [
|
||||
'name' => UserManager::formatUserFullName($user),
|
||||
'url' => 'user_information.php?user_id='.$user->getId(),
|
||||
];
|
||||
|
||||
$toolName = get_lang('AssignHrmToUser');
|
||||
|
||||
$view = new Template($toolName);
|
||||
$view->assign('header', $toolName);
|
||||
$view->assign('content', $form->returnForm());
|
||||
$view->display_one_col_template();
|
||||
349
main/admin/add_sessions_to_promotion.php
Normal file
349
main/admin/add_sessions_to_promotion.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_sessions');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_admin_script(true);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'career_dashboard.php', 'name' => get_lang('CareersAndPromotions')];
|
||||
|
||||
// Setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeSessionsToPromotions');
|
||||
$add_type = 'multiple';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function add_user_to_session (code, content) {
|
||||
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users_single").innerHTML = "";
|
||||
|
||||
destination = document.getElementById("session_in_promotion");
|
||||
|
||||
for (i=0;i<destination.length;i++) {
|
||||
if(destination.options[i].text == content) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
destination.options[destination.length] = new Option(content,code);
|
||||
destination.selectedIndex = -1;
|
||||
sortOptions(destination.options);
|
||||
}
|
||||
function remove_item(origin) {
|
||||
for(var i = 0 ; i<origin.options.length ; i++) {
|
||||
if(origin.options[i].selected) {
|
||||
origin.options[i]=null;
|
||||
i = i-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validate_filter() {
|
||||
document.formulaire.add_type.value = \''.$add_type.'\';
|
||||
document.formulaire.form_sent.value=0;
|
||||
document.formulaire.submit();
|
||||
}
|
||||
</script>';
|
||||
|
||||
$form_sent = 0;
|
||||
$errorMsg = '';
|
||||
$users = $sessions = [];
|
||||
$promotion = new Promotion();
|
||||
$id = intval($_GET['id']);
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$session_in_promotion_posted = $_POST['session_in_promotion_name'];
|
||||
if (!is_array($session_in_promotion_posted)) {
|
||||
$session_in_promotion_posted = [$session_in_promotion_posted];
|
||||
}
|
||||
if ($form_sent == 1) {
|
||||
// Added a parameter to send emails when registering a user
|
||||
SessionManager::subscribe_sessions_to_promotion($id, $session_in_promotion_posted);
|
||||
header('Location: promotions.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$promotion_data = $promotion->get($id);
|
||||
$session_list = SessionManager::get_sessions_list([], ['name']);
|
||||
$session_not_in_promotion = $session_in_promotion = [];
|
||||
|
||||
if (!empty($session_list)) {
|
||||
foreach ($session_list as $session) {
|
||||
$promotion_id = $session['promotion_id'];
|
||||
if (isset($promotion_id) && !empty($promotion_id)) {
|
||||
if ($promotion_id == $id) {
|
||||
$session_in_promotion[$session['id']] = $session['name'];
|
||||
} else {
|
||||
$session_not_in_promotion[$session['id']] = $session['name'];
|
||||
}
|
||||
} else {
|
||||
$session_not_in_promotion[$session['id']] = $session['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$ajax_search = $add_type == 'unique' ? true : false;
|
||||
|
||||
// Checking for extra field with filter on
|
||||
|
||||
$xajax->processRequests();
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique = '<a href="'.api_get_self().'?id='.$id.'&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='.$id.'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="promotions.php">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
?>
|
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($_GET['add'])) {
|
||||
echo '&add=true';
|
||||
} ?>" style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
}?>>
|
||||
<?php echo '<legend>'.$tool_name.' '.$promotion_data['name'].'</legend>';
|
||||
|
||||
if ($add_type == 'multiple') {
|
||||
$extraField = new \ExtraField('session');
|
||||
$extra_field_list = $extraField->get_all_extra_field_by_type(ExtraField::FIELD_TYPE_SELECT);
|
||||
$new_field_list = [];
|
||||
if (is_array($extra_field_list) && (count($extra_field_list) > 0)) {
|
||||
echo '<h3>'.get_lang('FilterSessions').'</h3>';
|
||||
foreach ($extra_field_list as $new_field) {
|
||||
echo $new_field['name'];
|
||||
$varname = 'field_'.$new_field['variable'];
|
||||
echo ' <select name="'.$varname.'">';
|
||||
echo '<option value="0">--'.get_lang('Select').'--</option>';
|
||||
foreach ($new_field['data'] as $option) {
|
||||
$checked = '';
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option[1]) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo ' ';
|
||||
}
|
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
}
|
||||
echo Display::input('hidden', 'id', $id);
|
||||
echo Display::input('hidden', 'form_sent', '1');
|
||||
echo Display::input('hidden', 'add_type', null);
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'normal'); //main API
|
||||
}
|
||||
?>
|
||||
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td align="center"><b><?php echo get_lang('SessionsInPlatform'); ?> :</b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td align="center"><b><?php echo get_lang('SessionsInPromotion'); ?> :</b></td>
|
||||
</tr>
|
||||
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php echo get_lang('FirstLetterSessions'); ?> :
|
||||
<select name="firstLetterUser" onchange = "xajax_search_sessions(this.value,'multiple')" >
|
||||
<option value = "%">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options(); ?>
|
||||
</select>
|
||||
</td>
|
||||
<td align="center"> </td>
|
||||
</tr>
|
||||
<?php
|
||||
} ?>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<div id="content_source">
|
||||
<?php
|
||||
if (!($add_type == 'multiple')) {
|
||||
?>
|
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
|
||||
<div id="ajax_list_users_single"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="ajax_list_multiple">
|
||||
<?php echo Display::select('session_not_in_promotion_name', $session_not_in_promotion, '', ['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'session_not_in_promotion', 'size' => '15px'], false); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td width="10%" valign="middle" align="center">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('session_in_promotion'))" >
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('session_not_in_promotion'), document.getElementById('session_in_promotion'))" onclick="moveItem(document.getElementById('session_not_in_promotion'), document.getElementById('session_in_promotion'))">
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br /><br />
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('session_in_promotion'), document.getElementById('session_not_in_promotion'))" onclick="moveItem(document.getElementById('session_in_promotion'), document.getElementById('session_not_in_promotion'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<br /><br /><br /><br /><br /><br />
|
||||
</td>
|
||||
<td align="center">
|
||||
<?php
|
||||
echo Display::select(
|
||||
'session_in_promotion_name[]',
|
||||
$session_in_promotion,
|
||||
'',
|
||||
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'session_in_promotion', 'size' => '15px'],
|
||||
false
|
||||
);
|
||||
unset($sessionUsersList);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<br />
|
||||
<?php
|
||||
echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('SubscribeSessionsToPromotion').'</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("Your browser does not support 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();
|
||||
|
||||
function search_sessions($needle, $type)
|
||||
{
|
||||
global $session_in_promotion;
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
$session_list = SessionManager::get_sessions_list(
|
||||
['s.name' => ['operator' => 'LIKE', 'value' => "$needle%"]]
|
||||
);
|
||||
$return .= '<select id="session_not_in_promotion" name="session_not_in_promotion_name[]" multiple="multiple" size="15" style="width:360px;">';
|
||||
foreach ($session_list as $row) {
|
||||
if (!in_array($row['id'], array_keys($session_in_promotion))) {
|
||||
$return .= '<option value="'.$row['id'].'">'.$row['name'].'</option>';
|
||||
}
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign('ajax_list_multiple', 'innerHTML', api_utf8_encode($return));
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
356
main/admin/add_sessions_to_usergroup.php
Normal file
356
main/admin/add_sessions_to_usergroup.php
Normal file
@@ -0,0 +1,356 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
$usergroup = new UserGroup();
|
||||
$data = $usergroup->get($id);
|
||||
$usergroup->protectScript($data);
|
||||
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_usergroup_sessions');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeClassToSessions');
|
||||
|
||||
$add_type = 'multiple';
|
||||
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
|
||||
$add_type = Security::remove_XSS($_REQUEST['add_type']);
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function add_user_to_session (code, content) {
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users_single").innerHTML = "";
|
||||
destination = document.getElementById("elements_in");
|
||||
for (i=0;i<destination.length;i++) {
|
||||
if(destination.options[i].text == content) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
destination.options[destination.length] = new Option(content,code);
|
||||
destination.selectedIndex = -1;
|
||||
sortOptions(destination.options);
|
||||
}
|
||||
function remove_item(origin) {
|
||||
for(var i = 0 ; i<origin.options.length ; i++) {
|
||||
if(origin.options[i].selected) {
|
||||
origin.options[i]=null;
|
||||
i = i-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function display_advanced_search () {
|
||||
if ($("#advancedSearch").css("display") == "none") {
|
||||
$("#advancedSearch").css("display","block");
|
||||
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_hide.gif', get_lang('Hide'), ['style' => 'vertical-align:middle']).' '.get_lang('AdvancedSearch').'\');
|
||||
} else {
|
||||
$("#advancedSearch").css("display","none");
|
||||
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_show.gif', get_lang('Show'), ['style' => 'vertical-align:middle']).' '.get_lang('AdvancedSearch').'\');
|
||||
}
|
||||
}
|
||||
|
||||
function validate_filter() {
|
||||
document.formulaire.add_type.value = \''.$add_type.'\';
|
||||
document.formulaire.form_sent.value=0;
|
||||
document.formulaire.submit();
|
||||
}
|
||||
</script>';
|
||||
|
||||
$errorMsg = '';
|
||||
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
|
||||
$form_sent = (int) $_POST['form_sent'];
|
||||
$elements_posted = Security::remove_XSS($_POST['elements_in_name']);
|
||||
if (!is_array($elements_posted)) {
|
||||
$elements_posted = [];
|
||||
}
|
||||
if ($form_sent == 1) {
|
||||
//added a parameter to send emails when registering a user
|
||||
$usergroup->subscribe_sessions_to_usergroup($id, $elements_posted);
|
||||
header('Location: usergroups.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$session_list_in = $usergroup->get_sessions_by_usergroup($id);
|
||||
|
||||
$onlyThisSessionList = [];
|
||||
if ($usergroup->allowTeachers()) {
|
||||
$userId = api_get_user_id();
|
||||
$sessionList = SessionManager::getSessionsFollowedByUser($userId, COURSEMANAGER);
|
||||
if (!empty($sessionList)) {
|
||||
$onlyThisSessionList = array_column($sessionList, 'id');
|
||||
}
|
||||
}
|
||||
$session_list = SessionManager::get_sessions_list([], ['name'], null, null, 0, $onlyThisSessionList);
|
||||
$elements_not_in = $elements_in = [];
|
||||
|
||||
if (!empty($session_list)) {
|
||||
foreach ($session_list as $session) {
|
||||
if (in_array($session['id'], $session_list_in)) {
|
||||
$elements_in[$session['id']] = $session['name'];
|
||||
} else {
|
||||
$elements_not_in[$session['id']] = $session['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ajax_search = $add_type === 'unique' ? true : false;
|
||||
|
||||
// checking for extra field with filter on
|
||||
function search_usergroup_sessions($needle, $type)
|
||||
{
|
||||
global $elements_in;
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
if ($type == 'searchbox') {
|
||||
$session_list = SessionManager::get_sessions_list(
|
||||
['s.name' => ['operator' => 'LIKE', 'value' => "%$needle%"]]
|
||||
);
|
||||
} elseif ($type != 'single') {
|
||||
$session_list = SessionManager::get_sessions_list(
|
||||
['s.name' => ['operator' => 'LIKE', 'value' => "$needle%"]]
|
||||
);
|
||||
}
|
||||
if ($type != 'single') {
|
||||
$return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">';
|
||||
foreach ($session_list as $row) {
|
||||
if (!in_array($row['id'], array_keys($elements_in))) {
|
||||
$return .= '<option value="'.$row['id'].'">'.$row['name'].'</option>';
|
||||
}
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign(
|
||||
'ajax_list_multiple',
|
||||
'innerHTML',
|
||||
api_utf8_encode($return)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
$xajax->processRequests();
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$add = (empty($_GET['add']) ? '' : Security::remove_XSS($_GET['add']));
|
||||
if ($add_type == 'multiple') {
|
||||
$link_add_type_unique = '<a href="'.api_get_self().'?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().'?add='.$add.'&add_type=multiple">'.
|
||||
Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
|
||||
}
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="usergroups.php">'.
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '<a href="javascript://" class="advanced_parameters" style="margin-top: 8px" onclick="display_advanced_search();"><span id="img_plus_and_minus"> '.
|
||||
Display::return_icon('div_show.gif', get_lang('Show'), ['style' => 'vertical-align:middle']).' '.get_lang('AdvancedSearch').'</span></a>';
|
||||
echo '</div>';
|
||||
echo '<div id="advancedSearch" style="display: none">'.get_lang('SearchSessions'); ?> :
|
||||
<input name="SearchSession" onchange = "xajax_search_usergroup_sessions(this.value,'searchbox')" onkeyup="this.onchange()">
|
||||
</div>
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($add)) {
|
||||
echo '&add=true';
|
||||
} ?>" style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
}?>>
|
||||
<?php
|
||||
echo '<legend>'.$data['name'].': '.$tool_name.'</legend>';
|
||||
echo Display::input('hidden', 'id', $id);
|
||||
echo Display::input('hidden', 'form_sent', '1');
|
||||
echo Display::input('hidden', 'add_type', null);
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'normal'); //main API
|
||||
}
|
||||
?>
|
||||
|
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td align="center"><b><?php echo get_lang('SessionsInPlatform'); ?> :</b>
|
||||
</td>
|
||||
<td></td>
|
||||
<td align="center"><b><?php echo get_lang('SessionsInGroup'); ?> :</b></td>
|
||||
</tr>
|
||||
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php echo get_lang('FirstLetterSessions'); ?> :
|
||||
<select name="firstLetterUser" onchange = "xajax_search_usergroup_sessions(this.value,'multiple')" >
|
||||
<option value = "%">--</option>
|
||||
<?php
|
||||
echo Display::get_alphabet_options(); ?>
|
||||
</select>
|
||||
<?php echo '<br />'; ?>
|
||||
</td>
|
||||
<td align="center"> </td>
|
||||
</tr>
|
||||
<?php
|
||||
} ?>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<div id="content_source">
|
||||
<?php
|
||||
if (!($add_type == 'multiple')) {
|
||||
?>
|
||||
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
|
||||
<div id="ajax_list_users_single"></div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="ajax_list_multiple">
|
||||
<?php echo Display::select(
|
||||
'elements_not_in_name',
|
||||
$elements_not_in,
|
||||
'',
|
||||
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_not_in', 'size' => '15px'],
|
||||
false
|
||||
); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td width="10%" valign="middle" align="center">
|
||||
<?php
|
||||
if ($ajax_search) {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('elements_in'))" >
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))">
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br /><br />
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<br /><br /><br /><br /><br /><br />
|
||||
</td>
|
||||
<td align="center">
|
||||
<?php
|
||||
echo Display::select(
|
||||
'elements_in_name[]',
|
||||
$elements_in,
|
||||
'',
|
||||
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_in', 'size' => '15px'],
|
||||
false
|
||||
);
|
||||
unset($sessionUsersList);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" align="center">
|
||||
<br />
|
||||
<?php
|
||||
echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('SubscribeClassToSessions').'</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('elements_in').options;
|
||||
for (i = 0 ; i<options.length ; i++)
|
||||
options[i].selected = true;
|
||||
document.forms.formulaire.submit();
|
||||
}
|
||||
|
||||
function loadUsersInSelect(select) {
|
||||
var xhr_object = null;
|
||||
if(window.XMLHttpRequest) // Firefox
|
||||
xhr_object = new XMLHttpRequest();
|
||||
else if(window.ActiveXObject) // Internet Explorer
|
||||
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
else // XMLHttpRequest non supporté par le navigateur
|
||||
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
|
||||
|
||||
xhr_object.open("POST", "loadUsersInSelect.ajax.php");
|
||||
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
nosessionUsers = makepost(document.getElementById('elements_not_in'));
|
||||
sessionUsers = makepost(document.getElementById('elements_in'));
|
||||
nosessionClasses = makepost(document.getElementById('origin_classes'));
|
||||
sessionClasses = makepost(document.getElementById('destination_classes'));
|
||||
xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
|
||||
|
||||
xhr_object.onreadystatechange = function() {
|
||||
if(xhr_object.readyState == 4) {
|
||||
document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
646
main/admin/add_users_to_usergroup.php
Normal file
646
main/admin/add_users_to_usergroup.php
Normal file
@@ -0,0 +1,646 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
// resetting the course id
|
||||
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
$relation = isset($_REQUEST['relation']) ? (int) $_REQUEST['relation'] : 0;
|
||||
$usergroup = new UserGroup();
|
||||
$groupInfo = $usergroup->get($id);
|
||||
$usergroup->protectScript($groupInfo);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('SubscribeUsersToClass');
|
||||
$showAllStudentByDefault = api_get_configuration_value('usergroup_add_user_show_all_student_by_default');
|
||||
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
|
||||
$(function () {
|
||||
$("#relation").change(function() {
|
||||
window.location = "add_users_to_usergroup.php?id='.$id.'" +"&relation=" + $(this).val();
|
||||
});
|
||||
});
|
||||
|
||||
function activeUsers(originalUrl) {
|
||||
var searchValue = document.getElementById("first_letter_user").value;
|
||||
window.location.href = originalUrl + "&firstLetterUser=" + encodeURIComponent(searchValue);
|
||||
}
|
||||
|
||||
function add_user_to_session (code, content) {
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users_single").innerHTML = "";
|
||||
destination = document.getElementById("elements_in");
|
||||
for (i=0;i<destination.length;i++) {
|
||||
if(destination.options[i].text == content) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
destination.options[destination.length] = new Option(content,code);
|
||||
destination.selectedIndex = -1;
|
||||
sortOptions(destination.options);
|
||||
}
|
||||
function remove_item(origin) {
|
||||
for(var i = 0 ; i<origin.options.length ; i++) {
|
||||
if(origin.options[i].selected) {
|
||||
origin.options[i]=null;
|
||||
i = i-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validate_filter() {
|
||||
document.formulaire.form_sent.value=0;
|
||||
document.formulaire.submit();
|
||||
}
|
||||
|
||||
function checked_in_no_group(checked)
|
||||
{
|
||||
$("#relation")
|
||||
.find("option")
|
||||
.attr("selected", false);
|
||||
|
||||
$("#first_letter_user")
|
||||
.find("option")
|
||||
.attr("selected", false);
|
||||
document.formulaire.form_sent.value="2";
|
||||
document.formulaire.submit();
|
||||
}
|
||||
|
||||
function change_select(reset) {
|
||||
$("#user_with_any_group_id").attr("checked", false);
|
||||
document.formulaire["form_sent"].value = "2";
|
||||
|
||||
var select = $(document.formulaire["elements_not_in_name"]);
|
||||
|
||||
select.empty();
|
||||
|
||||
if (reset) {
|
||||
document.formulaire["first_letter_user"].value = "";
|
||||
|
||||
if ('.($showAllStudentByDefault ? 0 : 1).') {
|
||||
document.formulaire["form_sent"].value = "1";
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$.post("'.api_get_self().'", $(document.formulaire).serialize(), function(data) {
|
||||
document.formulaire["form_sent"].value = "1";
|
||||
|
||||
$.each(data, function(index, item) {
|
||||
select.append($("<option>", {
|
||||
value: index,
|
||||
text: item
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
</script>';
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
function showLastTenUsers() {
|
||||
var selectedUsers = [];
|
||||
$("#elements_in option").each(function() {
|
||||
selectedUsers.push($(this).val());
|
||||
});
|
||||
|
||||
var groupId = "'.$id.'";
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "'.api_get_self().'",
|
||||
data: {
|
||||
action: "get_last_ten_users",
|
||||
excludedUsers: selectedUsers,
|
||||
id: groupId
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
var select = document.getElementById("elements_not_in");
|
||||
select.innerHTML = "";
|
||||
|
||||
$.each(data, function(index, user) {
|
||||
select.append(new Option(user.username + " - " + user.firstname + " " + user.lastname, user.id));
|
||||
});
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error("Error en la solicitud AJAX: " + status + " - " + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("#show_last_ten_users_button").click(function() {
|
||||
showLastTenUsers();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$form_sent = 0;
|
||||
$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] == 4) {
|
||||
$new_field_list[] = [
|
||||
'name' => $extra_field[3],
|
||||
'variable' => $extra_field[1], 'data' => $extra_field[9],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($id)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (ChamiloApi::isAjaxRequest() && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'get_last_ten_users') {
|
||||
$excludedUsers = isset($_POST['excludedUsers']) ? $_POST['excludedUsers'] : [];
|
||||
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
|
||||
|
||||
$excludedIds = !empty($excludedUsers) ? implode(",", array_map('intval', $excludedUsers)) : '0';
|
||||
$sql = 'SELECT id, username, firstname, lastname
|
||||
FROM user
|
||||
WHERE status != '.ANONYMOUS.'
|
||||
AND id NOT IN ('.$excludedIds.')
|
||||
ORDER BY id DESC
|
||||
LIMIT 10';
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = [];
|
||||
|
||||
while ($user = Database::fetch_array($result)) {
|
||||
$users[] = [
|
||||
'id' => $user['id'],
|
||||
'username' => $user['username'],
|
||||
'firstname' => $user['firstname'],
|
||||
'lastname' => $user['lastname'],
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($users);
|
||||
exit();
|
||||
}
|
||||
|
||||
$first_letter_user = '';
|
||||
|
||||
if ((isset($_POST['form_sent']) && $_POST['form_sent']) || isset($_REQUEST['firstLetterUser'])) {
|
||||
$form_sent = $_POST['form_sent'];
|
||||
$elements_posted = $_POST['elements_in_name'] ?? null;
|
||||
$first_letter_user = Security::remove_XSS($_REQUEST['firstLetterUser']);
|
||||
|
||||
if (!is_array($elements_posted)) {
|
||||
$elements_posted = [];
|
||||
}
|
||||
|
||||
// If "social group" you need to select a role
|
||||
if ($groupInfo['group_type'] == UserGroup::SOCIAL_CLASS && empty($relation)) {
|
||||
Display::addFlash(Display::return_message(get_lang('SelectRole'), 'warning'));
|
||||
header('Location: '.api_get_self().'?id='.$id);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($form_sent == 1) {
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
// Added a parameter to send emails when registering a user
|
||||
$usergroup->subscribe_users_to_usergroup(
|
||||
$id,
|
||||
$elements_posted,
|
||||
true,
|
||||
$relation
|
||||
);
|
||||
header('Location: usergroups.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'export') {
|
||||
$users = $usergroup->getUserListByUserGroup($id);
|
||||
if (!empty($users)) {
|
||||
$data = [
|
||||
['UserName', 'ClassName'],
|
||||
];
|
||||
foreach ($users as $user) {
|
||||
$data[] = [$user['username'], $groupInfo['name']];
|
||||
}
|
||||
$filename = 'export_user_class_'.api_get_local_time();
|
||||
Export::arrayToCsv($data, $filename);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by Extra Fields
|
||||
$use_extra_fields = false;
|
||||
$extra_field_result = [];
|
||||
if (is_array($extra_field_list)) {
|
||||
if (is_array($new_field_list) && count($new_field_list) > 0) {
|
||||
foreach ($new_field_list as $new_field) {
|
||||
$varname = 'field_'.$new_field['variable'];
|
||||
if (UserManager::is_extra_field_available($new_field['variable'])) {
|
||||
if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
|
||||
$use_extra_fields = true;
|
||||
$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];
|
||||
}
|
||||
}
|
||||
|
||||
// Filters
|
||||
$filters = [
|
||||
['type' => 'text', 'name' => 'username', 'label' => get_lang('Username')],
|
||||
['type' => 'text', 'name' => 'firstname', 'label' => get_lang('FirstName')],
|
||||
['type' => 'text', 'name' => 'lastname', 'label' => get_lang('LastName')],
|
||||
['type' => 'text', 'name' => 'official_code', 'label' => get_lang('OfficialCode')],
|
||||
['type' => 'text', 'name' => 'email', 'label' => get_lang('Email')],
|
||||
];
|
||||
|
||||
$searchForm = new FormValidator('search', 'get', api_get_self().'?id='.$id);
|
||||
$searchForm->addHeader(get_lang('AdvancedSearch'));
|
||||
|
||||
$searchForm->addElement('hidden', 'id', $id);
|
||||
$searchForm->addHidden('relation', $relation);
|
||||
foreach ($filters as $param) {
|
||||
$searchForm->addElement($param['type'], $param['name'], $param['label']);
|
||||
}
|
||||
$searchForm->addButtonSearch();
|
||||
|
||||
$data = $usergroup->get($id);
|
||||
$order = ['lastname'];
|
||||
if (api_is_western_name_order()) {
|
||||
$order = ['firstname'];
|
||||
}
|
||||
|
||||
$orderListByOfficialCode = 'true' === api_get_setting('order_user_list_by_official_code');
|
||||
if ($orderListByOfficialCode) {
|
||||
$order = ['official_code', 'lastname'];
|
||||
}
|
||||
$list_in = $usergroup->getUsersByUsergroupAndRelation($id, $relation, $order);
|
||||
$list_all = $usergroup->get_users_by_usergroup();
|
||||
|
||||
$conditions = [];
|
||||
if (!empty($first_letter_user) && strlen($first_letter_user) >= 3) {
|
||||
foreach ($filters as $filter) {
|
||||
$conditions[$filter['name']] = $first_letter_user;
|
||||
}
|
||||
}
|
||||
|
||||
$activeUser = isset($_REQUEST['active_users']) ? (int) $_REQUEST['active_users'] : null;
|
||||
if (1 === $activeUser) {
|
||||
$conditions['active'] = $activeUser;
|
||||
}
|
||||
|
||||
$filterData = [];
|
||||
if ($searchForm->validate()) {
|
||||
$filterData = $searchForm->getSubmitValues();
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if (isset($filterData[$filter['name']])) {
|
||||
$value = $filterData[$filter['name']];
|
||||
if (!empty($value)) {
|
||||
$conditions[$filter['name']] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$elements_not_in = $elements_in = [];
|
||||
$hideElementsIn = [];
|
||||
foreach ($list_in as $listedUserId) {
|
||||
$userInfo = api_get_user_info($listedUserId);
|
||||
|
||||
if (1 === $activeUser && empty($userInfo['active'])) {
|
||||
$hideElementsIn[] = $listedUserId;
|
||||
continue;
|
||||
}
|
||||
|
||||
$elements_in[$listedUserId] = formatCompleteName($userInfo, $orderListByOfficialCode);
|
||||
}
|
||||
|
||||
$user_with_any_group = !empty($_REQUEST['user_with_any_group']);
|
||||
$user_list = [];
|
||||
|
||||
if (!(!$showAllStudentByDefault && !isset($_POST['firstLetterUser']) && !isset($_REQUEST['active_users'])) && !$user_with_any_group) {
|
||||
$user_list = UserManager::getUserListLike($conditions, $order, true, 'OR');
|
||||
}
|
||||
|
||||
if ($user_with_any_group) {
|
||||
$new_user_list = [];
|
||||
foreach ($user_list as $item) {
|
||||
if (!in_array($item['user_id'], $list_all)) {
|
||||
$new_user_list[] = $item;
|
||||
}
|
||||
}
|
||||
$user_list = $new_user_list;
|
||||
}
|
||||
|
||||
if (!empty($user_list)) {
|
||||
foreach ($user_list as $item) {
|
||||
if ($use_extra_fields) {
|
||||
if (!in_array($item['user_id'], $final_result)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid anonymous users
|
||||
if ($item['status'] == ANONYMOUS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_array($item['user_id'], $list_in)) {
|
||||
$elements_not_in[$item['user_id']] = formatCompleteName($item, $orderListByOfficialCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$showAllStudentByDefault && !isset($_POST['firstLetterUser']) && !isset($_REQUEST['active_users'])) {
|
||||
$elements_not_in = [];
|
||||
}
|
||||
if ($showAllStudentByDefault
|
||||
&& empty($elements_not_in)
|
||||
&& empty($first_letter_user)
|
||||
) {
|
||||
$initialUserList = UserManager::getUserListLike([], $order, true, 'OR');
|
||||
$elements_not_in = [];
|
||||
|
||||
foreach ($initialUserList as $userInfo) {
|
||||
if (!in_array($userInfo['id'], $list_in)) {
|
||||
$elements_not_in[$userInfo['id']] = formatCompleteName($userInfo, $orderListByOfficialCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function formatCompleteName(array $userInfo, bool $orderListByOfficialCode): string
|
||||
{
|
||||
if ($orderListByOfficialCode) {
|
||||
$officialCode = !empty($userInfo['official_code']) ? $userInfo['official_code'].' - ' : '? - ';
|
||||
|
||||
return $officialCode.$userInfo['complete_name_with_username'];
|
||||
}
|
||||
|
||||
$officialCode = !empty($userInfo['official_code']) ? ' - '.$userInfo['official_code'] : null;
|
||||
|
||||
return $userInfo['complete_name_with_username']." $officialCode";
|
||||
}
|
||||
|
||||
if (ChamiloApi::isAjaxRequest()) {
|
||||
JsonResponse::create($elements_not_in)->send();
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="usergroups.php">'.
|
||||
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM).'</a>';
|
||||
|
||||
echo Display::url(get_lang('AdvancedSearch'), '#', ['class' => 'advanced_options', 'id' => 'advanced_search']);
|
||||
|
||||
echo '<a href="usergroup_user_import.php">'.
|
||||
Display::return_icon('import_csv.png', get_lang('Import'), [], ICON_SIZE_MEDIUM).'</a>';
|
||||
|
||||
echo '<a href="'.api_get_self().'?id='.$id.'&action=export">'.
|
||||
Display::return_icon('export_csv.png', get_lang('Export'), [], ICON_SIZE_MEDIUM).'</a>';
|
||||
|
||||
$isActiveUser = !empty($activeUser);
|
||||
$activeUsersParam = $isActiveUser ? '0' : '1';
|
||||
$newUrl = api_get_self().'?id='.$id.'&active_users='.$activeUsersParam;
|
||||
$buttonLabelKey = $isActiveUser ? 'ShowAllUsers' : 'OnlyShowActiveUsers';
|
||||
$buttonLabel = get_lang($buttonLabelKey);
|
||||
|
||||
echo '<a href="#" onclick="activeUsers(\''.htmlspecialchars($newUrl).'\'); return false;" class="btn btn-default">'.$buttonLabel.'</a>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div id="advanced_search_options" style="display:none">';
|
||||
$searchForm->display();
|
||||
echo '</div>';
|
||||
?>
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id;
|
||||
if (!empty($_GET['add'])) {
|
||||
echo '&add=true';
|
||||
} ?>" style="margin:0px;">
|
||||
<?php
|
||||
echo '<legend>'.$tool_name.': '.$data['name'].'</legend>';
|
||||
|
||||
if (is_array($extra_field_list)) {
|
||||
if (is_array($new_field_list) && count($new_field_list) > 0) {
|
||||
echo '<h3>'.get_lang('FilterByUser').'</h3>';
|
||||
foreach ($new_field_list as $new_field) {
|
||||
echo $new_field['name'];
|
||||
$varname = 'field_'.$new_field['variable'];
|
||||
echo ' <select name="'.$varname.'">';
|
||||
echo '<option value="0">--'.get_lang('Select').'--</option>';
|
||||
foreach ($new_field['data'] as $option) {
|
||||
$checked = '';
|
||||
if (isset($_POST[$varname])) {
|
||||
if ($_POST[$varname] == $option[1]) {
|
||||
$checked = 'selected="true"';
|
||||
}
|
||||
}
|
||||
echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo ' ';
|
||||
}
|
||||
echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
}
|
||||
|
||||
echo Display::input('hidden', 'id', $id);
|
||||
echo Display::input('hidden', 'form_sent', '1');
|
||||
echo Display::input('hidden', 'add_type', null);
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<?php if ($data['group_type'] == UserGroup::SOCIAL_CLASS) {
|
||||
?>
|
||||
<select name="relation" id="relation" class="form-control">
|
||||
<option value=""><?php echo get_lang('SelectARelationType'); ?></option>
|
||||
<option
|
||||
value="<?php echo GROUP_USER_PERMISSION_ADMIN; ?>" <?php echo (isset($relation) && $relation == GROUP_USER_PERMISSION_ADMIN) ? 'selected=selected' : ''; ?> >
|
||||
<?php echo get_lang('Admin'); ?></option>
|
||||
<option
|
||||
value="<?php echo GROUP_USER_PERMISSION_READER; ?>" <?php echo (isset($relation) && $relation == GROUP_USER_PERMISSION_READER) ? 'selected=selected' : ''; ?> >
|
||||
<?php echo get_lang('Reader'); ?></option>
|
||||
<option
|
||||
value="<?php echo GROUP_USER_PERMISSION_PENDING_INVITATION; ?>" <?php echo (isset($relation) && $relation == GROUP_USER_PERMISSION_PENDING_INVITATION) ? 'selected=selected' : ''; ?> >
|
||||
<?php echo get_lang('PendingInvitation'); ?></option>
|
||||
<option
|
||||
value="<?php echo GROUP_USER_PERMISSION_MODERATOR; ?>" <?php echo (isset($relation) && $relation == GROUP_USER_PERMISSION_MODERATOR) ? 'selected=selected' : ''; ?> >
|
||||
<?php echo get_lang('Moderator'); ?></option>
|
||||
<option
|
||||
value="<?php echo GROUP_USER_PERMISSION_HRM; ?>" <?php echo (isset($relation) && $relation == GROUP_USER_PERMISSION_HRM) ? 'selected=selected' : ''; ?> >
|
||||
<?php echo get_lang('Drh'); ?></option>
|
||||
</select>
|
||||
<?php
|
||||
} ?>
|
||||
|
||||
<div class="multiple_select_header">
|
||||
<b><?php echo get_lang('UsersInPlatform'); ?> :</b>
|
||||
<div class="input-group">
|
||||
<input id="first_letter_user" name="firstLetterUser" type="text" class="form-control"
|
||||
value="<?php echo Security::remove_XSS($first_letter_user); ?>"
|
||||
placeholder="<?php echo get_lang('Search'); ?>"
|
||||
onkeydown="return 13 !== event.keyCode;">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="button" onclick="change_select();">
|
||||
<?php echo get_lang('Filter'); ?>
|
||||
</button>
|
||||
<button class="btn btn-default" type="button" onclick="change_select(true);">
|
||||
<?php echo get_lang('Reset'); ?>
|
||||
</button>
|
||||
</span>
|
||||
<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>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
echo Display::select(
|
||||
'elements_not_in_name',
|
||||
$elements_not_in,
|
||||
'',
|
||||
[
|
||||
'class' => 'form-control',
|
||||
'multiple' => 'multiple',
|
||||
'id' => 'elements_not_in',
|
||||
'size' => '15px',
|
||||
],
|
||||
false
|
||||
);
|
||||
?>
|
||||
<br/>
|
||||
<label class="control-label">
|
||||
<input type="checkbox" <?php if ($user_with_any_group) {
|
||||
echo 'checked="checked"';
|
||||
} ?> onchange="checked_in_no_group(this.checked);" name="user_with_any_group" id="user_with_any_group_id">
|
||||
<?php echo get_lang('UsersRegisteredInAnyGroup'); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div style="padding-top:54px;width:auto;text-align: center;">
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))">
|
||||
<em class="fa fa-arrow-right"></em>
|
||||
</button>
|
||||
<br/><br/>
|
||||
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))">
|
||||
<em class="fa fa-arrow-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<div class="multiple_select_header">
|
||||
<b><?php echo get_lang('UsersInGroup'); ?> :</b>
|
||||
</div>
|
||||
<?php
|
||||
echo Display::select(
|
||||
'elements_in_name[]',
|
||||
$elements_in,
|
||||
'',
|
||||
[
|
||||
'class' => 'form-control',
|
||||
'multiple' => 'multiple',
|
||||
'id' => 'elements_in',
|
||||
'size' => '15px',
|
||||
],
|
||||
false
|
||||
);
|
||||
unset($sessionUsersList);
|
||||
if (!empty($hideElementsIn)) {
|
||||
foreach ($hideElementsIn as $hideElementId) {
|
||||
echo '<input type="hidden" name="elements_in_name[]" value="'.$hideElementId.'">';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (isset($activeUser)) { ?>
|
||||
<input type="hidden" name="active_users" value="<?php echo $activeUser; ?>" >;
|
||||
<?php } ?>
|
||||
<?php
|
||||
echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" ><em class="fa fa-check"></em>'.
|
||||
get_lang('SubscribeUsersToClass').'</button>';
|
||||
?>
|
||||
</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 = [];
|
||||
for (i = 0; i < options.length; i++)
|
||||
newOptions[i] = options[i];
|
||||
|
||||
newOptions = newOptions.sort(mysort);
|
||||
options.length = 0;
|
||||
for (i = 0; i < newOptions.length; i++)
|
||||
options[i] = newOptions[i];
|
||||
}
|
||||
|
||||
function mysort(a, b) {
|
||||
if (a.text.toLowerCase() > b.text.toLowerCase()) {
|
||||
return 1;
|
||||
}
|
||||
if (a.text.toLowerCase() < b.text.toLowerCase()) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function valide() {
|
||||
var options = document.getElementById('elements_in').options;
|
||||
for (i = 0; i < options.length; i++)
|
||||
options[i].selected = true;
|
||||
document.forms.formulaire.submit();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
90
main/admin/archive_cleanup.php
Normal file
90
main/admin/archive_cleanup.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
ini_set('memory_limit', -1);
|
||||
ini_set('max_execution_time', 0);
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_admin_script(true);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$form = new FormValidator(
|
||||
'archive_cleanup_form',
|
||||
'post',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_BOX
|
||||
);
|
||||
$form->addButtonSend(get_lang('ArchiveDirCleanupProceedButton'));
|
||||
|
||||
if ($form->validate()) {
|
||||
if (function_exists('opcache_reset')) {
|
||||
opcache_reset();
|
||||
}
|
||||
|
||||
$file = api_get_path(SYS_PUBLIC_PATH).'build/main.js';
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
$dir = api_get_path(SYS_PUBLIC_PATH).'build';
|
||||
$files = scandir($dir);
|
||||
foreach ($files as $file) {
|
||||
if (preg_match('/main\..*\.js/', $file)) {
|
||||
unlink($dir.'/'.$file);
|
||||
}
|
||||
}
|
||||
|
||||
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
|
||||
$htaccess = <<<TEXT
|
||||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order deny,allow
|
||||
Deny from all
|
||||
</IfModule>
|
||||
# pChart generated files should be allowed
|
||||
<FilesMatch "^[0-9a-f]+$">
|
||||
order allow,deny
|
||||
allow from all
|
||||
</FilesMatch>
|
||||
php_flag engine off
|
||||
TEXT;
|
||||
|
||||
$result = rmdirr($archive_path, true, true);
|
||||
if (false === $result) {
|
||||
Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupFailed'), 'error'));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('ArchiveDirCleanupSucceeded')));
|
||||
}
|
||||
try {
|
||||
\Chamilo\CoreBundle\Composer\ScriptHandler::dumpCssFiles();
|
||||
Display::addFlash(Display::return_message(get_lang('WebFolderRefreshSucceeded')));
|
||||
} catch (Exception $e) {
|
||||
Display::addFlash(Display::return_message(get_lang('WebFolderRefreshFailed'), 'error'));
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
|
||||
if (!empty($htaccess)) {
|
||||
@file_put_contents($archive_path.'/.htaccess', $htaccess);
|
||||
}
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::display_header(get_lang('ArchiveDirCleanup'));
|
||||
echo Display::return_message(get_lang('ArchiveDirCleanupDescr'), 'warning');
|
||||
$form->display();
|
||||
Display::display_footer();
|
||||
195
main/admin/career_dashboard.php
Normal file
195
main/admin/career_dashboard.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Careers dashboard.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
|
||||
$useCareerHierarchy = api_get_configuration_value('career_hierarchy_enable');
|
||||
|
||||
api_protect_admin_script($allowCareer);
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
//Adds the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'career_dashboard.php',
|
||||
'name' => get_lang('CareersAndPromotions'),
|
||||
];
|
||||
$tpl = new Template(get_lang('CareersAndPromotions'));
|
||||
|
||||
$html = null;
|
||||
$showHierarchy = $_GET['showHierarchy'] ?? null;
|
||||
if ($useCareerHierarchy && is_null($showHierarchy)) {
|
||||
$showHierarchy = 1;
|
||||
} elseif (!$useCareerHierarchy) {
|
||||
$showHierarchy = 0;
|
||||
}
|
||||
$form = new FormValidator('filter_form', 'GET', api_get_self());
|
||||
|
||||
$career = new Career();
|
||||
|
||||
$condition = ['status = ?' => 1];
|
||||
if ($form->validate()) {
|
||||
$data = $form->getSubmitValues();
|
||||
$filter = (int) $data['filter'];
|
||||
if (!empty($filter) && $showHierarchy == 0) {
|
||||
$condition = ['status = ? AND id = ? ' => [1, $filter]];
|
||||
}
|
||||
}
|
||||
|
||||
$careers = $career->get_all(['status = ?' => 1]); //only status =1
|
||||
$career_select_list = [];
|
||||
$career_select_list[0] = ' -- '.get_lang('Select').' --';
|
||||
foreach ($careers as $item) {
|
||||
$career_select_list[$item['id']] = $item['name'];
|
||||
}
|
||||
|
||||
$form->addSelect(
|
||||
'filter',
|
||||
get_lang('Career'),
|
||||
$career_select_list,
|
||||
['id' => 'filter_1']
|
||||
);
|
||||
$form->addButtonSearch(get_lang('Filter'));
|
||||
|
||||
if ($useCareerHierarchy && $showHierarchy == 1) {
|
||||
$form->addHidden('showHierarchy', '1');
|
||||
} else {
|
||||
$form->addHidden('showHierarchy', '0');
|
||||
}
|
||||
// action links
|
||||
$actionLeft = Display::url(
|
||||
Display::return_icon(
|
||||
'back.png',
|
||||
get_lang('BackTo').' '.get_lang('PlatformAdmin'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
'../admin/index.php'
|
||||
);
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'career.png',
|
||||
get_lang('Careers'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
'careers.php'
|
||||
);
|
||||
if ($useCareerHierarchy) {
|
||||
if ($showHierarchy) {
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'forum_listview.png',
|
||||
get_lang('HideCareersHierarchy'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
'career_dashboard.php?showHierarchy=0'
|
||||
);
|
||||
} else {
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'forum_nestedview.png',
|
||||
get_lang('ShowCareersHierarchy'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
'career_dashboard.php?showHierarchy=1'
|
||||
);
|
||||
}
|
||||
}
|
||||
if (api_is_platform_admin()) {
|
||||
$actionLeft .= Display::url(
|
||||
Display::return_icon(
|
||||
'promotion.png',
|
||||
get_lang('Promotions'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
'promotions.php'
|
||||
);
|
||||
}
|
||||
|
||||
$actions = Display::toolbarAction('toolbar-career', [$actionLeft]);
|
||||
$html .= $form->returnForm();
|
||||
$careers = $career->get_all($condition); //only status =1
|
||||
|
||||
$column_count = 3;
|
||||
$i = 0;
|
||||
$grid_js = '';
|
||||
$career_array = [];
|
||||
|
||||
if (!empty($careers)) {
|
||||
foreach ($careers as $career_item) {
|
||||
$promotion = new Promotion();
|
||||
// Getting all promotions
|
||||
$promotions = $promotion->get_all_promotions_by_career_id(
|
||||
$career_item['id'],
|
||||
'name ASC'
|
||||
);
|
||||
$career_content = '';
|
||||
$promotion_array = [];
|
||||
if (!empty($promotions)) {
|
||||
foreach ($promotions as $promotion_item) {
|
||||
if ($promotion_item['status'] == 0) {
|
||||
continue; //avoid status = 0
|
||||
}
|
||||
|
||||
$session_list = [];
|
||||
// Getting all sessions from this promotion
|
||||
if (!$useCareerHierarchy || 0 == $showHierarchy) {
|
||||
$sessions = SessionManager::get_all_sessions_by_promotion(
|
||||
$promotion_item['id']
|
||||
);
|
||||
foreach ($sessions as $session_item) {
|
||||
$course_list = SessionManager::get_course_list_by_session_id($session_item['id']);
|
||||
$session_list[] = [
|
||||
'data' => $session_item,
|
||||
'courses' => $course_list,
|
||||
];
|
||||
}
|
||||
}
|
||||
$promotion_array[$promotion_item['id']] = [
|
||||
'id' => $promotion_item['id'],
|
||||
'name' => $promotion_item['name'],
|
||||
'sessions' => $session_list,
|
||||
];
|
||||
}
|
||||
}
|
||||
$career_array[$career_item['id']] = [
|
||||
'name' => $career_item['name'],
|
||||
'promotions' => $promotion_array,
|
||||
];
|
||||
$careerList = [
|
||||
'promotions' => $promotion_array,
|
||||
];
|
||||
$careers[$career_item['id']]['career'] = $careerList;
|
||||
}
|
||||
}
|
||||
if ($useCareerHierarchy && 1 == $showHierarchy) {
|
||||
$filter = $filter ?? 0;
|
||||
$careers = $career->orderCareersByHierarchy($careers, $filter);
|
||||
}
|
||||
$tpl->assign('actions', $actions);
|
||||
$tpl->assign('form_filter', $html);
|
||||
$tpl->assign('data', $careers);
|
||||
|
||||
if ($useCareerHierarchy && 1 == $showHierarchy) {
|
||||
$layout = $tpl->get_template('admin/career_dashboard_hierarchy.tpl');
|
||||
} else {
|
||||
$layout = $tpl->get_template('admin/career_dashboard.tpl');
|
||||
}
|
||||
$tpl->display($layout);
|
||||
128
main/admin/career_diagram.php
Normal file
128
main/admin/career_diagram.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/*
|
||||
*
|
||||
* Requires extra_field_values.value to be longtext to save diagram:
|
||||
*
|
||||
UPDATE extra_field_values SET created_at = NULL WHERE CAST(created_at AS CHAR(20)) = '0000-00-00 00:00:00';
|
||||
UPDATE extra_field_values SET updated_at = NULL WHERE CAST(updated_at AS CHAR(20)) = '0000-00-00 00:00:00';
|
||||
ALTER TABLE extra_field_values modify column value longtext null;
|
||||
*/
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
if (false === api_get_configuration_value('allow_career_diagram')) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$careerId = $careerIdFromRequest = isset($_GET['id']) ? $_GET['id'] : 0;
|
||||
|
||||
if (empty($careerId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$career = new Career();
|
||||
$careerInfo = $career->getCareerFromId($careerId);
|
||||
if (empty($careerInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$careerId = $careerInfo['id'];
|
||||
|
||||
// Redirect to user/career_diagram.php if not admin/drh BT#18720
|
||||
if (!(api_is_platform_admin() || api_is_drh())) {
|
||||
if (api_get_configuration_value('use_career_external_id_as_identifier')) {
|
||||
$careerId = Security::remove_XSS($careerIdFromRequest);
|
||||
}
|
||||
$url = api_get_path(WEB_CODE_PATH).'user/career_diagram.php?career_id='.$careerId;
|
||||
api_location($url);
|
||||
}
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
|
||||
api_protect_admin_script($allowCareer);
|
||||
|
||||
$htmlHeadXtra[] = api_get_js('jsplumb2.js');
|
||||
|
||||
$career = new Career();
|
||||
$careerInfo = $career->get($careerId);
|
||||
if (empty($careerInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'career_dashboard.php',
|
||||
'name' => get_lang('CareersAndPromotions'),
|
||||
];
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'careers.php',
|
||||
'name' => get_lang('Careers'),
|
||||
];
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : '';
|
||||
|
||||
if ($action === 'add') {
|
||||
$interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
|
||||
$toolName = get_lang('Add');
|
||||
} elseif ($action === 'edit') {
|
||||
$interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
|
||||
$toolName = get_lang('Edit');
|
||||
} else {
|
||||
$toolName = get_lang('Careers');
|
||||
}
|
||||
|
||||
$extraFieldValue = new ExtraFieldValue('career');
|
||||
|
||||
// Check urls
|
||||
$itemUrls = $extraFieldValue->get_values_by_handler_and_field_variable(
|
||||
$careerId,
|
||||
'career_urls',
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
$urlToString = '';
|
||||
if (!empty($itemUrls) && !empty($itemUrls['value'])) {
|
||||
$urls = explode(',', $itemUrls['value']);
|
||||
$urlToString = ' ';
|
||||
if (!empty($urls)) {
|
||||
foreach ($urls as $urlData) {
|
||||
$urlData = explode('@', $urlData);
|
||||
if (isset($urlData[1])) {
|
||||
$urlToString .= Display::url($urlData[0], $urlData[1]).' ';
|
||||
} else {
|
||||
$urlToString .= $urlData[0].' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = new Template(get_lang('Diagram'));
|
||||
$html = Display::page_subheader2($careerInfo['name'].$urlToString);
|
||||
$diagram = Career::renderDiagramByColumn($careerInfo, $tpl);
|
||||
|
||||
if (!empty($diagram)) {
|
||||
$html .= $diagram;
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(get_lang('CareerXDoesntHaveADiagram'), $careerInfo['name']),
|
||||
'warning'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$tpl->assign('content', $html);
|
||||
$layout = $tpl->get_template('career/diagram_full.tpl');
|
||||
$tpl->display($layout);
|
||||
270
main/admin/careers.php
Normal file
270
main/admin/careers.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
|
||||
$useCareerHierarchy = api_get_configuration_value('career_hierarchy_enable');
|
||||
api_protect_admin_script($allowCareer);
|
||||
|
||||
// Add the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'career_dashboard.php',
|
||||
'name' => get_lang('CareersAndPromotions'),
|
||||
];
|
||||
|
||||
$action = $_GET['action'] ?? null;
|
||||
|
||||
$check = Security::check_token('request');
|
||||
$token = Security::get_token();
|
||||
|
||||
if ($action === 'add') {
|
||||
$interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
|
||||
$tool_name = get_lang('Add');
|
||||
} elseif ($action === 'edit') {
|
||||
$interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
|
||||
$tool_name = get_lang('Edit');
|
||||
} else {
|
||||
$tool_name = get_lang('Careers');
|
||||
}
|
||||
|
||||
//jqgrid will use this URL to do the selects
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_careers';
|
||||
|
||||
//The order is important you need to check the $column variable in the model.ajax.php file
|
||||
$columns = [get_lang('Name'), get_lang('Description'), get_lang('Actions')];
|
||||
|
||||
// Column config
|
||||
$column_model = [
|
||||
[
|
||||
'name' => 'name',
|
||||
'index' => 'name',
|
||||
'width' => '200',
|
||||
'align' => 'left',
|
||||
],
|
||||
[
|
||||
'name' => 'description',
|
||||
'index' => 'description',
|
||||
'width' => '400',
|
||||
'align' => 'left',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
[
|
||||
'name' => 'actions',
|
||||
'index' => 'actions',
|
||||
'width' => '100',
|
||||
'align' => 'left',
|
||||
'formatter' => 'action_formatter',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
];
|
||||
|
||||
$extra_params['autowidth'] = 'true';
|
||||
$extra_params['height'] = 'auto';
|
||||
|
||||
$diagramLink = '';
|
||||
$allow = api_get_configuration_value('allow_career_diagram');
|
||||
if ($allow) {
|
||||
$careerDiagramUrl = api_get_path(WEB_CODE_PATH).'admin/career_diagram.php';
|
||||
if (api_get_configuration_value('use_career_external_id_as_identifier_in_diagrams')) {
|
||||
$diagramLink = '<a href="'.$careerDiagramUrl.'?id=\'+rowObject[3]+\'">'.get_lang('Diagram').'</a>';
|
||||
} else {
|
||||
$diagramLink = '<a href="'.$careerDiagramUrl.'?id=\'+options.rowId+\'">'.get_lang('Diagram').'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
// With this function we can add actions to the jgrid (edit, delete, etc)
|
||||
if (api_is_platform_admin()) {
|
||||
$actionLinks = 'function action_formatter(cellvalue, options, rowObject) {
|
||||
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
$diagramLink.
|
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=copy&id=\'+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="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
'\';
|
||||
}';
|
||||
} else {
|
||||
$actionLinks = "function action_formatter(cellvalue, options, rowObject) {
|
||||
return '".$diagramLink."';
|
||||
}";
|
||||
}
|
||||
|
||||
$career = new Career();
|
||||
$content = '';
|
||||
$listUrl = api_get_self();
|
||||
|
||||
// Action handling: Add
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
api_protect_admin_script();
|
||||
|
||||
if (api_get_session_id() != 0 &&
|
||||
!api_is_allowed_to_session_edit(false, true)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
Session::write('notebook_view', 'creation_date');
|
||||
|
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
|
||||
$form = $career->return_form($url, 'add');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
if (isset($values['parent_id']) && '0' === $values['parent_id']) {
|
||||
$values['parent_id'] = null;
|
||||
}
|
||||
$res = $career->save($values);
|
||||
if ($res) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('ItemAdded'), 'confirmation')
|
||||
);
|
||||
}
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
} else {
|
||||
$content .= '<div class="actions">';
|
||||
$content .= '<a href="'.api_get_self().'">'.
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
$content .= '</div>';
|
||||
$form->protect();
|
||||
$content .= $form->returnForm();
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
api_protect_admin_script();
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
|
||||
$careerInfo = $career->get($id);
|
||||
if (empty($careerInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
// Action handling: Editing
|
||||
$url = api_get_self().'?action=edit&id='.$id;
|
||||
$form = $career->return_form($url, 'edit');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$career->update_all_promotion_status_by_career_id($values['id'], $values['status']);
|
||||
$old_status = $career->get_status($values['id']);
|
||||
if (isset($values['parent_id']) && '0' === $values['parent_id']) {
|
||||
$values['parent_id'] = null;
|
||||
}
|
||||
$res = $career->update($values);
|
||||
|
||||
$values['item_id'] = $values['id'];
|
||||
$sessionFieldValue = new ExtraFieldValue('career');
|
||||
$sessionFieldValue->saveFieldValues($values);
|
||||
|
||||
if ($res) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('CareerUpdated'), 'confirmation')
|
||||
);
|
||||
if ($values['status'] && !$old_status) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(get_lang('CareerXUnarchived'), $values['name']),
|
||||
'confirmation',
|
||||
false
|
||||
)
|
||||
);
|
||||
} elseif (!$values['status'] && $old_status) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(get_lang('CareerXArchived'), $values['name']),
|
||||
'confirmation',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
} else {
|
||||
$content .= '<div class="actions">';
|
||||
$content .= '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
$content .= '</div>';
|
||||
$form->protect();
|
||||
$content .= $form->returnForm();
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
api_protect_admin_script();
|
||||
// Action handling: delete
|
||||
if ($check) {
|
||||
$childCareers = $career->get_all(['parent_id' => $_GET['id']]);
|
||||
if (!empty($childCareers)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('CareerCannotBeDeletedAsItHasChildren'), 'warning')
|
||||
);
|
||||
} else {
|
||||
$res = $career->delete($_GET['id']);
|
||||
if ($res) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('ItemDeleted'), 'confirmation')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
break;
|
||||
case 'copy':
|
||||
api_protect_admin_script();
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
if ($check) {
|
||||
$res = $career->copy($_GET['id'], true); //copy career and promotions inside
|
||||
if ($res) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('ItemCopied'), 'confirmation')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: '.$listUrl);
|
||||
exit;
|
||||
break;
|
||||
default:
|
||||
$content = $career->display();
|
||||
break;
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
?>
|
||||
<script>
|
||||
$(function() {
|
||||
<?php
|
||||
// grid definition see the $career->display() function
|
||||
echo Display::grid_js(
|
||||
'careers',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
$actionLinks,
|
||||
true
|
||||
);
|
||||
?>
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
echo $content;
|
||||
|
||||
Display::display_footer();
|
||||
39
main/admin/cli.php
Normal file
39
main/admin/cli.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Used for external support of chamilo's users.
|
||||
*
|
||||
* @author Arnaud Ligot, CBlue SPRL
|
||||
*
|
||||
* @package chamilo.admin.cli
|
||||
*/
|
||||
|
||||
// we are in the admin area so we do not need a course id
|
||||
$cidReset = true;
|
||||
// include global script
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
// make sure only logged-in admins can execute this
|
||||
api_protect_admin_script();
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('CommandLineInterpreter');
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
// including the header file (which includes the banner itself)
|
||||
Display::display_header($tool_name);
|
||||
switch ($_GET["cmd"]) {
|
||||
case "clear_stapi":
|
||||
echo "Are you sure you are willing to erase all storage api data (no backup)? <a href='cli.php?cmd=clear_stapi_confirm' >Yes</a>";
|
||||
break;
|
||||
case "clear_stapi_confirm":
|
||||
Database::query("delete from ".Database::get_main_table(TABLE_TRACK_STORED_VALUES));
|
||||
Database::query("delete from ".Database::get_main_table(TABLE_TRACK_STORED_VALUES_STACK));
|
||||
echo "Done";
|
||||
break;
|
||||
default:
|
||||
echo "UNKNOWN COMMAND";
|
||||
break;
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
352
main/admin/configure_extensions.php
Normal file
352
main/admin/configure_extensions.php
Normal file
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
|
||||
|
||||
/**
|
||||
* Edition of extensions configuration.
|
||||
*
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
// Database Table Definitions
|
||||
$tbl_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
|
||||
$message = '';
|
||||
|
||||
if (isset($_POST['activeExtension'])) {
|
||||
switch ($_POST['extension_code']) {
|
||||
case 'ppt2lp':
|
||||
$sql = 'UPDATE '.$tbl_settings_current.' SET
|
||||
selected_value="true"
|
||||
WHERE variable="service_ppt2lp"
|
||||
AND subkey="active"';
|
||||
|
||||
$rs = Database::query($sql);
|
||||
|
||||
if (Database::affected_rows($rs) > 0) {
|
||||
$message = get_lang('ServiceActivated');
|
||||
}
|
||||
|
||||
$sql = 'UPDATE '.$tbl_settings_current.' SET
|
||||
selected_value="'.addslashes($_POST['host']).'"
|
||||
WHERE variable="service_ppt2lp"
|
||||
AND subkey="host"';
|
||||
Database::query($sql);
|
||||
|
||||
$sql = 'UPDATE '.$tbl_settings_current.' SET
|
||||
selected_value="'.addslashes($_POST['port']).'"
|
||||
WHERE variable="service_ppt2lp"
|
||||
AND subkey="port"';
|
||||
Database::query($sql);
|
||||
|
||||
$sql = 'UPDATE '.$tbl_settings_current.' SET
|
||||
selected_value="'.addslashes($_POST['ftp_password']).'"
|
||||
WHERE variable="service_ppt2lp"
|
||||
AND subkey="ftp_password"';
|
||||
Database::query($sql);
|
||||
|
||||
$sql = 'UPDATE '.$tbl_settings_current.' SET
|
||||
selected_value="'.addslashes($_POST['user']).'"
|
||||
WHERE variable="service_ppt2lp"
|
||||
AND subkey="user"';
|
||||
Database::query($sql);
|
||||
|
||||
$sql = 'UPDATE '.$tbl_settings_current.' SET
|
||||
selected_value="'.addslashes($_POST['path_to_lzx']).'"
|
||||
WHERE variable="service_ppt2lp"
|
||||
AND subkey="path_to_lzx"';
|
||||
Database::query($sql);
|
||||
|
||||
$sql = 'UPDATE '.$tbl_settings_current.' SET
|
||||
selected_value="'.addslashes($_POST['size']).'"
|
||||
WHERE variable="service_ppt2lp"
|
||||
AND subkey="size"';
|
||||
Database::query($sql);
|
||||
break;
|
||||
}
|
||||
api_flush_settings_cache(api_get_current_access_url_id());
|
||||
}
|
||||
|
||||
$listActiveServices = [];
|
||||
|
||||
// get the list of active services
|
||||
$sql = 'SELECT variable FROM '.$tbl_settings_current.'
|
||||
WHERE variable LIKE "service_%" AND subkey="active" and selected_value="true"';
|
||||
|
||||
$rs = Database::query($sql);
|
||||
while ($row = Database::fetch_array($rs)) {
|
||||
$listActiveServices[] = $row['variable'];
|
||||
}
|
||||
|
||||
// javascript to handle accordion behaviour
|
||||
$javascript_message = '';
|
||||
if (!empty($message)) {
|
||||
$javascript_message = '
|
||||
document.getElementById("message").style.display = "block";
|
||||
var timer = setTimeout(hideMessage, 5000);';
|
||||
}
|
||||
$htmlHeadXtra[] = '<script>
|
||||
var listeDiv;
|
||||
var extensionsHeader = new Array();
|
||||
var extensionsContent = new Array();
|
||||
window.onload = loadTables;
|
||||
function loadTables(){
|
||||
'.$javascript_message.'
|
||||
var listeDiv = document.getElementsByTagName("div");
|
||||
|
||||
// fill extensionsHeader and extensionsContent
|
||||
for(var i=0 ; i < listeDiv.length ; i++){
|
||||
if(listeDiv[i].id.indexOf(\'extension_header\')!=-1){
|
||||
listeDiv[i].onclick = afficheContent;
|
||||
extensionsHeader.push(listeDiv[i]);
|
||||
}
|
||||
if(listeDiv[i].id.indexOf("extension_content")!=-1){
|
||||
extensionsContent.push(listeDiv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hideMessage(){
|
||||
document.getElementById("message").style.display = "none";
|
||||
}
|
||||
|
||||
function afficheContent(event){
|
||||
var id = this.id.replace("header","content");
|
||||
switch(document.getElementById(id).style.display){
|
||||
case "block" :
|
||||
document.getElementById(id).style.display = "none";
|
||||
break;
|
||||
case "none" :
|
||||
document.getElementById(id).style.display = "block";
|
||||
for(var i=0 ; i < extensionsContent.length ; i++){
|
||||
if(extensionsContent[i].id != id)
|
||||
extensionsContent[i].style.display = "none";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
|
||||
$nameTool = get_lang('ConfigureExtensions');
|
||||
Display::display_header($nameTool);
|
||||
|
||||
?>
|
||||
<div id="message" style="display: none">
|
||||
<?php
|
||||
if (!empty($message)) {
|
||||
echo Display::return_message($message, 'normal');
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div id="content" align="center">
|
||||
<!-- PPT2LP -->
|
||||
<div class="chamilo-rapid">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?php echo Display::panel(get_lang('Ppt2lpDescription').' '.get_lang('Ppt2lpVoiceRecordingNeedsRed5'), get_lang('Ppt2lp')); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<?php Display::display_icon('screenshot_ppt2lp.jpg', get_lang('Ppt2lp'), ['class' => 'img-responsive']); ?>
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<form method="POST" class="form-horizontal" action="<?php echo api_get_self(); ?>">
|
||||
<?php
|
||||
$form = new FormValidator('ppt2lp');
|
||||
if (api_get_configuration_value('webservice_remote_ppt2png_enable') == true) {
|
||||
$form->addElement('text', 'host', get_lang('Host'));
|
||||
} else {
|
||||
$form->addElement('text', 'host', [get_lang('Host'), 'Remote host disabled - set webservice_remote_ppt2png_enable setting to true in configuration.php to enable']);
|
||||
}
|
||||
//$form -> addElement('html','<br /><br />');
|
||||
$form->addElement('text', 'port', get_lang('Port'));
|
||||
//$form -> addElement('html','<br /><br />');
|
||||
$form->addElement('text', 'user', get_lang('UserOnHost'));
|
||||
//$form -> addElement('html','<br /><br />');
|
||||
$form->addElement('text', 'ftp_password', get_lang('FtpPassword'));
|
||||
//$form -> addElement('html','<br /><br />');
|
||||
$form->addElement('text', 'path_to_lzx', get_lang('PathToLzx'));
|
||||
//$form -> addElement('html','<br /><br />');
|
||||
$options = ChamiloApi::getDocumentConversionSizes();
|
||||
$form->addElement('select', 'size', get_lang('SlideSize'), $options);
|
||||
$form->addElement('hidden', 'extension_code', 'ppt2lp');
|
||||
|
||||
$defaults = [];
|
||||
$renderer = $form->defaultRenderer();
|
||||
$renderer->setElementTemplate(
|
||||
'<div style="text-align:left">{label}</div><div style="text-align:left">{element}</div>'
|
||||
);
|
||||
if (in_array('service_ppt2lp', $listActiveServices)) {
|
||||
$sql = 'SELECT subkey, selected_value FROM '.$tbl_settings_current.'
|
||||
WHERE variable = "service_ppt2lp"
|
||||
AND subkey <> "active"';
|
||||
$rs = Database::query($sql);
|
||||
while ($row = Database::fetch_array($rs, 'ASSOC')) {
|
||||
$defaults[$row['subkey']] = $row['selected_value'];
|
||||
}
|
||||
$form->addButtonSave(get_lang('ReconfigureExtension'), 'activeExtension');
|
||||
} else {
|
||||
$defaults['host'] = 'localhost';
|
||||
$defaults['port'] = '2002';
|
||||
$defaults['size'] = '720x540';
|
||||
$form->addButtonSave(get_lang('ActivateExtension'), 'activeExtension');
|
||||
}
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
echo '<br />';
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
/*
|
||||
<!-- EPHORUS -->
|
||||
<div id="main_ephorus">
|
||||
<div id="extension_header_ephorus" class="accordion_header">
|
||||
<a href="#"><?php echo get_lang('EphorusPlagiarismPrevention') ?></a>
|
||||
</div>
|
||||
<div id="extension_content_ephorus" style="display:none;padding:0;width:780px;" class="accordion_content">
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<TABLE style="WIDTH: 750px" cellSpacing="0" cellPadding="0" align="middle" border="0">
|
||||
<TBODY>
|
||||
<TR>
|
||||
<TD>
|
||||
<TABLE style="WIDTH: 475px" cellSpacing="0" cellPadding="0" border="0">
|
||||
<TBODY>
|
||||
<TR>
|
||||
<TD>
|
||||
|
||||
<a title="http://www.ephorus.com/dokeos_activate.html" href="http://www.ephorus.com/dokeos_activate.html" target="_blank">
|
||||
<?php Display::display_icon('ephorus.gif','Ephorus'); ?>
|
||||
</a>
|
||||
</TD>
|
||||
<TD>
|
||||
<P align=center>
|
||||
<FONT color="#669966" size="3"><?php echo get_lang('EphorusLeadersInAntiPlagiarism') ?></FONT>
|
||||
</P>
|
||||
</TD>
|
||||
</TR>
|
||||
</TBODY>
|
||||
</TABLE>
|
||||
</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>
|
||||
<P>
|
||||
<TABLE style="WIDTH: 85%" cellSpacing="0" cellPadding="0" border="0">
|
||||
<TBODY>
|
||||
<TR>
|
||||
<TD width="50">
|
||||
|
||||
</TD>
|
||||
<TD>
|
||||
<P>
|
||||
<?php echo get_lang('EphorusDescription') ?>
|
||||
</P>
|
||||
<P>
|
||||
<A title="http://www.ephorus.nl/demo_account_en.html" href="http://www.ephorus.nl/demo_account_en.html" target="_blank"><?php echo get_lang('EphorusClickHereForADemoAccount') ?></A>
|
||||
</P>
|
||||
<P>
|
||||
<A title="http://www.ephorus.nl:80/dokeos_activate.html" href="http://www.ephorus.nl/dokeos_activate.html" target="_blank"><?php echo get_lang('EphorusClickHereForInformationsAndPrices') ?></A>.
|
||||
</P>
|
||||
</TD>
|
||||
</TR>
|
||||
</TBODY>
|
||||
</TABLE>
|
||||
</P>
|
||||
</TD>
|
||||
</TR>
|
||||
</TBODY>
|
||||
</TABLE>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
*/
|
||||
/*
|
||||
|
||||
<!-- SEARCH -->
|
||||
<div id="main_search">
|
||||
<div id="extension_header_search" class="accordion_header">
|
||||
<a href="#"><?php echo get_lang('SearchEngine') ?></a>
|
||||
</div>
|
||||
<div id="extension_content_search" style="display:none" class="accordion_content">
|
||||
<?php echo get_lang('SearchEngineDescription') ?><br /><br />
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td width="50%">
|
||||
<?php Display::display_icon('screenshot_search.jpg', get_lang('SearchEngine')); ?>
|
||||
</td>
|
||||
<td align="center" width="50%">
|
||||
<form method="POST" action="<?php echo api_get_self(); ?>">
|
||||
<input type="hidden" name="extension_code" value="search" />
|
||||
<button type="submit" class="save" name="activeExtension" value="<?php echo get_lang('ActivateExtension') ?>" ><?php echo get_lang('ActivateExtension') ?></button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SERVER STATS -->
|
||||
<div id="main_serverstats">
|
||||
<div id="extension_header_serverstats" class="accordion_header">
|
||||
<a href="#"><?php echo get_lang('ServerStatistics') ?></a>
|
||||
</div>
|
||||
<div id="extension_content_serverstats" style="display:none" class="accordion_content">
|
||||
<?php echo get_lang('ServerStatisticsDescription') ?><br /><br />
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td width="50%">
|
||||
<?php Display::display_icon('screenshot_serverstats.jpg', get_lang('ServerStatistics')); ?>
|
||||
</td>
|
||||
<td align="center" width="50%">
|
||||
<form method="POST" action="<?php echo api_get_self(); ?>">
|
||||
<input type="hidden" name="extension_code" value="serverstats" />
|
||||
<button type="submit" class="save" name="activeExtension" value="<?php echo get_lang('ActivateExtension') ?>" ><?php echo get_lang('ActivateExtension') ?></button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- BANDWIDTH STATS -->
|
||||
<div id="main_bandwidthstats">
|
||||
<div id="extension_header_bandwidthstats" class="accordion_header">
|
||||
<a href="#"><?php echo get_lang('BandWidthStatistics') ?></a>
|
||||
</div>
|
||||
<div id="extension_content_bandwidthstats" style="display:none" class="accordion_content">
|
||||
<?php echo get_lang('BandWidthStatisticsDescription') ?><br /><br />
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td width="50%">
|
||||
<?php Display::display_icon('screenshot_bandwidth.jpg', get_lang('BandWidthStatistics')); ?>
|
||||
</td>
|
||||
<td align="center" width="50%">
|
||||
<form method="POST" action="<?php echo api_get_self(); ?>">
|
||||
<input type="hidden" name="extension_code" value="bandwidthstats" />
|
||||
<button type="submit" class="save" name="activeExtension" value="<?php echo get_lang('ActivateExtension') ?>" ><?php echo get_lang('ActivateExtension') ?></button>
|
||||
</form>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
*/ ?>
|
||||
</div><!-- /content -->
|
||||
|
||||
<?php
|
||||
Display::display_footer();
|
||||
1305
main/admin/configure_homepage.php
Normal file
1305
main/admin/configure_homepage.php
Normal file
File diff suppressed because it is too large
Load Diff
467
main/admin/configure_inscription.php
Normal file
467
main/admin/configure_inscription.php
Normal file
@@ -0,0 +1,467 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This script displays a form for registering new users.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
// Load terms & conditions from the current lang
|
||||
if (api_get_setting('allow_terms_conditions') === 'true') {
|
||||
$get = array_keys($_GET);
|
||||
if (isset($get)) {
|
||||
if (isset($get[0]) && $get[0] === 'legal') {
|
||||
$language = api_get_language_id(api_get_interface_language());
|
||||
$term_preview = LegalManager::get_last_condition($language);
|
||||
if (!$term_preview) {
|
||||
//look for the default language
|
||||
$language = api_get_setting('platformLanguage');
|
||||
$language = api_get_language_id($language);
|
||||
$term_preview = LegalManager::get_last_condition($language);
|
||||
}
|
||||
$tool_name = get_lang('TermsAndConditions');
|
||||
Display::display_header('');
|
||||
echo '<div class="actions-title">';
|
||||
echo $tool_name;
|
||||
echo '</div>';
|
||||
if (!empty($term_preview['content'])) {
|
||||
echo $term_preview['content'];
|
||||
} else {
|
||||
echo get_lang('ComingSoon');
|
||||
}
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$tool_name = get_lang('ConfigureInscription');
|
||||
if (!empty($action)) {
|
||||
$interbreadcrumb[] = ['url' => 'configure_inscription.php', 'name' => get_lang('ConfigureInscription')];
|
||||
switch ($action) {
|
||||
case 'edit_top':
|
||||
$tool_name = get_lang('EditTopRegister');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$lang = ''; //el for "Edit Language"
|
||||
if (!empty($_SESSION['user_language_choice'])) {
|
||||
$lang = $_SESSION['user_language_choice'];
|
||||
} elseif (!empty($_SESSION['_user']['language'])) {
|
||||
$lang = $_SESSION['_user']['language'];
|
||||
} else {
|
||||
$lang = api_get_setting('platformLanguage');
|
||||
}
|
||||
|
||||
// ----- Ensuring availability of main files in the corresponding language -----
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
if ($access_url_id != -1) {
|
||||
$url_info = api_get_access_url($access_url_id);
|
||||
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
|
||||
|
||||
$clean_url = api_replace_dangerous_char($url);
|
||||
$clean_url = str_replace('/', '-', $clean_url);
|
||||
$clean_url .= '/';
|
||||
|
||||
$homep = api_get_path(SYS_HOME_PATH); //homep for Home Path
|
||||
$homep_new = api_get_path(SYS_HOME_PATH).$clean_url; //homep for Home Path added the url
|
||||
$new_url_dir = api_get_path(SYS_HOME_PATH).$clean_url;
|
||||
//we create the new dir for the new sites
|
||||
if (!is_dir($new_url_dir)) {
|
||||
mkdir($new_url_dir, api_get_permissions_for_new_directories());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$homep_new = '';
|
||||
$homep = api_get_path(SYS_HOME_PATH); //homep for Home Path
|
||||
}
|
||||
|
||||
$topf = 'register_top'; //topf for Top File
|
||||
$ext = '.html'; //ext for HTML Extension - when used frequently, variables are
|
||||
$homef = [$topf];
|
||||
|
||||
// If language-specific file does not exist, create it by copying default file
|
||||
foreach ($homef as $my_file) {
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
|
||||
copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);
|
||||
}
|
||||
} else {
|
||||
if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
|
||||
copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($homep_new)) {
|
||||
$homep = $homep_new;
|
||||
}
|
||||
|
||||
if (!empty($action)) {
|
||||
if (isset($_POST['formSent'])) {
|
||||
switch ($action) {
|
||||
case 'edit_top':
|
||||
// Filter
|
||||
$home_top = trim(stripslashes($_POST['register_top']));
|
||||
// Write
|
||||
if (file_exists($homep.$topf.'_'.$lang.$ext)) {
|
||||
if (is_writable($homep.$topf.'_'.$lang.$ext)) {
|
||||
$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
|
||||
fputs($fp, $home_top);
|
||||
fclose($fp);
|
||||
} else {
|
||||
$errorMsg = get_lang('HomePageFilesNotWritable');
|
||||
}
|
||||
} else {
|
||||
//File does not exist
|
||||
$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
|
||||
fputs($fp, $home_top);
|
||||
fclose($fp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (empty($errorMsg)) {
|
||||
header('Location: '.api_get_self());
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
switch ($action) {
|
||||
case 'edit_top':
|
||||
// This request is only the preparation for the update of the home_top
|
||||
$home_top = '';
|
||||
if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
|
||||
$home_top = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
|
||||
} elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
|
||||
$home_top = @(string) file_get_contents($homep.$topf.$lang.$ext);
|
||||
} else {
|
||||
$errorMsg = get_lang('HomePageFilesNotReadable');
|
||||
}
|
||||
$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo Display::page_header($tool_name);
|
||||
|
||||
// The following security condition has been removed, because it makes no sense here. See Bug #1846.
|
||||
//// Forbidden to self-register
|
||||
//if (api_get_setting('allow_registration') == 'false') {
|
||||
// api_not_allowed();
|
||||
//}
|
||||
|
||||
//api_display_tool_title($tool_name);
|
||||
if (api_get_setting('allow_registration') == 'approval') {
|
||||
echo Display::return_message(get_lang('YourAccountHasToBeApproved'), 'normal');
|
||||
}
|
||||
//if openid was not found
|
||||
if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
|
||||
echo Display::return_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister'), 'warning');
|
||||
}
|
||||
|
||||
$form = new FormValidator('registration');
|
||||
if (api_get_setting('allow_terms_conditions') === 'true') {
|
||||
$display_all_form = !isset($_SESSION['update_term_and_condition']['user_id']);
|
||||
} else {
|
||||
$display_all_form = true;
|
||||
}
|
||||
|
||||
if ($display_all_form) {
|
||||
if (api_is_western_name_order()) {
|
||||
// FIRST NAME and LAST NAME
|
||||
$form->addElement('text', 'firstname', get_lang('FirstName'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
$form->addElement('text', 'lastname', get_lang('LastName'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
} else {
|
||||
// LAST NAME and FIRST NAME
|
||||
$form->addElement('text', 'lastname', get_lang('LastName'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
$form->addElement('text', 'firstname', get_lang('FirstName'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
}
|
||||
$form->applyFilter('firstname', 'trim');
|
||||
$form->applyFilter('lastname', 'trim');
|
||||
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
|
||||
|
||||
// EMAIL
|
||||
$form->addElement('text', 'email', get_lang('Email'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
if (api_get_setting('registration', 'email') == 'true') {
|
||||
$form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
|
||||
}
|
||||
$form->addRule('email', get_lang('EmailWrong'), 'email');
|
||||
if (api_get_setting('openid_authentication') == 'true') {
|
||||
$form->addElement('text', 'openid', get_lang('OpenIDURL'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
}
|
||||
|
||||
// USERNAME
|
||||
$form->addElement(
|
||||
'text',
|
||||
'username',
|
||||
get_lang('UserName'),
|
||||
['size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled']
|
||||
);
|
||||
$form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('username', get_lang('UsernameWrong'), 'username');
|
||||
$form->addRule('username', get_lang('UserTaken'), 'username_available');
|
||||
$form->addRule(
|
||||
'username',
|
||||
sprintf(get_lang('UsernameMaxXCharacters'), (string) USERNAME_MAX_LENGTH),
|
||||
'maxlength',
|
||||
USERNAME_MAX_LENGTH
|
||||
);
|
||||
|
||||
// PASSWORD
|
||||
$form->addElement('password', 'pass1', get_lang('Pass'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
$form->addElement('password', 'pass2', get_lang('Confirmation'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
$form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule(['pass1', 'pass2'], get_lang('PassTwo'), 'compare');
|
||||
$form->addPasswordRule('pass1');
|
||||
|
||||
// PHONE
|
||||
$form->addElement('text', 'phone', get_lang('Phone'), ['size' => 40, 'disabled' => 'disabled']);
|
||||
if (api_get_setting('registration', 'phone') == 'true') {
|
||||
$form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
|
||||
}
|
||||
|
||||
// LANGUAGE
|
||||
if (api_get_setting('registration', 'language') == 'true') {
|
||||
$form->addSelectLanguage(
|
||||
'language',
|
||||
get_lang('Language'),
|
||||
'',
|
||||
['disabled' => 'disabled']
|
||||
);
|
||||
}
|
||||
|
||||
// STUDENT/TEACHER
|
||||
if (api_get_setting('allow_registration_as_teacher') != 'false') {
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'status',
|
||||
get_lang('Status'),
|
||||
get_lang('RegStudent'),
|
||||
STUDENT,
|
||||
['disabled' => 'disabled']
|
||||
);
|
||||
$form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, ['disabled' => 'disabled']);
|
||||
}
|
||||
|
||||
// EXTENDED FIELDS
|
||||
|
||||
// MY PERSONAL OPEN AREA
|
||||
if (api_get_setting('extended_profile') == 'true' &&
|
||||
api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
|
||||
) {
|
||||
$form->addHtmlEditor(
|
||||
'openarea',
|
||||
get_lang('MyPersonalOpenArea'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']
|
||||
);
|
||||
} // MY COMPETENCES
|
||||
if (api_get_setting('extended_profile') == 'true' &&
|
||||
api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
|
||||
) {
|
||||
$form->addHtmlEditor(
|
||||
'competences',
|
||||
get_lang('MyCompetences'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']
|
||||
);
|
||||
}
|
||||
// MY DIPLOMAS
|
||||
if (api_get_setting('extended_profile') == 'true' &&
|
||||
api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
|
||||
) {
|
||||
$form->addHtmlEditor(
|
||||
'diplomas',
|
||||
get_lang('MyDiplomas'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']
|
||||
);
|
||||
}
|
||||
// WHAT I AM ABLE TO TEACH
|
||||
if (api_get_setting('extended_profile') == 'true' &&
|
||||
api_get_setting('extendedprofile_registration', 'myteach') == 'true'
|
||||
) {
|
||||
$form->addHtmlEditor(
|
||||
'teach',
|
||||
get_lang('MyTeach'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']
|
||||
);
|
||||
}
|
||||
if (api_get_setting('extended_profile') == 'true') {
|
||||
// MY PERSONAL OPEN AREA
|
||||
if (api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea') == 'true') {
|
||||
$form->addRule('openarea', get_lang('ThisFieldIsRequired'), 'required');
|
||||
} // MY COMPETENCES
|
||||
if (api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') {
|
||||
$form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required');
|
||||
}
|
||||
// MY DIPLOMAS
|
||||
if (api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
|
||||
$form->addRule('diplomas', get_lang('ThisFieldIsRequired'), 'required');
|
||||
}
|
||||
// WHAT I AM ABLE TO TEACH
|
||||
if (api_get_setting('extendedprofile_registrationrequired', 'myteach') == 'true') {
|
||||
$form->addRule('teach', get_lang('ThisFieldIsRequired'), 'required');
|
||||
}
|
||||
}
|
||||
|
||||
$extraField = new ExtraField('user');
|
||||
$extraField->addElements($form);
|
||||
}
|
||||
|
||||
// Terms and conditions
|
||||
/*if (api_get_setting('allow_terms_conditions') == 'true') {
|
||||
$language = api_get_interface_language();
|
||||
$language = api_get_language_id($language);
|
||||
$term_preview = LegalManager::get_last_condition($language);
|
||||
|
||||
if (!$term_preview) {
|
||||
//we load from the platform
|
||||
$language = api_get_setting('platformLanguage');
|
||||
$language = api_get_language_id($language);
|
||||
$term_preview = LegalManager::get_last_condition($language);
|
||||
//if is false we load from english
|
||||
if (!$term_preview) {
|
||||
$language = api_get_language_id('english'); //this must work
|
||||
$term_preview = LegalManager::get_last_condition($language);
|
||||
}
|
||||
}
|
||||
|
||||
// Version and language //password
|
||||
$form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
|
||||
$form->addElement('hidden', 'legal_info', $term_preview['id'].':'.$term_preview['language_id']);
|
||||
|
||||
if ($term_preview['type'] == 1) {
|
||||
$form->addElement(
|
||||
'checkbox',
|
||||
'legal_accept',
|
||||
null,
|
||||
get_lang('IHaveReadAndAgree').' <a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>'
|
||||
);
|
||||
$form->addRule('legal_accept', get_lang('ThisFieldIsRequired'), 'required');
|
||||
} else {
|
||||
if (!empty($term_preview['content'])) {
|
||||
$preview = LegalManager::show_last_condition($term_preview);
|
||||
$form->addElement('label', get_lang('TermsAndConditions'), $preview);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
$form->addButtonSave(get_lang('RegisterUser'));
|
||||
|
||||
$defaults['status'] = STUDENT;
|
||||
|
||||
if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
|
||||
$defaults['language'] = $_SESSION['user_language_choice'];
|
||||
} else {
|
||||
$defaults['language'] = api_get_setting('platformLanguage');
|
||||
}
|
||||
|
||||
if (!empty($_GET['username'])) {
|
||||
$defaults['username'] = Security::remove_XSS($_GET['username']);
|
||||
}
|
||||
|
||||
if (!empty($_GET['email'])) {
|
||||
$defaults['email'] = Security::remove_XSS($_GET['email']);
|
||||
}
|
||||
|
||||
if (!empty($_GET['phone'])) {
|
||||
$defaults['phone'] = Security::remove_XSS($_GET['phone']);
|
||||
}
|
||||
|
||||
if (api_get_setting('openid_authentication') == 'true' && !empty($_GET['openid'])) {
|
||||
$defaults['openid'] = Security::remove_XSS($_GET['openid']);
|
||||
}
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
switch ($action) {
|
||||
case 'edit_top':
|
||||
if ($action == 'edit_top') {
|
||||
$name = $topf;
|
||||
$open = $home_top;
|
||||
} else {
|
||||
$name = $newsf;
|
||||
$open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
|
||||
$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
|
||||
}
|
||||
|
||||
if (!empty($errorMsg)) {
|
||||
echo Display::return_message($errorMsg, 'normal');
|
||||
}
|
||||
|
||||
$default = [];
|
||||
$form = new FormValidator(
|
||||
'configure_inscription_'.$action,
|
||||
'post',
|
||||
api_get_self().'?action='.$action,
|
||||
'',
|
||||
['style' => 'margin: 0px;']
|
||||
);
|
||||
$renderer = &$form->defaultRenderer();
|
||||
$renderer->setHeaderTemplate('');
|
||||
$renderer->setFormTemplate(
|
||||
'<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>'
|
||||
);
|
||||
$renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
|
||||
$renderer->setRequiredNoteTemplate('');
|
||||
$form->addElement('hidden', 'formSent', '1');
|
||||
$default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
|
||||
$form->addHtmlEditor(
|
||||
$name,
|
||||
'',
|
||||
true,
|
||||
false,
|
||||
[
|
||||
'ToolbarSet' => 'PortalHomePage',
|
||||
'Width' => '100%',
|
||||
'Height' => '400',
|
||||
]
|
||||
);
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
$form->setDefaults($default);
|
||||
$form->display();
|
||||
break;
|
||||
default:
|
||||
//Form of language
|
||||
api_display_language_form();
|
||||
echo ' <a href="'.api_get_self().'?action=edit_top">'.Display::display_icon(
|
||||
'edit.gif',
|
||||
get_lang('Edit')
|
||||
).'</a> <a href="'.api_get_self().'?action=edit_top">'.get_lang('EditNotice').'</a>';
|
||||
|
||||
$open = '';
|
||||
if (file_exists($homep.$topf.'_'.$lang.$ext)) {
|
||||
$open = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
|
||||
} else {
|
||||
$open = @(string) file_get_contents($homep.$topf.$ext);
|
||||
}
|
||||
$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
|
||||
if (!empty($open)) {
|
||||
echo '<div class="well_border">';
|
||||
echo $open;
|
||||
echo '</div>';
|
||||
}
|
||||
$form->display();
|
||||
break;
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
125
main/admin/configure_plugin.php
Normal file
125
main/admin/configure_plugin.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2012
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$pluginName = $_GET['name'];
|
||||
$appPlugin = new AppPlugin();
|
||||
$installedPlugins = $appPlugin->getInstalledPlugins();
|
||||
$pluginInfo = $appPlugin->getPluginInfo($pluginName, true);
|
||||
|
||||
if (!in_array($pluginName, $installedPlugins) || empty($pluginInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$currentUrl = api_get_self()."?name=$pluginName";
|
||||
|
||||
if (isset($pluginInfo['settings_form'])) {
|
||||
/** @var FormValidator $form */
|
||||
$form = $pluginInfo['settings_form'];
|
||||
if (isset($form)) {
|
||||
// We override the form attributes
|
||||
$attributes = ['action' => $currentUrl, 'method' => 'POST'];
|
||||
$form->updateAttributes($attributes);
|
||||
if (isset($pluginInfo['settings'])) {
|
||||
$form->setDefaults($pluginInfo['settings']);
|
||||
}
|
||||
$content = Display::page_header($pluginInfo['title']);
|
||||
$content .= $form->toHtml();
|
||||
}
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('NoConfigurationSettingsForThisPlugin'), 'warning')
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($form)) {
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
|
||||
// Fix only for bbb
|
||||
if ($pluginName === 'bbb') {
|
||||
if (!isset($values['global_conference_allow_roles'])) {
|
||||
$values['global_conference_allow_roles'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$accessUrlId = api_get_current_access_url_id();
|
||||
api_delete_settings_params(
|
||||
[
|
||||
'category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' => [
|
||||
'Plugins',
|
||||
$accessUrlId,
|
||||
$pluginName,
|
||||
'setting',
|
||||
'status',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
api_add_setting(
|
||||
$value,
|
||||
$pluginName.'_'.$key,
|
||||
$pluginName,
|
||||
'setting',
|
||||
'Plugins',
|
||||
$pluginName,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
$accessUrlId,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
Event::addEvent(
|
||||
LOG_PLUGIN_CHANGE,
|
||||
LOG_PLUGIN_SETTINGS_CHANGE,
|
||||
$pluginName,
|
||||
api_get_utc_datetime()
|
||||
);
|
||||
api_flush_settings_cache($accessUrlId);
|
||||
|
||||
if (!empty($pluginInfo['plugin_class'])) {
|
||||
/** @var \Plugin $objPlugin */
|
||||
$objPlugin = $pluginInfo['plugin_class']::create();
|
||||
$objPlugin->get_settings(true);
|
||||
$objPlugin->performActionsAfterConfigure();
|
||||
|
||||
if (isset($values['show_main_menu_tab'])) {
|
||||
$objPlugin->manageTab($values['show_main_menu_tab']);
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Updated'), 'success'));
|
||||
header("Location: $currentUrl");
|
||||
exit;
|
||||
} else {
|
||||
foreach ($form->_errors as $error) {
|
||||
Display::addFlash(Display::return_message($error, 'error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins',
|
||||
'name' => get_lang('Plugins'),
|
||||
];
|
||||
|
||||
$tpl = new Template($pluginName, true, true, false, true, false);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
309
main/admin/course_add.php
Normal file
309
main/admin/course_add.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\CourseCategory;
|
||||
use Chamilo\CoreBundle\Entity\Repository\CourseCategoryRepository;
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$tool_name = get_lang('AddCourse');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
|
||||
|
||||
$em = Database::getManager();
|
||||
/** @var CourseCategoryRepository $courseCategoriesRepo */
|
||||
$courseCategoriesRepo = $em->getRepository('ChamiloCoreBundle:CourseCategory');
|
||||
// Get all possible teachers.
|
||||
$accessUrlId = api_get_current_access_url_id();
|
||||
|
||||
// Build the form.
|
||||
$form = new FormValidator('update_course');
|
||||
$form->addElement('header', $tool_name);
|
||||
|
||||
// Title
|
||||
$form->addText(
|
||||
'title',
|
||||
get_lang('Title'),
|
||||
true,
|
||||
[
|
||||
'aria-label' => get_lang('Title'),
|
||||
]
|
||||
);
|
||||
$form->applyFilter('title', 'html_filter');
|
||||
$form->applyFilter('title', 'trim');
|
||||
|
||||
// Code
|
||||
if (!api_get_configuration_value('course_creation_form_hide_course_code')) {
|
||||
$form->addText(
|
||||
'visual_code',
|
||||
[
|
||||
get_lang('CourseCode'),
|
||||
get_lang('OnlyLettersAndNumbers'),
|
||||
],
|
||||
false,
|
||||
[
|
||||
'maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE,
|
||||
'pattern' => '[a-zA-Z0-9]+',
|
||||
'title' => get_lang('OnlyLettersAndNumbers'),
|
||||
'id' => 'visual_code',
|
||||
]
|
||||
);
|
||||
|
||||
$form->applyFilter('visual_code', 'api_strtoupper');
|
||||
$form->applyFilter('visual_code', 'html_filter');
|
||||
|
||||
$form->addRule(
|
||||
'visual_code',
|
||||
get_lang('Max'),
|
||||
'maxlength',
|
||||
CourseManager::MAX_COURSE_LENGTH_CODE
|
||||
);
|
||||
}
|
||||
|
||||
$countCategories = $courseCategoriesRepo->countAllInAccessUrl(
|
||||
$accessUrlId,
|
||||
api_get_configuration_value('allow_base_course_category')
|
||||
);
|
||||
|
||||
if ($countCategories >= 100) {
|
||||
// Category code
|
||||
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
|
||||
|
||||
$form->addElement(
|
||||
'select_ajax',
|
||||
'category_code',
|
||||
get_lang('CourseFaculty'),
|
||||
null,
|
||||
['url' => $url]
|
||||
);
|
||||
} else {
|
||||
$categories = $courseCategoriesRepo->findAllInAccessUrl(
|
||||
$accessUrlId,
|
||||
api_get_configuration_value('allow_base_course_category')
|
||||
);
|
||||
$categoriesOptions = [null => get_lang('None')];
|
||||
/** @var CourseCategory $category */
|
||||
foreach ($categories as $category) {
|
||||
$categoriesOptions[$category->getCode()] = (string) $category;
|
||||
}
|
||||
$form->addSelect(
|
||||
'category_code',
|
||||
get_lang('CourseFaculty'),
|
||||
$categoriesOptions
|
||||
);
|
||||
}
|
||||
|
||||
if (api_get_configuration_value('course_creation_form_set_course_category_mandatory')) {
|
||||
$form->addRule('category_code', get_lang('ThisFieldIsRequired'), 'required');
|
||||
}
|
||||
|
||||
$currentTeacher = api_get_user_entity(api_get_user_id());
|
||||
|
||||
$form->addSelectAjax(
|
||||
'course_teachers',
|
||||
get_lang('CourseTeachers'),
|
||||
[$currentTeacher->getId() => UserManager::formatUserFullName($currentTeacher, true)],
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=teacher_to_basis_course',
|
||||
'id' => 'course_teachers',
|
||||
'multiple' => 'multiple',
|
||||
]
|
||||
);
|
||||
$form->applyFilter('course_teachers', 'html_filter');
|
||||
|
||||
// Course department
|
||||
$form->addText(
|
||||
'department_name',
|
||||
get_lang('CourseDepartment'),
|
||||
false,
|
||||
['size' => '60', 'id' => 'department_name']
|
||||
);
|
||||
$form->applyFilter('department_name', 'html_filter');
|
||||
$form->applyFilter('department_name', 'trim');
|
||||
|
||||
// Department URL
|
||||
$form->addText(
|
||||
'department_url',
|
||||
get_lang('CourseDepartmentURL'),
|
||||
false,
|
||||
['size' => '60', 'id' => 'department_url']
|
||||
);
|
||||
$form->applyFilter('department_url', 'html_filter');
|
||||
|
||||
// Course language.
|
||||
$languages = api_get_languages();
|
||||
if (count($languages['name']) === 1) {
|
||||
// If there's only one language available, there's no point in asking
|
||||
$form->addElement('hidden', 'course_language', $languages['folder'][0]);
|
||||
} else {
|
||||
$form->addSelectLanguage(
|
||||
'course_language',
|
||||
get_lang('Ln'),
|
||||
[],
|
||||
['style' => 'width:150px']
|
||||
);
|
||||
}
|
||||
|
||||
if (api_get_setting('teacher_can_select_course_template') === 'true') {
|
||||
$form->addElement(
|
||||
'select_ajax',
|
||||
'course_template',
|
||||
[
|
||||
get_lang('CourseTemplate'),
|
||||
get_lang('PickACourseAsATemplateForThisNewCourse'),
|
||||
],
|
||||
null,
|
||||
['url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course']
|
||||
);
|
||||
}
|
||||
|
||||
$form->addElement('checkbox', 'exemplary_content', '', get_lang('FillWithExemplaryContent'));
|
||||
|
||||
$group = [];
|
||||
$group[] = $form->createElement('radio', 'visibility', get_lang('CourseAccess'), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
|
||||
$group[] = $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
|
||||
$group[] = $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
|
||||
$group[] = $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
|
||||
$group[] = $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
|
||||
|
||||
$form->addGroup($group, '', get_lang('CourseAccess'));
|
||||
|
||||
$group = [];
|
||||
$group[] = $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
|
||||
$group[] = $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
|
||||
$form->addGroup($group, '', get_lang('Subscription'));
|
||||
|
||||
$group = [];
|
||||
$group[] = $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
|
||||
$group[] = $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
|
||||
$form->addGroup($group, '', get_lang('Unsubscription'));
|
||||
|
||||
$form->addElement('text', 'disk_quota', [get_lang('CourseQuota'), null, get_lang('MB')], [
|
||||
'id' => 'disk_quota',
|
||||
]);
|
||||
$form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
|
||||
|
||||
$obj = new GradeModel();
|
||||
$obj->fill_grade_model_select_in_form($form);
|
||||
|
||||
//Extra fields
|
||||
$setExtraFieldsMandatory = api_get_configuration_value('course_creation_form_set_extra_fields_mandatory');
|
||||
$fieldsRequired = [];
|
||||
if (false !== $setExtraFieldsMandatory && !empty($setExtraFieldsMandatory['fields'])) {
|
||||
$fieldsRequired = $setExtraFieldsMandatory['fields'];
|
||||
}
|
||||
$extra_field = new ExtraField('course');
|
||||
$extra = $extra_field->addElements(
|
||||
$form,
|
||||
0,
|
||||
[],
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
[],
|
||||
$fieldsRequired
|
||||
);
|
||||
|
||||
if (api_get_configuration_value('allow_course_multiple_languages')) {
|
||||
// Course Multiple language.
|
||||
$cbMultiLanguage = $form->getElementByName('extra_multiple_language');
|
||||
if (isset($cbMultiLanguage)) {
|
||||
foreach ($languages['folder'] as $langFolder) {
|
||||
$cbMultiLanguage->addOption(get_lang($langFolder), $langFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
|
||||
$(function() {
|
||||
'.$extra['jquery_ready_content'].'
|
||||
});
|
||||
</script>';
|
||||
|
||||
$form->addProgress();
|
||||
$form->addButtonCreate(get_lang('CreateCourse'));
|
||||
|
||||
// Set some default values.
|
||||
$values['course_language'] = api_get_setting('platformLanguage');
|
||||
$values['disk_quota'] = round(api_get_setting('default_document_quotum') / 1024 / 1024, 1);
|
||||
|
||||
$default_course_visibility = api_get_setting('courses_default_creation_visibility');
|
||||
|
||||
if (isset($default_course_visibility)) {
|
||||
$values['visibility'] = api_get_setting('courses_default_creation_visibility');
|
||||
} else {
|
||||
$values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
|
||||
}
|
||||
$values['subscribe'] = 1;
|
||||
$values['unsubscribe'] = 0;
|
||||
$values['course_teachers'] = [$currentTeacher->getId()];
|
||||
|
||||
// Relation to prefill course extra field with user extra field
|
||||
$fillExtraField = api_get_configuration_value('course_creation_user_course_extra_field_relation_to_prefill');
|
||||
if (false !== $fillExtraField && !empty($fillExtraField['fields'])) {
|
||||
foreach ($fillExtraField['fields'] as $courseVariable => $userVariable) {
|
||||
$extraValue = UserManager::get_extra_user_data_by_field(api_get_user_id(), $userVariable);
|
||||
$values['extra_'.$courseVariable] = $extraValue[$userVariable];
|
||||
}
|
||||
}
|
||||
|
||||
$form->setDefaults($values);
|
||||
|
||||
// Validate the form
|
||||
if ($form->validate()) {
|
||||
$course = $form->exportValues();
|
||||
|
||||
$course_teachers = isset($course['course_teachers']) ? $course['course_teachers'] : null;
|
||||
$course['disk_quota'] = $course['disk_quota'] * 1024 * 1024;
|
||||
$course['exemplary_content'] = empty($course['exemplary_content']) ? false : true;
|
||||
$course['teachers'] = $course_teachers;
|
||||
$course['wanted_code'] = isset($course['visual_code']) ? $course['visual_code'] : '';
|
||||
$course['gradebook_model_id'] = isset($course['gradebook_model_id']) ? $course['gradebook_model_id'] : null;
|
||||
// Fixing category code
|
||||
$course['course_category'] = isset($course['category_code']) ? $course['category_code'] : '';
|
||||
|
||||
include_once api_get_path(SYS_CODE_PATH).'lang/english/trad4all.inc.php';
|
||||
$file_to_include = api_get_path(SYS_CODE_PATH).'lang/'.$course['course_language'].'/trad4all.inc.php';
|
||||
|
||||
if (file_exists($file_to_include)) {
|
||||
include $file_to_include;
|
||||
}
|
||||
|
||||
$courseInfo = CourseManager::create_course($course);
|
||||
if ($courseInfo && isset($courseInfo['course_public_url'])) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseXAdded'),
|
||||
Display::url($courseInfo['title'], $courseInfo['course_public_url'])
|
||||
),
|
||||
'confirmation',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
header('Location: course_list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Display the form.
|
||||
$content = $form->returnForm();
|
||||
|
||||
$tpl = new Template($tool_name);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
276
main/admin/course_category.php
Normal file
276
main/admin/course_category.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?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();
|
||||
$category = $_GET['category'] ?? null;
|
||||
|
||||
$parentInfo = [];
|
||||
if (!empty($category)) {
|
||||
$parentInfo = CourseCategory::getCategory($category);
|
||||
}
|
||||
$categoryId = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
|
||||
|
||||
if (!empty($categoryId)) {
|
||||
$categoryInfo = CourseCategory::getCategory($categoryId);
|
||||
}
|
||||
$action = $_GET['action'] ?? null;
|
||||
|
||||
$myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');
|
||||
|
||||
$baseUrl = api_get_path(WEB_CODE_PATH).'admin/course_category.php?'
|
||||
.http_build_query(['category' => $parentInfo['code'] ?? '']);
|
||||
|
||||
if (!empty($action)) {
|
||||
if ('export' === $action) {
|
||||
$categoryInfo = CourseCategory::getCategoryById($categoryId);
|
||||
if (!empty($categoryInfo)) {
|
||||
$courses = CourseCategory::getCoursesInCategory($categoryInfo['code'], '', false, false);
|
||||
if (!empty($courses)) {
|
||||
$name = api_get_local_time().'_'.$categoryInfo['code'];
|
||||
$courseList = array_map(
|
||||
function ($value) {
|
||||
return [$value];
|
||||
},
|
||||
array_column($courses, 'title')
|
||||
);
|
||||
Export::arrayToCsv($courseList, $name);
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('HaveNoCourse')));
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'delete') {
|
||||
CourseCategory::deleteNode($categoryId);
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
header('Location: '.$baseUrl);
|
||||
exit();
|
||||
} elseif (($action === 'add' || $action === 'edit') && isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
$newParentCategoryCode = $_POST['parent_id'] ?? $parentInfo['code'] ?? '';
|
||||
|
||||
if ($action === 'add') {
|
||||
$ret = CourseCategory::addNode(
|
||||
$_POST['code'],
|
||||
$_POST['name'],
|
||||
$_POST['auth_course_child'],
|
||||
$newParentCategoryCode
|
||||
);
|
||||
|
||||
$errorMsg = Display::return_message(get_lang('Created'));
|
||||
} else {
|
||||
$ret = CourseCategory::editNode(
|
||||
$_POST['code'],
|
||||
$_POST['name'],
|
||||
$_POST['auth_course_child'],
|
||||
$categoryId,
|
||||
$newParentCategoryCode,
|
||||
$parentInfo['code'] ?? ''
|
||||
);
|
||||
$categoryInfo = CourseCategory::getCategory($_POST['code']);
|
||||
$ret = $categoryInfo['id'];
|
||||
$errorMsg = Display::return_message(get_lang('Updated'));
|
||||
}
|
||||
if (!$ret) {
|
||||
$errorMsg = Display::return_message(get_lang('CatCodeAlreadyUsed'), 'error');
|
||||
} else {
|
||||
if ($myCourseListAsCategory) {
|
||||
if (isset($_FILES['image'])) {
|
||||
CourseCategory::saveImage($ret, $_FILES['image']);
|
||||
}
|
||||
CourseCategory::saveDescription($ret, $_POST['description']);
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash($errorMsg);
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'admin/course_category.php');
|
||||
exit;
|
||||
} elseif ($action === 'moveUp') {
|
||||
CourseCategory::moveNodeUp($categoryId, $_GET['tree_pos'], $parentInfo['code'] ?? '');
|
||||
header('Location: '.$baseUrl);
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
function showCourses(button, categoryId) {
|
||||
event.preventDefault();
|
||||
let url = button.getAttribute("href");
|
||||
let tableId = "cat_" + categoryId;
|
||||
let exists = button.parentNode.parentNode.parentNode.querySelector("#" + tableId);
|
||||
if (exists !== null) {
|
||||
button.parentNode.parentNode.parentNode.removeChild(exists);
|
||||
return ;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: "GET",
|
||||
success: function(result) {
|
||||
let row = document.createElement("tr");
|
||||
row.setAttribute("id", tableId);
|
||||
let cell = document.createElement("td");
|
||||
cell.setAttribute("colspan", "4");
|
||||
cell.innerHTML= result;
|
||||
row.appendChild(cell);
|
||||
button.parentNode.parentNode.parentNode.insertBefore(row, button.parentNode.parentNode.nextSibling);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>';
|
||||
|
||||
$tool_name = get_lang('AdminCategories');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
$urlId = api_get_current_access_url_id();
|
||||
|
||||
if ($action === 'add' || $action === 'edit') {
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('folder_up.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
|
||||
$baseUrl
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
$form_title = $action === 'add' ? get_lang('AddACategory') : get_lang('EditNode');
|
||||
if (!empty($categoryInfo['parent_id'])) {
|
||||
$form_title .= ' '.get_lang('Into').' '.$categoryInfo['parent_id'];
|
||||
}
|
||||
$url = $baseUrl.'&'
|
||||
.http_build_query(['action' => Security::remove_XSS($action), 'id' => Security::remove_XSS($categoryId)]);
|
||||
$form = new FormValidator('course_category', 'post', $url);
|
||||
$form->addElement('header', '', $form_title);
|
||||
$form->addElement('hidden', 'formSent', 1);
|
||||
$form->addElement('text', 'code', get_lang("CategoryCode"));
|
||||
|
||||
if (api_get_configuration_value('save_titles_as_html')) {
|
||||
$form->addHtmlEditor(
|
||||
'name',
|
||||
get_lang('CategoryName'),
|
||||
true,
|
||||
false,
|
||||
['ToolbarSet' => 'TitleAsHtml']
|
||||
);
|
||||
} else {
|
||||
$form->addElement('text', 'name', get_lang("CategoryName"));
|
||||
$form->addRule('name', get_lang('PleaseEnterCategoryInfo'), 'required');
|
||||
}
|
||||
|
||||
$form->addRule('code', get_lang('PleaseEnterCategoryInfo'), 'required');
|
||||
|
||||
$categories = ['' => get_lang('Select')];
|
||||
|
||||
foreach (CourseCategory::getAllCategories() as $categoryItemInfo) {
|
||||
if ($categoryId === $categoryItemInfo['code']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$categories[$categoryItemInfo['code']] = $categoryItemInfo['name'];
|
||||
}
|
||||
|
||||
$form->addSelect('parent_id', get_lang('ParentCategory'), $categories);
|
||||
|
||||
$group = [
|
||||
$form->createElement(
|
||||
'radio',
|
||||
'auth_course_child',
|
||||
get_lang('AllowCoursesInCategory'),
|
||||
get_lang('Yes'),
|
||||
'TRUE'
|
||||
),
|
||||
$form->createElement(
|
||||
'radio',
|
||||
'auth_course_child',
|
||||
null,
|
||||
get_lang('No'),
|
||||
'FALSE'
|
||||
),
|
||||
];
|
||||
$form->addGroup($group, null, get_lang('AllowCoursesInCategory'));
|
||||
|
||||
if ($myCourseListAsCategory) {
|
||||
$form->addHtmlEditor(
|
||||
'description',
|
||||
get_lang('Description'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Minimal']
|
||||
);
|
||||
$form->addFile('image', get_lang('Image'), ['accept' => 'image/*']);
|
||||
if ($action === 'edit' && !empty($categoryInfo['image'])) {
|
||||
$form->addHtml('
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-8">'.
|
||||
Display::img(
|
||||
api_get_path(WEB_UPLOAD_PATH).$categoryInfo['image'],
|
||||
get_lang('Image'),
|
||||
['width' => 256]
|
||||
).'</div>
|
||||
</div>
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($categoryInfo)) {
|
||||
$class = 'save';
|
||||
$text = get_lang('Save');
|
||||
$form->setDefaults($categoryInfo);
|
||||
$form->addButtonSave($text);
|
||||
} else {
|
||||
$class = 'add';
|
||||
$text = get_lang('AddCategory');
|
||||
$form->setDefaults(
|
||||
[
|
||||
'auth_course_child' => 'TRUE',
|
||||
'parent_id' => $parentInfo['code'] ?? '',
|
||||
]
|
||||
);
|
||||
$form->addButtonCreate($text);
|
||||
}
|
||||
$form->display();
|
||||
} else {
|
||||
// If multiple URLs and not main URL, prevent deletion and inform user
|
||||
if ($action === 'delete' && api_get_multiple_access_url() && $urlId != 1) {
|
||||
echo Display::return_message(get_lang('CourseCategoriesAreGlobal'), 'warning');
|
||||
}
|
||||
echo '<div class="actions">';
|
||||
$link = null;
|
||||
if (!empty($parentInfo)) {
|
||||
$parentCode = $parentInfo['parent_id'];
|
||||
echo Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$parentCode
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($parentInfo) || $parentInfo['auth_cat_child'] === 'TRUE') {
|
||||
$newCategoryLink = Display::url(
|
||||
Display::return_icon('new_folder.png', get_lang('AddACategory'), '', ICON_SIZE_MEDIUM),
|
||||
$baseUrl.'&action=add'
|
||||
);
|
||||
|
||||
if (!empty($parentInfo) && $parentInfo['access_url_id'] != $urlId) {
|
||||
$newCategoryLink = '';
|
||||
}
|
||||
echo $newCategoryLink;
|
||||
}
|
||||
echo '</div>';
|
||||
if (!empty($parentInfo)) {
|
||||
echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
|
||||
}
|
||||
echo CourseCategory::listCategories($parentInfo['code'] ?? '');
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
588
main/admin/course_edit.php
Normal file
588
main/admin/course_edit.php
Normal file
@@ -0,0 +1,588 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\CourseCategory;
|
||||
use Chamilo\CoreBundle\Entity\Repository\CourseCategoryRepository;
|
||||
use Chamilo\UserBundle\Entity\User;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$em = Database::getManager();
|
||||
/** @var CourseCategoryRepository $courseCategoriesRepo */
|
||||
$courseCategoriesRepo = $em->getRepository('ChamiloCoreBundle:CourseCategory');
|
||||
// Get all possible teachers.
|
||||
$urlId = api_get_current_access_url_id();
|
||||
|
||||
$courseId = isset($_GET['id']) ? $_GET['id'] : null;
|
||||
|
||||
if (empty($courseId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$courseCode = $courseInfo['code'];
|
||||
|
||||
if (empty($courseInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$tool_name = get_lang('ModifyCourseInfo');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
|
||||
|
||||
// Get all course categories
|
||||
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$course_code = $courseInfo['code'];
|
||||
$courseId = $courseInfo['real_id'];
|
||||
|
||||
// Get course teachers
|
||||
$table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
|
||||
$sql = "SELECT user.id as user_id,lastname,firstname
|
||||
FROM
|
||||
$table_user as user,
|
||||
$table_course_user as course_user
|
||||
WHERE
|
||||
course_user.status='1' AND
|
||||
course_user.user_id=user.id AND
|
||||
course_user.c_id ='".$courseId."'".
|
||||
$order_clause;
|
||||
$res = Database::query($sql);
|
||||
$course_teachers = [];
|
||||
while ($obj = Database::fetch_object($res)) {
|
||||
$course_teachers[] = $obj->user_id;
|
||||
}
|
||||
|
||||
// Get all possible teachers without the course teachers
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$sql = "SELECT u.id as user_id,lastname,firstname
|
||||
FROM $table_user as u
|
||||
INNER JOIN $access_url_rel_user_table url_rel_user
|
||||
ON (u.id=url_rel_user.user_id)
|
||||
WHERE
|
||||
url_rel_user.access_url_id = $urlId AND
|
||||
status = 1".$order_clause;
|
||||
} else {
|
||||
$sql = "SELECT id as user_id, lastname, firstname
|
||||
FROM $table_user WHERE status='1'".$order_clause;
|
||||
}
|
||||
$courseInfo['tutor_name'] = null;
|
||||
|
||||
$res = Database::query($sql);
|
||||
$teachers = [];
|
||||
$allTeachers = [];
|
||||
$platform_teachers[0] = '-- '.get_lang('NoManager').' --';
|
||||
while ($obj = Database::fetch_object($res)) {
|
||||
$allTeachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
|
||||
if (!array_key_exists($obj->user_id, $course_teachers)) {
|
||||
$teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
|
||||
}
|
||||
|
||||
if (isset($course_teachers[$obj->user_id]) &&
|
||||
$courseInfo['tutor_name'] == $course_teachers[$obj->user_id]
|
||||
) {
|
||||
$courseInfo['tutor_name'] = $obj->user_id;
|
||||
}
|
||||
// We add in the array platform teachers
|
||||
$platform_teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
|
||||
}
|
||||
|
||||
// Case where there is no teacher in the course
|
||||
if (count($course_teachers) == 0) {
|
||||
$sql = 'SELECT tutor_name FROM '.$course_table.' WHERE code="'.$course_code.'"';
|
||||
$res = Database::query($sql);
|
||||
$tutor_name = Database::result($res, 0, 0);
|
||||
$courseInfo['tutor_name'] = array_search($tutor_name, $platform_teachers);
|
||||
}
|
||||
|
||||
// Build the form
|
||||
$form = new FormValidator(
|
||||
'update_course',
|
||||
'post',
|
||||
api_get_self().'?id='.$courseId
|
||||
);
|
||||
$form->addHeader(get_lang('Course').' #'.$courseInfo['real_id'].' '.$course_code);
|
||||
$form->addElement('hidden', 'code', $course_code);
|
||||
|
||||
//title
|
||||
$form->addText('title', get_lang('Title'), true);
|
||||
$form->applyFilter('title', 'html_filter');
|
||||
$form->applyFilter('title', 'trim');
|
||||
|
||||
// Code
|
||||
$element = $form->addElement(
|
||||
'text',
|
||||
'real_code',
|
||||
[get_lang('CourseCode'), get_lang('ThisValueCantBeChanged')]
|
||||
);
|
||||
$element->freeze();
|
||||
|
||||
// Visual code
|
||||
$form->addText(
|
||||
'visual_code',
|
||||
[
|
||||
get_lang('VisualCode'),
|
||||
get_lang('OnlyLettersAndNumbers'),
|
||||
get_lang('ThisValueIsUsedInTheCourseURL'),
|
||||
],
|
||||
true,
|
||||
[
|
||||
'maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE,
|
||||
'pattern' => '[a-zA-Z0-9]+',
|
||||
'title' => get_lang('OnlyLettersAndNumbers'),
|
||||
]
|
||||
);
|
||||
|
||||
$form->applyFilter('visual_code', 'strtoupper');
|
||||
$form->applyFilter('visual_code', 'html_filter');
|
||||
|
||||
$countCategories = $courseCategoriesRepo->countAllInAccessUrl(
|
||||
$urlId,
|
||||
api_get_configuration_value('allow_base_course_category')
|
||||
);
|
||||
if ($countCategories >= 100) {
|
||||
// Category code
|
||||
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
|
||||
|
||||
$categorySelect = $form->addElement(
|
||||
'select_ajax',
|
||||
'category_code',
|
||||
get_lang('CourseFaculty'),
|
||||
null,
|
||||
['url' => $url]
|
||||
);
|
||||
|
||||
if (!empty($courseInfo['categoryCode'])) {
|
||||
$data = \CourseCategory::getCategory($courseInfo['categoryCode']);
|
||||
$categorySelect->addOption($data['name'], $data['code']);
|
||||
}
|
||||
} else {
|
||||
$courseInfo['category_code'] = $courseInfo['categoryCode'];
|
||||
$categories = $courseCategoriesRepo->findAllInAccessUrl(
|
||||
$urlId,
|
||||
api_get_configuration_value('allow_base_course_category')
|
||||
);
|
||||
$categoriesOptions = [null => get_lang('None')];
|
||||
|
||||
/** @var CourseCategory $category */
|
||||
foreach ($categories as $category) {
|
||||
$categoriesOptions[$category->getCode()] = (string) $category;
|
||||
}
|
||||
|
||||
$form->addSelect(
|
||||
'category_code',
|
||||
get_lang('CourseFaculty'),
|
||||
$categoriesOptions
|
||||
);
|
||||
}
|
||||
|
||||
$courseTeacherNames = [];
|
||||
foreach ($course_teachers as $courseTeacherId) {
|
||||
/** @var User $courseTeacher */
|
||||
$courseTeacher = UserManager::getRepository()->find($courseTeacherId);
|
||||
$courseTeacherNames[$courseTeacher->getId()] = UserManager::formatUserFullName($courseTeacher, true);
|
||||
}
|
||||
|
||||
$form->addSelectAjax(
|
||||
'course_teachers',
|
||||
get_lang('CourseTeachers'),
|
||||
$courseTeacherNames,
|
||||
['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=teacher_to_basis_course', 'multiple' => 'multiple']
|
||||
);
|
||||
$courseInfo['course_teachers'] = $course_teachers;
|
||||
if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
|
||||
$form->addElement(
|
||||
'checkbox',
|
||||
'add_teachers_to_sessions_courses',
|
||||
null,
|
||||
get_lang('TeachersWillBeAddedAsCoachInAllCourseSessions')
|
||||
);
|
||||
}
|
||||
|
||||
$allowEditSessionCoaches = api_get_configuration_value('disabled_edit_session_coaches_course_editing_course') === false;
|
||||
$coursesInSession = SessionManager::get_session_by_course($courseInfo['real_id']);
|
||||
if (!empty($coursesInSession) && $allowEditSessionCoaches) {
|
||||
foreach ($coursesInSession as $session) {
|
||||
$sessionId = $session['id'];
|
||||
$coaches = SessionManager::getCoachesByCourseSession(
|
||||
$sessionId,
|
||||
$courseInfo['real_id']
|
||||
);
|
||||
$teachers = $allTeachers;
|
||||
|
||||
$sessionTeachers = [];
|
||||
foreach ($coaches as $coachId) {
|
||||
$sessionTeachers[] = $coachId;
|
||||
|
||||
if (isset($teachers[$coachId])) {
|
||||
unset($teachers[$coachId]);
|
||||
}
|
||||
}
|
||||
|
||||
$groupName = 'session_coaches_'.$sessionId;
|
||||
$sessionUrl = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$sessionId;
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
$groupName,
|
||||
Display::url(
|
||||
$session['name'],
|
||||
$sessionUrl,
|
||||
['target' => '_blank']
|
||||
).' - '.get_lang('Coaches'),
|
||||
$allTeachers
|
||||
);
|
||||
$courseInfo[$groupName] = $sessionTeachers;
|
||||
}
|
||||
}
|
||||
|
||||
$form->addText('department_name', get_lang('CourseDepartment'), false, ['size' => '60']);
|
||||
$form->applyFilter('department_name', 'html_filter');
|
||||
$form->applyFilter('department_name', 'trim');
|
||||
|
||||
$form->addText('department_url', get_lang('CourseDepartmentURL'), false, ['size' => '60']);
|
||||
$form->applyFilter('department_url', 'html_filter');
|
||||
$form->applyFilter('department_url', 'trim');
|
||||
|
||||
$form->addSelectLanguage('course_language', get_lang('CourseLanguage'));
|
||||
|
||||
$group = [];
|
||||
$group[] = $form->createElement(
|
||||
'radio',
|
||||
'visibility',
|
||||
get_lang('CourseAccess'),
|
||||
get_lang('OpenToTheWorld'),
|
||||
COURSE_VISIBILITY_OPEN_WORLD
|
||||
);
|
||||
$group[] = $form->createElement(
|
||||
'radio',
|
||||
'visibility',
|
||||
null,
|
||||
get_lang('OpenToThePlatform'),
|
||||
COURSE_VISIBILITY_OPEN_PLATFORM
|
||||
);
|
||||
$group[] = $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
|
||||
$group[] = $form->createElement(
|
||||
'radio',
|
||||
'visibility',
|
||||
null,
|
||||
get_lang('CourseVisibilityClosed'),
|
||||
COURSE_VISIBILITY_CLOSED
|
||||
);
|
||||
$group[] = $form->createElement(
|
||||
'radio',
|
||||
'visibility',
|
||||
null,
|
||||
get_lang('CourseVisibilityHidden'),
|
||||
COURSE_VISIBILITY_HIDDEN
|
||||
);
|
||||
$form->addGroup($group, '', get_lang('CourseAccess'));
|
||||
|
||||
$group = [];
|
||||
$group[] = $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
|
||||
$group[] = $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
|
||||
$form->addGroup($group, '', get_lang('Subscription'));
|
||||
|
||||
$group = [];
|
||||
$group[] = $form->createElement(
|
||||
'radio',
|
||||
'unsubscribe',
|
||||
get_lang('Unsubscription'),
|
||||
get_lang('AllowedToUnsubscribe'),
|
||||
1
|
||||
);
|
||||
$group[] = $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
|
||||
$form->addGroup($group, '', get_lang('Unsubscription'));
|
||||
|
||||
$form->addElement('text', 'disk_quota', [get_lang('CourseQuota'), null, get_lang('MB')]);
|
||||
$form->addRule('disk_quota', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
|
||||
|
||||
// Extra fields
|
||||
$extra_field = new ExtraField('course');
|
||||
$extra = $extra_field->addElements(
|
||||
$form,
|
||||
$courseId,
|
||||
[],
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
if (api_get_configuration_value('allow_course_multiple_languages')) {
|
||||
// Course Multiple language.
|
||||
$languages = api_get_languages();
|
||||
$cbMultiLanguage = $form->getElementByName('extra_multiple_language');
|
||||
if (isset($cbMultiLanguage)) {
|
||||
foreach ($languages['folder'] as $langFolder) {
|
||||
$cbMultiLanguage->addOption(get_lang($langFolder), $langFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (api_get_configuration_value('multiple_access_url_show_shared_course_marker')) {
|
||||
$urls = UrlManager::get_access_url_from_course($courseId);
|
||||
$urlToString = '';
|
||||
foreach ($urls as $url) {
|
||||
$urlToString .= $url['url'].'<br />';
|
||||
}
|
||||
$form->addLabel('URLs', $urlToString);
|
||||
}
|
||||
$allowSkillRelItem = api_get_configuration_value('allow_skill_rel_items');
|
||||
if ($allowSkillRelItem) {
|
||||
Skill::setSkillsToCourse($form, $courseId);
|
||||
$htmlContentExtraClass[] = 'feature-item-user-skill-on';
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
$(function() {
|
||||
'.$extra['jquery_ready_content'].'
|
||||
});
|
||||
</script>';
|
||||
|
||||
$form->addButtonUpdate(get_lang('ModifyCourseInfo'));
|
||||
|
||||
// Set some default values
|
||||
$courseInfo['disk_quota'] = round(DocumentManager::get_course_quota($courseInfo['code']) / 1024 / 1024, 1);
|
||||
$courseInfo['real_code'] = $courseInfo['code'];
|
||||
$courseInfo['add_teachers_to_sessions_courses'] = $courseInfo['add_teachers_to_sessions_courses'] ?? 0;
|
||||
$form->setDefaults($courseInfo);
|
||||
|
||||
// Validate form
|
||||
if ($form->validate()) {
|
||||
$course = $form->getSubmitValues();
|
||||
$visibility = $course['visibility'];
|
||||
|
||||
/*if ($allowSkillRelItem) {
|
||||
$result = Skill::saveSkillsToCourseFromForm($form);
|
||||
}*/
|
||||
|
||||
global $_configuration;
|
||||
|
||||
if (isset($_configuration[$urlId]) &&
|
||||
isset($_configuration[$urlId]['hosting_limit_active_courses']) &&
|
||||
$_configuration[$urlId]['hosting_limit_active_courses'] > 0
|
||||
) {
|
||||
// Check if
|
||||
if ($courseInfo['visibility'] == COURSE_VISIBILITY_HIDDEN &&
|
||||
$visibility != $courseInfo['visibility']
|
||||
) {
|
||||
$num = CourseManager::countActiveCourses($urlId);
|
||||
if ($num >= $_configuration[$urlId]['hosting_limit_active_courses']) {
|
||||
api_warn_hosting_contact('hosting_limit_active_courses');
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('PortalActiveCoursesLimitReached'))
|
||||
);
|
||||
|
||||
header('Location: course_list.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$visual_code = $course['visual_code'];
|
||||
$visual_code = CourseManager::generate_course_code($visual_code);
|
||||
|
||||
// Check if the visual code is already used by *another* course
|
||||
$visual_code_is_used = false;
|
||||
|
||||
$warn = get_lang('TheFollowingCoursesAlreadyUseThisVisualCode');
|
||||
if (!empty($visual_code)) {
|
||||
$list = CourseManager::get_courses_info_from_visual_code($visual_code);
|
||||
foreach ($list as $course_temp) {
|
||||
if ($course_temp['code'] != $course_code) {
|
||||
$visual_code_is_used = true;
|
||||
$warn .= ' '.$course_temp['title'].' ('.$course_temp['code'].'),';
|
||||
}
|
||||
}
|
||||
$warn = substr($warn, 0, -1);
|
||||
}
|
||||
|
||||
$teachers = isset($course['course_teachers']) ? $course['course_teachers'] : '';
|
||||
$title = $course['title'];
|
||||
$category_code = isset($course['category_code']) ? $course['category_code'] : '';
|
||||
$department_name = $course['department_name'];
|
||||
$department_url = $course['department_url'];
|
||||
$course_language = $course['course_language'];
|
||||
$course['disk_quota'] = $course['disk_quota'] * 1024 * 1024;
|
||||
$disk_quota = $course['disk_quota'];
|
||||
$subscribe = $course['subscribe'];
|
||||
$unsubscribe = $course['unsubscribe'];
|
||||
$course['course_code'] = $course_code;
|
||||
|
||||
if (!stristr($department_url, 'http://')) {
|
||||
$department_url = 'http://'.$department_url;
|
||||
}
|
||||
|
||||
Database::query($sql);
|
||||
|
||||
$courseInfoBeforeUpdate = api_get_course_info_by_id($courseId);
|
||||
$title = str_replace('&', '&', $title);
|
||||
$params = [
|
||||
'title' => $title,
|
||||
'course_language' => $course_language,
|
||||
'category_code' => $category_code,
|
||||
'department_name' => $department_name,
|
||||
'department_url' => $department_url,
|
||||
'visibility' => $visibility,
|
||||
'subscribe' => $subscribe,
|
||||
'unsubscribe' => $unsubscribe,
|
||||
'disk_quota' => $disk_quota,
|
||||
'visual_code' => $visual_code,
|
||||
];
|
||||
Database::update($course_table, $params, ['id = ?' => $courseId]);
|
||||
CourseManager::saveSettingChanges($courseInfoBeforeUpdate, $params);
|
||||
|
||||
// update the extra fields
|
||||
$courseFieldValue = new ExtraFieldValue('course');
|
||||
$courseFieldValue->saveFieldValues($course);
|
||||
$addTeacherToSessionCourses = isset($course['add_teachers_to_sessions_courses']) && !empty($course['add_teachers_to_sessions_courses']) ? 1 : 0;
|
||||
|
||||
// Updating teachers
|
||||
if ($addTeacherToSessionCourses) {
|
||||
foreach ($coursesInSession as $session) {
|
||||
$sessionId = $session['id'];
|
||||
// Updating session coaches
|
||||
$sessionCoaches = isset($course['session_coaches_'.$sessionId]) ? $course['session_coaches_'.$sessionId] : [];
|
||||
|
||||
if (!empty($sessionCoaches)) {
|
||||
foreach ($sessionCoaches as $teacherInfo) {
|
||||
$coachesToSubscribe = isset($teacherInfo['coaches_by_session']) ? $teacherInfo['coaches_by_session'] : [];
|
||||
SessionManager::updateCoaches(
|
||||
$sessionId,
|
||||
$courseId,
|
||||
$coachesToSubscribe,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CourseManager::updateTeachers(
|
||||
$courseInfo,
|
||||
$teachers,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
// Normal behaviour
|
||||
CourseManager::updateTeachers($courseInfo, $teachers, true, false);
|
||||
|
||||
foreach ($coursesInSession as $session) {
|
||||
$sessionId = $session['id'];
|
||||
// Updating session coaches
|
||||
$sessionCoaches = isset($course['session_coaches_'.$sessionId]) ? $course['session_coaches_'.$sessionId] : [];
|
||||
|
||||
if (!empty($sessionCoaches)) {
|
||||
SessionManager::updateCoaches(
|
||||
$sessionId,
|
||||
$courseId,
|
||||
$sessionCoaches,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
|
||||
$sql = "UPDATE $course_table SET
|
||||
add_teachers_to_sessions_courses = '$addTeacherToSessionCourses'
|
||||
WHERE id = ".$courseInfo['real_id'];
|
||||
Database::query($sql);
|
||||
}
|
||||
|
||||
$courseInfo = api_get_course_info($courseInfo['code']);
|
||||
$message = Display::url($courseInfo['title'], $courseInfo['course_public_url']);
|
||||
Display::addFlash(Display::return_message(get_lang('ItemUpdated').': '.$message, 'info', false));
|
||||
if ($visual_code_is_used) {
|
||||
Display::addFlash(Display::return_message($warn));
|
||||
}
|
||||
header('Location: course_list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back')),
|
||||
api_get_path(WEB_CODE_PATH).'admin/course_list.php'
|
||||
);
|
||||
echo Display::url(
|
||||
Display::return_icon('course_home.png', get_lang('CourseHome')),
|
||||
$courseInfo['course_public_url'],
|
||||
['target' => '_blank']
|
||||
);
|
||||
|
||||
echo Display::url(
|
||||
Display::return_icon('info2.png', get_lang('Info')),
|
||||
api_get_path(WEB_CODE_PATH)."admin/course_information.php?code=$courseCode"
|
||||
);
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo "<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() {
|
||||
// Checking all multiple
|
||||
$('select').filter(function() {
|
||||
if ($(this).attr('multiple')) {
|
||||
$(this).find('option').each(function() {
|
||||
$(this).attr('selected', true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>";
|
||||
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
210
main/admin/course_export.php
Normal file
210
main/admin/course_export.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This tool allows platform admins to export courses to CSV file.
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
|
||||
$tool_name = get_lang('ExportCourses');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$course_list = CourseManager::get_courses_list(
|
||||
0,
|
||||
0,
|
||||
'title',
|
||||
'ASC',
|
||||
-1,
|
||||
'',
|
||||
api_get_current_access_url_id()
|
||||
);
|
||||
$formSent = null;
|
||||
$courses = $selected_courses = [];
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
$formSent = $_POST['formSent'];
|
||||
$select_type = (int) ($_POST['select_type']);
|
||||
$file_type = $_POST['file_type'];
|
||||
$includeUsers = (empty($_POST['include_users']) ? false : true);
|
||||
$includeExtraFields = (isset($_POST['include_extrafields']) && 1 === (int) $_POST['include_extrafields']);
|
||||
|
||||
if (2 == $select_type) {
|
||||
// Get selected courses from courses list in form sent
|
||||
$selected_courses = $_POST['course_code'];
|
||||
if (is_array($selected_courses)) {
|
||||
foreach ($course_list as $course) {
|
||||
if (!in_array($course['code'], $selected_courses)) {
|
||||
continue;
|
||||
}
|
||||
$courses[$course['real_id']] = $course;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Get all courses
|
||||
foreach ($course_list as $course) {
|
||||
$courses[$course['real_id']] = $course;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($courses)) {
|
||||
$archiveFile = 'export_courses_list_'.api_get_local_time();
|
||||
$listToExport[] = [
|
||||
'Code',
|
||||
'Title',
|
||||
'CourseCategory',
|
||||
'CourseCategoryName',
|
||||
'Teacher',
|
||||
'Language',
|
||||
'Visibility',
|
||||
];
|
||||
if ($includeUsers) {
|
||||
$listToExport[0][] = 'Users';
|
||||
$listToExport[0][] = 'OtherTeachers';
|
||||
}
|
||||
if ($includeExtraFields) {
|
||||
$extraField = new ExtraField('course');
|
||||
$allExtraFields = $extraField->get_all();
|
||||
foreach ($allExtraFields as $extra) {
|
||||
$listToExport[0][] = $extra['display_text'];
|
||||
}
|
||||
}
|
||||
$dataToExport = [];
|
||||
foreach ($courses as $courseId => $course) {
|
||||
$dataToExport['code'] = str_replace(';', ',', $course['code']);
|
||||
$dataToExport['title'] = str_replace(';', ',', $course['title']);
|
||||
$dataToExport['category_code'] = str_replace(';', ',', $course['category_code']);
|
||||
$categoryInfo = CourseCategory::getCategory($course['category_code']);
|
||||
if ($categoryInfo) {
|
||||
$dataToExport['category_name'] = str_replace(';', ',', $categoryInfo['name']);
|
||||
} else {
|
||||
$dataToExport['category_name'] = '';
|
||||
}
|
||||
$dataToExport['tutor_name'] = str_replace(';', ',', $course['tutor_name']);
|
||||
$dataToExport['course_language'] = str_replace(';', ',', $course['course_language']);
|
||||
$dataToExport['visibility'] = str_replace(';', ',', $course['visibility']);
|
||||
|
||||
if ($includeUsers) {
|
||||
$dataToExport['students'] = '';
|
||||
$dataToExport['teachers'] = '';
|
||||
$usersInCourse = CourseManager::get_user_list_from_course_code($course['code']);
|
||||
|
||||
if (is_array($usersInCourse) && !empty($usersInCourse)) {
|
||||
foreach ($usersInCourse as $user) {
|
||||
if ($user['status_rel'] == COURSEMANAGER) {
|
||||
$dataToExport['teachers'] .= $user['username'].'|';
|
||||
} else {
|
||||
$dataToExport['students'] .= $user['username'].'|';
|
||||
}
|
||||
}
|
||||
}
|
||||
$dataToExport['students'] = substr($dataToExport['students'], 0, -1);
|
||||
$dataToExport['teachers'] = substr($dataToExport['teachers'], 0, -1);
|
||||
}
|
||||
$listToExport[$courseId] = $dataToExport;
|
||||
}
|
||||
|
||||
if ($includeExtraFields) {
|
||||
foreach ($allExtraFields as $extra) {
|
||||
$default = $extraField->getDefaultValueByFieldId($extra['id']);
|
||||
$fieldValues = $extraField->getAllValuesByFieldId($extra['id']);
|
||||
foreach ($listToExport as $courseId => &$values) {
|
||||
if ($courseId === 0) {
|
||||
continue;
|
||||
}
|
||||
if (isset($fieldValues[$courseId])) {
|
||||
if (is_array($fieldValues[$courseId])) {
|
||||
$values['extra_'.$extra['variable']] = $fieldValues[$courseId];
|
||||
} else {
|
||||
$values[$extra['variable']] = $fieldValues[$courseId];
|
||||
}
|
||||
} else {
|
||||
$values[$extra['variable']] = $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($file_type) {
|
||||
case 'xml':
|
||||
// Remove header
|
||||
unset($listToExport[0]);
|
||||
Export::arrayToXml($listToExport, $archiveFile);
|
||||
break;
|
||||
case 'csv':
|
||||
Export::arrayToCsv($listToExport, $archiveFile);
|
||||
break;
|
||||
case 'xls':
|
||||
Export::arrayToXls($listToExport, $archiveFile);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('ThereAreNotSelectedCoursesOrCoursesListIsEmpty')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$form = new FormValidator('export', 'post', api_get_self());
|
||||
$form->addHeader($tool_name);
|
||||
$form->addHidden('formSent', 1);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'select_type',
|
||||
get_lang('Option'),
|
||||
get_lang('ExportAllCoursesList'),
|
||||
'1',
|
||||
['onclick' => "javascript: if(this.checked){document.getElementById('div-course-list').style.display='none';}"]
|
||||
);
|
||||
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'select_type',
|
||||
'',
|
||||
get_lang('ExportSelectedCoursesFromCoursesList'),
|
||||
'2',
|
||||
['onclick' => "javascript: if(this.checked){document.getElementById('div-course-list').style.display='block';}"]
|
||||
);
|
||||
|
||||
if (!empty($course_list)) {
|
||||
$form->addHtml('<div id="div-course-list" style="display:none">');
|
||||
$coursesInList = [];
|
||||
foreach ($course_list as $course) {
|
||||
$coursesInList[$course['code']] = $course['title'].' ('.$course['code'].')';
|
||||
}
|
||||
|
||||
$form->addSelect(
|
||||
'course_code',
|
||||
get_lang('WhichCoursesToExport'),
|
||||
$coursesInList,
|
||||
['multiple' => 'multiple']
|
||||
);
|
||||
|
||||
$form->addHtml('</div>');
|
||||
}
|
||||
|
||||
$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']);
|
||||
|
||||
$form->addElement('checkbox', 'include_users', get_lang('ExportUsers'), '', '1');
|
||||
|
||||
$form->addElement('checkbox', 'include_extrafields', get_lang('ExportExtraFields'), '', '1');
|
||||
|
||||
$form->setDefaults(['select_type' => '1', 'file_type' => 'csv', 'include_users' => '1', 'include_extrafields' => 0]);
|
||||
|
||||
$form->addButtonExport(get_lang('ExportCourses'));
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
281
main/admin/course_import.php
Normal file
281
main/admin/course_import.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This tool allows platform admins to create courses by uploading a CSV file
|
||||
* Copyright (c) 2005 Bart Mollet <bart.mollet@hogent.be>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validates imported data.
|
||||
*
|
||||
* @param array $courses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function validate_courses_data($courses)
|
||||
{
|
||||
$errors = [];
|
||||
$coursecodes = [];
|
||||
foreach ($courses as $index => $course) {
|
||||
$course['line'] = $index + 1;
|
||||
|
||||
// 1. Check whether mandatory fields are set.
|
||||
$mandatory_fields = ['Code', 'Title', 'CourseCategory'];
|
||||
foreach ($mandatory_fields as $field) {
|
||||
if (empty($course[$field])) {
|
||||
$course['error'] = get_lang($field.'Mandatory');
|
||||
$errors[] = $course;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Check current course code.
|
||||
if (!empty($course['Code'])) {
|
||||
// 2.1 Check whether code has been already used by this CVS-file.
|
||||
if (isset($coursecodes[$course['Code']])) {
|
||||
$course['error'] = get_lang('CodeTwiceInFile');
|
||||
$errors[] = $course;
|
||||
} else {
|
||||
// 2.2 Check whether course code has been occupied.
|
||||
$courseInfo = api_get_course_info($course['Code']);
|
||||
if (!empty($courseInfo)) {
|
||||
$course['error'] = get_lang('CodeExists');
|
||||
$errors[] = $course;
|
||||
}
|
||||
}
|
||||
$coursecodes[$course['Code']] = 1;
|
||||
}
|
||||
|
||||
// 3. Check whether teacher exists.
|
||||
$teacherList = getTeacherListInArray($course['Teacher']);
|
||||
|
||||
if (!empty($teacherList)) {
|
||||
foreach ($teacherList as $teacher) {
|
||||
$teacherInfo = api_get_user_info_from_username($teacher);
|
||||
if (empty($teacherInfo)) {
|
||||
$course['error'] = get_lang('UnknownTeacher').' ('.$teacher.')';
|
||||
$errors[] = $course;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($course['CourseCategory'])) {
|
||||
$categoryInfo = CourseCategory::getCategory($course['CourseCategory']);
|
||||
if (empty($categoryInfo)) {
|
||||
CourseCategory::addNode(
|
||||
$course['CourseCategory'],
|
||||
$course['CourseCategoryName'] ? $course['CourseCategoryName'] : $course['CourseCategory'],
|
||||
'TRUE',
|
||||
null
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$course['error'] = get_lang('NoCourseCategorySupplied');
|
||||
$errors[] = $course;
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the teacher list.
|
||||
*
|
||||
* @param array $teachers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getTeacherListInArray($teachers)
|
||||
{
|
||||
if (!empty($teachers)) {
|
||||
return explode('|', $teachers);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves imported data.
|
||||
*
|
||||
* @param array $courses List of courses
|
||||
*/
|
||||
function save_courses_data($courses)
|
||||
{
|
||||
$msg = '';
|
||||
foreach ($courses as $course) {
|
||||
$course_language = $course['Language'];
|
||||
$teachers = getTeacherListInArray($course['Teacher']);
|
||||
$teacherList = [];
|
||||
$creatorId = api_get_user_id();
|
||||
|
||||
if (!empty($teachers)) {
|
||||
foreach ($teachers as $teacher) {
|
||||
$teacherInfo = api_get_user_info_from_username($teacher);
|
||||
if (!empty($teacherInfo)) {
|
||||
$teacherList[] = $teacherInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$params = [];
|
||||
$params['title'] = $course['Title'];
|
||||
$params['wanted_code'] = $course['Code'];
|
||||
$params['tutor_name'] = null;
|
||||
$params['course_category'] = $course['CourseCategory'];
|
||||
$params['course_language'] = $course_language;
|
||||
$params['user_id'] = $creatorId;
|
||||
$addMeAsTeacher = isset($_POST['add_me_as_teacher']) ? $_POST['add_me_as_teacher'] : false;
|
||||
$params['add_user_as_teacher'] = $addMeAsTeacher;
|
||||
if (isset($course['Visibility'])) {
|
||||
$params['visibility'] = $course['Visibility'];
|
||||
}
|
||||
|
||||
// Check if there is a course template stated for this course. In that case, we check if that code exists in DB:
|
||||
if (array_key_exists('CourseTemplate', $course) && $course['CourseTemplate'] != '') {
|
||||
$result = Database::fetch_array(
|
||||
Database::query(
|
||||
"SELECT id as real_id FROM ".Database::get_main_table(TABLE_MAIN_COURSE)."
|
||||
WHERE code = '".Database::escape_string($course['CourseTemplate'])."'"
|
||||
),
|
||||
'ASSOC'
|
||||
);
|
||||
if (count($result) && array_key_exists('real_id', $result)) {
|
||||
$params['course_template'] = $result['real_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$courseInfo = CourseManager::create_course($params);
|
||||
|
||||
if (!empty($courseInfo)) {
|
||||
if (!empty($teacherList)) {
|
||||
foreach ($teacherList as $teacher) {
|
||||
CourseManager::subscribeUser(
|
||||
$teacher['user_id'],
|
||||
$courseInfo['code'],
|
||||
COURSEMANAGER
|
||||
);
|
||||
}
|
||||
}
|
||||
$msg .= '<a href="'.api_get_path(WEB_COURSE_PATH).$courseInfo['directory'].'/">
|
||||
'.$courseInfo['title'].'</a> '.get_lang('Created').'<br />';
|
||||
}
|
||||
// Check if necessary to clone tools' first page from the original course to the imported course:
|
||||
if (array_key_exists('CloneHomepageTools', $course) && $course['CloneHomepageTools'] == 'true' && array_key_exists('course_template', $params)) {
|
||||
$results = Database::store_result(
|
||||
Database::query(
|
||||
"SELECT * FROM ".Database::get_course_table(TABLE_TOOL_LIST)."
|
||||
WHERE c_id = ".$params['course_template']
|
||||
),
|
||||
'ASSOC'
|
||||
);
|
||||
if (count($results)) {
|
||||
foreach ($results as $row) {
|
||||
Database::update(
|
||||
Database::get_course_table(TABLE_TOOL_LIST),
|
||||
['visibility' => $row['visibility']],
|
||||
['c_id = ? and name = ?' => [$courseInfo['real_id'], $row['name']]]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($msg)) {
|
||||
echo Display::return_message($msg, 'normal', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the CSV-file.
|
||||
*
|
||||
* @param string $file Path to the CSV-file
|
||||
*
|
||||
* @return array All course-information read from the file
|
||||
*/
|
||||
function parse_csv_courses_data($file)
|
||||
{
|
||||
return Import::csv_reader($file);
|
||||
}
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
|
||||
$defined_auth_sources[] = PLATFORM_AUTH_SOURCE;
|
||||
|
||||
if (isset($extAuthSource) && is_array($extAuthSource)) {
|
||||
$defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));
|
||||
}
|
||||
|
||||
$tool_name = get_lang('ImportCourses').' CSV';
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
set_time_limit(0);
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (isset($_POST['formSent']) && $_POST['formSent']) {
|
||||
if (empty($_FILES['import_file']['tmp_name'])) {
|
||||
$error_message = get_lang('UplUploadFailed');
|
||||
echo Display::return_message($error_message, 'error', false);
|
||||
} else {
|
||||
$allowed_file_mimetype = ['csv'];
|
||||
|
||||
$ext_import_file = substr($_FILES['import_file']['name'], (strrpos($_FILES['import_file']['name'], '.') + 1));
|
||||
|
||||
if (!in_array($ext_import_file, $allowed_file_mimetype)) {
|
||||
echo Display::return_message(get_lang('YouMustImportAFileAccordingToSelectedOption'), 'error');
|
||||
} else {
|
||||
$courses = parse_csv_courses_data($_FILES['import_file']['tmp_name']);
|
||||
|
||||
$errors = validate_courses_data($courses);
|
||||
if (count($errors) == 0) {
|
||||
save_courses_data($courses);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($errors) && count($errors) != 0) {
|
||||
$error_message = '<ul>';
|
||||
foreach ($errors as $index => $error_course) {
|
||||
$error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';
|
||||
$error_message .= get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')';
|
||||
$error_message .= '</li>';
|
||||
}
|
||||
$error_message .= '</ul>';
|
||||
echo Display::return_message($error_message, 'error', false);
|
||||
}
|
||||
|
||||
$form = new FormValidator(
|
||||
'import',
|
||||
'post',
|
||||
api_get_self(),
|
||||
null,
|
||||
['enctype' => 'multipart/form-data']
|
||||
);
|
||||
$form->addHeader($tool_name);
|
||||
$form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
|
||||
$form->addElement('checkbox', 'add_me_as_teacher', null, get_lang('AddMeAsTeacherInCourses'));
|
||||
$form->addButtonImport(get_lang('Import'), 'save');
|
||||
$form->addElement('hidden', 'formSent', 1);
|
||||
$form->display();
|
||||
|
||||
?>
|
||||
<div style="clear: both;"></div>
|
||||
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
<strong>Code</strong>;<strong>Title</strong>;<strong>CourseCategory</strong>;<strong>CourseCategoryName</strong>;Teacher;Language;Visibility;CourseTemplate;CloneHomepageTools
|
||||
BIO0015;Biology;BIO;Science;teacher1;english;1;TEMPLATE1;true
|
||||
BIO0016;Maths;MATH;Engineerng;teacher2|teacher3;english;1;;
|
||||
BIO0017;Language;LANG;;;english;1;;
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
Display::display_footer();
|
||||
193
main/admin/course_information.php
Normal file
193
main/admin/course_information.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This script gives information about a course.
|
||||
*
|
||||
* @author Bart Mollet
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
if (!isset($_GET['code'])) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$courseInfo = api_get_course_info($_GET['code']);
|
||||
if (empty($courseInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
|
||||
|
||||
/**
|
||||
* @param array $course
|
||||
* @param int $session_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_course_usage($course, $session_id = 0)
|
||||
{
|
||||
$courseId = $course['real_id'];
|
||||
$tables = [
|
||||
[
|
||||
Database::get_course_table(TABLE_LP_MAIN),
|
||||
get_lang(ucfirst(TOOL_LEARNPATH)),
|
||||
],
|
||||
[
|
||||
Database::get_course_table(TABLE_FORUM),
|
||||
get_lang('Forums'),
|
||||
],
|
||||
[
|
||||
Database::get_course_table(TABLE_QUIZ_TEST),
|
||||
get_lang(ucfirst(TOOL_QUIZ)),
|
||||
],
|
||||
[
|
||||
Database::get_course_table(TABLE_DOCUMENT),
|
||||
get_lang(ucfirst(TOOL_DOCUMENT)),
|
||||
],
|
||||
[
|
||||
Database::get_course_table(TABLE_GROUP),
|
||||
get_lang(ucfirst(TOOL_GROUP)),
|
||||
],
|
||||
[
|
||||
Database::get_course_table(TABLE_AGENDA),
|
||||
get_lang('Calendar'),
|
||||
],
|
||||
[
|
||||
Database::get_course_table(TABLE_LINK),
|
||||
get_lang(ucfirst(TOOL_LINK)),
|
||||
],
|
||||
[
|
||||
Database::get_course_table(TABLE_ANNOUNCEMENT),
|
||||
get_lang(ucfirst(TOOL_ANNOUNCEMENT)),
|
||||
],
|
||||
];
|
||||
|
||||
$usage = [];
|
||||
$conditionSession = '';
|
||||
if ('' !== $session_id) {
|
||||
$session_id = (int) $session_id;
|
||||
$conditionSession = " AND session_id = '$session_id' ";
|
||||
}
|
||||
|
||||
foreach ($tables as $tableInfo) {
|
||||
$table = $tableInfo[0];
|
||||
$title = $tableInfo[1];
|
||||
$sql = "SELECT COUNT(*) count FROM $table
|
||||
WHERE c_id = '$courseId' $conditionSession ";
|
||||
$rs = Database::query($sql);
|
||||
$row = Database::fetch_array($rs);
|
||||
|
||||
$usage[] = [
|
||||
$title,
|
||||
$row['count'],
|
||||
];
|
||||
}
|
||||
|
||||
return $usage;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ["url" => 'course_list.php', "name" => get_lang('Courses')];
|
||||
$courseId = $courseInfo['real_id'];
|
||||
$tool_name = $courseInfo['title'].' ('.$courseInfo['visual_code'].')';
|
||||
Display::display_header($tool_name);
|
||||
?>
|
||||
<div class="actions">
|
||||
<a href="<?php echo $courseInfo['course_public_url']; ?>">
|
||||
<?php Display::display_icon('home.png', get_lang('CourseHomepage'), [], ICON_SIZE_MEDIUM); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
echo Display::page_header(get_lang('CourseUsage'));
|
||||
|
||||
$table = new SortableTableFromArray(
|
||||
get_course_usage($courseInfo, $sessionId),
|
||||
0,
|
||||
20,
|
||||
'usage_table'
|
||||
);
|
||||
$table->set_additional_parameters(['code' => $courseInfo['code']]);
|
||||
$table->set_other_tables(['user_table', 'class_table']);
|
||||
$table->set_header(0, get_lang('Tool'), true);
|
||||
$table->set_header(1, get_lang('NumberOfItems'), true);
|
||||
$table->display();
|
||||
|
||||
/**
|
||||
* Show all users subscribed in this course.
|
||||
*/
|
||||
echo Display::page_header(get_lang('Users'));
|
||||
|
||||
$table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$sql = "SELECT *, cu.status as course_status
|
||||
FROM $table_course_user cu, $table_user u";
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql .= " INNER JOIN ".Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER)." url_rel_user
|
||||
ON
|
||||
u.id = url_rel_user.user_id AND
|
||||
url_rel_user.access_url_id = ".api_get_current_access_url_id();
|
||||
}
|
||||
$sql .= " WHERE
|
||||
cu.user_id = u.id AND
|
||||
cu.c_id = '".$courseId."' AND
|
||||
cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH;
|
||||
$res = Database::query($sql);
|
||||
$is_western_name_order = api_is_western_name_order();
|
||||
if (Database::num_rows($res) > 0) {
|
||||
$users = [];
|
||||
while ($obj = Database::fetch_object($res)) {
|
||||
$user = [];
|
||||
$user[] = $obj->official_code;
|
||||
if ($is_western_name_order) {
|
||||
$user[] = $obj->firstname;
|
||||
$user[] = $obj->lastname;
|
||||
} else {
|
||||
$user[] = $obj->lastname;
|
||||
$user[] = $obj->firstname;
|
||||
}
|
||||
$user[] = Display::encrypted_mailto_link($obj->email, $obj->email);
|
||||
$user[] = $obj->course_status == 5 ? get_lang('Student') : get_lang('Teacher');
|
||||
$user[] = '<a href="user_information.php?user_id='.$obj->user_id.'">'.
|
||||
Display::return_icon('info2.png', get_lang('UserInfo')).'</a>';
|
||||
$users[] = $user;
|
||||
}
|
||||
$table = new SortableTableFromArray($users, 0, 20, 'user_table');
|
||||
$table->set_additional_parameters(['code' => $courseInfo['code']]);
|
||||
$table->set_other_tables(['usage_table', 'class_table']);
|
||||
$table->set_header(0, get_lang('OfficialCode'), true);
|
||||
if ($is_western_name_order) {
|
||||
$table->set_header(1, get_lang('FirstName'), true);
|
||||
$table->set_header(2, get_lang('LastName'), true);
|
||||
} else {
|
||||
$table->set_header(1, get_lang('LastName'), true);
|
||||
$table->set_header(2, get_lang('FirstName'), true);
|
||||
}
|
||||
$table->set_header(3, get_lang('Email'), true);
|
||||
$table->set_header(4, get_lang('Status'), true);
|
||||
$table->set_header(5, '', false);
|
||||
$table->display();
|
||||
} else {
|
||||
echo get_lang('NoUsersInCourse');
|
||||
}
|
||||
|
||||
$sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
|
||||
|
||||
$url = api_get_path(WEB_CODE_PATH);
|
||||
if (!empty($sessionList)) {
|
||||
foreach ($sessionList as &$session) {
|
||||
$session[0] = Display::url($session[0], $url.'session/resume_session.php?id_session='.$session['id']);
|
||||
unset($session[1]);
|
||||
}
|
||||
echo Display::page_header(get_lang('Sessions'));
|
||||
$table = new SortableTableFromArray($sessionList, 0, 20, 'user_table');
|
||||
$table->display();
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
183
main/admin/course_intro_pdf_import.php
Normal file
183
main/admin/course_intro_pdf_import.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This tool allows platform admins to upload a massive amount of PDFs to be
|
||||
* uploaded in each course.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
// temporary configuration of in which folder to upload the file in each course.
|
||||
// Should default to '', and start with a '/' and end without it, if defined
|
||||
$subDir = '';
|
||||
$tool_name = get_lang('ImportPDFIntroToCourses');
|
||||
$errors = [];
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
if (isset($_POST['formSent'])) {
|
||||
if (empty($_FILES['import_file']['tmp_name'])) {
|
||||
$error_message = get_lang('UplUploadFailed');
|
||||
Display::addFlash(Display::return_message($error_message, 'error', false));
|
||||
} else {
|
||||
$allowed_file_mimetype = ['zip'];
|
||||
$ext_import_file = substr($_FILES['import_file']['name'], (strrpos($_FILES['import_file']['name'], '.') + 1));
|
||||
|
||||
if (!in_array($ext_import_file, $allowed_file_mimetype)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('YouMustImportAZipFile'),
|
||||
'error'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$errors = import_pdfs($subDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$error_message = '<ul>';
|
||||
foreach ($errors as $index => $error_course) {
|
||||
$error_message .= '<li>'.get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')</li>';
|
||||
}
|
||||
$error_message .= '</ul>';
|
||||
Display::addFlash(Display::return_message($error_message, 'normal', false));
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
?>
|
||||
<form method="post" action="<?php echo api_get_self(); ?>" enctype="multipart/form-data" style="margin: 0;">
|
||||
<h3><?php echo $tool_name; ?></h3>
|
||||
<div class="control-group">
|
||||
<label><?php echo get_lang('ImportZipFileLocation'); ?></label>
|
||||
<div class="control">
|
||||
<input type="file" name="import_file"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="control">
|
||||
<button type="submit" class="save" value="<?php echo get_lang('Import'); ?>">
|
||||
<?php echo get_lang('Import'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="formSent" value="1"/>
|
||||
</form>
|
||||
<div style="clear: both;"></div>
|
||||
<p><?php echo get_lang('PDFsMustLookLike'); ?></p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
<strong>CourseCode</strong>_<strong>NameOfDocument</strong>_<strong>CourseName</strong>.pdf
|
||||
e.g.
|
||||
MAT101_Introduction_to_Mathematics-101.pdf
|
||||
MAT102_Introduction_to_Mathematics-102.pdf
|
||||
ENG101_Introduction_to_English-101.pdf
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
Display::display_footer();
|
||||
|
||||
/**
|
||||
* Import PDFs.
|
||||
*
|
||||
* @param string $subDir The subdirectory in which to put the files in each course
|
||||
*
|
||||
* @return bool|array List of possible errors found
|
||||
*/
|
||||
function import_pdfs($subDir = '/')
|
||||
{
|
||||
$baseDir = api_get_path(SYS_ARCHIVE_PATH);
|
||||
$uploadPath = 'pdfimport/';
|
||||
$errors = [];
|
||||
if (!is_dir($baseDir.$uploadPath)) {
|
||||
@mkdir($baseDir.$uploadPath);
|
||||
}
|
||||
if (!unzip_uploaded_file($_FILES['import_file'], $uploadPath, $baseDir, 1024 * 1024 * 1024)) {
|
||||
return false;
|
||||
}
|
||||
$list = scandir($baseDir.$uploadPath);
|
||||
$i = 0;
|
||||
foreach ($list as $file) {
|
||||
if (substr($file, 0, 1) == '.' or !is_file($baseDir.$uploadPath.$file)) {
|
||||
continue;
|
||||
}
|
||||
$parts = preg_split('/_/', $file);
|
||||
$course = api_get_course_info($parts[0]);
|
||||
if (count($course) > 0) {
|
||||
// Build file info because handle_uploaded_document() needs it (name, type, size, tmp_name)
|
||||
$fileSize = filesize($baseDir.$uploadPath.$file);
|
||||
$docId = add_document(
|
||||
$course,
|
||||
$subDir.'/'.$file,
|
||||
'file',
|
||||
$fileSize,
|
||||
$parts[1].' '.substr($parts[2], 0, -4)
|
||||
);
|
||||
if ($docId > 0) {
|
||||
if (!is_file($baseDir.$uploadPath.$file)) {
|
||||
error_log($baseDir.$uploadPath.$file.' does not exists in '.__FILE__);
|
||||
}
|
||||
if (is_file(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file)) {
|
||||
error_log(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file.' exists at destination in '.__FILE__);
|
||||
}
|
||||
if (!is_writeable(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir)) {
|
||||
error_log('Destination '.api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.' is NOT writeable in '.__FILE__);
|
||||
}
|
||||
// Place each file in its folder in each course
|
||||
rename(
|
||||
$baseDir.$uploadPath.$file,
|
||||
api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file
|
||||
);
|
||||
api_item_property_update(
|
||||
$course,
|
||||
TOOL_DOCUMENT,
|
||||
$docId,
|
||||
'DocumentAdded',
|
||||
api_get_user_id()
|
||||
);
|
||||
// Redo visibility
|
||||
api_set_default_visibility($docId, TOOL_DOCUMENT);
|
||||
$errors[] = ['Line' => 0, 'Code' => $course['code'], 'Title' => $course['title']];
|
||||
// Now add a link to the file from the Course description tool
|
||||
$link = '<p>Sílabo de la asignatura
|
||||
<a href="'.api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq_params($course['code']).'&action=download&id='.$docId.'" target="_blank">
|
||||
'.Display::return_icon('pdf.png').'
|
||||
</a></p>';
|
||||
$course_description = new CourseDescription();
|
||||
$session_id = api_get_session_id();
|
||||
$course_description->set_course_id($course['real_id']);
|
||||
$course_description->set_session_id($session_id);
|
||||
$course_description->set_title('Course presentation');
|
||||
$course_description->set_content($link);
|
||||
$course_description->set_description_type(1);
|
||||
$course_description->insert();
|
||||
}
|
||||
} else {
|
||||
$errors[] = ['Line' => 0, 'Code' => $parts[0], 'Title' => $parts[0].' - '.get_lang('CodeDoesNotExists')];
|
||||
}
|
||||
$i++; //found at least one entry that is not a dir or a .
|
||||
}
|
||||
if ($i == 0) {
|
||||
$errors[] = ['Line' => 0, 'Code' => '.', 'Title' => get_lang('NoPDFFoundAtRoot')];
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('CourseIntroductionsAllImportedSuccessfully'),
|
||||
'confirmation',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
659
main/admin/course_list.php
Normal file
659
main/admin/course_list.php
Normal file
@@ -0,0 +1,659 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This script shows a list of courses and allows searching for courses codes
|
||||
* and names.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
$sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
|
||||
$addTeacherColumn = api_get_configuration_value('add_teachers_in_course_list');
|
||||
|
||||
/**
|
||||
* Get the number of courses which will be displayed.
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return int The number of matching courses
|
||||
*/
|
||||
function get_number_of_courses()
|
||||
{
|
||||
return get_course_data(0, 0, 0, 0, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get course data to display.
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $number_of_items
|
||||
* @param int $column
|
||||
* @param string $direction
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_course_data($from, $number_of_items, $column, $direction, $dataFunctions = [], $getCount = false)
|
||||
{
|
||||
$addTeacherColumn = api_get_configuration_value('add_teachers_in_course_list');
|
||||
$table = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$from = (int) $from;
|
||||
$number_of_items = (int) $number_of_items;
|
||||
$column = (int) $column;
|
||||
|
||||
if (!in_array(strtolower($direction), ['asc', 'desc'])) {
|
||||
$direction = 'desc';
|
||||
}
|
||||
|
||||
$teachers = '';
|
||||
if ($addTeacherColumn) {
|
||||
$teachers = " GROUP_CONCAT(cu.user_id SEPARATOR ',') as col7, ";
|
||||
}
|
||||
$select = "SELECT
|
||||
code AS col0,
|
||||
title AS col1,
|
||||
code AS col2,
|
||||
course_language AS col3,
|
||||
category_code AS col4,
|
||||
subscribe AS col5,
|
||||
unsubscribe AS col6,
|
||||
$teachers
|
||||
visibility,
|
||||
directory,
|
||||
visual_code,
|
||||
course.code,
|
||||
course.id ";
|
||||
|
||||
if ($getCount) {
|
||||
$select = 'SELECT COUNT(DISTINCT(course.id)) as count ';
|
||||
}
|
||||
|
||||
$sql = "$select FROM $table course";
|
||||
|
||||
if ((api_is_platform_admin() || api_is_session_admin()) &&
|
||||
api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
|
||||
) {
|
||||
$access_url_rel_course_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
|
||||
$sql .= " INNER JOIN $access_url_rel_course_table url_rel_course
|
||||
ON (course.id = url_rel_course.c_id)";
|
||||
}
|
||||
|
||||
if ($addTeacherColumn) {
|
||||
$tableCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$sql .= "
|
||||
LEFT JOIN $tableCourseRelUser cu
|
||||
ON (course.id = cu.c_id AND cu.status = ".COURSEMANAGER.")
|
||||
";
|
||||
}
|
||||
|
||||
if (isset($_GET['keyword'])) {
|
||||
$keyword = Database::escape_string("%".trim($_GET['keyword'])."%");
|
||||
$sql .= " WHERE (
|
||||
title LIKE '".$keyword."' OR
|
||||
code LIKE '".$keyword."' OR
|
||||
visual_code LIKE '".$keyword."'
|
||||
)
|
||||
";
|
||||
} elseif (isset($_GET['keyword_code'])) {
|
||||
$keyword_code = Database::escape_string("%".$_GET['keyword_code']."%");
|
||||
$keyword_title = Database::escape_string("%".$_GET['keyword_title']."%");
|
||||
$keyword_category = isset($_GET['keyword_category'])
|
||||
? Database::escape_string("%".$_GET['keyword_category']."%")
|
||||
: null;
|
||||
$keyword_language = Database::escape_string("%".$_GET['keyword_language']."%");
|
||||
$keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%");
|
||||
$keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
|
||||
$keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
|
||||
|
||||
$sql .= " WHERE
|
||||
(code LIKE '".$keyword_code."' OR visual_code LIKE '".$keyword_code."') AND
|
||||
title LIKE '".$keyword_title."' AND
|
||||
course_language LIKE '".$keyword_language."' AND
|
||||
visibility LIKE '".$keyword_visibility."' AND
|
||||
subscribe LIKE '".$keyword_subscribe."' AND
|
||||
unsubscribe LIKE '".$keyword_unsubscribe."'";
|
||||
|
||||
if (!empty($keyword_category)) {
|
||||
$sql .= " AND category_code LIKE '".$keyword_category."' ";
|
||||
}
|
||||
}
|
||||
|
||||
// Adding the filter to see the user's only of the current access_url.
|
||||
if ((api_is_platform_admin() || api_is_session_admin()) &&
|
||||
api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
|
||||
) {
|
||||
$sql .= " AND url_rel_course.access_url_id = ".api_get_current_access_url_id();
|
||||
}
|
||||
|
||||
if ($addTeacherColumn) {
|
||||
$teachers = isset($_GET['course_teachers']) ? $_GET['course_teachers'] : [];
|
||||
if (!empty($teachers)) {
|
||||
$teachers = array_map('intval', $teachers);
|
||||
$addNull = '';
|
||||
foreach ($teachers as $key => $teacherId) {
|
||||
if (0 === $teacherId) {
|
||||
$addNull = 'OR cu.user_id IS NULL ';
|
||||
unset($key);
|
||||
}
|
||||
}
|
||||
$sql .= ' AND ( cu.user_id IN ("'.implode('", "', $teachers).'") '.$addNull.' ) ';
|
||||
}
|
||||
|
||||
if (false === $getCount) {
|
||||
$sql .= " GROUP BY course.id ";
|
||||
}
|
||||
}
|
||||
|
||||
if ($getCount) {
|
||||
$res = Database::query($sql);
|
||||
$row = Database::fetch_array($res);
|
||||
if ($row) {
|
||||
return (int) $row['count'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY col$column $direction ";
|
||||
$sql .= " LIMIT $from, $number_of_items";
|
||||
|
||||
$res = Database::query($sql);
|
||||
$courses = [];
|
||||
$languages = api_get_languages_to_array();
|
||||
$path = api_get_path(WEB_CODE_PATH);
|
||||
$coursePath = api_get_path(WEB_COURSE_PATH);
|
||||
|
||||
while ($course = Database::fetch_array($res)) {
|
||||
$courseId = $course['id'];
|
||||
$courseCode = $course['code'];
|
||||
|
||||
// Place colour icons in front of courses.
|
||||
$showVisualCode = $course['visual_code'] != $courseCode ? Display::label($course['visual_code'], 'info') : null;
|
||||
$course[1] = get_course_visibility_icon($course['visibility']).PHP_EOL
|
||||
.Display::url(Security::remove_XSS($course[1]), $coursePath.$course['directory'].'/index.php').PHP_EOL
|
||||
.$showVisualCode;
|
||||
$course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
|
||||
$course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
|
||||
$language = isset($languages[$course[3]]) ? $languages[$course[3]] : $course[3];
|
||||
|
||||
$actions = [];
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('info2.png', get_lang('Info')),
|
||||
"course_information.php?code=$courseCode"
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('course_home.png', get_lang('CourseHomepage')),
|
||||
$coursePath.$course['directory'].'/index.php'
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('statistics.png', get_lang('Tracking')),
|
||||
$path.'tracking/courseLog.php?'.api_get_cidreq_params($courseCode)
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
$path.'admin/course_edit.php?id='.$courseId
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('backup.png', get_lang('CreateBackup')),
|
||||
$path.'coursecopy/create_backup.php?'.api_get_cidreq_params($courseCode)
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('delete.png', get_lang('Delete')),
|
||||
$path.'admin/course_list.php?'
|
||||
.http_build_query([
|
||||
'delete_course' => $courseCode,
|
||||
'sec_token' => Security::getTokenFromSession(),
|
||||
]),
|
||||
[
|
||||
'onclick' => "javascript: if (!confirm('"
|
||||
.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."')) return false;",
|
||||
]
|
||||
);
|
||||
$courseItem = [
|
||||
$course[0],
|
||||
$course[1],
|
||||
$course[2],
|
||||
$language,
|
||||
$course[4],
|
||||
$course[5],
|
||||
$course[6],
|
||||
];
|
||||
|
||||
if ($addTeacherColumn) {
|
||||
$teacherIdList = array_filter(explode(',', $course[7]));
|
||||
$teacherList = [];
|
||||
if (!empty($teacherIdList)) {
|
||||
foreach ($teacherIdList as $teacherId) {
|
||||
$userInfo = api_get_user_info($teacherId);
|
||||
if ($userInfo) {
|
||||
$teacherList[] = $userInfo['complete_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$courseItem[] = implode(', ', $teacherList);
|
||||
}
|
||||
$courseItem[] = implode(PHP_EOL, $actions);
|
||||
$courses[] = $courseItem;
|
||||
}
|
||||
|
||||
return $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get course data to display filtered by session name.
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $number_of_items
|
||||
* @param int $column
|
||||
* @param string $direction
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_course_data_by_session($from, $number_of_items, $column, $direction)
|
||||
{
|
||||
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
$session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
|
||||
$from = (int) $from;
|
||||
$number_of_items = (int) $number_of_items;
|
||||
$column = (int) $column;
|
||||
|
||||
if (!in_array(strtolower($direction), ['asc', 'desc'])) {
|
||||
$direction = 'desc';
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
c.code AS col0,
|
||||
c.title AS col1,
|
||||
c.code AS col2,
|
||||
c.course_language AS col3,
|
||||
c.category_code AS col4,
|
||||
c.subscribe AS col5,
|
||||
c.unsubscribe AS col6,
|
||||
c.code AS col7,
|
||||
c.visibility AS col8,
|
||||
c.directory as col9,
|
||||
c.visual_code
|
||||
FROM $course_table c
|
||||
INNER JOIN $session_rel_course r
|
||||
ON c.id = r.c_id
|
||||
INNER JOIN $session s
|
||||
ON r.session_id = s.id
|
||||
";
|
||||
|
||||
if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
|
||||
$sessionId = (int) $_GET['session_id'];
|
||||
$sql .= " WHERE s.id = ".$sessionId;
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY col$column $direction ";
|
||||
$sql .= " LIMIT $from,$number_of_items";
|
||||
$res = Database::query($sql);
|
||||
|
||||
$courseUrl = api_get_path(WEB_COURSE_PATH);
|
||||
$courses = [];
|
||||
while ($course = Database::fetch_array($res)) {
|
||||
// Place colour icons in front of courses.
|
||||
$showVisualCode = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
|
||||
$course[1] = get_course_visibility_icon($course[8]).
|
||||
'<a href="'.$courseUrl.$course[9].'/index.php">'.
|
||||
$course[1].
|
||||
'</a> '.
|
||||
$showVisualCode;
|
||||
$course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
|
||||
$course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
|
||||
$row = [
|
||||
$course[0],
|
||||
$course[1],
|
||||
$course[2],
|
||||
$course[3],
|
||||
$course[4],
|
||||
$course[5],
|
||||
$course[6],
|
||||
$course[7],
|
||||
];
|
||||
$courses[] = $row;
|
||||
}
|
||||
|
||||
return $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an icon representing the visibility of the course.
|
||||
*
|
||||
* @param string $visibility
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_course_visibility_icon($visibility)
|
||||
{
|
||||
$style = 'margin-bottom:0;margin-right:5px;';
|
||||
switch ($visibility) {
|
||||
case 0:
|
||||
return Display::return_icon(
|
||||
'bullet_red.png',
|
||||
get_lang('CourseVisibilityClosed'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
return Display::return_icon(
|
||||
'bullet_orange.png',
|
||||
get_lang('Private'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
return Display::return_icon(
|
||||
'bullet_green.png',
|
||||
get_lang('OpenToThePlatform'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
return Display::return_icon(
|
||||
'bullet_blue.png',
|
||||
get_lang('OpenToTheWorld'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 4:
|
||||
return Display::return_icon(
|
||||
'bullet_grey.png',
|
||||
get_lang('CourseVisibilityHidden'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['action']) && Security::check_token('get')) {
|
||||
switch ($_POST['action']) {
|
||||
// Delete selected courses
|
||||
case 'delete_courses':
|
||||
if (!empty($_POST['course'])) {
|
||||
$course_codes = $_POST['course'];
|
||||
if (count($course_codes) > 0) {
|
||||
foreach ($course_codes as $course_code) {
|
||||
CourseManager::delete_course($course_code);
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$content = '';
|
||||
$message = '';
|
||||
$actions = '';
|
||||
|
||||
if (isset($_GET['search']) && $_GET['search'] === 'advanced') {
|
||||
// Get all course categories
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'course_list.php',
|
||||
'name' => get_lang('CourseList'),
|
||||
];
|
||||
$tool_name = get_lang('SearchACourse');
|
||||
$form = new FormValidator('advanced_course_search', 'get');
|
||||
$form->addElement('header', $tool_name);
|
||||
$form->addText('keyword_code', get_lang('CourseCode'), false);
|
||||
$form->addText('keyword_title', get_lang('Title'), false);
|
||||
|
||||
// Category code
|
||||
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
|
||||
|
||||
$form->addElement(
|
||||
'select_ajax',
|
||||
'keyword_category',
|
||||
get_lang('CourseFaculty'),
|
||||
null,
|
||||
[
|
||||
'url' => $url,
|
||||
]
|
||||
);
|
||||
|
||||
$el = $form->addSelectLanguage('keyword_language', get_lang('CourseLanguage'));
|
||||
$el->addOption(get_lang('All'), '%');
|
||||
|
||||
if ($addTeacherColumn) {
|
||||
$form->addSelectAjax(
|
||||
'course_teachers',
|
||||
get_lang('CourseTeachers'),
|
||||
[0 => get_lang('None')],
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=teacher_to_basis_course',
|
||||
'id' => 'course_teachers',
|
||||
'multiple' => 'multiple',
|
||||
]
|
||||
);
|
||||
$form->addLabel('', '<button id="set_none_teacher" class="btn ">'.get_lang('None').'</button>');
|
||||
}
|
||||
|
||||
$form->addElement('radio', 'keyword_visibility', get_lang('CourseAccess'), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
|
||||
$form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
|
||||
$form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);
|
||||
$form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%');
|
||||
$form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
|
||||
$form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
|
||||
$form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
|
||||
$form->addButtonSearch(get_lang('SearchCourse'));
|
||||
$defaults['keyword_language'] = '%';
|
||||
$defaults['keyword_visibility'] = '%';
|
||||
$defaults['keyword_subscribe'] = '%';
|
||||
$defaults['keyword_unsubscribe'] = '%';
|
||||
$form->setDefaults($defaults);
|
||||
$content .= $form->returnForm();
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$tool_name = get_lang('CourseList');
|
||||
if (isset($_GET['delete_course']) && Security::check_token('get')) {
|
||||
$result = CourseManager::delete_course($_GET['delete_course']);
|
||||
if ($result) {
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
}
|
||||
}
|
||||
// Create a search-box
|
||||
$form = new FormValidator(
|
||||
'search_simple',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$form->addElement(
|
||||
'text',
|
||||
'keyword',
|
||||
null,
|
||||
['id' => 'course-search-keyword', 'aria-label' => get_lang('SearchCourse')]
|
||||
);
|
||||
$form->addButtonSearch(get_lang('SearchCourse'));
|
||||
$advanced = '<a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'admin/course_list.php?search=advanced">
|
||||
<em class="fa fa-search"></em> '.
|
||||
get_lang('AdvancedSearch').'</a>';
|
||||
|
||||
// Create a filter by session
|
||||
$sessionFilter = new FormValidator(
|
||||
'course_filter',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session';
|
||||
$sessionSelect = $sessionFilter->addElement(
|
||||
'select_ajax',
|
||||
'session_name',
|
||||
get_lang('SearchCourseBySession'),
|
||||
null,
|
||||
['id' => 'session_name', 'url' => $url]
|
||||
);
|
||||
|
||||
if (!empty($sessionId)) {
|
||||
$sessionInfo = SessionManager::fetch($sessionId);
|
||||
$sessionSelect->addOption(
|
||||
$sessionInfo['name'],
|
||||
$sessionInfo['id'],
|
||||
['selected' => 'selected']
|
||||
);
|
||||
}
|
||||
|
||||
$courseListUrl = api_get_self();
|
||||
$actions1 = Display::url(
|
||||
Display::return_icon(
|
||||
'new_course.png',
|
||||
get_lang('AddCourse'),
|
||||
[],
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/course_add.php'
|
||||
);
|
||||
|
||||
if (api_get_setting('course_validation') === 'true') {
|
||||
$actions1 .= Display::url(
|
||||
Display::return_icon(
|
||||
'course_request_pending.png',
|
||||
get_lang('ReviewCourseRequests'),
|
||||
[],
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/course_request_review.php'
|
||||
);
|
||||
}
|
||||
|
||||
$actions2 = $form->returnForm();
|
||||
$actions3 = $sessionFilter->returnForm();
|
||||
$actions4 = $advanced;
|
||||
$actions4 .= '
|
||||
<script>
|
||||
$(function() {
|
||||
$("#session_name").on("change", function() {
|
||||
var sessionId = $(this).val();
|
||||
if (!sessionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.location = "'.$courseListUrl.'?session_id="+sessionId;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$actions = Display::toolbarAction(
|
||||
'toolbar',
|
||||
[$actions1, $actions2, $actions3, $actions4],
|
||||
[2, 4, 3, 3]
|
||||
);
|
||||
|
||||
if (!empty($sessionId)) {
|
||||
// Create a sortable table with the course data filtered by session
|
||||
$table = new SortableTable(
|
||||
'courses',
|
||||
'get_number_of_courses',
|
||||
'get_course_data_by_session',
|
||||
2
|
||||
);
|
||||
} else {
|
||||
// Create a sortable table with the course data
|
||||
$table = new SortableTable(
|
||||
'courses',
|
||||
'get_number_of_courses',
|
||||
'get_course_data',
|
||||
2,
|
||||
20,
|
||||
'ASC',
|
||||
'course-list'
|
||||
);
|
||||
}
|
||||
|
||||
$parameters = [];
|
||||
$parameters['sec_token'] = Security::get_token();
|
||||
if (isset($_GET['keyword'])) {
|
||||
$parameters = ['keyword' => Security::remove_XSS($_GET['keyword'])];
|
||||
} elseif (isset($_GET['keyword_code'])) {
|
||||
$parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']);
|
||||
$parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']);
|
||||
if (isset($_GET['keyword_category'])) {
|
||||
$parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']);
|
||||
}
|
||||
$parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']);
|
||||
$parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']);
|
||||
$parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']);
|
||||
$parameters['keyword_unsubscribe'] = Security::remove_XSS($_GET['keyword_unsubscribe']);
|
||||
}
|
||||
|
||||
if (isset($_GET['course_teachers'])) {
|
||||
$parsed = array_map('intval', $_GET['course_teachers']);
|
||||
$parameters["course_teachers"] = '';
|
||||
foreach ($parsed as $key => $teacherId) {
|
||||
$parameters["course_teachers[$key]"] = $teacherId;
|
||||
}
|
||||
}
|
||||
|
||||
$table->set_additional_parameters($parameters);
|
||||
$column = 0;
|
||||
$table->set_header($column++, '', false, 'width="8px"');
|
||||
$table->set_header($column++, get_lang('Title'), true, null, ['class' => 'title']);
|
||||
$table->set_header($column++, get_lang('Code'));
|
||||
$table->set_header($column++, get_lang('Language'), false, 'width="70px"');
|
||||
$table->set_header($column++, get_lang('Category'));
|
||||
$table->set_header($column++, get_lang('SubscriptionAllowed'), true, 'width="60px"');
|
||||
$table->set_header($column++, get_lang('UnsubscriptionAllowed'), false, 'width="50px"');
|
||||
if ($addTeacherColumn) {
|
||||
$table->set_header($column++, get_lang('Teachers'), true);
|
||||
}
|
||||
$table->set_header(
|
||||
$column++,
|
||||
get_lang('Action'),
|
||||
false,
|
||||
null,
|
||||
['class' => 'td_actions']
|
||||
);
|
||||
$table->set_form_actions(
|
||||
['delete_courses' => get_lang('DeleteCourse')],
|
||||
'course'
|
||||
);
|
||||
|
||||
$tab = CourseManager::getCourseListTabs('simple');
|
||||
|
||||
$content .= $tab.$table->return_table();
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
$(function() {
|
||||
$("#set_none_teacher").on("click", function () {
|
||||
$("#course_teachers").val("0").trigger("change");
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$tpl = new Template($tool_name);
|
||||
$tpl->assign('actions', $actions);
|
||||
$tpl->assign('message', $message);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
531
main/admin/course_list_admin.php
Normal file
531
main/admin/course_list_admin.php
Normal file
@@ -0,0 +1,531 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This script shows a list of courses and allows searching for courses codes
|
||||
* and names.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
$sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
|
||||
$addTeacherColumn = true;
|
||||
|
||||
/**
|
||||
* Get the number of courses which will be displayed.
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return int The number of matching courses
|
||||
*/
|
||||
function get_number_of_courses()
|
||||
{
|
||||
return get_course_data(0, 0, 0, 0, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get course data to display.
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $number_of_items
|
||||
* @param int $column
|
||||
* @param string $direction
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_course_data($from, $number_of_items, $column, $direction, $dataFunctions = [], $getCount = false)
|
||||
{
|
||||
$addTeacherColumn = true;
|
||||
$table = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
|
||||
$from = (int) $from;
|
||||
$number_of_items = (int) $number_of_items;
|
||||
$column = (int) $column;
|
||||
|
||||
if (!in_array(strtolower($direction), ['asc', 'desc'])) {
|
||||
$direction = 'desc';
|
||||
}
|
||||
|
||||
$teachers = '';
|
||||
if ($addTeacherColumn) {
|
||||
$teachers = " GROUP_CONCAT(cu.user_id SEPARATOR ',') as col4, ";
|
||||
}
|
||||
$select = "SELECT
|
||||
code AS col0,
|
||||
title AS col1,
|
||||
creation_date AS col2,
|
||||
$teachers
|
||||
visibility,
|
||||
directory,
|
||||
visual_code,
|
||||
course.code,
|
||||
course.id ";
|
||||
|
||||
if ($getCount) {
|
||||
$select = 'SELECT COUNT(DISTINCT(course.id)) as count ';
|
||||
}
|
||||
|
||||
$sql = "$select FROM $table course";
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$access_url_rel_course_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
|
||||
$sql .= " INNER JOIN $access_url_rel_course_table url_rel_course
|
||||
ON (course.id = url_rel_course.c_id)";
|
||||
}
|
||||
|
||||
$tableCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$sql .= "
|
||||
LEFT JOIN $tableCourseRelUser cu
|
||||
ON (course.id = cu.c_id AND cu.status = ".COURSEMANAGER." )
|
||||
";
|
||||
|
||||
$sql .= ' WHERE 1=1 ';
|
||||
if (isset($_GET['keyword'])) {
|
||||
$keyword = Database::escape_string("%".trim($_GET['keyword'])."%");
|
||||
$sql .= " AND (
|
||||
title LIKE '".$keyword."' OR
|
||||
code LIKE '".$keyword."' OR
|
||||
visual_code LIKE '".$keyword."'
|
||||
)
|
||||
";
|
||||
} elseif (isset($_GET['keyword_code'])) {
|
||||
$keyword_code = Database::escape_string("%".$_GET['keyword_code']."%");
|
||||
$keyword_title = Database::escape_string("%".$_GET['keyword_title']."%");
|
||||
$keyword_category = isset($_GET['keyword_category'])
|
||||
? Database::escape_string("%".$_GET['keyword_category']."%")
|
||||
: null;
|
||||
$keyword_language = Database::escape_string("%".$_GET['keyword_language']."%");
|
||||
$keyword_visibility = Database::escape_string("%".$_GET['keyword_visibility']."%");
|
||||
$keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
|
||||
$keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
|
||||
|
||||
$sql .= " AND
|
||||
title LIKE '".$keyword_title."' AND
|
||||
(code LIKE '".$keyword_code."' OR visual_code LIKE '".$keyword_code."') AND
|
||||
course_language LIKE '".$keyword_language."' AND
|
||||
visibility LIKE '".$keyword_visibility."' AND
|
||||
subscribe LIKE '".$keyword_subscribe."' AND
|
||||
unsubscribe LIKE '".$keyword_unsubscribe."'";
|
||||
|
||||
if (!empty($keyword_category)) {
|
||||
$sql .= " AND category_code LIKE '".$keyword_category."' ";
|
||||
}
|
||||
}
|
||||
|
||||
// Adding the filter to see the user's only of the current access_url.
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql .= " AND url_rel_course.access_url_id = ".api_get_current_access_url_id();
|
||||
}
|
||||
|
||||
if ($addTeacherColumn) {
|
||||
$teachers = isset($_GET['course_teachers']) ? $_GET['course_teachers'] : [];
|
||||
if (!empty($teachers)) {
|
||||
$teachers = array_map('intval', $teachers);
|
||||
$addNull = '';
|
||||
foreach ($teachers as $key => $teacherId) {
|
||||
if (0 === $teacherId) {
|
||||
$addNull = 'OR cu.user_id IS NULL ';
|
||||
unset($key);
|
||||
}
|
||||
}
|
||||
$sql .= ' AND ( cu.user_id IN ("'.implode('", "', $teachers).'") '.$addNull.' ) ';
|
||||
}
|
||||
|
||||
if (false === $getCount) {
|
||||
$sql .= " GROUP BY course.id ";
|
||||
}
|
||||
}
|
||||
|
||||
if ($getCount) {
|
||||
$res = Database::query($sql);
|
||||
$row = Database::fetch_array($res);
|
||||
if ($row) {
|
||||
return (int) $row['count'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
$sql .= " ORDER BY col$column $direction ";
|
||||
$sql .= " LIMIT $from, $number_of_items";
|
||||
|
||||
$res = Database::query($sql);
|
||||
$courses = [];
|
||||
$path = api_get_path(WEB_CODE_PATH);
|
||||
$coursePath = api_get_path(WEB_COURSE_PATH);
|
||||
|
||||
$icon = Display::return_icon('teacher.png', get_lang('Teacher'), [], ICON_SIZE_TINY);
|
||||
|
||||
while ($course = Database::fetch_array($res)) {
|
||||
$courseId = $course['id'];
|
||||
$courseCode = $course['code'];
|
||||
|
||||
// Place colour icons in front of courses.
|
||||
$showVisualCode = $course['visual_code'] != $courseCode ? Display::label($course['visual_code'], 'info') : null;
|
||||
$course[1] = get_course_visibility_icon($course['visibility']).PHP_EOL
|
||||
.Display::url(Security::remove_XSS($course[1]), $coursePath.$course['directory'].'/index.php').PHP_EOL
|
||||
.$showVisualCode;
|
||||
$course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
|
||||
$course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
|
||||
|
||||
$actions = [];
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('info2.png', get_lang('Info')),
|
||||
"course_information.php?code=$courseCode"
|
||||
);
|
||||
/*$actions[] = Display::url(
|
||||
Display::return_icon('course_home.png', get_lang('CourseHomepage')),
|
||||
$coursePath.$course['directory'].'/index.php'
|
||||
);*/
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('statistics.png', get_lang('Tracking')),
|
||||
$path.'tracking/courseLog.php?'.api_get_cidreq_params($courseCode)
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
$path.'admin/course_edit.php?id='.$courseId
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('backup.png', get_lang('CreateBackup')),
|
||||
$path.'coursecopy/create_backup.php?'.api_get_cidreq_params($courseCode)
|
||||
);
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('delete.png', get_lang('Delete')),
|
||||
$path.'admin/course_list_admin.php?'.http_build_query([
|
||||
'delete_course' => $courseCode,
|
||||
'sec_token' => Security::getTokenFromSession(),
|
||||
]),
|
||||
[
|
||||
'onclick' => "javascript: if (!confirm('"
|
||||
.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."')) return false;",
|
||||
]
|
||||
);
|
||||
|
||||
$course['creation_date'] = api_get_local_time($course['col2']);
|
||||
$lastAccessLocalTime = '';
|
||||
$lastAccess = Tracking::getLastConnectionDateByCourse($courseId);
|
||||
if ($lastAccess) {
|
||||
$lastAccessLocalTime = api_get_local_time($lastAccess);
|
||||
}
|
||||
|
||||
$courseItem = [
|
||||
$course[0],
|
||||
$course[1],
|
||||
$course['creation_date'],
|
||||
$lastAccessLocalTime,
|
||||
];
|
||||
|
||||
if ($addTeacherColumn) {
|
||||
$teacherIdList = array_filter(explode(',', $course['col4']));
|
||||
$teacherList = [];
|
||||
if (!empty($teacherIdList)) {
|
||||
foreach ($teacherIdList as $teacherId) {
|
||||
$userInfo = api_get_user_info($teacherId);
|
||||
if ($userInfo) {
|
||||
$teacherList[] = $userInfo['complete_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$courseItem[] = '<ul class="list-inline"><li>'
|
||||
."$icon ".implode("</li><li>$icon ", $teacherList)
|
||||
.'</li></ul>';
|
||||
}
|
||||
$courseItem[] = implode(PHP_EOL, $actions);
|
||||
$courses[] = $courseItem;
|
||||
}
|
||||
|
||||
return $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an icon representing the visibility of the course.
|
||||
*
|
||||
* @param string $visibility
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_course_visibility_icon($visibility)
|
||||
{
|
||||
$style = 'margin-bottom:0;margin-right:5px;';
|
||||
switch ($visibility) {
|
||||
case 0:
|
||||
return Display::return_icon(
|
||||
'bullet_red.png',
|
||||
get_lang('CourseVisibilityClosed'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
return Display::return_icon(
|
||||
'bullet_orange.png',
|
||||
get_lang('Private'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
return Display::return_icon(
|
||||
'bullet_green.png',
|
||||
get_lang('OpenToThePlatform'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
return Display::return_icon(
|
||||
'bullet_blue.png',
|
||||
get_lang('OpenToTheWorld'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
case 4:
|
||||
return Display::return_icon(
|
||||
'bullet_grey.png',
|
||||
get_lang('CourseVisibilityHidden'),
|
||||
['style' => $style]
|
||||
);
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['action']) && Security::check_token('get')) {
|
||||
switch ($_POST['action']) {
|
||||
// Delete selected courses
|
||||
case 'delete_courses':
|
||||
if (!empty($_POST['course'])) {
|
||||
$course_codes = $_POST['course'];
|
||||
if (count($course_codes) > 0) {
|
||||
foreach ($course_codes as $course_code) {
|
||||
CourseManager::delete_course($course_code);
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$content = '';
|
||||
$message = '';
|
||||
$actions = '';
|
||||
|
||||
if (isset($_GET['search']) && $_GET['search'] === 'advanced') {
|
||||
// Get all course categories
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'course_list_admin.php',
|
||||
'name' => get_lang('CourseList'),
|
||||
];
|
||||
$tool_name = get_lang('SearchACourse');
|
||||
$form = new FormValidator('advanced_course_search', 'get');
|
||||
$form->addElement('header', $tool_name);
|
||||
$form->addText('keyword_code', get_lang('CourseCode'), false);
|
||||
$form->addText('keyword_title', get_lang('Title'), false);
|
||||
|
||||
// Category code
|
||||
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
|
||||
|
||||
$form->addElement(
|
||||
'select_ajax',
|
||||
'keyword_category',
|
||||
get_lang('CourseFaculty'),
|
||||
null,
|
||||
[
|
||||
'url' => $url,
|
||||
]
|
||||
);
|
||||
|
||||
$el = $form->addSelectLanguage('keyword_language', get_lang('CourseLanguage'));
|
||||
$el->addOption(get_lang('All'), '%');
|
||||
|
||||
if ($addTeacherColumn) {
|
||||
$form->addSelectAjax(
|
||||
'course_teachers',
|
||||
get_lang('CourseTeachers'),
|
||||
[0 => get_lang('None')],
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=teacher_to_basis_course',
|
||||
'id' => 'course_teachers',
|
||||
'multiple' => 'multiple',
|
||||
]
|
||||
);
|
||||
$form->addLabel('', '<button id="set_none_teacher" class="btn ">'.get_lang('None').'</button>');
|
||||
}
|
||||
|
||||
$form->addElement('radio', 'keyword_visibility', get_lang('CourseAccess'), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
|
||||
$form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
|
||||
$form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
|
||||
$form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);
|
||||
$form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%');
|
||||
$form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
|
||||
$form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
|
||||
$form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
|
||||
$form->addButtonSearch(get_lang('SearchCourse'));
|
||||
$defaults['keyword_language'] = '%';
|
||||
$defaults['keyword_visibility'] = '%';
|
||||
$defaults['keyword_subscribe'] = '%';
|
||||
$defaults['keyword_unsubscribe'] = '%';
|
||||
$form->setDefaults($defaults);
|
||||
$content .= $form->returnForm();
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$tool_name = get_lang('CourseList');
|
||||
if (isset($_GET['delete_course']) && Security::check_token('get')) {
|
||||
$result = CourseManager::delete_course($_GET['delete_course']);
|
||||
if ($result) {
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
}
|
||||
}
|
||||
// Create a search-box
|
||||
$form = new FormValidator(
|
||||
'search_simple',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$form->addElement(
|
||||
'text',
|
||||
'keyword',
|
||||
null,
|
||||
['id' => 'course-search-keyword', 'aria-label' => get_lang('SearchCourse')]
|
||||
);
|
||||
$form->addButtonSearch(get_lang('SearchCourse'));
|
||||
$advanced = '<a class="btn btn-default" href="'.api_get_path(WEB_CODE_PATH).'admin/course_list_admin.php?search=advanced">
|
||||
<em class="fa fa-search"></em> '.
|
||||
get_lang('AdvancedSearch').'</a>';
|
||||
|
||||
// Create a filter by session
|
||||
$sessionFilter = new FormValidator(
|
||||
'course_filter',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
$courseListUrl = api_get_self();
|
||||
$actions1 = Display::url(
|
||||
Display::return_icon(
|
||||
'new_course.png',
|
||||
get_lang('AddCourse'),
|
||||
[],
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/course_add.php'
|
||||
);
|
||||
|
||||
if (api_get_setting('course_validation') === 'true') {
|
||||
$actions1 .= Display::url(
|
||||
Display::return_icon(
|
||||
'course_request_pending.png',
|
||||
get_lang('ReviewCourseRequests'),
|
||||
[],
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/course_request_review.php'
|
||||
);
|
||||
}
|
||||
|
||||
$actions2 = $form->returnForm();
|
||||
//$actions3 = $sessionFilter->returnForm();
|
||||
$actions4 = $advanced;
|
||||
|
||||
$actions = Display::toolbarAction(
|
||||
'toolbar',
|
||||
[$actions1, $actions2, $actions4],
|
||||
[2, 4, 3, 3]
|
||||
);
|
||||
|
||||
// Create a sortable table with the course data
|
||||
$table = new SortableTable(
|
||||
'course_list_admin',
|
||||
'get_number_of_courses',
|
||||
'get_course_data',
|
||||
1,
|
||||
20,
|
||||
'ASC',
|
||||
'course_list_admin'
|
||||
);
|
||||
|
||||
$parameters = [];
|
||||
$parameters['sec_token'] = Security::get_token();
|
||||
if (isset($_GET['keyword'])) {
|
||||
$parameters = ['keyword' => Security::remove_XSS($_GET['keyword'])];
|
||||
} elseif (isset($_GET['keyword_code'])) {
|
||||
$parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']);
|
||||
$parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']);
|
||||
if (isset($_GET['keyword_category'])) {
|
||||
$parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']);
|
||||
}
|
||||
$parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']);
|
||||
$parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']);
|
||||
$parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']);
|
||||
$parameters['keyword_unsubscribe'] = Security::remove_XSS($_GET['keyword_unsubscribe']);
|
||||
}
|
||||
|
||||
if (isset($_GET['course_teachers'])) {
|
||||
$parsed = array_map('intval', $_GET['course_teachers']);
|
||||
$parameters["course_teachers"] = '';
|
||||
foreach ($parsed as $key => $teacherId) {
|
||||
$parameters["course_teachers[$key]"] = $teacherId;
|
||||
}
|
||||
}
|
||||
|
||||
$table->set_additional_parameters($parameters);
|
||||
$column = 0;
|
||||
$table->set_header($column++, '', false, 'width="8px"');
|
||||
$table->set_header($column++, get_lang('Title'), true, null, ['class' => 'title']);
|
||||
$table->set_header($column++, get_lang('CreationDate'), true, 'width="70px"');
|
||||
$table->set_header($column++, get_lang('LatestLoginInCourse'), false, 'width="70px"');
|
||||
//$table->set_header($column++, get_lang('Category'));
|
||||
//$table->set_header($column++, get_lang('SubscriptionAllowed'), true, 'width="60px"');
|
||||
//$table->set_header($column++, get_lang('UnsubscriptionAllowed'), false, 'width="50px"');
|
||||
if ($addTeacherColumn) {
|
||||
$table->set_header($column++, get_lang('Teachers'), true, ['style' => 'width:350px;']);
|
||||
}
|
||||
$table->set_header(
|
||||
$column++,
|
||||
get_lang('Action'),
|
||||
false,
|
||||
null,
|
||||
['class' => 'td_actions', 'style' => 'width:145px;']
|
||||
);
|
||||
$table->set_form_actions(
|
||||
['delete_courses' => get_lang('DeleteCourse')],
|
||||
'course'
|
||||
);
|
||||
$tab = CourseManager::getCourseListTabs('admin');
|
||||
$content .= $tab.$table->return_table();
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '
|
||||
<script>
|
||||
$(function() {
|
||||
$("#set_none_teacher").on("click", function () {
|
||||
$("#course_teachers").val("0").trigger("change");
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$tpl = new Template($tool_name);
|
||||
$tpl->assign('actions', $actions);
|
||||
$tpl->assign('message', $message);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
196
main/admin/course_request_accepted.php
Normal file
196
main/admin/course_request_accepted.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* A list containig the accepted course requests.
|
||||
*
|
||||
* @author José Manuel Abuin Mosquera <chema@cesga.es>, 2010
|
||||
* @author Bruno Rubio Gayo <brubio@cesga.es>, 2010
|
||||
* Centro de Supercomputacion de Galicia (CESGA)
|
||||
* @author Ivan Tcholakov <ivantcholakov@gmail.com> (technical adaptation for Chamilo 1.8.8), 2010
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
|
||||
// A check whether the course validation feature is enabled.
|
||||
$course_validation_feature = api_get_setting('course_validation') == 'true';
|
||||
|
||||
// Filltering passed to this page parameters.
|
||||
$delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
|
||||
$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
|
||||
$is_error_message = !empty($_GET['is_error_message']);
|
||||
|
||||
if ($course_validation_feature) {
|
||||
/**
|
||||
* Deletion of a course request.
|
||||
*/
|
||||
if (!empty($delete_course_request)) {
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
|
||||
$result = CourseRequestManager::delete_course_request($delete_course_request);
|
||||
if ($result) {
|
||||
$message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (isset($_POST['action'])) {
|
||||
/**
|
||||
* Form actions: delete.
|
||||
*/
|
||||
switch ($_POST['action']) {
|
||||
// Delete selected courses
|
||||
case 'delete_course_requests':
|
||||
$course_requests = $_POST['course_request'];
|
||||
if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
|
||||
$success = true;
|
||||
foreach ($_POST['course_request'] as $index => $course_request_id) {
|
||||
$success &= CourseRequestManager::delete_course_request($course_request_id);
|
||||
}
|
||||
$message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
|
||||
$is_error_message = !$success;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
|
||||
$message = sprintf(
|
||||
get_lang('PleaseActivateCourseValidationFeature'),
|
||||
sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation'))
|
||||
);
|
||||
$is_error_message = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of courses which will be displayed.
|
||||
*/
|
||||
function get_number_of_requests()
|
||||
{
|
||||
return CourseRequestManager::count_course_requests(COURSE_REQUEST_ACCEPTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get course data to display.
|
||||
*/
|
||||
function get_request_data($from, $number_of_items, $column, $direction)
|
||||
{
|
||||
$keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : null;
|
||||
$course_request_table = Database::get_main_table(TABLE_MAIN_COURSE_REQUEST);
|
||||
|
||||
$from = intval($from);
|
||||
$number_of_items = intval($number_of_items);
|
||||
$column = intval($column);
|
||||
$direction = !in_array(strtolower(trim($direction)), ['asc', 'desc']) ? 'asc' : $direction;
|
||||
|
||||
$sql = "SELECT
|
||||
id AS col0,
|
||||
code AS col1,
|
||||
title AS col2,
|
||||
category_code AS col3,
|
||||
tutor_name AS col4,
|
||||
request_date AS col5,
|
||||
id AS col6
|
||||
FROM $course_request_table
|
||||
WHERE status = ".COURSE_REQUEST_ACCEPTED;
|
||||
|
||||
if ($keyword != '') {
|
||||
$sql .= " AND (
|
||||
title LIKE '%".$keyword."%' OR
|
||||
code LIKE '%".$keyword."%' OR
|
||||
visual_code LIKE '%".$keyword."%'
|
||||
)";
|
||||
}
|
||||
$sql .= " ORDER BY col$column $direction ";
|
||||
$sql .= " LIMIT $from,$number_of_items";
|
||||
$res = Database::query($sql);
|
||||
|
||||
$course_requests = [];
|
||||
while ($course_request = Database::fetch_row($res)) {
|
||||
$course_request[5] = api_get_local_time($course_request[5]);
|
||||
$course_requests[] = $course_request;
|
||||
}
|
||||
|
||||
return $course_requests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions in the list: edit, accept, delete.
|
||||
*/
|
||||
function modify_filter($id)
|
||||
{
|
||||
$code = CourseRequestManager::get_course_request_code($id);
|
||||
$result = '<a href="course_request_edit.php?id='.$id.'&caller=1">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), ['style' => 'vertical-align: middle;']).'</a>'.
|
||||
' <a href="?delete_course_request='.$id.'">'.
|
||||
Display::return_icon(
|
||||
'delete.png',
|
||||
get_lang('DeleteThisCourseRequest'),
|
||||
[
|
||||
'style' => 'vertical-align: middle;',
|
||||
'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;',
|
||||
]
|
||||
).
|
||||
'</a>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
|
||||
$tool_name = get_lang('AcceptedCourseRequests');
|
||||
|
||||
// Display confirmation or error message.
|
||||
if (!empty($message)) {
|
||||
if ($is_error_message) {
|
||||
Display::addFlash(Display::return_message($message, 'error', false));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message($message, 'normal', false));
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!$course_validation_feature) {
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Create a simple search-box.
|
||||
$form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
|
||||
$renderer = $form->defaultRenderer();
|
||||
$renderer->setCustomElementTemplate('<span>{element}</span> ');
|
||||
$form->addElement('text', 'keyword', get_lang('Keyword'));
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
|
||||
// The action bar.
|
||||
echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
|
||||
echo ' <a href="course_request_review.php">'.
|
||||
Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
|
||||
echo ' <a href="course_request_rejected.php">'.
|
||||
Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').'</a>';
|
||||
echo '</div>';
|
||||
echo '<div class="actions">';
|
||||
$form->display();
|
||||
echo '</div>';
|
||||
|
||||
// Create a sortable table with the course data.
|
||||
$table = new SortableTable('course_requests_accepted', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
|
||||
$table->set_header(0, '', false);
|
||||
$table->set_header(1, get_lang('Code'));
|
||||
$table->set_header(2, get_lang('Title'));
|
||||
$table->set_header(3, get_lang('Category'));
|
||||
$table->set_header(4, get_lang('Teacher'));
|
||||
$table->set_header(5, get_lang('CourseRequestDate'));
|
||||
$table->set_header(6, '', false);
|
||||
$table->set_column_filter(6, 'modify_filter');
|
||||
$table->set_form_actions(['delete_course_requests' => get_lang('DeleteCourseRequests')], 'course_request');
|
||||
$table->display();
|
||||
|
||||
/* FOOTER */
|
||||
|
||||
Display::display_footer();
|
||||
364
main/admin/course_request_edit.php
Normal file
364
main/admin/course_request_edit.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* A page for detailed preview or edition of a given course request.
|
||||
*
|
||||
* @author Ivan Tcholakov <ivantcholakov@gmail.com>, 2010
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$tool_name = get_lang('CourseRequestEdit');
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
// A check whether the course validation feature is enabled.
|
||||
$course_validation_feature = api_get_setting('course_validation') == 'true';
|
||||
|
||||
// Filtering passed to this page parameters.
|
||||
$id = intval($_GET['id']);
|
||||
$caller = intval($_GET['caller']);
|
||||
|
||||
if ($course_validation_feature) {
|
||||
// Retrieve request's data from the corresponding database record.
|
||||
$course_request_info = CourseRequestManager::get_course_request_info($id);
|
||||
if (!is_array($course_request_info)) {
|
||||
// Prepare an error message notifying that the course request has not been found or does not exist.
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('CourseRequestHasNotBeenFound'),
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// Ensure the database prefix + database name do not get over 40 characters.
|
||||
$maxlength = 40;
|
||||
|
||||
// Build the form.
|
||||
$form = new FormValidator(
|
||||
'add_course',
|
||||
'post',
|
||||
'course_request_edit.php?id='.$id.'&caller='.$caller
|
||||
);
|
||||
|
||||
// Form title.
|
||||
$form->addElement('header', $tool_name);
|
||||
|
||||
// Title.
|
||||
$form->addElement('text', 'title', get_lang('CourseName'), ['size' => '60', 'id' => 'title']);
|
||||
$form->applyFilter('title', 'html_filter');
|
||||
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
|
||||
|
||||
// Course category.
|
||||
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
|
||||
|
||||
$courseSelect = $form->addElement(
|
||||
'select_ajax',
|
||||
'category_code',
|
||||
get_lang('CourseFaculty'),
|
||||
null,
|
||||
['url' => $url]
|
||||
);
|
||||
|
||||
if (!empty($course_request_info['category_code'])) {
|
||||
$data = CourseCategory::getCategory($course_request_info['category_code']);
|
||||
$courseSelect->addOption($data['name'], $data['code'], ['selected' => 'selected']);
|
||||
}
|
||||
|
||||
// Course code.
|
||||
$form->addText('wanted_code', get_lang('Code'), false, ['size' => '$maxlength', 'maxlength' => $maxlength]);
|
||||
$form->applyFilter('wanted_code', 'html_filter');
|
||||
$form->addRule('wanted_code', get_lang('Max'), 'maxlength', $maxlength);
|
||||
$form->addRule('wanted_code', get_lang('ThisFieldIsRequired'), 'required');
|
||||
|
||||
// The teacher.
|
||||
$titular = $form->addText(
|
||||
'tutor_name',
|
||||
get_lang('Professor'),
|
||||
null,
|
||||
['size' => '60', 'disabled' => 'disabled']
|
||||
);
|
||||
|
||||
// Description of the requested course.
|
||||
$form->addElement('textarea', 'description', get_lang('Description'));
|
||||
$form->addRule('description', get_lang('ThisFieldIsRequired'), 'required');
|
||||
|
||||
// Objectives of the requested course.
|
||||
$form->addElement('textarea', 'objetives', get_lang('Objectives'));
|
||||
$form->addRule('objetives', get_lang('ThisFieldIsRequired'), 'required');
|
||||
|
||||
// Target audience of the requested course.
|
||||
$form->addElement('textarea', 'target_audience', get_lang('TargetAudience'));
|
||||
$form->addRule('target_audience', get_lang('ThisFieldIsRequired'), 'required');
|
||||
|
||||
// Course language.
|
||||
$form->addSelectLanguage('course_language', get_lang('Ln'));
|
||||
|
||||
// Exemplary content checkbox.
|
||||
$form->addElement('checkbox', 'exemplary_content', get_lang('FillWithExemplaryContent'));
|
||||
|
||||
// Submit buttons.
|
||||
$submit_buttons[] = $form->addButtonSave(get_lang('Save'), 'save_button', true);
|
||||
if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED) {
|
||||
$submit_buttons[] = $form->addButtonSave(get_lang('Accept'), 'accept_button', true);
|
||||
}
|
||||
if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED &&
|
||||
$course_request_info['status'] != COURSE_REQUEST_REJECTED
|
||||
) {
|
||||
$submit_buttons[] = $form->addButtonCancel(get_lang('Reject'), 'reject_button', true);
|
||||
}
|
||||
if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && intval($course_request_info['info']) <= 0) {
|
||||
$submit_buttons[] = $form->addButtonPreview(get_lang('AskAdditionalInfo'), 'ask_info_button', true);
|
||||
}
|
||||
$form->addGroup($submit_buttons);
|
||||
|
||||
// Hidden form fields.
|
||||
$form->addElement('hidden', 'user_id');
|
||||
$form->addElement('hidden', 'directory');
|
||||
$form->addElement('hidden', 'visual_code');
|
||||
$form->addElement('hidden', 'request_date');
|
||||
$form->addElement('hidden', 'status');
|
||||
$form->addElement('hidden', 'info');
|
||||
|
||||
// Set the default values based on the corresponding database record.
|
||||
$values['wanted_code'] = $course_request_info['code'];
|
||||
$values['user_id'] = $course_request_info['user_id'];
|
||||
$values['directory'] = $course_request_info['directory'];
|
||||
$values['course_language'] = $course_request_info['course_language'];
|
||||
$values['title'] = $course_request_info['title'];
|
||||
$values['description'] = $course_request_info['description'];
|
||||
//$values['category_code'] = $course_request_info['category_code'];
|
||||
$values['tutor_name'] = $course_request_info['tutor_name'];
|
||||
$values['visual_code'] = $course_request_info['visual_code'];
|
||||
$values['request_date'] = $course_request_info['request_date'];
|
||||
$values['objetives'] = $course_request_info['objetives'];
|
||||
$values['target_audience'] = $course_request_info['target_audience'];
|
||||
$values['status'] = $course_request_info['status'];
|
||||
$values['info'] = $course_request_info['info'];
|
||||
$values['exemplary_content'] = $course_request_info['exemplary_content'];
|
||||
$form->setDefaults($values);
|
||||
|
||||
// Validate the form and perform the ordered actions.
|
||||
if ($form->validate()) {
|
||||
$course_request_values = $form->getSubmitValues();
|
||||
|
||||
// Detection which submit button has been pressed.
|
||||
$submit_button = isset($_POST['save_button']) ? 'save_button'
|
||||
: (isset($_POST['accept_button']) ? 'accept_button'
|
||||
: (isset($_POST['reject_button']) ? 'reject_button'
|
||||
: (isset($_POST['ask_info_button']) ? 'ask_info_button'
|
||||
: 'submit_button')));
|
||||
|
||||
// Check the course code for avoiding duplication.
|
||||
$course_code_ok = $course_request_values['wanted_code'] == $course_request_info['code']
|
||||
? true
|
||||
: !CourseRequestManager::course_code_exists($course_request_values['wanted_code']);
|
||||
|
||||
if ($course_code_ok) {
|
||||
$message = [];
|
||||
|
||||
// Update the course request.
|
||||
$update_ok = CourseRequestManager::update_course_request(
|
||||
$id,
|
||||
$course_request_values['wanted_code'],
|
||||
$course_request_values['title'],
|
||||
$course_request_values['description'],
|
||||
$course_request_values['category_code'],
|
||||
$course_request_values['course_language'],
|
||||
$course_request_values['objetives'],
|
||||
$course_request_values['target_audience'],
|
||||
$course_request_values['user_id'],
|
||||
$course_request_values['exemplary_content']
|
||||
);
|
||||
|
||||
if ($update_ok) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestUpdated'),
|
||||
$course_request_values['wanted_code']
|
||||
),
|
||||
'normal',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
switch ($submit_button) {
|
||||
case 'accept_button':
|
||||
if (CourseRequestManager::accept_course_request($id)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestAccepted'),
|
||||
$course_request_values['wanted_code'],
|
||||
$course_request_values['wanted_code']
|
||||
),
|
||||
'normal',
|
||||
false
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestAcceptanceFailed'),
|
||||
$course_request_values['wanted_code']
|
||||
)
|
||||
),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'reject_button':
|
||||
if (CourseRequestManager::reject_course_request($id)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestRejected'),
|
||||
$course_request_values['wanted_code']
|
||||
)
|
||||
),
|
||||
'normal',
|
||||
false
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestRejectionFailed'),
|
||||
$course_request_values['wanted_code']
|
||||
)
|
||||
),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'ask_info_button':
|
||||
if (CourseRequestManager::ask_for_additional_info($id)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestInfoAsked'),
|
||||
$course_request_values['wanted_code']
|
||||
)
|
||||
),
|
||||
'normal',
|
||||
false
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestInfoFailed'),
|
||||
$course_request_values['wanted_code']
|
||||
)
|
||||
),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('CourseRequestUpdateFailed'),
|
||||
$course_request_values['wanted_code']
|
||||
)
|
||||
),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
$back_url = get_caller_name($caller);
|
||||
header('location:'.$back_url);
|
||||
exit;
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$course_request_values['wanted_code'].' - '.get_lang('CourseCodeAlreadyExists')
|
||||
),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Prepare an error message notifying that the course validation feature has not been enabled.
|
||||
$link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?search_field=course_validation&submit_button=&category=search_setting';
|
||||
$message = sprintf(
|
||||
get_lang('PleaseActivateCourseValidationFeature'),
|
||||
sprintf(
|
||||
'<strong><a href="%s">%s</a></strong>',
|
||||
$link_to_setting,
|
||||
get_lang('EnableCourseValidation')
|
||||
)
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message($message),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
// Functions.
|
||||
|
||||
// Converts the given numerical id to the name of the page that opened this editor.
|
||||
function get_caller_name($caller_id)
|
||||
{
|
||||
switch ($caller_id) {
|
||||
case 1:
|
||||
return 'course_request_accepted.php';
|
||||
case 2:
|
||||
return 'course_request_rejected.php';
|
||||
}
|
||||
|
||||
return 'course_request_review.php';
|
||||
}
|
||||
|
||||
// The header.
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!$course_validation_feature) {
|
||||
// Disabled course validation feature - show nothing after the error message.
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// The action bar.
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="course_list.php">'.
|
||||
Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
|
||||
echo '<a href="course_request_review.php">'.
|
||||
Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').
|
||||
'</a>';
|
||||
echo '<a href="course_request_accepted.php">'.
|
||||
Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').
|
||||
'</a>';
|
||||
echo '<a href="course_request_rejected.php">'.
|
||||
Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').
|
||||
'</a>';
|
||||
echo '</div>';
|
||||
|
||||
if (!is_array($course_request_info)) {
|
||||
// Not accessible database record - show the error message and the action bar.
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Display the form.
|
||||
$form->display();
|
||||
|
||||
// The footer.
|
||||
Display::display_footer();
|
||||
250
main/admin/course_request_rejected.php
Normal file
250
main/admin/course_request_rejected.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* A list containing the rejected course requests.
|
||||
*
|
||||
* @author José Manuel Abuin Mosquera <chema@cesga.es>, 2010
|
||||
* @author Bruno Rubio Gayo <brubio@cesga.es>, 2010
|
||||
* Centro de Supercomputacion de Galicia (CESGA)
|
||||
* @author Ivan Tcholakov <ivantcholakov@gmail.com> (technical adaptation for Chamilo 1.8.8), 2010
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
// A check whether the course validation feature is enabled.
|
||||
$course_validation_feature = api_get_setting('course_validation') == 'true';
|
||||
|
||||
// Filltering passed to this page parameters.
|
||||
$accept_course_request = isset($_GET['accept_course_request']) ? intval($_GET['accept_course_request']) : '';
|
||||
$delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
|
||||
$request_info = isset($_GET['request_info']) ? intval($_GET['request_info']) : '';
|
||||
$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
|
||||
$is_error_message = !empty($_GET['is_error_message']);
|
||||
|
||||
if ($course_validation_feature) {
|
||||
/**
|
||||
* Acceptance and creation of the requested course.
|
||||
*/
|
||||
if (!empty($accept_course_request)) {
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($accept_course_request);
|
||||
$course_id = CourseRequestManager::accept_course_request($accept_course_request);
|
||||
if ($course_id) {
|
||||
$course_code = CourseManager::get_course_code_from_course_id($course_id);
|
||||
$message = sprintf(get_lang('CourseRequestAccepted'), $course_request_code, $course_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestAcceptanceFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (!empty($request_info)) {
|
||||
/**
|
||||
* Sending to the teacher a request for additional information about the proposed course.
|
||||
*/
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($request_info);
|
||||
$result = CourseRequestManager::ask_for_additional_info($request_info);
|
||||
if ($result) {
|
||||
$message = sprintf(get_lang('CourseRequestInfoAsked'), $course_request_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestInfoFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (!empty($delete_course_request)) {
|
||||
/**
|
||||
* Deletion of a course request.
|
||||
*/
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
|
||||
$result = CourseRequestManager::delete_course_request($delete_course_request);
|
||||
if ($result) {
|
||||
$message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (isset($_POST['action'])) {
|
||||
/**
|
||||
* Form actions: delete.
|
||||
*/
|
||||
switch ($_POST['action']) {
|
||||
// Delete selected courses
|
||||
case 'delete_course_requests':
|
||||
$course_requests = $_POST['course_request'];
|
||||
if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
|
||||
$success = true;
|
||||
foreach ($_POST['course_request'] as $index => $course_request_id) {
|
||||
$success &= CourseRequestManager::delete_course_request($course_request_id);
|
||||
}
|
||||
$message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
|
||||
$is_error_message = !$success;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
|
||||
$message = sprintf(
|
||||
get_lang('PleaseActivateCourseValidationFeature'),
|
||||
sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation'))
|
||||
);
|
||||
$is_error_message = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of courses which will be displayed.
|
||||
*/
|
||||
function get_number_of_requests()
|
||||
{
|
||||
return CourseRequestManager::count_course_requests(COURSE_REQUEST_REJECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get course data to display.
|
||||
*/
|
||||
function get_request_data($from, $number_of_items, $column, $direction)
|
||||
{
|
||||
$keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
|
||||
$course_request_table = Database::get_main_table(TABLE_MAIN_COURSE_REQUEST);
|
||||
|
||||
$from = (int) $from;
|
||||
$number_of_items = (int) $number_of_items;
|
||||
$column = (int) $column;
|
||||
$direction = !in_array(strtolower(trim($direction)), ['asc', 'desc']) ? 'asc' : $direction;
|
||||
|
||||
$sql = "SELECT
|
||||
id AS col0,
|
||||
code AS col1,
|
||||
title AS col2,
|
||||
category_code AS col3,
|
||||
tutor_name AS col4,
|
||||
request_date AS col5,
|
||||
id AS col6
|
||||
FROM $course_request_table
|
||||
WHERE status = ".COURSE_REQUEST_REJECTED;
|
||||
|
||||
if ($keyword != '') {
|
||||
$sql .= " AND (
|
||||
title LIKE '%".$keyword."%' OR
|
||||
code LIKE '%".$keyword."%' OR
|
||||
visual_code LIKE '%".$keyword."%'
|
||||
)";
|
||||
}
|
||||
$sql .= " ORDER BY col$column $direction ";
|
||||
$sql .= " LIMIT $from,$number_of_items";
|
||||
$res = Database::query($sql);
|
||||
|
||||
$course_requests = [];
|
||||
while ($course_request = Database::fetch_row($res)) {
|
||||
$course_request[5] = api_get_local_time($course_request[5]);
|
||||
$course_requests[] = $course_request;
|
||||
}
|
||||
|
||||
return $course_requests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions in the list: edit, accept, delete, request additional information.
|
||||
*/
|
||||
function modify_filter($id)
|
||||
{
|
||||
$code = CourseRequestManager::get_course_request_code($id);
|
||||
$result = '<a href="course_request_edit.php?id='.$id.'&caller=2">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), ['style' => 'vertical-align: middle;']).'</a>'.
|
||||
' <a href="?accept_course_request='.$id.'">'.
|
||||
Display::return_icon(
|
||||
'accept.png',
|
||||
get_lang('AcceptThisCourseRequest'),
|
||||
[
|
||||
'style' => 'vertical-align: middle;',
|
||||
'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ANewCourseWillBeCreated'), $code), ENT_QUOTES)).'\')) return false;',
|
||||
]
|
||||
).
|
||||
'</a>';
|
||||
if (!CourseRequestManager::additional_info_asked($id)) {
|
||||
$result .= ' <a href="?request_info='.$id.'">'.
|
||||
Display::return_icon(
|
||||
'request_info.gif',
|
||||
get_lang('AskAdditionalInfo'),
|
||||
[
|
||||
'style' => 'vertical-align: middle;',
|
||||
'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('AdditionalInfoWillBeAsked'), $code), ENT_QUOTES)).'\')) return false;',
|
||||
]
|
||||
).
|
||||
'</a>';
|
||||
}
|
||||
$result .= ' <a href="?delete_course_request='.$id.'">'.
|
||||
Display::return_icon(
|
||||
'delete.png',
|
||||
get_lang('DeleteThisCourseRequest'),
|
||||
[
|
||||
'style' => 'vertical-align: middle;',
|
||||
'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;',
|
||||
]
|
||||
).
|
||||
'</a>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
|
||||
|
||||
$tool_name = get_lang('RejectedCourseRequests');
|
||||
|
||||
// Display confirmation or error message.
|
||||
if (!empty($message)) {
|
||||
if ($is_error_message) {
|
||||
Display::addFlash(Display::return_message($message, 'error', false));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message($message, 'normal', false));
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!$course_validation_feature) {
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Create a simple search-box.
|
||||
$form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
|
||||
$renderer = $form->defaultRenderer();
|
||||
$renderer->setCustomElementTemplate('<span>{element}</span> ');
|
||||
$form->addElement('text', 'keyword', get_lang('Keyword'));
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
|
||||
// The action bar.
|
||||
echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
|
||||
echo ' <a href="course_request_review.php">'.
|
||||
Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').
|
||||
'</a>';
|
||||
echo ' <a href="course_request_accepted.php">'.
|
||||
Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').
|
||||
'</a>';
|
||||
echo '</div>';
|
||||
echo '<div class="actions">';
|
||||
$form->display();
|
||||
echo '</div>';
|
||||
|
||||
// Create a sortable table with the course data.
|
||||
$table = new SortableTable('course_requests_rejected', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
|
||||
$table->set_header(0, '', false);
|
||||
$table->set_header(1, get_lang('Code'));
|
||||
$table->set_header(2, get_lang('Title'));
|
||||
$table->set_header(3, get_lang('Category'));
|
||||
$table->set_header(4, get_lang('Teacher'));
|
||||
$table->set_header(5, get_lang('CourseRequestDate'));
|
||||
$table->set_header(6, '', false);
|
||||
$table->set_column_filter(6, 'modify_filter');
|
||||
$table->set_form_actions(['delete_course_requests' => get_lang('DeleteCourseRequests')], 'course_request');
|
||||
$table->display();
|
||||
|
||||
Display::display_footer();
|
||||
296
main/admin/course_request_review.php
Normal file
296
main/admin/course_request_review.php
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* A list containing the pending course requests.
|
||||
*
|
||||
* @author José Manuel Abuin Mosquera <chema@cesga.es>, 2010
|
||||
* Centro de Supercomputacion de Galicia (CESGA)
|
||||
* @author Ivan Tcholakov <ivantcholakov@gmail.com> (technical adaptation for Chamilo 1.8.8), 2010
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
// The delete action should be deactivated in this page.
|
||||
// Better reject the target request, after that you can delete it.
|
||||
// see DELETE_ACTION_ENABLED constant in main_api.lib.php
|
||||
|
||||
// A check whether the course validation feature is enabled.
|
||||
$course_validation_feature = api_get_setting('course_validation') == 'true';
|
||||
|
||||
// Filltering passed to this page parameters.
|
||||
$accept_course_request = isset($_GET['accept_course_request']) ? intval($_GET['accept_course_request']) : '';
|
||||
$reject_course_request = isset($_GET['reject_course_request']) ? intval($_GET['reject_course_request']) : '';
|
||||
$request_info = isset($_GET['request_info']) ? intval($_GET['request_info']) : '';
|
||||
$delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
|
||||
$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
|
||||
$is_error_message = isset($_GET['is_error_message']) ? !empty($_GET['is_error_message']) : '';
|
||||
$keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
|
||||
|
||||
if ($course_validation_feature) {
|
||||
/**
|
||||
* Course acceptance and creation.
|
||||
*/
|
||||
if (!empty($accept_course_request)) {
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($accept_course_request);
|
||||
$course_id = CourseRequestManager::accept_course_request($accept_course_request);
|
||||
if ($course_id) {
|
||||
$course_code = CourseManager::get_course_code_from_course_id($course_id);
|
||||
$message = sprintf(get_lang('CourseRequestAccepted'), $course_request_code, $course_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestAcceptanceFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (!empty($reject_course_request)) {
|
||||
/**
|
||||
* Course rejection.
|
||||
*/
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($reject_course_request);
|
||||
$result = CourseRequestManager::reject_course_request($reject_course_request);
|
||||
if ($result) {
|
||||
$message = sprintf(get_lang('CourseRequestRejected'), $course_request_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestRejectionFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (!empty($request_info)) {
|
||||
/**
|
||||
* Sending to the teacher a request for additional information about the proposed course.
|
||||
*/
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($request_info);
|
||||
$result = CourseRequestManager::ask_for_additional_info($request_info);
|
||||
if ($result) {
|
||||
$message = sprintf(get_lang('CourseRequestInfoAsked'), $course_request_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestInfoFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (!empty($delete_course_request)) {
|
||||
/**
|
||||
* Deletion of a course request.
|
||||
*/
|
||||
$course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
|
||||
$result = CourseRequestManager::delete_course_request($delete_course_request);
|
||||
if ($result) {
|
||||
$message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
|
||||
$is_error_message = false;
|
||||
} else {
|
||||
$message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
|
||||
$is_error_message = true;
|
||||
}
|
||||
} elseif (DELETE_ACTION_ENABLED && isset($_POST['action'])) {
|
||||
/**
|
||||
* Form actions: delete.
|
||||
*/
|
||||
switch ($_POST['action']) {
|
||||
// Delete selected courses
|
||||
case 'delete_course_requests':
|
||||
$course_requests = $_POST['course_request'];
|
||||
if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
|
||||
$success = true;
|
||||
foreach ($_POST['course_request'] as $index => $course_request_id) {
|
||||
$success &= CourseRequestManager::delete_course_request($course_request_id);
|
||||
}
|
||||
$message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
|
||||
$is_error_message = !$success;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
|
||||
$message = sprintf(
|
||||
get_lang('PleaseActivateCourseValidationFeature'),
|
||||
sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation'))
|
||||
);
|
||||
$is_error_message = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of courses which will be displayed.
|
||||
*/
|
||||
function get_number_of_requests()
|
||||
{
|
||||
return CourseRequestManager::count_course_requests(COURSE_REQUEST_PENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get course data to display.
|
||||
*/
|
||||
function get_request_data($from, $number_of_items, $column, $direction)
|
||||
{
|
||||
global $keyword;
|
||||
$course_request_table = Database::get_main_table(TABLE_MAIN_COURSE_REQUEST);
|
||||
|
||||
$from = (int) $from;
|
||||
$number_of_items = (int) $number_of_items;
|
||||
$column = (int) $column;
|
||||
$direction = !in_array(strtolower(trim($direction)), ['asc', 'desc']) ? 'asc' : $direction;
|
||||
|
||||
if (DELETE_ACTION_ENABLED) {
|
||||
$sql = "SELECT id AS col0,
|
||||
code AS col1,
|
||||
title AS col2,
|
||||
category_code AS col3,
|
||||
tutor_name AS col4,
|
||||
request_date AS col5,
|
||||
id AS col6
|
||||
FROM $course_request_table
|
||||
WHERE status = ".COURSE_REQUEST_PENDING;
|
||||
} else {
|
||||
$sql = "SELECT
|
||||
code AS col0,
|
||||
title AS col1,
|
||||
category_code AS col2,
|
||||
tutor_name AS col3,
|
||||
request_date AS col4,
|
||||
id AS col5
|
||||
FROM $course_request_table
|
||||
WHERE status = ".COURSE_REQUEST_PENDING;
|
||||
}
|
||||
|
||||
if ($keyword != '') {
|
||||
$sql .= " AND (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
|
||||
}
|
||||
$sql .= " ORDER BY col$column $direction ";
|
||||
$sql .= " LIMIT $from,$number_of_items";
|
||||
$res = Database::query($sql);
|
||||
|
||||
$course_requests = [];
|
||||
while ($course_request = Database::fetch_row($res)) {
|
||||
if (DELETE_ACTION_ENABLED) {
|
||||
$course_request[5] = api_get_local_time($course_request[5]);
|
||||
} else {
|
||||
$course_request[4] = api_get_local_time($course_request[4]);
|
||||
}
|
||||
$course_requests[] = $course_request;
|
||||
}
|
||||
|
||||
return $course_requests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlace a la ficha del profesor.
|
||||
*/
|
||||
function email_filter($teacher)
|
||||
{
|
||||
$teacher = Database::escape_string($teacher);
|
||||
$sql = "SELECT user_id FROM ".Database::get_main_table(TABLE_MAIN_COURSE_REQUEST)."
|
||||
WHERE tutor_name LIKE '".$teacher."'";
|
||||
$res = Database::query($sql);
|
||||
$info = Database::fetch_array($res);
|
||||
|
||||
return '<a href="./user_information.php?user_id='.$info[0].'">'.$teacher.'</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions in the list: edit, accept, reject, request additional information.
|
||||
*/
|
||||
function modify_filter($id)
|
||||
{
|
||||
$code = CourseRequestManager::get_course_request_code($id);
|
||||
$result = '<a href="course_request_edit.php?id='.$id.'&caller=0">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), ['style' => 'vertical-align: middle;']).'</a>'.
|
||||
' <a href="?accept_course_request='.$id.'">'.
|
||||
Display::return_icon('accept.png', get_lang('AcceptThisCourseRequest'), ['style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ANewCourseWillBeCreated'), $code), ENT_QUOTES)).'\')) return false;'], 16).'</a>'.
|
||||
' <a href="?reject_course_request='.$id.'">'.
|
||||
Display::return_icon('error.png', get_lang('RejectThisCourseRequest'), ['style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeRejected'), $code), ENT_QUOTES)).'\')) return false;'], 16).'</a>';
|
||||
if (!CourseRequestManager::additional_info_asked($id)) {
|
||||
$result .= ' <a href="?request_info='.$id.'">'.
|
||||
Display::return_icon('request_info.gif', get_lang('AskAdditionalInfo'), ['style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('AdditionalInfoWillBeAsked'), $code), ENT_QUOTES)).'\')) return false;']).'</a>';
|
||||
}
|
||||
if (DELETE_ACTION_ENABLED) {
|
||||
$message = addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES));
|
||||
$result .= ' <a href="?delete_course_request='.$id.'">';
|
||||
$result .= Display::return_icon(
|
||||
'delete.png',
|
||||
get_lang('DeleteThisCourseRequest'),
|
||||
[
|
||||
'style' => 'vertical-align: middle;',
|
||||
'onclick' => 'javascript: if (!confirm(\''.$message.'\')) return false;',
|
||||
]
|
||||
);
|
||||
$result .= '</a>';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
|
||||
|
||||
$tool_name = get_lang('ReviewCourseRequests');
|
||||
|
||||
// Display confirmation or error message.
|
||||
if (!empty($message)) {
|
||||
if ($is_error_message) {
|
||||
Display::addFlash(Display::return_message($message, 'error', false));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message($message, 'normal', false));
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!$course_validation_feature) {
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Create a simple search-box.
|
||||
$form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
|
||||
$renderer = $form->defaultRenderer();
|
||||
$renderer->setCustomElementTemplate('<span>{element}</span> ');
|
||||
$form->addElement('text', 'keyword', get_lang('Keyword'));
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
|
||||
// The action bar.
|
||||
echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
|
||||
echo ' <a href="course_request_accepted.php">';
|
||||
echo Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).
|
||||
get_lang('AcceptedCourseRequests');
|
||||
echo '</a>';
|
||||
echo ' <a href="course_request_rejected.php">';
|
||||
echo Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).
|
||||
get_lang('RejectedCourseRequests');
|
||||
echo '</a>';
|
||||
echo '</div>';
|
||||
echo '<div class="actions">';
|
||||
$form->display();
|
||||
echo '</div>';
|
||||
|
||||
// Create a sortable table with the course data.
|
||||
$offet = DELETE_ACTION_ENABLED ? 1 : 0;
|
||||
$table = new SortableTable(
|
||||
'course_requests_review',
|
||||
'get_number_of_requests',
|
||||
'get_request_data',
|
||||
4 + $offet,
|
||||
20,
|
||||
'DESC'
|
||||
);
|
||||
//$table->set_additional_parameters($parameters);
|
||||
if (DELETE_ACTION_ENABLED) {
|
||||
$table->set_header(0, '', false);
|
||||
}
|
||||
$table->set_header(0 + $offet, get_lang('Code'));
|
||||
$table->set_header(1 + $offet, get_lang('Title'));
|
||||
$table->set_header(2 + $offet, get_lang('Category'));
|
||||
$table->set_header(3 + $offet, get_lang('Teacher'));
|
||||
$table->set_header(4 + $offet, get_lang('CourseRequestDate'));
|
||||
$table->set_header(5 + $offet, '', false);
|
||||
$table->set_column_filter(3 + $offet, 'email_filter');
|
||||
$table->set_column_filter(5 + $offet, 'modify_filter');
|
||||
if (DELETE_ACTION_ENABLED) {
|
||||
$table->set_form_actions(['delete_course_requests' => get_lang('DeleteCourseRequests')], 'course_request');
|
||||
}
|
||||
$table->display();
|
||||
|
||||
Display::display_footer();
|
||||
370
main/admin/course_update_import.php
Normal file
370
main/admin/course_update_import.php
Normal file
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
api_protect_admin_script();
|
||||
|
||||
/**
|
||||
* Generates a CSV model string showing how the CSV file should be structured for course updates.
|
||||
*/
|
||||
function generateCsvModel(array $fields): string
|
||||
{
|
||||
$headerCsv = "<strong>Code</strong>;Title;CourseCategory;Language;Visibility;";
|
||||
|
||||
$exampleCsv = "<b>COURSE001</b>;Introduction to Biology;BIO;english;1;";
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$fieldType = (int) $field['field_type'];
|
||||
switch ($fieldType) {
|
||||
case ExtraField::FIELD_TYPE_CHECKBOX:
|
||||
$exampleValue = '1'; // 1 for true, 0 for false
|
||||
break;
|
||||
case ExtraField::FIELD_TYPE_TAG:
|
||||
$exampleValue = 'tag1,tag2,tag3'; // Comma separated list of tags
|
||||
break;
|
||||
default:
|
||||
$exampleValue = 'xxx'; // Example value for text fields
|
||||
}
|
||||
|
||||
$headerCsv .= "<span style=\"color:red;\">".$field['field_variable']."</span>;";
|
||||
|
||||
$exampleCsv .= "<span style=\"color:red;\">$exampleValue</span>;";
|
||||
}
|
||||
|
||||
$modelCsv = $headerCsv."\n".$exampleCsv;
|
||||
|
||||
return $modelCsv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an XML model string showing how the XML file should be structured for course updates.
|
||||
*/
|
||||
function generateXmlModel(array $fields): string
|
||||
{
|
||||
$modelXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
$modelXml .= "<Courses>\n";
|
||||
$modelXml .= " <Course>\n";
|
||||
$modelXml .= " <b><Code>COURSE001</Code></b>\n";
|
||||
$modelXml .= " <Title>Introduction to Biology</Title>\n";
|
||||
$modelXml .= " <CourseCategory>BIO</CourseCategory>\n";
|
||||
$modelXml .= " <Language>english</Language>\n";
|
||||
$modelXml .= " <Visibility>1</Visibility>\n";
|
||||
foreach ($fields as $field) {
|
||||
switch ($field['field_type']) {
|
||||
case ExtraField::FIELD_TYPE_CHECKBOX:
|
||||
$exampleValue = '1'; // 1 for true, 0 for false
|
||||
break;
|
||||
case ExtraField::FIELD_TYPE_TAG:
|
||||
$exampleValue = 'tag1,tag2,tag3'; // Comma separated list of tags
|
||||
break;
|
||||
default:
|
||||
$exampleValue = 'xxx'; // Example value for text fields
|
||||
}
|
||||
|
||||
$modelXml .= " <span style=\"color:red;\"><".$field['field_variable'].">$exampleValue</".$field['field_variable']."></span>\n";
|
||||
}
|
||||
$modelXml .= " </Course>\n";
|
||||
$modelXml .= "</Courses>";
|
||||
|
||||
return $modelXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to validate course data from the CSV/XML file.
|
||||
*/
|
||||
function validateCourseData(array $courses): array
|
||||
{
|
||||
$errors = [];
|
||||
$courseCodes = [];
|
||||
|
||||
foreach ($courses as $course) {
|
||||
if (empty($course['Code'])) {
|
||||
$errors[] = get_lang("CodeIsRequired");
|
||||
} else {
|
||||
$courseId = api_get_course_int_id($course['Code']);
|
||||
if (!$courseId) {
|
||||
$errors[] = get_lang("CourseCodeDoesNotExist").': '.$course['Code'];
|
||||
} elseif (in_array($course['Code'], $courseCodes)) {
|
||||
$errors[] = get_lang("DuplicateCode").': '.$course['Code'];
|
||||
}
|
||||
|
||||
$courseCodes[] = $course['Code'];
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update course data in the database.
|
||||
*/
|
||||
function updateCourse(array $courseData, int $courseId): void
|
||||
{
|
||||
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$fieldsMapping = [
|
||||
'Title' => 'title',
|
||||
'Language' => 'course_language',
|
||||
'CourseCategory' => 'category_code',
|
||||
'Visibility' => 'visibility',
|
||||
];
|
||||
$params = [];
|
||||
foreach ($fieldsMapping as $inputField => $dbField) {
|
||||
if (isset($courseData[$inputField])) {
|
||||
$params[$dbField] = $courseData[$inputField];
|
||||
}
|
||||
}
|
||||
|
||||
Database::update($courseTable, $params, ['id = ?' => $courseId]);
|
||||
|
||||
if (isset($courseData['extra'])) {
|
||||
$courseData['extra']['code'] = $courseData['Code'];
|
||||
$courseData['extra']['item_id'] = $courseId;
|
||||
$saveOnlyThisFields = [];
|
||||
foreach ($courseData['extra'] as $key => $value) {
|
||||
$newKey = preg_replace('/^extra_/', '', $key);
|
||||
$saveOnlyThisFields[] = $newKey;
|
||||
}
|
||||
$courseFieldValue = new ExtraFieldValue('course');
|
||||
$courseFieldValue->saveFieldValues(
|
||||
$courseData['extra'],
|
||||
false,
|
||||
false,
|
||||
$saveOnlyThisFields,
|
||||
[],
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update courses from the imported data.
|
||||
*/
|
||||
function updateCourses(array $courses): void
|
||||
{
|
||||
foreach ($courses as $course) {
|
||||
$courseId = api_get_course_int_id($course['Code']);
|
||||
updateCourse($course, $courseId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to parse CSV data.
|
||||
*/
|
||||
function parseCsvCourseData(string $file, array $extraFields): array
|
||||
{
|
||||
$data = Import::csv_reader($file);
|
||||
$courses = [];
|
||||
|
||||
foreach ($data as $row) {
|
||||
$courseData = [];
|
||||
foreach ($row as $key => $value) {
|
||||
if (empty($key)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($key, array_column($extraFields, 'variable'))) {
|
||||
$processedValue = processExtraFieldValue($key, $value, $extraFields);
|
||||
$courseData['extra']['extra_'.$key] = $processedValue;
|
||||
} else {
|
||||
$courseData[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$courses[] = $courseData;
|
||||
}
|
||||
|
||||
return $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to parse XML data.
|
||||
*/
|
||||
function parseXmlCourseData(string $file, array $extraFields): array
|
||||
{
|
||||
$xmlContent = Import::xml($file);
|
||||
$courses = [];
|
||||
|
||||
foreach ($xmlContent->filter('Courses > Course') as $xmlCourse) {
|
||||
$courseData = [];
|
||||
foreach ($xmlCourse->childNodes as $node) {
|
||||
if ($node->nodeName !== '#text') {
|
||||
$key = $node->nodeName;
|
||||
if (empty($key)) {
|
||||
continue;
|
||||
}
|
||||
$value = $node->nodeValue;
|
||||
if (in_array($key, array_column($extraFields, 'variable'))) {
|
||||
$processedValue = processExtraFieldValue($key, $value, $extraFields);
|
||||
$courseData['extra']['extra_'.$key] = $processedValue;
|
||||
} else {
|
||||
$courseData[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($courseData)) {
|
||||
$courses[] = $courseData;
|
||||
}
|
||||
}
|
||||
|
||||
return $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the value of an extra field based on its type.
|
||||
*
|
||||
* This function takes the name and value of an extra field, along with an array of all extra fields, and processes
|
||||
* the value according to the field type. For checkbox fields, it returns an array with the field name as the key
|
||||
* and '1' (checked) or '0' (unchecked) as the value. For tag fields, it splits the string by commas into an array.
|
||||
* For other types, it returns the value as is.
|
||||
*/
|
||||
function processExtraFieldValue(string $fieldName, $value, array $extraFields)
|
||||
{
|
||||
$fieldIndex = array_search($fieldName, array_column($extraFields, 'variable'));
|
||||
if ($fieldIndex === false) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$fieldType = $extraFields[$fieldIndex]['field_type'];
|
||||
|
||||
switch ($fieldType) {
|
||||
case ExtraField::FIELD_TYPE_CHECKBOX:
|
||||
$newValue = 0;
|
||||
if ($value == '1') {
|
||||
$newValue = ['extra_'.$fieldName => '1'];
|
||||
}
|
||||
|
||||
return $newValue;
|
||||
case ExtraField::FIELD_TYPE_TAG:
|
||||
return explode(',', $value);
|
||||
default:
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
$toolName = get_lang('UpdateCourseListXMLCSV');
|
||||
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
|
||||
|
||||
$form = new FormValidator('course_update_import');
|
||||
$form->addHeader(get_lang('UpdateCourseListXMLCSV'));
|
||||
$form->addFile('importFile', get_lang('ImportCSVFileLocation'));
|
||||
|
||||
$form->addElement('radio', 'file_type', get_lang('FileType'), get_lang('CSV'), 'csv');
|
||||
$form->addElement('radio', 'file_type', '', get_lang('XML'), 'xml');
|
||||
|
||||
$defaults['file_type'] = 'csv';
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
$form->addButtonImport(get_lang('Import'));
|
||||
|
||||
if ($form->validate()) {
|
||||
if (!isset($_FILES['importFile']['error']) || is_array($_FILES['importFile']['error'])) {
|
||||
Display::addFlash(Display::return_message(get_lang('InvalidFileUpload'), 'error'));
|
||||
} else {
|
||||
switch ($_FILES['importFile']['error']) {
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
Display::addFlash(Display::return_message(get_lang('NoFileSent'), 'error'));
|
||||
break;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
Display::addFlash(Display::return_message(get_lang('ExceededFileSizeLimit'), 'error'));
|
||||
break;
|
||||
default:
|
||||
Display::addFlash(Display::return_message(get_lang('UnknownErrors'), 'error'));
|
||||
}
|
||||
}
|
||||
|
||||
$fileType = $_POST['file_type'];
|
||||
$fileExt = strtolower(pathinfo($_FILES['importFile']['name'], PATHINFO_EXTENSION));
|
||||
|
||||
if (($fileType === 'csv' && $fileExt !== 'csv') || ($fileType === 'xml' && $fileExt !== 'xml')) {
|
||||
Display::addFlash(Display::return_message(get_lang('InvalidFileType'), 'error'));
|
||||
} else {
|
||||
$file = $_FILES['importFile']['tmp_name'];
|
||||
$extraField = new ExtraField('course');
|
||||
$allExtraFields = $extraField->get_all();
|
||||
$successfulUpdates = [];
|
||||
$failedUpdates = [];
|
||||
try {
|
||||
if ($fileType === 'csv') {
|
||||
$courses = parseCsvCourseData($file, $allExtraFields);
|
||||
} else {
|
||||
$courses = parseXmlCourseData($file, $allExtraFields);
|
||||
}
|
||||
|
||||
foreach ($courses as $course) {
|
||||
$courseErrors = validateCourseData([$course]);
|
||||
if (!empty($courseErrors)) {
|
||||
$failedUpdates[] = $course['Code'].': '.implode(', ', $courseErrors);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
updateCourses([$course]);
|
||||
$successfulUpdates[] = $course['Code'];
|
||||
} catch (Exception $e) {
|
||||
$failedUpdates[] = $course['Code'].': '.$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($successfulUpdates)) {
|
||||
Display::addFlash(Display::return_message(get_lang('CoursesUpdatedSuccessfully').': '.implode(', ', $successfulUpdates), 'success'));
|
||||
}
|
||||
|
||||
if (!empty($failedUpdates)) {
|
||||
foreach ($failedUpdates as $error) {
|
||||
Display::addFlash(Display::return_message(get_lang('UpdateFailedForCourses').': '.$error, 'error'));
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Display::addFlash(Display::return_message($e->getMessage(), 'error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = "<script>
|
||||
$(document).ready(function() {
|
||||
function showFileType(type) {
|
||||
if (type === 'csv') {
|
||||
$('#csv-model').show();
|
||||
$('#xml-model').hide();
|
||||
} else {
|
||||
$('#csv-model').hide();
|
||||
$('#xml-model').show();
|
||||
}
|
||||
}
|
||||
|
||||
showFileType($('input[name=file_type]:checked').val());
|
||||
|
||||
$('input[name=file_type]').on('change', function() {
|
||||
showFileType($(this).val());
|
||||
});
|
||||
});
|
||||
</script>";
|
||||
|
||||
Display::display_header($toolName);
|
||||
|
||||
$form->display();
|
||||
|
||||
$extraField = new ExtraField('course');
|
||||
$allExtraFields = $extraField->get_all();
|
||||
|
||||
$extraFields = [];
|
||||
foreach ($allExtraFields as $field) {
|
||||
$extraFields[] = [
|
||||
'field_variable' => $field['variable'],
|
||||
'field_type' => $field['field_type'],
|
||||
];
|
||||
}
|
||||
|
||||
$csvContent = generateCsvModel($extraFields);
|
||||
$xmlContent = generateXmlModel($extraFields);
|
||||
echo '<div id="csv-model"><p>'.get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').'):</p>';
|
||||
echo '<blockquote><pre>'.$csvContent.'</pre></blockquote></div>';
|
||||
echo '<div id="xml-model" style="display: none;"><p>'.get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').'):</p>';
|
||||
echo '<blockquote><pre>'.$xmlContent.'</pre></blockquote></div>';
|
||||
echo '<div id="import-details"><p class="text-muted">Visibility: 0=CLOSED, 1=PRIVATE, 2=OPEN, 3=PUBLIC, 4=HIDDEN.</p></div>';
|
||||
|
||||
Display::display_footer();
|
||||
231
main/admin/course_user_import.php
Normal file
231
main/admin/course_user_import.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This tool allows platform admins to update course-user relations by uploading
|
||||
* a CSV file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validates the imported data.
|
||||
*/
|
||||
function validate_data($users_courses)
|
||||
{
|
||||
$errors = [];
|
||||
$coursecodes = [];
|
||||
foreach ($users_courses as $index => $user_course) {
|
||||
$user_course['line'] = $index + 1;
|
||||
// 1. Check whether mandatory fields are set.
|
||||
$mandatory_fields = ['UserName', 'CourseCode', 'Status'];
|
||||
foreach ($mandatory_fields as $key => $field) {
|
||||
if (!isset($user_course[$field]) || strlen($user_course[$field]) == 0) {
|
||||
$user_course['error'] = get_lang($field.'Mandatory');
|
||||
$errors[] = $user_course;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Check whether coursecode exists.
|
||||
if (isset($user_course['CourseCode']) && strlen($user_course['CourseCode']) != 0) {
|
||||
// 2.1 Check whethher code has been allready used by this CVS-file.
|
||||
if (!isset($coursecodes[$user_course['CourseCode']])) {
|
||||
// 2.1.1 Check whether course with this code exists in the system.
|
||||
$courseInfo = api_get_course_info($user_course['CourseCode']);
|
||||
if (empty($courseInfo)) {
|
||||
$user_course['error'] = get_lang('CodeDoesNotExists');
|
||||
$errors[] = $user_course;
|
||||
} else {
|
||||
$coursecodes[$user_course['CourseCode']] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Check whether username exists.
|
||||
if (isset($user_course['UserName']) && strlen($user_course['UserName']) != 0) {
|
||||
if (UserManager::is_username_available($user_course['UserName'])) {
|
||||
$user_course['error'] = get_lang('UnknownUser');
|
||||
$errors[] = $user_course;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Check whether status is valid.
|
||||
if (isset($user_course['Status']) && strlen($user_course['Status']) != 0) {
|
||||
if ($user_course['Status'] != COURSEMANAGER && $user_course['Status'] != STUDENT) {
|
||||
$user_course['error'] = get_lang('UnknownStatus');
|
||||
$errors[] = $user_course;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves imported data.
|
||||
*/
|
||||
function save_data($users_courses)
|
||||
{
|
||||
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$csv_data = [];
|
||||
$inserted_in_course = [];
|
||||
$courseListCache = [];
|
||||
$courseListById = [];
|
||||
foreach ($users_courses as $user_course) {
|
||||
if (!in_array($user_course['CourseCode'], array_keys($courseListCache))) {
|
||||
$courseInfo = api_get_course_info($user_course['CourseCode']);
|
||||
if ($courseInfo) {
|
||||
$courseListCache[$user_course['CourseCode']] = $courseInfo;
|
||||
}
|
||||
} else {
|
||||
$courseInfo = $courseListCache[$user_course['CourseCode']];
|
||||
}
|
||||
$courseListById[$courseInfo['real_id']] = $courseInfo;
|
||||
$csv_data[$user_course['UserName']][$courseInfo['real_id']] = $user_course['Status'];
|
||||
}
|
||||
|
||||
foreach ($csv_data as $username => $csv_subscriptions) {
|
||||
$userInfo = api_get_user_info_from_username($username);
|
||||
if (empty($userInfo)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user_id = $userInfo['user_id'];
|
||||
$sql = "SELECT * FROM $course_user_table cu
|
||||
WHERE cu.user_id = $user_id AND cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH." ";
|
||||
$res = Database::query($sql);
|
||||
$db_subscriptions = [];
|
||||
while ($obj = Database::fetch_object($res)) {
|
||||
$db_subscriptions[$obj->c_id] = $obj->status;
|
||||
}
|
||||
|
||||
$to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
|
||||
$to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
|
||||
|
||||
if (isset($_POST['subscribe']) && $_POST['subscribe']) {
|
||||
foreach ($to_subscribe as $courseId) {
|
||||
$courseInfo = $courseListById[$courseId];
|
||||
$courseCode = $courseInfo['code'];
|
||||
$result = CourseManager::subscribeUser(
|
||||
$user_id,
|
||||
$courseCode,
|
||||
$csv_subscriptions[$courseId]
|
||||
);
|
||||
if ($result) {
|
||||
$inserted_in_course[$courseInfo['code']] = $courseInfo['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['unsubscribe']) && $_POST['unsubscribe']) {
|
||||
foreach ($to_unsubscribe as $courseId) {
|
||||
if (isset($courseListById[$courseId])) {
|
||||
$courseInfo = $courseListById[$courseId];
|
||||
} else {
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
}
|
||||
$courseCode = $courseInfo['code'];
|
||||
CourseManager::unsubscribe_user($user_id, $courseCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $inserted_in_course;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads CSV-file.
|
||||
*
|
||||
* @param string $file Path to the CSV-file
|
||||
*
|
||||
* @return array All course-information read from the file
|
||||
*/
|
||||
function parse_csv_data($file)
|
||||
{
|
||||
return Import::csvToArray($file);
|
||||
}
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// Setting the section (for the tabs).
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Protecting the admin section.
|
||||
api_protect_admin_script();
|
||||
|
||||
$tool_name = get_lang('AddUsersToACourse').' CSV';
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
// Creating the form.
|
||||
$form = new FormValidator('course_user_import');
|
||||
$form->addElement('header', '', $tool_name);
|
||||
$form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
|
||||
$form->addElement('checkbox', 'subscribe', get_lang('Action'), get_lang('SubscribeUserIfNotAllreadySubscribed'));
|
||||
$form->addElement('checkbox', 'unsubscribe', '', get_lang('UnsubscribeUserIfSubscriptionIsNotInFile'));
|
||||
$form->addButtonImport(get_lang('Import'));
|
||||
$form->setDefaults(['subscribe' => '1', 'unsubscribe' => 0]);
|
||||
$errors = [];
|
||||
|
||||
if ($form->validate()) {
|
||||
$users_courses = parse_csv_data($_FILES['import_file']['tmp_name']);
|
||||
$errors = validate_data($users_courses);
|
||||
if (count($errors) == 0) {
|
||||
$inserted_in_course = save_data($users_courses);
|
||||
// Build the alert message in case there were visual codes subscribed to.
|
||||
if ($_POST['subscribe']) {
|
||||
//$warn = get_lang('UsersSubscribedToBecauseVisualCode').': ';
|
||||
} else {
|
||||
$warn = get_lang('UsersUnsubscribedFromBecauseVisualCode').': ';
|
||||
}
|
||||
|
||||
if (!empty($inserted_in_course)) {
|
||||
$warn = get_lang('FileImported');
|
||||
} else {
|
||||
$warn = get_lang('ErrorsWhenImportingFile');
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message($warn));
|
||||
|
||||
Security::clear_token();
|
||||
$tok = Security::get_token();
|
||||
header('Location: '.api_get_self());
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Displaying the header.
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (count($errors) != 0) {
|
||||
$error_message = '<ul>';
|
||||
foreach ($errors as $index => $error_course) {
|
||||
$error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';
|
||||
$error_message .= $error_course['Code'].' '.$error_course['Title'];
|
||||
$error_message .= '</li>';
|
||||
}
|
||||
$error_message .= '</ul>';
|
||||
echo Display::return_message($error_message, 'error', false);
|
||||
}
|
||||
|
||||
// Displaying the form.
|
||||
$form->display();
|
||||
?>
|
||||
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
|
||||
<blockquote>
|
||||
<pre>
|
||||
<b>UserName</b>;<b>CourseCode</b>;<b>Status</b>
|
||||
jdoe;course01;<?php echo COURSEMANAGER; ?>
|
||||
|
||||
adam;course01;<?php echo STUDENT; ?>
|
||||
</pre>
|
||||
<?php
|
||||
echo COURSEMANAGER.': '.get_lang('Teacher').'<br />';
|
||||
echo STUDENT.': '.get_lang('Student').'<br />';
|
||||
?>
|
||||
</blockquote>
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
232
main/admin/course_user_import_by_email.php
Normal file
232
main/admin/course_user_import_by_email.php
Normal file
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
exit;
|
||||
/**
|
||||
* This tool allows platform admins to update course-user relations by uploading
|
||||
* a CSV file.
|
||||
*/
|
||||
/**
|
||||
* Validates the imported data.
|
||||
*/
|
||||
function validate_data($users_courses)
|
||||
{
|
||||
$errors = [];
|
||||
$coursecodes = [];
|
||||
foreach ($users_courses as $index => $user_course) {
|
||||
$user_course['line'] = $index + 1;
|
||||
// 1. Check whether mandatory fields are set.
|
||||
$mandatory_fields = ['Email', 'CourseCode', 'Status'];
|
||||
foreach ($mandatory_fields as $key => $field) {
|
||||
if (!isset($user_course[$field]) || strlen($user_course[$field]) == 0) {
|
||||
$user_course['error'] = get_lang($field.'Mandatory');
|
||||
$errors[] = $user_course;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Check whether coursecode exists.
|
||||
if (isset($user_course['CourseCode']) && strlen($user_course['CourseCode']) != 0) {
|
||||
// 2.1 Check whethher code has been allready used by this CVS-file.
|
||||
if (!isset($coursecodes[$user_course['CourseCode']])) {
|
||||
// 2.1.1 Check whether course with this code exists in the system.
|
||||
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$sql = "SELECT * FROM $course_table
|
||||
WHERE code = '".Database::escape_string($user_course['CourseCode'])."'";
|
||||
$res = Database::query($sql);
|
||||
if (Database::num_rows($res) == 0) {
|
||||
$user_course['error'] = get_lang('CodeDoesNotExists');
|
||||
$errors[] = $user_course;
|
||||
} else {
|
||||
$coursecodes[$user_course['CourseCode']] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Check whether Email exists.
|
||||
if (isset($user_course['Email']) && strlen($user_course['Email']) != 0) {
|
||||
$user = api_get_user_info_from_email($user_course['Email']);
|
||||
if (empty($user)) {
|
||||
$user_course['error'] = get_lang('UnknownUser');
|
||||
$errors[] = $user_course;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Check whether status is valid.
|
||||
if (isset($user_course['Status']) && strlen($user_course['Status']) != 0) {
|
||||
if ($user_course['Status'] != COURSEMANAGER && $user_course['Status'] != STUDENT) {
|
||||
$user_course['error'] = get_lang('UnknownStatus');
|
||||
$errors[] = $user_course;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves imported data.
|
||||
*/
|
||||
function save_data($users_courses)
|
||||
{
|
||||
$user_table = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
||||
$csv_data = [];
|
||||
$inserted_in_course = [];
|
||||
|
||||
foreach ($users_courses as $user_course) {
|
||||
$csv_data[$user_course['Email']][$user_course['CourseCode']] = $user_course['Status'];
|
||||
}
|
||||
|
||||
foreach ($csv_data as $email => $csv_subscriptions) {
|
||||
$sql = "SELECT * FROM $user_table u
|
||||
WHERE u.email = '".Database::escape_string($email)."'
|
||||
LIMIT 1";
|
||||
$res = Database::query($sql);
|
||||
$obj = Database::fetch_object($res);
|
||||
$user_id = $obj->user_id;
|
||||
$sql = "SELECT * FROM $course_user_table cu
|
||||
WHERE cu.user_id = $user_id AND cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH." ";
|
||||
$res = Database::query($sql);
|
||||
$db_subscriptions = [];
|
||||
while ($obj = Database::fetch_object($res)) {
|
||||
$db_subscriptions[$obj->c_id] = $obj->status;
|
||||
}
|
||||
|
||||
$to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
|
||||
$to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
|
||||
|
||||
if (isset($_POST['subscribe']) && $_POST['subscribe']) {
|
||||
foreach ($to_subscribe as $courseId) {
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$course_code = $courseInfo['code'];
|
||||
if (CourseManager::course_exists($course_code)) {
|
||||
$course_info = api_get_course_info($course_code);
|
||||
$inserted_in_course[$course_code] = $course_info['title'];
|
||||
|
||||
CourseManager::subscribeUser(
|
||||
$user_id,
|
||||
$course_code,
|
||||
$csv_subscriptions[$course_code]
|
||||
);
|
||||
$inserted_in_course[$course_info['code']] = $course_info['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['unsubscribe']) && $_POST['unsubscribe']) {
|
||||
foreach ($to_unsubscribe as $courseId) {
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$course_code = $courseInfo['code'];
|
||||
if (CourseManager::course_exists($course_code)) {
|
||||
CourseManager::unsubscribe_user($user_id, $course_code);
|
||||
$course_info = api_get_course_info($course_code);
|
||||
CourseManager::unsubscribe_user($user_id, $course_code);
|
||||
$inserted_in_course[$course_info['code']] = $course_info['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $inserted_in_course;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads CSV-file.
|
||||
*
|
||||
* @param string $file Path to the CSV-file
|
||||
*
|
||||
* @return array All course-information read from the file
|
||||
*/
|
||||
function parse_csv_data($file)
|
||||
{
|
||||
return Import::csv_reader($file);
|
||||
}
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// Setting the section (for the tabs).
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Protecting the admin section.
|
||||
api_protect_admin_script();
|
||||
|
||||
$tool_name = get_lang('AddUsersToACourse').' CSV';
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
// Creating the form.
|
||||
$form = new FormValidator('course_user_import');
|
||||
$form->addElement('header', '', $tool_name);
|
||||
$form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
|
||||
$form->addElement('checkbox', 'subscribe', get_lang('Action'), get_lang('SubscribeUserIfNotAllreadySubscribed'));
|
||||
$form->addElement('checkbox', 'unsubscribe', '', get_lang('UnsubscribeUserIfSubscriptionIsNotInFile'));
|
||||
$form->addButtonImport(get_lang('Import'));
|
||||
$form->setDefaults(['subscribe' => '1', 'unsubscribe' => 1]);
|
||||
$errors = [];
|
||||
|
||||
if ($form->validate()) {
|
||||
$users_courses = parse_csv_data($_FILES['import_file']['tmp_name']);
|
||||
$errors = validate_data($users_courses);
|
||||
if (count($errors) == 0) {
|
||||
$inserted_in_course = save_data($users_courses);
|
||||
// Build the alert message in case there were visual codes subscribed to.
|
||||
if ($_POST['subscribe']) {
|
||||
$warn = get_lang('UsersSubscribedToBecauseVisualCode').': ';
|
||||
} else {
|
||||
$warn = get_lang('UsersUnsubscribedFromBecauseVisualCode').': ';
|
||||
}
|
||||
|
||||
if (!empty($inserted_in_course)) {
|
||||
$warn = $warn.' '.get_lang('FileImported');
|
||||
// The users have been inserted in more than one course.
|
||||
foreach ($inserted_in_course as $code => $info) {
|
||||
$warn .= ' '.$info.' ('.$code.') ';
|
||||
}
|
||||
} else {
|
||||
$warn = get_lang('ErrorsWhenImportingFile');
|
||||
}
|
||||
|
||||
Security::clear_token();
|
||||
$tok = Security::get_token();
|
||||
Display::addFlash(Display::return_message($warn));
|
||||
header('Location: user_list.php?sec_token='.$tok);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Displaying the header.
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (count($errors) != 0) {
|
||||
$error_message = '<ul>';
|
||||
foreach ($errors as $index => $error_course) {
|
||||
$error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';
|
||||
$error_message .= $error_course['Code'].' '.$error_course['Title'];
|
||||
$error_message .= '</li>';
|
||||
}
|
||||
$error_message .= '</ul>';
|
||||
echo Display::return_message($error_message, 'error', false);
|
||||
}
|
||||
|
||||
// Displaying the form.
|
||||
$form->display();
|
||||
?>
|
||||
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
|
||||
<blockquote>
|
||||
<pre>
|
||||
<b>Email</b>;<b>CourseCode</b>;<b>Status</b>
|
||||
example1@example.org;course01;<?php echo COURSEMANAGER; ?>
|
||||
|
||||
example2@example.org;course01;<?php echo STUDENT; ?>
|
||||
</pre>
|
||||
<?php
|
||||
echo COURSEMANAGER.': '.get_lang('Teacher').'<br />';
|
||||
echo STUDENT.': '.get_lang('Student').'<br />';
|
||||
?>
|
||||
</blockquote>
|
||||
<?php
|
||||
|
||||
Display::display_footer();
|
||||
298
main/admin/dashboard_add_courses_to_user.php
Normal file
298
main/admin/dashboard_add_courses_to_user.php
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Interface for assigning courses to Human Resources Manager.
|
||||
*/
|
||||
// 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;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_admin_script(true);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'user_list.php', 'name' => get_lang('UserList')];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
||||
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
|
||||
|
||||
// initializing variables
|
||||
$user_id = (int) ($_GET['user']);
|
||||
$user_info = api_get_user_info($user_id);
|
||||
$user_anonymous = api_get_anonymous_id();
|
||||
$current_user_id = api_get_user_id();
|
||||
|
||||
// setting the name of the tool
|
||||
if (UserManager::is_admin($user_id)) {
|
||||
$tool_name = get_lang('AssignCoursesToPlatformAdministrator');
|
||||
} elseif ($user_info['status'] == SESSIONADMIN) {
|
||||
$tool_name = get_lang('AssignCoursesToSessionsAdministrator');
|
||||
} else {
|
||||
$tool_name = get_lang('AssignCoursesToHumanResourcesManager');
|
||||
}
|
||||
|
||||
$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_not_allowed(true);
|
||||
}
|
||||
|
||||
function search_courses($needle, $type)
|
||||
{
|
||||
global $tbl_course, $tbl_course_rel_access_url, $user_id;
|
||||
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
// xajax send utf8 datas... datas in db can be non-utf8 datas
|
||||
$needle = Database::escape_string($needle);
|
||||
$assigned_courses_to_hrm = CourseManager::get_courses_followed_by_drh($user_id);
|
||||
$assigned_courses_code = array_keys($assigned_courses_to_hrm);
|
||||
foreach ($assigned_courses_code as &$value) {
|
||||
$value = "'".$value."'";
|
||||
}
|
||||
$without_assigned_courses = '';
|
||||
if (count($assigned_courses_code) > 0) {
|
||||
$without_assigned_courses = " AND c.code NOT IN(".implode(',', $assigned_courses_code).")";
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql = "SELECT c.code, c.title
|
||||
FROM $tbl_course c
|
||||
LEFT JOIN $tbl_course_rel_access_url a
|
||||
ON (a.c_id = c.id)
|
||||
WHERE
|
||||
c.code LIKE '$needle%' $without_assigned_courses AND
|
||||
access_url_id = ".api_get_current_access_url_id();
|
||||
} else {
|
||||
$sql = "SELECT c.code, c.title
|
||||
FROM $tbl_course c
|
||||
WHERE
|
||||
c.code LIKE '$needle%'
|
||||
$without_assigned_courses ";
|
||||
}
|
||||
|
||||
$rs = Database::query($sql);
|
||||
|
||||
$return .= '<select id="origin" name="NoAssignedCoursesList[]" multiple="multiple" size="20" >';
|
||||
while ($course = Database::fetch_array($rs)) {
|
||||
$return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'], ENT_QUOTES).'">'.$course['title'].' ('.$course['code'].')</option>';
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign('ajax_list_courses_multiple', 'innerHTML', api_utf8_encode($return));
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<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) {
|
||||
var 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();
|
||||
}
|
||||
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 = '';
|
||||
$UserList = [];
|
||||
|
||||
$msg = '';
|
||||
if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
|
||||
$courses_list = isset($_POST['CoursesList']) ? $_POST['CoursesList'] : [];
|
||||
$affected_rows = CourseManager::subscribeCoursesToDrhManager($user_id, $courses_list);
|
||||
if ($affected_rows) {
|
||||
$msg = get_lang('AssignedCoursesHaveBeenUpdatedSuccessfully');
|
||||
}
|
||||
}
|
||||
|
||||
// display header
|
||||
Display::display_header($tool_name);
|
||||
|
||||
// actions
|
||||
$actionsLeft = '<a href="dashboard_add_users_to_user.php?user='.$user_id.'">'.
|
||||
Display::return_icon('add-user.png', get_lang('AssignUsers'), null, ICON_SIZE_MEDIUM).'</a>';
|
||||
$actionsLeft .= '<a href="dashboard_add_sessions_to_user.php?user='.$user_id.'">'.
|
||||
Display::return_icon('session-add.png', get_lang('AssignSessions'), null, ICON_SIZE_MEDIUM).'</a>';
|
||||
|
||||
echo $html = Display::toolbarAction('toolbar-dashboard', [$actionsLeft]);
|
||||
|
||||
echo Display::page_header(
|
||||
sprintf(get_lang('AssignCoursesToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])),
|
||||
null,
|
||||
'h3'
|
||||
);
|
||||
|
||||
$assigned_courses_to_hrm = CourseManager::get_courses_followed_by_drh($user_id);
|
||||
$assigned_courses_code = array_keys($assigned_courses_to_hrm);
|
||||
foreach ($assigned_courses_code as &$value) {
|
||||
$value = "'".$value."'";
|
||||
}
|
||||
|
||||
$without_assigned_courses = '';
|
||||
if (count($assigned_courses_code) > 0) {
|
||||
$without_assigned_courses = " AND c.code NOT IN(".implode(',', $assigned_courses_code).")";
|
||||
}
|
||||
|
||||
$needle = '%';
|
||||
$firstLetter = null;
|
||||
if (isset($_POST['firstLetterCourse'])) {
|
||||
$firstLetter = $_POST['firstLetterCourse'];
|
||||
$needle = Database::escape_string($firstLetter.'%');
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql = " SELECT c.code, c.title
|
||||
FROM $tbl_course c
|
||||
LEFT JOIN $tbl_course_rel_access_url a
|
||||
ON (a.c_id = c.id)
|
||||
WHERE
|
||||
c.code LIKE '$needle' $without_assigned_courses AND
|
||||
access_url_id = ".api_get_current_access_url_id()."
|
||||
ORDER BY c.title";
|
||||
} else {
|
||||
$sql = " SELECT c.code, c.title
|
||||
FROM $tbl_course c
|
||||
WHERE c.code LIKE '$needle' $without_assigned_courses
|
||||
ORDER BY c.title";
|
||||
}
|
||||
|
||||
$result = Database::query($sql);
|
||||
|
||||
?>
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?user=<?php echo $user_id; ?>" style="margin:0px;">
|
||||
<input type="hidden" name="formSent" value="1" />
|
||||
<?php
|
||||
if (!empty($msg)) {
|
||||
echo Display::return_message($msg, 'normal'); //main API
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h5><?php echo get_lang('CoursesListInPlatform'); ?> :</h5>
|
||||
|
||||
<div id="ajax_list_courses_multiple">
|
||||
<select id="origin" name="NoAssignedCoursesList[]" multiple="multiple" size="20" style="width:340px;">
|
||||
<?php while ($enreg = Database::fetch_array($result)) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['code']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'], ENT_QUOTES).'"'; ?>><?php echo $enreg['title'].' ('.$enreg['code'].')'; ?></option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="code-course">
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<p><?php echo get_lang('FirstLetterCourse'); ?> :</p>
|
||||
<select name="firstLetterCourse" class="selectpicker form-control" onchange = "xajax_search_courses(this.value,'multiple')">
|
||||
<option value="%">--</option>
|
||||
<?php echo Display::get_alphabet_options($firstLetter); ?>
|
||||
</select>
|
||||
<?php
|
||||
} ?>
|
||||
</div>
|
||||
<div class="control-course">
|
||||
<div class="separate-action">
|
||||
<button 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-arrow-right"></em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="separate-action">
|
||||
<button 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-arrow-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="separate-action">
|
||||
<?php echo '<button class="btn btn-success" type="button" value="" onclick="valide()" >'.$tool_name.'</button>'; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h5><?php
|
||||
if (UserManager::is_admin($user_id)) {
|
||||
echo get_lang('AssignedCoursesListToPlatformAdministrator');
|
||||
} elseif ($user_info['status'] == SESSIONADMIN) {
|
||||
echo get_lang('AssignedCoursesListToSessionsAdministrator');
|
||||
} else {
|
||||
echo get_lang('AssignedCoursesListToHumanResourcesManager');
|
||||
}
|
||||
?>: </h5>
|
||||
|
||||
<select id='destination' name="CoursesList[]" multiple="multiple" size="20" style="width:320px;">
|
||||
<?php
|
||||
if (is_array($assigned_courses_to_hrm)) {
|
||||
foreach ($assigned_courses_to_hrm as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['code']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'], ENT_QUOTES).'"'; ?>><?php echo $enreg['title'].' ('.$enreg['code'].')'; ?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
308
main/admin/dashboard_add_sessions_to_user.php
Normal file
308
main/admin/dashboard_add_sessions_to_user.php
Normal file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Interface for assigning sessions to Human Resources Manager.
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// create an ajax object
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_sessions');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_admin_script(true);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'user_list.php', 'name' => get_lang('UserList')];
|
||||
|
||||
// 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_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
|
||||
|
||||
// Initializing variables
|
||||
$user_id = isset($_GET['user']) ? (int) $_GET['user'] : null;
|
||||
$user_info = api_get_user_info($user_id);
|
||||
$user_anonymous = api_get_anonymous_id();
|
||||
$current_user_id = api_get_user_id();
|
||||
$ajax_search = false;
|
||||
|
||||
// Setting the name of the tool
|
||||
if (UserManager::is_admin($user_id)) {
|
||||
$tool_name = get_lang('AssignSessionsToPlatformAdministrator');
|
||||
} elseif ($user_info['status'] == SESSIONADMIN) {
|
||||
$tool_name = get_lang('AssignSessionsToSessionsAdministrator');
|
||||
} else {
|
||||
$tool_name = get_lang('AssignSessionsToHumanResourcesManager');
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
function search_sessions($needle, $type)
|
||||
{
|
||||
global $user_id;
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
$needle = Database::escape_string($needle);
|
||||
$assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
|
||||
$assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
|
||||
|
||||
$without_assigned_sessions = '';
|
||||
if (count($assigned_sessions_id) > 0) {
|
||||
$without_assigned_sessions = " AND s.id NOT IN(".implode(',', $assigned_sessions_id).")";
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql = " SELECT s.id, s.name FROM $tbl_session s
|
||||
LEFT JOIN $tbl_session_rel_access_url a
|
||||
ON (s.id = a.session_id)
|
||||
WHERE
|
||||
s.name LIKE '$needle%' $without_assigned_sessions AND
|
||||
access_url_id = ".api_get_current_access_url_id();
|
||||
} else {
|
||||
$sql = "SELECT s.id, s.name FROM $tbl_session s
|
||||
WHERE s.name LIKE '$needle%' $without_assigned_sessions ";
|
||||
}
|
||||
$rs = Database::query($sql);
|
||||
$return .= '<select class="form-control" id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20">';
|
||||
while ($session = Database::fetch_array($rs)) {
|
||||
$return .= '<option value="'.$session['id'].'" title="'.htmlspecialchars($session['name'], ENT_QUOTES).'">'.$session['name'].'</option>';
|
||||
}
|
||||
$return .= '</select>';
|
||||
$xajax_response->addAssign(
|
||||
'ajax_list_sessions_multiple',
|
||||
'innerHTML',
|
||||
api_utf8_encode($return)
|
||||
);
|
||||
}
|
||||
|
||||
return $xajax_response;
|
||||
}
|
||||
|
||||
$xajax->processRequests();
|
||||
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
|
||||
$htmlHeadXtra[] = '<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) {
|
||||
var 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();
|
||||
}
|
||||
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;
|
||||
$firstLetterSession = isset($_POST['firstLetterSession']) ? Security::remove_XSS($_POST['firstLetterSession']) : null;
|
||||
$errorMsg = '';
|
||||
$UserList = [];
|
||||
|
||||
if (isset($_POST['formSent']) && 1 == (int) $_POST['formSent']) {
|
||||
$sessions_list = Security::remove_XSS($_POST['SessionsList']);
|
||||
$userInfo = api_get_user_info($user_id);
|
||||
$affected_rows = SessionManager::subscribeSessionsToDrh(
|
||||
$userInfo,
|
||||
$sessions_list
|
||||
);
|
||||
if ($affected_rows) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('AssignedSessionsHaveBeenUpdatedSuccessfully'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// display header
|
||||
Display::display_header($tool_name);
|
||||
|
||||
// Actions
|
||||
if ($user_info['status'] != SESSIONADMIN) {
|
||||
$actionsLeft = '<a href="dashboard_add_users_to_user.php?user='.$user_id.'">'.
|
||||
Display::return_icon('add-user.png', get_lang('AssignUsers'), null, ICON_SIZE_MEDIUM).'</a>';
|
||||
$actionsLeft .= '<a href="dashboard_add_courses_to_user.php?user='.$user_id.'">'.
|
||||
Display::return_icon('course-add.png', get_lang('AssignCourses'), null, ICON_SIZE_MEDIUM).'</a>';
|
||||
|
||||
echo Display::toolbarAction('toolbar-dashboard', [$actionsLeft]);
|
||||
}
|
||||
|
||||
echo Display::page_header(
|
||||
sprintf(get_lang('AssignSessionsToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])),
|
||||
null,
|
||||
'h3'
|
||||
);
|
||||
|
||||
$assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
|
||||
$assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
|
||||
|
||||
$without_assigned_sessions = '';
|
||||
if (count($assigned_sessions_id) > 0) {
|
||||
$without_assigned_sessions = " AND s.id NOT IN (".implode(',', $assigned_sessions_id).") ";
|
||||
}
|
||||
|
||||
$needle = '%';
|
||||
if (!empty($firstLetterSession)) {
|
||||
$needle = Database::escape_string($firstLetterSession.'%');
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql = "SELECT s.id, s.name
|
||||
FROM $tbl_session s
|
||||
LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
|
||||
WHERE
|
||||
s.name LIKE '$needle%' $without_assigned_sessions AND
|
||||
access_url_id = ".api_get_current_access_url_id()."
|
||||
ORDER BY s.name";
|
||||
} else {
|
||||
$sql = "SELECT s.id, s.name FROM $tbl_session s
|
||||
WHERE s.name LIKE '$needle%' $without_assigned_sessions
|
||||
ORDER BY s.name";
|
||||
}
|
||||
$result = Database::query($sql);
|
||||
?>
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?user=<?php echo $user_id; ?>" style="margin:0px;" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
}?>>
|
||||
<input type="hidden" name="formSent" value="1" />
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h5><?php echo get_lang('SessionsListInPlatform'); ?> :</h5>
|
||||
<div id="ajax_list_sessions_multiple">
|
||||
<select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">
|
||||
<?php
|
||||
while ($enreg = Database::fetch_array($result)) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'], ENT_QUOTES).'"'; ?>>
|
||||
<?php echo $enreg['name']; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="code-course">
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<p><?php echo get_lang('FirstLetterSession'); ?> :</p>
|
||||
<select class="selectpicker form-control" name="firstLetterSession" onchange = "xajax_search_sessions(this.value, 'multiple')">
|
||||
<option value="%">--</option>
|
||||
<?php echo Display::get_alphabet_options($firstLetterSession); ?>
|
||||
</select>
|
||||
<?php
|
||||
} ?>
|
||||
</div>
|
||||
<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-arrow-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button 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-arrow-right"></em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="separate-action">
|
||||
<button 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-arrow-left"></em>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
echo '<button class="btn btn-success" type="button" value="" onclick="valide()" >'.$tool_name.'</button>';
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h5>
|
||||
<?php
|
||||
if (UserManager::is_admin($user_id)) {
|
||||
echo get_lang('AssignedSessionsListToPlatformAdministrator');
|
||||
} elseif ($user_info['status'] == SESSIONADMIN) {
|
||||
echo get_lang('AssignedSessionsListToSessionsAdministrator');
|
||||
} else {
|
||||
echo get_lang('AssignedSessionsListToHumanResourcesManager');
|
||||
}
|
||||
?>
|
||||
:</h5>
|
||||
<select id='destination' name="SessionsList[]" multiple="multiple" size="20" style="width:320px;">
|
||||
<?php
|
||||
if (is_array($assigned_sessions_to_hrm)) {
|
||||
foreach ($assigned_sessions_to_hrm as $enreg) {
|
||||
?>
|
||||
<option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'], ENT_QUOTES).'"'; ?>>
|
||||
<?php echo $enreg['name']; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
}?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
517
main/admin/dashboard_add_users_to_user.php
Normal file
517
main/admin/dashboard_add_users_to_user.php
Normal file
@@ -0,0 +1,517 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Interface for assigning users to Human Resources Manager.
|
||||
*/
|
||||
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$ajax_search = false;
|
||||
// create an ajax object
|
||||
$xajax = new xajax();
|
||||
$xajax->registerFunction('search_users');
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_admin_script(true);
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'user_list.php', 'name' => get_lang('UserList')];
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
|
||||
$tbl_access_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
|
||||
// initializing variables
|
||||
$user_id = isset($_GET['user']) ? (int) $_GET['user'] : 0;
|
||||
$user_info = api_get_user_info($user_id);
|
||||
$user_anonymous = api_get_anonymous_id();
|
||||
$current_user_id = api_get_user_id();
|
||||
|
||||
$userStatus = api_get_user_status($user_id);
|
||||
|
||||
$firstLetterUser = isset($_POST['firstLetterUser']) ? Security::remove_XSS($_POST['firstLetterUser']) : null;
|
||||
|
||||
// setting the name of the tool
|
||||
$isAdmin = UserManager::is_admin($user_id);
|
||||
if ($isAdmin) {
|
||||
$userStatus = PLATFORM_ADMIN;
|
||||
$tool_name = get_lang('AssignUsersToPlatformAdministrator');
|
||||
} elseif ($user_info['status'] == SESSIONADMIN) {
|
||||
$tool_name = get_lang('AssignUsersToSessionsAdministrator');
|
||||
} elseif ($user_info['status'] == STUDENT_BOSS) {
|
||||
$tool_name = get_lang('AssignUsersToBoss');
|
||||
} else {
|
||||
$tool_name = get_lang('AssignUsersToHumanResourcesManager');
|
||||
}
|
||||
|
||||
$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_not_allowed(true);
|
||||
}
|
||||
|
||||
function search_users($needle, $type = 'multiple')
|
||||
{
|
||||
global $tbl_access_url_rel_user, $tbl_user, $user_anonymous, $current_user_id, $user_id, $userStatus;
|
||||
|
||||
$xajax_response = new xajaxResponse();
|
||||
$return = '';
|
||||
$needle = Database::escape_string($needle);
|
||||
$type = Database::escape_string($type);
|
||||
|
||||
if (!empty($needle) && !empty($type)) {
|
||||
$assigned_users_to_hrm = [];
|
||||
|
||||
switch ($userStatus) {
|
||||
case DRH:
|
||||
case PLATFORM_ADMIN:
|
||||
$assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id);
|
||||
break;
|
||||
case STUDENT_BOSS:
|
||||
$assigned_users_to_hrm = UserManager::getUsersFollowedByStudentBoss($user_id);
|
||||
break;
|
||||
}
|
||||
|
||||
$assigned_users_id = array_keys($assigned_users_to_hrm);
|
||||
$without_assigned_users = '';
|
||||
|
||||
$westernOrder = api_is_western_name_order();
|
||||
if ($westernOrder) {
|
||||
$order_clause = " ORDER BY firstname, lastname";
|
||||
} else {
|
||||
$order_clause = " ORDER BY lastname, firstname";
|
||||
}
|
||||
|
||||
if (count($assigned_users_id) > 0) {
|
||||
$without_assigned_users = " AND user.user_id NOT IN(".implode(',', $assigned_users_id).")";
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql = "SELECT user.user_id, username, lastname, firstname
|
||||
FROM $tbl_user user
|
||||
LEFT JOIN $tbl_access_url_rel_user au ON (au.user_id = user.user_id)
|
||||
WHERE
|
||||
".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND
|
||||
status NOT IN(".DRH.", ".SESSIONADMIN.", ".STUDENT_BOSS.") AND
|
||||
user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id)
|
||||
$without_assigned_users AND
|
||||
access_url_id = ".api_get_current_access_url_id()."
|
||||
$order_clause
|
||||
";
|
||||
} else {
|
||||
$sql = "SELECT user_id, username, lastname, firstname
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND
|
||||
status NOT IN(".DRH.", ".SESSIONADMIN.", ".STUDENT_BOSS.") AND
|
||||
user_id NOT IN ($user_anonymous, $current_user_id, $user_id)
|
||||
$without_assigned_users
|
||||
$order_clause
|
||||
";
|
||||
}
|
||||
$rs = Database::query($sql);
|
||||
$xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return));
|
||||
|
||||
if ($type == 'single') {
|
||||
$tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
|
||||
$access_url_id = api_get_current_access_url_id();
|
||||
|
||||
$sql = 'SELECT user.user_id, username, lastname, firstname
|
||||
FROM '.$tbl_user.' user
|
||||
INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
|
||||
WHERE
|
||||
access_url_id = '.$access_url_id.' AND
|
||||
(
|
||||
username LIKE "'.$needle.'%" OR
|
||||
firstname LIKE "'.$needle.'%" OR
|
||||
lastname LIKE "'.$needle.'%"
|
||||
) AND ';
|
||||
|
||||
switch ($userStatus) {
|
||||
case DRH:
|
||||
$sql .= " user.status <> 6 AND user.status <> ".DRH;
|
||||
break;
|
||||
case STUDENT_BOSS:
|
||||
$sql .= " user.status <> 6 AND user.status <> ".STUDENT_BOSS;
|
||||
break;
|
||||
}
|
||||
|
||||
$sql .= " $order_clause LIMIT 11";
|
||||
|
||||
$rs = Database::query($sql);
|
||||
$i = 0;
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$i++;
|
||||
if ($i <= 10) {
|
||||
$person_name = api_get_person_name($user['firstname'], $user['lastname']);
|
||||
$return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_user(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
|
||||
} else {
|
||||
$return .= '...<br />';
|
||||
}
|
||||
}
|
||||
$xajax_response->addAssign(
|
||||
'ajax_list_users_single',
|
||||
'innerHTML',
|
||||
api_utf8_encode($return)
|
||||
);
|
||||
} else {
|
||||
$return .= '<select id="origin" class="form-control" name="NoAssignedUsersList[]" multiple="multiple" size="15" ">';
|
||||
while ($user = Database::fetch_array($rs)) {
|
||||
$person_name = api_get_person_name($user['firstname'], $user['lastname']);
|
||||
$return .= '<option value="'.$user['user_id'].'" title="'.htmlspecialchars($person_name, ENT_QUOTES).'">'.$person_name.' ('.$user['username'].')</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_user (code, content) {
|
||||
document.getElementById("user_to_add").value = "";
|
||||
document.getElementById("ajax_list_users_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 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) {
|
||||
var 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();
|
||||
}
|
||||
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 = '';
|
||||
$UserList = [];
|
||||
|
||||
// Filters
|
||||
$filters = [
|
||||
['type' => 'text', 'name' => 'username', 'label' => get_lang('Username')],
|
||||
['type' => 'text', 'name' => 'firstname', 'label' => get_lang('FirstName')],
|
||||
['type' => 'text', 'name' => 'lastname', 'label' => get_lang('LastName')],
|
||||
['type' => 'text', 'name' => 'official_code', 'label' => get_lang('OfficialCode')],
|
||||
['type' => 'text', 'name' => 'email', 'label' => get_lang('Email')],
|
||||
];
|
||||
|
||||
$searchForm = new FormValidator('search', 'get', api_get_self().'?user='.$user_id);
|
||||
$searchForm->addHeader(get_lang('AdvancedSearch'));
|
||||
$renderer = &$searchForm->defaultRenderer();
|
||||
|
||||
$searchForm->addElement('hidden', 'user', $user_id);
|
||||
foreach ($filters as $param) {
|
||||
$searchForm->addElement($param['type'], $param['name'], $param['label']);
|
||||
}
|
||||
$searchForm->addButtonSearch(get_lang('Search'));
|
||||
|
||||
$filterData = [];
|
||||
if ($searchForm->validate()) {
|
||||
$filterData = $searchForm->getSubmitValues();
|
||||
}
|
||||
|
||||
$conditions = [];
|
||||
if (!empty($filters) && !empty($filterData)) {
|
||||
foreach ($filters as $filter) {
|
||||
if (isset($filter['name']) && isset($filterData[$filter['name']])) {
|
||||
$value = $filterData[$filter['name']];
|
||||
if (!empty($value)) {
|
||||
$conditions[$filter['name']] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
|
||||
$user_list = isset($_POST['UsersList']) ? Security::remove_XSS($_POST['UsersList']) : null;
|
||||
switch ($userStatus) {
|
||||
case DRH:
|
||||
case PLATFORM_ADMIN:
|
||||
$affected_rows = UserManager::subscribeUsersToHRManager($user_id, $user_list);
|
||||
break;
|
||||
case STUDENT_BOSS:
|
||||
$affected_rows = UserManager::subscribeBossToUsers($user_id, $user_list);
|
||||
break;
|
||||
default:
|
||||
$affected_rows = 0;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('AssignedUsersHaveBeenUpdatedSuccessfully'),
|
||||
'normal'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Display header
|
||||
Display::display_header($tool_name);
|
||||
|
||||
// actions
|
||||
$actionsLeft = '';
|
||||
if ($userStatus != STUDENT_BOSS) {
|
||||
$actionsLeft = Display::url(
|
||||
Display::return_icon('course-add.png', get_lang('AssignCourses'), null, ICON_SIZE_MEDIUM),
|
||||
"dashboard_add_courses_to_user.php?user=$user_id"
|
||||
);
|
||||
|
||||
$actionsLeft .= Display::url(
|
||||
Display::return_icon('session-add.png', get_lang('AssignSessions'), null, ICON_SIZE_MEDIUM),
|
||||
"dashboard_add_sessions_to_user.php?user=$user_id"
|
||||
);
|
||||
}
|
||||
|
||||
$actionsRight = Display::url(
|
||||
'<em class="fa fa-search"></em> '.get_lang('AdvancedSearch'),
|
||||
'#',
|
||||
['class' => 'btn btn-default advanced_options', 'id' => 'advanced_search']
|
||||
);
|
||||
|
||||
$toolbar = Display::toolbarAction('toolbar-dashboard', [$actionsLeft, $actionsRight]);
|
||||
echo $toolbar;
|
||||
|
||||
echo '<div id="advanced_search_options" style="display:none">';
|
||||
$searchForm->display();
|
||||
echo '</div>';
|
||||
|
||||
echo Display::page_header(
|
||||
sprintf(
|
||||
get_lang('AssignUsersToX'),
|
||||
api_get_person_name($user_info['firstname'], $user_info['lastname'])
|
||||
),
|
||||
null,
|
||||
'h3'
|
||||
);
|
||||
|
||||
$assigned_users_to_hrm = [];
|
||||
|
||||
switch ($userStatus) {
|
||||
case DRH:
|
||||
case PLATFORM_ADMIN:
|
||||
$assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id);
|
||||
break;
|
||||
case STUDENT_BOSS:
|
||||
$assigned_users_to_hrm = UserManager::getUsersFollowedByStudentBoss($user_id);
|
||||
break;
|
||||
}
|
||||
|
||||
$assigned_users_id = array_keys($assigned_users_to_hrm);
|
||||
$without_assigned_users = '';
|
||||
if (count($assigned_users_id) > 0) {
|
||||
$without_assigned_users = " user.user_id NOT IN(".implode(',', $assigned_users_id).") AND ";
|
||||
}
|
||||
|
||||
$search_user = '';
|
||||
$needle = '';
|
||||
if (!empty($firstLetterUser)) {
|
||||
$needle = Database::escape_string($firstLetterUser);
|
||||
$search_user = "AND ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%'";
|
||||
}
|
||||
|
||||
$sqlConditions = null;
|
||||
if (!empty($conditions)) {
|
||||
$temp_conditions = [];
|
||||
foreach ($conditions as $field => $value) {
|
||||
$field = Database::escape_string($field);
|
||||
$value = Database::escape_string($value);
|
||||
$temp_conditions[] = $field.' LIKE \'%'.$value.'%\'';
|
||||
}
|
||||
if (!empty($temp_conditions)) {
|
||||
$sqlConditions .= implode(' AND ', $temp_conditions);
|
||||
}
|
||||
if (!empty($sqlConditions)) {
|
||||
$sqlConditions = " AND $sqlConditions";
|
||||
}
|
||||
}
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$sql = "SELECT user.user_id, username, lastname, firstname
|
||||
FROM $tbl_user user
|
||||
LEFT JOIN $tbl_access_url_rel_user au
|
||||
ON (au.user_id = user.user_id)
|
||||
WHERE
|
||||
$without_assigned_users
|
||||
user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND
|
||||
status NOT IN(".DRH.", ".SESSIONADMIN.", ".ANONYMOUS.") $search_user AND
|
||||
access_url_id = ".api_get_current_access_url_id()."
|
||||
$sqlConditions
|
||||
ORDER BY firstname";
|
||||
} else {
|
||||
$sql = "SELECT user_id, username, lastname, firstname
|
||||
FROM $tbl_user user
|
||||
WHERE
|
||||
$without_assigned_users
|
||||
user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND
|
||||
status NOT IN(".DRH.", ".SESSIONADMIN.", ".ANONYMOUS.")
|
||||
$search_user
|
||||
$sqlConditions
|
||||
ORDER BY firstname ";
|
||||
}
|
||||
$result = Database::query($sql);
|
||||
?>
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?user=<?php echo $user_id; ?>" class="form-horizontal" <?php if ($ajax_search) {
|
||||
echo ' onsubmit="valide();"';
|
||||
}?>>
|
||||
<input type="hidden" name="formSent" value="1" />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<?php echo get_lang('UserListInPlatform'); ?>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<div id="ajax_list_users_multiple">
|
||||
<select id="origin" class="form-control" name="NoAssignedUsersList[]" multiple="multiple" size="15">
|
||||
<?php
|
||||
while ($enreg = Database::fetch_array($result)) {
|
||||
$person_name = api_get_person_name($enreg['firstname'], $enreg['lastname']); ?>
|
||||
<option value="<?php echo $enreg['user_id']; ?>" <?php echo 'title="'.htmlspecialchars($person_name, ENT_QUOTES).'"'; ?>>
|
||||
<?php echo $person_name.' ('.$enreg['username'].')'; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="code-course">
|
||||
<?php if ($add_type == 'multiple') {
|
||||
?>
|
||||
<p><?php echo get_lang('FirstLetterUser'); ?></p>
|
||||
<select class="selectpicker show-tick form-control" name="firstLetterUser" onchange = "xajax_search_users(this.value,'multiple')">
|
||||
<option value="%">--</option>
|
||||
<?php echo Display::get_alphabet_options($firstLetterUser); ?>
|
||||
</select>
|
||||
<?php
|
||||
} ?>
|
||||
</div>
|
||||
<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'))"></button>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="separate-action">
|
||||
<button id="add_user_button" 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 id="remove_user_button" 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">
|
||||
<?php
|
||||
echo '<button id="assign_user" class="btn btn-success" type="button" value="" onclick="valide()" >'.$tool_name.'</button>';
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?php
|
||||
if (UserManager::is_admin($user_id)) {
|
||||
echo get_lang('AssignedUsersListToPlatformAdministrator');
|
||||
} else {
|
||||
if ($user_info['status'] == SESSIONADMIN) {
|
||||
echo get_lang('AssignedUsersListToSessionsAdministrator');
|
||||
} else {
|
||||
if ($user_info['status'] == STUDENT_BOSS) {
|
||||
echo get_lang('AssignedUsersListToStudentBoss');
|
||||
} else {
|
||||
echo get_lang('AssignedUsersListToHumanResourcesManager');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<br>
|
||||
<select id='destination' class="form-control" name="UsersList[]" multiple="multiple" size="15" >
|
||||
<?php
|
||||
if (is_array($assigned_users_to_hrm)) {
|
||||
foreach ($assigned_users_to_hrm as $enreg) {
|
||||
$person_name = api_get_person_name($enreg['firstname'], $enreg['lastname']); ?>
|
||||
<option value="<?php echo $enreg['user_id']; ?>" <?php echo 'title="'.htmlspecialchars($person_name, ENT_QUOTES).'"'; ?>>
|
||||
<?php echo $person_name.' ('.$enreg['username'].')'; ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
}?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
15
main/admin/db.php
Normal file
15
main/admin/db.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
if (!api_is_global_platform_admin()) {
|
||||
exit('Please connect as a global administrator to access this page');
|
||||
}
|
||||
|
||||
echo "In this version, the script allowing you to connect to the database from your Chamilo interface has been
|
||||
deprecated/removed due to increasing reports about a possible vulnerability (which we agree with, in principle).
|
||||
To use this feature, please download Adminer as one single PHP file from https://www.adminer.org/#download,
|
||||
install it somewhere safe, unpredictable and or access-protected on your Chamilo server and load it from there.
|
||||
Our apologies for the extra effort needed.";
|
||||
127
main/admin/download_import_users.php
Normal file
127
main/admin/download_import_users.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* This tool allows platform admins to check history by csv file.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$userId = api_get_user_id();
|
||||
api_protect_admin_script(true, null);
|
||||
api_protect_limit_for_session_admin();
|
||||
set_time_limit(0);
|
||||
|
||||
/**
|
||||
* Read all the archive files previously placed in app/cache/backup/import_users/[user]/
|
||||
* when users were imported through CSV (one can only see the users imported by
|
||||
* oneself).
|
||||
*
|
||||
* @return array Array of archives found in the app/cache/backup
|
||||
*/
|
||||
function readImportedUsersArchives(string $path = '', string $parentFile = null, int $userId = 0): array
|
||||
{
|
||||
$data = [];
|
||||
if (empty($path)) {
|
||||
$path = api_get_path(SYS_ARCHIVE_PATH).'backup/import_users/'.api_get_user_id();
|
||||
}
|
||||
foreach (scandir($path) as $dir) {
|
||||
// exclude ".", ".." and ".htaccess"
|
||||
if (in_array($dir, ['.', '..', '.htaccess'])) {
|
||||
continue;
|
||||
}
|
||||
$currentPath = $path.DIRECTORY_SEPARATOR.$dir;
|
||||
if (is_dir($currentPath)) {
|
||||
$data[$dir] = readImportedUsersArchives($currentPath, $dir, $userId);
|
||||
} elseif (is_file($currentPath)) {
|
||||
if (strpos($dir, '.csv') !== false) {
|
||||
$data[$dir] = $currentPath;
|
||||
if (empty($_GET['download'])) {
|
||||
continue;
|
||||
}
|
||||
$filename = substr($_GET['download'], -strlen($dir));
|
||||
$time = (string) (int) substr($_GET['download'], 0, -strlen($dir));
|
||||
// Clean against hacks
|
||||
if ($filename == $dir) {
|
||||
if (!Security::check_abs_path($path.DIRECTORY_SEPARATOR.$filename, $path)) {
|
||||
continue;
|
||||
}
|
||||
DocumentManager::file_send_for_download($currentPath, true, $time.'_'.$filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
krsort($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print an HTML table of archives of imported users.
|
||||
*
|
||||
* @return string HTML table or empty string if no results
|
||||
*/
|
||||
function getImportedUsersArchivesTable(): string
|
||||
{
|
||||
$data = readImportedUsersArchives();
|
||||
if (empty($data)) {
|
||||
return '';
|
||||
}
|
||||
$table = new HTML_Table(['class' => 'table table-responsive']);
|
||||
$headers = [
|
||||
get_lang('SelectUser'),
|
||||
get_lang('FieldTypeDatetime'),
|
||||
get_lang('Files'),
|
||||
];
|
||||
$row = 0;
|
||||
$column = 0;
|
||||
foreach ($headers as $header) {
|
||||
$table->setHeaderContents($row, $column, $header);
|
||||
$column++;
|
||||
}
|
||||
|
||||
$row++;
|
||||
$userId = api_get_user_id();
|
||||
|
||||
$userInfo = api_get_user_info($userId);
|
||||
foreach ($data as $date => $elements) {
|
||||
$dateTime = DateTime::createFromFormat('YmdHis', $date)->format('Y-m-d H:i:s');
|
||||
$files = '';
|
||||
foreach ($elements as $fileName => $file) {
|
||||
$files .= "<a href='".api_get_self().'?download='.$date.'_'.$fileName."'>".
|
||||
Display::return_icon('down.png', get_lang('Down'), '', ICON_SIZE_SMALL).
|
||||
" $fileName </a> <br>";
|
||||
}
|
||||
if (!empty($files)) {
|
||||
$table->setCellContents($row, 0, $userInfo['complete_name']);
|
||||
$table->setCellContents($row, 1, $dateTime);
|
||||
$table->setCellContents($row, 2, $files);
|
||||
$row++;
|
||||
}
|
||||
}
|
||||
|
||||
return $table->toHtml();
|
||||
}
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$defined_auth_sources[] = PLATFORM_AUTH_SOURCE;
|
||||
if (isset($extAuthSource) && is_array($extAuthSource)) {
|
||||
$defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));
|
||||
}
|
||||
|
||||
$tool_name = get_lang('History');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'user_import.php', 'name' => get_lang('ImportUserListXMLCSV')];
|
||||
$reloadImport = (isset($_REQUEST['reload_import']) && (int) $_REQUEST['reload_import'] === 1);
|
||||
|
||||
$extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', true);
|
||||
$printTable = getImportedUsersArchivesTable();
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$form = new FormValidator('user_import', 'post', api_get_self());
|
||||
$form->addHeader($tool_name);
|
||||
$defaults['formSent'] = 1;
|
||||
$form->addHtml($printTable);
|
||||
$form->display();
|
||||
Display::display_footer();
|
||||
76
main/admin/email_tester.php
Normal file
76
main/admin/email_tester.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Index page of the admin tools.
|
||||
*/
|
||||
// Resetting the course id.
|
||||
$cidReset = true;
|
||||
|
||||
// Including some necessary chamilo files.
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
// Setting the section (for the tabs).
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$toolName = get_lang('EMailTester');
|
||||
|
||||
$form = new FormValidator('email_tester');
|
||||
$form->addText('smtp_host', get_lang('Host'), false, ['cols-size' => [2, 8, 2]]);
|
||||
$form->addText('smtp_port', get_lang('Port'), false, ['cols-size' => [2, 8, 2]]);
|
||||
$form->addText('destination', get_lang('Destination'), true, ['cols-size' => [2, 8, 2]]);
|
||||
$form->addText('subject', get_lang('Subject'), true, ['cols-size' => [2, 8, 2]]);
|
||||
$form->addHtmlEditor(
|
||||
'content',
|
||||
get_lang('Message'),
|
||||
true,
|
||||
false,
|
||||
['ToolbarSet' => 'Minimal', 'cols-size' => [2, 8, 2]]
|
||||
);
|
||||
$form->addButtonSend(get_lang('SendMessage'), 'submit', false, ['cols-size' => [2, 8, 2]]);
|
||||
$form->setDefaults([
|
||||
'smtp_host' => api_get_mail_configuration_value('SMTP_HOST'),
|
||||
'smtp_port' => api_get_mail_configuration_value('SMTP_PORT'),
|
||||
]);
|
||||
$form->freeze(['smtp_host', 'smtp_port']);
|
||||
|
||||
$errorsInfo = MessageManager::failedSentMailErrors();
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
|
||||
$user = api_get_user_entity(api_get_user_id());
|
||||
|
||||
$mailIsSent = api_mail_html(
|
||||
get_lang('UserTestingEMailConf'),
|
||||
$values['destination'],
|
||||
$values['subject'],
|
||||
$values['content'],
|
||||
UserManager::formatUserFullName($user),
|
||||
(!empty(api_get_mail_configuration_value('SMTP_UNIQUE_SENDER')) ? api_get_mail_configuration_value('SMTP_FROM_EMAIL') : $user->getEmail())
|
||||
);
|
||||
|
||||
if ($mailIsSent) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('MailingTestSent'), 'success')
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('MailingTestNotSent'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$view = new Template($toolName);
|
||||
$view->assign('form', $form->returnForm());
|
||||
$view->assign('errors', $errorsInfo);
|
||||
|
||||
$template = $view->get_template('admin/email_tester.tpl');
|
||||
$content = $view->fetch($template);
|
||||
|
||||
$view->assign('header', $toolName);
|
||||
$view->assign('content', $content);
|
||||
$view->display_one_col_template();
|
||||
81
main/admin/event_controller.php
Normal file
81
main/admin/event_controller.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Global events controller class.
|
||||
*
|
||||
* @deprecated to be removed in 2.x
|
||||
*
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
if (api_get_setting('activate_email_template') != 'true') {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
$action_links = '';
|
||||
$tool_name = '';
|
||||
$message = '';
|
||||
|
||||
switch ($action) {
|
||||
case 'show':
|
||||
break;
|
||||
case 'add':
|
||||
break;
|
||||
case 'new':
|
||||
break;
|
||||
case 'delete':
|
||||
$event_email_template = new EventEmailTemplate();
|
||||
$event_email_template->delete($_GET['id']);
|
||||
$content = $event_email_template->display();
|
||||
break;
|
||||
default:
|
||||
case 'listing':
|
||||
$event_email_template = new EventEmailTemplate();
|
||||
$content = $event_email_template->display();
|
||||
break;
|
||||
}
|
||||
|
||||
//jqgrid will use this URL to do the selects
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_event_email_template';
|
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file
|
||||
$columns = [
|
||||
get_lang('Subject'),
|
||||
get_lang('EventTypeName'),
|
||||
get_lang('Language'),
|
||||
get_lang('Status'),
|
||||
get_lang('Actions'),
|
||||
];
|
||||
|
||||
//Column config
|
||||
$column_model = [
|
||||
['name' => 'subject', 'index' => 'subject', 'width' => '80', 'align' => 'left'],
|
||||
// array('name'=>'message', 'index'=>'message', 'width'=>'500', 'align'=>'left','sortable'=>'false'),
|
||||
['name' => 'event_type_name', 'index' => 'event_type_name', 'width' => '80', 'align' => 'left'],
|
||||
['name' => 'language_id', 'index' => 'language_id', 'width' => '80', 'align' => 'left'],
|
||||
['name' => 'activated', 'index' => 'activated', 'width' => '80', 'align' => 'left'],
|
||||
['name' => 'actions', 'index' => 'actions', 'width' => '100'],
|
||||
];
|
||||
//Autowidth
|
||||
$extra_params['autowidth'] = 'true';
|
||||
//height auto
|
||||
$extra_params['height'] = 'auto';
|
||||
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
'.Display::grid_js('event_email_template', $url, $columns, $column_model, $extra_params, [], $action_links, true).'
|
||||
});
|
||||
</script>';
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Events')];
|
||||
|
||||
$tpl = new Template($tool_name);
|
||||
$tpl->assign('message', $message);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
409
main/admin/event_type.php
Normal file
409
main/admin/event_type.php
Normal file
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Definition of new system event types.
|
||||
*
|
||||
* @deprecated to be removed in 2.x
|
||||
*
|
||||
* @package chamilo.admin.events
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
if (api_get_setting('activate_email_template') != 'true') {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$action = isset($_POST['action']) ? $_POST['action'] : null;
|
||||
$eventName = isset($_POST['eventList']) ? $_POST['eventList'] : null;
|
||||
$eventUsers = isset($_POST['eventUsers']) ? $_POST['eventUsers'] : null;
|
||||
$eventMessage = isset($_POST['eventMessage']) ? $_POST['eventMessage'] : null;
|
||||
$eventSubject = isset($_POST['eventSubject']) ? $_POST['eventSubject'] : null;
|
||||
$eventMessageLanguage = isset($_POST['languages']) ? $_POST['languages'] : null;
|
||||
$activated = isset($_POST['activated']) ? $_POST['activated'] : 0;
|
||||
$event_name = isset($_REQUEST['event_type_name']) ? addslashes($_REQUEST['event_type_name']) : 0;
|
||||
|
||||
if ($action == 'modEventType') {
|
||||
if ($eventUsers) {
|
||||
$users = explode(';', $eventUsers);
|
||||
} else {
|
||||
$users = [];
|
||||
}
|
||||
if (!empty($event_name)) {
|
||||
$eventName = $event_name;
|
||||
}
|
||||
Event::save_event_type_message(
|
||||
$eventName,
|
||||
$users,
|
||||
$eventMessage,
|
||||
$eventSubject,
|
||||
$eventMessageLanguage,
|
||||
$activated
|
||||
);
|
||||
header('location: event_controller.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$ets = Event::get_all_event_types();
|
||||
$languages = api_get_languages();
|
||||
$ajaxPath = api_get_path(WEB_CODE_PATH).'inc/ajax/events.ajax.php';
|
||||
|
||||
$action_array = [
|
||||
[
|
||||
'url' => 'event_controller.php?action=listing',
|
||||
'content' => Display::return_icon(
|
||||
'view_text.png',
|
||||
get_lang('ListView'),
|
||||
[],
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
],
|
||||
];
|
||||
|
||||
$key_lang = get_lang('YouHaveSomeUnsavedChanges');
|
||||
$users = UserManager::get_user_list([], ['firstname']);
|
||||
$new_user_list = [];
|
||||
foreach ($users as $user) {
|
||||
if ($user['status'] == ANONYMOUS) {
|
||||
continue;
|
||||
}
|
||||
$new_user_list[] = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Header definition.
|
||||
*/
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'event_controller.php', 'name' => get_lang('Events')];
|
||||
$tool_name = get_lang('EventMessageManagement');
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo Display::actions($action_array);
|
||||
|
||||
/**
|
||||
* JavaScript code.
|
||||
*
|
||||
* @todo move into HTML header
|
||||
*/
|
||||
?>
|
||||
<script>
|
||||
var usersList = <?php echo json_encode($new_user_list); ?>;
|
||||
var eventTypes = <?php echo json_encode($ets); ?>;
|
||||
var eventsConfig = <?php echo json_encode($event_config); ?>;
|
||||
var currentLanguage = <?php echo json_encode(api_get_interface_language()); ?>;
|
||||
var flagContentHasChanged = false;
|
||||
var key_lang = "<?php echo $key_lang; ?>";
|
||||
var event_type_name = "<?php echo $event_name; ?>";
|
||||
|
||||
$(document).ready(function() {
|
||||
confirmMessage("eventList");
|
||||
if (event_type_name != 0) {
|
||||
$("#event_list_group").hide();
|
||||
}
|
||||
});
|
||||
|
||||
function ajax(params,func) {
|
||||
$.ajax({
|
||||
url: "<?php echo $ajaxPath; ?>",
|
||||
type: "POST",
|
||||
data: params,
|
||||
success: func
|
||||
});
|
||||
}
|
||||
|
||||
function refreshUsersList() {
|
||||
removeAllOption($('#usersList'));
|
||||
$.each(usersList, function(ind,item) {
|
||||
addOption($('#usersList'), item.user_id, item.firstname + ' '+item.lastname);
|
||||
});
|
||||
}
|
||||
|
||||
function getCurrentEventTypeName() {
|
||||
var name = false;
|
||||
|
||||
if (event_type_name != 0) {
|
||||
return event_type_name;
|
||||
} else {
|
||||
return $('#eventList option:selected').first().attr('value');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function self_sent_lock(self_sent) {
|
||||
if (self_sent == true) {
|
||||
$(".registration_case").show();
|
||||
$("#usersList").attr('disabled', 'true');
|
||||
$("#usersSubList").attr('disabled', 'true');
|
||||
removeAllOption($('#usersSubList'));
|
||||
} else {
|
||||
$(".registration_case").show();
|
||||
$("#usersList").removeAttr('disabled');
|
||||
$("#usersSubList").removeAttr('disabled');
|
||||
}
|
||||
}
|
||||
|
||||
function showEventType() {
|
||||
cleanInput();
|
||||
currentEventName = getCurrentEventTypeName();
|
||||
|
||||
$("span#activated_checkbox").css("display", "inline"); // make checkbox visible
|
||||
$('input[name=activated]').attr('checked', false);
|
||||
|
||||
var self_sent = false;
|
||||
|
||||
if (typeof(eventsConfig[currentEventName])!='undefined') {
|
||||
// if registration, only sent to self_user
|
||||
if (eventsConfig[currentEventName].self_sent == true) {
|
||||
self_sent = true;
|
||||
}
|
||||
}
|
||||
|
||||
self_sent_lock(self_sent);
|
||||
|
||||
// List of events configuration
|
||||
$('#eventName').attr('value', currentEventName);
|
||||
$('#eventNameTitle').text('');
|
||||
//$('#descLangVar').text(eventsConfig[currentEventName].desc_lang_var);
|
||||
|
||||
// Set message and subject accoding to the current interface language
|
||||
$.each(eventTypes,function(key,value) {
|
||||
if (eventTypes[key]["event_type_name"] == currentEventName) {
|
||||
$('#eventNameTitle').text(eventTypes[key]["nameLangVar"]);
|
||||
}
|
||||
|
||||
if (eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["activated"] == 1) {
|
||||
$('input[name=activated]').attr('checked', true);
|
||||
}
|
||||
|
||||
if (eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["dokeos_folder"] == currentLanguage) {
|
||||
$('#eventMessage').val(eventTypes[key]["message"]);
|
||||
$('#eventSubject').val(eventTypes[key]["subject"]);
|
||||
}
|
||||
});
|
||||
|
||||
// Displays the available keys for the mail template (related to an event name)
|
||||
$('#keys').find('li').remove();
|
||||
if(typeof(eventsConfig[currentEventName]["available_keyvars"])!='undefined') {
|
||||
$.each(eventsConfig[currentEventName]["available_keyvars"],function(key,value) {
|
||||
$('#keys').append('<li>'+key+'</li>');
|
||||
});
|
||||
}
|
||||
|
||||
if (self_sent == false ) {
|
||||
|
||||
$.ajax({
|
||||
url: '<?php echo $ajaxPath; ?>?action=get_event_users&eventName=' +currentEventName,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
removeAllOption($('#usersSubList'));
|
||||
refreshUsersList();
|
||||
usersIds = new Array();
|
||||
var json = jQuery.parseJSON(data);
|
||||
$.each(json, function(ind,item) {
|
||||
addOption($('#usersSubList'),item.user_id, item.firstname + ' '+item.lastname);
|
||||
usersIds[ind] = item.value;
|
||||
removeOption($('#usersList'),item.user_id);
|
||||
});
|
||||
$('#eventUsers').attr('value',usersIds.join(';'));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function submitForm() {
|
||||
if ($('#eventId')) {
|
||||
usersIds = new Array();
|
||||
|
||||
$('#usersSubList option').each(function(ind,item) {
|
||||
usersIds[ind] = item.value;
|
||||
});
|
||||
|
||||
$('#eventUsers').attr('value',usersIds.join(';'));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function addOption(select,value,text) {
|
||||
select.append('<option value="'+value+'">'+text+'</option>');
|
||||
}
|
||||
|
||||
function removeOption(select,value) {
|
||||
select.find('option[value='+value+']').remove();
|
||||
}
|
||||
|
||||
function removeAllOption(select) {
|
||||
select.find('option').remove();
|
||||
}
|
||||
|
||||
function moveUsers(src,dest) {
|
||||
src.find('option:selected').each(function(index,opt) {
|
||||
text = opt.text;
|
||||
val = opt.value;
|
||||
|
||||
addOption(dest,val,text);
|
||||
removeOption(src,val);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the message of the mail according to the selected language
|
||||
*/
|
||||
function changeLanguage()
|
||||
{
|
||||
cleanInput();
|
||||
currentEventName = getCurrentEventTypeName();
|
||||
$.each(eventTypes,function(key,value)
|
||||
{
|
||||
if(eventTypes[key]["event_type_name"] == currentEventName && eventTypes[key]["dokeos_folder"] == $('#languages option:selected').first().attr('value'))
|
||||
{
|
||||
$('#eventSubject').val(eventTypes[key]["subject"]);
|
||||
$('#eventMessage').val(eventTypes[key]["message"]);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag at true if message and/or content was changed
|
||||
*/
|
||||
function contentChanged()
|
||||
{
|
||||
flagContentHasChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks if user want to abandon the changes he's done
|
||||
*/
|
||||
function confirmMessage(sender) {
|
||||
|
||||
if (flagContentHasChanged == true) {
|
||||
if (confirm(key_lang)) {
|
||||
flagContentHasChanged = false;
|
||||
if (sender == "eventList") {
|
||||
cleanInput();
|
||||
showEventType();
|
||||
} else if(sender == "languages") {
|
||||
cleanInput();
|
||||
changeLanguage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(sender == "eventList")
|
||||
showEventType();
|
||||
else if(sender == "languages")
|
||||
changeLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the input and the textarea
|
||||
*/
|
||||
function cleanInput() {
|
||||
$('#eventMessage').val("");
|
||||
$('#eventSubject').val("");
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
/**
|
||||
* HTML body.
|
||||
*
|
||||
* @todo move as template layout
|
||||
*/
|
||||
?>
|
||||
<div class="page-header">
|
||||
<h2><?php echo get_lang('EventMessageManagement'); ?></h2>
|
||||
</div>
|
||||
|
||||
<form method="POST" onSubmit="return submitForm(); ">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12" id="event_list_group">
|
||||
<h4><?php echo get_lang('Events'); ?></h4>
|
||||
<select class="col-md-6" multiple="1" id="eventList" onchange="confirmMessage(this.name); return false;" name="eventList">
|
||||
<?php
|
||||
foreach ($event_config as $key => $config) {
|
||||
echo '<option value="'.$key.'">'.$config['name_lang_var'].'</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<h4><?php echo get_lang('Users'); ?></h4>
|
||||
<select multiple="1" id="usersList" class="registration_case"></select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="registration_case">
|
||||
<button class="btn btn-default" onclick='moveUsers($("#usersList"),$("#usersSubList")); return false;'><em class="fa fa-arrow-left"></em></button>
|
||||
<br />
|
||||
<br />
|
||||
<button class="btn btn-default" onclick='moveUsers($("#usersSubList"),$("#usersList")); return false;'><em class="fa fa-arrow-right"></em></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h4><?php echo get_lang('ToBeWarnedUserList'); ?></h4>
|
||||
<select class="col-md-3" multiple="1" id="usersSubList" class="registration_case"></select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<h2 id="eventNameTitle"></h2>
|
||||
<span id="activated_checkbox">
|
||||
<input type="checkbox" name="activated" value="1" />
|
||||
<label for="activated" style="display:inline;"><?php echo get_lang('ActivateEvent'); ?></label>
|
||||
</span>
|
||||
<br />
|
||||
<select id="languages" name="languages" style="margin-top:20px;" onclick='confirmMessage(this.name); return false;'>
|
||||
<?php foreach ($languages["name"] as $key => $value) {
|
||||
$english_name = $languages['folder'][$key]; ?>
|
||||
<option value="<?php echo $english_name; ?>" <?php echo ($english_name == api_get_interface_language()) ? "selected=selected" : ""; ?>>
|
||||
<?php echo $value; ?>
|
||||
</option>
|
||||
<?php
|
||||
} ?>
|
||||
</select>
|
||||
|
||||
<input type="hidden" name="action" value="modEventType" />
|
||||
<input type="hidden" name="eventId" id="eventId" />
|
||||
<input type="hidden" name="eventUsers" id="eventUsers" />
|
||||
<input type="hidden" id="eventName" value="<?php echo $event_name; ?>"/>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<label for="eventSubject">
|
||||
<h4><?php echo get_lang('Subject'); ?></h4>
|
||||
</label>
|
||||
<input class="col-md-6" type="text" id="eventSubject" name="eventSubject" onchange="contentChanged(); return false;" />
|
||||
<br /><br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="eventMessage"><h4><?php echo get_lang('Message'); ?></h4></label>
|
||||
</td>
|
||||
<td class="available_keys" style="padding-left: 30px;">
|
||||
<h4><?php echo get_lang('AvailableEventKeys'); ?></h4>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<textarea class="col-md-6" rows="10" name="eventMessage" id="eventMessage" onchange="contentChanged(); return false;">
|
||||
</textarea>
|
||||
</td>
|
||||
<td class="available_keys">
|
||||
<div id="keys" style="padding-left: 50px;"><ul></ul></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br /><br />
|
||||
<input class="btn btn-primary" type="submit" value="<?php echo get_lang('Save'); ?>" />
|
||||
|
||||
</form>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
3
main/admin/example.csv
Normal file
3
main/admin/example.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
LastName;FirstName;Email;UserName;Password;AuthSource;OfficialCode;PhoneNumber;Status;Courses
|
||||
Mcfly;Marty;marty@example.com;marty;secret;platform;12345678;001-123-456-789;user;COURSE1|COURSE2|COURSE3
|
||||
Brown;Emmert;drbrown@example.net;emmert;;platform;;;teacher;COURSE2
|
||||
|
27
main/admin/example.xml
Normal file
27
main/admin/example.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<Contacts>
|
||||
<Contact>
|
||||
<LastName>Mcfly</LastName>
|
||||
<FirstName>Marty</FirstName>
|
||||
<UserName>marty</UserName>
|
||||
<Password>secret</Password>
|
||||
<AuthSource>platform</AuthSource>
|
||||
<Email>marty@example.net</Email>
|
||||
<OfficialCode>12345678</OfficialCode>
|
||||
<PhoneNumber>001-123-456-789</PhoneNumber>
|
||||
<Status>user</Status>
|
||||
<Courses>COURSE1|COURSE2|COURSE3</Courses>
|
||||
</Contact>
|
||||
<Contact>
|
||||
<LastName>Brown</LastName>
|
||||
<FirstName>Emmett</FirstName>
|
||||
<UserName>emmett</UserName>
|
||||
<Password>secret</Password>
|
||||
<AuthSource>platform</AuthSource>
|
||||
<Email>drbrown@example.net</Email>
|
||||
<OfficialCode />
|
||||
<PhoneNumber />
|
||||
<Status>teacher</Status>
|
||||
<Courses>COURSE2</Courses>
|
||||
</Contact>
|
||||
</Contacts>
|
||||
3
main/admin/example_class.csv
Normal file
3
main/admin/example_class.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
name;description;
|
||||
Class A4;20 students in general courses
|
||||
Class B5;20 students from technical background
|
||||
|
3
main/admin/example_session.csv
Normal file
3
main/admin/example_session.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
SessionName;Coach;DateStart;DateEnd;Users;Courses
|
||||
Session1;jmontoya;2008/08/08;2020/12/12;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]
|
||||
Session2;jmontoya;2008/08/08;2020/12/12;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]
|
||||
|
38
main/admin/example_session.xml
Normal file
38
main/admin/example_session.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<Sessions>
|
||||
<Users>
|
||||
<User>
|
||||
<Username>jmontoya</Username>
|
||||
<Lastname>Montoya</Lastname>
|
||||
<Firstname>Julio</Firstname>
|
||||
<Password>secret</Password>
|
||||
<Email>example@example.com</Email>
|
||||
<OfficialCode>123</OfficialCode>
|
||||
<Phone>511-1234567</Phone>
|
||||
<Status>teacher</Status>
|
||||
</User>
|
||||
</Users>
|
||||
<Courses>
|
||||
<Course>
|
||||
<CourseCode>08011942</CourseCode>
|
||||
<CourseTeacher>Hawking</CourseTeacher>
|
||||
<CourseLanguage>English</CourseLanguage>
|
||||
<CourseTitle>Maths</CourseTitle>
|
||||
<CourseDescription>Wormholes</CourseDescription>
|
||||
</Course>
|
||||
</Courses>
|
||||
<Session>
|
||||
<SessionName>The Universe</SessionName>
|
||||
<Coach>Coach</Coach>
|
||||
<DateStart>2008/08/01</DateStart>
|
||||
<DateEnd>2020/12/12</DateEnd>
|
||||
<User>jmontoya</User>
|
||||
<User>jmontoya2</User>
|
||||
<Course>
|
||||
<CourseCode>08011942</CourseCode>
|
||||
<Coach>Hawking</Coach>
|
||||
<User>jmontoya</User>
|
||||
<User>jmontoya2</User>
|
||||
</Course>
|
||||
</Session>
|
||||
</Sessions>
|
||||
63
main/admin/export_certificates.php
Normal file
63
main/admin/export_certificates.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
Display::display_header(null);
|
||||
|
||||
$form = new FormValidator('export_certificate');
|
||||
$courses = CourseManager::get_courses_list(0, 0, 'title');
|
||||
$options = [];
|
||||
foreach ($courses as $course) {
|
||||
$options[$course['id']] = $course['title'];
|
||||
}
|
||||
$form->addElement('select', 'course', get_lang('Course'), $options);
|
||||
$form->addElement('file', 'file', get_lang('File'));
|
||||
$form->addButton('submit', get_lang('Submit'));
|
||||
$form->display();
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
if (isset($_FILES['file']['tmp_name']) &&
|
||||
!empty($_FILES['file']['tmp_name'])
|
||||
) {
|
||||
$users = Import::csv_reader($_FILES['file']['tmp_name']);
|
||||
$courseId = $values['course'];
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$courseCode = $courseInfo['code'];
|
||||
|
||||
$cats = Category::load(
|
||||
null,
|
||||
null,
|
||||
$courseCode,
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
false
|
||||
);
|
||||
|
||||
if (isset($cats[0])) {
|
||||
/** @var Category $cat */
|
||||
$userList = [];
|
||||
foreach ($users as $user) {
|
||||
$userInfo = api_get_user_info_from_official_code(
|
||||
$user['official_code']
|
||||
);
|
||||
if (!empty($userInfo)) {
|
||||
$userList[] = $userInfo;
|
||||
}
|
||||
}
|
||||
|
||||
Category::exportAllCertificates(
|
||||
$cat->get_id(),
|
||||
$userList
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
189
main/admin/export_exercise_results.php
Normal file
189
main/admin/export_exercise_results.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* This script exports the PDF reports from a test for several students at once.
|
||||
* This script has a teacher-focused version at main/exercise/export/export_exercise_result.php.
|
||||
*/
|
||||
$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);
|
||||
|
||||
$sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : null;
|
||||
$courseId = isset($_GET['selected_course']) ? (int) $_GET['selected_course'] : null;
|
||||
$exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null;
|
||||
$courseIdChanged = isset($_GET['course_id_changed']) ? (int) $_GET['course_id_changed'] : null;
|
||||
$exerciseIdChanged = isset($_GET['exercise_id_changed']) ? (int) $_GET['exercise_id_changed'] : null;
|
||||
|
||||
// Get the session list
|
||||
$sessionList = SessionManager::get_sessions_by_user(api_get_user_id(), api_is_platform_admin());
|
||||
|
||||
// Course list, get course list of session, or for course where user is admin
|
||||
$courseList = [];
|
||||
if (!empty($sessionId) && $sessionId != '-1' && !empty($sessionList)) {
|
||||
$sessionInfo = [];
|
||||
foreach ($sessionList as $session) {
|
||||
if ($session['session_id'] == $sessionId) {
|
||||
$sessionInfo = $session;
|
||||
}
|
||||
}
|
||||
$courseList = $sessionInfo['courses'];
|
||||
} else {
|
||||
if (api_is_platform_admin()) {
|
||||
$courseList = CourseManager::get_courses_list(0, 0, 'title');
|
||||
} else {
|
||||
$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
|
||||
}
|
||||
}
|
||||
|
||||
$courseInfo = [];
|
||||
if (empty($courseId)) {
|
||||
$exerciseId = 0;
|
||||
} else {
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$confirmYourChoice = addslashes(get_lang('ConfirmYourChoice'));
|
||||
$htmlHeadXtra[] = "
|
||||
<script>
|
||||
function submit_form(obj) {
|
||||
document.export_all_results_form.submit();
|
||||
}
|
||||
|
||||
function mark_course_id_changed() {
|
||||
$('#course_id_changed').val('0');
|
||||
}
|
||||
|
||||
function mark_exercise_id_changed() {
|
||||
$('#exercise_id_changed').val('0');
|
||||
}
|
||||
|
||||
function confirm_your_choice() {
|
||||
return confirm('$confirmYourChoice');
|
||||
}
|
||||
</script>";
|
||||
|
||||
$sessionSelectList = [0 => get_lang('Select')];
|
||||
foreach ($sessionList as $item) {
|
||||
$sessionSelectList[$item['session_id']] = $item['session_name'];
|
||||
}
|
||||
|
||||
$courseSelectList = [0 => get_lang('Select')];
|
||||
foreach ($courseList as $item) {
|
||||
$courseItemId = $item['real_id'];
|
||||
$courseInfo = api_get_course_info_by_id($courseItemId);
|
||||
$courseSelectList[$courseItemId] = '';
|
||||
if ($courseItemId == $courseId) {
|
||||
$courseSelectList[$courseItemId] = '> ';
|
||||
}
|
||||
$courseSelectList[$courseItemId] = $courseInfo['title'];
|
||||
}
|
||||
|
||||
// If course has changed, reset the menu default
|
||||
if (!empty($courseSelectList) && !in_array($courseId, array_keys($courseSelectList))) {
|
||||
$courseId = 0;
|
||||
}
|
||||
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
|
||||
// Get exercise list for this course
|
||||
$exerciseList = ExerciseLib::get_all_exercises_for_course_id(
|
||||
$courseInfo,
|
||||
$sessionId,
|
||||
$courseId,
|
||||
false
|
||||
);
|
||||
|
||||
$exerciseSelectList = [];
|
||||
$exerciseSelectList = [0 => get_lang('Select')];
|
||||
if (is_array($exerciseList)) {
|
||||
foreach ($exerciseList as $row) {
|
||||
$exerciseTitle = $row['title'];
|
||||
$exerciseSelectList[$row['iid']] = $exerciseTitle;
|
||||
}
|
||||
}
|
||||
|
||||
$url = api_get_self().'?'.api_get_cidreq().'&'.http_build_query(
|
||||
[
|
||||
'session_id' => $sessionId,
|
||||
'selected_course' => $courseId,
|
||||
'exerciseId' => $exerciseId,
|
||||
'course_id_changed' => $courseIdChanged,
|
||||
'exercise_id_changed' => $exerciseIdChanged,
|
||||
]
|
||||
);
|
||||
|
||||
// Form
|
||||
$form = new FormValidator('export_all_results_form', 'GET', $url);
|
||||
$form->addHeader(get_lang('ExportExerciseAllResults'));
|
||||
$form
|
||||
->addSelect(
|
||||
'session_id',
|
||||
get_lang('Session'),
|
||||
$sessionSelectList,
|
||||
['onchange' => 'submit_form(this)', 'id' => 'session_id']
|
||||
)
|
||||
->setSelected($sessionId);
|
||||
$form
|
||||
->addSelect(
|
||||
'selected_course',
|
||||
get_lang('Course'),
|
||||
$courseSelectList,
|
||||
['onchange' => 'mark_course_id_changed(); submit_form(this);', 'id' => 'selected_course']
|
||||
)
|
||||
->setSelected($courseId);
|
||||
$form
|
||||
->addSelect(
|
||||
'exerciseId',
|
||||
get_lang('Exercise'),
|
||||
$exerciseSelectList
|
||||
)
|
||||
->setSelected($exerciseId);
|
||||
|
||||
$form->addDateTimePicker('start_date', get_lang('StartDate'));
|
||||
$form->addDateTimePicker('end_date', get_lang('EndDate'));
|
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'datetime');
|
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'datetime');
|
||||
|
||||
$form->addRule(
|
||||
['start_date', 'end_date'],
|
||||
get_lang('StartDateShouldBeBeforeEndDate'),
|
||||
'date_compare',
|
||||
'lte'
|
||||
);
|
||||
|
||||
$form->addHidden('course_id_changed', '0');
|
||||
$form->addHidden('exercise_id_changed', '0');
|
||||
$form->addButtonExport(get_lang('Export'), 'name');
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
|
||||
if (!empty($values['exerciseId']) && !empty($values['selected_course'])) {
|
||||
$sessionId = (int) $values['session_id'];
|
||||
$courseId = (int) $values['selected_course'];
|
||||
$exerciseId = (int) $values['exerciseId'];
|
||||
$filterDates = [
|
||||
'start_date' => (!empty($values['start_date']) ? $values['start_date'] : ''),
|
||||
'end_date' => (!empty($values['end_date']) ? $values['end_date'] : ''),
|
||||
];
|
||||
ExerciseLib::exportExerciseAllResultsZip($sessionId, $courseId, $exerciseId, $filterDates);
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header(get_lang('ExportExerciseAllResults'));
|
||||
|
||||
echo Display::return_message(
|
||||
get_lang('PleaseWaitThisCouldTakeAWhile'),
|
||||
'normal',
|
||||
false
|
||||
);
|
||||
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
35
main/admin/extra_field_list.php
Normal file
35
main/admin/extra_field_list.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_global_admin_script();
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$template = new Template(get_lang('ExtraFields'));
|
||||
|
||||
$types = ExtraField::getValidExtraFieldTypes();
|
||||
|
||||
$table = new HTML_Table(['class' => 'table']);
|
||||
$table->setHeaderContents(0, 0, get_lang('Type'));
|
||||
$table->setHeaderContents(0, 1, get_lang('Actions'));
|
||||
$url = api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=';
|
||||
$row = 1;
|
||||
foreach ($types as $key => $label) {
|
||||
$table->setCellContents($row, 0, $label);
|
||||
$table->setCellContents(
|
||||
$row,
|
||||
1,
|
||||
Display::url(
|
||||
get_lang('List'),
|
||||
$url.''.$label,
|
||||
['class' => 'btn btn-default']
|
||||
)
|
||||
);
|
||||
$row++;
|
||||
}
|
||||
|
||||
$content = $table->toHtml();
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
207
main/admin/extra_field_options.php
Normal file
207
main/admin/extra_field_options.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
//Add the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$tool_name = null;
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
$field_id = isset($_GET['field_id']) ? $_GET['field_id'] : null;
|
||||
|
||||
if (empty($field_id)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
if (!in_array($type, ExtraField::getValidExtraFieldTypes())) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$extra_field = new ExtraField($type);
|
||||
$extra_field_info = $extra_field->get($field_id);
|
||||
|
||||
$check = Security::check_token('request');
|
||||
$token = Security::get_token();
|
||||
|
||||
if ($action == 'add') {
|
||||
$interbreadcrumb[] = ['url' => 'extra_fields.php?type='.$extra_field->type, 'name' => $extra_field->pageName];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],
|
||||
'name' => $extra_field_info['display_text'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'],
|
||||
'name' => get_lang('EditExtraFieldOptions'),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
|
||||
} elseif ($action == 'edit') {
|
||||
$interbreadcrumb[] = ['url' => 'extra_fields.php?type='.$extra_field->type, 'name' => $extra_field->pageName];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],
|
||||
'name' => $extra_field_info['display_text'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'],
|
||||
'name' => get_lang('EditExtraFieldOptions'),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
|
||||
} else {
|
||||
$interbreadcrumb[] = ['url' => 'extra_fields.php?type='.$extra_field->type, 'name' => $extra_field->pageName];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],
|
||||
'name' => $extra_field_info['display_text'],
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('EditExtraFieldOptions')];
|
||||
}
|
||||
|
||||
//jqgrid will use this URL to do the selects
|
||||
$params = 'field_id='.$field_id.'&type='.$extra_field->type;
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_field_options&'.$params;
|
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file
|
||||
$columns = [
|
||||
get_lang('Name'),
|
||||
get_lang('Value'),
|
||||
get_lang('Order'),
|
||||
get_lang('Actions'),
|
||||
];
|
||||
|
||||
//Column config
|
||||
$column_model = [
|
||||
[
|
||||
'name' => 'display_text',
|
||||
'index' => 'display_text',
|
||||
'width' => '180',
|
||||
'align' => 'left',
|
||||
],
|
||||
[
|
||||
'name' => 'option_value',
|
||||
'index' => 'option_value',
|
||||
'width' => '',
|
||||
'align' => 'left',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
[
|
||||
'name' => 'option_order',
|
||||
'index' => 'option_order',
|
||||
'width' => '',
|
||||
'align' => 'left',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
[
|
||||
'name' => 'actions',
|
||||
'index' => 'actions',
|
||||
'width' => '100',
|
||||
'align' => 'left',
|
||||
'formatter' => 'action_formatter',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
];
|
||||
|
||||
//Autowidth
|
||||
$extra_params['autowidth'] = 'true';
|
||||
//height auto
|
||||
$extra_params['height'] = 'auto';
|
||||
|
||||
//With this function we can add actions to the jgrid (edit, delete, etc)
|
||||
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
|
||||
return \'<a href="?action=edit&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
'\';
|
||||
}';
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
// grid definition see the $obj->display() function
|
||||
'.Display::grid_js(
|
||||
'extra_field_options',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
$action_links,
|
||||
true
|
||||
).'
|
||||
});
|
||||
</script>';
|
||||
|
||||
Display::display_header($tool_name);
|
||||
echo Display::page_header($extra_field_info['display_text'], $extra_field_info['variable'], 'h1');
|
||||
|
||||
$obj = new ExtraFieldOption($extra_field->type);
|
||||
$obj->fieldId = $field_id;
|
||||
|
||||
// Action handling: Add
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.$params;
|
||||
$form = $obj->return_form($url, 'add');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
if ($check) {
|
||||
$values = $form->exportValues();
|
||||
$res = $obj->save_one_item($values);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
|
||||
}
|
||||
}
|
||||
$obj->display();
|
||||
} else {
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
// Action handling: Editing
|
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']).'&'.$params;
|
||||
$form = $obj->return_form($url, 'edit');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
if ($check) {
|
||||
$values = $form->exportValues();
|
||||
$res = $obj->update($values);
|
||||
echo Display::return_message(
|
||||
sprintf(get_lang('ItemUpdated'), $values['display_text']),
|
||||
'confirmation',
|
||||
false
|
||||
);
|
||||
}
|
||||
$obj->display();
|
||||
} else {
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
// Action handling: delete
|
||||
if ($check) {
|
||||
$res = $obj->delete($_GET['id']);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('ItemDeleted'), 'confirmation');
|
||||
}
|
||||
}
|
||||
$obj->display();
|
||||
break;
|
||||
default:
|
||||
$obj->display();
|
||||
break;
|
||||
}
|
||||
Display::display_footer();
|
||||
265
main/admin/extra_field_workflow.php
Normal file
265
main/admin/extra_field_workflow.php
Normal file
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\ExtraFieldOptionRelFieldOption;
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$tool_name = null;
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
$field_id = isset($_GET['field_id']) ? (int) $_GET['field_id'] : null;
|
||||
|
||||
if (empty($field_id)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
if (!in_array($type, ExtraField::getValidExtraFieldTypes())) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$extraField = new ExtraField($type);
|
||||
$extraFieldInfo = $extraField->get($field_id);
|
||||
|
||||
$check = Security::check_token('request');
|
||||
$token = Security::get_token();
|
||||
|
||||
if ($action == 'add') {
|
||||
$interbreadcrumb[] = ['url' => 'extra_fields.php?type='.$extraField->type, 'name' => $extraField->pageName];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extraField->type.'&action=edit&id='.$extraFieldInfo['id'],
|
||||
'name' => $extraFieldInfo['display_text'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_field_options.php?type='.$extraField->type.'&field_id='.$extraFieldInfo['id'],
|
||||
'name' => get_lang('EditExtraFieldOptions'),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
|
||||
} elseif ($action == 'edit') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extraField->type,
|
||||
'name' => $extraField->pageName,
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extraField->type.'&action=edit&id='.$extraFieldInfo['id'],
|
||||
'name' => $extraFieldInfo['display_text'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_field_options.php?type='.$extraField->type.'&field_id='.$extraFieldInfo['id'],
|
||||
'name' => get_lang('EditExtraFieldOptions'),
|
||||
];
|
||||
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extraField->type,
|
||||
'name' => $extraField->pageName,
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'extra_fields.php?type='.$extraField->type.'&action=edit&id='.$extraFieldInfo['id'],
|
||||
'name' => $extraFieldInfo['display_text'],
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '#',
|
||||
'name' => get_lang('EditExtraFieldOptions'),
|
||||
];
|
||||
}
|
||||
|
||||
$roleId = isset($_REQUEST['roleId']) ? (int) $_REQUEST['roleId'] : null;
|
||||
|
||||
//jqgrid will use this URL to do the selects
|
||||
$params = 'field_id='.$field_id.'&type='.$extraField->type.'&roleId='.$roleId;
|
||||
$paramsNoRole = 'field_id='.$field_id.'&type='.$extraField->type;
|
||||
|
||||
// The order is important you need to check the the $column variable in the model.ajax.php file
|
||||
$columns = [get_lang('Name'), get_lang('Value'), get_lang('Order'), get_lang('Actions')];
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function setHidden(obj) {
|
||||
var name = $(obj).attr("name");
|
||||
var hiddenName = "hidden_" + name;
|
||||
if ($("#" + hiddenName).attr("value") == 1) {
|
||||
$("#" + hiddenName).attr("value", 0);
|
||||
} else {
|
||||
$("#" + hiddenName).attr("value", 1);
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$("#workflow_status").on("change", function() {
|
||||
var roleId = $(this).find(":selected").val();
|
||||
if (roleId != 0) {
|
||||
window.location.replace("'.api_get_self().'?'.$paramsNoRole.'&roleId="+roleId);
|
||||
}
|
||||
});
|
||||
|
||||
$("[name=select_all]").on("click", function() {
|
||||
$("#workflow :checkbox").prop("checked", 1);
|
||||
$("#workflow :hidden").prop("value", 1);
|
||||
return false;
|
||||
});
|
||||
|
||||
$("[name=unselect_all]").on("click", function() {
|
||||
$("#workflow :checkbox").prop("checked", 0);
|
||||
$("#workflow :hidden").prop("value", 0);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$obj = new ExtraFieldOption($type);
|
||||
$columns = ['display_text', 'option_value', 'option_order'];
|
||||
$result = Database::select(
|
||||
'*',
|
||||
$obj->table,
|
||||
[
|
||||
'where' => ['field_id = ? ' => $field_id],
|
||||
'order' => 'option_order ASC',
|
||||
]
|
||||
);
|
||||
|
||||
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
|
||||
$column = 0;
|
||||
$row = 0;
|
||||
$table->setHeaderContents($row, $column, get_lang('CurrentStatus'));
|
||||
$column++;
|
||||
foreach ($result as $item) {
|
||||
$table->setHeaderContents($row, $column, $item['display_text']);
|
||||
$column++;
|
||||
}
|
||||
$row++;
|
||||
|
||||
$form = new FormValidator('workflow', 'post', api_get_self().'?'.$params);
|
||||
//$options = api_get_user_roles();
|
||||
$options[0] = get_lang('SelectAnOption');
|
||||
$options[STUDENT] = get_lang('Student');
|
||||
$options[COURSEMANAGER] = get_lang('Teacher');
|
||||
|
||||
ksort($options);
|
||||
$form->addElement('select', 'status', get_lang('SelectRole'), $options);
|
||||
|
||||
$em = Database::getManager();
|
||||
$repo = $em->getRepository('ChamiloCoreBundle:ExtraFieldOptionRelFieldOption');
|
||||
|
||||
$checks = $repo->findBy(
|
||||
['fieldId' => $field_id, 'roleId' => $roleId]
|
||||
);
|
||||
$includedFields = [];
|
||||
if (!empty($checks)) {
|
||||
foreach ($checks as $availableField) {
|
||||
$includedFields[$availableField->getFieldOptionId()][] = $availableField->getRelatedFieldOptionId();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($result as $item) {
|
||||
$column = 0;
|
||||
$table->setCellContents($row, $column, $item['display_text']);
|
||||
$column++;
|
||||
$value = null;
|
||||
|
||||
foreach ($result as $itemCol) {
|
||||
$id = 'extra_field_status_'.$item['id'].'_'.$itemCol['id'];
|
||||
$idForm = 'extra_field_status['.$item['id'].']['.$itemCol['id'].']';
|
||||
$attributes = ['onclick' => 'setHidden(this)'];
|
||||
$value = 0;
|
||||
|
||||
if (isset($includedFields[$itemCol['id']]) && in_array($item['id'], $includedFields[$itemCol['id']])) {
|
||||
$value = 1;
|
||||
$attributes['checked'] = 'checked';
|
||||
}
|
||||
|
||||
$element = Display::input('checkbox', $id, null, $attributes);
|
||||
$table->setCellContents($row, $column, $element);
|
||||
$form->addElement('hidden', 'hidden_'.$idForm, $value, ['id' => 'hidden_'.$id]);
|
||||
$column++;
|
||||
}
|
||||
$row++;
|
||||
}
|
||||
|
||||
if (!empty($roleId)) {
|
||||
$form->addElement('html', $table->toHtml());
|
||||
$group = [];
|
||||
$group[] = $form->addButtonSave(get_lang('Save'), 'submit', true);
|
||||
$group[] = $form->addButton(
|
||||
'select_all',
|
||||
get_lang('SelectAll'),
|
||||
'check',
|
||||
'default',
|
||||
'default',
|
||||
null,
|
||||
[],
|
||||
true
|
||||
);
|
||||
$group[] = $form->addButton(
|
||||
'unselect_all',
|
||||
get_lang('UnSelectAll'),
|
||||
'check',
|
||||
'default',
|
||||
'default',
|
||||
null,
|
||||
[],
|
||||
true
|
||||
);
|
||||
|
||||
$form->addGroup($group, '', null, ' ');
|
||||
$form->setDefaults(['status' => $roleId]);
|
||||
} else {
|
||||
$form->addButtonUpdate(get_lang('Edit'));
|
||||
}
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
$result = $values['hidden_extra_field_status'];
|
||||
|
||||
if (!empty($result)) {
|
||||
foreach ($result as $id => $items) {
|
||||
foreach ($items as $subItemId => $value) {
|
||||
$extraFieldOptionRelFieldOption = $repo->findOneBy(
|
||||
[
|
||||
'fieldId' => $field_id,
|
||||
'fieldOptionId' => $subItemId,
|
||||
'roleId' => $roleId,
|
||||
'relatedFieldOptionId' => $id,
|
||||
]
|
||||
);
|
||||
|
||||
if ($value == 1) {
|
||||
if (empty($extraFieldOptionRelFieldOption)) {
|
||||
$extraFieldOptionRelFieldOption = new ExtraFieldOptionRelFieldOption();
|
||||
$extraFieldOptionRelFieldOption
|
||||
->setFieldId($field_id)
|
||||
->setFieldOptionId($subItemId)
|
||||
->setRelatedFieldOptionId($id)
|
||||
->setRoleId($roleId)
|
||||
;
|
||||
|
||||
$em->persist($extraFieldOptionRelFieldOption);
|
||||
}
|
||||
} else {
|
||||
if ($extraFieldOptionRelFieldOption) {
|
||||
$em->remove($extraFieldOptionRelFieldOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$em->flush();
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location:'.api_get_self().'?'.$params);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
echo Display::page_header($extraFieldInfo['display_text']);
|
||||
$form->display();
|
||||
|
||||
Display::display_footer();
|
||||
176
main/admin/extra_fields.php
Normal file
176
main/admin/extra_fields.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$extraFieldType = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
//Add the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$tool_name = null;
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
if (!in_array($extraFieldType, ExtraField::getValidExtraFieldTypes())) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$check = Security::check_token('request');
|
||||
$token = Security::get_token();
|
||||
|
||||
$obj = new ExtraField($extraFieldType);
|
||||
|
||||
$obj->setupBreadcrumb($interbreadcrumb, $action);
|
||||
|
||||
//jqgrid will use this URL to do the selects
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_fields&type='.$extraFieldType;
|
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file
|
||||
$columns = $obj->getJqgridColumnNames();
|
||||
|
||||
//Column config
|
||||
$column_model = $obj->getJqgridColumnModel();
|
||||
|
||||
//Autowidth
|
||||
$extra_params['autowidth'] = 'true';
|
||||
//height auto
|
||||
$extra_params['height'] = 'auto';
|
||||
$extra_params['sortname'] = 'field_order';
|
||||
|
||||
$action_links = $obj->getJqgridActionLinks($token);
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
// grid definition see the $obj->display() function
|
||||
'.Display::grid_js(
|
||||
$obj->type.'_fields',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
$action_links,
|
||||
true
|
||||
).'
|
||||
|
||||
$("#field_type").on("change", function() {
|
||||
id = $(this).val();
|
||||
switch(id) {
|
||||
case "1":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_text.png')).'");
|
||||
break;
|
||||
case "2":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_text_area.png')).'");
|
||||
break;
|
||||
case "3":
|
||||
$("#example").html("'.addslashes(Display::return_icon('add_user_field_howto.png')).'");
|
||||
break;
|
||||
case "4":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_drop_down.png')).'");
|
||||
break;
|
||||
case "5":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_multidropdown.png')).'");
|
||||
break;
|
||||
case "6":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
|
||||
break;
|
||||
case "7":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_date_time.png')).'");
|
||||
break;
|
||||
case "8":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_doubleselect.png')).'");
|
||||
break;
|
||||
case "9":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_divider.png')).'");
|
||||
break;
|
||||
case "10":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_user_tag.png')).'");
|
||||
break;
|
||||
case "11":
|
||||
$("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
// The header.
|
||||
Display::display_header($tool_name);
|
||||
|
||||
// Action handling: Add
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
if (api_get_session_id() != 0 &&
|
||||
!api_is_allowed_to_session_edit(false, true)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']);
|
||||
$form = $obj->return_form($url, 'add');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
unset($values['id']);
|
||||
$res = $obj->save($values);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
|
||||
}
|
||||
$obj->display();
|
||||
} else {
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="'.api_get_self().'?type='.$obj->type.'">'.
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
// Action handling: Editing
|
||||
$url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
|
||||
$form = $obj->return_form($url, 'edit');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$res = $obj->update($values);
|
||||
echo Display::return_message(
|
||||
sprintf(get_lang('ItemUpdated'), $values['variable']),
|
||||
'confirmation',
|
||||
false
|
||||
);
|
||||
$obj->display();
|
||||
} else {
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="'.api_get_self().'?type='.$obj->type.'">'.
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
echo '</div>';
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
// Action handling: delete
|
||||
$res = $obj->delete($_GET['id']);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('ItemDeleted'), 'confirmation');
|
||||
}
|
||||
$obj->display();
|
||||
break;
|
||||
default:
|
||||
$obj->display();
|
||||
break;
|
||||
}
|
||||
Display::display_footer();
|
||||
91
main/admin/filler.php
Normal file
91
main/admin/filler.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Index of the admin tools.
|
||||
*/
|
||||
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
|
||||
// including some necessary chamilo files
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$nameTools = get_lang('PlatformAdmin');
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => $nameTools];
|
||||
|
||||
// setting the name of the tool
|
||||
$nameTools = get_lang('DataFiller');
|
||||
|
||||
$output = [];
|
||||
if (!empty($_GET['fill'])) {
|
||||
switch ($_GET['fill']) {
|
||||
case 'users':
|
||||
require api_get_path(SYS_TEST_PATH).'datafiller/fill_users.php';
|
||||
$output = fill_users();
|
||||
break;
|
||||
case 'courses':
|
||||
require api_get_path(SYS_TEST_PATH).'datafiller/fill_courses.php';
|
||||
$output = fill_courses();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Displaying the header
|
||||
Display::display_header($nameTools);
|
||||
|
||||
$result = '';
|
||||
if (count($output) > 0) {
|
||||
$result = '<div class="filler-report">'."\n";
|
||||
$result .= '<h3>'.$output[0]['title'].'</h3>'."\n";
|
||||
$result .= '<table>';
|
||||
foreach ($output as $line) {
|
||||
$result .= '<tr>';
|
||||
$result .= '<td class="filler-report-data-init">'.$line['line-init'].' </td>
|
||||
<td class="filler-report-data">'.$line['line-info'].'</td>';
|
||||
$result .= '</tr>';
|
||||
}
|
||||
$result .= '</table>';
|
||||
$result .= '</div>';
|
||||
echo Display::return_message($result, 'normal', false);
|
||||
}
|
||||
?>
|
||||
<div id="datafiller" class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<h4><?php
|
||||
echo Display::return_icon('bug.png', get_lang('DataFiller'), null, ICON_SIZE_MEDIUM).' '.get_lang('DataFiller');
|
||||
?>
|
||||
</h4>
|
||||
<div class="description"><?php echo get_lang('ThisSectionIsOnlyVisibleOnSourceInstalls'); ?></div>
|
||||
<ul class="fillers">
|
||||
<li>
|
||||
<a href="filler.php?fill=users">
|
||||
<?php
|
||||
echo Display::return_icon('user.png', get_lang('FillUsers'), null, ICON_SIZE_SMALL).
|
||||
' '.get_lang('FillUsers');
|
||||
?>
|
||||
</a></li>
|
||||
<li>
|
||||
<a href="filler.php?fill=courses">
|
||||
<?php
|
||||
echo Display::return_icon('new-course.png', get_lang('FillCourses'), null, ICON_SIZE_SMALL).
|
||||
' '.get_lang('FillCourses');
|
||||
?>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
/* FOOTER */
|
||||
Display::display_footer();
|
||||
207
main/admin/grade_models.php
Normal file
207
main/admin/grade_models.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?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();
|
||||
|
||||
if (api_get_setting('gradebook_enable_grade_model') !== 'true') {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Add the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
|
||||
$check = Security::check_token('request');
|
||||
$token = Security::get_token();
|
||||
|
||||
if ($action === 'add') {
|
||||
$interbreadcrumb[] = ['url' => 'grade_models.php', 'name' => get_lang('GradeModel')];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
|
||||
} elseif ($action === 'edit') {
|
||||
$interbreadcrumb[] = ['url' => 'grade_models.php', 'name' => get_lang('GradeModel')];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
|
||||
} else {
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('GradeModel')];
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
function plusItem(item) {
|
||||
if (item != 1) {
|
||||
document.getElementById(item).style.display = "inline";
|
||||
document.getElementById("plus-"+item).style.display = "none";
|
||||
document.getElementById("min-"+(item-1)).style.display = "none";
|
||||
document.getElementById("min-"+(item)).style.display = "inline";
|
||||
document.getElementById("plus-"+(item+1)).style.display = "inline";
|
||||
//document.getElementById("txta-"+(item)).value = "100";
|
||||
//document.getElementById("txta-"+(item-1)).value = "";
|
||||
$("input").removeClass("form-control");
|
||||
}
|
||||
}
|
||||
|
||||
function minItem(item) {
|
||||
if (item != 1) {
|
||||
document.getElementById(item).style.display = "none";
|
||||
document.getElementById("plus-"+item).style.display = "inline";
|
||||
document.getElementById("min-"+(item-1)).style.display = "inline";
|
||||
$("input").removeClass("form-control");
|
||||
}
|
||||
if (item = 1) {
|
||||
document.getElementById("min-"+(item)).style.display = "none";
|
||||
$("input").removeClass("form-control");
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
|
||||
Display::display_header();
|
||||
|
||||
// jqgrid will use this URL to do the selects
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_grade_models';
|
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file
|
||||
$columns = [
|
||||
get_lang('Name'),
|
||||
get_lang('Description'),
|
||||
get_lang('Actions'),
|
||||
];
|
||||
|
||||
//Column config
|
||||
$column_model = [
|
||||
[
|
||||
'name' => 'name',
|
||||
'index' => 'name',
|
||||
'width' => '80',
|
||||
'align' => 'left',
|
||||
],
|
||||
[
|
||||
'name' => 'description',
|
||||
'index' => 'description',
|
||||
'width' => '500',
|
||||
'align' => 'left',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
[
|
||||
'name' => 'actions',
|
||||
'index' => 'actions',
|
||||
'width' => '100',
|
||||
'align' => 'left',
|
||||
'formatter' => 'action_formatter',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
];
|
||||
|
||||
//Autowidth
|
||||
$extra_params['autowidth'] = 'true';
|
||||
//height auto
|
||||
$extra_params['height'] = 'auto';
|
||||
|
||||
//With this function we can add actions to the jgrid (edit, delete, etc)
|
||||
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
|
||||
return \'<a href="?action=edit&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="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
'\';
|
||||
}';
|
||||
?>
|
||||
<script>
|
||||
$(function() {
|
||||
<?php
|
||||
// grid definition see the $obj->display() function
|
||||
echo Display::grid_js(
|
||||
'grade_model',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
$action_links,
|
||||
true
|
||||
);
|
||||
?>
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
$obj = new GradeModel();
|
||||
|
||||
// Action handling: Add
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
|
||||
$form = $obj->return_form($url, 'add');
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
if ($check) {
|
||||
$values = $form->exportValues();
|
||||
$res = $obj->save($values);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('ItemAdded'), 'confirm');
|
||||
}
|
||||
}
|
||||
$obj->display();
|
||||
} else {
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="'.api_get_self().'">'.
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).
|
||||
'</a>';
|
||||
echo '</div>';
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
// Action handling: Editing
|
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
|
||||
$form = $obj->return_form($url, 'edit');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
if ($check) {
|
||||
$values = $form->exportValues();
|
||||
$res = $obj->update($values);
|
||||
echo Display::return_message(get_lang('ItemUpdated'), 'confirm', false);
|
||||
}
|
||||
$obj->display();
|
||||
} else {
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="'.api_get_self().'">'.
|
||||
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).
|
||||
'</a>';
|
||||
echo '</div>';
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
// Action handling: delete
|
||||
if ($check) {
|
||||
$res = $obj->delete($_GET['id']);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('ItemDeleted'), 'confirm');
|
||||
}
|
||||
}
|
||||
$obj->display();
|
||||
break;
|
||||
default:
|
||||
$obj->display();
|
||||
break;
|
||||
}
|
||||
echo '<script>
|
||||
$(function () {
|
||||
$("input").removeClass("form-control");
|
||||
});
|
||||
</script>';
|
||||
Display::display_footer();
|
||||
194
main/admin/gradebook_dependency.php
Normal file
194
main/admin/gradebook_dependency.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\GradebookCategory;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$allow = api_get_configuration_value('gradebook_dependency');
|
||||
if (false == $allow) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$categoryId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 1;
|
||||
|
||||
$em = Database::getManager();
|
||||
$repo = $em->getRepository('ChamiloCoreBundle:GradebookCategory');
|
||||
/** @var GradebookCategory $category */
|
||||
$category = $repo->find($categoryId);
|
||||
if (!$category) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$categoryObj = Category::load($categoryId);
|
||||
/** @var Category $categoryObj */
|
||||
$categoryObj = $categoryObj[0];
|
||||
$dependencies = $categoryObj->getCourseListDependency();
|
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
|
||||
|
||||
$currentUrl = api_get_self().'?';
|
||||
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/gradebook_list.php',
|
||||
'name' => get_lang('Gradebook'),
|
||||
];
|
||||
|
||||
$tpl = new Template(get_lang('CourseList'));
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon('back.png', get_lang('Add'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/gradebook_list.php'
|
||||
);
|
||||
|
||||
if (empty($dependencies)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('ThisGradebookDoesntHaveDependencies'))
|
||||
);
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$courseList = [];
|
||||
$mandatoryList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
|
||||
$mandatoryList = isset($mandatoryList['courses']) ? $mandatoryList['courses'] : [];
|
||||
$mandatoryListCompleteList = [];
|
||||
foreach ($mandatoryList as $courseMandatoryId) {
|
||||
$mandatoryListCompleteList[] = api_get_course_info_by_id($courseMandatoryId);
|
||||
}
|
||||
$totalDependencies = count($dependencies);
|
||||
$min = $categoryObj->getMinimumToValidate();
|
||||
$gradeBooksToValidateInDependence = $categoryObj->getGradeBooksToValidateInDependence();
|
||||
$userResult = [];
|
||||
|
||||
$dependencyList = [];
|
||||
foreach ($dependencies as $courseId) {
|
||||
$dependencyList[$courseId] = api_get_course_info_by_id($courseId);
|
||||
}
|
||||
$courseUserLoaded = [];
|
||||
|
||||
foreach ($dependencyList as $courseId => $courseInfo) {
|
||||
$courseCode = $courseInfo['code'];
|
||||
$subCategory = Category::load(null, null, $courseCode);
|
||||
/** @var Category $subCategory */
|
||||
$subCategory = $subCategory ? $subCategory[0] : [];
|
||||
if (empty($subCategory)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$userList = CourseManager::get_student_list_from_course_code($courseCode);
|
||||
foreach ($userList as $user) {
|
||||
$userId = $user['user_id'];
|
||||
$userInfo = api_get_user_info($userId);
|
||||
$courseId = $courseInfo['real_id'];
|
||||
|
||||
$userCourseList = CourseManager::get_courses_list_by_user_id(
|
||||
$userId,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
[],
|
||||
false
|
||||
);
|
||||
$userCourseListCode = array_column($userCourseList, 'code');
|
||||
|
||||
if (!isset($userResult[$userId]['result_mandatory_20'])) {
|
||||
$userResult[$userId]['result_mandatory_20'] = 0;
|
||||
}
|
||||
if (!isset($userResult[$userId]['result_not_mandatory_80'])) {
|
||||
$userResult[$userId]['result_not_mandatory_80'] = 0;
|
||||
}
|
||||
|
||||
foreach ($userCourseList as $courseItem) {
|
||||
$myCourseCode = $courseItem['code'];
|
||||
$myCourseId = $courseItem['real_id'];
|
||||
if (in_array($myCourseId, $dependencies)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($courseUserLoaded[$userId][$myCourseId])) {
|
||||
continue;
|
||||
} else {
|
||||
$courseUserLoaded[$userId][$myCourseId] = true;
|
||||
}
|
||||
|
||||
$courseCategory = Category::load(
|
||||
null,
|
||||
null,
|
||||
$myCourseCode
|
||||
);
|
||||
$courseCategory = isset($courseCategory[0]) ? $courseCategory[0] : [];
|
||||
$userResult[$userId]['result_out_dependencies'][$myCourseCode] = false;
|
||||
if (!empty($courseCategory)) {
|
||||
$result = Category::userFinishedCourse(
|
||||
$userId,
|
||||
$courseCategory,
|
||||
true
|
||||
);
|
||||
$userResult[$userId]['result_out_dependencies'][$myCourseCode] = $result;
|
||||
|
||||
if (in_array($myCourseId, $mandatoryList)) {
|
||||
if ($userResult[$userId]['result_mandatory_20'] < 20 && $result) {
|
||||
$userResult[$userId]['result_mandatory_20'] += 10;
|
||||
}
|
||||
} else {
|
||||
if ($userResult[$userId]['result_not_mandatory_80'] < 80 && $result) {
|
||||
$userResult[$userId]['result_not_mandatory_80'] += 10;
|
||||
// var_dump($userResult[$userId]['result_80'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = Category::userFinishedCourse(
|
||||
$userId,
|
||||
$subCategory,
|
||||
true
|
||||
);
|
||||
|
||||
$userResult[$userId]['result_dependencies'][$courseCode] = $result;
|
||||
$userResult[$userId]['user_info'] = $userInfo;
|
||||
|
||||
if (in_array($courseId, $mandatoryList)) {
|
||||
if ($userResult[$userId]['result_mandatory_20'] < 20 && $result) {
|
||||
$userResult[$userId]['result_mandatory_20'] += 10;
|
||||
}
|
||||
} else {
|
||||
if ($userResult[$userId]['result_not_mandatory_80'] < 80 && $result) {
|
||||
$userResult[$userId]['result_not_mandatory_80'] += 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
$courseList[] = $courseInfo;
|
||||
}
|
||||
|
||||
foreach ($userResult as $userId => &$userData) {
|
||||
$courseListPassedOutDependency = count(array_filter($userData['result_out_dependencies']));
|
||||
$courseListPassedDependency = count(array_filter($userData['result_dependencies']));
|
||||
$total = $courseListPassedDependency + $courseListPassedOutDependency;
|
||||
$userData['course_list_passed_out_dependency'] = $courseListPassedOutDependency;
|
||||
$userData['course_list_passed_out_dependency_count'] = count($userData['result_out_dependencies']);
|
||||
// Min req must apply + mandatory should be 20
|
||||
//$userData['final_result'] = $total >= $min && $userData['result_mandatory_20'] == 20;
|
||||
//$userData['final_result'] = $total >= $min && $courseListPassedDependency == $totalDependencies;
|
||||
$userData['final_result'] = $total >= $min && $courseListPassedDependency >= $gradeBooksToValidateInDependence;
|
||||
}
|
||||
|
||||
$tpl->assign('current_url', $currentUrl);
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction(
|
||||
'toolbar',
|
||||
[$toolbar],
|
||||
[1, 4]
|
||||
)
|
||||
);
|
||||
|
||||
$tpl->assign('mandatory_courses', $mandatoryListCompleteList);
|
||||
$tpl->assign('min_to_validate', $min);
|
||||
$tpl->assign('gradebook_category', $category);
|
||||
$tpl->assign('courses', $courseList);
|
||||
$tpl->assign('users', $userResult);
|
||||
$layout = $tpl->get_template('admin/gradebook_dependency.tpl');
|
||||
$tpl->display($layout);
|
||||
316
main/admin/gradebook_list.php
Normal file
316
main/admin/gradebook_list.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\GradebookCategory;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Knp\Component\Pager\Paginator;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$allow = api_get_configuration_value('gradebook_dependency');
|
||||
if (false == $allow) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$em = Database::getManager();
|
||||
$repo = $em->getRepository('ChamiloCoreBundle:GradebookCategory');
|
||||
|
||||
$maxItems = 20;
|
||||
|
||||
$page = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 1;
|
||||
$categoryId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 1;
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
|
||||
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
|
||||
|
||||
if (empty($keyword)) {
|
||||
$gradeBookList = $repo->findAll();
|
||||
} else {
|
||||
$criteria = new Criteria();
|
||||
$criteria->where(
|
||||
Criteria::expr()->orX(
|
||||
Criteria::expr()->contains('courseCode', $keyword),
|
||||
Criteria::expr()->contains('name', $keyword)
|
||||
)
|
||||
);
|
||||
$gradeBookList = $repo->matching($criteria);
|
||||
}
|
||||
|
||||
$currentUrl = api_get_self().'?';
|
||||
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
|
||||
$contentForm = '';
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon('add.png', get_lang('Add'), [], ICON_SIZE_MEDIUM),
|
||||
$currentUrl.'&action=add'
|
||||
);
|
||||
|
||||
$toolName = get_lang('Gradebook');
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
case 'edit':
|
||||
$interbreadcrumb[] = [
|
||||
'url' => $currentUrl,
|
||||
'name' => get_lang('Gradebook'),
|
||||
];
|
||||
$toolName = get_lang(ucfirst($action));
|
||||
break;
|
||||
}
|
||||
|
||||
$tpl = new Template($toolName);
|
||||
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
|
||||
$currentUrl
|
||||
);
|
||||
$form = new FormValidator(
|
||||
'category_add',
|
||||
'post',
|
||||
$currentUrl.'&action=add'
|
||||
);
|
||||
$form->addText('name', get_lang('Name'));
|
||||
$form->addText('weight', get_lang('Weight'));
|
||||
$form->addSelectAjax(
|
||||
'course_id',
|
||||
get_lang('Course'),
|
||||
null,
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course',
|
||||
]
|
||||
);
|
||||
|
||||
$form->addSelectAjax(
|
||||
'depends',
|
||||
get_lang('DependsOnGradebook'),
|
||||
null,
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course',
|
||||
'multiple' => 'multiple',
|
||||
]
|
||||
);
|
||||
|
||||
$form->addText(
|
||||
'gradebooks_to_validate_in_dependence',
|
||||
get_lang('NumberOfGradebookToValidateInDependence')
|
||||
);
|
||||
|
||||
$form->addText(
|
||||
'minimum',
|
||||
get_lang('MinimumGradebookToValidate'),
|
||||
false
|
||||
);
|
||||
|
||||
$form->addButtonSave(get_lang('Add'));
|
||||
$contentForm = $form->returnForm();
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
$courseId = isset($values['course_id']) ? $values['course_id'] : 0;
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$courseCode = $courseInfo['code'];
|
||||
$criteria = ['courseCode' => $courseCode];
|
||||
$exists = $repo->findBy($criteria);
|
||||
if (empty($exists) || empty($courseId)) {
|
||||
if (empty($courseId)) {
|
||||
$courseCode = '';
|
||||
}
|
||||
$category = new GradebookCategory();
|
||||
$category
|
||||
->setName($values['name'])
|
||||
->setWeight($values['weight'])
|
||||
->setVisible(1)
|
||||
->setLocked(0)
|
||||
->setGenerateCertificates(0)
|
||||
->setIsRequirement(false)
|
||||
->setCourseCode($courseCode)
|
||||
->setUserId(api_get_user_id());
|
||||
$em->persist($category);
|
||||
$em->flush();
|
||||
if ($category->getId()) {
|
||||
$params = [];
|
||||
if (!empty($values['depends'])) {
|
||||
$depends = $values['depends'];
|
||||
$depends = array_map('intval', $depends);
|
||||
$value = serialize($depends);
|
||||
$params['depends'] = $value;
|
||||
}
|
||||
|
||||
if (!empty($values['minimum'])) {
|
||||
$params['minimum_to_validate'] = (int) $values['minimum'];
|
||||
}
|
||||
|
||||
if (!empty($values['gradebooks_to_validate_in_dependence'])) {
|
||||
$params['gradebooks_to_validate_in_dependence'] = (int) $values['gradebooks_to_validate_in_dependence'];
|
||||
}
|
||||
|
||||
if (!empty($params)) {
|
||||
Database::update(
|
||||
$table,
|
||||
$params,
|
||||
['id = ?' => $category->getId()]
|
||||
);
|
||||
}
|
||||
Display::addFlash(Display::return_message(get_lang('Added')));
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('CategoryExists')));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
|
||||
$currentUrl
|
||||
);
|
||||
/** @var GradebookCategory $category */
|
||||
$category = $repo->find($categoryId);
|
||||
if (!empty($category)) {
|
||||
$form = new FormValidator(
|
||||
'category_edit',
|
||||
'post',
|
||||
$currentUrl.'&action=edit&id='.$categoryId
|
||||
);
|
||||
$form->addText('name', get_lang('Name'));
|
||||
$form->addText('weight', get_lang('Weight'));
|
||||
$form->addLabel(get_lang('Course'), $category->getCourseCode());
|
||||
|
||||
$sql = "SELECT
|
||||
depends,
|
||||
minimum_to_validate,
|
||||
gradebooks_to_validate_in_dependence
|
||||
FROM $table WHERE id = ".$categoryId;
|
||||
$result = Database::query($sql);
|
||||
$categoryData = Database::fetch_array($result, 'ASSOC');
|
||||
|
||||
$options = [];
|
||||
if (!empty($categoryData['depends'])) {
|
||||
$list = UnserializeApi::unserialize('not_allowed_classes', $categoryData['depends']);
|
||||
foreach ($list as $itemId) {
|
||||
$courseInfo = api_get_course_info_by_id($itemId);
|
||||
$options[$itemId] = $courseInfo['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$form->addSelectAjax(
|
||||
'depends',
|
||||
get_lang('DependsOnGradebook'),
|
||||
$options,
|
||||
[
|
||||
'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course',
|
||||
'multiple' => 'multiple',
|
||||
]
|
||||
);
|
||||
|
||||
$form->addText(
|
||||
'gradebooks_to_validate_in_dependence',
|
||||
get_lang('NumberOfGradebookToValidateInDependence')
|
||||
);
|
||||
|
||||
$form->addText(
|
||||
'minimum',
|
||||
get_lang('MinimumGradebookToValidate'),
|
||||
false
|
||||
);
|
||||
|
||||
$form->addButtonSave(get_lang('Edit'));
|
||||
$defaults = [
|
||||
'name' => $category->getName(),
|
||||
'weight' => $category->getWeight(),
|
||||
'gradebooks_to_validate_in_dependence' => $categoryData['gradebooks_to_validate_in_dependence'],
|
||||
'depends' => array_keys($options),
|
||||
'minimum' => $categoryData['minimum_to_validate'],
|
||||
];
|
||||
$form->setDefaults($defaults);
|
||||
$contentForm = $form->returnForm();
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
$category->setName($values['name']);
|
||||
$category->setWeight($values['weight']);
|
||||
$em->merge($category);
|
||||
$em->flush();
|
||||
|
||||
if (!empty($values['depends'])) {
|
||||
$depends = $values['depends'];
|
||||
$depends = array_map('intval', $depends);
|
||||
$value = serialize($depends);
|
||||
$params['depends'] = $value;
|
||||
}
|
||||
|
||||
if (!empty($values['minimum'])) {
|
||||
$params['minimum_to_validate'] = (int) $values['minimum'];
|
||||
}
|
||||
|
||||
if (!empty($values['gradebooks_to_validate_in_dependence'])) {
|
||||
$params['gradebooks_to_validate_in_dependence'] = (int) $values['gradebooks_to_validate_in_dependence'];
|
||||
}
|
||||
|
||||
if (!empty($params)) {
|
||||
Database::update(
|
||||
$table,
|
||||
$params,
|
||||
['id = ?' => $category->getId()]
|
||||
);
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'list':
|
||||
default:
|
||||
$paginator = new Paginator();
|
||||
$pagination = $paginator->paginate(
|
||||
$gradeBookList,
|
||||
$page,
|
||||
$maxItems
|
||||
);
|
||||
|
||||
// pagination.tpl needs current_url with out "page" param
|
||||
$pagination->setCustomParameters(['current_url' => $currentUrl]);
|
||||
|
||||
$pagination->renderer = function ($data) use ($tpl) {
|
||||
foreach ($data as $key => $value) {
|
||||
$tpl->assign($key, $value);
|
||||
}
|
||||
$layout = $tpl->get_template('admin/pagination.tpl');
|
||||
$content = $tpl->fetch($layout);
|
||||
|
||||
return $content;
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$searchForm = new FormValidator(
|
||||
'course_filter',
|
||||
'get',
|
||||
'',
|
||||
'',
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$searchForm->addText('keyword', '', false);
|
||||
$searchForm->addButtonSearch(get_lang('Search'));
|
||||
|
||||
$tpl->assign('current_url', $currentUrl);
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction(
|
||||
'toolbar',
|
||||
[$toolbar, $searchForm->returnForm()],
|
||||
[1, 4]
|
||||
)
|
||||
);
|
||||
|
||||
$tpl->assign('form', $contentForm);
|
||||
if (!empty($pagination)) {
|
||||
$tpl->assign('gradebook_list', $pagination);
|
||||
}
|
||||
$layout = $tpl->get_template('admin/gradebook_list.tpl');
|
||||
$tpl->display($layout);
|
||||
2
main/admin/importCourseEventInCourseExample.csv
Normal file
2
main/admin/importCourseEventInCourseExample.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
UserName;StartDate;EndDate
|
||||
xxx;YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss
|
||||
|
2
main/admin/importCourseEventsExample.csv
Normal file
2
main/admin/importCourseEventsExample.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
CourseCode;UserName;StartDate;EndDate
|
||||
xxx;xxx;YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss
|
||||
|
212
main/admin/import_course_agenda_reminders.php
Normal file
212
main/admin/import_course_agenda_reminders.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$courseCode = api_get_course_id();
|
||||
$sessionId = api_get_session_id();
|
||||
$loadFromCourse = !empty($courseCode) && api_is_allowed_to_edit(false, true);
|
||||
$selfUrl = api_get_self();
|
||||
|
||||
if ($loadFromCourse) {
|
||||
api_protect_teacher_script();
|
||||
$selfUrl = api_get_self().'?'.api_get_cidreq().'&type=course';
|
||||
} else {
|
||||
api_protect_admin_script();
|
||||
}
|
||||
|
||||
$isAgendaRemindersEnabled = api_get_configuration_value('agenda_reminders');
|
||||
|
||||
if (!$isAgendaRemindersEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$tblPersonalAgenda = Database::get_main_table(TABLE_PERSONAL_AGENDA);
|
||||
|
||||
$tags = AnnouncementManager::getTags();
|
||||
$tags[] = '((date_start))';
|
||||
$tags[] = '((date_end))';
|
||||
|
||||
$tagsHelp = '<strong>'.get_lang('Tags').'</strong>'
|
||||
.'<pre>'.implode("\n", $tags).'</pre>';
|
||||
|
||||
$fileHelpText = get_lang('ImportCSVFileLocation').'<br>'
|
||||
.Display::url(
|
||||
get_lang('ExampleCSVFile'),
|
||||
$loadFromCourse ? 'importCourseEventInCourseExample.csv' : 'importCourseEventsExample.csv',
|
||||
[
|
||||
'target' => '_blank',
|
||||
'download' => $loadFromCourse ? 'importCourseEventInCourseExample.csv' : 'importCourseEventsExample.csv',
|
||||
]
|
||||
);
|
||||
|
||||
if ($loadFromCourse) {
|
||||
$fileHelpText .= '<pre>UserName;StartDate;EndDate<br>xxx;YYYY-MM-DD HH:ii:ss;YYYY-MM-DD HH:ii:ss</pre>';
|
||||
} else {
|
||||
$fileHelpText .= '<pre>CourseCode;UserName;StartDate;EndDate<br>xxx;xxx;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'] ?? [];
|
||||
|
||||
$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 = [];
|
||||
|
||||
foreach ($csvEvents as $csvEvent) {
|
||||
$hashDate = base64_encode($csvEvent['StartDate'].'||'.$csvEvent['EndDate']);
|
||||
|
||||
$userInfo = api_get_user_info_from_username($csvEvent['UserName']);
|
||||
|
||||
if (!$userInfo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($loadFromCourse) {
|
||||
$grouppedData[$courseCode][$hashDate][] = $userInfo['id'];
|
||||
} else {
|
||||
$courseInfo = api_get_course_info($csvEvent['CourseCode']);
|
||||
|
||||
if (!$courseInfo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$grouppedData[$courseInfo['code']][$hashDate][] = $userInfo['id'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($grouppedData as $dataCourseCode => $eventInfo) {
|
||||
foreach ($eventInfo 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'], $dataCourseCode, $sessionId);
|
||||
$content = AnnouncementManager::parseContent($userId, $values['description'], $dataCourseCode, $sessionId);
|
||||
|
||||
$title = str_replace(['((date_start))', '((date_end))'], [$strDateStart, $strDateEnd], $title);
|
||||
$content = str_replace(['((date_start))', '((date_end))'], [$strDateStart, $strDateEnd], $content);
|
||||
|
||||
$attributes = [
|
||||
'user' => $userId,
|
||||
'title' => $title,
|
||||
'text' => $content,
|
||||
'date' => $dateStart,
|
||||
'enddate' => $dateEnd,
|
||||
'all_day' => 0,
|
||||
'color' => '',
|
||||
];
|
||||
|
||||
$eventId = Database::insert($tblPersonalAgenda, $attributes);
|
||||
|
||||
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('ImportCourseAgendaReminderTitleDefault'),
|
||||
'description' => get_lang('ImportCourseAgendaReminderDescriptionDefault'),
|
||||
]
|
||||
);
|
||||
|
||||
$htmlHeadXtra[] = '<script>$(function () {'
|
||||
.Agenda::getJsForReminders('#agenda_reminders_add_notification')
|
||||
.'});</script>';
|
||||
|
||||
$pageTitle = get_lang('ImportCourseEvents');
|
||||
|
||||
$actions = '';
|
||||
|
||||
if (!$loadFromCourse) {
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
"url" => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=course&'.api_get_cidreq(),
|
||||
"name" => get_lang('Agenda'),
|
||||
];
|
||||
|
||||
$agenda = new Agenda('course');
|
||||
$actions = $agenda->displayActions('calendar');
|
||||
}
|
||||
|
||||
$template = new Template($pageTitle);
|
||||
$template->assign('header', $pageTitle);
|
||||
$template->assign('actions', $actions);
|
||||
$template->assign('content', $form->returnForm());
|
||||
$template->display_one_col_template();
|
||||
1104
main/admin/index.php
Normal file
1104
main/admin/index.php
Normal file
File diff suppressed because it is too large
Load Diff
325
main/admin/init_cas_user_extra_field_from_ldap.php
Normal file
325
main/admin/init_cas_user_extra_field_from_ldap.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/*
|
||||
User account CASification interactive script
|
||||
|
||||
to move user accounts from LDAP authentication to CAS authentication
|
||||
|
||||
Creates the "cas_user" extra field if missing, then for each registred user:
|
||||
- copies over the right CAS identifier to the "cas_user" extra field
|
||||
- ensures the "username" is spelled right
|
||||
- updates the "auth_source".
|
||||
|
||||
This script should be run from a terminal.
|
||||
It does not read any parameter from the command line, but uses the global configuration arrays
|
||||
$extldap_config
|
||||
and
|
||||
$extldap_user_correspondance
|
||||
defined in app/config/auth.conf.php.
|
||||
|
||||
The username is used to search the LDAP directory, in both attributes
|
||||
$extldap_user_correspondance['username']
|
||||
and
|
||||
$extldap_user_correspondance['extra']['cas_user'].
|
||||
|
||||
Any user account with no match or more than one matches in the LDAP directory is skipped.
|
||||
|
||||
All the corrections are only applied in phase 2, and take time.
|
||||
|
||||
Phase 1 only builds a TO-DO list.
|
||||
|
||||
Phase 2 starts with the script asking the operator confirmation for each modification category:
|
||||
- fix usernames
|
||||
- add missing CAS identifiers
|
||||
- fix wrong CAS identifiers
|
||||
- fix auth source
|
||||
|
||||
Planned modifications and progress are displayed.
|
||||
|
||||
Diagnostics and modifications can be saved using command script(1).
|
||||
|
||||
This script does not need to be run more than once,
|
||||
but can be run several times.
|
||||
In case phase 2 is stopped before the end, one should run this script again.
|
||||
If this script is run after all user accounts were CASified, it just stops after Phase 1.
|
||||
This can be used to check whether no work is left to do.
|
||||
*/
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
exit("this script is supposed to be run from the command-line\n");
|
||||
}
|
||||
require __DIR__.'/../../cli-config.php';
|
||||
require_once __DIR__.'/../../app/config/auth.conf.php';
|
||||
require_once __DIR__.'/../../main/inc/lib/api.lib.php';
|
||||
require_once __DIR__.'/../../main/inc/lib/database.constants.inc.php';
|
||||
require_once __DIR__.'/../../main/inc/lib/internationalization.lib.php';
|
||||
require_once __DIR__.'/../../main/inc/lib/text.lib.php';
|
||||
|
||||
// Bind to LDAP server
|
||||
|
||||
$ldap = false;
|
||||
foreach ($extldap_config['host'] as $ldapHost) {
|
||||
$ldap = array_key_exists('port', $extldap_config)
|
||||
? ldap_connect($ldapHost, $extldap_config['port'])
|
||||
: ldap_connect($ldapHost);
|
||||
if (false !== $ldap) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (false === $ldap) {
|
||||
exit("ldap_connect() failed\n");
|
||||
}
|
||||
echo "Connected to LDAP server $ldapHost.\n";
|
||||
|
||||
ldap_set_option(
|
||||
$ldap,
|
||||
LDAP_OPT_PROTOCOL_VERSION,
|
||||
array_key_exists('protocol_version', $extldap_config) ? $extldap_config['protocol_version'] : 2
|
||||
);
|
||||
|
||||
ldap_set_option(
|
||||
$ldap,
|
||||
LDAP_OPT_REFERRALS,
|
||||
array_key_exists('referrals', $extldap_config) ? $extldap_config['referrals'] : false
|
||||
);
|
||||
|
||||
ldap_bind($ldap, $extldap_config['admin_dn'], $extldap_config['admin_password'])
|
||||
or exit('ldap_bind() failed: '.ldap_error($ldap)."\n");
|
||||
echo "Bound to LDAP server as ${extldap_config['admin_dn']}.\n";
|
||||
|
||||
// set a few variables for LDAP search
|
||||
|
||||
$baseDn = $extldap_config['base_dn']
|
||||
or exit("cannot read the LDAP directory base DN where to search for user entries\n");
|
||||
echo "Base DN is '$baseDn'.\n";
|
||||
|
||||
$ldapCASUserAttribute = $extldap_user_correspondance['extra']['cas_user']
|
||||
or exit("cannot read the name of the LDAP attribute where to find the CAS user code\n");
|
||||
echo "LDAP CAS user code attribute is '$ldapCASUserAttribute'.\n";
|
||||
|
||||
$ldapUsernameAttribute = $extldap_user_correspondance['username']
|
||||
or exit("cannot read the name of the LDAP attribute where to find the username\n");
|
||||
echo "LDAP username attribute is '$ldapUsernameAttribute'.\n";
|
||||
|
||||
$filters = [
|
||||
"$ldapCASUserAttribute=*",
|
||||
"$ldapUsernameAttribute=*",
|
||||
];
|
||||
if (array_key_exists('filter', $extldap_config)) {
|
||||
$filters[] = $extldap_config['filter'];
|
||||
}
|
||||
|
||||
// read 'cas_user' extra field id from internal database
|
||||
|
||||
$extraField = new ExtraField('user');
|
||||
$extraFieldData = $extraField->get_handler_field_info_by_field_variable('cas_user');
|
||||
if (empty($extraFieldData)) {
|
||||
if ('y' === readline("Create missing 'cas_user' extra field ? (type 'y' to confirm) ")) {
|
||||
$fieldId = $extraField->save(
|
||||
[
|
||||
'variable' => 'cas_user',
|
||||
'field_type' => ExtraField::FIELD_TYPE_TEXT,
|
||||
'visible_to_self' => true,
|
||||
'filter' => true,
|
||||
'display_text' => get_lang('CAS User Identifier'),
|
||||
]
|
||||
);
|
||||
if (false === $fieldId) {
|
||||
exit("failed to create extra field\n");
|
||||
}
|
||||
} else {
|
||||
exit("Required extra field is missing\n");
|
||||
}
|
||||
} else {
|
||||
$fieldId = $extraFieldData['id'];
|
||||
}
|
||||
echo "'cas_user' extra field id is $fieldId.\n";
|
||||
|
||||
// read cas_user extra field existing values as an associative array ( user id => CAS code )
|
||||
|
||||
$extraFieldValueModel = new ExtraFieldValue('user');
|
||||
$recordList = $extraFieldValueModel->getValuesByFieldId($fieldId);
|
||||
$existingCasUserValues = [];
|
||||
if (false !== $recordList) {
|
||||
foreach ($recordList as $value) {
|
||||
$existingCasUserValues[$value['item_id']] = $value['value'];
|
||||
}
|
||||
}
|
||||
echo count($existingCasUserValues)." users have their cas_user value set already.\n";
|
||||
|
||||
// read all users from the internal database and check their LDAP CAS code to build a to-do list
|
||||
|
||||
$userRepository = Database::getManager()->getRepository('ChamiloUserBundle:User');
|
||||
$databaseUsers = $userRepository->findAll();
|
||||
$count = count($databaseUsers);
|
||||
echo "$count users are registered in the internal database.\n";
|
||||
|
||||
$userNamesInUse = [];
|
||||
foreach ($databaseUsers as $user) {
|
||||
$userNamesInUse[$user->getUsername()] = $user->getId();
|
||||
}
|
||||
|
||||
$missingCASCodes = [];
|
||||
$wrongCASCodes = [];
|
||||
$wrongUserNames = [];
|
||||
$wrongAuthSources = [];
|
||||
|
||||
$checked = 0;
|
||||
foreach ($databaseUsers as $user) {
|
||||
$username = $user->getUsername();
|
||||
echo "Checked $checked / $count users - now checking '$username'…\r";
|
||||
$filter = '(&('
|
||||
.join(
|
||||
')(',
|
||||
array_merge($filters, ["|($ldapUsernameAttribute=$username)($ldapCASUserAttribute=$username)"])
|
||||
)
|
||||
.'))';
|
||||
$searchResult = ldap_search($ldap, $baseDn, $filter, [$ldapCASUserAttribute, $ldapUsernameAttribute]);
|
||||
if (false === $searchResult) {
|
||||
exit('ldap_search() failed: '.ldap_error($ldap)."\n");
|
||||
}
|
||||
$userId = $user->getId();
|
||||
echo "$username ($userId): ";
|
||||
switch (ldap_count_entries($ldap, $searchResult)) {
|
||||
case 0:
|
||||
print "does not exist in the LDAP directory, skipping.\n";
|
||||
break;
|
||||
case 1:
|
||||
$entry = ldap_first_entry($ldap, $searchResult);
|
||||
if (false === $entry) {
|
||||
exit('ldap_first_entry() failed: '.ldap_error($ldap)."\n");
|
||||
}
|
||||
$ldapCASUser = ldap_get_values($ldap, $entry, $ldapCASUserAttribute)[0];
|
||||
if (false === $ldapCASUser) {
|
||||
exit('cannot read CAS user code from LDAP entry: '.ldap_error($ldap)."\n");
|
||||
}
|
||||
$ldapUsername = ldap_get_values($ldap, $entry, $ldapUsernameAttribute)[0];
|
||||
if (false === $ldapUsername) {
|
||||
exit('cannot read username from LDAP entry: '.ldap_error($ldap)."\n");
|
||||
}
|
||||
echo "\033[2K\r$ldapUsernameAttribute: $ldapUsername, $ldapCASUserAttribute: $ldapCASUser, ";
|
||||
$problems = [];
|
||||
if ($username === $ldapUsername) {
|
||||
//true;
|
||||
} elseif (in_array(
|
||||
strtolower(trim($username)),
|
||||
[strtolower(trim($ldapUsername)), strtolower(trim($ldapCASUser))]
|
||||
)) {
|
||||
if (array_key_exists($ldapUsername, $userNamesInUse)) {
|
||||
echo "wrong username but '$ldapUsername' is already taken, skipping.\n";
|
||||
break;
|
||||
} else {
|
||||
$problems[] = "wrong username";
|
||||
$wrongUserNames[$userId] = $ldapUsername;
|
||||
$userNamesInUse[$ldapUsername] = $userId;
|
||||
}
|
||||
} else {
|
||||
exit("LDAP search result does not match username; our filter is wrong: $filter\n");
|
||||
}
|
||||
if (array_key_exists($userId, $existingCasUserValues)) {
|
||||
$currentValue = $existingCasUserValues[$userId];
|
||||
if ($currentValue !== $ldapCASUser) {
|
||||
$problems[] = "wrong current CAS user code '$currentValue'";
|
||||
$wrongCASCodes[$userId] = $ldapCASUser;
|
||||
}
|
||||
} else {
|
||||
$problems[] = "CAS user code missing in database";
|
||||
$missingCASCodes[$userId] = $ldapCASUser;
|
||||
}
|
||||
$currentAuthSource = $user->getAuthSource();
|
||||
if (CAS_AUTH_SOURCE !== $currentAuthSource) {
|
||||
$problems[] = "wrong auth source '$currentAuthSource'";
|
||||
$wrongAuthSources[$userId] = true;
|
||||
}
|
||||
echo empty($problems) ? "ok\r" : (join(', ', $problems)."\n");
|
||||
break;
|
||||
default:
|
||||
print "more than 1 entries for username '$username' in the LDAP directory for user id=$userId, skipping.\n";
|
||||
}
|
||||
$checked++;
|
||||
}
|
||||
echo "\033[2K\r";
|
||||
|
||||
// ask for confirmation and write changes to the database
|
||||
|
||||
$fixUsernames = (
|
||||
!empty($wrongUserNames)
|
||||
&&
|
||||
('y' === readline("Fix wrong user names for ".count($wrongUserNames)." users ? (type 'y' to confirm) "))
|
||||
);
|
||||
if ($fixUsernames) {
|
||||
echo "I will fix user names.\n";
|
||||
}
|
||||
|
||||
$fixMissingCASCodes = (
|
||||
!empty($missingCASCodes)
|
||||
&&
|
||||
('y' === readline("Fix missing CAS codes for ".count($missingCASCodes)." users ? (type 'y' to confirm) "))
|
||||
);
|
||||
if ($fixMissingCASCodes) {
|
||||
echo "I will fix missing CAS codes.\n";
|
||||
}
|
||||
|
||||
$fixWrongCASCodes = (
|
||||
!empty($wrongCASCodes)
|
||||
&&
|
||||
('y' === readline("Fix wrong CAS codes for ".count($wrongCASCodes)." users ? (type 'y' to confirm) "))
|
||||
);
|
||||
if ($fixWrongCASCodes) {
|
||||
echo "I will fix wrong CAS codes.\n";
|
||||
}
|
||||
|
||||
$fixWrongAuthSources = (
|
||||
!empty($wrongAuthSources)
|
||||
&&
|
||||
('y' === readline("Fix auth source for ".count($wrongAuthSources)." users ? (type 'y' to confirm) "))
|
||||
);
|
||||
if ($fixWrongAuthSources) {
|
||||
echo "I will fix wrong authentication sources.\n";
|
||||
}
|
||||
|
||||
if ($fixUsernames || $fixWrongAuthSources || $fixWrongCASCodes || $fixMissingCASCodes) {
|
||||
$usersToFix = [];
|
||||
foreach ($databaseUsers as $user) {
|
||||
$userId = $user->getId();
|
||||
if ($fixUsernames && array_key_exists($userId, $wrongUserNames)
|
||||
|| $fixWrongAuthSources && array_key_exists($userId, $wrongAuthSources)
|
||||
|| $fixMissingCASCodes && array_key_exists($userId, $missingCASCodes)
|
||||
|| $fixWrongCASCodes && array_key_exists($userId, $wrongCASCodes)
|
||||
) {
|
||||
$usersToFix[] = $user;
|
||||
}
|
||||
}
|
||||
$fixCount = count($usersToFix);
|
||||
echo "Now fixing $fixCount out of $count database users…\n";
|
||||
$done = 0;
|
||||
foreach ($usersToFix as $user) {
|
||||
$userId = $user->getId();
|
||||
$dirty = false;
|
||||
if ($fixUsernames && array_key_exists($userId, $wrongUserNames)) {
|
||||
$user->setUsername($wrongUserNames[$userId]);
|
||||
$dirty = true;
|
||||
}
|
||||
if ($fixWrongAuthSources && array_key_exists($userId, $wrongAuthSources)) {
|
||||
$user->setAuthSource(CAS_AUTH_SOURCE);
|
||||
$dirty = true;
|
||||
}
|
||||
if ($dirty) {
|
||||
try {
|
||||
UserManager::getManager()->save($user);
|
||||
} catch (Exception $exception) {
|
||||
echo $exception->getMessage()."\n";
|
||||
exit("Script stopped before the end.\n");
|
||||
}
|
||||
}
|
||||
if ($fixMissingCASCodes && array_key_exists($userId, $missingCASCodes)) {
|
||||
UserManager::update_extra_field_value($userId, 'cas_user', $missingCASCodes[$userId]);
|
||||
} elseif ($fixWrongCASCodes && array_key_exists($userId, $wrongCASCodes)) {
|
||||
UserManager::update_extra_field_value($userId, 'cas_user', $wrongCASCodes[$userId]);
|
||||
}
|
||||
$done++;
|
||||
echo "Fixed $done / $fixCount users\r";
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
echo "End of script.\n";
|
||||
351
main/admin/languages.php
Normal file
351
main/admin/languages.php
Normal file
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* This page allows the platform admin to decide which languages should
|
||||
* be available in the language selection menu in the login page. This can be
|
||||
* useful for countries with more than one official language (like Belgium:
|
||||
* Dutch, French and German) or international organisations that are active in
|
||||
* a limited number of countries.
|
||||
*
|
||||
* @author Patrick Cool, main author
|
||||
* @author Roan EMbrechts, code cleaning
|
||||
*
|
||||
* @since Dokeos 1.6
|
||||
*/
|
||||
|
||||
// we are in the admin area so we do not need a course id
|
||||
$cidReset = true;
|
||||
|
||||
// include global script
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
|
||||
//Ajax request
|
||||
if (isset($_POST['sent_http_request'])) {
|
||||
if (isset($_POST['visibility']) &&
|
||||
$_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 0) {
|
||||
if (isset($_POST['id']) && $_POST['id'] == strval(intval($_POST['id']))) {
|
||||
if (SubLanguageManager::check_if_language_is_used($_POST['id']) == false) {
|
||||
SubLanguageManager::make_unavailable_language($_POST['id']);
|
||||
echo 'set_hidden';
|
||||
} else {
|
||||
echo 'confirm:'.intval($_POST['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_POST['visibility']) &&
|
||||
$_POST['visibility'] == strval(intval($_POST['visibility'])) && $_POST['visibility'] == 1
|
||||
) {
|
||||
if (isset($_POST['id']) && $_POST['id'] == strval(intval($_POST['id']))) {
|
||||
SubLanguageManager::make_available_language($_POST['id']);
|
||||
echo 'set_visible';
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$msgLang = isset($_SESSION['disabled_languages']) ? 1 : 0;
|
||||
$disabledLang = isset($_SESSION['disabled_languages']) ? $_SESSION['disabled_languages'] : null;
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function () {
|
||||
var msgLang = '.$msgLang.';
|
||||
var disabledLang = "'.$disabledLang.'"
|
||||
|
||||
if (msgLang == 1) {
|
||||
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\">'.get_lang('ThereAreUsersUsingThisLanguagesDisableItManually').' <br /> " + disabledLang + "</div");
|
||||
}
|
||||
|
||||
$("#disable_all_except_default").click(function () {
|
||||
if(confirm("'.get_lang('ConfirmYourChoice').'")) {
|
||||
$.ajax({
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
beforeSend: function(myObject) {
|
||||
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.get_lang('Loading').'</div>");
|
||||
},
|
||||
type: "GET",
|
||||
url: "../admin/languages.php",
|
||||
data: "action=disable_all_except_default",
|
||||
success: function(datos) {
|
||||
window.location.href = "'.api_get_self().'";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
//$(window).load(function () {
|
||||
$(".make_visible_and_invisible").attr("href","javascript:void(0)");
|
||||
//});
|
||||
|
||||
$("td .make_visible_and_invisible").click(function () {
|
||||
make_visible="visible.png";
|
||||
make_invisible="invisible.png";
|
||||
id_link_tool=$(this).attr("id");
|
||||
id_img_link_tool="img"+id_link_tool;
|
||||
path_name_of_imglinktool=$("#"+id_img_link_tool).attr("src");
|
||||
link_info_id=id_link_tool.split("linktool_");
|
||||
link_id=link_info_id[1];
|
||||
|
||||
link_tool_info=path_name_of_imglinktool.split("/");
|
||||
my_image_tool=link_tool_info[link_tool_info.length-1];
|
||||
|
||||
|
||||
if (my_image_tool=="visible.png") {
|
||||
path_name_of_imglinktool=path_name_of_imglinktool.replace(make_visible,make_invisible);
|
||||
my_visibility=0;
|
||||
} else {
|
||||
path_name_of_imglinktool=path_name_of_imglinktool.replace(make_invisible,make_visible);
|
||||
my_visibility=1;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
beforeSend: function(myObject) {
|
||||
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.get_lang('Loading').'</div>");
|
||||
},
|
||||
type: "POST",
|
||||
url: "../admin/languages.php",
|
||||
data: "id="+link_id+"&visibility="+my_visibility+"&sent_http_request=1",
|
||||
success: function(datos) {
|
||||
|
||||
if (datos=="set_visible" || datos=="set_hidden") {
|
||||
$("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
|
||||
|
||||
if (my_image_tool=="visible.png") {
|
||||
$("#"+id_img_link_tool).attr("alt","'.get_lang('MakeAvailable', '').'");
|
||||
$("#"+id_img_link_tool).attr("title","'.get_lang('MakeAvailable', '').'");
|
||||
} else {
|
||||
$("#"+id_img_link_tool).attr("alt","'.get_lang('MakeUnavailable', '').'");
|
||||
$("#"+id_img_link_tool).attr("title","'.get_lang('MakeUnavailable', '').'");
|
||||
}
|
||||
|
||||
if (datos=="set_visible") {
|
||||
$("#id_content_message").html("<div class=\"confirmation-message alert alert-success\">'.get_lang('LanguageIsNowVisible', '').'</div>");
|
||||
}
|
||||
|
||||
if (datos=="set_hidden") {
|
||||
$("#id_content_message").html("<div class=\"confirmation-message alert alert-success\">'.get_lang('LanguageIsNowHidden', '').'</div>");
|
||||
}
|
||||
}
|
||||
|
||||
var action = datos.split(":")[0];
|
||||
if (action && action == "confirm") {
|
||||
var id = datos.split(":")[1];
|
||||
var sure = "<div class=\"warning-message alert alert-warning\">'.get_lang('ThereAreUsersOrCoursesUsingThisLanguageYouWantToDisableThisLanguageAndSetUsersAndCoursesWithTheDefaultPortalLanguage').'<br /><br /><a href=\"languages.php?action=make_unavailable_confirmed&id="+id+"\" class=\"btn btn-default\"><em class=\"fa fa-eye\"></em> '.get_lang('MakeUnavailable').'</a></div>";
|
||||
$("#id_content_message").html(sure);
|
||||
$("html, body").animate({ scrollTop: 0 }, 200);
|
||||
}
|
||||
} });
|
||||
});
|
||||
|
||||
});
|
||||
</script>';
|
||||
|
||||
// unset the msg session variable
|
||||
unset($_SESSION['disabled_languages']);
|
||||
|
||||
// setting the table that is needed for the styles management (there is a check if it exists later in this code)
|
||||
$tbl_admin_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE);
|
||||
$tbl_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
|
||||
|
||||
// we change the availability
|
||||
if ($action == 'makeunavailable') {
|
||||
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
|
||||
SubLanguageManager::make_unavailable_language($_GET['id']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'makeavailable') {
|
||||
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
|
||||
SubLanguageManager::make_available_language($_GET['id']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'setplatformlanguage') {
|
||||
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
|
||||
SubLanguageManager::set_platform_language($_GET['id']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'disable_all_except_default') {
|
||||
$allLanguages = SubLanguageManager::getAllLanguages();
|
||||
$failedDisabledLanguages = '';
|
||||
$checkFailed = false;
|
||||
foreach ($allLanguages as $language) {
|
||||
if (SubLanguageManager::check_if_language_is_used($language['id']) == false) {
|
||||
SubLanguageManager::make_unavailable_language($language['id']);
|
||||
} else {
|
||||
if (intval(SubLanguageManager::get_platform_language_id()) !== intval($language['id'])) {
|
||||
$failedDisabledLanguages .= ' - '.$language['english_name'].'<br />';
|
||||
$checkFailed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($checkFailed) {
|
||||
$_SESSION['disabled_languages'] = $failedDisabledLanguages;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['Submit']) && $_POST['Submit']) {
|
||||
// changing the name
|
||||
$name = html_filter($_POST['txt_name']);
|
||||
$postId = (int) $_POST['edit_id'];
|
||||
Database::update(
|
||||
$tbl_admin_languages,
|
||||
['original_name' => $name],
|
||||
['id = ?' => $postId]
|
||||
);
|
||||
// changing the Platform language
|
||||
if (isset($_POST['platformlanguage']) && $_POST['platformlanguage'] != '') {
|
||||
api_set_setting('platformLanguage', $_POST['platformlanguage'], null, null, $_configuration['access_url']);
|
||||
}
|
||||
} elseif (isset($_POST['action'])) {
|
||||
switch ($_POST['action']) {
|
||||
case 'makeavailable':
|
||||
if (count($_POST['id']) > 0) {
|
||||
$ids = [];
|
||||
foreach ($_POST['id'] as $index => $id) {
|
||||
$ids[] = intval($id);
|
||||
}
|
||||
$sql = "UPDATE $tbl_admin_languages SET available='1' WHERE id IN ('".implode("','", $ids)."')";
|
||||
Database::query($sql);
|
||||
}
|
||||
break;
|
||||
case 'makeunavailable':
|
||||
if (count($_POST['id']) > 0) {
|
||||
$ids = [];
|
||||
foreach ($_POST['id'] as $index => $id) {
|
||||
$ids[] = intval($id);
|
||||
}
|
||||
$sql = "UPDATE $tbl_admin_languages SET available='0' WHERE id IN ('".implode("','", $ids)."')";
|
||||
Database::query($sql);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// setting the name of the tool
|
||||
$tool_name = get_lang('PlatformLanguages');
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'make_unavailable_confirmed') {
|
||||
$language_info = SubLanguageManager::get_all_information_of_language($_GET['id']);
|
||||
if ($language_info['available'] == 1) {
|
||||
SubLanguageManager::make_unavailable_language($_GET['id']);
|
||||
$platform_language = api_get_setting('platformLanguage');
|
||||
UserManager::update_all_user_languages($language_info['english_name'], $platform_language);
|
||||
CourseManager::updateAllCourseLanguages($language_info['english_name'], $platform_language);
|
||||
Display::addFlash(Display::return_message(get_lang('LanguageIsNowHidden'), 'confirm'));
|
||||
}
|
||||
}
|
||||
|
||||
// displaying the explanation for this tool
|
||||
Display::addFlash(Display::return_message(get_lang('PlatformLanguagesExplanation'), 'normal'));
|
||||
|
||||
// including the header file (which includes the banner itself)
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<a
|
||||
id="disable_all_except_default"
|
||||
href="javascript:void(0)" class="btn btn-primary">
|
||||
<em class="fa fa-eye"></em> '.get_lang('LanguagesDisableAllExceptDefault').'</a><br /><br />';
|
||||
|
||||
// selecting all the languages
|
||||
$sql_select = "SELECT * FROM $tbl_admin_languages";
|
||||
$result_select = Database::query($sql_select);
|
||||
|
||||
$sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE category='Languages'";
|
||||
$result_select_lang = Database::query($sql_select_lang);
|
||||
$row_lang = Database::fetch_array($result_select_lang);
|
||||
|
||||
// the table data
|
||||
$language_data = [];
|
||||
while ($row = Database::fetch_array($result_select)) {
|
||||
$row_td = [];
|
||||
$row_td[] = $row['id'];
|
||||
// the first column is the original name of the language OR a form containing the original name
|
||||
if ($action == 'edit' and $row['id'] == $_GET['id']) {
|
||||
$checked = '';
|
||||
if ($row['english_name'] == api_get_setting('platformLanguage')) {
|
||||
$checked = ' checked="checked" ';
|
||||
}
|
||||
|
||||
$row_td[] = '<input type="hidden" name="edit_id" value="'.Security::remove_XSS($_GET['id']).'" /><input type="text" name="txt_name" value="'.$row['original_name'].'" /> '
|
||||
.'<input type="checkbox" '.$checked.'name="platformlanguage" id="platformlanguage" value="'.$row['english_name'].'" /><label for="platformlanguage">'.$row['original_name'].' '.get_lang('AsPlatformLanguage').'</label> <input type="submit" name="Submit" value="'.get_lang('Ok').'" /><a name="value" />';
|
||||
} else {
|
||||
$row_td[] = $row['original_name'];
|
||||
}
|
||||
|
||||
// the second column
|
||||
$row_td[] = $row['english_name'];
|
||||
|
||||
// the third column
|
||||
$row_td[] = $row['dokeos_folder'];
|
||||
|
||||
if ($row['english_name'] == $row_lang['selected_value']) {
|
||||
$setplatformlanguage = Display::return_icon('languages.png', get_lang('CurrentLanguagesPortal'), '', ICON_SIZE_SMALL);
|
||||
} else {
|
||||
$setplatformlanguage = "<a href=\"javascript:if (confirm('".addslashes(get_lang('AreYouSureYouWantToSetThisLanguageAsThePortalDefault'))."')) { location.href='".api_get_self()."?action=setplatformlanguage&id=".$row['id']."'; }\">".Display::return_icon('languages_na.png', get_lang('SetLanguageAsDefault'), '', ICON_SIZE_SMALL)."</a>";
|
||||
}
|
||||
|
||||
$allow_delete_sub_language = null;
|
||||
$allow_add_term_sub_language = null;
|
||||
if (api_get_setting('allow_use_sub_language') == 'true') {
|
||||
$verified_if_is_sub_language = SubLanguageManager::check_if_language_is_sub_language($row['id']);
|
||||
|
||||
if ($verified_if_is_sub_language === false) {
|
||||
$verified_if_is_father = SubLanguageManager::check_if_language_is_father($row['id']);
|
||||
$allow_use_sub_language = " <a href='sub_language_add.php?action=definenewsublanguage&id=".$row['id']."'>".Display::return_icon('new_language.png', get_lang('CreateSubLanguage'), [], ICON_SIZE_SMALL)."</a>";
|
||||
if ($verified_if_is_father === true) {
|
||||
//$allow_add_term_sub_language = " <a href='sub_language.php?action=registersublanguage&id=".$row['id']."'>".Display::return_icon('2rightarrow.png', get_lang('AddWordForTheSubLanguage'),array('width'=>ICON_SIZE_SMALL,'height'=>ICON_SIZE_SMALL))."</a>";
|
||||
$allow_add_term_sub_language = '';
|
||||
} else {
|
||||
$allow_add_term_sub_language = '';
|
||||
}
|
||||
} else {
|
||||
$allow_use_sub_language = '';
|
||||
$all_information_of_sub_language = SubLanguageManager::get_all_information_of_language($row['id']);
|
||||
$allow_add_term_sub_language = " <a href='sub_language.php?action=registersublanguage&id=".Security::remove_XSS($all_information_of_sub_language['parent_id'])."&sub_language_id=".Security::remove_XSS($row['id'])."'>".Display::return_icon('2rightarrow.png', get_lang('AddWordForTheSubLanguage'), ['width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL])."</a>";
|
||||
$allow_delete_sub_language = " <a href='sub_language_add.php?action=deletesublanguage&id=".Security::remove_XSS($all_information_of_sub_language['parent_id'])."&sub_language_id=".Security::remove_XSS($row['id'])."'>".Display::return_icon('delete.png', get_lang('DeleteSubLanguage'), ['width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL])."</a>";
|
||||
}
|
||||
} else {
|
||||
$allow_use_sub_language = '';
|
||||
$allow_add_term_sub_language = '';
|
||||
}
|
||||
|
||||
if ($row['english_name'] == $row_lang['selected_value']) {
|
||||
$row_td[] = Display::return_icon('visible.png', get_lang('Visible'))."<a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL)."</a>
|
||||
".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
|
||||
} else {
|
||||
if ($row['available'] == 1) {
|
||||
$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeunavailable&id=".$row['id']."'>".Display::return_icon('visible.png', get_lang('MakeUnavailable'), ['id' => 'imglinktool_'.$row['id']], ICON_SIZE_SMALL)."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL)."</a> ".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
|
||||
} else {
|
||||
$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeavailable&id=".$row['id']."'>".Display::return_icon('invisible.png', get_lang('MakeAvailable'), ['id' => 'imglinktool_'.$row['id']], ICON_SIZE_SMALL)."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL)."</a> ".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
|
||||
}
|
||||
}
|
||||
$language_data[] = $row_td;
|
||||
}
|
||||
|
||||
$table = new SortableTableFromArrayConfig($language_data, 1, count($language_data));
|
||||
$table->set_header(0, '');
|
||||
$table->set_header(1, get_lang('OriginalName'));
|
||||
$table->set_header(2, get_lang('EnglishName'));
|
||||
$table->set_header(3, get_lang('LMSFolder'));
|
||||
$table->set_header(4, get_lang('Properties'));
|
||||
$form_actions = [];
|
||||
$form_actions['makeavailable'] = get_lang('MakeAvailable');
|
||||
$form_actions['makeunavailable'] = get_lang('MakeUnavailable');
|
||||
$table->set_form_actions($form_actions);
|
||||
echo '<div id="id_content_message"> </div>';
|
||||
$table->display();
|
||||
|
||||
Display::display_footer();
|
||||
71
main/admin/ldap_form_add_users_group.php
Normal file
71
main/admin/ldap_form_add_users_group.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Form to add users through LDAP (deprecated?).
|
||||
*
|
||||
* @package chamilo.admin
|
||||
* Copyright (c) 2007 Mustapha Alouani (supervised by Michel Moreau-Belliard)
|
||||
*/
|
||||
|
||||
/**
|
||||
* This form is included by ldap_import_students.php and ldap_import_students_to_session.php.
|
||||
*/
|
||||
$nbre = 0;
|
||||
echo '<form name="form" method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'">';
|
||||
if ($statut == 1) {
|
||||
echo get_lang(
|
||||
'EmailNotifySubscription'
|
||||
).': <input type="checkbox" name="mailling" value="1" checked="checked"><i>'.get_lang(
|
||||
'DontUnchek'
|
||||
).'</i>';
|
||||
} else {
|
||||
echo '<input type="hidden" name="mailling" value="1">';
|
||||
}
|
||||
if (!empty($course)) {
|
||||
echo '<input type="hidden" name="course" value="'.Security::remove_XSS($course).'">';
|
||||
} elseif (!empty($id_session)) {
|
||||
echo '<input type="hidden" name="id_session" value="'.Security::remove_XSS($id_session).'">';
|
||||
}
|
||||
$is_western_name_order = api_is_western_name_order();
|
||||
echo '<input type="hidden" name="confirmed" value="yes">';
|
||||
echo '<table border="0" cellspacing="0" width="100%">';
|
||||
echo '<tr align="center" id="header3">'.
|
||||
'<td width="15%"><input type="button" value="'.get_lang('AllSlashNone').'" onClick="checkAll();"></td>'.
|
||||
'<td width="40%"><b>'.get_lang('Email').'</b></td>'.
|
||||
($is_western_name_order
|
||||
? '<td width="15%"><b>'.get_lang('FirstName').'</b></td>'.
|
||||
'<td width="15%"><b>'.get_lang('Name').'</b></td>'
|
||||
: '<td width="15%"><b>'.get_lang('Name').'</b></td>'.
|
||||
'<td width="15%"><b>'.get_lang('FirstName').'</b></td>').
|
||||
'<td width="15%"><b>'.get_lang('Login').'</b></td>'.
|
||||
'</tr>'."\n";
|
||||
foreach ($nom_form as $key => $val) {
|
||||
$nbre = $nbre + 1;
|
||||
if ($nbre & 1) {
|
||||
$ndiv = 2;
|
||||
} else {
|
||||
$ndiv = 3;
|
||||
}
|
||||
echo '<tr align="center" id="header'.$ndiv.'">';
|
||||
echo '<td><input type="checkbox" name="checkboxes[]" value="'.$key.'" checked="checked"></td>';
|
||||
echo '<td>'.$email_form[$key].'<input type="hidden" name="email_form['.$key.']" size="40" value="'.$email_form[$key].'"></td>';
|
||||
if ($is_western_name_order) {
|
||||
echo '<td>'.$prenom_form[$key].'<input type="hidden" name="prenom_form['.$key.']" size="20" value="'.$prenom_form[$key].'"></td>';
|
||||
echo '<td>'.$nom_form[$key].'<input type="hidden" name="nom_form['.$key.']" size="20" value="'.$nom_form[$key].'"></td>';
|
||||
} else {
|
||||
echo '<td>'.$nom_form[$key].'<input type="hidden" name="nom_form['.$key.']" size="20" value="'.$nom_form[$key].'"></td>';
|
||||
echo '<td>'.$prenom_form[$key].'<input type="hidden" name="prenom_form['.$key.']" size="20" value="'.$prenom_form[$key].'"></td>';
|
||||
}
|
||||
echo '<td>'.$username_form[$key].'<input type="hidden" name="username_form['.$key.']" size="10" value="'.$username_form[$key].'">';
|
||||
echo '<input type="hidden" name="tutor_form['.$key.']" value="0">';
|
||||
echo '<input type="hidden" name="admin_form['.$key.']" value="1">';
|
||||
echo '<input type="hidden" name="password_form['.$key.']" value="'.$password_form[$key].'">';
|
||||
echo '<input type="hidden" name="statut['.$key.']" value="'.$statut.'">';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
echo '<br />';
|
||||
echo '<br />';
|
||||
echo '<input type="submit" name="submit" value="'.get_lang('Submit').'">';
|
||||
echo '</form>';
|
||||
156
main/admin/ldap_import_students.php
Normal file
156
main/admin/ldap_import_students.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Script to import students from LDAP.
|
||||
*
|
||||
* @package chamilo.admin
|
||||
* Copyright (c) 2007 Mustapha Alouani (supervised by Michel Moreau-Belliard)
|
||||
*/
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
// Access restrictions
|
||||
api_protect_admin_script();
|
||||
require '../auth/ldap/authldap.php';
|
||||
|
||||
$annee_base = date('Y');
|
||||
|
||||
$tool_name = get_lang('LDAPImport');
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
var buttoncheck = 1;
|
||||
function checkAll() {
|
||||
//var boxes = document.form.elements[\'checkboxes[]\'];
|
||||
var boxes = document.getElementsByName(\'checkboxes[]\');
|
||||
if (buttoncheck == 0) {
|
||||
for (i = 0; i < boxes.length; i++) {
|
||||
boxes[i].checked = true;
|
||||
}
|
||||
buttoncheck = 1;
|
||||
return "'.get_lang('None').'";
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < boxes.length; i++) {
|
||||
boxes[i].checked = false;
|
||||
}
|
||||
buttoncheck = 0;
|
||||
return " '.get_lang('All').' ";
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
|
||||
$annee = $_GET['annee'];
|
||||
$composante = $_GET['composante'];
|
||||
$etape = $_GET['etape'];
|
||||
$course = $_POST['course'];
|
||||
// form1 annee = 0; composante= 0 etape = 0
|
||||
//if ($annee == "" && $composante == "" && $etape == "") {
|
||||
if (empty($annee) && empty($course)) {
|
||||
Display::display_header($tool_name);
|
||||
echo '<div style="align:center">';
|
||||
Display::display_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU'));
|
||||
echo get_lang('LDAPSelectFilterOnUsersOU');
|
||||
//echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</em><br />';
|
||||
///echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />';
|
||||
|
||||
echo '<form method="get" action="'.api_get_self().'"><br />';
|
||||
echo '<em>'.get_lang('LDAPOUAttributeFilter').' :</em> ';
|
||||
echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />';
|
||||
echo '<input type="submit" value="'.get_lang('Submit').'">';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
} elseif (!empty($annee) && empty($course)) {
|
||||
Display::display_header($tool_name);
|
||||
echo '<div style="align:center">';
|
||||
echo Display::return_icon('course.png', get_lang('SelectCourseToImportUsersTo')).' '.get_lang('SelectCourseToImportUsersTo').'<br />';
|
||||
echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
|
||||
echo '<select name="course">';
|
||||
$courses = CourseManager::get_courses_list();
|
||||
foreach ($courses as $row) {
|
||||
echo '<option value="'.$row['code'].'">'.api_htmlentities($row['title']).'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="submit" value="'.get_lang('Submit').'">';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
} elseif (!empty($annee) && !empty($course) && empty($_POST['confirmed'])) {
|
||||
// form4 annee != 0; composante != 0 etape != 0
|
||||
//elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != 'yes') {
|
||||
Display::display_header($tool_name);
|
||||
echo '<div style="align: center;">';
|
||||
echo '<br />';
|
||||
echo '<br />';
|
||||
echo '<h3>'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'</h3>';
|
||||
//echo "Connection ...";
|
||||
$ds = ldap_connect($ldap_host, $ldap_port) or exit(get_lang('LDAPConnectionError'));
|
||||
ldap_set_version($ds);
|
||||
|
||||
if ($ds) {
|
||||
$r = false;
|
||||
$res = ldap_handle_bind($ds, $r);
|
||||
|
||||
//$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))");
|
||||
//echo "(ou=*$annee,ou=$composante)";
|
||||
$sr = @ldap_search($ds, $ldap_basedn, "(ou=*$annee)");
|
||||
|
||||
$info = ldap_get_entries($ds, $sr);
|
||||
|
||||
for ($key = 0; $key < $info["count"]; $key++) {
|
||||
$nom_form[] = $info[$key]["sn"][0];
|
||||
$prenom_form[] = $info[$key]["givenname"][0];
|
||||
$email_form[] = $info[$key]["mail"][0];
|
||||
// Get uid from dn
|
||||
//$dn_array=ldap_explode_dn($info[$key]["dn"],1);
|
||||
//$username_form[] = $dn_array[0]; // uid is first key
|
||||
$username_form[] = $info[$key]['uid'][0];
|
||||
$outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
|
||||
//$val = ldap_get_values_len($ds, $entry, "userPassword");
|
||||
//$password_form[] = $val[0];
|
||||
$password_form[] = $info[$key]['userPassword'][0];
|
||||
}
|
||||
ldap_unbind($ds);
|
||||
asort($nom_form);
|
||||
reset($nom_form);
|
||||
|
||||
$statut = 5;
|
||||
include 'ldap_form_add_users_group.php';
|
||||
} else {
|
||||
echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
|
||||
}
|
||||
echo '<br /><br />';
|
||||
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
|
||||
echo '<br /><br />';
|
||||
echo '</div>';
|
||||
} elseif (!empty($annee) && !empty($course) && ($_POST['confirmed'] == 'yes')) {
|
||||
$id = $_POST['username_form'];
|
||||
$UserList = [];
|
||||
$userid_match_login = [];
|
||||
foreach ($id as $form_index => $user_id) {
|
||||
if (is_array($_POST['checkboxes']) && in_array($form_index, array_values($_POST['checkboxes']))) {
|
||||
$tmp = ldap_add_user($user_id);
|
||||
$UserList[] = $tmp;
|
||||
$userid_match_login[$tmp] = $user_id;
|
||||
}
|
||||
}
|
||||
if (!empty($_POST['course'])) {
|
||||
foreach ($UserList as $user_id) {
|
||||
CourseManager::subscribeUser($user_id, $_POST['course']);
|
||||
}
|
||||
header('Location: course_information.php?code='.Security::remove_XSS($_POST['course']));
|
||||
exit;
|
||||
} else {
|
||||
$message = get_lang('NoUserAdded');
|
||||
Display::addFlash(Display::return_message($message, 'normal', false));
|
||||
Display::display_header($tool_name);
|
||||
}
|
||||
echo '<br /><br />';
|
||||
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
Display::display_footer();
|
||||
178
main/admin/ldap_import_students_to_session.php
Normal file
178
main/admin/ldap_import_students_to_session.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Edition script for sessions categories.
|
||||
*
|
||||
* @package chamilo.admin
|
||||
* Copyright (c) 2007 Mustapha Alouani (supervised by Michel Moreau-Belliard)
|
||||
*/
|
||||
|
||||
// resetting the course id
|
||||
$cidReset = true;
|
||||
require_once '../inc/global.inc.php';
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
// Access restrictions
|
||||
api_protect_admin_script();
|
||||
require '../auth/ldap/authldap.php';
|
||||
|
||||
$annee_base = date('Y');
|
||||
|
||||
$tool_name = get_lang('LDAPImport');
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript">
|
||||
var buttoncheck = 1;
|
||||
function checkAll() {
|
||||
//var boxes = document.form.elements[\'checkboxes[]\'];
|
||||
var boxes = document.getElementsByName(\'checkboxes[]\');
|
||||
if (buttoncheck == 0) {
|
||||
for (i = 0; i < boxes.length; i++) {
|
||||
boxes[i].checked = true;
|
||||
}
|
||||
buttoncheck = 1;
|
||||
return "'.get_lang('None').'";
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < boxes.length; i++) {
|
||||
boxes[i].checked = false;
|
||||
}
|
||||
buttoncheck = 0;
|
||||
return " '.get_lang('All').' ";
|
||||
}
|
||||
}
|
||||
</script>';
|
||||
|
||||
$annee = $_GET['annee'];
|
||||
$id_session = $_POST['id_session'];
|
||||
|
||||
// form1 annee = 0; composante= 0 etape = 0
|
||||
//if ($annee == "" && $composante == "" && $etape == "") {
|
||||
if (empty($annee) && empty($id_session)) {
|
||||
Display::display_header($tool_name);
|
||||
echo '<div style="align:center">';
|
||||
echo Display::return_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU')).' '.get_lang('LDAPSelectFilterOnUsersOU');
|
||||
echo '<form method="get" action="'.api_get_self().'"><br />';
|
||||
echo '<em>'.get_lang('LDAPOUAttributeFilter').' :</em> ';
|
||||
echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"> ';
|
||||
echo '<input type="submit" value="'.get_lang('Submit').'">';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
} elseif (!empty($annee) && empty($id_session)) {
|
||||
Display::display_header($tool_name);
|
||||
echo '<div style="align:center">';
|
||||
echo Display::return_icon(
|
||||
'course.png',
|
||||
get_lang('SelectSessionToImportUsersTo')
|
||||
).' '.get_lang('SelectSessionToImportUsersTo').'<br />';
|
||||
echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
|
||||
echo '<select name="id_session">';
|
||||
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$sql = "SELECT id,name,nbr_courses,access_start_date,access_end_date ".
|
||||
" FROM $tbl_session ".
|
||||
" ORDER BY name";
|
||||
$result = Database::query($sql);
|
||||
|
||||
$sessions = Database::store_result($result);
|
||||
$nbr_results = count($sessions);
|
||||
foreach ($sessions as $row) {
|
||||
echo '<option value="'.$row['id'].'">'.api_htmlentities($row['name']).' ('.$row['access_start_date'].' - '.$row['access_end_date'].')</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="submit" value="'.get_lang('Submit').'">';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
// form4 annee != 0; composante != 0 etape != 0
|
||||
//elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != 'yes') {
|
||||
elseif (!empty($annee) && !empty($id_session) && empty($_POST['confirmed'])) {
|
||||
Display::display_header($tool_name);
|
||||
echo '<div style="align: center;">';
|
||||
echo '<br />';
|
||||
echo '<br />';
|
||||
echo '<h3>'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'</h3>';
|
||||
//echo "Connection ...";
|
||||
$ds = ldap_connect($ldap_host, $ldap_port) or exit(get_lang('LDAPConnectionError'));
|
||||
ldap_set_version($ds);
|
||||
if ($ds) {
|
||||
$r = false;
|
||||
$res = ldap_handle_bind($ds, $r);
|
||||
|
||||
//$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))");
|
||||
//echo "(ou=*$annee,ou=$composante)";
|
||||
$sr = @ldap_search($ds, $ldap_basedn, "(ou=*$annee)");
|
||||
|
||||
$info = ldap_get_entries($ds, $sr);
|
||||
|
||||
for ($key = 0; $key < $info["count"]; $key++) {
|
||||
$nom_form[] = $info[$key]["sn"][0];
|
||||
$prenom_form[] = $info[$key]["givenname"][0];
|
||||
$email_form[] = $info[$key]["mail"][0];
|
||||
// Get uid from dn
|
||||
//$dn_array=ldap_explode_dn($info[$key]["dn"],1);
|
||||
//$username_form[] = $dn_array[0]; // uid is first key
|
||||
$username_form[] = $info[$key]['uid'][0];
|
||||
$outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
|
||||
//$val = ldap_get_values_len($ds, $entry, "userPassword");
|
||||
//$password_form[] = $val[0];
|
||||
$password_form[] = $info[$key]['userPassword'][0];
|
||||
}
|
||||
ldap_unbind($ds);
|
||||
asort($nom_form);
|
||||
reset($nom_form);
|
||||
$statut = 5;
|
||||
include 'ldap_form_add_users_group.php';
|
||||
} else {
|
||||
echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
|
||||
}
|
||||
echo '<br /><br />';
|
||||
echo '<a href="ldap_import_students.php?annee=">'.get_lang('BackToNewSearch').'</a>';
|
||||
echo '<br /><br />';
|
||||
echo '</div>';
|
||||
} elseif (!empty($annee) && !empty($id_session) && ($_POST['confirmed'] == 'yes')) {
|
||||
$id = $_POST['username_form'];
|
||||
$UserList = [];
|
||||
$userid_match_login = [];
|
||||
foreach ($id as $form_index => $user_id) {
|
||||
if (is_array($_POST['checkboxes']) && in_array($form_index, array_values($_POST['checkboxes']))) {
|
||||
$tmp = ldap_add_user($user_id);
|
||||
$UserList[] = $tmp;
|
||||
$userid_match_login[$tmp] = $user_id;
|
||||
}
|
||||
}
|
||||
if (!empty($_POST['id_session'])) {
|
||||
$num = 0;
|
||||
$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
foreach ($UserList as $user_id) {
|
||||
$res_user = Database::insert(
|
||||
$tbl_session_user,
|
||||
[
|
||||
'session_id' => intval($id_session),
|
||||
'user_id' => intval($user_id),
|
||||
'registered_at' => api_get_utc_datetime(),
|
||||
]
|
||||
);
|
||||
if ($res_user !== false) {
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($num > 0) {
|
||||
$sql = 'UPDATE '.$tbl_session.' SET nbr_users = (nbr_users + '.$num.') WHERE id = '.intval($id_session);
|
||||
$res = Database::query($sql);
|
||||
}
|
||||
header('Location: resume_session.php?id_session='.Security::remove_XSS($_POST['id_session']));
|
||||
exit;
|
||||
} else {
|
||||
$message = get_lang('NoUserAdded');
|
||||
Display::addFlash(Display::return_message($message, 'normal', false));
|
||||
Display::display_header($tool_name);
|
||||
}
|
||||
echo '<br /><br />';
|
||||
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
Display::display_footer();
|
||||
157
main/admin/ldap_synchro.php
Normal file
157
main/admin/ldap_synchro.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
/**
|
||||
* Code
|
||||
*/
|
||||
exit(); //not yet functional, needs to be revised
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$libpath = api_get_path(LIBRARY_PATH);
|
||||
require_once('../auth/ldap/authldap.php');
|
||||
$annee_base = date('Y');
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
//api_protect_admin_script(); // on vire la secu... qui n'a pas lieu d'etre ici (script de synchro)
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = array('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
|
||||
$interbreadcrumb[] = array('url' => api_get_self(), "name" => "Liste des sessions");
|
||||
|
||||
// Database Table Definitions
|
||||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
|
||||
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
|
||||
|
||||
$tbl_session_rel_etape = "session_rel_etape";
|
||||
|
||||
$message = "";
|
||||
|
||||
$result = Database::query("SELECT id, name FROM $tbl_session");
|
||||
$Sessions = Database::store_result($result);
|
||||
|
||||
$result = Database::query($sql);
|
||||
$users = Database::store_result($result);
|
||||
|
||||
foreach ($Sessions as $session) {
|
||||
$id_session = $session['id'];
|
||||
$name_session = $session['name'];
|
||||
$UserList = array();
|
||||
$UserUpdate = array();
|
||||
$UserAdd = array();
|
||||
|
||||
// Parse des code etape de la session
|
||||
/*
|
||||
$sql = "SELECT id_session, code_etape, etape_description, code_ufr, annee
|
||||
FROM $tbl_session_rel_etape
|
||||
WHERE id_session='$id_session'
|
||||
ORDER BY code_ufr, code_etape";
|
||||
$result = Database::query($sql);
|
||||
*/
|
||||
$ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
|
||||
ldap_set_version($ds);
|
||||
// Import des utilisateurs des etapes dans la session
|
||||
if ($ds)
|
||||
{
|
||||
$r = false;
|
||||
$res = ldap_handle_bind($ds, $r);
|
||||
$UserList = array();
|
||||
if ($result !== false)
|
||||
{
|
||||
//while($row = Database::fetch_array($result))
|
||||
//{
|
||||
/*
|
||||
$annee = $row['annee'];
|
||||
$code_ufr = $row['code_ufr'];
|
||||
$etape = $row['code_etape'];
|
||||
*/
|
||||
// LDAP Query
|
||||
// edupersonorgunitdn=ou=12CI1,ou=2006,ou=diploma,o=Paris1,dc=univ-paris1,dc=fr
|
||||
//etapescommented
|
||||
//$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "edupersonorgunitdn=ou=$etape,ou=$annee,ou=diploma,$LDAPbasedn");
|
||||
$sr = @ ldap_search($ds, $ldap_basedn, '(uid=*)');
|
||||
$info = ldap_get_entries($ds, $sr);
|
||||
for ($key = 0; $key < $info["count"]; $key++)
|
||||
{
|
||||
echo "<pre>";
|
||||
print_r($info[$key]);
|
||||
echo "</pre>";
|
||||
$lastname = api_utf8_decode($info[$key]["sn"][0]);
|
||||
$firstname = api_utf8_decode($info[$key]["givenname"][0]);
|
||||
$email = $info[$key]["mail"][0];
|
||||
// Get uid from dn
|
||||
$dn_array = ldap_explode_dn($info[$key]["dn"], 1);
|
||||
$username = $dn_array[0]; // uid is first key
|
||||
$outab[] = $info[$key]["edupersonprimaryaffiliation"][0]; // Ici "student"
|
||||
$val = ldap_get_values_len($ds, $sr, "userPassword");
|
||||
$password = $val[0];
|
||||
// Pour faciliter la gestion on ajoute le code "etape-annee"
|
||||
$official_code = $etape."-".$annee;
|
||||
$auth_source = "ldap";
|
||||
// Pas de date d'expiration d'etudiant (a recuperer par rapport au shadow expire LDAP)
|
||||
$expiration_date = '';
|
||||
$active = 1;
|
||||
// Ajout de l'utilisateur
|
||||
if (UserManager::is_username_available($username)) {
|
||||
$user_id = UserManager::create_user(
|
||||
$firstname,
|
||||
$lastname,
|
||||
$status,
|
||||
$email,
|
||||
$username,
|
||||
$password,
|
||||
$official_code,
|
||||
api_get_setting('platformLanguage'),
|
||||
$phone,
|
||||
$picture_uri,
|
||||
$auth_source,
|
||||
$expiration_date,
|
||||
$active
|
||||
);
|
||||
$UserAdd[] = $user_id;
|
||||
} else {
|
||||
$user = api_get_user_info_from_username($username);
|
||||
$user_id = $user['user_id'];
|
||||
UserManager::update_user(
|
||||
$user_id,
|
||||
$firstname,
|
||||
$lastname,
|
||||
$username,
|
||||
null,
|
||||
null,
|
||||
$email,
|
||||
$status,
|
||||
$official_code,
|
||||
$phone,
|
||||
$picture_uri,
|
||||
$expiration_date,
|
||||
$active
|
||||
);
|
||||
$UserUpdate[] = $user_id;
|
||||
}
|
||||
$UserList[] = $user_id;
|
||||
}
|
||||
//}
|
||||
}
|
||||
if (isset($included) && ($included))
|
||||
{
|
||||
$message .= "> $name_session: ".count($UserAdd)." ".get_lang('Added').' '.get_lang('And').' '.count($UserUpdate).' '.get_lang('Modified').'<br/>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print "> $name_session: ".count($UserAdd).get_lang('Added').' '.get_lang('And').' '.count($UserUpdate).' '.get_lang('Modified')."\n";
|
||||
}
|
||||
|
||||
// Une fois les utilisateurs importer dans la base des utilisateurs, on peux les affecter la session
|
||||
$result = Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id='$id_session'");
|
||||
$CourseList = array();
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
$CourseList[] = $row['c_id'];
|
||||
}
|
||||
|
||||
SessionManager::insertUsersInCourses($UserList, $CourseList, $id_session);
|
||||
}
|
||||
}
|
||||
201
main/admin/ldap_users_list.php
Normal file
201
main/admin/ldap_users_list.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @author Mustapha Alouani
|
||||
*
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
require '../auth/ldap/authldap.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$action = @$_GET["action"] ?: null;
|
||||
$login_as_user_id = @$_GET["user_id"] ?: null;
|
||||
|
||||
// Login as ...
|
||||
if ($action == "login_as" && !empty($login_as_user_id)) {
|
||||
login_user($login_as_user_id);
|
||||
}
|
||||
|
||||
//if we already have a session id and a user...
|
||||
/*
|
||||
if (($_GET['action']=="add_user") && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && $_GET['id_session']>0 ){
|
||||
header('Location: ldap_import_students_to_session.php?id_session='.$_GET['id_session'].'&ldap_user='.$_GET['id']);
|
||||
}
|
||||
*/
|
||||
|
||||
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
|
||||
$tool_name = get_lang('SearchLDAPUsers');
|
||||
//Display::display_header($tool_name); //cannot display now as we need to redirect
|
||||
//api_display_tool_title($tool_name);
|
||||
|
||||
if (isset($_GET['action'])) {
|
||||
$check = Security::check_token('get');
|
||||
if ($check) {
|
||||
switch ($_GET['action']) {
|
||||
case 'show_message':
|
||||
Display::addFlash(Display::return_message($_GET['message'], 'normal'));
|
||||
Display::display_header($tool_name);
|
||||
break;
|
||||
case 'delete_user':
|
||||
if ($user_id != $_user['user_id'] && UserManager::delete_user($_GET['user_id'])) {
|
||||
Display::addFlash(Display::return_message(get_lang('UserDeleted'), 'normal'));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('CannotDeleteUser'), 'error'));
|
||||
}
|
||||
Display::display_header($tool_name);
|
||||
break;
|
||||
case 'lock':
|
||||
$message = lock_unlock_user('lock', $_GET['user_id']);
|
||||
Display::addFlash(Display::return_message($message, 'normal'));
|
||||
Display::display_header($tool_name);
|
||||
break;
|
||||
case 'unlock':
|
||||
$message = lock_unlock_user('unlock', $_GET['user_id']);
|
||||
Display::addFlash(Display::return_message($message, 'normal'));
|
||||
Display::display_header($tool_name);
|
||||
break;
|
||||
case 'add_user':
|
||||
$id = $_GET['id'];
|
||||
$UserList = [];
|
||||
$userid_match_login = [];
|
||||
foreach ($id as $user_id) {
|
||||
$tmp = ldap_add_user($user_id);
|
||||
$UserList[] = $tmp;
|
||||
$userid_match_login[$tmp] = $user_id;
|
||||
}
|
||||
if (isset($_GET['id_session']) && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && ($_GET['id_session'] > 0)) {
|
||||
ldap_add_user_to_session($UserList, $_GET['id_session']);
|
||||
header('Location: resume_session.php?id_session='.intval($_GET['id_session']));
|
||||
} else {
|
||||
if (count($userid_match_login) > 0) {
|
||||
$message = get_lang('LDAPUsersAddedOrUpdated').':<br />';
|
||||
foreach ($userid_match_login as $user_id => $login) {
|
||||
$message .= '- '.$login.'<br />';
|
||||
}
|
||||
} else {
|
||||
$message = get_lang('NoUserAdded');
|
||||
}
|
||||
Display::addFlash(Display::return_message($message, 'normal', false));
|
||||
Display::display_header($tool_name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Display::display_header($tool_name);
|
||||
}
|
||||
Security::clear_token();
|
||||
} else {
|
||||
Display::display_header($tool_name);
|
||||
}
|
||||
} else {
|
||||
Display::display_header($tool_name);
|
||||
}
|
||||
|
||||
if (isset($_POST['action'])) {
|
||||
$check = Security::check_token('get');
|
||||
if ($check) {
|
||||
switch ($_POST['action']) {
|
||||
case 'delete':
|
||||
$number_of_selected_users = count($_POST['id']);
|
||||
$number_of_deleted_users = 0;
|
||||
foreach ($_POST['id'] as $index => $user_id) {
|
||||
if ($user_id != $_user['user_id']) {
|
||||
if (UserManager::delete_user($user_id)) {
|
||||
$number_of_deleted_users++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($number_of_selected_users == $number_of_deleted_users) {
|
||||
echo Display::return_message(get_lang('SelectedUsersDeleted'), 'normal');
|
||||
} else {
|
||||
echo Display::return_message(get_lang('SomeUsersNotDeleted'), 'error');
|
||||
}
|
||||
break;
|
||||
case 'add_user':
|
||||
$number_of_selected_users = count($_POST['id']);
|
||||
$number_of_added_users = 0;
|
||||
$UserList = [];
|
||||
foreach ($_POST['id'] as $index => $user_id) {
|
||||
if ($user_id != $_user['user_id']) {
|
||||
$UserList[] = ldap_add_user($user_id);
|
||||
}
|
||||
}
|
||||
if (isset($_GET['id_session']) && (trim($_GET['id_session']) != "")) {
|
||||
addUserToSession($UserList, $_GET['id_session']);
|
||||
}
|
||||
if (count($UserList) > 0) {
|
||||
echo Display::return_message(
|
||||
count($UserList)." ".get_lang('LDAPUsersAdded')
|
||||
);
|
||||
} else {
|
||||
echo Display::return_message(get_lang('NoUserAdded'));
|
||||
}
|
||||
break;
|
||||
}
|
||||
Security::clear_token();
|
||||
}
|
||||
}
|
||||
|
||||
$form = new FormValidator('advanced_search', 'get');
|
||||
$form->addText('keyword_username', get_lang('LoginName'), false);
|
||||
if (api_is_western_name_order()) {
|
||||
$form->addText('keyword_firstname', get_lang('FirstName'), false);
|
||||
$form->addText('keyword_lastname', get_lang('LastName'), false);
|
||||
} else {
|
||||
$form->addText('keyword_lastname', get_lang('LastName'), false);
|
||||
$form->addText('keyword_firstname', get_lang('FirstName'), false);
|
||||
}
|
||||
if (isset($_GET['id_session'])) {
|
||||
$form->addElement('hidden', 'id_session', $_GET['id_session']);
|
||||
}
|
||||
|
||||
$type = [];
|
||||
$type["all"] = get_lang('All');
|
||||
$type["employee"] = get_lang('Teacher');
|
||||
$type["student"] = get_lang('Student');
|
||||
|
||||
$form->addElement('select', 'keyword_type', get_lang('Status'), $type);
|
||||
// Structure a rajouer ??
|
||||
$form->addElement('submit', 'submit', get_lang('Ok'));
|
||||
//$defaults['keyword_active'] = 1;
|
||||
//$defaults['keyword_inactive'] = 1;
|
||||
//$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
$parameters['keyword_username'] = @$_GET['keyword_username'] ?: null;
|
||||
$parameters['keyword_firstname'] = @$_GET['keyword_firstname'] ?: null;
|
||||
$parameters['keyword_lastname'] = @$_GET['keyword_lastname'] ?: null;
|
||||
$parameters['keyword_email'] = @$_GET['keyword_email'] ?: null;
|
||||
if (isset($_GET['id_session'])) {
|
||||
$parameters['id_session'] = $_GET['id_session'];
|
||||
}
|
||||
// Create a sortable table with user-data
|
||||
|
||||
$parameters['sec_token'] = Security::get_token();
|
||||
$table = new SortableTable(
|
||||
'users',
|
||||
'ldap_get_number_of_users',
|
||||
'ldap_get_user_data',
|
||||
(api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
|
||||
);
|
||||
$table->set_additional_parameters($parameters);
|
||||
$table->set_header(0, '', false);
|
||||
$table->set_header(1, get_lang('LoginName'));
|
||||
if (api_is_western_name_order()) {
|
||||
$table->set_header(2, get_lang('FirstName'));
|
||||
$table->set_header(3, get_lang('LastName'));
|
||||
} else {
|
||||
$table->set_header(2, get_lang('LastName'));
|
||||
$table->set_header(3, get_lang('FirstName'));
|
||||
}
|
||||
$table->set_header(4, get_lang('Email'));
|
||||
$table->set_header(5, get_lang('Actions'));
|
||||
//$table->set_column_filter(5, 'email_filter');
|
||||
//$table->set_column_filter(5, 'active_filter');
|
||||
$table->set_column_filter(5, 'modify_filter');
|
||||
$table->set_form_actions(['add_user' => get_lang('AddLDAPUsers')]);
|
||||
$table->display();
|
||||
|
||||
Display::display_footer();
|
||||
53
main/admin/ldap_users_synchro.php
Normal file
53
main/admin/ldap_users_synchro.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
/**
|
||||
* Code.
|
||||
*/
|
||||
exit(); //not yet functional, needs to be revised
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require '../inc/global.inc.php';
|
||||
$libpath = api_get_path(LIBRARY_PATH);
|
||||
require "../auth/ldap/authldap.php";
|
||||
$annee_base = date('Y');
|
||||
// setting the section (for the tabs)
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', "name" => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => api_get_self(), "name" => get_lang('SessionsList')];
|
||||
|
||||
$id_session = intval($_GET['id_session']);
|
||||
|
||||
$formSent = 0;
|
||||
$errorMsg = $firstLetterUser = $firstLetterSession = '';
|
||||
$UserList = $SessionList = [];
|
||||
$users = $sessions = [];
|
||||
$page = intval($_GET['page']);
|
||||
$action = $_REQUEST['action'];
|
||||
|
||||
$tool_name = get_lang('Synchro LDAP : Import Etudiants/Etapes dans session');
|
||||
Display::display_header($tool_name);
|
||||
//api_display_tool_title($tool_name);
|
||||
|
||||
?>
|
||||
<form method="get" action="<?php echo api_get_self(); ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
|
||||
<select name="action">
|
||||
<option value="synchro"><?php echo get_lang('Synchro LDAP : Import Etudiants/Etapes dans toutes les sessions'); ?></option>
|
||||
</select>
|
||||
<input type="submit" value="<?php echo get_lang('Ok'); ?>">
|
||||
</form>
|
||||
|
||||
<?php
|
||||
if (isset($action) && ($action == "synchro")) {
|
||||
$included = true;
|
||||
require 'ldap_synchro.php';
|
||||
echo Display::return_message($message, 'normal', false);
|
||||
}
|
||||
Display::display_footer();
|
||||
?>
|
||||
211
main/admin/legal_add.php
Normal file
211
main/admin/legal_add.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Management of legal conditions.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
if ('true' !== api_get_setting('allow_terms_conditions')) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
// Create the form
|
||||
$form = new FormValidator('addlegal');
|
||||
|
||||
$defaults = [];
|
||||
$term_preview = [
|
||||
'type' => 0,
|
||||
'content' => '',
|
||||
'changes' => '',
|
||||
];
|
||||
|
||||
$extraField = new ExtraField('terms_and_condition');
|
||||
|
||||
$types = LegalManager::getTreatmentTypeList();
|
||||
|
||||
foreach ($types as $variable => $name) {
|
||||
$label = 'PersonalData'.ucfirst($name).'Title';
|
||||
$params = [
|
||||
'variable' => $variable,
|
||||
'display_text' => $label,
|
||||
'field_type' => ExtraField::FIELD_TYPE_TEXTAREA,
|
||||
'default_value' => '',
|
||||
'visible' => true,
|
||||
'changeable' => true,
|
||||
'filter' => true,
|
||||
'visible_to_self' => true,
|
||||
'visible_to_others' => true,
|
||||
];
|
||||
$extraField->save($params);
|
||||
}
|
||||
|
||||
if ($form->validate()) {
|
||||
$check = Security::check_token('post');
|
||||
if ($check) {
|
||||
$values = $form->getSubmitValues();
|
||||
$lang = $values['language'];
|
||||
// language id
|
||||
$lang = api_get_language_id($lang);
|
||||
$type = 0;
|
||||
if (isset($values['type'])) {
|
||||
$type = $values['type'];
|
||||
}
|
||||
$content = '';
|
||||
if (isset($values['content'])) {
|
||||
$content = $values['content'];
|
||||
}
|
||||
$changes = '';
|
||||
if (isset($values['changes'])) {
|
||||
$changes = $values['changes'];
|
||||
}
|
||||
|
||||
$submit = $values['send'];
|
||||
|
||||
$default['content'] = $content;
|
||||
if (isset($values['language'])) {
|
||||
if ('back' == $submit) {
|
||||
header('Location: legal_add.php');
|
||||
exit;
|
||||
} elseif ('save' === $submit) {
|
||||
$id = LegalManager::add($lang, $content, $type, $changes, $values);
|
||||
if (!empty($id)) {
|
||||
Display::addFlash(Display::return_message(get_lang('TermAndConditionSaved'), 'success'));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('TermAndConditionNotSaved'), 'warning'));
|
||||
}
|
||||
Security::clear_token();
|
||||
$tok = Security::get_token();
|
||||
header('Location: legal_list.php?sec_token='.$tok);
|
||||
exit();
|
||||
} elseif ($submit === 'preview') {
|
||||
$defaults['type'] = $type;
|
||||
$defaults['content'] = $content;
|
||||
$defaults['changes'] = $changes;
|
||||
$term_preview = $defaults;
|
||||
$term_preview['type'] = (int) $_POST['type'];
|
||||
} else {
|
||||
$my_lang = $_POST['language'];
|
||||
if (isset($_POST['language'])) {
|
||||
$all_langs = api_get_languages();
|
||||
if (in_array($my_lang, $all_langs['folder'])) {
|
||||
$language = api_get_language_id($my_lang);
|
||||
$term_preview = LegalManager::get_last_condition($language);
|
||||
$defaults = $term_preview;
|
||||
if (!$term_preview) {
|
||||
// there are not terms and conditions
|
||||
$term_preview['type'] = -1;
|
||||
$defaults['type'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
|
||||
if (isset($_POST['send'])) {
|
||||
Security::clear_token();
|
||||
}
|
||||
$token = Security::get_token();
|
||||
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$defaults['sec_token'] = $token;
|
||||
$form->addElement('header', get_lang('DisplayTermsConditions'));
|
||||
$jqueryReady = '';
|
||||
|
||||
if (isset($_POST['language'])) {
|
||||
$form->addElement('static', Security::remove_XSS($_POST['language']));
|
||||
$form->addElement('hidden', 'language', Security::remove_XSS($_POST['language']));
|
||||
$form->addHtmlEditor(
|
||||
'content',
|
||||
get_lang('Content'),
|
||||
true,
|
||||
false,
|
||||
['ToolbarSet' => 'terms_and_conditions', 'Width' => '100%', 'Height' => '250']
|
||||
);
|
||||
|
||||
$form->addElement('radio', 'type', '', get_lang('HTMLText'), '0');
|
||||
$form->addElement('radio', 'type', '', get_lang('PageLink'), '1');
|
||||
|
||||
$preview = LegalManager::show_last_condition($term_preview);
|
||||
|
||||
if ($term_preview['type'] != -1) {
|
||||
$preview = LegalManager::replaceTags($preview);
|
||||
$form->addElement('label', get_lang('Preview'), $preview);
|
||||
}
|
||||
|
||||
$termId = isset($term_preview['id']) ? $term_preview['id'] : 0;
|
||||
$returnParams = $extraField->addElements(
|
||||
$form,
|
||||
$termId,
|
||||
[],
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
true,
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$jqueryReady = $returnParams['jquery_ready_content'];
|
||||
|
||||
$form->addElement('textarea', 'changes', get_lang('ExplainChanges'), ['width' => '20']);
|
||||
|
||||
// Submit & preview button
|
||||
$buttons = '<div class="row" align="center">
|
||||
<div class="formw">
|
||||
<button type="submit" class="btn btn-default back" name="send" value="back">'.get_lang('Back').'</button>
|
||||
<button type="submit" class="btn btn-default search" name="send" value="preview">'.get_lang('Preview').'</button>
|
||||
<button type="submit" class="btn btn-primary save" name="send" value="save">'.get_lang('Save').'</button>
|
||||
</div>
|
||||
</div>';
|
||||
$form->addElement('html', $buttons);
|
||||
} else {
|
||||
$form->addSelectLanguage('language', get_lang('Language'), null, []);
|
||||
$form->addButtonSearch(get_lang('Load'), 'send');
|
||||
}
|
||||
|
||||
$tool_name = get_lang('AddTermsAndConditions');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function () {
|
||||
'.$jqueryReady.'
|
||||
});
|
||||
</script>';
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
echo '<script>
|
||||
function sendlang() {
|
||||
document.addlegal.sec_token.value=\''.$token.'\';
|
||||
document.addlegal.submit();
|
||||
}
|
||||
</script>';
|
||||
|
||||
// action menu
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/legal_list.php">'.
|
||||
Display::return_icon('search.gif', get_lang('EditTermsAndConditions'), '').
|
||||
get_lang('AllVersions').'</a>';
|
||||
echo '</div>';
|
||||
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
Display::display_footer();
|
||||
62
main/admin/legal_list.php
Normal file
62
main/admin/legal_list.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Repository\LegalRepository;
|
||||
|
||||
/**
|
||||
* Sessions list script.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$tool_name = get_lang('TermsAndConditions');
|
||||
Display::display_header($tool_name);
|
||||
|
||||
$parameters['sec_token'] = Security::get_token();
|
||||
|
||||
// action menu
|
||||
echo '<div class="actions">';
|
||||
echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/legal_add.php">';
|
||||
echo Display::return_icon(
|
||||
'edit.png',
|
||||
get_lang('EditTermsAndConditions')
|
||||
);
|
||||
echo get_lang('EditTermsAndConditions').'</a> ';
|
||||
echo '</div>';
|
||||
|
||||
$em = Database::getManager();
|
||||
/** @var LegalRepository $legalTermsRepo */
|
||||
$legalTermsRepo = $em->getRepository('ChamiloCoreBundle:Legal');
|
||||
$legalCount = $legalTermsRepo->countAllActiveLegalTerms();
|
||||
$languages = api_get_languages();
|
||||
$available_languages = count($languages['folder']);
|
||||
if ($legalCount != $available_languages) {
|
||||
echo Display::return_message(get_lang('YouShouldCreateTermAndConditionsForAllAvailableLanguages'), 'warning');
|
||||
}
|
||||
|
||||
$table = new SortableTable('conditions', 'count_mask', 'get_legal_data_mask', 2);
|
||||
$table->set_additional_parameters($parameters);
|
||||
$table->set_header(0, get_lang('Version'), false, 'width="15px"');
|
||||
$table->set_header(1, get_lang('Language'), false, 'width="30px"');
|
||||
$table->set_header(2, get_lang('Content'), false);
|
||||
$table->set_header(3, get_lang('Changes'), false, 'width="60px"');
|
||||
$table->set_header(4, get_lang('Type'), false, 'width="60px"');
|
||||
$table->set_header(5, get_lang('Date'), false, 'width="50px"');
|
||||
$table->display();
|
||||
|
||||
// this 2 "mask" function are here just because the SortableTable
|
||||
function get_legal_data_mask($id, $params = null, $row = null)
|
||||
{
|
||||
return LegalManager::get_legal_data($id, $params, $row);
|
||||
}
|
||||
|
||||
function count_mask()
|
||||
{
|
||||
return LegalManager::count();
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
96
main/admin/periodic_export.php
Normal file
96
main/admin/periodic_export.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
exit;
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
api_set_more_memory_and_time_limits();
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$nameTools = get_lang('PeriodicExport');
|
||||
$export = '';
|
||||
|
||||
Display::display_header($nameTools);
|
||||
|
||||
echo Display::page_header($nameTools);
|
||||
|
||||
$form = new FormValidator('special_exports', 'post');
|
||||
$form->addDateRangePicker('date', get_lang('Dates'));
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
|
||||
$form->display();
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
$urlId = api_get_current_access_url_id();
|
||||
$startDate = $values['date_start'];
|
||||
$endDate = $values['date_end'];
|
||||
|
||||
// Count active users in the platform
|
||||
$countUsers = UserManager::get_number_of_users(null, $urlId, 1);
|
||||
// Count user connected in those dates
|
||||
$connectedUsers = Statistics::getLoginCount($startDate, $endDate);
|
||||
|
||||
$activeCourses = CourseManager::countActiveCourses($urlId);
|
||||
$totalCourses = CourseManager::count_courses($urlId);
|
||||
|
||||
$total = Tracking::getTotalTimeSpentOnThePlatform();
|
||||
|
||||
$now = api_get_utc_datetime();
|
||||
|
||||
$beforeDateStart = new DateTime('-90 days', new DateTimeZone('UTC'));
|
||||
$end = $beforeDateStart->format('Y-m-d H:i:s');
|
||||
|
||||
$thisTrimester = Tracking::getTotalTimeSpentOnThePlatform($end, $now);
|
||||
|
||||
$beforeDateEnd = new DateTime('-180 days', new DateTimeZone('UTC'));
|
||||
$start = $beforeDateEnd->format('Y-m-d H:i:s');
|
||||
|
||||
$lastTrimester = Tracking::getTotalTimeSpentOnThePlatform($start, $end);
|
||||
|
||||
//var_dump($countUsers, $connectedUsers, $activeCourses, $totalCourses, $total, $thisTrimester, $lastTrimester);
|
||||
|
||||
$courses = Statistics::getCoursesWithActivity($startDate, $endDate);
|
||||
|
||||
$totalUsers = 0;
|
||||
$totalCertificates = 0;
|
||||
foreach ($courses as $courseId) {
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
|
||||
$countUsers = CourseManager::get_user_list_from_course_code(
|
||||
$courseInfo['code'],
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$totalUsers += $countUsers;
|
||||
|
||||
$categories = Category::load(
|
||||
null,
|
||||
null,
|
||||
$courseInfo['code'],
|
||||
null,
|
||||
false,
|
||||
0
|
||||
);
|
||||
|
||||
$category = null;
|
||||
$certificateCount = 0;
|
||||
if (!empty($categories)) {
|
||||
$category = current($categories);
|
||||
// @todo use count
|
||||
$certificateCount = count(GradebookUtils::get_list_users_certificates($categoryId));
|
||||
$totalCertificates += $certificateCount;
|
||||
}
|
||||
}
|
||||
|
||||
$totalUsersCourses = CourseManager::totalSubscribedUsersInCourses($urlId);
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
220
main/admin/promotions.php
Normal file
220
main/admin/promotions.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?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();
|
||||
|
||||
//Adds the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'career_dashboard.php', 'name' => get_lang('CareersAndPromotions')];
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
|
||||
$check = Security::check_token('request');
|
||||
$token = Security::get_token();
|
||||
|
||||
if ($action == 'add') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'promotions.php',
|
||||
'name' => get_lang('Promotions'),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
|
||||
} elseif ($action == 'edit') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'promotions.php',
|
||||
'name' => get_lang('Promotions'),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
|
||||
} else {
|
||||
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Promotions')];
|
||||
}
|
||||
|
||||
// The header.
|
||||
Display::display_header('');
|
||||
|
||||
// Tool name
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'add') {
|
||||
$tool = 'Add';
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_self(),
|
||||
'name' => get_lang('Promotion'),
|
||||
];
|
||||
}
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
|
||||
$tool = 'Modify';
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_self(),
|
||||
'name' => get_lang('Promotion'),
|
||||
];
|
||||
}
|
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_promotions';
|
||||
//The order is important you need to check the model.ajax.php the $column variable
|
||||
$columns = [
|
||||
get_lang('Name'),
|
||||
get_lang('Career'),
|
||||
get_lang('Description'),
|
||||
get_lang('Actions'),
|
||||
];
|
||||
$column_model = [
|
||||
[
|
||||
'name' => 'name',
|
||||
'index' => 'name',
|
||||
'width' => '180',
|
||||
'align' => 'left',
|
||||
],
|
||||
[
|
||||
'name' => 'career',
|
||||
'index' => 'career',
|
||||
'width' => '100',
|
||||
'align' => 'left',
|
||||
],
|
||||
[
|
||||
'name' => 'description',
|
||||
'index' => 'description',
|
||||
'width' => '500',
|
||||
'align' => 'left',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
[
|
||||
'name' => 'actions',
|
||||
'index' => 'actions',
|
||||
'width' => '100',
|
||||
'align' => 'left',
|
||||
'formatter' => 'action_formatter',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
];
|
||||
$extra_params['autowidth'] = 'true'; //use the width of the parent
|
||||
//$extra_params['editurl'] = $url; //use the width of the parent
|
||||
|
||||
$extra_params['height'] = 'auto'; //use the width of the parent
|
||||
//With this function we can add actions to the jgrid
|
||||
$action_links = 'function action_formatter (cellvalue, options, rowObject) {
|
||||
return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'">'.Display::return_icon('session_to_promotion.png', get_lang('SubscribeSessionsToPromotions'), '', ICON_SIZE_SMALL).'</a>'.
|
||||
' <a href="?action=edit&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="?sec_token='.$token.'&action=copy&id=\'+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="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a> \';
|
||||
}';
|
||||
|
||||
?>
|
||||
<script>
|
||||
$(function() {
|
||||
<?php
|
||||
echo Display::grid_js('promotions', $url, $columns, $column_model, $extra_params, [], $action_links, true);
|
||||
?>
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
$promotion = new Promotion();
|
||||
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
//First you need to create a Career
|
||||
$career = new Career();
|
||||
$careers = $career->get_all();
|
||||
if (empty($careers)) {
|
||||
$url = Display::url(get_lang('YouNeedToCreateACareerFirst'), 'careers.php?action=add');
|
||||
echo Display::return_message($url, 'normal', false);
|
||||
Display::display_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
|
||||
$form = $promotion->return_form($url, 'add');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
if ($check) {
|
||||
$values = $form->exportValues();
|
||||
$res = $promotion->save($values);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('ItemAdded'), 'confirm');
|
||||
}
|
||||
}
|
||||
$promotion->display();
|
||||
} else {
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM), api_get_self());
|
||||
echo '</div>';
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
//Editing
|
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
|
||||
$form = $promotion->return_form($url, 'edit');
|
||||
|
||||
// The validation or display
|
||||
if ($form->validate()) {
|
||||
if ($check) {
|
||||
$values = $form->exportValues();
|
||||
$res = $promotion->update($values);
|
||||
$promotion->update_all_sessions_status_by_promotion_id($values['id'], $values['status']);
|
||||
if ($res) {
|
||||
echo Display::return_message(get_lang('PromotionUpdated').': '.$values['name'], 'confirm');
|
||||
}
|
||||
}
|
||||
$promotion->display();
|
||||
} else {
|
||||
echo '<div class="actions">';
|
||||
echo Display::url(
|
||||
Display::return_icon(
|
||||
'back.png',
|
||||
get_lang('Back'),
|
||||
'',
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_self()
|
||||
);
|
||||
echo '</div>';
|
||||
$form->addElement('hidden', 'sec_token');
|
||||
$form->setConstants(['sec_token' => $token]);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if ($check) {
|
||||
// Action handling: deleting an obj
|
||||
$res = $promotion->delete($_GET['id']);
|
||||
if ($res) {
|
||||
return Display::return_message(get_lang('ItemDeleted'), 'confirm');
|
||||
}
|
||||
}
|
||||
$promotion->display();
|
||||
break;
|
||||
case 'copy':
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
if ($check) {
|
||||
$res = $promotion->copy($_GET['id'], null, true);
|
||||
if ($res) {
|
||||
echo Display::return_message(
|
||||
get_lang('ItemCopied').' - '.get_lang(
|
||||
'ExerciseAndLPsAreInvisibleInTheNewCourse'
|
||||
),
|
||||
'confirm'
|
||||
);
|
||||
}
|
||||
}
|
||||
$promotion->display();
|
||||
break;
|
||||
default:
|
||||
$promotion->display();
|
||||
break;
|
||||
}
|
||||
Display::display_footer();
|
||||
389
main/admin/questions.php
Normal file
389
main/admin/questions.php
Normal file
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CQuiz;
|
||||
use Chamilo\CourseBundle\Entity\CQuizQuestion;
|
||||
use ChamiloSession as Session;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Knp\Component\Pager\Paginator;
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script();
|
||||
|
||||
Session::erase('objExercise');
|
||||
Session::erase('objQuestion');
|
||||
Session::erase('objAnswer');
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$action = $_REQUEST['action'] ?? '';
|
||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : '';
|
||||
$description = $_REQUEST['description'] ?? '';
|
||||
$title = $_REQUEST['title'] ?? '';
|
||||
$page = isset($_GET['page']) && !empty($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
|
||||
// Prepare lists for form
|
||||
// Courses list
|
||||
$courseIdChanged = isset($_GET['course_id_changed']) ? (int) $_GET['course_id_changed'] : null;
|
||||
$selectedCourse = isset($_GET['selected_course']) ? (int) $_GET['selected_course'] : null;
|
||||
$courseList = CourseManager::get_courses_list(0, 0, 'title');
|
||||
$courseSelectionList = ['-1' => get_lang('Select')];
|
||||
foreach ($courseList as $item) {
|
||||
$courseItemId = $item['real_id'];
|
||||
$courseInfo = api_get_course_info_by_id($courseItemId);
|
||||
$courseSelectionList[$courseItemId] = '';
|
||||
if ($courseItemId == api_get_course_int_id()) {
|
||||
$courseSelectionList[$courseItemId] = '> ';
|
||||
}
|
||||
$courseSelectionList[$courseItemId] .= $courseInfo['title'];
|
||||
}
|
||||
|
||||
// Difficulty list (only from 0 to 5)
|
||||
$questionLevel = isset($_REQUEST['question_level']) ? (int) $_REQUEST['question_level'] : -1;
|
||||
$levels = [
|
||||
-1 => get_lang('All'),
|
||||
0 => 0,
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
];
|
||||
// Answer type
|
||||
$answerType = isset($_REQUEST['answer_type']) ? (int) $_REQUEST['answer_type'] : null;
|
||||
$questionList = Question::getQuestionTypeList();
|
||||
$questionTypesList = [];
|
||||
$questionTypesList['-1'] = get_lang('All');
|
||||
foreach ($questionList as $key => $item) {
|
||||
$questionTypesList[$key] = get_lang($item[1]);
|
||||
}
|
||||
|
||||
$form = new FormValidator('admin_questions', 'get');
|
||||
$form->addHeader(get_lang('Questions'));
|
||||
$form
|
||||
->addText(
|
||||
'id',
|
||||
get_lang('Id'),
|
||||
false
|
||||
);
|
||||
$form
|
||||
->addText(
|
||||
'title',
|
||||
get_lang('Title'),
|
||||
false
|
||||
);
|
||||
$form
|
||||
->addText(
|
||||
'description',
|
||||
get_lang('Description'),
|
||||
false
|
||||
);
|
||||
$form
|
||||
->addSelect(
|
||||
'selected_course',
|
||||
[get_lang('Course'), get_lang('CourseInWhichTheQuestionWasInitiallyCreated')],
|
||||
$courseSelectionList,
|
||||
['id' => 'selected_course']
|
||||
)
|
||||
->setSelected($selectedCourse);
|
||||
$form
|
||||
->addSelect(
|
||||
'question_level',
|
||||
get_lang('Difficulty'),
|
||||
$levels,
|
||||
['id' => 'question_level']
|
||||
)
|
||||
->setSelected($questionLevel);
|
||||
$form
|
||||
->addSelect(
|
||||
'answer_type',
|
||||
get_lang('AnswerType'),
|
||||
$questionTypesList,
|
||||
['id' => 'answer_type']
|
||||
)
|
||||
->setSelected($answerType);
|
||||
|
||||
$form->addHidden('form_sent', 1);
|
||||
$form->addHidden('course_id_changed', '0');
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
|
||||
$questions = [];
|
||||
$pagination = '';
|
||||
$formSent = isset($_REQUEST['form_sent']) ? (int) $_REQUEST['form_sent'] : 0;
|
||||
$length = 20;
|
||||
$questionCount = 0;
|
||||
$start = 0;
|
||||
$end = 0;
|
||||
$pdfContent = '';
|
||||
|
||||
$params = [
|
||||
'id' => $id,
|
||||
'title' => Security::remove_XSS($title),
|
||||
'description' => Security::remove_XSS($description),
|
||||
'selected_course' => $selectedCourse,
|
||||
'question_level' => $questionLevel,
|
||||
'answer_type' => $answerType,
|
||||
];
|
||||
if ($formSent) {
|
||||
$params['form_sent'] = 1;
|
||||
$em = Database::getManager();
|
||||
$repo = $em->getRepository('ChamiloCourseBundle:CQuizQuestion');
|
||||
$criteria = new Criteria();
|
||||
if (!empty($id)) {
|
||||
$criteria->where($criteria->expr()->eq('iid', $id));
|
||||
}
|
||||
|
||||
if (!empty($description)) {
|
||||
$criteria->orWhere($criteria->expr()->contains('description', $description."\r"));
|
||||
$criteria->orWhere($criteria->expr()->eq('description', $description));
|
||||
$criteria->orWhere($criteria->expr()->eq('description', '<p>'.$description.'</p>'));
|
||||
}
|
||||
|
||||
if (!empty($title)) {
|
||||
$criteria->orWhere($criteria->expr()->contains('question', "%$title%"));
|
||||
}
|
||||
|
||||
if (-1 !== $selectedCourse) {
|
||||
$criteria->andWhere($criteria->expr()->eq('cId', $selectedCourse));
|
||||
}
|
||||
|
||||
if (-1 !== $questionLevel) {
|
||||
$criteria->andWhere($criteria->expr()->eq('level', $questionLevel));
|
||||
}
|
||||
if (-1 !== $answerType) {
|
||||
$criteria->andWhere($criteria->expr()->eq('type', $answerType));
|
||||
}
|
||||
|
||||
$questions = $repo->matching($criteria);
|
||||
|
||||
$url = api_get_self().'?'.http_build_query($params);
|
||||
$form->setDefaults($params);
|
||||
$questionCount = count($questions);
|
||||
|
||||
if ('export_pdf' === $action) {
|
||||
$length = $questionCount;
|
||||
}
|
||||
|
||||
$paginator = new Paginator();
|
||||
$pagination = $paginator->paginate($questions, $page, $length);
|
||||
$pagination->setItemNumberPerPage($length);
|
||||
$pagination->setCurrentPageNumber($page);
|
||||
$pagination->renderer = function ($data) use ($url) {
|
||||
$render = '<ul class="pagination">';
|
||||
for ($i = 1; $i <= $data['pageCount']; $i++) {
|
||||
$page = (int) $i;
|
||||
$pageContent = '<li><a href="'.$url.'&page='.$page.'">'.$page.'</a></li>';
|
||||
if ($data['current'] == $page) {
|
||||
$pageContent = '<li class="active"><a href="#" >'.$page.'</a></li>';
|
||||
}
|
||||
$render .= $pageContent;
|
||||
}
|
||||
$render .= '</ul>';
|
||||
|
||||
return $render;
|
||||
};
|
||||
|
||||
if ($pagination) {
|
||||
$urlExercise = api_get_path(WEB_CODE_PATH).'exercise/admin.php?';
|
||||
$exerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?';
|
||||
$warningText = addslashes(api_htmlentities(get_lang('ConfirmYourChoice')));
|
||||
|
||||
/** @var CQuizQuestion $question */
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$index = $i;
|
||||
if (!empty($page)) {
|
||||
$index = ($page - 1) * $length + $i;
|
||||
}
|
||||
if (0 === $i) {
|
||||
$start = $index;
|
||||
}
|
||||
if (!isset($pagination[$index])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($i < $length) {
|
||||
$end = $index;
|
||||
}
|
||||
$question = &$pagination[$index];
|
||||
$courseId = $question->getCId();
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
$courseCode = $courseInfo['code'];
|
||||
$question->courseCode = $courseCode;
|
||||
// Creating empty exercise
|
||||
$exercise = new Exercise($courseId);
|
||||
/* @var Question $questionObject */
|
||||
$questionObject = Question::read($question->getIid(), $courseInfo);
|
||||
|
||||
ob_start();
|
||||
ExerciseLib::showQuestion(
|
||||
$exercise,
|
||||
$question->getIid(),
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true
|
||||
);
|
||||
$question->questionData = ob_get_contents();
|
||||
|
||||
if ('export_pdf' === $action) {
|
||||
$pdfContent .= '<span style="color:#000; font-weight:bold; font-size:x-large;">#'.$question->getIid().'. '.$question->getQuestion().'</span><br />';
|
||||
$pdfContent .= '<span style="color:#444;">('.$questionTypesList[$question->getType()].') ['.get_lang('Source').': '.$courseCode.']</span><br />';
|
||||
$pdfContent .= $question->getDescription().'<br />';
|
||||
$pdfContent .= $question->questionData;
|
||||
continue;
|
||||
}
|
||||
|
||||
$deleteUrl = $url.'&'.http_build_query([
|
||||
'courseId' => $question->getCId(),
|
||||
'questionId' => $question->getIid(),
|
||||
'action' => 'delete',
|
||||
]);
|
||||
|
||||
$exerciseData = '';
|
||||
$exerciseId = 0;
|
||||
if (!empty($questionObject->exerciseList)) {
|
||||
// Question exists in a valid exercise
|
||||
$exerciseData .= '<h4>'.get_lang('Exercises').'</h4>';
|
||||
foreach ($questionObject->exerciseList as $exerciseId) {
|
||||
$exercise = new Exercise($question->getCId());
|
||||
$exercise->course_id = $question->getCId();
|
||||
$exercise->read($exerciseId);
|
||||
$exerciseData .= $exercise->title.' ';
|
||||
$exerciseData .= Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
$urlExercise.http_build_query(
|
||||
[
|
||||
'cidReq' => $courseCode,
|
||||
'id_session' => $exercise->sessionId,
|
||||
'exerciseId' => $exerciseId,
|
||||
'type' => $question->getType(),
|
||||
'editQuestion' => $question->getIid(),
|
||||
]
|
||||
),
|
||||
['target' => '_blank']
|
||||
).'<br />';
|
||||
}
|
||||
$question->questionData .= '<br />'.$exerciseData;
|
||||
} else {
|
||||
// Question exists but it's orphan or it belongs to a deleted exercise
|
||||
// This means the question is added in a deleted exercise
|
||||
if ($questionObject->getCountExercise() > 0) {
|
||||
$exerciseList = $questionObject->getExerciseListWhereQuestionExists();
|
||||
if (!empty($exerciseList)) {
|
||||
$question->questionData .= '<br />'.get_lang('Exercises').'<br />';
|
||||
/** @var CQuiz $exercise */
|
||||
foreach ($exerciseList as $exercise) {
|
||||
$question->questionData .= $exercise->getTitle();
|
||||
if ($exercise->getActive() == -1) {
|
||||
$question->questionData .= '- ('.get_lang('ExerciseDeleted').' #'.$exercise->getId().') ';
|
||||
}
|
||||
$question->questionData .= '<br />';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// This question is orphan :(
|
||||
$question->questionData .= ' '.get_lang('OrphanQuestion');
|
||||
}
|
||||
|
||||
$question->questionData .= Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
$urlExercise.http_build_query(
|
||||
[
|
||||
'cidReq' => $courseCode,
|
||||
'id_session' => 0, //$exercise->sessionId,
|
||||
'exerciseId' => $exerciseId,
|
||||
'type' => $question->getType(),
|
||||
'editQuestion' => $question->getIid(),
|
||||
]
|
||||
),
|
||||
['target' => '_blank']
|
||||
);
|
||||
}
|
||||
|
||||
$question->questionData .= '<div class="pull-right">'.Display::url(
|
||||
get_lang('Delete'),
|
||||
$deleteUrl,
|
||||
[
|
||||
'class' => 'btn btn-danger',
|
||||
'onclick' => 'javascript: if(!confirm(\''.$warningText.'\')) return false',
|
||||
]
|
||||
).'</div>';
|
||||
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formContent = $form->returnForm();
|
||||
|
||||
switch ($action) {
|
||||
case 'export_pdf':
|
||||
$pdfContent = Security::remove_XSS($pdfContent);
|
||||
$pdfParams = [
|
||||
'filename' => 'questions-export-'.api_get_local_time(),
|
||||
'pdf_date' => api_get_local_time(),
|
||||
'orientation' => 'P',
|
||||
];
|
||||
$pdf = new PDF('A4', $pdfParams['orientation'], $pdfParams);
|
||||
$pdf->html_to_pdf_with_template($pdfContent, false, false, true);
|
||||
exit;
|
||||
case 'delete':
|
||||
$questionId = $_REQUEST['questionId'] ?? '';
|
||||
$courseId = $_REQUEST['courseId'] ?? '';
|
||||
$courseInfo = api_get_course_info_by_id($courseId);
|
||||
if (!empty($courseInfo)) {
|
||||
$objQuestionTmp = Question::read($questionId, $courseInfo);
|
||||
if (!empty($objQuestionTmp)) {
|
||||
$result = $objQuestionTmp->delete();
|
||||
if ($result) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('Deleted').' #'.$questionId.' - "'.$objQuestionTmp->question.'"'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: $url");
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
$actionsLeft = Display::url(
|
||||
Display::return_icon('back.png', get_lang('PlatformAdmin'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_CODE_PATH).'admin/index.php'
|
||||
);
|
||||
|
||||
$exportUrl = api_get_path(WEB_CODE_PATH)
|
||||
.'admin/questions.php?action=export_pdf&'
|
||||
.http_build_query($params);
|
||||
|
||||
$actionsRight = Display::url(
|
||||
Display::return_icon('pdf.png', get_lang('ExportToPDF'), [], ICON_SIZE_MEDIUM),
|
||||
$exportUrl
|
||||
);
|
||||
|
||||
$toolbar = Display::toolbarAction(
|
||||
'toolbar-admin-questions',
|
||||
[$actionsLeft, $actionsRight]
|
||||
);
|
||||
|
||||
$tpl = new Template(get_lang('Questions'));
|
||||
$tpl->assign('form', $formContent);
|
||||
$tpl->assign('toolbar', $toolbar);
|
||||
$tpl->assign('pagination', $pagination);
|
||||
$tpl->assign('pagination_length', $length);
|
||||
$tpl->assign('start', $start);
|
||||
$tpl->assign('end', $end);
|
||||
$tpl->assign('question_count', $questionCount);
|
||||
|
||||
$layout = $tpl->get_template('admin/questions.tpl');
|
||||
$tpl->display($layout);
|
||||
151
main/admin/resource_sequence.php
Normal file
151
main/admin/resource_sequence.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Sequence;
|
||||
use Chamilo\CoreBundle\Entity\SequenceResource;
|
||||
use ChamiloSession as Session;
|
||||
use Symfony\Component\HttpFoundation\Request as HttpRequest;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_global_admin_script();
|
||||
|
||||
Session::erase('sr_vertex');
|
||||
|
||||
$httpRequest = HttpRequest::createFromGlobals();
|
||||
|
||||
// setting breadcrumbs
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$type = $httpRequest->query->has('type')
|
||||
? $httpRequest->query->getInt('type', SequenceResource::SESSION_TYPE)
|
||||
: $httpRequest->request->getInt('type', SequenceResource::SESSION_TYPE);
|
||||
|
||||
$tpl = new Template(get_lang('ResourcesSequencing'));
|
||||
$em = Database::getManager();
|
||||
$sequenceRepository = $em->getRepository('ChamiloCoreBundle:Sequence');
|
||||
|
||||
$currentUrl = api_get_self().'?type='.$type;
|
||||
|
||||
$formSequence = new FormValidator('sequence_form', 'post', $currentUrl, null, null, FormValidator::LAYOUT_INLINE);
|
||||
$formSequence->addText('name', get_lang('Sequence'), true, ['cols-size' => [3, 8, 1]]);
|
||||
$formSequence->applyFilter('name', 'html_filter');
|
||||
$formSequence->addButtonCreate(get_lang('AddSequence'), 'submit_sequence', false, ['cols-size' => [3, 8, 1]]);
|
||||
|
||||
$em = Database::getManager();
|
||||
|
||||
// Add sequence
|
||||
if ($formSequence->validate()) {
|
||||
$values = $formSequence->exportValues();
|
||||
$sequence = new Sequence();
|
||||
$sequence->setName($values['name']);
|
||||
$em->persist($sequence);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Saved')));
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
$selectSequence = new FormValidator('frm_select_delete', 'post', $currentUrl);
|
||||
$sequenceList = $sequenceRepository->findAllToSelect($type);
|
||||
|
||||
$sequenceElement = $selectSequence->addSelect(
|
||||
'sequence',
|
||||
get_lang('Sequence'),
|
||||
$sequenceList,
|
||||
['id' => 'sequence_id', 'cols-size' => [3, 7, 2], 'disabled' => 'disabled']
|
||||
);
|
||||
|
||||
if (!empty($sequenceList)) {
|
||||
$selectSequence->addButtonDelete(get_lang('Delete'));
|
||||
$sequenceElement->removeAttribute('disabled');
|
||||
}
|
||||
|
||||
if ($selectSequence->validate()) {
|
||||
$values = $selectSequence->exportValues();
|
||||
$sequenceRepository->removeSequence($values['sequence']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Deleted'), 'success')
|
||||
);
|
||||
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
$list = $sequenceRepository->getItems($type);
|
||||
|
||||
switch ($type) {
|
||||
case SequenceResource::COURSE_TYPE:
|
||||
$label = get_lang('Courses');
|
||||
break;
|
||||
case SequenceResource::SESSION_TYPE:
|
||||
$label = get_lang('Sessions');
|
||||
break;
|
||||
}
|
||||
|
||||
$form = new FormValidator('');
|
||||
$form->addHtml("<div class='col-md-6'>");
|
||||
$form->addHidden('sequence_type', $type);
|
||||
$form->addSelect(
|
||||
'sessions',
|
||||
$label,
|
||||
$list,
|
||||
['id' => 'item', 'cols-size' => [4, 7, 1], 'disabled' => 'disabled']
|
||||
);
|
||||
$form->addButtonNext(
|
||||
get_lang('UseAsReference'),
|
||||
'use_as_reference',
|
||||
['cols-size' => [4, 7, 1], 'disabled' => 'disabled']
|
||||
);
|
||||
$form->addHtml("</div>");
|
||||
$form->addHtml("<div class='col-md-6'>");
|
||||
$form->addSelect(
|
||||
'requirements',
|
||||
get_lang('Requirements'),
|
||||
$list,
|
||||
['id' => 'requirements', 'cols-size' => [3, 7, 2], 'disabled' => 'disabled']
|
||||
);
|
||||
|
||||
$form->addButtonCreate(
|
||||
get_lang('SetAsRequirement'),
|
||||
'set_requirement',
|
||||
false,
|
||||
['cols-size' => [3, 7, 2], 'disabled' => 'disabled']
|
||||
);
|
||||
$form->addHtml('</div>');
|
||||
|
||||
$formSave = new FormValidator('');
|
||||
$formSave->addButton(
|
||||
'save_resource',
|
||||
get_lang('SaveSettings'),
|
||||
'floppy-o',
|
||||
'success',
|
||||
null,
|
||||
null,
|
||||
['cols-size' => [1, 10, 1], 'disabled' => 'disabled']
|
||||
);
|
||||
|
||||
$headers[] = [
|
||||
'url' => api_get_self().'?type='.SequenceResource::SESSION_TYPE,
|
||||
'content' => get_lang('Sessions'),
|
||||
];
|
||||
|
||||
$headers[] = [
|
||||
'url' => api_get_self().'?type='.SequenceResource::COURSE_TYPE,
|
||||
'content' => get_lang('Courses'),
|
||||
];
|
||||
|
||||
$tabs = Display::tabsOnlyLink($headers, $type === SequenceResource::COURSE_TYPE ? 2 : 1);
|
||||
|
||||
$tpl->assign('create_sequence', $formSequence->returnForm());
|
||||
$tpl->assign('select_sequence', $selectSequence->returnForm());
|
||||
$tpl->assign('configure_sequence', $form->returnForm());
|
||||
$tpl->assign('save_sequence', $formSave->returnForm());
|
||||
$tpl->assign('sequence_type', $type);
|
||||
$tpl->assign('tabs', $tabs);
|
||||
$layout = $tpl->get_template('admin/resource_sequence.tpl');
|
||||
$tpl->display($layout);
|
||||
2320
main/admin/settings.lib.php
Normal file
2320
main/admin/settings.lib.php
Normal file
File diff suppressed because it is too large
Load Diff
538
main/admin/settings.php
Normal file
538
main/admin/settings.php
Normal file
@@ -0,0 +1,538 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* With this tool you can easily adjust non critical configuration settings.
|
||||
* Non critical means that changing them will not result in a broken campus.
|
||||
*
|
||||
* @author Patrick Cool
|
||||
* @author Julio Montoya - Multiple URL site
|
||||
*/
|
||||
|
||||
// Resetting the course id.
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
require_once 'settings.lib.php';
|
||||
|
||||
// Setting the section (for the tabs).
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
$_SESSION['this_section'] = $this_section;
|
||||
|
||||
// Access restrictions.
|
||||
api_protect_admin_script();
|
||||
|
||||
// Submit stylesheets.
|
||||
if (isset($_POST['save']) && isset($_GET['category']) && $_GET['category'] === 'Stylesheets') {
|
||||
storeStylesheets();
|
||||
Display::addFlash(Display::return_message(get_lang('Saved')));
|
||||
}
|
||||
|
||||
// Settings to avoid
|
||||
$settings_to_avoid = [
|
||||
'use_session_mode' => 'true',
|
||||
'gradebook_enable' => 'false',
|
||||
// ON by default - now we have this option when we create a course
|
||||
'example_material_course_creation' => 'true',
|
||||
];
|
||||
|
||||
$convert_byte_to_mega_list = [
|
||||
'dropbox_max_filesize',
|
||||
'message_max_upload_filesize',
|
||||
'default_document_quotum',
|
||||
'default_group_quotum',
|
||||
];
|
||||
|
||||
if (isset($_POST['style'])) {
|
||||
Display::$preview_style = $_POST['style'];
|
||||
}
|
||||
|
||||
// Database table definitions.
|
||||
$table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
|
||||
|
||||
// Setting breadcrumbs.
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
// Setting the name of the tool.
|
||||
$tool_name = get_lang('PlatformConfigSettings');
|
||||
if (empty($_GET['category'])) {
|
||||
$_GET['category'] = 'Platform';
|
||||
}
|
||||
$watermark_deleted = false;
|
||||
if (isset($_GET['delete_watermark'])) {
|
||||
$watermark_deleted = PDF::delete_watermark();
|
||||
Display::addFlash(Display::return_message(get_lang('FileDeleted')));
|
||||
}
|
||||
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'delete_grading') {
|
||||
$id = intval($_GET['id']);
|
||||
api_delete_setting_option($id);
|
||||
}
|
||||
|
||||
$form_search = new FormValidator(
|
||||
'search_settings',
|
||||
'get',
|
||||
api_get_self(),
|
||||
null,
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$form_search->addElement('text', 'search_field', null, [
|
||||
'id' => 'search_field',
|
||||
'aria-label' => get_lang('Search'),
|
||||
]);
|
||||
$form_search->addElement('hidden', 'category', 'search_setting');
|
||||
$form_search->addButtonSearch(get_lang('Search'), 'submit_button');
|
||||
$form_search->setDefaults(
|
||||
['search_field' => isset($_REQUEST['search_field']) ? $_REQUEST['search_field'] : null]
|
||||
);
|
||||
|
||||
$form_search_html = $form_search->returnForm();
|
||||
|
||||
$url_id = api_get_current_access_url_id();
|
||||
|
||||
$settings = null;
|
||||
$flushSettings = false;
|
||||
$multipleUrlsEnabled = false;
|
||||
|
||||
if (api_is_multiple_url_enabled()) {
|
||||
$multipleUrlsEnabled = true;
|
||||
}
|
||||
|
||||
// Build the form.
|
||||
if (!empty($_GET['category']) &&
|
||||
!in_array($_GET['category'], ['Plugins', 'stylesheets', 'Search'])
|
||||
) {
|
||||
$my_category = isset($_GET['category']) ? $_GET['category'] : null;
|
||||
$settings_array = getCategorySettings($my_category);
|
||||
$settings = $settings_array['settings'];
|
||||
$settings_by_access_list = $settings_array['settings_by_access_list'];
|
||||
$form = generateSettingsForm($settings, $settings_by_access_list);
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
|
||||
$mark_all = false;
|
||||
$un_mark_all = false;
|
||||
|
||||
if ($multipleUrlsEnabled) {
|
||||
if (isset($values['buttons_in_action_right']) &&
|
||||
isset($values['buttons_in_action_right']['mark_all'])
|
||||
) {
|
||||
$mark_all = true;
|
||||
}
|
||||
|
||||
if (isset($values['buttons_in_action_right']) &&
|
||||
isset($values['buttons_in_action_right']['unmark_all'])
|
||||
) {
|
||||
$un_mark_all = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($mark_all || $un_mark_all) {
|
||||
if (api_is_global_platform_admin()) {
|
||||
$locked_settings = api_get_locked_settings();
|
||||
foreach ($values as $key => $value) {
|
||||
if (!in_array($key, $locked_settings)) {
|
||||
$changeable = 0;
|
||||
if ($mark_all) {
|
||||
$changeable = 1;
|
||||
}
|
||||
|
||||
$params = ['variable = ?' => [$key]];
|
||||
$data = api_get_settings_params($params);
|
||||
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $item) {
|
||||
$params = [
|
||||
'id' => $item['id'],
|
||||
'access_url_changeable' => $changeable,
|
||||
];
|
||||
api_set_setting_simple($params);
|
||||
}
|
||||
$flushSettings = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reload settings
|
||||
$settings_array = getCategorySettings($my_category);
|
||||
$settings = $settings_array['settings'];
|
||||
$settings_by_access_list = $settings_array['settings_by_access_list'];
|
||||
$form = generateSettingsForm(
|
||||
$settings,
|
||||
$settings_by_access_list
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!empty($_FILES['pdf_export_watermark_path'])) {
|
||||
$pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
|
||||
}
|
||||
|
||||
if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {
|
||||
$pdf_export_watermark_path_result = PDF::upload_watermark(
|
||||
$pdf_export_watermark_path['name'],
|
||||
$pdf_export_watermark_path['tmp_name']
|
||||
);
|
||||
if ($pdf_export_watermark_path_result) {
|
||||
Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded')));
|
||||
} else {
|
||||
$message = get_lang('UplUnableToSaveFile').' '.get_lang('Folder').': '.api_get_path(SYS_CODE_PATH).'default_course_document/images';
|
||||
Display::addFlash(Display::return_message($message), 'warning');
|
||||
}
|
||||
unset($update_values['pdf_export_watermark_path']);
|
||||
}
|
||||
|
||||
// Set true for allow_message_tool variable if social tool is actived
|
||||
foreach ($convert_byte_to_mega_list as $item) {
|
||||
if (isset($values[$item])) {
|
||||
$values[$item] = round($values[$item] * 1024 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($values['allow_social_tool']) && $values['allow_social_tool'] == 'true') {
|
||||
$values['allow_message_tool'] = 'true';
|
||||
}
|
||||
|
||||
foreach ($settings as $item) {
|
||||
$key = $item['variable'];
|
||||
if ($key === 'prevent_multiple_simultaneous_login') {
|
||||
Session::write('first_user_login', 1);
|
||||
}
|
||||
if (in_array($key, $settings_to_avoid)) {
|
||||
continue;
|
||||
}
|
||||
if ($key == 'search_field' || $key == 'submit_fixed_in_bottom') {
|
||||
continue;
|
||||
}
|
||||
$key = Database::escape_string($key);
|
||||
$sql = "UPDATE $table_settings_current
|
||||
SET selected_value = 'false'
|
||||
WHERE
|
||||
variable = '".$key."' AND
|
||||
access_url = ".intval($url_id)." AND
|
||||
type IN ('checkbox', 'radio') ";
|
||||
$res = Database::query($sql);
|
||||
$flushSettings = true;
|
||||
}
|
||||
|
||||
// Save the settings.
|
||||
$keys = [];
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
if (strcmp($key, 'MAX_FILE_SIZE') === 0) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($key, $settings_to_avoid)) {
|
||||
continue;
|
||||
}
|
||||
// Avoid form elements which have nothing to do with settings
|
||||
if ($key == 'search_field' || $key == 'submit_fixed_in_bottom') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Treat gradebook values in separate function.
|
||||
//if (strpos($key, 'gradebook_score_display_custom_values') === false) {
|
||||
if (!is_array($value)) {
|
||||
$old_value = api_get_setting($key);
|
||||
switch ($key) {
|
||||
case 'header_extra_content':
|
||||
file_put_contents(api_get_home_path().'header_extra_content.txt', $value);
|
||||
$value = api_get_home_path().'header_extra_content.txt';
|
||||
break;
|
||||
case 'footer_extra_content':
|
||||
file_put_contents(api_get_home_path().'footer_extra_content.txt', $value);
|
||||
$value = api_get_home_path().'footer_extra_content.txt';
|
||||
break;
|
||||
case 'InstitutionUrl':
|
||||
case 'course_validation_terms_and_conditions_url':
|
||||
// URL validation for some settings.
|
||||
$value = trim(Security::remove_XSS($value));
|
||||
if ($value != '') {
|
||||
// Here we accept absolute URLs only.
|
||||
if (strpos($value, '://') === false) {
|
||||
$value = 'http://'.$value;
|
||||
}
|
||||
if (!api_valid_url($value, true)) {
|
||||
// If the new (non-empty) URL value is invalid, then the old URL value stays.
|
||||
$value = $old_value;
|
||||
}
|
||||
}
|
||||
// If the new URL value is empty, then it will be stored (i.e. the setting will be deleted).
|
||||
break;
|
||||
case 'emailAdministrator':
|
||||
// Validation against e-mail address for some settings.
|
||||
$value = trim(Security::remove_XSS($value));
|
||||
if ($value != '' && !api_valid_email($value)) {
|
||||
// If the new (non-empty) e-mail address is invalid, then the old e-mail address stays.
|
||||
// If the new e-mail address is empty, then it will be stored (i.e. the setting will be deleted).
|
||||
$value = $old_value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($old_value != $value) {
|
||||
$keys[] = $key;
|
||||
}
|
||||
$result = api_set_setting($key, $value, null, null, $url_id);
|
||||
} else {
|
||||
$sql = "SELECT subkey FROM $table_settings_current
|
||||
WHERE variable = '$key'";
|
||||
$res = Database::query($sql);
|
||||
|
||||
while ($row_subkeys = Database::fetch_array($res)) {
|
||||
// If subkey is changed:
|
||||
if ((isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'false') ||
|
||||
(!isset($value[$row_subkeys['subkey']]) && api_get_setting($key, $row_subkeys['subkey']) == 'true')
|
||||
) {
|
||||
$keys[] = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($value as $subkey => $subvalue) {
|
||||
$result = api_set_setting($key, 'true', $subkey, null, $url_id);
|
||||
}
|
||||
$flushSettings = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Add event configuration settings category to the system log.
|
||||
$user_id = api_get_user_id();
|
||||
$category = $_GET['category'];
|
||||
Event::addEvent(
|
||||
LOG_CONFIGURATION_SETTINGS_CHANGE,
|
||||
LOG_CONFIGURATION_SETTINGS_CATEGORY,
|
||||
$category,
|
||||
api_get_utc_datetime(),
|
||||
$user_id
|
||||
);
|
||||
if ($flushSettings) {
|
||||
api_flush_settings_cache($url_id);
|
||||
}
|
||||
// Add event configuration settings variable to the system log.
|
||||
if (is_array($keys) && count($keys) > 0) {
|
||||
foreach ($keys as $variable) {
|
||||
if (in_array($key, $settings_to_avoid)) {
|
||||
continue;
|
||||
}
|
||||
Event::addEvent(
|
||||
LOG_CONFIGURATION_SETTINGS_CHANGE,
|
||||
LOG_CONFIGURATION_SETTINGS_VARIABLE,
|
||||
$variable,
|
||||
api_get_utc_datetime(),
|
||||
$user_id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
|
||||
header('Location: '.api_get_self().'?category='.Security::remove_XSS($my_category));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$htmlHeadXtra[] = '<script>
|
||||
var hide_icon = "'.api_get_path(WEB_IMG_PATH).'/icons/32/shared_setting_na.png";
|
||||
var show_icon = "'.api_get_path(WEB_IMG_PATH).'/icons/32/shared_setting.png";
|
||||
var url = "'.api_get_path(WEB_AJAX_PATH).'admin.ajax.php?a=update_changeable_setting";
|
||||
|
||||
$(function() {
|
||||
$(".share_this_setting").on("click", function() {
|
||||
var my_img = $(this).find("img");
|
||||
var link = $(this);
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: {
|
||||
changeable: $(this).attr("data_status"),
|
||||
id: $(this).attr("data_to_send")
|
||||
},
|
||||
success: function(data) {
|
||||
if (data == 1) {
|
||||
if (link.attr("data_status") == 1) {
|
||||
my_img.attr("src", show_icon);
|
||||
link.attr("data_status", 0);
|
||||
} else {
|
||||
my_img.attr("src", hide_icon);
|
||||
link.attr("data_status", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
// The action images.
|
||||
$action_images['platform'] = 'platform.png';
|
||||
$action_images['course'] = 'course.png';
|
||||
$action_images['session'] = 'session.png';
|
||||
$action_images['tools'] = 'tools.png';
|
||||
$action_images['user'] = 'user.png';
|
||||
$action_images['gradebook'] = 'gradebook.png';
|
||||
$action_images['ldap'] = 'ldap.png';
|
||||
$action_images['cas'] = 'cas.png';
|
||||
$action_images['security'] = 'security.png';
|
||||
$action_images['languages'] = 'languages.png';
|
||||
$action_images['tuning'] = 'tuning.png';
|
||||
$action_images['templates'] = 'template.png';
|
||||
$action_images['search'] = 'search.png';
|
||||
$action_images['editor'] = 'html_editor.png';
|
||||
$action_images['timezones'] = 'timezone.png';
|
||||
$action_images['extra'] = 'wizard.png';
|
||||
$action_images['tracking'] = 'statistics.png';
|
||||
$action_images['gradebook'] = 'gradebook.png';
|
||||
$action_images['search'] = 'search.png';
|
||||
$action_images['stylesheets'] = 'stylesheets.png';
|
||||
$action_images['templates'] = 'template.png';
|
||||
$action_images['plugins'] = 'plugins.png';
|
||||
$action_images['shibboleth'] = 'shibboleth.png';
|
||||
$action_images['facebook'] = 'facebook.png';
|
||||
$action_images['crons'] = 'crons.png';
|
||||
$action_images['webservices'] = 'webservices.png';
|
||||
if (api_get_configuration_value('allow_compilatio_tool')) {
|
||||
$action_images['plagiarism'] = 'plagiarism.png';
|
||||
}
|
||||
|
||||
$action_array = [];
|
||||
$resultcategories = [];
|
||||
|
||||
$resultcategories[] = ['category' => 'Platform'];
|
||||
$resultcategories[] = ['category' => 'Course'];
|
||||
$resultcategories[] = ['category' => 'Session'];
|
||||
$resultcategories[] = ['category' => 'Languages'];
|
||||
$resultcategories[] = ['category' => 'User'];
|
||||
$resultcategories[] = ['category' => 'Tools'];
|
||||
$resultcategories[] = ['category' => 'Editor'];
|
||||
$resultcategories[] = ['category' => 'Security'];
|
||||
$resultcategories[] = ['category' => 'Tuning'];
|
||||
$resultcategories[] = ['category' => 'Gradebook'];
|
||||
$resultcategories[] = ['category' => 'Timezones'];
|
||||
$resultcategories[] = ['category' => 'Tracking'];
|
||||
$resultcategories[] = ['category' => 'Search'];
|
||||
$resultcategories[] = ['category' => 'Stylesheets'];
|
||||
$resultcategories[] = ['category' => 'Templates'];
|
||||
$resultcategories[] = ['category' => 'Plugins'];
|
||||
$resultcategories[] = ['category' => 'LDAP'];
|
||||
$resultcategories[] = ['category' => 'CAS'];
|
||||
$resultcategories[] = ['category' => 'Shibboleth'];
|
||||
$resultcategories[] = ['category' => 'Facebook'];
|
||||
$resultcategories[] = ['category' => 'Crons'];
|
||||
$resultcategories[] = ['category' => 'WebServices'];
|
||||
if (api_get_configuration_value('allow_compilatio_tool')) {
|
||||
$resultcategories[] = ['category' => 'Plagiarism'];
|
||||
}
|
||||
|
||||
foreach ($resultcategories as $row) {
|
||||
$url = [];
|
||||
$url['url'] = api_get_self()."?category=".$row['category'];
|
||||
$url['content'] = Display::return_icon(
|
||||
$action_images[strtolower($row['category'])],
|
||||
api_ucfirst(get_lang($row['category'])),
|
||||
[],
|
||||
ICON_SIZE_MEDIUM
|
||||
);
|
||||
if (strtolower($row['category']) == strtolower($_GET['category'])) {
|
||||
$url['active'] = true;
|
||||
}
|
||||
$action_array[] = $url;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
if (!empty($_GET['category'])) {
|
||||
switch ($_GET['category']) {
|
||||
case 'Regions':
|
||||
handleRegions();
|
||||
break;
|
||||
case 'Plugins':
|
||||
// Displaying the extensions: Plugins.
|
||||
// This will be available to all the sites (access_urls).
|
||||
$securityToken = isset($_GET['sec_token']) ? Security::remove_XSS($_GET['sec_token']) : null;
|
||||
if (isset($_POST['submit_dashboard_plugins']) && Security::check_token($securityToken)) {
|
||||
Security::clear_token();
|
||||
$affected_rows = DashboardManager::store_dashboard_plugins($_POST);
|
||||
if ($affected_rows) {
|
||||
// add event to system log
|
||||
$user_id = api_get_user_id();
|
||||
$category = $_GET['category'];
|
||||
Event::addEvent(
|
||||
LOG_CONFIGURATION_SETTINGS_CHANGE,
|
||||
LOG_CONFIGURATION_SETTINGS_CATEGORY,
|
||||
$category,
|
||||
api_get_utc_datetime(),
|
||||
$user_id
|
||||
);
|
||||
echo Display::return_message(get_lang('DashboardPluginsUpdatedSuccessfully'), 'confirmation');
|
||||
}
|
||||
}
|
||||
echo '<script>
|
||||
$(function(){
|
||||
$("#tabs").tabs();
|
||||
});
|
||||
</script>';
|
||||
echo '<div id="tabs">';
|
||||
echo '<ul>';
|
||||
echo '<li><a href="#tabs-1">'.get_lang('Plugins').'</a></li>';
|
||||
echo '<li><a href="#tabs-2">'.get_lang('DashboardPlugins').'</a></li>';
|
||||
echo '<li><a href="#tabs-3">'.get_lang('ConfigureExtensions').'</a></li>';
|
||||
echo '<li><a href="#tabs-4">'.get_lang('UploadPlugin').'</a></li>';
|
||||
echo '</ul>';
|
||||
|
||||
echo '<div id="tabs-1">';
|
||||
handlePlugins();
|
||||
echo '</div>';
|
||||
|
||||
echo '<div id="tabs-2">';
|
||||
DashboardManager::handle_dashboard_plugins();
|
||||
echo '</div>';
|
||||
|
||||
echo '<div id="tabs-3">';
|
||||
handleExtensions();
|
||||
echo '</div>';
|
||||
|
||||
echo '<div id="tabs-4">';
|
||||
handlePluginUpload();
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
$flushSettings = true;
|
||||
break;
|
||||
case 'Stylesheets':
|
||||
// Displaying the extensions: Stylesheets.
|
||||
handleStylesheets();
|
||||
$flushSettings = true;
|
||||
break;
|
||||
case 'Search':
|
||||
handleSearch();
|
||||
break;
|
||||
case 'Templates':
|
||||
handleTemplates();
|
||||
break;
|
||||
case 'search_setting':
|
||||
if (isset($_REQUEST['search_field'])) {
|
||||
searchSetting($_REQUEST['search_field']);
|
||||
$form->display();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (isset($form)) {
|
||||
$form->display();
|
||||
}
|
||||
}
|
||||
}
|
||||
$content = ob_get_clean();
|
||||
if ($flushSettings) {
|
||||
api_flush_settings_cache($url_id);
|
||||
}
|
||||
|
||||
// Including the header (banner).
|
||||
Display::display_header($tool_name);
|
||||
echo Display::actions($action_array);
|
||||
echo '<br />';
|
||||
echo $form_search_html;
|
||||
echo Display::getFlashToString();
|
||||
Display::cleanFlashMessages();
|
||||
echo $content;
|
||||
|
||||
Display::display_footer();
|
||||
94
main/admin/skill.php
Normal file
94
main/admin/skill.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Skill;
|
||||
|
||||
/**
|
||||
* This script manages the skills, levels and profiles assignments.
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
api_protect_admin_script();
|
||||
$em = Database::getManager();
|
||||
$profiles = $em->getRepository('ChamiloSkillBundle:Profile')->findAll();
|
||||
$list = $em->getRepository('ChamiloCoreBundle:Skill')->findAll();
|
||||
|
||||
$listAction = api_get_self();
|
||||
$toolbarAction = '';
|
||||
|
||||
$action = '';
|
||||
if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete'])) {
|
||||
$action = $_GET['action'];
|
||||
}
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : '';
|
||||
|
||||
$item = null;
|
||||
if (!empty($id)) {
|
||||
/** @var Skill $item */
|
||||
$item = $em->getRepository('ChamiloCoreBundle:Skill')->find($id);
|
||||
if (!$item) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
$form = new FormValidator('Skill', 'GET', api_get_self().'?action='.$action.'&id='.$id);
|
||||
$form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles, null, true);
|
||||
$form->addHidden('action', $action);
|
||||
$form->addHidden('id', $id);
|
||||
$form->addButtonSave(get_lang('Update'));
|
||||
|
||||
if (!empty($item)) {
|
||||
$profile = $item->getProfile();
|
||||
if ($profile) {
|
||||
$form->setDefaults(
|
||||
[
|
||||
'profile_id' => $item->getProfile()->getId(),
|
||||
]
|
||||
);
|
||||
}
|
||||
$form->addHeader($item->getName());
|
||||
}
|
||||
$formToDisplay = $form->returnForm();
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('ManageSkillsLevels')];
|
||||
|
||||
$tpl = new Template($action);
|
||||
switch ($action) {
|
||||
case 'edit':
|
||||
$tpl->assign('form', $formToDisplay);
|
||||
$toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]);
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
|
||||
if ($profile) {
|
||||
$item->setProfile($profile);
|
||||
$em->persist($item);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
}
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
$toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]);
|
||||
|
||||
$em->remove($item);
|
||||
$em->flush();
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$tpl->assign('list', $list);
|
||||
$view = $tpl->get_template('admin/skill.tpl');
|
||||
$contentTemplate = $tpl->fetch($view);
|
||||
$tpl->assign('actions', $toolbarAction);
|
||||
$tpl->assign('content', $contentTemplate);
|
||||
$tpl->display_one_col_template();
|
||||
53
main/admin/skill_badge.php
Normal file
53
main/admin/skill_badge.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Show information about Mozilla OpenBadges.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
Skill::isAllowed();
|
||||
|
||||
$backpack = 'https://backpack.openbadges.org/';
|
||||
|
||||
$configBackpack = api_get_setting('openbadges_backpack');
|
||||
if (strcmp($backpack, $configBackpack) !== 0) {
|
||||
$backpack = $configBackpack;
|
||||
}
|
||||
|
||||
$interbreadcrumb = [
|
||||
[
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
|
||||
'name' => get_lang('Administration'),
|
||||
],
|
||||
];
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('ManageSkills'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/skill_list.php',
|
||||
['title' => get_lang('ManageSkills')]
|
||||
);
|
||||
|
||||
$tpl = new Template(get_lang('Badges'));
|
||||
$tpl->assign('backpack', $backpack);
|
||||
|
||||
$templateName = $tpl->get_template('skill/badge.tpl');
|
||||
$contentTemplate = $tpl->fetch($templateName);
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$tpl->assign('content', $contentTemplate);
|
||||
$tpl->display_one_col_template();
|
||||
105
main/admin/skill_badge_create.php
Normal file
105
main/admin/skill_badge_create.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Show information about Mozilla OpenBadges.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
Skill::isAllowed();
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$skillId = intval($_GET['id']);
|
||||
$objSkill = new Skill();
|
||||
$skill = $objSkill->get($skillId);
|
||||
|
||||
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/css/core.css" rel="stylesheet">';
|
||||
|
||||
// Add badge studio paths
|
||||
$badgeStudio = [
|
||||
'core' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/',
|
||||
'media' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/',
|
||||
'templates' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/images/templates/',
|
||||
'masks' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/images/masks/',
|
||||
'script_js' => '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/js/studio.js?"></script>',
|
||||
];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$params = [
|
||||
'id' => $skillId,
|
||||
];
|
||||
|
||||
if ((isset($_FILES['image']) && $_FILES['image']['error'] == 0) ||
|
||||
!empty($_POST['badge_studio_image'])
|
||||
) {
|
||||
$dirPermissions = api_get_permissions_for_new_directories();
|
||||
$fileName = sha1($skill['name']);
|
||||
$badgePath = api_get_path(SYS_UPLOAD_PATH).'badges/';
|
||||
$existsBadgesDirectory = is_dir($badgePath);
|
||||
|
||||
if (!$existsBadgesDirectory) {
|
||||
$existsBadgesDirectory = api_create_protected_dir('badges', api_get_path(SYS_UPLOAD_PATH));
|
||||
}
|
||||
|
||||
if ($existsBadgesDirectory) {
|
||||
if (!empty($skill['icon'])) {
|
||||
$iconFileAbsolutePath = $badgePath.$skill['icon'];
|
||||
|
||||
if (Security::check_abs_path($iconFileAbsolutePath, $badgePath)) {
|
||||
unlink($badgePath.$skill['icon']);
|
||||
}
|
||||
}
|
||||
|
||||
$skillImagePath = sprintf("%s%s.png", $badgePath, $fileName);
|
||||
if (!empty($_POST['badge_studio_image'])) {
|
||||
$badgeImage = base64_decode(
|
||||
preg_replace('#^data:image/\w+;base64,#i', '', $_POST['badge_studio_image'])
|
||||
);
|
||||
file_put_contents($skillImagePath, $badgeImage);
|
||||
$skillImage = new Image($skillImagePath);
|
||||
} else {
|
||||
$skillImage = new Image($_FILES['image']['tmp_name']);
|
||||
}
|
||||
|
||||
$skillImage->send_image($skillImagePath, -1, 'png');
|
||||
|
||||
$skillThumbPath = sprintf("%s%s-small.png", $badgePath, $fileName);
|
||||
|
||||
$skillImageThumb = new Image($skillImagePath);
|
||||
$skillImageThumb->resize(ICON_SIZE_BIG);
|
||||
$skillImageThumb->send_image($skillThumbPath);
|
||||
|
||||
$params['icon'] = sprintf("%s.png", $fileName);
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('UplUnableToSaveFile')), 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
$objSkill->update($params);
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
|
||||
'name' => get_lang('Administration'),
|
||||
];
|
||||
$interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('ManageSkills')];
|
||||
|
||||
$toolbar = $objSkill->getToolBar();
|
||||
|
||||
$tpl = new Template(get_lang('CreateBadge'));
|
||||
$tpl->assign('platformAdminEmail', api_get_setting('emailAdministrator'));
|
||||
$tpl->assign('skill', $skill);
|
||||
$tpl->assign('badge_studio', $badgeStudio);
|
||||
$templateName = $tpl->get_template('skill/badge_create.tpl');
|
||||
$contentTemplate = $tpl->fetch($templateName);
|
||||
$tpl->assign('content', $toolbar.$contentTemplate);
|
||||
$tpl->display_one_col_template();
|
||||
57
main/admin/skill_badge_list.php
Normal file
57
main/admin/skill_badge_list.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Show information about Mozilla OpenBadges.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*
|
||||
* @package chamilo.admin.openbadges
|
||||
*
|
||||
* @deprecated use skill_list.php
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
Skill::isAllowed();
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
$objSkill = new Skill();
|
||||
$skills = $objSkill->get_all();
|
||||
|
||||
$interbreadcrumb = [
|
||||
[
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
|
||||
'name' => get_lang('Administration'),
|
||||
],
|
||||
[
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/skill_badge.php',
|
||||
'name' => get_lang('Badges'),
|
||||
],
|
||||
];
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('ManageSkills'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/skill_list.php',
|
||||
['title' => get_lang('ManageSkills')]
|
||||
);
|
||||
|
||||
$tpl = new Template(get_lang('Skills'));
|
||||
$tpl->assign('skills', $skills);
|
||||
$templateName = $tpl->get_template('skill/badge_list.tpl');
|
||||
$contentTemplate = $tpl->fetch($templateName);
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$tpl->assign('content', $contentTemplate);
|
||||
$tpl->display_one_col_template();
|
||||
85
main/admin/skill_create.php
Normal file
85
main/admin/skill_create.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Create skill form.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
Skill::isAllowed();
|
||||
|
||||
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('ManageSkills')];
|
||||
|
||||
/* Process data */
|
||||
$skillParentId = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
|
||||
$formDefaultValues = [];
|
||||
|
||||
$objSkill = new Skill();
|
||||
if ($skillParentId > 0) {
|
||||
$skillParentInfo = $objSkill->getSkillInfo($skillParentId);
|
||||
|
||||
$formDefaultValues = [
|
||||
'parent_id' => $skillParentInfo['id'],
|
||||
'gradebook_id' => [],
|
||||
];
|
||||
|
||||
foreach ($skillParentInfo['gradebooks'] as $gradebook) {
|
||||
$formDefaultValues['gradebook_id'][] = intval($gradebook['id']);
|
||||
}
|
||||
}
|
||||
|
||||
/* Form */
|
||||
$createForm = new FormValidator('skill_create');
|
||||
$createForm->addHeader(get_lang('CreateSkill'));
|
||||
$returnParams = $objSkill->setForm($createForm, []);
|
||||
$jquery_ready_content = $returnParams['jquery_ready_content'];
|
||||
|
||||
// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
|
||||
if (!empty($jquery_ready_content)) {
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function () {
|
||||
'.$jquery_ready_content.'
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
$createForm->setDefaults($formDefaultValues);
|
||||
|
||||
if ($createForm->validate()) {
|
||||
$skillValues = $createForm->getSubmitValues();
|
||||
$created = $objSkill->add($skillValues);
|
||||
|
||||
$skillValues['item_id'] = $created;
|
||||
$extraFieldValue = new ExtraFieldValue('skill');
|
||||
$extraFieldValue->saveFieldValues($skillValues);
|
||||
if ($created) {
|
||||
$url = api_get_path(WEB_CODE_PATH).'admin/skill_edit.php?id='.$created;
|
||||
$link = Display::url($skillValues['name'], $url);
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('TheSkillHasBeenCreated').': '.$link, 'success', false)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('CannotCreateSkill'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$toolbar = $objSkill->getToolbar();
|
||||
|
||||
$tpl = new Template(get_lang('CreateSkill'));
|
||||
$tpl->assign('content', $toolbar.$createForm->returnForm());
|
||||
$tpl->display_one_col_template();
|
||||
105
main/admin/skill_edit.php
Normal file
105
main/admin/skill_edit.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Skill edit form.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*
|
||||
* @package chamilo.admin
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
Skill::isAllowed();
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('ManageSkills')];
|
||||
|
||||
/* Process data */
|
||||
$skillId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
|
||||
$objSkill = new Skill();
|
||||
$objGradebook = new Gradebook();
|
||||
$skillInfo = $objSkill->getSkillInfo($skillId);
|
||||
|
||||
if (empty($skillInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$allGradebooks = $objGradebook->find('all');
|
||||
|
||||
$skillDefaultInfo = [
|
||||
'id' => $skillInfo['id'],
|
||||
'name' => $skillInfo['name'],
|
||||
'short_code' => $skillInfo['short_code'],
|
||||
'description' => $skillInfo['description'],
|
||||
'parent_id' => $skillInfo['extra']['parent_id'],
|
||||
'criteria' => $skillInfo['criteria'],
|
||||
'gradebook_id' => [],
|
||||
];
|
||||
|
||||
foreach ($skillInfo['gradebooks'] as $gradebook) {
|
||||
$skillDefaultInfo['gradebook_id'][] = $gradebook['id'];
|
||||
}
|
||||
|
||||
$gradebookList = [];
|
||||
foreach ($allGradebooks as $gradebook) {
|
||||
$gradebookList[$gradebook['id']] = $gradebook['name'];
|
||||
}
|
||||
|
||||
/* Form */
|
||||
$editForm = new FormValidator('skill_edit');
|
||||
$editForm->addHeader(get_lang('SkillEdit'));
|
||||
$returnParams = $objSkill->setForm($editForm, $skillInfo);
|
||||
|
||||
$jquery_ready_content = $returnParams['jquery_ready_content'];
|
||||
|
||||
// the $jquery_ready_content variable collects all functions that will be load
|
||||
// in the $(document).ready javascript function
|
||||
if (!empty($jquery_ready_content)) {
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function () {
|
||||
'.$jquery_ready_content.'
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
$editForm->setDefaults($skillDefaultInfo);
|
||||
if ($editForm->validate()) {
|
||||
$skillValues = $editForm->getSubmitValues();
|
||||
$updated = $objSkill->edit($skillValues);
|
||||
|
||||
$extraFieldValue = new ExtraFieldValue('skill');
|
||||
$extraFieldValue->saveFieldValues($skillValues);
|
||||
|
||||
if ($updated) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('TheSkillHasBeenUpdated'),
|
||||
'success'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('CannotUpdateSkill'),
|
||||
'error'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$toolbar = $objSkill->getToolBar();
|
||||
|
||||
/* view */
|
||||
$tpl = new Template(get_lang('SkillEdit'));
|
||||
$tpl->assign('content', $toolbar.$editForm->returnForm());
|
||||
$tpl->display_one_col_template();
|
||||
37
main/admin/skill_example.csv
Normal file
37
main/admin/skill_example.csv
Normal file
@@ -0,0 +1,37 @@
|
||||
id;parent_id;name;description
|
||||
2;1;Reflection;
|
||||
3;1;Manage learning;
|
||||
4;1;Information literacy;
|
||||
5;1;Organization skills;
|
||||
6;1;Networking w/others;
|
||||
7;1;Researching;
|
||||
8;1;Communication skills;
|
||||
9;1;Creative skills;
|
||||
10;1;Collaboration skills;
|
||||
11;4;Identify info;
|
||||
12;4;Find information;
|
||||
13;5;Personal librarianship;
|
||||
14;5;Personal categorization;Personal categorization and taxonomies
|
||||
15;6;Shared knowledge;Knowing what your network of people knows
|
||||
16;6;Knowledge links;Knowing who might have additional knowledge and resources to help you
|
||||
17;7;Researching;
|
||||
18;7;Canvassing;
|
||||
19;7;Paying attention;
|
||||
20;7;Interviewing;
|
||||
21;7;Observational;Observational 'cultural anthropology' skills
|
||||
22;8;Perception;
|
||||
23;8;Intuition;
|
||||
24;8;Expression;
|
||||
25;8;Visualization;
|
||||
26;8;Interpretation;
|
||||
27;9;Imagination;
|
||||
28;9;Pattern recognition;
|
||||
29;9;Appreciation;
|
||||
30;9;Innovation;
|
||||
31;9;Inference;
|
||||
32;9;Understanding systems;Understanding of complex adaptive systems
|
||||
33;10;Coordination;
|
||||
34;10;Synchronization;
|
||||
35;10;Experimentation;
|
||||
36;10;Cooperation;
|
||||
37;10;Design;
|
||||
|
181
main/admin/skill_level.php
Normal file
181
main/admin/skill_level.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\SkillBundle\Entity\Level;
|
||||
|
||||
/**
|
||||
* Add a skill Level.
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$em = Database::getManager();
|
||||
$profiles = $em->getRepository('ChamiloSkillBundle:Profile')->findAll();
|
||||
$list = $em->getRepository('ChamiloSkillBundle:Level')->findAll();
|
||||
|
||||
$listAction = api_get_self();
|
||||
|
||||
$action = '';
|
||||
if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete', 'add_level'])) {
|
||||
$action = $_GET['action'];
|
||||
}
|
||||
|
||||
$id = isset($_GET['id']) ? $_GET['id'] : '';
|
||||
|
||||
$profileId = !empty($_GET['profile_id']) ? (int) $_GET['profile_id'] : 0;
|
||||
|
||||
$item = null;
|
||||
if (!empty($id)) {
|
||||
/** @var Level $item */
|
||||
$item = $em->getRepository('ChamiloSkillBundle:Level')->find($id);
|
||||
if (!$item) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
$form = new FormValidator('level', 'GET', api_get_self().'?action='.$action.'&id='.$id);
|
||||
$form->addText('name', get_lang('Name'));
|
||||
$form->addText('short_name', get_lang('ShortName'));
|
||||
$form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles);
|
||||
$form->addHidden('action', $action);
|
||||
$form->addHidden('id', $id);
|
||||
// Submit buttons
|
||||
if ($action == 'edit') {
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
} elseif ($action == 'add') {
|
||||
$html_results_enabled[] = $form->createElement('button', 'submit', get_lang('Add'), 'plus', 'primary');
|
||||
$html_results_enabled[] = $form->createElement('button', 'submit_plus', get_lang('Add').'+', 'plus', 'primary');
|
||||
$form->addGroup($html_results_enabled);
|
||||
}
|
||||
|
||||
if (!empty($item)) {
|
||||
$form->setDefaults([
|
||||
'name' => $item->getName(),
|
||||
'short_name' => $item->getShortName(),
|
||||
'profile_id' => $item->getProfile()->getId(),
|
||||
]);
|
||||
} elseif (!empty($profileId)) {
|
||||
$form->setDefaults([
|
||||
'profile_id' => $profileId,
|
||||
]);
|
||||
}
|
||||
|
||||
$formToDisplay = '';
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/skill.php', 'name' => get_lang('ManageSkillsLevels')];
|
||||
$interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('SkillLevels')];
|
||||
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
$formToDisplay = $form->returnForm();
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
if (isset($values['profile_id']) && !empty($values['profile_id'])) {
|
||||
$profileId = (int) $values['profile_id'];
|
||||
$profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($profileId);
|
||||
if ($profile) {
|
||||
$item = new Level();
|
||||
$item->setName($values['name']);
|
||||
$item->setShortName($values['short_name']);
|
||||
$item->setProfile($profile);
|
||||
$em->persist($item);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Added')));
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('Added')));
|
||||
}
|
||||
} else {
|
||||
Display::addFlash(Display::return_message(get_lang('YouNeedToCreateASkillProfile')));
|
||||
}
|
||||
if (isset($values['submit_plus'])) {
|
||||
header('Location: '.$listAction.'?action=add&profile_id='.$profileId);
|
||||
exit;
|
||||
}
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
}
|
||||
$toolbarAction = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('List'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$listAction,
|
||||
['title' => get_lang('List')]
|
||||
);
|
||||
break;
|
||||
case 'edit':
|
||||
$formToDisplay = $form->returnForm();
|
||||
$toolbarAction = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('List'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$listAction,
|
||||
['title' => get_lang('List')]
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
|
||||
$item->setName($values['name']);
|
||||
$item->setShortName($values['short_name']);
|
||||
$profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
|
||||
if ($profile) {
|
||||
$item->setProfile($profile);
|
||||
}
|
||||
|
||||
$em->persist($item);
|
||||
$em->flush();
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
$toolbarAction = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('List'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$listAction,
|
||||
['title' => get_lang('List')]
|
||||
);
|
||||
if ($item) {
|
||||
$em->remove($item);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
}
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
|
||||
break;
|
||||
default:
|
||||
$toolbarAction = Display::url(
|
||||
Display::return_icon(
|
||||
'add.png',
|
||||
get_lang('Add'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_self().'?action=add',
|
||||
['title' => get_lang('Add')]
|
||||
);
|
||||
}
|
||||
|
||||
$tpl = new Template($action);
|
||||
$tpl->assign('form', $formToDisplay);
|
||||
$tpl->assign('list', $list);
|
||||
$templateName = $tpl->get_template('admin/skill_level.tpl');
|
||||
$contentTemplate = $tpl->fetch($templateName);
|
||||
$tpl->assign('actions', Display::toolbarAction('toolbar', [$toolbarAction]));
|
||||
$tpl->assign('content', $contentTemplate);
|
||||
$tpl->display_one_col_template();
|
||||
188
main/admin/skill_list.php
Normal file
188
main/admin/skill_list.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Skill list for management.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
Skill::isAllowed();
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
|
||||
$skillId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
|
||||
switch ($action) {
|
||||
case 'enable':
|
||||
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
|
||||
|
||||
if (is_null($skill)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('SkillNotFound'),
|
||||
'error'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$updatedAt = new DateTime(
|
||||
api_get_utc_datetime(),
|
||||
new DateTimeZone(api_get_timezone())
|
||||
);
|
||||
|
||||
$skill->setStatus(1);
|
||||
$skill->setUpdatedAt($updatedAt);
|
||||
|
||||
$entityManager->persist($skill);
|
||||
$entityManager->flush();
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(get_lang('SkillXEnabled'), $skill->getName()),
|
||||
'success'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
break;
|
||||
case 'disable':
|
||||
/** @var \Chamilo\CoreBundle\Entity\Skill $skill */
|
||||
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
|
||||
|
||||
if (is_null($skill)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('SkillNotFound'),
|
||||
'error'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$updatedAt = new DateTime(
|
||||
api_get_utc_datetime(),
|
||||
new DateTimeZone(api_get_timezone())
|
||||
);
|
||||
|
||||
$skill->setStatus(0);
|
||||
$skill->setUpdatedAt($updatedAt);
|
||||
|
||||
$entityManager->persist($skill);
|
||||
|
||||
$skillObj = new Skill();
|
||||
$children = $skillObj->getChildren($skill->getId());
|
||||
|
||||
foreach ($children as $child) {
|
||||
$skill = $entityManager->find(
|
||||
'ChamiloCoreBundle:Skill',
|
||||
$child['id']
|
||||
);
|
||||
|
||||
if (empty($skill)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$skill->setStatus(0);
|
||||
$skill->setUpdatedAt($updatedAt);
|
||||
$entityManager->persist($skill);
|
||||
}
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(get_lang('SkillXDisabled'), $skill->getName()),
|
||||
'success'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
break;
|
||||
case 'list':
|
||||
default:
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon(
|
||||
'add.png',
|
||||
get_lang('CreateSkill'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/skill_create.php',
|
||||
['title' => get_lang('CreateSkill')]
|
||||
);
|
||||
|
||||
$toolbar .= Display::url(
|
||||
Display::return_icon(
|
||||
'wheel_skill.png',
|
||||
get_lang('SkillsWheel'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
|
||||
['title' => get_lang('SkillsWheel')]
|
||||
);
|
||||
|
||||
$toolbar .= Display::url(
|
||||
Display::return_icon(
|
||||
'import_csv.png',
|
||||
get_lang('ImportSkillsListCSV'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_path(WEB_CODE_PATH).'admin/skills_import.php',
|
||||
['title' => get_lang('ImportSkillsListCSV')]
|
||||
);
|
||||
|
||||
$extraField = new ExtraField('skill');
|
||||
$arrayVals = $extraField->get_handler_field_info_by_tags('tags');
|
||||
$tags = [];
|
||||
|
||||
if (isset($arrayVals['options'])) {
|
||||
foreach ($arrayVals['options'] as $value) {
|
||||
$tags[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/* View */
|
||||
$skill = new Skill();
|
||||
$skillList = $skill->get_all();
|
||||
$extraFieldSearchTagId = isset($_REQUEST['tag_id']) ? $_REQUEST['tag_id'] : 0;
|
||||
|
||||
if ($extraFieldSearchTagId) {
|
||||
$skills = [];
|
||||
$skillsFiltered = $extraField->getAllSkillPerTag($arrayVals['id'], $extraFieldSearchTagId);
|
||||
foreach ($skillList as $index => $value) {
|
||||
if (array_search($index, $skillsFiltered)) {
|
||||
$skills[$index] = $value;
|
||||
}
|
||||
}
|
||||
$skillList = $skills;
|
||||
}
|
||||
|
||||
$tpl = new Template(get_lang('ManageSkills'));
|
||||
$tpl->assign('skills', $skillList);
|
||||
$tpl->assign('current_tag_id', $extraFieldSearchTagId);
|
||||
$tpl->assign('tags', $tags);
|
||||
$templateName = $tpl->get_template('skill/list.tpl');
|
||||
$content = $tpl->fetch($templateName);
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar], [12])
|
||||
);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
break;
|
||||
}
|
||||
180
main/admin/skill_profile.php
Normal file
180
main/admin/skill_profile.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\SkillBundle\Entity\Level;
|
||||
use Chamilo\SkillBundle\Entity\Profile;
|
||||
|
||||
/**
|
||||
* Add a skill Profile.
|
||||
*
|
||||
* @package chamilo.skill
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
$em = Database::getManager();
|
||||
$list = $em->getRepository('ChamiloSkillBundle:Profile')->findAll();
|
||||
|
||||
$listAction = api_get_self();
|
||||
|
||||
$action = '';
|
||||
if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete', 'move_up', 'move_down'])) {
|
||||
$action = $_GET['action'];
|
||||
}
|
||||
|
||||
$id = isset($_GET['id']) ? $_GET['id'] : '';
|
||||
|
||||
$item = null;
|
||||
if (!empty($id)) {
|
||||
$item = $em->getRepository('ChamiloSkillBundle:Profile')->find($id);
|
||||
if (!$item) {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
$form = new FormValidator('Profile', 'GET', api_get_self().'?action='.$action.'&id='.$id);
|
||||
$form->addText('name', get_lang('Name'));
|
||||
$form->addHidden('action', $action);
|
||||
$form->addHidden('id', $id);
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if (!empty($item)) {
|
||||
$form->setDefaults(['name' => $item->getName()]);
|
||||
}
|
||||
$formToDisplay = $form->returnForm();
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/skill.php', 'name' => get_lang('ManageSkillsLevels')];
|
||||
$interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('SkillLevelProfiles')];
|
||||
|
||||
$toolbar = null;
|
||||
|
||||
$tpl = new Template($action);
|
||||
switch ($action) {
|
||||
case 'move_up':
|
||||
/** @var Level $item */
|
||||
$item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
|
||||
if ($item) {
|
||||
$position = $item->getPosition();
|
||||
if (!empty($position)) {
|
||||
$item->setPosition($position - 1);
|
||||
}
|
||||
$em->persist($item);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
}
|
||||
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
break;
|
||||
case 'move_down':
|
||||
/** @var Level $item */
|
||||
$item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
|
||||
if ($item) {
|
||||
$position = $item->getPosition();
|
||||
$item->setPosition($position + 1);
|
||||
$em->persist($item);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
}
|
||||
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
break;
|
||||
case 'add':
|
||||
$tpl->assign('form', $formToDisplay);
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$item = new Profile();
|
||||
$item->setName($values['name']);
|
||||
$em->persist($item);
|
||||
$em->flush();
|
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Added')));
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
}
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('List'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$listAction,
|
||||
['title' => get_lang('List')]
|
||||
);
|
||||
break;
|
||||
case 'edit':
|
||||
$tpl->assign('form', $formToDisplay);
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('List'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$listAction,
|
||||
['title' => get_lang('List')]
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$item->setName($values['name']);
|
||||
$em->persist($item);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'delete':
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon(
|
||||
'list_badges.png',
|
||||
get_lang('List'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
$listAction,
|
||||
['title' => get_lang('List')]
|
||||
);
|
||||
|
||||
try {
|
||||
$em->remove($item);
|
||||
$em->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted')));
|
||||
} catch (Exception $e) {
|
||||
Display::addFlash(Display::return_message(get_lang('DeleteError'), 'error'));
|
||||
}
|
||||
header('Location: '.$listAction);
|
||||
exit;
|
||||
break;
|
||||
default:
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon(
|
||||
'add.png',
|
||||
get_lang('Add'),
|
||||
null,
|
||||
ICON_SIZE_MEDIUM
|
||||
),
|
||||
api_get_self().'?action=add',
|
||||
['title' => get_lang('Add')]
|
||||
);
|
||||
}
|
||||
|
||||
$tpl->assign('list', $list);
|
||||
$templateName = $tpl->get_template('admin/skill_profile.tpl');
|
||||
$contentTemplate = $tpl->fetch($templateName);
|
||||
|
||||
if ($toolbar) {
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
}
|
||||
|
||||
$tpl->assign('content', $contentTemplate);
|
||||
$tpl->display_one_col_template();
|
||||
61
main/admin/skill_rel_course.php
Normal file
61
main/admin/skill_rel_course.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
if (api_get_configuration_value('allow_skill_rel_items') == false) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$htmlContentExtraClass[] = 'feature-item-user-skill-on';
|
||||
|
||||
$courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
|
||||
|
||||
$course = api_get_course_entity($courseId);
|
||||
if (empty($course)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : null;
|
||||
|
||||
$url = api_get_self().'?course_id='.$courseId.'&session_id='.$sessionId;
|
||||
$form = new FormValidator('skills', 'post', $url);
|
||||
|
||||
$sessionName = $course->getTitleAndCode();
|
||||
if (!empty($sessionId)) {
|
||||
$session = api_get_session_entity($sessionId);
|
||||
$courseExistsInSession = SessionManager::sessionHasCourse($sessionId, $course->getCode());
|
||||
if (!$courseExistsInSession) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$sessionName = ' '.$session->getName().' - '.$course->getTitleAndCode();
|
||||
}
|
||||
|
||||
$form->addHeader(get_lang('AddSkills').$sessionName);
|
||||
Skill::setSkillsToCourse($form, $courseId, $sessionId);
|
||||
|
||||
/*$form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if ($form->validate()) {
|
||||
$result = Skill::saveSkillsToCourseFromForm($form);
|
||||
if ($result) {
|
||||
Display::addFlash(Display::return_message(get_lang('Updated')));
|
||||
}
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}*/
|
||||
$content = $form->returnForm();
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'session/session_list.php',
|
||||
'name' => get_lang('SessionList'),
|
||||
];
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$sessionId,
|
||||
'name' => get_lang('SessionOverview'),
|
||||
];
|
||||
|
||||
$template = new Template(get_lang('SkillRelCourses'));
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
109
main/admin/skill_translate.php
Normal file
109
main/admin/skill_translate.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
|
||||
use Chamilo\CoreBundle\Entity\Language;
|
||||
use Chamilo\CoreBundle\Entity\Skill;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$em = Database::getManager();
|
||||
|
||||
$skill = null;
|
||||
$extraFieldOption = null;
|
||||
$variableLanguage = null;
|
||||
$originalName = null;
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'name';
|
||||
|
||||
if (isset($_GET['skill'])) {
|
||||
/** @var Skill $skill */
|
||||
$skill = $em->find('ChamiloCoreBundle:Skill', intval($_GET['skill']));
|
||||
|
||||
if ($action === 'name') {
|
||||
$variableLanguage = ChamiloApi::getLanguageVar(
|
||||
$skill->getName(false),
|
||||
'Skill'
|
||||
);
|
||||
$originalName = $skill->getName(false);
|
||||
} elseif ($action === 'code') {
|
||||
$variableLanguage = ChamiloApi::getLanguageVar(
|
||||
$skill->getShortCode(false),
|
||||
'SkillCode'
|
||||
);
|
||||
$originalName = $skill->getShortCode(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$skill || empty($variableLanguage)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (empty($originalName)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('CanNotTranslate'), 'error')
|
||||
);
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_edit.php?id='.$skill->getId());
|
||||
exit;
|
||||
}
|
||||
|
||||
$languageId = isset($_GET['sub_language']) ? intval($_GET['sub_language']) : 0;
|
||||
|
||||
$languages = $em
|
||||
->getRepository('ChamiloCoreBundle:Language')
|
||||
->findAllPlatformSubLanguages();
|
||||
|
||||
$languagesOptions = [0 => get_lang('None')];
|
||||
|
||||
/** @var Language $language */
|
||||
foreach ($languages as $language) {
|
||||
$languagesOptions[$language->getId()] = $language->getOriginalName();
|
||||
}
|
||||
|
||||
$translateUrl = api_get_path(WEB_CODE_PATH).'admin/sub_language_ajax.inc.php?skill='.$skill->getId();
|
||||
|
||||
$form = new FormValidator('new_lang_variable', 'POST', $translateUrl);
|
||||
$form->addHeader(get_lang('AddWordForTheSubLanguage'));
|
||||
$form->addText('variable_language', get_lang('LanguageVariable'), false);
|
||||
$form->addText('original_name', get_lang('OriginalName'), false);
|
||||
$form->addSelect(
|
||||
'sub_language',
|
||||
[get_lang('SubLanguage'), get_lang('OnlyActiveSubLanguagesAreListed')],
|
||||
$languagesOptions
|
||||
);
|
||||
|
||||
if ($languageId) {
|
||||
$languageInfo = api_get_language_info($languageId);
|
||||
$form->addText(
|
||||
'new_language',
|
||||
[get_lang('Translation'), get_lang('IfThisTranslationExistsThisWillReplaceTheTerm')]
|
||||
);
|
||||
$form->addHidden('file_id', 0);
|
||||
$form->addHidden('id', $languageInfo['parent_id']);
|
||||
$form->addHidden('sub', $languageInfo['id']);
|
||||
$form->addHidden('sub_language_id', $languageInfo['id']);
|
||||
$form->addHidden('redirect', true);
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
}
|
||||
|
||||
$form->setDefaults([
|
||||
'variable_language' => '$'.$variableLanguage,
|
||||
'original_name' => $originalName,
|
||||
'sub_language' => $languageId,
|
||||
'new_language' => $action === 'code' ? $skill->getShortCode() : $skill->getName(),
|
||||
]);
|
||||
$form->addRule('sub_language', get_lang('Required'), 'required');
|
||||
$form->freeze(['variable_language', 'original_name']);
|
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
$interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('ManageSkills')];
|
||||
|
||||
$view = new Template(get_lang('AddWordForTheSubLanguage'));
|
||||
$view->assign('form', $form->returnForm());
|
||||
$template = $view->get_template('extrafield/translate.tpl');
|
||||
$content = $view->fetch($template);
|
||||
$view->assign('content', $content);
|
||||
$view->display_one_col_template();
|
||||
34
main/admin/skills.php
Normal file
34
main/admin/skills.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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();
|
||||
Skill::isAllowed();
|
||||
|
||||
//Adds the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');
|
||||
$htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
|
||||
$htmlHeadXtra[] = api_get_js('skills.js');
|
||||
|
||||
$skill = new Skill();
|
||||
$type = 'edit'; //edit
|
||||
$tree = $skill->getSkillsTree(null, null, true);
|
||||
$skill_visualizer = new SkillVisualizer($tree, $type);
|
||||
|
||||
$html = $skill_visualizer->return_html();
|
||||
$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?1=1';
|
||||
|
||||
$tpl = new Template(null, false, false);
|
||||
$tpl->assign('url', $url);
|
||||
$tpl->assign('html', $html);
|
||||
$tpl->assign('skill_visualizer', $skill_visualizer);
|
||||
$tpl->assign('js', $skill_visualizer->return_js());
|
||||
$templateName = $tpl->get_template('skill/skill_tree.tpl');
|
||||
$content = $tpl->fetch($templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_no_layout_template();
|
||||
132
main/admin/skills_gradebook.php
Normal file
132
main/admin/skills_gradebook.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?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();
|
||||
Skill::isAllowed();
|
||||
|
||||
//Adds the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'display';
|
||||
|
||||
// setting breadcrumbs
|
||||
$tool_name = get_lang('SkillsAndGradebooks');
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
||||
if ($action == 'add_skill') {
|
||||
$interbreadcrumb[] = ['url' => 'skills_gradebook.php', 'name' => get_lang('SkillsAndGradebooks')];
|
||||
$tool_name = get_lang('Add');
|
||||
}
|
||||
|
||||
$gradebook = new Gradebook();
|
||||
switch ($action) {
|
||||
case 'display':
|
||||
$content = $gradebook->returnGrid();
|
||||
break;
|
||||
case 'add_skill':
|
||||
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
|
||||
$gradebook_info = $gradebook->get($id);
|
||||
$url = api_get_self().'?action='.$action.'&id='.$id;
|
||||
$form = $gradebook->show_skill_form($id, $url, $gradebook_info['name']);
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$gradebook->updateSkillsToGradeBook($values['id'], $values['skill']);
|
||||
Display::addFlash(Display::return_message(get_lang('ItemAdded'), 'confirm'));
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
$content = $form->returnForm();
|
||||
break;
|
||||
}
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
//jqgrid will use this URL to do the selects
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_gradebooks';
|
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file
|
||||
$columns = [
|
||||
get_lang('Name'),
|
||||
get_lang('CertificatesFiles'),
|
||||
get_lang('Skills'),
|
||||
get_lang('Actions'),
|
||||
];
|
||||
|
||||
//Column config
|
||||
$column_model = [
|
||||
[
|
||||
'name' => 'name',
|
||||
'index' => 'name',
|
||||
'width' => '150',
|
||||
'align' => 'left',
|
||||
],
|
||||
[
|
||||
'name' => 'certificate',
|
||||
'index' => 'certificate',
|
||||
'width' => '25',
|
||||
'align' => 'left',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
[
|
||||
'name' => 'skills',
|
||||
'index' => 'skills',
|
||||
'width' => '300',
|
||||
'align' => 'left',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
[
|
||||
'name' => 'actions',
|
||||
'index' => 'actions',
|
||||
'width' => '30',
|
||||
'align' => 'left',
|
||||
'formatter' => 'action_formatter',
|
||||
'sortable' => 'false',
|
||||
],
|
||||
];
|
||||
//Autowidth
|
||||
$extra_params['autowidth'] = 'true';
|
||||
//height auto
|
||||
$extra_params['height'] = 'auto';
|
||||
|
||||
$iconAdd = Display::return_icon('add.png', addslashes(get_lang('AddSkill')));
|
||||
$iconAddNa = Display::return_icon(
|
||||
'add_na.png',
|
||||
addslashes(get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'))
|
||||
);
|
||||
|
||||
//With this function we can add actions to the jgrid (edit, delete, etc)
|
||||
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
|
||||
//certificates
|
||||
if (rowObject[4] == 1) {
|
||||
return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.$iconAdd.'</a>'.'\';
|
||||
} else {
|
||||
return \''.$iconAddNa.'\';
|
||||
}
|
||||
}';
|
||||
?>
|
||||
<script>
|
||||
$(function() {
|
||||
<?php
|
||||
// grid definition see the $career->display() function
|
||||
echo Display::grid_js(
|
||||
'gradebooks',
|
||||
$url,
|
||||
$columns,
|
||||
$column_model,
|
||||
$extra_params,
|
||||
[],
|
||||
$action_links,
|
||||
true
|
||||
);
|
||||
?>
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
echo $content;
|
||||
|
||||
Display::display_footer();
|
||||
217
main/admin/skills_import.php
Normal file
217
main/admin/skills_import.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* This tool allows platform admins to add skills by uploading a CSV or XML file.
|
||||
*
|
||||
* @documentation Some interesting basic skills can be found in the "Skills"
|
||||
* section here: http://en.wikipedia.org/wiki/Personal_knowledge_management
|
||||
*/
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
/**
|
||||
* Validate the imported data.
|
||||
*
|
||||
* @param $skills
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function validate_data($skills)
|
||||
{
|
||||
$errors = [];
|
||||
// 1. Check if mandatory fields are set.
|
||||
$mandatory_fields = ['id', 'parent_id', 'name'];
|
||||
foreach ($skills as $index => $skill) {
|
||||
foreach ($mandatory_fields as $field) {
|
||||
if (empty($skill[$field])) {
|
||||
$skill['error'] = get_lang(ucfirst($field).'Mandatory');
|
||||
$errors[] = $skill;
|
||||
}
|
||||
}
|
||||
// 2. Check skill ID is not empty
|
||||
if (!isset($skill['id']) || empty($skill['id'])) {
|
||||
$skill['error'] = get_lang('SkillImportNoID');
|
||||
$errors[] = $skill;
|
||||
}
|
||||
// 3. Check skill Parent
|
||||
if (!isset($skill['parent_id'])) {
|
||||
$skill['error'] = get_lang('SkillImportNoParent');
|
||||
$errors[] = $skill;
|
||||
}
|
||||
// 4. Check skill Name
|
||||
if (!isset($skill['name'])) {
|
||||
$skill['error'] = get_lang('SkillImportNoName');
|
||||
$errors[] = $skill;
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the imported data.
|
||||
*
|
||||
* @param array List of users
|
||||
*
|
||||
* @uses \global variable $inserted_in_course,
|
||||
* which returns the list of courses the user was inserted in
|
||||
*/
|
||||
function save_data($skills)
|
||||
{
|
||||
if (is_array($skills)) {
|
||||
$parents = [];
|
||||
$urlId = api_get_current_access_url_id();
|
||||
foreach ($skills as $index => $skill) {
|
||||
if (isset($parents[$skill['parent_id']])) {
|
||||
$skill['parent_id'] = $parents[$skill['parent_id']];
|
||||
} else {
|
||||
$skill['parent_id'] = 1;
|
||||
}
|
||||
if (empty($skill['access_url_id'])) {
|
||||
$skill['access_url_id'] = $urlId;
|
||||
}
|
||||
$skill['a'] = 'add';
|
||||
$saved_id = $skill['id'];
|
||||
$skill['id'] = null;
|
||||
$oskill = new Skill();
|
||||
$skill_id = $oskill->add($skill);
|
||||
$parents[$saved_id] = $skill_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the CSV-file.
|
||||
*
|
||||
* @param string $file Path to the CSV-file
|
||||
*
|
||||
* @return array All userinformation read from the file
|
||||
*/
|
||||
function parse_csv_data($file)
|
||||
{
|
||||
$skills = Import::csvToArray($file);
|
||||
foreach ($skills as $index => $skill) {
|
||||
$skills[$index] = $skill;
|
||||
}
|
||||
|
||||
return $skills;
|
||||
}
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$tool_name = get_lang('ImportSkillsListCSV');
|
||||
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
|
||||
|
||||
set_time_limit(0);
|
||||
$extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', true);
|
||||
$user_id_error = [];
|
||||
$error_message = '';
|
||||
|
||||
if (!empty($_POST['formSent']) && $_FILES['import_file']['size'] !== 0) {
|
||||
$file_type = $_POST['file_type'];
|
||||
Security::clear_token();
|
||||
$tok = Security::get_token();
|
||||
$allowed_file_mimetype = ['csv'];
|
||||
$error_kind_file = false;
|
||||
$error_message = '';
|
||||
|
||||
$ext_import_file = substr($_FILES['import_file']['name'], (strrpos($_FILES['import_file']['name'], '.') + 1));
|
||||
|
||||
if (in_array($ext_import_file, $allowed_file_mimetype)) {
|
||||
if (strcmp($file_type, 'csv') === 0 && $ext_import_file == $allowed_file_mimetype[0]) {
|
||||
$skills = parse_csv_data($_FILES['import_file']['tmp_name']);
|
||||
$errors = validate_data($skills);
|
||||
$error_kind_file = false;
|
||||
} else {
|
||||
$error_kind_file = true;
|
||||
}
|
||||
} else {
|
||||
$error_kind_file = true;
|
||||
}
|
||||
|
||||
// List skill id with error.
|
||||
$skills_to_insert = $skill_id_error = [];
|
||||
if (is_array($errors)) {
|
||||
foreach ($errors as $my_errors) {
|
||||
$skill_id_error[] = $my_errors['SkillName'];
|
||||
}
|
||||
}
|
||||
if (is_array($skills)) {
|
||||
foreach ($skills as $my_skill) {
|
||||
if (isset($my_skill['name']) && !in_array($my_skill['name'], $skill_id_error)) {
|
||||
$skills_to_insert[] = $my_skill;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp($file_type, 'csv') === 0) {
|
||||
save_data($skills_to_insert);
|
||||
} else {
|
||||
$error_message = get_lang('YouMustImportAFileAccordingToSelectedOption');
|
||||
}
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$see_message_import = get_lang('FileImportedJustSkillsThatAreNotRegistered');
|
||||
} else {
|
||||
$see_message_import = get_lang('FileImported');
|
||||
}
|
||||
|
||||
if (count($errors) != 0) {
|
||||
$warning_message = '<ul>';
|
||||
foreach ($errors as $index => $error_skill) {
|
||||
$warning_message .= '<li><b>'.$error_skill['error'].'</b>: ';
|
||||
$warning_message .= '<strong>'.$error_skill['SkillName'].'</strong> ('.$error_skill['SkillName'].')';
|
||||
$warning_message .= '</li>';
|
||||
}
|
||||
$warning_message .= '</ul>';
|
||||
}
|
||||
|
||||
if ($error_kind_file) {
|
||||
$error_message = get_lang('YouMustImportAFileAccordingToSelectedOption');
|
||||
}
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ["url" => 'skill_list.php', "name" => get_lang('ManageSkills')];
|
||||
|
||||
Display::display_header($tool_name);
|
||||
|
||||
if (!empty($error_message)) {
|
||||
echo Display::return_message($error_message, 'error');
|
||||
}
|
||||
if (!empty($see_message_import)) {
|
||||
echo Display::return_message($see_message_import, 'normal');
|
||||
}
|
||||
|
||||
$objSkill = new Skill();
|
||||
echo $objSkill->getToolBar();
|
||||
|
||||
$form = new FormValidator('user_import', 'post', 'skills_import.php');
|
||||
$form->addElement('header', '', $tool_name);
|
||||
$form->addElement('hidden', 'formSent');
|
||||
$form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
|
||||
$group = [];
|
||||
$group[] = $form->createElement(
|
||||
'radio',
|
||||
'file_type',
|
||||
'',
|
||||
'CSV (<a href="skill_example.csv" target="_blank" download>'.get_lang('ExampleCSVFile').'</a>)',
|
||||
'csv'
|
||||
);
|
||||
$form->addGroup($group, '', get_lang('FileType'));
|
||||
$form->addButtonImport(get_lang('Import'));
|
||||
$defaults['formSent'] = 1;
|
||||
$defaults['sendMail'] = 0;
|
||||
$defaults['file_type'] = 'csv';
|
||||
$form->setDefaults($defaults);
|
||||
$form->display();
|
||||
|
||||
?>
|
||||
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
|
||||
|
||||
<pre>
|
||||
<b>id</b>;<b>parent_id</b>;<b>name</b>;<b>description</b>
|
||||
<b>2</b>;<b>1</b>;<b>Chamilo Expert</b>;Chamilo is an open source LMS;<br />
|
||||
</pre>
|
||||
<?php
|
||||
Display::display_footer();
|
||||
140
main/admin/skills_profile.php
Normal file
140
main/admin/skills_profile.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
$cidReset = true;
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script();
|
||||
Skill::isAllowed();
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'index.php',
|
||||
"name" => get_lang('PlatformAdmin'),
|
||||
];
|
||||
|
||||
$skill = new Skill();
|
||||
$skill_profile = new SkillProfile();
|
||||
$skill_rel_user = new SkillRelUser();
|
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php';
|
||||
$tpl = new Template(get_lang('Skills'));
|
||||
$form = new FormValidator('profile_search');
|
||||
|
||||
$form->addElement('header', get_lang('SearchSkills'));
|
||||
$form->addElement('select', 'skills', null, null, ['id' => 'skills']);
|
||||
$form->addButtonSearch(get_lang('Search'));
|
||||
|
||||
$profiles = $skill_profile->get_all();
|
||||
|
||||
$tpl->assign('profiles', $profiles);
|
||||
|
||||
$total_skills_to_search = [];
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
|
||||
$skills = $values['skills'];
|
||||
if (!empty($skills)) {
|
||||
$hidden_skills = isset($values['hidden_skills']) ? $values['hidden_skills'] : [];
|
||||
$skills = array_merge($skills, $hidden_skills);
|
||||
$skills = array_filter($skills);
|
||||
$skills = array_unique($skills);
|
||||
Session::write('skills', $skills);
|
||||
} else {
|
||||
$skills = Session::read('skills', []);
|
||||
}
|
||||
} else {
|
||||
$skills = Session::read('skills', []);
|
||||
}
|
||||
|
||||
$user_list = [];
|
||||
$count_skills = count($skills);
|
||||
$users = $skill_rel_user->getUserBySkills($skills);
|
||||
|
||||
if (!empty($users)) {
|
||||
foreach ($users as $user) {
|
||||
$user_info = api_get_user_info($user['user_id']);
|
||||
$user_list[$user['user_id']]['user'] = $user_info;
|
||||
$my_user_skills = $skill_rel_user->getUserSkills($user['user_id']);
|
||||
$user_skills = [];
|
||||
$found_counts = 0;
|
||||
foreach ($my_user_skills as $my_skill) {
|
||||
$found = false;
|
||||
if (in_array($my_skill['skill_id'], $skills)) {
|
||||
$found = true;
|
||||
$found_counts++;
|
||||
}
|
||||
$user_skills[] = [
|
||||
'skill_id' => $my_skill['skill_id'],
|
||||
'found' => $found,
|
||||
];
|
||||
$total_skills_to_search[$my_skill['skill_id']] = $my_skill['skill_id'];
|
||||
}
|
||||
$user_list[$user['user_id']]['skills'] = $user_skills;
|
||||
$user_list[$user['user_id']]['total_found_skills'] = $found_counts;
|
||||
}
|
||||
$ordered_user_list = [];
|
||||
foreach ($user_list as $user_id => $user_data) {
|
||||
$ordered_user_list[$user_data['total_found_skills']][] = $user_data;
|
||||
}
|
||||
if (!empty($ordered_user_list)) {
|
||||
asort($ordered_user_list);
|
||||
}
|
||||
}
|
||||
|
||||
$tpl->assign('order_user_list', $ordered_user_list);
|
||||
$tpl->assign('total_search_skills', $count_skills);
|
||||
|
||||
if (!empty($skills)) {
|
||||
$counter = 0;
|
||||
foreach ($skills as $hidden_skill_id) {
|
||||
$form->addElement('hidden', 'hidden_skills[]', $hidden_skill_id);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($skills)) {
|
||||
foreach ($skills as $my_skill) {
|
||||
$total_skills_to_search[$my_skill] = $my_skill;
|
||||
}
|
||||
}
|
||||
|
||||
$total_skills_to_search = $skill->getSkillsInfo($total_skills_to_search);
|
||||
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
|
||||
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
|
||||
|
||||
switch ($action) {
|
||||
case 'remove_skill':
|
||||
$new_skill = [];
|
||||
foreach ($skills as $skill_id) {
|
||||
if ($id != $skill_id) {
|
||||
$new_skill[] = $skill_id;
|
||||
}
|
||||
}
|
||||
$skills = $new_skill;
|
||||
Session::write('skills', $skills);
|
||||
break;
|
||||
case 'load_profile':
|
||||
$skill_profile = new SkillRelProfile();
|
||||
$skills = $skill_profile->getSkillsByProfile($id);
|
||||
$total_skills_to_search = $skill->getSkillsInfo($skills);
|
||||
break;
|
||||
}
|
||||
|
||||
$skill_list = [];
|
||||
foreach ($total_skills_to_search as $skill_info) {
|
||||
$skill_list[$skill_info['id']] = $skill_info;
|
||||
}
|
||||
|
||||
$tpl->assign('skill_list', $skill_list);
|
||||
$tpl->assign('search_skill_list', $skills);
|
||||
$form_to_html = $form->returnForm();
|
||||
$tpl->assign('form', $form_to_html);
|
||||
$tpl->assign('url', $url);
|
||||
$templateName = $tpl->get_template('skill/profile.tpl');
|
||||
$content = $tpl->fetch($templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
95
main/admin/skills_wheel.php
Normal file
95
main/admin/skills_wheel.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request as HttpRequest;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN;
|
||||
|
||||
api_protect_admin_script(false, true);
|
||||
Skill::isAllowed();
|
||||
|
||||
$httpRequest = HttpRequest::createFromGlobals();
|
||||
|
||||
//Adds the JS needed to use the jqgrid
|
||||
$htmlHeadXtra[] = api_get_js('d3/d3.v3.5.4.min.js');
|
||||
$htmlHeadXtra[] = api_get_js('d3/colorbrewer.js');
|
||||
$htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
|
||||
|
||||
$tpl = new Template(null, false, false);
|
||||
|
||||
$load_user = 0;
|
||||
if (isset($_GET['load_user'])) {
|
||||
$load_user = 1;
|
||||
}
|
||||
|
||||
$skill_condition = '';
|
||||
if (isset($_GET['skill_id'])) {
|
||||
$skillId = $httpRequest->query->getInt('skill_id');
|
||||
$skill_condition = "&skill_id=$skillId";
|
||||
$tpl->assign('skill_id_to_load', $skillId);
|
||||
}
|
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH)."skill.ajax.php?a=get_skills_tree_json&load_user=$load_user";
|
||||
$tpl->assign('wheel_url', $url);
|
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?1=1';
|
||||
$tpl->assign('url', $url);
|
||||
$tpl->assign('isAdministration', true);
|
||||
|
||||
$dialogForm = new FormValidator('form', 'post', null, null, ['id' => 'add_item']);
|
||||
$dialogForm->addLabel(
|
||||
get_lang('Name'),
|
||||
Display::tag('p', null, ['id' => 'name', 'class' => 'form-control-static'])
|
||||
);
|
||||
$dialogForm->addLabel(
|
||||
get_lang('ShortCode'),
|
||||
Display::tag('p', null, ['id' => 'short_code', 'class' => 'form-control-static'])
|
||||
);
|
||||
$dialogForm->addLabel(
|
||||
get_lang('Parent'),
|
||||
Display::tag('p', null, ['id' => 'parent', 'class' => 'form-control-static'])
|
||||
);
|
||||
$dialogForm->addLabel(
|
||||
[get_lang('Gradebook'), get_lang('WithCertificate')],
|
||||
Display::tag('ul', null, ['id' => 'gradebook', 'class' => 'form-control-static list-unstyled'])
|
||||
);
|
||||
$dialogForm->addLabel(
|
||||
get_lang('Description'),
|
||||
Display::tag(
|
||||
'p',
|
||||
null,
|
||||
['id' => 'description', 'class' => 'form-control-static']
|
||||
)
|
||||
);
|
||||
|
||||
$tpl->assign('dialogForm', $dialogForm->returnForm());
|
||||
|
||||
$saveProfileForm = new FormValidator(
|
||||
'form',
|
||||
'post',
|
||||
null,
|
||||
null,
|
||||
['id' => 'dialog-form-profile']
|
||||
);
|
||||
$saveProfileForm->addHidden('profile_id', null);
|
||||
$saveProfileForm->addText(
|
||||
'name',
|
||||
get_lang('Name'),
|
||||
true,
|
||||
['id' => 'name_profile']
|
||||
);
|
||||
$saveProfileForm->addTextarea(
|
||||
'description',
|
||||
get_lang('Description'),
|
||||
['id' => 'description_profile', 'rows' => 6]
|
||||
);
|
||||
$tpl->assign('save_profile_form', $saveProfileForm->returnForm());
|
||||
$templateName = $tpl->get_template('skill/skill_wheel.tpl');
|
||||
$content = $tpl->fetch($templateName);
|
||||
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_no_layout_template();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user