Add new plugin LPCalendar (WIP) see BT#14608

- Block usergroups pages using new function $usergroup->protectScript();
- Change breadcrumbs to not show the "Administration" in classes
- Make number of users inside usergroup/classes clickable now we show
the list of users.
- Add LPCalendar link in "Reporting"
- Add new ajax page usergroup.ajax.php
- Add lp_item "calendar" extra field
pull/2591/head
Julio 8 years ago
parent 4a8bace60f
commit 44208472ce
  1. 7
      main/admin/add_courses_to_usergroup.php
  2. 51
      main/admin/add_sessions_to_usergroup.php
  3. 12
      main/admin/add_users_to_usergroup.php
  4. 8
      main/admin/usergroup_export.php
  5. 10
      main/admin/usergroup_import.php
  6. 11
      main/admin/usergroup_user_import.php
  7. 251
      main/admin/usergroup_users.php
  8. 23
      main/admin/usergroups.php
  9. 42
      main/inc/ajax/model.ajax.php
  10. 24
      main/inc/ajax/usergroup.ajax.php
  11. 1
      main/inc/lib/display.lib.php
  12. 129
      main/inc/lib/usergroup.lib.php
  13. 34
      main/lp/learnpath.class.php
  14. 10
      main/mySpace/index.php
  15. 393
      plugin/lp_calendar/LpCalendarPlugin.php
  16. 2
      plugin/lp_calendar/README.md
  17. 69
      plugin/lp_calendar/ajax.php
  18. 64
      plugin/lp_calendar/calendar.php
  19. 8
      plugin/lp_calendar/install.php
  20. 6
      plugin/lp_calendar/lang/english.php
  21. 6
      plugin/lp_calendar/lang/french.php
  22. 6
      plugin/lp_calendar/lang/spanish.php
  23. 4
      plugin/lp_calendar/plugin.php
  24. 222
      plugin/lp_calendar/start.php
  25. 4
      plugin/lp_calendar/uninstall.php
  26. 65
      plugin/lp_calendar/view/calendar.tpl
  27. 3
      plugin/lp_calendar/view/start.tpl

