<?php
// File: $Id: inc.plug_config.php,v 1.12 2004/06/14 13:30:13 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.plug.php');
/**
 * 2. Eventuelle Actions/ Funktionen abarbeiten
 */
if ($idclient != 0 && $idclient != (int) $client || !isset($idclient)) $idclient = (int) $client;
if (!$idplug && $dedi_plugin) $idplug = $dedi_plugin;
$perm_edit_settings = $idclient > 0 ? 'area_plug_settings' : 'area_plug_settings_general';
$perm_edit_settings_view = $idclient > 0 ? 'area_plug_settings_view' : 'area_plug_settings_view_general';
$perm->check('area_plug_conf');
// get plugconfig
$sql = "SELECT * FROM " . $dedi_db['plug'] . " WHERE idplug='$idplug'";
$db->query($sql);
$db->next_record();
$plugname = $db->f('name');
$plugroot = $db->f('root_name');
$plugversion = $db->f('version');
$plugcat = $db->f('cat');
$description = $db->f('description');
$plugconfig = $db->f('config');
$list['id'][] = '';
/**
 * 3. Eventuelle Dateien zur Darstellung includieren
 */
include('inc/inc.header.php');
include('inc/class.values_ct_edit.php');
/**
 * 4. Bildschirmausgabe aufbereiten und ausgeben
 */
$BACK = "<a class=\"action\" href=\"" . $sess->url("main.php?area=plug&idplug=&idclient=$idclient") . "\" onMouseOver=\"on('" . $dedi_lang['gen_back'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['gen_back'] . "</a>&nbsp;";
if($idclient >= 1) {
    if($perm->have_perm(18, 'plug', $idplug)) $CONFIG_GLOBAL = "<a class=\"action\" href=\"" . $sess->url("main.php?area=plug_config&idplug=$idplug&idclient=0") . "\" onMouseOver=\"on('Globale" . $dedi_lang['plug_konfiguration'] . "');return true;\" onMouseOut=\"off();return true;\">Globale " . $dedi_lang['plug_konfiguration'] . "</a>&nbsp;|&nbsp;";
} else {
    if($perm->have_perm(4, 'plug', $idplug) || $perm->have_perm(18, 'plug', $idplug)) $CONFIG_CLIENT = "<a class=\"action\" href=\"" . $sess->url("main.php?area=plug_config&idplug=$idplug&idclient=$client") . "\" onMouseOver=\"on('Client " . $dedi_lang['plug_konfiguration'] . "');return true;\" onMouseOut=\"off();return true;\">Client " . $dedi_lang['plug_konfiguration'] . "</a>&nbsp;|&nbsp;";
}
echo "<center>\n";
echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"98%\">\n";
echo "  <tr>\n";
echo "    <td>&nbsp;" . $dedi_lang['area_plug_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";
function extract_plugconfig($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);
        remove_magic_quotes_gpc($out[$key]);
    } 
    return $out;
}
// todo:insert a full configuration module-table for plugin
$a = extract_plugconfig($plugconfig);
foreach ($a as $key => $value) {
    $dedi_plug['value'][$key] = $value;
    $input = str_replace("MOD_VALUE[$key]", $value, $input);
} 
echo "    <form name=\"editform\" onsubmit=\"document.editform.area.value='plug'\" method=\"post\" action=\"" . $sess->url("main.php") . "\">\n";
echo "    <input type=\"hidden\" name=\"area\" value=\"plug_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=\"idplug\" value=\"$idplug\">\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['plug_pluginname'] . "&nbsp;</td>\n";
echo "        <td class=\"content\" style=\"width:640\"><table cellpadding=\"$cellpadding\" cellspacing=\"$cellspacing\" border=\"$border\"><tr><td align=\"left\" style=\"width:600\">$plugname $plugversion</td><td align=\"right\" style=\"width:40\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"18\" height=\"18\"></td></tr></table></td>\n";
echo "      </tr>\n";

//rechte bearbeiten
if (!empty($idplug) && $perm->have_perm(6, 'area_plug', 0)){
	$panel = $perm->get_right_panel('area_plug_'.$plugroot, $idplug, array('formname' => 'editform'), 'text', true);
	if (!empty($panel)) {
	    echo "	   <tr valign=\"top\">\n";
	    echo "	     <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang['gen_rights'] . "&nbsp;</td>\n";
	    echo "	     <td class=\"content\">".implode("", $panel)."</td>\n";
	    echo "      </tr>\n";
	}
}    

// Konfiguration Data
if ($perm->have_perm($perm_edit_settings_view) || $perm->have_perm($perm_edit_settings)) {
    $output = &new values_ct_edit(array('sqlgroup' => $plugroot,
            'client' => $idclient,
            'lang' => '0',
            'perm_edit' => $perm_edit_settings,
            'tpl_file' => 'plug_settings.tpl',
            'table_cellpadding' => $cellpadding,
            'table_cellspacing' => $cellspacing,
            'table_border' => $border,
            'area' => 'plug_config',
            'dedi_plugin' => $idplug,
            'action' => $action,
            'view' => 'use',
            'prefix' => '$cfg_' . $plugroot));
    $output->start();
    $old_cache = $tpl->clearCache;
    $tpl->clearCache = true;
    echo "      <tr valign=\"top\">\n";
    echo "        <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang['plug_config_settings'] . "</td>\n";
    echo "        <td class=\"content\" style=\"width:640\"><table cellpadding=\"$cellpadding\" cellspacing=\"0\" border=\"$border\">\n";
    echo $return_tpl = $tpl->get('ENTRY');
    $tpl->clearCache = $old_cache;
    if ($return_tpl == '') echo "&nbsp;" . $dedi_lang['plug_config_nosetting'];
    echo "        </table></td>\n";
    echo "      </tr>\n";
}
if ($idclient == '0') {
// Einstellungen auf alle Projekte anwenden, die das Plugin enthalten
echo "  <tr>\n";
echo "    <td class=\"head\" valign=\"middle\">&nbsp;" . $dedi_lang['gen_expand'] . "</td>\n";
echo '    <td class="content" valign=\"middle\"><input type="checkbox" name="plug_config_overwrite_all" value="1" id="touchme"><label for="touchme">' . $dedi_lang['plug_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=plug&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');
?>
