Example #1
0
function form_alb_thumb()
{
    global $CONFIG, $lang_catmgr_php, $lang_modifyalb_php, $current_category, $cid, $USER_DATA, $LINEBREAK;
    function cpg_get_alb_keyword($sql)
    {
        $keyword = '';
        $result = cpg_db_query($sql);
        if ($result->numRows()) {
            while ($row = $result->fetchAssoc()) {
                $keyword .= "OR (keywords LIKE '%{$row['keyword']}%') ";
            }
        }
        $result->free();
        return $keyword;
    }
    if ($cid == USER_GAL_CAT) {
        $keyword = cpg_get_alb_keyword("SELECT DISTINCT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE category > " . FIRST_USER_CAT . " AND keyword != ''");
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category > " . FIRST_USER_CAT . " {$keyword}) AND approved = 'YES' ORDER BY filename");
    } else {
        $keyword = cpg_get_alb_keyword("SELECT DISTINCT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$cid} AND keyword != ''");
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category = {$cid} {$keyword}) AND approved = 'YES' ORDER BY filename");
    }
    if ($results->numRows() == 0) {
        echo <<<EOT

        <tr>
                <td class="tableb" valign="top">
                        {$lang_modifyalb_php['alb_thumb']}
                </td>
                <td class="tableb" valign="top">
                        <i>{$lang_modifyalb_php['alb_empty']}</i>
                        <input type="hidden" name="thumb" value="0" />
                </td>
        </tr>

EOT;
        return;
    }
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $USER_DATA['user_id']);
    $initial_thumb_url = $cpg_nopic_data['thumb'];
    //'images/nopic.jpg';
    echo <<<EOT

<script language="JavaScript" type="text/JavaScript">
var Pic = new Array()

Pic[0] = '{$initial_thumb_url}'

EOT;
    $img_list = array(0 => $lang_modifyalb_php['last_uploaded']);
    while ($picture = $results->fetchAssoc()) {
        $thumb_url = get_pic_url($picture, 'thumb');
        echo "Pic[{$picture['pid']}] = '" . $thumb_url . "'\n";
        if ($picture['pid'] == $current_category['thumb']) {
            $initial_thumb_url = $thumb_url;
        }
        $img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
    }
    // while
    $results->free();
    echo <<<EOT

</script>

EOT;
    $thumb_cell_height = $CONFIG['thumb_width'] + 17;
    echo <<<EOT
        <tr>
                <td class="tableb" valign="top">
                        {$lang_catmgr_php['cat_thumb']}
                </td>
                <td class="tableb" align="center">
                        <table cellspacing="0" cellpadding="5" border="0">
                                <tr>
                                        <td width="{$thumb_cell_height}" height="{$thumb_cell_height}" align="center"><img src="{$initial_thumb_url}" name='Thumb' class='image' /><br /></td>
                                </tr>
                        </table>
                        <select name="thumb" class="listbox" onchange="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);" onKeyUp="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);">

EOT;
    foreach ($img_list as $pid => $pic_name) {
        echo '                            <option value="' . $pid . '"' . (!empty($current_category['thumb']) && $pid == $current_category['thumb'] ? ' selected' : '') . '>' . $pic_name . '</option>' . $LINEBREAK;
    }
    echo <<<EOT
                        </select>
                </td>
        </tr>

EOT;
}
Example #2
0
/**
* list_cat_albums()
*
* This has been added to list the albums in a category, used for showing first level albums, largely a repetition of code elsewhere
* Redone for a cleaner approach
* @param integer $cat Category id for which albums are needed
*/
function list_cat_albums($cat, $catdata)
{
    global $CONFIG, $lang_date, $FORBIDDEN_SET_DATA;
    global $lang_list_albums;
    $PAGE = 1;
    if ($cat == 0) {
        return '';
    }
    $cat_owner_id = $cat > 10000 ? 10000 - $cat : 10001;
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $cat_owner_id);
    $cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $cat_owner_id);
    $alb_per_page = $CONFIG['albums_per_page'];
    //unused code {SaWey}
    /*$maxTab = $CONFIG['max_tabs'];
    
        $album_filter = '';
        $pic_filter = '';
    
        if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
            $album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
            $pic_filter = ' and ' . $FORBIDDEN_SET;
        }*/
    $nbAlb = $catdata['details']['alb_count'];
    if ($nbAlb == 0) {
        return;
    }
    $totalPages = ceil($nbAlb / $alb_per_page);
    $alb_list = array();
    $approved = ' AND approved=\'YES\'';
    $forbidden_set_string = count($FORBIDDEN_SET_DATA) > 0 ? ' AND aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')' : '';
    $last_pids = array();
    $last_pid_data = array();
    foreach ($catdata['subalbums'] as $aid => $album) {
        if ($CONFIG['link_pic_count'] == 1 || $album['pic_count'] == 0) {
            if (!empty($album['keyword'])) {
                $keyword = $album['keyword'] ? "AND (keywords like '%" . addslashes($album['keyword']) . "%' {$forbidden_set_string})" : '';
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload " . " FROM {$CONFIG['TABLE_PICTURES']} " . " WHERE ((aid != '{$aid}' {$forbidden_set_string}) {$keyword}) {$approved}";
                $result = cpg_db_query($query);
                $link_stat = $result->fetchAssoc(true);
                $catdata['subalbums'][$aid]['link_pic_count'] = $link_stat['link_pic_count'];
                $catdata['subalbums'][$aid]['last_pid'] = !empty($album['last_pid']) && $album['last_pid'] > $link_stat['link_last_pid'] ? $album['last_pid'] : $link_stat['link_last_pid'];
                if ($CONFIG['link_last_upload'] && $link_stat['link_pic_count'] > 0) {
                    $catdata['subalbums'][$aid]['last_upload'] = $album['last_upload'] > $link_stat['link_last_upload'] ? $album['last_upload'] : $link_stat['link_last_upload'];
                }
            }
        }
        if ($catdata['subalbums'][$aid]['last_pid']) {
            $last_pids[] = $catdata['subalbums'][$aid]['last_pid'];
        }
        if ($album['thumb'] > 0) {
            $last_pids[] = $album['thumb'];
        }
    }
    if (count($last_pids)) {
        $result = cpg_db_query("SELECT pid, filepath, filename, url_prefix, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} WHERE pid IN (" . implode(',', $last_pids) . ")");
        while ($row = $result->fetchAssoc()) {
            $last_pid_data[$row['pid']] = $row;
            unset($last_pid_data[$row['pid']]['pid']);
        }
        $result->free();
    }
    unset($last_pids);
    foreach ($catdata['subalbums'] as $aid => $album) {
        // Inserts a thumbnail if the album contains 1 or more images
        //unused code {SaWey}
        //$visibility = $album['visibility'];
        $keyword = $album['keyword'] ? "OR (keywords like '%" . addslashes($album['keyword']) . "%' {$forbidden_set_string})" : '';
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            //test for visibility
            if ($album['pic_count'] > 0 || !empty($album['link_pic_count'])) {
                if (!empty($last_pid_data[$album['thumb']]['filename'])) {
                    $picture = $last_pid_data[$album['thumb']];
                } elseif ($album['thumb'] < 0) {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid = '{$aid}' {$forbidden_set_string}) {$keyword}) {$approved} " . "ORDER BY RAND() LIMIT 0,1";
                    $result = cpg_db_query($sql);
                    $picture = $result->fetchAssoc(true);
                } else {
                    $picture = $last_pid_data[$album['last_pid']];
                }
                $pic_url = get_pic_url($picture, 'thumb');
                if (!is_image($picture['filename'])) {
                    $image_info = cpg_getimagesize(urldecode($pic_url));
                    $picture['pwidth'] = $image_info[0];
                    $picture['pheight'] = $image_info[1];
                }
                //thumb cropping
                if (array_key_exists('system_icon', $picture) && $picture['system_icon'] == true) {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
                } else {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
                }
                $alb_list[$aid]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image thumbnail\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
            } else {
                // Inserts an empty thumbnail if the album contains 0 images
                // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
                $alb_list[$aid]['thumb_pic'] = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
            }
        } elseif ($CONFIG['show_private']) {
            // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
            $alb_list[$aid]['thumb_pic'] = '<img src="' . $cpg_privatepic_data['thumb'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
        }
        // Prepare everything
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            $link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
            $last_upload_date = $album['pic_count'] || $CONFIG['link_pic_count'] && $link_pic_count > 0 ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
            $alb_list[$aid]['aid'] = $aid;
            $alb_list[$aid]['album_title'] = $album['title'];
            $alb_list[$aid]['album_desc'] = bb_decode($album['description']);
            $alb_list[$aid]['pic_count'] = $album['pic_count'];
            $alb_list[$aid]['last_upl'] = $last_upload_date;
            $alb_list[$aid]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $album['alb_hits']);
            $alb_list[$aid]['album_info'] = theme_album_info($album['pic_count'], $link_pic_count, $last_upload_date);
            $alb_list[$aid]['album_adm_menu'] = album_adm_menu($aid, $cat, $album['owner']);
        } elseif ($CONFIG['show_private']) {
            // show private album description
            $link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
            $last_upload_date = $album['pic_count'] || $CONFIG['link_pic_count'] && $link_pic_count > 0 ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
            $alb_list[$aid]['aid'] = $aid;
            $alb_list[$aid]['album_title'] = $album['title'];
            $alb_list[$aid]['album_desc'] = bb_decode($album['description']);
            $alb_list[$aid]['pic_count'] = $album['pic_count'];
            $alb_list[$aid]['last_upl'] = $last_upload_date;
            $alb_list[$aid]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $album['alb_hits']);
            $alb_list[$aid]['album_info'] = theme_album_info($album['pic_count'], $link_pic_count, $last_upload_date);
            $alb_list[$aid]['album_adm_menu'] = album_adm_menu($aid, $cat, $album['owner']);
        }
    }
    ob_start();
    theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
    $cat_albums = ob_get_contents();
    ob_end_clean();
    return $cat_albums;
}
Example #3
0
function form_alb_thumb($text, $name)
{
    global $CONFIG, $ALBUM_DATA, $CLEAN, $lang_modifyalb_php, $USER_DATA;
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $USER_DATA['user_id']);
    if ($ALBUM_DATA['keyword']) {
        $keyword = "OR (keywords like '%{$ALBUM_DATA['keyword']}%')";
    }
    $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} WHERE aid='{$CLEAN['album']}' {$keyword} AND approved='YES' ORDER BY filename");
    if (mysql_num_rows($results) == 0) {
        echo <<<EOT
        <tr>
                <td class="tableb" valign="top">
                        {$text}
                </td>
                <td class="tableb" valign="top">
                        <i>{$lang_modifyalb_php['alb_empty']}</i>
                        <input type="hidden" name="{$name}" value="0" />
                </td>
        </tr>

EOT;
        return;
    }
    $initial_thumb_url = $cpg_nopic_data['thumb'];
    //'images/nopic.jpg';
    echo <<<EOT
<script language="JavaScript" type="text/JavaScript">
<!--
var Pic = new Array()

Pic[0] = '{$initial_thumb_url}'

EOT;
    $img_list = array(0 => $lang_modifyalb_php['last_uploaded'], -1 => $lang_modifyalb_php['random_image']);
    while ($picture = mysql_fetch_array($results)) {
        $thumb_url = get_pic_url($picture, 'thumb');
        echo "Pic[{$picture['pid']}] = '" . $thumb_url . "'\n";
        if ($picture['pid'] == $ALBUM_DATA[$name]) {
            $initial_thumb_url = $thumb_url;
        }
        $img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
    }
    // while
    echo <<<EOT

function ChangeThumb(index)
{
        if (index == -1) index = 0;
        document.images.Thumb.src = Pic[index]
}

var checkobj

function agreesubmit(el){
    checkobj=el
    if (document.all||document.getElementById){
        for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
            var tempobj=checkobj.form.elements[i]
            if(tempobj.type.toLowerCase()=="submit")
                tempobj.disabled=!checkobj.checked
        }
    }
}

function defaultagree(el){
    if (!document.all&&!document.getElementById){
        if (window.checkobj&&checkobj.checked)
            return true
        else{
            alert("{$lang_modifyalb_php['reset_views_confirm']}")
            return false
        }
    }
}

-->
</script>

EOT;
    $thumb_cell_height = $CONFIG['thumb_width'] + 17;
    echo <<<EOT
        <tr>
                <td class="tableb" valign="top">
                        {$text}
                </td>
                <td class="tableb" align="center">
                        <table cellspacing="0" cellpadding="5" border="0">
                                <tr>
                                        <td width="{$thumb_cell_height}" height="{$thumb_cell_height}" align="center"><img src="{$initial_thumb_url}" name='Thumb' class='image' /><br /></td>
                                </tr>
                        </table>
                        <select name="{$name}" class="listbox" onChange="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);" onKeyUp="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);">

EOT;
    foreach ($img_list as $pid => $pic_name) {
        echo '                                <option value="' . $pid . '"' . ($pid == $ALBUM_DATA[$name] ? ' selected' : '') . '>' . $pic_name . "</option>\n";
    }
    echo <<<EOT
                        </select>
                </td>
        </tr>

EOT;
}
function form_alb_thumb($text, $name)
{
    global $CONFIG, $ALBUM_DATA, $CLEAN, $lang_modifyalb_php, $USER_DATA, $LINEBREAK, $help, $icon_array;
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $USER_DATA['user_id']);
    $keyword = '';
    if ($ALBUM_DATA['keyword']) {
        $keyword = "OR (keywords LIKE '%{$ALBUM_DATA['keyword']}%')";
    }
    $query = "SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND (aid = '{$CLEAN['album']}' {$keyword} ) ORDER BY filename";
    $results = cpg_db_query($query);
    if (mysql_num_rows($results) == 0) {
        echo <<<EOT
    <tr>
        <td valign="top">
            {$text}
        </td>
        <td valign="top">
            <em>{$lang_modifyalb_php['alb_empty']}</em>
            <input type="hidden" name="{$name}" value="0" />
        </td>
    </tr>

EOT;
        return;
    }
    $thumbs = array(0 => $cpg_nopic_data['thumb']);
    $img_list = array(0 => $lang_modifyalb_php['last_uploaded'], -1 => $lang_modifyalb_php['random_image']);
    while ($picture = mysql_fetch_assoc($results)) {
        $thumb_url = get_pic_url($picture, 'thumb');
        $thumbs[$picture['pid']] = $thumb_url;
        if ($picture['pid'] == $ALBUM_DATA[$name]) {
            $thumbs[0] = $thumb_url;
        }
        $img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
    }
    mysql_free_result($results);
    $thumbs_json = json_encode($thumbs);
    $thumb_cell_height = $CONFIG['thumb_width'] + 17;
    echo <<<EOT
    <tr>
        <td valign="top">
            {$icon_array['album_thumbnail']}{$text}{$help['album_thumbnail']}
        </td>
        <td align="left">
            <img src="{$thumbs[0]}" name="Thumb" class="image" alt="{$text}" />
            <br />

EOT;
    echo <<<EOT
            <script language="JavaScript" type="text/JavaScript">
                var Pic = {$thumbs_json};
            </script>

EOT;
    echo <<<EOT
            <select name="{$name}" class="listbox" onchange="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);" onkeyup="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);">

EOT;
    foreach ($img_list as $pid => $pic_name) {
        echo '                <option value="' . $pid . '"' . ($pid == $ALBUM_DATA[$name] ? ' selected="selected"' : '') . '>' . $pic_name . '</option>' . $LINEBREAK;
    }
    echo <<<EOT
            </select>
        </td>
    </tr>

EOT;
}
Example #5
0
function form_alb_thumb()
{
    global $CONFIG, $lang_catmgr_php, $lang_modifyalb_php, $current_category, $cid, $USER_DATA;
    $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category = '{$cid}' AND approved='YES' ORDER BY filename");
    if (mysql_num_rows($results) == 0) {
        echo <<<EOT
        <tr>
                <td class="tableb" valign="top">
                        {$lang_modifyalb_php['alb_thumb']}
                </td>
                <td class="tableb" valign="top">
                        <i>{$lang_modifyalb_php['alb_empty']}</i>
                        <input type="hidden" name="thumb" value="0" />
                </td>
        </tr>

EOT;
        return;
    }
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $USER_DATA['user_id']);
    $initial_thumb_url = $cpg_nopic_data['thumb'];
    //'images/nopic.jpg';
    echo <<<EOT
<script language="JavaScript" type="text/JavaScript">
var Pic = new Array()

Pic[0] = '{$initial_thumb_url}'

EOT;
    $img_list = array(0 => $lang_modifyalb_php['last_uploaded']);
    while ($picture = mysql_fetch_array($results)) {
        $thumb_url = get_pic_url($picture, 'thumb');
        echo "Pic[{$picture['pid']}] = '" . $thumb_url . "'\n";
        if ($picture['pid'] == $current_category['thumb']) {
            $initial_thumb_url = $thumb_url;
        }
        $img_list[$picture['pid']] = htmlspecialchars($picture['filename']);
    }
    // while
    echo <<<EOT

function ChangeThumb(index)
{
        document.images.Thumb.src = Pic[index]
}
</script>

EOT;
    $thumb_cell_height = $CONFIG['thumb_width'] + 17;
    echo <<<EOT
        <tr>
                <td class="tableb" valign="top">
                        {$lang_catmgr_php['cat_thumb']}
                </td>
                <td class="tableb" align="center">
                        <table cellspacing="0" cellpadding="5" border="0">
                                <tr>
                                        <td width="{$thumb_cell_height}" height="{$thumb_cell_height}" align="center"><img src="{$initial_thumb_url}" name='Thumb' class='image' /><br /></td>
                                </tr>
                        </table>
                        <select name="thumb" class="listbox" onChange="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);" onKeyUp="if(this.options[this.selectedIndex].value) ChangeThumb(this.options[this.selectedIndex].value);">

EOT;
    foreach ($img_list as $pid => $pic_name) {
        echo '                                <option value="' . $pid . '"' . (!empty($current_category['thumb']) && $pid == $current_category['thumb'] ? ' selected' : '') . '>' . $pic_name . "</option>\n";
    }
    echo <<<EOT
                        </select>
                </td>
        </tr>

EOT;
}
Example #6
0
/**
* list_cat_albums()
*
* This has been added to list the albums in a category, used for showing first level albumslargely a repetition of code elsewhere
* Redone for a cleaner approach
* @param integer $cat Category id for which albums are needed
*/
function list_cat_albums($cat = 0)
{
    global $CONFIG, $USER, $lastup_date_fmt, $USER_DATA, $FORBIDDEN_SET, $FORBIDDEN_SET_DATA, $cpg_show_private_album;
    global $lang_list_albums, $lang_errors;
    $PAGE = 1;
    if ($cat == 0) {
        return '';
    }
    $cat_owner_id = $cat > 10000 ? 10000 - $cat : 10001;
    $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $cat_owner_id);
    $cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $cat_owner_id);
    $alb_per_page = $CONFIG['albums_per_page'];
    $maxTab = $CONFIG['max_tabs'];
    $album_filter = '';
    $pic_filter = '';
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
        $album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
        $pic_filter = ' and ' . $FORBIDDEN_SET;
    }
    $sql = "SELECT count(aid) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '{$cat}'" . $album_filter;
    $result = cpg_db_query($sql);
    $nbEnr = mysql_fetch_array($result);
    $nbAlb = $nbEnr[0];
    mysql_free_result($result);
    if ($nbAlb == 0) {
        return;
    }
    $totalPages = ceil($nbAlb / $alb_per_page);
    if ($PAGE > $totalPages) {
        $PAGE = 1;
    }
    $lower_limit = ($PAGE - 1) * $alb_per_page;
    $upper_limit = min($nbAlb, $PAGE * $alb_per_page);
    $limit = "LIMIT " . $lower_limit . "," . ($upper_limit - $lower_limit);
    $sql = 'SELECT a.aid, a.title, a.description, a.thumb, visibility, filepath, ' . 'filename, url_prefix, pwidth, pheight ' . 'FROM ' . $CONFIG['TABLE_ALBUMS'] . ' as a ' . 'LEFT JOIN ' . $CONFIG['TABLE_PICTURES'] . ' as p ' . 'ON a.thumb=p.pid ' . 'WHERE category=' . $cat . $album_filter . ' ORDER BY a.pos ' . $limit;
    $alb_thumbs_q = cpg_db_query($sql);
    $alb_thumbs = cpg_db_fetch_rowset($alb_thumbs_q);
    mysql_free_result($alb_thumbs_q);
    $disp_album_count = count($alb_thumbs);
    $album_set = '';
    foreach ($alb_thumbs as $value) {
        $album_set .= $value['aid'] . ', ';
    }
    $album_set = '(' . substr($album_set, 0, -2) . ')';
    /*$sql = "SELECT aid, count(pid) as pic_count, max(pid) as last_pid, max(ctime) as last_upload " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE aid IN $album_set AND approved = 'YES' " . "GROUP BY aid";
      $alb_stats_q = cpg_db_query($sql);
      $alb_stats = cpg_db_fetch_rowset($alb_stats_q);
      mysql_free_result($alb_stats_q);*/
    //This query will fetch album stats and keyword for the albums
    $sql = "SELECT a.aid, count( p.pid )  AS pic_count, max( p.pid )  AS last_pid, max( p.ctime )  AS last_upload, a.keyword, a.alb_hits" . " FROM {$CONFIG['TABLE_ALBUMS']} AS a " . " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.aid = p.aid AND p.approved =  'YES' " . "WHERE a.aid IN {$album_set}" . "GROUP BY a.aid";
    $alb_stats_q = cpg_db_query($sql);
    $alb_stats = cpg_db_fetch_rowset($alb_stats_q);
    mysql_free_result($alb_stats_q);
    foreach ($alb_stats as $key => $value) {
        $cross_ref[$value['aid']] =& $alb_stats[$key];
        if ($CONFIG['link_pic_count'] == 1) {
            if (!empty($value['keyword'])) {
                $query = "SELECT count(pid) AS link_pic_count\n                      FROM {$CONFIG['TABLE_PICTURES']}\n                        WHERE aid != {$value['aid']} AND\n                        keywords LIKE '%{$value['keyword']}%' AND\n                        approved = 'YES'";
                $result = cpg_db_query($query);
                $link_stat = mysql_fetch_array($result);
                mysql_free_result($result);
                $alb_stats[$key]['link_pic_count'] = $link_stat['link_pic_count'];
            }
        }
    }
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
        $alb_thumb =& $alb_thumbs[$alb_idx];
        $aid = $alb_thumb['aid'];
        if (isset($cross_ref[$aid])) {
            $alb_stat = $cross_ref[$aid];
            $count = $alb_stat['pic_count'];
            $alb_hits = $alb_stat['alb_hits'];
        } else {
            $alb_stat = array();
            $count = 0;
            $alb_hits = 0;
        }
        // Inserts a thumbnail if the album contains 1 or more images
        $visibility = $alb_thumb['visibility'];
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            //test for visibility
            if ($count > 0) {
                // Inserts a thumbnail if the album contains 1 or more images
                if ($alb_thumb['filename']) {
                    $picture =& $alb_thumb;
                } elseif ($alb_thumb['thumb'] < 0) {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = '{$alb_thumb['aid']}' ORDER BY RAND() LIMIT 0,1";
                    $result = cpg_db_query($sql);
                    $picture = mysql_fetch_array($result);
                    mysql_free_result($result);
                } else {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='{$alb_stat['last_pid']}'";
                    $result = cpg_db_query($sql);
                    $picture = mysql_fetch_array($result);
                    mysql_free_result($result);
                }
                $pic_url = get_pic_url($picture, 'thumb');
                if (!is_image($picture['filename'])) {
                    $image_info = cpg_getimagesize(urldecode($pic_url));
                    $picture['pwidth'] = $image_info[0];
                    $picture['pheight'] = $image_info[1];
                }
                //thumb cropping
                if ($picture['system_icon'] == 'true') {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
                } else {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
                }
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
            } else {
                // Inserts an empty thumbnail if the album contains 0 images
                // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
                $alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image" border="0" alt="" />';
            }
        } elseif ($CONFIG['show_private']) {
            // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
            $alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_privatepic_data['thumb'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image" border="0" alt="" />';
        }
        // Prepare everything
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
            $alb_list[$alb_idx]['pic_count'] = $count;
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
            $alb_list[$alb_idx]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . ($CONFIG['link_pic_count'] && $link_pic_count > 0 ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
            $alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat);
        } elseif ($CONFIG['show_private']) {
            // uncomment this else block to show private album description
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
            $alb_list[$alb_idx]['pic_count'] = $count;
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
            $alb_list[$alb_idx]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . ($CONFIG['link_pic_count'] && $link_pic_count > 0 ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
            $alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat);
        }
    }
    ob_start();
    theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
    $cat_albums = ob_get_contents();
    ob_end_clean();
    return $cat_albums;
}