add role filter to bulk message

This commit is contained in:
xiaomlove
2022-09-20 18:47:33 +08:00
parent e7211b6492
commit dd36d6a654
5 changed files with 40 additions and 24 deletions
@@ -85,7 +85,7 @@ class ExamResource extends Resource
Forms\Components\Section::make(__('label.exam.section_time'))->schema([ Forms\Components\Section::make(__('label.exam.section_time'))->schema([
Forms\Components\DateTimePicker::make('begin')->label(__('label.begin')), Forms\Components\DateTimePicker::make('begin')->label(__('label.begin')),
Forms\Components\DateTimePicker::make('end')->label(__('label.begin')), Forms\Components\DateTimePicker::make('end')->label(__('label.end')),
Forms\Components\TextInput::make('duration') Forms\Components\TextInput::make('duration')
->integer() ->integer()
->columnSpan(['sm' => 2]) ->columnSpan(['sm' => 2])
@@ -118,7 +118,7 @@ class ExamResource extends Resource
Tables\Columns\TextColumn::make('name')->searchable()->label(__('label.name')), Tables\Columns\TextColumn::make('name')->searchable()->label(__('label.name')),
Tables\Columns\TextColumn::make('indexFormatted')->label(__('label.exam.index_formatted'))->html(), Tables\Columns\TextColumn::make('indexFormatted')->label(__('label.exam.index_formatted'))->html(),
Tables\Columns\TextColumn::make('begin')->label(__('label.begin')), Tables\Columns\TextColumn::make('begin')->label(__('label.begin')),
Tables\Columns\TextColumn::make('end')->label(__('label.begin')), Tables\Columns\TextColumn::make('end')->label(__('label.end')),
Tables\Columns\TextColumn::make('durationText')->label(__('label.duration')), Tables\Columns\TextColumn::make('durationText')->label(__('label.duration')),
Tables\Columns\TextColumn::make('filterFormatted')->label(__('label.exam.filter_formatted'))->html(), Tables\Columns\TextColumn::make('filterFormatted')->label(__('label.exam.filter_formatted'))->html(),
Tables\Columns\BooleanColumn::make('is_discovered')->label(__('label.exam.is_discovered')), Tables\Columns\BooleanColumn::make('is_discovered')->label(__('label.exam.is_discovered')),
+1 -1
View File
@@ -64,7 +64,7 @@ $classes = array_chunk(\App\Models\User::$classes, 4, true);
</table> </table>
</td> </td>
</tr> </tr>
<?php do_action('increment_bulk_form_filters') ?> <?php do_action('form_role_filter', 'Add to Role') ?>
<tr><td class="rowhead" valign="top">Subject </td><td class="rowfollow"><input type=text name=subject size=82></td></tr> <tr><td class="rowhead" valign="top">Subject </td><td class="rowfollow"><input type=text name=subject size=82></td></tr>
<tr><td class="rowhead" valign="top">Reason </td><td class="rowfollow"><textarea name=msg cols=80 rows=5><?php echo $body ?? ''?></textarea></td></tr> <tr><td class="rowhead" valign="top">Reason </td><td class="rowfollow"><textarea name=msg cols=80 rows=5><?php echo $body ?? ''?></textarea></td></tr>
<tr> <tr>
+26 -18
View File
@@ -24,35 +24,43 @@ if ($_GET["returnto"] || $_SERVER["HTTP_REFERER"])
<?php <?php
if ($_GET["sent"] == 1) { if ($_GET["sent"] == 1) {
?> ?>
<tr><td colspan=2><font color=red><b>The message has ben sent.</font></b></tr></td> <tr><td colspan=2><font color=red><b>The message has ben sent.</b></font></td></tr>
<?php <?php
} }
?> ?>
<tr> <tr>
<td><b>Send to:</b><br /> <td><b>Send to class:</b></td>
<table style="border: 0" width="100%" cellpadding="0" cellspacing="0"> <td>
<?php <table style="border: 0" width="100%" cellpadding="0" cellspacing="0">
foreach ($classes as $chunk) { <?php
printf('<tr>'); foreach ($classes as $chunk) {
foreach ($chunk as $class => $info) { printf('<tr>');
printf('<td style="border: 0"><label><input type="checkbox" name="clases[]" value="%s" />%s</label></td>', $class, $info['text']); foreach ($chunk as $class => $info) {
} printf('<td style="border: 0"><label><input type="checkbox" name="classes[]" value="%s" />%s</label></td>', $class, $info['text']);
printf('</tr>'); }
} printf('</tr>');
?> }
</table> ?>
</td> </table>
</td>
</tr> </tr>
<tr><td>Subject <input type=text name=subject size=75></tr></td> <?php do_action('form_role_filter', 'Send to Role:') ?>
<tr><td><textarea name=msg cols=80 rows=15><?php echo $body?></textarea></td></tr>
<tr> <tr>
<td colspan=1><div align="center"><b>Sender:&nbsp;&nbsp;</b> <td class="rowhead">Subject</td>
<td> <input type=text name=subject size=75></td>
</tr>
<tr>
<td class="rowhead">Message</td>
<td><textarea name=msg cols=80 rows=15><?php echo $body?></textarea></td>
</tr>
<tr>
<td colspan=2><div align="center"><b>Sender:&nbsp;&nbsp;</b>
<?php echo $CURUSER['username']?> <?php echo $CURUSER['username']?>
<input name="sender" type="radio" value="self" checked> <input name="sender" type="radio" value="self" checked>
&nbsp; System &nbsp; System
<input name="sender" type="radio" value="system"> <input name="sender" type="radio" value="system">
</div></td></tr> </div></td></tr>
<tr><td colspan=1 align=center><input type=submit value="Send!" class=btn></td></tr> <tr><td colspan=2 align=center><input type=submit value="Send!" class=btn></td></tr>
</table> </table>
<input type=hidden name=receiver value=<?php echo $receiver?>> <input type=hidden name=receiver value=<?php echo $receiver?>>
</form> </form>
+1 -1
View File
@@ -37,7 +37,7 @@ $conditions = [];
if (!empty($_POST['classes'])) { if (!empty($_POST['classes'])) {
$conditions[] = "class IN (" . implode(', ', $_POST['classes']) . ")"; $conditions[] = "class IN (" . implode(', ', $_POST['classes']) . ")";
} }
$conditions = apply_filter("increment_bulk_query_conditions", $conditions, $_POST); $conditions = apply_filter("role_query_conditions", $conditions, $_POST);
if (empty($conditions)) { if (empty($conditions)) {
stderr("Error","No valid filter"); stderr("Error","No valid filter");
} }
+10 -2
View File
@@ -28,11 +28,19 @@ $subject = trim($_POST['subject']);
$size = 10000; $size = 10000;
$page = 1; $page = 1;
set_time_limit(300); set_time_limit(300);
$classStr = implode(",", $updateset); $conditions = [];
if (!empty($_POST['classes'])) {
$conditions[] = "class IN (" . implode(', ', $_POST['classes']) . ")";
}
$conditions = apply_filter("role_query_conditions", $conditions, $_POST);
if (empty($conditions)) {
stderr("Error","No valid filter");
}
$whereStr = implode(' OR ', $conditions);
while (true) { while (true) {
$msgValues = []; $msgValues = [];
$offset = ($page - 1) * $size; $offset = ($page - 1) * $size;
$query = sql_query("SELECT id FROM users WHERE class IN ($classStr) and `enabled` = 'yes' and `status` = 'confirmed' limit $offset, $size"); $query = sql_query("SELECT id FROM users WHERE ($whereStr) and `enabled` = 'yes' and `status` = 'confirmed' limit $offset, $size");
while($dat=mysql_fetch_assoc($query)) while($dat=mysql_fetch_assoc($query))
{ {
$msgValues[] = sprintf('(%s, %s, %s, %s, %s)', $sender_id, $dat['id'], $dt, sqlesc($subject), sqlesc($msg)); $msgValues[] = sprintf('(%s, %s, %s, %s, %s)', $sender_id, $dat['id'], $dt, sqlesc($subject), sqlesc($msg));