<?PHP
// +----------------------------------------------------------------------+
// | Der Dirigent 1.0                                                     |
// | Last update : 2005-11-24        - Bugfix for multibyte charsets      |
// | Part of     : Update to Version 01.00.02                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003-2004 the dedi-group <dedi-group@der-dirigent.de>  |
// +----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License                 |
// |                                                                      |
// | This program is subject to the GPL license, that is bundled with     |
// | this package in the file LICENSE.TXT.                                |
// | If you did not receive a copy of the GNU General Public License      |
// | along with this program write to the Free Software Foundation, Inc., |
// | 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA               |
// |                                                                      |
// | 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.  See the        |
// | GNU General Public License for more details.                         |
// |                                                                      |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+

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

$perm->check('1', 'area_group');
switch ($action) {
	case 'activate':
		group_set_active('1');
		break;
	case 'deactivate':
		group_set_active('0');
		break;
	case 'delete':
		group_delete();
		//Wird eine gruppe gelöscht, wird eventuell noch eine aufgeklappte Spracheinstellung angezeigt - redirect um das zu verhindern
		header ('Status: 302 Moved Temporarily');
		header ('Location:'.$sess->url("main.php?area=group&order=$order&ascdesc=$ascdesc"));
		exit;
		break;
	case 'activate_lang':
		group_visible_lang();
		break;
}

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


// Allgemeine Einstellungen initialisieren
if (empty($ascdesc)) {
	$order = 'name';
	$ascdesc = 'ASC';
}
$base_url = $sess->url('main.php?area=%s&order=%s&ascdesc=%s');

// Templatedatei laden
$tpl->loadTemplatefile('group.tpl');
$tmp['AREA'] = $dedi_lang['area_group'];
if (!empty($errno)) {
	$tpl -> setCurrentBlock('ERROR');
	$tpl_error['ERRORMESSAGE'] = $dedi_lang['err_'.$errno];
	$tpl->setVariable($tpl_error);
	$tpl->parseCurrentBlock();
}
if ($perm->have_perm('area_group_edit')) $tmp['NEW_GROUP'] = '<a href="'.sprintf($base_url, 'group_edit', $order, $ascdesc).'" class="action" onMouseOver="on(\''.$dedi_lang['group_new'].'\');return true;" onMouseOut="off();return true;">Neue Gruppe</a>';

// Tabellenformatierung
$tmp['CELLPADDING'] = $cellpadding;
$tmp['CELLSPACING'] = $cellspacing;
$tmp['BORDER'] = $border;

// Tabellenüberschrift
$tmp['LANG_NAME'] = '<a href ="'.sprintf($base_url, 'group', 'name', ($order == 'name' && ($ascdesc == 'ASC' || $ascdesc == '')) ? 'DESC' : 'ASC').'" onMouseOver="on(\''.$dedi_lang['gen_sort'].'\');return true;" onMouseOut="off()" ;return true;">'.$dedi_lang['group_name'].'</a>';
$tmp['LANG_DESCRIPTION'] = '<a href ="'.sprintf($base_url, 'group', 'description', ($order == 'description' && ($ascdesc == 'ASC' || $ascdesc == '')) ? 'DESC' : 'ASC').'" onMouseOver="on(\''.$dedi_lang['gen_sort'].'\');return true;" onMouseOut="off()" ;return true;">'.$dedi_lang['group_description'].'</a>';
$tmp['LANG_ACTIONS'] = $dedi_lang['group_actions'];
$tpl->setVariable($tmp);
unset($tmp);

// Usergruppen auflisten
$tpl->setCurrentBlock('PREENTRY');
$sql = "SELECT * FROM ".$dedi_db['groups']." WHERE is_deletable = '1' ORDER BY $order $ascdesc";
$db->query($sql);
while ($db->next_record()) {
	if ($db->f('idgroup') == $idgroup) $tpl->setCurrentBlock('ENTRY');
	$tmp['NAME'] = htmlspecialchars($db->f('name'));
	$tmp['DESCRIPTION'] = htmlspecialchars($db->f('description'));
	$tmp['BUTTON_EDIT'] = '<a href="'.sprintf($base_url, 'group_edit', $order, $ascdesc).'&idgroup='.$db->f('idgroup').'" onMouseOver="on(\''.$dedi_lang['group_edit'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_edit.gif" border="0" alt="'.$dedi_lang['group_edit'].'" title="'.$dedi_lang['group_edit'].'" width="18" height="14"></a>';
	$tmp['BUTTON_CONFIG'] = '<a href="'.sprintf($base_url.'%s', 'group', $order, $ascdesc, ($db->f('idgroup') != $idgroup) ? '&idgroup='.$db->f('idgroup') : '').'" onMouseOver="on(\''.$dedi_lang['group_config'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_config.gif" border="0" alt="'.$dedi_lang['group_config'].'" title="'.$dedi_lang['group_config'].'" width="15" height="15"></a>';
	$tmp['BUTTON_AKTIVE'] = ($db->f('is_active') == '0') ? '<a href="'.sprintf($base_url, 'group', $order, $ascdesc).'&action=activate&idgroup='.$db->f('idgroup').'" onMouseOver="on(\''.$dedi_lang['group_on'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_offline.gif" border="0" alt="'.$dedi_lang['group_on'].'" title="'.$dedi_lang['group_on'].'" width="13" height="13"></a>' : '<a href="'.sprintf($base_url, 'group', $order, $ascdesc).'&action=deactivate&idgroup='.$db->f('idgroup').'" onMouseOver="on(\''.$dedi_lang['group_off'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_online.gif" border="0" alt="'.$dedi_lang['group_off'].'" title="'.$dedi_lang['group_off'].'" width="13" height="13"></a>';
	$tmp['BUTTON_DELETE'] = '<a href="'.sprintf($base_url, 'group', $order, $ascdesc).'&action=delete&idgroup='.$db->f('idgroup').'" onMouseOver="on(\''.$dedi_lang['group_delete'].'\');return true;" onMouseOut="off();return true;" onClick="return delete_confirm()"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_delete.gif" alt="'.$dedi_lang['group_delete'].'" title="'.$dedi_lang['group_delete'].'" width="13" height="13" border="0"></a>';
	$tpl->setVariable($tmp);
	$tpl->parseCurrentBlock();
	unset($tmp);
	if ($db->f('idgroup') == $idgroup) $tpl->setCurrentBlock('POSTENTRY');
}
if (!$db->affected_rows()) {
	$tpl -> setCurrentBlock('EMPTY');
	$tmp['LANG_NOGROUPS'] = $dedi_lang['group_nogroups'];
	$tpl->setVariable($tmp);
	$tpl->parse('EMPTY');
	unset($tmp);
}

// Sprachen zuordnen
if ($idgroup) {
	$sim_perm = &new dedi_perms($client_id, $idlang, true, $idgroup);
	$tpl->setCurrentBlock('CONFIG');
	$db2 = &new DB_dedi;
	$sql = "SELECT A.idclient, A.name, B.idlang, B.name AS lang FROM ". $dedi_db['clients'] ." A, ". $dedi_db['lang'] ." B LEFT JOIN ". $dedi_db['clients_lang'] ." C USING(idlang) WHERE A.idclient = C.idclient ORDER BY A.idclient, lang";
	$db2->query($sql);
	while ($db2->next_record()) {
		$tmp['NAME'] = htmlspecialchars($db2->f('name'));
		$tmp['DESCRIPTION'] = htmlspecialchars($db2->f('lang'));
		if ($sim_perm -> have_perm('1', 'lang', $db2->f('idlang'))) {
			$tmp['BUTTON_CONFIG'] = '<a href="'.sprintf($base_url, 'group_config', $order, $ascdesc).'&idgroup='.$idgroup.'&idlang='.$db2->f('idlang').'&idclient='.$db2->f('idclient').'" onMouseOver="on(\''.$dedi_lang['group_langconfig'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_config.gif" border="0" alt="'.$dedi_lang['group_langconfig'].'" title="'.$dedi_lang['group_langconfig'].'" width="15" height="15"></a>';
			$tmp['BUTTON_AKTIVE'] = '<a href="'.sprintf($base_url, 'group', $order, $ascdesc).'&action=activate_lang&idgroup='.$idgroup.'&idlang='.$db2->f('idlang').'" onMouseOver="on(\''.$dedi_lang['group_langoff'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_online.gif" border="0" alt="'.$dedi_lang['group_langoff'].'" title="'.$dedi_lang['group_langoff'].'" width="13" height="13"></a>';
                 } else $tmp['BUTTON_AKTIVE'] = '<a href="'.sprintf($base_url, 'group', $order, $ascdesc).'&action=activate_lang&idgroup='.$idgroup.'&idlang='.$db2->f('idlang').'" onMouseOver="on(\''.$dedi_lang['group_langon'].'\');return true;" onMouseOut="off()" ;return true;"><img src="tpl/'.$cfg_dedi['skin'].'/img/but_offline.gif" border="0" alt="'.$dedi_lang['group_langon'].'" title="'.$dedi_lang['group_langon'].'" width="13" height="13"></a>';
		$tmp['SPACE'] = '<img src="tpl/'.$cfg_dedi['skin'].'/img/space.gif" border="0" width="13" height="13">';
		$tpl->setVariable($tmp);
		$tpl->parseCurrentBlock();
		unset($tmp);
	}
}
?>