@ -0,0 +1,146 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
require_once __DIR__.'/../inc/global.inc.php'; |
||||||
|
|
||||||
|
if (api_get_configuration_value('allow_exercise_categories') === false) { |
||||||
|
api_not_allowed(); |
||||||
|
} |
||||||
|
|
||||||
|
api_protect_course_script(); |
||||||
|
|
||||||
|
if (!api_is_allowed_to_edit()) { |
||||||
|
api_not_allowed(true); |
||||||
|
} |
||||||
|
|
||||||
|
$interbreadcrumb[] = [ |
||||||
|
'url' => api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq(), |
||||||
|
'name' => get_lang('Exercises'), |
||||||
|
]; |
||||||
|
|
||||||
|
$courseId = api_get_course_int_id(); |
||||||
|
|
||||||
|
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_categories&c_id='.$courseId.'&'.api_get_cidreq(); |
||||||
|
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : ''; |
||||||
|
|
||||||
|
$obj = new ExerciseCategoryManager(); |
||||||
|
|
||||||
|
$check = Security::check_token('request'); |
||||||
|
$token = Security::get_token(); |
||||||
|
|
||||||
|
//Add the JS needed to use the jqgrid |
||||||
|
$htmlHeadXtra[] = api_get_jqgrid_js(); |
||||||
|
|
||||||
|
//The order is important you need to check the the $column variable in the model.ajax.php file |
||||||
|
$columns = [ |
||||||
|
get_lang('Name'), |
||||||
|
get_lang('Actions'), |
||||||
|
]; |
||||||
|
|
||||||
|
// Column config |
||||||
|
$column_model = [ |
||||||
|
[ |
||||||
|
'name' => 'name', |
||||||
|
'index' => 'name', |
||||||
|
'width' => '140', |
||||||
|
'align' => 'left', |
||||||
|
], |
||||||
|
[ |
||||||
|
'name' => 'actions', |
||||||
|
'index' => 'actions', |
||||||
|
'width' => '40', |
||||||
|
'align' => 'left', |
||||||
|
'formatter' => 'action_formatter', |
||||||
|
'sortable' => 'false', |
||||||
|
], |
||||||
|
]; |
||||||
|
|
||||||
|
// Autowidth |
||||||
|
$extra_params['autowidth'] = 'true'; |
||||||
|
// height auto |
||||||
|
$extra_params['height'] = 'auto'; |
||||||
|
|
||||||
|
$action_links = $obj->getJqgridActionLinks($token); |
||||||
|
|
||||||
|
$htmlHeadXtra[] = '<script> |
||||||
|
$(function() { |
||||||
|
// grid definition see the $obj->display() function |
||||||
|
'.Display::grid_js( |
||||||
|
'categories', |
||||||
|
$url, |
||||||
|
$columns, |
||||||
|
$column_model, |
||||||
|
$extra_params, |
||||||
|
[], |
||||||
|
$action_links, |
||||||
|
true |
||||||
|
).' |
||||||
|
}); |
||||||
|
</script>'; |
||||||
|
|
||||||
|
$url = api_get_self().'?'.api_get_cidreq(); |
||||||
|
|
||||||
|
switch ($action) { |
||||||
|
case 'add': |
||||||
|
$interbreadcrumb[] = ['url' => $url, 'name' => get_lang('Categories')]; |
||||||
|
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')]; |
||||||
|
$form = $obj->return_form($url.'&action=add', 'add'); |
||||||
|
// The validation or display |
||||||
|
if ($form->validate()) { |
||||||
|
$values = $form->exportValues(); |
||||||
|
unset($values['id']); |
||||||
|
$res = $obj->save($values); |
||||||
|
if ($res) { |
||||||
|
Display::addFlash(Display::return_message(get_lang('ItemAdded'), 'confirmation')); |
||||||
|
} |
||||||
|
header('Location: '.$url); |
||||||
|
exit; |
||||||
|
} else { |
||||||
|
$content = '<div class="actions">'; |
||||||
|
$content .= '<a href="'.$url.'">'. |
||||||
|
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>'; |
||||||
|
$content .= '</div>'; |
||||||
|
$form->addElement('hidden', 'sec_token'); |
||||||
|
$form->setConstants(['sec_token' => $token]); |
||||||
|
$content .= $form->returnForm(); |
||||||
|
} |
||||||
|
break; |
||||||
|
case 'edit': |
||||||
|
$interbreadcrumb[] = ['url' => $url, 'name' => get_lang('Categories')]; |
||||||
|
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')]; |
||||||
|
$form = $obj->return_form($url.'&action=edit&id='.intval($_GET['id']), 'edit'); |
||||||
|
|
||||||
|
// The validation or display |
||||||
|
if ($form->validate()) { |
||||||
|
$values = $form->exportValues(); |
||||||
|
$res = $obj->update($values); |
||||||
|
if ($res) { |
||||||
|
Display::addFlash(Display::return_message(get_lang('ItemUpdated'), 'confirmation')); |
||||||
|
} |
||||||
|
header('Location: '.$url); |
||||||
|
exit; |
||||||
|
} else { |
||||||
|
$content = '<div class="actions">'; |
||||||
|
$content .= '<a href="'.$url.'">'. |
||||||
|
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>'; |
||||||
|
$content .= '</div>'; |
||||||
|
$form->addElement('hidden', 'sec_token'); |
||||||
|
$form->setConstants(['sec_token' => $token]); |
||||||
|
$content .= $form->returnForm(); |
||||||
|
} |
||||||
|
break; |
||||||
|
case 'delete': |
||||||
|
$res = $obj->delete($_GET['id']); |
||||||
|
if ($res) { |
||||||
|
Display::addFlash(Display::return_message(get_lang('ItemDeleted'), 'confirmation')); |
||||||
|
} |
||||||
|
header('Location: '.$url); |
||||||
|
exit; |
||||||
|
break; |
||||||
|
default: |
||||||
|
$content = $obj->display(); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
Display::display_header(); |
||||||
|
echo $content; |
||||||
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 154 B |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 377 B |
|
After Width: | Height: | Size: 396 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 21 KiB |
@ -0,0 +1,618 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
/** |
||||||
|
* Build the comunication with the SOAP server Compilatio.net |
||||||
|
* call severals methods for the file management in Compilatio.net. |
||||||
|
* |
||||||
|
* @version: 2.0 |
||||||
|
*/ |
||||||
|
class Compilatio |
||||||
|
{ |
||||||
|
/** Identification key for the Compilatio account*/ |
||||||
|
public $key; |
||||||
|
/** Webservice connection*/ |
||||||
|
public $soapcli; |
||||||
|
private $transportMode; |
||||||
|
private $maxFileSize; |
||||||
|
private $wgetUri; |
||||||
|
private $wgetLogin; |
||||||
|
private $wgetPassword; |
||||||
|
private $proxyHost; |
||||||
|
private $proxyPort; |
||||||
|
|
||||||
|
/** |
||||||
|
* Compilatio constructor. |
||||||
|
*/ |
||||||
|
public function __construct() |
||||||
|
{ |
||||||
|
if (empty(api_get_configuration_value('allow_compilatio_tool')) || |
||||||
|
empty(api_get_configuration_value('compilatio_tool')) |
||||||
|
) { |
||||||
|
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']; |
||||||
|
$proxyPort = $this->proxyPort = $settings['proxy_port']; |
||||||
|
$this->transportMode = $settings['transport_mode']; |
||||||
|
$this->maxFileSize = $settings['max_filesize']; |
||||||
|
$this->wgetUri = $settings['wget_uri']; |
||||||
|
$this->wgetLogin = $settings['wget_login']; |
||||||
|
$this->wgetPassword = $settings['wget_password']; |
||||||
|
$soapVersion = 2; |
||||||
|
|
||||||
|
try { |
||||||
|
if (!empty($key)) { |
||||||
|
$this->key = $key; |
||||||
|
if (!empty($urlsoap)) { |
||||||
|
if (!empty($proxyHost)) { |
||||||
|
$param = [ |
||||||
|
'trace' => false, |
||||||
|
'soap_version' => $soapVersion, |
||||||
|
'exceptions' => true, |
||||||
|
'proxy_host' => '"'.$proxyHost.'"', |
||||||
|
'proxy_port' => $proxyPort, |
||||||
|
]; |
||||||
|
} else { |
||||||
|
$param = [ |
||||||
|
'trace' => false, |
||||||
|
'soap_version' => $soapVersion, |
||||||
|
'exceptions' => true, |
||||||
|
]; |
||||||
|
} |
||||||
|
$this->soapcli = new SoapClient($urlsoap, $param); |
||||||
|
} else { |
||||||
|
throw new Exception('WS urlsoap not available'); |
||||||
|
} |
||||||
|
} else { |
||||||
|
throw new Exception('API key not available'); |
||||||
|
} |
||||||
|
} catch (SoapFault $fault) { |
||||||
|
$this->soapcli = "Error constructor compilatio $fault->faultcode $fault->faultstring "; |
||||||
|
} catch (Exception $e) { |
||||||
|
$this->soapcli = "Error constructor compilatio with urlsoap $urlsoap ".$e->getMessage(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getKey() |
||||||
|
{ |
||||||
|
return $this->key; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $key |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setKey($key) |
||||||
|
{ |
||||||
|
$this->key = $key; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function getTransportMode() |
||||||
|
{ |
||||||
|
return $this->transportMode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $transportMode |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setTransportMode($transportMode) |
||||||
|
{ |
||||||
|
$this->transportMode = $transportMode; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function getMaxFileSize() |
||||||
|
{ |
||||||
|
return $this->maxFileSize; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $maxFileSize |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setMaxFileSize($maxFileSize) |
||||||
|
{ |
||||||
|
$this->maxFileSize = $maxFileSize; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function getWgetUri() |
||||||
|
{ |
||||||
|
return $this->wgetUri; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $wgetUri |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setWgetUri($wgetUri) |
||||||
|
{ |
||||||
|
$this->wgetUri = $wgetUri; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function getWgetLogin() |
||||||
|
{ |
||||||
|
return $this->wgetLogin; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $wgetLogin |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setWgetLogin($wgetLogin) |
||||||
|
{ |
||||||
|
$this->wgetLogin = $wgetLogin; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function getWgetPassword() |
||||||
|
{ |
||||||
|
return $this->wgetPassword; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $wgetPassword |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setWgetPassword($wgetPassword) |
||||||
|
{ |
||||||
|
$this->wgetPassword = $wgetPassword; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function getProxyHost() |
||||||
|
{ |
||||||
|
return $this->proxyHost; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $proxyHost |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setProxyHost($proxyHost) |
||||||
|
{ |
||||||
|
$this->proxyHost = $proxyHost; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function getProxyPort() |
||||||
|
{ |
||||||
|
return $this->proxyPort; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mixed $proxyPort |
||||||
|
* |
||||||
|
* @return Compilatio |
||||||
|
*/ |
||||||
|
public function setProxyPort($proxyPort) |
||||||
|
{ |
||||||
|
$this->proxyPort = $proxyPort; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for the file load. |
||||||
|
* |
||||||
|
* @param $title |
||||||
|
* @param $description |
||||||
|
* @param $filename |
||||||
|
* @param $mimeType |
||||||
|
* @param $content |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function sendDoc($title, $description, $filename, $mimeType, $content) |
||||||
|
{ |
||||||
|
try { |
||||||
|
if (!is_object($this->soapcli)) { |
||||||
|
return "Error in constructor compilatio() $this->soapcli"; |
||||||
|
} |
||||||
|
$idDocument = $this->soapcli->__call( |
||||||
|
'addDocumentBase64', |
||||||
|
[ |
||||||
|
$this->key, |
||||||
|
utf8_encode(urlencode($title)), |
||||||
|
utf8_encode(urlencode($description)), |
||||||
|
utf8_encode(urlencode($filename)), |
||||||
|
utf8_encode($mimeType), |
||||||
|
base64_encode($content), |
||||||
|
] |
||||||
|
); |
||||||
|
|
||||||
|
return $idDocument; |
||||||
|
} catch (SoapFault $fault) { |
||||||
|
return "Erreur sendDoc()".$fault->faultcode." ".$fault->faultstring; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for recover a document's information. |
||||||
|
* |
||||||
|
* @param $compiHash |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getDoc($compiHash) |
||||||
|
{ |
||||||
|
try { |
||||||
|
if (!is_object($this->soapcli)) { |
||||||
|
return "Error in constructor compilatio() ".$this->soapcli; |
||||||
|
} |
||||||
|
$param = [$this->key, $compiHash]; |
||||||
|
$idDocument = $this->soapcli->__call('getDocument', $param); |
||||||
|
|
||||||
|
return $idDocument; |
||||||
|
} catch (SoapFault $fault) { |
||||||
|
return "Erreur getDoc()".$fault->faultcode." ".$fault->faultstring; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* method for recover an url document's report. |
||||||
|
* |
||||||
|
* @param $compiHash |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getReportUrl($compiHash) |
||||||
|
{ |
||||||
|
try { |
||||||
|
if (!is_object($this->soapcli)) { |
||||||
|
return "Error in constructor compilatio() ".$this->soapcli; |
||||||
|
} |
||||||
|
$param = [$this->key, $compiHash]; |
||||||
|
$idDocument = $this->soapcli->__call('getDocumentReportUrl', $param); |
||||||
|
|
||||||
|
return $idDocument; |
||||||
|
} catch (SoapFault $fault) { |
||||||
|
return "Erreur getReportUrl()".$fault->faultcode." ".$fault->faultstring; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for deleting a Compialtio's account document. |
||||||
|
* |
||||||
|
* @param $compiHash |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function deldoc($compiHash) |
||||||
|
{ |
||||||
|
try { |
||||||
|
if (!is_object($this->soapcli)) { |
||||||
|
return "Error in constructor compilatio() ".$this->soapcli; |
||||||
|
} |
||||||
|
$param = [$this->key, $compiHash]; |
||||||
|
$this->soapcli->__call('deleteDocument', $param); |
||||||
|
} catch (SoapFault $fault) { |
||||||
|
return "Erreur deldoc()".$fault->faultcode." ".$fault->faultstring; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for start the analysis for a document. |
||||||
|
* |
||||||
|
* @param $compiHash |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function startAnalyse($compiHash) |
||||||
|
{ |
||||||
|
try { |
||||||
|
if (!is_object($this->soapcli)) { |
||||||
|
return "Error in constructor compilatio() ".$this->soapcli; |
||||||
|
} |
||||||
|
$param = [$this->key, $compiHash]; |
||||||
|
$this->soapcli->__call('startDocumentAnalyse', $param); |
||||||
|
} catch (SoapFault $fault) { |
||||||
|
return "Erreur startAnalyse()".$fault->faultcode." ".$fault->faultstring; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for recover the account's quota. |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getQuotas() |
||||||
|
{ |
||||||
|
try { |
||||||
|
if (!is_object($this->soapcli)) { |
||||||
|
return "Error in constructor compilatio() ".$this->soapcli; |
||||||
|
} |
||||||
|
$param = [$this->key]; |
||||||
|
$resultat = $this->soapcli->__call('getAccountQuotas', $param); |
||||||
|
|
||||||
|
return $resultat; |
||||||
|
} catch (SoapFault $fault) { |
||||||
|
return "Erreur getQuotas()".$fault->faultcode." ".$fault->faultstring; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for identify a file extension and the possibility that the document can be managed by Compilatio. |
||||||
|
* |
||||||
|
* @param $filename |
||||||
|
* |
||||||
|
* @return bool |
||||||
|
*/ |
||||||
|
public static function verifiFileType($filename) |
||||||
|
{ |
||||||
|
$types = ['doc', 'docx', 'rtf', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'pdf', 'txt', 'htm', 'html']; |
||||||
|
$extension = substr($filename, strrpos($filename, '.') + 1); |
||||||
|
$extension = strtolower($extension); |
||||||
|
|
||||||
|
return in_array($extension, $types); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Fonction affichage de la barre de progression d'analyse version 3.1. |
||||||
|
* |
||||||
|
* @param string $status From the document |
||||||
|
* @param int $pour |
||||||
|
* @param array $text Array includes the extract from the text |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public static function getProgressionAnalyseDocv31($status, $pour = 0, $text = []) |
||||||
|
{ |
||||||
|
$loading = Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin'); |
||||||
|
$loading .= ' '; |
||||||
|
//$refreshReturn = Display::url('javascript:window.location.reload(false);', $loading); |
||||||
|
|
||||||
|
switch ($status) { |
||||||
|
case 'ANALYSE_IN_QUEUE': |
||||||
|
$content = $loading.$text['analysisinqueue']; |
||||||
|
break; |
||||||
|
case 'ANALYSE_PROCESSING': |
||||||
|
$content = $loading.$text['analysisinfinalization']; |
||||||
|
break; |
||||||
|
default: |
||||||
|
$content = Display::bar_progress($pour, true); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
return $content; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for display the PomprseuilmankBar (% de plagiat). |
||||||
|
* |
||||||
|
* @param $index |
||||||
|
* @param $weakThreshold |
||||||
|
* @param $highThreshold |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public static function getPomprankBarv31( |
||||||
|
$index, |
||||||
|
$weakThreshold, |
||||||
|
$highThreshold |
||||||
|
) { |
||||||
|
$index = round($index); |
||||||
|
$pour = round((50 * $index) / 100); |
||||||
|
$return = ''; |
||||||
|
$class = 'error'; |
||||||
|
if ($index < $weakThreshold) { |
||||||
|
$class = 'success'; |
||||||
|
} else { |
||||||
|
if ($index >= $weakThreshold && $index < $highThreshold) { |
||||||
|
$class = 'warning'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$return .= Display::bar_progress($index, true, null, $class); |
||||||
|
|
||||||
|
return $return; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method for validation of hash. |
||||||
|
* |
||||||
|
* @param string $hash |
||||||
|
* |
||||||
|
* @return bool |
||||||
|
*/ |
||||||
|
public static function isMd5($hash) |
||||||
|
{ |
||||||
|
return preg_match('`^[a-f0-9]{32}$`', $hash); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 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) |
||||||
|
{ |
||||||
|
if (api_get_configuration_value('allow_compilatio_tool')) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
$table = Database:: get_course_table(TABLE_PLAGIARISM); |
||||||
|
$params = [$courseId, $itemId]; |
||||||
|
Database::delete($table, ['c_id = ? AND document_id = ?' => $params]); |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $courseId |
||||||
|
* @param int $documentId |
||||||
|
* @param int $compilatioId |
||||||
|
*/ |
||||||
|
public function saveDocument($courseId, $documentId, $compilatioId) |
||||||
|
{ |
||||||
|
$documentId = (int) $documentId; |
||||||
|
$courseId = (int) $courseId; |
||||||
|
|
||||||
|
$table = Database::get_course_table(TABLE_PLAGIARISM); |
||||||
|
$params = [ |
||||||
|
'c_id' => $courseId, |
||||||
|
'document_id' => $documentId, |
||||||
|
'compilatio_id' => $compilatioId, |
||||||
|
]; |
||||||
|
Database::insert($table, $params); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $documentId |
||||||
|
* @param int $courseId |
||||||
|
* |
||||||
|
* @return string md5 value |
||||||
|
*/ |
||||||
|
public function getCompilatioId($documentId, $courseId) |
||||||
|
{ |
||||||
|
$documentId = (int) $documentId; |
||||||
|
$courseId = (int) $courseId; |
||||||
|
|
||||||
|
$table = Database::get_course_table(TABLE_PLAGIARISM); |
||||||
|
$sql = "SELECT compilatio_id FROM $table |
||||||
|
WHERE document_id = $documentId AND c_id= $courseId"; |
||||||
|
$result = Database::query($sql); |
||||||
|
$result = Database::fetch_object($result); |
||||||
|
|
||||||
|
if ($result) { |
||||||
|
return (string) $result->compilatio_id; |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $workId |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function giveWorkIdState($workId) |
||||||
|
{ |
||||||
|
$compilatioImgFolder = api_get_path(WEB_CODE_PATH).'plagiarism/compilatio/img/'; |
||||||
|
$courseId = api_get_course_int_id(); |
||||||
|
$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 |
||||||
|
$soapRes = $this->getDoc($compilatioId); |
||||||
|
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() ) |
||||||
|
$status = 'NOT_IN_COMPILATIO'; |
||||||
|
$actionCompilatio = get_lang('CompilatioDocumentTextNotImage').'<br/>'. |
||||||
|
get_lang('CompilatioDocumentNotCorrupt'); |
||||||
|
} |
||||||
|
|
||||||
|
switch ($status) { |
||||||
|
case 'ANALYSE_COMPLETE': |
||||||
|
$urlRapport = $this->getReportUrl($compilatioId); |
||||||
|
$actionCompilatio .= self::getPomprankBarv31( |
||||||
|
$soapRes->documentStatus->indice, |
||||||
|
10, |
||||||
|
35 |
||||||
|
) |
||||||
|
.Display::url( |
||||||
|
get_lang('CompilatioAnalysis'), |
||||||
|
$urlRapport, |
||||||
|
['class' => 'btn btn-primary btn-xs', 'target' => '_blank'] |
||||||
|
); |
||||||
|
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 = []; |
||||||
|
$text['analysisinqueue'] = get_lang('CompilatioWaitingAnalysis'); |
||||||
|
$text['analysisinfinalization'] = get_lang('CompilatioAnalysisEnding'); |
||||||
|
$text['refresh'] = get_lang('Refresh'); |
||||||
|
$actionCompilatio .= self::getProgressionAnalyseDocv31( |
||||||
|
$status, |
||||||
|
$soapRes->documentStatus->progression, |
||||||
|
$text |
||||||
|
); |
||||||
|
break; |
||||||
|
case 'ANALYSE_IN_QUEUE': |
||||||
|
$loading = Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin'); |
||||||
|
$actionCompilatio .= $loading.' '.get_lang('CompilatioAwaitingAnalysis'); |
||||||
|
break; |
||||||
|
case 'BAD_FILETYPE': |
||||||
|
$actionCompilatio .= get_lang('CompilatioFileIsNotSupported') |
||||||
|
.'<br/>' |
||||||
|
.get_lang('CompilatioProtectedPdfVerification'); |
||||||
|
break; |
||||||
|
case 'BAD_FILESIZE': |
||||||
|
$actionCompilatio .= get_lang('CompilatioFileIsTooBig'); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$result = $workId.'|'.$actionCompilatio.'|'.$status.'|'; |
||||||
|
|
||||||
|
return $result; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,268 @@ |
|||||||
|
<?php |
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
use Chamilo\CourseBundle\Entity\CExerciseCategory; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class ExtraFieldValue |
||||||
|
* Declaration for the ExtraFieldValue class, managing the values in extra |
||||||
|
* fields for any data type. |
||||||
|
* |
||||||
|
* @package chamilo.library |
||||||
|
*/ |
||||||
|
class ExerciseCategoryManager extends Model |
||||||
|
{ |
||||||
|
public $type = ''; |
||||||
|
public $columns = [ |
||||||
|
'id', |
||||||
|
'name', |
||||||
|
'c_id', |
||||||
|
'description', |
||||||
|
'created_at', |
||||||
|
'updated_at', |
||||||
|
]; |
||||||
|
|
||||||
|
/** |
||||||
|
* Formats the necessary elements for the given datatype. |
||||||
|
* |
||||||
|
* @param string $type The type of data to which this extra field |
||||||
|
* applies (user, course, session, ...) |
||||||
|
* |
||||||
|
* @assert (-1) === false |
||||||
|
*/ |
||||||
|
public function __construct() |
||||||
|
{ |
||||||
|
parent::__construct(); |
||||||
|
$this->is_course_model = true; |
||||||
|
$this->table = Database::get_course_table('exercise_category'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the number of values stored in the table (all fields together) |
||||||
|
* for this type of resource. |
||||||
|
* |
||||||
|
* @param int $courseId |
||||||
|
* |
||||||
|
* @return int Number of rows in the table |
||||||
|
*/ |
||||||
|
public function getCourseCount($courseId) |
||||||
|
{ |
||||||
|
$em = Database::getManager(); |
||||||
|
$query = $em->getRepository('ChamiloCourseBundle:CExerciseCategory')->createQueryBuilder('e'); |
||||||
|
$query->select('count(e.id)'); |
||||||
|
$query->where('e.cId = :cId'); |
||||||
|
$query->setParameter('cId', $courseId); |
||||||
|
|
||||||
|
return $query->getQuery()->getSingleScalarResult(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $courseId |
||||||
|
* |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
public function getCategories($courseId) |
||||||
|
{ |
||||||
|
$em = Database::getManager(); |
||||||
|
$query = $em->getRepository('ChamiloCourseBundle:CExerciseCategory')->createQueryBuilder('e'); |
||||||
|
$query->where('e.cId = :cId'); |
||||||
|
$query->setParameter('cId', $courseId); |
||||||
|
$query->orderBy('e.position'); |
||||||
|
|
||||||
|
return $query->getQuery()->getResult(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $courseId |
||||||
|
* |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
public function getCategoriesForSelect($courseId) |
||||||
|
{ |
||||||
|
$categories = $this->getCategories($courseId); |
||||||
|
$options = []; |
||||||
|
|
||||||
|
if (!empty($categories)) { |
||||||
|
/** @var CExerciseCategory $category */ |
||||||
|
foreach ($categories as $category) { |
||||||
|
$options[$category->getId()] = $category->getName(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return $options; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param int $id |
||||||
|
*/ |
||||||
|
public function delete($id) |
||||||
|
{ |
||||||
|
$em = Database::getManager(); |
||||||
|
$repo = Database::getManager()->getRepository('ChamiloCourseBundle:CExerciseCategory'); |
||||||
|
$category = $repo->find($id); |
||||||
|
if ($category) { |
||||||
|
$em->remove($category); |
||||||
|
$em->flush(); |
||||||
|
|
||||||
|
$courseId = api_get_course_int_id(); |
||||||
|
$table = Database::get_course_table(TABLE_QUIZ_TEST); |
||||||
|
$id = (int) $id; |
||||||
|
|
||||||
|
$sql = "UPDATE $table SET exercise_category_id = 0 |
||||||
|
WHERE c_id = $courseId AND exercise_category_id = $id"; |
||||||
|
Database::query($sql); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Save values in the *_field_values table. |
||||||
|
* |
||||||
|
* @param array $params Structured array with the values to save |
||||||
|
* @param bool $showQuery Whether to show the insert query (passed to the parent save() method) |
||||||
|
*/ |
||||||
|
public function save($params, $showQuery = false) |
||||||
|
{ |
||||||
|
$courseId = api_get_course_int_id(); |
||||||
|
$em = Database::getManager(); |
||||||
|
$category = new CExerciseCategory(); |
||||||
|
$category |
||||||
|
->setName($params['name']) |
||||||
|
->setCId(api_get_course_int_id()) |
||||||
|
->setDescription($params['name']) |
||||||
|
; |
||||||
|
/* |
||||||
|
// Update position |
||||||
|
$query = $em->getRepository('ChamiloCourseBundle:CExerciseCategory')->createQueryBuilder('e'); |
||||||
|
$query |
||||||
|
->where('e.cId = :cId') |
||||||
|
->setParameter('cId', $courseId) |
||||||
|
->setMaxResults(1) |
||||||
|
->orderBy('e.position', 'DESC'); |
||||||
|
$last = $query->getQuery()->getOneOrNullResult(); |
||||||
|
$position = 0; |
||||||
|
if (!empty($last)) { |
||||||
|
$position = $last->getPosition() + 1; |
||||||
|
} |
||||||
|
$category->setPosition($position); |
||||||
|
*/ |
||||||
|
$em->persist($category); |
||||||
|
$em->flush(); |
||||||
|
|
||||||
|
return $category; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param $token |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getJqgridActionLinks($token) |
||||||
|
{ |
||||||
|
//With this function we can add actions to the jgrid (edit, delete, etc) |
||||||
|
$editIcon = Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL); |
||||||
|
$deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL); |
||||||
|
$confirmMessage = addslashes( |
||||||
|
api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES) |
||||||
|
); |
||||||
|
|
||||||
|
$courseParams = api_get_cidreq(); |
||||||
|
|
||||||
|
$editButton = <<<JAVASCRIPT |
||||||
|
<a href="?action=edit&{$courseParams}&id=' + options.rowId + '" class="btn btn-link btn-xs">\ |
||||||
|
$editIcon\ |
||||||
|
</a> |
||||||
|
JAVASCRIPT; |
||||||
|
$deleteButton = <<<JAVASCRIPT |
||||||
|
<a \ |
||||||
|
onclick="if (!confirm(\'$confirmMessage\')) {return false;}" \ |
||||||
|
href="?sec_token=$token&{$courseParams}&id=' + options.rowId + '&action=delete" \ |
||||||
|
class="btn btn-link btn-xs">\ |
||||||
|
$deleteIcon\ |
||||||
|
</a> |
||||||
|
JAVASCRIPT; |
||||||
|
|
||||||
|
return "function action_formatter(cellvalue, options, rowObject) { |
||||||
|
return '$editButton $deleteButton'; |
||||||
|
}"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param string $url |
||||||
|
* @param string $action |
||||||
|
* |
||||||
|
* @return FormValidator |
||||||
|
*/ |
||||||
|
public function return_form($url, $action) |
||||||
|
{ |
||||||
|
$form = new FormValidator('category', 'post', $url); |
||||||
|
$id = isset($_GET['id']) ? (int) $_GET['id'] : null; |
||||||
|
$form->addElement('hidden', 'id', $id); |
||||||
|
|
||||||
|
// Setting the form elements |
||||||
|
$header = get_lang('Add'); |
||||||
|
$defaults = []; |
||||||
|
|
||||||
|
if ($action === 'edit') { |
||||||
|
$header = get_lang('Modify'); |
||||||
|
// Setting the defaults |
||||||
|
$defaults = $this->get($id, false); |
||||||
|
} |
||||||
|
|
||||||
|
$form->addElement('header', $header); |
||||||
|
|
||||||
|
$form->addText( |
||||||
|
'name', |
||||||
|
get_lang('Name') |
||||||
|
); |
||||||
|
|
||||||
|
$form->addHtmlEditor('description', get_lang('Description')); |
||||||
|
|
||||||
|
if ($action === 'edit') { |
||||||
|
$form->addButtonUpdate(get_lang('Modify')); |
||||||
|
} else { |
||||||
|
$form->addButtonCreate(get_lang('Add')); |
||||||
|
} |
||||||
|
|
||||||
|
/*if (!empty($defaults['created_at'])) { |
||||||
|
$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']); |
||||||
|
} |
||||||
|
if (!empty($defaults['updated_at'])) { |
||||||
|
$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']); |
||||||
|
}*/ |
||||||
|
$form->setDefaults($defaults); |
||||||
|
|
||||||
|
// Setting the rules |
||||||
|
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); |
||||||
|
|
||||||
|
return $form; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function display() |
||||||
|
{ |
||||||
|
// action links |
||||||
|
$content = '<div class="actions">'; |
||||||
|
$content .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'">'; |
||||||
|
$content .= Display::return_icon( |
||||||
|
'back.png', |
||||||
|
get_lang('BackTo').' '.get_lang('PlatformAdmin'), |
||||||
|
'', |
||||||
|
ICON_SIZE_MEDIUM |
||||||
|
); |
||||||
|
$content .= '</a>'; |
||||||
|
$content .= '<a href="'.api_get_self().'?action=add&'.api_get_cidreq().'">'; |
||||||
|
$content .= Display::return_icon( |
||||||
|
'add.png', |
||||||
|
get_lang('Add'), |
||||||
|
'', |
||||||
|
ICON_SIZE_MEDIUM |
||||||
|
); |
||||||
|
$content .= '</a>'; |
||||||
|
$content .= '</div>'; |
||||||
|
$content .= Display::grid_html('categories'); |
||||||
|
|
||||||
|
return $content; |
||||||
|
} |
||||||
|
} |
||||||