<?php
// | Last update : 2005-11-24        - Bugfix for multibyte charsets
// | Part of     : Update to Version 01.00.02
// +----------------------------------------------------------------------+
// | 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');
/**
 * 2. Eventuelle Actions/ Funktionen abarbeiten
 */
$perm->check('area_mod');
if ($idclient != 0 && $idclient != (int) $client && $idclient != '-1' || !isset($idclient)) $idclient = (int) $client;
unset($errno);
switch($action) {
    case 'copy':// Modul kopieren (import/ export)
        $errno = mod_copy($idmod, $from, $into);
        break;
    case 'save':// Modul speichern
        if(is_numeric($idmod)) $perm->check(3, 'mod', $idmod);
        else $perm->check(3, 'area_mod', 0);
	    $modname2     = $modname;
		$modverbose2  = $modverbose;
	    $description2 = $description;
	    $modversion2  = $modversion;
	    $modcat2 	  = $modcat;
	    $input2 	  = $input;
	    $output2 	  = $output;
	    remove_magic_quotes_gpc($modname2);
	    remove_magic_quotes_gpc($modverbose2);
	    remove_magic_quotes_gpc($description2);
	    remove_magic_quotes_gpc($modversion2);
	    remove_magic_quotes_gpc($modcat2);
	    remove_magic_quotes_gpc($input2);
	    remove_magic_quotes_gpc($output2);
	    if ( ((($errno = ($rep->mod_test($input2, $idmod) || $rep->mod_test($output2, $idmod)) ? '0423' : false) || ($errno = (empty($input2) && empty($output2)) ? '0424' : false))
           && !$s_overide)
           || '0412' != ($errno = mod_save($idmod, $modname, $modverbose, $description, $modversion, $modcat, $input, $output, $idclient, $repository_id,
              $install_sql, $uninstall_sql, $update_sql, $mod_rebuild_sql, $source, $mod_no_wedding)) ) {
            if (empty($modname) || $modname == '') $modname = $dedi_lang['mod_defaultname'];
			if (empty($modversion) || $modversion == '') $modversion = '1.0';
            $s_modul = array(
                'name'        => $modname2,
                'verbose'     => $modverbose2,
                'description' => $description2,
                'version'     => $modversion2,
                'cat'         => $modcat2,
                'input'       => $input2,
                'output'      => $output2);
            $sess->register('s_modul'); // merke:erst ein value kann gespeichert werden ;)
            $sess->freeze();
            header ('Location:' . $sess->url("main.php?area=mod_edit&idmod=" . $idmod . "&idclient=" . $idclient . "&errno=" . $errno));
            exit;
        }
        if ($sess->is_registered('s_modul')) $sess->unregister('s_modul');
        break;
    case 'save_config':// Konfiguration speichern
        $perm->check(4, 'mod', $idmod);
        $config = make_array_to_urlstring($MOD_VAR);
        $default = make_array_to_urlstring($s_default);
		// übernahme von 0A hexadecimal (US-ASCII character LF), und 0D (US-ASCII character CR)
        if (strpos($config, '%0D%0A') && !strpos($default, '%0D%0A')) $default = preg_replace('/(?<!%0D)%0A/','%0D%0A',$default);
        // übernahme von 5C hexadecimal (US-ASCII character \), und 22 (US-ASCII character ")
		if (strpos($config, '%5C%22') && !strpos($default, '%5C%22')) $default = preg_replace('/(?<!%5C)%22/','%5C%22',$default);
		// übernahme von 5C hexadecimal (US-ASCII character \), und 27 (US-ASCII character ')
		if (strpos($config, '%5C%27') && !strpos($default, '%5C%27')) $default = preg_replace('/(?<!%5C)%27/','%5C%27',$default);
		if ($config == $default) $config = '';
        $errno = mod_save_config($idmod, $config);
        if ($mod_config_overwrite_all == '1') mod_set_config_all($idmod, $config);
        if ($sess->is_registered('s_default')) $sess->unregister('s_default');
        break;
    case 'download': // Modul downloaden
        $perm->check(10, 'area_mod', 0);
        $errno = mod_download($idmod, $idclient);
        break;
    case 'upload': // Modul hochladen
        $perm->check(9, 'mod', $idmod);
        if ($override == 'false' || ($override == 'true' && !is_array($umodule) && !is_array($smodule) && !is_array($rmodule))) {
            if ($sess->is_registered('s_upload')) $sess->unregister('s_upload');
            $errno = '0418';
            break;
        }
        else $errno = mod_upload($idclient, $override, $umodule, $cmodule, $smodule, $rmodule);
        if ($errno == '0417' || $errno == '0419') {
            // Modul Update ||Reinstall?
            $link = $sess->url('main.php?area=mod_update&idclient=' . $idclient. '&errno=' . $errno);
            $tpl_in['ONLOAD_FUNCTION'] = "new_window('$link', 'updatewin','scrollbars=yes', 450, 400, 'true');";
        }
        break;
    case 'delete': // Modul löschen
        $perm->check(5, 'mod', $idmod);
        $errno = mod_delete($idmod);
        break;
    case 'update': // Modul updaten Repository
        $perm->check(12, 'mod', $idmod);
        $updatedata = $rep->mod_update_data($repid);
        if ($updatedata['repository_id'] == $repid) $errno = mod_update($idmod, $updatedata['repository_id'], $updatedata['name'], $updatedata['description'], $updatedata['version'], $updatedata['cat'], $updatedata['input'], $updatedata['output'], $updatedata['install_sql'], $updatedata['uninstall_sql'], $updatedata['update_sql'], $idclient);
        else $errno = '1500';
        break;
    case 'import': // Modul import Repository
        $perm->check(14, 'area_mod', 0);
        $installdata = $rep->mod_import_data($repid);
        if ($installdata['repository_id'] == $repid) $errno = mod_install($installdata['repository_id'], $installdata['name'], $installdata['description'], $installdata['version'], $installdata['cat'], $installdata['input'], $installdata['output'], $updatedata['install_sql'], $updatedata['uninstall_sql'], $updatedata['update_sql'], $idclient);
        else $errno = '1500';
        break;
    case 'lupdate': // Modul local updaten
        $perm->check(3, 'mod', $idmod);
        if ($override == 'false' || ($override == 'true' && !is_array($umodule) && !is_array($smodule) && !is_array($rmodule))) {
            $errno = '0418';
            break;
        } elseif ((is_array($umodule) || is_array($smodule) || is_array($rmodule)) && $override == 'true' && $sourceid) {
            $updatedata = $rep->mod_update_data($sourceid, 'all');
			if ($updatedata['idmod'] == $sourceid) {
            	if (is_array($umodule)) foreach($umodule as $uid => $key) {
                    if ($umodule["$uid"] == true) {
                        mod_lupdate($uid, $updatedata['repository_id'], $updatedata['name'], $updatedata['description'], $updatedata['version'], $updatedata['cat'], $updatedata['input'], $updatedata['output'], $updatedata['install_sql'], $updatedata['uninstall_sql'], $updatedata['update_sql'], $idclient);
                        if ($cmodule["$uid"] == false) {
							mod_save_config($uid, $updatedata['config']);
							mod_set_config_all($uid, $updatedata['config']);
						}
						else mod_set_config_status($uid);
						$errno = '0420';
                    }
                }
                if (is_array($rmodule)) foreach($rmodule as $uid => $key) {
                    if ($rmodule["$uid"] == true) {
                        mod_lupdate($uid, $updatedata['repository_id'], $updatedata['name'], $updatedata['description'], $updatedata['version'], $updatedata['cat'], $updatedata['input'], $updatedata['output'], $updatedata['install_sql'], $updatedata['uninstall_sql'], $updatedata['update_sql'], $idclient);
                        if ($cmodule["$uid"] == false) {
							mod_save_config($uid, $updatedata['config']);
							mod_set_config_all($uid, $updatedata['config']);
						}
						else mod_set_config_status($uid);
						$errno = ($errno == '0420') ? '0422' : '0421';
                    }
                }
			}
        	if (is_array($smodule) && $override == 'true') {
            	if ($smodule[$sourceid] == 'true') $errno2 = mod_copy($sourceid, '0', $client);
        	}
			break;
        } elseif ($sourceid && $idmod && !$override) {
        	// Modul Update?
            $errno = '0417';
        	$link = $sess->url('main.php?area=mod_lupdate&idclient=' . $idclient . '&idmod=' . $idmod . '&sourceid=' . $sourceid);
            $tpl_in['ONLOAD_FUNCTION'] = "new_window('$link', 'updatewin','scrollbars=yes', 450, 400, 'true');";
            break;
		}
		else $errno = '1500';
        break;
}

