added a gui item for managing automated searches

This commit is contained in:
SJ
2014-01-24 14:23:49 +01:00
parent 3d472205b6
commit e49704fac7
18 changed files with 447 additions and 37 deletions

View File

@ -331,6 +331,7 @@ define('TABLE_ONLINE', 'online');
define('TABLE_IMPORT', 'import');
define('TABLE_GOOGLE', 'google');
define('TABLE_GOOGLE_IMAP', 'google_imap');
define('TABLE_AUTOSEARCH', 'autosearch');
define('VIEW_MESSAGES', 'v_messages');
define('EOL', "\n");

View File

@ -0,0 +1,117 @@
<?php
class ControllerSearchAutosearch extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "search/autosearch.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$ldap_id = 0;
$this->load->model('search/auto');
$this->document->title = $this->data['text_automated_search'];
$this->data['username'] = Registry::get('username');
$this->data['page'] = 0;
$this->data['page_len'] = get_page_length();
$this->data['total'] = 0;
$this->data['domains'] = array();
/* get search term if there's any */
$this->data['search'] = '';
$this->data['remove'] = 0;
$this->data['removed_query'] = '';
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']; }
/* get page */
if(isset($this->request->get['page']) && is_numeric($this->request->get['page']) && $this->request->get['page'] > 0) {
$this->data['page'] = $this->request->get['page'];
}
/* check if we are admin */
if(Registry::get('admin_user') == 1) {
if($this->request->server['REQUEST_METHOD'] == 'POST') {
if($this->validate() == true) {
if($this->model_search_auto->add($this->request->post) == 1) {
$this->data['x'] = $this->data['text_successfully_added'];
} else {
$this->data['errorstring'] = $this->data['text_failed_to_add'];
}
}
else {
$this->data['errorstring'] = $this->data['text_error_message'];
$this->data['errors'] = $this->error;
$this->data['post'] = $this->request->post;
}
}
if(isset($this->request->get['remove']) && $this->request->get['remove'] == 1 && $this->request->get['id'] > 0) {
$this->model_search_auto->remove($this->request->get['id']);
$this->data['remove'] = 1;
$this->data['removed_query'] = $this->request->get['name'];
}
$this->data['data'] = $this->model_search_auto->get($this->data['search']);
}
else {
$this->template = "common/error.tpl";
$this->data['errorstring'] = $this->data['text_you_are_not_admin'];
}
$this->data['prev_page'] = $this->data['page'] - 1;
$this->data['next_page'] = $this->data['page'] + 1;
$this->data['total'] = floor(count($this->data['data']) / $this->data['page_len']);
$this->render();
}
private function validate() {
if(!isset($this->request->post['query']) || strlen($this->request->post['query']) < 3) {
$this->data['text_field_length'] = str_replace("?",3,$this->data['text_field_length']);
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>

View File

@ -472,5 +472,9 @@ $_['text_refresh_qr_code'] = "Refresh QR code";
$_['text_print_message'] = "Print";
$_['text_forward_selected_emails_to'] = "Forward selected emails to";
$_['text_search_expression'] = "Search expression";
$_['text_automated_search'] = "Automated search";
$_['text_delete_confirm_message'] = "Do you wish to delete";
$_['text_existing'] = "Existing";
$_['text_new'] = "new";
?>

View File

@ -31,6 +31,7 @@ $_['text_attachment_name'] = "Attachment name";
$_['text_attachment_size'] = "Attachment size";
$_['text_attachment_type'] = "Attachment type";
$_['text_audit'] = "Audit";
$_['text_automated_search'] = "Automated search";
$_['text_back'] = "Back";
$_['text_background_colour'] = "Background colour";
@ -75,6 +76,7 @@ $_['text_days_to_retain'] = "Days to retain";
$_['text_deferred_queue'] = "deferred queue";
$_['text_deferred_queue_sender'] = "deferred queue vs. sender";
$_['text_delay'] = "Delay";
$_['text_delete_confirm_message'] = "Do you wish to delete";
$_['text_deleted_users'] = "deleted";
$_['text_deliver'] = "Deliver";
$_['text_delivered'] = "Delivered";
@ -116,6 +118,7 @@ $_['text_enter_search_terms'] = "Enter your search terms";
$_['text_error'] = "Error";
$_['text_exact_domain_name_or_email_address'] = "exact domain name or email address";
$_['text_exclude'] = "Exclude";
$_['text_existing'] = "Existing";
$_['text_existing_domains'] = "Existing domains";
$_['text_existing_email'] = "Existing email";
$_['text_existing_folders'] = "Existing folders";
@ -219,6 +222,7 @@ $_['text_monitor'] = "Monitor";
$_['text_months'] = "months";
$_['text_monthly_report'] = "Monthly report";
$_['text_new'] = "new";
$_['text_new_users'] = "new";
$_['text_next'] = "Next";
$_['text_no_domain_found'] = 'No domain found';

View File

@ -471,5 +471,9 @@ $_['text_refresh_qr_code'] = "Refresh QR code";
$_['text_print_message'] = "Print";
$_['text_forward_selected_emails_to'] = "Forward selected emails to";
$_['text_search_expression'] = "Search expression";
$_['text_automated_search'] = "Automated search";
$_['text_delete_confirm_message'] = "Do you wish to delete";
$_['text_existing'] = "Existing";
$_['text_new'] = "new";
?>

View File

@ -31,6 +31,7 @@ $_['text_attachment_name'] = "Mell
$_['text_attachment_size'] = "Mell<EFBFBD>klet m<>ret";
$_['text_attachment_type'] = "Mell<EFBFBD>klet t<>pus";
$_['text_audit'] = "Audit";
$_['text_automated_search'] = "Automatikus keres<65>s";
$_['text_back'] = "Vissza";
$_['text_background_colour'] = "H<EFBFBD>tt<EFBFBD>rsz<EFBFBD>n";
@ -75,6 +76,7 @@ $_['text_days_to_retain'] = "Meg
$_['text_deferred_queue'] = "k<EFBFBD>s<EFBFBD>bbi kik<69>ld<6C>sre v<>r<EFBFBD> <20>zenetsor";
$_['text_deferred_queue_sender'] = "k<EFBFBD>s<EFBFBD>bbi kik<69>ld<6C>sre v<>r<EFBFBD> <20>zenetsor (felad<61> szerint)";
$_['text_delay'] = "K<EFBFBD>sleltet<EFBFBD>s";
$_['text_delete_confirm_message'] = "T<EFBFBD>r<EFBFBD>lni akarja";
$_['text_deleted_users'] = "t<EFBFBD>r<EFBFBD>lt";
$_['text_deliver'] = "K<EFBFBD>zbes<EFBFBD>t<EFBFBD>s";
$_['text_delivered'] = "K<EFBFBD>zbes<EFBFBD>tett";
@ -117,6 +119,7 @@ $_['text_enter_search_terms'] = "
$_['text_error'] = "Hiba";
$_['text_exact_domain_name_or_email_address'] = "pontos domainn<6E>v vagy email c<>m";
$_['text_exclude'] = "Kihagy";
$_['text_existing'] = "L<EFBFBD>tez<EFBFBD>";
$_['text_existing_domains'] = "L<EFBFBD>tez<EFBFBD> domainek";
$_['text_existing_email'] = "L<EFBFBD>tez<EFBFBD> email";
$_['text_existing_entries'] = "Jelenlegi bejegyz<79>sek";
@ -220,6 +223,7 @@ $_['text_monitor'] = "Monitor";
$_['text_months'] = "h<EFBFBD>nap";
$_['text_monthly_report'] = "Havi jelent<6E>s";
$_['text_new'] = "<EFBFBD>j";
$_['text_new_users'] = "<EFBFBD>j";
$_['text_next'] = "K<EFBFBD>vetkez<EFBFBD>";
$_['text_no_domain_found'] = 'Nem tal<61>ltam domaineket';

View File

@ -31,6 +31,7 @@ $_['text_attachment_name'] = "Melléklet név";
$_['text_attachment_size'] = "Melléklet méret";
$_['text_attachment_type'] = "Melléklet típus";
$_['text_audit'] = "Audit";
$_['text_automated_search'] = "Automatikus keresés";
$_['text_back'] = "Vissza";
$_['text_background_colour'] = "Háttérszín";
@ -75,6 +76,7 @@ $_['text_days_to_retain'] = "Megőrzési idő (nap)";
$_['text_deferred_queue'] = "későbbi kiküldésre váró üzenetsor";
$_['text_deferred_queue_sender'] = "későbbi kiküldésre váró üzenetsor (feladó szerint)";
$_['text_delay'] = "Késleltetés";
$_['text_delete_confirm_message'] = "Törölni akarja";
$_['text_deleted_users'] = "törölt";
$_['text_deliver'] = "Kézbesítés";
$_['text_delivered'] = "Kézbesített";
@ -117,6 +119,7 @@ $_['text_enter_search_terms'] = "Írja be a keresési feltételeket";
$_['text_error'] = "Hiba";
$_['text_exact_domain_name_or_email_address'] = "pontos domainnév vagy email cím";
$_['text_exclude'] = "Kihagy";
$_['text_existing'] = "Létező";
$_['text_existing_domains'] = "Létező domainek";
$_['text_existing_email'] = "Létező email";
$_['text_existing_entries'] = "Jelenlegi bejegyzések";
@ -220,6 +223,7 @@ $_['text_monitor'] = "Monitor";
$_['text_months'] = "hónap";
$_['text_monthly_report'] = "Havi jelentés";
$_['text_new'] = "új";
$_['text_new_users'] = "új";
$_['text_next'] = "Következő";
$_['text_no_domain_found'] = 'Nem találtam domaineket';

View File

@ -461,5 +461,9 @@ $_['text_qr_code'] = "QR";
$_['text_refresh_qr_code'] = "Renovar código QR";
$_['text_forward_selected_emails_to'] = "Forward selected emails to";
$_['text_search_expression'] = "Search expression";
$_['text_automated_search'] = "Automated search";
$_['text_delete_confirm_message'] = "Do you wish to delete";
$_['text_existing'] = "Existing";
$_['text_new'] = "new";
?>

View File

@ -0,0 +1,51 @@
<?php
class ModelSearchAuto extends Model {
public function get($s = '') {
$data = array();
$query = $this->db->query("SELECT * FROM " . TABLE_AUTOSEARCH . " ORDER BY id ASC");
if(isset($query->rows)) {
foreach($query->rows as $q) {
$data[] = array('id' => $q['id'], 'query' => $q['query']);
}
}
return $data;
}
public function add($data = array()) {
if(!isset($data['query'])) { return 0; }
$query = $this->db->query("INSERT INTO " . TABLE_AUTOSEARCH . " (query) VALUES (?)", array($data['query']));
$rc = $this->db->countAffected();
LOGGER("add new automated search query: " . $data['query'] . " (rc=$rc)");
return $rc;
}
public function remove($id = 0) {
if($id == 0) { return 0; }
$query = $this->db->query("DELETE FROM " . TABLE_AUTOSEARCH . " WHERE id=?", array($id));
$rc = $this->db->countAffected();
LOGGER("remove autosearch: $id (rc=$rc)");
return $rc;
}
}
?>

View File

@ -48,6 +48,8 @@ if(isset($this->request->get['route'])) {
<?php print $menu; ?>
</div>
<div id="messagebox1" class="alert alert-info lead"></div>
<div id="piler1" class="container">

View File

@ -41,6 +41,7 @@
<?php } ?>
<li><a href="index.php?route=policy/archiving"><i class="icon-folder-open"></i>&nbsp;<?php print $text_archiving_rules; ?></a></li>
<li><a href="index.php?route=policy/retention"><i class="icon-time"></i>&nbsp;<?php print $text_retention_rules; ?></a></li>
<li><a href="index.php?route=search/autosearch"><i class="icon-search"></i>&nbsp;<?php print $text_automated_search; ?></a></li>
</ul>
</li>

View File

@ -0,0 +1,79 @@
<div id="deleteconfirm-modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" role="dialog" aria-hidden="true"><i class="icon-remove"></i></button>
<h3><?php print $text_confirm; ?> <?php print $text_delete; ?></h3>
</div>
<div class="modal-body">
<p><?php print $text_delete_confirm_message; ?> <span id="name">ERROR</span>?</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal" aria-hidden="true"><?php print $text_close; ?></a>
<a href="index.php?route=search/autosearch&amp;remove=1&amp;id=-1&amp;&amp;confirmed=0" class="btn btn-primary" id="id"><?php print $text_delete; ?></a>
</div>
</div>
<!--form method="get" name="search1" action="index.php?route=search/autosearch" class="form-inline pull-right">
<div class="input-append">
<input type="text" name="search" class="input-medium" value="<?php print $search; ?>" />
<input type="submit" class="btn" value="<?php print $text_search; ?>" />
</div>
</form-->
<h4><?php print $text_new; ?></h4>
<?php if(isset($errorstring)){ ?><div class="alert alert-danger"><?php print $text_error; ?>: <?php print $errorstring; ?></div><?php } ?>
<?php if(isset($x)){ ?>
<div class="alert alert-success"><?php print $x; ?></div>
<?php } ?>
<form method="post" name="add1" action="index.php?route=search/autosearch" class="form-horizontal">
<div class="control-group<?php if(isset($errors['mapped'])){ print " error"; } ?>">
<label class="control-label" for="mapped"><?php print $text_search; ?>:</label>
<div class="controls">
<input type="text" class="text span6" name="query" placeholder="Search query"<?php if(isset($post['query'])){ echo " value='".$post['query']."'"; } ?> />
<?php if ( isset($errors['query']) ) { ?><span class="help-inline"><?php print $errors['query']; ?></span><?php } ?>
</div>
</div>
<div class="form-actions">
<input type="submit" value="<?php print $text_add; ?>" class="btn btn-primary" />
<input type="reset" value="<?php print $text_clear; ?>" class="btn" />
</div>
</form>
<h4><?php print $text_existing; ?></h4>
<div class="listarea">
<?php if(isset($data) && count($data) > 0){ ?>
<table id="ss1" class="table table-striped table-condensed">
<tr>
<th><?php print $text_search; ?></th>
<th>&nbsp;</th>
</tr>
<?php foreach($data as $d) { ?>
<tr>
<td><?php print $d['query']; ?></td>
<td><a href="index.php?route=search/autosearch&amp;remove=1&amp;id=<?php print $d['id']; ?>&amp;query=<?php print urlencode($d['query']); ?>" class="confirm-delete" data-id="<?php print $d['id']; ?>" data-name="<?php print $d['query']; ?>"><i class="icon-remove-sign"></i>&nbsp;<?php print $text_remove; ?></a></td>
</tr>
<?php } ?>
</div>
<?php } else { ?>
<div class="alert alert-error lead">
<?php print $text_not_found; ?>
</div>
<?php } ?>
</div>
<?php if($remove == 1) { ?>
<script>Piler.show_message('messagebox1', '<?php print $text_successfully_removed; ?>', 0.85);</script>
<?php } ?>

View File

@ -41,6 +41,8 @@ if(isset($this->request->get['route'])) {
} ?>>
<div id="messagebox1"></div>
<div id="piler1" class="container">
<div id="menu">

View File

@ -37,6 +37,7 @@
<?php } ?>
<li><a href="index.php?route=policy/archiving"><?php print $text_archiving_rules; ?></a></li>
<li><a href="index.php?route=policy/retention"><?php print $text_retention_rules; ?></a></li>
<li><a href="index.php?route=search/autosearch"><?php print $text_automated_search; ?></a></li>
</ul>
</li>

View File

@ -0,0 +1,73 @@
<div id="deleteconfirm-modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" role="dialog" aria-hidden="true"><i class="icon-remove"></i></button>
<h3><?php print $text_confirm; ?> <?php print $text_delete; ?></h3>
</div>
<div class="modal-body">
<p><?php print $text_delete_confirm_message; ?> <span id="name">ERROR</span>?</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal" aria-hidden="true"><?php print $text_close; ?></a>
<a href="index.php?route=search/autosearch&amp;remove=1&amp;id=-1&amp;domain=Error&amp;confirmed=0" class="btn btn-primary" id="id"><?php print $text_delete; ?></a>
</div>
</div>
<!--form method="get" name="search1" action="index.php?route=search/autosearch" class="form-inline pull-right">
<div class="input-append">
<input type="text" name="search" class="input-medium" value="<?php print $search; ?>" />
<input type="submit" class="btn" value="<?php print $text_search; ?>" />
</div>
</form-->
<h4><?php print $text_new; ?></h4>
<form method="post" name="add1" action="index.php?route=search/autosearch" class="formbottom">
<div id="ss1">
<div class="row">
<div class="domaincell"><?php print $text_search; ?>:</div>
<div class="domaincell"><input type="text" class="text span6" name="query" /></div>
</div>
<div class="row">
<div class="domaincell">&nbsp;</div>
<div class="domaincell"><input type="submit" class="btn btn-primary" value="<?php print $text_add; ?>" /> <input type="reset" class="btn" value="<?php print $text_cancel; ?>" /></div>
</div>
</div>
</form>
<h4><?php print $text_existing; ?></h4>
<div class="listarea">
<?php if(isset($data) && count($data) > 0){ ?>
<div id="ss1">
<div class="domainrow">
<div class="domaincell"><?php print $text_search; ?></div>
<div class="domaincell">&nbsp;</div>
</div>
<?php foreach($data as $d) { ?>
<div class="domainrow">
<div class="domaincell"><?php print $d['query']; ?></a></div>
<div class="domaincell"><a href="index.php?route=search/autosearch&amp;id=1&amp;domain=<?php print urlencode($d['query']); ?>" class="confirm-delete" data-id="<?php print $d['id']; ?>" data-name="<?php print $d['query']; ?>"><i class="icon-remove-sign"></i>&nbsp;<?php print $text_remove; ?></a></div>
</div>
<?php } ?>
</div>
<?php } else { ?>
<?php print $text_not_found; ?>
<?php } ?>
</div>
<?php if($remove == 1) { ?>
<script>Piler.show_message('messagebox1', '<?php print $text_successfully_removed; ?>', 0.85);</script>
<?php } ?>