<?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 Jürgen Brändle  <braendle@web.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.                         |
// |                                                                      |
// +----------------------------------------------------------------------+
// | Authors: Björn Brockmann <bjoern@project-gooseberry.de>              |
// |          Paul Eppner     <paul@twomoons.de>                          |
// |          Jürgen Brändle  <braendle@web.de>                           |
// +----------------------------------------------------------------------+
// | Changed: none                                                        |
// +----------------------------------------------------------------------+
// @Homepage    http://www.der-dirigent.de

/******************************************************************************
 0. Prüfe Zugriffsrechte
******************************************************************************/
$perm->check('area_group_edit');

/******************************************************************************
 1. Benötigte Funktionen und Klassen includieren
******************************************************************************/
include('inc/fnc.group.php');
// Lade Liste der möglichen Rechte in Der Dirigent
$dedi_perm_val = $val_ct->get_by_group('user_perms', $idclient);

/******************************************************************************
 2. Eventuelle Actions/ Funktionen abarbeiten
******************************************************************************/
switch($action) {
	case 'save':
		$errno = group_save_perms();
		if (!$errno) {
			header ('Status: 302 Moved Temporarily');
			header ('Location:'.$sess->url("main.php?area=group&order=$order&ascdesc=$ascdesc&idgroup=$idgroup"));
			exit;
		}
		break;
}

/******************************************************************************
 3. Eventuelle Dateien zur Darstellung includieren
******************************************************************************/
include('inc/inc.header.php');

/******************************************************************************
 4. Bildschirmausgabe aufbereiten und ausgeben
******************************************************************************/
// Templatedatei laden und Überschrift setzen
$tpl->loadTemplatefile('group_config.tpl');

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

$sql = "SELECT name FROM ".$dedi_db['groups']." WHERE idgroup = $idgroup";
$db->query($sql);
if ($db->next_record()) {
	$_group = ": " . htmlspecialchars($db->f('name'));
}
$sql = "SELECT name FROM ".$dedi_db['lang']." WHERE idlang = $idlang";
$db->query($sql);
if ($db->next_record()) {
	$_group .= "/" . htmlspecialchars($db->f('name'));
}

$tmp['AREA'] = $tmp['AREA'] . $_group;

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

// Links zusammenstellen
$img_path   = 'tpl/'.$cfg_dedi['skin'].'/img/';
$query = "main.php?area=group&order=$order&ascdesc=$ascdesc&idclient=$idclient&idlang=$idlang&idgroup=$idgroup";
$url = '<a href="'.$sess->url($query).'" class="action" onMouseOver="on(\'%s\');return true;" onMouseOut="off();return true;">%s</a>';
$img_abort  = '<img src="' . $img_path . 'but_cancel.gif" alt="' . $dedi_lang['gen_abort'] . '" title="' . $dedi_lang['gen_abort'];
$img_abort .= '" width="21" height="21" border="0"></a>';

// Zurück-Link setzen
$tmp['BACK'] = sprintf($url, $dedi_lang['group_back'], $dedi_lang['group_back']);

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

// Formulareinstellungen
$tmp['FORM_URL']   = $sess->url('main.php');
$tmp['FORM_ABORT'] = sprintf($url, $dedi_lang['gen_abort'], $img_abort);
$tmp['IMGPATH']    = $img_path;
$tmp['IDGROUP']    = $idgroup;
$tmp['IDLANG']     = $idlang;
$tmp['IDCLIENT']   = $idclient;
$tmp['ORDER']      = $order;
$tmp['ASCDESC']    = $ascdesc;
$tpl->setVariable($tmp);
unset($tmp);

// Lade eingetragene Rechte der Gruppe
$sim_perm = &new dedi_perms($idclient, $idlang, true, $idgroup);

// Lade die algemeinen Rechtegruppen und zeige für jede die eingetragenen Rechte an
$sql  = 'SELECT DISTINCT key2, conf_desc_langstring, conf_sortindex ';
$sql .= 'FROM ' . $dedi_db['values'] . ' ';
$sql .= 'WHERE ';
$sql .= " (key1 = 'dedi_access' AND key2 NOT LIKE 'area_plug_%') ";
$sql .= 'GROUP BY conf_sortindex, key2, conf_desc_langstring';
_show_rightgroup( $sql, false );

// Prüfe auf installierte Plugins und zeige für jede die eingetragenen Rechte an
// Signalisiere dem System, das hier Rechtenamen mit einem Punkt im Namen vorkommen, diese müssen mit "_" ersetzt werden
$sql  = 'SELECT DISTINCT V.key2, V.conf_desc_langstring, V.conf_sortindex ';
$sql .= 'FROM ' . $dedi_db['values'] . ' V, ' . $dedi_db['plug'] . ' P ';
$sql .= 'WHERE ';
// $sql .= " (V.group_name = 'user_perms' AND P.idclient = $idclient AND V.key2 LIKE concat('area_plug_', P.root_name, '_', P.version, '%')) ";
$sql .= " (V.group_name = 'user_perms' AND P.idclient = $idclient AND V.key2 LIKE concat('area_plug_', P.root_name, '%')) ";
$sql .= 'GROUP BY V.conf_sortindex, V.key2, V.conf_desc_langstring';
_show_rightgroup( $sql, true );


function _show_rightgroup( $sql, $plugins ) {
	global $db, $dedi_lang, $tmp;

	$db2 = &new DB_dedi;
	$db2->query($sql);
	while ($db2->next_record()) {
		$area_name = $db2->f('key2');
		$display   = $db2->f('conf_desc_langstring');
		$topic     = $dedi_lang[$display];
		create_area_checkbox($area_name, $topic, $display, $plugins);
		unset($tmp);
	}
}

?>