<?php
/**
 * pragmaMx  Content Management System
 * Copyright (c) 2005 pragmaMx Dev Team - http://pragmaMx.org
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * $Source: /home/www/dps3311/home/cvsroot/pragmamx2/CoppermineMx/html/blocks/block-Gallery-Last_pictures_thumb.php,v $
 * $Revision: 1.1.2.3 $
 * $Author: tora60 $
 * $Date: 2006/06/15 19:34:59 $
 * 
 * this file based on:
 * Coppermine Photo Gallery
 * Copyright (c) 2003-2005 Coppermine Dev Team
 * v1.1 originally written by Gregory DEMAR
 * required version: >= 1.4.3
 */

if (!defined("mxMainFileLoaded")) die ("You can't access this file directly...");

// //// Beginn Blockkonfiguration  //////////////////////////
// der Name/Pfad des Gallerymoduls
$cpg_name = 'Gallery';
// Anzahl der Thumbnails
$limit = 4;
// Länge des Bildtitels unter dem Bild
$title_length = 17;
// Liste der Alben, aus denen keine Bilder angezeigt werden sollen. Die ID's durch Komma trennen.
$exluded_albums = '';
// //// Ende Blockkonfiguration  ////////////////////////////

if (@file_exists('modules/' . $cpg_name . '/blocks.inc.php')) {
    include('modules/' . $cpg_name . '/blocks.inc.php');
} else {
    if (mxIsAdmin()) {
        $content = 'The module "' . $cpg_name . '" doesn\'t exist or is not correctly installed. Please install this module or change the Variable $cpg_name in file blocks/' . basename(__file__) . '.';
    } 
    return;
} 
// Abfragebedingung für versteckte Alben erstellen
$exluded_albums = preg_split('#\s*,\s*#', trim($exluded_albums));
foreach($exluded_albums as $ex) {
    $excluded[] = intval($ex);
} 
$exluded_albums = '';
if (isset($excluded)) {
    $exluded_albums = ' AND p.aid NOT IN (' . implode(',', $excluded) . ')';
} 

$result = sql_query("
SELECT p.pid,  p.url_prefix,p.ctime, p.filepath, p.filename, p.aid, a.title 
FROM $CONFIG[TABLE_PICTURES] AS p INNER JOIN $CONFIG[TABLE_ALBUMS] AS a ON (a.aid = p.aid)
WHERE p.approved='YES' AND " . $vis_groups . " " . $exluded_albums . "
GROUP BY p.aid ORDER BY p.ctime DESC, p.pid DESC
LIMIT $limit");

$pic = 0;
$output = '';
while ($row = sql_fetch_array($result)) {
	if (empty($row['title'])) {
		if (preg_match('#^(.+)\.[^.]{2,4}$#', $row['filename'], $matches)) {
			$row['title'] = $matches[1];
		}
		$row['title'] = str_replace('_', ' ', $row['title']);
	}
	$output .= '<p align="center"><a href="modules.php?name=' . $cpg_name . '&amp;&act=thumbnails&album='.$row['aid'].'"><img src="' . get_pic_url($row, 'thumb') . '" border="0" alt="' . $row['title'] . '" title="' . $row['title'] . '"><br />' . mxCutString($row['title'], $title_length) . '</a></p>';
    $pic++;
} 

if ($output) {
    $content = $output . '<p align="center"><a href="modules.php?name=' . $cpg_name . '">' . $CONFIG['gallery_name'] . '</a></p>';
} 

?>