LpCalendar WIP - See BT#14608

- New config: private_messages_about_user_visible_to_user,
allow_teachers_to_classes

- Format code, ui fixes for the new calendar year view
pull/2588/merge
Julio Montoya 7 years ago
parent 1e88d0f484
commit 834622f8f6
  1. 22
      main/admin/add_courses_to_usergroup.php
  2. 20
      main/admin/add_sessions_to_usergroup.php
  3. 29
      main/admin/add_users_to_usergroup.php
  4. 40
      main/admin/usergroup_users.php
  5. 269
      main/admin/usergroups.php
  6. 9
      main/auth/my_progress.php
  7. 12
      main/course_info/infocours.php
  8. 55
      main/inc/ajax/model.ajax.php
  9. 2
      main/inc/ajax/user_manager.ajax.php
  10. 18
      main/inc/lib/course.lib.php
  11. 44
      main/inc/lib/message.lib.php
  12. 79
      main/inc/lib/sessionmanager.lib.php
  13. 122
      main/inc/lib/usergroup.lib.php
  14. 16
      main/inc/lib/usermanager.lib.php
  15. 20
      main/inc/lib/userportal.lib.php
  16. 6
      main/install/configuration.dist.php
  17. 4
      main/lp/learnpath.class.php
  18. 25
      main/mySpace/index.php
  19. 34
      main/mySpace/myStudents.php
  20. 2
      main/ticket/tickets.php
  21. 6
      main/user/class.php
  22. 2
      main/user/classes.php
  23. 266
      plugin/lp_calendar/LpCalendarPlugin.php
  24. 77
      plugin/lp_calendar/ajax.php
  25. 19
      plugin/lp_calendar/calendar.php
  26. 108
      plugin/lp_calendar/calendar_users.php
  27. 5
      plugin/lp_calendar/lang/english.php
  28. 3
      plugin/lp_calendar/lang/french.php
  29. 49
      plugin/lp_calendar/start.php
  30. 43
      plugin/lp_calendar/view/calendar.tpl
  31. 7
      src/Chamilo/CoreBundle/Entity/Usergroup.php
  32. 2
      user_portal.php

