Browse Source

Add fixes to compilation see BT#15698

Julio Montoya 5 years ago
parent
commit
106100a53d

+ 0 - 17
main/admin/configure_extensions.php

@@ -341,23 +341,6 @@ Display::display_header($nameTool);
         </div>
     </div>
      */ ?>
-
-        <!-- COMPILATIO JLUCAS -->
-        <div id="main_compilatio">
-            <div id="extension_header_compilatio" class="accordion_header">
-                <a href="#"><?php echo get_lang('compilatioPlagiarismDetector');?></a>
-            </div>
-            <div id="extension_content_compilatio" style="display:none;padding:0;width:780px;" class="accordion_content">
-                <table width="100%" cellpadding="0" cellspacing="0">
-                    <tr>
-                        <td align="center">
-                            <iframe frameborder="0" width="780" height="480" src="../plagiarism/compilatio/compiladmin.php"></iframe>
-                        </td>
-                    </tr>
-                </table>
-            </div>
-        </div>
-
 </div><!-- /content -->
 
 <?php

+ 88 - 95
main/plagiarism/compilatio/Compilatio.php → main/inc/lib/Compilatio.php

@@ -32,11 +32,17 @@ class Compilatio
         if (empty(api_get_configuration_value('allow_compilatio_tool')) ||
             empty(api_get_configuration_value('compilatio_tool'))
         ) {
-            throw new Exception('Compilation not available');
+            throw new Exception('Compilatio not available');
         }
 
         $settings = api_get_configuration_value('compilatio_tool');
 
+        if (isset($settings['settings'])) {
+            $settings = $settings['settings'];
+        } else {
+            throw new Exception('Compilatio config available');
+        }
+
         $key = $this->key = $settings['key'];
         $urlsoap = $settings['soap_url'];
         $proxyHost = $this->proxyHost = $settings['proxy_host'];
@@ -46,6 +52,7 @@ class Compilatio
         $this->wgetUri = $settings['wget_uri'];
         $this->wgetLogin = $settings['wget_login'];
         $this->wgetPassword = $settings['wget_password'];
+        $soapVersion = 2;
 
         try {
             if (!empty($key)) {
@@ -54,7 +61,7 @@ class Compilatio
                     if (!empty($proxyHost)) {
                         $param = array(
                             'trace' => false,
-                            'soap_version' => SOAP_1_2,
+                            'soap_version' => $soapVersion,
                             'exceptions' => true,
                             'proxy_host' => '"'.$proxyHost.'"',
                             'proxy_port' => $proxyPort,
@@ -62,21 +69,21 @@ class Compilatio
                     } else {
                         $param = array(
                             'trace' => false,
-                            'soap_version' => SOAP_1_2,
+                            'soap_version' => $soapVersion,
                             'exceptions' => true,
                         );
                     }
                     $this->soapcli = new SoapClient($urlsoap, $param);
                 } else {
-                    $this->soapcli = 'WS urlsoap not available';
+                    throw new Exception('WS urlsoap not available');
                 }
             } else {
-                $this->soapcli = 'API key not available';
+                throw new Exception('API key not available');
             }
         } catch (SoapFault $fault) {
-            $this->soapcli = "Error constructor compilatio ".$fault->faultcode." ".$fault->faultstring;
+            $this->soapcli = "Error constructor compilatio $fault->faultcode $fault->faultstring ";
         } catch (Exception $e) {
-            $this->soapcli = "Error constructor compilatio with urlsoap".$urlsoap;
+            $this->soapcli = "Error constructor compilatio with urlsoap $urlsoap ".$e->getMessage();
         }
     }
 
