added tagging the search results

This commit is contained in:
SJ 2012-03-10 14:52:50 +01:00
parent ee9c2af1b2
commit 99848614e8
13 changed files with 163 additions and 16 deletions

View File

@ -311,6 +311,8 @@ int main(int argc, char **argv){
regfree(&regexp);
(void) openlog("pilerexport", LOG_PID, LOG_MAIL);
snprintf(s, sizeof(s)-1, "SELECT DISTINCT `id`, `piler_id`, `digest`, `bodydigest` FROM %s WHERE ", SQL_MESSAGES_VIEW);

View File

@ -214,6 +214,7 @@ int main(int argc, char **argv){
if(!mailbox && !emlfile && !directory) usage();
(void) openlog("pilerimport", LOG_PID, LOG_MAIL);
cfg = read_config(configfile);

View File

@ -94,6 +94,10 @@ create table if not exists `attachment` (
create index `attachment_idx` on `attachment`(`piler_id`);
create index `attachment_idx2` on `attachment`(`sig`);
create index `attachment_idx3` on `attachment`(`ptr`);
drop view if exists `v_attachment`;
create view `v_attachment` AS select `id` as `i`, `piler_id`, `attachment_id`, `ptr`, (select count(*) from `attachment` where `ptr`=`i`) as `refcount` from `attachment`;
drop table if exists `tag`;

View File

@ -129,6 +129,7 @@ define('SEARCH_HELPER_URL', SITE_URL . 'search-helper.php');
define('AUDIT_HELPER_URL', SITE_URL . 'audit-helper.php');
define('SAVE_SEARCH_URL', SITE_URL . 'index.php?route=search/save');
define('SEARCH_TAG_URL', SITE_URL . 'index.php?route=search/tag');
define('HEALTH_WORKER_URL', SITE_URL . 'index.php?route=health/worker');
define('HEALTH_REFRESH', 60);

View File

@ -53,7 +53,7 @@ class ControllerSearchHelper extends Controller {
$this->preprocess_post_advanced_request($this->request->post);
$this->fixup_post_request();
list ($this->data['n'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, ADVANCED_SEARCH, $this->data['page']);
list ($this->data['n'], $this->data['all_ids'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, ADVANCED_SEARCH, $this->data['page']);
}
else if($this->request->post['searchtype'] == 'expert'){
@ -61,14 +61,15 @@ class ControllerSearchHelper extends Controller {
$this->preprocess_post_expert_request($this->request->post);
$this->fixup_post_request();
list ($this->data['n'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, ADVANCED_SEARCH, $this->data['page']);
list ($this->data['n'], $this->data['all_ids'], $this->data['messages']) = $this->model_search_search->search_messages($this->a, ADVANCED_SEARCH, $this->data['page']);
}
else {
$this->fixup_post_simple_request();
list ($this->data['n'], $this->data['messages']) = $this->model_search_search->search_messages($this->request->post, SIMPLE_SEARCH, $this->data['page']);
list ($this->data['n'], $this->data['all_ids'], $this->data['messages']) = $this->model_search_search->search_messages($this->request->post, SIMPLE_SEARCH, $this->data['page']);
}
if($this->a['ref']) { $this->data['_ref'] = $this->a['ref']; }
/* paging info */

View File

@ -0,0 +1,42 @@
<?php
class ControllerSearchTag extends Controller {
private $error = array();
public function index(){
$this->id = "content";
$this->template = "search/tag.tpl";
$this->layout = "common/layout-empty";
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('search/search');
$this->load->model('search/message');
if(isset($this->request->post['tag']) && isset($this->request->post['idlist'])) {
$idlist = explode(",", $this->request->post['idlist']);
if(count($idlist) > 0) {
$q = '';
$ids = $this->model_search_search->check_your_permission_by_id_list($idlist);
for($i=0; $i<count($ids); $i++) { $q .= ",?"; }
$q = preg_replace("/^\,/", "", $q);
$this->model_search_message->bulk_add_message_tag($ids, $_SESSION['uid'], $this->request->post['tag'], $q);
}
}
/*$this->data['message'] = 'I tagged this!';
$this->render();*/
}
}
?>

View File

@ -415,6 +415,18 @@ class ModelSearchMessage extends Model {
}
public function bulk_add_message_tag($ids = array(), $uid = 0, $tag = '', $q = '') {
$arr = array_merge(array($uid), $ids);
$query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id IN ($q)", $arr);
if($tag) {
foreach ($ids as $id) {
$query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag));
}
}
}
}
?>

View File

@ -11,6 +11,7 @@ class ModelSearchSearch extends Model {
$cache_key = "";
$q = "";
$s = "";
$all_ids_csv = "";
while(list($k,$v) = each($data)) {
if($v) { $s .= '&' . $k . '=' . $v; }
@ -61,6 +62,7 @@ class ModelSearchSearch extends Model {
$total_hits = count($all_ids);
$all_ids_csv = implode(",", $all_ids);
$data['page_len'] = get_page_length();
@ -71,6 +73,7 @@ class ModelSearchSearch extends Model {
if($i >= $data['page_len'] * $page && $i < $data['page_len'] * ($page+1) ) {
array_push($one_page_of_ids, $id);
$all_ids_csv .= ",$id";
if($q) { $q .= ",?"; } else { $q = "?"; }
}
@ -80,7 +83,7 @@ class ModelSearchSearch extends Model {
}
return array($total_hits, $this->get_meta_data($one_page_of_ids, $q, $sortorder));
return array($total_hits, $all_ids_csv, $this->get_meta_data($one_page_of_ids, $q, $sortorder));
}
@ -451,6 +454,46 @@ class ModelSearchSearch extends Model {
}
public function check_your_permission_by_id_list($id = array()) {
$q = $q2 = '';
$arr = $a = $result = array();
if($id == '') { return 0; }
if(Registry::get('admin_user') == 1 || Registry::get('auditor_user') == 1) { return 1; }
$arr = $id;
for($i=0; $i<count($id); $i++) {
$q2 .= ",?";
}
$q2 = preg_replace("/^\,/", "", $q2);
while(list($k, $v) = each($_SESSION['emails'])) {
if(validemail($v) == 1) {
$q .= ",?";
array_push($a, $v);
}
}
$q = preg_replace("/^\,/", "", $q);
$arr = array_merge($arr, $a, $a);
$query = $this->db->query("SELECT distinct id FROM " . VIEW_MESSAGES . " WHERE `id` IN ($q2) AND ( `from` IN ($q) OR `to` IN ($q) )", $arr);
if($query->num_rows > 0) {
foreach ($query->rows as $q) {
array_push($result, $q['id']);
}
}
return $result;
}
public function remove_message($id = '') {
if($id == '') { return 0; }

View File

@ -355,6 +355,37 @@ function removeme(id) {
}
function tag_search_results(url){
var idlist = '';
var tag_keys = document.getElementById('tag_keys').value;
var tag_value = document.getElementById('tag_value').value;
if(tag_keys) {
params = "idlist=" + tag_keys + "&tag=" + encodeURI(tag_value);
var http = getXMLHttp();
if(http == null) { alert("Error creating XMLHttpRequest"); return; }
http.onreadystatechange = function() {
if(http.readyState == 4) {
if(http.status != 200) alert("Problem retrieving XML data:" + http.statusText);
}
}
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
}
}
$(document).ready(function() {
$.datepicker.setDefaults($.datepicker.regional[piler_ui_lang]);
$("#date1").datepicker( { dateFormat: 'yy-mm-dd' } );

View File

@ -64,6 +64,7 @@
.text { font: normal 12px Arial, sans-serif; font-weight: bold; text-align:left; width: 408px; }
.ruletext { font: normal 12px Arial, sans-serif; font-weight: bold; text-align:left; width: 365px; }
.advtext { font: bold 12px Arial, sans-serif; font-weight: bold; text-align:left; width: 280px; }
.tagtext { font: normal 10px Arial, sans-serif; font-weight: bold; text-align:left; width: 280px; }
.advtextgrey { font: bold 12px Arial, sans-serif; color: #999; font-weight: bold; text-align:left; width: 280px; }
.textregular { font: normal 12px Arial, sans-serif; font-weight: bold; text-align:left; }
@ -108,13 +109,14 @@
#health1 .error { color: red; font-weight: bold; }
#pagenav { float: left; margin-top: 0px; margin-bottom: 0px; text-align: left; width: 990px; border: 0px solid red; }
.navrow { display: table-row; width: 282px; border: 1px solid red; }
.navrow { display: table-row; }
.navlink { color: #bbb; font: bold 12px Arial, sans-serif; }
#pagenav a.navlink { color: #850505; font: bold 12px Arial, sans-serif; }
#pagingleft { display: table-cell; float: left; text-align: left; width: 60px; border: 0px solid red; }
#pagingcenter { display: table-cell; float: left; text-align: center; width: 145px; border: 0px solid red; }
#pagingright { display: table-cell; float: right; text-align: right; width: 60px; border: 0px solid red; }
#pagingright { display: table-cell; float: left; text-align: right; width: 60px; border: 0px solid red; }
#tagbox { display: table-cell; float: left; text-align: right; vertical-align: top; width: 725px; border: 0px solid red; }
.messagelink { border-bottom: 1px solid gray; color: #850505; }
.messagelink.spam { border-bottom: 1px solid gray; color: #aaa; }
@ -125,7 +127,6 @@
.advselect2 { width: 205px; font: bold 12px Arial, sans-serif; padding: 0; margin:0;}
.ruleselect { width: 40px; font: bold 12px Arial, sans-serif; padding: 0; margin:0;}
/*button { margin-left: 0px; background-color:gray; border-top:1px solid gray; border-left:1px solid gray; font: bold 12px Arial, sans-serif; border-left: yellow; border-right: black; width:50%;}*/
button { margin: 0; background-color:gray; font: bold 12px Arial, sans-serif; width:40%; height: 40px; margin-left: 5%; margin-right: 5%; }
button.active { background-color: #850505; color:white; }
@ -136,6 +137,8 @@
input[type=button].load { margin: 0; background-color:#eee; color: black; font: bold 12px Arial, sans-serif; width: 17%;}
input[type=button].short { margin: 0; background-color:#eee; color: gray; font: bold 12px Arial, sans-serif; width: 50px;}
input[type=button].tag { margin: 0; background-color:#eee; color: gray; font: normal 10px Arial, sans-serif; }
input[type=checkbox].attachmenttype { margin: 0; vertical-align: middle; }
#messagepopup { margin: 10px 20px 10px 20px; padding: 0; background-color: white; text-align: left; }
@ -158,8 +161,8 @@
ul.dropdown { position: relative; }
ul.dropdown li { font-weight: bold; float: left; background: #ffffff; text-align: center; padding-right: 40px; padding-left: 40px; border: 0px solid red; }
ul.dropdown li.first_li { font-weight: bold; float: left; background: #ffffff; text-align: left; padding-left:80px; padding-right: 5px; }
ul.dropdown li.search_li { font-weight: bold; float: left; background: #ffffff; text-align: center; padding: 0; padding-right: 5px; }
ul.dropdown li.no_search_li { font-weight: bold; float: left; background: #ffffff; text-align: center; padding: 0; padding-right: 5px; }
ul.dropdown li.search_li { font-weight: bold; float: left; background: #ffffff; text-align: center; padding: 0; padding-right: 0px; }
ul.dropdown li.no_search_li { font-weight: bold; float: left; background: #ffffff; text-align: center; padding: 0; padding-right: 0px; }
ul.dropdown li.center_li { font-weight: bold; float: left; background: #ffffff; text-align: center; padding: 0; width: 190px; }
ul.dropdown li.last_li { font-weight: bold; float: left; background: #ffffff; text-align: right; padding: 0; }

View File

@ -10,7 +10,7 @@
<div class="mcell" style="width: 315px;">
<ul class="dropdown">
<li class="search_li"><a href="search.php"<?php if($_SERVER['REQUEST_URI'] == '/' || strstr($_SERVER['REQUEST_URI'], "search.php")){ ?> id="active"<?php } ?>><?php print $text_simple_search; ?></a></li>
<li class="search_li"><a href="search.php"<?php if($_SERVER['REQUEST_URI'] == '/' || strstr($_SERVER['REQUEST_URI'], "search.php")){ ?> id="active"<?php } ?>><?php print $text_simple_search; ?></a> |&nbsp;</li>
<li class="search_li"><a href="advanced.php"<?php if(strstr($_SERVER['REQUEST_URI'], "advanced.php")){ ?> id="active"<?php } ?>><?php print $text_advanced_search; ?></a></li>
</ul>
</div>

View File

@ -15,14 +15,20 @@
<?php if($next_page <= $total_pages){ ?><a href="#" class="navlink" onclick="script:load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), <?php print $next_page; ?>); return false;">&gt; </a> <?php } else { ?><span class="navlink">&gt; </span><?php } ?>
<?php if($page < $total_pages) { ?> &nbsp; <a href="#" class="navlink" onclick="script:load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), <?php print $total_pages; ?>); return false;"> &gt;&gt; </a><?php } else { ?> <span class="navlink"> &nbsp; &gt;&gt;</span><?php } ?>
</div>
<?php } if($n > 0){ ?>
<div id="tagbox"<?php if($n < $page_len) { ?> style="margin-left: 265px;"<?php } ?>>
<input type="hidden" id="tag_keys" name="tag_keys" value="<?php print $all_ids; ?>" />
<input type="hidden" id="_ref" name="_ref" value="<?php print $_ref; ?>" />
Tag search results: <input type="text" id="tag_value" name="tag_value" class="tagtext" /> <input type="button" class="tag" onclick="javascript: tag_search_results('<?php print SEARCH_TAG_URL; ?>'); var __ref = document.getElementById('_ref').value; if(__ref) { add_message_reference_to_form(__ref); } load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), 0); return false;" value="OK" />
</div>
<?php } else { ?>&nbsp;<?php } ?>
</div>
</div>
<div id="resultscontainer"<?php if($n <= 0) { ?> class="empty"<?php } ?>>
<div id="results">
@ -65,14 +71,14 @@
<?php $i=0; foreach ($messages as $message) { $i++; ?>
<div class="resultrow<?php if($i % 2) { ?> odd<?php } ?><?php if($message['spam'] == 1) { ?> spam<?php } ?>">
<div id="e_<?php print $message['id']; ?>" class="resultrow<?php if($i % 2) { ?> odd<?php } ?><?php if($message['spam'] == 1) { ?> spam<?php } ?>">
<div class="cell5 id"><?php print ($page*$page_len) + $i; ?>.</div>
<div class="cell5 date"><?php print $message['date']; ?></div>
<div class="cell5 from"><?php if($message['from'] != $message['shortfrom']) { ?><span onmouseover="Tip('<?php print preg_replace("/&/", "&amp;", $message['from']); ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip()"><?php print $message['shortfrom']; ?></span><?php } else { print $message['from']; } ?></div>
<div class="cell5 subject"><a class="messagelink<?php if($message['spam'] == 1) { ?> spam<?php } ?>" href="<?php print SITE_URL; ?>message.php/<?php print $message['piler_id']; ?>"><?php if($message['subject'] != $message['shortsubject']) { ?><span onmouseover="Tip('<?php print preg_replace("/&/", "&amp;", $message['subject']); ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip()"><?php print $message['shortsubject']; ?></span><?php } else { print $message['subject']; } ?></a><?php if($message['reference']) { ?> <a href="#" onclick="script:add_message_reference_to_form('<?php print $message['reference']; ?>'); load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), 0); a = document.getElementById('ref'); a.value=''; return false;"><span onmouseover="Tip('<?php print $text_conversation_available; ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip()">[+]</span></a><?php } ?></div>
<div class="cell5 from"><?php if($message['from'] != $message['shortfrom']) { ?><span onmouseover="Tip('<?php print preg_replace("/&/", "&amp;", $message['from']); ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();"><?php print $message['shortfrom']; ?></span><?php } else { print $message['from']; } ?></div>
<div class="cell5 subject"><a class="messagelink<?php if($message['spam'] == 1) { ?> spam<?php } ?>" href="<?php print SITE_URL; ?>message.php/<?php print $message['piler_id']; ?>"><?php if($message['subject'] != $message['shortsubject']) { ?><span onmouseover="Tip('<?php print preg_replace("/&/", "&amp;", $message['subject']); ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();"><?php print $message['shortsubject']; ?></span><?php } else { print $message['subject']; } ?></a><?php if($message['reference']) { ?> <a href="#" onclick="script:add_message_reference_to_form('<?php print $message['reference']; ?>'); load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), 0); a = document.getElementById('ref'); a.value=''; return false;"><span onmouseover="Tip('<?php print $text_conversation_available; ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();">[+]</span></a><?php } ?></div>
<div class="cell5 size"><?php print $message['size']; ?></div>
<div class="cell5"><?php if($message['attachments'] > 0) { ?><img src="<?php print ICON_ATTACHMENT; ?>" alt="" width="16" height="18" /><?php } else { ?>&nbsp;<?php } ?></div>
<div class="cell5"><?php if($message['tag']) { ?><span onmouseover="Tip('<?php print $message['tag']; ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip()"><img src="<?php print ICON_TAG; ?>" alt="" /></span><?php } else { ?>&nbsp;<?php } ?></div>
<div class="cell5"><?php if($message['tag']) { ?><span onmouseover="Tip('<?php print $message['tag']; ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();"><img src="<?php print ICON_TAG; ?>" alt="" /></span><?php } else { ?>&nbsp;<?php } ?></div>
<?php if(ENABLE_ON_THE_FLY_VERIFICATION == 1) { ?>
<div class="cell5 verification"><img src="<?php if($message['verification'] == 1){ print ICON_GREEN_OK; } else { print ICON_RED_X; } ?>" alt="verification status" /></div>
<?php } ?>

View File

@ -0,0 +1 @@
<p><?php print $message; ?></p>