Example #1
0
     unset($disk_by_tag);
 }
 if ($_REQUEST["what"] == "disk") {
     saveSearchParams($_SERVER['PHP_SELF'], array('what', 'tag_pattern', 'tag', 'term'));
     $term = convertWildcards($_REQUEST['term']);
     $tag = convertWildcards($_REQUEST['tag_pattern']);
     $disks = fetchDisksByCriteria("tag LIKE '{$tag}' AND (title LIKE '%{$term}%' OR label LIKE '%{$term}%')");
     if (db_num_rows($disks) == 0) {
         unset($disks);
     } else {
         $ids = getDiskIdsFromDbRes($disks);
         $category_map = getDiskCategories($ids);
     }
 }
 if ($_REQUEST["what"] == "file") {
     saveSearchParams($_SERVER['PHP_SELF'], array('what', 'tag_pattern', 'tag', 'term'));
     $term = convertWildcards($_REQUEST["term"]);
     $crit = "(Filename LIKE '%{$term}%' OR BetterName LIKE '%{$term}%')";
     if (isset($_REQUEST["tag_pattern"])) {
         $tag = convertWildcards($_REQUEST['tag_pattern']);
         $crit .= " AND disk.tag LIKE '{$tag}'";
     }
     $t1 = getmicrotime();
     $files = fetchFilesByCriteria($crit);
     $searchTime = getmicrotime() - $t1;
     if (db_num_rows($files) == 0) {
         unset($files);
     } else {
         $t1 = getmicrotime();
         $ids = getFileIdsFromDbRes($files);
         $category_map = getFileCategories($ids);
        } else {
            if ($not == 'between') {
                return " AND FileId IN (SELECT obj_id FROM category_map WHERE cat_id=" . $categoryId . " AND value >= {$from} AND value <= {$to})";
            } else {
                return " AND FileId IN (SELECT obj_id FROM category_map WHERE cat_id=" . $categoryId . ")";
                // Doesn't work with boolean connectives
                /*      $tables = array('category_map');
                      return " AND cat_id=" . $categoryId . " AND obj_id=FileId";*/
            }
        }
    }
    return '';
}
db_open();
if (isset($_REQUEST['bt_search'])) {
    saveSearchParams($_SERVER['PHP_SELF'], array('bt_search', 'tag_pattern', 'term', 'min_size', 'max_size', 'category1', 'category2', 'category3', 'category4', 'category_not1', 'category_not2', 'category_not3', 'category_not4', 'files_only', 'group_by_disk', 'sort'));
    htmldb_set_hilight_words(array($_REQUEST["term"]));
    $tables = array();
    $term = convertWildcards($_REQUEST["term"]);
    $crit = "(Filename LIKE '%{$term}%' OR BetterName LIKE '%{$term}%')";
    if (isset($_REQUEST["tag_pattern"])) {
        $tag = convertWildcards($_REQUEST['tag_pattern']);
        $crit .= " AND disk.tag LIKE '{$tag}'";
    }
    if ($_REQUEST['min_size'] != '' || $_REQUEST['max_size'] != '') {
        $min_size = convertSize($_REQUEST['min_size']);
        $max_size = convertSize($_REQUEST['max_size']);
        if ($min_size != '') {
            $crit .= " AND Size >= '{$min_size}'";
        }
        if ($max_size != '') {
        } else {
            if ($categoryId == -1) {
                return " AND obj_id IS NULL";
            } else {
                return " AND id IN (SELECT obj_id FROM category_map_disk WHERE cat_id=" . $categoryId . ")";
            }
            // Doesn't work with boolean connectives
            /*      $tables = array('category_map');
                  return " AND cat_id=" . $categoryId . " AND obj_id=FileId";*/
        }
    }
    return '';
}
db_open();
if (isset($_REQUEST['bt_search'])) {
    saveSearchParams($_SERVER['PHP_SELF'], array('bt_search', 'tag_pattern', 'term', 'category1', 'category2', 'category3', 'category4', 'category_not1', 'category_not2', 'category_not3', 'category_not4', 'sort'));
    htmldb_set_hilight_words(array($_REQUEST["term"]));
    $tables = array();
    $term = convertWildcards($_REQUEST["term"]);
    $crit = "(title LIKE '%{$term}%' OR label LIKE '%{$term}%')";
    if (isset($_REQUEST['tag_pattern'])) {
        $tag = convertWildcards($_REQUEST['tag_pattern']);
        $crit .= " AND disk.tag LIKE '{$tag}'";
    }
    $left_join = '';
    if ($_REQUEST['category1'] == -1) {
        $left_join = 'LEFT JOIN category_map_disk ON disk.id=category_map_disk.obj_id';
    }
    $crit .= make_category_criteria($_REQUEST['category1'], $_REQUEST['category_not1']);
    $crit .= make_category_criteria($_REQUEST['category2'], $_REQUEST['category_not2']);
    $crit .= make_category_criteria($_REQUEST['category3'], $_REQUEST['category_not3']);