@ -10,15 +10,15 @@ $cidReset = true;
// Including some necessary files.
require_once __DIR__.'/../inc/global.inc.php';
$usergroup = new UserGroup();
$usergroup->protectScript();
$xajax = new xajax();
$xajax->registerFunction('search');
// 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' => 'usergroups.php', 'name' => get_lang('Classes')];
@ -48,7 +48,6 @@ function remove_item(origin) {
$form_sent = 0;
$errorMsg = '';
$sessions = [];
$usergroup = new UserGroup();
$id = intval($_GET['id']);
if (isset($_POST['form_sent']) && $_POST['form_sent']) {

@ -9,23 +9,19 @@ $cidReset = true;
// including some necessary files
require_once __DIR__.'/../inc/global.inc.php';
$xajax = new xajax();
$usergroup = new UserGroup();
$usergroup->protectScript();
//$xajax->debugOn();
$xajax = new xajax();
$xajax->registerFunction('search_usergroup_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' => 'usergroups.php', 'name' => get_lang('Classes')];
// Database Table Definitions
// setting the name of the tool
$tool_name = get_lang('SubscribeClassToSessions');
@ -40,9 +36,7 @@ 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;
@ -63,13 +57,13 @@ function remove_item(origin) {
}
function display_advanced_search () {
if ($("#advancedSearch").css("display") == "none") {
$("#advancedSearch").css("display","block");
$("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide'), ['style' => 'vertical-align:middle']).'&nbsp;'.get_lang('AdvancedSearch').'\');
} else {
$("#advancedSearch").css("display","none");
$("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show'), ['style' => 'vertical-align:middle']).'&nbsp;'.get_lang('AdvancedSearch').'\');
}
if ($("#advancedSearch").css("display") == "none") {
$("#advancedSearch").css("display","block");
$("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide'), ['style' => 'vertical-align:middle']).'&nbsp;'.get_lang('AdvancedSearch').'\');
} else {
$("#advancedSearch").css("display","none");
$("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show'), ['style' => 'vertical-align:middle']).'&nbsp;'.get_lang('AdvancedSearch').'\');
}
}
function validate_filter() {
@ -112,10 +106,9 @@ if (!empty($session_list)) {
}
}
$ajax_search = $add_type == 'unique' ? true : false;
//checking for extra field with filter on
$ajax_search = $add_type === 'unique' ? true : false;
// checking for extra field with filter on
function search_usergroup_sessions($needle, $type)
{
global $elements_in;
@ -165,7 +158,8 @@ if ($add_type == 'multiple') {
}
echo '<div class="actions">';
echo '<a href="usergroups.php">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
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">&nbsp;'.
Display::return_icon('div_show.gif', get_lang('Show'), ['style' => 'vertical-align:middle']).' '.get_lang('AdvancedSearch').'</span></a>';
echo '</div>';
@ -223,7 +217,13 @@ if (!empty($errorMsg)) {
} 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); ?>
<?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
}
@ -254,7 +254,13 @@ if (!empty($errorMsg)) {
</td>
<td align="center">
<?php
echo Display::select('elements_in_name[]', $elements_in, '', ['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_in', 'size' => '15px'], false);
echo Display::select(
'elements_in_name[]',
$elements_in,
'',
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_in', 'size' => '15px'],
false
);
unset($sessionUsersList);
?>
</td>
@ -331,7 +337,6 @@ function loadUsersInSelect(select) {
xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 4) {
document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
//alert(xhr_object.responseText);
}
}
}

@ -14,15 +14,13 @@ 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);
$usergroup = new UserGroup();
$usergroup->protectScript();
// setting breadcrumbs
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
// Database Table Definitions
// setting the name of the tool
$tool_name = get_lang('SubscribeUsersToClass');
@ -66,8 +64,8 @@ function validate_filter() {
document.formulaire.submit();
}
function checked_in_no_group(checked) {
function checked_in_no_group(checked)
{
$("#relation")
.find("option")
.attr("selected", false);
@ -102,8 +100,6 @@ if (is_array($extra_field_list)) {
}
}
$usergroup = new UserGroup();
if (empty($id)) {
api_not_allowed(true);
}

@ -9,11 +9,10 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$userGroup = new UserGroup();
$userGroup->protectScript();
$tool_name = get_lang('Export');
$interbreadcrumb[] = ["url" => 'index.php', "name" => get_lang('PlatformAdmin')];
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
set_time_limit(0);
@ -23,7 +22,6 @@ $form->addElement('header', $tool_name);
$form->addButtonExport(get_lang('Export'));
if ($form->validate()) {
$userGroup = new UserGroup();
$header = [['id', 'name', 'description', 'users']];
$data = $userGroup->getDataToExport();
$data = array_merge($header, $data);
@ -32,6 +30,6 @@ if ($form->validate()) {
exit;
}
Display :: display_header($tool_name);
Display::display_header($tool_name);
$form->display();
Display::display_footer();

@ -82,14 +82,12 @@ require_once __DIR__.'/../inc/global.inc.php';
// Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN;
// Access restrictions.
api_protect_admin_script();
$usergroup = new UserGroup();
$usergroup->protectScript();
// setting breadcrumbs
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
// Database Table Definitions
// Setting the name of the tool.
$tool_name = get_lang('ImportClassListCSV');
@ -128,7 +126,7 @@ if ($form->validate()) {
}
// Displaying the header.
Display :: display_header($tool_name);
Display::display_header($tool_name);
$form->display();
?>
@ -140,4 +138,4 @@ $form->display();
</pre>
<?php
// Displaying the footer.
Display :: display_footer();
Display::display_footer();

@ -83,8 +83,6 @@ function save_data($users_classes, $deleteUsersNotInList = false)
WHERE username = '".Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames))."'";
$res1 = Database::query($sql1);
$obj1 = Database::fetch_object($res1);
$usergroup = new UserGroup();
$id = $usergroup->get_id_by_name($user_class['ClassName']);
if ($obj1 && $id) {
@ -135,11 +133,12 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
$usergroup = new UserGroup();
$usergroup->protectScript();
$tool_name = get_lang('AddUsersToAClass').' CSV';
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
// Set this option to true to enforce strict purification for usenames.
@ -164,7 +163,7 @@ if ($form->validate()) {
}
}
Display :: display_header($tool_name);
Display::display_header($tool_name);
if (isset($return) && $return) {
echo $return;
@ -188,4 +187,4 @@ jdoe;class01
adam;class01
</pre>
<?php
Display :: display_footer();
Display::display_footer();

@ -0,0 +1,251 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
$usergroup = new UserGroup();
$usergroup->protectScript();
// 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, '');
if (empty($calendars)) {
echo Display::return_message(get_lang('Nodata'));
exit;
}
$userInfo = api_get_user_info($userId);
$calendars = array_column($calendars, 'title', 'id');
$calendars = array_map('strip_tags', $calendars);
$form = new FormValidator(
'add_calendar',
'post',
api_get_self().'?id='.$id.'&user_id='.$userId.'&action=add_calendar'
);
$form->addHeader($userInfo['complete_name']);
$form->addSelect('calendar_id', get_lang('Calendar'), $calendars, ['disable_js' => true]);
$form->addButtonSave(get_lang('Save'));
$form->display();
if ($form->validate()) {
$calendarId = $form->getSubmitValue('calendar_id');
if (!empty($calendarId)) {
LpCalendarPlugin::addUserToCalendar($calendarId, $userId);
Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation'));
header('Location: '.api_get_self().'?id='.$id);
exit;
}
}
exit;
break;
case 'edit_calendar':
$calendars = LpCalendarPlugin::getCalendars(0, 1000, '');
if (empty($calendars)) {
echo Display::return_message(get_lang('Nodata'));
exit;
}
$calendars = array_column($calendars, 'title', 'id');
$calendars = array_map('strip_tags', $calendars);
$form = new FormValidator(
'add_calendar',
'post',
api_get_self().'?id='.$id.'&user_id='.$userId.'&action=edit_calendar&calendar_id='.$calendarId
);
$userInfo = api_get_user_info($userId);
$form->addHeader($userInfo['complete_name']);
$form->addSelect('calendar_id', get_lang('Calendar'), $calendars, ['disable_js' => true]);
$form->addButtonSave(get_lang('Update'));
$form->setDefaults(['calendar_id' => $calendarId]);
$form->display();
if ($form->validate()) {
$calendarId = $form->getSubmitValue('calendar_id');
if (!empty($calendarId)) {
LpCalendarPlugin::updateUserToCalendar($calendarId, $userId);
Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation'));
header('Location: '.api_get_self().'?id='.$id);
exit;
}
}
exit;
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
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_users&id='.$id;
// The order is important you need to check the the $column variable in the model.ajax.php file
$columns = [
get_lang('Name'),
get_lang('Actions'),
];
// Column config
$column_model = [
['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
[
'name' => 'actions',
'index' => 'actions',
'width' => '20',
'align' => 'center',
'sortable' => 'false',
'formatter' => 'action_formatter',
],
];
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') {
$columns = [
get_lang('Name'),
get_lang('Calendar'),
get_lang('Actions'),
];
// Column config
$column_model = [
['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
[
'name' => 'calendar',
'index' => 'calendar',
'width' => '35',
'align' => 'left',
'sortable' => 'false',
'formatter' => 'extra_formatter',
],
[
'name' => 'actions',
'index' => 'actions',
'width' => '20',
'align' => 'center',
'sortable' => 'false',
'formatter' => 'action_formatter',
],
];
}
// 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);
//$addCalendar = '<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('agenda.png', get_lang('Agenda'), '', ICON_SIZE_SMALL).'</a>';
//return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
// With this function we can add actions to the jgrid
$action_links = '
function action_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>\';
}
function extra_formatter(cellvalue, options, rowObject) {
var calendarName = rowObject[1];
var calendarId = rowObject[3];
if (calendarName == "") {
return \'<a href="'.
api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?user_id=\'+options.rowId+\'&id='.$id.'&action=add_calendar&width=700" class="btn btn-primary ajax">'.get_lang('Add').'</a>\';
} else {
return \' \'+calendarName+\' <a href="'.
api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?calendar_id=\'+calendarId+\'&user_id=\'+options.rowId+\'&id='.$id.'&action=edit_calendar&width=700" class="btn btn-primary ajax"> '.get_lang('Edit').'</a>\';
}
return calendarName;
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;
?>
<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
$usergroup->showGroupTypeSetting = true;
// Action handling: Adding a note
if ($action === 'delete' && is_numeric($_GET['id'])) {
$res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']);
Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation'));
header('Location: '.api_get_self().'?id='.$id);
exit;
} else {
$usergroup->displayToolBarUserGroupUsers();
}
Display::display_footer();

@ -8,13 +8,14 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
api_protect_limit_for_session_admin();
//Add the JS needed to use the jqgrid
$usergroup = new UserGroup();
$usergroup->protectScript();
// 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']) ? Security::remove_XSS($_GET['action']) : null;
if ($action == 'add') {
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
@ -60,7 +61,14 @@ $column_model = [
['name' => 'courses', 'index' => 'courses', 'width' => '15', 'align' => 'left'],
['name' => 'sessions', 'index' => 'sessions', 'width' => '15', 'align' => 'left'],
['name' => 'group_type', 'index' => 'group_type', 'width' => '15', 'align' => 'center'],
['name' => 'actions', 'index' => 'actions', 'width' => '20', 'align' => 'center', 'sortable' => 'false', 'formatter' => 'action_formatter'],
[
'name' => 'actions',
'index' => 'actions',
'width' => '20',
'align' => 'center',
'sortable' => 'false',
'formatter' => 'action_formatter',
],
];
//Autowidth
@ -99,7 +107,6 @@ $(function() {
</script>
<?php
$usergroup = new UserGroup();
$usergroup->showGroupTypeSetting = true;
// Action handling: Adding a note
if ($action == 'add') {
@ -135,7 +142,7 @@ if ($action == 'add') {
} else {
echo '<div class="actions">';
echo '<a href="'.api_get_self().'">'.
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
@ -193,4 +200,4 @@ if ($action == 'add') {
} else {
$usergroup->display();
}
Display :: display_footer();
Display::display_footer();

@ -60,6 +60,8 @@ if (!in_array(
'get_sessions',
'get_course_announcements',
'course_log_events',
'get_learning_path_calendars',
'get_usergroups_users',
]
) && !isset($_REQUEST['from_course_session'])) {
api_protect_admin_script(true);
@ -228,6 +230,14 @@ if (!$sidx) {
//@todo rework this
switch ($action) {
case 'get_usergroups_users':
$usergroup = new UserGroup();
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$count = $usergroup->getUserGroupUsers($id, true);
break;
case 'get_learning_path_calendars':
$count = LpCalendarPlugin::getCalendarCount();
break;
case 'course_log_events':
$courseId = api_get_course_int_id();
if (empty($courseId)) {
@ -737,10 +747,9 @@ switch ($action) {
case 'get_usergroups_teacher':
$obj = new UserGroup();
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
$groupFilter = isset($_REQUEST['group_filter']) ? intval($_REQUEST['group_filter']) : 0;
$groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0;
$course_id = api_get_course_int_id();
if ($type == 'registered') {
if ($type === 'registered') {
$count = $obj->getUserGroupByCourseWithDataCount(
$course_id,
$groupFilter
@ -780,6 +789,23 @@ $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit
$columns = [];
switch ($action) {
case 'get_usergroups_users':
$usergroup->protectScript();
$columns = ['name', 'actions'];
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') {
$columns = ['name', 'calendar', 'actions', 'calendar_id'];
}
$result = $usergroup->getUserGroupUsers($id);
break;
case 'get_learning_path_calendars':
$columns = ['title', 'total_hours', 'minutes_per_day', 'actions'];
$result = LpCalendarPlugin::getCalendars(
$start,
$limit,
$sidx,
$sord
);
break;
case 'course_log_events':
$columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
@ -791,7 +817,6 @@ switch ($action) {
$courseId,
$sessionId
);
break;
case 'get_programmed_announcements':
$columns = ['subject', 'date', 'sent', 'actions'];
@ -1910,6 +1935,7 @@ switch ($action) {
$result = $new_result;
break;
case 'get_usergroups':
$obj->protectScript();
$columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions'];
$result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
break;
@ -2082,8 +2108,12 @@ switch ($action) {
$new_result = [];
if (!empty($result)) {
$url = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq();
foreach ($result as $group) {
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
$group['users'] = Display::url(
count($obj->get_users_by_usergroup($group['id'])),
$url.'&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'));
@ -2155,6 +2185,8 @@ $allowed_actions = [
'get_course_announcements',
'get_programmed_announcements',
'course_log_events',
'get_learning_path_calendars',
'get_usergroups_users',
];
//5. Creating an obj to return a json

@ -0,0 +1,24 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls.
*/
require_once __DIR__.'/../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : '';
$isAllowedToEdit = api_is_allowed_to_edit();
switch ($action) {
case 'delete_user_in_usergroup':
if ($isAllowedToEdit) {
$userGroup = new UserGroup();
$userId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$groupId = isset($_REQUEST['group_id']) ? $_REQUEST['group_id'] : 0;
$userGroup->delete_user_rel_group($userId, $groupId);
}
break;
default:
echo '';
break;
}
exit;

@ -1414,6 +1414,7 @@ class Display
$json_encode = str_replace('"wrap_cell":true', 'cellattr : function(rowId, value, rowObject, colModel, arrData) { return \'class = "jqgrid_whitespace"\'; }', $json_encode);
$json_encode = str_replace(':"false"', ':false', $json_encode);
$json_encode = str_replace('"formatter":"action_formatter"', 'formatter:action_formatter', $json_encode);
$json_encode = str_replace('"formatter":"extra_formatter"', 'formatter:extra_formatter', $json_encode);
$json_encode = str_replace(['{"first":"first",', '"end":"end"}'], '', $json_encode);
// Creating the jqgrid element.

@ -63,6 +63,70 @@ class UserGroup extends Model
return $row['count'];
}
/**
* @param int $id
* @param bool $getCount
*
* @return array|int
*/
public function getUserGroupUsers($id, $getCount = false)
{
$id = (int) $id;
if ($getCount) {
$select = 'COUNT(u.id) count ';
} else {
$select = ' u.* ';
}
if ($this->useMultipleUrl) {
$urlId = api_get_current_access_url_id();
$sql = "SELECT $select
FROM ".$this->usergroup_rel_user_table." u
INNER JOIN ".$this->access_url_rel_usergroup." a
ON (u.user_id = a.user_id)
WHERE usergroup_id = $id AND access_url_id = $urlId ";
} else {
$sql = "SELECT $select
FROM ".$this->usergroup_rel_user_table." u
WHERE usergroup_id = $id";
}
$result = Database::query($sql);
if ($getCount) {
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);
return $row['count'];
}
return 0;
} else {
$list = [];
$showCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
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);
$data['calendar_id'] = 0;
$data['calendar'] = '';
if (!empty($calendar)) {
$calendarInfo = LpCalendarPlugin::getCalendar($calendar['calendar_id']);
if ($calendarInfo) {
$data['calendar_id'] = $calendar['calendar_id'];
$data['calendar'] = $calendarInfo['title'];
}
}
}
$data['id'] = $data['user_id'];
$list[] = $data;
}
return $list;
}
}
/**
* @param int $type
*
@ -88,7 +152,7 @@ class UserGroup extends Model
} else {
$typeCondition = '';
if ($type != -1) {
$type = intval($type);
$type = (int) $type;
$typeCondition = " WHERE group_type = $type ";
}
@ -114,7 +178,7 @@ class UserGroup extends Model
public function getUserGroupByCourseWithDataCount($course_id, $type = -1)
{
if ($this->useMultipleUrl) {
$course_id = intval($course_id);
$course_id = (int) $course_id;
$urlId = api_get_current_access_url_id();
$sql = "SELECT count(c.usergroup_id) as count
FROM {$this->usergroup_rel_course_table} c
@ -133,7 +197,7 @@ class UserGroup extends Model
} else {
$typeCondition = '';
if ($type != -1) {
$type = intval($type);
$type = (int) $type;
$typeCondition = " AND group_type = $type ";
}
$sql = "SELECT count(c.usergroup_id) as count
@ -197,6 +261,20 @@ class UserGroup extends Model
echo Display::grid_html('usergroups');
}
/**
* Displays the title + grid.
*/
public function displayToolBarUserGroupUsers()
{
// action links
echo '<div class="actions">';
echo '<a href="../admin/usergroups.php">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', '32').
'</a>';
echo '</div>';
echo Display::grid_html('usergroups');
}
/**
* Get HTML grid.
*/
@ -300,7 +378,7 @@ class UserGroup extends Model
$typeCondition = '';
if ($type != -1) {
$type = intval($type);
$type = (int) $type;
$typeCondition = " AND group_type = $type ";
}
@ -341,7 +419,7 @@ class UserGroup extends Model
{
$course_id = null;
if (isset($options['course_id'])) {
$course_id = intval($options['course_id']);
$course_id = (int) $options['course_id'];
unset($options['course_id']);
}
@ -351,7 +429,7 @@ class UserGroup extends Model
$typeCondition = '';
if ($type != -1) {
$type = intval($type);
$type = (int) $type;
$typeCondition = " AND group_type = $type ";
}
@ -943,8 +1021,8 @@ class UserGroup extends Model
{
$sord = in_array(strtolower($sord), ['asc', 'desc']) ? $sord : 'desc';
$start = intval($start);
$limit = intval($limit);
$start = (int) $start;
$limit = (int) $limit;
if ($this->useMultipleUrl) {
$urlId = api_get_current_access_url_id();
$from = $this->table." u INNER JOIN {$this->access_url_rel_usergroup} a ON (u.id = a.usergroup_id)";
@ -985,7 +1063,10 @@ class UserGroup extends Model
];
break;
}
$group['users'] = count($this->get_users_by_usergroup($group['id'], $roles));
$group['users'] = Display::url(
count($this->get_users_by_usergroup($group['id'], $roles)),
api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?id='.$group['id']
);
$new_result[] = $group;
}
$result = $new_result;
@ -1616,7 +1697,7 @@ class UserGroup extends Model
return $anonymous ? ['dir' => $base.'img/', 'file' => 'unknown.jpg'] : ['dir' => '', 'file' => ''];
}
$id = intval($id);
$id = (int) $id;
$group_table = Database::get_main_table(TABLE_USERGROUP);
$sql = "SELECT picture FROM $group_table WHERE id = ".$id;
$res = Database::query($sql);
@ -1668,7 +1749,7 @@ class UserGroup extends Model
*/
public function setGroupType($type)
{
$this->groupType = intval($type);
$this->groupType = (int) $type;
}
/**
@ -1845,18 +1926,25 @@ class UserGroup extends Model
*
* @author Julio Montoya
*
* @param int $user_id
* @param int $group_id
* @param int $userId
* @param int $groupId
*
* @return bool true if success
* */
public function delete_user_rel_group($user_id, $group_id)
public function delete_user_rel_group($userId, $groupId)
{
$userId = (int) $userId;
$groupId = (int) $groupId;
if (empty($userId) || empty($groupId)) {
return false;
}
$table = $this->usergroup_rel_user_table;
$sql = "DELETE FROM $table
WHERE
user_id = ".intval($user_id)." AND
usergroup_id = ".intval($group_id)." ";
user_id = $userId AND
usergroup_id = $groupId";
$result = Database::query($sql);
return $result;
@ -2610,4 +2698,13 @@ class UserGroup extends Model
{
return $groupInfo['allow_members_leave_group'] == 1 ? true : false;
}
/**
* Check permissions and blocks the page
*/
public function protectScript()
{
api_protect_admin_script(true);
api_protect_limit_for_session_admin();
}
}

@ -6322,6 +6322,15 @@ class learnpath
$prerequisities_icon = '';
$forumIcon = '';
$previewIcon = '';
$pluginCalendarIcon = '';
$pluginCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
$plugin = null;
if ($pluginCalendar) {
$plugin = LpCalendarPlugin::create();
}
$pluginUrl = api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php?';
if ($is_allowed_to_edit) {
if (!$update_audio || $update_audio != 'true') {
@ -6387,7 +6396,7 @@ class learnpath
ICON_SIZE_TINY
),
$forumIconUrl,
['class' => "btn btn-default lp-btn-associate-forum"]
['class' => 'btn btn-default lp-btn-associate-forum']
);
}
}
@ -6414,6 +6423,22 @@ class learnpath
}
}
if ($pluginCalendar) {
$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);
$itemInfo = $plugin->getItemVisibility($arrLP[$i]['id']);
if ($itemInfo && $itemInfo['value'] == 1) {
$iconCalendar = Display::return_icon('agenda.png', get_lang('Edit'), [], ICON_SIZE_TINY);
}
$pluginCalendarIcon = Display::url(
$iconCalendar,
$pluginLink,
['class' => 'btn btn-default']
);
}
$delete_icon .= ' <a
href="'.$mainUrl.'&action=delete_item&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id.'"
onclick="return confirmation(\''.addslashes($title).'\');"
@ -6532,6 +6557,7 @@ class learnpath
$previewIcon
$audio
$edit_icon
$pluginCalendarIcon
$forumIcon
$prerequisities_icon
$move_item_icon
@ -6640,7 +6666,7 @@ class learnpath
$result = $this->processBuildMenuElements($update_audio);
$list = '<ul id="lp_item_list">';
$tree = self::print_recursive(
$tree = $this->print_recursive(
$result['elements'],
$result['default_data'],
$result['default_content']
@ -6664,7 +6690,7 @@ class learnpath
'scorm-list-collapse'
);
if ($update_audio == 'true') {
if ($update_audio === 'true') {
$return = $result['return_audio'];
}
@ -10983,7 +11009,7 @@ class learnpath
$children = $organization->childNodes;
$possible_parent = $this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
if ($possible_parent) {
if ($possible_parent->getAttribute('identifier') == 'ITEM_'.$item->parent) {
if ($possible_parent->getAttribute('identifier') === 'ITEM_'.$item->parent) {
$possible_parent->appendChild($my_item);
}
}

@ -1,8 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* Homepage for the MySpace directory.
*
@ -100,6 +98,14 @@ if ($is_platform_admin) {
Display::return_icon('statistics.png', get_lang('CurrentCoursesReport'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php'
);
$pluginCalendar = api_get_plugin_setting('lp_calendar', 'enabled') === 'true';
if ($pluginCalendar) {
$menu_items[] = Display::url(
Display::return_icon('agenda.png', get_lang('LearningCalendar'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php'
);
}
}
}

@ -0,0 +1,393 @@
<?php
/* For license terms, see /license.txt */
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\DBALException;
use Symfony\Component\Filesystem\Filesystem;
/**
* Class LpCalendarPlugin
*/
class LpCalendarPlugin extends Plugin
{
const EVENT_TYPE_TAKEN = 1;
const EVENT_TYPE_EXAM = 2;
/**
* Class constructor
*/
protected function __construct()
{
$version = '0.1';
$author = 'Julio Montoya';
parent::__construct($version, $author, ['enabled' => 'boolean']);
}
public static function getEventTypeList()
{
return [
//self::EVENT_TYPE_FREE => 'green',
self::EVENT_TYPE_TAKEN => 'red',
self::EVENT_TYPE_EXAM => 'yellow'
];
}
/**
* Get the class instance
*
* @return $this
*/
public static function create()
{
static $result = null;
return $result ?: $result = new self();
}
/**
* Get the plugin directory name
*/
public function get_name()
{
return 'lp_calendar';
}
/**
* Install the plugin. Setup the database
*/
public function install()
{
$sql = "
CREATE TABLE IF NOT EXISTS learning_calendar(
id int not null AUTO_INCREMENT primary key,
title varchar(255) not null default '',
description longtext default null,
total_hours int not null default 0,
minutes_per_day int not null default 0,
disabled int default 0
)
";
Database::query($sql);
$sql = "
CREATE TABLE IF NOT EXISTS learning_calendar_events(
id int not null AUTO_INCREMENT primary key,
name varchar(255) default '',
calendar_id int not null,
start_date date not null,
end_date date not null,
type int not null
)
";
Database::query($sql);
$sql = "
CREATE TABLE IF NOT EXISTS learning_calendar_user(
id int not null AUTO_INCREMENT primary key,
user_id int(11) not null,
calendar_id int not null
)
";
Database::query($sql);
$extraField = new ExtraField('lp_item');
$params = [
'variable' => 'calendar',
'visible_to_self' => 1,
'changeable' => 1,
'visible_to_others' => 1,
'field_type' => ExtraField::FIELD_TYPE_CHECKBOX
];
$extraField->save($params);
$extraField = new ExtraField('course');
$params = [
'variable' => 'course_hours_duration',
'visible_to_self' => 1,
'changeable' => 1,
'visible_to_others' => 1,
'field_type' => ExtraField::FIELD_TYPE_TEXT
];
$extraField->save($params);
return true;
}
/**
* uninstall plugin. Clear the database
*/
public function uninstall()
{
$tables = [
'learning_calendar',
'learning_calendar_events',
'learning_calendar_user',
];
foreach ($tables as $table) {
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
}
$extraField = new ExtraField('lp_item');
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('calendar');
if ($fieldInfo) {
$extraField->delete($fieldInfo['id']);
}
$extraField = new ExtraField('course');
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('course_hours_duration');
if ($fieldInfo) {
$extraField->delete($fieldInfo['id']);
}
return true;
}
/**
* @param int $from
* @param int $numberOfItems
* @param int $column
* @param string $direction
*
* @return array|\Doctrine\DBAL\Driver\Statement
*/
public static function getCalendars(
$from,
$numberOfItems,
$column,
$direction = 'DESC'
) {
$column = (int) $column;
$from = (int) $from;
$numberOfItems = (int) $numberOfItems;
$direction = strtoupper($direction);
if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'DESC';
}
$sql = 'select * FROM learning_calendar';
$sql .= " LIMIT $from, $numberOfItems ";
$result = Database::query($sql);
$list = [];
$link = api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php';
while ($row = Database::fetch_array($result)) {
$id = $row['id'];
$row['title'] = Display::url(
$row['title'],
api_get_path(WEB_PLUGIN_PATH).'lp_calendar/calendar.php?id='.$id
);
$actions = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
$link.'?action=edit&id='.$id
);
$actions .= Display::url(
Display::return_icon('copy.png', get_lang('Copy')),
$link.'?action=copy&id='.$id
);
$actions .= Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
$link.'?action=delete&id='.$id
);
$row['actions'] = $actions;
$list[] = $row;
}
return $list;
}
/**
* @return int
*/
public static function getCalendarCount()
{
$sql = 'select count(*) as count FROM learning_calendar';
$result = Database::query($sql);
$result = Database::fetch_array($result);
return (int) $result['count'];
}
/**
* @param int $id
*/
public function toggleVisibility($id)
{
$extraField = new ExtraField('lp_item');
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('calendar');
if ($fieldInfo) {
$itemInfo = $this->getItemVisibility($id);
if (empty($itemInfo)) {
$extraField = new ExtraFieldValue('lp_item');
$value = 1;
$params = [
'field_id' => $fieldInfo['id'],
'value' => $value,
'item_id' => $id,
];
$extraField->save($params);
} else {
$newValue = (int) $itemInfo['value'] === 1 ? 0 : 1;
$extraField = new ExtraFieldValue('lp_item');
$params = [
'id' => $itemInfo['id'],
'value' => $newValue
];
$extraField->update($params);
}
}
}
/**
* @param int $id
*
* @return array
*/
public function getItemVisibility($id)
{
$extraField = new ExtraFieldValue('lp_item');
$values = $extraField->get_values_by_handler_and_field_variable($id, 'calendar');
return $values;
}
/**
* @param int $calendarId
*
* @return array|mixed
*/
public static function getCalendar($calendarId)
{
$calendarId = (int) $calendarId;
$sql = "SELECT * FROM learning_calendar WHERE id = $calendarId";
$result = Database::query($sql);
$item = Database::fetch_array($result, 'ASSOC');
return $item;
}
/**
* @param int $userId
*
* @return array|mixed
*/
public static function getUserCalendar($userId)
{
$userId = (int) $userId;
$sql = "SELECT * FROM learning_calendar_user WHERE user_id = $userId";
$result = Database::query($sql);
$item = Database::fetch_array($result, 'ASSOC');
return $item;
}
/**
* @param int $userId
*
* @return mixed|string
*/
public static function getUserCalendarToString($userId)
{
$calendar = self::getUserCalendar($userId);
if ($calendar) {
$calendarInfo = self::getCalendar($calendar['calendar_id']);
return $calendarInfo['title'];
}
return '';
}
/**
* @param int $calendarId
* @param int $userId
*
* @return bool
*/
public static function addUserToCalendar($calendarId, $userId)
{
$calendar = self::getUserCalendar($userId);
if (empty($calendar)) {
$params = [
'calendar_id' => $calendarId,
'user_id' => $userId,
];
Database::insert('learning_calendar_user', $params);
}
return true;
}
/**
* @param int $calendarId
* @param int $userId
*
* @return bool
*/
public static function updateUserToCalendar($calendarId, $userId)
{
$calendar = self::getUserCalendar($userId);
if (!empty($calendar)) {
$params = [
'calendar_id' => $calendarId,
'user_id' => $userId,
];
Database::update('learning_calendar_user', $params, ['id = ?' => $calendar['id']]);
}
return true;
}
/**
* @param int $calendarId
* @param int $userId
*
* @return bool
*/
public static function deleteAllCalendarFromUser($calendarId, $userId)
{
$calendarId = (int) $calendarId;
$userId = (int) $userId;
$sql = "DELETE FROM learning_calendar_user
WHERE user_id = $userId AND calendar_id = $calendarId";
Database::query($sql);
return true;
}
/*public static function getUserCalendar($calendarId, $userId)
{
$params = [
'calendar_id' => $calendarId,
'user_id' => $calendarId,
];
Database::insert('learning_calendar_user', $params);
return true;
}*/
/**
* @param FormValidator $form
*/
public function getForm(FormValidator &$form)
{
$form->addText('title', get_lang('Title'));
$form->addText('total_hours', get_lang('TotalHours'));
$form->addText('minutes_per_day', get_lang('MinutesPerDay'));
$form->addHtmlEditor('description', get_lang('Description'), false);
}
}

@ -0,0 +1,2 @@
## Learning path calendar

@ -0,0 +1,69 @@
<?php
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();
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]]
);
}
} else {
$params = [
'name' => '',
'calendar_id' => $calendarId,
'start_date' => $startDate,
'end_date' => $startDate,
'type' => LpCalendarPlugin::EVENT_TYPE_TAKEN
];
Database::insert('learning_calendar_events', $params);
}
break;
case 'get_events':
$sql = "SELECT * FROM learning_calendar_events";
$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']]
];
}
echo json_encode($list);
break;
}

@ -0,0 +1,64 @@
<?php
/* For license terms, see /license.txt */
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);
if (empty($item)) {
api_not_allowed(true);
}
$isoCode = api_get_language_isocode();
$htmlHeadXtra[] = api_get_asset('bootstrap-year-calendar/js/bootstrap-year-calendar.js');
$calendarLanguage = 'en';
if ($isoCode !== 'en') {
$file = 'bootstrap-year-calendar/js/languages/bootstrap-year-calendar.'.$isoCode.'.js';
$path = api_get_path(SYS_PUBLIC_PATH).'assets/'.$file;
if (file_exists($path)) {
$htmlHeadXtra[] = api_get_asset($file);
$calendarLanguage = $isoCode;
}
}
$htmlHeadXtra[] = api_get_css_asset('bootstrap-year-calendar/css/bootstrap-year-calendar.css');
$plugin = LpCalendarPlugin::create();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$formToString = '';
switch ($action) {
}
$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]);
$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);
$template->assign('content', $content);
$template->display_one_col_template();

