require_once('./global.php');
require_once('./includes/functions_product.php');
require_once('./includes/class_sort.php');
+require_once('./includes/class_logging.php');
require_once('./includes/api_bug.php');
require_once('./includes/class_api_error.php');
$message->error_permission();
}
-define('MODE_ANY', ($bugsys->in['mode'] == 1));
-define('MODE_ALL', ($bugsys->in['mode'] == 2));
-define('MODE_RAW', ($bugsys->in['mode'] == 3));
+define('MODE_ANY', 1);
+define('MODE_ALL', 2);
+define('MODE_RAW', 3);
$var = $db->query_first("SHOW VARIABLES LIKE 'ft_min_word_len'");
define('SEARCH_WORD_MIN', $var['Value']);
// ###################################################################
+if ($_REQUEST['do'] == 'search')
+{
+ if ($bugsys->in['new'])
+ {
+ $newsearch = true;
+ }
+ else if ($bugsys->in['searchid'])
+ {
+ $cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']);
+ }
+ else if ($bugsys->userinfo['userid'])
+ {
+ $cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']);
+ }
+ else
+ {
+ $newsearch = true;
+ }
+
+ if ($cachedsearch)
+ {
+ $show['cached'] = true;
+ if ($cachedsearch['dateline'] < TIMNOW - 900 OR $bugsys->in['rerun'])
+ {
+ $_REQUEST['do'] = 'process';
+ $bugsys->in = array_merge(unserialize($cachedsearch['query']), $bugsys->in);
+ }
+ else
+ {
+ $search = $cachedsearch;
+ $_POST['do'] = 'results';
+ }
+ }
+ else
+ {
+ $newsearch = true;
+ }
+
+ if ($newsearch)
+ {
+ if (!is_array($bugsys->datastore['product']))
+ {
+ $message->error(_('No products are setup, therefore there can be no bugs and thus search cannot function.'));
+ }
+
+ if (!is_array($bugsys->datastore['version']))
+ {
+ $message->error(_('No versions have been added underneath your product(s), there can be no bugs and thus search cannot function.'));
+ }
+
+ $productSelect = ConstructProductSelect();
+
+ // -------------------------------------------------------------------
+ // custom fields
+ $fields = construct_custom_fields(null, true, false, true);
+ $i = 0;
+ foreach ($fields AS $field)
+ {
+ if ($i % 2 == 0)
+ {
+ $customfields['left'] .= $field;
+ }
+ else
+ {
+ $customfields['right'] .= $field;
+ }
+ $i++;
+ }
+
+ // -------------------------------------------------------------------
+ // built-in fields
+ $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid');
+ $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
+ $select['status'] = construct_datastore_select('status', 'status', 'statusid');
+ $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
+
+ $searches = '';
+ if ($bugsys->userinfo['userid'])
+ {
+ $searchesFetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NOT NULL AND userid = " . $bugsys->userinfo['userid']);
+ while ($search = $db->fetch_array($searchesFetch))
+ {
+ $value = $search['searchid'];
+ $label = $search['name'];
+ eval('$searches .= "' . $template->fetch('selectoption') . '";');
+ }
+ }
+
+ $select['dev'] = '';
+ foreach ($bugsys->datastore['assignto'] AS $dev)
+ {
+ $value = $dev['userid'];
+ $label = construct_user_display($dev, false);
+ eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
+ }
+
+ eval('$template->flush("' . $template->fetch('search') . '");');
+ }
+}
+
+// ###################################################################
+
if ($_REQUEST['do'] == 'process')
{
// -------------------------------------------------------------------
continue;
}
- if (MODE_ALL)
+ if ($bugsys->in['mode'] == MODE_ALL)
{
$querybuild['text'] .= " +$word";
}
$temp = trim($querybuild['text']);
- if (MODE_ALL OR MODE_RAW)
+ if ($bugsys->in['mode'] == MODE_ALL OR $bugsys->in['mode'] == MODE_RAW)
{
$bool_flag = ' IN BOOLEAN MODE';
}
// -------------------------------------------------------------------
// do the search
- $query = "
+
+ $search = $db->query("
SELECT bug.*, comment.commentid
FROM " . TABLE_PREFIX . "bug AS bug
LEFT JOIN " . TABLE_PREFIX . "comment AS comment
ON (bug.bugid = comment.bugid)
WHERE bug.bugid <> 0
- AND bug.product IN (#<'ONBITS:VIEW'>#)
- AND (!bug.hidden OR (bug.hidden AND bug.product IN (#<'ONBITS:HIDDEN'>#))" . (can_perform('canviewownhidden') ? " OR (bug.hidden AND bug.userid = " . $bugsys->userinfo['userid'] . " AND bug.product IN (#<'ONBITS:OWNHIDDEN'>#))" : "") . ")
+ AND bug.product IN (" . fetch_on_bits('canviewbugs') . ")
+ AND
+ (
+ !bug.hidden
+ OR
+ (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden') . "))" . (can_perform('canviewownhidden') ? "
+ OR
+ (bug.hidden AND bug.userid = " . $bugsys->userinfo['userid'] . " AND bug.product IN (" . fetch_on_bits('canviewonhidden') . "))" : "") . "
+ )
" . implode("\n\t\t", $querybuild) . "
GROUP BY bug.bugid
- $sortclause";
-
- $runquery = str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#", "#<'ONBITS:OWNHIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden'), fetch_on_bits('canviewonhidden')), $query);
-
- $search = $db->query($runquery);
+ $sortclause
+ ");
$numrows = $db->num_rows($search);
$results[] = $result;
}
- if ($bugsys->userinfo['userid'])
+ if ($bugsys->userinfo['userid'] AND $cachedsearch['name'] == null AND !$bugsys->in['rerun'])
{
$db->query("DELETE FROM " . TABLE_PREFIX . "search WHERE userid = " . $bugsys->userinfo['userid'] . " AND name IS NULL");
}
- $db->query("
- INSERT INTO " . TABLE_PREFIX . "search
- (userid, dateline, query, ids, orderby, hilight, resultcount)
- VALUES
- (" . $bugsys->userinfo['userid'] . ",
- " . TIMENOW . ", '" . $bugsys->escape($query) . "',
- '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
- '" . $bugsys->escape($hilight) . "',
- " . sizeof($results) . "
- )"
- );
-
- $searchid = $db->insert_id();
-
- $justprocess = true;
- $search = array('ids' => implode(',', $ids), 'orderby' => $sortclause);
-
- $_POST['do'] = 'results';
-}
-
-// ###################################################################
-
-if ($_REQUEST['do'] == 'search')
-{
- if ($bugsys->in['searchid'] AND !$bugsys->in['new'])
+ // store the search params
+ $params = $bugsys->in;
+ foreach ($_COOKIE AS $key => $value)
{
- if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $bugsys->input_clean('searchid', TYPE_UINT) . " AND userid = " . $bugsys->userinfo['userid']))
- {
- $_POST['do'] = 'results';
- $searchid = $cachedsearch['searchid'];
- }
- else
- {
- $newsearch = true;
- }
+ unset($params["$key"]);
}
- else if ($bugsys->userinfo['userid'] AND !$bugsys->in['new'])
+
+ if ($cachedsearch)
{
- if ($cachedsearch = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NULL AND userid = " . $bugsys->userinfo['userid']))
- {
- $_POST['do'] = 'results';
- $searchid = $cachedsearch['searchid'];
- }
- else
- {
- $newsearch = true;
- }
+ $db->query("UPDATE " . TABLE_PREFIX . "search SET ids = '" . implode(',', $ids) . "', resultcount = " . sizeof($results) . " WHERE searchid = " . $cachedsearch['searchid']);
+ $search = $cachedsearch;
}
else
{
- $newsearch = true;
+ $db->query("
+ INSERT INTO " . TABLE_PREFIX . "search
+ (userid, dateline, query, ids, orderby, hilight, resultcount)
+ VALUES
+ (" . $bugsys->userinfo['userid'] . ",
+ " . TIMENOW . ", '" . $bugsys->escape(serialize($params)) . "',
+ '" . implode(',', $ids) . "', '" . $bugsys->escape($sortclause) . "',
+ '" . $bugsys->escape($hilight) . "',
+ " . sizeof($results) . "
+ )"
+ );
+ $search = array('searchid' => $db->insert_id(), 'ids' => implode(',', $ids), 'orderby' => $sortclause, 'hilight' => $hilight, 'resultcount' => sizeof($results));
}
- if ($newsearch)
- {
- if (!is_array($bugsys->datastore['product']))
- {
- $message->error(_('No products are setup, therefore there can be no bugs and thus search cannot function.'));
- }
-
- if (!is_array($bugsys->datastore['version']))
- {
- $message->error(_('No versions have been added underneath your product(s), there can be no bugs and thus search cannot function.'));
- }
-
- $productSelect = ConstructProductSelect();
-
- // -------------------------------------------------------------------
- // custom fields
- $fields = construct_custom_fields(null, true, false, true);
- $i = 0;
- foreach ($fields AS $field)
- {
- if ($i % 2 == 0)
- {
- $customfields['left'] .= $field;
- }
- else
- {
- $customfields['right'] .= $field;
- }
- $i++;
- }
-
- // -------------------------------------------------------------------
- // built-in fields
- $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid');
- $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
- $select['status'] = construct_datastore_select('status', 'status', 'statusid');
- $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
-
- $searches = '';
- if ($bugsys->userinfo['userid'])
- {
- $searchesFetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NOT NULL AND userid = " . $bugsys->userinfo['userid']);
- while ($search = $db->fetch_array($searchesFetch))
- {
- $value = $search['searchid'];
- $label = $search['name'];
- eval('$searches .= "' . $template->fetch('selectoption') . '";');
- }
- }
-
- $select['dev'] = '';
- foreach ($bugsys->datastore['assignto'] AS $dev)
- {
- $value = $dev['userid'];
- $label = construct_user_display($dev, false);
- eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
- }
-
- eval('$template->flush("' . $template->fetch('search') . '");');
- }
+ $_POST['do'] = 'results';
}
// ###################################################################
}
$api = new BugApi($bugsys);
+ $api->set('bugid', $bug['bugid']);
+ $api->set_condition();
+
$log = new Logging();
$log->set_bugid($bug['bugid']);
$log->add_data(true, $bug, $log->getCommonFields());
}
if ($bugsys->in['assignedto'] AND can_perform('canassign', $bug['product']))
{
- $api->set('severity', $bugsys->in['severity']);
+ $api->set('assignedto', $bugsys->in['assignedto']);
}
if ($bugsys->in['product'])
{
$api->set('version', $product[2]);
}
- $log->add_data(false, $api->values, $log->getCommonFields());
-
- process_custom_fields($api, $message);
+ process_custom_fields($api, $message, false, true);
+ $log->add_data(false, $api->values, $log->getCommonFields());
+
$api->update();
$log->update_history();
}
- $message->redirect(_('The specified bugs have been updated and you will now return to your search results.'), 'search.php?do=results&searchid=' . $bugsys->in['searchid']);
+ $message->redirect(_('The specified bugs have been updated and you will now return to your search results.'), 'search.php?searchid=' . $bugsys->in['searchid']);
}
// ###################################################################
// ###################################################################
if ($_POST['do'] == 'results')
-{
- $show['cached'] = false;
- if ($searchid AND !$justprocess)
- {
- $search = $cachedsearch;
- if ($search['dateline'] < TIMENOW - 900 OR $bugsys->in['rerun'])
- {
- $research = $db->query(str_replace(array("#<'ONBITS:VIEW'>#", "#<'ONBITS:HIDDEN'>#", "#<'ONBITS:OWNHIDDEN'>#"), array(fetch_on_bits('canviewbugs'), fetch_on_bits('canviewhidden'), fetch_on_bits('canviewownhidden')), $search['query']));
- while ($bug = $db->fetch_array($research))
- {
- $ids[] = $bug['bugid'];
- $results[] = $bug;
- }
- $search['ids'] = implode(',', $ids);
- $db->query("UPDATE " . TABLE_PREFIX . "search SET ids = '" . implode(',', $ids) . "', dateline = " . TIMENOW . ", resultcount = " . sizeof($results) . " WHERE searchid = " . $search['searchid']);
- }
- $show['cached'] = true;
- $hilight = $search['hilight'];
- }
-
+{
if (!$search['ids'])
{
$message->error(_('No bugs matched your search criteria. Please <a href="search.php?new=1">try again</a> with different search requirements.'));
}
+ $searchid = $search['searchid'];
+ $hilight = $search['hilight'];
+
LoadPaginationFramework();
$pagination->setTotal($search['resultcount']);
$pagination->splitPages();