Minor - fix php warning, set course info

pull/2458/head
jmontoyaa 8 years ago
parent 27dcf0a73d
commit fd54e7b97a
  1. 2
      main/document/create_paint.php
  2. 24
      main/document/edit_paint.php
  3. 71
      main/document/save_pixlr.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'));

@ -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 '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.'&'.api_
Display::return_icon('edit.png', get_lang('Rename').'/'.get_lang('Comment'), '', ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
///pixlr
// pixlr
$title = $file; //disk name. No sql name because pixlr return this when save
$pixlr_code_translation_table = ['' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn'];
$langpixlr = api_get_language_isocode();
$langpixlr = isset($pixlr_code_translation_table[$langpixlr]) ? $pixlredit_code_translation_table[$langpixlr] : $langpixlr;
$loc = $langpixlr; // deprecated ?? TODO:check pixlr read user browser
@ -212,12 +212,12 @@ $pixlr_url = '//pixlr.com/editor/?title='.$title.'&image='.$image.'&loc='.$loc.'
<script>
document.write ('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo $pixlr_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
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;

@ -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')));
}
}
}

Loading…
Cancel
Save