/**
 * 3. Eventuelle Dateien zur Darstellung includieren
 */
include('inc/inc.header.php');
// DebugMe! $debug_mod_update = true;
/**
 * 4. Bildschirmausgabe aufbereiten und ausgeben
 */
// Templatedatei laden
echo'<script language="JavaScript">';
echo'<!--';
echo'function update_confirm(url) {';
echo'  var update_all = false;';
echo"  if(confirm('" . $dedi_lang['mod_confirm_update'] . "')) update_all = true;";
echo'  alert(url+'|'+update_all);';
echo'}';
echo'//-->';
echo'</script>';
$tpl->loadTemplatefile('mod.tpl');
unset($tmp);
if ($idclient > '0') {
    if ($perm->have_perm(2, 'area_mod', 0)) $tmp['NEW_MOD'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod_edit&idclient=$idclient") . "\" onMouseOver=\"on('" . $dedi_lang['mod_new'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['mod_new'] . "</a>&nbsp;|&nbsp;";
    if ($perm->have_perm(7, 'area_mod', 0)) $tmp['IMPORT_MOD'] = "<a class=\"action\" href=\"" . $sess->url('main.php?area=mod&idclient=0') . "\" onMouseOver=\"on('" . $dedi_lang['mod_import'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['mod_import'] . "</a>&nbsp;";
} else {
    $tmp['BACK'] = "<a class=action href=\"" . $sess->url("main.php?area=mod&idclient=$client") . "\" onMouseOver=\"on('" . $dedi_lang['gen_back'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['gen_back'] . "</a>&nbsp;";
    if ($perm->have_perm(11, 'area_mod', 0) && $rep->enabled()) {
        if ($idclient == 0) {
            $tmp['BACK'] .= "|&nbsp;<a class=\"action\" href=\"" . $sess->url('main.php?area=mod&idclient=-1') . "\" onMouseOver=\"on('" . $dedi_lang['mod_repository_import'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['mod_repository'] . "</a>&nbsp;";
        } elseif ($idclient == '-1') {
            $tmp['BACK'] .= "|&nbsp;<a class=\"action\" href=\"" . $sess->url('main.php?area=mod&idclient=0') . "\" onMouseOver=\"on('" . $dedi_lang['mod_database_import'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['mod_database'] . "</a>&nbsp;";
        }
    }
}
$tmp['AREA'] = ($idclient == '0') ? (($perm->have_perm(12, 'mod', 0) && $rep->enabled()) ? $dedi_lang['area_mod_database'] : $dedi_lang['area_mod_import']) : (($idclient == '-1') ? (($perm->have_perm(12, 'mod', 0) && $rep->enabled()) ? $dedi_lang['area_mod_repository'] : $dedi_lang['area_mod_import']) : $dedi_lang['area_mod']);
$errno3 = ($rep->error()) ? $rep->error(1) : false;
if(!empty($errno) ||!empty($errno2) || !empty($errno3)) {
    $tpl->setCurrentBlock('ERROR');
    $tpl_error['ERRORMESSAGE'] = (!empty($errno)) ? $dedi_lang['err_' . $errno] . ' ' . $dedi_lang['err_' . $errno2] :  $dedi_lang['err_' . $errno2];
    if (!empty($errno3)) $tpl_error['ERRORMESSAGE'] .= '<br>'. $dedi_lang['err_' . $errno3];
    $tpl->setVariable($tpl_error);
    unset($tpl_error);
    $tpl->parseCurrentBlock();
}
// Tabellenformatierung
$tmp['TABLE_PADDING'] = $cellpadding;
$tmp['TABLE_SPACING'] = $cellspacing;
$tmp['TABLE_BORDER'] = $border;
$tmp['MOD_MODULENAME'] = $dedi_lang['mod_modulename'];
$tmp['MOD_DESCRIPTION'] = $dedi_lang['mod_description'];
$tmp['MOD_MODULEVERSION'] = $dedi_lang['mod_version'];
$tmp['MOD_MODULECAT'] = $dedi_lang['mod_cat'];
$tmp['MOD_ACTION'] = $dedi_lang['mod_action'];
$tmp['MOD_AUTHOR'] = $dedi_lang['mod_author'];

$tpl->setVariable($tmp);
unset($tmp);
if ($idclient != '-1') {
    // Module aus der Datenbank suchen
    $modlist = $rep->mod_list($idclient);
    if (is_array($modlist)) {
        $tpl->setCurrentBlock('ENTRY');
        foreach ($modlist as $mod) {
            $mod['titel'] = ( ' ++ ' .$dedi_lang['gen_description'] . ' ++ &#10;' . (($mod['cat'] != '') ? $dedi_lang['gen_cat'] . ': ' . htmlspecialchars($mod['cat']) . ' &#10;' : '') .
                        (($mod['verbose'] != '') ? $dedi_lang['gen_verbosename'] . ': ' . htmlspecialchars($mod['verbose']) . ' &#10;' : '') .
                        (empty($mod['source_id']) ? $dedi_lang['gen_name'] : $dedi_lang['gen_original']) . ': ' . htmlspecialchars($mod['name']) . ' &#10;' .
                        (($mod['version'] != '') ? $dedi_lang['gen_version'] . ': ' . htmlspecialchars($mod['version']) . ' &#10;' : '') . 'IdMod: ' . htmlspecialchars($mod['idmod']) . ' &#10;' .
                        $dedi_lang['gen_author'] . ': ' . htmlspecialchars($mod['author'])); // todo: real author name
            if (!$perm->have_perm(1, 'mod', $mod['idmod'])) continue;
            if (!$perm->have_perm(15, 'mod', 0) && (strpos($mod['version'], 'dev') != false && $mod['version'] != '')) continue;
            $mod['parse_error'] = !$mod['checked'];
            #if (!$mod['checked']) if (($mod['err_i'] = $rep->mod_test($mod['input'], $mod['idmod']))) $mod['parse_error'] = sprintf($dedi_lang['err_0416'], 'Input', $mod['err_i']);
            #if (!$mod['checked']) if (($mod['err_o'] = $rep->mod_test($mod['output'], $mod['idmod']))) $mod['parse_error'] = ($mod['parse_error'] != '') ? $mod['parse_error'] . ';  ' . sprintf($dedi_lang['err_0416'], 'Output', $mod['err_o']) : sprintf($dedi_lang['err_0416'], 'Output', $mod['err_o']);
            $mod['count'] = ($idclient == '0') ? (int) $rep->mod_count($client, $mod['idmod']) : $rep->mod_count('0', $mod['source_id']);
            $mod['count_delete'] = ($idclient == '0') ? (int) $rep->mod_count($client, $mod['idmod']) : $rep->mod_count($idclient, $mod['idmod']);
            $mod['count_repository'] = ($idclient == '-1') ? (int) $rep->mod_count('0', $mod['repository_id'], true) : false;
            // Hintergrundfarbe wählen
            if ($idclient == '0' && !$mod['parse_error']) {
                $tmpid['ENTRY_BGCOLOR'] = '#C7D5EB';
                $tmpid['OVERENTRY_BGCOLOR'] = '#A8BADE';
            } elseif ($mod['parse_error']) {
                $tmpid['ENTRY_BGCOLOR'] = '#EFE3DB';
                $tmpid['OVERENTRY_BGCOLOR'] = '#EBD5C7';
            } else {
                $tmpid['ENTRY_BGCOLOR'] = '#DBE3EF';
                $tmpid['OVERENTRY_BGCOLOR'] = '#C7D5EB';
            }
            // Modul Info
            $tmpid['CURSOR'] = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') ? 'hand' : 'pointer';
            $tmpid['ENTRY_INFO'] = "<img style=\"cursor:" . $tmpid['CURSOR'] . "\" src=\"tpl/" . $cfg_dedi['skin'] . "/img/about.gif\" border=\"0\" alt=\"" . $mod['titel'] . "\" title=\"" . $mod['titel'] . "\" width=\"16\" height=\"16\">";
            // Modul bearbeiten
            if ($perm->have_perm(3, 'mod', $mod['idmod'])) $tmpid['ENTRY_EDIT'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod_edit&idmod=" . $mod['idmod'] . "&idclient=$idclient") . "\" onMouseOver=\"on('" . $dedi_lang['mod_edit'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_edit.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_edit'] . "\" title=\"" . $dedi_lang['mod_edit'] . "\" width=\"18\" height=\"14\"></a>";
            else $tmpid['ENTRY_EDIT'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"18\" height=\"14\">";
            // Modul duplizieren - braucht perm neu und bearbeiten
            if ($perm->have_perm(2, 'mod', $mod['idmod']) && $perm->have_perm(3, 'area_mod', 0) && !$mod['parse_error']) $tmpid['ENTRY_DUPLICATE'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod_edit&idmod=" . $mod['idmod'] . "&idclient=$idclient&action=duplicate") . "\" onMouseOver=\"on('" . $dedi_lang['mod_duplicate'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_duplicate.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_duplicate'] . "\" title=\"" . $dedi_lang['mod_duplicate'] . "\" width=\"18\" height=\"14\"></a>";
            else $tmpid['ENTRY_DUPLICATE'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"18\" height=\"14\">";
            // Modul Sql erneut installieren
            /* todo:oldperms!
             *if ( $idclient > 0 && ($perm->have_perm('area_mod_import' ) || $perm->have_perm('area_mod_export')) && $mod['install_sql'] != '' && !$mod['parse_error'] ) $tmpid['ENTRY_SQL'] = "<a class=\"action\" href=\"".$sess->url("main.php?area=mod&action=copy&idmod=".$mod['idmod']."&into=$client&idclient=$client&from=$client")."\" onMouseOver=\"on('".$dedi_lang['mod_rebuild_sql']."');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/".$cfg_dedi['skin']."/img/but_calendar.gif\" border=\"0\" alt=\"".$dedi_lang['mod_rebuild_sql']."\" title=\"".$dedi_lang['mod_rebuild_sql']."\" width=\"14\" height=\"14\"></a>";
	         *elseif ( $idclient > 0 && ($perm->have_perm('area_mod_import' ) || $perm->have_perm('area_mod_export'))  && !$mod['parse_error'] ) $tmpid['ENTRY_SQL'] = "<img src=\"tpl/".$cfg_dedi['skin']."/img/space.gif\" border=\"0\" width=\"14\" height=\"14\">";// Modul konfigurieren
             *else $tmpid['ENTRY_SQL'] = "<img src=\"tpl/".$cfg_dedi['skin']."/img/space.gif\" border=\"0\" width=\"14\" height=\"14\">";
             */
            // Modul konfigurieren
            $mod['but_config'] = $mod['config'] != '' ? 'but_config_red.gif' : 'but_config.gif';
            $mod['mod_config'] = $mod['config'] != '' ? $dedi_lang['mod_config_change'] : $dedi_lang['mod_config'];
            if ($perm->have_perm(4, 'mod', $mod['idmod']) && !$mod['parse_error']) $tmpid['ENTRY_CONFIG'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod_config&idmod=" . $mod['idmod'] . "&idclient=$idclient") . "\" onMouseOver=\"on('" . $mod['mod_config'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/" . $mod['but_config'] . "\" border=\"0\" alt=\"" . $mod['mod_config'] . "\" title=\"" . $mod['mod_config'] . "\" width=\"15\" height=\"15\"></a>";
            else $tmpid['ENTRY_CONFIG'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"15\" height=\"15\">";
            // Modul importieren
            if ($idclient == '0' && ($perm->have_perm(7, 'mod', $mod['idmod']) || $perm->have_perm(8, 'area_mod', 0)) && !$mod['parse_error']) {
				if ($mod['count'] < 1) $tmpid['ENTRY_IMPORT'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod&action=copy&idmod=" . $mod['idmod'] . "&into=$client&idclient=0") . "\" onMouseOver=\"on('" . $dedi_lang['mod_import'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/import.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_import'] . "\" title=\"" . $dedi_lang['mod_import'] . "\" width=\"19\" height=\"11\"></a>";
                else $tmpid['ENTRY_IMPORT'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod&action=lupdate&idmod=" . $mod['idmod'] . "&sourceid=" . $mod['idmod'] . "&idclient=" . $client) . "\" onMouseOver=\"on('" . $dedi_lang['mod_reinstall_save'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/reinstall.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_reinstall_save'] . "\" title=\"" . $dedi_lang['mod_reinstall_save'] . "\" width=\"19\" height=\"15\"></a>";
			} elseif ($idclient == '0') $tmpid['ENTRY_IMPORT'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"19\" height=\"11\">";
            // Modul exportieren
            if ($idclient != '0' && $perm->have_perm(8, 'mod', $mod['idmod']) && $mod['count'] < 1 && !$mod['parse_error'] && empty($mod['source_id'])) $tmpid['ENTRY_EXPORT'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod&action=copy&idmod=" . $mod['idmod'] . "&from=$client&idclient=$idclient&into=0") . "\" onMouseOver=\"on('" . $dedi_lang['mod_export'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/export.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_export'] . "\" title=\"" . $dedi_lang['mod_export'] . "\" width=\"19\" height=\"11\"></a>";
			// Modul reinstallieren
			elseif ($idclient != '0' && $perm->have_perm(3, 'mod', $mod['idmod']) && !empty($mod['source_id'])) $tmpid['ENTRY_IMPORT'] = "<a class=\"action\" href=\"" . $sess->url('main.php?area=mod&action=lupdate&idmod=' . $mod['idmod'] . '&sourceid=' . $mod['source_id'] . '&idclient=' . $client) . "\" onMouseOver=\"on('" . $dedi_lang['mod_reinstall_save'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/reinstall.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_reinstall_save'] . "\" title=\"" . $dedi_lang['mod_reinstall_save'] . "\" width=\"19\" height=\"15\"></a>";
			elseif ($idclient != '0') $tmpid['ENTRY_EXPORT'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"19\" height=\"11\">";
			// Modul downloaden
            if($perm->have_perm(10, 'mod', $mod['idmod'])) $tmpid['ENTRY_DOWNLOAD'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod&idmod=" . $mod['idmod'] . "&idclient=$idclient&action=download") . "\" onMouseOver=\"on('" . $dedi_lang['mod_download'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_download.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_download'] . "\" title=\"" . $dedi_lang['mod_download'] . "\" width=\"15\" height=\"15\"></a>";
            else $tmpid['ENTRY_DOWNLOAD'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"15\" height=\"15\">";
            // Modul updaten
            if ($idclient == '0' && $perm->have_perm(12, 'mod', $mod['idmod']) && $rep->enabled()) {
                if (empty($mod['repository_id'])) $tmpid['ENTRY_UPDATE'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"13\" height=\"13\">";
                elseif (!$rep->online() && $cfg_rep['repository_show_offline'] == 'true') $tmpid['ENTRY_UPDATE'] = "<a name='norepository' onMouseOver=\"on('" . $dedi_lang['mod_repository_notonline'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_offline.gif\" width=\"13\" height=\"13\" border=\"0\" alt=\"" . $dedi_lang['mod_repository_notonline'] . "\" title=\"" . $dedi_lang['mod_repository_notonline'] . "\"></a>";
                elseif ($rep->mod_updates($mod['repository_id'], $mod['version'], $perm->have_perm(15, 'mod', $mod['idmod']))) $tmpid['ENTRY_UPDATE'] = "<a href=\"" . $sess->url('main.php?area=mod&action=update&idmod=' . $mod['idmod'] . '&repid=' . $mod['repository_id'] . '&idclient=' . $idclient) . "\" onMouseOver=\"on('" . $dedi_lang['mod_repository_update'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_onpublish.gif\" width=\"13\" height=\"13\" border=\"0\" alt=\"" . $dedi_lang['mod_repository_update'] . "\" title=\"" . $dedi_lang['mod_repository_update'] . "\"></a>";
                elseif ($cfg_rep['repository_show_up2date']) $tmpid['ENTRY_UPDATE'] = "<a name='norepository' onMouseOver=\"on('" . $dedi_lang['mod_repository_noupdate'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_online.gif\" width=\"13\" height=\"13\" border=\"0\" alt=\"" . $dedi_lang['mod_repository_noupdate'] . "\" title=\"" . $dedi_lang['mod_repository_noupdate'] . "\"></a>";
                else $tmpid['ENTRY_UPDATE'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"13\" height=\"13\">";
            } elseif ($idclient >=1 && ($perm->have_perm(7, 'mod', $mod['idmod']) || $perm->have_perm(8, 'area_mod', 0)) && $rep->loopback()) {
                if (empty($mod['source_id'])) $tmpid['ENTRY_UPDATE'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"13\" height=\"13\">";
                elseif ($rep->mod_local_update($mod['source_id'], $mod['version'], 'all') || $debug_mod_update) $tmpid['ENTRY_UPDATE'] = "<a href=\"" . $sess->url('main.php?area=mod&action=lupdate&idmod=' . $mod['idmod'] . '&sourceid=' . $mod['source_id'] . '&idclient=' . $idclient) . "\" onMouseOver=\"on('" . $dedi_lang['mod_local_update'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_onpublish.gif\" width=\"13\" height=\"13\" border=\"0\" alt=\"" . $dedi_lang['mod_local_update'] . "\" title=\"" . $dedi_lang['mod_local_update'] . "\"></a>";
                elseif ($cfg_rep['repository_show_up2date']) $tmpid['ENTRY_UPDATE'] = "<a name='norepository' onMouseOver=\"on('" . $dedi_lang['mod_repository_noupdate'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_online.gif\" width=\"13\" height=\"13\" border=\"0\" alt=\"" . $dedi_lang['mod_repository_noupdate'] . "\" title=\"" . $dedi_lang['mod_repository_noupdate'] . "\"></a>";
                else $tmpid['ENTRY_UPDATE'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"13\" height=\"13\">";
            }
            //DebugMe! echo "<br>$idmod:".$mod['deletable'].'|'.$perm->have_perm(5, 'mod', $mod['idmod']).'|'.$mod['count_delete'];
            // Modul löschen
            if ($mod['deletable'] == '1' && $perm->have_perm(5, 'mod', $mod['idmod']) && $mod['count_delete'] < 1) $tmpid['ENTRY_DELBUT'] = "<a href=\"" . $sess->url('main.php?area=mod&action=delete&idmod=' . $mod['idmod'] . '&idclient=' . $idclient) . "\" onMouseOver=\"on('" . $dedi_lang['mod_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['mod_delete'] . "\" title=\"" . $dedi_lang['mod_delete'] . "\"></a>";
            else $tmpid['ENTRY_DELBUT'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"13\" height=\"13\">";
            $tmpid['ENTRY_NAME'] = ($idclient >= 1 && $mod['verbose'] != '') ? htmlspecialchars($mod['verbose']) : htmlspecialchars($mod['name']);
            $tmpid['ENTRY_ANAME'] = "<a name=\"" . (htmlspecialchars('mod' . $mod['idmod']) . "\">");
            $tmpid['ENTRY_DESCRIPTION'] = htmlspecialchars($mod['description']);
            $tmpid['ENTRY_VERSION'] = htmlspecialchars($mod['version']);
            $tmpid['ENTRY_CAT'] = htmlspecialchars($mod['cat']);
            $tpl->setVariable($tmpid);
            unset($tmpid);
            $tpl->parseCurrentBlock();
        }
    } else {
        $tmp['MOD_NOMODULES'] = !$rep->error() ? $dedi_lang['mod_nomodules'] : $dedi_lang['err_' . $rep->error(1)];
        $tpl->setCurrentBlock('NOENTRY');
        $tpl->setVariable($tmp);
        unset($tmp);
        $tpl->parseCurrentBlock();
    }
} else {
    // Repository
    $modlist = $rep->mod_list($idclient);
    if (is_array($modlist)) {
        $tpl->setCurrentBlock('ENTRY');
        foreach ($modlist as $mod) {
            if (!$perm->have_perm(15, 'mod', 0) && (strpos($mod['version'], 'dev') != false && $mod['version'] != '')) continue;
            // Hintergrundfarbe wählen
            $tmp['ENTRY_BGCOLOR'] = '#DBE3EF';
            $tmp['OVERENTRY_BGCOLOR'] = '#C7D5EB';
            $mod['count_repository'] = (int) $rep->mod_count('0', $mod['repository_id'], true);
            $mod['titel'] = ( ' ++ ' .$dedi_lang['gen_description'] . ' ++ &#10;' . (($mod['cat'] != '') ? $dedi_lang['gen_cat'] . ': ' . htmlspecialchars($mod['cat']) . ' &#10;' : '') .
                        $dedi_lang['gen_name'] . ': ' . htmlspecialchars($mod['name']) . ' &#10;' .
                        (($mod['version'] != '') ? $dedi_lang['gen_version'] . ': ' . htmlspecialchars($mod['version']) . ' &#10;' : '') .
                        $dedi_lang['gen_author'] . ': ' . htmlspecialchars($mod['author'])); // todo: real author name
            // Modul Info
            $tmp['CURSOR'] = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE 5') ? 'hand' : 'pointer';
            $tmp['ENTRY_INFO'] = "<img style=\"cursor:" . $tmp['CURSOR'] . "\" src=\"tpl/" . $cfg_dedi['skin'] . "/img/about.gif\" border=\"0\" alt=\"" . $mod['titel'] . "\" title=\"" . $mod['titel'] . "\" width=\"16\" height=\"16\">";
            // Modul importieren, todo:validate developer module
            if ($perm->have_perm(14, 'area_mod', 0) && $mod['count_repository'] < 1) $tmp['ENTRY_IMPORT'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod&action=import&repid=" . $mod['repository_id'] . "&idclient=0") . "\" onMouseOver=\"on('" . $dedi_lang['mod_repository_import'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/import.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_repository_import'] . "\" title=\"" . $dedi_lang['mod_repository_import'] . "\" width=\"19\" height=\"11\"></a>";
            else $tmp['ENTRY_IMPORT'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"19\" height=\"11\">";
            // Modul downloaden, todo:validate developer module
            if($perm->have_perm(13, 'area_mod', 0)) $tmp['ENTRY_DOWNLOAD'] = "<a class=\"action\" href=\"" . $sess->url("main.php?area=mod&repid=" . $mod['repository_id'] . "&idclient=-1&action=download") . "\" onMouseOver=\"on('" . $dedi_lang['mod_repository_download'] . "');return true;\" onMouseOut=\"off();return true;\"><img src=\"tpl/" . $cfg_dedi['skin'] . "/img/but_download.gif\" border=\"0\" alt=\"" . $dedi_lang['mod_repository_download'] . "\" title=\"" . $dedi_lang['mod_repository_download'] . "\" width=\"15\" height=\"15\"></a>";
            else $tmp['ENTRY_DOWNLOAD'] = "<img src=\"tpl/" . $cfg_dedi['skin'] . "/img/space.gif\" border=\"0\" width=\"15\" height=\"15\">";
            $tmp['ENTRY_NAME'] = htmlspecialchars($mod['name']);
            $tmp['ENTRY_DESCRIPTION'] = htmlspecialchars($mod['description']);
            $tmp['ENTRY_VERSION'] = htmlspecialchars($mod['version']);
            $tmp['ENTRY_CAT'] = htmlspecialchars($mod['cat']);
            $tpl->setCurrentBlock('ENTRY');
            $tpl->setVariable($tmp);
            unset($tmp);
            $tpl->parseCurrentBlock();
        }
    } else {
        $tpl->setCurrentBlock('NOENTRY');
        $tmp['MOD_NOMODULES'] = !$rep->error() ? $dedi_lang['mod_nomodules'] : $dedi_lang['err_' . $rep->error(1)];
        $tpl->setVariable($tmp);
        unset($tmp);
        $tpl->parseCurrentBlock();
    }
}
unset($tmp);
// Upload
if($perm->have_perm(9, 'area_mod', 0) && $idclient != '-1') {
    $tpl->setCurrentBlock('FILEUPLOAD');
    $tmp['FILEUPLOAD_SESSIONNAME'] = $sess->name;
    $tmp['FILEUPLOAD_SESSIONID'] = $sess->id;
    $tmp['FILEUPLOAD_AREA'] = 'mod';
    $tmp['FILEUPLOAD_ACTION'] = 'upload';
    $tmp['FILEUPLOAD_CLIENT'] = $idclient;
    $tmp['FILEUPLOAD_TEXT'] = $dedi_lang['mod_upload'];
    $tmp['FILEUPLOAD_NAME'] = 'mod_upload_file';
    $tmp['FILEUPLOAD_HINT'] = $dedi_lang['mod_upload'];
    $tmp['FILEUPLOAD_PICT'] = 'tpl/' . $cfg_dedi['skin'] . '/img/upl_upload.gif';
} else {
    $tpl->setCurrentBlock('CLOSELINE');
    $tmp['NOVALUE'] = '&nbsp';
}
$tpl->setVariable($tmp);
unset($tmp);
$tpl->parseCurrentBlock();
?>