Fixes bug when creating groups see #5551

skala
Julio Montoya 13 years ago
parent 2e2d633f61
commit 56c5f0f1bc
  1. 30
      main/document/document.inc.php
  2. 2
      main/document/document.php
  3. 30
      main/forum/forumfunction.inc.php
  4. 1
      main/gradebook/lib/fe/flatviewtable.class.php
  5. 2
      main/group/group.php
  6. 6
      main/group/group_creation.php
  7. 115
      main/group/group_space.php
  8. 58
      main/inc/lib/document.lib.php
  9. 11
      main/inc/lib/fileUpload.lib.php
  10. 110
      main/inc/lib/groupmanager.lib.php
  11. 9
      main/inc/lib/main_api.lib.php

@ -67,20 +67,22 @@ function build_directory_selector($folders, $document_id, $group_dir = '', $chan
}
}
}
} else {
foreach ($folders as $folder_id => & $folder) {
$selected = ($document_id == $folder_id) ? ' selected="selected"' : '';
$label = $folder_titles[$folder];
if ($folder == $group_dir) {
$label = get_lang('Documents');
} else {
$path_parts = explode('/', str_replace($group_dir, '', $folder));
$label = cut($label, 80);
$label = str_repeat('   ', count($path_parts) - 2).' — '.$label;
}
$parent_select -> addOption($label, $folder_id);
if ($selected != '') {
$parent_select->setSelected($folder_id);
} else {
if (!empty($folders)) {
foreach ($folders as $folder_id => & $folder) {
$selected = ($document_id == $folder_id) ? ' selected="selected"' : '';
$label = $folder_titles[$folder];
if ($folder == $group_dir) {
$label = get_lang('Documents');
} else {
$path_parts = explode('/', str_replace($group_dir, '', $folder));
$label = cut($label, 80);
$label = str_repeat('   ', count($path_parts) - 2).' — '.$label;
}
$parent_select -> addOption($label, $folder_id);
if ($selected != '') {
$parent_select->setSelected($folder_id);
}
}
}
}

@ -90,7 +90,7 @@ $dbl_click_id = 0; // Used for avoiding double-click
$selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null;
/* Constants and variables */
$session_id = api_get_session_id();
$session_id = api_get_session_id();
$course_code = api_get_course_id();
$to_group_id = api_get_group_id();

@ -507,23 +507,33 @@ function store_forumcategory($values) {
* @version february 2006, dokeos 1.8
*/
function store_forum($values) {
global $_course;
global $_user;
global $_course;
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
if (isset($values['group_id']) && !empty($values['group_id'])) {
$group_id = $values['group_id'];
} else {
$group_id = api_get_group_id();
}
$table_forums = Database::get_course_table(TABLE_FORUM);
// Find the max forum_order for the given category. The new forum is added at the end => max cat_order + &
if (is_null($values['forum_category'])) {
$new_max = null;
} else {
$sql = "SELECT MAX(forum_order) as sort_max FROM ".$table_forums."
WHERE c_id = $course_id AND forum_category='".Database::escape_string($values['forum_category'])."'";
$sql = "SELECT MAX(forum_order) as sort_max
FROM ".$table_forums."
WHERE c_id = $course_id AND
forum_category='".Database::escape_string($values['forum_category'])."'";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$new_max = $row['sort_max'] + 1;
}
$session_id = api_get_session_id();
$clean_title = Database::escape_string($values['forum_title']);
// Forum images
@ -595,8 +605,10 @@ function store_forum($values) {
forum_of_group='". Database::escape_string($values['group_forum'])."'
WHERE c_id = $course_id AND forum_id='".Database::escape_string($values['forum_id'])."'";
Database::query($sql);
api_item_property_update($_course, TOOL_FORUM, Database::escape_string($values['forum_id']), 'ForumUpdated', api_get_user_id());
api_item_property_update($_course, TOOL_FORUM, Database::escape_string($values['forum_id']), 'ForumUpdated', api_get_user_id(), $group_id);
$return_message = get_lang('ForumEdited');
} else {
$sql_image = '';
@ -626,8 +638,8 @@ function store_forum($values) {
Database::query($sql);
$last_id = Database::insert_id();
if ($last_id > 0) {
api_item_property_update($_course, TOOL_FORUM, $last_id, 'ForumAdded', api_get_user_id());
api_set_default_visibility($last_id, TOOL_FORUM);
api_item_property_update($_course, TOOL_FORUM, $last_id, 'ForumAdded', api_get_user_id(), $group_id);
api_set_default_visibility($last_id, TOOL_FORUM, $group_id);
}
$return_message = get_lang('ForumAdded');
}

@ -488,7 +488,6 @@ class FlatViewTable extends SortableTable
$column++;
}
//$this->set_header($column++, get_lang('Total'));
$data_array = $this->datagen->get_data($users_sorting, $from, $this->per_page, $this->offset, $selectlimit);
$table_data = array();

@ -250,7 +250,7 @@ foreach ($group_cats as $index => $category) {
GroupManager::user_has_access($_user['user_id'], $this_group['id'], GroupManager::GROUP_TOOL_WIKI))
&& !(api_is_course_coach() && intval($this_group['session_id']) != intval($_SESSION['id_session']))) {
$orig = isset($origin) ? $origin : null;
$group_name = '<a href="group_space.php?'.api_get_cidreq().'&amp;origin='.$orig.'&amp;gidReq='.$this_group['id'].'">'.stripslashes($this_group['name']).'</a>';
$group_name = '<a href="group_space.php?cidReq='.api_get_course_id().'&amp;origin='.$orig.'&amp;gidReq='.$this_group['id'].'">'.Security::remove_XSS($this_group['name']).'</a>';
if (!empty($_SESSION['_user']['user_id']) && !empty($this_group['id_tutor']) && $_SESSION['_user']['user_id'] == $this_group['id_tutor']) {
$group_name .= ' ('.get_lang('OneMyGroups').')';
} elseif ($this_group['is_member']) {

@ -17,8 +17,6 @@ $current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php';
/* Create the groups */
@ -288,6 +286,7 @@ EOT;
/*
* Show form to generate groups from classes subscribed to the course
*/
/*
$classes = ClassManager :: get_classes_in_course($_course['sysCode']);
if (count($classes) > 0) {
echo '<b>'.get_lang('GroupsFromClasses').'</b>';
@ -324,7 +323,8 @@ EOT;
$create_class_groups_form->setDefaults($defaults);
$create_class_groups_form->display();
echo '</blockquote>';
}
}*/
}
/* FOOTER */

@ -123,7 +123,7 @@ $is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course
$edit_url = '';
if (api_is_allowed_to_edit(false, true) or GroupManager :: is_tutor_of_group(api_get_user_id(), api_get_group_id())) {
$my_origin = isset($origin) ? $origin : '';
$edit_url = '<a href="group_edit.php?origin='.$my_origin.'&gidReq='.api_get_group_id().'">'.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
$edit_url = '<a href="group_edit.php?cidReq='. api_get_course_id().'&origin='.$my_origin.'&gidReq='.api_get_group_id().'">'.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
}
echo Display::page_header(Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group);
@ -136,9 +136,8 @@ if (!empty($current_group['description'])) {
* Group Tools
*/
// If the user is subscribed to the group or the user is a tutor of the group then
if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group(api_get_user_id(), $current_group['id'])) {
echo '<ul>';
$tools = '';
if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group(api_get_user_id(), $current_group['id'])) {
$actions_array = array();
// Link to the forum of this group
$forums_of_groups = get_forums_of_group($current_group['id']);
@ -146,93 +145,141 @@ if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group(api_
if ($current_group['forum_state'] != GroupManager::TOOL_NOT_AVAILABLE ) {
foreach ($forums_of_groups as $key => $value) {
if ($value['forum_group_public_private'] == 'public' || (/*!empty($user_subscribe_to_current_group) && */ $value['forum_group_public_private'] == 'private') || !empty($user_is_tutor) || api_is_allowed_to_edit(false, true)) {
$tools .= '<li style="display:inline; margin:5px;"><a href="../forum/viewforum.php?forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'&amp;origin=group">'.Display::return_icon('forum.png', get_lang('Forum').': '.$value['forum_title'] , array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../forum/viewforum.php?forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'&amp;origin=group',
'content' => Display::return_icon('forum.png', get_lang('Forum').': '.$value['forum_title'] , array(), 32)
);
}
}
}
}
if ($current_group['doc_state'] != GroupManager::TOOL_NOT_AVAILABLE ) {
// Link to the documents area of this group
$tools .= '<li style="display:inline; margin:5px;" ><a href="../document/document.php?'.api_get_cidreq().'&amp;gidReq='.$current_group['id'].'">'.Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32).'</a></li>';
// Link to the documents area of this group
$actions_array[] = array(
'url' => '../document/document.php?'.api_get_cidreq(),
'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32)
);
}
if ($current_group['calendar_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
// Link to a group-specific part of agenda
$tools .= '<li style="display:inline; margin:5px;"><a href="../calendar/agenda.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;group='.$current_group['id'].'&amp;acces=0">'.Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../calendar/agenda.php?'.api_get_cidreq(),
'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32)
);
}
if ($current_group['work_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
// Link to the works area of this group
$tools .= '<li style="display:inline; margin:5px;" ><a href="../work/work.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('work.png', get_lang('GroupWork'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../work/work.php?'.api_get_cidreq(),
'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), 32)
);
}
if ($current_group['announcements_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
// Link to a group-specific part of announcements
$tools .= '<li style="display:inline; margin:5px;"><a href="../announcements/announcements.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../announcements/announcements.php?'.api_get_cidreq(),
'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32)
);
}
if ($current_group['wiki_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
// Link to the wiki area of this group
$tools .= '<li style="display:inline; margin:5px;"><a href="../wiki/index.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'].'">'.Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../wiki/index.php?'.api_get_cidreq().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'],
'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
);
}
if ($current_group['chat_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
// Link to the chat area of this group
if (api_get_course_setting('allow_open_chat_window')) {
$tools .= "<li style=\"display:inline; margin:5px;\"><a href=\"javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \" >".Display::return_icon('chat.png', get_lang('Chat'),'',ICON_SIZE_MEDIUM)."</a></li>";
$actions_array[] = array(
'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"",
'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
);
} else {
$tools .= "<li style=\"display:inline; margin:5px;\"><a href=\"../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."\">".Display::return_icon('chat.png', get_lang('Chat'), array(), 32)."</a></li>";
$actions_array[] = array(
'url' => "../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id'],
'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
);
}
}
echo '</ul>';
echo Display::page_subheader(get_lang('Tools'));
if (!empty($tools)) {
echo $tools;
if (!empty($actions_array)) {
echo Display::page_subheader(get_lang('Tools'));
echo Display::actions($actions_array);
}
} else {
echo '<ul>';
$tools = '';
$actions_array = array();
// Link to the forum of this group
$forums_of_groups = get_forums_of_group($current_group['id']);
if (is_array($forums_of_groups)) {
if ( $current_group['forum_state'] == GroupManager::TOOL_PUBLIC ) {
foreach ($forums_of_groups as $key => $value) {
if ($value['forum_group_public_private'] == 'public' ) {
$tools.= '<li style="display:inline; margin:5px;"><a href="../forum/viewforum.php?forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'&amp;origin=group">'.Display::return_icon('forum.png', get_lang('GroupForum'), array(), 32).'</a></li>';
if ($value['forum_group_public_private'] == 'public' ) {
$actions_array[] = array(
'url' => '../forum/viewforum.php?cidReq='.api_get_course_id().'&forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'&amp;origin=group',
'content' => Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_MEDIUM)
);
}
}
}
}
if ($current_group['doc_state'] == GroupManager::TOOL_PUBLIC) {
// Link to the documents area of this group
$tools .= '<li style="display:inline; margin:5px;"><a href="../document/document.php?'.api_get_cidreq().'&amp;gidReq='.$current_group['id'].'&amp;origin='.$origin.'">'.Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../document/document.php?cidReq='.api_get_course_id().'&amp;origin='.$origin,
'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_MEDIUM)
);
}
if ($current_group['calendar_state'] == GroupManager::TOOL_PUBLIC) {
// Link to a group-specific part of agenda
$tools .= '<li style="display:inline; margin:5px;"><a href="../calendar/agenda.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;group='.$current_group['id'].'">'.Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../calendar/agenda.php?'.api_get_cidreq(),
'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_MEDIUM)
);
}
if ($current_group['work_state'] == GroupManager::TOOL_PUBLIC) {
// Link to the works area of this group
$tools .= '<li style="display:inline; margin:5px;"><a href="../work/work.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'">'.Display::return_icon('work.png', get_lang('GroupWork'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../work/work.php?'.api_get_cidreq(),
'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_MEDIUM)
);
}
if ($current_group['announcements_state'] == GroupManager::TOOL_PUBLIC) {
// Link to a group-specific part of announcements
$tools .= '<li style="display:inline; margin:5px;"><a href="../announcements/announcements.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;group='.$current_group['id'].'">'.Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../announcements/announcements.php?'.api_get_cidreq(),
'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_MEDIUM)
);
}
if ($current_group['wiki_state'] == GroupManager::TOOL_PUBLIC) {
// Link to the wiki area of this group
$tools .= '<li style="display:inline; margin:5px;"><a href="../wiki/index.php?'.api_get_cidreq().'&amp;toolgroup='.$current_group['id'].'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'].'">'.Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32).'</a></li>';
$actions_array[] = array(
'url' => '../wiki/index.php?'.api_get_cidreq().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'],
'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
);
}
if ($current_group['chat_state'] == GroupManager::TOOL_PUBLIC ) {
// Link to the chat area of this group
if (api_get_course_setting('allow_open_chat_window')) {
$tools .= "<li style=\"display:inline; margin:5px;\"><a href=\"javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \" >".Display::return_icon('chat.png', get_lang("Chat"), array(), 32)."</a></li>";
$actions_array[] = array(
'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"",
'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
);
} else {
$tools .= "<li style=\"display:inline; margin:5px;\"><a href=\"../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."\">".Display::return_icon('chat.png', get_lang("Chat"), array(), 32)."</a></li>";
$actions_array[] = array(
'url' => "../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id'],
'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
);
}
}
echo '</ul>';
echo Display::page_subheader(get_lang('Tools'));
if (!empty($tools)) {
echo $tools;
if (!empty($actions_array)) {
echo Display::page_subheader(get_lang('Tools'));
echo Display::actions($actions_array);
}
}

