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

allow forcing of 'manual auto insert', fixes #2576

Closes #2576

Merge request studip/studip!1735
parent bdded9bf
No related branches found
No related tags found
No related merge requests found
...@@ -149,14 +149,17 @@ class Admin_AutoinsertController extends AuthenticatedController ...@@ -149,14 +149,17 @@ class Admin_AutoinsertController extends AuthenticatedController
$this->seminar_search = []; $this->seminar_search = [];
PageLayout::setTitle(_('Manuelles Eintragen von Nutzergruppen in Veranstaltungen')); PageLayout::setTitle(_('Manuelles Eintragen von Nutzergruppen in Veranstaltungen'));
if (Request::submitted('submit')) { if (Request::submittedSome('submit', 'force')) {
$filters = array_filter(Request::getArray('filter')); $filters = array_filter(Request::getArray('filter'));
if (!Request::get('sem_id') || Request::get('sem_id') == 'false') { $force = Request::bool('force', false);
$seminar_id = Request::option('sem_id');
if (!$seminar_id || $seminar_id === 'false') {
PageLayout::postError(_('Ungültiger Aufruf')); PageLayout::postError(_('Ungültiger Aufruf'));
} elseif (!count($filters)) { } elseif (!count($filters)) {
PageLayout::postError(_('Keine Filterkriterien gewählt')); PageLayout::postError(_('Keine Filterkriterien gewählt'));
} else { } else {
$seminar = Seminar::GetInstance(Request::option('sem_id')); $seminar = Seminar::GetInstance($seminar_id);
$userlookup = new UserLookup(); $userlookup = new UserLookup();
foreach ($filters as $type => $values) { foreach ($filters as $type => $values) {
...@@ -166,9 +169,9 @@ class Admin_AutoinsertController extends AuthenticatedController ...@@ -166,9 +169,9 @@ class Admin_AutoinsertController extends AuthenticatedController
$real_users = 0; $real_users = 0;
foreach ($user_ids as $user_id) { foreach ($user_ids as $user_id) {
if (!AutoInsert::checkAutoInsertUser(Request::option('sem_id'), $user_id)) { if ($force || !AutoInsert::checkAutoInsertUser($seminar_id, $user_id)) {
$seminar->addMember($user_id); $real_users += $seminar->addMember($user_id) ? 1 : 0;
$real_users += AutoInsert::saveAutoInsertUser(Request::option('sem_id'), $user_id); AutoInsert::saveAutoInsertUser($seminar_id, $user_id);
} }
} }
...@@ -192,6 +195,7 @@ class Admin_AutoinsertController extends AuthenticatedController ...@@ -192,6 +195,7 @@ class Admin_AutoinsertController extends AuthenticatedController
} }
$this->redirect('admin/autoinsert/manual'); $this->redirect('admin/autoinsert/manual');
return;
} }
} }
......
...@@ -134,6 +134,25 @@ ...@@ -134,6 +134,25 @@
</tr> </tr>
</tbody> </tbody>
<? endif ?> <? endif ?>
<thead>
<tr>
<th colspan="3"><?= _('Einstellungen') ?></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">
<label>
<input type="checkbox" name="force" value="1">
<?= _('Eintragung forcieren') ?>
<?= tooltipIcon(implode("\n", [
_('Über diese Einstellung kann forciert werden, dass alle gefundenen Personen in die Veranstaltung eingetragen werden.'),
_('Ansonsten werden nur die Personen eingetragen, die bislang noch nicht über diesen Mechanismus eingetragen wurden.'),
])) ?>
</label>
</td>
</tr>
</tbody>
<tfoot> <tfoot>
<tr> <tr>
<td colspan="3"> <td colspan="3">
...@@ -157,20 +176,20 @@ ...@@ -157,20 +176,20 @@
if (!$(this).next().length || !$(this).next().is('span')) { if (!$(this).next().length || !$(this).next().is('span')) {
$(this).after($('<span id="autoinsert_count" style="vertical-align: middle;"/>')); $(this).after($('<span id="autoinsert_count" style="vertical-align: middle;"/>'));
} }
$.getJSON('<?= $controller->manual_count() ?>', $.getJSON(
$(this).closest('form').serializeArray(), '<?= $controller->manual_count() ?>',
function (json) { $(this).closest('form').serializeArray()
var result = ""; ).done(function (json) {
if (!json || json.error) { let result = '';
result = '<?= _('Fehler') ?>: '; if (!json || json.error) {
result += json.error || '<?= _('Fehler bei der Übertragung') ?>'; result = '<?= _('Fehler') ?>: ';
} else { result += json.error || '<?= _('Fehler bei der Übertragung') ?>';
result = '<?= _('Gefundene Nutzer') ?>: '; } else {
result += "<strong>" + json.users + "</strong>"; result = '<?= _('Gefundene Personen') ?>: ';
} result += "<strong>" + json.users + "</strong>";
$('#autoinsert_count').html(result);
} }
); $('#autoinsert_count').html(' ' + result);
});
event.preventDefault(); event.preventDefault();
}); });
$('input[name^=remove_filter]').click(function (event) { $('input[name^=remove_filter]').click(function (event) {
......
...@@ -313,12 +313,11 @@ class AutoInsert ...@@ -313,12 +313,11 @@ class AutoInsert
*/ */
public static function saveAutoInsertUser($seminar_id, $user_id) public static function saveAutoInsertUser($seminar_id, $user_id)
{ {
$query = "INSERT INTO auto_insert_user (Seminar_id, user_id, mkdate) $query = "INSERT IGNORE INTO auto_insert_user (Seminar_id, user_id, mkdate)
SELECT ?, user_id, UNIX_TIMESTAMP() FROM auth_user_md5 WHERE SELECT ?, user_id, UNIX_TIMESTAMP()
user_id=? AND perms NOT IN('root','admin')"; FROM auth_user_md5
$statement = DBManager::get()->prepare($query); WHERE user_id = ? AND perms NOT IN ('root','admin')";
$statement->execute([$seminar_id, $user_id]); return DBManager::get()->execute($query, [$seminar_id, $user_id]);
return $statement->rowCount();
} }
/** /**
......
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