Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group: fix new group category creation #6055

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions public/main/group/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,13 @@

/* List all categories */
if ('true' === api_get_setting('allow_group_categories')) {
$defaultCategory = [
'iid' => null,
'description' => '',
'title' => get_lang('Default groups'),
];
$categories = array_merge([$defaultCategory], $categories);
if (empty($categories)) {
$defaultCategoryId = GroupManager::create_category(
get_lang('Default groups')
);
$defaultCategory = GroupManager::get_category($defaultCategoryId);
$categories = [$defaultCategory];
}
$course = api_get_course_entity();
foreach ($categories as $index => $category) {
$categoryId = $category['iid'];
Expand All @@ -264,13 +265,15 @@
// Edit
$actions .= '<a
href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
Display::getMdiIcon('edit', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit this category')).'</a>';
Display::getMdiIcon('pencil', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit this category')).'</a>';

// Delete
$actions .= Display::url(
Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')),
Display::getMdiIcon(ActionIcon::DELETE, count($categories) == 1 ? 'ch-tool-icon-disabled' : 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')),
'group.php?'.api_get_cidreq().'&action=delete_category&category_id='.$categoryId,
[
count($categories) == 1 ? [
'onclick' => 'javascript:alert('."'".addslashes(api_htmlentities(get_lang('You cannot delete the last category'), ENT_QUOTES))."'".'); return false;',
] : [
'onclick' => 'javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."'".')) return false;',
]
);
Expand Down
8 changes: 6 additions & 2 deletions public/main/group/group_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ function check_groups_per_user($value)
} else {
// Create a new category
$action = 'add_category';
$form = new FormValidator('group_category');
$form = new FormValidator(
'group_category',
'post',
api_get_self().'?'.api_get_cidreq()
);
}

$form->addElement('header', $nameTools);
Expand Down Expand Up @@ -436,7 +440,7 @@ function check_groups_per_user($value)
// Else display the form
Display::display_header($nameTools, 'Group');

$actions = '<a href="group.php">'.
$actions = '<a href="group.php?'.api_get_cidreq().'">'.
Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back to Groups list')).'</a>';
echo Display::toolbarAction('toolbar', [$actions]);

Expand Down
14 changes: 7 additions & 7 deletions public/main/inc/lib/groupmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,13 +889,13 @@ public static function delete_category($cat_id, $course_code = '')
*/
public static function create_category(
$title,
$description,
$docState,
$workState,
$calendarState,
$anonuncementState,
$forumState,
$wikiState,
$description = '',
$docState = 1,
$workState = 1,
$calendarState = 1,
$anonuncementState = 1,
$forumState = 1,
$wikiState = 1,
$chatState = 1,
$selfRegistrationAllowed = 0,
$selfUnRegistrationAllowed = 0,
Expand Down