Help with search feature Help with search feature
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Help with search feature

Started by squid, April 12, 2006, 04:41:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

squid

Need a bit of help on this one guys.

Let's say I want to search for "a" in album "1"

Currently, when I search for "a" it gives me results from all albums.

So in short can Coppermine be configured to search in a specific album, or another? And if yes, how do I do it.

Thanks,

Emile Cooper

Stramm

try this, I hope it works

search.php
after

                                                $customs
                                                $ip

add
<tr>
<td>Albums:</td>
<td>
EOT;
$cpg_udb->albumlist();
echo <<< EOT
</td>
</tr>


thumbnails.php
after
    $USER['search'] = $_POST;
        $album = 'search';

add
if (isset($_POST['aid']) && $_POST['aid'] != 0) {
$ALBUM_SET = "AND aid=".$_POST['aid'];
}


bridge/udb_base.inc.php
at the end right before
}
?>

add
    function albumlist()
    {
            global $lang_util_php, $CONFIG, $lang_upload_php;

            // Reset counter
            $list_count = 0;

            if ($this->can_join_tables) {

                    $user_albums = cpg_db_query("SELECT {$this->field['username']} AS user_name, aid, a.title
                                                                            FROM {$CONFIG['TABLE_ALBUMS']} AS a
                                                                            LEFT JOIN {$this->usertable} AS u
                                                                            ON (category - " . FIRST_USER_CAT . ") = {$this->field['user_id']}
                                                                            WHERE category > " . FIRST_USER_CAT);
                    $user_albums_list = cpg_db_fetch_rowset($user_albums);
                    mysql_free_result($user_albums);

                    // Cycle through the User albums
                    foreach($user_albums_list as $album) {

                            // Add to multi-dim array for later sorting
                            $listArray[$list_count]['cat'] = $lang_upload_php['personal_albums'];
                            $listArray[$list_count]['aid'] = $album['aid'];
                            $username = is_null($album['user_name']) ? 'Mr. X' : $album['user_name'];
                            $listArray[$list_count]['title'] = '(' . $username . ') ' . $album['title'];
                            $list_count++;
                    }

            } else {

                    $user_albums = cpg_db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category > " . FIRST_USER_CAT);

                    $user_albums_list = $user_ids = array();

                    if (mysql_num_rows($user_albums)){

                            while ($row = cpg_db_fetch_row($user_albums)){
                                    $user_albums_list[] = $row;
                                    $user_ids[] = $row['category'] - FIRST_USER_CAT;
                            }
                            mysql_free_result($user_albums);

                            $user_id_list = implode(', ', array_unique($user_ids));

                            $user_names = cpg_db_query("SELECT {$this->field['username']} AS user_name, {$this->field['user_id']} AS user_id  FROM {$this->usertable} WHERE {$this->field['user_id']} IN ($user_id_list)", $this->link_id);

                            while ($row = cpg_db_fetch_row($user_names)){
                                    $user_names_list[$row['user_id']] = $row['user_name'];
                            }
                            mysql_free_result($user_names);

                            // Cycle through the User albums
                            foreach($user_albums_list as $album) {

                                    // Add to multi-dim array for later sorting
                                    $listArray[$list_count]['cat'] = $lang_upload_php['personal_albums'];
                                    $listArray[$list_count]['aid'] = $album['aid'];
                                    $username = isset($user_names_list[$album['category'] - FIRST_USER_CAT]) ? $user_names_list[$album['category'] - FIRST_USER_CAT] : 'Mr. X';
                                    $listArray[$list_count]['title'] = '(' . $username . ') ' . $album['title'];
                                    $list_count++;
                            }
                    } else {
                            mysql_free_result($user_albums);
                    }
            }

            $public_albums = cpg_db_query("SELECT aid, title, name FROM {$CONFIG['TABLE_ALBUMS']} LEFT JOIN {$CONFIG['TABLE_CATEGORIES']} ON cid = category WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
            $public_albums_list = cpg_db_fetch_rowset($public_albums);
            mysql_free_result($public_albums);

            // Cycle through the public albums
            foreach($public_albums_list as $album) {

                    // Set $album_id to the actual album ID
                    $album_id = $album['aid'];

                    // Add to multi-dim array for sorting later
                    $vRes['name'] = $album['name'];
                    if ($vRes['name']) {
                            $listArray[$list_count]['cat'] = $vRes['name'];
                    } else {
                            $listArray[$list_count]['cat'] = $lang_upload_php['albums_no_category'];
                    }
                    $listArray[$list_count]['aid'] = $album['aid'];
                    $listArray[$list_count]['title'] = $album['title'];
                    $list_count++;
            }

            // Sort the pulldown options by category and album name
            $listArray = array_csort($listArray,'cat','title');

            // Finally, print out the nicely sorted and formatted drop down list
            $alb_cat = '';

            echo '&nbsp;&nbsp;&nbsp;&nbsp;<select size="1" name="aid" class="listbox"><option value="0">All Albums</option>';

            foreach ($listArray as $val) {
                    if ($val['cat'] != $alb_cat) {
                            if ($alb_cat) echo "                </optgroup>\n";
                            echo '                <optgroup label="' . $val['cat'] . '">' . "\n";
                            $alb_cat = $val['cat'];
                    }
                    echo '                <option value="' . $val['aid'] . '">   ' . $val['title'] . "</option>\n";
            }

            if ($alb_cat) echo "                </optgroup>\n";
    }

squid

#2
Thanks for the help Stramm .

It almost worked. I can now search a specific album, but there is a small problem.

When I search from the 1st of 2 albums created,the thumbnail comes up properly, and when I click it, the photo comes up properly.

When I search from the 2nd of the 2 albums, the thumbnail comes up properly, but when I click it, the photo from the 1st album comes up.

The file name in the 2 albums is not the same.

Super close, but not there yet.

Emile.

Ok, after looking at the result a bit more I came up with this.

The thumbnail part works perfectly, but when you click on the thumbnail seems to generate a page with the first image from the 1st album, then you can click next, then up comes the image from the 2nd album.

I hope that makes sense....

Stramm

add this to your theme.php
it's not perfect, prev/ next won't work for search metaalbum as well as the thumbnail list icon

function theme_display_thumbnails(&$thumb_list, $nbThumb, $album_name, $aid, $cat, $page, $total_pages, $sort_options, $display_tabs, $mode = 'thumb')
{
    global $CONFIG;
    global $template_thumb_view_title_row,$template_fav_thumb_view_title_row, $lang_thumb_view, $template_tab_display, $template_thumbnail_view, $lang_album_list;

    static $header = '';
    static $thumb_cell = '';
    static $empty_cell = '';
    static $row_separator = '';
    static $footer = '';
    static $tabs = '';
    static $spacer = '';

    if ($header == '') {
        $thumb_cell = template_extract_block($template_thumbnail_view, 'thumb_cell');
        $tabs = template_extract_block($template_thumbnail_view, 'tabs');
        $header = template_extract_block($template_thumbnail_view, 'header');
        $empty_cell = template_extract_block($template_thumbnail_view, 'empty_cell');
        $row_separator = template_extract_block($template_thumbnail_view, 'row_separator');
        $footer = template_extract_block($template_thumbnail_view, 'footer');
        $spacer = template_extract_block($template_thumbnail_view, 'spacer');
    }

    $cat_link = is_numeric($aid) ? '' : '&amp;cat=' . $cat;

    $theme_thumb_tab_tmpl = $template_tab_display;

    if ($mode == 'thumb') {
        $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $aid == 'lastalb' ? $lang_album_list['album_on_page'] : $lang_thumb_view['pic_on_page']));
        $theme_thumb_tab_tmpl['inactive_tab'] = strtr($theme_thumb_tab_tmpl['inactive_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . '&amp;page=%d'));
        $theme_thumb_tab_tmpl['inactive_next_tab'] = strtr($theme_thumb_tab_tmpl['inactive_next_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . '&amp;page=%d'));
        $theme_thumb_tab_tmpl['inactive_prev_tab'] = strtr($theme_thumb_tab_tmpl['inactive_prev_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . '&amp;page=%d'));
    } else {
        $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $lang_thumb_view['user_on_page']));
        $theme_thumb_tab_tmpl['inactive_tab'] = strtr($theme_thumb_tab_tmpl['inactive_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&amp;page=%d'));
        $theme_thumb_tab_tmpl['inactive_next_tab'] = strtr($theme_thumb_tab_tmpl['inactive_next_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&amp;page=%d'));
        $theme_thumb_tab_tmpl['inactive_prev_tab'] = strtr($theme_thumb_tab_tmpl['inactive_prev_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&amp;page=%d'));
    }

    $thumbcols = $CONFIG['thumbcols'];
    $cell_width = ceil(100 / $CONFIG['thumbcols']) . '%';

    $tabs_html = $display_tabs ? create_tabs($nbThumb, $page, $total_pages, $theme_thumb_tab_tmpl) : '';
    // The sort order options are not available for meta albums
    if ($sort_options) {
        $param = array('{ALBUM_NAME}' => $album_name,
            '{AID}' => $aid,
            '{PAGE}' => $page,
            '{NAME}' => $lang_thumb_view['name'],
            '{TITLE}' => $lang_thumb_view['title'],
            '{DATE}' => $lang_thumb_view['date'],
            '{SORT_TA}' => $lang_thumb_view['sort_ta'],
            '{SORT_TD}' => $lang_thumb_view['sort_td'],
            '{SORT_NA}' => $lang_thumb_view['sort_na'],
            '{SORT_ND}' => $lang_thumb_view['sort_nd'],
            '{SORT_DA}' => $lang_thumb_view['sort_da'],
            '{SORT_DD}' => $lang_thumb_view['sort_dd'],
            '{POSITION}' => $lang_thumb_view['position'],
            '{SORT_PA}' => $lang_thumb_view['sort_pa'],
            '{SORT_PD}' => $lang_thumb_view['sort_pd'],
            );
        $title = template_eval($template_thumb_view_title_row, $param);
    } else if ($aid == 'favpics' && $CONFIG['enable_zipdownload'] == 1) { //Lots of stuff can be added here later
       $param = array('{ALBUM_NAME}' => $album_name,
                             '{DOWNLOAD_ZIP}'=>$lang_thumb_view['download_zip']
                               );
       $title = template_eval($template_fav_thumb_view_title_row, $param);
    }else{
        $title = $album_name;
    }


    if ($mode == 'thumb') {
        starttable('100%', $title, $thumbcols);
    } else {
        starttable('100%');
    }

    echo $header;

    $i = 0;
    foreach($thumb_list as $thumb) {
        $i++;
        if ($mode == 'thumb') {
            if ($aid == 'lastalb') {
                $params = array('{CELL_WIDTH}' => $cell_width,
                    '{LINK_TGT}' => "thumbnails.php?album={$thumb['aid']}",
                    '{THUMB}' => $thumb['image'],
                    '{CAPTION}' => $thumb['caption'],
                    '{ADMIN_MENU}' => $thumb['admin_menu']
                    );
            } elseif ($aid == 'search') {
                $params = array('{CELL_WIDTH}' => $cell_width,
                    '{LINK_TGT}' => "displayimage.php?album=$aid$cat_link&amp;pos=-{$thumb['pid']}",
                    '{THUMB}' => $thumb['image'],
                    '{CAPTION}' => $thumb['caption'],
                    '{ADMIN_MENU}' => $thumb['admin_menu']
                    );
            } else {
                $params = array('{CELL_WIDTH}' => $cell_width,
                    '{LINK_TGT}' => "displayimage.php?album=$aid$cat_link&amp;pos={$thumb['pos']}",
                    '{THUMB}' => $thumb['image'],
                    '{CAPTION}' => $thumb['caption'],
                    '{ADMIN_MENU}' => $thumb['admin_menu']
                    );
            }
        } else {
            $params = array('{CELL_WIDTH}' => $cell_width,
                '{LINK_TGT}' => "index.php?cat={$thumb['cat']}",
                '{THUMB}' => $thumb['image'],
                '{CAPTION}' => $thumb['caption'],
                '{ADMIN_MENU}' => ''
                );
        }
        echo template_eval($thumb_cell, $params);

        if ((($i % $thumbcols) == 0) && ($i < count($thumb_list))) {
            echo $row_separator;
        }
    }
    for (;($i % $thumbcols); $i++) {
        echo $empty_cell;
    }
    echo $footer;

    if ($display_tabs) {
        $params = array('{THUMB_COLS}' => $thumbcols,
            '{TABS}' => $tabs_html
            );
        echo template_eval($tabs, $params);
    }

    endtable();
    echo $spacer;
}

squid

That seems to have done the trick.

THANK YOU VERY MUCH

line-web

Can i use this to search by album?