<?php
/******************************************************************************
 @Author:     Björn Brockmann, Paul Eppner (paul@twomoons.de)
			      Sven Bräutigam, Jürgen Brändle
 @Homepage    http://www.der-dirigent.de
 Last update : 2005-11-24     - Bugfix for multibyte charsets 
 Part of     : Update to Version 01.00.02 
******************************************************************************/

/******************************************************************************
 1. Benötigte Funktionen und Klassen includieren
******************************************************************************/

include('inc/fnc.tpl.php');

/******************************************************************************
 2. Eventuelle Actions/ Funktionen abarbeiten
******************************************************************************/

$perm->check('area_tpl');
switch($action) {
	case 'delete':  // Template löschen
		$perm->check(5, 'tpl', $idtpl);
		$errno = tpl_delete_template($idtpl);
		break;
}

/******************************************************************************
 3. Eventuelle Dateien zur Darstellung includieren
******************************************************************************/

include('inc/inc.header.php');

/******************************************************************************
 4. Bildschirmausgabe aufbereiten und ausgeben
******************************************************************************/


$tpl->loadTemplatefile('tpl.tpl');

$tmp['AREA'] = $dedi_lang['area_tpl'];

if ( $perm->have_perm(2, 'area_tpl', 0) ) $tmp['NEW_TEMPLATE'] = "<a class=action href=\"".$sess->url("main.php?area=tpl_edit")."\" onMouseOver=\"on('".$dedi_lang["tpl_actions"]["10"]."');return true;\" onMouseOut=\"off();return true;\">".$dedi_lang["tpl_actions"]["10"]."</a>";

if(! empty($errno)){
	$tpl -> setCurrentBlock('ERROR');
	$tpl_error['ERRORMESSAGE'] = $dedi_lang['err_' . $errno];
	$tpl->setVariable($tpl_error);
	$tpl->parseCurrentBlock();
}

// Tabellenformatierung
$tmp['TABLE_PADDING'] = $cellpadding;
$tmp['TABLE_SPACING'] = $cellspacing;
$tmp['TABLE_BORDER'] = $border;

// Templatedatei laden

$tmp['TPL_TEMPLATENAME'] = $dedi_lang['tpl_templatename'];
$tmp['TPL_DESCRIPTION'] = $dedi_lang['tpl_description'];
$tmp['TPL_ACTION'] = $dedi_lang['tpl_action'];
$tpl->setVariable($tmp);
unset($tmp);

// Template aus der Datenbank suchen
$tpl->setCurrentBlock('ENTRY');
$sql = "SELECT * FROM $dedi_db[tpl] WHERE idclient='$client' ORDER BY name";
$db->query($sql);
$int_max = $db->affected_rows();
while ($db->next_record()) 
{
	$idtpl = $db->f('idtpl');
	
	//Darf Template sehen
	if( $perm->have_perm(1, 'tpl', $idtpl) ){
		// Hintergrundfarbe wählen
		$tmp['ENTRY_BGCOLOR'] = '#DBE3EF';
		$tmp['OVERENTRY_BGCOLOR'] = '#C7D5EB';

		// Template duplizieren
		if ( $perm->have_perm(2, 'area_tpl', 0) && $perm->have_perm(3, 'tpl', $idtpl) ){
			$tmp['ENTRY_DUPLICATE'] = "<a class=\"action\" href=\"".$sess->url("main.php?area=tpl_edit&action=duplicate&idtpl=".$db->f('idtpl'))."\" onMouseOver=\"on('".$dedi_lang['tpl_duplicate']."');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/".$cfg_dedi['skin']."/img/but_duplicate.gif\" border=\"0\" alt=\"".$dedi_lang['tpl_duplicate']."\" title=\"".$dedi_lang['tpl_duplicate']."\" width=\"18\" height=\"14\"></a>";
		}

		// Template bearbeiten
		if ( $perm->have_perm(3, 'tpl', $idtpl) ){
			$tmp['ENTRY_EDIT'] = "<a class=\"action\" href=\"".$sess->url("main.php?area=tpl_edit&idtpl=".$db->f('idtpl'))."\" onMouseOver=\"on('".$dedi_lang['tpl_edit']."');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/".$cfg_dedi['skin']."/img/but_edit.gif\" border=\"0\" alt=\"".$dedi_lang['tpl_edit']."\" title=\"".$dedi_lang['tpl_edit']."\" width=\"18\" height=\"14\"></a>";
		}

		// Template löschen
		if ($db->f('deletable')=='1' && $perm->have_perm(5, 'tpl', $idtpl) ){
			$tmp['ENTRY_DELBUT'] = "<a href=\"".$sess->url('main.php?area=tpl&action=delete&idtpl='.$db->f('idtpl'))."\" onMouseOver=\"on('".$dedi_lang['tpl_delete']."');return true;\" onMouseOut=\"off();return true;\" onClick=\"return delete_confirm()\"><img src=\"tpl/".$cfg_dedi['skin']."/img/but_deleteside.gif\" width=\"13\" height=\"13\" border=\"0\" alt=\"".$dedi_lang['tpl_delete']."\" title=\"".$dedi_lang['tpl_delete']."\"></a>";
		}
		else{
			$tmp['ENTRY_DELBUT'] = "<img src=\"tpl/".$cfg_dedi['skin']."/img/space.gif\" border=\"0\" width=\"13\" height=\"13\">";
		}

		$tmp['ENTRY_NAME'] = htmlspecialchars($db->f('name'));
		$tmp['ENTRY_DESCRIPTION'] = htmlspecialchars($db->f('description'));
		$tpl->setVariable($tmp);
		$tpl->parseCurrentBlock();
		unset($tmp);
	}
}

$tpl->setCurrentBlock('NOENTRY');
if ($int_max < 1) {
	$tmp['TPL_NOTEMPLATES'] = $dedi_lang['tpl_notemplates'];
	$tpl->setVariable($tmp);
	$tpl->parseCurrentBlock();
	unset($tmp);
}
?>