<?php
// File: $Id: inc.mod_config.php,v 1.23 2004/06/21 13:47:02 roland Exp $
// +----------------------------------------------------------------------+
// | Der Dirigent 1.0                                                     |
// +----------------------------------------------------------------------+
// | 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.                         |
// |                                                                      |
// +----------------------------------------------------------------------+
// | Authors: Roland Braband <stam@der-dirigent.de>                       |
// +----------------------------------------------------------------------+


/**
 * 1. Benötigte Funktionen und Klassen includieren
 */
include_once('inc/fnc.mod.php');
include_once('inc/fnc.mipforms.php');
/**
 * 2. Eventuelle Actions/ Funktionen abarbeiten
 */
$perm->check(4, 'mod', $idmod);
if ($idclient != 0 && $idclient != (int) $client || !isset($idclient)) $idclient = (int) $client;
/**
 * 3. Eventuelle Dateien zur Darstellung includieren
 */
include('inc/inc.header.php');
/**
 * 4. Bildschirmausgabe aufbereiten und ausgeben
 */
$BACK = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod&idmod=&idclient=$idclient") . "\" onMouseOver=\"on('" . $dedi_lang['gen_back'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['gen_back'] . "</a>&nbsp;";
echo "<center>\n";
echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"98%\">\n";
echo "  <tr>\n";
echo "    <td>&nbsp;" . $dedi_lang['area_mod_config'] . "&nbsp;";
if ($errno) echo "&nbsp;<span class=\"errormsg\">" . $dedi_lang["err_$errno"] . "</span>&nbsp;";
echo "  </td>\n";
echo "    <td align=\"right\">&nbsp;".$CONFIG_GLOBAL.$CONFIG_CLIENT.$BACK."&nbsp;</td>";
echo "  </tr>\n";
echo "  <tr>\n";
echo "    <td colspan=\"2\"><br>\n";
// get modconfig
$modul = $rep->mod_data($idmod, $idclient);
if (is_array($modul)) {
    $modname = (empty($modul['verbose'])) ? htmlspecialchars($modul['name']) : htmlspecialchars($modul['verbose']);
    $modversion = (!empty($modul['version'])) ? ' (' . htmlspecialchars($modul['version']) . ')' : '';
    $modcat = htmlspecialchars($modul['cat']);
    $description = htmlspecialchars($modul['description']);
    $default = $modul['input'];
    $input = $modul['input'];
    $output = $modul['output'];
    if($action == 'change' && !$resetmod) $modconfig = make_array_to_urlstring($MOD_VAR);
    elseif (!$resetmod) $modconfig = $modul['config'];
}
$reset = '';
$list['id'][] = '';
$s_default = array(NULL);
if ($sess->is_registered('s_default')) $sess->unregister('s_default');
mip_forms_ob_start();
eval(' ?>' . $default);
$default_arr = mip_forms_get_array();
$default_arr = array_merge ($dedi_mod, $default_arr);
mip_forms_ob_end();
$trans_html = get_html_translation_table(HTML_ENTITIES);
$trans_html = array_flip($trans_html);
if (is_array($default_arr)) foreach($default_arr as $test_key => $test_var) {
    if ($test_key == 'value') {
        foreach ($test_var as $val_key => $val_var) {
            if (!is_array($val_var)) $s_default[$val_key] = ($val_var != '') ? strtr($val_var, $trans_html) : '';
        }
        continue;
    }
    preg_match("/MOD_VAR\[([^\]]\d*)\]/", $test_key, $match_key);
    $s_default[$match_key['1']] = ($test_var != '') ? strtr($test_var, $trans_html) : '';
}
$sess->register('s_default');
// Alle verfügbaren Layouts einlesen
$sql = "SELECT idlay FROM " . $dedi_db['lay'] . " WHERE idclient='$client'";
$db->query($sql);
while ($db->next_record()) $idlay[] = $db->f('idlay');
if (is_array($idlay)) $idlay = implode(',', $idlay);
function extract_modconfig($in) {
    $keyandvalues = preg_split("/&/", $in);
    foreach ($keyandvalues as $kandv) {
        $extracted_pairs = explode('=', $kandv);
        $key = $extracted_pairs['0'];
        $value = $extracted_pairs['1'];
        $out[$key] = urldecode($value);
        $out[$key] = dedi_stripslashes($out[$key]);
    }
    return $out;
}
$a = extract_modconfig($modconfig);
foreach ($a as $key => $value) {
    $dedi_mod['value'][$key] = $value;
    $input = str_replace("MOD_VALUE[$key]", $value, $input);
}
echo "    <form name=\"editform\" onsubmit=\"document.editform.area.value='mod'\" method=\"post\" action=\"" . $sess->url("main.php") . "\">\n";
echo "    <input type=\"hidden\" name=\"area\" value=\"mod_config\">\n";
echo "    <input type=\"hidden\" name=\"action\" value=\"save_config\">\n";
echo "    <input type=\"hidden\" name=\"idclient\" value=\"$idclient\">\n";
echo "    <input type=\"hidden\" name=\"idmod\" value=\"$idmod\">\n";
echo "    <input type=\"hidden\" name=\"anchor\" value=\"\">\n";
echo "    <table cellpadding=\"$cellpadding\" cellspacing=\"$cellspacing\" border=\"$border\">\n";
echo "      <tr valign=\"top\">\n";
echo "        <td class=\"head\" width=\"110\" valign=\"middle\" nowrap>&nbsp;" . $dedi_lang['mod_modulename'] . "&nbsp;</td>\n";
echo "        <td class=\"content\" style=\"width:640\"><table cellpadding=\"$cellpadding\" cellspacing=\"$cellspacing\" border=\"$border\"><tr><td align=\"left\" style=\"width:600\">$modname $modversion</td><td align=\"right\" style=\"width:40\"><a class=\"action\" href=\"" . $sess->url("main.php?area=mod_config&idmod=" . $idmod . "&idclient=$idclient&resetmod=1") . "\" onMouseOver=\"on('" . $dedi_lang['gen_fundamental'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_resetform.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_config_return'] . "\" title=\"" . $dedi_lang['mod_config_return'] . "\" width=\"18\" height=\"18\"></a></td></tr></table></td>\n";
echo "      </tr>\n";
// rechte management
if (!empty($idmod) && $perm->have_perm(6, 'mod', $idmod)) {
    $panel = $perm->get_right_panel('mod', $idmod, array('formname' => 'editform'), 'text');
	if (!empty($panel)) {
    echo "      <tr>\n";
    echo "        <td class=\"head\">&nbsp;" . $dedi_lang['gen_rights'] . "&nbsp;</td>\n";
    echo "        <td class=\"content\">&nbsp;";
	echo implode("", $panel);
    echo "      </tr>\n";
	}
}
echo "      <tr valign=\"top\">\n";
echo "        <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang['mod_konfiguration'] . "&nbsp;</td>\n";
echo "        <td class=\"content\" style=\"width:640\">\n";
// Konfiguration Data
eval(' ?>' . $input);
echo "        </td>\n";
echo "      </tr>\n";
if ($idclient >= 1) {
    // Einstellungen auf alle Templates anwenden, die das Modul enthalten
    echo "  <tr>\n";
    echo "    <td class=\"head\" valign=\"middle\">&nbsp;" . $dedi_lang['gen_expand'] . "</td>\n";
    echo '    <td class="content"><input type="checkbox" name="mod_config_overwrite_all" value="1" id="touchme"><label for="touchme">' . $dedi_lang['mod_config_all'] . '</label><img src="tpl/' . $cfg_dedi['skin'] . '/img/space.gif" border="0" width="18" height="18"></td>';
    echo "  </tr>\n";
}

// Abbrechen und Bestätigungsbutton
echo "  <tr>\n";
echo "    <td>&nbsp;</td>\n";
echo "    <td align=\"right\"><a href=" . $sess->url('main.php?area=mod&idclient=' . $idclient) . "><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_cancel.gif\" border=\"0\"></a>&nbsp;<input type=\"image\" src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_ok.gif\" border=\"0\"></td>\n";
echo "  </tr>\n";
echo "</table>\n";
echo "</form>\n";
include('tpl/' . $cfg_dedi['skin'] . '/footer.php');
function eval_default($input) {
    global $db, $auth, $dedi_db, $cfg_dedi, $rep, $mod, $perm, $client, $lang;
    eval(' ?>' . $input);
}
?>
