Browse Source

Use group info instead of group id as parameter

Function api_item_property_update
jmontoyaa 7 years ago
parent
commit
2a5a63e6be

+ 4 - 3
main/document/create_audio.php

@@ -355,7 +355,6 @@ function downloadMP3_google($filepath, $dir)
     }
 
     $documentPath = $filepath . '/' . $audio_filename;
-
     $clean_text = api_replace_dangerous_char($clean_text);
 
     // adding the file
@@ -380,6 +379,7 @@ function downloadMP3_google($filepath, $dir)
     // add document to database
     $current_session_id = api_get_session_id();
     $groupId = api_get_group_id();
+    $groupInfo = GroupManager::get_group_properties($groupId);
     $relativeUrlPath = $dir;
     $doc_id = add_document(
         $_course,
@@ -394,7 +394,7 @@ function downloadMP3_google($filepath, $dir)
         $doc_id,
         'DocumentAdded',
         $_user['user_id'],
-        $groupId,
+        $groupInfo,
         null,
         null,
         null,
@@ -495,6 +495,7 @@ function downloadMP3_pediaphon($filepath, $dir)
     //add document to database
     $current_session_id = api_get_session_id();
     $groupId = api_get_group_id();
+    $groupInfo = GroupManager::get_group_properties($groupId);
     $relativeUrlPath = $dir;
     $doc_id = add_document(
         $_course,
@@ -509,7 +510,7 @@ function downloadMP3_pediaphon($filepath, $dir)
         $doc_id,
         'DocumentAdded',
         $_user['user_id'],
-        $groupId,
+        $groupInfo,
         null,
         null,
         null,

+ 2 - 6
main/document/create_document.php

@@ -97,7 +97,7 @@ if (!empty($sessionId) && empty($document_data)) {
     );
 }
 $groupIid = 0;
-
+$group_properties = [];
 if (!empty($groupId)) {
     $group_properties = GroupManager::get_group_properties($groupId);
     $groupIid = $group_properties['iid'];
@@ -193,7 +193,6 @@ if (!is_dir($filepath)) {
     $dir = '/';
 }
 
-$to_group_id = 0;
 if (!$is_certificate_mode) {
     if (api_is_in_group()) {
         $interbreadcrumb[] = array(
@@ -201,7 +200,6 @@ if (!$is_certificate_mode) {
             "name" => get_lang('GroupSpace'),
         );
         $noPHP_SELF = true;
-        $to_group_id = $group_properties['iid'];
         $path = explode('/', $dir);
         if ('/'.$path[1] != $group_properties['directory']) {
             api_not_allowed(true);
@@ -518,8 +516,6 @@ if ($form->validate()) {
         fputs($fp, $content);
         fclose($fp);
         chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files());
-
-
         $file_size = filesize($filepath.$filename.'.'.$extension);
         $save_file_path = $dir.$filename.'.'.$extension;
 
@@ -540,7 +536,7 @@ if ($form->validate()) {
                 $document_id,
                 'DocumentAdded',
                 $userId,
-                $to_group_id,
+                $group_properties,
                 null,
                 null,
                 null,

+ 5 - 5
main/document/document.php

@@ -153,7 +153,6 @@ if (api_get_session_id() != 0) {
 // Get group info
 $groupIid = 0;
 $groupMemberWithEditRights = false;
-
 // Setting group variables.
 if (!empty($groupId)) {
     $group_properties = GroupManager::get_group_properties($groupId);
@@ -1131,7 +1130,7 @@ if ($isAllowedToEdit ||
                         $doc_id,
                         'FolderMoved',
                         api_get_user_id(),
-                        $groupIid,
+                        $group_properties,
                         null,
                         null,
                         null,
@@ -1145,7 +1144,7 @@ if ($isAllowedToEdit ||
                         $doc_id,
                         'DocumentMoved',
                         api_get_user_id(),
-                        $groupIid,
+                        $group_properties,
                         null,
                         null,
                         null,
@@ -1338,7 +1337,7 @@ if ($isAllowedToEdit ||
                 $courseInfo,
                 api_get_user_id(),
                 $sessionId,
-                $groupId,
+                $groupIid,
                 $to_user_id,
                 $base_work_dir,
                 $dir_name,
@@ -1404,7 +1403,8 @@ if ($isAllowedToEdit) {
             null,
             null,
             null,
-            $sessionId)
+            $sessionId
+        )
         ) {
             Display::addFlash(
                 Display::return_message(get_lang('VisibilityChanged'), 'confirmation')

+ 15 - 12
main/document/downloadfolder.inc.php

@@ -4,9 +4,9 @@
 use ChamiloSession as Session;
 
 /**
- *	Functions and main code for the download folder feature
+ * Functions and main code for the download folder feature
  *
- *	@package chamilo.document
+ * @package chamilo.document
  */
 
 set_time_limit(0);
@@ -114,8 +114,12 @@ function fixDocumentNameCallback($p_event, &$p_header)
     return 1;
 }
 
-$groupCondition = " props.to_group_id = ".$groupId;
-if (empty($groupId)) {
+$groupJoin = '';
+if (!empty($groupId)) {
+    $table = Database::get_course_table(TABLE_GROUP);
+    $groupJoin = " INNER JOIN $table g ON (g.iid = props.to_group_id AND g.c_id = docs.c_id)";
+    $groupCondition = " g.id = ".$groupId;
+} else {
     $groupCondition = " (props.to_group_id = 0 OR props.to_group_id IS NULL ) ";
 }
 
@@ -141,6 +145,7 @@ if (api_is_allowed_to_edit()) {
             ON
                 docs.id = props.ref AND
                 docs.c_id = props.c_id
+                $groupJoin
 			WHERE
 			    props.tool ='".TOOL_DOCUMENT."' AND
                 docs.path LIKE '".$querypath."/%' AND
@@ -153,7 +158,6 @@ if (api_is_allowed_to_edit()) {
     $sql .= DocumentManager::getSessionFolderFilters($querypath, $sessionId);
 
     $result = Database::query($sql);
-
     $files = array();
     while ($row = Database::fetch_array($result)) {
         $files[$row['path']] = $row;
@@ -194,7 +198,7 @@ if (api_is_allowed_to_edit()) {
     }
 
     /* A big problem: Visible files that are in a hidden folder are
-       included when we do a query for visiblity='v'
+       included when we do a query for visibility='v'
        So... I do it in a couple of steps:
        1st: Get all files that are visible in the given path
     */
@@ -205,6 +209,7 @@ if (api_is_allowed_to_edit()) {
             ON
                 docs.id = props.ref AND
                 docs.c_id = props.c_id
+                $groupJoin
             WHERE
                 docs.c_id = $courseId AND
                 props.tool = '".TOOL_DOCUMENT."' AND
@@ -218,8 +223,8 @@ if (api_is_allowed_to_edit()) {
     $sql .= DocumentManager::getSessionFolderFilters($querypath, $sessionId);
     $result = Database::query($sql);
 
-    $files = array();
-
+    $files = [];
+    $all_visible_files_path = [];
     // Add them to an array
     while ($all_visible_files = Database::fetch_assoc($result)) {
         if (strpos($all_visible_files['path'], 'chat_files') > 0 ||
@@ -241,7 +246,7 @@ if (api_is_allowed_to_edit()) {
             INNER JOIN $prop_table AS props
             ON
                 docs.id = props.ref AND
-                docs.c_id = props.c_id
+                docs.c_id = props.c_id                
             WHERE
                 docs.c_id = $courseId AND
                 props.tool = '".TOOL_DOCUMENT."' AND
@@ -252,7 +257,6 @@ if (api_is_allowed_to_edit()) {
     $query2 = Database::query($sql);
 
     // If we get invisible folders, we have to filter out these results from all visible files we found
-
     if (Database::num_rows($query2) > 0) {
         $files = array();
         // Add item to an array
@@ -263,7 +267,7 @@ if (api_is_allowed_to_edit()) {
                     INNER JOIN $prop_table AS props
                     ON
                         docs.id = props.ref AND
-                        docs.c_id = props.c_id
+                        docs.c_id = props.c_id                        
                     WHERE
                         docs.c_id = $courseId AND
                         props.tool ='".TOOL_DOCUMENT."' AND
@@ -285,7 +289,6 @@ if (api_is_allowed_to_edit()) {
             (array) $all_visible_files_path,
             (array) $files_in_invisible_folder_path
         );
-
     } else {
         // No invisible folders found, so all visible files can be added to the zipfile
         $files_for_zipfile = $all_visible_files_path;

+ 101 - 64
main/document/save_pixlr.php

@@ -17,18 +17,18 @@ api_protect_course_script();
 api_block_anonymous_users();
 
 if ($_user['user_id'] != api_get_user_id() || api_get_user_id() == 0 || $_user['user_id'] == 0) {
-	api_not_allowed();
-	die();
+    api_not_allowed();
+    die();
 }
 
 if (!isset($_GET['title']) || !isset($_GET['type']) || !isset($_GET['image'])) {
-	api_not_allowed();
-	die();
+    api_not_allowed();
+    die();
 }
 
 if (!isset($_SESSION['paint_dir']) || !isset($_SESSION['whereami'])) {
-	api_not_allowed();
-	die();
+    api_not_allowed();
+    die();
 }
 
 //pixlr return
@@ -42,18 +42,18 @@ $urlcontents = Security::remove_XSS($_GET['image']); //A URL to the image on Pix
 $title = Database::escape_string(str_replace('_', ' ', $filename));
 $current_session_id = api_get_session_id();
 $groupId = api_get_group_id();
+$groupInfo = GroupManager::get_group_properties($groupId);
 $relativeUrlPath = $_SESSION['paint_dir'];
 $currentTool = $_SESSION['whereami'];
 $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 $saveDir = $dirBaseDocuments.$_SESSION['paint_dir'];
-
 $contents = file_get_contents($urlcontents);
 
 //Security. Verify that the URL is pointing to a file @ pixlr.com domain or an ip @ pixlr.com. Comment because sometimes return a ip number
 /*
 if (strpos($urlcontents, "pixlr.com") === 0){
-	echo "Invalid referrer";
-	exit;
+    echo "Invalid referrer";
+    exit;
 }
 */
 
@@ -72,22 +72,22 @@ $filename = api_replace_dangerous_char($filename);
 $filename = disable_dangerous_file($filename);
 
 if (strlen(trim($filename)) == 0) {
-	 echo "The title is empty"; //if title is empty, headers Content-Type = application/octet-stream, then not create a new title here please
-	 exit;
+     echo "The title is empty"; //if title is empty, headers Content-Type = application/octet-stream, then not create a new title here please
+     exit;
 }
 
 //check file_get_contents
 if ($contents === false) {
-	echo "I cannot read: ".$urlcontents;
+    echo "I cannot read: ".$urlcontents;
     exit;
 }
 
 // Extension security
 if ($extension != 'jpg' && $extension != 'png' && $extension != 'pxd') {
-	die();
+    die();
 }
 if ($extension == 'pxd') {
-	echo "pxd file type does not supported"; // not secure because check security headers and finfo() return  Content-Type = application/octet-stream
+    echo "pxd file type does not supported"; // not secure because check security headers and finfo() return  Content-Type = application/octet-stream
     exit;
 }
 
@@ -95,8 +95,8 @@ if ($extension == 'pxd') {
 $headers = get_headers($urlcontents, 1);
 $content_type = explode("/", $headers['Content-Type']);
 if ($content_type[0] != "image") {
-	echo "Invalid file type";
-	exit;
+    echo "Invalid file type";
+    exit;
 }
 
 //Verify that the file is an image. Fileinfo method
@@ -114,49 +114,86 @@ $paintFileName = $filename.'.'.$extension;
 $title = $title.'.'.$extension;
 
 if ($currentTool == 'document/createpaint') {
-	//check save as and prevent rewrite an older file with same name
-	if (0 != $groupId) {
+    //check save as and prevent rewrite an older file with same name
+    if (0 != $groupId) {
         $group_properties = GroupManager :: get_group_properties($groupId);
         $groupPath = $group_properties['directory'];
-	} else {
-		$groupPath = '';
-	}
-
-	if (file_exists($saveDir.'/'.$filename.'.'.$extension)) {
-		$i = 1;
-		while (file_exists($saveDir.'/'.$filename.'_'.$i.'.'.$extension)) $i++;
-		$paintFileName = $filename.'_'.$i.'.'.$extension;
-		$title = $filename.'_'.$i.'.'.$extension;
-	}
-
-	//
-	$documentPath = $saveDir.'/'.$paintFileName;
-	//add new document to disk
-	file_put_contents($documentPath, $contents);
-	//add document to database
-	$doc_id = add_document($_course, $relativeUrlPath.'/'.$paintFileName, 'file', filesize($documentPath), $title);
-	api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
-
-}elseif ($currentTool == 'document/editpaint') {
-
-	$documentPath = $saveDir.'/'.$paintFileName;
-	//add new document to disk
-	file_put_contents($documentPath, $contents);
-
-	//check path
-	if (!isset($_SESSION['paint_file'])) {
-		api_not_allowed();
-		die();
-	}
-	if ($_SESSION['paint_file'] == $paintFileName) {
-		$document_id = DocumentManager::get_document_id($_course, $relativeUrlPath.'/'.$paintFileName);
-		update_existing_document($_course, $document_id, filesize($documentPath), null);
-		api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'], $groupId, null, null, null, $current_session_id);
-	} else {
-		//add a new document
-		$doc_id = add_document($_course, $relativeUrlPath.'/'.$paintFileName, 'file', filesize($documentPath), $title);
-		api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
-	}
+    } else {
+        $groupPath = '';
+    }
+
+    if (file_exists($saveDir.'/'.$filename.'.'.$extension)) {
+        $i = 1;
+        while (file_exists($saveDir.'/'.$filename.'_'.$i.'.'.$extension)) $i++;
+        $paintFileName = $filename.'_'.$i.'.'.$extension;
+        $title = $filename.'_'.$i.'.'.$extension;
+    }
+
+    //
+    $documentPath = $saveDir.'/'.$paintFileName;
+    //add new document to disk
+    file_put_contents($documentPath, $contents);
+    //add document to database
+    $doc_id = add_document($_course, $relativeUrlPath.'/'.$paintFileName, 'file', filesize($documentPath), $title);
+    api_item_property_update(
+        $_course,
+        TOOL_DOCUMENT,
+        $doc_id,
+        'DocumentAdded',
+        $_user['user_id'],
+        $groupInfo,
+        null,
+        null,
+        null,
+        $current_session_id
+    );
+} elseif ($currentTool == 'document/editpaint') {
+    $documentPath = $saveDir.'/'.$paintFileName;
+    //add new document to disk
+    file_put_contents($documentPath, $contents);
+
+    //check path
+    if (!isset($_SESSION['paint_file'])) {
+        api_not_allowed();
+        die();
+    }
+    if ($_SESSION['paint_file'] == $paintFileName) {
+        $document_id = DocumentManager::get_document_id($_course, $relativeUrlPath.'/'.$paintFileName);
+        update_existing_document($_course, $document_id, filesize($documentPath), null);
+        api_item_property_update(
+            $_course,
+            TOOL_DOCUMENT,
+            $document_id,
+            'DocumentUpdated',
+            $_user['user_id'],
+            $groupInfo,
+            null,
+            null,
+            null,
+            $current_session_id
+        );
+    } else {
+        //add a new document
+        $doc_id = add_document(
+            $_course,
+            $relativeUrlPath.'/'.$paintFileName,
+            'file',
+            filesize($documentPath),
+            $title
+        );
+        api_item_property_update(
+            $_course,
+            TOOL_DOCUMENT,
+            $doc_id,
+            'DocumentAdded',
+            $_user['user_id'],
+            $groupInfo,
+            null,
+            null,
+            null,
+            $current_session_id
+        );
+    }
 }
 
 
@@ -171,12 +208,12 @@ unset($_SESSION['whereami']);
 unset($_SESSION['temp_realpath_image']);
 
 if (!isset($_SESSION['exit_pixlr'])) {
-	$location = api_get_path(WEB_CODE_PATH).'document/document.php';
-	echo '<script>window.parent.location.href="'.$location.'"</script>';
-	api_not_allowed(true);
+    $location = api_get_path(WEB_CODE_PATH).'document/document.php';
+    echo '<script>window.parent.location.href="'.$location.'"</script>';
+    api_not_allowed(true);
 } else {
-	echo '<div align="center" style="padding-top:150; font-family:Arial, Helvetica, Sans-serif;font-size:25px;color:#aaa;font-weight:bold;">'.get_lang('PleaseStandBy').'</div>';
-	$location = api_get_path(WEB_CODE_PATH).'document/document.php?id='.Security::remove_XSS($_SESSION['exit_pixlr']);
-	echo '<script>window.parent.location.href="'.$location.'"</script>';
-	unset($_SESSION['exit_pixlr']);
+    echo '<div align="center" style="padding-top:150; font-family:Arial, Helvetica, Sans-serif;font-size:25px;color:#aaa;font-weight:bold;">'.get_lang('PleaseStandBy').'</div>';
+    $location = api_get_path(WEB_CODE_PATH).'document/document.php?id='.Security::remove_XSS($_SESSION['exit_pixlr']);
+    echo '<script>window.parent.location.href="'.$location.'"</script>';
+    unset($_SESSION['exit_pixlr']);
 }

+ 37 - 17
main/document/webcam_receiver.php

@@ -14,18 +14,18 @@ api_block_anonymous_users();
 parse_str($_SERVER['QUERY_STRING'], $params);
 
 if (isset($params['webcamname']) && isset($params['webcamdir']) && isset($params['webcamuserid'])) {
-	$webcamname = $params['webcamname'];
-	$webcamdir = $params['webcamdir'];
-	$webcamuserid = $params['webcamuserid'];
+    $webcamname = $params['webcamname'];
+    $webcamdir = $params['webcamdir'];
+    $webcamuserid = $params['webcamuserid'];
 }
 else {
-	api_not_allowed();
-	die();
+    api_not_allowed();
+    die();
 }
 
 if ($webcamuserid != api_get_user_id() || api_get_user_id() == 0 || $webcamuserid == 0) {
-	api_not_allowed();
-	die();
+    api_not_allowed();
+    die();
 }
 
 
@@ -42,7 +42,7 @@ $ext = explode('.', $webcamname);
 $ext = strtolower($ext[sizeof($ext) - 1]);
 
 if ($ext != 'jpg') {
-	die();
+    die();
 }
 
 //Do not use here check Fileinfo method because return: text/plain                //CHECK THIS BEFORE COMMIT
@@ -51,17 +51,20 @@ $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 $saveDir = $dirBaseDocuments.$webcamdir;
 $current_session_id = api_get_session_id();
 $groupId = api_get_group_id();
+$groupInfo = GroupManager::get_group_properties($groupId);
 
 //Avoid duplicates
 $webcamname_to_save = $webcamname;
 $title_to_save = str_replace('_', ' ', $webcamname);
 $webcamname_noex = basename($webcamname, ".jpg");
 if (file_exists($saveDir.'/'.$webcamname_noex.'.'.$ext)) {
-		$i = 1;
-		while (file_exists($saveDir.'/'.$webcamname_noex.'_'.$i.'.'.$ext)) $i++;
-		$webcamname_to_save = $webcamname_noex.'_'.$i.'.'.$ext;
-		$title_to_save = $webcamname_noex.'_'.$i.'.'.$ext;
-		$title_to_save = str_replace('_', ' ', $title_to_save);
+    $i = 1;
+    while (file_exists($saveDir.'/'.$webcamname_noex.'_'.$i.'.'.$ext)) {
+        $i++;
+    }
+    $webcamname_to_save = $webcamname_noex.'_'.$i.'.'.$ext;
+    $title_to_save = $webcamname_noex.'_'.$i.'.'.$ext;
+    $title_to_save = str_replace('_', ' ', $title_to_save);
 }
 
 $documentPath = $saveDir.'/'.$webcamname_to_save;
@@ -70,13 +73,30 @@ $documentPath = $saveDir.'/'.$webcamname_to_save;
 //Change to move_uploaded_file() function instead file_get_contents() to adapt the new lib
 $content = move_uploaded_file($_FILES['webcam']['tmp_name'], $documentPath);
 if (!$content) {
-	print "PHP ERROR: Failed to read data\n";
-	exit();
+    print "PHP ERROR: Failed to read data\n";
+    exit();
 }
 
 //add document to database
-	$doc_id = add_document($_course, $webcamdir.'/'.$webcamname_to_save, 'file', filesize($documentPath), $title_to_save);
-	api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
+$doc_id = add_document(
+    $_course,
+    $webcamdir.'/'.$webcamname_to_save,
+    'file',
+    filesize($documentPath),
+    $title_to_save
+);
+api_item_property_update(
+    $_course,
+    TOOL_DOCUMENT,
+    $doc_id,
+    'DocumentAdded',
+    $_user['user_id'],
+    $groupInfo,
+    null,
+    null,
+    null,
+    $current_session_id
+);
 ///
 $url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI']).'/'.$documentPath;
 print get_lang('ClipSent');

+ 26 - 11
main/forum/forumfunction.inc.php

@@ -628,6 +628,11 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
     } else {
         $group_id = api_get_group_id();
     }
+    $groupIid = 0;
+    if (!empty($group_id)) {
+        $groupInfo = GroupManager::get_group_properties($group_id);
+        $groupIid = $groupInfo['iid'];
+    }
 
     $table_forums = Database::get_course_table(TABLE_FORUM);
 
@@ -732,7 +737,7 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
             Database::escape_string($values['forum_id']),
             'ForumUpdated',
             api_get_user_id(),
-            $group_id
+            $groupInfo
         );
 
         $return_message = get_lang('ForumEdited');
@@ -775,7 +780,7 @@ function store_forum($values, $courseInfo = array(), $returnId = false)
                 $last_id,
                 'ForumAdded',
                 api_get_user_id(),
-                $group_id
+                $groupInfo
             );
 
             api_set_default_visibility(
@@ -821,6 +826,7 @@ function deleteForumCategoryThread($content, $id)
     $table_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD);
     $course_id = api_get_course_int_id();
     $groupId = api_get_group_id();
+    $groupInfo = GroupManager::get_group_properties($groupId);
     $userId = api_get_user_id();
     $id = intval($id);
 
@@ -890,7 +896,7 @@ function deleteForumCategoryThread($content, $id)
         $id,
         'delete',
         $userId,
-        $groupId
+        $groupInfo
     );
 
     // Check if this returns a true and if so => return $return_message, if not => return false;
@@ -2560,9 +2566,7 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
     } else {
         $visible = 1;
     }
-
     $clean_post_title = $values['post_title'];
-
     // We first store an entry in the forum_thread table because the thread_id is used in the forum_post table.
 
     $lastThread = new CForumThread();
@@ -2627,7 +2631,7 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
             $lastThread->getIid(),
             'ForumThreadAdded',
             $userId,
-            $groupIid,
+            $groupInfo,
             null,
             null,
             null,
@@ -2645,7 +2649,7 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
         api_set_default_visibility(
             $lastThread->getIid(),
             TOOL_FORUM_THREAD,
-            $groupIid,
+            $groupId,
             $courseInfo,
             $sessionId,
             $userId
@@ -2658,8 +2662,7 @@ function store_thread($current_forum, $values, $courseInfo = array(), $showMessa
                 $lastThread->getIid(),
                 'invisible',
                 $userId,
-                $groupIid
-
+                $groupInfo
             );
             $visible = 1;
         }
@@ -4775,7 +4778,13 @@ function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
                 $sql = "UPDATE $table_forum_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', post_id = '$safe_post_id', size ='".$attachment['size']."'
                        WHERE c_id = $course_id AND id = '$safe_id_attach'";
                 Database::query($sql);
-                api_item_property_update($_course, TOOL_FORUM_ATTACH, $safe_id_attach, 'ForumAttachmentUpdated', api_get_user_id());
+                api_item_property_update(
+                    $_course,
+                    TOOL_FORUM_ATTACH,
+                    $safe_id_attach,
+                    'ForumAttachmentUpdated',
+                    api_get_user_id()
+                );
             }
         }
     }
@@ -4872,7 +4881,13 @@ function delete_attachment($post_id, $id_attach = 0, $display = true)
     }
 
     // Update item_property.
-    api_item_property_update($_course, TOOL_FORUM_ATTACH, $id_attach, 'ForumAttachmentDelete', api_get_user_id());
+    api_item_property_update(
+        $_course,
+        TOOL_FORUM_ATTACH,
+        $id_attach,
+        'ForumAttachmentDelete',
+        api_get_user_id()
+    );
 
     if (!empty($result) && !empty($id_attach) && $display) {
         $message = get_lang('AttachmentFileDeleteSuccess');

+ 1 - 1
main/gradebook/lib/be/exerciselink.class.php

@@ -466,7 +466,7 @@ class ExerciseLink extends AbstractLink
                 $sql = 'SELECT * FROM '.$tbl_exercise.'
                         WHERE
                             c_id = '.$this->course_id.' AND
-                            id = '.$ref_id.' ';
+                            id = '.$ref_id;
             }
             $result = Database::query($sql);
             $this->exercise_data = Database::fetch_array($result);

+ 9 - 4
main/inc/lib/AnnouncementManager.php

@@ -345,6 +345,7 @@ class AnnouncementManager
         ) {
             $modify_icons = "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=modify&id=" . $id . "\">" .
                 Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>";
+
             if ($itemProperty->getVisibility() === 1) {
                 $image_visibility = 'visible';
                 $alt_visibility = get_lang('Hide');
@@ -538,13 +539,14 @@ class AnnouncementManager
                 if (is_array($send_to['groups']) && !empty($send_to['groups'])) {
                     $counter = 1;
                     foreach ($send_to['groups'] as $group) {
+                        $groupInfo = GroupManager::get_group_properties($group);
                         api_item_property_update(
                             $courseInfo,
                             TOOL_ANNOUNCEMENT,
                             $last_id,
                             'AnnouncementAdded',
                             $authorId,
-                            $group
+                            $groupInfo
                         );
 
                         if (($counter % $batchSize) === 0) {
@@ -648,13 +650,14 @@ class AnnouncementManager
                 // storing the selected groups
                 if (is_array($send_to['groups'])) {
                     foreach ($send_to['groups'] as $group) {
+                        $groupInfo = GroupManager::get_group_properties($group);
                         api_item_property_update(
                             $_course,
                             TOOL_ANNOUNCEMENT,
                             $last_id,
                             'AnnouncementAdded',
                             api_get_user_id(),
-                            $group
+                            $groupInfo
                         );
                     }
                 }
@@ -666,6 +669,7 @@ class AnnouncementManager
                 // storing the selected users
                 if (is_array($to_users) && is_array($to_groups)) {
                     foreach ($to_groups as $group) {
+                        $groupInfo = GroupManager::get_group_properties($group);
                         foreach ($to_users as $user) {
                             api_item_property_update(
                                 $_course,
@@ -673,7 +677,7 @@ class AnnouncementManager
                                 $last_id,
                                 'AnnouncementAdded',
                                 api_get_user_id(),
-                                $group,
+                                $groupInfo,
                                 $user
                             );
                         }
@@ -761,13 +765,14 @@ class AnnouncementManager
             // storing the selected groups
             if (is_array($send_to['groups'])) {
                 foreach ($send_to['groups'] as $group) {
+                    $groupInfo = GroupManager::get_group_properties($group);
                     api_item_property_update(
                         $_course,
                         TOOL_ANNOUNCEMENT,
                         $id,
                         'AnnouncementUpdated',
                         api_get_user_id(),
-                        $group
+                        $groupInfo
                     );
                 }
             }

+ 8 - 15
main/inc/lib/CourseChatUtils.php

@@ -115,7 +115,7 @@ class CourseChatUtils
         $isMaster = (bool) api_is_course_admin();
         $document_path = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
         $basepath_chat = '/chat_files';
-
+        $group_info = [];
         if (!$this->groupId) {
             $group_info = GroupManager::get_group_properties($this->groupId);
             $basepath_chat = $group_info['directory'].'/chat_files';
@@ -162,7 +162,7 @@ class CourseChatUtils
                     $doc_id,
                     $logType,
                     $this->userId,
-                    $this->groupId,
+                    $group_info,
                     null,
                     null,
                     null,
@@ -1511,7 +1511,7 @@ class CourseChatUtils
         $isMaster = (bool) api_is_course_admin();
         $basepath_chat = '/chat_files';
         $document_path = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
-
+        $group_info = [];
         if ($this->groupId) {
             $group_info = GroupManager:: get_group_properties($this->groupId);
             $basepath_chat = $group_info['directory'].'/chat_files';
@@ -1535,7 +1535,7 @@ class CourseChatUtils
                         $doc_id,
                         'FolderCreated',
                         null,
-                        $this->groupId,
+                        $group_info,
                         null,
                         null,
                         null
@@ -1568,7 +1568,7 @@ class CourseChatUtils
                     $doc_id,
                     'DocumentAdded',
                     $this->userId,
-                    $this->groupId,
+                    $group_info,
                     null,
                     null,
                     null,
@@ -1580,7 +1580,7 @@ class CourseChatUtils
                     $doc_id,
                     'invisible',
                     $this->userId,
-                    $this->groupId,
+                    $group_info,
                     null,
                     null,
                     null,
@@ -1591,7 +1591,6 @@ class CourseChatUtils
         }
 
         $basename_chat = 'messages-'.$date_now;
-
         if ($this->groupId && !$friendId) {
             $basename_chat = 'messages-'.$date_now.'_gid-'.$this->groupId;
         } else if ($this->sessionId && !$friendId) {
@@ -1605,9 +1604,7 @@ class CourseChatUtils
         }
 
         if ($reset && $isMaster) {
-
             $i = 1;
-
             while (file_exists($chat_path.$basename_chat.'-'.$i.'.log.html')) {
                 $i++;
             }
@@ -1629,7 +1626,7 @@ class CourseChatUtils
                 $doc_id,
                 'DocumentAdded',
                 $this->userId,
-                $this->groupId,
+                $group_info,
                 null,
                 null,
                 null,
@@ -1641,19 +1638,17 @@ class CourseChatUtils
                 $doc_id,
                 'invisible',
                 $this->userId,
-                $this->groupId,
+                $group_info,
                 null,
                 null,
                 null,
                 $this->sessionId
             );
             item_property_update_on_folder($courseInfo, $basepath_chat, $this->userId);
-
             $doc_id = DocumentManager::get_document_id(
                 $courseInfo,
                 $basepath_chat.'/'.$basename_chat.'.log.html'
             );
-
             update_existing_document($courseInfo, $doc_id, 0);
         }
 
@@ -1678,11 +1673,9 @@ class CourseChatUtils
         }
 
         $history = '<div id="content-chat">';
-
         foreach ($content as $this_line) {
             $history .= $this_line;
         }
-
         $history .= '</div>';
 
         if ($isMaster || $GLOBALS['is_courseCoach']) {

+ 24 - 25
main/inc/lib/agenda.lib.php

@@ -265,6 +265,7 @@ class Agenda
 
                     $groupId = api_get_group_id();
                     $groupIid = 0;
+                    $groupInfo = [];
                     if ($groupId) {
                         $groupInfo = GroupManager::get_group_properties(
                             $groupId
@@ -284,7 +285,7 @@ class Agenda
                                 $id,
                                 'AgendaAdded',
                                 $senderId,
-                                $groupIid,
+                                $groupInfo,
                                 '',
                                 $start,
                                 $end,
@@ -296,7 +297,7 @@ class Agenda
                                 $id,
                                 'visible',
                                 $senderId,
-                                $groupIid,
+                                $groupInfo,
                                 '',
                                 $start,
                                 $end,
@@ -306,13 +307,13 @@ class Agenda
                             // Storing the selected groups
                             if (!empty($sendTo['groups'])) {
                                 foreach ($sendTo['groups'] as $group) {
-                                    $groupIidItem = 0;
+                                    $groupInfoItem = [];
                                     if ($group) {
-                                        $groupInfo = GroupManager::get_group_properties(
+                                        $groupInfoItem = GroupManager::get_group_properties(
                                             $group
                                         );
-                                        if ($groupInfo) {
-                                            $groupIidItem = $groupInfo['iid'];
+                                        if ($groupInfoItem) {
+                                            $groupIidItem = $groupInfoItem['iid'];
                                         }
                                     }
 
@@ -322,7 +323,7 @@ class Agenda
                                         $id,
                                         'AgendaAdded',
                                         $senderId,
-                                        $groupIidItem,
+                                        $groupInfoItem,
                                         0,
                                         $start,
                                         $end,
@@ -335,7 +336,7 @@ class Agenda
                                         $id,
                                         'visible',
                                         $senderId,
-                                        $groupIidItem,
+                                        $groupInfoItem,
                                         0,
                                         $start,
                                         $end,
@@ -353,7 +354,7 @@ class Agenda
                                         $id,
                                         'AgendaAdded',
                                         $senderId,
-                                        $groupIid,
+                                        $groupInfo,
                                         $userId,
                                         $start,
                                         $end,
@@ -366,7 +367,7 @@ class Agenda
                                         $id,
                                         'visible',
                                         $senderId,
-                                        $groupIid,
+                                        $groupInfo,
                                         $userId,
                                         $start,
                                         $end,
@@ -808,11 +809,11 @@ class Agenda
                                 foreach ($eventInfo['send_to']['groups'] as $group) {
                                     $groupIidItem = 0;
                                     if ($group) {
-                                        $groupInfo = GroupManager::get_group_properties(
+                                        $groupInfoItem = GroupManager::get_group_properties(
                                             $group
                                         );
-                                        if ($groupInfo) {
-                                            $groupIidItem = $groupInfo['iid'];
+                                        if ($groupInfoItem) {
+                                            $groupIidItem = $groupInfoItem['iid'];
                                         }
                                     }
 
@@ -850,7 +851,7 @@ class Agenda
                                 $id,
                                 'visible',
                                 $authorId,
-                                $groupIid,
+                                $groupInfo,
                                 null,
                                 $start,
                                 $end,
@@ -870,14 +871,11 @@ class Agenda
                             // Add groups
                             if (!empty($groupToAdd)) {
                                 foreach ($groupToAdd as $group) {
-                                    $groupIidItem = 0;
+                                    $groupInfoItem = [];
                                     if ($group) {
-                                        $groupInfo = GroupManager::get_group_properties(
+                                        $groupInfoItem = GroupManager::get_group_properties(
                                             $group
                                         );
-                                        if ($groupInfo) {
-                                            $groupIidItem = $groupInfo['iid'];
-                                        }
                                     }
 
                                     api_item_property_update(
@@ -886,7 +884,7 @@ class Agenda
                                         $id,
                                         'visible',
                                         $authorId,
-                                        $groupIidItem,
+                                        $groupInfoItem,
                                         0,
                                         $start,
                                         $end,
@@ -899,12 +897,13 @@ class Agenda
                             if (!empty($groupsToDelete)) {
                                 foreach ($groupsToDelete as $group) {
                                     $groupIidItem = 0;
+                                    $groupInfoItem = [];
                                     if ($group) {
-                                        $groupInfo = GroupManager::get_group_properties(
+                                        $groupInfoItem = GroupManager::get_group_properties(
                                             $group
                                         );
-                                        if ($groupInfo) {
-                                            $groupIidItem = $groupInfo['iid'];
+                                        if ($groupInfoItem) {
+                                            $groupIidItem = $groupInfoItem['iid'];
                                         }
                                     }
 
@@ -928,7 +927,7 @@ class Agenda
                                         $id,
                                         'visible',
                                         $authorId,
-                                        $groupIid,
+                                        $groupInfo,
                                         $userId,
                                         $start,
                                         $end,
@@ -945,7 +944,7 @@ class Agenda
                                         TOOL_CALENDAR_EVENT,
                                         $id,
                                         $userId,
-                                        $groupIid,
+                                        $groupInfo,
                                         $this->sessionId
                                     );
                                 }

+ 10 - 8
main/inc/lib/api.lib.php

@@ -3516,7 +3516,7 @@ function api_get_item_visibility(
  * @param string $tool
  * @param int $itemId
  * @param int $userId
- * @param int $groupId
+ * @param int $groupId group.iid
  * @param int $sessionId
  * @return false|null
  */
@@ -3581,7 +3581,7 @@ function api_item_property_delete(
  * (3) "visible"
  * (4) "invisible"
  * @param int $user_id id of the editing/adding user
- * @param int $to_group_id group.iid
+ * @param array $groupInfo must include group.iid/group.od
  * @param int $to_user_id id of the intended user (always has priority over $to_group_id !), only relevant for $type (1)
  * @param string $start_visible 0000-00-00 00:00:00 format
  * @param string $end_visible 0000-00-00 00:00:00 format
@@ -3597,7 +3597,7 @@ function api_item_property_update(
     $item_id,
     $last_edit_type,
     $user_id,
-    $to_group_id = 0,
+    $groupInfo = [],
     $to_user_id = null,
     $start_visible = '',
     $end_visible = '',
@@ -3613,6 +3613,11 @@ function api_item_property_update(
         return false;
     }
 
+    $to_group_id = 0;
+    if (!empty($groupInfo) && isset($groupInfo['iid'])) {
+        $to_group_id = $groupInfo['iid'];
+    }
+
     $em = Database::getManager();
 
     // Definition of variables.
@@ -3662,7 +3667,6 @@ function api_item_property_update(
     }
 
     $toValueCondition = empty($to_value) ? "NULL" : "'$to_value'";
-
     // Set filters for $to_user_id and $to_group_id, with priority for $to_user_id
     $condition_session = " AND session_id = $session_id ";
     if (empty($session_id)) {
@@ -4589,7 +4593,6 @@ function api_get_permissions_for_new_files()
  */
 function rmdirr($dirname, $delete_only_content_in_folder = false, $strict = false) {
     $res = true;
-
     // A sanity check.
     if (!file_exists($dirname)) {
         return false;
@@ -6839,7 +6842,7 @@ function api_is_global_chat_enabled()
  *
  * @param int $item_id
  * @param int $tool_id
- * @param int $group_id iid
+ * @param int $group_id id
  * @param array $courseInfo
  * @param int $sessionId
  * @param int $userId
@@ -6912,7 +6915,7 @@ function api_set_default_visibility(
             $item_id,
             $visibility,
             $userId,
-            $groupIid,
+            $groupInfo,
             null,
             null,
             null,
@@ -6920,7 +6923,6 @@ function api_set_default_visibility(
         );
 
         // Fixes default visibility for tests
-
         switch ($original_tool_id) {
             case TOOL_QUIZ:
                 if (empty($sessionId)) {

+ 9 - 3
main/inc/lib/attendance.lib.php

@@ -449,7 +449,7 @@ class Attendance
                         $_course,
                         TOOL_ATTENDANCE,
                         $id,
-                        "restore",
+                        'restore',
                         $user_id
                     );
                 }
@@ -466,7 +466,7 @@ class Attendance
                     $_course,
                     TOOL_ATTENDANCE,
                     $attendance_id,
-                    "restore",
+                    'restore',
                     $user_id
                 );
             }
@@ -556,7 +556,13 @@ class Attendance
                 $affected_rows = Database::affected_rows($result);
                 if (!empty($affected_rows)) {
                     // update row item property table
-                    api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
+                    api_item_property_update(
+                        $_course,
+                        TOOL_ATTENDANCE,
+                        $id,
+                        $action,
+                        $user_id
+                    );
                 }
             }
         } else {

+ 14 - 8
main/inc/lib/fileUpload.lib.php

@@ -240,6 +240,7 @@ function handle_uploaded_document(
     }
 
     $groupIid = 0;
+    $groupInfo = [];
     if (!empty($groupId)) {
         $groupInfo = GroupManager::get_group_properties($groupId);
         $groupIid = $groupInfo['iid'];
@@ -415,7 +416,7 @@ function handle_uploaded_document(
                                     $documentId,
                                     'DocumentUpdated',
                                     $userId,
-                                    $groupIid,
+                                    $groupInfo,
                                     $toUserId,
                                     null,
                                     null,
@@ -454,7 +455,7 @@ function handle_uploaded_document(
                                         $documentId,
                                         'DocumentAdded',
                                         $userId,
-                                        $groupIid,
+                                        $groupInfo,
                                         $toUserId,
                                         null,
                                         null,
@@ -462,7 +463,12 @@ function handle_uploaded_document(
                                     );
 
                                     // Redo visibility
-                                    api_set_default_visibility($documentId, TOOL_DOCUMENT, null, $courseInfo);
+                                    api_set_default_visibility(
+                                        $documentId,
+                                        TOOL_DOCUMENT,
+                                        null,
+                                        $courseInfo
+                                    );
                                 }
                             }
 
@@ -503,7 +509,7 @@ function handle_uploaded_document(
                                     $documentId,
                                     'DocumentAdded',
                                     $userId,
-                                    $groupIid,
+                                    $groupInfo,
                                     $toUserId,
                                     null,
                                     null,
@@ -591,7 +597,7 @@ function handle_uploaded_document(
                                 $documentId,
                                 'DocumentAdded',
                                 $userId,
-                                $groupId,
+                                $groupInfo,
                                 $toUserId,
                                 null,
                                 null,
@@ -665,7 +671,7 @@ function handle_uploaded_document(
                                     $documentId,
                                     'DocumentAdded',
                                     $userId,
-                                    $groupId,
+                                    $groupInfo,
                                     $toUserId,
                                     null,
                                     null,
@@ -1604,7 +1610,7 @@ function create_unexisting_directory(
                             $document_id,
                             $visibilities[$visibility],
                             $user_id,
-                            $groupIid,
+                            $groupInfo,
                             $to_user_id,
                             null,
                             null,
@@ -1617,7 +1623,7 @@ function create_unexisting_directory(
                             $document_id,
                             'FolderCreated',
                             $user_id,
-                            $groupIid,
+                            $groupInfo,
                             $to_user_id,
                             null,
                             null,

+ 2 - 2
main/inc/lib/nanogong/receiver.php

@@ -56,7 +56,7 @@ if ($nano_user_id != api_get_user_id() || api_get_user_id() == 0 || $nano_user_i
 }
 
 // Do not use here check Fileinfo method because return: text/plain
-
+$groupInfo = GroupManager::get_group_properties($nano_group_id);
 if (!file_exists($documentPath)) {
     //add document to disk
     move_uploaded_file($_FILES['voicefile']['tmp_name'], $documentPath);
@@ -73,7 +73,7 @@ if (!file_exists($documentPath)) {
         $doc_id,
         'DocumentAdded',
         $nano_user_id,
-        $groupId,
+        $groupInfo,
         null,
         null,
         null,

+ 79 - 27
main/inc/lib/svg-edit/extensions/savefile_config.php

@@ -58,13 +58,14 @@ if (!isset($_SESSION['draw_dir']) && !isset($_SESSION['whereami'])) {
 
 $current_session_id = api_get_session_id();
 $groupId = api_get_group_id();
+$groupInfo = GroupManager::get_group_properties($groupId);
+
 $relativeUrlPath = $_SESSION['draw_dir'];
 $currentTool = $_SESSION['whereami'];
 $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
-$saveDir=$dirBaseDocuments.$_SESSION['draw_dir'];
+$saveDir = $dirBaseDocuments.$_SESSION['draw_dir'];
 
 // a bit title security
-
 $filename = addslashes(trim($filename));
 $filename = Security::remove_XSS($filename);
 $filename = api_replace_dangerous_char($filename);
@@ -79,17 +80,17 @@ if ($suffix != 'svg' && $suffix != 'png') {
 //comment because finfo seems stopping the save process files in some php vers.
 /*
 if (phpversion() >= '5.3' && extension_loaded('fileinfo')) {
-	$finfo = new finfo(FILEINFO_MIME);
-	$current_mime=$finfo->buffer($contents);
-	finfo_close($finfo);
-	$mime_png='image/png';//svg-edit return image/png; charset=binary
-	$mime_svg='image/svg+xml';
-	$mime_xml='application/xml';//hack for svg-edit because original code return application/xml; charset=us-ascii. See
-	if(strpos($current_mime, $mime_png)===false && $extension=='png') {
-		die();//File extension does not match its content
-	} elseif(strpos($current_mime, $mime_svg)===false && strpos($current_mime, $mime_xml)===false && $extension=='svg') {
-		die();//File extension does not match its content
-	}
+    $finfo = new finfo(FILEINFO_MIME);
+    $current_mime=$finfo->buffer($contents);
+    finfo_close($finfo);
+    $mime_png='image/png';//svg-edit return image/png; charset=binary
+    $mime_svg='image/svg+xml';
+    $mime_xml='application/xml';//hack for svg-edit because original code return application/xml; charset=us-ascii. See
+    if(strpos($current_mime, $mime_png)===false && $extension=='png') {
+        die();//File extension does not match its content
+    } elseif(strpos($current_mime, $mime_svg)===false && strpos($current_mime, $mime_xml)===false && $extension=='svg') {
+        die();//File extension does not match its content
+    }
 }
 */
 
@@ -110,28 +111,79 @@ if (file_exists($saveDir.'/'.$filename.'.'.$extension) && $currentTool=='documen
 $documentPath = $saveDir.'/'.$drawFileName;
 
 //add new document to disk
-file_put_contents( $documentPath, $contents );
-
-if ($currentTool=='document/createdraw') {
+file_put_contents($documentPath, $contents);
+if ($currentTool == 'document/createdraw') {
     //add document to database
-    $doc_id = add_document($_course, $relativeUrlPath.'/'.$drawFileName, 'file', filesize($documentPath), $title);
-    api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
-
-} elseif($currentTool=='document/editdraw') {
+    $doc_id = add_document(
+        $_course,
+        $relativeUrlPath.'/'.$drawFileName,
+        'file',
+        filesize($documentPath),
+        $title
+    );
+    api_item_property_update(
+        $_course,
+        TOOL_DOCUMENT,
+        $doc_id,
+        'DocumentAdded',
+        $_user['user_id'],
+        $groupInfo,
+        null,
+        null,
+        null,
+        $current_session_id
+    );
 
+} elseif ($currentTool == 'document/editdraw') {
     //check path
-    if (!isset($_SESSION['draw_file'])){
+    if (!isset($_SESSION['draw_file'])) {
         api_not_allowed();//from Chamilo
         die();
     }
-    if ($_SESSION['draw_file'] == $drawFileName ){
-        $document_id = DocumentManager::get_document_id($_course, $relativeUrlPath.'/'.$drawFileName);
-        update_existing_document($_course, $document_id, filesize($documentPath), null);
-        api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'], $groupId, null, null, null, $current_session_id);
+    if ($_SESSION['draw_file'] == $drawFileName) {
+        $document_id = DocumentManager::get_document_id(
+            $_course,
+            $relativeUrlPath.'/'.$drawFileName
+        );
+        update_existing_document(
+            $_course,
+            $document_id,
+            filesize($documentPath),
+            null
+        );
+        api_item_property_update(
+            $_course,
+            TOOL_DOCUMENT,
+            $document_id,
+            'DocumentUpdated',
+            $_user['user_id'],
+            $groupInfo,
+            null,
+            null,
+            null,
+            $current_session_id
+        );
     } else {
         //add a new document
-        $doc_id = add_document($_course, $relativeUrlPath.'/'.$drawFileName, 'file', filesize($documentPath), $title);
-        api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
+        $doc_id = add_document(
+            $_course,
+            $relativeUrlPath.'/'.$drawFileName,
+            'file',
+            filesize($documentPath),
+            $title
+        );
+        api_item_property_update(
+            $_course,
+            TOOL_DOCUMENT,
+            $doc_id,
+            'DocumentAdded',
+            $_user['user_id'],
+            $groupInfo,
+            null,
+            null,
+            null,
+            $current_session_id
+        );
     }
 }
 

+ 20 - 4
main/lp/openoffice_presentation.class.php

@@ -152,18 +152,34 @@ class OpenofficePresentation extends OpenofficeDocument
             );
 
             if ($document_id) {
-
                 // Put the document in item_property update.
-                api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), 0, 0, null, null, api_get_session_id());
+                api_item_property_update(
+                    $_course,
+                    TOOL_DOCUMENT,
+                    $document_id,
+                    'DocumentAdded',
+                    api_get_user_id(),
+                    0,
+                    0,
+                    null,
+                    null,
+                    api_get_session_id()
+                );
 
-                $previous = $this->add_item(0, $previous, 'document', $document_id, $slide_name, '');
+                $previous = $this->add_item(
+                    0,
+                    $previous,
+                    'document',
+                    $document_id,
+                    $slide_name,
+                    ''
+                );
                 if ($this->first_item == 0) {
                     $this->first_item = $previous;
                 }
             }
             // Code for text indexing.
             if (api_get_setting('search_enabled') == 'true') {
-
                 if (isset($_POST['index_document']) && $_POST['index_document']) {
                     $di = new ChamiloIndexer();
                     isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english';

+ 10 - 6
main/lp/openoffice_text.class.php

@@ -150,10 +150,17 @@ class OpenofficeText extends OpenofficeDocument {
             fwrite($handle, $page_content);
             fclose($handle);
 
-            $document_id = add_document($_course, $this->created_dir.'/'.$html_file, 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$html_file), $html_file);
-
-            if ($document_id){
+            $document_id = add_document(
+                $_course,
+                $this->created_dir.'/'.$html_file,
+                'file',
+                filesize(
+                    $this->base_work_dir.$this->created_dir.'/'.$html_file
+                ),
+                $html_file
+            );
 
+            if ($document_id) {
                 // Put the document in item_property update.
                 api_item_property_update(
                     $_course,
@@ -200,12 +207,9 @@ class OpenofficeText extends OpenofficeDocument {
         $pages = explode('||page_break||', $body);
 
         $first_item = 0;
-
         foreach ($pages as $key => $page_content) {
             // For every pages, we create a new file.
-
             $key += 1;
-
             $page_content = $this->format_page_content($header, $page_content, $this->base_work_dir.$this->created_dir);
             $html_file = $this->created_dir.'-'.$key.'.html';
             $handle = fopen($this->base_work_dir.$this->created_dir.'/'.$html_file, 'w+');

+ 9 - 5
main/wiki/wiki.inc.php

@@ -274,6 +274,7 @@ class Wiki
         $session_id = api_get_session_id();
         $groupId = api_get_group_id();
         $userId = api_get_user_id();
+        $groupInfo = GroupManager::get_group_properties($groupId);
         $course_id = api_get_course_int_id();
 
         $_clean = array(
@@ -382,7 +383,7 @@ class Wiki
                 $id,
                 'WikiAdded',
                 $userId,
-                $groupId
+                $groupInfo
             );
 
             if ($values['page_id']== 0) {
@@ -439,7 +440,7 @@ class Wiki
             $id,
             'WikiAdded',
             $userId,
-            $groupId
+            $groupInfo
         );
         self::check_emailcue($_clean['reflink'], 'P', $time, $userId);
         $this->setWikiData($id);
@@ -472,6 +473,7 @@ class Wiki
         $r_comment = get_lang('RestoredFromVersion').': '.$c_version;
         $session_id = api_get_session_id();
         $course_id = api_get_course_int_id();
+        $groupInfo = GroupManager::get_group_properties($r_group_id);
 
         $params = [
             'c_id' => $course_id,
@@ -502,7 +504,7 @@ class Wiki
                 $id,
                 'WikiAdded',
                 api_get_user_id(),
-                $r_group_id
+                $groupInfo
             );
             self::check_emailcue($r_reflink, 'P', $r_dtime, $r_user_id);
         }
@@ -616,6 +618,7 @@ class Wiki
         $_clean['version'] = 1;
 
         $groupId = api_get_group_id();
+        $groupInfo = GroupManager::get_group_properties($groupId);
 
         //check wikilinks
         $_clean['linksto'] = self::links_to($_clean['content']);
@@ -692,7 +695,7 @@ class Wiki
                         $id,
                         'WikiAdded',
                         api_get_user_id(),
-                        $groupId
+                        $groupInfo
                     );
 
                     $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'"
@@ -1927,6 +1930,7 @@ class Wiki
     {
         $_course = $this->courseInfo;
         $groupId = api_get_group_id();
+        $groupInfo = GroupManager::get_group_properties($groupId);
         $data = self::getWikiDataFromDb($doc_id);
 
         if (empty($data)) {
@@ -2020,7 +2024,7 @@ class Wiki
             $doc_id,
             'DocumentAdded',
             api_get_user_id(),
-            $groupId
+            $groupInfo
         );
 
         return $doc_id;

+ 4 - 2
main/work/work.lib.php

@@ -3854,6 +3854,7 @@ function processWorkForm(
     }
 
     $groupIid = 0;
+    $groupInfo = [];
     if ($groupId) {
         $groupInfo = GroupManager::get_group_properties($groupId);
         $groupIid = $groupInfo['iid'];
@@ -3910,7 +3911,7 @@ function processWorkForm(
                 $workId,
                 'DocumentAdded',
                 $userId,
-                $groupIid
+                $groupInfo
             );
             sendAlertToUsers($workId, $courseInfo, $sessionId);
             Event::event_upload($workId);
@@ -4009,6 +4010,7 @@ function addDir($formValues, $user_id, $courseInfo, $groupId, $session_id)
     $groupId = intval($groupId);
 
     $groupIid = 0;
+    $groupInfo = [];
     if (!empty($groupId)) {
         $groupInfo = GroupManager::get_group_properties($groupId);
         $groupIid = $groupInfo['iid'];
@@ -4080,7 +4082,7 @@ function addDir($formValues, $user_id, $courseInfo, $groupId, $session_id)
         $workTable->getIid(),
         'DirectoryCreated',
         $user_id,
-        $groupIid
+        $groupInfo
     );
 
     updatePublicationAssignment(

+ 27 - 9
src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php

@@ -355,6 +355,9 @@ class CourseRestorer
                         $toUserId = isset($document->item_properties[0]['to_user_id']) ? $document->item_properties[0]['to_user_id'] : null;
                         $toUserId = $this->checkUserId($toUserId, true);
 
+                        $groupId = isset($document->item_properties[0]['to_group_id']) ? $document->item_properties[0]['to_group_id'] : null;
+                        $groupInfo = $this->checkGroupId($groupId);
+
                         // if folder exists then just refresh it
                         api_item_property_update(
                             $course_info,
@@ -362,7 +365,7 @@ class CourseRestorer
                             $documentData,
                             'FolderUpdated',
                             $insertUserId,
-                            $document->item_properties[0]['to_group_id'],
+                            $groupInfo,
                             $toUserId,
                             null,
                             null,
@@ -406,7 +409,7 @@ class CourseRestorer
                             $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
                             $toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
                             $toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
-
+                            $groupInfo = $this->checkGroupId($toGroupId);
                             $insertUserId = $this->checkUserId($insertUserId);
                             $toUserId = $this->checkUserId($toUserId, true);
 
@@ -416,7 +419,7 @@ class CourseRestorer
                                 $document_id,
                                 'FolderCreated',
                                 $insertUserId,
-                                $toGroupId,
+                                $groupInfo,
                                 $toUserId,
                                 null,
                                 null,
@@ -468,6 +471,7 @@ class CourseRestorer
 
                                     $insertUserId = $this->checkUserId($insertUserId);
                                     $toUserId = $this->checkUserId($toUserId, true);
+                                    $groupInfo = $this->checkGroupId($toGroupId);
 
                                     api_item_property_update(
                                         $course_info,
@@ -475,7 +479,7 @@ class CourseRestorer
                                         $document_id,
                                         'DocumentAdded',
                                         $insertUserId,
-                                        $toGroupId,
+                                        $groupInfo,
                                         $toUserId,
                                         null,
                                         null,
@@ -514,6 +518,7 @@ class CourseRestorer
 
                                     $insertUserId = $this->checkUserId($insertUserId);
                                     $toUserId = $this->checkUserId($toUserId, true);
+                                    $groupInfo = $this->checkGroupId($toGroupId);
 
                                     api_item_property_update(
                                         $course_info,
@@ -521,7 +526,7 @@ class CourseRestorer
                                         $obj->id,
                                         'default',
                                         $insertUserId,
-                                        $toGroupId,
+                                        $groupInfo,
                                         $toUserId,
                                         null,
                                         null,
@@ -694,6 +699,7 @@ class CourseRestorer
 
                                     $insertUserId = $this->checkUserId($insertUserId);
                                     $toUserId = $this->checkUserId($toUserId, true);
+                                    $groupInfo = $this->checkGroupId($toGroupId);
 
                                     api_item_property_update(
                                         $course_info,
@@ -701,7 +707,7 @@ class CourseRestorer
                                         $document_id,
                                         'DocumentAdded',
                                         $insertUserId,
-                                        $toGroupId,
+                                        $groupInfo,
                                         $toUserId,
                                         null,
                                         null,
@@ -755,6 +761,7 @@ class CourseRestorer
 
                                         $insertUserId = $this->checkUserId($insertUserId);
                                         $toUserId = $this->checkUserId($toUserId, true);
+                                        $groupInfo = $this->checkGroupId($toGroupId);
 
                                         api_item_property_update(
                                             $course_info,
@@ -762,7 +769,7 @@ class CourseRestorer
                                             $document_id,
                                             'DocumentAdded',
                                             $insertUserId,
-                                            $toGroupId,
+                                            $groupInfo,
                                             $toUserId,
                                             null,
                                             null,
@@ -821,6 +828,7 @@ class CourseRestorer
 
                                 $insertUserId = $this->checkUserId($insertUserId);
                                 $toUserId = $this->checkUserId($toUserId, true);
+                                $groupInfo = $this->checkGroupId($toGroupId);
 
                                 api_item_property_update(
                                     $course_info,
@@ -828,7 +836,7 @@ class CourseRestorer
                                     $document_id,
                                     'DocumentAdded',
                                     $insertUserId,
-                                    $toGroupId,
+                                    $groupInfo,
                                     $toUserId,
                                     null,
                                     null,
@@ -897,6 +905,7 @@ class CourseRestorer
 
                         $insertUserId = $this->checkUserId($insertUserId);
                         $toUserId = $this->checkUserId($toUserId, true);
+                        $groupInfo = $this->checkGroupId($toGroupId);
 
                         api_item_property_update(
                             $course_info,
@@ -904,7 +913,7 @@ class CourseRestorer
                             $document_id,
                             'DocumentAdded',
                             $insertUserId,
-                            $toGroupId,
+                            $groupInfo,
                             $toUserId,
                             null,
                             null,
@@ -3498,6 +3507,15 @@ class CourseRestorer
         }
     }
 
+    /**
+     * @param int $groupId
+     * @return array
+     */
+    public function checkGroupId($groupId)
+    {
+        return \GroupManager::get_group_properties($groupId);
+    }
+
     /**
      * Check if user exist otherwise use current user
      * @param int $userId