Skip to content
Snippets Groups Projects
Commit 40876d75 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

remove unused table admissionrule_inst as well as jstree dependency and adjust...

remove unused table admissionrule_inst as well as jstree dependency and adjust ui accordingly, fixes #973

Closes #973

Merge request studip/studip!561
parent a3ef933c
No related branches found
No related tags found
No related merge requests found
Showing
with 98 additions and 4913 deletions
<?php <?php
/** /**
* Admission_RuleAdministrationController - Global administration * Admission_RuleadministrationController - Global administration
* of available admission rules * of available admission rules
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* @since 3.0 * @since 3.0
*/ */
class Admission_RuleAdministrationController extends AuthenticatedController class Admission_RuleadministrationController extends AuthenticatedController
{ {
/** /**
* @see AuthenticatedController::before_filter * @see AuthenticatedController::before_filter
...@@ -32,12 +32,14 @@ class Admission_RuleAdministrationController extends AuthenticatedController ...@@ -32,12 +32,14 @@ class Admission_RuleAdministrationController extends AuthenticatedController
$sidebar = Sidebar::Get(); $sidebar = Sidebar::Get();
$views = new ViewsWidget(); $views = new ViewsWidget();
$views->addLink(_('Installierte Anmelderegeln'), $views->addLink(
$this->url_for('admission/ruleadministration')) _('Installierte Anmelderegeln'),
->setActive($action === 'index'); $this->url_for('admission/ruleadministration')
$views->addLink(_('Regelkompatibilität'), )->setActive($action === 'index');
$this->url_for('admission/ruleadministration/compatibility')) $views->addLink(
->setActive($action === 'compatibility'); _('Regelkompatibilität'),
$this->url_for('admission/ruleadministration/compatibility')
)->setActive($action === 'compatibility');
$sidebar->addWidget($views); $sidebar->addWidget($views);
} }
...@@ -49,12 +51,27 @@ class Admission_RuleAdministrationController extends AuthenticatedController ...@@ -49,12 +51,27 @@ class Admission_RuleAdministrationController extends AuthenticatedController
PageLayout::setTitle(_('Verwaltung von Anmelderegeln')); PageLayout::setTitle(_('Verwaltung von Anmelderegeln'));
$this->ruleTypes = AdmissionRule::getAvailableAdmissionRules(false); $this->ruleTypes = AdmissionRule::getAvailableAdmissionRules(false);
// Available rule classes. // Available rule classes.
$ruleClasses = array_map(function($s) { return mb_strtolower($s); }, array_keys($this->ruleTypes)); $ruleClasses = array_map(function($s) {
return mb_strtolower($s);
}, array_keys($this->ruleTypes));
// Found directories with rule definitions. // Found directories with rule definitions.
$ruleDirs = array_map(function($s) { return basename($s); }, glob($GLOBALS['STUDIP_BASE_PATH'].'/lib/admissionrules/*', GLOB_ONLYDIR)); $ruleDirs = array_map(function($s) {
return basename($s);
}, glob($GLOBALS['STUDIP_BASE_PATH'] . '/lib/admissionrules/*', GLOB_ONLYDIR));
// Compare the two. // Compare the two.
$this->newRules = array_diff($ruleDirs, $ruleClasses); $this->newRules = array_diff($ruleDirs, $ruleClasses);
if (count($this->newRules) > 0) {
PageLayout::postInfo(
_('Es wurden Anmelderegeln gefunden, die zwar im'
. 'Dateisystem unter lib/admissionrules vorhanden sind, aber noch nicht '
. 'installiert wurden:'),
$this->newRules
);
}
} }
public function compatibility_action() public function compatibility_action()
...@@ -71,77 +88,13 @@ class Admission_RuleAdministrationController extends AuthenticatedController ...@@ -71,77 +88,13 @@ class Admission_RuleAdministrationController extends AuthenticatedController
* *
* @param String $ruleType Class name of the rule type to check. * @param String $ruleType Class name of the rule type to check.
*/ */
public function check_activation_action($ruleType) public function toggle_activation_action($ruleType)
{ {
PageLayout::setTitle(_('Verfügbarkeit der Anmelderegel')); $query = "UPDATE `admissionrules`
$this->ruleTypes = AdmissionRule::getAvailableAdmissionRules(false); SET `active` = !`active`
$this->type = $ruleType; WHERE `ruletype` = ?";
$stmt = DBManager::get()->prepare("SELECT ai.`institute_id` DBManager::get()->execute($query, [$ruleType]);
FROM `admissionrule_inst` ai
JOIN `admissionrules` r ON (ai.`rule_id`=r.`id`)
WHERE r.`ruletype`=?");
$stmt->execute([$ruleType]);
$this->activated = [];
$globally = true;
$atInst = false;
while ($current = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($globally) $globally = false;
if (!$atInst) $atInst = true;
$institute = new Institute($current['institute_id']);
$this->activated[$current['institute_id']] = $institute->name;
}
$this->globally = $globally;
$this->atInst = $atInst;
}
/**
* (De-)Activates the given rule type for system wide usage.
*
* @param String $ruleType the class name of the rule type to activate.
*/
public function activate_action($ruleType)
{
CSRFProtection::verifyUnsafeRequest();
if (Request::submitted('submit')) {
$success = false;
$stmt = DBManager::get()->prepare("UPDATE `admissionrules` SET `active`=? WHERE `ruletype`=?");
$success = $stmt->execute([(bool) Request::get('enabled'), $ruleType]);
// Get corresponding rule id.
$stmt = DBManager::get()->prepare("SELECT `id` FROM `admissionrules` WHERE `ruletype`=? LIMIT 1");
$success = $stmt->execute([$ruleType]);
if ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
if (Request::get('enabled')) {
$stmt = DBManager::get()->prepare("DELETE FROM `admissionrule_inst`
WHERE `rule_id` IN (SELECT `id` FROM `admissionrules` WHERE `ruletype`=?);");
$success = $stmt->execute([$ruleType]);
if (Request::get(activated) == 'inst') {
$institutes = Request::getArray('institutes');
$query = "INSERT INTO `admissionrule_inst`
(`rule_id`, `institute_id`, `mkdate`)
VALUES ";
$params = [];
$first = true;
foreach ($institutes as $institute) {
if ($first) {
$first = false;
} else {
$query .= ", ";
}
$query .= "(?, ?, UNIX_TIMESTAMP())";
$params[] = $data['id'];
$params[] = $institute;
}
$stmt = DBManager::get()->prepare($query);
$success = $stmt->execute($params);
}
}
}
if ($success) {
PageLayout::postSuccess(_('Ihre Einstellungen wurden gespeichert.'));
} else {
PageLayout::postError(_('Ihre Einstellungen konnten nicht gespeichert werden.'));
}
}
$this->redirect('admission/ruleadministration'); $this->redirect('admission/ruleadministration');
} }
...@@ -238,7 +191,5 @@ class Admission_RuleAdministrationController extends AuthenticatedController ...@@ -238,7 +191,5 @@ class Admission_RuleAdministrationController extends AuthenticatedController
if (!check_ticket(Request::option('ticket'))) { if (!check_ticket(Request::option('ticket'))) {
throw new InvalidArgumentException(_('Das Ticket für diese Aktion ist ungültig.')); throw new InvalidArgumentException(_('Das Ticket für diese Aktion ist ungültig.'));
} }
} }
} }
<?php
use Studip\Button, Studip\LinkButton;
?>
<form class="default" id="rule_activation_form"
action="<?= $controller->url_for('admission/ruleadministration/activate/' . $type) ?>" method="post">
<?= CSRFProtection::tokenTag() ?>
<fieldset>
<legend><?= _('Verfügbarkeit der Anmelderegel') ?></legend>
<label class="caption">
<input type="checkbox" name="enabled"
onclick="STUDIP.Admission.checkRuleActivation('rule_activation_form')"<?= $ruleTypes[$type]['active'] ? ' checked="checked"' : '' ?>/>&nbsp;<?= _('Regel ist aktiv') ?>
</label>
<section>
<?= _('Regel ist verfügbar') ?>
</section>
<label>
<input type="radio" name="activated" value="studip"
onclick="STUDIP.Admission.checkRuleActivation('rule_activation_form')"<?= $globally ? ' checked="checked"' : '' ?>>
<?= _('systemweit') ?>
</label>
<label>
<input type="radio" name="activated" value="inst"
onclick="STUDIP.Admission.checkRuleActivation('rule_activation_form')"<?= $atInst ? ' checked="checked"' : '' ?>>
<?= _('an ausgewählten Einrichtungen') ?>
</label>
<div id="institutes_activation"<?= $globally ? ' style="display:none"' : '' ?>>
<ul>
<?php foreach (Institute::findBySQL("`fakultaets_id`=`Institut_id`") as $fak) { ?>
<li id="<?= $fak->Institut_id ?>">
<input type="checkbox" name="institutes[]"
value="<?= $fak->Institut_id ?>"<?= $activated[$fak->Institut_id] ? ' checked="checked"' : '' ?>>
<a href="">
<?= htmlReady($fak->name) ?>
</a>
<?php if ($fak->sub_institutes) { ?>
<ul>
<?php
foreach ($fak->sub_institutes as $inst) {
if ($inst->Institut_id != $fak->Institut_id) {
?>
<li id="<?= $inst->Institut_id ?>">
<input type="checkbox" name="institutes[]"
value="<?= $inst->Institut_id ?>"<?= $activated[$inst->Institut_id] ? ' checked="checked"' : '' ?>>
<a href="">
<?= htmlReady($inst->name) ?>
</a>
</li>
<?php
}
}
?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
<script type="text/javascript">
//<!--
$(function () {
$('#institutes_activation').bind('loaded.jstree', function (event, data) {
// Show checked checkboxes.
var checkedItems = $('#institutes_activation').find('.jstree-checked');
checkedItems.removeClass('jstree-unchecked');
// Open parent nodes of checked nodes.
checkedItems.parents().each(function () {
data.inst.open_node(this, false, true);
});
}).bind('select_node.jstree', function (event, data) {
return data.inst.toggle_node(data.rslt.obj);
}).jstree({
'core': {
'animation': 100,
'open_parents': true
},
'checkbox': {
'real_checkboxes': true,
'selected_parent_open': true,
'override_ui': false
},
'themes': {
'icons': false
},
'plugins': ['html_data', 'themes', 'checkbox', 'ui']
});
});
//-->
</script>
</div>
</fieldset>
<footer data-dialog-button>
<?= Button::createAccept(_('Speichern'), 'submit') ?>
<?= LinkButton::createCancel(_('Abbrechen'), '', ['rel' => 'close']) ?>
</footer>
</form>
<?php
if (isset($flash['error'])) {
echo MessageBox::error($flash['error'], $flash['error_detail']);
} elseif (isset($flash['success'])) {
echo MessageBox::success($flash['success']);
}
// New rules found in file system that are not yet installed.
if ($newRules) {
echo MessageBox::info(_('Es wurden Anmelderegeln gefunden, die zwar im' .
'Dateisystem unter lib/admissionrules vorhanden sind, aber noch nicht ' .
'installiert wurden:'), $newRules);
}
?>
<?php
if ($ruleTypes) : ?>
<table class="default" id="admissionrules">
<caption><?= _('Installierte Anmelderegeln:') ?></caption>
<thead>
<th><?= _('aktiv?') ?></th>
<th><?= _('Art der Anmelderegel') ?></th>
</thead>
<tbody>
<?php
foreach ($ruleTypes as $type => $details) {
if ($details['active']) {
$text = _('Diese Regel ist aktiv. Klicken Sie hier, um die Einstellungen zu bearbeiten.');
$img = 'checkbox-checked';
} else {
$text = _('Diese Regel ist inaktiv. Klicken Sie hier, um die Einstellungen zu bearbeiten.');
$img = 'checkbox-unchecked';
}
?>
<tr id="ruletype_<?= $type ?>">
<td>
<a href="<?= $controller->url_for('admission/ruleadministration/check_activation', $type) ?>"
data-dialog>
<?= Icon::create($img, 'clickable', ['title' => $text])->asImg() ?>
</a>
</td>
<td>
<b><?= htmlReady($details['name']) ?></b> (<?= $type ?>)
<br/>
<?= htmlReady($details['description']) ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<? else : ?>
<?= MessageBox::info(sprintf(_('Sie haben noch keine Anmelderegeln installiert!'))); ?>
<?php endif ?>
\ No newline at end of file
<? if ($ruleTypes) : ?>
<table class="default" id="admissionrules">
<caption><?= _('Installierte Anmelderegeln:') ?></caption>
<thead>
<tr>
<th><?= _('aktiv?') ?></th>
<th><?= _('Art der Anmelderegel') ?></th>
</tr>
</thead>
<tbody>
<? foreach ($ruleTypes as $type => $details): ?>
<tr id="ruletype_<?= htmlReady($type) ?>">
<td>
<a href="<?= $controller->toggle_activation($type) ?>">
<? if ($details['active']): ?>
<?= Icon::create('checkbox-checked')->asImg([
'title' => _('Diese Regel ist aktiv. Klicken Sie hier, um sie zu deaktivieren.')
]) ?>
<? else: ?>
<?= Icon::create('checkbox-unchecked')->asImg([
'title' => _('Diese Regel ist inaktiv. Klicken Sie hier, um sie zu aktivieren.')
]) ?>
<? endif; ?>
</a>
</td>
<td>
<strong><?= htmlReady($details['name']) ?></strong> (<?= htmlReady($type) ?>)
<br>
<?= htmlReady($details['description']) ?>
</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
<? else : ?>
<?= MessageBox::info(_('Sie haben noch keine Anmelderegeln installiert!'))->hideClose(); ?>
<? endif ?>
<?php
/**
* @see https://gitlab.studip.de/studip/studip/-/issues/973
*/
final class RemoveTableAdmissionruleInst extends Migration
{
public function description()
{
return 'Removes the unused table admissionrule_inst';
}
protected function up()
{
$query = "DROP TABLE IF EXISTS `admissionrule_inst`";
DBManager::get()->exec($query);
}
protected function down()
{
$query = "CREATE TABLE IF NOT EXISTS `admissionrule_inst` (
`rule_id` CHAR(32) COLLATE latin1_bin NOT NULL,
`institute_id` CHAR(32) COLLATE latin1_bin NOT NULL,
`mkdate` INT(11) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`rule_id`,`institute_id`)
)";
DBManager::get()->exec($query);
}
}
import "./jquery/jstree/jquery.jstree.js"
import "./bootstrap/admission.js" import "./bootstrap/admission.js"
This diff is collapsed.
resources/assets/javascripts/jquery/jstree/themes/default/d.gif

2.88 KiB

resources/assets/javascripts/jquery/jstree/themes/default/d.png

7.46 KiB

resources/assets/javascripts/jquery/jstree/themes/default/throbber.gif

1.81 KiB

...@@ -168,43 +168,6 @@ const Admission = { ...@@ -168,43 +168,6 @@ const Admission = {
return false; return false;
}, },
/**
* Creates a tree view from the HTML list in <elementId> using the
* given data for special node types.
*
* @param String elementId
* @param typesData JS object with tree nodes types
* (@see http://www.jstree.com/documentation/types)
*/
makeTree: function(elementId, typesData) {
var config = {
core: {
animation: 100,
open_parents: true,
initially_open: ['root']
},
checkbox: {
real_checkboxes: true,
selected_parent_open: true,
override_ui: false,
two_state: true
},
plugins: ['html_data', 'themes', 'types', 'checkbox', 'ui']
};
config.types = { types: typesData };
$('#' + elementId)
.on('loaded.jstree', function(event, data) {
// Show checked checkboxes.
var checkedItems = $('#' + elementId).find('.jstree-checked');
checkedItems.removeClass('jstree-unchecked');
// Open parent nodes of checked nodes.
checkedItems.parents().each(function() {
data.inst.open_node(this, false, true);
});
})
.jstree(config);
},
updateInstitutes: function(elementId, instURL, courseURL, mode) { updateInstitutes: function(elementId, instURL, courseURL, mode) {
if (elementId !== '') { if (elementId !== '') {
var query = ''; var query = '';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment