get($id); if (empty($userGroupInfo)) { api_not_allowed(true); } $usergroup->protectScript($userGroupInfo, true, true); $allowEdit = api_is_platform_admin() || isset($userGroupInfo['author_id']) && $userGroupInfo['author_id'] == api_get_user_id(); $calendarPlugin = null; if ($allowEdit && api_get_plugin_setting('learning_calendar', 'enabled') === 'true') { $calendarPlugin = LearningCalendarPlugin::create(); } // Add the JS needed to use the jqgrid $htmlHeadXtra[] = api_get_jqgrid_js(); $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; $userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0; $calendarId = isset($_REQUEST['calendar_id']) ? (int) $_REQUEST['calendar_id'] : 0; $courseInfo = api_get_course_info(); if (empty($courseInfo)) { $interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')]; } else { $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'user/class.php?'.api_get_cidreq(), 'name' => get_lang('Classes')]; } $interbreadcrumb[] = ['url' => '#', 'name' => $userGroupInfo['name']]; if (!empty($action)) { $usergroup->protectScript($userGroupInfo); } switch ($action) { case 'add_calendar': $form = new FormValidator( 'add_calendar', 'post', api_get_self().'?id='.$id.'&user_id='.$userId.'&action=add_calendar' ); $userInfo = api_get_user_info($userId); $form->addHeader($userInfo['complete_name']); $calendarPlugin->getAddUserToCalendarForm($form); $form->addButtonSave(get_lang('Add')); $form->display(); if ($form->validate()) { $calendarId = $form->getSubmitValue('calendar_id'); if (!empty($calendarId)) { $calendarPlugin->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': $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']); $calendarPlugin->getAddUserToCalendarForm($form); $form->setDefaults(['calendar_id' => $calendarId]); $form->addButtonSave(get_lang('Update')); $form->display(); if ($form->validate()) { $calendarId = $form->getSubmitValue('calendar_id'); if (!empty($calendarId)) { $calendarPlugin->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']); Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation')); header('Location: '.api_get_self().'?id='.$id); exit; break; case 'create_control_point': $value = isset($_GET['value']) ? (int) $_GET['value'] : 0; $calendarPlugin->addControlPoint($userId, $value); Display::addFlash( Display::return_message($calendarPlugin->get_lang('Control point added'), 'confirmation') ); header('Location: '.api_get_self().'?id='.$id); exit; case 'add_multiple_users_to_calendar': $userList = isset($_REQUEST['user_list']) ? explode(',', $_REQUEST['user_list']) : 0; foreach ($userList as $userId) { $isAdded = $calendarPlugin->addUserToCalendar($calendarId, $userId); if (!$isAdded) { $isAdded = $calendarPlugin->updateUserToCalendar($calendarId, $userId); } } Display::addFlash( Display::return_message(get_lang('Added'), 'confirmation') ); header('Location: '.api_get_self().'?id='.$id); exit; break; } 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('Detail'), ]; // 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 ($calendarPlugin) { $columns = [ get_lang('Name'), get_lang('Calendar'), get_lang('Classroom activity'), get_lang('Time spent by students in courses'), $calendarPlugin->get_lang('Number of days accumulated in calendar'), $calendarPlugin->get_lang('Difference between days and calendar'), get_lang('Detail'), ]; // 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' => 'gradebook_items', 'index' => 'gradebook_items', 'width' => '35', 'align' => 'left', 'sortable' => 'false', ], ['name' => 'time_spent', 'index' => 'time_spent', 'width' => '35', 'align' => 'left', 'sortable' => 'false'], [ 'name' => 'lp_day_completed', 'index' => 'lp_day_completed', 'width' => '35', 'align' => 'left', 'sortable' => 'false', ], ['name' => 'days_diff', 'index' => 'days_diff', 'width' => '35', 'align' => 'left', 'sortable' => 'false'], [ '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'] = $allowEdit; $deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), null, ICON_SIZE_SMALL); $urlStats = api_get_path(WEB_CODE_PATH); $reportingIcon = Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_SMALL); $controlPoint = Display::return_icon('add.png', get_lang('Control point'), '', ICON_SIZE_SMALL); $link = ''; if ($calendarPlugin) { $link = ''.$controlPoint.''; } $deleteButton = ''; if ($allowEdit) { $deleteButton = ''.$deleteIcon.''; } //return \''.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).''. // With this function we can add actions to the jgrid $action_links = ' function action_formatter(cellvalue, options, rowObject) { var value = rowObject[5]; return \''. ' '.$link. ' '.$reportingIcon.''. ' '.$deleteButton.' \'; } function extra_formatter(cellvalue, options, rowObject) { var calendarName = rowObject[1]; var calendarId = rowObject[7]; if (calendarName == "") { return \''.get_lang('Add').'\'; } else { return \' \'+calendarName+\' '.get_lang('Edit').'\'; } return calendarName; return \''. ' '.Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_SMALL).''. ' '.$deleteIcon.'\'; }'; $deleteUrl = api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=delete_user_in_usergroup&group_id='.$id; if ($calendarPlugin) { $form = new FormValidator( 'add_multiple_calendar', 'post', api_get_self().'?id='.$id.'&action=add_multiple_users_to_calendar' ); $calendarPlugin->getAddUserToCalendarForm($form); $form->addHidden('user_list', ''); $form->addButtonSave(get_lang('Add')); } ?> showGroupTypeSetting = true; // Action handling: Adding a note if ($allowEdit && $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; } $usergroup->displayToolBarUserGroupUsers(); Display::display_footer();