@ -457,8 +457,6 @@ class DocumentManager {
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
//if to_user_id = NULL -> change query (IS NULL)
//$to_user_id = (is_null($to_user_id)) ? 'IS NULL' : '= '.$to_user_id;
if (!is_null($to_user_id)) {
$to_field = 'last.to_user_id';
$to_value = $to_user_id;
@ -492,28 +490,28 @@ class DocumentManager {
}
//condition for search (get ALL folders and documents)
if ($search) {
$sql = "SELECT docs.id, docs.filetype, docs.path, docs.title, docs.comment, docs.size, docs.readonly, docs.session_id, last.id_session item_property_session_id, last.lastedit_date, last.visibility, last.insert_user_id
FROM ".$TABLE_ITEMPROPERTY." AS last, ".$TABLE_DOCUMENT." AS docs
WHERE docs.id = last.ref
AND last.tool = '".TOOL_DOCUMENT."'
AND ".$to_field." = ".$to_value."
AND last.visibility".$visibility_bit . $condition_session." AND
docs.c_id = {$_course['real_id']} AND
last.c_id = {$_course['real_id']} ";
} else {
$sql = "SELECT docs.id, docs.filetype, docs.path, docs.title, docs.comment, docs.size, docs.readonly, docs.session_id, last.id_session item_property_session_id, last.lastedit_date, last.visibility, last.insert_user_id
FROM ".$TABLE_ITEMPROPERTY." AS last, ".$TABLE_DOCUMENT." AS docs
WHERE docs.id = last.ref
AND docs.path LIKE '".$path.$added_slash."%'
AND docs.path NOT LIKE '".$path.$added_slash."%/%'
AND last.tool = '".TOOL_DOCUMENT."'
AND ".$to_field." = ".$to_value."
AND last.visibility".$visibility_bit.$condition_session." AND
docs.c_id = {$_course['real_id']} AND
last.c_id = {$_course['real_id']} ";
}
$sql = "SELECT docs.id,
docs.filetype,
docs.path,
docs.title,
docs.comment,
docs.size,
docs.readonly,
docs.session_id,
last.id_session item_property_session_id,
last.lastedit_date,
last.visibility,
last.insert_user_id
FROM ".$TABLE_ITEMPROPERTY." AS last INNER JOIN ".$TABLE_DOCUMENT." AS docs
ON (docs.id = last.ref AND docs.c_id = {$_course['real_id']} AND last.c_id = {$_course['real_id']})
WHERE
docs.path LIKE '".$path.$added_slash."%' AND
docs.path NOT LIKE '".$path.$added_slash."%/%' AND
last.tool = '".TOOL_DOCUMENT."' AND
".$to_field." = ".$to_value." AND
last.visibility".$visibility_bit.$condition_session;
$result = Database::query($sql);
$doc_list = array();
@ -522,7 +520,6 @@ class DocumentManager {
if ($result !== false && Database::num_rows($result) != 0) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
if (api_is_coach()) {
//Looking for course items that are invisible to hide it in the session
if (in_array($row['id'], array_keys($doc_list))) {
@ -533,7 +530,6 @@ class DocumentManager {
}
}
}
$doc_list[$row['id']] = $row;
}
@ -546,9 +542,9 @@ class DocumentManager {
//Templates management
$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
$sql_is_template = "SELECT id FROM $table_template
WHERE course_code='".$_course['id']."'
AND user_id='".api_get_user_id()."'
AND ref_doc='".$row['id']."'";
WHERE course_code = '".$_course['code']."'
AND user_id = '".api_get_user_id()."'
AND ref_doc = '".$row['id']."'";
$template_result = Database::query($sql_is_template);
$row['is_template'] = (Database::num_rows($template_result) > 0) ? 1 : 0;
}
@ -556,8 +552,6 @@ class DocumentManager {
$document_data[$row['id']] = $row;
}
//Only for the student we filter the results see BT#1652
if (!api_is_coach() && !$is_allowed_to_edit) {
$ids_to_remove = array();
@ -610,7 +604,7 @@ class DocumentManager {
//Checking parents visibility
$final_document_data = array();
foreach($document_data as $row) {
foreach ($document_data as $row) {
$is_visible = DocumentManager::check_visibility_tree($row['id'], $_course['code'], $current_session_id, api_get_user_id());
if ($is_visible) {
$final_document_data[$row['id']]=$row;

@ -839,15 +839,14 @@ function filter_extension(&$filename) {
* @param string $title
* @return id if inserted document
*/
function add_document($_course, $path, $filetype, $filesize, $title, $comment = null, $readonly = 0, $save_visibility = true) {
function add_document($_course, $path, $filetype, $filesize, $title, $comment = null, $readonly = 0, $save_visibility = true, $group_id = null) {
$session_id = api_get_session_id();
$readonly = intval($readonly);
$comment = Database::escape_string($comment);
$path = Database::escape_string($path);
$filetype = Database::escape_string($filetype);
$filesize = intval($filesize);
$title = htmlspecialchars($title);
$title = Database::escape_string($title);
$filesize = intval($filesize);
$title = Database::escape_string(htmlspecialchars($title));
$c_id = $_course['real_id'];
$table_document = Database::get_course_table(TABLE_DOCUMENT);
@ -858,7 +857,7 @@ function add_document($_course, $path, $filetype, $filesize, $title, $comment =
$document_id = Database::insert_id();
if ($document_id) {
if ($save_visibility) {
api_set_default_visibility($document_id, TOOL_DOCUMENT);
api_set_default_visibility($document_id, TOOL_DOCUMENT, $group_id);
}
}
return $document_id;
@ -1089,7 +1088,7 @@ function create_unexisting_directory($_course, $user_id, $session_id, $to_group_
$rs = Database::query($sql);
if (Database::num_rows($rs) == 0) {
$document_id = add_document($_course, $desired_dir_name.$nb, 'folder', 0, $title);
$document_id = add_document($_course, $desired_dir_name.$nb, 'folder', 0, $title, null, 0, true, $to_group_id);
if ($document_id) {
// Update document item_property
if ($visibility !== '') {

@ -195,6 +195,7 @@ class GroupManager {
}
return $groups;
}
/**
* Create a group
* @param string $name The name for this group
@ -202,19 +203,21 @@ class GroupManager {
* @param int $places How many people can subscribe to the new group
*/
public static function create_group ($name, $category_id, $tutor, $places) {
global $_course,$_user;
isset($_SESSION['id_session'])?$my_id_session = intval($_SESSION['id_session']):$my_id_session=0;
global $_course;
$table_group = Database :: get_course_table(TABLE_GROUP);
$session_id = api_get_session_id();
$course_id = api_get_course_int_id();
$currentCourseRepository = $_course['path'];
$table_group = Database :: get_course_table(TABLE_GROUP);
$table_forum = Database :: get_course_table(TABLE_FORUM);
$category = self :: get_category($category_id);
$course_id = api_get_course_int_id();
$category = self :: get_category($category_id);
if (intval($places) == 0) {
//if the amount of users per group is not filled in, use the setting from the category
$places = $category['max_student'];
}
$sql = "INSERT INTO ".$table_group." SET
c_id = $course_id ,
category_id='".Database::escape_string($category_id)."',
@ -228,55 +231,62 @@ class GroupManager {
chat_state = '".$category['chat_state']."',
self_registration_allowed = '".$category['self_reg_allowed']."',
self_unregistration_allowed = '".$category['self_unreg_allowed']."',
session_id='".Database::escape_string($my_id_session)."'";
session_id='".Database::escape_string($session_id)."'";
Database::query($sql);
$lastId = Database::insert_id();
if ($lastId) {
$desired_dir_name= '/'.replace_dangerous_char($name,'strict').'_groupdocs';
$my_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository.'/document';
$unique_name = create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, NULL, $my_path, $desired_dir_name);
/* Stores the directory path into the group table */
$sql = "UPDATE ".$table_group." SET name = '".Database::escape_string($name)."', secret_directory = '".$unique_name."'
WHERE c_id = $course_id AND id ='".$lastId."'";
$desired_dir_name= '/'.replace_dangerous_char($name,'strict').'_groupdocs';
$my_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository.'/document';
$unique_name = create_unexisting_directory($_course,$_user['user_id'], api_get_session_id(), $lastId,NULL,$my_path, $desired_dir_name);
/* Stores the directory path into the group table */
$sql = "UPDATE ".$table_group." SET name = '".Database::escape_string($name)."', secret_directory = '".$unique_name."'
WHERE c_id = $course_id AND id ='".$lastId."'";
Database::query($sql);
Database::query($sql);
// create a forum if needed
if ($category['forum_state'] >= 0) {
require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php';
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
// create a forum if needed
if ($category['forum_state'] >= 0) {
require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php';
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
$forum_categories = get_forum_categories();
$values['forum_title'] = $name;
$counter = 0;
foreach ($forum_categories as $key=>$value) {
if ($counter==0) {
$forum_category_id = $key;
}
$counter++;
}
// A sanity check.
if (empty($forum_category_id)) {
$forum_category_id = 0;
}
$values['forum_category'] = $forum_category_id;
$values['allow_anonymous_group']['allow_anonymous'] = 0;
$values['students_can_edit_group']['students_can_edit'] = 0;
$values['approval_direct_group']['approval_direct'] = 0;
$values['allow_attachments_group']['allow_attachments'] = 1;
$values['allow_new_threads_group']['allow_new_threads'] = 1;
$values['default_view_type_group']['default_view_type']=api_get_setting('default_forum_view');
$values['group_forum'] = $lastId;
if ($category['forum_state'] == '1') {
$values['public_private_group_forum_group']['public_private_group_forum']='public';
} elseif ($category['forum_state'] == '2') {
$values['public_private_group_forum_group']['public_private_group_forum']='private';
} elseif ($category['forum_state'] == '0') {
$values['public_private_group_forum_group']['public_private_group_forum']='unavailable';
}
store_forum($values);
}
$forum_categories = get_forum_categories();
$values = array();
$values['forum_title'] = $name;
$values['group_id'] = $lastId;
$counter = 0;
foreach ($forum_categories as $key=>$value) {
if ($counter==0) {
$forum_category_id = $key;
}
$counter++;
}
// A sanity check.
if (empty($forum_category_id)) {
$forum_category_id = 0;
}
$values['forum_category'] = $forum_category_id;
$values['allow_anonymous_group']['allow_anonymous'] = 0;
$values['students_can_edit_group']['students_can_edit'] = 0;
$values['approval_direct_group']['approval_direct'] = 0;
$values['allow_attachments_group']['allow_attachments'] = 1;
$values['allow_new_threads_group']['allow_new_threads'] = 1;
$values['default_view_type_group']['default_view_type']=api_get_setting('default_forum_view');
$values['group_forum'] = $lastId;
if ($category['forum_state'] == '1') {
$values['public_private_group_forum_group']['public_private_group_forum']='public';
} elseif ($category['forum_state'] == '2') {
$values['public_private_group_forum_group']['public_private_group_forum']='private';
} elseif ($category['forum_state'] == '0') {
$values['public_private_group_forum_group']['public_private_group_forum']='unavailable';
}
store_forum($values);
}
}
return $lastId;
}
/**

@ -6037,7 +6037,7 @@ function api_is_global_chat_enabled(){
/**
* @todo Fix tool_visible_by_default_at_creation labels
*/
function api_set_default_visibility($item_id, $tool_id) {
function api_set_default_visibility($item_id, $tool_id, $group_id = null) {
$original_tool_id = $tool_id;
switch ($tool_id) {
@ -6071,7 +6071,10 @@ function api_set_default_visibility($item_id, $tool_id) {
$visibility = 'invisible';
if ($setting[$tool_id] == 'true') {
$visibility = 'visible';
}
api_item_property_update(api_get_course_info(), $original_tool_id, $item_id, $visibility, api_get_user_id(), api_get_group_id(), null, null, null, api_get_session_id());
}
if (empty($group_id)) {
$group_id = api_get_group_id();
}
api_item_property_update(api_get_course_info(), $original_tool_id, $item_id, $visibility, api_get_user_id(), $group_id, null, null, null, api_get_session_id());
}
}
Loading…
Cancel
Save