@ -10,8 +10,10 @@ $cidReset = true;
// Including some necessary files.
require_once __DIR__.'/../inc/global.inc.php';
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$usergroup = new UserGroup();
$usergroup->protectScript();
$data = $usergroup->get($id);
$usergroup->protectScript($data);
$xajax = new xajax();
$xajax->registerFunction('search');
@ -48,7 +50,6 @@ function remove_item(origin) {
$form_sent = 0;
$errorMsg = '';
$sessions = [];
$id = intval($_GET['id']);
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$form_sent = $_POST['form_sent'];
@ -96,8 +97,17 @@ if (!empty($filters) && !empty($filterData)) {
}
}
$data = $usergroup->get($id);
$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,
@ -107,11 +117,11 @@ $course_list = CourseManager::get_courses_list(
null,
api_get_current_access_url_id(),
false,
$conditions
$conditions,
$onlyThisCourseList
);
$elements_not_in = $elements_in = [];
foreach ($course_list_in as $course) {
$elements_in[$course['id']] = $course['title']." (".$course['visual_code'].")";
}
@ -127,7 +137,7 @@ if (!empty($course_list)) {
$ajax_search = $add_type == 'unique' ? true : false;
//checking for extra field with filter on
// checking for extra field with filter on
function search($needle, $type)
{
global $elements_in;

@ -9,8 +9,10 @@ $cidReset = true;
// including some necessary files
require_once __DIR__.'/../inc/global.inc.php';
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$usergroup = new UserGroup();
$usergroup->protectScript();
$data = $usergroup->get($id);
$usergroup->protectScript($data);
$xajax = new xajax();
$xajax->registerFunction('search_usergroup_sessions');
@ -33,7 +35,6 @@ if (isset($_REQUEST['add_type']) && $_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");
@ -42,7 +43,6 @@ function add_user_to_session (code, content) {
return false;
}
}
destination.options[destination.length] = new Option(content,code);
destination.selectedIndex = -1;
sortOptions(destination.options);
@ -76,8 +76,6 @@ function validate_filter() {
$form_sent = 0;
$errorMsg = '';
$sessions = [];
$usergroup = new UserGroup();
$id = intval($_GET['id']);
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$form_sent = $_POST['form_sent'];
$elements_posted = $_POST['elements_in_name'];
@ -91,9 +89,17 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
exit;
}
}
$data = $usergroup->get($id);
$session_list_in = $usergroup->get_sessions_by_usergroup($id);
$session_list = SessionManager::get_sessions_list([], ['name']);
$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)) {

@ -14,8 +14,11 @@ 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'] : '';
$usergroup = new UserGroup();
$usergroup->protectScript();
$groupInfo = $usergroup->get($id);
$usergroup->protectScript($groupInfo);
// setting breadcrumbs
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
@ -24,8 +27,7 @@ $interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
// setting the name of the tool
$tool_name = get_lang('SubscribeUsersToClass');
$id = intval($_GET['id']);
$relation = isset($_REQUEST['relation']) ? intval($_REQUEST['relation']) : '';
$htmlHeadXtra[] = '
<script>
@ -104,8 +106,6 @@ if (empty($id)) {
api_not_allowed(true);
}
$groupInfo = $usergroup->get($id);
$first_letter_user = '';
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
@ -240,7 +240,19 @@ if (!empty($filters) && !empty($filterData)) {
}
$elements_not_in = $elements_in = [];
$complete_user_list = UserManager::get_user_list_like([], $order);
$onlyThisUserList = [];
if ($usergroup->allowTeachers()) {
$userId = api_get_user_id();
$courseList = CourseManager::getCoursesFollowedByUser($userId, COURSEMANAGER);
foreach ($courseList as $course) {
$userList = CourseManager::get_user_list_from_course_code($course['code'], 0, null, null, STUDENT);
$userList = array_column($userList, 'user_id');
$onlyThisUserList = array_merge($onlyThisUserList, $userList);
}
}
$complete_user_list = UserManager::getUserListLike([], $order, false, 'AND', $onlyThisUserList);
if (!empty($complete_user_list)) {
foreach ($complete_user_list as $item) {
@ -277,9 +289,8 @@ if (!empty($complete_user_list)) {
}
$user_with_any_group = isset($_REQUEST['user_with_any_group']) && !empty($_REQUEST['user_with_any_group']) ? true : false;
if ($user_with_any_group) {
$user_list = UserManager::get_user_list_like($conditions, $order, true);
$user_list = UserManager::getUserListLike($conditions, $order, true, 'AND', $onlyThisUserList);
$new_user_list = [];
foreach ($user_list as $item) {
if (!in_array($item['user_id'], $list_all)) {
@ -288,7 +299,7 @@ if ($user_with_any_group) {
}
$user_list = $new_user_list;
} else {
$user_list = UserManager::get_user_list_like($conditions, $order, true);
$user_list = UserManager::getUserListLike($conditions, $order, true, 'AND', $onlyThisUserList);
}
if (!empty($user_list)) {

@ -9,36 +9,40 @@ require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$usergroup = new UserGroup();
$userGroupInfo = $usergroup->get($id);
if (empty($userGroupInfo)) {
api_not_allowed(true);
}
$usergroup->protectScript();
$usergroup->protectScript($userGroupInfo);
$calendarPlugin = null;
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') {
$calendarPlugin = LpCalendarPlugin::create();
}
// Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0;
$calendarId = isset($_GET['calendar_id']) ? (int) $_GET['calendar_id'] : 0;
$userGroupInfo = $usergroup->get($id);
if (empty($userGroupInfo)) {
api_not_allowed(true);
}
// setting breadcrumbs
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
$interbreadcrumb[] = ['url' => '#', 'name' => $userGroupInfo['name']];
switch ($action) {
case 'add_calendar':
$calendars = LpCalendarPlugin::getCalendars(0, 1000, '');
$calendars = $calendarPlugin->getCalendars(0, 1000, '');
if (empty($calendars)) {
echo Display::return_message(get_lang('NoData'), 'warning');
exit;
}
$userInfo = api_get_user_info($userId);
$calendars = array_column($calendars, 'title', 'id');
$calendars = array_map('strip_tags', $calendars);
@ -55,7 +59,7 @@ switch ($action) {
if ($form->validate()) {
$calendarId = $form->getSubmitValue('calendar_id');
if (!empty($calendarId)) {
LpCalendarPlugin::addUserToCalendar($calendarId, $userId);
$calendarPlugin->addUserToCalendar($calendarId, $userId);
Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation'));
header('Location: '.api_get_self().'?id='.$id);
exit;
@ -64,7 +68,7 @@ switch ($action) {
exit;
break;
case 'edit_calendar':
$calendars = LpCalendarPlugin::getCalendars(0, 1000, '');
$calendars = $calendarPlugin->getCalendars(0, 1000, '');
if (empty($calendars)) {
echo Display::return_message(get_lang('Nodata'));
exit;
@ -88,7 +92,7 @@ switch ($action) {
if ($form->validate()) {
$calendarId = $form->getSubmitValue('calendar_id');
if (!empty($calendarId)) {
LpCalendarPlugin::updateUserToCalendar($calendarId, $userId);
$calendarPlugin->updateUserToCalendar($calendarId, $userId);
Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation'));
header('Location: '.api_get_self().'?id='.$id);
exit;
@ -98,16 +102,12 @@ switch ($action) {
break;
case 'delete':
$res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']);
//LpCalendarPlugin::deleteAllCalendarFromUser();
Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation'));
header('Location: '.api_get_self().'?id='.$id);
exit;
break;
}
// The header.
Display::display_header();
// jqgrid will use this URL to do the selects
@ -133,7 +133,6 @@ $column_model = [
];
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') {
$calendarPlugin = LpCalendarPlugin::create();
$columns = [
get_lang('Name'),
get_lang('Calendar'),
@ -221,9 +220,7 @@ function extra_formatter(cellvalue, options, rowObject) {
return \''.
'&nbsp;<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_SMALL).'</a>'.
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?id='.$id.'&action=delete&user_id=\'+options.rowId+\'">'.$deleteIcon.'</a>\';
}
';
}';
$deleteUrl = api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=delete_user_in_usergroup&group_id='.$id;
@ -253,7 +250,6 @@ $(function() {
{ width:500 } // search options
);
});
</script>
<?php

@ -5,6 +5,7 @@
* @package chamilo.admin
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
@ -16,32 +17,10 @@ $usergroup->protectScript();
$htmlHeadXtra[] = api_get_jqgrid_js();
// setting breadcrumbs
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
if ($action == 'add') {
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
} elseif ($action == 'edit') {
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
} else {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Classes')];
}
// The header.
Display::display_header();
// Tool name
if ($action == 'add') {
$tool = 'Add';
$interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('Group')];
}
if ($action == 'edit') {
$tool = 'Modify';
$interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('Group')];
}
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
$userGroupId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
// jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups';
//The order is important you need to check the the $column variable in the model.ajax.php file
@ -71,13 +50,13 @@ $column_model = [
],
];
//Autowidth
// Autowidth
$extra_params['autowidth'] = 'true';
//height auto
// Height auto
$extra_params['height'] = 'auto';
$extra_params['sortname'] = 'name';
$extra_params['sortorder'] = 'desc';
//With this function we can add actions to the jgrid
// With this function we can add actions to the jgrid
$action_links = 'function action_formatter (cellvalue, options, rowObject) {
return \''
.' <a href="add_users_to_usergroup.php?id=\'+options.rowId+\'">'.Display::return_icon('user_to_class.png', get_lang('SubscribeUsersToClass'), null, ICON_SIZE_MEDIUM).'</a>'
@ -87,117 +66,141 @@ $action_links = 'function action_formatter (cellvalue, options, rowObject) {
.' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), null, ICON_SIZE_SMALL).'</a>\';
}';
?>
<script>
$(function() {
<?php
// grid definition see the $usergroup>display() function
echo Display::grid_js(
'usergroups',
$url,
$columns,
$column_model,
$extra_params,
[],
$action_links,
true
);
?>
});
</script>
<?php
$usergroup->showGroupTypeSetting = true;
$content = '';
// Action handling: Adding a note
if ($action == 'add') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
}
$form = new FormValidator(
'usergroup',
'post',
api_get_self().'?action='.$action
);
$usergroup->setForm($form, 'add');
// Setting the defaults
$form->setDefaults(['visibility' => 2]);
// The validation or display
if ($form->validate()) {
$values = $form->exportValues();
$res = $usergroup->save($values);
if ($res) {
echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
switch ($action) {
case 'add':
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
}
$form = new FormValidator(
'usergroup',
'post',
api_get_self().'?action='.$action
);
$usergroup->setForm($form, 'add');
// Setting the defaults
$form->setDefaults(['visibility' => 2]);
// The validation or display
if ($form->validate()) {
$values = $form->exportValues();
$res = $usergroup->save($values);
if ($res) {
Display::addFlash(Display::return_message(get_lang('ItemAdded'), 'confirmation'));
} else {
Display::addFlash(Display::return_message(
Security::remove_XSS($values['name']).': '.
get_lang('AlreadyExists'),
'warning'
));
}
header('Location: '.api_get_self());
exit;
} else {
echo Display::return_message(
Security::remove_XSS($values['name']).': '.
get_lang('AlreadyExists'),
'warning'
);
$content .= '<div class="actions">';
$content .= '<a href="'.api_get_self().'">'.
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
$content .= '</div>';
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
$content .= $form->returnForm();
}
$usergroup->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>';
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(['sec_token' => $token]);
$form->display();
}
} elseif ($action == 'edit' && is_numeric($_GET['id'])) {
$id = intval($_GET['id']);
$form = new FormValidator(
'usergroup',
'post',
api_get_self().'?action='.$action.'&id='.$id
);
$defaults = $usergroup->get($id);
$usergroup->setForm($form, 'edit', $defaults);
// Setting the form elements
$form->addElement('hidden', 'id', $id);
// Setting the defaults
$form->setDefaults($defaults);
// The validation or display.
if ($form->validate()) {
$values = $form->getSubmitValues();
$res = $usergroup->update($values);
if ($res) {
echo Display::return_message(get_lang('Updated'), 'confirmation');
break;
case 'edit':
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
$defaults = $usergroup->get($userGroupId);
$usergroup->protectScript($defaults);
$form = new FormValidator(
'usergroup',
'post',
api_get_self().'?action='.$action.'&id='.$userGroupId
);
$usergroup->setForm($form, 'edit', $defaults);
// Setting the form elements
$form->addElement('hidden', 'id', $userGroupId);
// Setting the defaults
$form->setDefaults($defaults);
// The validation or display.
if ($form->validate()) {
$values = $form->getSubmitValues();
$res = $usergroup->update($values);
if ($res) {
Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation'));
} else {
Display::addFlash(Display::return_message(
Security::remove_XSS($values['name']).': '.
get_lang('AlreadyExists'),
'warning'
));
}
header('Location: '.api_get_self());
exit;
} else {
echo Display::return_message(
Security::remove_XSS($values['name']).': '.
get_lang('AlreadyExists'),
'warning'
);
$content .= '<div class="actions">';
$content .= '<a href="'.api_get_self().'">'.Display::return_icon(
'back.png',
get_lang('Back'),
'',
ICON_SIZE_MEDIUM
).'</a>';
$content .= '</div>';
$content .= $form->returnForm();
}
$usergroup->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->display();
}
} elseif ($action == 'delete' && is_numeric($_GET['id'])) {
$res = $usergroup->delete($_GET['id']);
if ($res) {
echo Display::return_message(get_lang('Deleted'), 'confirmation');
}
$usergroup->display();
} else {
$usergroup->display();
break;
case 'delete':
$defaults = $usergroup->get($userGroupId);
$usergroup->protectScript($defaults);
$res = $usergroup->delete($userGroupId);
if ($res) {
Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation'));
}
header('Location: '.api_get_self());
exit;
break;
default:
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Classes')];
$content = $usergroup->returnGrid();
break;
}
// The header.
Display::display_header();
?>
<script>
$(function() {
<?php
// grid definition see the $usergroup>display() function
echo Display::grid_js(
'usergroups',
$url,
$columns,
$column_model,
$extra_params,
[],
$action_links,
true
);
?>
});
</script>
<?php
echo $content;
Display::display_footer();

@ -94,6 +94,15 @@ if (!empty($dates)) {
$content .= '</div></div>';
}
if (api_get_configuration_value('private_messages_about_user_visible_to_user') === true) {
$allowMessages = api_get_configuration_value('private_messages_about_user');
if ($allowMessages === true) {
// Messages
$content .= Display::page_subheader2(get_lang('Messages'));
$content .= MessageManager::getMessagesAboutUserToString(api_get_user_info());
}
}
$message = null;
if (empty($content)) {
$message = Display::return_message(get_lang('NoDataAvailable'), 'warning');

@ -28,7 +28,7 @@ define('MODULE_HELP_NAME', 'Settings');
define('COURSE_CHANGE_PROPERTIES', 'COURSE_CHANGE_PROPERTIES');
$currentCourseRepository = $_course['path'];
$is_allowedToEdit = $is_courseAdmin || $is_platformAdmin;
$is_allowedToEdit = api_is_course_admin() || api_is_platform_admin();
$course_code = api_get_course_id();
$courseId = api_get_course_int_id();
@ -127,19 +127,25 @@ $form->applyFilter('department_url', 'html_filter');
// Extra fields
$extra_field = new ExtraField('course');
$extraFieldAdminPermissions = false;
$showOnlyTheseFields = [];
if (api_get_configuration_value('allow_teachers_to_classes') === true) {
$extraFieldAdminPermissions = true;
$showOnlyTheseFields[] = 'course_hours_duration';
}
$extra = $extra_field->addElements(
$form,
$courseId,
[],
false,
false,
[],
$showOnlyTheseFields,
[],
true
);
//Tags ExtraField
$htmlHeadXtra[] = '
<script>
$(function() {

@ -53,6 +53,7 @@ if (!in_array(
'get_work_user_list_all',
'get_timelines',
'get_user_skill_ranking',
'get_usergroups',
'get_usergroups_teacher',
'get_user_course_report_resumed',
'get_user_course_report',
@ -62,6 +63,7 @@ if (!in_array(
'course_log_events',
'get_learning_path_calendars',
'get_usergroups_users',
'get_calendar_users',
]
) && !isset($_REQUEST['from_course_session'])) {
api_protect_admin_script(true);
@ -230,13 +232,20 @@ if (!$sidx) {
//@todo rework this
switch ($action) {
case 'get_calendar_users':
$calendarPlugin = LpCalendarPlugin::create();
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$count = $calendarPlugin->getUsersPerCalendarCount($id);
break;
case 'get_usergroups_users':
$usergroup = new UserGroup();
$usergroup->protectScript();
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$count = $usergroup->getUserGroupUsers($id, true);
break;
case 'get_learning_path_calendars':
$count = LpCalendarPlugin::getCalendarCount();
$calendarPlugin = LpCalendarPlugin::create();
$count = $calendarPlugin->getCalendarCount();
break;
case 'course_log_events':
$courseId = api_get_course_int_id();
@ -244,7 +253,6 @@ switch ($action) {
exit;
}
$sessionId = api_get_session_id();
if (!api_is_allowed_to_edit()) {
exit;
}
@ -272,7 +280,6 @@ switch ($action) {
if ($userNotAllowed) {
exit;
}
$userId = api_get_user_id();
$sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
$courseCodeList = [];
@ -742,10 +749,12 @@ switch ($action) {
break;
case 'get_usergroups':
$obj = new UserGroup();
$obj->protectScript();
$count = $obj->get_count();
break;
case 'get_usergroups_teacher':
$obj = new UserGroup();
$obj->protectScript();
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
$groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0;
$course_id = api_get_course_int_id();
@ -789,8 +798,11 @@ $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit
$columns = [];
switch ($action) {
case 'get_calendar_users':
$columns = ['firstname', 'lastname', 'exam'];
$result = $calendarPlugin->getUsersPerCalendar($id);
break;
case 'get_usergroups_users':
$usergroup->protectScript();
$columns = ['name', 'actions'];
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') {
$columns = [
@ -808,7 +820,7 @@ switch ($action) {
break;
case 'get_learning_path_calendars':
$columns = ['title', 'total_hours', 'minutes_per_day', 'actions'];
$result = LpCalendarPlugin::getCalendars(
$result = $calendarPlugin->getCalendars(
$start,
$limit,
$sidx,
@ -817,7 +829,6 @@ switch ($action) {
break;
case 'course_log_events':
$columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
$result = Statistics::getActivitiesData(
$start,
$limit,
@ -2106,23 +2117,29 @@ switch ($action) {
switch ($type) {
case 'not_registered':
$options['where'] = [" (course_id IS NULL OR course_id != ?) " => $course_id];
$options['where'] = [' (course_id IS NULL OR course_id != ?) ' => $course_id];
$result = $obj->getUserGroupNotInCourse($options, $groupFilter);
break;
case 'registered':
$options['where'] = [" usergroup.course_id = ? " => $course_id];
$options['where'] = [' usergroup.course_id = ? ' => $course_id];
$result = $obj->getUserGroupInCourse($options, $groupFilter);
break;
}
$new_result = [];
if (!empty($result)) {
$url = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq();
$urlUserGroup = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq();
foreach ($result as $group) {
$group['users'] = Display::url(
count($obj->get_users_by_usergroup($group['id'])),
$url.'&id='.$group['id']
);
$count = count($obj->get_users_by_usergroup($group['id']));
$group['users'] = $count;
if ($obj->allowTeachers()) {
$group['users'] = Display::url(
$count,
$urlUserGroup.'&id='.$group['id']
);
}
if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
$url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq();
$icon = Display::return_icon('delete.png', get_lang('Remove'));
@ -2142,7 +2159,16 @@ switch ($action) {
$role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
$group['status'] = $role;
$group['actions'] = Display::url($icon, $url);
$group['actions'] = '';
if ($obj->allowTeachers()) {
$group['actions'] .= Display::url(
Display::return_icon('stats.png'),
$urlUserGroup.'&id='.$group['id']
).'&nbsp;';
}
$group['actions'] .= Display::url($icon, $url);
$new_result[] = $group;
}
$result = $new_result;
@ -2196,6 +2222,7 @@ $allowed_actions = [
'course_log_events',
'get_learning_path_calendars',
'get_usergroups_users',
'get_calendar_users',
];
//5. Creating an obj to return a json

@ -20,7 +20,7 @@ switch ($action) {
'firstname' => $query,
'lastname' => $query,
];
$users = UserManager::get_user_list_like($conditions, [], false, 'OR');
$users = UserManager::getUserListLike($conditions, [], false, 'OR');
$result = [];
if (!empty($users)) {
foreach ($users as $user) {

@ -152,6 +152,7 @@ class CourseManager
* @param string $urlId The Access URL ID, if using multiple URLs
* @param bool $alsoSearchCode An extension option to indicate that we also want to search for course codes (not *only* titles)
* @param array $conditionsLike
* @param array $onlyThisCourseList
*
* @return array
*/
@ -164,7 +165,8 @@ class CourseManager
$startwith = '',
$urlId = null,
$alsoSearchCode = false,
$conditionsLike = []
$conditionsLike = [],
$onlyThisCourseList = []
) {
$sql = "SELECT course.* FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." course ";
@ -173,27 +175,35 @@ class CourseManager
$sql .= " INNER JOIN $table url ON (url.c_id = course.id) ";
}
$visibility = (int) $visibility;
if (!empty($startwith)) {
$sql .= "WHERE (title LIKE '".Database::escape_string($startwith)."%' ";
if ($alsoSearchCode) {
$sql .= "OR code LIKE '".Database::escape_string($startwith)."%' ";
}
$sql .= ') ';
if ($visibility !== -1 && $visibility == strval(intval($visibility))) {
if ($visibility !== -1) {
$sql .= " AND visibility = $visibility ";
}
} else {
$sql .= "WHERE 1 ";
if ($visibility !== -1 && $visibility == strval(intval($visibility))) {
if ($visibility !== -1) {
$sql .= " AND visibility = $visibility ";
}
}
if (!empty($urlId)) {
$urlId = intval($urlId);
$urlId = (int) $urlId;
$sql .= " AND access_url_id = $urlId";
}
if (!empty($onlyThisCourseList)) {
$onlyThisCourseList = array_map('intval', $onlyThisCourseList);
$onlyThisCourseList = implode("','", $onlyThisCourseList);
$sql .= " AND course.id IN ('$onlyThisCourseList') ";
}
$allowedFields = [
'title',
'code',

@ -266,6 +266,50 @@ class MessageManager
return [];
}
/**
* @param array $userInfo
*
* @return string
*/
public static function getMessagesAboutUserToString($userInfo)
{
$messages = self::getMessagesAboutUser($userInfo);
$html = '';
if (!empty($messages)) {
/** @var Message $message */
foreach ($messages as $message) {
$tag = 'message_'.$message->getId();
$tagAccordion = 'accordion_'.$message->getId();
$tagCollapse = 'collapse_'.$message->getId();
$date = Display::dateToStringAgoAndLongDate(
$message->getSendDate()
);
$localTime = api_get_local_time(
$message->getSendDate(),
null,
null,
false,
false
);
$senderId = $message->getUserSenderId();
$senderInfo = api_get_user_info($senderId);
$html .= Display::panelCollapse(
$localTime.' '.$senderInfo['complete_name'].' '.$message->getTitle(),
$message->getContent().'<br />'.$date.'<br />'.get_lang(
'Author'
).': '.$senderInfo['complete_name_with_message_link'],
$tag,
null,
$tagAccordion,
$tagCollapse,
false
);
}
}
return $html;
}
/**
* @param int $senderId
* @param int $receiverId

@ -6,6 +6,7 @@ use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\Repository\SequenceRepository;
use Chamilo\CoreBundle\Entity\SequenceResource;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionRelCourse;
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
use Chamilo\CoreBundle\Entity\SessionRelUser;
use Chamilo\UserBundle\Entity\User;
@ -3153,13 +3154,20 @@ class SessionManager
* array('s.name' => array('operator' => 'LIKE', value = '%$needle%'))
* @param array $order_by a list of fields on which sort
* @param int $urlId
* @param array $onlyThisSessionList
*
* @return array an array with all sessions of the platform
*
* @todo optional course code parameter, optional sorting parameters...
*/
public static function get_sessions_list($conditions = [], $order_by = [], $from = null, $to = null, $urlId = 0)
{
public static function get_sessions_list(
$conditions = [],
$order_by = [],
$from = null,
$to = null,
$urlId = 0,
$onlyThisSessionList = []
) {
$session_table = Database::get_main_table(TABLE_MAIN_SESSION);
$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
@ -3211,6 +3219,13 @@ class SessionManager
}
}
if (!empty($onlyThisSessionList)) {
$onlyThisSessionList = array_map('intval', $onlyThisSessionList);
$onlyThisSessionList = implode("','", $onlyThisSessionList);
$sql_query .=" AND s.id IN ('$onlyThisSessionList') ";
}
$orderAvailableList = ['name'];
if (count($order_by) > 0) {
$order = null;
@ -3228,8 +3243,8 @@ class SessionManager
}
if (!is_null($from) && !is_null($to)) {
$to = intval($to);
$from = intval($from);
$to = (int) $to;
$from = (int) $from;
$sql_query .= "LIMIT $from, $to";
}
@ -7658,7 +7673,6 @@ SQL;
}
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$sessionList[] = $row;
}
@ -7734,7 +7748,7 @@ SQL;
$coachInfo = [];
if (!empty($sessionInfo)) {
$sessionId = intval($sessionInfo['id']);
$sessionId = (int) $sessionInfo['id'];
$coachInfo = api_get_user_info($sessionInfo['id_coach']);
}
@ -7776,11 +7790,11 @@ SQL;
} else {
$sql = "SELECT COUNT(1) FROM $tbl_user WHERE status = 1";
$rs = Database::query($sql);
$countUsers = Database::result($rs, 0, 0);
$countUsers = (int) Database::result($rs, 0, 0);
if (intval($countUsers) < 50) {
$orderClause = "ORDER BY ";
$orderClause .= api_sort_by_first_name() ? "firstname, lastname, username" : "lastname, firstname, username";
if ($countUsers < 50) {
$orderClause = 'ORDER BY ';
$orderClause .= api_sort_by_first_name() ? 'firstname, lastname, username' : 'lastname, firstname, username';
$sql = "SELECT user_id, lastname, firstname, username
FROM $tbl_user
@ -7792,7 +7806,6 @@ SQL;
TABLE_MAIN_ACCESS_URL_REL_USER
);
$accessUrlId = api_get_current_access_url_id();
if ($accessUrlId != -1) {
$sql = "SELECT user.user_id, username, lastname, firstname
FROM $tbl_user user
@ -7807,7 +7820,6 @@ SQL;
$result = Database::query($sql);
$coachesList = Database::store_result($result);
$coachesOptions = [];
foreach ($coachesList as $coachItem) {
$coachesOptions[$coachItem['user_id']] =
@ -7883,11 +7895,16 @@ SQL;
$form->addElement('checkbox', 'show_description', null, get_lang('ShowDescription'));
$visibilityGroup = [];
$visibilityGroup[] = $form->createElement('select', 'session_visibility', null, [
SESSION_VISIBLE_READ_ONLY => get_lang('SessionReadOnly'),
SESSION_VISIBLE => get_lang('SessionAccessible'),
SESSION_INVISIBLE => api_ucfirst(get_lang('SessionNotAccessible')),
]);
$visibilityGroup[] = $form->createElement(
'select',
'session_visibility',
null,
[
SESSION_VISIBLE_READ_ONLY => get_lang('SessionReadOnly'),
SESSION_VISIBLE => get_lang('SessionAccessible'),
SESSION_INVISIBLE => api_ucfirst(get_lang('SessionNotAccessible')),
]
);
$form->addGroup(
$visibilityGroup,
'visibility_group',
@ -7907,7 +7924,6 @@ SQL;
]);
$form->addHtml('<div id="duration_div" style="display:none">');
$form->addElement(
'number',
'duration',
@ -8067,7 +8083,11 @@ SQL;
$options['where'] = str_replace('AND', 'OR', $options['where']);
foreach ($options['extra'] as $extra) {
$options['where'] = str_replace($extra['field'], 'fv.field_id = '.$extra['id'].' AND fvo.option_value', $options['where']);
$options['where'] = str_replace(
$extra['field'],
'fv.field_id = '.$extra['id'].' AND fvo.option_value',
$options['where']
);
$extraFieldTables = "$tbl_session_field_values fv, $tbl_session_field_options fvo, ";
}
}
@ -8099,7 +8119,6 @@ SQL;
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$where .= " AND ar.access_url_id = $access_url_id ";
$query_rows = "SELECT count(*) as total_rows
FROM $tbl_session s
LEFT JOIN $tbl_session_category sc
@ -8261,7 +8280,6 @@ SQL;
// Inject extra session fields
$session_field = new ExtraFieldModel('session');
$rules = $session_field->getRules($columns, $column_model);
$column_model[] = [
'name' => 'actions',
'index' => 'actions',
@ -8641,7 +8659,7 @@ SQL;
*/
public static function getAdminPath($id)
{
$id = intval($id);
$id = (int) $id;
$session = self::fetch($id);
if (empty($session)) {
return false;
@ -8661,7 +8679,7 @@ SQL;
*/
public static function getPath($id, $courseId = 0)
{
$id = intval($id);
$id = (int) $id;
$session = self::fetch($id);
if (empty($session)) {
return false;
@ -8719,12 +8737,13 @@ SQL;
* Return an associative array 'id_course' => [id_session1, id_session2...]
* where course id_course is in sessions id_session1, id_session2.
*
* @param $userId
* @param int $userId
*
* @return array
*/
public static function getCoursesForCourseSessionCoach($userId)
{
$userId = (int) $userId;
$listResCourseSession = [];
$tblCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$tblSessionRelCourseRelUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
@ -8734,7 +8753,7 @@ SQL;
LEFT JOIN $tblCourse c
ON c.id = srcru.c_id
WHERE
srcru.user_id =".intval($userId)." AND
srcru.user_id = $userId AND
srcru.status = 2";
$res = Database::query($sql);
@ -8761,12 +8780,13 @@ SQL;
*/
public static function getCoursesForMainSessionCoach($userId)
{
$userId = (int) $userId;
$listResCourseSession = [];
$tblSession = Database::get_main_table(TABLE_MAIN_SESSION);
// list of SESSION where user is session coach
$sql = "SELECT id FROM $tblSession
WHERE id_coach = ".intval($userId);
WHERE id_coach = ".$userId;
$res = Database::query($sql);
while ($data = Database::fetch_assoc($res)) {
@ -8870,8 +8890,8 @@ SQL;
}
$listSessionInfo = self::fetch($sessionId);
$listSessionIdName = [
"sessionId" => $sessionId,
"sessionName" => $listSessionInfo['name'],
'sessionId' => $sessionId,
'sessionName' => $listSessionInfo['name'],
];
$listCat[$catId]['sessionList'][] = $listSessionIdName;
}
@ -9025,7 +9045,8 @@ SQL;
if ($response) {
$urlToRedirect = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$sessionId;
if (!empty($onlyOneCourseSessionToRedirect)) {
$urlToRedirect = api_get_path(WEB_PATH).'courses/'.$onlyOneCourseSessionToRedirect.'/index.php?id_session='.$sessionId;
$urlToRedirect = api_get_path(WEB_PATH).
'courses/'.$onlyOneCourseSessionToRedirect.'/index.php?id_session='.$sessionId;
}
header('Location: '.$urlToRedirect);

@ -43,6 +43,9 @@ class UserGroup extends Model
$this->table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$this->table_user = Database::get_main_table(TABLE_MAIN_USER);
$this->useMultipleUrl = api_get_configuration_value('multiple_access_urls');
if ($this->allowTeachers()) {
$this->columns[] = 'author_id';
}
}
/**
@ -103,21 +106,28 @@ class UserGroup extends Model
} else {
$list = [];
$showCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
$calendarPlugin = null;
if ($showCalendar) {
$calendarPlugin = LpCalendarPlugin::create();
}
$url = api_get_path(WEB_PLUGIN_PATH).'lp_calendar/calendar_users.php?';
while ($data = Database::fetch_array($result)) {
$userId = $data['user_id'];
$userInfo = api_get_user_info($userId);
$data['name'] = $userInfo['complete_name_with_username'];
if ($showCalendar) {
$calendar = LpCalendarPlugin::getUserCalendar($userId);
$calendar = $calendarPlugin->getUserCalendar($userId);
$data['calendar_id'] = 0;
$data['calendar'] = '';
if (!empty($calendar)) {
$calendarInfo = LpCalendarPlugin::getCalendar($calendar['calendar_id']);
$calendarInfo = $calendarPlugin->getCalendar($calendar['calendar_id']);
if ($calendarInfo) {
$data['calendar_id'] = $calendar['calendar_id'];
$data['calendar'] = $calendarInfo['title'];
$data['calendar'] = Display::url(
$calendarInfo['title'],
$url.'&id='.$calendar['calendar_id']
);
}
}
@ -130,7 +140,7 @@ class UserGroup extends Model
true
);
$stats = LpCalendarPlugin::getUserStats($userId, $courseAndSessionList);
$stats = $calendarPlugin->getUserStats($userId, $courseAndSessionList);
$data['gradebook_items'] = '@todo';
$totalTime = 0;
@ -159,13 +169,22 @@ class UserGroup extends Model
*/
public function get_count($type = -1)
{
$authorCondition = '';
if ($this->allowTeachers()) {
if (!api_is_platform_admin()) {
$userId = api_get_user_id();
$authorCondition = " AND author_id = $userId";
}
}
if ($this->useMultipleUrl) {
$urlId = api_get_current_access_url_id();
$sql = "SELECT count(u.id) as count FROM ".$this->table." u
INNER JOIN ".$this->access_url_rel_usergroup." a
ON (u.id = a.usergroup_id)
WHERE access_url_id = $urlId
ON (u.id = a.usergroup_id)
WHERE access_url_id = $urlId $authorCondition
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);
@ -178,12 +197,14 @@ class UserGroup extends Model
$typeCondition = '';
if ($type != -1) {
$type = (int) $type;
$typeCondition = " WHERE group_type = $type ";
$typeCondition = " AND group_type = $type ";
}
$sql = "SELECT count(a.id) as count
FROM {$this->table} a
WHERE 1 =1
$typeCondition
$authorCondition
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
@ -264,26 +285,36 @@ class UserGroup extends Model
/**
* Displays the title + grid.
*/
public function display()
public function returnGrid()
{
// action links
echo '<div class="actions">';
echo '<a href="../admin/index.php">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', '32').
'</a>';
echo '<a href="'.api_get_self().'?action=add">'.
Display::return_icon('new_class.png', get_lang('AddClasses'), '', '32').
$html = '<div class="actions">';
if (api_is_platform_admin()) {
$html .= '<a href="../admin/index.php">'.
Display::return_icon(
'back.png',
get_lang('BackTo').' '.get_lang('PlatformAdmin'),
'',
ICON_SIZE_MEDIUM
).
'</a>';
}
$html .= '<a href="'.api_get_self().'?action=add">'.
Display::return_icon('new_class.png', get_lang('AddClasses'), '', ICON_SIZE_MEDIUM).
'</a>';
echo Display::url(
$html .= Display::url(
Display::return_icon('import_csv.png', get_lang('Import'), [], ICON_SIZE_MEDIUM),
'usergroup_import.php'
);
echo Display::url(
$html .= Display::url(
Display::return_icon('export_csv.png', get_lang('Export'), [], ICON_SIZE_MEDIUM),
'usergroup_export.php'
);
echo '</div>';
echo Display::grid_html('usergroups');
$html .= '</div>';
$html .= Display::grid_html('usergroups');
return $html;
}
/**
@ -620,6 +651,7 @@ class UserGroup extends Model
$this->usergroup_rel_user_table,
$conditions
);
$array = [];
if (!empty($results)) {
foreach ($results as $row) {
@ -726,7 +758,7 @@ class UserGroup extends Model
INNER JOIN {$this->access_url_rel_usergroup} a ON (a.usergroup_id = u.usergroup_id)";
$where = ['where' => ['user_id = ? AND access_url_id = ? ' => [$userId, $urlId]]];
} else {
$from = $this->usergroup_rel_user_table." u ";
$from = $this->usergroup_rel_user_table.' u ';
$where = ['where' => ['user_id = ?' => $userId]];
}
@ -1029,11 +1061,21 @@ class UserGroup extends Model
} else {
$sql = "SELECT * FROM $this->table WHERE name = '".$name."'";
}
$res = Database::query($sql);
return Database::num_rows($res) != 0;
}
/**
* @return bool
*/
public function allowTeachers()
{
return api_get_configuration_value('allow_teachers_to_classes') === true;
}
/**
* @param int $sidx
* @param int $sord
@ -1053,10 +1095,17 @@ class UserGroup extends Model
$from = $this->table." u INNER JOIN {$this->access_url_rel_usergroup} a ON (u.id = a.usergroup_id)";
$where = [' access_url_id = ?' => $urlId];
} else {
$from = $this->table." u ";
$from = $this->table.' u ';
$where = [];
}
if ($this->allowTeachers()) {
if (!api_is_platform_admin()) {
$userId = api_get_user_id();
$where = [' author_id = ?' => $userId];
}
}
$result = Database::select(
'u.*',
$from,
@ -1120,15 +1169,21 @@ class UserGroup extends Model
$from = $this->table." u INNER JOIN {$this->access_url_rel_usergroup} a
ON (u.id = a.usergroup_id)";
$options = ['where' => ['access_url_id = ? ' => $urlId]];
if ($this->allowTeachers()) {
$options['where'] = [ ' author_id = ? ' => api_get_user_id()];
}
$classes = Database::select('a.id, name, description', $from, $options);
} else {
if ($this->allowTeachers()) {
$options['where'] = [ ' author_id = ? ' => api_get_user_id()];
}
$classes = Database::select('id, name, description', $this->table, $options);
}
$result = [];
if (!empty($classes)) {
foreach ($classes as $data) {
$users = self::getUserListByUserGroup($data['id']);
$users = $this->getUserListByUserGroup($data['id']);
$userToString = null;
if (!empty($users)) {
$userNameList = [];
@ -1200,6 +1255,9 @@ class UserGroup extends Model
$groupExists = $this->usergroup_exists(trim($params['name']));
if ($groupExists == false) {
if ($this->allowTeachers()) {
$params['author_id'] = api_get_user_id();
}
$id = parent::save($params, $show_query);
if ($id) {
if ($this->useMultipleUrl) {
@ -2726,10 +2784,24 @@ class UserGroup extends Model
/**
* Check permissions and blocks the page.
*
* @param array $userGroupInfo
*/
public function protectScript()
public function protectScript($userGroupInfo = [])
{
api_protect_admin_script(true);
api_protect_limit_for_session_admin();
api_block_anonymous_users();
if (!api_is_platform_admin()) {
if ($this->allowTeachers() && api_is_teacher()) {
if (!empty($userGroupInfo)) {
if ($userGroupInfo['author_id'] != api_get_user_id()) {
api_not_allowed(true);
}
}
} else {
api_protect_admin_script(true);
api_protect_limit_for_session_admin();
}
}
}
}

@ -1655,17 +1655,19 @@ class UserManager
* @param array $order_by a list of fields on which sort
* @param bool $simple_like Whether we want a simple LIKE 'abc' or a LIKE '%abc%'
* @param string $condition Whether we want the filters to be combined by AND or OR
* @param array $onlyThisUserList
*
* @return array an array with all users of the platform
*
* @todo optional course code parameter, optional sorting parameters...
* @todo security filter order_by
*/
public static function get_user_list_like(
public static function getUserListLike(
$conditions = [],
$order_by = [],
$simple_like = false,
$condition = 'AND'
$condition = 'AND',
$onlyThisUserList = []
) {
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$tblAccessUrlRelUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@ -1676,8 +1678,8 @@ class UserManager
$sql_query .= " INNER JOIN $tblAccessUrlRelUser auru ON auru.user_id = user.id ";
}
$sql_query .= ' WHERE 1 = 1 ';
if (count($conditions) > 0) {
$sql_query .= ' WHERE ';
$temp_conditions = [];
foreach ($conditions as $field => $value) {
$field = Database::escape_string($field);
@ -1697,9 +1699,15 @@ class UserManager
}
} else {
if (api_is_multiple_url_enabled()) {
$sql_query .= ' WHERE auru.access_url_id = '.api_get_current_access_url_id();
$sql_query .= ' AND auru.access_url_id = '.api_get_current_access_url_id();
}
}
if (!empty($onlyThisUserList)) {
$onlyThisUserListToString = implode("','", $onlyThisUserList);
$sql_query .= " AND user.id IN ('$onlyThisUserListToString') ";
}
if (count($order_by) > 0) {
$sql_query .= ' ORDER BY '.Database::escape_string(implode(',', $order_by));
}

@ -706,7 +706,7 @@ class IndexManager
*
* @return string
*/
public function show_right_block(
public function showRightBlock(
$title,
$content,
$id = '',
@ -766,7 +766,7 @@ class IndexManager
<button class="btn btn-default" type="submit" name="submit" value="'.$search_btn.'" />'.
$search_btn.' </button>
</div></form>';
$html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
$html .= $this->showRightBlock(get_lang('Search'), $search_content, 'search_block');
}
return $html;
@ -775,7 +775,7 @@ class IndexManager
/**
* @return string
*/
public function return_classes_block()
public function returnClassesBlock()
{
if (api_get_setting('show_groups_to_users') !== 'true') {
return '';
@ -793,14 +793,22 @@ class IndexManager
];
}
}
if (api_is_platform_admin()) {
$items[] = [
'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add',
'title' => get_lang('AddClasses'),
];
} else {
if (api_is_teacher() && $usergroup->allowTeachers()) {
$items[] = [
'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add',
'title' => get_lang('AddClasses'),
];
}
}
$html = self::show_right_block(
$html = $this->showRightBlock(
get_lang('Classes'),
self::returnRightBlockItems($items),
'classes_block'
@ -827,7 +835,7 @@ class IndexManager
<img class="img-circle" title="'.get_lang('EditProfile').'" src="'.$userPicture.'"></a>';
}
$html = self::show_right_block(
$html = $this->showRightBlock(
null,
$content,
'user_image_block',
@ -852,7 +860,7 @@ class IndexManager
$items = [];
$userGroup = new UserGroup();
// @todo Add a platform setting to add the user image.
if (api_get_setting('allow_message_tool') == 'true') {
if (api_get_setting('allow_message_tool') === 'true') {
// New messages.
$number_of_new_messages = MessageManager::getCountNewMessages();
// New contact invitations.

@ -539,6 +539,8 @@ $_configuration['send_all_emails_to'] = [
//$_configuration['hide_search_form_in_session_list'] = false;
// Allow exchange of messages from teachers/bosses about a user.
//$_configuration['private_messages_about_user'] = false;
// Allow the messages to be visible for the students
//$_configuration['private_messages_about_user_visible_to_user'] = false;
// Allow send email notification per exercise
//ALTER TABLE c_quiz ADD COLUMN notifications VARCHAR(255) NULL DEFAULT NULL;
//$_configuration['allow_notification_setting_per_exercise'] = false;
@ -905,6 +907,10 @@ VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1,
// In this example the index.php will be redirected to user_portal.php for logged in users
//$_configuration['redirect_index_to_url_for_logged_users'] = 'user_portal.php';
// Teachers can CRUD classes
// ALTER TABLE usergroup ADD author_id INT DEFAULT NULL;
//$_configuration['allow_teachers_to_classes'] = false;
// ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email

@ -6429,10 +6429,10 @@ class learnpath
$pluginLink = $pluginUrl.
'&action=toggle_visibility&lp_item_id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id;
$iconCalendar = Display::return_icon('agenda_na.png', get_lang('Edit'), [], ICON_SIZE_TINY);
$iconCalendar = Display::return_icon('agenda_na.png', get_lang('OneDay'), [], ICON_SIZE_TINY);
$itemInfo = $plugin->getItemVisibility($arrLP[$i]['id']);
if ($itemInfo && $itemInfo['value'] == 1) {
$iconCalendar = Display::return_icon('agenda.png', get_lang('Edit'), [], ICON_SIZE_TINY);
$iconCalendar = Display::return_icon('agenda.png', get_lang('OneDay'), [], ICON_SIZE_TINY);
}
$pluginCalendarIcon = Display::url(
$iconCalendar,

@ -26,7 +26,7 @@ $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
$display = isset($_GET['display']) ? Security::remove_XSS($_GET['display']) : null;
$csv_content = [];
$user_id = api_get_user_id();
$session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
$session_id = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
$is_coach = api_is_coach($session_id);
$is_platform_admin = api_is_platform_admin();
$is_drh = api_is_drh();
@ -56,6 +56,9 @@ if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
}
$menu_items = [];
$pluginCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
$calendarMenuAdded = false;
if ($is_platform_admin) {
if ($view == 'admin') {
$title = get_lang('CoachList');
@ -99,13 +102,13 @@ if ($is_platform_admin) {
api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php'
);
$pluginCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
if ($pluginCalendar) {
$lpCalendar = LpCalendarPlugin::create();
$menu_items[] = Display::url(
Display::return_icon('agenda.png', $lpCalendar->get_lang('LearningCalendar'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php'
);
$calendarMenuAdded = true;
}
}
}
@ -143,7 +146,7 @@ $actionsLeft = '';
if ($display == 'useroverview' || $display == 'sessionoverview' || $display == 'courseoverview') {
$actionsRight .= Display::url(
Display::return_icon(
"export_csv.png",
'export_csv.png',
get_lang('ExportAsCSV'),
null,
ICON_SIZE_MEDIUM
@ -151,6 +154,7 @@ if ($display == 'useroverview' || $display == 'sessionoverview' || $display == '
api_get_self().'?display='.$display.'&export=csv&view='.$view
);
}
$actionsRight .= Display::url(
Display::return_icon(
'printer.png',
@ -210,18 +214,26 @@ if (!empty($session_id) &&
null,
ICON_SIZE_MEDIUM
),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
);
if ($pluginCalendar && api_is_teacher() && $calendarMenuAdded === false) {
$lpCalendar = LpCalendarPlugin::create();
$actionsLeft .= Display::url(
Display::return_icon('agenda.png', $lpCalendar->get_lang('LearningCalendar'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php'
);
}
if (api_is_platform_admin(true) || api_is_student_boss()) {
$actionsLeft .= Display::url(
Display::return_icon(
"certificate_list.png",
get_lang("GradebookSeeListOfStudentsCertificates"),
get_lang('GradebookSeeListOfStudentsCertificates'),
null,
ICON_SIZE_MEDIUM
),
api_get_path(WEB_CODE_PATH)."gradebook/certificate_report.php"
api_get_path(WEB_CODE_PATH).'gradebook/certificate_report.php'
);
}
}
@ -291,7 +303,6 @@ $form = new FormValidator(
api_get_path(WEB_CODE_PATH).'mySpace/student.php'
);
$form = Tracking::setUserSearchForm($form);
$skipData = api_get_configuration_value('tracking_skip_generic_data');
$totalTimeSpent = null;

@ -1784,39 +1784,7 @@ if ($allowAll) {
if ($allowMessages === true) {
// Messages
echo Display::page_subheader2(get_lang('Messages'));
$messages = MessageManager::getMessagesAboutUser($user_info);
if (!empty($messages)) {
/** @var Message $message */
foreach ($messages as $message) {
$tag = 'message_'.$message->getId();
$tagAccordion = 'accordion_'.$message->getId();
$tagCollapse = 'collapse_'.$message->getId();
$date = Display::dateToStringAgoAndLongDate(
$message->getSendDate()
);
$localTime = api_get_local_time(
$message->getSendDate(),
null,
null,
false,
false
);
$senderId = $message->getUserSenderId();
$senderInfo = api_get_user_info($senderId);
echo Display::panelCollapse(
$localTime.' '.$senderInfo['complete_name'].' '.$message->getTitle(),
$message->getContent().'<br />'.$date.'<br />'.get_lang(
'Author'
).': '.$senderInfo['complete_name_with_message_link'],
$tag,
null,
$tagAccordion,
$tagCollapse,
false
);
}
}
echo MessageManager::getMessagesAboutUserToString($user_info);
echo Display::url(
get_lang('NewMessage'),

@ -180,7 +180,7 @@ if (!empty($projectId)) {
$selectTypes[$type['category_id']] = $type['name'];
}
$admins = UserManager::get_user_list_like(
$admins = UserManager::getUserListLike(
['status' => '1'],
['username'],
true

@ -102,10 +102,10 @@ if (api_is_allowed_to_edit()) {
}
}
//jqgrid will use this URL to do the selects
// jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter;
//The order is important you need to check the the $column variable in the model.ajax.php file
// The order is important you need to check the the $column variable in the model.ajax.php file
$columns = [
get_lang('Name'),
get_lang('Users'),
@ -152,7 +152,7 @@ $extraParams['autowidth'] = 'true';
// height auto
$extraParams['height'] = 'auto';
Display::display_header($tool_name, "User");
Display::display_header($tool_name, 'User');
?>
<script>

@ -46,7 +46,7 @@ if (!empty($usergroup_list)) {
}
}
Display::display_header($tool_name, 'Classes');
Display::display_header('', 'Classes');
echo $content;

@ -8,6 +8,7 @@ class LpCalendarPlugin extends Plugin
{
const EVENT_TYPE_TAKEN = 1;
const EVENT_TYPE_EXAM = 2;
const EVENT_TYPE_FREE = 3;
/**
* Class constructor.
@ -21,17 +22,34 @@ class LpCalendarPlugin extends Plugin
}
/**
* Event definition.
*
* @return array
*/
public static function getEventTypeList()
public function getEventTypeList()
{
return [
//self::EVENT_TYPE_FREE => 'green',
self::EVENT_TYPE_TAKEN => 'red',
self::EVENT_TYPE_EXAM => 'yellow',
self::EVENT_TYPE_TAKEN => ['color' => 'red', 'name' => self::get_lang('EventTypeTaken')],
self::EVENT_TYPE_EXAM => ['color' => 'yellow', 'name' => self::get_lang('EventTypeExam')],
self::EVENT_TYPE_FREE => ['color' => 'green', 'name' => self::get_lang('EventTypeFree')],
];
}
/**
*
* @return array
*/
public function getEventTypeColorList()
{
$list = $this->getEventTypeList();
$newList = [];
foreach ($list as $eventId => $event) {
$newList[$eventId] = $event['color'];
}
return $newList;
}
/**
* Get the class instance.
*
@ -103,6 +121,7 @@ class LpCalendarPlugin extends Plugin
$extraField = new ExtraField('course');
$params = [
'display_text' => get_lang('Duration'),
'variable' => 'course_hours_duration',
'visible_to_self' => 1,
'changeable' => 1,
@ -155,7 +174,7 @@ class LpCalendarPlugin extends Plugin
*
* @return array
*/
public static function getCalendars(
public function getCalendars(
$from,
$numberOfItems,
$column,
@ -213,7 +232,7 @@ class LpCalendarPlugin extends Plugin
*
* @return array
*/
public static function getCalendarsEventsByDate($calendarInfo, $start, $end, $type = 0, $getCount = false)
public function getCalendarsEventsByDate($calendarInfo, $start, $end, $type = 0, $getCount = false)
{
if (empty($calendarInfo)) {
return [];
@ -247,7 +266,7 @@ class LpCalendarPlugin extends Plugin
}
$sql = "SELECT $select FROM learning_calendar_events
WHERE calendar_id = $calendarId $startCondition $endCondition ";
WHERE calendar_id = $calendarId $startCondition $endCondition $typeCondition";
$result = Database::query($sql);
if ($getCount) {
@ -270,7 +289,7 @@ class LpCalendarPlugin extends Plugin
*
* @return array
*/
public static function getFirstCalendarDate($calendarInfo)
public function getFirstCalendarDate($calendarInfo)
{
if (empty($calendarInfo)) {
return [];
@ -286,7 +305,6 @@ class LpCalendarPlugin extends Plugin
$sql = "SELECT start_date FROM learning_calendar_events
WHERE calendar_id = $calendarId ORDER BY start_date LIMIT 1";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
return $row['start_date'];
@ -295,7 +313,7 @@ class LpCalendarPlugin extends Plugin
/**
* @return int
*/
public static function getCalendarCount()
public function getCalendarCount()
{
$sql = 'select count(*) as count FROM learning_calendar';
$result = Database::query($sql);
@ -304,6 +322,43 @@ class LpCalendarPlugin extends Plugin
return (int) $result['count'];
}
/**
* @param int $calendarId
*
* @return array
*/
public function getUsersPerCalendar($calendarId)
{
$calendarId = (int) $calendarId;
$sql = "SELECT * FROM learning_calendar_user
WHERE calendar_id = $calendarId";
$result = Database::query($sql);
$list = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
$userInfo = api_get_user_info($row['user_id']);
$userInfo['exam'] = 'exam';
$list[] = $userInfo;
}
return $list;
}
/**
* @param int $calendarId
*
* @return int
*/
public function getUsersPerCalendarCount($calendarId)
{
$calendarId = (int) $calendarId;
$sql = "SELECT count(id) as count FROM learning_calendar_user
WHERE calendar_id = $calendarId";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
return (int) $row['count'];
}
/**
* @param int $id
*/
@ -356,7 +411,7 @@ class LpCalendarPlugin extends Plugin
*
* @return array|mixed
*/
public static function getCalendar($calendarId)
public function getCalendar($calendarId)
{
$calendarId = (int) $calendarId;
$sql = "SELECT * FROM learning_calendar WHERE id = $calendarId";
@ -371,7 +426,7 @@ class LpCalendarPlugin extends Plugin
*
* @return array|mixed
*/
public static function getUserCalendar($userId)
public function getUserCalendar($userId)
{
$userId = (int) $userId;
$sql = "SELECT * FROM learning_calendar_user WHERE user_id = $userId";
@ -390,13 +445,13 @@ class LpCalendarPlugin extends Plugin
*
* @return array|int
*/
public static function getUserEvents($userId, $start, $end, $type = 0, $getCount = false)
public function getUserEvents($userId, $start, $end, $type = 0, $getCount = false)
{
$calendarRelUser = self::getUserCalendar($userId);
$calendarRelUser = $this->getUserCalendar($userId);
if (!empty($calendarRelUser)) {
$calendar = self::getCalendar($calendarRelUser['calendar_id']);
$calendar = $this->getCalendar($calendarRelUser['calendar_id']);
return self::getCalendarsEventsByDate($calendar, $start, $end, $type, $getCount);
return $this->getCalendarsEventsByDate($calendar, $start, $end, $type, $getCount);
}
if ($getCount) {
@ -411,11 +466,11 @@ class LpCalendarPlugin extends Plugin
*
* @return mixed|string
*/
public static function getUserCalendarToString($userId)
public function getUserCalendarToString($userId)
{
$calendar = self::getUserCalendar($userId);
$calendar = $this->getUserCalendar($userId);
if ($calendar) {
$calendarInfo = self::getCalendar($calendar['calendar_id']);
$calendarInfo = $this->getCalendar($calendar['calendar_id']);
return $calendarInfo['title'];
}
@ -429,9 +484,9 @@ class LpCalendarPlugin extends Plugin
*
* @return bool
*/
public static function addUserToCalendar($calendarId, $userId)
public function addUserToCalendar($calendarId, $userId)
{
$calendar = self::getUserCalendar($userId);
$calendar = $this->getUserCalendar($userId);
if (empty($calendar)) {
$params = [
'calendar_id' => $calendarId,
@ -450,9 +505,9 @@ class LpCalendarPlugin extends Plugin
*
* @return bool
*/
public static function updateUserToCalendar($calendarId, $userId)
public function updateUserToCalendar($calendarId, $userId)
{
$calendar = self::getUserCalendar($userId);
$calendar = $this->getUserCalendar($userId);
if (!empty($calendar)) {
$params = [
'calendar_id' => $calendarId,
@ -471,7 +526,7 @@ class LpCalendarPlugin extends Plugin
*
* @return bool
*/
public static function deleteAllCalendarFromUser($calendarId, $userId)
public function deleteAllCalendarFromUser($calendarId, $userId)
{
$calendarId = (int) $calendarId;
$userId = (int) $userId;
@ -514,7 +569,7 @@ class LpCalendarPlugin extends Plugin
public function getPersonalEvents($calendar, $start, $end)
{
$userId = api_get_user_id();
$events = self::getUserEvents($userId, $start, $end);
$events = $this->getUserEvents($userId, $start, $end);
if (empty($events)) {
return [];
@ -524,13 +579,13 @@ class LpCalendarPlugin extends Plugin
$events = $events['events'];
$list = [];
$typeList = self::getEventTypeList();
$typeList = $this->getEventTypeColorList();
foreach ($events as $row) {
$event = [];
$event['id'] = 'personal_'.$row['id'];
$event['title'] = $calendarInfo['title'];
$event['className'] = 'personal';
$color = isset($typeList[$row['type']]) ? $typeList[$row['type']] : 'green';
$color = isset($typeList[$row['type']]) ? $typeList[$row['type']] : $typeList[self::EVENT_TYPE_FREE];
$event['borderColor'] = $color;
$event['backgroundColor'] = $color;
@ -563,7 +618,7 @@ class LpCalendarPlugin extends Plugin
*
* @return int
*/
public static function getItemCountChecked($userId, $coursesAndSessions)
public function getItemCountChecked($userId, $coursesAndSessions)
{
$userId = (int) $userId;
@ -641,7 +696,7 @@ class LpCalendarPlugin extends Plugin
{
// @todo use translation
// get events from this year to today
$stats = self::getUserStats($userId, $courseAndSessionList);
$stats = $this->getUserStats($userId, $courseAndSessionList);
$html = $this->get_lang('NumberDaysAccumulatedInCalendar').$stats['user_event_count'];
if (!empty($courseAndSessionList)) {
$html .= '<br />';
@ -661,10 +716,10 @@ class LpCalendarPlugin extends Plugin
*
* @return array
*/
public static function getUserStats($userId, $courseAndSessionList)
public function getUserStats($userId, $courseAndSessionList)
{
// Get events from this year to today
$takenCount = self::getUserEvents(
$takenCount = $this->getUserEvents(
$userId,
strtotime(date('Y-01-01')),
time(),
@ -674,12 +729,11 @@ class LpCalendarPlugin extends Plugin
$completed = 0;
$diff = 0;
if (!empty($courseAndSessionList)) {
$completed = self::getItemCountChecked($userId, $courseAndSessionList);
if ($takenCount > $completed) {
$completed = $this->getItemCountChecked($userId, $courseAndSessionList);
//if ($takenCount > $completed) {
$diff = $takenCount - $completed;
}
//}
}
return [
@ -688,4 +742,146 @@ class LpCalendarPlugin extends Plugin
'diff' => $diff,
];
}
/**
* @param int $calendarId
*
* @return bool
*/
public function copyCalendar($calendarId)
{
$item = $this->getCalendar($calendarId);
if (empty($item)) {
return false;
}
$calendarId = (int) $calendarId;
unset($item['id']);
//$item['title'] = $item['title'];
$newCalendarId = Database::insert('learning_calendar', $item);
if (!empty($newCalendarId)) {
$sql = "SELECT * FROM learning_calendar_events WHERE calendar_id = $calendarId";
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
unset($row['id']);
$row['calendar_id'] = $newCalendarId;
Database::insert('learning_calendar_events', $row);
}
return true;
}
return false;
}
/**
* @param int $calendarId
*
* @return bool
*/
public function deleteCalendar($calendarId)
{
$item = $this->getCalendar($calendarId);
if (empty($item)) {
return false;
}
$calendarId = (int) $calendarId;
$sql = "DELETE FROM learning_calendar WHERE id = $calendarId";
Database::query($sql);
// Delete events
$sql = "DELETE FROM learning_calendar_events WHERE calendar_id = $calendarId";
Database::query($sql);
return true;
}
/**
* @param int $calendarId
* @param string $startDate
*/
public function toogleDayType($calendarId, $startDate)
{
$startDate = Database::escape_string($startDate);
$calendarId = (int) $calendarId;
$eventTypeList = $this->getEventTypeColorList();
// Remove the free type to loop correctly when toogle days.
unset($eventTypeList[self::EVENT_TYPE_FREE]);
$sql = "SELECT * FROM learning_calendar_events
WHERE start_date = '$startDate' AND calendar_id = $calendarId ";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result, 'ASSOC');
$currentType = $row['type'];
$currentType++;
if ($currentType > count($eventTypeList)) {
Database::delete(
'learning_calendar_events',
[' calendar_id = ? AND start_date = ?' => [$calendarId, $startDate]]
);
} else {
$params = [
'type' => $currentType,
];
Database::update(
'learning_calendar_events',
$params,
[' calendar_id = ? AND start_date = ?' => [$calendarId, $startDate]]
);
}
} else {
$params = [
'name' => '',
'calendar_id' => $calendarId,
'start_date' => $startDate,
'end_date' => $startDate,
'type' => self::EVENT_TYPE_TAKEN,
];
Database::insert('learning_calendar_events', $params);
}
}
/**
* @param int $calendarId
*
* @return array
*/
public function getEvents($calendarId)
{
$calendarId = (int) $calendarId;
$eventTypeList = $this->getEventTypeColorList();
$sql = "SELECT * FROM learning_calendar_events
WHERE calendar_id = $calendarId ";
$result = Database::query($sql);
$list = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
$list[] = [
'start_date' => $row['start_date'],
'end_date' => $row['start_date'],
'color' => $eventTypeList[$row['type']],
];
}
return $list;
}
public function protectCalendar($calendarId = 0)
{
$allow = api_is_platform_admin() || api_is_teacher();
if (!$allow) {
api_not_allowed(true);
}
}
}

@ -3,69 +3,40 @@
require_once __DIR__.'/../../main/inc/global.inc.php';
$allow = api_is_allowed_to_edit();
if (!$allow) {
api_not_allowed(true);
}
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : '';
$calendarId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$eventTypeList = LpCalendarPlugin::getEventTypeList();
$plugin = LpCalendarPlugin::create();
$plugin->protectCalendar($calendarId);
switch ($action) {
case 'toggle_day':
$startDate = isset($_REQUEST['date']) ? $_REQUEST['date'] : '';
//$endDate = isset($_REQUEST['date']) ? $_REQUEST['date'] : 0;
$sql = "SELECT * FROM learning_calendar_events
WHERE start_date = '$startDate' AND calendar_id = $calendarId ";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result, 'ASSOC');
$currentType = $row['type'];
$currentType++;
if ($currentType > count($eventTypeList)) {
$currentType = 1;
Database::delete(
'learning_calendar_events',
[' calendar_id = ? AND start_date = ?' => [$calendarId, $startDate]]
);
} else {
$params = [
'type' => $currentType,
];
Database::update(
'learning_calendar_events',
$params,
[' calendar_id = ? AND start_date = ?' => [$calendarId, $startDate]]
);
}
$startDate = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : '';
if (empty($startDate)) {
exit;
}
$endDate = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : '';
if (empty($endDate)) {
// One day
$plugin->toogleDayType($calendarId, $startDate);
} else {
$params = [
'name' => '',
'calendar_id' => $calendarId,
'start_date' => $startDate,
'end_date' => $startDate,
'type' => LpCalendarPlugin::EVENT_TYPE_TAKEN,
];
Database::insert('learning_calendar_events', $params);
// A list of days
$startDateTime = new DateTime($startDate);
$endDateTime = new DateTime($endDate);
$diff = $startDateTime->diff($endDateTime);
$countDays = $diff->format('%a');
$dayList[] = $startDate;
for ($i = 0; $i < $countDays; $i++) {
$startDateTime->modify('+1 day');
$dayList[] = $startDateTime->format('Y-m-d');
}
foreach ($dayList as $day) {
$plugin->toogleDayType($calendarId, $day);
}
}
break;
case 'get_events':
$sql = "SELECT * FROM learning_calendar_events
WHERE calendar_id = $calendarId ";
$result = Database::query($sql);
$list = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
$list[] = [
'start_date' => $row['start_date'],
'end_date' => $row['start_date'],
'color' => $eventTypeList[$row['type']],
];
}
$list = $plugin->getEvents($calendarId);
echo json_encode($list);
break;
}

@ -3,15 +3,10 @@
require_once __DIR__.'/../../main/inc/global.inc.php';
$allow = api_is_allowed_to_edit();
if (!$allow) {
api_not_allowed(true);
}
$calendarId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$item = LpCalendarPlugin::getCalendar($calendarId);
$plugin = LpCalendarPlugin::create();
$plugin->protectCalendar($calendarId);
$item = $plugin->getCalendar($calendarId);
if (empty($item)) {
api_not_allowed(true);
@ -31,12 +26,10 @@ if ($isoCode !== 'en') {
$htmlHeadXtra[] = api_get_css_asset('bootstrap-year-calendar/css/bootstrap-year-calendar.css');
$plugin = LpCalendarPlugin::create();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$formToString = '';
$template = new Template();
$actionLeft = Display::url(
Display::return_icon(
'back.png',
@ -48,10 +41,12 @@ $actionLeft = Display::url(
);
$actions = Display::toolbarAction('toolbar-forum', [$actionLeft]);
$template->assign('calendar_language', $calendarLanguage);
$template->assign('ajax_url', api_get_path(WEB_PLUGIN_PATH).'lp_calendar/ajax.php?id='.$calendarId);
$eventList = $plugin->getEventTypeList();
$template->assign('events', $eventList);
$template->assign('calendar_language', $calendarLanguage);
$template->assign('ajax_url', api_get_path(WEB_PLUGIN_PATH).'lp_calendar/ajax.php?id='.$calendarId);
$template->assign('header', $item['title']);
$content = $template->fetch('lp_calendar/view/calendar.tpl');
$template->assign('actions', $actions);

@ -0,0 +1,108 @@
<?php
/* For license terms, see /license.txt */
require_once __DIR__.'/../../main/inc/global.inc.php';
$calendarId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$plugin = LpCalendarPlugin::create();
$plugin->protectCalendar($calendarId);
$item = $plugin->getCalendar($calendarId);
if (empty($item)) {
api_not_allowed(true);
}
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$formToString = '';
$template = new Template();
$actionLeft = Display::url(
Display::return_icon(
'back.png',
get_lang('Add'),
null,
ICON_SIZE_MEDIUM
),
api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php'
);
$actions = Display::toolbarAction('toolbar-forum', [$actionLeft]);
// jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_calendar_users&id='.$calendarId;
// The order is important you need to check the the $column variable in the model.ajax.php file
$columns = [
get_lang('FirstName'),
get_lang('LastName'),
get_lang('Exam'),
];
// Column config
$column_model = [
['name' => 'firstname', 'index' => 'firstname', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
['name' => 'lastname', 'index' => 'lastname', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
[
'name' => 'exam',
'index' => 'exam',
'width' => '20',
'align' => 'center',
'sortable' => 'false'
],
];
// Autowidth
$extraParams['autowidth'] = 'true';
// height auto
$extraParams['height'] = 'auto';
$extraParams['sortname'] = 'name';
$extraParams['sortorder'] = 'desc';
$extraParams['multiselect'] = true;
$deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), null, ICON_SIZE_SMALL);
$urlStats = api_get_path(WEB_CODE_PATH);
$action_links = '';
$deleteUrl = '';
// Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
Display::display_header();
?>
<script>
$(function() {
<?php
// grid definition see the $usergroup>display() function
echo Display::grid_js(
'usergroups',
$url,
$columns,
$column_model,
$extraParams,
[],
$action_links,
true
);
?>
$("#usergroups").jqGrid(
"navGrid",
"#usergroups_pager",
{ edit: false, add: false, del: true, search: false},
{ height:280, reloadAfterSubmit:false }, // edit options
{ height:280, reloadAfterSubmit:false }, // add options
{ reloadAfterSubmit:false, url: "<?php echo $deleteUrl; ?>" }, // del options
{ width:500 } // search options
);
});
</script>
<?php
// action links
echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?id='.$calendarId.'">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', '32').
'</a>';
echo '</div>';
echo Display::grid_html('usergroups');
Display::display_footer();

@ -9,3 +9,8 @@ $strings['NumberDaysAccumulatedInCalendar'] = 'Number of days accumulated in the
$strings['NumberDaysAccumulatedInLp'] = 'Number of days accumulated in the LP: ';
$strings['NumberDaysInRetard'] = 'Number of days in retard: ';
$strings['DifferenceOfDaysAndCalendar'] = 'Difference of days and calendar';
$strings['EventTypeTaken'] = 'Taken';
$strings['EventTypeExam'] = 'Exam';
$strings['EventTypeFree'] = 'Free';

@ -9,3 +9,6 @@ $strings['NumberDaysAccumulatedInCalendar'] = 'Nombre de jours cumulés dans le
$strings['NumberDaysAccumulatedInLp'] = 'Nombre de jours cumulés dans les parcours réalisés: ';
$strings['NumberDaysInRetard'] = "Nombre de jour de retard ou d'avance à la date d'aujourd'hui: ";
$strings['DifferenceOfDaysAndCalendar'] = 'Différence de nombre de jours avec le plan issu du learning_calendar';
$strings['EventTypeTaken'] = 'Occupé';
$strings['EventTypeExam'] = 'Examen';
$strings['EventTypeFree'] = 'Libre';

@ -3,7 +3,7 @@
require_once __DIR__.'/../../main/inc/global.inc.php';
$allow = api_is_allowed_to_edit();
$allow = api_is_platform_admin() || api_is_teacher();
if (!$allow) {
api_not_allowed(true);
@ -19,7 +19,6 @@ switch ($action) {
$form = new FormValidator('calendar', 'post', api_get_self().'?action=add');
$plugin->getForm($form);
$form->addButtonSave(get_lang('Save'));
$formToString = $form->returnForm();
if ($form->validate()) {
@ -40,15 +39,13 @@ switch ($action) {
$form = new FormValidator('calendar', 'post', api_get_self().'?action=edit&id='.$calendarId);
$plugin->getForm($form);
$form->addButtonSave(get_lang('Update'));
$item = LpCalendarPlugin::getCalendar($calendarId);
$item = $plugin->getCalendar($calendarId);
if (empty($item)) {
api_not_allowed(true);
}
$form->setDefaults($item);
$formToString = $form->returnForm();
if ($form->validate()) {
@ -66,55 +63,29 @@ switch ($action) {
}
break;
case 'copy':
$item = LpCalendarPlugin::getCalendar($calendarId);
if (empty($item)) {
api_not_allowed(true);
}
unset($item['id']);
$item['title'] = $item['title'].' - '.get_lang('Copy');
$newCalendarId = Database::insert('learning_calendar', $item);
if (!empty($newCalendarId)) {
$result = $plugin->copyCalendar($calendarId);
if ($result) {
Display::addFlash(Display::return_message(get_lang('Saved')));
$sql = "SELECT * FROM learning_calendar_events WHERE calendar_id = $calendarId";
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
unset($row['id']);
$row['calendar_id'] = $newCalendarId;
Database::insert('learning_calendar_events', $row);
}
}
header('Location: start.php');
exit;
break;
case 'delete':
$item = LpCalendarPlugin::getCalendar($calendarId);
if (empty($item)) {
api_not_allowed(true);
$result = $plugin->deleteCalendar($calendarId);
if ($result) {
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
$sql = "DELETE FROM learning_calendar WHERE id = $calendarId";
Database::query($sql);
// Delete events
$sql = "DELETE FROM learning_calendar_events WHERE calendar_id = $calendarId";
Database::query($sql);
Display::addFlash(Display::return_message(get_lang('Deleted')));
header('Location: start.php');
exit;
break;
case 'toggle_visibility':
$itemId = isset($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : 0;
$lpId = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : 0;
$plugin->toggleVisibility($itemId);
Display::addFlash(Display::return_message(get_lang('Updated')));
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=add_item&lp_id='.$lpId.'&'.api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH).
'lp/lp_controller.php?action=add_item&type=step&lp_id='.$lpId.'&'.api_get_cidreq();
header("Location: $url");
exit;
break;

@ -22,7 +22,7 @@
$('#calendar').calendar({
style:'background',
language : '{{ calendar_language }}',
enableRangeSelection: false,
enableRangeSelection: true,
enableContextMenu: true,
/*contextMenuItems:[
{
@ -41,7 +41,18 @@
var dateString = moment(e.date).format("YYYY-MM-DD");
$.ajax({
type: "GET",
url: "{{ ajax_url }}&a=toggle_day&date="+dateString,
url: "{{ ajax_url }}&a=toggle_day&start_date="+dateString+"&end_date=",
success: function(returnValue) {
getEvents(e);
}
});
},
selectRange: function(e) {
var startString = moment(e.startDate).format("YYYY-MM-DD");
var endString = moment(e.endDate).format("YYYY-MM-DD");
$.ajax({
type: "GET",
url: "{{ ajax_url }}&a=toggle_day&start_date="+startString+"&end_date=" + endString,
success: function(returnValue) {
getEvents(e);
}
@ -60,6 +71,32 @@
#calendar {
overflow: visible;
}
.calendar table.month tr td .day-content {
height: 24px;
}
</style>
<div id=calendar></div>
<div class="row">
<div class="col-xs-12 col-md-12">
<div id="calendar"></div>
</div>
</div>
<br />
<br />
<div class="row">
<div class="col-xs-12 col-md-12">
<table>
{% for event in events %}
<tr>
<td>
{{ event.name }}:
</td>
<td>
<span style="display:block;height:20px;width:100px; background-color: {{ event.color }}"></span>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>

@ -66,6 +66,13 @@ class Usergroup
*/
protected $visibility;
/**
* @var string
*
* ORM\Column(name="author_id", type="integer", nullable=true)
*/
//protected $authorId;
/**
* @var int
*

@ -283,7 +283,7 @@ $controller->tpl->assign('course_block', $controller->return_course_block());
$controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
$controller->tpl->assign('search_block', $controller->return_search_block());
$controller->tpl->assign('notice_block', $controller->return_notice());
$controller->tpl->assign('classes_block', $controller->return_classes_block());
$controller->tpl->assign('classes_block', $controller->returnClassesBlock());
$controller->tpl->assign('skills_block', $controller->returnSkillLinks());
$historyClass = '';

Loading…
Cancel
Save