@ -0,0 +1,8 @@
<?php
/* For license terms, see /license.txt */
if (!api_is_platform_admin()) {
die('You must have admin permissions to install plugins');
}
LpCalendarPlugin::create()->install();

@ -0,0 +1,6 @@
<?php
/* For license terms, see /license.txt */
$strings['plugin_title'] = 'Learning path calendar';
$strings['plugin_comment'] = '';
$strings['enabled'] = 'Enabled';

@ -0,0 +1,6 @@
<?php
/* For license terms, see /license.txt */
$strings['plugin_title'] = 'Learning path calendar';
$strings['plugin_comment'] = '';
$strings['enabled'] = 'Enabled';

@ -0,0 +1,6 @@
<?php
/* For license terms, see /license.txt */
$strings['plugin_title'] = 'Learning path calendar';
$strings['plugin_comment'] = '';
$strings['enabled'] = 'Activado';

@ -0,0 +1,4 @@
<?php
/* For license terms, see /license.txt */
$plugin_info = LpCalendarPlugin::create()->get_info();

@ -0,0 +1,222 @@
<?php
/* For license terms, see /license.txt */
require_once __DIR__.'/../../main/inc/global.inc.php';
$allow = api_is_allowed_to_edit();
if (!$allow) {
api_not_allowed(true);
}
$plugin = LpCalendarPlugin::create();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$calendarId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$formToString = '';
switch ($action) {
case 'add':
$form = new FormValidator('calendar', 'post', api_get_self().'?action=add');
$plugin->getForm($form);
$form->addButtonSave(get_lang('Save'));
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'title' => $values['title'],
'total_hours' => $values['total_hours'],
'minutes_per_day' => $values['minutes_per_day'],
'description' => $values['description'],
];
Database::insert('learning_calendar', $params);
Display::addFlash(Display::return_message(get_lang('Saved')));
header('Location: start.php');
exit;
}
break;
case 'edit':
$form = new FormValidator('calendar', 'post', api_get_self().'?action=edit&id='.$calendarId);
$plugin->getForm($form);
$form->addButtonSave(get_lang('Update'));
$item = LpCalendarPlugin::getCalendar($calendarId);
if (empty($item)) {
api_not_allowed(true);
}
$form->setDefaults($item);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'title' => $values['title'],
'total_hours' => $values['total_hours'],
'minutes_per_day' => $values['minutes_per_day'],
'description' => $values['description'],
];
Database::update('learning_calendar', $params, ['id = ?' => $calendarId]);
Display::addFlash(Display::return_message(get_lang('Updated')));
header('Location: start.php');
exit;
}
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 ($newCalendarId) {
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);
}
$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'] : '';
$lpId = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : '';
$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();
header("Location: $url");
exit;
break;
}
$htmlHeadXtra[] = api_get_jqgrid_js();
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_learning_path_calendars';
$columns = [
get_lang('Title'),
get_lang('TotalHours'),
get_lang('MinutesPerDay'),
get_lang('Actions'),
];
$columnModel = [
[
'name' => 'title',
'index' => 'title',
'width' => '300',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'total_hours',
'index' => 'total_hours',
'width' => '100',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'minutes_per_day',
'index' => 'minutes_per_day',
'width' => '100',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'actions',
'index' => 'actions',
'width' => '150',
'align' => 'left',
//'formatter' => 'action_formatter',
'sortable' => 'false',
],
];
$extraParams = [];
$extraParams['autowidth'] = 'true';
// height auto
$extraParams['height'] = 'auto';
$template = new Template();
if (in_array($action, ['add', 'edit'])) {
$actionLeft = Display::url(
Display::return_icon(
'back.png',
get_lang('Back'),
null,
ICON_SIZE_MEDIUM
),
api_get_self().'?'.api_get_cidreq()
);
} else {
$actionLeft = Display::url(
Display::return_icon(
'add.png',
get_lang('Add'),
null,
ICON_SIZE_MEDIUM
),
api_get_self().'?'.api_get_cidreq().'&action=add'
);
$content = '<script>
$(function() {'.
Display::grid_js(
'calendars',
$url,
$columns,
$columnModel,
$extraParams,
[],
'',
true
).'
});
</script>';
$content .= Display::grid_html('calendars');
$template->assign('grid', $content);
}
$template->assign('form', $formToString);
$actions = Display::toolbarAction('toolbar-calendar', [$actionLeft]);
$content = $template->fetch('lp_calendar/view/start.tpl');
$template->assign('content', $content);
$template->assign('actions', $actions);
$template->display_one_col_template();

