<?php
// File: $Id: inc.mod_lupdate.php,v 1.4 2004/06/24 13:08:47 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');

// Browsern das cachen von Backendseiten verbieten
if ($cfg_dedi['backend_cache'] == '1') {
	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Datum aus Vergangenheit
	header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // immer geändert
	header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
	header('Cache-Control: post-check=0, pre-check=0', false);
	header('Pragma: no-cache');
}
// Debug options
$cfg_dedi['debug_sql'] 		= false;
$cfg_dedi['debug_general'] 	= false;
$cfg_dedi['debug_error'] 	= false;
// read update Modul
$updatedata = $rep->mod_update_data($sourceid, 'all'); 
$modversion = $updatedata['version'];
$modname    = $updatedata['name'];
list($type,$rid,$uid) = explode(":",$updatedata['repository_id']);
$repid = $type.':'.$rid;
if ($idmod == $sourceid) {
	// read Repository
	$items = $rep->rep_local_count($idclient, 'mod');
	if ($idclient != '0' && count($items['rep']["$idclient"]["$repid"]) >= 1) {
            foreach($items['rep']["$idclient"]["$repid"] as $modul) {
                if ((lib_floatval($modversion) > lib_floatval($modul['version'])) && !empty($modul['source_id'])) {
                    $umod[] = $modul;
                } elseif ((lib_floatval($modversion) == lib_floatval($modul['version'])) && !empty($modul['source_id'])) {
                    $rmod[] = $modul;
                }
            }
	} elseif ($idclient == '0' && count($items['rep']["$repid"]) >= 1) {
            foreach($items['rep']["$repid"] as $modul) {
                if ((lib_floatval($modversion) > lib_floatval($modul['version'])) && $modul['idclient'] == '0') {
                    $umod[] = $modul;
                } elseif ((lib_floatval($modversion) == lib_floatval($modul['version'])) && $modul['idclient'] == '0') {
                    $rmod[] = $modul;
                }
            }
	}
} else {
	$modul = $rep->mod_data($idmod, $idclient);
	if ((lib_floatval($updatedata['version']) > lib_floatval($modul['version'])) && !empty($modul['source_id'])) {
		$umod[] = $modul;
	}
	elseif ((lib_floatval($updatedata['version']) == lib_floatval($modul['version'])) && !empty($modul['source_id'])) {
		$rmod[] = $modul;
	}
}
$modversion = $updatedata['version'];
$modname    = $updatedata['name'];
$tmp['ENTRY_BGCOLOR'] = '#DBE3EF';
$tmp['OVERENTRY_BGCOLOR'] = '#C7D5EB';
$ENTRY_SAFE    = $dedi_lang['mod_confirm_new'] . '&nbsp;<input type="checkbox" name="smodule['.$sourceid.']" value="true" id="smodule['.$sourceid.']">';
// Start Output
echo '<html>';
echo '<head>';
echo '  <title>der-dirigent '.$cfg_dedi['version'].'</title>';
echo '  <link rel="stylesheet" type="text/css" href="tpl/standard/css/styles.css">';
echo '  <script src="tpl/standard/js/standard.js" type="text/javascript"></script>';
echo '<script type="text/javascript">
<!--';
echo "
var query = '';\n
function submitUri(){\n
for(i=0; i<document.updatemod.elements.length; ++i) {\n
  if (document.updatemod.elements[i].name.search(/umodule.+/) != -1) {
    if (document.updatemod.elements[i].checked == true) query = query + '&' + document.updatemod.elements[i].name + '=' + document.updatemod.elements[i].value;\n
  }
  else if (document.updatemod.elements[i].name.search(/cmodule.+/) != -1) {
    if (document.updatemod.elements[i].checked == true) query = query + '&' + document.updatemod.elements[i].name + '=' + document.updatemod.elements[i].value;\n
  }
  else if (document.updatemod.elements[i].name.search(/rmodule.+/) != -1) {
    if (document.updatemod.elements[i].checked == true) query = query + '&' + document.updatemod.elements[i].name + '=' + document.updatemod.elements[i].value;\n
  }
  else if (document.updatemod.elements[i].name.search(/smodule.+/) != -1) {
    if (document.updatemod.elements[i].checked == true) query = query + '&' + document.updatemod.elements[i].name + '=' + document.updatemod.elements[i].value;\n
  }
  else query = query + '&' + document.updatemod.elements[i].name + '=' + document.updatemod.elements[i].value;\n
}\n
window.opener.location.href='" . $sess->url("main.php?area=mod") . "' + query;\n
self.close();\n
return false;\n
}";
echo '//-->
</script>';
echo '</head>';
echo '<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" onload="off();return true;">';
echo "<center>\n";
echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"98%\">\n";
echo "  <tr>\n";
echo "    <td>";
echo $dedi_lang['mod_confirm_lupdate'];
echo "&nbsp;";
if ($errno) echo "&nbsp;<span class=\"errormsg\">" . $dedi_lang["err_$errno"] . "</span>&nbsp;";
echo "     </td>\n";
$tmp['BACK'] = "<a class=\"action\" href=\"javascript:window.opener.location.href='" . $sess->url("main.php?area=mod&action=lupdate&idclient=$idclient&override=false") . "';self.close();\" onMouseOver=\"on('" . $dedi_lang['gen_abort'] . "');return true;\" onMouseOut=\"off();return true;\">" . $dedi_lang['gen_abort'] . "</a>&nbsp;";
echo "     <td align=\"right\">&nbsp;<br>" . $tmp['BACK'] . "&nbsp;</td>";
echo "  </tr>\n";
echo "  <tr>\n";
echo "    <td colspan=\"2\"><br>\n";
// Formular zum updaten der Module
echo "    <form name=\"updatemod\" action=\"\" method=\"get\" onSubmit=\"return submitUri();\">\n";
echo "    <input type=\"hidden\" name=\"action\" value=\"lupdate\">\n";
echo "    <input type=\"hidden\" name=\"idclient\" value=\"$idclient\">\n";
echo "    <input type=\"hidden\" name=\"override\" value=\"true\">\n";
echo "    <input type=\"hidden\" name=\"sourceid\" value=\"$sourceid\">\n";
echo "    <input type=\"hidden\" name=\"idmod\" value=\"$idmod\">\n";
echo "	 <table cellpadding=\"$cellpadding\" cellspacing=\"$cellspacing\" border=\"$border\">\n";
echo "	   <tr valign=\"top\">\n";
echo "	     <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang["mod_modulename"] . "&nbsp;</td>\n";
echo "	     <td class=\"content\">" . htmlspecialchars($modname) . "</td>\n";
echo "      </tr>\n";
echo "	   <tr valign=\"top\">\n";
echo "	     <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang["mod_version"] . "&nbsp;</td>\n";
echo "	     <td class=\"content\">" . htmlspecialchars($modversion) . "</td>\n";
echo "      </tr>\n";
if (is_array($umod)) {
echo "	   <tr valign=\"top\">\n";
echo "	     <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang["gen_overide"] . "&nbsp;</td>\n";
echo "	     <td class=\"content\">";
echo "         <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
echo "          <tr valign=\"top\">
                 <th align=\"left\" nowrap>&nbsp;ID&nbsp;</th>
                 <th align=\"left\" nowrap>&nbsp;".$dedi_lang['mod_version']."&nbsp;</th>
                 <th>&nbsp;".$dedi_lang['mod_action']."&nbsp;</th>
                </tr>";
foreach($umod as $modul) {
$ENTRY_ID = $modul['idmod'];
$ENTRY_VERSION = $modul['version'];
$ENTRY_UPDATE  = $dedi_lang['mod_update_save'] . '&nbsp;<input type="checkbox" name="umodule['.$modul['idmod'].']" value="true" id="umodule['.$modul['idmod'].']">';
$ENTRY_CONFIG  = $dedi_lang['mod_config_save'] . '&nbsp;<input type="checkbox" name="cmodule['.$modul['idmod'].']" value="true" id="cmodule['.$modul['idmod'].']">';
echo "          <tr valign=\"top\" onMouseOver=\"this.style['background']='".$tmp['OVERENTRY_BGCOLOR']."';\" onMouseOut=\"this.style['background']='".$tmp['ENTRY_BGCOLOR']."';\" bgcolor=\"".$tmp['ENTRY_BGCOLOR']."\">
                 <td class=\"entry\" valign=\"middle\" align=\"center\"><nobr>&nbsp;".$ENTRY_ID."&nbsp;</nobr></td>
                 <td class=\"entry\" valign=\"middle\" align=\"center\" nowrap>&nbsp;".$ENTRY_VERSION."&nbsp;</td>
                 <td class=\"entry\" valign=\"middle\" align=\"right\" nowrap>&nbsp;</td>
                </tr>
                <tr valign=\"top\" onMouseOver=\"this.style['background']='".$tmp['OVERENTRY_BGCOLOR']."';\" onMouseOut=\"this.style['background']='".$tmp['ENTRY_BGCOLOR']."';\" bgcolor=\"".$tmp['ENTRY_BGCOLOR']."\">
                 <td colspan=\"2\" class=\"entry\" valign=\"middle\" align=\"center\" nowrap>&nbsp;</td>
                 <td class=\"entry\" valign=\"middle\" align=\"right\" nowrap>".$ENTRY_UPDATE."</td>
                </tr>
                <tr valign=\"top\" onMouseOver=\"this.style['background']='".$tmp['OVERENTRY_BGCOLOR']."';\" onMouseOut=\"this.style['background']='".$tmp['ENTRY_BGCOLOR']."';\" bgcolor=\"".$tmp['ENTRY_BGCOLOR']."\">
                 <td colspan=\"2\" class=\"entry\" valign=\"middle\" align=\"center\" nowrap>&nbsp;</td>
                 <td class=\"entry\" valign=\"middle\" align=\"right\" nowrap>".$ENTRY_CONFIG."</td>
                </tr>";
}
echo "         </table>";
echo "       </td>\n";
echo "      </tr>\n";
}
if (is_array($rmod)) {
echo "	   <tr valign=\"top\">\n";
echo "	     <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang["gen_reinstall"] . "&nbsp;</td>\n";
echo "	     <td class=\"content\">";
echo "         <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
echo "          <tr valign=\"top\">
                 <th align=\"left\" nowrap>&nbsp;ID&nbsp;</th>
                 <th align=\"left\" nowrap>&nbsp;".$dedi_lang['mod_version']."&nbsp;</th>
                 <th>&nbsp;".$dedi_lang['mod_action']."&nbsp;</th>
                </tr>";
foreach($rmod as $modul) {
$ENTRY_ID = $modul['idmod'];
$ENTRY_VERSION = $modul['version'];
$ENTRY_REINSTALL = $dedi_lang['mod_reinstall_save'] . '&nbsp;<input type="checkbox" name="rmodule['.$modul['idmod'].']" value="true" id="rmodule['.$modul['idmod'].']">';
$ENTRY_CONFIG  = $dedi_lang['mod_config_save'] . '&nbsp;<input type="checkbox" name="cmodule['.$modul['idmod'].']" value="true" id="cmodule['.$modul['idmod'].']">';
echo "          <tr valign=\"top\" onMouseOver=\"this.style['background']='".$tmp['OVERENTRY_BGCOLOR']."';\" onMouseOut=\"this.style['background']='".$tmp['ENTRY_BGCOLOR']."';\" bgcolor=\"".$tmp['ENTRY_BGCOLOR']."\">
                 <td class=\"entry\" valign=\"middle\" align=\"center\"><nobr>&nbsp;".$ENTRY_ID."&nbsp;</nobr></td>
                 <td class=\"entry\" valign=\"middle\" align=\"center\" nowrap>&nbsp;".$ENTRY_VERSION."&nbsp;</td>
                 <td class=\"entry\" valign=\"middle\" align=\"right\" nowrap>&nbsp;</td>
                </tr>
                <tr valign=\"top\" onMouseOver=\"this.style['background']='".$tmp['OVERENTRY_BGCOLOR']."';\" onMouseOut=\"this.style['background']='".$tmp['ENTRY_BGCOLOR']."';\" bgcolor=\"".$tmp['ENTRY_BGCOLOR']."\">
                 <td colspan=\"2\" class=\"entry\" valign=\"middle\" align=\"center\" nowrap>&nbsp;</td>
                 <td class=\"entry\" valign=\"middle\" align=\"right\" nowrap>".$ENTRY_REINSTALL."</td>
                </tr>
                <tr valign=\"top\" onMouseOver=\"this.style['background']='".$tmp['OVERENTRY_BGCOLOR']."';\" onMouseOut=\"this.style['background']='".$tmp['ENTRY_BGCOLOR']."';\" bgcolor=\"".$tmp['ENTRY_BGCOLOR']."\">
                 <td colspan=\"2\" class=\"entry\" valign=\"middle\" align=\"center\" nowrap>&nbsp;</td>
                 <td class=\"entry\" valign=\"middle\" align=\"right\" nowrap>".$ENTRY_CONFIG."</td>
                </tr>";
}
echo "         </table>";
echo "       </td>\n";
echo "      </tr>\n";
}
if ($idclient != $updatedata['idclient']) {
echo "	   <tr valign=\"top\">\n";
echo "	     <td class=\"head\" width=\"110\" nowrap>&nbsp;" . $dedi_lang['mod_defaultname'] . "&nbsp;</td>\n";
echo "	     <td class=\"content\" valign=\"middle\" align=\"right\">".$ENTRY_SAFE."</td>\n";
echo "      </tr>\n";
echo "      <tr>\n";
}
echo "        <td>&nbsp;</td>\n";
echo "        <td><a href=\"javascript:window.opener.location.href='" . $sess->url("main.php?area=mod&action=lupdate&idclient=$idclient&override=false") . "';self.close();\"><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');
?>
