Updating gif + some minor validations BT#2784

skala
Julio Montoya 15 years ago
parent 9f8dbf8eeb
commit 56988cb3fe
  1. 293
      main/inc/lib/document.lib.php
  2. 5
      main/inc/lib/fileUpload.lib.php
  3. BIN
      main/inc/lib/javascript/jquery-upload/pbar-ani.gif

@ -1830,120 +1830,153 @@ class DocumentManager {
if (isset($files['file'])) { if (isset($files['file'])) {
$upload_ok = process_uploaded_file($files['file']); $upload_ok = process_uploaded_file($files['file']);
if ($upload_ok) { if ($upload_ok) {
// File got on the server without problems, now process it // File got on the server without problems, now process it
$new_path = handle_uploaded_document($course_info, $files['file'], $base_work_dir, $path, api_get_user_id(), api_get_group_id(), null, $max_filled_space, $unzip, $if_exists, $show_output); $new_path = handle_uploaded_document($course_info, $files['file'], $base_work_dir, $path, api_get_user_id(), api_get_group_id(), null, $max_filled_space, $unzip, $if_exists, $show_output);
if ($new_path) {
$new_comment = isset($title) ? trim($comment) : ''; $new_comment = isset($title) ? trim($comment) : '';
$new_title = isset($title) ? trim($title) : ''; $new_title = isset($title) ? trim($title) : '';
$docid = DocumentManager::get_document_id($course_info, $new_path); $docid = DocumentManager::get_document_id($course_info, $new_path);
if ($new_path && ($new_comment || $new_title)) { if ($new_path && ($new_comment || $new_title)) {
if (!empty($docid)) { if (!empty($docid)) {
$table_document = Database::get_course_table(TABLE_DOCUMENT); $table_document = Database::get_course_table(TABLE_DOCUMENT);
$ct = ''; $ct = '';
if ($new_comment) $ct .= ", comment='$new_comment'"; if ($new_comment) $ct .= ", comment='$new_comment'";
if ($new_title) $ct .= ", title='$new_title'"; if ($new_title) $ct .= ", title='$new_title'";
Database::query("UPDATE $table_document SET ".substr($ct, 1)." WHERE id = $docid"); Database::query("UPDATE $table_document SET ".substr($ct, 1)." WHERE id = $docid");
}
} }
}
// Showing message when sending zip files // Showing message when sending zip files
if ($new_path === true && $unzip == 1 && $show_output) { if ($new_path === true && $unzip == 1 && $show_output) {
Display::display_confirmation_message(get_lang('UplUploadSucceeded').'<br />', false); Display::display_confirmation_message(get_lang('UplUploadSucceeded').'<br />', false);
} }
//@todo move this code somewhere else a.k.a Rework search module //@todo move this code somewhere else a.k.a Rework search module
if ((api_get_setting('search_enabled') == 'true') && $index_document && !empty($docid)) { if ((api_get_setting('search_enabled') == 'true') && $index_document && !empty($docid)) {
$table_document = Database::get_course_table(TABLE_DOCUMENT); $table_document = Database::get_course_table(TABLE_DOCUMENT);
$result = Database::query("SELECT * FROM $table_document WHERE id = '$docid' LIMIT 1"); $result = Database::query("SELECT * FROM $table_document WHERE id = '$docid' LIMIT 1");
if (Database::num_rows($result) == 1) { if (Database::num_rows($result) == 1) {
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$doc_path = api_get_path(SYS_COURSE_PATH).$courseDir.$row['path']; $doc_path = api_get_path(SYS_COURSE_PATH).$courseDir.$row['path'];
//TODO: mime_content_type is deprecated, fileinfo php extension is enabled by default as of PHP 5.3.0 //TODO: mime_content_type is deprecated, fileinfo php extension is enabled by default as of PHP 5.3.0
// now versions of PHP on Debian testing(5.2.6-5) and Ubuntu(5.2.6-2ubuntu) are lower, so wait for a while // now versions of PHP on Debian testing(5.2.6-5) and Ubuntu(5.2.6-2ubuntu) are lower, so wait for a while
$doc_mime = mime_content_type($doc_path); $doc_mime = mime_content_type($doc_path);
//echo $doc_mime; //echo $doc_mime;
//TODO: more mime types //TODO: more mime types
$allowed_mime_types = array('text/plain', 'application/pdf', 'application/postscript', 'application/msword', 'text/html', 'text/rtf', 'application/vnd.ms-powerpoint', 'application/vnd.ms-excel'); $allowed_mime_types = array('text/plain', 'application/pdf', 'application/postscript', 'application/msword', 'text/html', 'text/rtf', 'application/vnd.ms-powerpoint', 'application/vnd.ms-excel');
// mime_content_type does not detect correctly some formats that are going to be supported for index, so an extensions array is used by the moment // mime_content_type does not detect correctly some formats that are going to be supported for index, so an extensions array is used by the moment
if (empty($doc_mime)) { if (empty($doc_mime)) {
$allowed_extensions = array('ppt', 'pps', 'xls'); $allowed_extensions = array('ppt', 'pps', 'xls');
$extensions = preg_split("/[\/\\.]/", $doc_path) ; $extensions = preg_split("/[\/\\.]/", $doc_path) ;
$doc_ext = strtolower($extensions[count($extensions) - 1]); $doc_ext = strtolower($extensions[count($extensions) - 1]);
if (in_array($doc_ext, $allowed_extensions)) { if (in_array($doc_ext, $allowed_extensions)) {
switch ($doc_ext) { switch ($doc_ext) {
case 'ppt': case 'ppt':
case 'pps': case 'pps':
$doc_mime = 'application/vnd.ms-powerpoint'; $doc_mime = 'application/vnd.ms-powerpoint';
break; break;
case 'xls': case 'xls':
$doc_mime = 'application/vnd.ms-excel'; $doc_mime = 'application/vnd.ms-excel';
break; break;
}
} }
} }
}
//@todo move this nightmare in a search controller or something like that!!! J.M //@todo move this nightmare in a search controller or something like that!!! J.M
if (in_array($doc_mime, $allowed_mime_types) && isset($index_document) && $index_document) { if (in_array($doc_mime, $allowed_mime_types) && isset($index_document) && $index_document) {
$file_title = $row['title']; $file_title = $row['title'];
$file_content = self::get_text_content($doc_path, $doc_mime); $file_content = self::get_text_content($doc_path, $doc_mime);
$courseid = api_get_course_id(); $courseid = api_get_course_id();
$lang = isset($_POST['language']) ? Database::escape_string($_POST['language']) : 'english'; $lang = isset($_POST['language']) ? Database::escape_string($_POST['language']) : 'english';
require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php'; require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php'; require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
$ic_slide = new IndexableChunk(); $ic_slide = new IndexableChunk();
$ic_slide->addValue('title', $file_title); $ic_slide->addValue('title', $file_title);
$ic_slide->addCourseId($courseid); $ic_slide->addCourseId($courseid);
$ic_slide->addToolId(TOOL_DOCUMENT); $ic_slide->addToolId(TOOL_DOCUMENT);
$xapian_data = array( $xapian_data = array(
SE_COURSE_ID => $courseid, SE_COURSE_ID => $courseid,
SE_TOOL_ID => TOOL_DOCUMENT, SE_TOOL_ID => TOOL_DOCUMENT,
SE_DATA => array('doc_id' => (int)$docid), SE_DATA => array('doc_id' => (int)$docid),
SE_USER => (int)api_get_user_id(), SE_USER => (int)api_get_user_id(),
); );
$ic_slide->xapian_data = serialize($xapian_data); $ic_slide->xapian_data = serialize($xapian_data);
$di = new DokeosIndexer(); $di = new DokeosIndexer();
$di->connectDb(null, null, $lang); $di->connectDb(null, null, $lang);
$specific_fields = get_specific_field_list(); $specific_fields = get_specific_field_list();
// process different depending on what to do if file exists // process different depending on what to do if file exists
/** /**
* FIXME: Find a way to really verify if the file had been * FIXME: Find a way to really verify if the file had been
* overwriten. Now all work is done at * overwriten. Now all work is done at
* handle_uploaded_document() and it's difficult to verify it * handle_uploaded_document() and it's difficult to verify it
*/ */
if (!empty($if_exists) && $if_exists == 'overwrite') { if (!empty($if_exists) && $if_exists == 'overwrite') {
// overwrite the file on search engine // overwrite the file on search engine
// actually, it consists on delete terms from db, insert new ones, create a new search engine document, and remove the old one // actually, it consists on delete terms from db, insert new ones, create a new search engine document, and remove the old one
// Get search_did // Get search_did
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1'; $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
$sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid); $sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid);
$res = Database::query($sql); $res = Database::query($sql);
if (Database::num_rows($res) > 0) { if (Database::num_rows($res) > 0) {
$se_ref = Database::fetch_array($res); $se_ref = Database::fetch_array($res);
$di->remove_document((int)$se_ref['search_did']); $di->remove_document((int)$se_ref['search_did']);
$all_specific_terms = '';
foreach ($specific_fields as $specific_field) {
delete_all_specific_field_value($courseid, $specific_field['id'], TOOL_DOCUMENT, $docid);
// Update search engine
$sterms = trim($_REQUEST[$specific_field['code']]);
$all_specific_terms .= ' '. $sterms;
$sterms = explode(',', $sterms);
foreach ($sterms as $sterm) {
$sterm = trim($sterm);
if (!empty($sterm)) {
$ic_slide->addTerm($sterm, $specific_field['code']);
add_specific_field_value($specific_field['id'], $courseid, TOOL_DOCUMENT, $docid, $value);
}
}
}
// Add terms also to content to make terms findable by probabilistic search
$file_content = $all_specific_terms .' '. $file_content;
$ic_slide->addValue('content', $file_content);
$di->addChunk($ic_slide);
// Index and return a new search engine document id
$did = $di->index();
if ($did) {
// update the search_did on db
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'UPDATE %s SET search_did=%d WHERE id=%d LIMIT 1';
$sql = sprintf($sql, $tbl_se_ref, (int)$did, (int)$se_ref['id']);
Database::query($sql);
}
}
} else {
// Add all terms
$all_specific_terms = ''; $all_specific_terms = '';
foreach ($specific_fields as $specific_field) { foreach ($specific_fields as $specific_field) {
delete_all_specific_field_value($courseid, $specific_field['id'], TOOL_DOCUMENT, $docid); if (isset($_REQUEST[$specific_field['code']])) {
// Update search engine $sterms = trim($_REQUEST[$specific_field['code']]);
$sterms = trim($_REQUEST[$specific_field['code']]); $all_specific_terms .= ' '. $sterms;
$all_specific_terms .= ' '. $sterms; if (!empty($sterms)) {
$sterms = explode(',', $sterms); $sterms = explode(',', $sterms);
foreach ($sterms as $sterm) { foreach ($sterms as $sterm) {
$sterm = trim($sterm); $ic_slide->addTerm(trim($sterm), $specific_field['code']);
if (!empty($sterm)) { add_specific_field_value($specific_field['id'], $courseid, TOOL_DOCUMENT, $docid, $sterm);
$ic_slide->addTerm($sterm, $specific_field['code']); }
add_specific_field_value($specific_field['id'], $courseid, TOOL_DOCUMENT, $docid, $value);
} }
} }
} }
@ -1951,62 +1984,32 @@ class DocumentManager {
$file_content = $all_specific_terms .' '. $file_content; $file_content = $all_specific_terms .' '. $file_content;
$ic_slide->addValue('content', $file_content); $ic_slide->addValue('content', $file_content);
$di->addChunk($ic_slide); $di->addChunk($ic_slide);
// Index and return a new search engine document id // Index and return search engine document id
$did = $di->index(); $did = $di->index();
if ($did) { if ($did) {
// update the search_did on db // Save it to db
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'UPDATE %s SET search_did=%d WHERE id=%d LIMIT 1'; $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
$sql = sprintf($sql, $tbl_se_ref, (int)$did, (int)$se_ref['id']); VALUES (NULL , \'%s\', \'%s\', %s, %s)';
$sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid, $did);
Database::query($sql); Database::query($sql);
} }
}
} else {
// Add all terms
$all_specific_terms = '';
foreach ($specific_fields as $specific_field) {
if (isset($_REQUEST[$specific_field['code']])) {
$sterms = trim($_REQUEST[$specific_field['code']]);
$all_specific_terms .= ' '. $sterms;
if (!empty($sterms)) {
$sterms = explode(',', $sterms);
foreach ($sterms as $sterm) {
$ic_slide->addTerm(trim($sterm), $specific_field['code']);
add_specific_field_value($specific_field['id'], $courseid, TOOL_DOCUMENT, $docid, $sterm);
}
}
}
}
// Add terms also to content to make terms findable by probabilistic search
$file_content = $all_specific_terms .' '. $file_content;
$ic_slide->addValue('content', $file_content);
$di->addChunk($ic_slide);
// Index and return search engine document id
$did = $di->index();
if ($did) {
// Save it to db
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
VALUES (NULL , \'%s\', \'%s\', %s, %s)';
$sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid, $did);
Database::query($sql);
} }
} }
} }
} }
}
// Check for missing images in html files // Check for missing images in html files
$missing_files = check_for_missing_files($base_work_dir.$new_path); $missing_files = check_for_missing_files($base_work_dir.$new_path);
if ($missing_files && $show_output) { if ($missing_files && $show_output) {
// Show a form to upload the missing files // Show a form to upload the missing files
Display::display_normal_message(build_missing_files_form($missing_files, $path, $files['file']['name']), false); Display::display_normal_message(build_missing_files_form($missing_files, $path, $files['file']['name']), false);
} }
if (!empty($docid) && is_numeric($docid)) { if (!empty($docid) && is_numeric($docid)) {
$document_data = self::get_document_data_by_id($docid, $course_info['code']); $document_data = self::get_document_data_by_id($docid, $course_info['code']);
return $document_data; return $document_data;
}
} }
} }
} }

@ -137,10 +137,11 @@ function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upl
// Add extension to files without one (if possible) // Add extension to files without one (if possible)
$uploaded_file['name'] = add_ext_on_mime($uploaded_file['name'], $uploaded_file['type']); $uploaded_file['name'] = add_ext_on_mime($uploaded_file['name'], $uploaded_file['type']);
$current_session_id = api_get_session_id(); $current_session_id = api_get_session_id();
// Check if there is enough space to save the file // Check if there is enough space to save the file
if (!enough_space($uploaded_file['size'], $maxFilledSpace)) { if (!enough_space($uploaded_file['size'], $maxFilledSpace)) {
if ($output){ if ($output) {
Display::display_error_message(get_lang('UplNotEnoughSpace')); Display::display_error_message(get_lang('UplNotEnoughSpace'));
} }
return false; return false;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 297 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Loading…
Cancel
Save