From fd54e7b97a7aefa2f06965dd1b4c729d079bcb3d Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 13 Feb 2018 13:56:18 +0100 Subject: [PATCH] Minor - fix php warning, set course info --- main/document/create_paint.php | 2 +- main/document/edit_paint.php | 24 ++++++------ main/document/save_pixlr.php | 71 +++++++++++++++++++--------------- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/main/document/create_paint.php b/main/document/create_paint.php index 7695f5b504..9247145664 100755 --- a/main/document/create_paint.php +++ b/main/document/create_paint.php @@ -37,7 +37,6 @@ if (empty($document_data)) { $document_id = $document_data['id']; $dir = $document_data['path']; -// $dir = isset($_GET['dir']) ? Security::remove_XSS($_GET['dir']) : Security::remove_XSS($_POST['dir']); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); // path for pixlr save @@ -45,6 +44,7 @@ $paintDir = Security::remove_XSS($dir); if (empty($paintDir)) { $paintDir = '/'; } + Session::write('paint_dir', $paintDir); Session::write('paint_file', get_lang('NewImage')); diff --git a/main/document/edit_paint.php b/main/document/edit_paint.php index a84d22f723..ea42cf52d6 100755 --- a/main/document/edit_paint.php +++ b/main/document/edit_paint.php @@ -19,6 +19,7 @@ $groupRights = Session::read('group_member_with_upload_rights'); api_protect_course_script(true); api_block_anonymous_users(); +$_course = api_get_course_info(); $groupId = api_get_group_id(); $document_data = DocumentManager::get_document_data_by_id( $_GET['id'], @@ -36,7 +37,8 @@ if (empty($document_data)) { $my_cur_dir_path = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null; } -$dir = str_replace('\\', '/', $dir); //and urlencode each url $curdirpath (hack clean $curdirpath under Windows - Bug #3261) +//and urlencode each url $curdirpath (hack clean $curdirpath under Windows - Bug #3261) +$dir = str_replace('\\', '/', $dir); /* Constants & Variables */ $current_session_id = api_get_session_id(); @@ -53,9 +55,7 @@ $filename = $temp_file[0]; $nameTools = get_lang('EditDocument').': '.$filename; $courseDir = $_course['path'].'/document'; $is_allowed_to_edit = api_is_allowed_to_edit(null, true); - -/* Other initialization code */ - +/* Other initialization code */ /* Please, do not modify this dirname formatting */ if (strstr($dir, '..')) { $dir = '/'; @@ -131,9 +131,9 @@ echo '<p>Sorry, your browser does not handle frames</p>'); function resizeIframe() { - var height = window.innerHeight; - //max lower size - if (height<600) { - height=600; - } - document.getElementById('frame').style.height = height +"px"; + var height = window.innerHeight; + //max lower size + if (height<600) { + height=600; + } + document.getElementById('frame').style.height = height +"px"; }; document.getElementById('frame').onload = resizeIframe; window.onresize = resizeIframe; diff --git a/main/document/save_pixlr.php b/main/document/save_pixlr.php index d3b2f859d4..3dc201cace 100755 --- a/main/document/save_pixlr.php +++ b/main/document/save_pixlr.php @@ -27,6 +27,12 @@ if (empty($paintDir)) { exit; } +$_course = api_get_course_info(); +if (empty($_course)) { + echo 'Course not set'; + exit; +} + // pixlr return $filename = Security::remove_XSS($_GET['title']); //The user preferred file name of the image. $extension = Security::remove_XSS($_GET['type']); //The image type, "pdx", "jpg", "bmp" or "png". @@ -37,7 +43,6 @@ $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::read('paint_dir'); $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; $saveDir = $dirBaseDocuments.$paintDir; $contents = file_get_contents($urlcontents); @@ -101,7 +106,6 @@ if (strpos($current_mime, 'image') === false) { exit; } - //path, file and title $paintFileName = $filename.'.'.$extension; $title = $title.'.'.$extension; @@ -125,24 +129,26 @@ if (empty($temp_file_2delete)) { $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 - ); + $documentId = add_document($_course, $paintDir.'/'.$paintFileName, 'file', filesize($documentPath), $title); + if ($documentId) { + api_item_property_update( + $_course, + TOOL_DOCUMENT, + $doc_id, + 'DocumentAdded', + $_user['user_id'], + $groupInfo, + null, + null, + null, + $current_session_id + ); + Display::addFlash(Display::return_message(get_lang('Saved'))); + } } else { // Update $documentPath = $saveDir.'/'.$paintFileName; @@ -155,7 +161,7 @@ if (empty($temp_file_2delete)) { exit; } if ($paintFile == $paintFileName) { - $document_id = DocumentManager::get_document_id($_course, $relativeUrlPath.'/'.$paintFileName); + $document_id = DocumentManager::get_document_id($_course, $paintDir.'/'.$paintFileName); update_existing_document($_course, $document_id, filesize($documentPath), null); api_item_property_update( $_course, @@ -171,25 +177,28 @@ if (empty($temp_file_2delete)) { ); } else { //add a new document - $doc_id = add_document( + $documentId = add_document( $_course, - $relativeUrlPath.'/'.$paintFileName, + $paintDir.'/'.$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 - ); + if ($documentId) { + api_item_property_update( + $_course, + TOOL_DOCUMENT, + $doc_id, + 'DocumentAdded', + $_user['user_id'], + $groupInfo, + null, + null, + null, + $current_session_id + ); + Display::addFlash(Display::return_message(get_lang('Updated'))); + } } }