Commit 054f4f8a authored by Son Nguyen's avatar Son Nguyen
Browse files

Fix the problem of searching for the string: '0' (Bug #1095834)



Wrong use of the empty() function causes this problem.
 - !empty($query) must be replaced by isset($query) && ($query != '')
 - !empty($values['query']) replaced by isset($values['query']) &&
($values['query'] != '')

Change-Id: I5dee9187f48fa3b3f1eeddd23bf29413bb6433c8
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 5efa4b24
......@@ -77,5 +77,5 @@ $smarty->assign('results', $data);
$smarty->display('admin/groups/groups.tpl');
function search_submit(Pieform $form, $values) {
redirect(get_config('wwwroot') . 'admin/groups/groups.php' . (!empty($values['query']) ? '?query=' . urlencode($values['query']) : ''));
redirect(get_config('wwwroot') . 'admin/groups/groups.php' . ((isset($values['query']) && ($values['query'] != '')) ? '?query=' . urlencode($values['query']) : ''));
}
......@@ -905,7 +905,7 @@ if ($institution && $institution != 'mahara') {
}
function search_submit(Pieform $form, $values) {
redirect('/admin/users/institutions.php' . (!empty($values['query']) ? '?query=' . urlencode($values['query']) : ''));
redirect('/admin/users/institutions.php' . ((isset($values['query']) && ($values['query'] != '')) ? '?query=' . urlencode($values['query']) : ''));
}
// Hide custom colour boxes unless theme selector is on 'custom'
......
......@@ -153,7 +153,7 @@ $pagination = build_pagination(array(
));
function search_submit(Pieform $form, $values) {
redirect('/group/find.php?filter=' . $values['filter'] . (!empty($values['query']) ? '&query=' . urlencode($values['query']) : '') . (!empty($values['groupcategory']) ? '&groupcategory=' . intval($values['groupcategory']) : ''));
redirect('/group/find.php?filter=' . $values['filter'] . ((isset($values['query']) && ($values['query'] != '')) ? '&query=' . urlencode($values['query']) : '') . (!empty($values['groupcategory']) ? '&groupcategory=' . intval($values['groupcategory']) : ''));
}
$smarty = smarty();
......
......@@ -197,7 +197,7 @@ $smarty->display('group/members.tpl');
function search_submit(Pieform $form, $values) {
redirect('/group/members.php?id=' . $values['id'] .
(!empty($values['query']) ? '&query=' . urlencode($values['query']) : '') .
((isset($values['query']) && ($values['query'] != '')) ? '&query=' . urlencode($values['query']) : '') .
(!empty($values['membershiptype']) ? '&membershiptype=' . urlencode($values['membershiptype']) : '') .
(!empty($values['setlimit']) ? '&setlimit=' . urlencode($values['setlimit']) : ''));
}
......@@ -42,7 +42,7 @@ if (!empty($tag)) {
$queryparams['tag'] = $tag;
$query = null;
}
else if (!empty($query)) {
else if ($query != '') {
$queryparams['query'] = $query;
}
......
......@@ -1553,7 +1553,7 @@ function build_grouplist_html($query, $limit, $offset, &$count=null) {
$pagination = build_pagination(array(
'id' => 'admgroupslist_pagination',
'datatable' => 'admgroupslist',
'url' => get_config('wwwroot') . 'admin/groups/groups.php' . (!empty($query) ? '?query=' . urlencode($query) : ''),
'url' => get_config('wwwroot') . 'admin/groups/groups.php' . (($query != '') ? '?query=' . urlencode($query) : ''),
'jsonscript' => 'admin/groups/groups.json.php',
'count' => $count,
'limit' => $limit,
......@@ -1574,7 +1574,7 @@ function group_get_membersearch_data($results, $group, $query, $membershiptype,
global $USER;
$params = array();
if (!empty($query)) {
if ($query != '') {
$params['query'] = $query;
}
if (!empty($membershiptype)) {
......
......@@ -782,7 +782,7 @@ function build_institutions_html($filter, $showdefault, $query, $limit, $offset,
$pagination = build_pagination(array(
'id' => 'adminstitutionslist_pagination',
'datatable' => 'adminstitutionslist',
'url' => get_config('wwwroot') . 'admin/users/institutions.php' . (!empty($query) ? '?query=' . urlencode($query) : ''),
'url' => get_config('wwwroot') . 'admin/users/institutions.php' . (($query != '') ? '?query=' . urlencode($query) : ''),
'jsonscript' => 'admin/users/institutions.json.php',
'count' => $count,
'limit' => $limit,
......
......@@ -2642,7 +2642,7 @@ class View {
INNER JOIN {view_tag} vt ON (vt.view = v.id AND vt.tag = ?)";
$values[] = $tag;
}
elseif ($query) { // Include matches on the title, description or tag
else if ($query != '') { // Include matches on the title, description or tag
$from .= "
LEFT JOIN {view_tag} vt ON (vt.view = v.id AND vt.tag = ?)";
$like = db_ilike();
......@@ -2720,7 +2720,7 @@ class View {
if (!empty($tag)) {
$queryparams[] = 'tag=' . urlencode($tag);
}
else if (!empty($query)) {
else if ($query != '') {
$queryparams[] = 'query=' . urlencode($query);
}
......@@ -3617,11 +3617,11 @@ class View {
}
$params = array();
if (!empty($search->query)) {
if (isset($search->query) && ($search->query != '')) {
$params['viewquery'] = $search->query;
}
if (!empty($search->ownerquery)) {
$params['ownerquery'] = $search->query;
if (isset($search->ownerquery) && ($search->ownerquery != '')) {
$params['ownerquery'] = $search->ownerquery;
}
if (!empty($search->group)) {
$params['group'] = $search->group;
......@@ -4446,7 +4446,7 @@ function createview_cancel_submit(Pieform $form, $values) {
function searchviews_submit(Pieform $form, $values) {
$tag = $query = null;
if (!empty($values['query'])) {
if ($values['query'] != '') {
if ($values['type'] == 'tagsonly') {
$tag = $values['query'];
}
......
......@@ -609,7 +609,7 @@ class PluginSearchInternal extends PluginSearch {
WHERE u.id <> 0 AND u.deleted = 0 ';
$values = array();
if (!empty($query)) {
if ($query != '') {
$where .= 'AND (t.tag = LOWER(?) OR ';
$values[] = $query;
$query = preg_replace('/\s\s+/', ' ', $query);
......
......@@ -88,7 +88,7 @@ function dosearch(e) {
}
EOF;
if (!empty($query)) {
if ($query != '') {
$javascript .= 'results.query = ' . json_encode($query) . ";\n";
$javascript .= "results.updateOnLoad();\n";
}
......
......@@ -121,5 +121,5 @@ $smarty->assign('form', $searchform);
$smarty->display('user/find.tpl');
function search_submit(Pieform $form, $values) {
redirect('/user/find.php' . (!empty($values['query']) ? '?query=' . urlencode($values['query']) : ''));
redirect('/user/find.php' . ((isset($values['query']) && ($values['query'] != '')) ? '?query=' . urlencode($values['query']) : ''));
}
......@@ -53,7 +53,7 @@ if (!empty($tag)) {
else {
$searchtype = 'titleanddescription';
$searchdefault = $query;
if (!empty($query)) {
if ($query != '') {
$queryparams['query'] = $query;
}
}
......@@ -174,7 +174,7 @@ function search_submit(Pieform $form, $values) {
$tag = null;
}
if (!empty($values['query'])) {
if ((isset($values['query']) && ($values['query'] != ''))) {
if ($values['type'] == 'tagsonly') {
$queryparams['tag'] = $tag = $values['query'];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment