Skip to content
Snippets Groups Projects
Commit 14a9ec3c authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

prevent php8 warnings in elearning module (fifth batch of changes), re #2193

Merge request studip/studip!1428
parent f2fb170e
No related branches found
No related tags found
1 merge request!4Draft: Icon creation
...@@ -16,32 +16,33 @@ ...@@ -16,32 +16,33 @@
*/ */
class ConnectedCMS class ConnectedCMS
{ {
var $title; public $title;
var $is_active; public $is_active;
var $cms_type; public $cms_type;
var $name; public $name = null;
var $ABSOLUTE_PATH_ELEARNINGMODULES; public $ABSOLUTE_PATH_ELEARNINGMODULES = null;
var $ABSOLUTE_PATH_SOAP; public $ABSOLUTE_PATH_SOAP = null;
var $RELATIVE_PATH_DB_CLASSES; public $RELATIVE_PATH_DB_CLASSES = false;
var $CLASS_PREFIX; public $CLASS_PREFIX = null;
var $auth_necessary; public $auth_necessary = null;
var $USER_AUTO_CREATE; public $USER_AUTO_CREATE = null;
var $USER_PREFIX; public $USER_PREFIX = null;
var $target_file; public $target_file = null;
var $logo_file; public $logo_file = null;
var $db_classes; public $db_classes;
var $soap_data; public $soap_data = null;
var $soap_client; public $soap_client;
var $types; public $types = null;
var $roles; public $roles = null;
var $db; public $db;
var $db_class; public $db_class;
var $link; public $link;
var $user; public $user;
var $permissions; public $permissions;
var $content_module; public $content_module;
/** /**
* constructor * constructor
* *
...@@ -53,7 +54,10 @@ class ConnectedCMS ...@@ -53,7 +54,10 @@ class ConnectedCMS
{ {
$this->cms_type = $cms; $this->cms_type = $cms;
$this->is_active = (bool) Config::get()->getValue("ELEARNING_INTERFACE_{$cms}_ACTIVE"); $this->is_active = (bool) Config::get()->getValue("ELEARNING_INTERFACE_{$cms}_ACTIVE");
$this->init($cms);
if ($cms) {
$this->init($cms);
}
} }
/** /**
...@@ -66,7 +70,7 @@ class ConnectedCMS ...@@ -66,7 +70,7 @@ class ConnectedCMS
public function init($cms) public function init($cms)
{ {
global $ELEARNING_INTERFACE_MODULES; global $ELEARNING_INTERFACE_MODULES;
$this->name = $ELEARNING_INTERFACE_MODULES[$cms]["name"]; $this->name = $ELEARNING_INTERFACE_MODULES[$cms]["name"] ?? null;
$this->ABSOLUTE_PATH_ELEARNINGMODULES = $ELEARNING_INTERFACE_MODULES[$cms]["ABSOLUTE_PATH_ELEARNINGMODULES"]; $this->ABSOLUTE_PATH_ELEARNINGMODULES = $ELEARNING_INTERFACE_MODULES[$cms]["ABSOLUTE_PATH_ELEARNINGMODULES"];
$this->ABSOLUTE_PATH_SOAP = $ELEARNING_INTERFACE_MODULES[$cms]["ABSOLUTE_PATH_SOAP"]; $this->ABSOLUTE_PATH_SOAP = $ELEARNING_INTERFACE_MODULES[$cms]["ABSOLUTE_PATH_SOAP"];
if (isset($ELEARNING_INTERFACE_MODULES[$cms]["RELATIVE_PATH_DB_CLASSES"])) if (isset($ELEARNING_INTERFACE_MODULES[$cms]["RELATIVE_PATH_DB_CLASSES"]))
...@@ -120,96 +124,118 @@ class ConnectedCMS ...@@ -120,96 +124,118 @@ class ConnectedCMS
*/ */
public function getConnectionStatus($cms = "") public function getConnectionStatus($cms = "")
{ {
if ($this->cms_type == "") $msg = [
{ 'path' => [],
];
if ($this->cms_type == "") {
$this->init($cms); $this->init($cms);
} }
// check connection to CMS
// check connection to CMS
if (!$this->auth_necessary) { if (!$this->auth_necessary) {
$msg["auth"]["info"] = sprintf(_("Eine Authentifizierung ist für dieses System nicht vorgesehen.")); $msg['auth'] = [
'info' => _('Eine Authentifizierung ist für dieses System nicht vorgesehen.')
];
} }
// check for SOAP-Interface // check for SOAP-Interface
if (in_array($this->CLASS_PREFIX, ['Ilias3','Ilias4','Ilias5'])) if (in_array($this->CLASS_PREFIX, ['Ilias3','Ilias4','Ilias5'])) {
{
$ch = curl_init($this->ABSOLUTE_PATH_ELEARNINGMODULES . 'login.php'); $ch = curl_init($this->ABSOLUTE_PATH_ELEARNINGMODULES . 'login.php');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch); curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) !== 200) { if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) !== 200) {
$msg["path"]["error"] = sprintf(_("Die Verbindung zum System \"%s\" konnte nicht hergestellt werden. Der Pfad \"$this->ABSOLUTE_PATH_ELEARNINGMODULES\" ist ungültig."), $this->name); $msg['path']['error'] = sprintf(
_('Die Verbindung zum System "%s" konnte nicht hergestellt werden. Der Pfad "%s" ist ungültig.'),
$this->name,
$this->ABSOLUTE_PATH_ELEARNINGMODULES
);
} else { } else {
$msg["path"]["info"] = sprintf(_("Die %s-Installation wurde gefunden."), $this->name); $msg['path']['info'] = sprintf(
_('Die %s-Installation wurde gefunden.'),
$this->name
);
} }
$msg['soap'] = [];
if (!Config::get()->SOAP_ENABLE) { if (!Config::get()->SOAP_ENABLE) {
$msg["soap"]["error"] = sprintf(_("Das Stud.IP-Modul für die SOAP-Schnittstelle ist nicht aktiviert. Ändern Sie den entsprechenden Eintrag in der Konfigurationsdatei \"local.inc\".")); $msg['soap']['error'] = _('Das Stud.IP-Modul für die SOAP-Schnittstelle ist nicht aktiviert. Ändern Sie den entsprechenden Eintrag in der Konfigurationsdatei "local.inc".');
} } elseif (!is_array($this->soap_data)) {
elseif (! is_array($this->soap_data)) { $msg['soap']['error'] = _('Die SOAP-Verbindungsdaten sind für dieses System nicht gesetzt. Ergänzen Sie die Einstellungen für dieses Systems um den Eintrag "soap_data" in der Konfigurationsdatei "local.inc".');
$msg["soap"]["error"] = sprintf(_("Die SOAP-Verbindungsdaten sind für dieses System nicht gesetzt. Ergänzen Sie die Einstellungen für dieses Systems um den Eintrag \"soap_data\" in der Konfigurationsdatei \"local.inc\".")); } else {
}
else
{
$this->soap_client = new StudipSoapClient($this->ABSOLUTE_PATH_SOAP); $this->soap_client = new StudipSoapClient($this->ABSOLUTE_PATH_SOAP);
$msg["soap"]["info"] = sprintf(_("Das SOAP-Modul ist aktiv.")); $msg['soap']['info'] = _('Das SOAP-Modul ist aktiv.');
} }
} else { } else {
$file = fopen($this->ABSOLUTE_PATH_ELEARNINGMODULES."", "r"); $file = fopen($this->ABSOLUTE_PATH_ELEARNINGMODULES, 'r');
if ($file == false) if ($file === false) {
{ $msg['path']['error'] = sprintf(
$msg["path"]["error"] = sprintf(_("Die Verbindung zum System \"%s\" konnte nicht hergestellt werden. Der Pfad \"$this->ABSOLUTE_PATH_ELEARNINGMODULES\" ist ungültig."), $this->name); _('Die Verbindung zum System "%s" konnte nicht hergestellt werden. Der Pfad "%s" ist ungültig.'),
} $this->name,
else $this->ABSOLUTE_PATH_ELEARNINGMODULES
{ );
} else {
fclose($file); fclose($file);
$msg["path"]["info"] = sprintf(_("Die %s-Installation wurde gefunden."), $this->name); $msg['path']['info'] = sprintf(
_("Die %s-Installation wurde gefunden."),
$this->name
);
// check if target-file exists // check if target-file exists
$file = fopen($this->ABSOLUTE_PATH_ELEARNINGMODULES.$this->target_file, "r"); $msg['auth'] = [];
if ($file == false)
{ $file = fopen($this->ABSOLUTE_PATH_ELEARNINGMODULES . $this->target_file, 'r');
$msg["auth"]["error"] = sprintf(_("Die Zieldatei \"%s\" liegt nicht im Hauptverzeichnis der %s-Installation."), $this->target_file, $this->name); if ($file === false) {
} $msg['auth']['error'] = sprintf(
else _('Die Zieldatei "%s" liegt nicht im Hauptverzeichnis der %s-Installation.'),
{ $this->target_file,
$this->name
);
} else {
fclose($file); fclose($file);
$msg["auth"]["info"] = sprintf(_("Die Zieldatei ist vorhanden.")); $msg['auth']['info'] = _('Die Zieldatei ist vorhanden.');
} }
} }
} }
$el_path = $GLOBALS['STUDIP_BASE_PATH'] . '/lib/elearning'; $el_path = $GLOBALS['STUDIP_BASE_PATH'] . '/lib/elearning';
// check if needed classes exist // check if needed classes exist
if (!file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedUser.class.php") && ($this->auth_necessary)) { $files = [
$msg["class_user"]["error"] .= sprintf(_("Die Datei \"%s\" existiert nicht."), $el_path."/" . $this->CLASS_PREFIX . "ConnectedUser.class.php"); 'class_link' => "{$el_path}/{$this->CLASS_PREFIX}ConnectedLink.class.php",
} 'class_content' => "{$el_path}/{$this->CLASS_PREFIX}ContentModule.class.php",
if (!file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedPermissions.class.php") && ($this->auth_necessary)) { 'class_cms' => "{$el_path}/{$this->CLASS_PREFIX}ConnectedCMS.class.php",
$msg["class_perm"]["error"] .= sprintf(_("Die Datei \"%s\" existiert nicht."), $el_path."/" . $this->CLASS_PREFIX . "ConnectedPermissions.class.php"); ];
}
if (!file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedLink.class.php")) { if ($this->auth_necessary) {
$msg["class_link"]["error"] .= sprintf(_("Die Datei \"%s\" existiert nicht."), $el_path."/" . $this->CLASS_PREFIX . "ConnectedLink.class.php"); $files['class_user'] = "{$el_path}/{$this->CLASS_PREFIX}ConnectedUser.class.php";
$files['class_perm'] = "{$el_path}/{$this->CLASS_PREFIX}ConnectedPermissions.class.php";
} }
if (!file_exists($el_path."/" . $this->CLASS_PREFIX . "ContentModule.class.php")) {
$msg["class_content"]["error"] .= sprintf(_("Die Datei \"%s\" existiert nicht."), $el_path."/" . $this->CLASS_PREFIX . "ContentModule.class.php"); $errors = 0;
} foreach ($files as $index => $file) {
if (!file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedCMS.class.php")) { if (!file_exists($file)) {
$msg["class_cms"]["error"] .= sprintf(_("Die Datei \"%s\" existiert nicht."), $el_path."/" . $this->CLASS_PREFIX . "ConnectedCMS.class.php"); $msg[$index] = [
} 'error' => sprintf(_('Die Datei "%s" existiert nicht.'), $file),
if (file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedCMS.class.php") && ];
(file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedUser.class.php") || (!$this->auth_necessary)) && $errors += 1;
(file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedPermissions.class.php") || (!$this->auth_necessary)) && }
file_exists($el_path."/" . $this->CLASS_PREFIX . "ConnectedLink.class.php") &&
file_exists($el_path."/" . $this->CLASS_PREFIX . "ContentModule.class.php"))
{
require_once ($el_path."/" . $this->CLASS_PREFIX . "ConnectedCMS.class.php");
$msg["classes"]["info"] .= sprintf(_("Die Klassen der Schnittstelle zum System \"%s\" wurden geladen."), $this->name);
} }
else
{ $msg['classes'] = [];
$msg["classes"]["error"] .= sprintf(_("Die Klassen der Schnittstelle zum System \"%s\" wurden nicht geladen."), $this->name); if ($errors === 0) {
require_once $files['class_cms'];
$msg['classes']['info'] = sprintf(
_('Die Klassen der Schnittstelle zum System "%s" wurden geladen.'),
$this->name
);
} else {
$msg['classes']['error'] = sprintf(
_('Die Klassen der Schnittstelle zum System "%s" wurden nicht geladen.'),
$this->name
);
} }
return $msg; return $msg;
......
...@@ -68,22 +68,16 @@ if (Config::get()->ELEARNING_INTERFACE_ENABLE) ...@@ -68,22 +68,16 @@ if (Config::get()->ELEARNING_INTERFACE_ENABLE)
unset($cms_select); unset($cms_select);
} }
if ($messages["error"] != "") if (!empty($messages["error"])) {
{
PageLayout::postError($messages["error"]); PageLayout::postError($messages["error"]);
} }
if ($messages["info"] != "") if (!empty($messages["info"])) {
{
PageLayout::postInfo($messages["info"]); PageLayout::postInfo($messages["info"]);
} }
if ($cms_select == "") echo ELearningUtils::getCMSSelectbox(_("Bitte wählen Sie ein angebundenes System für die Schnittstelle: "), false) . "\n\n<br><br>";
echo ELearningUtils::getCMSSelectbox(_("Bitte wählen Sie ein angebundenes System für die Schnittstelle: "), false) . "\n\n<br><br>";
else
echo ELearningUtils::getCMSSelectbox(_("Bitte wählen Sie ein angebundenes System für die Schnittstelle: "), false) . "\n\n<br><br>";
if ($cms_select != "") if (!empty($cms_select)) {
{
echo "<table>"; echo "<table>";
$error_count = 0; $error_count = 0;
foreach ($connection_status as $type => $msg) foreach ($connection_status as $type => $msg)
...@@ -167,18 +161,17 @@ if (Config::get()->ELEARNING_INTERFACE_ENABLE) ...@@ -167,18 +161,17 @@ if (Config::get()->ELEARNING_INTERFACE_ENABLE)
Helpbar::Get()->addPlainText(_('Aktionen'), _('Nachdem Sie ein angebundenes System ausgewählt haben wird die Verbindung zum System geprüft.'), Icon::create('info')); Helpbar::Get()->addPlainText(_('Aktionen'), _('Nachdem Sie ein angebundenes System ausgewählt haben wird die Verbindung zum System geprüft.'), Icon::create('info'));
// Anzeige, wenn noch keine Account-Zuordnung besteht // Anzeige, wenn noch keine Account-Zuordnung besteht
switch($status_info) switch ($status_info ?? null) {
{ case "active":
case "active": PageLayout::postSuccess(sprintf(_("Die Verbindung zum System \"%s\" ist <b>aktiv</b>. Sie können die Einbindung des Systems in Stud.IP jederzeit deaktivieren."), htmlReady($connected_cms[$cms_select]->getName())));
PageLayout::postSuccess(sprintf(_("Die Verbindung zum System \"%s\" ist <b>aktiv</b>. Sie können die Einbindung des Systems in Stud.IP jederzeit deaktivieren."), htmlReady($connected_cms[$cms_select]->getName()))); break;
break; case "not active":
case "not active": PageLayout::postWarning(sprintf(_("Die Verbindung zum System \"%s\" steht, das System ist jedoch nicht aktiviert. Sie können die Einbindung des Systems in Stud.IP jederzeit aktivieren. Solange die Verbindung nicht aktiviert wurde, werden die Module des Systems \"%s\" in Stud.IP nicht angezeigt."), htmlReady($connected_cms[$cms_select]->getName()), htmlReady($connected_cms[$cms_select]->getName())));
PageLayout::postWarning(sprintf(_("Die Verbindung zum System \"%s\" steht, das System ist jedoch nicht aktiviert. Sie können die Einbindung des Systems in Stud.IP jederzeit aktivieren. Solange die Verbindung nicht aktiviert wurde, werden die Module des Systems \"%s\" in Stud.IP nicht angezeigt."), htmlReady($connected_cms[$cms_select]->getName()), htmlReady($connected_cms[$cms_select]->getName()))); break;
break; case "error":
case "error": PageLayout::postError(sprintf(_("Bei der Prüfung der Verbindung sind Fehler aufgetreten. Sie müssen zunächst die Einträge in der Konfigurationsdatei korrigieren, bevor das System angebunden werden kann."), $connected_cms[$cms_select]->getName()));
PageLayout::postError(sprintf(_("Bei der Prüfung der Verbindung sind Fehler aufgetreten. Sie müssen zunächst die Einträge in der Konfigurationsdatei korrigieren, bevor das System angebunden werden kann."), $connected_cms[$cms_select]->getName())); break;
break; }
}
// terminate objects // terminate objects
if (is_array($connected_cms)) if (is_array($connected_cms))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment