////////////////////////////////////////////////////////////////////////////////
//   Copyright (C) 2004 ReloadCMS Development Team                            //
//   http://reloadcms.sf.net                                                  //
//                                                                            //
//   This program is distributed in the hope that it will be useful,          //
//   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
//                                                                            //
//   This product released under GNU General Public License v2                //
////////////////////////////////////////////////////////////////////////////////
$images = rcms_scandir(GALLERY_PATH);
function is_pic($element)
{
    return preg_match('/.*\\.(jpg|gif|png|bmp|JPG|GIF|BMP|PNG)$/', $element);
}
rcms_chtitle($lang['gallery']['menu']);
function show_gallery_item($id)
{
    global $system;
    $images = rcms_scandir(GALLERY_PATH);
    $gal = '';
    for ($i = 0; $i < count($images); $i++) {
        if (is_pic($images[$i])) {
            if ($id != $i) {
                $gal .= '<a href="?module=gallery&id=' . $i . '">[' . $i . ']</a> ';
            } else {
                $gal .= '<b>[' . $i . ']</b>&nbsp;';
            }
        }
    }
    $gal .= '<br><hr>';
                $start = 0;
                $total = count($contents);
            }
            $result .= '<div align="right">' . rcms_pagination(count($contents), $system->config['perpage'], $page + 1, '?module=' . $module . '&id=' . $_GET['id'] . $work_dir_suffix) . '</div>';
            for ($c = $start; $c < $total + $start; $c++) {
                $article =& $contents[$c];
                if (!empty($article)) {
                    $result .= rcms_parse_module_template('article.tpl', $article + array('showdesc' => true, 'showtitle' => true, 'linktext' => ($article['text_nonempty'] ? $lang['articles']['readart'] : $lang['articles']['comments']) . ' (' . $article['comcnt'] . '/' . $article['views'] . ')', 'linkurl' => '?module=' . $module . '&catid=' . $article['catid'] . '&id=' . $article['id'] . $work_dir_suffix, 'cat_data' => $cat_data));
                }
            }
        }
        $system->showModuleWindow('<a href="./index.php?module=' . $module . $work_dir_suffix . '">' . $lang['articles']['categories'] . '</a> -&gt; ' . (strlen($cat_data['title']) > 30 ? substr($cat_data['title'], 0, 30) . '...' : $cat_data['title']), $result, 'center');
    } else {
        $system->showModuleWindow('', $lang['results']['articles'][12], 'center');
    }
} else {
    /*********************************************************************************
    * List of categories                                                             *
    *********************************************************************************/
    rcms_chtitle($lang['articles']['categories']);
    if ($contents = articles_get_categories_list(false, true, $work_dir)) {
        $result = '';
        foreach ($contents as $category) {
            $result .= rcms_parse_module_template('category.tpl', $category + array('link' => './index.php?module=' . $module . '&id=' . $category['id'] . $work_dir_suffix));
        }
        $system->showModuleWindow($lang['articles']['categories'], $result, 'center');
        $system->config['pagename'] = $lang['articles']['categories'];
    } else {
        $system->showModuleWindow('', $lang['results']['articles'][9], 'center');
    }
}