@ -0,0 +1,4 @@
<?php
/* For license terms, see /license.txt */
LpCalendarPlugin::create()->uninstall();

@ -0,0 +1,65 @@
<script>
function getEvents(e) {
var myData = [];
$.ajax({
dataType: "json",
url: "{{ ajax_url }}&a=get_events",
success: function(response) {
for (var i = 0; i < response.length; i++) {
myData.push({
id: response[i].id,
title: response[i].title,
startDate: new Date(response[i].start_date),
endDate: new Date(response[i].end_date),
color: response[i].color
});
}
$(e.target).data('calendar').setDataSource(myData);
}
});
}
$(document).ready(function() {
$('#calendar').calendar({
style:'background',
language : '{{ calendar_language }}',
enableRangeSelection: false,
enableContextMenu: true,
/*contextMenuItems:[
{
text: 'Update',
//click: editEvent
},
{
text: 'Delete',
click: deleteEvent
}
],*/
customDayRenderer: function(e) {
$(e).parent().css('background-color', 'green');
},
clickDay: function(e) {
var dateString = moment(e.date).format("YYYY-MM-DD");
$.ajax({
type: "GET",
url: "{{ ajax_url }}&a=toggle_day&date="+dateString,
success: function(returnValue) {
getEvents(e);
}
});
},
yearChanged: function(e) {
e.preventRendering = true;
$(e.target).append('<div style="text-align:center"><i class="fa fa-spinner fa-spin fa-2x"></i></div>');
getEvents(e);
},
});
});
</script>
<style>
#calendar {
overflow: visible;
}
</style>
<div id=calendar></div>

@ -0,0 +1,3 @@
{{ form }}
{{ grid }}
Loading…
Cancel
Save