Skip to content

Commit

Permalink
Added sorting to archiving policy (jsuto#128)
Browse files Browse the repository at this point in the history
Signed-off-by: Janos SUTO <sj@acts.hu>
  • Loading branch information
jsuto authored Aug 4, 2024
1 parent 0785d37 commit 3a225ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
13 changes: 12 additions & 1 deletion webui/controller/policy/archiving.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ public function index(){

$this->data['search'] = '';

$order = 'ASC';
$sort = 'from';

if(isset($this->request->post['search'])) { $this->data['search'] = $this->request->post['search']; }
else if(isset($this->request->get['search'])) { $this->data['search'] = $this->request->get['search']; }

if(isset($this->request->get['order'])) { $order = $this->request->get['order']; }
if(isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; }

// toggle sort order
$order == 'ASC' ? $order_to_display = 'DESC' : $order_to_display = 'ASC';

$this->data['MEURL'] = $_SERVER['DOCUMENT_URI'] . '?route=policy/archiving&order=' . $order_to_display;

if(Registry::get('admin_user') == 0) {
die("go away");
}
Expand All @@ -41,7 +52,7 @@ public function index(){
}
}

$this->data['rules'] = htmlentities_on_array($this->model_policy_archiving->get_rules($this->data['search']));
$this->data['rules'] = htmlentities_on_array($this->model_policy_archiving->get_rules($this->data['search'], $sort, $order));


$this->render();
Expand Down
18 changes: 13 additions & 5 deletions webui/model/policy/archiving.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@

class ModelPolicyArchiving extends Model {

public function get_rules($s = '') {
public function get_rules($s = '', $sort = 'from', $order = 'ASC') {
if(in_array($sort, ['from', 'to', 'subject'])) {
$sort = '`' . $sort . '`';
} else {
$sort = '`from`';
}

if(!in_array($order, ['ASC', 'DESC'])) {
$order = 'ASC';
}

if($s) {
$query = $this->db->query("SELECT * FROM " . TABLE_ARCHIVING_RULE . " WHERE `from` LIKE ? OR `to` LIKE ? OR `subject` LIKE ? OR `body` LIKE ? ORDER BY domain, id", array('%' . $s . '%', '%' . $s . '%', '%' . $s . '%', '%' . $s . '%'));
$query = $this->db->query("SELECT * FROM " . TABLE_ARCHIVING_RULE . " WHERE `from` LIKE ? OR `to` LIKE ? OR `subject` LIKE ? OR `body` LIKE ? ORDER BY $sort $order", array('%' . $s . '%', '%' . $s . '%', '%' . $s . '%', '%' . $s . '%'));
} else {
$query = $this->db->query("SELECT * FROM " . TABLE_ARCHIVING_RULE . " ORDER BY id");
$query = $this->db->query("SELECT * FROM " . TABLE_ARCHIVING_RULE . " ORDER BY $sort $order");
}

if(isset($query->rows)) { return $query->rows; }
Expand Down Expand Up @@ -39,5 +49,3 @@ public function remove_rule($id = 0) {


}

?>
6 changes: 3 additions & 3 deletions webui/templates/policy/archiving.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@
<table class="table table-striped">
<thead class="table-dark">
<tr>
<th><?php print $text_from; ?></th>
<th><?php print $text_to; ?></th>
<th><?php print $text_subject; ?></th>
<th><?php print $text_from; ?> <a href="<?php print $MEURL; ?>&sort=from"><i class="bi bi-arrow-down-up"></i></a></th>
<th><?php print $text_to; ?> <a href="<?php print $MEURL; ?>&sort=to"><i class="bi bi-arrow-down-up"></i></a></th>
<th><?php print $text_subject; ?> <a href="<?php print $MEURL; ?>&sort=subject"><i class="bi bi-arrow-down-up"></i></a></th>
<th><?php print $text_body; ?></th>
<th><?php print $text_spam; ?></th>
<th><?php print $text_size; ?></th>
Expand Down

0 comments on commit 3a225ea

Please sign in to comment.