Actualización
This commit is contained in:
60
main/plagiarism/compilatio/compiladmin.php
Normal file
60
main/plagiarism/compilatio/compiladmin.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
exit;
|
||||
|
||||
require_once '../../inc/global.inc.php';
|
||||
|
||||
$use_space = number_format($quotas->usedSpace / 1000000, 2);
|
||||
$total_space = $quotas->space / 1000000;
|
||||
|
||||
echo "<h3>".get_lang('CompilatioDescription')."</h3>";
|
||||
|
||||
echo "<b>"
|
||||
.get_lang('CompilatioQuota')
|
||||
.":"
|
||||
." </b><br>"
|
||||
.sprintf(get_lang('CompilatioCreditXOnY'), $quotas->usedCredits, $quotas->credits);
|
||||
|
||||
?>
|
||||
<br><br>
|
||||
<?php
|
||||
if (!isset($_GET['action'])) {
|
||||
?>
|
||||
<body style="margin:0px;padding:0px">
|
||||
<form style="margin:0px;" method="GET">
|
||||
<input type="submit" name="action" value="Test de Connexion SOAP">
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
echo get_lang('CompilatioConnectionTestSoap')."<br>";
|
||||
echo "1) ".get_lang('CompilatioServerConnection')."<br>";
|
||||
|
||||
try {
|
||||
$compilatio = new Compilatio();
|
||||
} catch (Exception $e) {
|
||||
$compilatio = null;
|
||||
echo get_lang('CompilatioNoConnection')."<br>";
|
||||
echo get_lang('CompilatioParamVerification')."<br>";
|
||||
}
|
||||
|
||||
if ($compilatio) {
|
||||
echo get_lang('CompilatioConnectionSuccessful')."<br>";
|
||||
echo "2) ".get_lang('CompilatioSendTextToServer')."<br>";
|
||||
$text = sprintf(get_lang('CompilatioTextSendingTestKeyX'), $compilatio->getKey());
|
||||
try {
|
||||
$id_compi = $compilatio->sendDoc(
|
||||
'Doc de test',
|
||||
'test',
|
||||
'test',
|
||||
$text
|
||||
);
|
||||
echo get_lang('CompilatioSuccessfulTransfer')."<br>";
|
||||
} catch (Exception $e) {
|
||||
echo get_lang('CompilatioFailedTransfer')."<br>";
|
||||
echo get_lang('CompilatioParamVerification')."<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
BIN
main/plagiarism/compilatio/compilatio.gif
Normal file
BIN
main/plagiarism/compilatio/compilatio.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
25
main/plagiarism/compilatio/compilatio_ajax.php
Normal file
25
main/plagiarism/compilatio/compilatio_ajax.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once '../../inc/global.inc.php';
|
||||
|
||||
api_protect_course_script();
|
||||
|
||||
if (isset($_GET['workid'])) {
|
||||
$workIdList = $_GET['workid']; // list of workid separate by the :
|
||||
$workList = explode('a', $workIdList);
|
||||
$workList = array_map('intval', $workList);
|
||||
$workList = array_filter($workList);
|
||||
try {
|
||||
$compilatio = new Compilatio();
|
||||
$result = '';
|
||||
foreach ($workList as $workId) {
|
||||
if (!empty($workId)) {
|
||||
$result .= $compilatio->giveWorkIdState($workId);
|
||||
}
|
||||
}
|
||||
echo $result;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
BIN
main/plagiarism/compilatio/compilatio_na.gif
Normal file
BIN
main/plagiarism/compilatio/compilatio_na.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 778 B |
60
main/plagiarism/compilatio/download.php
Normal file
60
main/plagiarism/compilatio/download.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
exit;
|
||||
|
||||
/**
|
||||
* This file is responsible for passing requested documents to the browser.
|
||||
* Html files are parsed to fix a few problems with URLs,
|
||||
* but this code will hopefully be replaced soon by an Apache URL
|
||||
* rewrite mechanism.
|
||||
*/
|
||||
session_cache_limiter('public');
|
||||
require_once '../../inc/global.inc.php';
|
||||
$current_course_tool = TOOL_STUDENTPUBLICATION;
|
||||
$this_section = SECTION_COURSES;
|
||||
|
||||
// IMPORTANT to avoid caching of documents
|
||||
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
|
||||
header('Cache-Control: public');
|
||||
header('Pragma: no-cache');
|
||||
|
||||
api_protect_course_script(true);
|
||||
|
||||
$id = (int) $_GET['id'];
|
||||
$courseInfo = api_get_course_info();
|
||||
|
||||
if (empty($courseInfo)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
|
||||
|
||||
if (!empty($courseInfo['real_id'])) {
|
||||
$courseId = $courseInfo['real_id'];
|
||||
$sql = "SELECT * FROM $tbl_student_publication
|
||||
WHERE c_id = $courseId AND id = $id";
|
||||
$result = Database::query($sql);
|
||||
if ($result && Database::num_rows($result)) {
|
||||
$row = Database::fetch_array($result, 'ASSOC');
|
||||
$full_file_name = $courseInfo['course_sys_path'].$row['url'];
|
||||
|
||||
$item_info = api_get_item_property_info($courseId, 'work', $row['id']);
|
||||
if (empty($item_info)) {
|
||||
exit;
|
||||
}
|
||||
if ($courseInfo['show_score'] == 0 || $item_info['visibility'] == 1 && $row['accepted'] == 1 &&
|
||||
($row['user_id'] == api_get_user_id() || api_is_allowed_to_edit())
|
||||
) {
|
||||
$title = str_replace(' ', '_', $row['title']);
|
||||
Event::event_download($title);
|
||||
if (Security::check_abs_path($full_file_name, $courseInfo['course_sys_path'])) {
|
||||
DocumentManager::file_send_for_download($full_file_name, true, $title);
|
||||
}
|
||||
} else {
|
||||
api_not_allowed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
208
main/plagiarism/compilatio/upload.php
Normal file
208
main/plagiarism/compilatio/upload.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once '../../inc/global.inc.php';
|
||||
require_once '../../work/work.lib.php';
|
||||
|
||||
ini_set('soap.wsdl_cache_enabled', 0);
|
||||
ini_set('default_socket_timeout', '1000');
|
||||
|
||||
api_set_more_memory_and_time_limits();
|
||||
|
||||
api_protect_course_script();
|
||||
|
||||
$courseId = api_get_course_int_id();
|
||||
$courseInfo = api_get_course_info();
|
||||
|
||||
try {
|
||||
$compilatio = new Compilatio();
|
||||
} catch (Exception $e) {
|
||||
$message = Display::return_message($e->getMessage(), 'error');
|
||||
|
||||
exit($message);
|
||||
}
|
||||
|
||||
/* if we have to upload severals documents*/
|
||||
if (isset($_REQUEST['type']) && 'multi' === $_REQUEST['type']) {
|
||||
$docs = explode('a', $_REQUEST['doc']);
|
||||
for ($k = 0; $k < count($docs) - 1; $k++) {
|
||||
$documentId = 0;
|
||||
if (isset($docs[$k])) {
|
||||
$documentId = (int) $docs[$k];
|
||||
}
|
||||
|
||||
/**
|
||||
* File problem in the url field that no longer have the file extension,
|
||||
* Compilatio's server refuse the files
|
||||
* we renames in the FS and the database with the file extension that is found in the title field.
|
||||
*/
|
||||
compilatioUpdateWorkDocument($documentId, $courseId);
|
||||
|
||||
$compilatioId = $compilatio->getCompilatioId($documentId, $courseId);
|
||||
if (empty($compilatioId)) {
|
||||
$workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
|
||||
$query = "SELECT * FROM $workTable WHERE id= $documentId AND c_id= $courseId";
|
||||
$sqlResult = Database::query($query);
|
||||
$doc = Database::fetch_object($sqlResult);
|
||||
if ($doc) {
|
||||
try {
|
||||
$compilatioId = $compilatio->sendDoc(
|
||||
$doc->title,
|
||||
$doc->description,
|
||||
$doc->url,
|
||||
$courseInfo['course_sys_path'].$doc->url
|
||||
);
|
||||
|
||||
/*we associate in the database the document chamilo to the document compilatio*/
|
||||
$compilatio->saveDocument($courseId, $doc->id, $compilatioId);
|
||||
sleep(10);
|
||||
$compilatio->startAnalyse($compilatioId);
|
||||
} catch (Exception $e) {
|
||||
$message = Display::return_message($e->getMessage(), 'error');
|
||||
|
||||
exit($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$documentId = isset($_GET['doc']) ? $_GET['doc'] : 0;
|
||||
sendDocument($documentId, $courseInfo);
|
||||
}
|
||||
|
||||
function sendDocument($documentId, $courseInfo)
|
||||
{
|
||||
if (empty($courseInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$courseId = $courseInfo['real_id'] ?? 0;
|
||||
$documentId = (int) $documentId;
|
||||
|
||||
if (empty($courseId) || empty($documentId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
compilatioUpdateWorkDocument($documentId, $courseId);
|
||||
$workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
|
||||
$query = "SELECT * FROM $workTable
|
||||
WHERE id = $documentId AND c_id= $courseId";
|
||||
$sqlResult = Database::query($query);
|
||||
$doc = Database::fetch_object($sqlResult);
|
||||
|
||||
$filePath = $courseInfo['course_sys_path'].$doc->url;
|
||||
|
||||
try {
|
||||
$compilatio = new Compilatio();
|
||||
|
||||
$compilatioId = $compilatio->sendDoc(
|
||||
$doc->title,
|
||||
$doc->description,
|
||||
$doc->url,
|
||||
$filePath
|
||||
);
|
||||
|
||||
$compilatio->saveDocument($courseId, $doc->id, $compilatioId);
|
||||
sleep(10);
|
||||
$compilatio->startAnalyse($compilatioId);
|
||||
echo Display::return_message(get_lang('Uploaded'), 'success');
|
||||
} catch (Exception $e) {
|
||||
echo Display::return_message($e->getMessage(), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function for show and recovery the extension from a file.
|
||||
*
|
||||
* @param $docId
|
||||
* @param $courseId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function workDocExtension($docId, $courseId)
|
||||
{
|
||||
$dbTitle = getWorkTitle($docId, $courseId);
|
||||
$res = getFileExtension($dbTitle);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getFileExtension($filename)
|
||||
{
|
||||
$res = '';
|
||||
preg_match("/.*\.([^.]+)/", $filename, $dbTitle);
|
||||
if (count($dbTitle) > 1) {
|
||||
$res = $dbTitle[1];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getWorkTitle($docId, $courseId)
|
||||
{
|
||||
$docId = (int) $docId;
|
||||
$courseId = (int) $courseId;
|
||||
|
||||
$workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
|
||||
$sql = "SELECT title FROM $workTable
|
||||
WHERE c_id= $courseId AND id = $docId";
|
||||
$res = Database::query($sql);
|
||||
if (Database::num_rows($res) > 0) {
|
||||
$data = Database::fetch_array($res);
|
||||
$res = $data['title'];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getFilename($txt)
|
||||
{
|
||||
$res = $txt;
|
||||
preg_match('|.*/([^/]+)|', $txt, $urlList);
|
||||
if (count($urlList) > 0) {
|
||||
$res = $urlList[1];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getWorkFolder($txt)
|
||||
{
|
||||
$res = '';
|
||||
preg_match('|(.*/)[^/]+|', $txt, $urlList);
|
||||
if (count($urlList) > 0) {
|
||||
$res = $urlList[1];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function compilatioUpdateWorkDocument($docId, $courseId)
|
||||
{
|
||||
$_course = api_get_course_info();
|
||||
|
||||
$docId = (int) $docId;
|
||||
$courseId = (int) $courseId;
|
||||
|
||||
$workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
|
||||
$extensionFile = workDocExtension($docId, $courseId);
|
||||
$urlFile = get_work_path($docId);
|
||||
$filename = getFilename($urlFile);
|
||||
$work_folder = getWorkFolder($urlFile);
|
||||
$urlFile_ext = getFileExtension($urlFile);
|
||||
$coursePath = $_course['course_sys_path'];
|
||||
$workTitle = getWorkTitle($docId, $courseId);
|
||||
|
||||
if ($extensionFile != '' && $urlFile_ext == '') {
|
||||
/* Rename the files in the FS with the extension */
|
||||
$shortFilename = $filename;
|
||||
$cleanWorkTitle = api_replace_dangerous_char($workTitle);
|
||||
$newestFilename = $shortFilename.'_'.$cleanWorkTitle;
|
||||
rename($coursePath.$urlFile, $coursePath.$work_folder.$newestFilename);
|
||||
/*rename the db's input with the extension*/
|
||||
$sql = "UPDATE $workTable SET url='".$work_folder.$newestFilename."'
|
||||
WHERE c_id=$courseId AND id=$docId";
|
||||
Database::query($sql);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user