<?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    
******************************************************************************/
include('inc/fnc.lay.php');


$perm->check('area_lay');
switch($action)
{
	case 'copy':  // Layout kopieren
		$errno = lay_copy($idlay, $from, $into);
		break;
	case 'save':  // Layout speichern
		if(is_numeric($idlay)) $perm->check(3, 'lay', $idlay);
		else $perm->check(3, 'area_lay', 0);
		lay_edit_layout($idlay, $layname, $description, $code, $idclient);
		break;
	case 'delete':  // Layout löschen
		$perm->check(5, 'lay', $idlay);
		$errno = lay_delete_layout($idlay);
		break;
}

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

// Templatedatei laden
$tpl->loadTemplatefile('lay.tpl');

if ($idclient != '0') {
	//Layout anlegen
	if ($perm->have_perm(2, 'area_lay', 0)){
		$tmp['NEW_LAYOUT'] = "<a class=\"action\" href=\"".$sess->url("main.php?area=lay_edit&idclient=$idclient")."\" onMouseOver=\"on('".$dedi_lang['lay_new']."');return true;\" onMouseOut=\"off();return true;\">".$dedi_lang['lay_new']."</a>";
	}
	//Layout importieren
	if ($perm->have_perm(7, 'area_lay', 0)){
		$tmp['IMPORT_LAYOUT'] = "&nbsp;|&nbsp;<a class=\"action\" href=\"".$sess->url('main.php?area=lay&idclient=0')."\" onMouseOver=\"on('".$dedi_lang['lay_import']."');return true;\" onMouseOut=\"off();return true;\">".$dedi_lang['lay_import']."</a>&nbsp;";
	}
}
else{
	$tmp['BACK'] = "<a class=action href=\"".$sess->url("main.php?area=lay&idclient=$client")."\" onMouseOver=\"on('".$dedi_lang['gen_back']."');return true;\" onMouseOut=\"off();return true;\">".$dedi_lang['gen_back']."</a>&nbsp;";
}


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

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;


$tmp['LAY_LAYOUTNAME'] = $dedi_lang['lay_layoutname'];
$tmp['LAY_DESCRIPTION'] = $dedi_lang['lay_description'];
$tmp['LAY_ACTION'] = $dedi_lang['lay_action'];
$tpl->setVariable($tmp);
unset($tmp);

// Layout aus der Datenbank suchen
$tpl->setCurrentBlock('ENTRY');
$sql = "SELECT * FROM $dedi_db[lay] WHERE idclient='$idclient' ORDER BY name";
$db->query($sql);
$affected_rows = $db->affected_rows();
while ($db->next_record()) 
{
	$idlay = $db->f('idlay');

	//Darf aktuelles Layout sehen, wenn nicht, Schleifendurchgang abbrechen
	//In der Standardübersicht
	if(! $perm->have_perm(1, 'lay', $idlay)) continue;
	
	// Hintergrundfarbe wählen
	if ($idclient=='0') {
         	$tmp['ENTRY_BGCOLOR'] = '#C7D5EB';
                 $tmp['OVERENTRY_BGCOLOR'] = '#A8BADE';
	} else {
         	$tmp['ENTRY_BGCOLOR'] = '#DBE3EF';
                 $tmp['OVERENTRY_BGCOLOR'] = '#C7D5EB';
	}

	//Layout duplirieren - braucht Rechte neu anlegen (2) und bearbeiten (3)
	if ( $perm->have_perm(2, 'lay', $idlay) && $perm->have_perm(3, 'lay', $idlay) ) $tmp['ENTRY_DUPLICATE'] = "<a class=\"action\" href=\"".$sess->url("main.php?area=lay_edit&idlay=".$db->f('idlay')."&idclient=$idclient&action=duplicate")."\" onMouseOver=\"on('".$dedi_lang['lay_duplicate']."');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/".$cfg_dedi['skin']."/img/but_duplicate.gif\" border=\"0\" alt=\"".$dedi_lang['lay_duplicate']."\" title=\"".$dedi_lang['lay_duplicate']."\" width=\"18\" height=\"14\"></a>";

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

	//Layout importieren - Recht importieren (7), exportieren (8)
	//Nur im Importbereich 
	if ($idclient=='0' && $perm->have_perm(7, 'lay', $idlay) ) $tmp['ENTRY_IMPORT'] = "<a class=\"action\" href=\"".$sess->url("main.php?area=lay&action=copy&idlay=".$db->f('idlay')."&into=$client&idclient=0")."\" onMouseOver=\"on('".$dedi_lang['lay_import']."');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/".$cfg_dedi['skin']."/img/import.gif\" border=\"0\" alt=\"".$dedi_lang['lay_import']."\" title=\"".$dedi_lang['lay_import']."\" width=\"19\" height=\"11\"></a>";

	// Layout exportieren - Recht exportieren (8)
	if ($idclient!='0' && $perm->have_perm(8, 'lay', $idlay) ) $tmp['ENTRY_EXPORT'] = "<a class=\"action\" href=\"".$sess->url("main.php?area=lay&action=copy&idlay=".$db->f('idlay')."&from=$client&idclient=$idclient")."\" onMouseOver=\"on('".$dedi_lang['lay_export']."');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/".$cfg_dedi['skin']."/img/export.gif\" border=\"0\" alt=\"".$dedi_lang['lay_export']."\" title=\"".$dedi_lang['lay_export']."\" width=\"19\" height=\"11\"></a>";

	//Layout löschen - Recht löschen (5) 
	if ($db->f('deletable')=='1' &&  $perm->have_perm(5, 'lay', $idlay)  ) $tmp['ENTRY_DELBUT'] = "<a href=\"".$sess->url('main.php?area=lay&action=delete&idlay='.$db->f('idlay').'&idclient='.$idclient)."\" onMouseOver=\"on('".$dedi_lang['lay_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['lay_delete']."\" title=\"".$dedi_lang['lay_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);
}


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