@@ -255,7 +262,7 @@ class Compilatio
     {
         try {
             if (!is_object($this->soapcli)) {
-                return ("Error in constructor compilatio() ".$this->soapcli);
+                return "Error in constructor compilatio() $this->soapcli";
             }
             $idDocument = $this->soapcli->__call(
                 'addDocumentBase64',
@@ -387,7 +394,7 @@ class Compilatio
      */
     public static function verifiFileType($filename)
     {
-        $types = array('doc', 'docx', 'rtf', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'pdf', 'txt', 'htm', 'html');
+        $types = ['doc', 'docx', 'rtf', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'pdf', 'txt', 'htm', 'html'];
         $extension = substr($filename, strrpos($filename, '.') + 1);
         $extension = strtolower($extension);
 
@@ -402,7 +409,7 @@ class Compilatio
      * @param string $imagesPath
      * @param array $text   Array includes the extract from the text
      *
-     * @return unknown_type
+     * @return string
      */
     public static function getProgressionAnalyseDocv31($status, $pour = 0, $imagesPath = '', $text = [])
     {
@@ -459,23 +466,28 @@ class Compilatio
      * @param $percentagePumping
      * @param $weakThreshold
      * @param $highThreshold
-     * @param $imagesPath
+     * @param $chemin_images
      * @param $text : array  includes the extract from the text
      *
-     * @return unknown_type
+     * @return string
      */
-    public static function getPomprankBarv31($pourcentagePompage, $weakThreshold, $highThreshold, $chemin_images = '', $texte = '')
-    {
+    public static function getPomprankBarv31(
+        $pourcentagePompage,
+        $weakThreshold,
+        $highThreshold,
+        $chemin_images = '',
+        $texte = ''
+    ) {
         $pourcentagePompage = round($pourcentagePompage);
         $pour = round((50 * $pourcentagePompage) / 100);
         $return = '';
         if ($pourcentagePompage < $weakThreshold) {
-            $couleur = "vert";
+            $couleur = 'vert';
         } else {
             if ($pourcentagePompage >= $weakThreshold && $pourcentagePompage < $highThreshold) {
-                $couleur = "orange";
+                $couleur = 'orange';
             } else {
-                $couleur = "rouge";
+                $couleur = 'rouge';
             }
         }
         $return .= "<div style='float:left;margin-right:2px;'><img src='"
@@ -501,7 +513,8 @@ class Compilatio
 
     /**
      * Method for validation of hash
-     * @param $hash
+     * @param string $hash
+     *
      * @return bool
      *
      */
@@ -510,34 +523,13 @@ class Compilatio
         return preg_match('`^[a-f0-9]{32}$`', $hash);
     }
 
-    /*
-     * Method for identify Internet media type
-     * @param $filename
-     */
-    public static function typeMime($filename)
-    {
-        if (preg_match("@Opera(/| )([0-9].[0-9]{1,2})@", $_SERVER['HTTP_USER_AGENT'], $resultats)) {
-            $navigateur = "Opera";
-        } elseif (preg_match("@MSIE ([0-9].[0-9]{1,2})@", $_SERVER['HTTP_USER_AGENT'], $resultats)) {
-            $navigateur = "Internet Explorer";
-        } else {
-            $navigateur = "Mozilla";
-            $mime = parse_ini_file("mime.ini");
-            $extension = substr($filename, strrpos($filename, ".") + 1);
-        }
-        if (array_key_exists($extension, $mime)) {
-            $type = $mime[$extension];
-        } else {
-            $type = ($navigateur != "Mozilla") ? 'application/octetstream' : 'application/octet-stream';
-        }
-
-        return $type;
-    }
-
     /**
      * function for delete a document of the compilatio table if plagiarismTool is Compilatio
+     *
      * @param int $courseId
      * @param int $itemId
+     *
+     * @return bool
      */
     public static function plagiarismDeleteDoc($courseId, $itemId)
     {
@@ -548,6 +540,8 @@ class Compilatio
         $table = Database:: get_course_table(TABLE_PLAGIARISM);
         $params = [$courseId, $itemId];
         Database::delete($table, ['c_id = ? AND document_id = ?' => $params]);
+
+        return true;
     }
 
     /**
@@ -607,81 +601,80 @@ class Compilatio
         $compilatioId = $this->getCompilatioId($workId, $courseId);
 
         $actionCompilatio = '';
+        $status = '';
         if (!empty($compilatioId)) {
             if (self::isMd5($compilatioId)) {
-                // if compilatio_id is a hash md5, we call the function of the compilatio's webservice who return the document's status
+                // if compilatio_id is a hash md5, we call the function of the compilatio's
+                // webservice who return the document's status
                 $soapRes = $this->getDoc($compilatioId);
-                $status = '';
                 if (isset($soapRes->documentStatus)) {
                     $status = $soapRes->documentStatus->status;
                 }
             } else {
-                // if the compilatio's hash is not a valide hash md5, we return à specific status (cf : IsInCompilatio() )
+                // if the compilatio's hash is not a valide hash md5,
+                // we return à specific status (cf : IsInCompilatio() )
                 $status = 'NOT_IN_COMPILATIO';
-                $actionCompilatio = "<div style='font-style:italic'>"
-                    .get_lang('compilatioDocumentTextNotImage')
-                    ."<br/>"
-                    .get_lang('compilatioDocumentNotCorrupt')
-                    ."</div>";
+                $actionCompilatio = get_lang('CompilatioDocumentTextNotImage').'<br/>'.
+                    get_lang('CompilatioDocumentNotCorrupt');
             }
 
-            if ($status === 'ANALYSE_COMPLETE') {
-                $urlRapport = $this->getReportUrl($compilatioId);
-                $actionCompilatio .= self::getPomprankBarv31(
-                        $soapRes->documentStatus->indice,
-                        10,
-                        35,
+            switch ($status) {
+                case 'ANALYSE_COMPLETE':
+                    $urlRapport = $this->getReportUrl($compilatioId);
+                    $actionCompilatio .= self::getPomprankBarv31(
+                            $soapRes->documentStatus->indice,
+                            10,
+                            35,
+                            $compilatioImgFolder,
+                            $text
+                        )
+                        ."<br/><a href='".$urlRapport."' target='_blank'>"
+                        .get_lang('compilatioSeeReport')
+                        ."</a>";
+                    break;
+                case 'ANALYSE_PROCESSING':
+                    $actionCompilatio .= "<div style='font-weight:bold;text-align:left'>"
+                        .get_lang('CompilatioAnalysisInProgress')
+                        ."</div>";
+                    $actionCompilatio .= "<div style='font-size:80%;font-style:italic;margin-bottom:5px;'>"
+                        .get_lang('CompilatioAnalysisPercentage')
+                        ."</div>";
+                    $text['analysisinqueue'] = get_lang('CompilatioWaitingAnalysis');
+                    $text['analysisinfinalization'] = get_lang('CompilatioAnalysisEnding');
+                    $text['refresh'] = get_lang('Refresh');
+                    $actionCompilatio .= self::getProgressionAnalyseDocv31(
+                        $status,
+                        $soapRes->documentStatus->progression,
                         $compilatioImgFolder,
                         $text
-                    )
-                    ."<br/><a href='"
-                    .$urlRapport
-                    ."' target='_blank'>"
-                    .get_lang('compilatioSeeReport')
-                    ."</a>";
-            } elseif ($status === 'ANALYSE_PROCESSING') {
-                $actionCompilatio .= "<div style='font-weight:bold;text-align:left'>"
-                    .get_lang('compilatioAnalysisInProgress')
-                    ."</div>";
-                $actionCompilatio .= "<div style='font-size:80%;font-style:italic;margin-bottom:5px;'>"
-                    .get_lang('compilatioAnalysisPercentage')
-                    ."</div>";
-                $text['analysisinqueue'] = get_lang('compilatioWaitingAnalysis');
-                $text['analysisinfinalization'] = get_lang('compilatioAnalysisEnding');
-                $text['refresh'] = get_lang('Refresh');
-                $actionCompilatio .= self::getProgressionAnalyseDocv31(
-                    $status,
-                    $soapRes->documentStatus->progression,
-                    $compilatioImgFolder,
-                    $text
-                );
-            } elseif ($status == 'ANALYSE_IN_QUEUE') {
-                $actionCompilatio .= "<img src='"
-                    .$compilatioImgFolder
-                    ."/ajax-loader2.gif' style='margin-right:10px;' />"
-                    .get_lang('compilatioAwaitingAnalysis');
-            } elseif ($status == 'BAD_FILETYPE') {
-                $actionCompilatio .= "<div style='font-style:italic'>"
-                    .get_lang('compilatioFileisnotsupported')
-                    ."<br/>"
-                    .get_lang('compilatioProtectedPdfVerification')
-                    ."</div>";
-            } elseif ($status == 'BAD_FILESIZE') {
-                $actionCompilatio .= "<div style='font-style:italic'>"
-                    .get_lang('compilatioTooHeavyDocument')
-                    ."</div>";
+                    );
+                    break;
+                case 'ANALYSE_IN_QUEUE':
+                    $loading = Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin');
+                    $actionCompilatio .= $loading.'&nbsp;'.get_lang('compilatioAwaitingAnalysis');
+                    break;
+                case 'BAD_FILETYPE':
+                    $actionCompilatio .= get_lang('CompilatioFileIsNotSupported')
+                        ."<br/>"
+                        .get_lang('CompilatioProtectedPdfVerification');
+                    break;
+                case 'BAD_FILESIZE':
+                    $actionCompilatio .= get_lang('CompilatioFileIsTooBig');
+                    break;
+            }
+
+            /*
             } elseif ($status != 'NOT_IN_COMPILATIO') {
                 $actionCompilatio .= "<div style='font-style:italic'>"
                     .get_lang('compilatioMomentarilyUnavailableResult')
                     ." : [ "
                     .$status
                     ."].</div>";
-            }
+            }*/
         }
 
         $result = $workId.'|'.$actionCompilatio.'|'.$status.'|';
 
         return $result;
     }
-
 }

+ 0 - 4
main/inc/lib/display.lib.php

@@ -1441,10 +1441,6 @@ class Display
             }
         }
 
-        if (api_get_configuration_value('allow_compilatio_tool')) {
-            $obj->gridComplete = 'function () { compilatioInit() }';
-        }
-
         if (!empty($extra_params['viewrecords'])) {
             $obj->viewrecords = $extra_params['viewrecords'];
         }

+ 4 - 1
main/install/configuration.dist.php

@@ -1255,7 +1255,10 @@ CREATE TABLE c_plagiarism_compilatio_docs (
 // If table exists already
 ALTER TABLE c_plagiarism_compilatio_docs drop primary key;
 ALTER TABLE c_plagiarism_compilatio_docs ADD COLUMN id INT AUTO_INCREMENT NOT NULL PRIMARY KEY;
-ALTER TABLE c_plagiarism_compilatio_docs CHANGE COLUMN id_doc document_id INT NOT NULL;*/
+ALTER TABLE c_plagiarism_compilatio_docs CHANGE COLUMN id_doc document_id INT NOT NULL;
+
+requires extension "php-soap"  sudo apt-get install php-soap
+*/
 //$_configuration['allow_compilatio_tool'] = false;
 //$_configuration['compilatio_tool'] = [
 //    'settings' => [

+ 2 - 0
main/plagiarism/compilatio/compiladmin.php

@@ -1,6 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+exit;
+
 ini_set('soap.wsdl_cache_enabled', 0);
 ini_set('default_socket_timeout', '1000');
 

+ 2 - 0
main/plagiarism/compilatio/compilatio_ajax.php

@@ -3,6 +3,8 @@
 
 require_once '../../inc/global.inc.php';
 
+api_protect_course_script();
+
 if (isset($_GET['workid'])) {
     $workIdList = $_GET['workid'];    // list of workid separate by the :
     $result = '';

+ 0 - 30
main/plagiarism/compilatio/config.php

@@ -1,30 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/*Compilatio's key*/
-$compilatioParameter['key'] = api_get_setting('compilatioParamKey');
-$compilatioParameter['version'] = '1.2';
-
-/* Url from soap Compilatio server */
-/* You can choice the SSL version if you want */
-$compilatioParameter['$urlsoap'] = api_get_setting('compilatioParamURLSoap');
-
-/* Parameter form your server's proxy (for call SOAP), don't enter it if you dont have one */
-
-$compilatioParameter['proxy_host'] = '';
-$compilatioParameter['proxy_port'] = '';
-
-/* Method to data transmission */
-/* Nothing by default, the data transmission is done by SOAP */
-/* Wget: the Compilatio's server download the file for the analysis  */
-$compilatioParameter['mode_transport'] = '';
-/* if the selected data transmission method is wget, you can set up a special url acces */
-$compilatioParameter['wget_uri'] = '';
-
-/* If the selected data transmission method is wget, you can specify a login/password acces to the directory */
-$compilatioParameter['wget_login'] = '';
-$compilatioParameter['wget_password'] = '';
-
-/*Document's maximum size*/
-$compilatioParameter['max_filesize'] = 10000000;   // 10Mo
-

+ 7 - 5
main/plagiarism/compilatio/download.php

@@ -1,6 +1,8 @@
 <?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,
@@ -23,7 +25,6 @@ header('Pragma: no-cache');
 api_protect_course_script(true);
 
 $id = (int) $_GET['id'];
-
 $courseInfo = api_get_course_info();
 
 if (empty($courseInfo)) {
@@ -33,14 +34,15 @@ if (empty($courseInfo)) {
 $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
 
 if (!empty($courseInfo['real_id'])) {
-	$sql = 'SELECT * FROM '.$tbl_student_publication.' 
-	        WHERE c_id = '.$courseInfo['real_id'].' AND id = "'.$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(api_get_course_int_id(), 'work', $row['id']);
+        $item_info = api_get_item_property_info($courseId, 'work', $row['id']);
         if (empty($item_info)) {
             exit;
         }
@@ -58,4 +60,4 @@ if (!empty($courseInfo['real_id'])) {
 	}
 }
 
-exit;
+exit;

+ 32 - 26
main/plagiarism/compilatio/upload.php

@@ -6,6 +6,9 @@ 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();
+
 $courseId = api_get_course_int_id();
 $courseInfo = api_get_course_info();
 $typeMessage = 0;
@@ -17,13 +20,11 @@ $msgWait = get_lang('PleaseWaitThisCouldTakeAWhile');
 $compilatio = new Compilatio();
 
 /* if we have to upload severals documents*/
-if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'multi') {
-    $docs = preg_split("/a/", $_REQUEST['doc']);
-    for ($k = 0; $k < sizeof($docs) - 1; $k++) {
-        /* We have to modify the timeout server for send the heavy files */
-        set_time_limit(600);
+if (isset($_REQUEST['type']) && $_REQUEST['type'] === 'multi') {
+    $docs = explode('a', $_REQUEST['doc']);
+    for ($k = 0; $k < count($docs) - 1; $k++) {
         $documentId = 0;
-        if (intval($docs[$k])) {
+        if (!isset($docs[$k])) {
             $documentId = (int) $docs[$k];
         }
 
@@ -35,11 +36,9 @@ if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'multi') {
         compilatioUpdateWorkDocument($documentId, $courseId);
 
         $compilatioId = $compilatio->getCompilatioId($documentId, $courseId);
-        if (!empty($compilatioId)) {
-            /*The document is already in Compilatio, we do nothing*/
-        } else {
+        if (empty($compilatioId)) {
             $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
-            $query = "SELECT * FROM $workTable WHERE id='".$documentId."' AND c_id= $courseId";
+            $query = "SELECT * FROM $workTable WHERE id= $documentId AND c_id= $courseId";
             $sqlResult = Database::query($query);
             $doc = Database::fetch_object($sqlResult);
             if ($doc) {
@@ -47,9 +46,7 @@ if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'multi') {
                 $currentCourseRepositoryWeb = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/';
                 $WrkUrl = $currentCourseRepositoryWeb.$doc->url;
                 $LocalWrkUrl = $courseInfo['course_sys_path'].$doc->url;
-                $LocalWrkTitle = $doc->title;
-                $mime = Compilatio::typeMime($LocalWrkTitle);
-
+                $mime = DocumentManager::file_get_mime_type($doc->title);
                 if ($compilatio->getTransportMode() === 'wget') {
                     /*Compilatio's server recover tjre file throught wget like this:
                     username:password@http://somedomain.com/reg/remotefilename.tar.gz */
@@ -90,25 +87,32 @@ if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'multi') {
         }
     }
 } else {
-    // non multiple
-    $documentId = $_GET['doc'];
+    $documentId = isset($_GET['doc']) ? $_GET['doc']: 0;
+    sendDocument($documentId, $courseInfo);
+}
+
+function sendDocument($documentId, $courseInfo)
+{
+    $courseId = $courseInfo['real_id'];
+
     compilatioUpdateWorkDocument($documentId, $courseId);
     $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
     $query = "SELECT * FROM $workTable 
-              WHERE id= $documentId AND c_id= $courseId";
+              WHERE id = $documentId AND c_id= $courseId";
     $sqlResult = Database::query($query);
     $doc = Database::fetch_object($sqlResult);
     $currentCourseRepositoryWeb = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/';
-    $WrkUrl = $currentCourseRepositoryWeb.$doc->url;
-    $WrkTitle = $doc->title;
-    $LocalWrkUrl = $courseInfo['course_sys_path'].$doc->url;
-    $mime = Compilatio::typeMime($WrkTitle);
+    $documentUrl = $currentCourseRepositoryWeb.$doc->url;
+
+    $filePath = $courseInfo['course_sys_path'].$doc->url;
+    $mime = DocumentManager::file_get_mime_type($doc->title);
+
     $compilatio = new Compilatio();
     if ($compilatio->getTransportMode() === 'wget') {
         if (strlen($compilatio->getWgetUri()) > 2) {
-            $filename = preg_replace('/$', '', $compilatio->getWgetUri()).'/'.$_course['path'].'/'.$doc->title;
+            $filename = preg_replace('/$', '', $compilatio->getWgetUri()).'/'.$courseInfo['path'].'/'.$doc->title;
         } else {
-            $filename = $WrkUrl;
+            $filename = $documentUrl;
         }
         if (strlen($compilatio->getWgetLogin()) > 2) {
             $filename = $compilatio->getWgetLogin().':'.$compilatio->getWgetPassword().'@'.$filename;
@@ -118,15 +122,17 @@ if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'multi') {
         $pieces = explode('/', $doc->url);
         $nbPieces = count($pieces);
         $filename = $pieces[$nbPieces - 1];
-        $compilatioId = $compilatio->sendDoc($doc->title, '', $filename, $mime, file_get_contents($LocalWrkUrl));
+        $compilatioId = $compilatio->sendDoc($doc->title, '', $filename, $mime, file_get_contents($filePath));
     }
 
+    var_dump($compilatioId);
+
     if (Compilatio::isMd5($compilatioId)) {
         $compilatio->saveDocument($courseId, $doc->id, $compilatioId);
-        $soapRes = $compilatio->startAnalyse($compilatioId);
-        Display::addFlash(Display::return_message(get_lang('Uploaded')));
+        $compilatio->startAnalyse($compilatioId);
+        echo Display::return_message(get_lang('Uploaded'));
     } else {
-        Display::addFlash(Display::return_message(get_lang('Error')));
+        echo Display::return_message(get_lang('Error'), 'error');
     }
 }
 

+ 8 - 18
main/work/work.lib.php

@@ -1955,13 +1955,10 @@ function get_work_user_list(
 
         $blockEdition = api_get_configuration_value('block_student_publication_edition');
         $blockScoreEdition = api_get_configuration_value('block_student_publication_score_edition');
-
+        $loading = Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin');
         while ($work = Database::fetch_array($result, 'ASSOC')) {
             $item_id = $work['id'];
-            /* JLUCAS COMPILATIO */
             $dbTitle = $work['title'];
-            /* FIN  JLUCAS COMPILATIO */
-
             // Get the author ID for that document from the item_property table
             $is_author = false;
             $can_read = false;
@@ -2242,29 +2239,22 @@ function get_work_user_list(
                     $workDirectory = api_get_path(SYS_COURSE_PATH).$course_info['directory'];
                     if ($compilationId) {
                         $actionCompilatio = "<div id='id_avancement".$item_id."'>
-                            <img src='".$compilatio_web_folder."/img/ajax-loader2.gif' style='margin-right:10px'/>"
-                            .get_lang('compilatioConnectionWithServer')
+                            ".$loading."&nbsp;".get_lang('CompilatioConnectionWithServer')
                             ."</div>";
                     } else {
                         if (!Compilatio::verifiFileType($dbTitle)) {
-                            $actionCompilatio = "<div style='font-style:italic'>"
-                                .get_lang('compilatioFileisnotsupported')
-                                ."</div>";
-                        } elseif (filesize($workDirectory."/".$work['url']) > $compilation->getMaxFileSize()) {
-                            $sizeFile = round(filesize($workDirectory."/".$work['url']) / 1000000);
-                            $actionCompilatio = "<div style='font-style:italic'>"
-                                .get_lang('compilatioTooHeavyDocument')
-                                .": "
-                                .$sizeFile
-                                ." Mo.<br/></div>";
+                            $actionCompilatio = get_lang('CompilatioFileIsNotSupported');
+                        } elseif (filesize($workDirectory.'/'.$work['url']) > $compilation->getMaxFileSize()) {
+                            $sizeFile = round(filesize($workDirectory.'/'.$work['url']) / 1000000);
+                            $actionCompilatio = get_lang('CompilatioFileIsTooBig').': '.format_file_size($sizeFile).'<br />';
                         } else {
                             $actionCompilatio = "<div id='id_avancement".$item_id."'>"
                                 ."<a href='javascript:void(0)' class=\"getSingleCompilatio\" onClick='getSingleCompilatio("
                                 .$item_id
                                 .");'>"
-                                .get_lang('compilatioAnalyse')
+                                .get_lang('CompilatioAnalyse')
                                 ." </a>"
-                                .get_lang('compilatioWithCompilatio')
+                                .get_lang('CompilatioWithCompilatio')
                                 ."</div>";
                         }
                     }

+ 5 - 7
main/work/work.php

@@ -18,7 +18,7 @@ $groupId = api_get_group_id();
 
 // Section (for the tabs)
 $this_section = SECTION_COURSES;
-$work_id = isset($_GET['id']) ? intval($_GET['id']) : null;
+$work_id = isset($_GET['id']) ? (int) $_GET['id'] : null;
 $my_folder_data = get_work_data_by_id($work_id);
 
 $curdirpath = '';
@@ -29,13 +29,13 @@ $htmlHeadXtra[] = to_javascript_work();
 
 $tool_name = get_lang('StudentPublications');
 
-$item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
+$item_id = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : null;
 $origin = api_get_origin();
 $course_dir = api_get_path(SYS_COURSE_PATH).$courseInfo['path'];
 $base_work_dir = $course_dir.'/work';
 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'list';
 
-//Download folder
+// Download folder
 if ($action === 'downloadfolder') {
     require 'downloadfolder.inc.php';
 }
@@ -107,17 +107,16 @@ if (!empty($groupId)) {
             ];
         }
 
-        if ($action == 'upload_form') {
+        if ($action === 'upload_form') {
             $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('UploadADocument')];
         }
 
-        if ($action == 'create_dir') {
+        if ($action === 'create_dir') {
             $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('CreateAssignment')];
         }
     }
 }
 
-// Stats
 Event::event_access_tool(TOOL_STUDENTPUBLICATION);
 
 $logInfo = [
@@ -125,7 +124,6 @@ $logInfo = [
     'tool_id' => 0,
     'tool_id_detail' => 0,
     'action' => $action,
-    'action_details' => '',
 ];
 Event::registerLog($logInfo);
 

+ 214 - 221
main/work/work_list_all.php

@@ -211,8 +211,8 @@ echo Display::toolbarAction('toolbar-worklist', [$actionsLeft]);
 
 $plagiarismListJqgridColumn = [];
 $plagiarismListJqgridLine = [];
-if (api_get_configuration_value('allow_compilatio_tool')) {
-    require_once api_get_path(SYS_CODE_PATH).'/plagiarism/compilatio/config.php';
+$allowAntiPlagiarism = api_get_configuration_value('allow_compilatio_tool');
+if ($allowAntiPlagiarism) {
     $plagiarismListJqgridColumn = ['Compilatio'];
     $plagiarismListJqgridLine = [
         [
@@ -224,8 +224,8 @@ if (api_get_configuration_value('allow_compilatio_tool')) {
             'sortable'=>'false'
         ]
     ];
-
 }
+
 if (!empty($my_folder_data['title'])) {
     echo Display::page_subheader($my_folder_data['title']);
 }
@@ -393,6 +393,10 @@ $deleteUrl = $workUrl.'&a=delete_student_work';
 $showUrl = $workUrl.'&a=show_student_work';
 $hideUrl = $workUrl.'&a=hide_student_work';
 
+if ($allowAntiPlagiarism) {
+    $extra_params['gridComplete'] = 'compilatioInit()';
+}
+
 ?>
 <script>
 $(function() {
@@ -456,82 +460,72 @@ $(function() {
 echo $documentsAddedInWork;
 
 $tableWork = Display::grid_html('results');
-
 echo workGetExtraFieldData($workId);
 echo Display::panel($tableWork);
 
-echo '<div class="list-work-results">';
-echo '<div class="panel panel-default">';
-echo '<div class="panel-body">';
-echo '<table style="display:none; width:100%" class="files data_table">
+if ($allowAntiPlagiarism) {
+    echo '<div id="compilation-results"></div>';
+    echo '<div class="list-work-results">';
+    $table = '<table style="display:none; width:100%" class="files data_table">
         <tr>
             <th>'.get_lang('FileName').'</th>
             <th>'.get_lang('Size').'</th>
             <th>'.get_lang('Status').'</th>
         </tr>
     </table>';
-echo '</div></div></div>';
+    Display::panel($table);
+    echo '</div>';
 
-if (api_get_configuration_value('allow_compilatio_tool')) {
-    $workTable = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
+    $workTable = Database:: get_course_table(TABLE_STUDENT_PUBLICATION);
     $courseId = $courseInfo['real_id'];
-    $form_action['analyseCompilatio'] = [
-        'label' => get_lang('compilatioStartAnalysis'),
-        'data-action' => get_lang('compilatioStartAnalysis'),
+    $formAction['analyseCompilatio'] = [
+        'label' => get_lang('CompilatioStartAnalysis'),
+        'data-action' => get_lang('CompilatioStartAnalysis'),
         'onClick' => "onclick='getMultiCompilatio()'",
     ];
 
-    $html = '<form id ="mes_actions" class="form-search" method="post" name="form_actions">';
+    $html = '<form class="form-search" method="post" name="form_actions">';
     $html .= '<input type="hidden" name="action">';
     $html .= '<table style="width:100%;">';
     $html .= '<tr>';
     $html .= '<td>';
-    if (count($form_action) > 0) {
-        $html .= '<div class="btn-toolbar">';
-        $html .= '<div class="btn-group">';
-        $html .= '<a class="btn btn-default" href="?'
-            .  '&amp;'
-            . "gbox_results"
-            .  '&amp;'
-            . 'selectall=1" onclick="javascript: setCheckbox(true, \''
-            . "gbox_results". '\'); return false;">'
-            . get_lang('SelectAll')
-            . '</a>';
-        $html .= '<a class="btn btn-default" href="?'
-            .  '" onclick="javascript: setCheckbox(false, \''
-            . "gbox_results"
-            . '\'); return false;">'
-            . get_lang('UnSelectAll')
-            . '</a> ';
-        $html .= '</div>';
-        $html .= '<div class="btn-group">
-                                <button class="btn btn-default" onclick="javascript:return false;">'
-            . get_lang('Actions')
-            . '</button>'
-            . '<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">'
-            . '<span class="caret"></span>'
-            . '</button>';
-	$html .= '<ul class="dropdown-menu">';
-        /*ORIGINAL*/
-//        foreach ($form_action as $action => & $label) {
-//            $html .= '<li><a data-action ="' . $action . '" href="#" onclick="javascript:action_click(this, \'' . "gbox_results" . '\');">' . $label . '</a></li>';
-//        }
-        /*fin original*/
-        foreach ($form_action as $action ) {
-            $html .= '<li>
-                        <a data-action ="'.$action['data-action'].'" href="#" '.$action['onClick'].'>'
-                        .$action['label'].'</a>
-                    </li>';
-        }
-        $html .= '</ul>';
-        $html .= '</div>';//btn-group
-        $html .= '</div>'; //toolbar
-        $html .= '</td></tr></table></form>';
+    $html .= '<div class="btn-toolbar">';
+    $html .= '<div class="btn-group">';
+    $html .= '<a class="btn btn-default" href="?'
+        .'&amp;'."gbox_results".'&amp;'.'selectall=1" onclick="javascript: setCheckbox(true, \''
+        ."gbox_results".'\'); return false;">'
+        .get_lang('SelectAll')
+        .'</a>';
+    $html .= '<a class="btn btn-default" href="?'
+        .'" onclick="javascript: setCheckbox(false, \''
+        ."gbox_results"
+        .'\'); return false;">'
+        .get_lang('UnSelectAll')
+        .'</a> ';
+    $html .= '</div>';
+    $html .= '<div class="btn-group">
+        <button class="btn btn-default" onclick="javascript:return false;">'
+        .get_lang('Actions')
+        .'</button>'
+        .'<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">'
+        .'<span class="caret"></span>'
+        .'</button>';
+
+    $html .= '<ul class="dropdown-menu">';
+    foreach ($formAction as $action) {
+        $html .= '<li>
+                    <a data-action ="'.$action['data-action'].'" href="#" '.$action['onClick'].'>'
+            .$action['label'].'</a>
+                </li>';
     }
+    $html .= '</ul>';
+    $html .= '</div>';
+    $html .= '</div>';
+    $html .= '</td></tr></table></form>';
+
     echo $html;
 
     $compTable = Database::get_course_table(TABLE_PLAGIARISM);
-
     $listCompilatioDocId = [];
     $compilatioQuery = "SELECT * FROM $compTable WHERE c_id= $courseId";
     $compilatioResult = Database::query($compilatioQuery);
@@ -546,199 +540,198 @@ if (api_get_configuration_value('allow_compilatio_tool')) {
             $javascriptWorkId .= $data['id'].'a';
         }
     }
-}
 
-Display::display_footer();
-?>
-<!--
-    Lets display the javascript AJAX tools for refreshing datas that needed to be refreshed
-    Only document with state ANALYSE_IN_QUEUE or ANALYSE_PROCESSING need to ask server
-    for a new state
-    Hubert Borderiou - Grenoble Universites - avril 2013
--->
-<script>
-    var xhrObject;      // the htmlhttprequest object
-    var analyseComplete = "ANALYSE_COMPLETE";
-    var analyseProcessing = "ANALYSE_PROCESSING";
-    var analyseInQueue = "ANALYSE_IN_QUEUE";
-    var refreshDelaisAfter = 30000;
-    var allWorkId = "<?php echo $javascriptWorkId?>";
-    var workFolderId = "<?php echo $workId; ?>";
-    var compilationWebUrl = "<?php echo api_get_path(WEB_CODE_PATH) . 'plagiarism/compilatio/' ?>";
-    var divExisteTimer = null;
-    var msgWaitJS = '<?php echo Display::display_confirmation_message(get_lang('PleaseWaitThisCouldTakeAWhile')); ?>';
-    var div = document.createElement('div');
-    var referent =  document.getElementById('toolbar-worklist');
-    var Analyse = '<?php echo get_lang('compilatioAnalyse'); ?>';
-    var compiReport = '<?php echo get_lang('compilatioSeeReport'); ?>';
-    var compiNonToAnalyse = '<?php echo Display::display_error_message(get_lang('compilatioNonToAnalyse')); ?>';
-    var clickTrigger = false;
-
-    function compilatioInit() {
-        if (isWorkFolder()) {
-            searchAdvancement();
-            setInterval("searchAdvancement()", refreshDelaisAfter);
-
-            if(!clickTrigger) {
-                clickTrigger = true;
-                $('.getSingleCompilatio').on('click', function () {
-                    var parts = $(this).parent().attr('id').split('id_avancement');
-                    getSingleCompilatio(parts[1]);
-                });
+    ?>
+    <!--
+        Lets display the javascript AJAX tools for refreshing datas that needed to be refreshed
+        Only document with state ANALYSE_IN_QUEUE or ANALYSE_PROCESSING need to ask server
+        for a new state
+        Hubert Borderiou - Grenoble Universites - avril 2013
+    -->
+    <script>
+        var xhrObject;      // the htmlhttprequest object
+        var analyseComplete = "ANALYSE_COMPLETE";
+        var analyseProcessing = "ANALYSE_PROCESSING";
+        var analyseInQueue = "ANALYSE_IN_QUEUE";
+        var refreshDelaisAfter = 30000;
+        var allWorkId = "<?php echo $javascriptWorkId ?>";
+        var workFolderId = "<?php echo $workId; ?>";
+        var compilationWebUrl = "<?php echo api_get_path(WEB_CODE_PATH).'plagiarism/compilatio/' ?>";
+        var divExisteTimer = null;
+        var msgWaitJS = '<?php echo Display::return_message(get_lang('PleaseWaitThisCouldTakeAWhile')); ?>';
+        var div = document.createElement('div');
+        var referent = document.getElementById('compilation-results');
+        var Analyse = '<?php echo get_lang('compilatioAnalyse'); ?>';
+        var compiReport = '<?php echo get_lang('compilatioSeeReport'); ?>';
+        var compiNonToAnalyse = '<?php echo Display::return_message(get_lang('compilatioNonToAnalyse'), 'error'); ?>';
+        var clickTrigger = false;
+
+        function compilatioInit() {
+            if (isWorkFolder()) {
+                searchAdvancement();
+                setInterval("searchAdvancement()", refreshDelaisAfter);
+                if (!clickTrigger) {
+                    clickTrigger = true;
+                    $('.getSingleCompilatio').on('click', function () {
+                        var parts = $(this).parent().attr('id').split('id_avancement');
+                        getSingleCompilatio(parts[1]);
+                    });
+                }
             }
-
         }
-    }
 
-    // true if we are in a work folder
-    function isWorkFolder() {
-        var res = false;
-        if (workFolderId.match(/[0-9]+/)) {
-            res = true;
-        }
-        return res;
-    }
-
-    // check all compilatio docs
-    function checkAllCompilatio(action) {
-        $("input").each(function() {
-            if ($(this).attr("id")) {
-                objId = $(this).attr("id");
-                listObjId = objId.match(/jqg_results_(\d+)/)
-                if (listObjId.length > 1) {
-                    $(this).prop('checked', action);
-                }
+        // true if we are in a work folder
+        function isWorkFolder() {
+            var res = false;
+            if (workFolderId.match(/[0-9]+/)) {
+                res = true;
             }
-        });
-    }
-
-    function getSingleCompilatio(itemId) {
-        if (div.id == "status_message") {
-            referent.removeChild(div);
+            return res;
         }
-        div.id = "status_message";
-        div.className = 'row';
-        div.innerHTML = '<div class="col-md-6"> <br>'  + msgWaitJS + '</div>';
-        referent.appendChild(div);
-        $.ajax({
-            url: compilationWebUrl + "upload.php?doc="+itemId,
-            type: "get",
-            dataType: "html",
-            success: function(message) {
-                allWorkId += itemId+"a";
-                compilatioInit();
-                if (message.trim() != ""){
-                    div.id = "status_message";
-                    div.className = 'row';
-                    div.innerHTML = '<div class="col-md-6"> <br>'+message+'</div>';
-                    referent.appendChild(div);
-                }
-            }
-        });
-    }
 
-    function getMultiCompilatio() {
-        if (div.id == "status_message") {
-            referent.removeChild(div);
-        }
-        div.id = "status_message";
-        div.className = 'row';
-        div.innerHTML = '<div class="col-md-6"> <br>'  + msgWaitJS + '</div>';
-        referent.appendChild(div);
-        multi_compilatio = "";
-        $("input:checked").each(function() {
-            if ($(this).attr("id")) {
-                objId = $(this).attr("id");
-                listObjId = objId.match(/jqg_results_(\d+)/)
-                if(listObjId){
-                    objClick = document.getElementById('id_avancement'+listObjId[1]);
-                    if (objClick){
-                        objLink = objClick.getElementsByTagName('a');
-                        if (objLink){
-                            stringLink = [].map.call( objLink, function(node){
-                                return node.textContent || node.innerText || "";
-                            }).join("");
-                            if(stringLink.trim() == Analyse.trim()){
-                                if (listObjId && listObjId.length > 1) {
-                                    multi_compilatio += listObjId[1]+"a";
-                                }
-                            }
-                        }
+        // check all compilatio docs
+        function checkAllCompilatio(action) {
+            $("input").each(function () {
+                if ($(this).attr("id")) {
+                    objId = $(this).attr("id");
+                    listObjId = objId.match(/jqg_results_(\d+)/)
+                    if (listObjId.length > 1) {
+                        $(this).prop('checked', action);
                     }
                 }
-            }
-        });
-
-        if ($("#verif")) {
-            $("#verif").append(multi_compilatio);
+            });
         }
 
-        // run compilatio
-        if (multi_compilatio !=  "") {
+        function getSingleCompilatio(itemId) {
+            if (div.id == "status_message") {
+                referent.removeChild(div);
+            }
+            div.id = "status_message";
+            div.className = 'row';
+            div.innerHTML = '<div class="col-md-6"> <br>' + msgWaitJS + '</div>';
+            referent.appendChild(div);
             $.ajax({
-                url: compilationWebUrl + "upload.php",
-                data: { doc: multi_compilatio, type: "multi"}, // on envoie $_GET['id_region'] *// idz
-                success: function(message) { // idz
-                    allWorkId = multi_compilatio;//idz
+                url: compilationWebUrl + "upload.php?<?php echo api_get_cidreq(); ?>&doc=" + itemId,
+                type: "get",
+                dataType: "html",
+                success: function (message) {
+                    console.log(message);
+                    allWorkId += itemId + "a";
                     compilatioInit();
-                    if (message.trim() != ""){
+                    if (message.trim() != "") {
                         div.id = "status_message";
                         div.className = 'row';
-                        div.innerHTML = '<div class="col-md-6"> <br>'+message+'</div>';
+                        div.innerHTML = '<div class="col-md-6"> <br>' + message + '</div>';
                         referent.appendChild(div);
                     }
                 }
             });
-        } else {
-            //multi_compilatio is empty
+        }
+
+        function getMultiCompilatio() {
+            if (div.id == "status_message") {
+                referent.removeChild(div);
+            }
             div.id = "status_message";
             div.className = 'row';
-            div.innerHTML = '<div class="col-md-6"> <br>'  + compiNonToAnalyse + '</div>';
+            div.innerHTML = '<div class="col-md-6"> <br>' + msgWaitJS + '</div>';
             referent.appendChild(div);
-        }
-    }
+            multi_compilatio = "";
+            $("input:checked").each(function () {
+                if ($(this).attr("id")) {
+                    objId = $(this).attr("id");
+                    listObjId = objId.match(/jqg_results_(\d+)/)
+                    if (listObjId) {
+                        objClick = document.getElementById('id_avancement' + listObjId[1]);
+                        if (objClick) {
+                            objLink = objClick.getElementsByTagName('a');
+                            if (objLink) {
+                                stringLink = [].map.call(objLink, function (node) {
+                                    return node.textContent || node.innerText || "";
+                                }).join("");
+                                if (stringLink.trim() == Analyse.trim()) {
+                                    if (listObjId && listObjId.length > 1) {
+                                        multi_compilatio += listObjId[1] + "a";
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            });
 
-    function searchAdvancement(workId) {
-        $.ajax({
-            url: compilationWebUrl + "compilatio_ajax.php?workid=" + allWorkId,
-            type: "get",
-            dataType: "html",
-            error: function(){
-                showData("<?php echo get_lang('compilatioComunicationAjaxImpossible');?>");
-            },
-            success: function( strData ){
-                showData( strData );
+            if ($("#verif")) {
+                $("#verif").append(multi_compilatio);
             }
-        });
-    }
 
-    function deleteIdListeRefresh(id) {
-        var regexp = eval("/"+id+":/");
-        allWorkId = allWorkId.replace(regexp, "");
-    }
+            // run compilatio
+            if (multi_compilatio != "") {
+                $.ajax({
+                    url: compilationWebUrl + "upload.php?<?php echo api_get_cidreq(); ?>",
+                    data: {doc: multi_compilatio, type: "multi"}, // on envoie $_GET['id_region'] *// idz
+                    success: function (message) { // idz
+                        allWorkId = multi_compilatio;//idz
+                        compilatioInit();
+                        if (message.trim() != "") {
+                            div.id = "status_message";
+                            div.className = 'row';
+                            div.innerHTML = '<div class="col-md-6"> <br>' + message + '</div>';
+                            referent.appendChild(div);
+                        }
+                    }
+                });
+            } else {
+                // multi_compilatio is empty
+                div.id = "status_message";
+                div.className = 'row';
+                div.innerHTML = '<div class="col-md-6"> <br>' + compiNonToAnalyse + '</div>';
+                referent.appendChild(div);
+            }
+        }
 
-    function showData(res) {
-        var listRes = new Array();
-        // for debugging
-        $("#verif").html("");
-        // parse the answer string
-        listRes = res.split("|");
-        for (var i=0; i < listRes.length; i=i+3) {
-            if (listRes[i] != "") {
-                var workId = listRes[i];
-                if (i < listRes.length) {
-                    var HTMLcode = listRes[i+1];
+        function searchAdvancement(workId) {
+            $.ajax({
+                url: compilationWebUrl + "compilatio_ajax.php?<?php echo api_get_cidreq(); ?>&workid=" + allWorkId,
+                type: "get",
+                dataType: "html",
+                error: function () {
+                    showData("<?php echo get_lang('CompilatioComunicationAjaxImpossible');?>");
+                },
+                success: function (strData) {
+                    showData(strData);
                 }
-                if (i < listRes.length + 1) {
-                    var idStatus = listRes[i+2];
-                    if (idStatus != analyseInQueue && idStatus != analyseProcessing) {
-                        deleteIdListeRefresh(workId);
+            });
+        }
+
+        function deleteIdListeRefresh(id) {
+            var regexp = eval("/" + id + ":/");
+            allWorkId = allWorkId.replace(regexp, "");
+        }
+
+        function showData(res) {
+            var listRes = new Array();
+            $("#verif").html("");
+            // parse the answer string
+            listRes = res.split("|");
+            for (var i = 0; i < listRes.length; i = i + 3) {
+                if (listRes[i] != "") {
+                    var workId = listRes[i];
+                    if (i < listRes.length) {
+                        var HTMLcode = listRes[i + 1];
+                    }
+                    if (i < listRes.length + 1) {
+                        var idStatus = listRes[i + 2];
+                        if (idStatus != analyseInQueue && idStatus != analyseProcessing) {
+                            deleteIdListeRefresh(workId);
+                        }
+                        $("#verif").append(workId + ":" + idStatus + "<br/>");
                     }
-                    $("#verif").append(workId+":"+idStatus+"<br/>");
+                    $("#" + "id_avancement" + workId).html(HTMLcode);
                 }
-                $("#"+"id_avancement"+workId).html(HTMLcode);
             }
         }
-    }
-</script>
+    </script>
+    <?php
+}
 
+Display::display_footer();